blob: 4596c4db8f6a8c0d808c94a4f5e80e4ec0981df5 [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"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049
50#if !defined(LIBPEERCONNECTION_LIB) && \
51 !defined(LIBPEERCONNECTION_IMPLEMENTATION)
buildbot@webrtc.org6b21b712014-07-31 15:08:53 +000052// If you hit this, then you've tried to include this header from outside
53// the shared library. An instance of this class must only be created from
54// within the library that actually implements it. Otherwise use the
55// WebRtcMediaEngine to construct an instance.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056#error "Bogus include."
57#endif
58
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +000059namespace webrtc {
60class VideoEngine;
61}
62
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063namespace cricket {
64
65// WebRtcSoundclipStream is an adapter object that allows a memory stream to be
66// passed into WebRtc, and support looping.
67class WebRtcSoundclipStream : public webrtc::InStream {
68 public:
69 WebRtcSoundclipStream(const char* buf, size_t len)
70 : mem_(buf, len), loop_(true) {
71 }
72 void set_loop(bool loop) { loop_ = loop; }
xians@webrtc.org3cefbc92014-10-10 09:42:53 +000073
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000074 int Read(void* buf, size_t len) override;
75 int Rewind() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076
77 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000078 rtc::MemoryStream mem_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079 bool loop_;
80};
81
82// WebRtcMonitorStream is used to monitor a stream coming from WebRtc.
83// For now we just dump the data.
84class WebRtcMonitorStream : public webrtc::OutStream {
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000085 bool Write(const void* buf, size_t len) override { return true; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086};
87
88class AudioDeviceModule;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +000089class AudioRenderer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090class VoETraceWrapper;
91class VoEWrapper;
92class VoiceProcessor;
93class WebRtcSoundclipMedia;
94class 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.
105 WebRtcVoiceEngine(VoEWrapper* voe_wrapper,
106 VoEWrapper* voe_wrapper_sc,
107 VoETraceWrapper* tracing);
108 ~WebRtcVoiceEngine();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000109 bool Init(rtc::Thread* worker_thread);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110 void Terminate();
111
112 int GetCapabilities();
113 VoiceMediaChannel* CreateChannel();
114
115 SoundclipMedia* CreateSoundclip();
116
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000117 AudioOptions GetOptions() const { return options_; }
118 bool SetOptions(const AudioOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119 // Overrides, when set, take precedence over the options on a
120 // per-option basis. For example, if AGC is set in options and AEC
121 // is set in overrides, AGC and AEC will be both be set. Overrides
122 // can also turn off options. For example, if AGC is set to "on" in
123 // options and AGC is set to "off" in overrides, the result is that
124 // AGC will be off until different overrides are applied or until
125 // the overrides are cleared. Only one set of overrides is present
126 // at a time (they do not "stack"). And when the overrides are
127 // cleared, the media engine's state reverts back to the options set
128 // via SetOptions. This allows us to have both "persistent options"
129 // (the normal options) and "temporary options" (overrides).
130 bool SetOptionOverrides(const AudioOptions& options);
131 bool ClearOptionOverrides();
132 bool SetDelayOffset(int offset);
133 bool SetDevices(const Device* in_device, const Device* out_device);
134 bool GetOutputVolume(int* level);
135 bool SetOutputVolume(int level);
136 int GetInputLevel();
137 bool SetLocalMonitor(bool enable);
138
139 const std::vector<AudioCodec>& codecs();
140 bool FindCodec(const AudioCodec& codec);
141 bool FindWebRtcCodec(const AudioCodec& codec, webrtc::CodecInst* gcodec);
142
143 const std::vector<RtpHeaderExtension>& rtp_header_extensions() const;
144
145 void SetLogging(int min_sev, const char* filter);
146
147 bool RegisterProcessor(uint32 ssrc,
148 VoiceProcessor* voice_processor,
149 MediaProcessorDirection direction);
150 bool UnregisterProcessor(uint32 ssrc,
151 VoiceProcessor* voice_processor,
152 MediaProcessorDirection direction);
153
154 // Method from webrtc::VoEMediaProcess
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000155 void Process(int channel,
156 webrtc::ProcessingTypes type,
157 int16_t audio10ms[],
158 int length,
159 int sampling_freq,
160 bool is_stereo) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161
162 // For tracking WebRtc channels. Needed because we have to pause them
163 // all when switching devices.
164 // May only be called by WebRtcVoiceMediaChannel.
165 void RegisterChannel(WebRtcVoiceMediaChannel *channel);
166 void UnregisterChannel(WebRtcVoiceMediaChannel *channel);
167
168 // May only be called by WebRtcSoundclipMedia.
169 void RegisterSoundclip(WebRtcSoundclipMedia *channel);
170 void UnregisterSoundclip(WebRtcSoundclipMedia *channel);
171
172 // Called by WebRtcVoiceMediaChannel to set a gain offset from
173 // the default AGC target level.
174 bool AdjustAgcLevel(int delta);
175
176 VoEWrapper* voe() { return voe_wrapper_.get(); }
177 VoEWrapper* voe_sc() { return voe_wrapper_sc_.get(); }
178 int GetLastEngineError();
179
180 // Set the external ADMs. This can only be called before Init.
181 bool SetAudioDeviceModule(webrtc::AudioDeviceModule* adm,
182 webrtc::AudioDeviceModule* adm_sc);
183
wu@webrtc.orga9890802013-12-13 00:21:03 +0000184 // Starts AEC dump using existing file.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000185 bool StartAecDump(rtc::PlatformFile file);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000186
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 // Check whether the supplied trace should be ignored.
188 bool ShouldIgnoreTrace(const std::string& trace);
189
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000190 // Create a VoiceEngine Channel.
191 int CreateMediaVoiceChannel();
192 int CreateSoundclipVoiceChannel();
193
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 private:
195 typedef std::vector<WebRtcSoundclipMedia *> SoundclipList;
196 typedef std::vector<WebRtcVoiceMediaChannel *> ChannelList;
197 typedef sigslot::
198 signal3<uint32, MediaProcessorDirection, AudioFrame*> FrameSignal;
199
200 void Construct();
201 void ConstructCodecs();
henrik.lundin@webrtc.org8038d422014-11-11 08:38:24 +0000202 bool GetVoeCodec(int index, webrtc::CodecInst* codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 bool InitInternal();
wu@webrtc.org4551b792013-10-09 15:37:36 +0000204 bool EnsureSoundclipEngineInit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 void SetTraceFilter(int filter);
206 void SetTraceOptions(const std::string& options);
207 // Applies either options or overrides. Every option that is "set"
208 // will be applied. Every option not "set" will be ignored. This
209 // allows us to selectively turn on and off different options easily
210 // at any time.
211 bool ApplyOptions(const AudioOptions& options);
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000212
213 // webrtc::TraceCallback:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000214 void Print(webrtc::TraceLevel level, const char* trace, int length) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000215
216 // webrtc::VoiceEngineObserver:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000217 void CallbackOnError(int channel, int errCode) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000218
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 // Given the device type, name, and id, find device id. Return true and
220 // set the output parameter rtc_id if successful.
221 bool FindWebRtcAudioDeviceId(
222 bool is_input, const std::string& dev_name, int dev_id, int* rtc_id);
223 bool FindChannelAndSsrc(int channel_num,
224 WebRtcVoiceMediaChannel** channel,
225 uint32* ssrc) const;
226 bool FindChannelNumFromSsrc(uint32 ssrc,
227 MediaProcessorDirection direction,
228 int* channel_num);
229 bool ChangeLocalMonitor(bool enable);
230 bool PauseLocalMonitor();
231 bool ResumeLocalMonitor();
232
233 bool UnregisterProcessorChannel(MediaProcessorDirection channel_direction,
234 uint32 ssrc,
235 VoiceProcessor* voice_processor,
236 MediaProcessorDirection processor_direction);
237
238 void StartAecDump(const std::string& filename);
239 void StopAecDump();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000240 int CreateVoiceChannel(VoEWrapper* voe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241
242 // When a voice processor registers with the engine, it is connected
243 // to either the Rx or Tx signals, based on the direction parameter.
244 // SignalXXMediaFrame will be invoked for every audio packet.
245 FrameSignal SignalRxMediaFrame;
246 FrameSignal SignalTxMediaFrame;
247
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000248 static const int kDefaultLogSeverity = rtc::LS_WARNING;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249
250 // The primary instance of WebRtc VoiceEngine.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000251 rtc::scoped_ptr<VoEWrapper> voe_wrapper_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 // A secondary instance, for playing out soundclips (on the 'ring' device).
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000253 rtc::scoped_ptr<VoEWrapper> voe_wrapper_sc_;
wu@webrtc.org4551b792013-10-09 15:37:36 +0000254 bool voe_wrapper_sc_initialized_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000255 rtc::scoped_ptr<VoETraceWrapper> tracing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 // The external audio device manager
257 webrtc::AudioDeviceModule* adm_;
258 webrtc::AudioDeviceModule* adm_sc_;
259 int log_filter_;
260 std::string log_options_;
261 bool is_dumping_aec_;
262 std::vector<AudioCodec> codecs_;
263 std::vector<RtpHeaderExtension> rtp_header_extensions_;
264 bool desired_local_monitor_enable_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000265 rtc::scoped_ptr<WebRtcMonitorStream> monitor_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000266 SoundclipList soundclips_;
267 ChannelList channels_;
268 // channels_ can be read from WebRtc callback thread. We need a lock on that
269 // callback as well as the RegisterChannel/UnregisterChannel.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000270 rtc::CriticalSection channels_cs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 webrtc::AgcConfig default_agc_config_;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000272
273 webrtc::Config voe_config_;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000274
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275 bool initialized_;
276 // See SetOptions and SetOptionOverrides for a description of the
277 // difference between options and overrides.
278 // options_ are the base options, which combined with the
279 // option_overrides_, create the current options being used.
280 // options_ is stored so that when option_overrides_ is cleared, we
281 // can restore the options_ without the option_overrides.
282 AudioOptions options_;
283 AudioOptions option_overrides_;
284
285 // When the media processor registers with the engine, the ssrc is cached
286 // here so that a look up need not be made when the callback is invoked.
287 // This is necessary because the lookup results in mux_channels_cs lock being
288 // held and if a remote participant leaves the hangout at the same time
289 // we hit a deadlock.
290 uint32 tx_processor_ssrc_;
291 uint32 rx_processor_ssrc_;
292
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000293 rtc::CriticalSection signal_media_critical_;
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000294
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100295 // Cache received experimental_aec, delay_agnostic_aec and experimental_ns
296 // values, and apply them in case they are missing in the audio options. We
297 // need to do this because SetExtraOptions() will revert to defaults for
298 // options which are not provided.
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000299 Settable<bool> experimental_aec_;
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100300 Settable<bool> delay_agnostic_aec_;
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000301 Settable<bool> experimental_ns_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302};
303
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304// WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses
305// WebRtc Voice Engine.
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200306class WebRtcVoiceMediaChannel : public VoiceMediaChannel,
307 public webrtc::Transport {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 public:
309 explicit WebRtcVoiceMediaChannel(WebRtcVoiceEngine *engine);
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200310 ~WebRtcVoiceMediaChannel() override;
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200311
312 int voe_channel() const { return voe_channel_; }
313 bool valid() const { return voe_channel_ != -1; }
314
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200315 bool SetOptions(const AudioOptions& options) override;
316 bool GetOptions(AudioOptions* options) const override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 *options = options_;
318 return true;
319 }
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200320 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) override;
321 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) override;
322 bool SetRecvRtpHeaderExtensions(
323 const std::vector<RtpHeaderExtension>& extensions) override;
324 bool SetSendRtpHeaderExtensions(
325 const std::vector<RtpHeaderExtension>& extensions) override;
326 bool SetPlayout(bool playout) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 bool PausePlayout();
328 bool ResumePlayout();
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200329 bool SetSend(SendFlags send) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 bool PauseSend();
331 bool ResumeSend();
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200332 bool AddSendStream(const StreamParams& sp) override;
333 bool RemoveSendStream(uint32 ssrc) override;
334 bool AddRecvStream(const StreamParams& sp) override;
335 bool RemoveRecvStream(uint32 ssrc) override;
336 bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) override;
337 bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) override;
338 bool GetActiveStreams(AudioInfo::StreamList* actives) override;
339 int GetOutputLevel() override;
340 int GetTimeSinceLastTyping() override;
341 void SetTypingDetectionParameters(int time_window,
342 int cost_per_typing,
343 int reporting_threshold,
344 int penalty_decay,
345 int type_event_delay) override;
346 bool SetOutputScaling(uint32 ssrc, double left, double right) override;
347 bool GetOutputScaling(uint32 ssrc, double* left, double* right) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200349 bool SetRingbackTone(const char* buf, int len) override;
350 bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) override;
351 bool CanInsertDtmf() override;
352 bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200354 void OnPacketReceived(rtc::Buffer* packet,
355 const rtc::PacketTime& packet_time) override;
356 void OnRtcpReceived(rtc::Buffer* packet,
357 const rtc::PacketTime& packet_time) override;
358 void OnReadyToSend(bool ready) override {}
359 bool MuteStream(uint32 ssrc, bool on) override;
360 bool SetMaxSendBandwidth(int bps) override;
361 bool GetStats(VoiceMediaInfo* info) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 // Gets last reported error from WebRtc voice engine. This should be only
363 // called in response a failure.
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200364 void GetLastMediaError(uint32* ssrc,
365 VoiceMediaChannel::Error* error) override;
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200366
367 // implements Transport interface
368 int SendPacket(int channel, const void* data, size_t len) override {
369 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len,
370 kMaxRtpPacketLen);
371 return VoiceMediaChannel::SendPacket(&packet) ? static_cast<int>(len) : -1;
372 }
373
374 int SendRTCPPacket(int channel, const void* data, size_t len) override {
375 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len,
376 kMaxRtpPacketLen);
377 return VoiceMediaChannel::SendRtcp(&packet) ? static_cast<int>(len) : -1;
378 }
379
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 bool FindSsrc(int channel_num, uint32* ssrc);
381 void OnError(uint32 ssrc, int error);
382
383 bool sending() const { return send_ != SEND_NOTHING; }
384 int GetReceiveChannelNum(uint32 ssrc);
385 int GetSendChannelNum(uint32 ssrc);
386
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200387 void SetCall(webrtc::Call* call);
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200388
389 private:
390 WebRtcVoiceEngine* engine() { return engine_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000391 int GetLastEngineError() { return engine()->GetLastEngineError(); }
392 int GetOutputLevel(int channel);
393 bool GetRedSendCodec(const AudioCodec& red_codec,
394 const std::vector<AudioCodec>& all_codecs,
395 webrtc::CodecInst* send_codec);
396 bool EnableRtcp(int channel);
397 bool ResetRecvCodecs(int channel);
398 bool SetPlayout(int channel, bool playout);
399 static uint32 ParseSsrc(const void* data, size_t len, bool rtcp);
400 static Error WebRtcErrorToChannelError(int err_code);
401
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +0000402 class WebRtcVoiceChannelRenderer;
403 // Map of ssrc to WebRtcVoiceChannelRenderer object. A new object of
404 // WebRtcVoiceChannelRenderer will be created for every new stream and
405 // will be destroyed when the stream goes away.
406 typedef std::map<uint32, WebRtcVoiceChannelRenderer*> ChannelMap;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000407 typedef int (webrtc::VoERTP_RTCP::* ExtensionSetterFunction)(int, bool,
408 unsigned char);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000409
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000410 void SetNack(int channel, bool nack_enabled);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000411 void SetNack(const ChannelMap& channels, bool nack_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412 bool SetSendCodec(const webrtc::CodecInst& send_codec);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000413 bool SetSendCodec(int channel, const webrtc::CodecInst& send_codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414 bool ChangePlayout(bool playout);
415 bool ChangeSend(SendFlags send);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000416 bool ChangeSend(int channel, SendFlags send);
417 void ConfigureSendChannel(int channel);
wu@webrtc.org78187522013-10-07 23:32:02 +0000418 bool ConfigureRecvChannel(int channel);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000419 bool DeleteChannel(int channel);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000420 bool InConferenceMode() const {
421 return options_.conference_mode.GetWithDefaultIfUnset(false);
422 }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000423 bool IsDefaultChannel(int channel_id) const {
424 return channel_id == voe_channel();
425 }
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000426 bool SetSendCodecs(int channel, const std::vector<AudioCodec>& codecs);
minyue@webrtc.org26236952014-10-29 02:27:08 +0000427 bool SetSendBitrateInternal(int bps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000428
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000429 bool SetHeaderExtension(ExtensionSetterFunction setter, int channel_id,
430 const RtpHeaderExtension* extension);
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200431 void TryAddAudioRecvStream(uint32 ssrc);
432 void TryRemoveAudioRecvStream(uint32 ssrc);
433
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000434 bool SetChannelRecvRtpHeaderExtensions(
435 int channel_id,
436 const std::vector<RtpHeaderExtension>& extensions);
437 bool SetChannelSendRtpHeaderExtensions(
438 int channel_id,
439 const std::vector<RtpHeaderExtension>& extensions);
440
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200441 rtc::ThreadChecker thread_checker_;
442
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200443 WebRtcVoiceEngine* engine_;
444 const int voe_channel_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000445 rtc::scoped_ptr<WebRtcSoundclipStream> ringback_tone_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446 std::set<int> ringback_channels_; // channels playing ringback
447 std::vector<AudioCodec> recv_codecs_;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000448 std::vector<AudioCodec> send_codecs_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000449 rtc::scoped_ptr<webrtc::CodecInst> send_codec_;
minyue@webrtc.org26236952014-10-29 02:27:08 +0000450 bool send_bitrate_setting_;
451 int send_bitrate_bps_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452 AudioOptions options_;
453 bool dtmf_allowed_;
454 bool desired_playout_;
455 bool nack_enabled_;
456 bool playout_;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000457 bool typing_noise_detected_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458 SendFlags desired_send_;
459 SendFlags send_;
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200460 webrtc::Call* call_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000462 // send_channels_ contains the channels which are being used for sending.
463 // When the default channel (voe_channel) is used for sending, it is
464 // contained in send_channels_, otherwise not.
465 ChannelMap send_channels_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000466 std::vector<RtpHeaderExtension> send_extensions_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000467 uint32 default_receive_ssrc_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000468 // Note the default channel (voe_channel()) can reside in both
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000469 // receive_channels_ and send_channels_ in non-conference mode and in that
470 // case it will only be there if a non-zero default_receive_ssrc_ is set.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000471 ChannelMap receive_channels_; // for multiple sources
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200472 std::map<uint32, webrtc::AudioReceiveStream*> receive_streams_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000473 // receive_channels_ can be read from WebRtc callback thread. Access from
474 // the WebRtc thread must be synchronized with edits on the worker thread.
475 // Reads on the worker thread are ok.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000476 //
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000477 std::vector<RtpHeaderExtension> receive_extensions_;
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200478 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
479
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480 // Do not lock this on the VoE media processor thread; potential for deadlock
481 // exists.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000482 mutable rtc::CriticalSection receive_channels_cs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483};
484
485} // namespace cricket
486
487#endif // TALK_MEDIA_WEBRTCVOICEENGINE_H_