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