henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 36 | #include "talk/base/buffer.h" |
| 37 | #include "talk/base/byteorder.h" |
| 38 | #include "talk/base/logging.h" |
| 39 | #include "talk/base/scoped_ptr.h" |
| 40 | #include "talk/base/stream.h" |
| 41 | #include "talk/media/base/rtputils.h" |
| 42 | #include "talk/media/webrtc/webrtccommon.h" |
| 43 | #include "talk/media/webrtc/webrtcexport.h" |
| 44 | #include "talk/media/webrtc/webrtcvoe.h" |
| 45 | #include "talk/session/media/channel.h" |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 46 | #include "webrtc/common.h" |
| 47 | #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 48 | |
| 49 | #if !defined(LIBPEERCONNECTION_LIB) && \ |
| 50 | !defined(LIBPEERCONNECTION_IMPLEMENTATION) |
| 51 | #error "Bogus include." |
| 52 | #endif |
| 53 | |
| 54 | |
| 55 | namespace cricket { |
| 56 | |
| 57 | // WebRtcSoundclipStream is an adapter object that allows a memory stream to be |
| 58 | // passed into WebRtc, and support looping. |
| 59 | class WebRtcSoundclipStream : public webrtc::InStream { |
| 60 | public: |
| 61 | WebRtcSoundclipStream(const char* buf, size_t len) |
| 62 | : mem_(buf, len), loop_(true) { |
| 63 | } |
| 64 | void set_loop(bool loop) { loop_ = loop; } |
| 65 | virtual int Read(void* buf, int len); |
| 66 | virtual int Rewind(); |
| 67 | |
| 68 | private: |
| 69 | talk_base::MemoryStream mem_; |
| 70 | bool loop_; |
| 71 | }; |
| 72 | |
| 73 | // WebRtcMonitorStream is used to monitor a stream coming from WebRtc. |
| 74 | // For now we just dump the data. |
| 75 | class WebRtcMonitorStream : public webrtc::OutStream { |
| 76 | virtual bool Write(const void *buf, int len) { |
| 77 | return true; |
| 78 | } |
| 79 | }; |
| 80 | |
| 81 | class AudioDeviceModule; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 82 | class AudioRenderer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | class VoETraceWrapper; |
| 84 | class VoEWrapper; |
| 85 | class VoiceProcessor; |
| 86 | class WebRtcSoundclipMedia; |
| 87 | class WebRtcVoiceMediaChannel; |
| 88 | |
| 89 | // WebRtcVoiceEngine is a class to be used with CompositeMediaEngine. |
| 90 | // It uses the WebRtc VoiceEngine library for audio handling. |
| 91 | class WebRtcVoiceEngine |
| 92 | : public webrtc::VoiceEngineObserver, |
| 93 | public webrtc::TraceCallback, |
| 94 | public webrtc::VoEMediaProcess { |
| 95 | public: |
| 96 | WebRtcVoiceEngine(); |
| 97 | // Dependency injection for testing. |
| 98 | WebRtcVoiceEngine(VoEWrapper* voe_wrapper, |
| 99 | VoEWrapper* voe_wrapper_sc, |
| 100 | VoETraceWrapper* tracing); |
| 101 | ~WebRtcVoiceEngine(); |
| 102 | bool Init(talk_base::Thread* worker_thread); |
| 103 | void Terminate(); |
| 104 | |
| 105 | int GetCapabilities(); |
| 106 | VoiceMediaChannel* CreateChannel(); |
| 107 | |
| 108 | SoundclipMedia* CreateSoundclip(); |
| 109 | |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 110 | AudioOptions GetOptions() const { return options_; } |
| 111 | bool SetOptions(const AudioOptions& options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 112 | // Overrides, when set, take precedence over the options on a |
| 113 | // per-option basis. For example, if AGC is set in options and AEC |
| 114 | // is set in overrides, AGC and AEC will be both be set. Overrides |
| 115 | // can also turn off options. For example, if AGC is set to "on" in |
| 116 | // options and AGC is set to "off" in overrides, the result is that |
| 117 | // AGC will be off until different overrides are applied or until |
| 118 | // the overrides are cleared. Only one set of overrides is present |
| 119 | // at a time (they do not "stack"). And when the overrides are |
| 120 | // cleared, the media engine's state reverts back to the options set |
| 121 | // via SetOptions. This allows us to have both "persistent options" |
| 122 | // (the normal options) and "temporary options" (overrides). |
| 123 | bool SetOptionOverrides(const AudioOptions& options); |
| 124 | bool ClearOptionOverrides(); |
| 125 | bool SetDelayOffset(int offset); |
| 126 | bool SetDevices(const Device* in_device, const Device* out_device); |
| 127 | bool GetOutputVolume(int* level); |
| 128 | bool SetOutputVolume(int level); |
| 129 | int GetInputLevel(); |
| 130 | bool SetLocalMonitor(bool enable); |
| 131 | |
| 132 | const std::vector<AudioCodec>& codecs(); |
| 133 | bool FindCodec(const AudioCodec& codec); |
| 134 | bool FindWebRtcCodec(const AudioCodec& codec, webrtc::CodecInst* gcodec); |
| 135 | |
| 136 | const std::vector<RtpHeaderExtension>& rtp_header_extensions() const; |
| 137 | |
| 138 | void SetLogging(int min_sev, const char* filter); |
| 139 | |
| 140 | bool RegisterProcessor(uint32 ssrc, |
| 141 | VoiceProcessor* voice_processor, |
| 142 | MediaProcessorDirection direction); |
| 143 | bool UnregisterProcessor(uint32 ssrc, |
| 144 | VoiceProcessor* voice_processor, |
| 145 | MediaProcessorDirection direction); |
| 146 | |
| 147 | // Method from webrtc::VoEMediaProcess |
| 148 | virtual void Process(int channel, |
| 149 | webrtc::ProcessingTypes type, |
| 150 | int16_t audio10ms[], |
| 151 | int length, |
| 152 | int sampling_freq, |
| 153 | bool is_stereo); |
| 154 | |
| 155 | // For tracking WebRtc channels. Needed because we have to pause them |
| 156 | // all when switching devices. |
| 157 | // May only be called by WebRtcVoiceMediaChannel. |
| 158 | void RegisterChannel(WebRtcVoiceMediaChannel *channel); |
| 159 | void UnregisterChannel(WebRtcVoiceMediaChannel *channel); |
| 160 | |
| 161 | // May only be called by WebRtcSoundclipMedia. |
| 162 | void RegisterSoundclip(WebRtcSoundclipMedia *channel); |
| 163 | void UnregisterSoundclip(WebRtcSoundclipMedia *channel); |
| 164 | |
| 165 | // Called by WebRtcVoiceMediaChannel to set a gain offset from |
| 166 | // the default AGC target level. |
| 167 | bool AdjustAgcLevel(int delta); |
| 168 | |
| 169 | VoEWrapper* voe() { return voe_wrapper_.get(); } |
| 170 | VoEWrapper* voe_sc() { return voe_wrapper_sc_.get(); } |
| 171 | int GetLastEngineError(); |
| 172 | |
| 173 | // Set the external ADMs. This can only be called before Init. |
| 174 | bool SetAudioDeviceModule(webrtc::AudioDeviceModule* adm, |
| 175 | webrtc::AudioDeviceModule* adm_sc); |
| 176 | |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 177 | // Starts AEC dump using existing file. |
wu@webrtc.org | a8910d2 | 2014-01-23 22:12:45 +0000 | [diff] [blame] | 178 | bool StartAecDump(talk_base::PlatformFile file); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 179 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 180 | // Check whether the supplied trace should be ignored. |
| 181 | bool ShouldIgnoreTrace(const std::string& trace); |
| 182 | |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 183 | // Create a VoiceEngine Channel. |
| 184 | int CreateMediaVoiceChannel(); |
| 185 | int CreateSoundclipVoiceChannel(); |
| 186 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 187 | private: |
| 188 | typedef std::vector<WebRtcSoundclipMedia *> SoundclipList; |
| 189 | typedef std::vector<WebRtcVoiceMediaChannel *> ChannelList; |
| 190 | typedef sigslot:: |
| 191 | signal3<uint32, MediaProcessorDirection, AudioFrame*> FrameSignal; |
| 192 | |
| 193 | void Construct(); |
| 194 | void ConstructCodecs(); |
| 195 | bool InitInternal(); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 196 | bool EnsureSoundclipEngineInit(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 197 | void SetTraceFilter(int filter); |
| 198 | void SetTraceOptions(const std::string& options); |
| 199 | // Applies either options or overrides. Every option that is "set" |
| 200 | // will be applied. Every option not "set" will be ignored. This |
| 201 | // allows us to selectively turn on and off different options easily |
| 202 | // at any time. |
| 203 | bool ApplyOptions(const AudioOptions& options); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 204 | // Configure for using ACM2, if |enable| is true, otherwise configure for |
| 205 | // ACM1. |
| 206 | void EnableExperimentalAcm(bool enable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 207 | virtual void Print(webrtc::TraceLevel level, const char* trace, int length); |
| 208 | virtual void CallbackOnError(int channel, int errCode); |
| 209 | // Given the device type, name, and id, find device id. Return true and |
| 210 | // set the output parameter rtc_id if successful. |
| 211 | bool FindWebRtcAudioDeviceId( |
| 212 | bool is_input, const std::string& dev_name, int dev_id, int* rtc_id); |
| 213 | bool FindChannelAndSsrc(int channel_num, |
| 214 | WebRtcVoiceMediaChannel** channel, |
| 215 | uint32* ssrc) const; |
| 216 | bool FindChannelNumFromSsrc(uint32 ssrc, |
| 217 | MediaProcessorDirection direction, |
| 218 | int* channel_num); |
| 219 | bool ChangeLocalMonitor(bool enable); |
| 220 | bool PauseLocalMonitor(); |
| 221 | bool ResumeLocalMonitor(); |
| 222 | |
| 223 | bool UnregisterProcessorChannel(MediaProcessorDirection channel_direction, |
| 224 | uint32 ssrc, |
| 225 | VoiceProcessor* voice_processor, |
| 226 | MediaProcessorDirection processor_direction); |
| 227 | |
| 228 | void StartAecDump(const std::string& filename); |
| 229 | void StopAecDump(); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 230 | int CreateVoiceChannel(VoEWrapper* voe); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 231 | |
| 232 | // When a voice processor registers with the engine, it is connected |
| 233 | // to either the Rx or Tx signals, based on the direction parameter. |
| 234 | // SignalXXMediaFrame will be invoked for every audio packet. |
| 235 | FrameSignal SignalRxMediaFrame; |
| 236 | FrameSignal SignalTxMediaFrame; |
| 237 | |
| 238 | static const int kDefaultLogSeverity = talk_base::LS_WARNING; |
| 239 | |
| 240 | // The primary instance of WebRtc VoiceEngine. |
| 241 | talk_base::scoped_ptr<VoEWrapper> voe_wrapper_; |
| 242 | // A secondary instance, for playing out soundclips (on the 'ring' device). |
| 243 | talk_base::scoped_ptr<VoEWrapper> voe_wrapper_sc_; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 244 | bool voe_wrapper_sc_initialized_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 245 | talk_base::scoped_ptr<VoETraceWrapper> tracing_; |
| 246 | // The external audio device manager |
| 247 | webrtc::AudioDeviceModule* adm_; |
| 248 | webrtc::AudioDeviceModule* adm_sc_; |
| 249 | int log_filter_; |
| 250 | std::string log_options_; |
| 251 | bool is_dumping_aec_; |
| 252 | std::vector<AudioCodec> codecs_; |
| 253 | std::vector<RtpHeaderExtension> rtp_header_extensions_; |
| 254 | bool desired_local_monitor_enable_; |
| 255 | talk_base::scoped_ptr<WebRtcMonitorStream> monitor_; |
| 256 | SoundclipList soundclips_; |
| 257 | ChannelList channels_; |
| 258 | // channels_ can be read from WebRtc callback thread. We need a lock on that |
| 259 | // callback as well as the RegisterChannel/UnregisterChannel. |
| 260 | talk_base::CriticalSection channels_cs_; |
| 261 | webrtc::AgcConfig default_agc_config_; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 262 | |
| 263 | webrtc::Config voe_config_; |
| 264 | bool use_experimental_acm_; |
| 265 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 266 | bool initialized_; |
| 267 | // See SetOptions and SetOptionOverrides for a description of the |
| 268 | // difference between options and overrides. |
| 269 | // options_ are the base options, which combined with the |
| 270 | // option_overrides_, create the current options being used. |
| 271 | // options_ is stored so that when option_overrides_ is cleared, we |
| 272 | // can restore the options_ without the option_overrides. |
| 273 | AudioOptions options_; |
| 274 | AudioOptions option_overrides_; |
| 275 | |
| 276 | // When the media processor registers with the engine, the ssrc is cached |
| 277 | // here so that a look up need not be made when the callback is invoked. |
| 278 | // This is necessary because the lookup results in mux_channels_cs lock being |
| 279 | // held and if a remote participant leaves the hangout at the same time |
| 280 | // we hit a deadlock. |
| 281 | uint32 tx_processor_ssrc_; |
| 282 | uint32 rx_processor_ssrc_; |
| 283 | |
| 284 | talk_base::CriticalSection signal_media_critical_; |
| 285 | }; |
| 286 | |
| 287 | // WebRtcMediaChannel is a class that implements the common WebRtc channel |
| 288 | // functionality. |
| 289 | template <class T, class E> |
| 290 | class WebRtcMediaChannel : public T, public webrtc::Transport { |
| 291 | public: |
| 292 | WebRtcMediaChannel(E *engine, int channel) |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 293 | : engine_(engine), voe_channel_(channel) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 294 | E *engine() { return engine_; } |
| 295 | int voe_channel() const { return voe_channel_; } |
| 296 | bool valid() const { return voe_channel_ != -1; } |
| 297 | |
| 298 | protected: |
| 299 | // implements Transport interface |
| 300 | virtual int SendPacket(int channel, const void *data, int len) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 301 | talk_base::Buffer packet(data, len, kMaxRtpPacketLen); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 302 | if (!T::SendPacket(&packet)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 303 | return -1; |
| 304 | } |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 305 | return len; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 306 | } |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 307 | |
| 308 | virtual int SendRTCPPacket(int channel, const void *data, int len) { |
| 309 | talk_base::Buffer packet(data, len, kMaxRtpPacketLen); |
| 310 | return T::SendRtcp(&packet) ? len : -1; |
| 311 | } |
| 312 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 313 | private: |
| 314 | E *engine_; |
| 315 | int voe_channel_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 316 | }; |
| 317 | |
| 318 | // WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses |
| 319 | // WebRtc Voice Engine. |
| 320 | class WebRtcVoiceMediaChannel |
| 321 | : public WebRtcMediaChannel<VoiceMediaChannel, WebRtcVoiceEngine> { |
| 322 | public: |
| 323 | explicit WebRtcVoiceMediaChannel(WebRtcVoiceEngine *engine); |
| 324 | virtual ~WebRtcVoiceMediaChannel(); |
| 325 | virtual bool SetOptions(const AudioOptions& options); |
| 326 | virtual bool GetOptions(AudioOptions* options) const { |
| 327 | *options = options_; |
| 328 | return true; |
| 329 | } |
| 330 | virtual bool SetRecvCodecs(const std::vector<AudioCodec> &codecs); |
| 331 | virtual bool SetSendCodecs(const std::vector<AudioCodec> &codecs); |
| 332 | virtual bool SetRecvRtpHeaderExtensions( |
| 333 | const std::vector<RtpHeaderExtension>& extensions); |
| 334 | virtual bool SetSendRtpHeaderExtensions( |
| 335 | const std::vector<RtpHeaderExtension>& extensions); |
| 336 | virtual bool SetPlayout(bool playout); |
| 337 | bool PausePlayout(); |
| 338 | bool ResumePlayout(); |
| 339 | virtual bool SetSend(SendFlags send); |
| 340 | bool PauseSend(); |
| 341 | bool ResumeSend(); |
| 342 | virtual bool AddSendStream(const StreamParams& sp); |
| 343 | virtual bool RemoveSendStream(uint32 ssrc); |
| 344 | virtual bool AddRecvStream(const StreamParams& sp); |
| 345 | virtual bool RemoveRecvStream(uint32 ssrc); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 346 | virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer); |
| 347 | virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 348 | virtual bool GetActiveStreams(AudioInfo::StreamList* actives); |
| 349 | virtual int GetOutputLevel(); |
| 350 | virtual int GetTimeSinceLastTyping(); |
| 351 | virtual void SetTypingDetectionParameters(int time_window, |
| 352 | int cost_per_typing, int reporting_threshold, int penalty_decay, |
| 353 | int type_event_delay); |
| 354 | virtual bool SetOutputScaling(uint32 ssrc, double left, double right); |
| 355 | virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right); |
| 356 | |
| 357 | virtual bool SetRingbackTone(const char *buf, int len); |
| 358 | virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop); |
| 359 | virtual bool CanInsertDtmf(); |
| 360 | virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags); |
| 361 | |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 362 | virtual void OnPacketReceived(talk_base::Buffer* packet, |
| 363 | const talk_base::PacketTime& packet_time); |
| 364 | virtual void OnRtcpReceived(talk_base::Buffer* packet, |
| 365 | const talk_base::PacketTime& packet_time); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 366 | virtual void OnReadyToSend(bool ready) {} |
| 367 | virtual bool MuteStream(uint32 ssrc, bool on); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 368 | virtual bool SetStartSendBandwidth(int bps); |
| 369 | virtual bool SetMaxSendBandwidth(int bps); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 370 | virtual bool GetStats(VoiceMediaInfo* info); |
| 371 | // Gets last reported error from WebRtc voice engine. This should be only |
| 372 | // called in response a failure. |
| 373 | virtual void GetLastMediaError(uint32* ssrc, |
| 374 | VoiceMediaChannel::Error* error); |
| 375 | bool FindSsrc(int channel_num, uint32* ssrc); |
| 376 | void OnError(uint32 ssrc, int error); |
| 377 | |
| 378 | bool sending() const { return send_ != SEND_NOTHING; } |
| 379 | int GetReceiveChannelNum(uint32 ssrc); |
| 380 | int GetSendChannelNum(uint32 ssrc); |
| 381 | |
| 382 | protected: |
| 383 | int GetLastEngineError() { return engine()->GetLastEngineError(); } |
| 384 | int GetOutputLevel(int channel); |
| 385 | bool GetRedSendCodec(const AudioCodec& red_codec, |
| 386 | const std::vector<AudioCodec>& all_codecs, |
| 387 | webrtc::CodecInst* send_codec); |
| 388 | bool EnableRtcp(int channel); |
| 389 | bool ResetRecvCodecs(int channel); |
| 390 | bool SetPlayout(int channel, bool playout); |
| 391 | static uint32 ParseSsrc(const void* data, size_t len, bool rtcp); |
| 392 | static Error WebRtcErrorToChannelError(int err_code); |
| 393 | |
| 394 | private: |
mallinath@webrtc.org | 67ee6b9 | 2014-02-03 16:57:16 +0000 | [diff] [blame] | 395 | class WebRtcVoiceChannelRenderer; |
| 396 | // Map of ssrc to WebRtcVoiceChannelRenderer object. A new object of |
| 397 | // WebRtcVoiceChannelRenderer will be created for every new stream and |
| 398 | // will be destroyed when the stream goes away. |
| 399 | typedef std::map<uint32, WebRtcVoiceChannelRenderer*> ChannelMap; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 400 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 401 | void SetNack(int channel, bool nack_enabled); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 402 | void SetNack(const ChannelMap& channels, bool nack_enabled); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 403 | bool SetSendCodec(const webrtc::CodecInst& send_codec); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 404 | bool SetSendCodec(int channel, const webrtc::CodecInst& send_codec); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 405 | bool ChangePlayout(bool playout); |
| 406 | bool ChangeSend(SendFlags send); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 407 | bool ChangeSend(int channel, SendFlags send); |
| 408 | void ConfigureSendChannel(int channel); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 409 | bool ConfigureRecvChannel(int channel); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 410 | bool DeleteChannel(int channel); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 411 | bool InConferenceMode() const { |
| 412 | return options_.conference_mode.GetWithDefaultIfUnset(false); |
| 413 | } |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 414 | bool IsDefaultChannel(int channel_id) const { |
| 415 | return channel_id == voe_channel(); |
| 416 | } |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 417 | bool SetSendCodecs(int channel, const std::vector<AudioCodec>& codecs); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 418 | bool SetSendBandwidthInternal(int bps); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 419 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 420 | talk_base::scoped_ptr<WebRtcSoundclipStream> ringback_tone_; |
| 421 | std::set<int> ringback_channels_; // channels playing ringback |
| 422 | std::vector<AudioCodec> recv_codecs_; |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 423 | std::vector<AudioCodec> send_codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 424 | talk_base::scoped_ptr<webrtc::CodecInst> send_codec_; |
wu@webrtc.org | 1d1ffc9 | 2013-10-16 18:12:02 +0000 | [diff] [blame] | 425 | bool send_bw_setting_; |
wu@webrtc.org | 1d1ffc9 | 2013-10-16 18:12:02 +0000 | [diff] [blame] | 426 | int send_bw_bps_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 427 | AudioOptions options_; |
| 428 | bool dtmf_allowed_; |
| 429 | bool desired_playout_; |
| 430 | bool nack_enabled_; |
| 431 | bool playout_; |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 432 | bool typing_noise_detected_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 433 | SendFlags desired_send_; |
| 434 | SendFlags send_; |
| 435 | |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 436 | // send_channels_ contains the channels which are being used for sending. |
| 437 | // When the default channel (voe_channel) is used for sending, it is |
| 438 | // contained in send_channels_, otherwise not. |
| 439 | ChannelMap send_channels_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 440 | uint32 default_receive_ssrc_; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 441 | // Note the default channel (voe_channel()) can reside in both |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 442 | // receive_channels_ and send_channels_ in non-conference mode and in that |
| 443 | // case it will only be there if a non-zero default_receive_ssrc_ is set. |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 444 | ChannelMap receive_channels_; // for multiple sources |
| 445 | // 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 448 | // |
| 449 | // Do not lock this on the VoE media processor thread; potential for deadlock |
| 450 | // exists. |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 451 | mutable talk_base::CriticalSection receive_channels_cs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 452 | }; |
| 453 | |
| 454 | } // namespace cricket |
| 455 | |
| 456 | #endif // TALK_MEDIA_WEBRTCVOICEENGINE_H_ |