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