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