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/webrtc/fakewebrtccommon.h" |
| 38 | #include "talk/media/webrtc/webrtcvoe.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 39 | #include "webrtc/base/basictypes.h" |
Fredrik Solenberg | d3ddc1b | 2015-05-07 17:07:34 +0200 | [diff] [blame] | 40 | #include "webrtc/base/checks.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 41 | #include "webrtc/base/gunit.h" |
| 42 | #include "webrtc/base/stringutils.h" |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 43 | #include "webrtc/config.h" |
solenberg | 26c8c91 | 2015-11-27 04:00:25 -0800 | [diff] [blame^] | 44 | #include "webrtc/modules/audio_coding/acm2/rent_a_codec.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 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 49 | static const char kFakeDefaultDeviceName[] = "Fake Default"; |
| 50 | static const int kFakeDefaultDeviceId = -1; |
| 51 | static const char kFakeDeviceName[] = "Fake Device"; |
| 52 | #ifdef WIN32 |
| 53 | static const int kFakeDeviceId = 0; |
| 54 | #else |
| 55 | static const int kFakeDeviceId = 1; |
| 56 | #endif |
| 57 | |
buildbot@webrtc.org | 5d639b3 | 2014-09-10 07:57:12 +0000 | [diff] [blame] | 58 | static const int kOpusBandwidthNb = 4000; |
| 59 | static const int kOpusBandwidthMb = 6000; |
| 60 | static const int kOpusBandwidthWb = 8000; |
| 61 | static const int kOpusBandwidthSwb = 12000; |
| 62 | static const int kOpusBandwidthFb = 20000; |
| 63 | |
Fredrik Solenberg | d3ddc1b | 2015-05-07 17:07:34 +0200 | [diff] [blame] | 64 | #define WEBRTC_CHECK_CHANNEL(channel) \ |
| 65 | if (channels_.find(channel) == channels_.end()) return -1; |
| 66 | |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 67 | class FakeAudioProcessing : public webrtc::AudioProcessing { |
| 68 | public: |
| 69 | FakeAudioProcessing() : experimental_ns_enabled_(false) {} |
| 70 | |
| 71 | WEBRTC_STUB(Initialize, ()) |
| 72 | WEBRTC_STUB(Initialize, ( |
| 73 | int input_sample_rate_hz, |
| 74 | int output_sample_rate_hz, |
| 75 | int reverse_sample_rate_hz, |
| 76 | webrtc::AudioProcessing::ChannelLayout input_layout, |
| 77 | webrtc::AudioProcessing::ChannelLayout output_layout, |
| 78 | webrtc::AudioProcessing::ChannelLayout reverse_layout)); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 79 | WEBRTC_STUB(Initialize, ( |
| 80 | const webrtc::ProcessingConfig& processing_config)); |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 81 | |
| 82 | WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) { |
| 83 | experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled; |
| 84 | } |
| 85 | |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 86 | WEBRTC_STUB_CONST(proc_sample_rate_hz, ()); |
| 87 | WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ()); |
| 88 | WEBRTC_STUB_CONST(num_input_channels, ()); |
| 89 | WEBRTC_STUB_CONST(num_output_channels, ()); |
| 90 | WEBRTC_STUB_CONST(num_reverse_channels, ()); |
| 91 | WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted)); |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 92 | WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame)); |
| 93 | WEBRTC_STUB(ProcessStream, ( |
| 94 | const float* const* src, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 95 | size_t samples_per_channel, |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 96 | int input_sample_rate_hz, |
| 97 | webrtc::AudioProcessing::ChannelLayout input_layout, |
| 98 | int output_sample_rate_hz, |
| 99 | webrtc::AudioProcessing::ChannelLayout output_layout, |
| 100 | float* const* dest)); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 101 | WEBRTC_STUB(ProcessStream, |
| 102 | (const float* const* src, |
| 103 | const webrtc::StreamConfig& input_config, |
| 104 | const webrtc::StreamConfig& output_config, |
| 105 | float* const* dest)); |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 106 | WEBRTC_STUB(AnalyzeReverseStream, (webrtc::AudioFrame* frame)); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 107 | WEBRTC_STUB(ProcessReverseStream, (webrtc::AudioFrame * frame)); |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 108 | WEBRTC_STUB(AnalyzeReverseStream, ( |
| 109 | const float* const* data, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 110 | size_t samples_per_channel, |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 111 | int sample_rate_hz, |
| 112 | webrtc::AudioProcessing::ChannelLayout layout)); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 113 | WEBRTC_STUB(ProcessReverseStream, |
| 114 | (const float* const* src, |
| 115 | const webrtc::StreamConfig& reverse_input_config, |
| 116 | const webrtc::StreamConfig& reverse_output_config, |
| 117 | float* const* dest)); |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 118 | WEBRTC_STUB(set_stream_delay_ms, (int delay)); |
| 119 | WEBRTC_STUB_CONST(stream_delay_ms, ()); |
| 120 | WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ()); |
| 121 | WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed)); |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 122 | WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset)); |
| 123 | WEBRTC_STUB_CONST(delay_offset_ms, ()); |
| 124 | WEBRTC_STUB(StartDebugRecording, (const char filename[kMaxFilenameSize])); |
| 125 | WEBRTC_STUB(StartDebugRecording, (FILE* handle)); |
| 126 | WEBRTC_STUB(StopDebugRecording, ()); |
Bjorn Volcker | 4e7aa43 | 2015-07-07 11:50:05 +0200 | [diff] [blame] | 127 | WEBRTC_VOID_STUB(UpdateHistogramsOnCallEnd, ()); |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 128 | webrtc::EchoCancellation* echo_cancellation() const override { return NULL; } |
| 129 | webrtc::EchoControlMobile* echo_control_mobile() const override { |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 130 | return NULL; |
| 131 | } |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 132 | webrtc::GainControl* gain_control() const override { return NULL; } |
| 133 | webrtc::HighPassFilter* high_pass_filter() const override { return NULL; } |
| 134 | webrtc::LevelEstimator* level_estimator() const override { return NULL; } |
| 135 | webrtc::NoiseSuppression* noise_suppression() const override { return NULL; } |
| 136 | webrtc::VoiceDetection* voice_detection() const override { return NULL; } |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 137 | |
| 138 | bool experimental_ns_enabled() { |
| 139 | return experimental_ns_enabled_; |
| 140 | } |
| 141 | |
| 142 | private: |
| 143 | bool experimental_ns_enabled_; |
| 144 | }; |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 145 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 146 | class FakeWebRtcVoiceEngine |
| 147 | : public webrtc::VoEAudioProcessing, |
| 148 | public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf, |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 149 | public webrtc::VoEHardware, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 150 | public webrtc::VoENetwork, public webrtc::VoERTP_RTCP, |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 151 | public webrtc::VoEVolumeControl { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 152 | public: |
| 153 | struct DtmfInfo { |
| 154 | DtmfInfo() |
| 155 | : dtmf_event_code(-1), |
| 156 | dtmf_out_of_band(false), |
| 157 | dtmf_length_ms(-1) {} |
| 158 | int dtmf_event_code; |
| 159 | bool dtmf_out_of_band; |
| 160 | int dtmf_length_ms; |
| 161 | }; |
| 162 | struct Channel { |
buildbot@webrtc.org | af6640f | 2014-04-28 21:31:51 +0000 | [diff] [blame] | 163 | explicit Channel() |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 164 | : external_transport(false), |
| 165 | send(false), |
| 166 | playout(false), |
| 167 | volume_scale(1.0), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 168 | vad(false), |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 169 | codec_fec(false), |
buildbot@webrtc.org | 5d639b3 | 2014-09-10 07:57:12 +0000 | [diff] [blame] | 170 | max_encoding_bandwidth(0), |
minyue@webrtc.org | 9b2e114 | 2015-03-13 09:38:07 +0000 | [diff] [blame] | 171 | opus_dtx(false), |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 172 | red(false), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 173 | nack(false), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 174 | cn8_type(13), |
| 175 | cn16_type(105), |
| 176 | dtmf_type(106), |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 177 | red_type(117), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 178 | nack_max_packets(0), |
| 179 | send_ssrc(0), |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 180 | associate_send_channel(-1), |
solenberg | 26c8c91 | 2015-11-27 04:00:25 -0800 | [diff] [blame^] | 181 | recv_codecs(), |
Henrik Lundin | 5263b3c | 2015-06-01 10:29:41 +0200 | [diff] [blame] | 182 | neteq_capacity(-1), |
| 183 | neteq_fast_accelerate(false) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 184 | memset(&send_codec, 0, sizeof(send_codec)); |
| 185 | } |
| 186 | bool external_transport; |
| 187 | bool send; |
| 188 | bool playout; |
| 189 | float volume_scale; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 190 | bool vad; |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 191 | bool codec_fec; |
buildbot@webrtc.org | 5d639b3 | 2014-09-10 07:57:12 +0000 | [diff] [blame] | 192 | int max_encoding_bandwidth; |
minyue@webrtc.org | 9b2e114 | 2015-03-13 09:38:07 +0000 | [diff] [blame] | 193 | bool opus_dtx; |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 194 | bool red; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 195 | bool nack; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 196 | int cn8_type; |
| 197 | int cn16_type; |
| 198 | int dtmf_type; |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 199 | int red_type; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 200 | int nack_max_packets; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 201 | uint32_t send_ssrc; |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 202 | int associate_send_channel; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 203 | DtmfInfo dtmf_info; |
| 204 | std::vector<webrtc::CodecInst> recv_codecs; |
| 205 | webrtc::CodecInst send_codec; |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 206 | webrtc::PacketTime last_rtp_packet_time; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 207 | std::list<std::string> packets; |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 208 | int neteq_capacity; |
Henrik Lundin | 5263b3c | 2015-06-01 10:29:41 +0200 | [diff] [blame] | 209 | bool neteq_fast_accelerate; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 210 | }; |
| 211 | |
solenberg | 26c8c91 | 2015-11-27 04:00:25 -0800 | [diff] [blame^] | 212 | FakeWebRtcVoiceEngine() |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 213 | : inited_(false), |
| 214 | last_channel_(-1), |
| 215 | fail_create_channel_(false), |
wu@webrtc.org | 05e7b44 | 2014-04-01 17:44:24 +0000 | [diff] [blame] | 216 | num_set_send_codecs_(0), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 217 | ec_enabled_(false), |
| 218 | ec_metrics_enabled_(false), |
| 219 | cng_enabled_(false), |
| 220 | ns_enabled_(false), |
| 221 | agc_enabled_(false), |
| 222 | highpass_filter_enabled_(false), |
| 223 | stereo_swapping_enabled_(false), |
| 224 | typing_detection_enabled_(false), |
| 225 | ec_mode_(webrtc::kEcDefault), |
| 226 | aecm_mode_(webrtc::kAecmSpeakerphone), |
| 227 | ns_mode_(webrtc::kNsDefault), |
| 228 | agc_mode_(webrtc::kAgcDefault), |
| 229 | observer_(NULL), |
| 230 | playout_fail_channel_(-1), |
| 231 | send_fail_channel_(-1), |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 232 | recording_sample_rate_(-1), |
Fredrik Solenberg | 7d17336 | 2015-09-23 12:23:21 +0200 | [diff] [blame] | 233 | playout_sample_rate_(-1) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 234 | memset(&agc_config_, 0, sizeof(agc_config_)); |
| 235 | } |
| 236 | ~FakeWebRtcVoiceEngine() { |
solenberg | 26c8c91 | 2015-11-27 04:00:25 -0800 | [diff] [blame^] | 237 | RTC_CHECK(channels_.empty()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 238 | } |
| 239 | |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 240 | bool ec_metrics_enabled() const { return ec_metrics_enabled_; } |
| 241 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 242 | bool IsInited() const { return inited_; } |
| 243 | int GetLastChannel() const { return last_channel_; } |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 244 | int GetNumChannels() const { return static_cast<int>(channels_.size()); } |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 245 | uint32_t GetLocalSSRC(int channel) { |
| 246 | return channels_[channel]->send_ssrc; |
| 247 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 248 | bool GetPlayout(int channel) { |
| 249 | return channels_[channel]->playout; |
| 250 | } |
| 251 | bool GetSend(int channel) { |
| 252 | return channels_[channel]->send; |
| 253 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 254 | bool GetVAD(int channel) { |
| 255 | return channels_[channel]->vad; |
| 256 | } |
Minyue Li | 7100dcd | 2015-03-27 05:05:59 +0100 | [diff] [blame] | 257 | bool GetOpusDtx(int channel) { |
| 258 | return channels_[channel]->opus_dtx; |
| 259 | } |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 260 | bool GetRED(int channel) { |
| 261 | return channels_[channel]->red; |
| 262 | } |
| 263 | bool GetCodecFEC(int channel) { |
| 264 | return channels_[channel]->codec_fec; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 265 | } |
buildbot@webrtc.org | 5d639b3 | 2014-09-10 07:57:12 +0000 | [diff] [blame] | 266 | int GetMaxEncodingBandwidth(int channel) { |
| 267 | return channels_[channel]->max_encoding_bandwidth; |
| 268 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 269 | bool GetNACK(int channel) { |
| 270 | return channels_[channel]->nack; |
| 271 | } |
| 272 | int GetNACKMaxPackets(int channel) { |
| 273 | return channels_[channel]->nack_max_packets; |
| 274 | } |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 275 | const webrtc::PacketTime& GetLastRtpPacketTime(int channel) { |
solenberg | 26c8c91 | 2015-11-27 04:00:25 -0800 | [diff] [blame^] | 276 | RTC_DCHECK(channels_.find(channel) != channels_.end()); |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 277 | return channels_[channel]->last_rtp_packet_time; |
| 278 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 279 | int GetSendCNPayloadType(int channel, bool wideband) { |
| 280 | return (wideband) ? |
| 281 | channels_[channel]->cn16_type : |
| 282 | channels_[channel]->cn8_type; |
| 283 | } |
| 284 | int GetSendTelephoneEventPayloadType(int channel) { |
| 285 | return channels_[channel]->dtmf_type; |
| 286 | } |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 287 | int GetSendREDPayloadType(int channel) { |
| 288 | return channels_[channel]->red_type; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 289 | } |
| 290 | bool CheckPacket(int channel, const void* data, size_t len) { |
| 291 | bool result = !CheckNoPacket(channel); |
| 292 | if (result) { |
| 293 | std::string packet = channels_[channel]->packets.front(); |
| 294 | result = (packet == std::string(static_cast<const char*>(data), len)); |
| 295 | channels_[channel]->packets.pop_front(); |
| 296 | } |
| 297 | return result; |
| 298 | } |
| 299 | bool CheckNoPacket(int channel) { |
| 300 | return channels_[channel]->packets.empty(); |
| 301 | } |
| 302 | void TriggerCallbackOnError(int channel_num, int err_code) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 303 | RTC_DCHECK(observer_ != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 304 | observer_->CallbackOnError(channel_num, err_code); |
| 305 | } |
| 306 | void set_playout_fail_channel(int channel) { |
| 307 | playout_fail_channel_ = channel; |
| 308 | } |
| 309 | void set_send_fail_channel(int channel) { |
| 310 | send_fail_channel_ = channel; |
| 311 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 312 | void set_fail_create_channel(bool fail_create_channel) { |
| 313 | fail_create_channel_ = fail_create_channel; |
| 314 | } |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 315 | int AddChannel(const webrtc::Config& config) { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 316 | if (fail_create_channel_) { |
| 317 | return -1; |
| 318 | } |
buildbot@webrtc.org | af6640f | 2014-04-28 21:31:51 +0000 | [diff] [blame] | 319 | Channel* ch = new Channel(); |
solenberg | 26c8c91 | 2015-11-27 04:00:25 -0800 | [diff] [blame^] | 320 | auto db = webrtc::acm2::RentACodec::Database(); |
| 321 | ch->recv_codecs.assign(db.begin(), db.end()); |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 322 | if (config.Get<webrtc::NetEqCapacityConfig>().enabled) { |
| 323 | ch->neteq_capacity = config.Get<webrtc::NetEqCapacityConfig>().capacity; |
| 324 | } |
Henrik Lundin | 5263b3c | 2015-06-01 10:29:41 +0200 | [diff] [blame] | 325 | ch->neteq_fast_accelerate = |
| 326 | config.Get<webrtc::NetEqFastAccelerate>().enabled; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 327 | channels_[++last_channel_] = ch; |
| 328 | return last_channel_; |
| 329 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 330 | |
wu@webrtc.org | 05e7b44 | 2014-04-01 17:44:24 +0000 | [diff] [blame] | 331 | int GetNumSetSendCodecs() const { return num_set_send_codecs_; } |
| 332 | |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 333 | int GetAssociateSendChannel(int channel) { |
| 334 | return channels_[channel]->associate_send_channel; |
| 335 | } |
| 336 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 337 | WEBRTC_STUB(Release, ()); |
| 338 | |
| 339 | // webrtc::VoEBase |
| 340 | WEBRTC_FUNC(RegisterVoiceEngineObserver, ( |
| 341 | webrtc::VoiceEngineObserver& observer)) { |
| 342 | observer_ = &observer; |
| 343 | return 0; |
| 344 | } |
| 345 | WEBRTC_STUB(DeRegisterVoiceEngineObserver, ()); |
| 346 | WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm, |
| 347 | webrtc::AudioProcessing* audioproc)) { |
| 348 | inited_ = true; |
| 349 | return 0; |
| 350 | } |
| 351 | WEBRTC_FUNC(Terminate, ()) { |
| 352 | inited_ = false; |
| 353 | return 0; |
| 354 | } |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 355 | webrtc::AudioProcessing* audio_processing() override { |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 356 | return &audio_processing_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 357 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 358 | WEBRTC_FUNC(CreateChannel, ()) { |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 359 | webrtc::Config empty_config; |
| 360 | return AddChannel(empty_config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 361 | } |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 362 | WEBRTC_FUNC(CreateChannel, (const webrtc::Config& config)) { |
| 363 | return AddChannel(config); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 364 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 365 | WEBRTC_FUNC(DeleteChannel, (int channel)) { |
| 366 | WEBRTC_CHECK_CHANNEL(channel); |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 367 | for (const auto& ch : channels_) { |
| 368 | if (ch.second->associate_send_channel == channel) { |
| 369 | ch.second->associate_send_channel = -1; |
| 370 | } |
| 371 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 372 | delete channels_[channel]; |
| 373 | channels_.erase(channel); |
| 374 | return 0; |
| 375 | } |
| 376 | WEBRTC_STUB(StartReceive, (int channel)); |
| 377 | WEBRTC_FUNC(StartPlayout, (int channel)) { |
| 378 | if (playout_fail_channel_ != channel) { |
| 379 | WEBRTC_CHECK_CHANNEL(channel); |
| 380 | channels_[channel]->playout = true; |
| 381 | return 0; |
| 382 | } else { |
| 383 | // When playout_fail_channel_ == channel, fail the StartPlayout on this |
| 384 | // channel. |
| 385 | return -1; |
| 386 | } |
| 387 | } |
| 388 | WEBRTC_FUNC(StartSend, (int channel)) { |
| 389 | if (send_fail_channel_ != channel) { |
| 390 | WEBRTC_CHECK_CHANNEL(channel); |
| 391 | channels_[channel]->send = true; |
| 392 | return 0; |
| 393 | } else { |
| 394 | // When send_fail_channel_ == channel, fail the StartSend on this |
| 395 | // channel. |
| 396 | return -1; |
| 397 | } |
| 398 | } |
| 399 | WEBRTC_STUB(StopReceive, (int channel)); |
| 400 | WEBRTC_FUNC(StopPlayout, (int channel)) { |
| 401 | WEBRTC_CHECK_CHANNEL(channel); |
| 402 | channels_[channel]->playout = false; |
| 403 | return 0; |
| 404 | } |
| 405 | WEBRTC_FUNC(StopSend, (int channel)) { |
| 406 | WEBRTC_CHECK_CHANNEL(channel); |
| 407 | channels_[channel]->send = false; |
| 408 | return 0; |
| 409 | } |
| 410 | WEBRTC_STUB(GetVersion, (char version[1024])); |
| 411 | WEBRTC_STUB(LastError, ()); |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 412 | WEBRTC_FUNC(AssociateSendChannel, (int channel, |
| 413 | int accociate_send_channel)) { |
| 414 | WEBRTC_CHECK_CHANNEL(channel); |
| 415 | channels_[channel]->associate_send_channel = accociate_send_channel; |
| 416 | return 0; |
| 417 | } |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 418 | webrtc::RtcEventLog* GetEventLog() { return nullptr; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 419 | |
| 420 | // webrtc::VoECodec |
solenberg | 26c8c91 | 2015-11-27 04:00:25 -0800 | [diff] [blame^] | 421 | WEBRTC_STUB(NumOfCodecs, ()); |
| 422 | WEBRTC_STUB(GetCodec, (int index, webrtc::CodecInst& codec)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 423 | WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) { |
| 424 | WEBRTC_CHECK_CHANNEL(channel); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 425 | // To match the behavior of the real implementation. |
| 426 | if (_stricmp(codec.plname, "telephone-event") == 0 || |
| 427 | _stricmp(codec.plname, "audio/telephone-event") == 0 || |
| 428 | _stricmp(codec.plname, "CN") == 0 || |
| 429 | _stricmp(codec.plname, "red") == 0 ) { |
| 430 | return -1; |
| 431 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 432 | channels_[channel]->send_codec = codec; |
wu@webrtc.org | 05e7b44 | 2014-04-01 17:44:24 +0000 | [diff] [blame] | 433 | ++num_set_send_codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 434 | return 0; |
| 435 | } |
| 436 | WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) { |
| 437 | WEBRTC_CHECK_CHANNEL(channel); |
| 438 | codec = channels_[channel]->send_codec; |
| 439 | return 0; |
| 440 | } |
Ivo Creusen | adf89b7 | 2015-04-29 16:03:33 +0200 | [diff] [blame] | 441 | WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps)); |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 442 | WEBRTC_STUB(GetRecCodec, (int channel, webrtc::CodecInst& codec)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 443 | WEBRTC_FUNC(SetRecPayloadType, (int channel, |
| 444 | const webrtc::CodecInst& codec)) { |
| 445 | WEBRTC_CHECK_CHANNEL(channel); |
| 446 | Channel* ch = channels_[channel]; |
| 447 | if (ch->playout) |
| 448 | return -1; // Channel is in use. |
| 449 | // Check if something else already has this slot. |
| 450 | if (codec.pltype != -1) { |
| 451 | for (std::vector<webrtc::CodecInst>::iterator it = |
| 452 | ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) { |
| 453 | if (it->pltype == codec.pltype && |
| 454 | _stricmp(it->plname, codec.plname) != 0) { |
| 455 | return -1; |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | // Otherwise try to find this codec and update its payload type. |
solenberg | 26c8c91 | 2015-11-27 04:00:25 -0800 | [diff] [blame^] | 460 | int result = -1; // not found |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 461 | for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin(); |
| 462 | it != ch->recv_codecs.end(); ++it) { |
| 463 | if (strcmp(it->plname, codec.plname) == 0 && |
solenberg | 26c8c91 | 2015-11-27 04:00:25 -0800 | [diff] [blame^] | 464 | it->plfreq == codec.plfreq && |
| 465 | it->channels == codec.channels) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 466 | it->pltype = codec.pltype; |
solenberg | 26c8c91 | 2015-11-27 04:00:25 -0800 | [diff] [blame^] | 467 | result = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 468 | } |
| 469 | } |
solenberg | 26c8c91 | 2015-11-27 04:00:25 -0800 | [diff] [blame^] | 470 | return result; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 471 | } |
| 472 | WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type, |
| 473 | webrtc::PayloadFrequencies frequency)) { |
| 474 | WEBRTC_CHECK_CHANNEL(channel); |
| 475 | if (frequency == webrtc::kFreq8000Hz) { |
| 476 | channels_[channel]->cn8_type = type; |
| 477 | } else if (frequency == webrtc::kFreq16000Hz) { |
| 478 | channels_[channel]->cn16_type = type; |
| 479 | } |
| 480 | return 0; |
| 481 | } |
| 482 | WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) { |
| 483 | WEBRTC_CHECK_CHANNEL(channel); |
| 484 | Channel* ch = channels_[channel]; |
| 485 | for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin(); |
| 486 | it != ch->recv_codecs.end(); ++it) { |
| 487 | if (strcmp(it->plname, codec.plname) == 0 && |
| 488 | it->plfreq == codec.plfreq && |
| 489 | it->channels == codec.channels && |
| 490 | it->pltype != -1) { |
| 491 | codec.pltype = it->pltype; |
| 492 | return 0; |
| 493 | } |
| 494 | } |
| 495 | return -1; // not found |
| 496 | } |
| 497 | WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode, |
| 498 | bool disableDTX)) { |
| 499 | WEBRTC_CHECK_CHANNEL(channel); |
| 500 | if (channels_[channel]->send_codec.channels == 2) { |
| 501 | // Replicating VoE behavior; VAD cannot be enabled for stereo. |
| 502 | return -1; |
| 503 | } |
| 504 | channels_[channel]->vad = enable; |
| 505 | return 0; |
| 506 | } |
| 507 | WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled, |
| 508 | webrtc::VadModes& mode, bool& disabledDTX)); |
buildbot@webrtc.org | 5d639b3 | 2014-09-10 07:57:12 +0000 | [diff] [blame] | 509 | |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 510 | WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) { |
| 511 | WEBRTC_CHECK_CHANNEL(channel); |
buildbot@webrtc.org | 5d639b3 | 2014-09-10 07:57:12 +0000 | [diff] [blame] | 512 | if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) { |
buildbot@webrtc.org | 3ffa1f9 | 2014-07-02 19:51:26 +0000 | [diff] [blame] | 513 | // Return -1 if current send codec is not Opus. |
| 514 | // TODO(minyue): Excludes other codecs if they support inband FEC. |
| 515 | return -1; |
| 516 | } |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 517 | channels_[channel]->codec_fec = enable; |
| 518 | return 0; |
| 519 | } |
| 520 | WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) { |
| 521 | WEBRTC_CHECK_CHANNEL(channel); |
| 522 | enable = channels_[channel]->codec_fec; |
| 523 | return 0; |
| 524 | } |
buildbot@webrtc.org | 5d639b3 | 2014-09-10 07:57:12 +0000 | [diff] [blame] | 525 | |
| 526 | WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) { |
| 527 | WEBRTC_CHECK_CHANNEL(channel); |
| 528 | if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) { |
| 529 | // Return -1 if current send codec is not Opus. |
| 530 | return -1; |
| 531 | } |
| 532 | if (frequency_hz <= 8000) |
| 533 | channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb; |
| 534 | else if (frequency_hz <= 12000) |
| 535 | channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb; |
| 536 | else if (frequency_hz <= 16000) |
| 537 | channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb; |
| 538 | else if (frequency_hz <= 24000) |
| 539 | channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb; |
| 540 | else |
| 541 | channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb; |
| 542 | return 0; |
| 543 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 544 | |
minyue@webrtc.org | 9b2e114 | 2015-03-13 09:38:07 +0000 | [diff] [blame] | 545 | WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) { |
| 546 | WEBRTC_CHECK_CHANNEL(channel); |
| 547 | if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) { |
| 548 | // Return -1 if current send codec is not Opus. |
| 549 | return -1; |
| 550 | } |
| 551 | channels_[channel]->opus_dtx = enable_dtx; |
| 552 | return 0; |
| 553 | } |
| 554 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 555 | // webrtc::VoEDtmf |
| 556 | WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code, |
| 557 | bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) { |
| 558 | channels_[channel]->dtmf_info.dtmf_event_code = event_code; |
| 559 | channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band; |
| 560 | channels_[channel]->dtmf_info.dtmf_length_ms = length_ms; |
| 561 | return 0; |
| 562 | } |
| 563 | |
| 564 | WEBRTC_FUNC(SetSendTelephoneEventPayloadType, |
| 565 | (int channel, unsigned char type)) { |
| 566 | channels_[channel]->dtmf_type = type; |
| 567 | return 0; |
| 568 | }; |
| 569 | WEBRTC_STUB(GetSendTelephoneEventPayloadType, |
| 570 | (int channel, unsigned char& type)); |
| 571 | |
| 572 | WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback)); |
| 573 | WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 574 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 575 | WEBRTC_FUNC(PlayDtmfTone, |
| 576 | (int event_code, int length_ms = 200, int attenuation_db = 10)) { |
| 577 | dtmf_info_.dtmf_event_code = event_code; |
| 578 | dtmf_info_.dtmf_length_ms = length_ms; |
| 579 | return 0; |
| 580 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 581 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 582 | // webrtc::VoEHardware |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 583 | WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) { |
| 584 | return GetNumDevices(num); |
| 585 | } |
| 586 | WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) { |
| 587 | return GetNumDevices(num); |
| 588 | } |
| 589 | WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) { |
| 590 | return GetDeviceName(i, name, guid); |
| 591 | } |
| 592 | WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) { |
| 593 | return GetDeviceName(i, name, guid); |
| 594 | } |
| 595 | WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel)); |
| 596 | WEBRTC_STUB(SetPlayoutDevice, (int)); |
| 597 | WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers)); |
| 598 | WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&)); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 599 | WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) { |
| 600 | recording_sample_rate_ = samples_per_sec; |
| 601 | return 0; |
| 602 | } |
| 603 | WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) { |
| 604 | *samples_per_sec = recording_sample_rate_; |
| 605 | return 0; |
| 606 | } |
| 607 | WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) { |
| 608 | playout_sample_rate_ = samples_per_sec; |
| 609 | return 0; |
| 610 | } |
| 611 | WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) { |
| 612 | *samples_per_sec = playout_sample_rate_; |
| 613 | return 0; |
| 614 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 615 | WEBRTC_STUB(EnableBuiltInAEC, (bool enable)); |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 616 | virtual bool BuiltInAECIsAvailable() const { return false; } |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 617 | WEBRTC_STUB(EnableBuiltInAGC, (bool enable)); |
| 618 | virtual bool BuiltInAGCIsAvailable() const { return false; } |
| 619 | WEBRTC_STUB(EnableBuiltInNS, (bool enable)); |
| 620 | virtual bool BuiltInNSIsAvailable() const { return false; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 621 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 622 | // webrtc::VoENetwork |
| 623 | WEBRTC_FUNC(RegisterExternalTransport, (int channel, |
| 624 | webrtc::Transport& transport)) { |
| 625 | WEBRTC_CHECK_CHANNEL(channel); |
| 626 | channels_[channel]->external_transport = true; |
| 627 | return 0; |
| 628 | } |
| 629 | WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) { |
| 630 | WEBRTC_CHECK_CHANNEL(channel); |
| 631 | channels_[channel]->external_transport = false; |
| 632 | return 0; |
| 633 | } |
| 634 | WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 635 | size_t length)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 636 | WEBRTC_CHECK_CHANNEL(channel); |
| 637 | if (!channels_[channel]->external_transport) return -1; |
| 638 | channels_[channel]->packets.push_back( |
| 639 | std::string(static_cast<const char*>(data), length)); |
| 640 | return 0; |
| 641 | } |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 642 | WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 643 | size_t length, |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 644 | const webrtc::PacketTime& packet_time)) { |
| 645 | WEBRTC_CHECK_CHANNEL(channel); |
| 646 | if (ReceivedRTPPacket(channel, data, length) == -1) { |
| 647 | return -1; |
| 648 | } |
| 649 | channels_[channel]->last_rtp_packet_time = packet_time; |
| 650 | return 0; |
| 651 | } |
buildbot@webrtc.org | f875f15 | 2014-04-14 16:06:21 +0000 | [diff] [blame] | 652 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 653 | WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 654 | size_t length)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 655 | |
| 656 | // webrtc::VoERTP_RTCP |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 657 | WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) { |
| 658 | WEBRTC_CHECK_CHANNEL(channel); |
| 659 | channels_[channel]->send_ssrc = ssrc; |
| 660 | return 0; |
| 661 | } |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 662 | WEBRTC_STUB(GetLocalSSRC, (int channel, unsigned int& ssrc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 663 | WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc)); |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 664 | WEBRTC_STUB(SetSendAudioLevelIndicationStatus, (int channel, bool enable, |
| 665 | unsigned char id)); |
solenberg | 7add058 | 2015-11-20 09:59:34 -0800 | [diff] [blame] | 666 | WEBRTC_STUB(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable, |
| 667 | unsigned char id)); |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 668 | WEBRTC_STUB(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable, |
| 669 | unsigned char id)); |
solenberg | 7add058 | 2015-11-20 09:59:34 -0800 | [diff] [blame] | 670 | WEBRTC_STUB(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable, |
| 671 | unsigned char id)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 672 | WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable)); |
| 673 | WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled)); |
| 674 | WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256])); |
| 675 | WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256])); |
| 676 | WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname)); |
| 677 | WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh, |
| 678 | unsigned int& NTPLow, |
| 679 | unsigned int& timestamp, |
| 680 | unsigned int& playoutTimestamp, |
| 681 | unsigned int* jitter, |
| 682 | unsigned short* fractionLost)); |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 683 | WEBRTC_STUB(GetRemoteRTCPReportBlocks, |
| 684 | (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 685 | WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs, |
| 686 | unsigned int& maxJitterMs, |
| 687 | unsigned int& discardedPackets)); |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 688 | WEBRTC_STUB(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 689 | WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 690 | WEBRTC_CHECK_CHANNEL(channel); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 691 | channels_[channel]->red = enable; |
| 692 | channels_[channel]->red_type = redPayloadtype; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 693 | return 0; |
| 694 | } |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 695 | WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 696 | WEBRTC_CHECK_CHANNEL(channel); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 697 | enable = channels_[channel]->red; |
| 698 | redPayloadtype = channels_[channel]->red_type; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 699 | return 0; |
| 700 | } |
| 701 | WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) { |
| 702 | WEBRTC_CHECK_CHANNEL(channel); |
| 703 | channels_[channel]->nack = enable; |
| 704 | channels_[channel]->nack_max_packets = maxNoPackets; |
| 705 | return 0; |
| 706 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 707 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 708 | // webrtc::VoEVolumeControl |
| 709 | WEBRTC_STUB(SetSpeakerVolume, (unsigned int)); |
| 710 | WEBRTC_STUB(GetSpeakerVolume, (unsigned int&)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 711 | WEBRTC_STUB(SetMicVolume, (unsigned int)); |
| 712 | WEBRTC_STUB(GetMicVolume, (unsigned int&)); |
| 713 | WEBRTC_STUB(SetInputMute, (int, bool)); |
| 714 | WEBRTC_STUB(GetInputMute, (int, bool&)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 715 | WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&)); |
| 716 | WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&)); |
| 717 | WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&)); |
| 718 | WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&)); |
| 719 | WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) { |
| 720 | WEBRTC_CHECK_CHANNEL(channel); |
| 721 | channels_[channel]->volume_scale= scale; |
| 722 | return 0; |
| 723 | } |
| 724 | WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) { |
| 725 | WEBRTC_CHECK_CHANNEL(channel); |
| 726 | scale = channels_[channel]->volume_scale; |
| 727 | return 0; |
| 728 | } |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 729 | WEBRTC_STUB(SetOutputVolumePan, (int channel, float left, float right)); |
| 730 | WEBRTC_STUB(GetOutputVolumePan, (int channel, float& left, float& right)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 731 | |
| 732 | // webrtc::VoEAudioProcessing |
| 733 | WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) { |
| 734 | ns_enabled_ = enable; |
| 735 | ns_mode_ = mode; |
| 736 | return 0; |
| 737 | } |
| 738 | WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) { |
| 739 | enabled = ns_enabled_; |
| 740 | mode = ns_mode_; |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) { |
| 745 | agc_enabled_ = enable; |
| 746 | agc_mode_ = mode; |
| 747 | return 0; |
| 748 | } |
| 749 | WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) { |
| 750 | enabled = agc_enabled_; |
| 751 | mode = agc_mode_; |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) { |
| 756 | agc_config_ = config; |
| 757 | return 0; |
| 758 | } |
| 759 | WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) { |
| 760 | config = agc_config_; |
| 761 | return 0; |
| 762 | } |
| 763 | WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) { |
| 764 | ec_enabled_ = enable; |
| 765 | ec_mode_ = mode; |
| 766 | return 0; |
| 767 | } |
| 768 | WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) { |
| 769 | enabled = ec_enabled_; |
| 770 | mode = ec_mode_; |
| 771 | return 0; |
| 772 | } |
| 773 | WEBRTC_STUB(EnableDriftCompensation, (bool enable)) |
| 774 | WEBRTC_BOOL_STUB(DriftCompensationEnabled, ()) |
| 775 | WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset)) |
| 776 | WEBRTC_STUB(DelayOffsetMs, ()); |
| 777 | WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) { |
| 778 | aecm_mode_ = mode; |
| 779 | cng_enabled_ = enableCNG; |
| 780 | return 0; |
| 781 | } |
| 782 | WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) { |
| 783 | mode = aecm_mode_; |
| 784 | enabledCNG = cng_enabled_; |
| 785 | return 0; |
| 786 | } |
| 787 | WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode)); |
| 788 | WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled, |
| 789 | webrtc::NsModes& mode)); |
solenberg | 0b67546 | 2015-10-09 01:37:09 -0700 | [diff] [blame] | 790 | WEBRTC_STUB(SetRxAgcStatus, (int channel, bool enable, |
| 791 | webrtc::AgcModes mode)); |
| 792 | WEBRTC_STUB(GetRxAgcStatus, (int channel, bool& enabled, |
| 793 | webrtc::AgcModes& mode)); |
| 794 | WEBRTC_STUB(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)); |
| 795 | WEBRTC_STUB(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 796 | |
| 797 | WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&)); |
| 798 | WEBRTC_STUB(DeRegisterRxVadObserver, (int channel)); |
| 799 | WEBRTC_STUB(VoiceActivityIndicator, (int channel)); |
| 800 | WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) { |
| 801 | ec_metrics_enabled_ = enable; |
| 802 | return 0; |
| 803 | } |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 804 | WEBRTC_STUB(GetEcMetricsStatus, (bool& enabled)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 805 | 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] | 806 | WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std, |
| 807 | float& fraction_poor_delays)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 808 | |
| 809 | WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8)); |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 810 | WEBRTC_STUB(StartDebugRecording, (FILE* handle)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 811 | WEBRTC_STUB(StopDebugRecording, ()); |
| 812 | |
| 813 | WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) { |
| 814 | typing_detection_enabled_ = enable; |
| 815 | return 0; |
| 816 | } |
| 817 | WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) { |
| 818 | enabled = typing_detection_enabled_; |
| 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | WEBRTC_STUB(TimeSinceLastTyping, (int& seconds)); |
| 823 | WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow, |
| 824 | int costPerTyping, |
| 825 | int reportingThreshold, |
| 826 | int penaltyDecay, |
| 827 | int typeEventDelay)); |
| 828 | int EnableHighPassFilter(bool enable) { |
| 829 | highpass_filter_enabled_ = enable; |
| 830 | return 0; |
| 831 | } |
| 832 | bool IsHighPassFilterEnabled() { |
| 833 | return highpass_filter_enabled_; |
| 834 | } |
| 835 | bool IsStereoChannelSwappingEnabled() { |
| 836 | return stereo_swapping_enabled_; |
| 837 | } |
| 838 | void EnableStereoChannelSwapping(bool enable) { |
| 839 | stereo_swapping_enabled_ = enable; |
| 840 | } |
| 841 | bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) { |
| 842 | return (channels_[channel]->dtmf_info.dtmf_event_code == event_code && |
| 843 | channels_[channel]->dtmf_info.dtmf_out_of_band == true && |
| 844 | channels_[channel]->dtmf_info.dtmf_length_ms == length_ms); |
| 845 | } |
| 846 | bool WasPlayDtmfToneCalled(int event_code, int length_ms) { |
| 847 | return (dtmf_info_.dtmf_event_code == event_code && |
| 848 | dtmf_info_.dtmf_length_ms == length_ms); |
| 849 | } |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 850 | int GetNetEqCapacity() const { |
| 851 | auto ch = channels_.find(last_channel_); |
| 852 | ASSERT(ch != channels_.end()); |
| 853 | return ch->second->neteq_capacity; |
| 854 | } |
Henrik Lundin | 5263b3c | 2015-06-01 10:29:41 +0200 | [diff] [blame] | 855 | bool GetNetEqFastAccelerate() const { |
| 856 | auto ch = channels_.find(last_channel_); |
| 857 | ASSERT(ch != channels_.end()); |
| 858 | return ch->second->neteq_fast_accelerate; |
| 859 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 860 | |
| 861 | private: |
| 862 | int GetNumDevices(int& num) { |
| 863 | #ifdef WIN32 |
| 864 | num = 1; |
| 865 | #else |
| 866 | // On non-Windows platforms VE adds a special entry for the default device, |
| 867 | // so if there is one physical device then there are two entries in the |
| 868 | // list. |
| 869 | num = 2; |
| 870 | #endif |
| 871 | return 0; |
| 872 | } |
| 873 | |
| 874 | int GetDeviceName(int i, char* name, char* guid) { |
| 875 | const char *s; |
| 876 | #ifdef WIN32 |
| 877 | if (0 == i) { |
| 878 | s = kFakeDeviceName; |
| 879 | } else { |
| 880 | return -1; |
| 881 | } |
| 882 | #else |
| 883 | // See comment above. |
| 884 | if (0 == i) { |
| 885 | s = kFakeDefaultDeviceName; |
| 886 | } else if (1 == i) { |
| 887 | s = kFakeDeviceName; |
| 888 | } else { |
| 889 | return -1; |
| 890 | } |
| 891 | #endif |
| 892 | strcpy(name, s); |
| 893 | guid[0] = '\0'; |
| 894 | return 0; |
| 895 | } |
| 896 | |
| 897 | bool inited_; |
| 898 | int last_channel_; |
| 899 | std::map<int, Channel*> channels_; |
| 900 | bool fail_create_channel_; |
wu@webrtc.org | 05e7b44 | 2014-04-01 17:44:24 +0000 | [diff] [blame] | 901 | int num_set_send_codecs_; // how many times we call SetSendCodec(). |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 902 | bool ec_enabled_; |
| 903 | bool ec_metrics_enabled_; |
| 904 | bool cng_enabled_; |
| 905 | bool ns_enabled_; |
| 906 | bool agc_enabled_; |
| 907 | bool highpass_filter_enabled_; |
| 908 | bool stereo_swapping_enabled_; |
| 909 | bool typing_detection_enabled_; |
| 910 | webrtc::EcModes ec_mode_; |
| 911 | webrtc::AecmModes aecm_mode_; |
| 912 | webrtc::NsModes ns_mode_; |
| 913 | webrtc::AgcModes agc_mode_; |
| 914 | webrtc::AgcConfig agc_config_; |
| 915 | webrtc::VoiceEngineObserver* observer_; |
| 916 | int playout_fail_channel_; |
| 917 | int send_fail_channel_; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 918 | int recording_sample_rate_; |
| 919 | int playout_sample_rate_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 920 | DtmfInfo dtmf_info_; |
buildbot@webrtc.org | a8d8ad2 | 2014-07-16 14:23:08 +0000 | [diff] [blame] | 921 | FakeAudioProcessing audio_processing_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 922 | }; |
| 923 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 924 | } // namespace cricket |
| 925 | |
| 926 | #endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_ |