blob: 076922b06657c7cb7fa8190ad010c90e98be5b54 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2004 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef TALK_MEDIA_WEBRTCVOICEENGINE_H_
29#define TALK_MEDIA_WEBRTCVOICEENGINE_H_
30
31#include <map>
32#include <set>
33#include <string>
34#include <vector>
35
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036#include "talk/media/base/rtputils.h"
37#include "talk/media/webrtc/webrtccommon.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038#include "talk/media/webrtc/webrtcvoe.h"
39#include "talk/session/media/channel.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000040#include "webrtc/base/buffer.h"
41#include "webrtc/base/byteorder.h"
42#include "webrtc/base/logging.h"
43#include "webrtc/base/scoped_ptr.h"
44#include "webrtc/base/stream.h"
Fredrik Solenberg4b60c732015-05-07 14:07:48 +020045#include "webrtc/base/thread_checker.h"
46#include "webrtc/call.h"
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +000047#include "webrtc/common.h"
Henrik Lundin64dad832015-05-11 12:44:23 +020048#include "webrtc/config.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +000050namespace webrtc {
51class VideoEngine;
52}
53
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054namespace cricket {
55
56// WebRtcSoundclipStream is an adapter object that allows a memory stream to be
57// passed into WebRtc, and support looping.
58class WebRtcSoundclipStream : public webrtc::InStream {
59 public:
60 WebRtcSoundclipStream(const char* buf, size_t len)
61 : mem_(buf, len), loop_(true) {
62 }
63 void set_loop(bool loop) { loop_ = loop; }
xians@webrtc.org3cefbc92014-10-10 09:42:53 +000064
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000065 int Read(void* buf, size_t len) override;
66 int Rewind() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067
68 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000069 rtc::MemoryStream mem_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070 bool loop_;
71};
72
73// WebRtcMonitorStream is used to monitor a stream coming from WebRtc.
74// For now we just dump the data.
75class WebRtcMonitorStream : public webrtc::OutStream {
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000076 bool Write(const void* buf, size_t len) override { return true; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077};
78
79class AudioDeviceModule;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +000080class AudioRenderer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081class VoETraceWrapper;
82class VoEWrapper;
83class VoiceProcessor;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084class WebRtcVoiceMediaChannel;
85
86// WebRtcVoiceEngine is a class to be used with CompositeMediaEngine.
87// It uses the WebRtc VoiceEngine library for audio handling.
88class WebRtcVoiceEngine
89 : public webrtc::VoiceEngineObserver,
90 public webrtc::TraceCallback,
91 public webrtc::VoEMediaProcess {
92 public:
93 WebRtcVoiceEngine();
94 // Dependency injection for testing.
Fredrik Solenbergccb49e72015-05-19 11:37:56 +020095 WebRtcVoiceEngine(VoEWrapper* voe_wrapper, VoETraceWrapper* tracing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096 ~WebRtcVoiceEngine();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000097 bool Init(rtc::Thread* worker_thread);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098 void Terminate();
99
100 int GetCapabilities();
101 VoiceMediaChannel* CreateChannel();
102
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000103 AudioOptions GetOptions() const { return options_; }
104 bool SetOptions(const AudioOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105 // Overrides, when set, take precedence over the options on a
106 // per-option basis. For example, if AGC is set in options and AEC
107 // is set in overrides, AGC and AEC will be both be set. Overrides
108 // can also turn off options. For example, if AGC is set to "on" in
109 // options and AGC is set to "off" in overrides, the result is that
110 // AGC will be off until different overrides are applied or until
111 // the overrides are cleared. Only one set of overrides is present
112 // at a time (they do not "stack"). And when the overrides are
113 // cleared, the media engine's state reverts back to the options set
114 // via SetOptions. This allows us to have both "persistent options"
115 // (the normal options) and "temporary options" (overrides).
116 bool SetOptionOverrides(const AudioOptions& options);
117 bool ClearOptionOverrides();
118 bool SetDelayOffset(int offset);
119 bool SetDevices(const Device* in_device, const Device* out_device);
120 bool GetOutputVolume(int* level);
121 bool SetOutputVolume(int level);
122 int GetInputLevel();
123 bool SetLocalMonitor(bool enable);
124
125 const std::vector<AudioCodec>& codecs();
126 bool FindCodec(const AudioCodec& codec);
127 bool FindWebRtcCodec(const AudioCodec& codec, webrtc::CodecInst* gcodec);
128
129 const std::vector<RtpHeaderExtension>& rtp_header_extensions() const;
130
131 void SetLogging(int min_sev, const char* filter);
132
133 bool RegisterProcessor(uint32 ssrc,
134 VoiceProcessor* voice_processor,
135 MediaProcessorDirection direction);
136 bool UnregisterProcessor(uint32 ssrc,
137 VoiceProcessor* voice_processor,
138 MediaProcessorDirection direction);
139
140 // Method from webrtc::VoEMediaProcess
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000141 void Process(int channel,
142 webrtc::ProcessingTypes type,
143 int16_t audio10ms[],
144 int length,
145 int sampling_freq,
146 bool is_stereo) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000147
148 // For tracking WebRtc channels. Needed because we have to pause them
149 // all when switching devices.
150 // May only be called by WebRtcVoiceMediaChannel.
151 void RegisterChannel(WebRtcVoiceMediaChannel *channel);
152 void UnregisterChannel(WebRtcVoiceMediaChannel *channel);
153
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154 // Called by WebRtcVoiceMediaChannel to set a gain offset from
155 // the default AGC target level.
156 bool AdjustAgcLevel(int delta);
157
158 VoEWrapper* voe() { return voe_wrapper_.get(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159 int GetLastEngineError();
160
Fredrik Solenbergccb49e72015-05-19 11:37:56 +0200161 // Set the external ADM. This can only be called before Init.
162 bool SetAudioDeviceModule(webrtc::AudioDeviceModule* adm);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163
wu@webrtc.orga9890802013-12-13 00:21:03 +0000164 // Starts AEC dump using existing file.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000165 bool StartAecDump(rtc::PlatformFile file);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000166
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 // Check whether the supplied trace should be ignored.
168 bool ShouldIgnoreTrace(const std::string& trace);
169
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000170 // Create a VoiceEngine Channel.
171 int CreateMediaVoiceChannel();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000172
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 private:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174 typedef std::vector<WebRtcVoiceMediaChannel *> ChannelList;
175 typedef sigslot::
176 signal3<uint32, MediaProcessorDirection, AudioFrame*> FrameSignal;
177
178 void Construct();
179 void ConstructCodecs();
henrik.lundin@webrtc.org8038d422014-11-11 08:38:24 +0000180 bool GetVoeCodec(int index, webrtc::CodecInst* codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 bool InitInternal();
182 void SetTraceFilter(int filter);
183 void SetTraceOptions(const std::string& options);
184 // Applies either options or overrides. Every option that is "set"
185 // will be applied. Every option not "set" will be ignored. This
186 // allows us to selectively turn on and off different options easily
187 // at any time.
188 bool ApplyOptions(const AudioOptions& options);
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000189
190 // webrtc::TraceCallback:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000191 void Print(webrtc::TraceLevel level, const char* trace, int length) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000192
193 // webrtc::VoiceEngineObserver:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000194 void CallbackOnError(int channel, int errCode) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000195
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 // Given the device type, name, and id, find device id. Return true and
197 // set the output parameter rtc_id if successful.
198 bool FindWebRtcAudioDeviceId(
199 bool is_input, const std::string& dev_name, int dev_id, int* rtc_id);
200 bool FindChannelAndSsrc(int channel_num,
201 WebRtcVoiceMediaChannel** channel,
202 uint32* ssrc) const;
203 bool FindChannelNumFromSsrc(uint32 ssrc,
204 MediaProcessorDirection direction,
205 int* channel_num);
206 bool ChangeLocalMonitor(bool enable);
207 bool PauseLocalMonitor();
208 bool ResumeLocalMonitor();
209
210 bool UnregisterProcessorChannel(MediaProcessorDirection channel_direction,
211 uint32 ssrc,
212 VoiceProcessor* voice_processor,
213 MediaProcessorDirection processor_direction);
214
215 void StartAecDump(const std::string& filename);
216 void StopAecDump();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000217 int CreateVoiceChannel(VoEWrapper* voe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218
219 // When a voice processor registers with the engine, it is connected
220 // to either the Rx or Tx signals, based on the direction parameter.
221 // SignalXXMediaFrame will be invoked for every audio packet.
222 FrameSignal SignalRxMediaFrame;
223 FrameSignal SignalTxMediaFrame;
224
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000225 static const int kDefaultLogSeverity = rtc::LS_WARNING;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226
227 // The primary instance of WebRtc VoiceEngine.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000228 rtc::scoped_ptr<VoEWrapper> voe_wrapper_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000229 rtc::scoped_ptr<VoETraceWrapper> tracing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 // The external audio device manager
231 webrtc::AudioDeviceModule* adm_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 int log_filter_;
233 std::string log_options_;
234 bool is_dumping_aec_;
235 std::vector<AudioCodec> codecs_;
236 std::vector<RtpHeaderExtension> rtp_header_extensions_;
237 bool desired_local_monitor_enable_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000238 rtc::scoped_ptr<WebRtcMonitorStream> monitor_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239 ChannelList channels_;
240 // channels_ can be read from WebRtc callback thread. We need a lock on that
241 // callback as well as the RegisterChannel/UnregisterChannel.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000242 rtc::CriticalSection channels_cs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000243 webrtc::AgcConfig default_agc_config_;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000244
245 webrtc::Config voe_config_;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000246
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 bool initialized_;
248 // See SetOptions and SetOptionOverrides for a description of the
249 // difference between options and overrides.
250 // options_ are the base options, which combined with the
251 // option_overrides_, create the current options being used.
252 // options_ is stored so that when option_overrides_ is cleared, we
253 // can restore the options_ without the option_overrides.
254 AudioOptions options_;
255 AudioOptions option_overrides_;
256
257 // When the media processor registers with the engine, the ssrc is cached
258 // here so that a look up need not be made when the callback is invoked.
259 // This is necessary because the lookup results in mux_channels_cs lock being
260 // held and if a remote participant leaves the hangout at the same time
261 // we hit a deadlock.
262 uint32 tx_processor_ssrc_;
263 uint32 rx_processor_ssrc_;
264
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000265 rtc::CriticalSection signal_media_critical_;
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000266
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100267 // Cache received experimental_aec, delay_agnostic_aec and experimental_ns
268 // values, and apply them in case they are missing in the audio options. We
269 // need to do this because SetExtraOptions() will revert to defaults for
270 // options which are not provided.
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000271 Settable<bool> experimental_aec_;
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100272 Settable<bool> delay_agnostic_aec_;
buildbot@webrtc.org1f8a2372014-08-28 10:52:44 +0000273 Settable<bool> experimental_ns_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000274};
275
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000276// WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses
277// WebRtc Voice Engine.
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200278class WebRtcVoiceMediaChannel : public VoiceMediaChannel,
279 public webrtc::Transport {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280 public:
281 explicit WebRtcVoiceMediaChannel(WebRtcVoiceEngine *engine);
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200282 ~WebRtcVoiceMediaChannel() override;
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200283
284 int voe_channel() const { return voe_channel_; }
285 bool valid() const { return voe_channel_ != -1; }
286
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200287 bool SetOptions(const AudioOptions& options) override;
288 bool GetOptions(AudioOptions* options) const override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289 *options = options_;
290 return true;
291 }
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200292 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) override;
293 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) override;
294 bool SetRecvRtpHeaderExtensions(
295 const std::vector<RtpHeaderExtension>& extensions) override;
296 bool SetSendRtpHeaderExtensions(
297 const std::vector<RtpHeaderExtension>& extensions) override;
298 bool SetPlayout(bool playout) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 bool PausePlayout();
300 bool ResumePlayout();
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200301 bool SetSend(SendFlags send) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 bool PauseSend();
303 bool ResumeSend();
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200304 bool AddSendStream(const StreamParams& sp) override;
305 bool RemoveSendStream(uint32 ssrc) override;
306 bool AddRecvStream(const StreamParams& sp) override;
307 bool RemoveRecvStream(uint32 ssrc) override;
308 bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) override;
309 bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) override;
310 bool GetActiveStreams(AudioInfo::StreamList* actives) override;
311 int GetOutputLevel() override;
312 int GetTimeSinceLastTyping() override;
313 void SetTypingDetectionParameters(int time_window,
314 int cost_per_typing,
315 int reporting_threshold,
316 int penalty_decay,
317 int type_event_delay) override;
318 bool SetOutputScaling(uint32 ssrc, double left, double right) override;
319 bool GetOutputScaling(uint32 ssrc, double* left, double* right) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200321 bool SetRingbackTone(const char* buf, int len) override;
322 bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) override;
323 bool CanInsertDtmf() override;
324 bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200326 void OnPacketReceived(rtc::Buffer* packet,
327 const rtc::PacketTime& packet_time) override;
328 void OnRtcpReceived(rtc::Buffer* packet,
329 const rtc::PacketTime& packet_time) override;
330 void OnReadyToSend(bool ready) override {}
331 bool MuteStream(uint32 ssrc, bool on) override;
332 bool SetMaxSendBandwidth(int bps) override;
333 bool GetStats(VoiceMediaInfo* info) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334 // Gets last reported error from WebRtc voice engine. This should be only
335 // called in response a failure.
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200336 void GetLastMediaError(uint32* ssrc,
337 VoiceMediaChannel::Error* error) override;
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200338
339 // implements Transport interface
340 int SendPacket(int channel, const void* data, size_t len) override {
341 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len,
342 kMaxRtpPacketLen);
343 return VoiceMediaChannel::SendPacket(&packet) ? static_cast<int>(len) : -1;
344 }
345
346 int SendRTCPPacket(int channel, const void* data, size_t len) override {
347 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len,
348 kMaxRtpPacketLen);
349 return VoiceMediaChannel::SendRtcp(&packet) ? static_cast<int>(len) : -1;
350 }
351
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 bool FindSsrc(int channel_num, uint32* ssrc);
353 void OnError(uint32 ssrc, int error);
354
355 bool sending() const { return send_ != SEND_NOTHING; }
356 int GetReceiveChannelNum(uint32 ssrc);
357 int GetSendChannelNum(uint32 ssrc);
358
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200359 void SetCall(webrtc::Call* call);
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200360
361 private:
362 WebRtcVoiceEngine* engine() { return engine_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 int GetLastEngineError() { return engine()->GetLastEngineError(); }
364 int GetOutputLevel(int channel);
365 bool GetRedSendCodec(const AudioCodec& red_codec,
366 const std::vector<AudioCodec>& all_codecs,
367 webrtc::CodecInst* send_codec);
368 bool EnableRtcp(int channel);
369 bool ResetRecvCodecs(int channel);
370 bool SetPlayout(int channel, bool playout);
371 static uint32 ParseSsrc(const void* data, size_t len, bool rtcp);
372 static Error WebRtcErrorToChannelError(int err_code);
373
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +0000374 class WebRtcVoiceChannelRenderer;
375 // Map of ssrc to WebRtcVoiceChannelRenderer object. A new object of
376 // WebRtcVoiceChannelRenderer will be created for every new stream and
377 // will be destroyed when the stream goes away.
378 typedef std::map<uint32, WebRtcVoiceChannelRenderer*> ChannelMap;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000379 typedef int (webrtc::VoERTP_RTCP::* ExtensionSetterFunction)(int, bool,
380 unsigned char);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000381
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000382 void SetNack(int channel, bool nack_enabled);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000383 void SetNack(const ChannelMap& channels, bool nack_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 bool SetSendCodec(const webrtc::CodecInst& send_codec);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000385 bool SetSendCodec(int channel, const webrtc::CodecInst& send_codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386 bool ChangePlayout(bool playout);
387 bool ChangeSend(SendFlags send);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000388 bool ChangeSend(int channel, SendFlags send);
389 void ConfigureSendChannel(int channel);
wu@webrtc.org78187522013-10-07 23:32:02 +0000390 bool ConfigureRecvChannel(int channel);
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000391 bool DeleteChannel(int channel);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000392 bool InConferenceMode() const {
393 return options_.conference_mode.GetWithDefaultIfUnset(false);
394 }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000395 bool IsDefaultChannel(int channel_id) const {
396 return channel_id == voe_channel();
397 }
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000398 bool SetSendCodecs(int channel, const std::vector<AudioCodec>& codecs);
minyue@webrtc.org26236952014-10-29 02:27:08 +0000399 bool SetSendBitrateInternal(int bps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000400
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000401 bool SetHeaderExtension(ExtensionSetterFunction setter, int channel_id,
402 const RtpHeaderExtension* extension);
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200403 void TryAddAudioRecvStream(uint32 ssrc);
404 void TryRemoveAudioRecvStream(uint32 ssrc);
405
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000406 bool SetChannelRecvRtpHeaderExtensions(
407 int channel_id,
408 const std::vector<RtpHeaderExtension>& extensions);
409 bool SetChannelSendRtpHeaderExtensions(
410 int channel_id,
411 const std::vector<RtpHeaderExtension>& extensions);
412
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200413 rtc::ThreadChecker thread_checker_;
414
Fredrik Solenberge444a3d2015-05-07 16:42:08 +0200415 WebRtcVoiceEngine* engine_;
416 const int voe_channel_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000417 rtc::scoped_ptr<WebRtcSoundclipStream> ringback_tone_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418 std::set<int> ringback_channels_; // channels playing ringback
419 std::vector<AudioCodec> recv_codecs_;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000420 std::vector<AudioCodec> send_codecs_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000421 rtc::scoped_ptr<webrtc::CodecInst> send_codec_;
minyue@webrtc.org26236952014-10-29 02:27:08 +0000422 bool send_bitrate_setting_;
423 int send_bitrate_bps_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424 AudioOptions options_;
425 bool dtmf_allowed_;
426 bool desired_playout_;
427 bool nack_enabled_;
428 bool playout_;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000429 bool typing_noise_detected_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430 SendFlags desired_send_;
431 SendFlags send_;
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200432 webrtc::Call* call_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000433
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000434 // send_channels_ contains the channels which are being used for sending.
435 // When the default channel (voe_channel) is used for sending, it is
436 // contained in send_channels_, otherwise not.
437 ChannelMap send_channels_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000438 std::vector<RtpHeaderExtension> send_extensions_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000439 uint32 default_receive_ssrc_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000440 // Note the default channel (voe_channel()) can reside in both
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000441 // receive_channels_ and send_channels_ in non-conference mode and in that
442 // case it will only be there if a non-zero default_receive_ssrc_ is set.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000443 ChannelMap receive_channels_; // for multiple sources
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200444 std::map<uint32, webrtc::AudioReceiveStream*> receive_streams_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000445 // receive_channels_ can be read from WebRtc callback thread. Access from
446 // the WebRtc thread must be synchronized with edits on the worker thread.
447 // Reads on the worker thread are ok.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000448 //
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000449 std::vector<RtpHeaderExtension> receive_extensions_;
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200450 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
451
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452 // Do not lock this on the VoE media processor thread; potential for deadlock
453 // exists.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000454 mutable rtc::CriticalSection receive_channels_cs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455};
456
457} // namespace cricket
458
459#endif // TALK_MEDIA_WEBRTCVOICEENGINE_H_