blob: 242467dd990ddb6e0ad46b30baff8b773adfacdf [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;
94class WebRtcSoundclipMedia;
95class WebRtcVoiceMediaChannel;
96
97// WebRtcVoiceEngine is a class to be used with CompositeMediaEngine.
98// It uses the WebRtc VoiceEngine library for audio handling.
99class WebRtcVoiceEngine
100 : public webrtc::VoiceEngineObserver,
101 public webrtc::TraceCallback,
102 public webrtc::VoEMediaProcess {
103 public:
104 WebRtcVoiceEngine();
105 // Dependency injection for testing.
106 WebRtcVoiceEngine(VoEWrapper* voe_wrapper,
107 VoEWrapper* voe_wrapper_sc,
108 VoETraceWrapper* tracing);
109 ~WebRtcVoiceEngine();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000110 bool Init(rtc::Thread* worker_thread);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111 void Terminate();
112
113 int GetCapabilities();
114 VoiceMediaChannel* CreateChannel();
115
116 SoundclipMedia* CreateSoundclip();
117
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000118 AudioOptions GetOptions() const { return options_; }
119 bool SetOptions(const AudioOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120 // Overrides, when set, take precedence over the options on a
121 // per-option basis. For example, if AGC is set in options and AEC
122 // is set in overrides, AGC and AEC will be both be set. Overrides
123 // can also turn off options. For example, if AGC is set to "on" in
124 // options and AGC is set to "off" in overrides, the result is that
125 // AGC will be off until different overrides are applied or until
126 // the overrides are cleared. Only one set of overrides is present
127 // at a time (they do not "stack"). And when the overrides are
128 // cleared, the media engine's state reverts back to the options set
129 // via SetOptions. This allows us to have both "persistent options"
130 // (the normal options) and "temporary options" (overrides).
131 bool SetOptionOverrides(const AudioOptions& options);
132 bool ClearOptionOverrides();
133 bool SetDelayOffset(int offset);
134 bool SetDevices(const Device* in_device, const Device* out_device);
135 bool GetOutputVolume(int* level);
136 bool SetOutputVolume(int level);
137 int GetInputLevel();
138 bool SetLocalMonitor(bool enable);
139
140 const std::vector<AudioCodec>& codecs();
141 bool FindCodec(const AudioCodec& codec);
142 bool FindWebRtcCodec(const AudioCodec& codec, webrtc::CodecInst* gcodec);
143
144 const std::vector<RtpHeaderExtension>& rtp_header_extensions() const;
145
146 void SetLogging(int min_sev, const char* filter);
147
148 bool RegisterProcessor(uint32 ssrc,
149 VoiceProcessor* voice_processor,
150 MediaProcessorDirection direction);
151 bool UnregisterProcessor(uint32 ssrc,
152 VoiceProcessor* voice_processor,
153 MediaProcessorDirection direction);
154
155 // Method from webrtc::VoEMediaProcess
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000156 void Process(int channel,
157 webrtc::ProcessingTypes type,
158 int16_t audio10ms[],
159 int length,
160 int sampling_freq,
161 bool is_stereo) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162
163 // For tracking WebRtc channels. Needed because we have to pause them
164 // all when switching devices.
165 // May only be called by WebRtcVoiceMediaChannel.
166 void RegisterChannel(WebRtcVoiceMediaChannel *channel);
167 void UnregisterChannel(WebRtcVoiceMediaChannel *channel);
168
169 // May only be called by WebRtcSoundclipMedia.
170 void RegisterSoundclip(WebRtcSoundclipMedia *channel);
171 void UnregisterSoundclip(WebRtcSoundclipMedia *channel);
172
173 // Called by WebRtcVoiceMediaChannel to set a gain offset from
174 // the default AGC target level.
175 bool AdjustAgcLevel(int delta);
176
177 VoEWrapper* voe() { return voe_wrapper_.get(); }
178 VoEWrapper* voe_sc() { return voe_wrapper_sc_.get(); }
179 int GetLastEngineError();
180
181 // Set the external ADMs. This can only be called before Init.
182 bool SetAudioDeviceModule(webrtc::AudioDeviceModule* adm,
183 webrtc::AudioDeviceModule* adm_sc);
184
wu@webrtc.orga9890802013-12-13 00:21:03 +0000185 // Starts AEC dump using existing file.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000186 bool StartAecDump(rtc::PlatformFile file);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000187
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 // Check whether the supplied trace should be ignored.
189 bool ShouldIgnoreTrace(const std::string& trace);
190
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000191 // Create a VoiceEngine Channel.
192 int CreateMediaVoiceChannel();
193 int CreateSoundclipVoiceChannel();
194
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195 private:
196 typedef std::vector<WebRtcSoundclipMedia *> SoundclipList;
197 typedef std::vector<WebRtcVoiceMediaChannel *> ChannelList;
198 typedef sigslot::
199 signal3<uint32, MediaProcessorDirection, AudioFrame*> FrameSignal;
200
201 void Construct();
202 void ConstructCodecs();
henrik.lundin@webrtc.org8038d422014-11-11 08:38:24 +0000203 bool GetVoeCodec(int index, webrtc::CodecInst* codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204 bool InitInternal();
wu@webrtc.org4551b792013-10-09 15:37:36 +0000205 bool EnsureSoundclipEngineInit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 void SetTraceFilter(int filter);
207 void SetTraceOptions(const std::string& options);
208 // Applies either options or overrides. Every option that is "set"
209 // will be applied. Every option not "set" will be ignored. This
210 // allows us to selectively turn on and off different options easily
211 // at any time.
212 bool ApplyOptions(const AudioOptions& options);
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000213
214 // webrtc::TraceCallback:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000215 void Print(webrtc::TraceLevel level, const char* trace, int length) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000216
217 // webrtc::VoiceEngineObserver:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000218 void CallbackOnError(int channel, int errCode) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000219
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220 // Given the device type, name, and id, find device id. Return true and
221 // set the output parameter rtc_id if successful.
222 bool FindWebRtcAudioDeviceId(
223 bool is_input, const std::string& dev_name, int dev_id, int* rtc_id);
224 bool FindChannelAndSsrc(int channel_num,
225 WebRtcVoiceMediaChannel** channel,
226 uint32* ssrc) const;
227 bool FindChannelNumFromSsrc(uint32 ssrc,
228 MediaProcessorDirection direction,
229 int* channel_num);
230 bool ChangeLocalMonitor(bool enable);
231 bool PauseLocalMonitor();
232 bool ResumeLocalMonitor();
233
234 bool UnregisterProcessorChannel(MediaProcessorDirection channel_direction,
235 uint32 ssrc,
236 VoiceProcessor* voice_processor,
237 MediaProcessorDirection processor_direction);
238
239 void StartAecDump(const std::string& filename);
240 void StopAecDump();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000241 int CreateVoiceChannel(VoEWrapper* voe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242
243 // When a voice processor registers with the engine, it is connected
244 // to either the Rx or Tx signals, based on the direction parameter.
245 // SignalXXMediaFrame will be invoked for every audio packet.
246 FrameSignal SignalRxMediaFrame;
247 FrameSignal SignalTxMediaFrame;
248
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000249 static const int kDefaultLogSeverity = rtc::LS_WARNING;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250
251 // The primary instance of WebRtc VoiceEngine.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000252 rtc::scoped_ptr<VoEWrapper> voe_wrapper_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 // A secondary instance, for playing out soundclips (on the 'ring' device).
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000254 rtc::scoped_ptr<VoEWrapper> voe_wrapper_sc_;
wu@webrtc.org4551b792013-10-09 15:37:36 +0000255 bool voe_wrapper_sc_initialized_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000256 rtc::scoped_ptr<VoETraceWrapper> tracing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 // The external audio device manager
258 webrtc::AudioDeviceModule* adm_;
259 webrtc::AudioDeviceModule* adm_sc_;
260 int log_filter_;
261 std::string log_options_;
262 bool is_dumping_aec_;
263 std::vector<AudioCodec> codecs_;
264 std::vector<RtpHeaderExtension> rtp_header_extensions_;
265 bool desired_local_monitor_enable_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000266 rtc::scoped_ptr<WebRtcMonitorStream> monitor_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267 SoundclipList soundclips_;
268 ChannelList channels_;
269 // channels_ can be read from WebRtc callback thread. We need a lock on that
270 // callback as well as the RegisterChannel/UnregisterChannel.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000271 rtc::CriticalSection channels_cs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 webrtc::AgcConfig default_agc_config_;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000273
274 webrtc::Config voe_config_;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000275
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000276 bool initialized_;
277 // See SetOptions and SetOptionOverrides for a description of the
278 // difference between options and overrides.
279 // options_ are the base options, which combined with the
280 // option_overrides_, create the current options being used.
281 // options_ is stored so that when option_overrides_ is cleared, we
282 // can restore the options_ without the option_overrides.
283 AudioOptions options_;
284 AudioOptions option_overrides_;
285
286 // When the media processor registers with the engine, the ssrc is cached
287 // here so that a look up need not be made when the callback is invoked.
288 // This is necessary because the lookup results in mux_channels_cs lock being
289 // held and if a remote participant leaves the hangout at the same time
290 // we hit a deadlock.
291 uint32 tx_processor_ssrc_;
292 uint32 rx_processor_ssrc_;
293
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000294 rtc::CriticalSection signal_media_critical_;
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000295
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100296 // Cache received experimental_aec, delay_agnostic_aec and experimental_ns
297 // values, and apply them in case they are missing in the audio options. We
298 // need to do this because SetExtraOptions() will revert to defaults for
299 // options which are not provided.
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000300 Settable<bool> experimental_aec_;
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100301 Settable<bool> delay_agnostic_aec_;
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000302 Settable<bool> experimental_ns_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303};
304
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305// WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses
306// WebRtc Voice Engine.
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200307class WebRtcVoiceMediaChannel : public VoiceMediaChannel,
308 public webrtc::Transport {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 public:
310 explicit WebRtcVoiceMediaChannel(WebRtcVoiceEngine *engine);
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200311 ~WebRtcVoiceMediaChannel() override;
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200312
313 int voe_channel() const { return voe_channel_; }
314 bool valid() const { return voe_channel_ != -1; }
315
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200316 bool SetOptions(const AudioOptions& options) override;
317 bool GetOptions(AudioOptions* options) const override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318 *options = options_;
319 return true;
320 }
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200321 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) override;
322 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) override;
323 bool SetRecvRtpHeaderExtensions(
324 const std::vector<RtpHeaderExtension>& extensions) override;
325 bool SetSendRtpHeaderExtensions(
326 const std::vector<RtpHeaderExtension>& extensions) override;
327 bool SetPlayout(bool playout) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328 bool PausePlayout();
329 bool ResumePlayout();
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200330 bool SetSend(SendFlags send) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 bool PauseSend();
332 bool ResumeSend();
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200333 bool AddSendStream(const StreamParams& sp) override;
334 bool RemoveSendStream(uint32 ssrc) override;
335 bool AddRecvStream(const StreamParams& sp) override;
336 bool RemoveRecvStream(uint32 ssrc) override;
337 bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) override;
338 bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) override;
339 bool GetActiveStreams(AudioInfo::StreamList* actives) override;
340 int GetOutputLevel() override;
341 int GetTimeSinceLastTyping() override;
342 void SetTypingDetectionParameters(int time_window,
343 int cost_per_typing,
344 int reporting_threshold,
345 int penalty_decay,
346 int type_event_delay) override;
347 bool SetOutputScaling(uint32 ssrc, double left, double right) override;
348 bool GetOutputScaling(uint32 ssrc, double* left, double* right) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200350 bool SetRingbackTone(const char* buf, int len) override;
351 bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) override;
352 bool CanInsertDtmf() override;
353 bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200355 void OnPacketReceived(rtc::Buffer* packet,
356 const rtc::PacketTime& packet_time) override;
357 void OnRtcpReceived(rtc::Buffer* packet,
358 const rtc::PacketTime& packet_time) override;
359 void OnReadyToSend(bool ready) override {}
360 bool MuteStream(uint32 ssrc, bool on) override;
361 bool SetMaxSendBandwidth(int bps) override;
362 bool GetStats(VoiceMediaInfo* info) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 // Gets last reported error from WebRtc voice engine. This should be only
364 // called in response a failure.
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200365 void GetLastMediaError(uint32* ssrc,
366 VoiceMediaChannel::Error* error) override;
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200367
368 // implements Transport interface
369 int SendPacket(int channel, const void* data, size_t len) override {
370 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len,
371 kMaxRtpPacketLen);
372 return VoiceMediaChannel::SendPacket(&packet) ? static_cast<int>(len) : -1;
373 }
374
375 int SendRTCPPacket(int channel, const void* data, size_t len) override {
376 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len,
377 kMaxRtpPacketLen);
378 return VoiceMediaChannel::SendRtcp(&packet) ? static_cast<int>(len) : -1;
379 }
380
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381 bool FindSsrc(int channel_num, uint32* ssrc);
382 void OnError(uint32 ssrc, int error);
383
384 bool sending() const { return send_ != SEND_NOTHING; }
385 int GetReceiveChannelNum(uint32 ssrc);
386 int GetSendChannelNum(uint32 ssrc);
387
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200388 void SetCall(webrtc::Call* call);
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200389
390 private:
391 WebRtcVoiceEngine* engine() { return engine_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392 int GetLastEngineError() { return engine()->GetLastEngineError(); }
393 int GetOutputLevel(int channel);
394 bool GetRedSendCodec(const AudioCodec& red_codec,
395 const std::vector<AudioCodec>& all_codecs,
396 webrtc::CodecInst* send_codec);
397 bool EnableRtcp(int channel);
398 bool ResetRecvCodecs(int channel);
399 bool SetPlayout(int channel, bool playout);
400 static uint32 ParseSsrc(const void* data, size_t len, bool rtcp);
401 static Error WebRtcErrorToChannelError(int err_code);
402
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +0000403 class WebRtcVoiceChannelRenderer;
404 // Map of ssrc to WebRtcVoiceChannelRenderer object. A new object of
405 // WebRtcVoiceChannelRenderer will be created for every new stream and
406 // will be destroyed when the stream goes away.
407 typedef std::map<uint32, WebRtcVoiceChannelRenderer*> ChannelMap;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000408 typedef int (webrtc::VoERTP_RTCP::* ExtensionSetterFunction)(int, bool,
409 unsigned char);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000410
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000411 void SetNack(int channel, bool nack_enabled);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000412 void SetNack(const ChannelMap& channels, bool nack_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000413 bool SetSendCodec(const webrtc::CodecInst& send_codec);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000414 bool SetSendCodec(int channel, const webrtc::CodecInst& send_codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415 bool ChangePlayout(bool playout);
416 bool ChangeSend(SendFlags send);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000417 bool ChangeSend(int channel, SendFlags send);
418 void ConfigureSendChannel(int channel);
wu@webrtc.org78187522013-10-07 23:32:02 +0000419 bool ConfigureRecvChannel(int channel);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000420 bool DeleteChannel(int channel);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000421 bool InConferenceMode() const {
422 return options_.conference_mode.GetWithDefaultIfUnset(false);
423 }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000424 bool IsDefaultChannel(int channel_id) const {
425 return channel_id == voe_channel();
426 }
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000427 bool SetSendCodecs(int channel, const std::vector<AudioCodec>& codecs);
minyue@webrtc.org26236952014-10-29 02:27:08 +0000428 bool SetSendBitrateInternal(int bps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000429
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000430 bool SetHeaderExtension(ExtensionSetterFunction setter, int channel_id,
431 const RtpHeaderExtension* extension);
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200432 void TryAddAudioRecvStream(uint32 ssrc);
433 void TryRemoveAudioRecvStream(uint32 ssrc);
434
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000435 bool SetChannelRecvRtpHeaderExtensions(
436 int channel_id,
437 const std::vector<RtpHeaderExtension>& extensions);
438 bool SetChannelSendRtpHeaderExtensions(
439 int channel_id,
440 const std::vector<RtpHeaderExtension>& extensions);
441
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200442 rtc::ThreadChecker thread_checker_;
443
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200444 WebRtcVoiceEngine* engine_;
445 const int voe_channel_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000446 rtc::scoped_ptr<WebRtcSoundclipStream> ringback_tone_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447 std::set<int> ringback_channels_; // channels playing ringback
448 std::vector<AudioCodec> recv_codecs_;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000449 std::vector<AudioCodec> send_codecs_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000450 rtc::scoped_ptr<webrtc::CodecInst> send_codec_;
minyue@webrtc.org26236952014-10-29 02:27:08 +0000451 bool send_bitrate_setting_;
452 int send_bitrate_bps_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453 AudioOptions options_;
454 bool dtmf_allowed_;
455 bool desired_playout_;
456 bool nack_enabled_;
457 bool playout_;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000458 bool typing_noise_detected_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459 SendFlags desired_send_;
460 SendFlags send_;
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200461 webrtc::Call* call_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000463 // send_channels_ contains the channels which are being used for sending.
464 // When the default channel (voe_channel) is used for sending, it is
465 // contained in send_channels_, otherwise not.
466 ChannelMap send_channels_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000467 std::vector<RtpHeaderExtension> send_extensions_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468 uint32 default_receive_ssrc_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000469 // Note the default channel (voe_channel()) can reside in both
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000470 // receive_channels_ and send_channels_ in non-conference mode and in that
471 // case it will only be there if a non-zero default_receive_ssrc_ is set.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000472 ChannelMap receive_channels_; // for multiple sources
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200473 std::map<uint32, webrtc::AudioReceiveStream*> receive_streams_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000474 // receive_channels_ can be read from WebRtc callback thread. Access from
475 // the WebRtc thread must be synchronized with edits on the worker thread.
476 // Reads on the worker thread are ok.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000477 //
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000478 std::vector<RtpHeaderExtension> receive_extensions_;
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200479 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
480
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000481 // Do not lock this on the VoE media processor thread; potential for deadlock
482 // exists.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000483 mutable rtc::CriticalSection receive_channels_cs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484};
485
486} // namespace cricket
487
488#endif // TALK_MEDIA_WEBRTCVOICEENGINE_H_