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