blob: 781901e2febac5ff29d3d85d9434d290921e1e4a [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"
38#include "talk/media/webrtc/webrtcexport.h"
39#include "talk/media/webrtc/webrtcvoe.h"
40#include "talk/session/media/channel.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000041#include "webrtc/base/buffer.h"
42#include "webrtc/base/byteorder.h"
43#include "webrtc/base/logging.h"
44#include "webrtc/base/scoped_ptr.h"
45#include "webrtc/base/stream.h"
Fredrik Solenberg4b60c732015-05-07 14:07:48 +020046#include "webrtc/base/thread_checker.h"
47#include "webrtc/call.h"
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +000048#include "webrtc/common.h"
Henrik Lundin64dad832015-05-11 12:44:23 +020049#include "webrtc/config.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050
51#if !defined(LIBPEERCONNECTION_LIB) && \
52 !defined(LIBPEERCONNECTION_IMPLEMENTATION)
buildbot@webrtc.org6b21b712014-07-31 15:08:53 +000053// If you hit this, then you've tried to include this header from outside
54// the shared library. An instance of this class must only be created from
55// within the library that actually implements it. Otherwise use the
56// WebRtcMediaEngine to construct an instance.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057#error "Bogus include."
58#endif
59
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +000060namespace webrtc {
61class VideoEngine;
62}
63
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064namespace cricket {
65
66// WebRtcSoundclipStream is an adapter object that allows a memory stream to be
67// passed into WebRtc, and support looping.
68class WebRtcSoundclipStream : public webrtc::InStream {
69 public:
70 WebRtcSoundclipStream(const char* buf, size_t len)
71 : mem_(buf, len), loop_(true) {
72 }
73 void set_loop(bool loop) { loop_ = loop; }
xians@webrtc.org3cefbc92014-10-10 09:42:53 +000074
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000075 int Read(void* buf, size_t len) override;
76 int Rewind() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077
78 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000079 rtc::MemoryStream mem_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080 bool loop_;
81};
82
83// WebRtcMonitorStream is used to monitor a stream coming from WebRtc.
84// For now we just dump the data.
85class WebRtcMonitorStream : public webrtc::OutStream {
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000086 bool Write(const void* buf, size_t len) override { return true; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087};
88
89class AudioDeviceModule;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +000090class AudioRenderer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091class VoETraceWrapper;
92class VoEWrapper;
93class VoiceProcessor;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094class WebRtcVoiceMediaChannel;
95
96// WebRtcVoiceEngine is a class to be used with CompositeMediaEngine.
97// It uses the WebRtc VoiceEngine library for audio handling.
98class WebRtcVoiceEngine
99 : public webrtc::VoiceEngineObserver,
100 public webrtc::TraceCallback,
101 public webrtc::VoEMediaProcess {
102 public:
103 WebRtcVoiceEngine();
104 // Dependency injection for testing.
Fredrik Solenbergccb49e72015-05-19 11:37:56 +0200105 WebRtcVoiceEngine(VoEWrapper* voe_wrapper, VoETraceWrapper* tracing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106 ~WebRtcVoiceEngine();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000107 bool Init(rtc::Thread* worker_thread);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108 void Terminate();
109
110 int GetCapabilities();
111 VoiceMediaChannel* CreateChannel();
112
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000113 AudioOptions GetOptions() const { return options_; }
114 bool SetOptions(const AudioOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115 // Overrides, when set, take precedence over the options on a
116 // per-option basis. For example, if AGC is set in options and AEC
117 // is set in overrides, AGC and AEC will be both be set. Overrides
118 // can also turn off options. For example, if AGC is set to "on" in
119 // options and AGC is set to "off" in overrides, the result is that
120 // AGC will be off until different overrides are applied or until
121 // the overrides are cleared. Only one set of overrides is present
122 // at a time (they do not "stack"). And when the overrides are
123 // cleared, the media engine's state reverts back to the options set
124 // via SetOptions. This allows us to have both "persistent options"
125 // (the normal options) and "temporary options" (overrides).
126 bool SetOptionOverrides(const AudioOptions& options);
127 bool ClearOptionOverrides();
128 bool SetDelayOffset(int offset);
129 bool SetDevices(const Device* in_device, const Device* out_device);
130 bool GetOutputVolume(int* level);
131 bool SetOutputVolume(int level);
132 int GetInputLevel();
133 bool SetLocalMonitor(bool enable);
134
135 const std::vector<AudioCodec>& codecs();
136 bool FindCodec(const AudioCodec& codec);
137 bool FindWebRtcCodec(const AudioCodec& codec, webrtc::CodecInst* gcodec);
138
139 const std::vector<RtpHeaderExtension>& rtp_header_extensions() const;
140
141 void SetLogging(int min_sev, const char* filter);
142
143 bool RegisterProcessor(uint32 ssrc,
144 VoiceProcessor* voice_processor,
145 MediaProcessorDirection direction);
146 bool UnregisterProcessor(uint32 ssrc,
147 VoiceProcessor* voice_processor,
148 MediaProcessorDirection direction);
149
150 // Method from webrtc::VoEMediaProcess
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000151 void Process(int channel,
152 webrtc::ProcessingTypes type,
153 int16_t audio10ms[],
154 int length,
155 int sampling_freq,
156 bool is_stereo) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157
158 // For tracking WebRtc channels. Needed because we have to pause them
159 // all when switching devices.
160 // May only be called by WebRtcVoiceMediaChannel.
161 void RegisterChannel(WebRtcVoiceMediaChannel *channel);
162 void UnregisterChannel(WebRtcVoiceMediaChannel *channel);
163
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 // Called by WebRtcVoiceMediaChannel to set a gain offset from
165 // the default AGC target level.
166 bool AdjustAgcLevel(int delta);
167
168 VoEWrapper* voe() { return voe_wrapper_.get(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 int GetLastEngineError();
170
Fredrik Solenbergccb49e72015-05-19 11:37:56 +0200171 // Set the external ADM. This can only be called before Init.
172 bool SetAudioDeviceModule(webrtc::AudioDeviceModule* adm);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173
wu@webrtc.orga9890802013-12-13 00:21:03 +0000174 // Starts AEC dump using existing file.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000175 bool StartAecDump(rtc::PlatformFile file);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000176
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177 // Check whether the supplied trace should be ignored.
178 bool ShouldIgnoreTrace(const std::string& trace);
179
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000180 // Create a VoiceEngine Channel.
181 int CreateMediaVoiceChannel();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000182
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183 private:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 typedef std::vector<WebRtcVoiceMediaChannel *> ChannelList;
185 typedef sigslot::
186 signal3<uint32, MediaProcessorDirection, AudioFrame*> FrameSignal;
187
188 void Construct();
189 void ConstructCodecs();
henrik.lundin@webrtc.org8038d422014-11-11 08:38:24 +0000190 bool GetVoeCodec(int index, webrtc::CodecInst* codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191 bool InitInternal();
192 void SetTraceFilter(int filter);
193 void SetTraceOptions(const std::string& options);
194 // Applies either options or overrides. Every option that is "set"
195 // will be applied. Every option not "set" will be ignored. This
196 // allows us to selectively turn on and off different options easily
197 // at any time.
198 bool ApplyOptions(const AudioOptions& options);
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000199
200 // webrtc::TraceCallback:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000201 void Print(webrtc::TraceLevel level, const char* trace, int length) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000202
203 // webrtc::VoiceEngineObserver:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000204 void CallbackOnError(int channel, int errCode) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000205
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 // Given the device type, name, and id, find device id. Return true and
207 // set the output parameter rtc_id if successful.
208 bool FindWebRtcAudioDeviceId(
209 bool is_input, const std::string& dev_name, int dev_id, int* rtc_id);
210 bool FindChannelAndSsrc(int channel_num,
211 WebRtcVoiceMediaChannel** channel,
212 uint32* ssrc) const;
213 bool FindChannelNumFromSsrc(uint32 ssrc,
214 MediaProcessorDirection direction,
215 int* channel_num);
216 bool ChangeLocalMonitor(bool enable);
217 bool PauseLocalMonitor();
218 bool ResumeLocalMonitor();
219
220 bool UnregisterProcessorChannel(MediaProcessorDirection channel_direction,
221 uint32 ssrc,
222 VoiceProcessor* voice_processor,
223 MediaProcessorDirection processor_direction);
224
225 void StartAecDump(const std::string& filename);
226 void StopAecDump();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000227 int CreateVoiceChannel(VoEWrapper* voe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228
229 // When a voice processor registers with the engine, it is connected
230 // to either the Rx or Tx signals, based on the direction parameter.
231 // SignalXXMediaFrame will be invoked for every audio packet.
232 FrameSignal SignalRxMediaFrame;
233 FrameSignal SignalTxMediaFrame;
234
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000235 static const int kDefaultLogSeverity = rtc::LS_WARNING;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236
237 // The primary instance of WebRtc VoiceEngine.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000238 rtc::scoped_ptr<VoEWrapper> voe_wrapper_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000239 rtc::scoped_ptr<VoETraceWrapper> tracing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 // The external audio device manager
241 webrtc::AudioDeviceModule* adm_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 int log_filter_;
243 std::string log_options_;
244 bool is_dumping_aec_;
245 std::vector<AudioCodec> codecs_;
246 std::vector<RtpHeaderExtension> rtp_header_extensions_;
247 bool desired_local_monitor_enable_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000248 rtc::scoped_ptr<WebRtcMonitorStream> monitor_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 ChannelList channels_;
250 // channels_ can be read from WebRtc callback thread. We need a lock on that
251 // callback as well as the RegisterChannel/UnregisterChannel.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000252 rtc::CriticalSection channels_cs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 webrtc::AgcConfig default_agc_config_;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000254
255 webrtc::Config voe_config_;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000256
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 bool initialized_;
258 // See SetOptions and SetOptionOverrides for a description of the
259 // difference between options and overrides.
260 // options_ are the base options, which combined with the
261 // option_overrides_, create the current options being used.
262 // options_ is stored so that when option_overrides_ is cleared, we
263 // can restore the options_ without the option_overrides.
264 AudioOptions options_;
265 AudioOptions option_overrides_;
266
267 // When the media processor registers with the engine, the ssrc is cached
268 // here so that a look up need not be made when the callback is invoked.
269 // This is necessary because the lookup results in mux_channels_cs lock being
270 // held and if a remote participant leaves the hangout at the same time
271 // we hit a deadlock.
272 uint32 tx_processor_ssrc_;
273 uint32 rx_processor_ssrc_;
274
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000275 rtc::CriticalSection signal_media_critical_;
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000276
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100277 // Cache received experimental_aec, delay_agnostic_aec and experimental_ns
278 // values, and apply them in case they are missing in the audio options. We
279 // need to do this because SetExtraOptions() will revert to defaults for
280 // options which are not provided.
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000281 Settable<bool> experimental_aec_;
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100282 Settable<bool> delay_agnostic_aec_;
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000283 Settable<bool> experimental_ns_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284};
285
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286// WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses
287// WebRtc Voice Engine.
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200288class WebRtcVoiceMediaChannel : public VoiceMediaChannel,
289 public webrtc::Transport {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290 public:
291 explicit WebRtcVoiceMediaChannel(WebRtcVoiceEngine *engine);
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200292 ~WebRtcVoiceMediaChannel() override;
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200293
294 int voe_channel() const { return voe_channel_; }
295 bool valid() const { return voe_channel_ != -1; }
296
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200297 bool SetOptions(const AudioOptions& options) override;
298 bool GetOptions(AudioOptions* options) const override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 *options = options_;
300 return true;
301 }
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200302 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) override;
303 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) override;
304 bool SetRecvRtpHeaderExtensions(
305 const std::vector<RtpHeaderExtension>& extensions) override;
306 bool SetSendRtpHeaderExtensions(
307 const std::vector<RtpHeaderExtension>& extensions) override;
308 bool SetPlayout(bool playout) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 bool PausePlayout();
310 bool ResumePlayout();
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200311 bool SetSend(SendFlags send) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 bool PauseSend();
313 bool ResumeSend();
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200314 bool AddSendStream(const StreamParams& sp) override;
315 bool RemoveSendStream(uint32 ssrc) override;
316 bool AddRecvStream(const StreamParams& sp) override;
317 bool RemoveRecvStream(uint32 ssrc) override;
318 bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) override;
319 bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) override;
320 bool GetActiveStreams(AudioInfo::StreamList* actives) override;
321 int GetOutputLevel() override;
322 int GetTimeSinceLastTyping() override;
323 void SetTypingDetectionParameters(int time_window,
324 int cost_per_typing,
325 int reporting_threshold,
326 int penalty_decay,
327 int type_event_delay) override;
328 bool SetOutputScaling(uint32 ssrc, double left, double right) override;
329 bool GetOutputScaling(uint32 ssrc, double* left, double* right) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200331 bool SetRingbackTone(const char* buf, int len) override;
332 bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) override;
333 bool CanInsertDtmf() override;
334 bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200336 void OnPacketReceived(rtc::Buffer* packet,
337 const rtc::PacketTime& packet_time) override;
338 void OnRtcpReceived(rtc::Buffer* packet,
339 const rtc::PacketTime& packet_time) override;
340 void OnReadyToSend(bool ready) override {}
341 bool MuteStream(uint32 ssrc, bool on) override;
342 bool SetMaxSendBandwidth(int bps) override;
343 bool GetStats(VoiceMediaInfo* info) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344 // Gets last reported error from WebRtc voice engine. This should be only
345 // called in response a failure.
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200346 void GetLastMediaError(uint32* ssrc,
347 VoiceMediaChannel::Error* error) override;
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200348
349 // implements Transport interface
350 int SendPacket(int channel, const void* data, size_t len) override {
351 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len,
352 kMaxRtpPacketLen);
353 return VoiceMediaChannel::SendPacket(&packet) ? static_cast<int>(len) : -1;
354 }
355
356 int SendRTCPPacket(int channel, const void* data, size_t len) override {
357 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len,
358 kMaxRtpPacketLen);
359 return VoiceMediaChannel::SendRtcp(&packet) ? static_cast<int>(len) : -1;
360 }
361
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 bool FindSsrc(int channel_num, uint32* ssrc);
363 void OnError(uint32 ssrc, int error);
364
365 bool sending() const { return send_ != SEND_NOTHING; }
366 int GetReceiveChannelNum(uint32 ssrc);
367 int GetSendChannelNum(uint32 ssrc);
368
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200369 void SetCall(webrtc::Call* call);
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200370
371 private:
372 WebRtcVoiceEngine* engine() { return engine_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373 int GetLastEngineError() { return engine()->GetLastEngineError(); }
374 int GetOutputLevel(int channel);
375 bool GetRedSendCodec(const AudioCodec& red_codec,
376 const std::vector<AudioCodec>& all_codecs,
377 webrtc::CodecInst* send_codec);
378 bool EnableRtcp(int channel);
379 bool ResetRecvCodecs(int channel);
380 bool SetPlayout(int channel, bool playout);
381 static uint32 ParseSsrc(const void* data, size_t len, bool rtcp);
382 static Error WebRtcErrorToChannelError(int err_code);
383
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +0000384 class WebRtcVoiceChannelRenderer;
385 // Map of ssrc to WebRtcVoiceChannelRenderer object. A new object of
386 // WebRtcVoiceChannelRenderer will be created for every new stream and
387 // will be destroyed when the stream goes away.
388 typedef std::map<uint32, WebRtcVoiceChannelRenderer*> ChannelMap;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000389 typedef int (webrtc::VoERTP_RTCP::* ExtensionSetterFunction)(int, bool,
390 unsigned char);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000391
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000392 void SetNack(int channel, bool nack_enabled);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000393 void SetNack(const ChannelMap& channels, bool nack_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394 bool SetSendCodec(const webrtc::CodecInst& send_codec);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000395 bool SetSendCodec(int channel, const webrtc::CodecInst& send_codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000396 bool ChangePlayout(bool playout);
397 bool ChangeSend(SendFlags send);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000398 bool ChangeSend(int channel, SendFlags send);
399 void ConfigureSendChannel(int channel);
wu@webrtc.org78187522013-10-07 23:32:02 +0000400 bool ConfigureRecvChannel(int channel);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000401 bool DeleteChannel(int channel);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000402 bool InConferenceMode() const {
403 return options_.conference_mode.GetWithDefaultIfUnset(false);
404 }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000405 bool IsDefaultChannel(int channel_id) const {
406 return channel_id == voe_channel();
407 }
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000408 bool SetSendCodecs(int channel, const std::vector<AudioCodec>& codecs);
minyue@webrtc.org26236952014-10-29 02:27:08 +0000409 bool SetSendBitrateInternal(int bps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000410
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000411 bool SetHeaderExtension(ExtensionSetterFunction setter, int channel_id,
412 const RtpHeaderExtension* extension);
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200413 void TryAddAudioRecvStream(uint32 ssrc);
414 void TryRemoveAudioRecvStream(uint32 ssrc);
415
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000416 bool SetChannelRecvRtpHeaderExtensions(
417 int channel_id,
418 const std::vector<RtpHeaderExtension>& extensions);
419 bool SetChannelSendRtpHeaderExtensions(
420 int channel_id,
421 const std::vector<RtpHeaderExtension>& extensions);
422
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200423 rtc::ThreadChecker thread_checker_;
424
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200425 WebRtcVoiceEngine* engine_;
426 const int voe_channel_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000427 rtc::scoped_ptr<WebRtcSoundclipStream> ringback_tone_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000428 std::set<int> ringback_channels_; // channels playing ringback
429 std::vector<AudioCodec> recv_codecs_;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000430 std::vector<AudioCodec> send_codecs_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000431 rtc::scoped_ptr<webrtc::CodecInst> send_codec_;
minyue@webrtc.org26236952014-10-29 02:27:08 +0000432 bool send_bitrate_setting_;
433 int send_bitrate_bps_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434 AudioOptions options_;
435 bool dtmf_allowed_;
436 bool desired_playout_;
437 bool nack_enabled_;
438 bool playout_;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000439 bool typing_noise_detected_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440 SendFlags desired_send_;
441 SendFlags send_;
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200442 webrtc::Call* call_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000444 // send_channels_ contains the channels which are being used for sending.
445 // When the default channel (voe_channel) is used for sending, it is
446 // contained in send_channels_, otherwise not.
447 ChannelMap send_channels_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000448 std::vector<RtpHeaderExtension> send_extensions_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449 uint32 default_receive_ssrc_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000450 // Note the default channel (voe_channel()) can reside in both
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000451 // receive_channels_ and send_channels_ in non-conference mode and in that
452 // case it will only be there if a non-zero default_receive_ssrc_ is set.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000453 ChannelMap receive_channels_; // for multiple sources
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200454 std::map<uint32, webrtc::AudioReceiveStream*> receive_streams_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000455 // receive_channels_ can be read from WebRtc callback thread. Access from
456 // the WebRtc thread must be synchronized with edits on the worker thread.
457 // Reads on the worker thread are ok.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458 //
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000459 std::vector<RtpHeaderExtension> receive_extensions_;
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200460 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
461
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462 // Do not lock this on the VoE media processor thread; potential for deadlock
463 // exists.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000464 mutable rtc::CriticalSection receive_channels_cs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465};
466
467} // namespace cricket
468
469#endif // TALK_MEDIA_WEBRTCVOICEENGINE_H_