blob: a1a6b489668a0481d28cab88bdfbeb2601afefd9 [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;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056class WebRtcVoiceMediaChannel;
57
58// WebRtcVoiceEngine is a class to be used with CompositeMediaEngine.
59// It uses the WebRtc VoiceEngine library for audio handling.
60class WebRtcVoiceEngine
61 : public webrtc::VoiceEngineObserver,
Fredrik Solenberg7d173362015-09-23 12:23:21 +020062 public webrtc::TraceCallback {
Jelena Marusicc28a8962015-05-29 15:05:44 +020063 friend class WebRtcVoiceMediaChannel;
64
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065 public:
66 WebRtcVoiceEngine();
67 // Dependency injection for testing.
Fredrik Solenbergccb49e72015-05-19 11:37:56 +020068 WebRtcVoiceEngine(VoEWrapper* voe_wrapper, VoETraceWrapper* tracing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069 ~WebRtcVoiceEngine();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000070 bool Init(rtc::Thread* worker_thread);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071 void Terminate();
72
73 int GetCapabilities();
Fredrik Solenberg709ed672015-09-15 12:26:33 +020074 webrtc::VoiceEngine* GetVoE() { return voe()->engine(); }
75 VoiceMediaChannel* CreateChannel(webrtc::Call* call,
76 const AudioOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +000078 AudioOptions GetOptions() const { return options_; }
79 bool SetOptions(const AudioOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080 bool SetDelayOffset(int offset);
81 bool SetDevices(const Device* in_device, const Device* out_device);
82 bool GetOutputVolume(int* level);
83 bool SetOutputVolume(int level);
84 int GetInputLevel();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085
86 const std::vector<AudioCodec>& codecs();
87 bool FindCodec(const AudioCodec& codec);
88 bool FindWebRtcCodec(const AudioCodec& codec, webrtc::CodecInst* gcodec);
89
90 const std::vector<RtpHeaderExtension>& rtp_header_extensions() const;
91
92 void SetLogging(int min_sev, const char* filter);
93
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094 // For tracking WebRtc channels. Needed because we have to pause them
95 // all when switching devices.
96 // May only be called by WebRtcVoiceMediaChannel.
97 void RegisterChannel(WebRtcVoiceMediaChannel *channel);
98 void UnregisterChannel(WebRtcVoiceMediaChannel *channel);
99
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100 // Called by WebRtcVoiceMediaChannel to set a gain offset from
101 // the default AGC target level.
102 bool AdjustAgcLevel(int delta);
103
104 VoEWrapper* voe() { return voe_wrapper_.get(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105 int GetLastEngineError();
106
Fredrik Solenbergccb49e72015-05-19 11:37:56 +0200107 // Set the external ADM. This can only be called before Init.
108 bool SetAudioDeviceModule(webrtc::AudioDeviceModule* adm);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109
wu@webrtc.orga9890802013-12-13 00:21:03 +0000110 // Starts AEC dump using existing file.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000111 bool StartAecDump(rtc::PlatformFile file);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000112
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113 // Check whether the supplied trace should be ignored.
114 bool ShouldIgnoreTrace(const std::string& trace);
115
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000116 // Create a VoiceEngine Channel.
117 int CreateMediaVoiceChannel();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000118
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119 private:
Fredrik Solenbergaf9fb212015-08-26 10:45:53 +0200120 typedef std::vector<WebRtcVoiceMediaChannel*> ChannelList;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121
122 void Construct();
123 void ConstructCodecs();
henrik.lundin@webrtc.org8038d422014-11-11 08:38:24 +0000124 bool GetVoeCodec(int index, webrtc::CodecInst* codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125 bool InitInternal();
126 void SetTraceFilter(int filter);
127 void SetTraceOptions(const std::string& options);
128 // Applies either options or overrides. Every option that is "set"
129 // will be applied. Every option not "set" will be ignored. This
130 // allows us to selectively turn on and off different options easily
131 // at any time.
132 bool ApplyOptions(const AudioOptions& options);
Jelena Marusicc28a8962015-05-29 15:05:44 +0200133 // Overrides, when set, take precedence over the options on a
134 // per-option basis. For example, if AGC is set in options and AEC
135 // is set in overrides, AGC and AEC will be both be set. Overrides
136 // can also turn off options. For example, if AGC is set to "on" in
137 // options and AGC is set to "off" in overrides, the result is that
138 // AGC will be off until different overrides are applied or until
139 // the overrides are cleared. Only one set of overrides is present
140 // at a time (they do not "stack"). And when the overrides are
141 // cleared, the media engine's state reverts back to the options set
142 // via SetOptions. This allows us to have both "persistent options"
143 // (the normal options) and "temporary options" (overrides).
144 bool SetOptionOverrides(const AudioOptions& options);
145 bool ClearOptionOverrides();
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000146
147 // webrtc::TraceCallback:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000148 void Print(webrtc::TraceLevel level, const char* trace, int length) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000149
150 // webrtc::VoiceEngineObserver:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000151 void CallbackOnError(int channel, int errCode) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000152
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153 // Given the device type, name, and id, find device id. Return true and
154 // set the output parameter rtc_id if successful.
155 bool FindWebRtcAudioDeviceId(
156 bool is_input, const std::string& dev_name, int dev_id, int* rtc_id);
157 bool FindChannelAndSsrc(int channel_num,
158 WebRtcVoiceMediaChannel** channel,
159 uint32* ssrc) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000160
161 void StartAecDump(const std::string& filename);
162 void StopAecDump();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000163 int CreateVoiceChannel(VoEWrapper* voe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000165 static const int kDefaultLogSeverity = rtc::LS_WARNING;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166
167 // The primary instance of WebRtc VoiceEngine.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000168 rtc::scoped_ptr<VoEWrapper> voe_wrapper_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000169 rtc::scoped_ptr<VoETraceWrapper> tracing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170 // The external audio device manager
171 webrtc::AudioDeviceModule* adm_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 int log_filter_;
173 std::string log_options_;
174 bool is_dumping_aec_;
175 std::vector<AudioCodec> codecs_;
176 std::vector<RtpHeaderExtension> rtp_header_extensions_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177 ChannelList channels_;
178 // channels_ can be read from WebRtc callback thread. We need a lock on that
179 // callback as well as the RegisterChannel/UnregisterChannel.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000180 rtc::CriticalSection channels_cs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 webrtc::AgcConfig default_agc_config_;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000182
183 webrtc::Config voe_config_;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000184
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 bool initialized_;
186 // See SetOptions and SetOptionOverrides for a description of the
187 // difference between options and overrides.
188 // options_ are the base options, which combined with the
189 // option_overrides_, create the current options being used.
190 // options_ is stored so that when option_overrides_ is cleared, we
191 // can restore the options_ without the option_overrides.
192 AudioOptions options_;
193 AudioOptions option_overrides_;
194
Henrik Lundin441f6342015-06-09 16:03:13 +0200195 // Cache received extended_filter_aec, delay_agnostic_aec and experimental_ns
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100196 // values, and apply them in case they are missing in the audio options. We
197 // need to do this because SetExtraOptions() will revert to defaults for
198 // options which are not provided.
Henrik Lundin441f6342015-06-09 16:03:13 +0200199 Settable<bool> extended_filter_aec_;
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100200 Settable<bool> delay_agnostic_aec_;
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000201 Settable<bool> experimental_ns_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000202};
203
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204// WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses
205// WebRtc Voice Engine.
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200206class WebRtcVoiceMediaChannel : public VoiceMediaChannel,
207 public webrtc::Transport {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200209 WebRtcVoiceMediaChannel(WebRtcVoiceEngine* engine,
210 const AudioOptions& options,
211 webrtc::Call* call);
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200212 ~WebRtcVoiceMediaChannel() override;
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200213
214 int voe_channel() const { return voe_channel_; }
215 bool valid() const { return voe_channel_ != -1; }
solenberg66f43392015-09-09 01:36:22 -0700216 const AudioOptions& options() const { return options_; }
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200217
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700218 bool SetSendParameters(const AudioSendParameters& params) override;
219 bool SetRecvParameters(const AudioRecvParameters& params) override;
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200220 bool SetPlayout(bool playout) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 bool PausePlayout();
222 bool ResumePlayout();
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200223 bool SetSend(SendFlags send) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 bool PauseSend();
225 bool ResumeSend();
solenberg1dd98f32015-09-10 01:57:14 -0700226 bool SetAudioSend(uint32 ssrc, bool mute, const AudioOptions* options,
227 AudioRenderer* renderer) override;
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200228 bool AddSendStream(const StreamParams& sp) override;
229 bool RemoveSendStream(uint32 ssrc) override;
230 bool AddRecvStream(const StreamParams& sp) override;
231 bool RemoveRecvStream(uint32 ssrc) override;
232 bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) override;
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200233 bool GetActiveStreams(AudioInfo::StreamList* actives) override;
234 int GetOutputLevel() override;
235 int GetTimeSinceLastTyping() override;
236 void SetTypingDetectionParameters(int time_window,
237 int cost_per_typing,
238 int reporting_threshold,
239 int penalty_decay,
240 int type_event_delay) override;
241 bool SetOutputScaling(uint32 ssrc, double left, double right) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200243 bool CanInsertDtmf() override;
244 bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200246 void OnPacketReceived(rtc::Buffer* packet,
247 const rtc::PacketTime& packet_time) override;
248 void OnRtcpReceived(rtc::Buffer* packet,
249 const rtc::PacketTime& packet_time) override;
250 void OnReadyToSend(bool ready) override {}
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200251 bool GetStats(VoiceMediaInfo* info) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 // Gets last reported error from WebRtc voice engine. This should be only
253 // called in response a failure.
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200254 void GetLastMediaError(uint32* ssrc,
255 VoiceMediaChannel::Error* error) override;
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200256
257 // implements Transport interface
Peter Boströmac547a62015-09-17 23:03:57 +0200258 int SendPacket(const void* data, size_t len) override {
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200259 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len,
260 kMaxRtpPacketLen);
261 return VoiceMediaChannel::SendPacket(&packet) ? static_cast<int>(len) : -1;
262 }
263
Peter Boströmac547a62015-09-17 23:03:57 +0200264 int SendRTCPPacket(const void* data, size_t len) override {
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200265 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len,
266 kMaxRtpPacketLen);
267 return VoiceMediaChannel::SendRtcp(&packet) ? static_cast<int>(len) : -1;
268 }
269
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 bool FindSsrc(int channel_num, uint32* ssrc);
271 void OnError(uint32 ssrc, int error);
272
273 bool sending() const { return send_ != SEND_NOTHING; }
Fredrik Solenbergaf9fb212015-08-26 10:45:53 +0200274 int GetReceiveChannelNum(uint32 ssrc) const;
275 int GetSendChannelNum(uint32 ssrc) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000276
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200277 private:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200278 bool SetSendCodecs(const std::vector<AudioCodec>& codecs);
279 bool SetSendRtpHeaderExtensions(
280 const std::vector<RtpHeaderExtension>& extensions);
281 bool SetOptions(const AudioOptions& options);
282 bool SetMaxSendBandwidth(int bps);
283 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs);
284 bool SetRecvRtpHeaderExtensions(
285 const std::vector<RtpHeaderExtension>& extensions);
solenberg1dd98f32015-09-10 01:57:14 -0700286 bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer);
287 bool MuteStream(uint32 ssrc, bool mute);
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200288
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200289 WebRtcVoiceEngine* engine() { return engine_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290 int GetLastEngineError() { return engine()->GetLastEngineError(); }
291 int GetOutputLevel(int channel);
292 bool GetRedSendCodec(const AudioCodec& red_codec,
293 const std::vector<AudioCodec>& all_codecs,
294 webrtc::CodecInst* send_codec);
295 bool EnableRtcp(int channel);
296 bool ResetRecvCodecs(int channel);
297 bool SetPlayout(int channel, bool playout);
298 static uint32 ParseSsrc(const void* data, size_t len, bool rtcp);
299 static Error WebRtcErrorToChannelError(int err_code);
300
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +0000301 class WebRtcVoiceChannelRenderer;
302 // Map of ssrc to WebRtcVoiceChannelRenderer object. A new object of
303 // WebRtcVoiceChannelRenderer will be created for every new stream and
304 // will be destroyed when the stream goes away.
305 typedef std::map<uint32, WebRtcVoiceChannelRenderer*> ChannelMap;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000306 typedef int (webrtc::VoERTP_RTCP::* ExtensionSetterFunction)(int, bool,
307 unsigned char);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000308
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000309 void SetNack(int channel, bool nack_enabled);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000310 void SetNack(const ChannelMap& channels, bool nack_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 bool SetSendCodec(const webrtc::CodecInst& send_codec);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000312 bool SetSendCodec(int channel, const webrtc::CodecInst& send_codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 bool ChangePlayout(bool playout);
314 bool ChangeSend(SendFlags send);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000315 bool ChangeSend(int channel, SendFlags send);
316 void ConfigureSendChannel(int channel);
wu@webrtc.org78187522013-10-07 23:32:02 +0000317 bool ConfigureRecvChannel(int channel);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000318 bool DeleteChannel(int channel);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000319 bool InConferenceMode() const {
320 return options_.conference_mode.GetWithDefaultIfUnset(false);
321 }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000322 bool IsDefaultChannel(int channel_id) const {
323 return channel_id == voe_channel();
324 }
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000325 bool SetSendCodecs(int channel, const std::vector<AudioCodec>& codecs);
minyue@webrtc.org26236952014-10-29 02:27:08 +0000326 bool SetSendBitrateInternal(int bps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000328 bool SetHeaderExtension(ExtensionSetterFunction setter, int channel_id,
329 const RtpHeaderExtension* extension);
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200330 void RecreateAudioReceiveStreams();
331 void AddAudioReceiveStream(uint32 ssrc);
332 void RemoveAudioReceiveStream(uint32 ssrc);
Fredrik Solenbergaf9fb212015-08-26 10:45:53 +0200333 bool SetRecvCodecsInternal(const std::vector<AudioCodec>& new_codecs);
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200334
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000335 bool SetChannelRecvRtpHeaderExtensions(
336 int channel_id,
337 const std::vector<RtpHeaderExtension>& extensions);
338 bool SetChannelSendRtpHeaderExtensions(
339 int channel_id,
340 const std::vector<RtpHeaderExtension>& extensions);
341
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200342 rtc::ThreadChecker thread_checker_;
343
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200344 WebRtcVoiceEngine* const engine_;
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200345 const int voe_channel_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 std::vector<AudioCodec> recv_codecs_;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000347 std::vector<AudioCodec> send_codecs_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000348 rtc::scoped_ptr<webrtc::CodecInst> send_codec_;
minyue@webrtc.org26236952014-10-29 02:27:08 +0000349 bool send_bitrate_setting_;
350 int send_bitrate_bps_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 AudioOptions options_;
352 bool dtmf_allowed_;
353 bool desired_playout_;
354 bool nack_enabled_;
355 bool playout_;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000356 bool typing_noise_detected_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 SendFlags desired_send_;
358 SendFlags send_;
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200359 webrtc::Call* const call_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000361 // send_channels_ contains the channels which are being used for sending.
362 // When the default channel (voe_channel) is used for sending, it is
363 // contained in send_channels_, otherwise not.
364 ChannelMap send_channels_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000365 std::vector<RtpHeaderExtension> send_extensions_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 uint32 default_receive_ssrc_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000367 // Note the default channel (voe_channel()) can reside in both
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000368 // receive_channels_ and send_channels_ in non-conference mode and in that
369 // case it will only be there if a non-zero default_receive_ssrc_ is set.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000370 ChannelMap receive_channels_; // for multiple sources
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200371 std::map<uint32, webrtc::AudioReceiveStream*> receive_streams_;
pbos8fc7fa72015-07-15 08:02:58 -0700372 std::map<uint32, StreamParams> receive_stream_params_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000373 // receive_channels_ can be read from WebRtc callback thread. Access from
374 // the WebRtc thread must be synchronized with edits on the worker thread.
375 // Reads on the worker thread are ok.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000376 std::vector<RtpHeaderExtension> receive_extensions_;
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200377 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
378
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 // Do not lock this on the VoE media processor thread; potential for deadlock
380 // exists.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000381 mutable rtc::CriticalSection receive_channels_cs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000382};
383
384} // namespace cricket
385
386#endif // TALK_MEDIA_WEBRTCVOICEENGINE_H_