henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2010 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_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_ |
| 29 | #define TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_ |
| 30 | |
| 31 | #include <list> |
| 32 | #include <map> |
| 33 | #include <vector> |
| 34 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 35 | #include "talk/media/base/codec.h" |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 36 | #include "talk/media/base/rtputils.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | #include "talk/media/base/voiceprocessor.h" |
| 38 | #include "talk/media/webrtc/fakewebrtccommon.h" |
| 39 | #include "talk/media/webrtc/webrtcvoe.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 40 | #include "webrtc/base/basictypes.h" |
Fredrik Solenberg | d3ddc1b | 2015-05-07 17:07:34 +0200 | [diff] [blame] | 41 | #include "webrtc/base/checks.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 42 | #include "webrtc/base/gunit.h" |
| 43 | #include "webrtc/base/stringutils.h" |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 44 | #include "webrtc/config.h" |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 45 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 46 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 47 | namespace cricket { |
| 48 | |
| 49 | // Function returning stats will return these values |
| 50 | // for all values based on type. |
| 51 | const int kIntStatValue = 123; |
| 52 | const float kFractionLostStatValue = 0.5; |
| 53 | |
| 54 | static const char kFakeDefaultDeviceName[] = "Fake Default"; |
| 55 | static const int kFakeDefaultDeviceId = -1; |
| 56 | static const char kFakeDeviceName[] = "Fake Device"; |
| 57 | #ifdef WIN32 |
| 58 | static const int kFakeDeviceId = 0; |
| 59 | #else |
| 60 | static const int kFakeDeviceId = 1; |
| 61 | #endif |
| 62 | |
buildbot@webrtc.org | 5d639b3 | 2014-09-10 07:57:12 +0000 | [diff] [blame] | 63 | static const int kOpusBandwidthNb = 4000; |
| 64 | static const int kOpusBandwidthMb = 6000; |
| 65 | static const int kOpusBandwidthWb = 8000; |
| 66 | static const int kOpusBandwidthSwb = 12000; |
| 67 | static const int kOpusBandwidthFb = 20000; |
| 68 | |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 69 | static const webrtc::NetworkStatistics kNetStats = { |
| 70 | 1, // uint16_t currentBufferSize; |
| 71 | 2, // uint16_t preferredBufferSize; |
| 72 | true, // bool jitterPeaksFound; |
| 73 | 1234, // uint16_t currentPacketLossRate; |
| 74 | 567, // uint16_t currentDiscardRate; |
| 75 | 8901, // uint16_t currentExpandRate; |
| 76 | 234, // uint16_t currentSpeechExpandRate; |
| 77 | 5678, // uint16_t currentPreemptiveRate; |
| 78 | 9012, // uint16_t currentAccelerateRate; |
| 79 | 3456, // uint16_t currentSecondaryDecodedRate; |
| 80 | 7890, // int32_t clockDriftPPM; |
| 81 | 54, // meanWaitingTimeMs; |
| 82 | 32, // int medianWaitingTimeMs; |
| 83 | 1, // int minWaitingTimeMs; |
| 84 | 98, // int maxWaitingTimeMs; |
| 85 | 7654, // int addedSamples; |
| 86 | }; // These random but non-trivial numbers are used for testing. |
| 87 | |
Fredrik Solenberg | d3ddc1b | 2015-05-07 17:07:34 +0200 | [diff] [blame] | 88 | #define WEBRTC_CHECK_CHANNEL(channel) \ |
| 89 | if (channels_.find(channel) == channels_.end()) return -1; |
| 90 | |
| 91 | #define WEBRTC_ASSERT_CHANNEL(channel) \ |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 92 | RTC_DCHECK(channels_.find(channel) != channels_.end()); |
Fredrik Solenberg | d3ddc1b | 2015-05-07 17:07:34 +0200 | [diff] [blame] | 93 | |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 94 | // Verify the header extension ID, if enabled, is within the bounds specified in |
| 95 | // [RFC5285]: 1-14 inclusive. |
| 96 | #define WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id) \ |
| 97 | do { \ |
| 98 | if (enable && (id < 1 || id > 14)) { \ |
| 99 | return -1; \ |
| 100 | } \ |
| 101 | } while (0); |
| 102 | |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 103 | class FakeAudioProcessing : public webrtc::AudioProcessing { |
| 104 | public: |
| 105 | FakeAudioProcessing() : experimental_ns_enabled_(false) {} |
| 106 | |
| 107 | WEBRTC_STUB(Initialize, ()) |
| 108 | WEBRTC_STUB(Initialize, ( |
| 109 | int input_sample_rate_hz, |
| 110 | int output_sample_rate_hz, |
| 111 | int reverse_sample_rate_hz, |
| 112 | webrtc::AudioProcessing::ChannelLayout input_layout, |
| 113 | webrtc::AudioProcessing::ChannelLayout output_layout, |
| 114 | webrtc::AudioProcessing::ChannelLayout reverse_layout)); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 115 | WEBRTC_STUB(Initialize, ( |
| 116 | const webrtc::ProcessingConfig& processing_config)); |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 117 | |
| 118 | WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) { |
| 119 | experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled; |
| 120 | } |
| 121 | |
| 122 | WEBRTC_STUB(set_sample_rate_hz, (int rate)); |
| 123 | WEBRTC_STUB_CONST(input_sample_rate_hz, ()); |
| 124 | WEBRTC_STUB_CONST(sample_rate_hz, ()); |
| 125 | WEBRTC_STUB_CONST(proc_sample_rate_hz, ()); |
| 126 | WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ()); |
| 127 | WEBRTC_STUB_CONST(num_input_channels, ()); |
| 128 | WEBRTC_STUB_CONST(num_output_channels, ()); |
| 129 | WEBRTC_STUB_CONST(num_reverse_channels, ()); |
| 130 | WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted)); |
| 131 | WEBRTC_BOOL_STUB_CONST(output_will_be_muted, ()); |
| 132 | WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame)); |
| 133 | WEBRTC_STUB(ProcessStream, ( |
| 134 | const float* const* src, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 135 | size_t samples_per_channel, |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 136 | int input_sample_rate_hz, |
| 137 | webrtc::AudioProcessing::ChannelLayout input_layout, |
| 138 | int output_sample_rate_hz, |
| 139 | webrtc::AudioProcessing::ChannelLayout output_layout, |
| 140 | float* const* dest)); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 141 | WEBRTC_STUB(ProcessStream, |
| 142 | (const float* const* src, |
| 143 | const webrtc::StreamConfig& input_config, |
| 144 | const webrtc::StreamConfig& output_config, |
| 145 | float* const* dest)); |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 146 | WEBRTC_STUB(AnalyzeReverseStream, (webrtc::AudioFrame* frame)); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 147 | WEBRTC_STUB(ProcessReverseStream, (webrtc::AudioFrame * frame)); |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 148 | WEBRTC_STUB(AnalyzeReverseStream, ( |
| 149 | const float* const* data, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 150 | size_t samples_per_channel, |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 151 | int sample_rate_hz, |
| 152 | webrtc::AudioProcessing::ChannelLayout layout)); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 153 | WEBRTC_STUB(ProcessReverseStream, |
| 154 | (const float* const* src, |
| 155 | const webrtc::StreamConfig& reverse_input_config, |
| 156 | const webrtc::StreamConfig& reverse_output_config, |
| 157 | float* const* dest)); |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 158 | WEBRTC_STUB(set_stream_delay_ms, (int delay)); |
| 159 | WEBRTC_STUB_CONST(stream_delay_ms, ()); |
| 160 | WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ()); |
| 161 | WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed)); |
| 162 | WEBRTC_BOOL_STUB_CONST(stream_key_pressed, ()); |
| 163 | WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset)); |
| 164 | WEBRTC_STUB_CONST(delay_offset_ms, ()); |
| 165 | WEBRTC_STUB(StartDebugRecording, (const char filename[kMaxFilenameSize])); |
| 166 | WEBRTC_STUB(StartDebugRecording, (FILE* handle)); |
| 167 | WEBRTC_STUB(StopDebugRecording, ()); |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 168 | WEBRTC_VOID_STUB(UpdateHistogramsOnCallEnd, ()); |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 169 | webrtc::EchoCancellation* echo_cancellation() const override { return NULL; } |
| 170 | webrtc::EchoControlMobile* echo_control_mobile() const override { |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 171 | return NULL; |
| 172 | } |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 173 | webrtc::GainControl* gain_control() const override { return NULL; } |
| 174 | webrtc::HighPassFilter* high_pass_filter() const override { return NULL; } |
| 175 | webrtc::LevelEstimator* level_estimator() const override { return NULL; } |
| 176 | webrtc::NoiseSuppression* noise_suppression() const override { return NULL; } |
| 177 | webrtc::VoiceDetection* voice_detection() const override { return NULL; } |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 178 | |
| 179 | bool experimental_ns_enabled() { |
| 180 | return experimental_ns_enabled_; |
| 181 | } |
| 182 | |
| 183 | private: |
| 184 | bool experimental_ns_enabled_; |
| 185 | }; |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 186 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 187 | class FakeWebRtcVoiceEngine |
| 188 | : public webrtc::VoEAudioProcessing, |
| 189 | public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf, |
Fredrik Solenberg | 0967734 | 2015-09-23 12:05:37 +0200 | [diff] [blame^] | 190 | public webrtc::VoEHardware, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 191 | public webrtc::VoEExternalMedia, public webrtc::VoENetEqStats, |
| 192 | public webrtc::VoENetwork, public webrtc::VoERTP_RTCP, |
| 193 | public webrtc::VoEVideoSync, public webrtc::VoEVolumeControl { |
| 194 | public: |
| 195 | struct DtmfInfo { |
| 196 | DtmfInfo() |
| 197 | : dtmf_event_code(-1), |
| 198 | dtmf_out_of_band(false), |
| 199 | dtmf_length_ms(-1) {} |
| 200 | int dtmf_event_code; |
| 201 | bool dtmf_out_of_band; |
| 202 | int dtmf_length_ms; |
| 203 | }; |
| 204 | struct Channel { |
buildbot@webrtc.org | af6640f | 2014-04-28 21:31:51 +0000 | [diff] [blame] | 205 | explicit Channel() |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 206 | : external_transport(false), |
| 207 | send(false), |
| 208 | playout(false), |
| 209 | volume_scale(1.0), |
| 210 | volume_pan_left(1.0), |
| 211 | volume_pan_right(1.0), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 212 | vad(false), |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 213 | codec_fec(false), |
buildbot@webrtc.org | 5d639b3 | 2014-09-10 07:57:12 +0000 | [diff] [blame] | 214 | max_encoding_bandwidth(0), |
minyue@webrtc.org | 9b2e114 | 2015-03-13 09:38:07 +0000 | [diff] [blame] | 215 | opus_dtx(false), |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 216 | red(false), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 217 | nack(false), |
| 218 | media_processor_registered(false), |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 219 | rx_agc_enabled(false), |
| 220 | rx_agc_mode(webrtc::kAgcDefault), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 221 | cn8_type(13), |
| 222 | cn16_type(105), |
| 223 | dtmf_type(106), |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 224 | red_type(117), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 225 | nack_max_packets(0), |
| 226 | send_ssrc(0), |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 227 | send_audio_level_ext_(-1), |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 228 | receive_audio_level_ext_(-1), |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 229 | send_absolute_sender_time_ext_(-1), |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 230 | receive_absolute_sender_time_ext_(-1), |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 231 | associate_send_channel(-1), |
Henrik Lundin | 5263b3c | 2015-06-01 10:29:41 +0200 | [diff] [blame] | 232 | neteq_capacity(-1), |
| 233 | neteq_fast_accelerate(false) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 234 | memset(&send_codec, 0, sizeof(send_codec)); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 235 | memset(&rx_agc_config, 0, sizeof(rx_agc_config)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 236 | } |
| 237 | bool external_transport; |
| 238 | bool send; |
| 239 | bool playout; |
| 240 | float volume_scale; |
| 241 | float volume_pan_left; |
| 242 | float volume_pan_right; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 243 | bool vad; |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 244 | bool codec_fec; |
buildbot@webrtc.org | 5d639b3 | 2014-09-10 07:57:12 +0000 | [diff] [blame] | 245 | int max_encoding_bandwidth; |
minyue@webrtc.org | 9b2e114 | 2015-03-13 09:38:07 +0000 | [diff] [blame] | 246 | bool opus_dtx; |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 247 | bool red; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 248 | bool nack; |
| 249 | bool media_processor_registered; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 250 | bool rx_agc_enabled; |
| 251 | webrtc::AgcModes rx_agc_mode; |
| 252 | webrtc::AgcConfig rx_agc_config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 253 | int cn8_type; |
| 254 | int cn16_type; |
| 255 | int dtmf_type; |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 256 | int red_type; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 257 | int nack_max_packets; |
| 258 | uint32 send_ssrc; |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 259 | int send_audio_level_ext_; |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 260 | int receive_audio_level_ext_; |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 261 | int send_absolute_sender_time_ext_; |
| 262 | int receive_absolute_sender_time_ext_; |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 263 | int associate_send_channel; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 264 | DtmfInfo dtmf_info; |
| 265 | std::vector<webrtc::CodecInst> recv_codecs; |
| 266 | webrtc::CodecInst send_codec; |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 267 | webrtc::PacketTime last_rtp_packet_time; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 268 | std::list<std::string> packets; |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 269 | int neteq_capacity; |
Henrik Lundin | 5263b3c | 2015-06-01 10:29:41 +0200 | [diff] [blame] | 270 | bool neteq_fast_accelerate; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 271 | }; |
| 272 | |
| 273 | FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs, |
| 274 | int num_codecs) |
| 275 | : inited_(false), |
| 276 | last_channel_(-1), |
| 277 | fail_create_channel_(false), |
| 278 | codecs_(codecs), |
| 279 | num_codecs_(num_codecs), |
wu@webrtc.org | 05e7b44 | 2014-04-01 17:44:24 +0000 | [diff] [blame] | 280 | num_set_send_codecs_(0), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 281 | ec_enabled_(false), |
| 282 | ec_metrics_enabled_(false), |
| 283 | cng_enabled_(false), |
| 284 | ns_enabled_(false), |
| 285 | agc_enabled_(false), |
| 286 | highpass_filter_enabled_(false), |
| 287 | stereo_swapping_enabled_(false), |
| 288 | typing_detection_enabled_(false), |
| 289 | ec_mode_(webrtc::kEcDefault), |
| 290 | aecm_mode_(webrtc::kAecmSpeakerphone), |
| 291 | ns_mode_(webrtc::kNsDefault), |
| 292 | agc_mode_(webrtc::kAgcDefault), |
| 293 | observer_(NULL), |
| 294 | playout_fail_channel_(-1), |
| 295 | send_fail_channel_(-1), |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 296 | recording_sample_rate_(-1), |
| 297 | playout_sample_rate_(-1), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 298 | media_processor_(NULL) { |
| 299 | memset(&agc_config_, 0, sizeof(agc_config_)); |
| 300 | } |
| 301 | ~FakeWebRtcVoiceEngine() { |
| 302 | // Ought to have all been deleted by the WebRtcVoiceMediaChannel |
| 303 | // destructors, but just in case ... |
| 304 | for (std::map<int, Channel*>::const_iterator i = channels_.begin(); |
| 305 | i != channels_.end(); ++i) { |
| 306 | delete i->second; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | bool IsExternalMediaProcessorRegistered() const { |
| 311 | return media_processor_ != NULL; |
| 312 | } |
| 313 | bool IsInited() const { return inited_; } |
| 314 | int GetLastChannel() const { return last_channel_; } |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 315 | int GetChannelFromLocalSsrc(uint32 local_ssrc) const { |
| 316 | for (std::map<int, Channel*>::const_iterator iter = channels_.begin(); |
| 317 | iter != channels_.end(); ++iter) { |
| 318 | if (local_ssrc == iter->second->send_ssrc) |
| 319 | return iter->first; |
| 320 | } |
| 321 | return -1; |
| 322 | } |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 323 | int GetNumChannels() const { return static_cast<int>(channels_.size()); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 324 | bool GetPlayout(int channel) { |
| 325 | return channels_[channel]->playout; |
| 326 | } |
| 327 | bool GetSend(int channel) { |
| 328 | return channels_[channel]->send; |
| 329 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 330 | bool GetVAD(int channel) { |
| 331 | return channels_[channel]->vad; |
| 332 | } |
Minyue Li | 7100dcd | 2015-03-27 05:05:59 +0100 | [diff] [blame] | 333 | bool GetOpusDtx(int channel) { |
| 334 | return channels_[channel]->opus_dtx; |
| 335 | } |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 336 | bool GetRED(int channel) { |
| 337 | return channels_[channel]->red; |
| 338 | } |
| 339 | bool GetCodecFEC(int channel) { |
| 340 | return channels_[channel]->codec_fec; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 341 | } |
buildbot@webrtc.org | 5d639b3 | 2014-09-10 07:57:12 +0000 | [diff] [blame] | 342 | int GetMaxEncodingBandwidth(int channel) { |
| 343 | return channels_[channel]->max_encoding_bandwidth; |
| 344 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 345 | bool GetNACK(int channel) { |
| 346 | return channels_[channel]->nack; |
| 347 | } |
| 348 | int GetNACKMaxPackets(int channel) { |
| 349 | return channels_[channel]->nack_max_packets; |
| 350 | } |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 351 | const webrtc::PacketTime& GetLastRtpPacketTime(int channel) { |
| 352 | WEBRTC_ASSERT_CHANNEL(channel); |
| 353 | return channels_[channel]->last_rtp_packet_time; |
| 354 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 355 | int GetSendCNPayloadType(int channel, bool wideband) { |
| 356 | return (wideband) ? |
| 357 | channels_[channel]->cn16_type : |
| 358 | channels_[channel]->cn8_type; |
| 359 | } |
| 360 | int GetSendTelephoneEventPayloadType(int channel) { |
| 361 | return channels_[channel]->dtmf_type; |
| 362 | } |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 363 | int GetSendREDPayloadType(int channel) { |
| 364 | return channels_[channel]->red_type; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 365 | } |
| 366 | bool CheckPacket(int channel, const void* data, size_t len) { |
| 367 | bool result = !CheckNoPacket(channel); |
| 368 | if (result) { |
| 369 | std::string packet = channels_[channel]->packets.front(); |
| 370 | result = (packet == std::string(static_cast<const char*>(data), len)); |
| 371 | channels_[channel]->packets.pop_front(); |
| 372 | } |
| 373 | return result; |
| 374 | } |
| 375 | bool CheckNoPacket(int channel) { |
| 376 | return channels_[channel]->packets.empty(); |
| 377 | } |
| 378 | void TriggerCallbackOnError(int channel_num, int err_code) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 379 | RTC_DCHECK(observer_ != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 380 | observer_->CallbackOnError(channel_num, err_code); |
| 381 | } |
| 382 | void set_playout_fail_channel(int channel) { |
| 383 | playout_fail_channel_ = channel; |
| 384 | } |
| 385 | void set_send_fail_channel(int channel) { |
| 386 | send_fail_channel_ = channel; |
| 387 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 388 | void set_fail_create_channel(bool fail_create_channel) { |
| 389 | fail_create_channel_ = fail_create_channel; |
| 390 | } |
| 391 | void TriggerProcessPacket(MediaProcessorDirection direction) { |
| 392 | webrtc::ProcessingTypes pt = |
| 393 | (direction == cricket::MPD_TX) ? |
| 394 | webrtc::kRecordingPerChannel : webrtc::kPlaybackAllChannelsMixed; |
| 395 | if (media_processor_ != NULL) { |
| 396 | media_processor_->Process(0, |
| 397 | pt, |
| 398 | NULL, |
| 399 | 0, |
| 400 | 0, |
| 401 | true); |
| 402 | } |
| 403 | } |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 404 | int AddChannel(const webrtc::Config& config) { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 405 | if (fail_create_channel_) { |
| 406 | return -1; |
| 407 | } |
buildbot@webrtc.org | af6640f | 2014-04-28 21:31:51 +0000 | [diff] [blame] | 408 | Channel* ch = new Channel(); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 409 | for (int i = 0; i < NumOfCodecs(); ++i) { |
| 410 | webrtc::CodecInst codec; |
| 411 | GetCodec(i, codec); |
| 412 | ch->recv_codecs.push_back(codec); |
| 413 | } |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 414 | if (config.Get<webrtc::NetEqCapacityConfig>().enabled) { |
| 415 | ch->neteq_capacity = config.Get<webrtc::NetEqCapacityConfig>().capacity; |
| 416 | } |
Henrik Lundin | 5263b3c | 2015-06-01 10:29:41 +0200 | [diff] [blame] | 417 | ch->neteq_fast_accelerate = |
| 418 | config.Get<webrtc::NetEqFastAccelerate>().enabled; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 419 | channels_[++last_channel_] = ch; |
| 420 | return last_channel_; |
| 421 | } |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 422 | int GetSendRtpExtensionId(int channel, const std::string& extension) { |
| 423 | WEBRTC_ASSERT_CHANNEL(channel); |
| 424 | if (extension == kRtpAudioLevelHeaderExtension) { |
| 425 | return channels_[channel]->send_audio_level_ext_; |
| 426 | } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) { |
| 427 | return channels_[channel]->send_absolute_sender_time_ext_; |
| 428 | } |
| 429 | return -1; |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 430 | } |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 431 | int GetReceiveRtpExtensionId(int channel, const std::string& extension) { |
| 432 | WEBRTC_ASSERT_CHANNEL(channel); |
| 433 | if (extension == kRtpAudioLevelHeaderExtension) { |
| 434 | return channels_[channel]->receive_audio_level_ext_; |
| 435 | } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) { |
| 436 | return channels_[channel]->receive_absolute_sender_time_ext_; |
| 437 | } |
| 438 | return -1; |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 439 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 440 | |
wu@webrtc.org | 05e7b44 | 2014-04-01 17:44:24 +0000 | [diff] [blame] | 441 | int GetNumSetSendCodecs() const { return num_set_send_codecs_; } |
| 442 | |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 443 | int GetAssociateSendChannel(int channel) { |
| 444 | return channels_[channel]->associate_send_channel; |
| 445 | } |
| 446 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 447 | WEBRTC_STUB(Release, ()); |
| 448 | |
| 449 | // webrtc::VoEBase |
| 450 | WEBRTC_FUNC(RegisterVoiceEngineObserver, ( |
| 451 | webrtc::VoiceEngineObserver& observer)) { |
| 452 | observer_ = &observer; |
| 453 | return 0; |
| 454 | } |
| 455 | WEBRTC_STUB(DeRegisterVoiceEngineObserver, ()); |
| 456 | WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm, |
| 457 | webrtc::AudioProcessing* audioproc)) { |
| 458 | inited_ = true; |
| 459 | return 0; |
| 460 | } |
| 461 | WEBRTC_FUNC(Terminate, ()) { |
| 462 | inited_ = false; |
| 463 | return 0; |
| 464 | } |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 465 | webrtc::AudioProcessing* audio_processing() override { |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 466 | return &audio_processing_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 467 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 468 | WEBRTC_FUNC(CreateChannel, ()) { |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 469 | webrtc::Config empty_config; |
| 470 | return AddChannel(empty_config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 471 | } |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 472 | WEBRTC_FUNC(CreateChannel, (const webrtc::Config& config)) { |
| 473 | return AddChannel(config); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 474 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 475 | WEBRTC_FUNC(DeleteChannel, (int channel)) { |
| 476 | WEBRTC_CHECK_CHANNEL(channel); |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 477 | for (const auto& ch : channels_) { |
| 478 | if (ch.second->associate_send_channel == channel) { |
| 479 | ch.second->associate_send_channel = -1; |
| 480 | } |
| 481 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 482 | delete channels_[channel]; |
| 483 | channels_.erase(channel); |
| 484 | return 0; |
| 485 | } |
| 486 | WEBRTC_STUB(StartReceive, (int channel)); |
| 487 | WEBRTC_FUNC(StartPlayout, (int channel)) { |
| 488 | if (playout_fail_channel_ != channel) { |
| 489 | WEBRTC_CHECK_CHANNEL(channel); |
| 490 | channels_[channel]->playout = true; |
| 491 | return 0; |
| 492 | } else { |
| 493 | // When playout_fail_channel_ == channel, fail the StartPlayout on this |
| 494 | // channel. |
| 495 | return -1; |
| 496 | } |
| 497 | } |
| 498 | WEBRTC_FUNC(StartSend, (int channel)) { |
| 499 | if (send_fail_channel_ != channel) { |
| 500 | WEBRTC_CHECK_CHANNEL(channel); |
| 501 | channels_[channel]->send = true; |
| 502 | return 0; |
| 503 | } else { |
| 504 | // When send_fail_channel_ == channel, fail the StartSend on this |
| 505 | // channel. |
| 506 | return -1; |
| 507 | } |
| 508 | } |
| 509 | WEBRTC_STUB(StopReceive, (int channel)); |
| 510 | WEBRTC_FUNC(StopPlayout, (int channel)) { |
| 511 | WEBRTC_CHECK_CHANNEL(channel); |
| 512 | channels_[channel]->playout = false; |
| 513 | return 0; |
| 514 | } |
| 515 | WEBRTC_FUNC(StopSend, (int channel)) { |
| 516 | WEBRTC_CHECK_CHANNEL(channel); |
| 517 | channels_[channel]->send = false; |
| 518 | return 0; |
| 519 | } |
| 520 | WEBRTC_STUB(GetVersion, (char version[1024])); |
| 521 | WEBRTC_STUB(LastError, ()); |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 522 | WEBRTC_FUNC(AssociateSendChannel, (int channel, |
| 523 | int accociate_send_channel)) { |
| 524 | WEBRTC_CHECK_CHANNEL(channel); |
| 525 | channels_[channel]->associate_send_channel = accociate_send_channel; |
| 526 | return 0; |
| 527 | } |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 528 | webrtc::RtcEventLog* GetEventLog() { return nullptr; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 529 | |
| 530 | // webrtc::VoECodec |
| 531 | WEBRTC_FUNC(NumOfCodecs, ()) { |
| 532 | return num_codecs_; |
| 533 | } |
| 534 | WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) { |
| 535 | if (index < 0 || index >= NumOfCodecs()) { |
| 536 | return -1; |
| 537 | } |
| 538 | const cricket::AudioCodec& c(*codecs_[index]); |
| 539 | codec.pltype = c.id; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 540 | rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 541 | codec.plfreq = c.clockrate; |
| 542 | codec.pacsize = 0; |
| 543 | codec.channels = c.channels; |
| 544 | codec.rate = c.bitrate; |
| 545 | return 0; |
| 546 | } |
| 547 | WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) { |
| 548 | WEBRTC_CHECK_CHANNEL(channel); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 549 | // To match the behavior of the real implementation. |
| 550 | if (_stricmp(codec.plname, "telephone-event") == 0 || |
| 551 | _stricmp(codec.plname, "audio/telephone-event") == 0 || |
| 552 | _stricmp(codec.plname, "CN") == 0 || |
| 553 | _stricmp(codec.plname, "red") == 0 ) { |
| 554 | return -1; |
| 555 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 556 | channels_[channel]->send_codec = codec; |
wu@webrtc.org | 05e7b44 | 2014-04-01 17:44:24 +0000 | [diff] [blame] | 557 | ++num_set_send_codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 558 | return 0; |
| 559 | } |
| 560 | WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) { |
| 561 | WEBRTC_CHECK_CHANNEL(channel); |
| 562 | codec = channels_[channel]->send_codec; |
| 563 | return 0; |
| 564 | } |
Ivo Creusen | adf89b7 | 2015-04-29 16:03:33 +0200 | [diff] [blame] | 565 | WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps)); |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 566 | WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) { |
| 567 | WEBRTC_CHECK_CHANNEL(channel); |
| 568 | const Channel* c = channels_[channel]; |
| 569 | for (std::list<std::string>::const_iterator it_packet = c->packets.begin(); |
| 570 | it_packet != c->packets.end(); ++it_packet) { |
| 571 | int pltype; |
| 572 | if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) { |
| 573 | continue; |
| 574 | } |
| 575 | for (std::vector<webrtc::CodecInst>::const_iterator it_codec = |
| 576 | c->recv_codecs.begin(); it_codec != c->recv_codecs.end(); |
| 577 | ++it_codec) { |
| 578 | if (it_codec->pltype == pltype) { |
| 579 | codec = *it_codec; |
| 580 | return 0; |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | return -1; |
| 585 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 586 | WEBRTC_FUNC(SetRecPayloadType, (int channel, |
| 587 | const webrtc::CodecInst& codec)) { |
| 588 | WEBRTC_CHECK_CHANNEL(channel); |
| 589 | Channel* ch = channels_[channel]; |
| 590 | if (ch->playout) |
| 591 | return -1; // Channel is in use. |
| 592 | // Check if something else already has this slot. |
| 593 | if (codec.pltype != -1) { |
| 594 | for (std::vector<webrtc::CodecInst>::iterator it = |
| 595 | ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) { |
| 596 | if (it->pltype == codec.pltype && |
| 597 | _stricmp(it->plname, codec.plname) != 0) { |
| 598 | return -1; |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | // Otherwise try to find this codec and update its payload type. |
| 603 | for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin(); |
| 604 | it != ch->recv_codecs.end(); ++it) { |
| 605 | if (strcmp(it->plname, codec.plname) == 0 && |
| 606 | it->plfreq == codec.plfreq) { |
| 607 | it->pltype = codec.pltype; |
| 608 | it->channels = codec.channels; |
| 609 | return 0; |
| 610 | } |
| 611 | } |
| 612 | return -1; // not found |
| 613 | } |
| 614 | WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type, |
| 615 | webrtc::PayloadFrequencies frequency)) { |
| 616 | WEBRTC_CHECK_CHANNEL(channel); |
| 617 | if (frequency == webrtc::kFreq8000Hz) { |
| 618 | channels_[channel]->cn8_type = type; |
| 619 | } else if (frequency == webrtc::kFreq16000Hz) { |
| 620 | channels_[channel]->cn16_type = type; |
| 621 | } |
| 622 | return 0; |
| 623 | } |
| 624 | WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) { |
| 625 | WEBRTC_CHECK_CHANNEL(channel); |
| 626 | Channel* ch = channels_[channel]; |
| 627 | for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin(); |
| 628 | it != ch->recv_codecs.end(); ++it) { |
| 629 | if (strcmp(it->plname, codec.plname) == 0 && |
| 630 | it->plfreq == codec.plfreq && |
| 631 | it->channels == codec.channels && |
| 632 | it->pltype != -1) { |
| 633 | codec.pltype = it->pltype; |
| 634 | return 0; |
| 635 | } |
| 636 | } |
| 637 | return -1; // not found |
| 638 | } |
| 639 | WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode, |
| 640 | bool disableDTX)) { |
| 641 | WEBRTC_CHECK_CHANNEL(channel); |
| 642 | if (channels_[channel]->send_codec.channels == 2) { |
| 643 | // Replicating VoE behavior; VAD cannot be enabled for stereo. |
| 644 | return -1; |
| 645 | } |
| 646 | channels_[channel]->vad = enable; |
| 647 | return 0; |
| 648 | } |
| 649 | WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled, |
| 650 | webrtc::VadModes& mode, bool& disabledDTX)); |
buildbot@webrtc.org | 5d639b3 | 2014-09-10 07:57:12 +0000 | [diff] [blame] | 651 | |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 652 | WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) { |
| 653 | WEBRTC_CHECK_CHANNEL(channel); |
buildbot@webrtc.org | 5d639b3 | 2014-09-10 07:57:12 +0000 | [diff] [blame] | 654 | if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) { |
buildbot@webrtc.org | 3ffa1f9 | 2014-07-02 19:51:26 +0000 | [diff] [blame] | 655 | // Return -1 if current send codec is not Opus. |
| 656 | // TODO(minyue): Excludes other codecs if they support inband FEC. |
| 657 | return -1; |
| 658 | } |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 659 | channels_[channel]->codec_fec = enable; |
| 660 | return 0; |
| 661 | } |
| 662 | WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) { |
| 663 | WEBRTC_CHECK_CHANNEL(channel); |
| 664 | enable = channels_[channel]->codec_fec; |
| 665 | return 0; |
| 666 | } |
buildbot@webrtc.org | 5d639b3 | 2014-09-10 07:57:12 +0000 | [diff] [blame] | 667 | |
| 668 | WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) { |
| 669 | WEBRTC_CHECK_CHANNEL(channel); |
| 670 | if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) { |
| 671 | // Return -1 if current send codec is not Opus. |
| 672 | return -1; |
| 673 | } |
| 674 | if (frequency_hz <= 8000) |
| 675 | channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb; |
| 676 | else if (frequency_hz <= 12000) |
| 677 | channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb; |
| 678 | else if (frequency_hz <= 16000) |
| 679 | channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb; |
| 680 | else if (frequency_hz <= 24000) |
| 681 | channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb; |
| 682 | else |
| 683 | channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb; |
| 684 | return 0; |
| 685 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 686 | |
minyue@webrtc.org | 9b2e114 | 2015-03-13 09:38:07 +0000 | [diff] [blame] | 687 | WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) { |
| 688 | WEBRTC_CHECK_CHANNEL(channel); |
| 689 | if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) { |
| 690 | // Return -1 if current send codec is not Opus. |
| 691 | return -1; |
| 692 | } |
| 693 | channels_[channel]->opus_dtx = enable_dtx; |
| 694 | return 0; |
| 695 | } |
| 696 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 697 | // webrtc::VoEDtmf |
| 698 | WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code, |
| 699 | bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) { |
| 700 | channels_[channel]->dtmf_info.dtmf_event_code = event_code; |
| 701 | channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band; |
| 702 | channels_[channel]->dtmf_info.dtmf_length_ms = length_ms; |
| 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | WEBRTC_FUNC(SetSendTelephoneEventPayloadType, |
| 707 | (int channel, unsigned char type)) { |
| 708 | channels_[channel]->dtmf_type = type; |
| 709 | return 0; |
| 710 | }; |
| 711 | WEBRTC_STUB(GetSendTelephoneEventPayloadType, |
| 712 | (int channel, unsigned char& type)); |
| 713 | |
| 714 | WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback)); |
| 715 | WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 716 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 717 | WEBRTC_FUNC(PlayDtmfTone, |
| 718 | (int event_code, int length_ms = 200, int attenuation_db = 10)) { |
| 719 | dtmf_info_.dtmf_event_code = event_code; |
| 720 | dtmf_info_.dtmf_length_ms = length_ms; |
| 721 | return 0; |
| 722 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 723 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 724 | // webrtc::VoEHardware |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 725 | WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) { |
| 726 | return GetNumDevices(num); |
| 727 | } |
| 728 | WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) { |
| 729 | return GetNumDevices(num); |
| 730 | } |
| 731 | WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) { |
| 732 | return GetDeviceName(i, name, guid); |
| 733 | } |
| 734 | WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) { |
| 735 | return GetDeviceName(i, name, guid); |
| 736 | } |
| 737 | WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel)); |
| 738 | WEBRTC_STUB(SetPlayoutDevice, (int)); |
| 739 | WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers)); |
| 740 | WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&)); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 741 | WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) { |
| 742 | recording_sample_rate_ = samples_per_sec; |
| 743 | return 0; |
| 744 | } |
| 745 | WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) { |
| 746 | *samples_per_sec = recording_sample_rate_; |
| 747 | return 0; |
| 748 | } |
| 749 | WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) { |
| 750 | playout_sample_rate_ = samples_per_sec; |
| 751 | return 0; |
| 752 | } |
| 753 | WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) { |
| 754 | *samples_per_sec = playout_sample_rate_; |
| 755 | return 0; |
| 756 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 757 | WEBRTC_STUB(EnableBuiltInAEC, (bool enable)); |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 758 | virtual bool BuiltInAECIsAvailable() const { return false; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 759 | |
| 760 | // webrtc::VoENetEqStats |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 761 | WEBRTC_FUNC(GetNetworkStatistics, (int channel, |
| 762 | webrtc::NetworkStatistics& ns)) { |
| 763 | WEBRTC_CHECK_CHANNEL(channel); |
| 764 | memcpy(&ns, &kNetStats, sizeof(webrtc::NetworkStatistics)); |
| 765 | return 0; |
| 766 | } |
| 767 | |
wu@webrtc.org | 24301a6 | 2013-12-13 19:17:43 +0000 | [diff] [blame] | 768 | WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel, |
| 769 | webrtc::AudioDecodingCallStats*)) { |
| 770 | WEBRTC_CHECK_CHANNEL(channel); |
| 771 | return 0; |
| 772 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 773 | |
| 774 | // webrtc::VoENetwork |
| 775 | WEBRTC_FUNC(RegisterExternalTransport, (int channel, |
| 776 | webrtc::Transport& transport)) { |
| 777 | WEBRTC_CHECK_CHANNEL(channel); |
| 778 | channels_[channel]->external_transport = true; |
| 779 | return 0; |
| 780 | } |
| 781 | WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) { |
| 782 | WEBRTC_CHECK_CHANNEL(channel); |
| 783 | channels_[channel]->external_transport = false; |
| 784 | return 0; |
| 785 | } |
| 786 | WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 787 | size_t length)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 788 | WEBRTC_CHECK_CHANNEL(channel); |
| 789 | if (!channels_[channel]->external_transport) return -1; |
| 790 | channels_[channel]->packets.push_back( |
| 791 | std::string(static_cast<const char*>(data), length)); |
| 792 | return 0; |
| 793 | } |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 794 | WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 795 | size_t length, |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 796 | const webrtc::PacketTime& packet_time)) { |
| 797 | WEBRTC_CHECK_CHANNEL(channel); |
| 798 | if (ReceivedRTPPacket(channel, data, length) == -1) { |
| 799 | return -1; |
| 800 | } |
| 801 | channels_[channel]->last_rtp_packet_time = packet_time; |
| 802 | return 0; |
| 803 | } |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 804 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 805 | WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 806 | size_t length)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 807 | |
| 808 | // webrtc::VoERTP_RTCP |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 809 | WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) { |
| 810 | WEBRTC_CHECK_CHANNEL(channel); |
| 811 | channels_[channel]->send_ssrc = ssrc; |
| 812 | return 0; |
| 813 | } |
| 814 | WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) { |
| 815 | WEBRTC_CHECK_CHANNEL(channel); |
| 816 | ssrc = channels_[channel]->send_ssrc; |
| 817 | return 0; |
| 818 | } |
| 819 | WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc)); |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 820 | WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable, |
| 821 | unsigned char id)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 822 | WEBRTC_CHECK_CHANNEL(channel); |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 823 | WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id); |
| 824 | channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 825 | return 0; |
| 826 | } |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 827 | WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable, |
| 828 | unsigned char id)) { |
| 829 | WEBRTC_CHECK_CHANNEL(channel); |
| 830 | WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id); |
| 831 | channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1; |
| 832 | return 0; |
| 833 | } |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 834 | WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable, |
| 835 | unsigned char id)) { |
| 836 | WEBRTC_CHECK_CHANNEL(channel); |
| 837 | WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id); |
| 838 | channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1; |
| 839 | return 0; |
| 840 | } |
| 841 | WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable, |
| 842 | unsigned char id)) { |
| 843 | WEBRTC_CHECK_CHANNEL(channel); |
| 844 | WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id); |
| 845 | channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1; |
| 846 | return 0; |
| 847 | } |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 848 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 849 | WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable)); |
| 850 | WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled)); |
| 851 | WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256])); |
| 852 | WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256])); |
| 853 | WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname)); |
| 854 | WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh, |
| 855 | unsigned int& NTPLow, |
| 856 | unsigned int& timestamp, |
| 857 | unsigned int& playoutTimestamp, |
| 858 | unsigned int* jitter, |
| 859 | unsigned short* fractionLost)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 860 | WEBRTC_FUNC(GetRemoteRTCPReportBlocks, |
| 861 | (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) { |
| 862 | WEBRTC_CHECK_CHANNEL(channel); |
| 863 | webrtc::ReportBlock block; |
| 864 | block.source_SSRC = channels_[channel]->send_ssrc; |
| 865 | webrtc::CodecInst send_codec = channels_[channel]->send_codec; |
| 866 | if (send_codec.pltype >= 0) { |
| 867 | block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256); |
| 868 | if (send_codec.plfreq / 1000 > 0) { |
| 869 | block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000); |
| 870 | } |
| 871 | block.cumulative_num_packets_lost = kIntStatValue; |
| 872 | block.extended_highest_sequence_number = kIntStatValue; |
| 873 | receive_blocks->push_back(block); |
| 874 | } |
| 875 | return 0; |
| 876 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 877 | WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs, |
| 878 | unsigned int& maxJitterMs, |
| 879 | unsigned int& discardedPackets)); |
| 880 | WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) { |
| 881 | WEBRTC_CHECK_CHANNEL(channel); |
| 882 | stats.fractionLost = static_cast<int16>(kIntStatValue); |
| 883 | stats.cumulativeLost = kIntStatValue; |
| 884 | stats.extendedMax = kIntStatValue; |
| 885 | stats.jitterSamples = kIntStatValue; |
| 886 | stats.rttMs = kIntStatValue; |
| 887 | stats.bytesSent = kIntStatValue; |
| 888 | stats.packetsSent = kIntStatValue; |
| 889 | stats.bytesReceived = kIntStatValue; |
| 890 | stats.packetsReceived = kIntStatValue; |
| 891 | return 0; |
| 892 | } |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 893 | WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) { |
buildbot@webrtc.org | bfa758a | 2014-06-27 16:04:43 +0000 | [diff] [blame] | 894 | return SetFECStatus(channel, enable, redPayloadtype); |
| 895 | } |
buildbot@webrtc.org | bfa758a | 2014-06-27 16:04:43 +0000 | [diff] [blame] | 896 | // TODO(minyue): remove the below function when transition to SetREDStatus |
| 897 | // is finished. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 898 | WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) { |
| 899 | WEBRTC_CHECK_CHANNEL(channel); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 900 | channels_[channel]->red = enable; |
| 901 | channels_[channel]->red_type = redPayloadtype; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 902 | return 0; |
| 903 | } |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 904 | WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) { |
buildbot@webrtc.org | bfa758a | 2014-06-27 16:04:43 +0000 | [diff] [blame] | 905 | return GetFECStatus(channel, enable, redPayloadtype); |
| 906 | } |
buildbot@webrtc.org | bfa758a | 2014-06-27 16:04:43 +0000 | [diff] [blame] | 907 | // TODO(minyue): remove the below function when transition to GetREDStatus |
| 908 | // is finished. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 909 | WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) { |
| 910 | WEBRTC_CHECK_CHANNEL(channel); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 911 | enable = channels_[channel]->red; |
| 912 | redPayloadtype = channels_[channel]->red_type; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 913 | return 0; |
| 914 | } |
| 915 | WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) { |
| 916 | WEBRTC_CHECK_CHANNEL(channel); |
| 917 | channels_[channel]->nack = enable; |
| 918 | channels_[channel]->nack_max_packets = maxNoPackets; |
| 919 | return 0; |
| 920 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 921 | |
| 922 | // webrtc::VoEVideoSync |
| 923 | WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs)); |
| 924 | WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp)); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 925 | WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 926 | WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp)); |
| 927 | WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber)); |
| 928 | WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs)); |
| 929 | WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms)); |
| 930 | WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms, |
| 931 | int* playout_buffer_delay_ms)); |
| 932 | WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel)); |
| 933 | |
| 934 | // webrtc::VoEVolumeControl |
| 935 | WEBRTC_STUB(SetSpeakerVolume, (unsigned int)); |
| 936 | WEBRTC_STUB(GetSpeakerVolume, (unsigned int&)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 937 | WEBRTC_STUB(SetMicVolume, (unsigned int)); |
| 938 | WEBRTC_STUB(GetMicVolume, (unsigned int&)); |
| 939 | WEBRTC_STUB(SetInputMute, (int, bool)); |
| 940 | WEBRTC_STUB(GetInputMute, (int, bool&)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 941 | WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&)); |
| 942 | WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&)); |
| 943 | WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&)); |
| 944 | WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&)); |
| 945 | WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) { |
| 946 | WEBRTC_CHECK_CHANNEL(channel); |
| 947 | channels_[channel]->volume_scale= scale; |
| 948 | return 0; |
| 949 | } |
| 950 | WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) { |
| 951 | WEBRTC_CHECK_CHANNEL(channel); |
| 952 | scale = channels_[channel]->volume_scale; |
| 953 | return 0; |
| 954 | } |
| 955 | WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) { |
| 956 | WEBRTC_CHECK_CHANNEL(channel); |
| 957 | channels_[channel]->volume_pan_left = left; |
| 958 | channels_[channel]->volume_pan_right = right; |
| 959 | return 0; |
| 960 | } |
| 961 | WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) { |
| 962 | WEBRTC_CHECK_CHANNEL(channel); |
| 963 | left = channels_[channel]->volume_pan_left; |
| 964 | right = channels_[channel]->volume_pan_right; |
| 965 | return 0; |
| 966 | } |
| 967 | |
| 968 | // webrtc::VoEAudioProcessing |
| 969 | WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) { |
| 970 | ns_enabled_ = enable; |
| 971 | ns_mode_ = mode; |
| 972 | return 0; |
| 973 | } |
| 974 | WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) { |
| 975 | enabled = ns_enabled_; |
| 976 | mode = ns_mode_; |
| 977 | return 0; |
| 978 | } |
| 979 | |
| 980 | WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) { |
| 981 | agc_enabled_ = enable; |
| 982 | agc_mode_ = mode; |
| 983 | return 0; |
| 984 | } |
| 985 | WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) { |
| 986 | enabled = agc_enabled_; |
| 987 | mode = agc_mode_; |
| 988 | return 0; |
| 989 | } |
| 990 | |
| 991 | WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) { |
| 992 | agc_config_ = config; |
| 993 | return 0; |
| 994 | } |
| 995 | WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) { |
| 996 | config = agc_config_; |
| 997 | return 0; |
| 998 | } |
| 999 | WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) { |
| 1000 | ec_enabled_ = enable; |
| 1001 | ec_mode_ = mode; |
| 1002 | return 0; |
| 1003 | } |
| 1004 | WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) { |
| 1005 | enabled = ec_enabled_; |
| 1006 | mode = ec_mode_; |
| 1007 | return 0; |
| 1008 | } |
| 1009 | WEBRTC_STUB(EnableDriftCompensation, (bool enable)) |
| 1010 | WEBRTC_BOOL_STUB(DriftCompensationEnabled, ()) |
| 1011 | WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset)) |
| 1012 | WEBRTC_STUB(DelayOffsetMs, ()); |
| 1013 | WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) { |
| 1014 | aecm_mode_ = mode; |
| 1015 | cng_enabled_ = enableCNG; |
| 1016 | return 0; |
| 1017 | } |
| 1018 | WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) { |
| 1019 | mode = aecm_mode_; |
| 1020 | enabledCNG = cng_enabled_; |
| 1021 | return 0; |
| 1022 | } |
| 1023 | WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode)); |
| 1024 | WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled, |
| 1025 | webrtc::NsModes& mode)); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1026 | WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable, |
| 1027 | webrtc::AgcModes mode)) { |
| 1028 | channels_[channel]->rx_agc_enabled = enable; |
| 1029 | channels_[channel]->rx_agc_mode = mode; |
| 1030 | return 0; |
| 1031 | } |
| 1032 | WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled, |
| 1033 | webrtc::AgcModes& mode)) { |
| 1034 | enabled = channels_[channel]->rx_agc_enabled; |
| 1035 | mode = channels_[channel]->rx_agc_mode; |
| 1036 | return 0; |
| 1037 | } |
| 1038 | |
| 1039 | WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) { |
| 1040 | channels_[channel]->rx_agc_config = config; |
| 1041 | return 0; |
| 1042 | } |
| 1043 | WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) { |
| 1044 | config = channels_[channel]->rx_agc_config; |
| 1045 | return 0; |
| 1046 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1047 | |
| 1048 | WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&)); |
| 1049 | WEBRTC_STUB(DeRegisterRxVadObserver, (int channel)); |
| 1050 | WEBRTC_STUB(VoiceActivityIndicator, (int channel)); |
| 1051 | WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) { |
| 1052 | ec_metrics_enabled_ = enable; |
| 1053 | return 0; |
| 1054 | } |
| 1055 | WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) { |
| 1056 | enabled = ec_metrics_enabled_; |
| 1057 | return 0; |
| 1058 | } |
| 1059 | WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP)); |
bjornv@webrtc.org | cc64a9c | 2015-02-05 12:52:44 +0000 | [diff] [blame] | 1060 | WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std, |
| 1061 | float& fraction_poor_delays)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1062 | |
| 1063 | WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8)); |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 1064 | WEBRTC_STUB(StartDebugRecording, (FILE* handle)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1065 | WEBRTC_STUB(StopDebugRecording, ()); |
| 1066 | |
| 1067 | WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) { |
| 1068 | typing_detection_enabled_ = enable; |
| 1069 | return 0; |
| 1070 | } |
| 1071 | WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) { |
| 1072 | enabled = typing_detection_enabled_; |
| 1073 | return 0; |
| 1074 | } |
| 1075 | |
| 1076 | WEBRTC_STUB(TimeSinceLastTyping, (int& seconds)); |
| 1077 | WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow, |
| 1078 | int costPerTyping, |
| 1079 | int reportingThreshold, |
| 1080 | int penaltyDecay, |
| 1081 | int typeEventDelay)); |
| 1082 | int EnableHighPassFilter(bool enable) { |
| 1083 | highpass_filter_enabled_ = enable; |
| 1084 | return 0; |
| 1085 | } |
| 1086 | bool IsHighPassFilterEnabled() { |
| 1087 | return highpass_filter_enabled_; |
| 1088 | } |
| 1089 | bool IsStereoChannelSwappingEnabled() { |
| 1090 | return stereo_swapping_enabled_; |
| 1091 | } |
| 1092 | void EnableStereoChannelSwapping(bool enable) { |
| 1093 | stereo_swapping_enabled_ = enable; |
| 1094 | } |
| 1095 | bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) { |
| 1096 | return (channels_[channel]->dtmf_info.dtmf_event_code == event_code && |
| 1097 | channels_[channel]->dtmf_info.dtmf_out_of_band == true && |
| 1098 | channels_[channel]->dtmf_info.dtmf_length_ms == length_ms); |
| 1099 | } |
| 1100 | bool WasPlayDtmfToneCalled(int event_code, int length_ms) { |
| 1101 | return (dtmf_info_.dtmf_event_code == event_code && |
| 1102 | dtmf_info_.dtmf_length_ms == length_ms); |
| 1103 | } |
| 1104 | // webrtc::VoEExternalMedia |
| 1105 | WEBRTC_FUNC(RegisterExternalMediaProcessing, |
| 1106 | (int channel, webrtc::ProcessingTypes type, |
| 1107 | webrtc::VoEMediaProcess& processObject)) { |
| 1108 | WEBRTC_CHECK_CHANNEL(channel); |
| 1109 | if (channels_[channel]->media_processor_registered) { |
| 1110 | return -1; |
| 1111 | } |
| 1112 | channels_[channel]->media_processor_registered = true; |
| 1113 | media_processor_ = &processObject; |
| 1114 | return 0; |
| 1115 | } |
| 1116 | WEBRTC_FUNC(DeRegisterExternalMediaProcessing, |
| 1117 | (int channel, webrtc::ProcessingTypes type)) { |
| 1118 | WEBRTC_CHECK_CHANNEL(channel); |
| 1119 | if (!channels_[channel]->media_processor_registered) { |
| 1120 | return -1; |
| 1121 | } |
| 1122 | channels_[channel]->media_processor_registered = false; |
| 1123 | media_processor_ = NULL; |
| 1124 | return 0; |
| 1125 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1126 | WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz, |
| 1127 | webrtc::AudioFrame* frame)); |
| 1128 | WEBRTC_STUB(SetExternalMixing, (int channel, bool enable)); |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 1129 | int GetNetEqCapacity() const { |
| 1130 | auto ch = channels_.find(last_channel_); |
| 1131 | ASSERT(ch != channels_.end()); |
| 1132 | return ch->second->neteq_capacity; |
| 1133 | } |
Henrik Lundin | 5263b3c | 2015-06-01 10:29:41 +0200 | [diff] [blame] | 1134 | bool GetNetEqFastAccelerate() const { |
| 1135 | auto ch = channels_.find(last_channel_); |
| 1136 | ASSERT(ch != channels_.end()); |
| 1137 | return ch->second->neteq_fast_accelerate; |
| 1138 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1139 | |
| 1140 | private: |
| 1141 | int GetNumDevices(int& num) { |
| 1142 | #ifdef WIN32 |
| 1143 | num = 1; |
| 1144 | #else |
| 1145 | // On non-Windows platforms VE adds a special entry for the default device, |
| 1146 | // so if there is one physical device then there are two entries in the |
| 1147 | // list. |
| 1148 | num = 2; |
| 1149 | #endif |
| 1150 | return 0; |
| 1151 | } |
| 1152 | |
| 1153 | int GetDeviceName(int i, char* name, char* guid) { |
| 1154 | const char *s; |
| 1155 | #ifdef WIN32 |
| 1156 | if (0 == i) { |
| 1157 | s = kFakeDeviceName; |
| 1158 | } else { |
| 1159 | return -1; |
| 1160 | } |
| 1161 | #else |
| 1162 | // See comment above. |
| 1163 | if (0 == i) { |
| 1164 | s = kFakeDefaultDeviceName; |
| 1165 | } else if (1 == i) { |
| 1166 | s = kFakeDeviceName; |
| 1167 | } else { |
| 1168 | return -1; |
| 1169 | } |
| 1170 | #endif |
| 1171 | strcpy(name, s); |
| 1172 | guid[0] = '\0'; |
| 1173 | return 0; |
| 1174 | } |
| 1175 | |
| 1176 | bool inited_; |
| 1177 | int last_channel_; |
| 1178 | std::map<int, Channel*> channels_; |
| 1179 | bool fail_create_channel_; |
| 1180 | const cricket::AudioCodec* const* codecs_; |
| 1181 | int num_codecs_; |
wu@webrtc.org | 05e7b44 | 2014-04-01 17:44:24 +0000 | [diff] [blame] | 1182 | int num_set_send_codecs_; // how many times we call SetSendCodec(). |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1183 | bool ec_enabled_; |
| 1184 | bool ec_metrics_enabled_; |
| 1185 | bool cng_enabled_; |
| 1186 | bool ns_enabled_; |
| 1187 | bool agc_enabled_; |
| 1188 | bool highpass_filter_enabled_; |
| 1189 | bool stereo_swapping_enabled_; |
| 1190 | bool typing_detection_enabled_; |
| 1191 | webrtc::EcModes ec_mode_; |
| 1192 | webrtc::AecmModes aecm_mode_; |
| 1193 | webrtc::NsModes ns_mode_; |
| 1194 | webrtc::AgcModes agc_mode_; |
| 1195 | webrtc::AgcConfig agc_config_; |
| 1196 | webrtc::VoiceEngineObserver* observer_; |
| 1197 | int playout_fail_channel_; |
| 1198 | int send_fail_channel_; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1199 | int recording_sample_rate_; |
| 1200 | int playout_sample_rate_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1201 | DtmfInfo dtmf_info_; |
| 1202 | webrtc::VoEMediaProcess* media_processor_; |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 1203 | FakeAudioProcessing audio_processing_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1204 | }; |
| 1205 | |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 1206 | #undef WEBRTC_CHECK_HEADER_EXTENSION_ID |
| 1207 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1208 | } // namespace cricket |
| 1209 | |
| 1210 | #endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_ |