blob: 85c3dc7f9b94b390d892fe6c18cd7c8f395fb448 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2004 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef TALK_MEDIA_WEBRTCVOICEENGINE_H_
29#define TALK_MEDIA_WEBRTCVOICEENGINE_H_
30
31#include <map>
32#include <set>
33#include <string>
34#include <vector>
35
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036#include "talk/media/base/rtputils.h"
37#include "talk/media/webrtc/webrtccommon.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038#include "talk/media/webrtc/webrtcvoe.h"
39#include "talk/session/media/channel.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000040#include "webrtc/base/buffer.h"
41#include "webrtc/base/byteorder.h"
42#include "webrtc/base/logging.h"
43#include "webrtc/base/scoped_ptr.h"
44#include "webrtc/base/stream.h"
Fredrik Solenberg4b60c732015-05-07 14:07:48 +020045#include "webrtc/base/thread_checker.h"
46#include "webrtc/call.h"
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +000047#include "webrtc/common.h"
Henrik Lundin64dad832015-05-11 12:44:23 +020048#include "webrtc/config.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050namespace cricket {
51
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052class AudioDeviceModule;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +000053class AudioRenderer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054class VoETraceWrapper;
55class VoEWrapper;
56class VoiceProcessor;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057class WebRtcVoiceMediaChannel;
58
59// WebRtcVoiceEngine is a class to be used with CompositeMediaEngine.
60// It uses the WebRtc VoiceEngine library for audio handling.
61class WebRtcVoiceEngine
62 : public webrtc::VoiceEngineObserver,
63 public webrtc::TraceCallback,
64 public webrtc::VoEMediaProcess {
Jelena Marusicc28a8962015-05-29 15:05:44 +020065 friend class WebRtcVoiceMediaChannel;
66
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067 public:
68 WebRtcVoiceEngine();
69 // Dependency injection for testing.
Fredrik Solenbergccb49e72015-05-19 11:37:56 +020070 WebRtcVoiceEngine(VoEWrapper* voe_wrapper, VoETraceWrapper* tracing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071 ~WebRtcVoiceEngine();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000072 bool Init(rtc::Thread* worker_thread);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 void Terminate();
74
75 int GetCapabilities();
Fredrik Solenberg709ed672015-09-15 12:26:33 +020076 webrtc::VoiceEngine* GetVoE() { return voe()->engine(); }
77 VoiceMediaChannel* CreateChannel(webrtc::Call* call,
78 const AudioOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +000080 AudioOptions GetOptions() const { return options_; }
81 bool SetOptions(const AudioOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082 bool SetDelayOffset(int offset);
83 bool SetDevices(const Device* in_device, const Device* out_device);
84 bool GetOutputVolume(int* level);
85 bool SetOutputVolume(int level);
86 int GetInputLevel();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087
88 const std::vector<AudioCodec>& codecs();
89 bool FindCodec(const AudioCodec& codec);
90 bool FindWebRtcCodec(const AudioCodec& codec, webrtc::CodecInst* gcodec);
91
92 const std::vector<RtpHeaderExtension>& rtp_header_extensions() const;
93
94 void SetLogging(int min_sev, const char* filter);
95
96 bool RegisterProcessor(uint32 ssrc,
97 VoiceProcessor* voice_processor,
98 MediaProcessorDirection direction);
99 bool UnregisterProcessor(uint32 ssrc,
100 VoiceProcessor* voice_processor,
101 MediaProcessorDirection direction);
102
103 // Method from webrtc::VoEMediaProcess
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000104 void Process(int channel,
105 webrtc::ProcessingTypes type,
106 int16_t audio10ms[],
Peter Kastingdce40cf2015-08-24 14:52:23 -0700107 size_t length,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000108 int sampling_freq,
109 bool is_stereo) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110
111 // For tracking WebRtc channels. Needed because we have to pause them
112 // all when switching devices.
113 // May only be called by WebRtcVoiceMediaChannel.
114 void RegisterChannel(WebRtcVoiceMediaChannel *channel);
115 void UnregisterChannel(WebRtcVoiceMediaChannel *channel);
116
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117 // Called by WebRtcVoiceMediaChannel to set a gain offset from
118 // the default AGC target level.
119 bool AdjustAgcLevel(int delta);
120
121 VoEWrapper* voe() { return voe_wrapper_.get(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000122 int GetLastEngineError();
123
Fredrik Solenbergccb49e72015-05-19 11:37:56 +0200124 // Set the external ADM. This can only be called before Init.
125 bool SetAudioDeviceModule(webrtc::AudioDeviceModule* adm);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126
wu@webrtc.orga9890802013-12-13 00:21:03 +0000127 // Starts AEC dump using existing file.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000128 bool StartAecDump(rtc::PlatformFile file);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000129
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130 // Check whether the supplied trace should be ignored.
131 bool ShouldIgnoreTrace(const std::string& trace);
132
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000133 // Create a VoiceEngine Channel.
134 int CreateMediaVoiceChannel();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000135
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136 private:
Fredrik Solenbergaf9fb212015-08-26 10:45:53 +0200137 typedef std::vector<WebRtcVoiceMediaChannel*> ChannelList;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138 typedef sigslot::
139 signal3<uint32, MediaProcessorDirection, AudioFrame*> FrameSignal;
140
141 void Construct();
142 void ConstructCodecs();
henrik.lundin@webrtc.org8038d422014-11-11 08:38:24 +0000143 bool GetVoeCodec(int index, webrtc::CodecInst* codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144 bool InitInternal();
145 void SetTraceFilter(int filter);
146 void SetTraceOptions(const std::string& options);
147 // Applies either options or overrides. Every option that is "set"
148 // will be applied. Every option not "set" will be ignored. This
149 // allows us to selectively turn on and off different options easily
150 // at any time.
151 bool ApplyOptions(const AudioOptions& options);
Jelena Marusicc28a8962015-05-29 15:05:44 +0200152 // Overrides, when set, take precedence over the options on a
153 // per-option basis. For example, if AGC is set in options and AEC
154 // is set in overrides, AGC and AEC will be both be set. Overrides
155 // can also turn off options. For example, if AGC is set to "on" in
156 // options and AGC is set to "off" in overrides, the result is that
157 // AGC will be off until different overrides are applied or until
158 // the overrides are cleared. Only one set of overrides is present
159 // at a time (they do not "stack"). And when the overrides are
160 // cleared, the media engine's state reverts back to the options set
161 // via SetOptions. This allows us to have both "persistent options"
162 // (the normal options) and "temporary options" (overrides).
163 bool SetOptionOverrides(const AudioOptions& options);
164 bool ClearOptionOverrides();
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000165
166 // webrtc::TraceCallback:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000167 void Print(webrtc::TraceLevel level, const char* trace, int length) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000168
169 // webrtc::VoiceEngineObserver:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000170 void CallbackOnError(int channel, int errCode) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000171
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 // Given the device type, name, and id, find device id. Return true and
173 // set the output parameter rtc_id if successful.
174 bool FindWebRtcAudioDeviceId(
175 bool is_input, const std::string& dev_name, int dev_id, int* rtc_id);
176 bool FindChannelAndSsrc(int channel_num,
177 WebRtcVoiceMediaChannel** channel,
178 uint32* ssrc) const;
179 bool FindChannelNumFromSsrc(uint32 ssrc,
180 MediaProcessorDirection direction,
181 int* channel_num);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182
183 bool UnregisterProcessorChannel(MediaProcessorDirection channel_direction,
184 uint32 ssrc,
185 VoiceProcessor* voice_processor,
186 MediaProcessorDirection processor_direction);
187
188 void StartAecDump(const std::string& filename);
189 void StopAecDump();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000190 int CreateVoiceChannel(VoEWrapper* voe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191
192 // When a voice processor registers with the engine, it is connected
193 // to either the Rx or Tx signals, based on the direction parameter.
194 // SignalXXMediaFrame will be invoked for every audio packet.
195 FrameSignal SignalRxMediaFrame;
196 FrameSignal SignalTxMediaFrame;
197
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000198 static const int kDefaultLogSeverity = rtc::LS_WARNING;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000199
200 // The primary instance of WebRtc VoiceEngine.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000201 rtc::scoped_ptr<VoEWrapper> voe_wrapper_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000202 rtc::scoped_ptr<VoETraceWrapper> tracing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 // The external audio device manager
204 webrtc::AudioDeviceModule* adm_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 int log_filter_;
206 std::string log_options_;
207 bool is_dumping_aec_;
208 std::vector<AudioCodec> codecs_;
209 std::vector<RtpHeaderExtension> rtp_header_extensions_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 ChannelList channels_;
211 // channels_ can be read from WebRtc callback thread. We need a lock on that
212 // callback as well as the RegisterChannel/UnregisterChannel.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000213 rtc::CriticalSection channels_cs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 webrtc::AgcConfig default_agc_config_;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000215
216 webrtc::Config voe_config_;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000217
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 bool initialized_;
219 // See SetOptions and SetOptionOverrides for a description of the
220 // difference between options and overrides.
221 // options_ are the base options, which combined with the
222 // option_overrides_, create the current options being used.
223 // options_ is stored so that when option_overrides_ is cleared, we
224 // can restore the options_ without the option_overrides.
225 AudioOptions options_;
226 AudioOptions option_overrides_;
227
228 // When the media processor registers with the engine, the ssrc is cached
229 // here so that a look up need not be made when the callback is invoked.
230 // This is necessary because the lookup results in mux_channels_cs lock being
231 // held and if a remote participant leaves the hangout at the same time
232 // we hit a deadlock.
233 uint32 tx_processor_ssrc_;
234 uint32 rx_processor_ssrc_;
235
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000236 rtc::CriticalSection signal_media_critical_;
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000237
Henrik Lundin441f6342015-06-09 16:03:13 +0200238 // Cache received extended_filter_aec, delay_agnostic_aec and experimental_ns
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100239 // values, and apply them in case they are missing in the audio options. We
240 // need to do this because SetExtraOptions() will revert to defaults for
241 // options which are not provided.
Henrik Lundin441f6342015-06-09 16:03:13 +0200242 Settable<bool> extended_filter_aec_;
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100243 Settable<bool> delay_agnostic_aec_;
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000244 Settable<bool> experimental_ns_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245};
246
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247// WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses
248// WebRtc Voice Engine.
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200249class WebRtcVoiceMediaChannel : public VoiceMediaChannel,
250 public webrtc::Transport {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200252 WebRtcVoiceMediaChannel(WebRtcVoiceEngine* engine,
253 const AudioOptions& options,
254 webrtc::Call* call);
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200255 ~WebRtcVoiceMediaChannel() override;
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200256
257 int voe_channel() const { return voe_channel_; }
258 bool valid() const { return voe_channel_ != -1; }
solenberg66f43392015-09-09 01:36:22 -0700259 const AudioOptions& options() const { return options_; }
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200260
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700261 bool SetSendParameters(const AudioSendParameters& params) override;
262 bool SetRecvParameters(const AudioRecvParameters& params) override;
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200263 bool SetPlayout(bool playout) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 bool PausePlayout();
265 bool ResumePlayout();
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200266 bool SetSend(SendFlags send) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267 bool PauseSend();
268 bool ResumeSend();
solenberg1dd98f32015-09-10 01:57:14 -0700269 bool SetAudioSend(uint32 ssrc, bool mute, const AudioOptions* options,
270 AudioRenderer* renderer) override;
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200271 bool AddSendStream(const StreamParams& sp) override;
272 bool RemoveSendStream(uint32 ssrc) override;
273 bool AddRecvStream(const StreamParams& sp) override;
274 bool RemoveRecvStream(uint32 ssrc) override;
275 bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) override;
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200276 bool GetActiveStreams(AudioInfo::StreamList* actives) override;
277 int GetOutputLevel() override;
278 int GetTimeSinceLastTyping() override;
279 void SetTypingDetectionParameters(int time_window,
280 int cost_per_typing,
281 int reporting_threshold,
282 int penalty_decay,
283 int type_event_delay) override;
284 bool SetOutputScaling(uint32 ssrc, double left, double right) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000285
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200286 bool CanInsertDtmf() override;
287 bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200289 void OnPacketReceived(rtc::Buffer* packet,
290 const rtc::PacketTime& packet_time) override;
291 void OnRtcpReceived(rtc::Buffer* packet,
292 const rtc::PacketTime& packet_time) override;
293 void OnReadyToSend(bool ready) override {}
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200294 bool GetStats(VoiceMediaInfo* info) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295 // Gets last reported error from WebRtc voice engine. This should be only
296 // called in response a failure.
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200297 void GetLastMediaError(uint32* ssrc,
298 VoiceMediaChannel::Error* error) override;
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200299
300 // implements Transport interface
Peter Boströmac547a62015-09-17 23:03:57 +0200301 int SendPacket(const void* data, size_t len) override {
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200302 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len,
303 kMaxRtpPacketLen);
304 return VoiceMediaChannel::SendPacket(&packet) ? static_cast<int>(len) : -1;
305 }
306
Peter Boströmac547a62015-09-17 23:03:57 +0200307 int SendRTCPPacket(const void* data, size_t len) override {
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200308 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len,
309 kMaxRtpPacketLen);
310 return VoiceMediaChannel::SendRtcp(&packet) ? static_cast<int>(len) : -1;
311 }
312
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 bool FindSsrc(int channel_num, uint32* ssrc);
314 void OnError(uint32 ssrc, int error);
315
316 bool sending() const { return send_ != SEND_NOTHING; }
Fredrik Solenbergaf9fb212015-08-26 10:45:53 +0200317 int GetReceiveChannelNum(uint32 ssrc) const;
318 int GetSendChannelNum(uint32 ssrc) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200320 private:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200321 bool SetSendCodecs(const std::vector<AudioCodec>& codecs);
322 bool SetSendRtpHeaderExtensions(
323 const std::vector<RtpHeaderExtension>& extensions);
324 bool SetOptions(const AudioOptions& options);
325 bool SetMaxSendBandwidth(int bps);
326 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs);
327 bool SetRecvRtpHeaderExtensions(
328 const std::vector<RtpHeaderExtension>& extensions);
solenberg1dd98f32015-09-10 01:57:14 -0700329 bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer);
330 bool MuteStream(uint32 ssrc, bool mute);
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200331
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200332 WebRtcVoiceEngine* engine() { return engine_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333 int GetLastEngineError() { return engine()->GetLastEngineError(); }
334 int GetOutputLevel(int channel);
335 bool GetRedSendCodec(const AudioCodec& red_codec,
336 const std::vector<AudioCodec>& all_codecs,
337 webrtc::CodecInst* send_codec);
338 bool EnableRtcp(int channel);
339 bool ResetRecvCodecs(int channel);
340 bool SetPlayout(int channel, bool playout);
341 static uint32 ParseSsrc(const void* data, size_t len, bool rtcp);
342 static Error WebRtcErrorToChannelError(int err_code);
343
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +0000344 class WebRtcVoiceChannelRenderer;
345 // Map of ssrc to WebRtcVoiceChannelRenderer object. A new object of
346 // WebRtcVoiceChannelRenderer will be created for every new stream and
347 // will be destroyed when the stream goes away.
348 typedef std::map<uint32, WebRtcVoiceChannelRenderer*> ChannelMap;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000349 typedef int (webrtc::VoERTP_RTCP::* ExtensionSetterFunction)(int, bool,
350 unsigned char);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000351
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000352 void SetNack(int channel, bool nack_enabled);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000353 void SetNack(const ChannelMap& channels, bool nack_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 bool SetSendCodec(const webrtc::CodecInst& send_codec);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000355 bool SetSendCodec(int channel, const webrtc::CodecInst& send_codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 bool ChangePlayout(bool playout);
357 bool ChangeSend(SendFlags send);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000358 bool ChangeSend(int channel, SendFlags send);
359 void ConfigureSendChannel(int channel);
wu@webrtc.org78187522013-10-07 23:32:02 +0000360 bool ConfigureRecvChannel(int channel);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000361 bool DeleteChannel(int channel);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000362 bool InConferenceMode() const {
363 return options_.conference_mode.GetWithDefaultIfUnset(false);
364 }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000365 bool IsDefaultChannel(int channel_id) const {
366 return channel_id == voe_channel();
367 }
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000368 bool SetSendCodecs(int channel, const std::vector<AudioCodec>& codecs);
minyue@webrtc.org26236952014-10-29 02:27:08 +0000369 bool SetSendBitrateInternal(int bps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000371 bool SetHeaderExtension(ExtensionSetterFunction setter, int channel_id,
372 const RtpHeaderExtension* extension);
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200373 void RecreateAudioReceiveStreams();
374 void AddAudioReceiveStream(uint32 ssrc);
375 void RemoveAudioReceiveStream(uint32 ssrc);
Fredrik Solenbergaf9fb212015-08-26 10:45:53 +0200376 bool SetRecvCodecsInternal(const std::vector<AudioCodec>& new_codecs);
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200377
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000378 bool SetChannelRecvRtpHeaderExtensions(
379 int channel_id,
380 const std::vector<RtpHeaderExtension>& extensions);
381 bool SetChannelSendRtpHeaderExtensions(
382 int channel_id,
383 const std::vector<RtpHeaderExtension>& extensions);
384
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200385 rtc::ThreadChecker thread_checker_;
386
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200387 WebRtcVoiceEngine* const engine_;
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200388 const int voe_channel_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000389 std::vector<AudioCodec> recv_codecs_;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000390 std::vector<AudioCodec> send_codecs_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000391 rtc::scoped_ptr<webrtc::CodecInst> send_codec_;
minyue@webrtc.org26236952014-10-29 02:27:08 +0000392 bool send_bitrate_setting_;
393 int send_bitrate_bps_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394 AudioOptions options_;
395 bool dtmf_allowed_;
396 bool desired_playout_;
397 bool nack_enabled_;
398 bool playout_;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000399 bool typing_noise_detected_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000400 SendFlags desired_send_;
401 SendFlags send_;
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200402 webrtc::Call* const call_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000404 // send_channels_ contains the channels which are being used for sending.
405 // When the default channel (voe_channel) is used for sending, it is
406 // contained in send_channels_, otherwise not.
407 ChannelMap send_channels_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000408 std::vector<RtpHeaderExtension> send_extensions_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000409 uint32 default_receive_ssrc_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000410 // Note the default channel (voe_channel()) can reside in both
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000411 // receive_channels_ and send_channels_ in non-conference mode and in that
412 // case it will only be there if a non-zero default_receive_ssrc_ is set.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000413 ChannelMap receive_channels_; // for multiple sources
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200414 std::map<uint32, webrtc::AudioReceiveStream*> receive_streams_;
pbos8fc7fa72015-07-15 08:02:58 -0700415 std::map<uint32, StreamParams> receive_stream_params_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000416 // receive_channels_ can be read from WebRtc callback thread. Access from
417 // the WebRtc thread must be synchronized with edits on the worker thread.
418 // Reads on the worker thread are ok.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000419 std::vector<RtpHeaderExtension> receive_extensions_;
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200420 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
421
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422 // Do not lock this on the VoE media processor thread; potential for deadlock
423 // exists.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000424 mutable rtc::CriticalSection receive_channels_cs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425};
426
427} // namespace cricket
428
429#endif // TALK_MEDIA_WEBRTCVOICEENGINE_H_