blob: 56665de7ba2fad4893e294278cc61aac58251f0c [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"
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +000046#include "webrtc/common.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
48#if !defined(LIBPEERCONNECTION_LIB) && \
49 !defined(LIBPEERCONNECTION_IMPLEMENTATION)
buildbot@webrtc.org6b21b712014-07-31 15:08:53 +000050// If you hit this, then you've tried to include this header from outside
51// the shared library. An instance of this class must only be created from
52// within the library that actually implements it. Otherwise use the
53// WebRtcMediaEngine to construct an instance.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054#error "Bogus include."
55#endif
56
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +000057namespace webrtc {
58class VideoEngine;
59}
60
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061namespace cricket {
62
63// WebRtcSoundclipStream is an adapter object that allows a memory stream to be
64// passed into WebRtc, and support looping.
65class WebRtcSoundclipStream : public webrtc::InStream {
66 public:
67 WebRtcSoundclipStream(const char* buf, size_t len)
68 : mem_(buf, len), loop_(true) {
69 }
70 void set_loop(bool loop) { loop_ = loop; }
xians@webrtc.org3cefbc92014-10-10 09:42:53 +000071
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000072 int Read(void* buf, size_t len) override;
73 int Rewind() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074
75 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000076 rtc::MemoryStream mem_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077 bool loop_;
78};
79
80// WebRtcMonitorStream is used to monitor a stream coming from WebRtc.
81// For now we just dump the data.
82class WebRtcMonitorStream : public webrtc::OutStream {
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000083 bool Write(const void* buf, size_t len) override { return true; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084};
85
86class AudioDeviceModule;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +000087class AudioRenderer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088class VoETraceWrapper;
89class VoEWrapper;
90class VoiceProcessor;
91class WebRtcSoundclipMedia;
92class WebRtcVoiceMediaChannel;
93
94// WebRtcVoiceEngine is a class to be used with CompositeMediaEngine.
95// It uses the WebRtc VoiceEngine library for audio handling.
96class WebRtcVoiceEngine
97 : public webrtc::VoiceEngineObserver,
98 public webrtc::TraceCallback,
99 public webrtc::VoEMediaProcess {
100 public:
101 WebRtcVoiceEngine();
102 // Dependency injection for testing.
103 WebRtcVoiceEngine(VoEWrapper* voe_wrapper,
104 VoEWrapper* voe_wrapper_sc,
105 VoETraceWrapper* tracing);
106 ~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
113 SoundclipMedia* CreateSoundclip();
114
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000115 AudioOptions GetOptions() const { return options_; }
116 bool SetOptions(const AudioOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117 // Overrides, when set, take precedence over the options on a
118 // per-option basis. For example, if AGC is set in options and AEC
119 // is set in overrides, AGC and AEC will be both be set. Overrides
120 // can also turn off options. For example, if AGC is set to "on" in
121 // options and AGC is set to "off" in overrides, the result is that
122 // AGC will be off until different overrides are applied or until
123 // the overrides are cleared. Only one set of overrides is present
124 // at a time (they do not "stack"). And when the overrides are
125 // cleared, the media engine's state reverts back to the options set
126 // via SetOptions. This allows us to have both "persistent options"
127 // (the normal options) and "temporary options" (overrides).
128 bool SetOptionOverrides(const AudioOptions& options);
129 bool ClearOptionOverrides();
130 bool SetDelayOffset(int offset);
131 bool SetDevices(const Device* in_device, const Device* out_device);
132 bool GetOutputVolume(int* level);
133 bool SetOutputVolume(int level);
134 int GetInputLevel();
135 bool SetLocalMonitor(bool enable);
136
137 const std::vector<AudioCodec>& codecs();
138 bool FindCodec(const AudioCodec& codec);
139 bool FindWebRtcCodec(const AudioCodec& codec, webrtc::CodecInst* gcodec);
140
141 const std::vector<RtpHeaderExtension>& rtp_header_extensions() const;
142
143 void SetLogging(int min_sev, const char* filter);
144
145 bool RegisterProcessor(uint32 ssrc,
146 VoiceProcessor* voice_processor,
147 MediaProcessorDirection direction);
148 bool UnregisterProcessor(uint32 ssrc,
149 VoiceProcessor* voice_processor,
150 MediaProcessorDirection direction);
151
152 // Method from webrtc::VoEMediaProcess
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000153 void Process(int channel,
154 webrtc::ProcessingTypes type,
155 int16_t audio10ms[],
156 int length,
157 int sampling_freq,
158 bool is_stereo) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159
160 // For tracking WebRtc channels. Needed because we have to pause them
161 // all when switching devices.
162 // May only be called by WebRtcVoiceMediaChannel.
163 void RegisterChannel(WebRtcVoiceMediaChannel *channel);
164 void UnregisterChannel(WebRtcVoiceMediaChannel *channel);
165
166 // May only be called by WebRtcSoundclipMedia.
167 void RegisterSoundclip(WebRtcSoundclipMedia *channel);
168 void UnregisterSoundclip(WebRtcSoundclipMedia *channel);
169
170 // Called by WebRtcVoiceMediaChannel to set a gain offset from
171 // the default AGC target level.
172 bool AdjustAgcLevel(int delta);
173
174 VoEWrapper* voe() { return voe_wrapper_.get(); }
175 VoEWrapper* voe_sc() { return voe_wrapper_sc_.get(); }
176 int GetLastEngineError();
177
178 // Set the external ADMs. This can only be called before Init.
179 bool SetAudioDeviceModule(webrtc::AudioDeviceModule* adm,
180 webrtc::AudioDeviceModule* adm_sc);
181
wu@webrtc.orga9890802013-12-13 00:21:03 +0000182 // Starts AEC dump using existing file.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000183 bool StartAecDump(rtc::PlatformFile file);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000184
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 // Check whether the supplied trace should be ignored.
186 bool ShouldIgnoreTrace(const std::string& trace);
187
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000188 // Create a VoiceEngine Channel.
189 int CreateMediaVoiceChannel();
190 int CreateSoundclipVoiceChannel();
191
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 private:
193 typedef std::vector<WebRtcSoundclipMedia *> SoundclipList;
194 typedef std::vector<WebRtcVoiceMediaChannel *> ChannelList;
195 typedef sigslot::
196 signal3<uint32, MediaProcessorDirection, AudioFrame*> FrameSignal;
197
198 void Construct();
199 void ConstructCodecs();
henrik.lundin@webrtc.org8038d422014-11-11 08:38:24 +0000200 bool GetVoeCodec(int index, webrtc::CodecInst* codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000201 bool InitInternal();
wu@webrtc.org4551b792013-10-09 15:37:36 +0000202 bool EnsureSoundclipEngineInit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 void SetTraceFilter(int filter);
204 void SetTraceOptions(const std::string& options);
205 // Applies either options or overrides. Every option that is "set"
206 // will be applied. Every option not "set" will be ignored. This
207 // allows us to selectively turn on and off different options easily
208 // at any time.
209 bool ApplyOptions(const AudioOptions& options);
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000210
211 // webrtc::TraceCallback:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000212 void Print(webrtc::TraceLevel level, const char* trace, int length) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000213
214 // webrtc::VoiceEngineObserver:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000215 void CallbackOnError(int channel, int errCode) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000216
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 // Given the device type, name, and id, find device id. Return true and
218 // set the output parameter rtc_id if successful.
219 bool FindWebRtcAudioDeviceId(
220 bool is_input, const std::string& dev_name, int dev_id, int* rtc_id);
221 bool FindChannelAndSsrc(int channel_num,
222 WebRtcVoiceMediaChannel** channel,
223 uint32* ssrc) const;
224 bool FindChannelNumFromSsrc(uint32 ssrc,
225 MediaProcessorDirection direction,
226 int* channel_num);
227 bool ChangeLocalMonitor(bool enable);
228 bool PauseLocalMonitor();
229 bool ResumeLocalMonitor();
230
231 bool UnregisterProcessorChannel(MediaProcessorDirection channel_direction,
232 uint32 ssrc,
233 VoiceProcessor* voice_processor,
234 MediaProcessorDirection processor_direction);
235
236 void StartAecDump(const std::string& filename);
237 void StopAecDump();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000238 int CreateVoiceChannel(VoEWrapper* voe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239
240 // When a voice processor registers with the engine, it is connected
241 // to either the Rx or Tx signals, based on the direction parameter.
242 // SignalXXMediaFrame will be invoked for every audio packet.
243 FrameSignal SignalRxMediaFrame;
244 FrameSignal SignalTxMediaFrame;
245
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000246 static const int kDefaultLogSeverity = rtc::LS_WARNING;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247
248 // The primary instance of WebRtc VoiceEngine.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000249 rtc::scoped_ptr<VoEWrapper> voe_wrapper_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 // A secondary instance, for playing out soundclips (on the 'ring' device).
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000251 rtc::scoped_ptr<VoEWrapper> voe_wrapper_sc_;
wu@webrtc.org4551b792013-10-09 15:37:36 +0000252 bool voe_wrapper_sc_initialized_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000253 rtc::scoped_ptr<VoETraceWrapper> tracing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254 // The external audio device manager
255 webrtc::AudioDeviceModule* adm_;
256 webrtc::AudioDeviceModule* adm_sc_;
257 int log_filter_;
258 std::string log_options_;
259 bool is_dumping_aec_;
260 std::vector<AudioCodec> codecs_;
261 std::vector<RtpHeaderExtension> rtp_header_extensions_;
262 bool desired_local_monitor_enable_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000263 rtc::scoped_ptr<WebRtcMonitorStream> monitor_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 SoundclipList soundclips_;
265 ChannelList channels_;
266 // channels_ can be read from WebRtc callback thread. We need a lock on that
267 // callback as well as the RegisterChannel/UnregisterChannel.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000268 rtc::CriticalSection channels_cs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000269 webrtc::AgcConfig default_agc_config_;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000270
271 webrtc::Config voe_config_;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000272
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273 bool initialized_;
274 // See SetOptions and SetOptionOverrides for a description of the
275 // difference between options and overrides.
276 // options_ are the base options, which combined with the
277 // option_overrides_, create the current options being used.
278 // options_ is stored so that when option_overrides_ is cleared, we
279 // can restore the options_ without the option_overrides.
280 AudioOptions options_;
281 AudioOptions option_overrides_;
282
283 // When the media processor registers with the engine, the ssrc is cached
284 // here so that a look up need not be made when the callback is invoked.
285 // This is necessary because the lookup results in mux_channels_cs lock being
286 // held and if a remote participant leaves the hangout at the same time
287 // we hit a deadlock.
288 uint32 tx_processor_ssrc_;
289 uint32 rx_processor_ssrc_;
290
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000291 rtc::CriticalSection signal_media_critical_;
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000292
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100293 // Cache received experimental_aec, delay_agnostic_aec and experimental_ns
294 // values, and apply them in case they are missing in the audio options. We
295 // need to do this because SetExtraOptions() will revert to defaults for
296 // options which are not provided.
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000297 Settable<bool> experimental_aec_;
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100298 Settable<bool> delay_agnostic_aec_;
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000299 Settable<bool> experimental_ns_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300};
301
302// WebRtcMediaChannel is a class that implements the common WebRtc channel
303// functionality.
304template <class T, class E>
305class WebRtcMediaChannel : public T, public webrtc::Transport {
306 public:
307 WebRtcMediaChannel(E *engine, int channel)
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000308 : engine_(engine), voe_channel_(channel) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 E *engine() { return engine_; }
310 int voe_channel() const { return voe_channel_; }
311 bool valid() const { return voe_channel_ != -1; }
312
313 protected:
314 // implements Transport interface
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000315 int SendPacket(int channel, const void* data, size_t len) override {
Karl Wiberg94784372015-04-20 14:03:07 +0200316 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len,
317 kMaxRtpPacketLen);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000318 return T::SendPacket(&packet) ? static_cast<int>(len) : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000320
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000321 int SendRTCPPacket(int channel, const void* data, size_t len) override {
Karl Wiberg94784372015-04-20 14:03:07 +0200322 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len,
323 kMaxRtpPacketLen);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000324 return T::SendRtcp(&packet) ? static_cast<int>(len) : -1;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000325 }
326
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 private:
328 E *engine_;
pbos@webrtc.org8296ec52015-03-20 14:27:49 +0000329 const int voe_channel_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330};
331
332// WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses
333// WebRtc Voice Engine.
334class WebRtcVoiceMediaChannel
335 : public WebRtcMediaChannel<VoiceMediaChannel, WebRtcVoiceEngine> {
336 public:
337 explicit WebRtcVoiceMediaChannel(WebRtcVoiceEngine *engine);
338 virtual ~WebRtcVoiceMediaChannel();
339 virtual bool SetOptions(const AudioOptions& options);
340 virtual bool GetOptions(AudioOptions* options) const {
341 *options = options_;
342 return true;
343 }
344 virtual bool SetRecvCodecs(const std::vector<AudioCodec> &codecs);
345 virtual bool SetSendCodecs(const std::vector<AudioCodec> &codecs);
346 virtual bool SetRecvRtpHeaderExtensions(
347 const std::vector<RtpHeaderExtension>& extensions);
348 virtual bool SetSendRtpHeaderExtensions(
349 const std::vector<RtpHeaderExtension>& extensions);
350 virtual bool SetPlayout(bool playout);
351 bool PausePlayout();
352 bool ResumePlayout();
353 virtual bool SetSend(SendFlags send);
354 bool PauseSend();
355 bool ResumeSend();
356 virtual bool AddSendStream(const StreamParams& sp);
357 virtual bool RemoveSendStream(uint32 ssrc);
358 virtual bool AddRecvStream(const StreamParams& sp);
359 virtual bool RemoveRecvStream(uint32 ssrc);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000360 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer);
361 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 virtual bool GetActiveStreams(AudioInfo::StreamList* actives);
363 virtual int GetOutputLevel();
364 virtual int GetTimeSinceLastTyping();
365 virtual void SetTypingDetectionParameters(int time_window,
366 int cost_per_typing, int reporting_threshold, int penalty_decay,
367 int type_event_delay);
368 virtual bool SetOutputScaling(uint32 ssrc, double left, double right);
369 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right);
370
371 virtual bool SetRingbackTone(const char *buf, int len);
372 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop);
373 virtual bool CanInsertDtmf();
374 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags);
375
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000376 virtual void OnPacketReceived(rtc::Buffer* packet,
377 const rtc::PacketTime& packet_time);
378 virtual void OnRtcpReceived(rtc::Buffer* packet,
379 const rtc::PacketTime& packet_time);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 virtual void OnReadyToSend(bool ready) {}
381 virtual bool MuteStream(uint32 ssrc, bool on);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000382 virtual bool SetMaxSendBandwidth(int bps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383 virtual bool GetStats(VoiceMediaInfo* info);
384 // Gets last reported error from WebRtc voice engine. This should be only
385 // called in response a failure.
386 virtual void GetLastMediaError(uint32* ssrc,
387 VoiceMediaChannel::Error* error);
388 bool FindSsrc(int channel_num, uint32* ssrc);
389 void OnError(uint32 ssrc, int error);
390
391 bool sending() const { return send_ != SEND_NOTHING; }
392 int GetReceiveChannelNum(uint32 ssrc);
393 int GetSendChannelNum(uint32 ssrc);
394
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000395 bool SetupSharedBandwidthEstimation(webrtc::VideoEngine* vie,
396 int vie_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000397 protected:
398 int GetLastEngineError() { return engine()->GetLastEngineError(); }
399 int GetOutputLevel(int channel);
400 bool GetRedSendCodec(const AudioCodec& red_codec,
401 const std::vector<AudioCodec>& all_codecs,
402 webrtc::CodecInst* send_codec);
403 bool EnableRtcp(int channel);
404 bool ResetRecvCodecs(int channel);
405 bool SetPlayout(int channel, bool playout);
406 static uint32 ParseSsrc(const void* data, size_t len, bool rtcp);
407 static Error WebRtcErrorToChannelError(int err_code);
408
409 private:
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +0000410 class WebRtcVoiceChannelRenderer;
411 // Map of ssrc to WebRtcVoiceChannelRenderer object. A new object of
412 // WebRtcVoiceChannelRenderer will be created for every new stream and
413 // will be destroyed when the stream goes away.
414 typedef std::map<uint32, WebRtcVoiceChannelRenderer*> ChannelMap;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000415 typedef int (webrtc::VoERTP_RTCP::* ExtensionSetterFunction)(int, bool,
416 unsigned char);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000417
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000418 void SetNack(int channel, bool nack_enabled);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000419 void SetNack(const ChannelMap& channels, bool nack_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000420 bool SetSendCodec(const webrtc::CodecInst& send_codec);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000421 bool SetSendCodec(int channel, const webrtc::CodecInst& send_codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422 bool ChangePlayout(bool playout);
423 bool ChangeSend(SendFlags send);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000424 bool ChangeSend(int channel, SendFlags send);
425 void ConfigureSendChannel(int channel);
wu@webrtc.org78187522013-10-07 23:32:02 +0000426 bool ConfigureRecvChannel(int channel);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000427 bool DeleteChannel(int channel);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000428 bool InConferenceMode() const {
429 return options_.conference_mode.GetWithDefaultIfUnset(false);
430 }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000431 bool IsDefaultChannel(int channel_id) const {
432 return channel_id == voe_channel();
433 }
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000434 bool SetSendCodecs(int channel, const std::vector<AudioCodec>& codecs);
minyue@webrtc.org26236952014-10-29 02:27:08 +0000435 bool SetSendBitrateInternal(int bps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000436
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000437 bool SetHeaderExtension(ExtensionSetterFunction setter, int channel_id,
438 const RtpHeaderExtension* extension);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000439 bool SetupSharedBweOnChannel(int voe_channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000440
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000441 bool SetChannelRecvRtpHeaderExtensions(
442 int channel_id,
443 const std::vector<RtpHeaderExtension>& extensions);
444 bool SetChannelSendRtpHeaderExtensions(
445 int channel_id,
446 const std::vector<RtpHeaderExtension>& extensions);
447
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000448 rtc::scoped_ptr<WebRtcSoundclipStream> ringback_tone_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449 std::set<int> ringback_channels_; // channels playing ringback
450 std::vector<AudioCodec> recv_codecs_;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000451 std::vector<AudioCodec> send_codecs_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000452 rtc::scoped_ptr<webrtc::CodecInst> send_codec_;
minyue@webrtc.org26236952014-10-29 02:27:08 +0000453 bool send_bitrate_setting_;
454 int send_bitrate_bps_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455 AudioOptions options_;
456 bool dtmf_allowed_;
457 bool desired_playout_;
458 bool nack_enabled_;
459 bool playout_;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000460 bool typing_noise_detected_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461 SendFlags desired_send_;
462 SendFlags send_;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000463 // shared_bwe_vie_ and shared_bwe_vie_channel_ together identifies a WebRTC
464 // VideoEngine channel that this voice channel should forward incoming packets
465 // to for Bandwidth Estimation purposes.
466 webrtc::VideoEngine* shared_bwe_vie_;
467 int shared_bwe_vie_channel_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000469 // send_channels_ contains the channels which are being used for sending.
470 // When the default channel (voe_channel) is used for sending, it is
471 // contained in send_channels_, otherwise not.
472 ChannelMap send_channels_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000473 std::vector<RtpHeaderExtension> send_extensions_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000474 uint32 default_receive_ssrc_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000475 // Note the default channel (voe_channel()) can reside in both
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000476 // receive_channels_ and send_channels_ in non-conference mode and in that
477 // case it will only be there if a non-zero default_receive_ssrc_ is set.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000478 ChannelMap receive_channels_; // for multiple sources
479 // receive_channels_ can be read from WebRtc callback thread. Access from
480 // the WebRtc thread must be synchronized with edits on the worker thread.
481 // Reads on the worker thread are ok.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482 //
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000483 std::vector<RtpHeaderExtension> receive_extensions_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484 // Do not lock this on the VoE media processor thread; potential for deadlock
485 // exists.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000486 mutable rtc::CriticalSection receive_channels_cs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000487};
488
489} // namespace cricket
490
491#endif // TALK_MEDIA_WEBRTCVOICEENGINE_H_