henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2008 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 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 27 | |
| 28 | #ifdef WIN32 |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 29 | #include "webrtc/base/win32.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 30 | #include <objbase.h> |
| 31 | #endif |
| 32 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 33 | #include "webrtc/base/byteorder.h" |
| 34 | #include "webrtc/base/gunit.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 35 | #include "talk/media/base/constants.h" |
| 36 | #include "talk/media/base/fakemediaengine.h" |
| 37 | #include "talk/media/base/fakemediaprocessor.h" |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 38 | #include "talk/media/base/fakenetworkinterface.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 39 | #include "talk/media/base/fakertp.h" |
| 40 | #include "talk/media/webrtc/fakewebrtcvoiceengine.h" |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 41 | #include "talk/media/webrtc/webrtcvie.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 42 | #include "talk/media/webrtc/webrtcvoiceengine.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame^] | 43 | #include "webrtc/p2p/base/fakesession.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | #include "talk/session/media/channel.h" |
| 45 | |
| 46 | // Tests for the WebRtcVoiceEngine/VoiceChannel code. |
| 47 | |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 48 | using cricket::kRtpAudioLevelHeaderExtension; |
| 49 | using cricket::kRtpAbsoluteSenderTimeHeaderExtension; |
| 50 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 51 | static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1, 0); |
| 52 | static const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1, 0); |
| 53 | static const cricket::AudioCodec kCeltCodec(110, "CELT", 32000, 64000, 2, 0); |
| 54 | static const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2, 0); |
| 55 | static const cricket::AudioCodec kRedCodec(117, "red", 8000, 0, 1, 0); |
| 56 | static const cricket::AudioCodec kCn8000Codec(13, "CN", 8000, 0, 1, 0); |
| 57 | static const cricket::AudioCodec kCn16000Codec(105, "CN", 16000, 0, 1, 0); |
| 58 | static const cricket::AudioCodec |
| 59 | kTelephoneEventCodec(106, "telephone-event", 8000, 0, 1, 0); |
| 60 | static const cricket::AudioCodec* const kAudioCodecs[] = { |
| 61 | &kPcmuCodec, &kIsacCodec, &kCeltCodec, &kOpusCodec, &kRedCodec, |
| 62 | &kCn8000Codec, &kCn16000Codec, &kTelephoneEventCodec, |
| 63 | }; |
| 64 | const char kRingbackTone[] = "RIFF____WAVE____ABCD1234"; |
| 65 | static uint32 kSsrc1 = 0x99; |
| 66 | static uint32 kSsrc2 = 0x98; |
| 67 | |
| 68 | class FakeVoEWrapper : public cricket::VoEWrapper { |
| 69 | public: |
| 70 | explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine) |
| 71 | : cricket::VoEWrapper(engine, // processing |
| 72 | engine, // base |
| 73 | engine, // codec |
| 74 | engine, // dtmf |
| 75 | engine, // file |
| 76 | engine, // hw |
| 77 | engine, // media |
| 78 | engine, // neteq |
| 79 | engine, // network |
| 80 | engine, // rtp |
| 81 | engine, // sync |
| 82 | engine) { // volume |
| 83 | } |
| 84 | }; |
| 85 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 86 | class FakeVoETraceWrapper : public cricket::VoETraceWrapper { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 87 | public: |
| 88 | virtual int SetTraceFilter(const unsigned int filter) { |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 89 | filter_ = filter; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 90 | return 0; |
| 91 | } |
| 92 | virtual int SetTraceFile(const char* fileNameUTF8) { |
| 93 | return 0; |
| 94 | } |
| 95 | virtual int SetTraceCallback(webrtc::TraceCallback* callback) { |
| 96 | return 0; |
| 97 | } |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 98 | unsigned int filter_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | class WebRtcVoiceEngineTestFake : public testing::Test { |
| 102 | public: |
| 103 | class ChannelErrorListener : public sigslot::has_slots<> { |
| 104 | public: |
| 105 | explicit ChannelErrorListener(cricket::VoiceMediaChannel* channel) |
| 106 | : ssrc_(0), error_(cricket::VoiceMediaChannel::ERROR_NONE) { |
| 107 | ASSERT(channel != NULL); |
| 108 | channel->SignalMediaError.connect( |
| 109 | this, &ChannelErrorListener::OnVoiceChannelError); |
| 110 | } |
| 111 | void OnVoiceChannelError(uint32 ssrc, |
| 112 | cricket::VoiceMediaChannel::Error error) { |
| 113 | ssrc_ = ssrc; |
| 114 | error_ = error; |
| 115 | } |
| 116 | void Reset() { |
| 117 | ssrc_ = 0; |
| 118 | error_ = cricket::VoiceMediaChannel::ERROR_NONE; |
| 119 | } |
| 120 | uint32 ssrc() const { |
| 121 | return ssrc_; |
| 122 | } |
| 123 | cricket::VoiceMediaChannel::Error error() const { |
| 124 | return error_; |
| 125 | } |
| 126 | |
| 127 | private: |
| 128 | uint32 ssrc_; |
| 129 | cricket::VoiceMediaChannel::Error error_; |
| 130 | }; |
| 131 | |
| 132 | WebRtcVoiceEngineTestFake() |
| 133 | : voe_(kAudioCodecs, ARRAY_SIZE(kAudioCodecs)), |
| 134 | voe_sc_(kAudioCodecs, ARRAY_SIZE(kAudioCodecs)), |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 135 | trace_wrapper_(new FakeVoETraceWrapper()), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 136 | engine_(new FakeVoEWrapper(&voe_), |
| 137 | new FakeVoEWrapper(&voe_sc_), |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 138 | trace_wrapper_), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 139 | channel_(NULL), soundclip_(NULL) { |
| 140 | options_conference_.conference_mode.Set(true); |
| 141 | options_adjust_agc_.adjust_agc_delta.Set(-10); |
| 142 | } |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 143 | bool SetupEngineWithoutStream() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 144 | if (!engine_.Init(rtc::Thread::Current())) { |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 145 | return false; |
| 146 | } |
| 147 | channel_ = engine_.CreateChannel(); |
| 148 | return (channel_ != NULL); |
| 149 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 150 | bool SetupEngine() { |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 151 | if (!SetupEngineWithoutStream()) { |
| 152 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 153 | } |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 154 | return channel_->AddSendStream( |
| 155 | cricket::StreamParams::CreateLegacy(kSsrc1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 156 | } |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 157 | void SetupForMultiSendStream() { |
| 158 | EXPECT_TRUE(SetupEngine()); |
| 159 | // Remove stream added in Setup, which is corresponding to default channel. |
| 160 | int default_channel_num = voe_.GetLastChannel(); |
henrike@webrtc.org | 7666db7 | 2013-08-22 14:45:42 +0000 | [diff] [blame] | 161 | uint32 default_send_ssrc = 0u; |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 162 | EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc)); |
| 163 | EXPECT_EQ(kSsrc1, default_send_ssrc); |
| 164 | EXPECT_TRUE(channel_->RemoveSendStream(default_send_ssrc)); |
| 165 | |
| 166 | // Verify the default channel still exists. |
| 167 | EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc)); |
| 168 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 169 | void DeliverPacket(const void* data, int len) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 170 | rtc::Buffer packet(data, len); |
| 171 | channel_->OnPacketReceived(&packet, rtc::PacketTime()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 172 | } |
| 173 | virtual void TearDown() { |
| 174 | delete soundclip_; |
| 175 | delete channel_; |
| 176 | engine_.Terminate(); |
| 177 | } |
| 178 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 179 | void TestInsertDtmf(uint32 ssrc, bool caller) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 180 | EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 181 | channel_ = engine_.CreateChannel(); |
| 182 | EXPECT_TRUE(channel_ != NULL); |
| 183 | if (caller) { |
| 184 | // if this is a caller, local description will be applied and add the |
| 185 | // send stream. |
| 186 | EXPECT_TRUE(channel_->AddSendStream( |
| 187 | cricket::StreamParams::CreateLegacy(kSsrc1))); |
| 188 | } |
| 189 | int channel_id = voe_.GetLastChannel(); |
| 190 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 191 | // Test we can only InsertDtmf when the other side supports telephone-event. |
| 192 | std::vector<cricket::AudioCodec> codecs; |
| 193 | codecs.push_back(kPcmuCodec); |
| 194 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 195 | EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| 196 | EXPECT_FALSE(channel_->CanInsertDtmf()); |
| 197 | EXPECT_FALSE(channel_->InsertDtmf(ssrc, 1, 111, cricket::DF_SEND)); |
| 198 | codecs.push_back(kTelephoneEventCodec); |
| 199 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 200 | EXPECT_TRUE(channel_->CanInsertDtmf()); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 201 | |
| 202 | if (!caller) { |
| 203 | // There's no active send channel yet. |
| 204 | EXPECT_FALSE(channel_->InsertDtmf(ssrc, 2, 123, cricket::DF_SEND)); |
| 205 | EXPECT_TRUE(channel_->AddSendStream( |
| 206 | cricket::StreamParams::CreateLegacy(kSsrc1))); |
| 207 | } |
| 208 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 209 | // Check we fail if the ssrc is invalid. |
| 210 | EXPECT_FALSE(channel_->InsertDtmf(-1, 1, 111, cricket::DF_SEND)); |
| 211 | |
| 212 | // Test send |
| 213 | EXPECT_FALSE(voe_.WasSendTelephoneEventCalled(channel_id, 2, 123)); |
| 214 | EXPECT_TRUE(channel_->InsertDtmf(ssrc, 2, 123, cricket::DF_SEND)); |
| 215 | EXPECT_TRUE(voe_.WasSendTelephoneEventCalled(channel_id, 2, 123)); |
| 216 | |
| 217 | // Test play |
| 218 | EXPECT_FALSE(voe_.WasPlayDtmfToneCalled(3, 134)); |
| 219 | EXPECT_TRUE(channel_->InsertDtmf(ssrc, 3, 134, cricket::DF_PLAY)); |
| 220 | EXPECT_TRUE(voe_.WasPlayDtmfToneCalled(3, 134)); |
| 221 | |
| 222 | // Test send and play |
| 223 | EXPECT_FALSE(voe_.WasSendTelephoneEventCalled(channel_id, 4, 145)); |
| 224 | EXPECT_FALSE(voe_.WasPlayDtmfToneCalled(4, 145)); |
| 225 | EXPECT_TRUE(channel_->InsertDtmf(ssrc, 4, 145, |
| 226 | cricket::DF_PLAY | cricket::DF_SEND)); |
| 227 | EXPECT_TRUE(voe_.WasSendTelephoneEventCalled(channel_id, 4, 145)); |
| 228 | EXPECT_TRUE(voe_.WasPlayDtmfToneCalled(4, 145)); |
| 229 | } |
| 230 | |
| 231 | // Test that send bandwidth is set correctly. |
| 232 | // |codec| is the codec under test. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 233 | // |max_bitrate| is a parameter to set to SetMaxSendBandwidth(). |
| 234 | // |expected_result| is the expected result from SetMaxSendBandwidth(). |
| 235 | // |expected_bitrate| is the expected audio bitrate afterward. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 236 | void TestSendBandwidth(const cricket::AudioCodec& codec, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 237 | int max_bitrate, |
| 238 | bool expected_result, |
| 239 | int expected_bitrate) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 240 | int channel_num = voe_.GetLastChannel(); |
| 241 | std::vector<cricket::AudioCodec> codecs; |
| 242 | |
| 243 | codecs.push_back(codec); |
| 244 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 245 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 246 | bool result = channel_->SetMaxSendBandwidth(max_bitrate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 247 | EXPECT_EQ(expected_result, result); |
| 248 | |
wu@webrtc.org | 1d1ffc9 | 2013-10-16 18:12:02 +0000 | [diff] [blame] | 249 | webrtc::CodecInst temp_codec; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 250 | EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec)); |
| 251 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 252 | EXPECT_EQ(expected_bitrate, temp_codec.rate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 253 | } |
| 254 | |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 255 | void TestSetSendRtpHeaderExtensions(const std::string& ext) { |
| 256 | EXPECT_TRUE(SetupEngineWithoutStream()); |
| 257 | int channel_num = voe_.GetLastChannel(); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 258 | |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 259 | // Ensure extensions are off by default. |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 260 | EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext)); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 261 | |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 262 | std::vector<cricket::RtpHeaderExtension> extensions; |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 263 | // Ensure unknown extensions won't cause an error. |
| 264 | extensions.push_back(cricket::RtpHeaderExtension( |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 265 | "urn:ietf:params:unknownextention", 1)); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 266 | EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions)); |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 267 | EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext)); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 268 | |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 269 | // Ensure extensions stay off with an empty list of headers. |
| 270 | extensions.clear(); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 271 | EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions)); |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 272 | EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext)); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 273 | |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 274 | // Ensure extension is set properly. |
| 275 | const int id = 1; |
| 276 | extensions.push_back(cricket::RtpHeaderExtension(ext, id)); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 277 | EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions)); |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 278 | EXPECT_EQ(id, voe_.GetSendRtpExtensionId(channel_num, ext)); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 279 | |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 280 | // Ensure extension is set properly on new channel. |
| 281 | // The first stream to occupy the default channel. |
| 282 | EXPECT_TRUE(channel_->AddSendStream( |
| 283 | cricket::StreamParams::CreateLegacy(123))); |
| 284 | EXPECT_TRUE(channel_->AddSendStream( |
| 285 | cricket::StreamParams::CreateLegacy(234))); |
| 286 | int new_channel_num = voe_.GetLastChannel(); |
| 287 | EXPECT_NE(channel_num, new_channel_num); |
| 288 | EXPECT_EQ(id, voe_.GetSendRtpExtensionId(new_channel_num, ext)); |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 289 | |
| 290 | // Ensure all extensions go back off with an empty list. |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 291 | extensions.clear(); |
| 292 | EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions)); |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 293 | EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext)); |
| 294 | EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(new_channel_num, ext)); |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 295 | } |
| 296 | |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 297 | void TestSetRecvRtpHeaderExtensions(const std::string& ext) { |
| 298 | EXPECT_TRUE(SetupEngineWithoutStream()); |
| 299 | int channel_num = voe_.GetLastChannel(); |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 300 | |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 301 | // Ensure extensions are off by default. |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 302 | EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext)); |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 303 | |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 304 | std::vector<cricket::RtpHeaderExtension> extensions; |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 305 | // Ensure unknown extensions won't cause an error. |
| 306 | extensions.push_back(cricket::RtpHeaderExtension( |
| 307 | "urn:ietf:params:unknownextention", 1)); |
| 308 | EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions)); |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 309 | EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext)); |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 310 | |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 311 | // Ensure extensions stay off with an empty list of headers. |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 312 | extensions.clear(); |
| 313 | EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions)); |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 314 | EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext)); |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 315 | |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 316 | // Ensure extension is set properly. |
| 317 | const int id = 2; |
| 318 | extensions.push_back(cricket::RtpHeaderExtension(ext, id)); |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 319 | EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions)); |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 320 | EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(channel_num, ext)); |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 321 | |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 322 | // Ensure extension is set properly on new channel. |
| 323 | // The first stream to occupy the default channel. |
| 324 | EXPECT_TRUE(channel_->AddRecvStream( |
| 325 | cricket::StreamParams::CreateLegacy(345))); |
| 326 | EXPECT_TRUE(channel_->AddRecvStream( |
| 327 | cricket::StreamParams::CreateLegacy(456))); |
| 328 | int new_channel_num = voe_.GetLastChannel(); |
| 329 | EXPECT_NE(channel_num, new_channel_num); |
| 330 | EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(new_channel_num, ext)); |
| 331 | |
| 332 | // Ensure all extensions go back off with an empty list. |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 333 | extensions.clear(); |
| 334 | EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions)); |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 335 | EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext)); |
| 336 | EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(new_channel_num, ext)); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 337 | } |
| 338 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 339 | protected: |
| 340 | cricket::FakeWebRtcVoiceEngine voe_; |
| 341 | cricket::FakeWebRtcVoiceEngine voe_sc_; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 342 | FakeVoETraceWrapper* trace_wrapper_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 343 | cricket::WebRtcVoiceEngine engine_; |
| 344 | cricket::VoiceMediaChannel* channel_; |
| 345 | cricket::SoundclipMedia* soundclip_; |
| 346 | |
| 347 | cricket::AudioOptions options_conference_; |
| 348 | cricket::AudioOptions options_adjust_agc_; |
| 349 | }; |
| 350 | |
| 351 | // Tests that our stub library "works". |
| 352 | TEST_F(WebRtcVoiceEngineTestFake, StartupShutdown) { |
| 353 | EXPECT_FALSE(voe_.IsInited()); |
| 354 | EXPECT_FALSE(voe_sc_.IsInited()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 355 | EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 356 | EXPECT_TRUE(voe_.IsInited()); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 357 | // The soundclip engine is lazily initialized. |
| 358 | EXPECT_FALSE(voe_sc_.IsInited()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 359 | engine_.Terminate(); |
| 360 | EXPECT_FALSE(voe_.IsInited()); |
| 361 | EXPECT_FALSE(voe_sc_.IsInited()); |
| 362 | } |
| 363 | |
| 364 | // Tests that we can create and destroy a channel. |
| 365 | TEST_F(WebRtcVoiceEngineTestFake, CreateChannel) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 366 | EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 367 | channel_ = engine_.CreateChannel(); |
| 368 | EXPECT_TRUE(channel_ != NULL); |
| 369 | } |
| 370 | |
| 371 | // Tests that we properly handle failures in CreateChannel. |
| 372 | TEST_F(WebRtcVoiceEngineTestFake, CreateChannelFail) { |
| 373 | voe_.set_fail_create_channel(true); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 374 | EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 375 | channel_ = engine_.CreateChannel(); |
| 376 | EXPECT_TRUE(channel_ == NULL); |
| 377 | } |
| 378 | |
| 379 | // Tests that the list of supported codecs is created properly and ordered |
| 380 | // correctly |
| 381 | TEST_F(WebRtcVoiceEngineTestFake, CodecPreference) { |
| 382 | const std::vector<cricket::AudioCodec>& codecs = engine_.codecs(); |
| 383 | ASSERT_FALSE(codecs.empty()); |
| 384 | EXPECT_STRCASEEQ("opus", codecs[0].name.c_str()); |
| 385 | EXPECT_EQ(48000, codecs[0].clockrate); |
| 386 | EXPECT_EQ(2, codecs[0].channels); |
| 387 | EXPECT_EQ(64000, codecs[0].bitrate); |
| 388 | int pref = codecs[0].preference; |
| 389 | for (size_t i = 1; i < codecs.size(); ++i) { |
| 390 | EXPECT_GT(pref, codecs[i].preference); |
| 391 | pref = codecs[i].preference; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | // Tests that we can find codecs by name or id, and that we interpret the |
| 396 | // clockrate and bitrate fields properly. |
| 397 | TEST_F(WebRtcVoiceEngineTestFake, FindCodec) { |
| 398 | cricket::AudioCodec codec; |
| 399 | webrtc::CodecInst codec_inst; |
| 400 | // Find PCMU with explicit clockrate and bitrate. |
| 401 | EXPECT_TRUE(engine_.FindWebRtcCodec(kPcmuCodec, &codec_inst)); |
| 402 | // Find ISAC with explicit clockrate and 0 bitrate. |
| 403 | EXPECT_TRUE(engine_.FindWebRtcCodec(kIsacCodec, &codec_inst)); |
| 404 | // Find telephone-event with explicit clockrate and 0 bitrate. |
| 405 | EXPECT_TRUE(engine_.FindWebRtcCodec(kTelephoneEventCodec, &codec_inst)); |
| 406 | // Find ISAC with a different payload id. |
| 407 | codec = kIsacCodec; |
| 408 | codec.id = 127; |
| 409 | EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst)); |
| 410 | EXPECT_EQ(codec.id, codec_inst.pltype); |
| 411 | // Find PCMU with a 0 clockrate. |
| 412 | codec = kPcmuCodec; |
| 413 | codec.clockrate = 0; |
| 414 | EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst)); |
| 415 | EXPECT_EQ(codec.id, codec_inst.pltype); |
| 416 | EXPECT_EQ(8000, codec_inst.plfreq); |
| 417 | // Find PCMU with a 0 bitrate. |
| 418 | codec = kPcmuCodec; |
| 419 | codec.bitrate = 0; |
| 420 | EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst)); |
| 421 | EXPECT_EQ(codec.id, codec_inst.pltype); |
| 422 | EXPECT_EQ(64000, codec_inst.rate); |
| 423 | // Find ISAC with an explicit bitrate. |
| 424 | codec = kIsacCodec; |
| 425 | codec.bitrate = 32000; |
| 426 | EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst)); |
| 427 | EXPECT_EQ(codec.id, codec_inst.pltype); |
| 428 | EXPECT_EQ(32000, codec_inst.rate); |
| 429 | } |
| 430 | |
| 431 | // Test that we set our inbound codecs properly, including changing PT. |
| 432 | TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecs) { |
| 433 | EXPECT_TRUE(SetupEngine()); |
| 434 | int channel_num = voe_.GetLastChannel(); |
| 435 | std::vector<cricket::AudioCodec> codecs; |
| 436 | codecs.push_back(kIsacCodec); |
| 437 | codecs.push_back(kPcmuCodec); |
| 438 | codecs.push_back(kTelephoneEventCodec); |
| 439 | codecs[0].id = 106; // collide with existing telephone-event |
| 440 | codecs[2].id = 126; |
| 441 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 442 | webrtc::CodecInst gcodec; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 443 | rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 444 | gcodec.plfreq = 16000; |
| 445 | gcodec.channels = 1; |
| 446 | EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec)); |
| 447 | EXPECT_EQ(106, gcodec.pltype); |
| 448 | EXPECT_STREQ("ISAC", gcodec.plname); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 449 | rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 450 | "telephone-event"); |
| 451 | gcodec.plfreq = 8000; |
| 452 | EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec)); |
| 453 | EXPECT_EQ(126, gcodec.pltype); |
| 454 | EXPECT_STREQ("telephone-event", gcodec.plname); |
| 455 | } |
| 456 | |
| 457 | // Test that we fail to set an unknown inbound codec. |
| 458 | TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) { |
| 459 | EXPECT_TRUE(SetupEngine()); |
| 460 | std::vector<cricket::AudioCodec> codecs; |
| 461 | codecs.push_back(kIsacCodec); |
| 462 | codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1, 0)); |
| 463 | EXPECT_FALSE(channel_->SetRecvCodecs(codecs)); |
| 464 | } |
| 465 | |
| 466 | // Test that we fail if we have duplicate types in the inbound list. |
| 467 | TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsDuplicatePayloadType) { |
| 468 | EXPECT_TRUE(SetupEngine()); |
| 469 | std::vector<cricket::AudioCodec> codecs; |
| 470 | codecs.push_back(kIsacCodec); |
| 471 | codecs.push_back(kCn16000Codec); |
| 472 | codecs[1].id = kIsacCodec.id; |
| 473 | EXPECT_FALSE(channel_->SetRecvCodecs(codecs)); |
| 474 | } |
| 475 | |
| 476 | // Test that we can decode OPUS without stereo parameters. |
| 477 | TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) { |
| 478 | EXPECT_TRUE(SetupEngine()); |
| 479 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 480 | std::vector<cricket::AudioCodec> codecs; |
| 481 | codecs.push_back(kIsacCodec); |
| 482 | codecs.push_back(kPcmuCodec); |
| 483 | codecs.push_back(kOpusCodec); |
| 484 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 485 | EXPECT_TRUE(channel_->AddRecvStream( |
| 486 | cricket::StreamParams::CreateLegacy(kSsrc1))); |
| 487 | int channel_num2 = voe_.GetLastChannel(); |
| 488 | webrtc::CodecInst opus; |
| 489 | engine_.FindWebRtcCodec(kOpusCodec, &opus); |
| 490 | // Even without stereo parameters, recv codecs still specify channels = 2. |
| 491 | EXPECT_EQ(2, opus.channels); |
| 492 | EXPECT_EQ(111, opus.pltype); |
| 493 | EXPECT_STREQ("opus", opus.plname); |
| 494 | opus.pltype = 0; |
| 495 | EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus)); |
| 496 | EXPECT_EQ(111, opus.pltype); |
| 497 | } |
| 498 | |
| 499 | // Test that we can decode OPUS with stereo = 0. |
| 500 | TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) { |
| 501 | EXPECT_TRUE(SetupEngine()); |
| 502 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 503 | std::vector<cricket::AudioCodec> codecs; |
| 504 | codecs.push_back(kIsacCodec); |
| 505 | codecs.push_back(kPcmuCodec); |
| 506 | codecs.push_back(kOpusCodec); |
| 507 | codecs[2].params["stereo"] = "0"; |
| 508 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 509 | EXPECT_TRUE(channel_->AddRecvStream( |
| 510 | cricket::StreamParams::CreateLegacy(kSsrc1))); |
| 511 | int channel_num2 = voe_.GetLastChannel(); |
| 512 | webrtc::CodecInst opus; |
| 513 | engine_.FindWebRtcCodec(kOpusCodec, &opus); |
| 514 | // Even when stereo is off, recv codecs still specify channels = 2. |
| 515 | EXPECT_EQ(2, opus.channels); |
| 516 | EXPECT_EQ(111, opus.pltype); |
| 517 | EXPECT_STREQ("opus", opus.plname); |
| 518 | opus.pltype = 0; |
| 519 | EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus)); |
| 520 | EXPECT_EQ(111, opus.pltype); |
| 521 | } |
| 522 | |
| 523 | // Test that we can decode OPUS with stereo = 1. |
| 524 | TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus1Stereo) { |
| 525 | EXPECT_TRUE(SetupEngine()); |
| 526 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 527 | std::vector<cricket::AudioCodec> codecs; |
| 528 | codecs.push_back(kIsacCodec); |
| 529 | codecs.push_back(kPcmuCodec); |
| 530 | codecs.push_back(kOpusCodec); |
| 531 | codecs[2].params["stereo"] = "1"; |
| 532 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 533 | EXPECT_TRUE(channel_->AddRecvStream( |
| 534 | cricket::StreamParams::CreateLegacy(kSsrc1))); |
| 535 | int channel_num2 = voe_.GetLastChannel(); |
| 536 | webrtc::CodecInst opus; |
| 537 | engine_.FindWebRtcCodec(kOpusCodec, &opus); |
| 538 | EXPECT_EQ(2, opus.channels); |
| 539 | EXPECT_EQ(111, opus.pltype); |
| 540 | EXPECT_STREQ("opus", opus.plname); |
| 541 | opus.pltype = 0; |
| 542 | EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus)); |
| 543 | EXPECT_EQ(111, opus.pltype); |
| 544 | } |
| 545 | |
| 546 | // Test that changes to recv codecs are applied to all streams. |
| 547 | TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithMultipleStreams) { |
| 548 | EXPECT_TRUE(SetupEngine()); |
| 549 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 550 | std::vector<cricket::AudioCodec> codecs; |
| 551 | codecs.push_back(kIsacCodec); |
| 552 | codecs.push_back(kPcmuCodec); |
| 553 | codecs.push_back(kTelephoneEventCodec); |
| 554 | codecs[0].id = 106; // collide with existing telephone-event |
| 555 | codecs[2].id = 126; |
| 556 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 557 | EXPECT_TRUE(channel_->AddRecvStream( |
| 558 | cricket::StreamParams::CreateLegacy(kSsrc1))); |
| 559 | int channel_num2 = voe_.GetLastChannel(); |
| 560 | webrtc::CodecInst gcodec; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 561 | rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 562 | gcodec.plfreq = 16000; |
| 563 | gcodec.channels = 1; |
| 564 | EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec)); |
| 565 | EXPECT_EQ(106, gcodec.pltype); |
| 566 | EXPECT_STREQ("ISAC", gcodec.plname); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 567 | rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 568 | "telephone-event"); |
| 569 | gcodec.plfreq = 8000; |
| 570 | gcodec.channels = 1; |
| 571 | EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec)); |
| 572 | EXPECT_EQ(126, gcodec.pltype); |
| 573 | EXPECT_STREQ("telephone-event", gcodec.plname); |
| 574 | } |
| 575 | |
| 576 | TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) { |
| 577 | EXPECT_TRUE(SetupEngine()); |
| 578 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 579 | std::vector<cricket::AudioCodec> codecs; |
| 580 | codecs.push_back(kIsacCodec); |
| 581 | codecs[0].id = 106; // collide with existing telephone-event |
| 582 | |
| 583 | EXPECT_TRUE(channel_->AddRecvStream( |
| 584 | cricket::StreamParams::CreateLegacy(kSsrc1))); |
| 585 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 586 | |
| 587 | int channel_num2 = voe_.GetLastChannel(); |
| 588 | webrtc::CodecInst gcodec; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 589 | rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 590 | gcodec.plfreq = 16000; |
| 591 | gcodec.channels = 1; |
| 592 | EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec)); |
| 593 | EXPECT_EQ(106, gcodec.pltype); |
| 594 | EXPECT_STREQ("ISAC", gcodec.plname); |
| 595 | } |
| 596 | |
| 597 | // Test that we can apply the same set of codecs again while playing. |
| 598 | TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWhilePlaying) { |
| 599 | EXPECT_TRUE(SetupEngine()); |
| 600 | int channel_num = voe_.GetLastChannel(); |
| 601 | std::vector<cricket::AudioCodec> codecs; |
| 602 | codecs.push_back(kIsacCodec); |
| 603 | codecs.push_back(kCn16000Codec); |
| 604 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 605 | EXPECT_TRUE(channel_->SetPlayout(true)); |
| 606 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 607 | |
| 608 | // Changing the payload type of a codec should fail. |
| 609 | codecs[0].id = 127; |
| 610 | EXPECT_FALSE(channel_->SetRecvCodecs(codecs)); |
| 611 | EXPECT_TRUE(voe_.GetPlayout(channel_num)); |
| 612 | } |
| 613 | |
| 614 | // Test that we can add a codec while playing. |
| 615 | TEST_F(WebRtcVoiceEngineTestFake, AddRecvCodecsWhilePlaying) { |
| 616 | EXPECT_TRUE(SetupEngine()); |
| 617 | int channel_num = voe_.GetLastChannel(); |
| 618 | std::vector<cricket::AudioCodec> codecs; |
| 619 | codecs.push_back(kIsacCodec); |
| 620 | codecs.push_back(kCn16000Codec); |
| 621 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 622 | EXPECT_TRUE(channel_->SetPlayout(true)); |
| 623 | |
| 624 | codecs.push_back(kOpusCodec); |
| 625 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 626 | EXPECT_TRUE(voe_.GetPlayout(channel_num)); |
| 627 | webrtc::CodecInst gcodec; |
| 628 | EXPECT_TRUE(engine_.FindWebRtcCodec(kOpusCodec, &gcodec)); |
| 629 | EXPECT_EQ(kOpusCodec.id, gcodec.pltype); |
| 630 | } |
| 631 | |
| 632 | TEST_F(WebRtcVoiceEngineTestFake, SetSendBandwidthAuto) { |
| 633 | EXPECT_TRUE(SetupEngine()); |
| 634 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 635 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 636 | // Test that when autobw is enabled, bitrate is kept as the default |
| 637 | // value. autobw is enabled for the following tests because the target |
| 638 | // bitrate is <= 0. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 639 | |
| 640 | // ISAC, default bitrate == 32000. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 641 | TestSendBandwidth(kIsacCodec, 0, true, 32000); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 642 | |
| 643 | // PCMU, default bitrate == 64000. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 644 | TestSendBandwidth(kPcmuCodec, -1, true, 64000); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 645 | |
| 646 | // CELT, default bitrate == 64000. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 647 | TestSendBandwidth(kCeltCodec, 0, true, 64000); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 648 | |
| 649 | // opus, default bitrate == 64000. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 650 | TestSendBandwidth(kOpusCodec, -1, true, 64000); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 651 | } |
| 652 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 653 | TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCaller) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 654 | EXPECT_TRUE(SetupEngine()); |
| 655 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 656 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 657 | // Test that the bitrate of a multi-rate codec is always the maximum. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 658 | |
| 659 | // ISAC, default bitrate == 32000. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 660 | TestSendBandwidth(kIsacCodec, 128000, true, 128000); |
| 661 | TestSendBandwidth(kIsacCodec, 16000, true, 16000); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 662 | |
| 663 | // CELT, default bitrate == 64000. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 664 | TestSendBandwidth(kCeltCodec, 96000, true, 96000); |
| 665 | TestSendBandwidth(kCeltCodec, 32000, true, 32000); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 666 | |
| 667 | // opus, default bitrate == 64000. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 668 | TestSendBandwidth(kOpusCodec, 96000, true, 96000); |
| 669 | TestSendBandwidth(kOpusCodec, 48000, true, 48000); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 670 | } |
| 671 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 672 | TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthFixedRateAsCaller) { |
| 673 | EXPECT_TRUE(SetupEngine()); |
| 674 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 675 | |
| 676 | // Test that we can only set a maximum bitrate for a fixed-rate codec |
| 677 | // if it's bigger than the fixed rate. |
| 678 | |
| 679 | // PCMU, fixed bitrate == 64000. |
| 680 | TestSendBandwidth(kPcmuCodec, 0, true, 64000); |
| 681 | TestSendBandwidth(kPcmuCodec, 1, false, 64000); |
| 682 | TestSendBandwidth(kPcmuCodec, 128000, true, 64000); |
| 683 | TestSendBandwidth(kPcmuCodec, 32000, false, 64000); |
| 684 | TestSendBandwidth(kPcmuCodec, 64000, true, 64000); |
| 685 | TestSendBandwidth(kPcmuCodec, 63999, false, 64000); |
| 686 | TestSendBandwidth(kPcmuCodec, 64001, true, 64000); |
| 687 | } |
| 688 | |
| 689 | TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCallee) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 690 | EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); |
wu@webrtc.org | 1d1ffc9 | 2013-10-16 18:12:02 +0000 | [diff] [blame] | 691 | channel_ = engine_.CreateChannel(); |
| 692 | EXPECT_TRUE(channel_ != NULL); |
| 693 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 694 | |
| 695 | int desired_bitrate = 128000; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 696 | EXPECT_TRUE(channel_->SetMaxSendBandwidth(desired_bitrate)); |
wu@webrtc.org | 1d1ffc9 | 2013-10-16 18:12:02 +0000 | [diff] [blame] | 697 | |
| 698 | EXPECT_TRUE(channel_->AddSendStream( |
| 699 | cricket::StreamParams::CreateLegacy(kSsrc1))); |
| 700 | |
| 701 | int channel_num = voe_.GetLastChannel(); |
| 702 | webrtc::CodecInst codec; |
| 703 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); |
| 704 | EXPECT_EQ(desired_bitrate, codec.rate); |
| 705 | } |
| 706 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 707 | // Test that bitrate cannot be set for CBR codecs. |
| 708 | // Bitrate is ignored if it is higher than the fixed bitrate. |
| 709 | // Bitrate less then the fixed bitrate is an error. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 710 | TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthCbr) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 711 | EXPECT_TRUE(SetupEngine()); |
| 712 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 713 | |
| 714 | webrtc::CodecInst codec; |
| 715 | int channel_num = voe_.GetLastChannel(); |
| 716 | std::vector<cricket::AudioCodec> codecs; |
| 717 | |
| 718 | // PCMU, default bitrate == 64000. |
| 719 | codecs.push_back(kPcmuCodec); |
| 720 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 721 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); |
| 722 | EXPECT_EQ(64000, codec.rate); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 723 | EXPECT_TRUE(channel_->SetMaxSendBandwidth(128000)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 724 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); |
| 725 | EXPECT_EQ(64000, codec.rate); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 726 | EXPECT_FALSE(channel_->SetMaxSendBandwidth(128)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 727 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); |
| 728 | EXPECT_EQ(64000, codec.rate); |
| 729 | } |
| 730 | |
| 731 | // Test that we apply codecs properly. |
| 732 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) { |
| 733 | EXPECT_TRUE(SetupEngine()); |
| 734 | int channel_num = voe_.GetLastChannel(); |
| 735 | std::vector<cricket::AudioCodec> codecs; |
| 736 | codecs.push_back(kIsacCodec); |
| 737 | codecs.push_back(kPcmuCodec); |
| 738 | codecs.push_back(kRedCodec); |
| 739 | codecs[0].id = 96; |
| 740 | codecs[0].bitrate = 48000; |
| 741 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
wu@webrtc.org | 05e7b44 | 2014-04-01 17:44:24 +0000 | [diff] [blame] | 742 | EXPECT_EQ(1, voe_.GetNumSetSendCodecs()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 743 | webrtc::CodecInst gcodec; |
| 744 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 745 | EXPECT_EQ(96, gcodec.pltype); |
| 746 | EXPECT_EQ(48000, gcodec.rate); |
| 747 | EXPECT_STREQ("ISAC", gcodec.plname); |
| 748 | EXPECT_FALSE(voe_.GetVAD(channel_num)); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 749 | EXPECT_FALSE(voe_.GetRED(channel_num)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 750 | EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); |
| 751 | EXPECT_EQ(105, voe_.GetSendCNPayloadType(channel_num, true)); |
| 752 | EXPECT_EQ(106, voe_.GetSendTelephoneEventPayloadType(channel_num)); |
| 753 | } |
| 754 | |
wu@webrtc.org | 05e7b44 | 2014-04-01 17:44:24 +0000 | [diff] [blame] | 755 | // Test that VoE Channel doesn't call SetSendCodec again if same codec is tried |
| 756 | // to apply. |
| 757 | TEST_F(WebRtcVoiceEngineTestFake, DontResetSetSendCodec) { |
| 758 | EXPECT_TRUE(SetupEngine()); |
| 759 | std::vector<cricket::AudioCodec> codecs; |
| 760 | codecs.push_back(kIsacCodec); |
| 761 | codecs.push_back(kPcmuCodec); |
| 762 | codecs.push_back(kRedCodec); |
| 763 | codecs[0].id = 96; |
| 764 | codecs[0].bitrate = 48000; |
| 765 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 766 | EXPECT_EQ(1, voe_.GetNumSetSendCodecs()); |
| 767 | // Calling SetSendCodec again with same codec which is already set. |
| 768 | // In this case media channel shouldn't send codec to VoE. |
| 769 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 770 | EXPECT_EQ(1, voe_.GetNumSetSendCodecs()); |
| 771 | } |
| 772 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 773 | // Test that if clockrate is not 48000 for opus, we fail. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 774 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBadClockrate) { |
| 775 | EXPECT_TRUE(SetupEngine()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 776 | std::vector<cricket::AudioCodec> codecs; |
| 777 | codecs.push_back(kOpusCodec); |
| 778 | codecs[0].bitrate = 0; |
| 779 | codecs[0].clockrate = 50000; |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 780 | EXPECT_FALSE(channel_->SetSendCodecs(codecs)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 781 | } |
| 782 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 783 | // Test that if channels=0 for opus, we fail. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 784 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0ChannelsNoStereo) { |
| 785 | EXPECT_TRUE(SetupEngine()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 786 | std::vector<cricket::AudioCodec> codecs; |
| 787 | codecs.push_back(kOpusCodec); |
| 788 | codecs[0].bitrate = 0; |
| 789 | codecs[0].channels = 0; |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 790 | EXPECT_FALSE(channel_->SetSendCodecs(codecs)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 791 | } |
| 792 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 793 | // Test that if channels=0 for opus, we fail. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 794 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0Channels1Stereo) { |
| 795 | EXPECT_TRUE(SetupEngine()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 796 | std::vector<cricket::AudioCodec> codecs; |
| 797 | codecs.push_back(kOpusCodec); |
| 798 | codecs[0].bitrate = 0; |
| 799 | codecs[0].channels = 0; |
| 800 | codecs[0].params["stereo"] = "1"; |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 801 | EXPECT_FALSE(channel_->SetSendCodecs(codecs)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | // Test that if channel is 1 for opus and there's no stereo, we fail. |
| 805 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpus1ChannelNoStereo) { |
| 806 | EXPECT_TRUE(SetupEngine()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 807 | std::vector<cricket::AudioCodec> codecs; |
| 808 | codecs.push_back(kOpusCodec); |
| 809 | codecs[0].bitrate = 0; |
| 810 | codecs[0].channels = 1; |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 811 | EXPECT_FALSE(channel_->SetSendCodecs(codecs)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | // Test that if channel is 1 for opus and stereo=0, we fail. |
| 815 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel0Stereo) { |
| 816 | EXPECT_TRUE(SetupEngine()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 817 | std::vector<cricket::AudioCodec> codecs; |
| 818 | codecs.push_back(kOpusCodec); |
| 819 | codecs[0].bitrate = 0; |
| 820 | codecs[0].channels = 1; |
| 821 | codecs[0].params["stereo"] = "0"; |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 822 | EXPECT_FALSE(channel_->SetSendCodecs(codecs)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | // Test that if channel is 1 for opus and stereo=1, we fail. |
| 826 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel1Stereo) { |
| 827 | EXPECT_TRUE(SetupEngine()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 828 | std::vector<cricket::AudioCodec> codecs; |
| 829 | codecs.push_back(kOpusCodec); |
| 830 | codecs[0].bitrate = 0; |
| 831 | codecs[0].channels = 1; |
| 832 | codecs[0].params["stereo"] = "1"; |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 833 | EXPECT_FALSE(channel_->SetSendCodecs(codecs)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | // Test that with bitrate=0 and no stereo, |
| 837 | // channels and bitrate are 1 and 32000. |
| 838 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0BitrateNoStereo) { |
| 839 | EXPECT_TRUE(SetupEngine()); |
| 840 | int channel_num = voe_.GetLastChannel(); |
| 841 | std::vector<cricket::AudioCodec> codecs; |
| 842 | codecs.push_back(kOpusCodec); |
| 843 | codecs[0].bitrate = 0; |
| 844 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 845 | webrtc::CodecInst gcodec; |
| 846 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 847 | EXPECT_STREQ("opus", gcodec.plname); |
| 848 | EXPECT_EQ(1, gcodec.channels); |
| 849 | EXPECT_EQ(32000, gcodec.rate); |
| 850 | } |
| 851 | |
| 852 | // Test that with bitrate=0 and stereo=0, |
| 853 | // channels and bitrate are 1 and 32000. |
| 854 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate0Stereo) { |
| 855 | EXPECT_TRUE(SetupEngine()); |
| 856 | int channel_num = voe_.GetLastChannel(); |
| 857 | std::vector<cricket::AudioCodec> codecs; |
| 858 | codecs.push_back(kOpusCodec); |
| 859 | codecs[0].bitrate = 0; |
| 860 | codecs[0].params["stereo"] = "0"; |
| 861 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 862 | webrtc::CodecInst gcodec; |
| 863 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 864 | EXPECT_STREQ("opus", gcodec.plname); |
| 865 | EXPECT_EQ(1, gcodec.channels); |
| 866 | EXPECT_EQ(32000, gcodec.rate); |
| 867 | } |
| 868 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 869 | // Test that with bitrate=invalid and stereo=0, |
| 870 | // channels and bitrate are 1 and 32000. |
| 871 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate0Stereo) { |
| 872 | EXPECT_TRUE(SetupEngine()); |
| 873 | int channel_num = voe_.GetLastChannel(); |
| 874 | std::vector<cricket::AudioCodec> codecs; |
| 875 | codecs.push_back(kOpusCodec); |
| 876 | codecs[0].params["stereo"] = "0"; |
| 877 | webrtc::CodecInst gcodec; |
| 878 | |
buildbot@webrtc.org | 9d446f2 | 2014-10-23 12:22:06 +0000 | [diff] [blame] | 879 | // bitrate that's out of the range between 6000 and 510000 will be clamped. |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 880 | codecs[0].bitrate = 5999; |
| 881 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 882 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 883 | EXPECT_STREQ("opus", gcodec.plname); |
| 884 | EXPECT_EQ(1, gcodec.channels); |
buildbot@webrtc.org | 9d446f2 | 2014-10-23 12:22:06 +0000 | [diff] [blame] | 885 | EXPECT_EQ(6000, gcodec.rate); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 886 | |
| 887 | codecs[0].bitrate = 510001; |
| 888 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 889 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 890 | EXPECT_STREQ("opus", gcodec.plname); |
| 891 | EXPECT_EQ(1, gcodec.channels); |
buildbot@webrtc.org | 9d446f2 | 2014-10-23 12:22:06 +0000 | [diff] [blame] | 892 | EXPECT_EQ(510000, gcodec.rate); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 893 | } |
| 894 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 895 | // Test that with bitrate=0 and stereo=1, |
| 896 | // channels and bitrate are 2 and 64000. |
| 897 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate1Stereo) { |
| 898 | EXPECT_TRUE(SetupEngine()); |
| 899 | int channel_num = voe_.GetLastChannel(); |
| 900 | std::vector<cricket::AudioCodec> codecs; |
| 901 | codecs.push_back(kOpusCodec); |
| 902 | codecs[0].bitrate = 0; |
| 903 | codecs[0].params["stereo"] = "1"; |
| 904 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 905 | webrtc::CodecInst gcodec; |
| 906 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 907 | EXPECT_STREQ("opus", gcodec.plname); |
| 908 | EXPECT_EQ(2, gcodec.channels); |
| 909 | EXPECT_EQ(64000, gcodec.rate); |
| 910 | } |
| 911 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 912 | // Test that with bitrate=invalid and stereo=1, |
| 913 | // channels and bitrate are 2 and 64000. |
| 914 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate1Stereo) { |
| 915 | EXPECT_TRUE(SetupEngine()); |
| 916 | int channel_num = voe_.GetLastChannel(); |
| 917 | std::vector<cricket::AudioCodec> codecs; |
| 918 | codecs.push_back(kOpusCodec); |
| 919 | codecs[0].params["stereo"] = "1"; |
| 920 | webrtc::CodecInst gcodec; |
| 921 | |
buildbot@webrtc.org | 9d446f2 | 2014-10-23 12:22:06 +0000 | [diff] [blame] | 922 | // bitrate that's out of the range between 6000 and 510000 will be clamped. |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 923 | codecs[0].bitrate = 5999; |
| 924 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 925 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 926 | EXPECT_STREQ("opus", gcodec.plname); |
| 927 | EXPECT_EQ(2, gcodec.channels); |
buildbot@webrtc.org | 9d446f2 | 2014-10-23 12:22:06 +0000 | [diff] [blame] | 928 | EXPECT_EQ(6000, gcodec.rate); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 929 | |
| 930 | codecs[0].bitrate = 510001; |
| 931 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 932 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 933 | EXPECT_STREQ("opus", gcodec.plname); |
| 934 | EXPECT_EQ(2, gcodec.channels); |
buildbot@webrtc.org | 9d446f2 | 2014-10-23 12:22:06 +0000 | [diff] [blame] | 935 | EXPECT_EQ(510000, gcodec.rate); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 936 | } |
| 937 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 938 | // Test that with bitrate=N and stereo unset, |
| 939 | // channels and bitrate are 1 and N. |
| 940 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoStereo) { |
| 941 | EXPECT_TRUE(SetupEngine()); |
| 942 | int channel_num = voe_.GetLastChannel(); |
| 943 | std::vector<cricket::AudioCodec> codecs; |
| 944 | codecs.push_back(kOpusCodec); |
| 945 | codecs[0].bitrate = 96000; |
| 946 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 947 | webrtc::CodecInst gcodec; |
| 948 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 949 | EXPECT_EQ(111, gcodec.pltype); |
| 950 | EXPECT_EQ(96000, gcodec.rate); |
| 951 | EXPECT_STREQ("opus", gcodec.plname); |
| 952 | EXPECT_EQ(1, gcodec.channels); |
| 953 | EXPECT_EQ(48000, gcodec.plfreq); |
| 954 | } |
| 955 | |
| 956 | // Test that with bitrate=N and stereo=0, |
| 957 | // channels and bitrate are 1 and N. |
| 958 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate0Stereo) { |
| 959 | EXPECT_TRUE(SetupEngine()); |
| 960 | int channel_num = voe_.GetLastChannel(); |
| 961 | std::vector<cricket::AudioCodec> codecs; |
| 962 | codecs.push_back(kOpusCodec); |
| 963 | codecs[0].bitrate = 30000; |
| 964 | codecs[0].params["stereo"] = "0"; |
| 965 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 966 | webrtc::CodecInst gcodec; |
| 967 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 968 | EXPECT_EQ(1, gcodec.channels); |
| 969 | EXPECT_EQ(30000, gcodec.rate); |
| 970 | EXPECT_STREQ("opus", gcodec.plname); |
| 971 | } |
| 972 | |
| 973 | // Test that with bitrate=N and without any parameters, |
| 974 | // channels and bitrate are 1 and N. |
| 975 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoParameters) { |
| 976 | EXPECT_TRUE(SetupEngine()); |
| 977 | int channel_num = voe_.GetLastChannel(); |
| 978 | std::vector<cricket::AudioCodec> codecs; |
| 979 | codecs.push_back(kOpusCodec); |
| 980 | codecs[0].bitrate = 30000; |
| 981 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 982 | webrtc::CodecInst gcodec; |
| 983 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 984 | EXPECT_EQ(1, gcodec.channels); |
| 985 | EXPECT_EQ(30000, gcodec.rate); |
| 986 | EXPECT_STREQ("opus", gcodec.plname); |
| 987 | } |
| 988 | |
| 989 | // Test that with bitrate=N and stereo=1, |
| 990 | // channels and bitrate are 2 and N. |
| 991 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate1Stereo) { |
| 992 | EXPECT_TRUE(SetupEngine()); |
| 993 | int channel_num = voe_.GetLastChannel(); |
| 994 | std::vector<cricket::AudioCodec> codecs; |
| 995 | codecs.push_back(kOpusCodec); |
| 996 | codecs[0].bitrate = 30000; |
| 997 | codecs[0].params["stereo"] = "1"; |
| 998 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 999 | webrtc::CodecInst gcodec; |
| 1000 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1001 | EXPECT_EQ(2, gcodec.channels); |
| 1002 | EXPECT_EQ(30000, gcodec.rate); |
| 1003 | EXPECT_STREQ("opus", gcodec.plname); |
| 1004 | } |
| 1005 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1006 | // Test that bitrate will be overridden by the "maxaveragebitrate" parameter. |
| 1007 | // Also test that the "maxaveragebitrate" can't be set to values outside the |
| 1008 | // range of 6000 and 510000 |
| 1009 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusMaxAverageBitrate) { |
| 1010 | EXPECT_TRUE(SetupEngine()); |
| 1011 | int channel_num = voe_.GetLastChannel(); |
| 1012 | std::vector<cricket::AudioCodec> codecs; |
| 1013 | codecs.push_back(kOpusCodec); |
| 1014 | codecs[0].bitrate = 30000; |
| 1015 | webrtc::CodecInst gcodec; |
| 1016 | |
| 1017 | // Ignore if less than 6000. |
| 1018 | codecs[0].params["maxaveragebitrate"] = "5999"; |
| 1019 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1020 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
buildbot@webrtc.org | 9d446f2 | 2014-10-23 12:22:06 +0000 | [diff] [blame] | 1021 | EXPECT_EQ(6000, gcodec.rate); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1022 | |
| 1023 | // Ignore if larger than 510000. |
| 1024 | codecs[0].params["maxaveragebitrate"] = "510001"; |
| 1025 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1026 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
buildbot@webrtc.org | 9d446f2 | 2014-10-23 12:22:06 +0000 | [diff] [blame] | 1027 | EXPECT_EQ(510000, gcodec.rate); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1028 | |
| 1029 | codecs[0].params["maxaveragebitrate"] = "200000"; |
| 1030 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1031 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1032 | EXPECT_EQ(200000, gcodec.rate); |
| 1033 | } |
| 1034 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 1035 | // Test that we can enable NACK with opus as caller. |
| 1036 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCaller) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1037 | EXPECT_TRUE(SetupEngine()); |
| 1038 | int channel_num = voe_.GetLastChannel(); |
| 1039 | std::vector<cricket::AudioCodec> codecs; |
| 1040 | codecs.push_back(kOpusCodec); |
| 1041 | codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1042 | cricket::kParamValueEmpty)); |
| 1043 | EXPECT_FALSE(voe_.GetNACK(channel_num)); |
| 1044 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1045 | EXPECT_TRUE(voe_.GetNACK(channel_num)); |
| 1046 | } |
| 1047 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 1048 | // Test that we can enable NACK with opus as callee. |
| 1049 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCallee) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1050 | EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 1051 | channel_ = engine_.CreateChannel(); |
| 1052 | EXPECT_TRUE(channel_ != NULL); |
| 1053 | |
| 1054 | int channel_num = voe_.GetLastChannel(); |
| 1055 | std::vector<cricket::AudioCodec> codecs; |
| 1056 | codecs.push_back(kOpusCodec); |
| 1057 | codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1058 | cricket::kParamValueEmpty)); |
| 1059 | EXPECT_FALSE(voe_.GetNACK(channel_num)); |
| 1060 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1061 | EXPECT_FALSE(voe_.GetNACK(channel_num)); |
| 1062 | |
| 1063 | EXPECT_TRUE(channel_->AddSendStream( |
| 1064 | cricket::StreamParams::CreateLegacy(kSsrc1))); |
| 1065 | EXPECT_TRUE(voe_.GetNACK(channel_num)); |
| 1066 | } |
| 1067 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1068 | // Test that we can enable NACK on receive streams. |
| 1069 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackRecvStreams) { |
| 1070 | EXPECT_TRUE(SetupEngine()); |
| 1071 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 1072 | int channel_num1 = voe_.GetLastChannel(); |
| 1073 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| 1074 | int channel_num2 = voe_.GetLastChannel(); |
| 1075 | std::vector<cricket::AudioCodec> codecs; |
| 1076 | codecs.push_back(kOpusCodec); |
| 1077 | codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1078 | cricket::kParamValueEmpty)); |
| 1079 | EXPECT_FALSE(voe_.GetNACK(channel_num1)); |
| 1080 | EXPECT_FALSE(voe_.GetNACK(channel_num2)); |
| 1081 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1082 | EXPECT_TRUE(voe_.GetNACK(channel_num1)); |
| 1083 | EXPECT_TRUE(voe_.GetNACK(channel_num2)); |
| 1084 | } |
| 1085 | |
| 1086 | // Test that we can disable NACK. |
| 1087 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNack) { |
| 1088 | EXPECT_TRUE(SetupEngine()); |
| 1089 | int channel_num = voe_.GetLastChannel(); |
| 1090 | std::vector<cricket::AudioCodec> codecs; |
| 1091 | codecs.push_back(kOpusCodec); |
| 1092 | codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1093 | cricket::kParamValueEmpty)); |
| 1094 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1095 | EXPECT_TRUE(voe_.GetNACK(channel_num)); |
| 1096 | |
| 1097 | codecs.clear(); |
| 1098 | codecs.push_back(kOpusCodec); |
| 1099 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1100 | EXPECT_FALSE(voe_.GetNACK(channel_num)); |
| 1101 | } |
| 1102 | |
| 1103 | // Test that we can disable NACK on receive streams. |
| 1104 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNackRecvStreams) { |
| 1105 | EXPECT_TRUE(SetupEngine()); |
| 1106 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 1107 | int channel_num1 = voe_.GetLastChannel(); |
| 1108 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| 1109 | int channel_num2 = voe_.GetLastChannel(); |
| 1110 | std::vector<cricket::AudioCodec> codecs; |
| 1111 | codecs.push_back(kOpusCodec); |
| 1112 | codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1113 | cricket::kParamValueEmpty)); |
| 1114 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1115 | EXPECT_TRUE(voe_.GetNACK(channel_num1)); |
| 1116 | EXPECT_TRUE(voe_.GetNACK(channel_num2)); |
| 1117 | |
| 1118 | codecs.clear(); |
| 1119 | codecs.push_back(kOpusCodec); |
| 1120 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1121 | EXPECT_FALSE(voe_.GetNACK(channel_num1)); |
| 1122 | EXPECT_FALSE(voe_.GetNACK(channel_num2)); |
| 1123 | } |
| 1124 | |
| 1125 | // Test that NACK is enabled on a new receive stream. |
| 1126 | TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamEnableNack) { |
| 1127 | EXPECT_TRUE(SetupEngine()); |
| 1128 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 1129 | int channel_num = voe_.GetLastChannel(); |
| 1130 | std::vector<cricket::AudioCodec> codecs; |
| 1131 | codecs.push_back(kIsacCodec); |
| 1132 | codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 1133 | cricket::kParamValueEmpty)); |
| 1134 | codecs.push_back(kCn16000Codec); |
| 1135 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1136 | EXPECT_TRUE(voe_.GetNACK(channel_num)); |
| 1137 | |
| 1138 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| 1139 | channel_num = voe_.GetLastChannel(); |
| 1140 | EXPECT_TRUE(voe_.GetNACK(channel_num)); |
| 1141 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3))); |
| 1142 | channel_num = voe_.GetLastChannel(); |
| 1143 | EXPECT_TRUE(voe_.GetNACK(channel_num)); |
| 1144 | } |
| 1145 | |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1146 | #ifdef USE_WEBRTC_DEV_BRANCH |
| 1147 | // Test that without useinbandfec, Opus FEC is off. |
buildbot@webrtc.org | d27d9ae | 2014-06-19 01:56:46 +0000 | [diff] [blame] | 1148 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecNoOpusFec) { |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1149 | EXPECT_TRUE(SetupEngine()); |
| 1150 | int channel_num = voe_.GetLastChannel(); |
| 1151 | std::vector<cricket::AudioCodec> codecs; |
| 1152 | codecs.push_back(kOpusCodec); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1153 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1154 | EXPECT_FALSE(voe_.GetCodecFEC(channel_num)); |
| 1155 | } |
| 1156 | |
| 1157 | // Test that with useinbandfec=0, Opus FEC is off. |
buildbot@webrtc.org | d27d9ae | 2014-06-19 01:56:46 +0000 | [diff] [blame] | 1158 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusDisableFec) { |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1159 | EXPECT_TRUE(SetupEngine()); |
| 1160 | int channel_num = voe_.GetLastChannel(); |
| 1161 | std::vector<cricket::AudioCodec> codecs; |
| 1162 | codecs.push_back(kOpusCodec); |
| 1163 | codecs[0].bitrate = 0; |
| 1164 | codecs[0].params["useinbandfec"] = "0"; |
| 1165 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1166 | EXPECT_FALSE(voe_.GetCodecFEC(channel_num)); |
| 1167 | webrtc::CodecInst gcodec; |
| 1168 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1169 | EXPECT_STREQ("opus", gcodec.plname); |
| 1170 | EXPECT_EQ(1, gcodec.channels); |
| 1171 | EXPECT_EQ(32000, gcodec.rate); |
| 1172 | } |
| 1173 | |
| 1174 | // Test that with useinbandfec=1, Opus FEC is on. |
buildbot@webrtc.org | d27d9ae | 2014-06-19 01:56:46 +0000 | [diff] [blame] | 1175 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFec) { |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1176 | EXPECT_TRUE(SetupEngine()); |
| 1177 | int channel_num = voe_.GetLastChannel(); |
| 1178 | std::vector<cricket::AudioCodec> codecs; |
| 1179 | codecs.push_back(kOpusCodec); |
| 1180 | codecs[0].bitrate = 0; |
| 1181 | codecs[0].params["useinbandfec"] = "1"; |
| 1182 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1183 | EXPECT_TRUE(voe_.GetCodecFEC(channel_num)); |
| 1184 | webrtc::CodecInst gcodec; |
| 1185 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1186 | EXPECT_STREQ("opus", gcodec.plname); |
| 1187 | EXPECT_EQ(1, gcodec.channels); |
| 1188 | EXPECT_EQ(32000, gcodec.rate); |
| 1189 | } |
| 1190 | |
| 1191 | // Test that with useinbandfec=1, stereo=1, Opus FEC is on. |
buildbot@webrtc.org | d27d9ae | 2014-06-19 01:56:46 +0000 | [diff] [blame] | 1192 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFecStereo) { |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1193 | EXPECT_TRUE(SetupEngine()); |
| 1194 | int channel_num = voe_.GetLastChannel(); |
| 1195 | std::vector<cricket::AudioCodec> codecs; |
| 1196 | codecs.push_back(kOpusCodec); |
| 1197 | codecs[0].bitrate = 0; |
| 1198 | codecs[0].params["stereo"] = "1"; |
| 1199 | codecs[0].params["useinbandfec"] = "1"; |
| 1200 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1201 | EXPECT_TRUE(voe_.GetCodecFEC(channel_num)); |
| 1202 | webrtc::CodecInst gcodec; |
| 1203 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1204 | EXPECT_STREQ("opus", gcodec.plname); |
| 1205 | EXPECT_EQ(2, gcodec.channels); |
| 1206 | EXPECT_EQ(64000, gcodec.rate); |
| 1207 | } |
| 1208 | |
| 1209 | // Test that with non-Opus, codec FEC is off. |
buildbot@webrtc.org | d27d9ae | 2014-06-19 01:56:46 +0000 | [diff] [blame] | 1210 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacNoFec) { |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1211 | EXPECT_TRUE(SetupEngine()); |
| 1212 | int channel_num = voe_.GetLastChannel(); |
| 1213 | std::vector<cricket::AudioCodec> codecs; |
| 1214 | codecs.push_back(kIsacCodec); |
| 1215 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1216 | EXPECT_FALSE(voe_.GetCodecFEC(channel_num)); |
| 1217 | } |
buildbot@webrtc.org | 3ffa1f9 | 2014-07-02 19:51:26 +0000 | [diff] [blame] | 1218 | |
| 1219 | // Test the with non-Opus, even if useinbandfec=1, FEC is off. |
| 1220 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacWithParamNoFec) { |
| 1221 | EXPECT_TRUE(SetupEngine()); |
| 1222 | int channel_num = voe_.GetLastChannel(); |
| 1223 | std::vector<cricket::AudioCodec> codecs; |
| 1224 | codecs.push_back(kIsacCodec); |
| 1225 | codecs[0].params["useinbandfec"] = "1"; |
| 1226 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1227 | EXPECT_FALSE(voe_.GetCodecFEC(channel_num)); |
| 1228 | } |
buildbot@webrtc.org | 5d639b3 | 2014-09-10 07:57:12 +0000 | [diff] [blame] | 1229 | |
| 1230 | // Test that Opus FEC status can be changed. |
| 1231 | TEST_F(WebRtcVoiceEngineTestFake, ChangeOpusFecStatus) { |
| 1232 | EXPECT_TRUE(SetupEngine()); |
| 1233 | int channel_num = voe_.GetLastChannel(); |
| 1234 | std::vector<cricket::AudioCodec> codecs; |
| 1235 | codecs.push_back(kOpusCodec); |
| 1236 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1237 | EXPECT_FALSE(voe_.GetCodecFEC(channel_num)); |
| 1238 | codecs[0].params["useinbandfec"] = "1"; |
| 1239 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1240 | EXPECT_TRUE(voe_.GetCodecFEC(channel_num)); |
| 1241 | } |
| 1242 | |
| 1243 | // Test maxplaybackrate <= 8000 triggers Opus narrow band mode. |
| 1244 | TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateNb) { |
| 1245 | EXPECT_TRUE(SetupEngine()); |
| 1246 | int channel_num = voe_.GetLastChannel(); |
| 1247 | std::vector<cricket::AudioCodec> codecs; |
| 1248 | codecs.push_back(kOpusCodec); |
| 1249 | codecs[0].bitrate = 0; |
| 1250 | codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000); |
| 1251 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1252 | EXPECT_EQ(cricket::kOpusBandwidthNb, |
| 1253 | voe_.GetMaxEncodingBandwidth(channel_num)); |
| 1254 | webrtc::CodecInst gcodec; |
| 1255 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1256 | EXPECT_STREQ("opus", gcodec.plname); |
| 1257 | // TODO(minyue): Default bit rate is not but can in future be affected by |
| 1258 | // kCodecParamMaxPlaybackRate. |
| 1259 | EXPECT_EQ(32000, gcodec.rate); |
| 1260 | } |
| 1261 | |
| 1262 | // Test 8000 < maxplaybackrate <= 12000 triggers Opus medium band mode. |
| 1263 | TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateMb) { |
| 1264 | EXPECT_TRUE(SetupEngine()); |
| 1265 | int channel_num = voe_.GetLastChannel(); |
| 1266 | std::vector<cricket::AudioCodec> codecs; |
| 1267 | codecs.push_back(kOpusCodec); |
| 1268 | codecs[0].bitrate = 0; |
| 1269 | codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8001); |
| 1270 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1271 | EXPECT_EQ(cricket::kOpusBandwidthMb, |
| 1272 | voe_.GetMaxEncodingBandwidth(channel_num)); |
| 1273 | webrtc::CodecInst gcodec; |
| 1274 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1275 | EXPECT_STREQ("opus", gcodec.plname); |
| 1276 | // TODO(minyue): Default bit rate is not but can in future be affected by |
| 1277 | // kCodecParamMaxPlaybackRate. |
| 1278 | EXPECT_EQ(32000, gcodec.rate); |
| 1279 | } |
| 1280 | |
| 1281 | // Test 12000 < maxplaybackrate <= 16000 triggers Opus wide band mode. |
| 1282 | TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateWb) { |
| 1283 | EXPECT_TRUE(SetupEngine()); |
| 1284 | int channel_num = voe_.GetLastChannel(); |
| 1285 | std::vector<cricket::AudioCodec> codecs; |
| 1286 | codecs.push_back(kOpusCodec); |
| 1287 | codecs[0].bitrate = 0; |
| 1288 | codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 12001); |
| 1289 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1290 | EXPECT_EQ(cricket::kOpusBandwidthWb, |
| 1291 | voe_.GetMaxEncodingBandwidth(channel_num)); |
| 1292 | webrtc::CodecInst gcodec; |
| 1293 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1294 | EXPECT_STREQ("opus", gcodec.plname); |
| 1295 | // TODO(minyue): Default bit rate is not but can in future be affected by |
| 1296 | // kCodecParamMaxPlaybackRate. |
| 1297 | EXPECT_EQ(32000, gcodec.rate); |
| 1298 | } |
| 1299 | |
| 1300 | // Test 16000 < maxplaybackrate <= 24000 triggers Opus super wide band mode. |
| 1301 | TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateSwb) { |
| 1302 | EXPECT_TRUE(SetupEngine()); |
| 1303 | int channel_num = voe_.GetLastChannel(); |
| 1304 | std::vector<cricket::AudioCodec> codecs; |
| 1305 | codecs.push_back(kOpusCodec); |
| 1306 | codecs[0].bitrate = 0; |
| 1307 | codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 16001); |
| 1308 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1309 | EXPECT_EQ(cricket::kOpusBandwidthSwb, |
| 1310 | voe_.GetMaxEncodingBandwidth(channel_num)); |
| 1311 | webrtc::CodecInst gcodec; |
| 1312 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1313 | EXPECT_STREQ("opus", gcodec.plname); |
| 1314 | // TODO(minyue): Default bit rate is not but can in future be affected by |
| 1315 | // kCodecParamMaxPlaybackRate. |
| 1316 | EXPECT_EQ(32000, gcodec.rate); |
| 1317 | } |
| 1318 | |
| 1319 | // Test 24000 < maxplaybackrate triggers Opus full band mode. |
| 1320 | TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateFb) { |
| 1321 | EXPECT_TRUE(SetupEngine()); |
| 1322 | int channel_num = voe_.GetLastChannel(); |
| 1323 | std::vector<cricket::AudioCodec> codecs; |
| 1324 | codecs.push_back(kOpusCodec); |
| 1325 | codecs[0].bitrate = 0; |
| 1326 | codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 24001); |
| 1327 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1328 | EXPECT_EQ(cricket::kOpusBandwidthFb, |
| 1329 | voe_.GetMaxEncodingBandwidth(channel_num)); |
| 1330 | webrtc::CodecInst gcodec; |
| 1331 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1332 | EXPECT_STREQ("opus", gcodec.plname); |
| 1333 | // TODO(minyue): Default bit rate is not but can in future be affected by |
| 1334 | // kCodecParamMaxPlaybackRate. |
| 1335 | EXPECT_EQ(32000, gcodec.rate); |
| 1336 | } |
| 1337 | |
| 1338 | // Test Opus that without maxplaybackrate, default playback rate is used. |
| 1339 | TEST_F(WebRtcVoiceEngineTestFake, DefaultOpusMaxPlaybackRate) { |
| 1340 | EXPECT_TRUE(SetupEngine()); |
| 1341 | int channel_num = voe_.GetLastChannel(); |
| 1342 | std::vector<cricket::AudioCodec> codecs; |
| 1343 | codecs.push_back(kOpusCodec); |
| 1344 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1345 | EXPECT_EQ(cricket::kOpusBandwidthFb, |
| 1346 | voe_.GetMaxEncodingBandwidth(channel_num)); |
| 1347 | } |
| 1348 | |
| 1349 | // Test the with non-Opus, maxplaybackrate has no effect. |
| 1350 | TEST_F(WebRtcVoiceEngineTestFake, SetNonOpusMaxPlaybackRate) { |
| 1351 | EXPECT_TRUE(SetupEngine()); |
| 1352 | int channel_num = voe_.GetLastChannel(); |
| 1353 | std::vector<cricket::AudioCodec> codecs; |
| 1354 | codecs.push_back(kIsacCodec); |
| 1355 | codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 32000); |
| 1356 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1357 | EXPECT_EQ(0, voe_.GetMaxEncodingBandwidth(channel_num)); |
| 1358 | } |
| 1359 | |
| 1360 | // Test maxplaybackrate can be set on two streams. |
| 1361 | TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateOnTwoStreams) { |
| 1362 | EXPECT_TRUE(SetupEngine()); |
| 1363 | int channel_num = voe_.GetLastChannel(); |
| 1364 | std::vector<cricket::AudioCodec> codecs; |
| 1365 | codecs.push_back(kOpusCodec); |
| 1366 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1367 | // Default bandwidth is 24000. |
| 1368 | EXPECT_EQ(cricket::kOpusBandwidthFb, |
| 1369 | voe_.GetMaxEncodingBandwidth(channel_num)); |
| 1370 | |
| 1371 | codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000); |
| 1372 | |
| 1373 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1374 | EXPECT_EQ(cricket::kOpusBandwidthNb, |
| 1375 | voe_.GetMaxEncodingBandwidth(channel_num)); |
| 1376 | |
| 1377 | channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc2)); |
| 1378 | channel_num = voe_.GetLastChannel(); |
| 1379 | EXPECT_EQ(cricket::kOpusBandwidthNb, |
| 1380 | voe_.GetMaxEncodingBandwidth(channel_num)); |
| 1381 | } |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1382 | #endif // USE_WEBRTC_DEV_BRANCH |
| 1383 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1384 | // Test that we can apply CELT with stereo mode but fail with mono mode. |
| 1385 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCelt) { |
| 1386 | EXPECT_TRUE(SetupEngine()); |
| 1387 | int channel_num = voe_.GetLastChannel(); |
| 1388 | std::vector<cricket::AudioCodec> codecs; |
| 1389 | codecs.push_back(kCeltCodec); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 1390 | codecs.push_back(kIsacCodec); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1391 | codecs[0].id = 96; |
| 1392 | codecs[0].channels = 2; |
| 1393 | codecs[0].bitrate = 96000; |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 1394 | codecs[1].bitrate = 64000; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1395 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1396 | webrtc::CodecInst gcodec; |
| 1397 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1398 | EXPECT_EQ(96, gcodec.pltype); |
| 1399 | EXPECT_EQ(96000, gcodec.rate); |
| 1400 | EXPECT_EQ(2, gcodec.channels); |
| 1401 | EXPECT_STREQ("CELT", gcodec.plname); |
| 1402 | // Doesn't support mono, expect it to fall back to the next codec in the list. |
| 1403 | codecs[0].channels = 1; |
| 1404 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1405 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 1406 | EXPECT_EQ(103, gcodec.pltype); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1407 | EXPECT_EQ(1, gcodec.channels); |
| 1408 | EXPECT_EQ(64000, gcodec.rate); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 1409 | EXPECT_STREQ("ISAC", gcodec.plname); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | // Test that we can switch back and forth between CELT and ISAC with CN. |
| 1413 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsIsacCeltSwitching) { |
| 1414 | EXPECT_TRUE(SetupEngine()); |
| 1415 | int channel_num = voe_.GetLastChannel(); |
| 1416 | std::vector<cricket::AudioCodec> celt_codecs; |
| 1417 | celt_codecs.push_back(kCeltCodec); |
| 1418 | EXPECT_TRUE(channel_->SetSendCodecs(celt_codecs)); |
| 1419 | webrtc::CodecInst gcodec; |
| 1420 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1421 | EXPECT_EQ(110, gcodec.pltype); |
| 1422 | EXPECT_STREQ("CELT", gcodec.plname); |
| 1423 | |
| 1424 | std::vector<cricket::AudioCodec> isac_codecs; |
| 1425 | isac_codecs.push_back(kIsacCodec); |
| 1426 | isac_codecs.push_back(kCn16000Codec); |
| 1427 | isac_codecs.push_back(kCeltCodec); |
| 1428 | EXPECT_TRUE(channel_->SetSendCodecs(isac_codecs)); |
| 1429 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1430 | EXPECT_EQ(103, gcodec.pltype); |
| 1431 | EXPECT_STREQ("ISAC", gcodec.plname); |
| 1432 | |
| 1433 | EXPECT_TRUE(channel_->SetSendCodecs(celt_codecs)); |
| 1434 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1435 | EXPECT_EQ(110, gcodec.pltype); |
| 1436 | EXPECT_STREQ("CELT", gcodec.plname); |
| 1437 | } |
| 1438 | |
| 1439 | // Test that we handle various ways of specifying bitrate. |
| 1440 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBitrate) { |
| 1441 | EXPECT_TRUE(SetupEngine()); |
| 1442 | int channel_num = voe_.GetLastChannel(); |
| 1443 | std::vector<cricket::AudioCodec> codecs; |
| 1444 | codecs.push_back(kIsacCodec); // bitrate == 32000 |
| 1445 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1446 | webrtc::CodecInst gcodec; |
| 1447 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1448 | EXPECT_EQ(103, gcodec.pltype); |
| 1449 | EXPECT_STREQ("ISAC", gcodec.plname); |
| 1450 | EXPECT_EQ(32000, gcodec.rate); |
| 1451 | |
| 1452 | codecs[0].bitrate = 0; // bitrate == default |
| 1453 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1454 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1455 | EXPECT_EQ(103, gcodec.pltype); |
| 1456 | EXPECT_STREQ("ISAC", gcodec.plname); |
| 1457 | EXPECT_EQ(-1, gcodec.rate); |
| 1458 | |
| 1459 | codecs[0].bitrate = 28000; // bitrate == 28000 |
| 1460 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1461 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1462 | EXPECT_EQ(103, gcodec.pltype); |
| 1463 | EXPECT_STREQ("ISAC", gcodec.plname); |
| 1464 | EXPECT_EQ(28000, gcodec.rate); |
| 1465 | |
| 1466 | codecs[0] = kPcmuCodec; // bitrate == 64000 |
| 1467 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1468 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1469 | EXPECT_EQ(0, gcodec.pltype); |
| 1470 | EXPECT_STREQ("PCMU", gcodec.plname); |
| 1471 | EXPECT_EQ(64000, gcodec.rate); |
| 1472 | |
| 1473 | codecs[0].bitrate = 0; // bitrate == default |
| 1474 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1475 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1476 | EXPECT_EQ(0, gcodec.pltype); |
| 1477 | EXPECT_STREQ("PCMU", gcodec.plname); |
| 1478 | EXPECT_EQ(64000, gcodec.rate); |
| 1479 | |
| 1480 | codecs[0] = kOpusCodec; |
| 1481 | codecs[0].bitrate = 0; // bitrate == default |
| 1482 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1483 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1484 | EXPECT_EQ(111, gcodec.pltype); |
| 1485 | EXPECT_STREQ("opus", gcodec.plname); |
| 1486 | EXPECT_EQ(32000, gcodec.rate); |
| 1487 | } |
| 1488 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 1489 | // Test that we fail if no codecs are specified. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1490 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsNoCodecs) { |
| 1491 | EXPECT_TRUE(SetupEngine()); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 1492 | std::vector<cricket::AudioCodec> codecs; |
| 1493 | EXPECT_FALSE(channel_->SetSendCodecs(codecs)); |
| 1494 | } |
| 1495 | |
| 1496 | // Test that we can set send codecs even with telephone-event codec as the first |
| 1497 | // one on the list. |
| 1498 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFOnTop) { |
| 1499 | EXPECT_TRUE(SetupEngine()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1500 | int channel_num = voe_.GetLastChannel(); |
| 1501 | std::vector<cricket::AudioCodec> codecs; |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 1502 | codecs.push_back(kTelephoneEventCodec); |
| 1503 | codecs.push_back(kIsacCodec); |
| 1504 | codecs.push_back(kPcmuCodec); |
| 1505 | codecs[0].id = 98; // DTMF |
| 1506 | codecs[1].id = 96; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1507 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1508 | webrtc::CodecInst gcodec; |
| 1509 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 1510 | EXPECT_EQ(96, gcodec.pltype); |
| 1511 | EXPECT_STREQ("ISAC", gcodec.plname); |
| 1512 | EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num)); |
| 1513 | } |
| 1514 | |
| 1515 | // Test that we can set send codecs even with CN codec as the first |
| 1516 | // one on the list. |
| 1517 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNOnTop) { |
| 1518 | EXPECT_TRUE(SetupEngine()); |
| 1519 | int channel_num = voe_.GetLastChannel(); |
| 1520 | std::vector<cricket::AudioCodec> codecs; |
| 1521 | codecs.push_back(kCn16000Codec); |
| 1522 | codecs.push_back(kIsacCodec); |
| 1523 | codecs.push_back(kPcmuCodec); |
| 1524 | codecs[0].id = 98; // wideband CN |
| 1525 | codecs[1].id = 96; |
| 1526 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1527 | webrtc::CodecInst gcodec; |
| 1528 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1529 | EXPECT_EQ(96, gcodec.pltype); |
| 1530 | EXPECT_STREQ("ISAC", gcodec.plname); |
| 1531 | EXPECT_EQ(98, voe_.GetSendCNPayloadType(channel_num, true)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1532 | } |
| 1533 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 1534 | // Test that we set VAD and DTMF types correctly as caller. |
| 1535 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCaller) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1536 | EXPECT_TRUE(SetupEngine()); |
| 1537 | int channel_num = voe_.GetLastChannel(); |
| 1538 | std::vector<cricket::AudioCodec> codecs; |
| 1539 | codecs.push_back(kIsacCodec); |
| 1540 | codecs.push_back(kPcmuCodec); |
| 1541 | // TODO(juberti): cn 32000 |
| 1542 | codecs.push_back(kCn16000Codec); |
| 1543 | codecs.push_back(kCn8000Codec); |
| 1544 | codecs.push_back(kTelephoneEventCodec); |
| 1545 | codecs.push_back(kRedCodec); |
| 1546 | codecs[0].id = 96; |
| 1547 | codecs[2].id = 97; // wideband CN |
| 1548 | codecs[4].id = 98; // DTMF |
| 1549 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1550 | webrtc::CodecInst gcodec; |
| 1551 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1552 | EXPECT_EQ(96, gcodec.pltype); |
| 1553 | EXPECT_STREQ("ISAC", gcodec.plname); |
| 1554 | EXPECT_TRUE(voe_.GetVAD(channel_num)); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1555 | EXPECT_FALSE(voe_.GetRED(channel_num)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1556 | EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); |
| 1557 | EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); |
| 1558 | EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num)); |
| 1559 | } |
| 1560 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 1561 | // Test that we set VAD and DTMF types correctly as callee. |
| 1562 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCallee) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1563 | EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 1564 | channel_ = engine_.CreateChannel(); |
| 1565 | EXPECT_TRUE(channel_ != NULL); |
| 1566 | |
| 1567 | int channel_num = voe_.GetLastChannel(); |
| 1568 | std::vector<cricket::AudioCodec> codecs; |
| 1569 | codecs.push_back(kIsacCodec); |
| 1570 | codecs.push_back(kPcmuCodec); |
| 1571 | // TODO(juberti): cn 32000 |
| 1572 | codecs.push_back(kCn16000Codec); |
| 1573 | codecs.push_back(kCn8000Codec); |
| 1574 | codecs.push_back(kTelephoneEventCodec); |
| 1575 | codecs.push_back(kRedCodec); |
| 1576 | codecs[0].id = 96; |
| 1577 | codecs[2].id = 97; // wideband CN |
| 1578 | codecs[4].id = 98; // DTMF |
| 1579 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1580 | EXPECT_TRUE(channel_->AddSendStream( |
| 1581 | cricket::StreamParams::CreateLegacy(kSsrc1))); |
| 1582 | |
| 1583 | webrtc::CodecInst gcodec; |
| 1584 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1585 | EXPECT_EQ(96, gcodec.pltype); |
| 1586 | EXPECT_STREQ("ISAC", gcodec.plname); |
| 1587 | EXPECT_TRUE(voe_.GetVAD(channel_num)); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1588 | EXPECT_FALSE(voe_.GetRED(channel_num)); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 1589 | EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); |
| 1590 | EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); |
| 1591 | EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num)); |
| 1592 | } |
| 1593 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1594 | // Test that we only apply VAD if we have a CN codec that matches the |
| 1595 | // send codec clockrate. |
| 1596 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNNoMatch) { |
| 1597 | EXPECT_TRUE(SetupEngine()); |
| 1598 | int channel_num = voe_.GetLastChannel(); |
| 1599 | std::vector<cricket::AudioCodec> codecs; |
| 1600 | // Set ISAC(16K) and CN(16K). VAD should be activated. |
| 1601 | codecs.push_back(kIsacCodec); |
| 1602 | codecs.push_back(kCn16000Codec); |
| 1603 | codecs[1].id = 97; |
| 1604 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1605 | webrtc::CodecInst gcodec; |
| 1606 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1607 | EXPECT_STREQ("ISAC", gcodec.plname); |
| 1608 | EXPECT_TRUE(voe_.GetVAD(channel_num)); |
| 1609 | EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); |
| 1610 | // Set PCMU(8K) and CN(16K). VAD should not be activated. |
| 1611 | codecs[0] = kPcmuCodec; |
| 1612 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1613 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1614 | EXPECT_STREQ("PCMU", gcodec.plname); |
| 1615 | EXPECT_FALSE(voe_.GetVAD(channel_num)); |
| 1616 | // Set PCMU(8K) and CN(8K). VAD should be activated. |
| 1617 | codecs[1] = kCn8000Codec; |
| 1618 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1619 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1620 | EXPECT_STREQ("PCMU", gcodec.plname); |
| 1621 | EXPECT_TRUE(voe_.GetVAD(channel_num)); |
| 1622 | EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); |
| 1623 | // Set ISAC(16K) and CN(8K). VAD should not be activated. |
| 1624 | codecs[0] = kIsacCodec; |
| 1625 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1626 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1627 | EXPECT_STREQ("ISAC", gcodec.plname); |
| 1628 | EXPECT_FALSE(voe_.GetVAD(channel_num)); |
| 1629 | } |
| 1630 | |
| 1631 | // Test that we perform case-insensitive matching of codec names. |
| 1632 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCaseInsensitive) { |
| 1633 | EXPECT_TRUE(SetupEngine()); |
| 1634 | int channel_num = voe_.GetLastChannel(); |
| 1635 | std::vector<cricket::AudioCodec> codecs; |
| 1636 | codecs.push_back(kIsacCodec); |
| 1637 | codecs.push_back(kPcmuCodec); |
| 1638 | codecs.push_back(kCn16000Codec); |
| 1639 | codecs.push_back(kCn8000Codec); |
| 1640 | codecs.push_back(kTelephoneEventCodec); |
| 1641 | codecs.push_back(kRedCodec); |
| 1642 | codecs[0].name = "iSaC"; |
| 1643 | codecs[0].id = 96; |
| 1644 | codecs[2].id = 97; // wideband CN |
| 1645 | codecs[4].id = 98; // DTMF |
| 1646 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1647 | webrtc::CodecInst gcodec; |
| 1648 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1649 | EXPECT_EQ(96, gcodec.pltype); |
| 1650 | EXPECT_STREQ("ISAC", gcodec.plname); |
| 1651 | EXPECT_TRUE(voe_.GetVAD(channel_num)); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1652 | EXPECT_FALSE(voe_.GetRED(channel_num)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1653 | EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); |
| 1654 | EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); |
| 1655 | EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num)); |
| 1656 | } |
| 1657 | |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1658 | // Test that we set up RED correctly as caller. |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 1659 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCaller) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1660 | EXPECT_TRUE(SetupEngine()); |
| 1661 | int channel_num = voe_.GetLastChannel(); |
| 1662 | std::vector<cricket::AudioCodec> codecs; |
| 1663 | codecs.push_back(kRedCodec); |
| 1664 | codecs.push_back(kIsacCodec); |
| 1665 | codecs.push_back(kPcmuCodec); |
| 1666 | codecs[0].id = 127; |
| 1667 | codecs[0].params[""] = "96/96"; |
| 1668 | codecs[1].id = 96; |
| 1669 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1670 | webrtc::CodecInst gcodec; |
| 1671 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1672 | EXPECT_EQ(96, gcodec.pltype); |
| 1673 | EXPECT_STREQ("ISAC", gcodec.plname); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1674 | EXPECT_TRUE(voe_.GetRED(channel_num)); |
| 1675 | EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1678 | // Test that we set up RED correctly as callee. |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 1679 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCallee) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1680 | EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 1681 | channel_ = engine_.CreateChannel(); |
| 1682 | EXPECT_TRUE(channel_ != NULL); |
| 1683 | |
| 1684 | int channel_num = voe_.GetLastChannel(); |
| 1685 | std::vector<cricket::AudioCodec> codecs; |
| 1686 | codecs.push_back(kRedCodec); |
| 1687 | codecs.push_back(kIsacCodec); |
| 1688 | codecs.push_back(kPcmuCodec); |
| 1689 | codecs[0].id = 127; |
| 1690 | codecs[0].params[""] = "96/96"; |
| 1691 | codecs[1].id = 96; |
| 1692 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1693 | EXPECT_TRUE(channel_->AddSendStream( |
| 1694 | cricket::StreamParams::CreateLegacy(kSsrc1))); |
| 1695 | webrtc::CodecInst gcodec; |
| 1696 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1697 | EXPECT_EQ(96, gcodec.pltype); |
| 1698 | EXPECT_STREQ("ISAC", gcodec.plname); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1699 | EXPECT_TRUE(voe_.GetRED(channel_num)); |
| 1700 | EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num)); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 1701 | } |
| 1702 | |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1703 | // Test that we set up RED correctly if params are omitted. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1704 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDNoParams) { |
| 1705 | EXPECT_TRUE(SetupEngine()); |
| 1706 | int channel_num = voe_.GetLastChannel(); |
| 1707 | std::vector<cricket::AudioCodec> codecs; |
| 1708 | codecs.push_back(kRedCodec); |
| 1709 | codecs.push_back(kIsacCodec); |
| 1710 | codecs.push_back(kPcmuCodec); |
| 1711 | codecs[0].id = 127; |
| 1712 | codecs[1].id = 96; |
| 1713 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1714 | webrtc::CodecInst gcodec; |
| 1715 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1716 | EXPECT_EQ(96, gcodec.pltype); |
| 1717 | EXPECT_STREQ("ISAC", gcodec.plname); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1718 | EXPECT_TRUE(voe_.GetRED(channel_num)); |
| 1719 | EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | // Test that we ignore RED if the parameters aren't named the way we expect. |
| 1723 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED1) { |
| 1724 | EXPECT_TRUE(SetupEngine()); |
| 1725 | int channel_num = voe_.GetLastChannel(); |
| 1726 | std::vector<cricket::AudioCodec> codecs; |
| 1727 | codecs.push_back(kRedCodec); |
| 1728 | codecs.push_back(kIsacCodec); |
| 1729 | codecs.push_back(kPcmuCodec); |
| 1730 | codecs[0].id = 127; |
| 1731 | codecs[0].params["ABC"] = "96/96"; |
| 1732 | codecs[1].id = 96; |
| 1733 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1734 | webrtc::CodecInst gcodec; |
| 1735 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1736 | EXPECT_EQ(96, gcodec.pltype); |
| 1737 | EXPECT_STREQ("ISAC", gcodec.plname); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1738 | EXPECT_FALSE(voe_.GetRED(channel_num)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | // Test that we ignore RED if it uses different primary/secondary encoding. |
| 1742 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED2) { |
| 1743 | EXPECT_TRUE(SetupEngine()); |
| 1744 | int channel_num = voe_.GetLastChannel(); |
| 1745 | std::vector<cricket::AudioCodec> codecs; |
| 1746 | codecs.push_back(kRedCodec); |
| 1747 | codecs.push_back(kIsacCodec); |
| 1748 | codecs.push_back(kPcmuCodec); |
| 1749 | codecs[0].id = 127; |
| 1750 | codecs[0].params[""] = "96/0"; |
| 1751 | codecs[1].id = 96; |
| 1752 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1753 | webrtc::CodecInst gcodec; |
| 1754 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1755 | EXPECT_EQ(96, gcodec.pltype); |
| 1756 | EXPECT_STREQ("ISAC", gcodec.plname); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1757 | EXPECT_FALSE(voe_.GetRED(channel_num)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | // Test that we ignore RED if it uses more than 2 encodings. |
| 1761 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED3) { |
| 1762 | EXPECT_TRUE(SetupEngine()); |
| 1763 | int channel_num = voe_.GetLastChannel(); |
| 1764 | std::vector<cricket::AudioCodec> codecs; |
| 1765 | codecs.push_back(kRedCodec); |
| 1766 | codecs.push_back(kIsacCodec); |
| 1767 | codecs.push_back(kPcmuCodec); |
| 1768 | codecs[0].id = 127; |
| 1769 | codecs[0].params[""] = "96/96/96"; |
| 1770 | codecs[1].id = 96; |
| 1771 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1772 | webrtc::CodecInst gcodec; |
| 1773 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1774 | EXPECT_EQ(96, gcodec.pltype); |
| 1775 | EXPECT_STREQ("ISAC", gcodec.plname); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1776 | EXPECT_FALSE(voe_.GetRED(channel_num)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | // Test that we ignore RED if it has bogus codec ids. |
| 1780 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED4) { |
| 1781 | EXPECT_TRUE(SetupEngine()); |
| 1782 | int channel_num = voe_.GetLastChannel(); |
| 1783 | std::vector<cricket::AudioCodec> codecs; |
| 1784 | codecs.push_back(kRedCodec); |
| 1785 | codecs.push_back(kIsacCodec); |
| 1786 | codecs.push_back(kPcmuCodec); |
| 1787 | codecs[0].id = 127; |
| 1788 | codecs[0].params[""] = "ABC/ABC"; |
| 1789 | codecs[1].id = 96; |
| 1790 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1791 | webrtc::CodecInst gcodec; |
| 1792 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1793 | EXPECT_EQ(96, gcodec.pltype); |
| 1794 | EXPECT_STREQ("ISAC", gcodec.plname); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1795 | EXPECT_FALSE(voe_.GetRED(channel_num)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | // Test that we ignore RED if it refers to a codec that is not present. |
| 1799 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED5) { |
| 1800 | EXPECT_TRUE(SetupEngine()); |
| 1801 | int channel_num = voe_.GetLastChannel(); |
| 1802 | std::vector<cricket::AudioCodec> codecs; |
| 1803 | codecs.push_back(kRedCodec); |
| 1804 | codecs.push_back(kIsacCodec); |
| 1805 | codecs.push_back(kPcmuCodec); |
| 1806 | codecs[0].id = 127; |
| 1807 | codecs[0].params[""] = "97/97"; |
| 1808 | codecs[1].id = 96; |
| 1809 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1810 | webrtc::CodecInst gcodec; |
| 1811 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1812 | EXPECT_EQ(96, gcodec.pltype); |
| 1813 | EXPECT_STREQ("ISAC", gcodec.plname); |
buildbot@webrtc.org | ae740dd | 2014-06-17 10:56:41 +0000 | [diff] [blame] | 1814 | EXPECT_FALSE(voe_.GetRED(channel_num)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1815 | } |
| 1816 | |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 1817 | // Test support for audio level header extension. |
| 1818 | TEST_F(WebRtcVoiceEngineTestFake, SendAudioLevelHeaderExtensions) { |
| 1819 | TestSetSendRtpHeaderExtensions(kRtpAudioLevelHeaderExtension); |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 1820 | } |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 1821 | TEST_F(WebRtcVoiceEngineTestFake, RecvAudioLevelHeaderExtensions) { |
| 1822 | TestSetRecvRtpHeaderExtensions(kRtpAudioLevelHeaderExtension); |
| 1823 | } |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 1824 | |
buildbot@webrtc.org | 150835e | 2014-05-06 15:54:38 +0000 | [diff] [blame] | 1825 | // Test support for absolute send time header extension. |
| 1826 | TEST_F(WebRtcVoiceEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) { |
| 1827 | TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension); |
| 1828 | } |
| 1829 | TEST_F(WebRtcVoiceEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) { |
| 1830 | TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | // Test that we can create a channel and start sending/playing out on it. |
| 1834 | TEST_F(WebRtcVoiceEngineTestFake, SendAndPlayout) { |
| 1835 | EXPECT_TRUE(SetupEngine()); |
| 1836 | int channel_num = voe_.GetLastChannel(); |
| 1837 | std::vector<cricket::AudioCodec> codecs; |
| 1838 | codecs.push_back(kPcmuCodec); |
| 1839 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1840 | EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| 1841 | EXPECT_TRUE(voe_.GetSend(channel_num)); |
| 1842 | EXPECT_TRUE(channel_->SetPlayout(true)); |
| 1843 | EXPECT_TRUE(voe_.GetPlayout(channel_num)); |
| 1844 | EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING)); |
| 1845 | EXPECT_FALSE(voe_.GetSend(channel_num)); |
| 1846 | EXPECT_TRUE(channel_->SetPlayout(false)); |
| 1847 | EXPECT_FALSE(voe_.GetPlayout(channel_num)); |
| 1848 | } |
| 1849 | |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 1850 | // Test that we can add and remove send streams. |
| 1851 | TEST_F(WebRtcVoiceEngineTestFake, CreateAndDeleteMultipleSendStreams) { |
| 1852 | SetupForMultiSendStream(); |
| 1853 | |
| 1854 | static const uint32 kSsrcs4[] = {1, 2, 3, 4}; |
| 1855 | |
| 1856 | // Set the global state for sending. |
| 1857 | EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| 1858 | |
| 1859 | for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { |
| 1860 | EXPECT_TRUE(channel_->AddSendStream( |
| 1861 | cricket::StreamParams::CreateLegacy(kSsrcs4[i]))); |
| 1862 | |
| 1863 | // Verify that we are in a sending state for all the created streams. |
| 1864 | int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]); |
| 1865 | EXPECT_TRUE(voe_.GetSend(channel_num)); |
| 1866 | } |
| 1867 | |
| 1868 | // Remove the first send channel, which is the default channel. It will only |
| 1869 | // recycle the default channel but not delete it. |
| 1870 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[0])); |
| 1871 | // Stream should already be Removed from the send stream list. |
| 1872 | EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[0])); |
| 1873 | // But the default still exists. |
| 1874 | EXPECT_EQ(0, voe_.GetChannelFromLocalSsrc(kSsrcs4[0])); |
| 1875 | |
| 1876 | // Delete the rest of send channel streams. |
| 1877 | for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) { |
| 1878 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[i])); |
| 1879 | // Stream should already be deleted. |
| 1880 | EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[i])); |
| 1881 | EXPECT_EQ(-1, voe_.GetChannelFromLocalSsrc(kSsrcs4[i])); |
| 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | // Test SetSendCodecs correctly configure the codecs in all send streams. |
| 1886 | TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsWithMultipleSendStreams) { |
| 1887 | SetupForMultiSendStream(); |
| 1888 | |
| 1889 | static const uint32 kSsrcs4[] = {1, 2, 3, 4}; |
| 1890 | // Create send streams. |
| 1891 | for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { |
| 1892 | EXPECT_TRUE(channel_->AddSendStream( |
| 1893 | cricket::StreamParams::CreateLegacy(kSsrcs4[i]))); |
| 1894 | } |
| 1895 | |
| 1896 | std::vector<cricket::AudioCodec> codecs; |
| 1897 | // Set ISAC(16K) and CN(16K). VAD should be activated. |
| 1898 | codecs.push_back(kIsacCodec); |
| 1899 | codecs.push_back(kCn16000Codec); |
| 1900 | codecs[1].id = 97; |
| 1901 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1902 | |
| 1903 | // Verify ISAC and VAD are corrected configured on all send channels. |
| 1904 | webrtc::CodecInst gcodec; |
| 1905 | for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { |
| 1906 | int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]); |
| 1907 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1908 | EXPECT_STREQ("ISAC", gcodec.plname); |
| 1909 | EXPECT_TRUE(voe_.GetVAD(channel_num)); |
| 1910 | EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); |
| 1911 | } |
| 1912 | |
| 1913 | // Change to PCMU(8K) and CN(16K). VAD should not be activated. |
| 1914 | codecs[0] = kPcmuCodec; |
| 1915 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1916 | for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { |
| 1917 | int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]); |
| 1918 | EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
| 1919 | EXPECT_STREQ("PCMU", gcodec.plname); |
| 1920 | EXPECT_FALSE(voe_.GetVAD(channel_num)); |
| 1921 | } |
| 1922 | } |
| 1923 | |
| 1924 | // Test we can SetSend on all send streams correctly. |
| 1925 | TEST_F(WebRtcVoiceEngineTestFake, SetSendWithMultipleSendStreams) { |
| 1926 | SetupForMultiSendStream(); |
| 1927 | |
| 1928 | static const uint32 kSsrcs4[] = {1, 2, 3, 4}; |
| 1929 | // Create the send channels and they should be a SEND_NOTHING date. |
| 1930 | for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { |
| 1931 | EXPECT_TRUE(channel_->AddSendStream( |
| 1932 | cricket::StreamParams::CreateLegacy(kSsrcs4[i]))); |
| 1933 | int channel_num = voe_.GetLastChannel(); |
| 1934 | EXPECT_FALSE(voe_.GetSend(channel_num)); |
| 1935 | } |
| 1936 | |
| 1937 | // Set the global state for starting sending. |
| 1938 | EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| 1939 | for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { |
| 1940 | // Verify that we are in a sending state for all the send streams. |
| 1941 | int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]); |
| 1942 | EXPECT_TRUE(voe_.GetSend(channel_num)); |
| 1943 | } |
| 1944 | |
| 1945 | // Set the global state for stopping sending. |
| 1946 | EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING)); |
| 1947 | for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) { |
| 1948 | // Verify that we are in a stop state for all the send streams. |
| 1949 | int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]); |
| 1950 | EXPECT_FALSE(voe_.GetSend(channel_num)); |
| 1951 | } |
| 1952 | } |
| 1953 | |
| 1954 | // Test we can set the correct statistics on all send streams. |
| 1955 | TEST_F(WebRtcVoiceEngineTestFake, GetStatsWithMultipleSendStreams) { |
| 1956 | SetupForMultiSendStream(); |
| 1957 | |
| 1958 | static const uint32 kSsrcs4[] = {1, 2, 3, 4}; |
| 1959 | // Create send streams. |
| 1960 | for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { |
| 1961 | EXPECT_TRUE(channel_->AddSendStream( |
| 1962 | cricket::StreamParams::CreateLegacy(kSsrcs4[i]))); |
| 1963 | } |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 1964 | // Create a receive stream to check that none of the send streams end up in |
| 1965 | // the receive stream stats. |
| 1966 | EXPECT_TRUE(channel_->AddRecvStream( |
| 1967 | cricket::StreamParams::CreateLegacy(kSsrc2))); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 1968 | // We need send codec to be set to get all stats. |
| 1969 | std::vector<cricket::AudioCodec> codecs; |
| 1970 | codecs.push_back(kPcmuCodec); |
| 1971 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 1972 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 1973 | |
| 1974 | cricket::VoiceMediaInfo info; |
| 1975 | EXPECT_EQ(true, channel_->GetStats(&info)); |
| 1976 | EXPECT_EQ(static_cast<size_t>(ARRAY_SIZE(kSsrcs4)), info.senders.size()); |
| 1977 | |
| 1978 | // Verify the statistic information is correct. |
| 1979 | for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 1980 | EXPECT_EQ(kSsrcs4[i], info.senders[i].ssrc()); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 1981 | EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name); |
| 1982 | EXPECT_EQ(cricket::kIntStatValue, info.senders[i].bytes_sent); |
| 1983 | EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_sent); |
| 1984 | EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_lost); |
| 1985 | EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[i].fraction_lost); |
| 1986 | EXPECT_EQ(cricket::kIntStatValue, info.senders[i].ext_seqnum); |
| 1987 | EXPECT_EQ(cricket::kIntStatValue, info.senders[i].rtt_ms); |
| 1988 | EXPECT_EQ(cricket::kIntStatValue, info.senders[i].jitter_ms); |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 1989 | EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 1990 | } |
| 1991 | |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 1992 | EXPECT_EQ(0u, info.receivers.size()); |
| 1993 | DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); |
| 1994 | EXPECT_EQ(true, channel_->GetStats(&info)); |
| 1995 | |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 1996 | EXPECT_EQ(1u, info.receivers.size()); |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 1997 | EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd); |
| 1998 | EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd); |
| 1999 | EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost); |
| 2000 | EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum); |
| 2001 | EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 2002 | } |
| 2003 | |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 2004 | // Test that we can add and remove receive streams, and do proper send/playout. |
| 2005 | // We can receive on multiple streams while sending one stream. |
| 2006 | TEST_F(WebRtcVoiceEngineTestFake, PlayoutWithMultipleStreams) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2007 | EXPECT_TRUE(SetupEngine()); |
| 2008 | int channel_num1 = voe_.GetLastChannel(); |
| 2009 | |
| 2010 | // Start playout on the default channel. |
| 2011 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 2012 | EXPECT_TRUE(channel_->SetPlayout(true)); |
| 2013 | EXPECT_TRUE(voe_.GetPlayout(channel_num1)); |
| 2014 | |
| 2015 | // Adding another stream should disable playout on the default channel. |
| 2016 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| 2017 | int channel_num2 = voe_.GetLastChannel(); |
| 2018 | std::vector<cricket::AudioCodec> codecs; |
| 2019 | codecs.push_back(kPcmuCodec); |
| 2020 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 2021 | EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| 2022 | EXPECT_TRUE(voe_.GetSend(channel_num1)); |
| 2023 | EXPECT_FALSE(voe_.GetSend(channel_num2)); |
| 2024 | |
| 2025 | // Make sure only the new channel is played out. |
| 2026 | EXPECT_FALSE(voe_.GetPlayout(channel_num1)); |
| 2027 | EXPECT_TRUE(voe_.GetPlayout(channel_num2)); |
| 2028 | |
| 2029 | // Adding yet another stream should have stream 2 and 3 enabled for playout. |
| 2030 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3))); |
| 2031 | int channel_num3 = voe_.GetLastChannel(); |
| 2032 | EXPECT_FALSE(voe_.GetPlayout(channel_num1)); |
| 2033 | EXPECT_TRUE(voe_.GetPlayout(channel_num2)); |
| 2034 | EXPECT_TRUE(voe_.GetPlayout(channel_num3)); |
| 2035 | EXPECT_FALSE(voe_.GetSend(channel_num3)); |
| 2036 | |
| 2037 | // Stop sending. |
| 2038 | EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING)); |
| 2039 | EXPECT_FALSE(voe_.GetSend(channel_num1)); |
| 2040 | EXPECT_FALSE(voe_.GetSend(channel_num2)); |
| 2041 | EXPECT_FALSE(voe_.GetSend(channel_num3)); |
| 2042 | |
| 2043 | // Stop playout. |
| 2044 | EXPECT_TRUE(channel_->SetPlayout(false)); |
| 2045 | EXPECT_FALSE(voe_.GetPlayout(channel_num1)); |
| 2046 | EXPECT_FALSE(voe_.GetPlayout(channel_num2)); |
| 2047 | EXPECT_FALSE(voe_.GetPlayout(channel_num3)); |
| 2048 | |
| 2049 | // Restart playout and make sure the default channel still is not played out. |
| 2050 | EXPECT_TRUE(channel_->SetPlayout(true)); |
| 2051 | EXPECT_FALSE(voe_.GetPlayout(channel_num1)); |
| 2052 | EXPECT_TRUE(voe_.GetPlayout(channel_num2)); |
| 2053 | EXPECT_TRUE(voe_.GetPlayout(channel_num3)); |
| 2054 | |
| 2055 | // Now remove the new streams and verify that the default channel is |
| 2056 | // played out again. |
| 2057 | EXPECT_TRUE(channel_->RemoveRecvStream(3)); |
| 2058 | EXPECT_TRUE(channel_->RemoveRecvStream(2)); |
| 2059 | |
| 2060 | EXPECT_TRUE(voe_.GetPlayout(channel_num1)); |
| 2061 | } |
| 2062 | |
| 2063 | // Test that we can set the devices to use. |
| 2064 | TEST_F(WebRtcVoiceEngineTestFake, SetDevices) { |
| 2065 | EXPECT_TRUE(SetupEngine()); |
| 2066 | int channel_num = voe_.GetLastChannel(); |
| 2067 | std::vector<cricket::AudioCodec> codecs; |
| 2068 | codecs.push_back(kPcmuCodec); |
| 2069 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 2070 | |
| 2071 | cricket::Device default_dev(cricket::kFakeDefaultDeviceName, |
| 2072 | cricket::kFakeDefaultDeviceId); |
| 2073 | cricket::Device dev(cricket::kFakeDeviceName, |
| 2074 | cricket::kFakeDeviceId); |
| 2075 | |
| 2076 | // Test SetDevices() while not sending or playing. |
| 2077 | EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev)); |
| 2078 | |
| 2079 | // Test SetDevices() while sending and playing. |
| 2080 | EXPECT_TRUE(engine_.SetLocalMonitor(true)); |
| 2081 | EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| 2082 | EXPECT_TRUE(channel_->SetPlayout(true)); |
| 2083 | EXPECT_TRUE(voe_.GetRecordingMicrophone()); |
| 2084 | EXPECT_TRUE(voe_.GetSend(channel_num)); |
| 2085 | EXPECT_TRUE(voe_.GetPlayout(channel_num)); |
| 2086 | |
| 2087 | EXPECT_TRUE(engine_.SetDevices(&dev, &dev)); |
| 2088 | |
| 2089 | EXPECT_TRUE(voe_.GetRecordingMicrophone()); |
| 2090 | EXPECT_TRUE(voe_.GetSend(channel_num)); |
| 2091 | EXPECT_TRUE(voe_.GetPlayout(channel_num)); |
| 2092 | |
| 2093 | // Test that failure to open newly selected devices does not prevent opening |
| 2094 | // ones after that. |
| 2095 | voe_.set_fail_start_recording_microphone(true); |
| 2096 | voe_.set_playout_fail_channel(channel_num); |
| 2097 | voe_.set_send_fail_channel(channel_num); |
| 2098 | |
| 2099 | EXPECT_FALSE(engine_.SetDevices(&default_dev, &default_dev)); |
| 2100 | |
| 2101 | EXPECT_FALSE(voe_.GetRecordingMicrophone()); |
| 2102 | EXPECT_FALSE(voe_.GetSend(channel_num)); |
| 2103 | EXPECT_FALSE(voe_.GetPlayout(channel_num)); |
| 2104 | |
| 2105 | voe_.set_fail_start_recording_microphone(false); |
| 2106 | voe_.set_playout_fail_channel(-1); |
| 2107 | voe_.set_send_fail_channel(-1); |
| 2108 | |
| 2109 | EXPECT_TRUE(engine_.SetDevices(&dev, &dev)); |
| 2110 | |
| 2111 | EXPECT_TRUE(voe_.GetRecordingMicrophone()); |
| 2112 | EXPECT_TRUE(voe_.GetSend(channel_num)); |
| 2113 | EXPECT_TRUE(voe_.GetPlayout(channel_num)); |
| 2114 | } |
| 2115 | |
| 2116 | // Test that we can set the devices to use even if we failed to |
| 2117 | // open the initial ones. |
| 2118 | TEST_F(WebRtcVoiceEngineTestFake, SetDevicesWithInitiallyBadDevices) { |
| 2119 | EXPECT_TRUE(SetupEngine()); |
| 2120 | int channel_num = voe_.GetLastChannel(); |
| 2121 | std::vector<cricket::AudioCodec> codecs; |
| 2122 | codecs.push_back(kPcmuCodec); |
| 2123 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 2124 | |
| 2125 | cricket::Device default_dev(cricket::kFakeDefaultDeviceName, |
| 2126 | cricket::kFakeDefaultDeviceId); |
| 2127 | cricket::Device dev(cricket::kFakeDeviceName, |
| 2128 | cricket::kFakeDeviceId); |
| 2129 | |
| 2130 | // Test that failure to open devices selected before starting |
| 2131 | // send/play does not prevent opening newly selected ones after that. |
| 2132 | voe_.set_fail_start_recording_microphone(true); |
| 2133 | voe_.set_playout_fail_channel(channel_num); |
| 2134 | voe_.set_send_fail_channel(channel_num); |
| 2135 | |
| 2136 | EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev)); |
| 2137 | |
| 2138 | EXPECT_FALSE(engine_.SetLocalMonitor(true)); |
| 2139 | EXPECT_FALSE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| 2140 | EXPECT_FALSE(channel_->SetPlayout(true)); |
| 2141 | EXPECT_FALSE(voe_.GetRecordingMicrophone()); |
| 2142 | EXPECT_FALSE(voe_.GetSend(channel_num)); |
| 2143 | EXPECT_FALSE(voe_.GetPlayout(channel_num)); |
| 2144 | |
| 2145 | voe_.set_fail_start_recording_microphone(false); |
| 2146 | voe_.set_playout_fail_channel(-1); |
| 2147 | voe_.set_send_fail_channel(-1); |
| 2148 | |
| 2149 | EXPECT_TRUE(engine_.SetDevices(&dev, &dev)); |
| 2150 | |
| 2151 | EXPECT_TRUE(voe_.GetRecordingMicrophone()); |
| 2152 | EXPECT_TRUE(voe_.GetSend(channel_num)); |
| 2153 | EXPECT_TRUE(voe_.GetPlayout(channel_num)); |
| 2154 | } |
| 2155 | |
| 2156 | // Test that we can create a channel configured for multi-point conferences, |
| 2157 | // and start sending/playing out on it. |
| 2158 | TEST_F(WebRtcVoiceEngineTestFake, ConferenceSendAndPlayout) { |
| 2159 | EXPECT_TRUE(SetupEngine()); |
| 2160 | int channel_num = voe_.GetLastChannel(); |
| 2161 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 2162 | std::vector<cricket::AudioCodec> codecs; |
| 2163 | codecs.push_back(kPcmuCodec); |
| 2164 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 2165 | EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| 2166 | EXPECT_TRUE(voe_.GetSend(channel_num)); |
| 2167 | } |
| 2168 | |
| 2169 | // Test that we can create a channel configured for Codian bridges, |
| 2170 | // and start sending/playing out on it. |
| 2171 | TEST_F(WebRtcVoiceEngineTestFake, CodianSendAndPlayout) { |
| 2172 | EXPECT_TRUE(SetupEngine()); |
| 2173 | int channel_num = voe_.GetLastChannel(); |
| 2174 | webrtc::AgcConfig agc_config; |
| 2175 | EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); |
| 2176 | EXPECT_EQ(0, agc_config.targetLeveldBOv); |
| 2177 | EXPECT_TRUE(channel_->SetOptions(options_adjust_agc_)); |
| 2178 | std::vector<cricket::AudioCodec> codecs; |
| 2179 | codecs.push_back(kPcmuCodec); |
| 2180 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 2181 | EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| 2182 | EXPECT_TRUE(voe_.GetSend(channel_num)); |
| 2183 | EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); |
| 2184 | EXPECT_EQ(agc_config.targetLeveldBOv, 10); // level was attenuated |
| 2185 | EXPECT_TRUE(channel_->SetPlayout(true)); |
| 2186 | EXPECT_TRUE(voe_.GetPlayout(channel_num)); |
| 2187 | EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING)); |
| 2188 | EXPECT_FALSE(voe_.GetSend(channel_num)); |
| 2189 | EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); |
| 2190 | EXPECT_EQ(0, agc_config.targetLeveldBOv); // level was restored |
| 2191 | EXPECT_TRUE(channel_->SetPlayout(false)); |
| 2192 | EXPECT_FALSE(voe_.GetPlayout(channel_num)); |
| 2193 | } |
| 2194 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2195 | TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) { |
| 2196 | EXPECT_TRUE(SetupEngine()); |
| 2197 | webrtc::AgcConfig agc_config; |
| 2198 | EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); |
| 2199 | EXPECT_EQ(0, agc_config.targetLeveldBOv); |
| 2200 | |
| 2201 | cricket::AudioOptions options; |
| 2202 | options.tx_agc_target_dbov.Set(3); |
| 2203 | options.tx_agc_digital_compression_gain.Set(9); |
| 2204 | options.tx_agc_limiter.Set(true); |
| 2205 | options.auto_gain_control.Set(true); |
| 2206 | EXPECT_TRUE(engine_.SetOptions(options)); |
| 2207 | |
| 2208 | EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); |
| 2209 | EXPECT_EQ(3, agc_config.targetLeveldBOv); |
| 2210 | EXPECT_EQ(9, agc_config.digitalCompressionGaindB); |
| 2211 | EXPECT_TRUE(agc_config.limiterEnable); |
| 2212 | |
| 2213 | // Check interaction with adjust_agc_delta. Both should be respected, for |
| 2214 | // backwards compatibility. |
| 2215 | options.adjust_agc_delta.Set(-10); |
| 2216 | EXPECT_TRUE(engine_.SetOptions(options)); |
| 2217 | |
| 2218 | EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); |
| 2219 | EXPECT_EQ(13, agc_config.targetLeveldBOv); |
| 2220 | } |
| 2221 | |
| 2222 | TEST_F(WebRtcVoiceEngineTestFake, RxAgcConfigViaOptions) { |
| 2223 | EXPECT_TRUE(SetupEngine()); |
| 2224 | int channel_num = voe_.GetLastChannel(); |
| 2225 | cricket::AudioOptions options; |
| 2226 | options.rx_agc_target_dbov.Set(6); |
| 2227 | options.rx_agc_digital_compression_gain.Set(0); |
| 2228 | options.rx_agc_limiter.Set(true); |
| 2229 | options.rx_auto_gain_control.Set(true); |
| 2230 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 2231 | |
| 2232 | webrtc::AgcConfig agc_config; |
| 2233 | EXPECT_EQ(0, engine_.voe()->processing()->GetRxAgcConfig( |
| 2234 | channel_num, agc_config)); |
| 2235 | EXPECT_EQ(6, agc_config.targetLeveldBOv); |
| 2236 | EXPECT_EQ(0, agc_config.digitalCompressionGaindB); |
| 2237 | EXPECT_TRUE(agc_config.limiterEnable); |
| 2238 | } |
| 2239 | |
| 2240 | TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) { |
| 2241 | EXPECT_TRUE(SetupEngine()); |
| 2242 | cricket::AudioOptions options; |
| 2243 | options.recording_sample_rate.Set(48000u); |
| 2244 | options.playout_sample_rate.Set(44100u); |
| 2245 | EXPECT_TRUE(engine_.SetOptions(options)); |
| 2246 | |
| 2247 | unsigned int recording_sample_rate, playout_sample_rate; |
| 2248 | EXPECT_EQ(0, voe_.RecordingSampleRate(&recording_sample_rate)); |
| 2249 | EXPECT_EQ(0, voe_.PlayoutSampleRate(&playout_sample_rate)); |
| 2250 | EXPECT_EQ(48000u, recording_sample_rate); |
| 2251 | EXPECT_EQ(44100u, playout_sample_rate); |
| 2252 | } |
| 2253 | |
| 2254 | TEST_F(WebRtcVoiceEngineTestFake, TraceFilterViaTraceOptions) { |
| 2255 | EXPECT_TRUE(SetupEngine()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2256 | engine_.SetLogging(rtc::LS_INFO, ""); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2257 | EXPECT_EQ( |
| 2258 | // Info: |
| 2259 | webrtc::kTraceStateInfo | webrtc::kTraceInfo | |
| 2260 | // Warning: |
| 2261 | webrtc::kTraceTerseInfo | webrtc::kTraceWarning | |
| 2262 | // Error: |
| 2263 | webrtc::kTraceError | webrtc::kTraceCritical, |
| 2264 | static_cast<int>(trace_wrapper_->filter_)); |
| 2265 | // Now set it explicitly |
| 2266 | std::string filter = |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2267 | "tracefilter " + rtc::ToString(webrtc::kTraceDefault); |
| 2268 | engine_.SetLogging(rtc::LS_VERBOSE, filter.c_str()); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2269 | EXPECT_EQ(static_cast<unsigned int>(webrtc::kTraceDefault), |
| 2270 | trace_wrapper_->filter_); |
| 2271 | } |
| 2272 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2273 | // Test that we can set the outgoing SSRC properly. |
| 2274 | // SSRC is set in SetupEngine by calling AddSendStream. |
| 2275 | TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrc) { |
| 2276 | EXPECT_TRUE(SetupEngine()); |
| 2277 | int channel_num = voe_.GetLastChannel(); |
| 2278 | unsigned int send_ssrc; |
| 2279 | EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc)); |
| 2280 | EXPECT_NE(0U, send_ssrc); |
| 2281 | EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc)); |
| 2282 | EXPECT_EQ(kSsrc1, send_ssrc); |
| 2283 | } |
| 2284 | |
| 2285 | TEST_F(WebRtcVoiceEngineTestFake, GetStats) { |
| 2286 | // Setup. We need send codec to be set to get all stats. |
| 2287 | EXPECT_TRUE(SetupEngine()); |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 2288 | // SetupEngine adds a send stream with kSsrc1, so the receive stream has to |
| 2289 | // use a different SSRC. |
| 2290 | EXPECT_TRUE(channel_->AddRecvStream( |
| 2291 | cricket::StreamParams::CreateLegacy(kSsrc2))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2292 | std::vector<cricket::AudioCodec> codecs; |
| 2293 | codecs.push_back(kPcmuCodec); |
| 2294 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 2295 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2296 | |
| 2297 | cricket::VoiceMediaInfo info; |
| 2298 | EXPECT_EQ(true, channel_->GetStats(&info)); |
| 2299 | EXPECT_EQ(1u, info.senders.size()); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 2300 | EXPECT_EQ(kSsrc1, info.senders[0].ssrc()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2301 | EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name); |
| 2302 | EXPECT_EQ(cricket::kIntStatValue, info.senders[0].bytes_sent); |
| 2303 | EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_sent); |
| 2304 | EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_lost); |
| 2305 | EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[0].fraction_lost); |
| 2306 | EXPECT_EQ(cricket::kIntStatValue, info.senders[0].ext_seqnum); |
| 2307 | EXPECT_EQ(cricket::kIntStatValue, info.senders[0].rtt_ms); |
| 2308 | EXPECT_EQ(cricket::kIntStatValue, info.senders[0].jitter_ms); |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 2309 | EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2310 | // TODO(sriniv): Add testing for more fields. These are not populated |
| 2311 | // in FakeWebrtcVoiceEngine yet. |
| 2312 | // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].audio_level); |
| 2313 | // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_median_ms); |
| 2314 | // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_std_ms); |
| 2315 | // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_return_loss); |
| 2316 | // EXPECT_EQ(cricket::kIntStatValue, |
| 2317 | // info.senders[0].echo_return_loss_enhancement); |
| 2318 | |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 2319 | EXPECT_EQ(0u, info.receivers.size()); |
| 2320 | DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); |
| 2321 | EXPECT_EQ(true, channel_->GetStats(&info)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2322 | EXPECT_EQ(1u, info.receivers.size()); |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 2323 | |
| 2324 | EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd); |
| 2325 | EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd); |
| 2326 | EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost); |
| 2327 | EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum); |
| 2328 | EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name); |
| 2329 | // TODO(sriniv): Add testing for more receiver fields. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | // Test that we can set the outgoing SSRC properly with multiple streams. |
| 2333 | // SSRC is set in SetupEngine by calling AddSendStream. |
| 2334 | TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcWithMultipleStreams) { |
| 2335 | EXPECT_TRUE(SetupEngine()); |
| 2336 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 2337 | int channel_num1 = voe_.GetLastChannel(); |
| 2338 | unsigned int send_ssrc; |
| 2339 | EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num1, send_ssrc)); |
| 2340 | EXPECT_EQ(kSsrc1, send_ssrc); |
| 2341 | |
| 2342 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| 2343 | int channel_num2 = voe_.GetLastChannel(); |
| 2344 | EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num2, send_ssrc)); |
| 2345 | EXPECT_EQ(kSsrc1, send_ssrc); |
| 2346 | } |
| 2347 | |
| 2348 | // Test that the local SSRC is the same on sending and receiving channels if the |
| 2349 | // receive channel is created before the send channel. |
| 2350 | TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2351 | EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2352 | channel_ = engine_.CreateChannel(); |
| 2353 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 2354 | |
| 2355 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 2356 | int receive_channel_num = voe_.GetLastChannel(); |
| 2357 | EXPECT_TRUE(channel_->AddSendStream( |
| 2358 | cricket::StreamParams::CreateLegacy(1234))); |
| 2359 | int send_channel_num = voe_.GetLastChannel(); |
| 2360 | |
| 2361 | unsigned int ssrc = 0; |
| 2362 | EXPECT_EQ(0, voe_.GetLocalSSRC(send_channel_num, ssrc)); |
| 2363 | EXPECT_EQ(1234U, ssrc); |
| 2364 | ssrc = 0; |
| 2365 | EXPECT_EQ(0, voe_.GetLocalSSRC(receive_channel_num, ssrc)); |
| 2366 | EXPECT_EQ(1234U, ssrc); |
| 2367 | } |
| 2368 | |
| 2369 | // Test that we can properly receive packets. |
| 2370 | TEST_F(WebRtcVoiceEngineTestFake, Recv) { |
| 2371 | EXPECT_TRUE(SetupEngine()); |
| 2372 | int channel_num = voe_.GetLastChannel(); |
| 2373 | DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); |
| 2374 | EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame, |
| 2375 | sizeof(kPcmuFrame))); |
| 2376 | } |
| 2377 | |
| 2378 | // Test that we can properly receive packets on multiple streams. |
| 2379 | TEST_F(WebRtcVoiceEngineTestFake, RecvWithMultipleStreams) { |
| 2380 | EXPECT_TRUE(SetupEngine()); |
| 2381 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 2382 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 2383 | int channel_num1 = voe_.GetLastChannel(); |
| 2384 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| 2385 | int channel_num2 = voe_.GetLastChannel(); |
| 2386 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3))); |
| 2387 | int channel_num3 = voe_.GetLastChannel(); |
| 2388 | // Create packets with the right SSRCs. |
| 2389 | char packets[4][sizeof(kPcmuFrame)]; |
| 2390 | for (size_t i = 0; i < ARRAY_SIZE(packets); ++i) { |
| 2391 | memcpy(packets[i], kPcmuFrame, sizeof(kPcmuFrame)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2392 | rtc::SetBE32(packets[i] + 8, static_cast<uint32>(i)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2393 | } |
| 2394 | EXPECT_TRUE(voe_.CheckNoPacket(channel_num1)); |
| 2395 | EXPECT_TRUE(voe_.CheckNoPacket(channel_num2)); |
| 2396 | EXPECT_TRUE(voe_.CheckNoPacket(channel_num3)); |
| 2397 | DeliverPacket(packets[0], sizeof(packets[0])); |
| 2398 | EXPECT_TRUE(voe_.CheckNoPacket(channel_num1)); |
| 2399 | EXPECT_TRUE(voe_.CheckNoPacket(channel_num2)); |
| 2400 | EXPECT_TRUE(voe_.CheckNoPacket(channel_num3)); |
| 2401 | DeliverPacket(packets[1], sizeof(packets[1])); |
| 2402 | EXPECT_TRUE(voe_.CheckPacket(channel_num1, packets[1], |
| 2403 | sizeof(packets[1]))); |
| 2404 | EXPECT_TRUE(voe_.CheckNoPacket(channel_num2)); |
| 2405 | EXPECT_TRUE(voe_.CheckNoPacket(channel_num3)); |
| 2406 | DeliverPacket(packets[2], sizeof(packets[2])); |
| 2407 | EXPECT_TRUE(voe_.CheckNoPacket(channel_num1)); |
| 2408 | EXPECT_TRUE(voe_.CheckPacket(channel_num2, packets[2], |
| 2409 | sizeof(packets[2]))); |
| 2410 | EXPECT_TRUE(voe_.CheckNoPacket(channel_num3)); |
| 2411 | DeliverPacket(packets[3], sizeof(packets[3])); |
| 2412 | EXPECT_TRUE(voe_.CheckNoPacket(channel_num1)); |
| 2413 | EXPECT_TRUE(voe_.CheckNoPacket(channel_num2)); |
| 2414 | EXPECT_TRUE(voe_.CheckPacket(channel_num3, packets[3], |
| 2415 | sizeof(packets[3]))); |
| 2416 | EXPECT_TRUE(channel_->RemoveRecvStream(3)); |
| 2417 | EXPECT_TRUE(channel_->RemoveRecvStream(2)); |
| 2418 | EXPECT_TRUE(channel_->RemoveRecvStream(1)); |
| 2419 | } |
| 2420 | |
| 2421 | // Test that we properly handle failures to add a stream. |
| 2422 | TEST_F(WebRtcVoiceEngineTestFake, AddStreamFail) { |
| 2423 | EXPECT_TRUE(SetupEngine()); |
| 2424 | voe_.set_fail_create_channel(true); |
| 2425 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 2426 | EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| 2427 | |
| 2428 | // In 1:1 call, we should not try to create a new channel. |
| 2429 | cricket::AudioOptions options_no_conference_; |
| 2430 | options_no_conference_.conference_mode.Set(false); |
| 2431 | EXPECT_TRUE(channel_->SetOptions(options_no_conference_)); |
| 2432 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| 2433 | } |
| 2434 | |
| 2435 | // Test that AddRecvStream doesn't create new channel for 1:1 call. |
| 2436 | TEST_F(WebRtcVoiceEngineTestFake, AddRecvStream1On1) { |
| 2437 | EXPECT_TRUE(SetupEngine()); |
| 2438 | int channel_num = voe_.GetLastChannel(); |
| 2439 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 2440 | EXPECT_EQ(channel_num, voe_.GetLastChannel()); |
| 2441 | } |
| 2442 | |
| 2443 | // Test that after adding a recv stream, we do not decode more codecs than |
| 2444 | // those previously passed into SetRecvCodecs. |
| 2445 | TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) { |
| 2446 | EXPECT_TRUE(SetupEngine()); |
| 2447 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 2448 | std::vector<cricket::AudioCodec> codecs; |
| 2449 | codecs.push_back(kIsacCodec); |
| 2450 | codecs.push_back(kPcmuCodec); |
| 2451 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 2452 | EXPECT_TRUE(channel_->AddRecvStream( |
| 2453 | cricket::StreamParams::CreateLegacy(kSsrc1))); |
| 2454 | int channel_num2 = voe_.GetLastChannel(); |
| 2455 | webrtc::CodecInst gcodec; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2456 | rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "CELT"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2457 | gcodec.plfreq = 32000; |
| 2458 | gcodec.channels = 2; |
| 2459 | EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec)); |
| 2460 | } |
| 2461 | |
| 2462 | // Test that we properly clean up any streams that were added, even if |
| 2463 | // not explicitly removed. |
| 2464 | TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) { |
| 2465 | EXPECT_TRUE(SetupEngine()); |
| 2466 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 2467 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 2468 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| 2469 | EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added |
| 2470 | delete channel_; |
| 2471 | channel_ = NULL; |
| 2472 | EXPECT_EQ(0, voe_.GetNumChannels()); |
| 2473 | } |
| 2474 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2475 | TEST_F(WebRtcVoiceEngineTestFake, TestAddRecvStreamFailWithZeroSsrc) { |
| 2476 | EXPECT_TRUE(SetupEngine()); |
| 2477 | EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0))); |
| 2478 | } |
| 2479 | |
| 2480 | TEST_F(WebRtcVoiceEngineTestFake, TestNoLeakingWhenAddRecvStreamFail) { |
| 2481 | EXPECT_TRUE(SetupEngine()); |
| 2482 | // Stream 1 reuses default channel. |
| 2483 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 2484 | // Manually delete default channel to simulate a failure. |
| 2485 | int default_channel = voe_.GetLastChannel(); |
| 2486 | EXPECT_EQ(0, voe_.DeleteChannel(default_channel)); |
| 2487 | // Add recv stream 2 should fail because default channel is gone. |
| 2488 | EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| 2489 | int new_channel = voe_.GetLastChannel(); |
| 2490 | EXPECT_NE(default_channel, new_channel); |
| 2491 | // The last created channel should have already been deleted. |
| 2492 | EXPECT_EQ(-1, voe_.DeleteChannel(new_channel)); |
| 2493 | } |
| 2494 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2495 | // Test the InsertDtmf on default send stream as caller. |
| 2496 | TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCaller) { |
| 2497 | TestInsertDtmf(0, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2498 | } |
| 2499 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 2500 | // Test the InsertDtmf on default send stream as callee |
| 2501 | TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCallee) { |
| 2502 | TestInsertDtmf(0, false); |
| 2503 | } |
| 2504 | |
| 2505 | // Test the InsertDtmf on specified send stream as caller. |
| 2506 | TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCaller) { |
| 2507 | TestInsertDtmf(kSsrc1, true); |
| 2508 | } |
| 2509 | |
| 2510 | // Test the InsertDtmf on specified send stream as callee. |
| 2511 | TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCallee) { |
| 2512 | TestInsertDtmf(kSsrc1, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2513 | } |
| 2514 | |
| 2515 | // Test that we can play a ringback tone properly in a single-stream call. |
| 2516 | TEST_F(WebRtcVoiceEngineTestFake, PlayRingback) { |
| 2517 | EXPECT_TRUE(SetupEngine()); |
| 2518 | int channel_num = voe_.GetLastChannel(); |
| 2519 | EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num)); |
| 2520 | // Check we fail if no ringback tone specified. |
| 2521 | EXPECT_FALSE(channel_->PlayRingbackTone(0, true, true)); |
| 2522 | EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num)); |
| 2523 | // Check we can set and play a ringback tone. |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 2524 | EXPECT_TRUE(channel_->SetRingbackTone( |
| 2525 | kRingbackTone, static_cast<int>(strlen(kRingbackTone)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2526 | EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true)); |
| 2527 | EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num)); |
| 2528 | // Check we can stop the tone manually. |
| 2529 | EXPECT_TRUE(channel_->PlayRingbackTone(0, false, false)); |
| 2530 | EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num)); |
| 2531 | // Check we stop the tone if a packet arrives. |
| 2532 | EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true)); |
| 2533 | EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num)); |
| 2534 | DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); |
| 2535 | EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num)); |
| 2536 | } |
| 2537 | |
| 2538 | // Test that we can play a ringback tone properly in a multi-stream call. |
| 2539 | TEST_F(WebRtcVoiceEngineTestFake, PlayRingbackWithMultipleStreams) { |
| 2540 | EXPECT_TRUE(SetupEngine()); |
| 2541 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 2542 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 2543 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| 2544 | int channel_num = voe_.GetLastChannel(); |
| 2545 | EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num)); |
| 2546 | // Check we fail if no ringback tone specified. |
| 2547 | EXPECT_FALSE(channel_->PlayRingbackTone(2, true, true)); |
| 2548 | EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num)); |
| 2549 | // Check we can set and play a ringback tone on the correct ssrc. |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 2550 | EXPECT_TRUE(channel_->SetRingbackTone( |
| 2551 | kRingbackTone, static_cast<int>(strlen(kRingbackTone)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2552 | EXPECT_FALSE(channel_->PlayRingbackTone(77, true, true)); |
| 2553 | EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true)); |
| 2554 | EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num)); |
| 2555 | // Check we can stop the tone manually. |
| 2556 | EXPECT_TRUE(channel_->PlayRingbackTone(2, false, false)); |
| 2557 | EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num)); |
| 2558 | // Check we stop the tone if a packet arrives, but only with the right SSRC. |
| 2559 | EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true)); |
| 2560 | EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num)); |
| 2561 | // Send a packet with SSRC 1; the tone should not stop. |
| 2562 | DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); |
| 2563 | EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num)); |
| 2564 | // Send a packet with SSRC 2; the tone should stop. |
| 2565 | char packet[sizeof(kPcmuFrame)]; |
| 2566 | memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2567 | rtc::SetBE32(packet + 8, 2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2568 | DeliverPacket(packet, sizeof(packet)); |
| 2569 | EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num)); |
| 2570 | } |
| 2571 | |
| 2572 | // Tests creating soundclips, and make sure they come from the right engine. |
| 2573 | TEST_F(WebRtcVoiceEngineTestFake, CreateSoundclip) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2574 | EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 2575 | EXPECT_FALSE(voe_sc_.IsInited()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2576 | soundclip_ = engine_.CreateSoundclip(); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 2577 | EXPECT_TRUE(voe_sc_.IsInited()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2578 | ASSERT_TRUE(soundclip_ != NULL); |
| 2579 | EXPECT_EQ(0, voe_.GetNumChannels()); |
| 2580 | EXPECT_EQ(1, voe_sc_.GetNumChannels()); |
| 2581 | int channel_num = voe_sc_.GetLastChannel(); |
| 2582 | EXPECT_TRUE(voe_sc_.GetPlayout(channel_num)); |
| 2583 | delete soundclip_; |
| 2584 | soundclip_ = NULL; |
| 2585 | EXPECT_EQ(0, voe_sc_.GetNumChannels()); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 2586 | // Make sure the soundclip engine is uninitialized on shutdown, now that |
| 2587 | // we've initialized it by creating a soundclip. |
| 2588 | engine_.Terminate(); |
| 2589 | EXPECT_FALSE(voe_sc_.IsInited()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | // Tests playing out a fake sound. |
| 2593 | TEST_F(WebRtcVoiceEngineTestFake, PlaySoundclip) { |
| 2594 | static const char kZeroes[16000] = {}; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2595 | EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2596 | soundclip_ = engine_.CreateSoundclip(); |
| 2597 | ASSERT_TRUE(soundclip_ != NULL); |
| 2598 | EXPECT_TRUE(soundclip_->PlaySound(kZeroes, sizeof(kZeroes), 0)); |
| 2599 | } |
| 2600 | |
| 2601 | TEST_F(WebRtcVoiceEngineTestFake, MediaEngineCallbackOnError) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2602 | rtc::scoped_ptr<ChannelErrorListener> listener; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2603 | cricket::WebRtcVoiceMediaChannel* media_channel; |
| 2604 | unsigned int ssrc = 0; |
| 2605 | |
| 2606 | EXPECT_TRUE(SetupEngine()); |
| 2607 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 2608 | EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| 2609 | |
| 2610 | media_channel = static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); |
| 2611 | listener.reset(new ChannelErrorListener(channel_)); |
| 2612 | |
| 2613 | // Test on WebRtc VoE channel. |
| 2614 | voe_.TriggerCallbackOnError(media_channel->voe_channel(), |
| 2615 | VE_SATURATION_WARNING); |
| 2616 | EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION, |
| 2617 | listener->error()); |
| 2618 | EXPECT_NE(-1, voe_.GetLocalSSRC(voe_.GetLastChannel(), ssrc)); |
| 2619 | EXPECT_EQ(ssrc, listener->ssrc()); |
| 2620 | |
| 2621 | listener->Reset(); |
| 2622 | voe_.TriggerCallbackOnError(-1, VE_TYPING_NOISE_WARNING); |
| 2623 | EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED, |
| 2624 | listener->error()); |
| 2625 | EXPECT_EQ(0U, listener->ssrc()); |
| 2626 | |
| 2627 | // Add another stream and test on that. |
| 2628 | ++ssrc; |
| 2629 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy( |
| 2630 | ssrc))); |
| 2631 | listener->Reset(); |
| 2632 | voe_.TriggerCallbackOnError(voe_.GetLastChannel(), |
| 2633 | VE_SATURATION_WARNING); |
| 2634 | EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION, |
| 2635 | listener->error()); |
| 2636 | EXPECT_EQ(ssrc, listener->ssrc()); |
| 2637 | |
| 2638 | // Testing a non-existing channel. |
| 2639 | listener->Reset(); |
| 2640 | voe_.TriggerCallbackOnError(voe_.GetLastChannel() + 2, |
| 2641 | VE_SATURATION_WARNING); |
| 2642 | EXPECT_EQ(0, listener->error()); |
| 2643 | } |
| 2644 | |
| 2645 | TEST_F(WebRtcVoiceEngineTestFake, TestSetPlayoutError) { |
| 2646 | EXPECT_TRUE(SetupEngine()); |
| 2647 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 2648 | std::vector<cricket::AudioCodec> codecs; |
| 2649 | codecs.push_back(kPcmuCodec); |
| 2650 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 2651 | EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| 2652 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| 2653 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3))); |
| 2654 | EXPECT_TRUE(channel_->SetPlayout(true)); |
| 2655 | voe_.set_playout_fail_channel(voe_.GetLastChannel() - 1); |
| 2656 | EXPECT_TRUE(channel_->SetPlayout(false)); |
| 2657 | EXPECT_FALSE(channel_->SetPlayout(true)); |
| 2658 | } |
| 2659 | |
| 2660 | // Test that the Registering/Unregistering with the |
| 2661 | // webrtcvoiceengine works as expected |
| 2662 | TEST_F(WebRtcVoiceEngineTestFake, RegisterVoiceProcessor) { |
| 2663 | EXPECT_TRUE(SetupEngine()); |
| 2664 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 2665 | EXPECT_TRUE(channel_->AddRecvStream( |
| 2666 | cricket::StreamParams::CreateLegacy(kSsrc2))); |
| 2667 | cricket::FakeMediaProcessor vp_1; |
| 2668 | cricket::FakeMediaProcessor vp_2; |
| 2669 | |
| 2670 | EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_TX)); |
| 2671 | EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX)); |
| 2672 | EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_2, cricket::MPD_RX)); |
| 2673 | voe_.TriggerProcessPacket(cricket::MPD_RX); |
| 2674 | voe_.TriggerProcessPacket(cricket::MPD_TX); |
| 2675 | |
| 2676 | EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered()); |
| 2677 | EXPECT_EQ(1, vp_1.voice_frame_count()); |
| 2678 | EXPECT_EQ(1, vp_2.voice_frame_count()); |
| 2679 | |
| 2680 | EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2, |
| 2681 | &vp_2, |
| 2682 | cricket::MPD_RX)); |
| 2683 | voe_.TriggerProcessPacket(cricket::MPD_RX); |
| 2684 | EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered()); |
| 2685 | EXPECT_EQ(1, vp_2.voice_frame_count()); |
| 2686 | EXPECT_EQ(2, vp_1.voice_frame_count()); |
| 2687 | |
| 2688 | EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2, |
| 2689 | &vp_1, |
| 2690 | cricket::MPD_RX)); |
| 2691 | voe_.TriggerProcessPacket(cricket::MPD_RX); |
| 2692 | EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered()); |
| 2693 | EXPECT_EQ(2, vp_1.voice_frame_count()); |
| 2694 | |
| 2695 | EXPECT_FALSE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_RX)); |
| 2696 | EXPECT_TRUE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_TX)); |
| 2697 | voe_.TriggerProcessPacket(cricket::MPD_RX); |
| 2698 | voe_.TriggerProcessPacket(cricket::MPD_TX); |
| 2699 | EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered()); |
| 2700 | EXPECT_EQ(3, vp_1.voice_frame_count()); |
| 2701 | |
| 2702 | EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc1, |
| 2703 | &vp_1, |
| 2704 | cricket::MPD_RX_AND_TX)); |
| 2705 | voe_.TriggerProcessPacket(cricket::MPD_TX); |
| 2706 | EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered()); |
| 2707 | EXPECT_EQ(3, vp_1.voice_frame_count()); |
| 2708 | EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc2)); |
| 2709 | EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX)); |
| 2710 | EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered()); |
| 2711 | |
| 2712 | // Test that we can register a processor on the receive channel on SSRC 0. |
| 2713 | // This tests the 1:1 case when the receive SSRC is unknown. |
| 2714 | EXPECT_TRUE(engine_.RegisterProcessor(0, &vp_1, cricket::MPD_RX)); |
| 2715 | voe_.TriggerProcessPacket(cricket::MPD_RX); |
| 2716 | EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered()); |
| 2717 | EXPECT_EQ(4, vp_1.voice_frame_count()); |
| 2718 | EXPECT_TRUE(engine_.UnregisterProcessor(0, |
| 2719 | &vp_1, |
| 2720 | cricket::MPD_RX)); |
| 2721 | |
| 2722 | // The following tests test that FindChannelNumFromSsrc is doing |
| 2723 | // what we expect. |
| 2724 | // pick an invalid ssrc and make sure we can't register |
| 2725 | EXPECT_FALSE(engine_.RegisterProcessor(99, |
| 2726 | &vp_1, |
| 2727 | cricket::MPD_RX)); |
| 2728 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 2729 | EXPECT_TRUE(engine_.RegisterProcessor(1, |
| 2730 | &vp_1, |
| 2731 | cricket::MPD_RX)); |
| 2732 | EXPECT_TRUE(engine_.UnregisterProcessor(1, |
| 2733 | &vp_1, |
| 2734 | cricket::MPD_RX)); |
| 2735 | EXPECT_FALSE(engine_.RegisterProcessor(1, |
| 2736 | &vp_1, |
| 2737 | cricket::MPD_TX)); |
| 2738 | EXPECT_TRUE(channel_->RemoveRecvStream(1)); |
| 2739 | } |
| 2740 | |
| 2741 | TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { |
| 2742 | EXPECT_TRUE(SetupEngine()); |
| 2743 | |
| 2744 | bool ec_enabled; |
| 2745 | webrtc::EcModes ec_mode; |
| 2746 | bool ec_metrics_enabled; |
| 2747 | webrtc::AecmModes aecm_mode; |
| 2748 | bool cng_enabled; |
| 2749 | bool agc_enabled; |
| 2750 | webrtc::AgcModes agc_mode; |
| 2751 | webrtc::AgcConfig agc_config; |
| 2752 | bool ns_enabled; |
| 2753 | webrtc::NsModes ns_mode; |
| 2754 | bool highpass_filter_enabled; |
| 2755 | bool stereo_swapping_enabled; |
| 2756 | bool typing_detection_enabled; |
| 2757 | voe_.GetEcStatus(ec_enabled, ec_mode); |
| 2758 | voe_.GetEcMetricsStatus(ec_metrics_enabled); |
| 2759 | voe_.GetAecmMode(aecm_mode, cng_enabled); |
| 2760 | voe_.GetAgcStatus(agc_enabled, agc_mode); |
| 2761 | voe_.GetAgcConfig(agc_config); |
| 2762 | voe_.GetNsStatus(ns_enabled, ns_mode); |
| 2763 | highpass_filter_enabled = voe_.IsHighPassFilterEnabled(); |
| 2764 | stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled(); |
| 2765 | voe_.GetTypingDetectionStatus(typing_detection_enabled); |
| 2766 | EXPECT_TRUE(ec_enabled); |
| 2767 | EXPECT_TRUE(ec_metrics_enabled); |
| 2768 | EXPECT_FALSE(cng_enabled); |
| 2769 | EXPECT_TRUE(agc_enabled); |
| 2770 | EXPECT_EQ(0, agc_config.targetLeveldBOv); |
| 2771 | EXPECT_TRUE(ns_enabled); |
| 2772 | EXPECT_TRUE(highpass_filter_enabled); |
| 2773 | EXPECT_FALSE(stereo_swapping_enabled); |
| 2774 | EXPECT_TRUE(typing_detection_enabled); |
| 2775 | EXPECT_EQ(ec_mode, webrtc::kEcConference); |
| 2776 | EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression); |
| 2777 | |
| 2778 | // Nothing set, so all ignored. |
| 2779 | cricket::AudioOptions options; |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 2780 | ASSERT_TRUE(engine_.SetOptions(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2781 | voe_.GetEcStatus(ec_enabled, ec_mode); |
| 2782 | voe_.GetEcMetricsStatus(ec_metrics_enabled); |
| 2783 | voe_.GetAecmMode(aecm_mode, cng_enabled); |
| 2784 | voe_.GetAgcStatus(agc_enabled, agc_mode); |
| 2785 | voe_.GetAgcConfig(agc_config); |
| 2786 | voe_.GetNsStatus(ns_enabled, ns_mode); |
| 2787 | highpass_filter_enabled = voe_.IsHighPassFilterEnabled(); |
| 2788 | stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled(); |
| 2789 | voe_.GetTypingDetectionStatus(typing_detection_enabled); |
| 2790 | EXPECT_TRUE(ec_enabled); |
| 2791 | EXPECT_TRUE(ec_metrics_enabled); |
| 2792 | EXPECT_FALSE(cng_enabled); |
| 2793 | EXPECT_TRUE(agc_enabled); |
| 2794 | EXPECT_EQ(0, agc_config.targetLeveldBOv); |
| 2795 | EXPECT_TRUE(ns_enabled); |
| 2796 | EXPECT_TRUE(highpass_filter_enabled); |
| 2797 | EXPECT_FALSE(stereo_swapping_enabled); |
| 2798 | EXPECT_TRUE(typing_detection_enabled); |
| 2799 | EXPECT_EQ(ec_mode, webrtc::kEcConference); |
| 2800 | EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression); |
| 2801 | |
| 2802 | // Turn echo cancellation off |
| 2803 | options.echo_cancellation.Set(false); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 2804 | ASSERT_TRUE(engine_.SetOptions(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2805 | voe_.GetEcStatus(ec_enabled, ec_mode); |
| 2806 | EXPECT_FALSE(ec_enabled); |
| 2807 | |
| 2808 | // Turn echo cancellation back on, with settings, and make sure |
| 2809 | // nothing else changed. |
| 2810 | options.echo_cancellation.Set(true); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 2811 | ASSERT_TRUE(engine_.SetOptions(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2812 | voe_.GetEcStatus(ec_enabled, ec_mode); |
| 2813 | voe_.GetEcMetricsStatus(ec_metrics_enabled); |
| 2814 | voe_.GetAecmMode(aecm_mode, cng_enabled); |
| 2815 | voe_.GetAgcStatus(agc_enabled, agc_mode); |
| 2816 | voe_.GetAgcConfig(agc_config); |
| 2817 | voe_.GetNsStatus(ns_enabled, ns_mode); |
| 2818 | highpass_filter_enabled = voe_.IsHighPassFilterEnabled(); |
| 2819 | stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled(); |
| 2820 | voe_.GetTypingDetectionStatus(typing_detection_enabled); |
| 2821 | EXPECT_TRUE(ec_enabled); |
| 2822 | EXPECT_TRUE(ec_metrics_enabled); |
| 2823 | EXPECT_TRUE(agc_enabled); |
| 2824 | EXPECT_EQ(0, agc_config.targetLeveldBOv); |
| 2825 | EXPECT_TRUE(ns_enabled); |
| 2826 | EXPECT_TRUE(highpass_filter_enabled); |
| 2827 | EXPECT_FALSE(stereo_swapping_enabled); |
| 2828 | EXPECT_TRUE(typing_detection_enabled); |
| 2829 | EXPECT_EQ(ec_mode, webrtc::kEcConference); |
| 2830 | EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression); |
| 2831 | |
| 2832 | // Turn off AGC |
| 2833 | options.auto_gain_control.Set(false); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 2834 | ASSERT_TRUE(engine_.SetOptions(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2835 | voe_.GetAgcStatus(agc_enabled, agc_mode); |
| 2836 | EXPECT_FALSE(agc_enabled); |
| 2837 | |
| 2838 | // Turn AGC back on |
| 2839 | options.auto_gain_control.Set(true); |
| 2840 | options.adjust_agc_delta.Clear(); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 2841 | ASSERT_TRUE(engine_.SetOptions(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2842 | voe_.GetAgcStatus(agc_enabled, agc_mode); |
| 2843 | EXPECT_TRUE(agc_enabled); |
| 2844 | voe_.GetAgcConfig(agc_config); |
| 2845 | EXPECT_EQ(0, agc_config.targetLeveldBOv); |
| 2846 | |
| 2847 | // Turn off other options (and stereo swapping on). |
| 2848 | options.noise_suppression.Set(false); |
| 2849 | options.highpass_filter.Set(false); |
| 2850 | options.typing_detection.Set(false); |
| 2851 | options.stereo_swapping.Set(true); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 2852 | ASSERT_TRUE(engine_.SetOptions(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2853 | voe_.GetNsStatus(ns_enabled, ns_mode); |
| 2854 | highpass_filter_enabled = voe_.IsHighPassFilterEnabled(); |
| 2855 | stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled(); |
| 2856 | voe_.GetTypingDetectionStatus(typing_detection_enabled); |
| 2857 | EXPECT_FALSE(ns_enabled); |
| 2858 | EXPECT_FALSE(highpass_filter_enabled); |
| 2859 | EXPECT_FALSE(typing_detection_enabled); |
| 2860 | EXPECT_TRUE(stereo_swapping_enabled); |
| 2861 | |
| 2862 | // Turn on "conference mode" to ensure it has no impact. |
| 2863 | options.conference_mode.Set(true); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 2864 | ASSERT_TRUE(engine_.SetOptions(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2865 | voe_.GetEcStatus(ec_enabled, ec_mode); |
| 2866 | voe_.GetNsStatus(ns_enabled, ns_mode); |
| 2867 | EXPECT_TRUE(ec_enabled); |
| 2868 | EXPECT_EQ(webrtc::kEcConference, ec_mode); |
| 2869 | EXPECT_FALSE(ns_enabled); |
| 2870 | EXPECT_EQ(webrtc::kNsHighSuppression, ns_mode); |
| 2871 | } |
| 2872 | |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 2873 | TEST_F(WebRtcVoiceEngineTestFake, DefaultOptions) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2874 | EXPECT_TRUE(SetupEngine()); |
| 2875 | |
| 2876 | bool ec_enabled; |
| 2877 | webrtc::EcModes ec_mode; |
| 2878 | bool ec_metrics_enabled; |
| 2879 | bool agc_enabled; |
| 2880 | webrtc::AgcModes agc_mode; |
| 2881 | bool ns_enabled; |
| 2882 | webrtc::NsModes ns_mode; |
| 2883 | bool highpass_filter_enabled; |
| 2884 | bool stereo_swapping_enabled; |
| 2885 | bool typing_detection_enabled; |
| 2886 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2887 | voe_.GetEcStatus(ec_enabled, ec_mode); |
| 2888 | voe_.GetEcMetricsStatus(ec_metrics_enabled); |
| 2889 | voe_.GetAgcStatus(agc_enabled, agc_mode); |
| 2890 | voe_.GetNsStatus(ns_enabled, ns_mode); |
| 2891 | highpass_filter_enabled = voe_.IsHighPassFilterEnabled(); |
| 2892 | stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled(); |
| 2893 | voe_.GetTypingDetectionStatus(typing_detection_enabled); |
| 2894 | EXPECT_TRUE(ec_enabled); |
| 2895 | EXPECT_TRUE(agc_enabled); |
| 2896 | EXPECT_TRUE(ns_enabled); |
| 2897 | EXPECT_TRUE(highpass_filter_enabled); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 2898 | EXPECT_TRUE(typing_detection_enabled); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2899 | EXPECT_FALSE(stereo_swapping_enabled); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2900 | } |
| 2901 | |
| 2902 | TEST_F(WebRtcVoiceEngineTestFake, InitDoesNotOverwriteDefaultAgcConfig) { |
| 2903 | webrtc::AgcConfig set_config = {0}; |
| 2904 | set_config.targetLeveldBOv = 3; |
| 2905 | set_config.digitalCompressionGaindB = 9; |
| 2906 | set_config.limiterEnable = true; |
| 2907 | EXPECT_EQ(0, voe_.SetAgcConfig(set_config)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2908 | EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2909 | |
| 2910 | webrtc::AgcConfig config = {0}; |
| 2911 | EXPECT_EQ(0, voe_.GetAgcConfig(config)); |
| 2912 | EXPECT_EQ(set_config.targetLeveldBOv, config.targetLeveldBOv); |
| 2913 | EXPECT_EQ(set_config.digitalCompressionGaindB, |
| 2914 | config.digitalCompressionGaindB); |
| 2915 | EXPECT_EQ(set_config.limiterEnable, config.limiterEnable); |
| 2916 | } |
| 2917 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2918 | TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { |
| 2919 | EXPECT_TRUE(SetupEngine()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2920 | rtc::scoped_ptr<cricket::VoiceMediaChannel> channel1( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2921 | engine_.CreateChannel()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2922 | rtc::scoped_ptr<cricket::VoiceMediaChannel> channel2( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2923 | engine_.CreateChannel()); |
| 2924 | |
| 2925 | // Have to add a stream to make SetSend work. |
| 2926 | cricket::StreamParams stream1; |
| 2927 | stream1.ssrcs.push_back(1); |
| 2928 | channel1->AddSendStream(stream1); |
| 2929 | cricket::StreamParams stream2; |
| 2930 | stream2.ssrcs.push_back(2); |
| 2931 | channel2->AddSendStream(stream2); |
| 2932 | |
| 2933 | // AEC and AGC and NS |
| 2934 | cricket::AudioOptions options_all; |
| 2935 | options_all.echo_cancellation.Set(true); |
| 2936 | options_all.auto_gain_control.Set(true); |
| 2937 | options_all.noise_suppression.Set(true); |
| 2938 | |
| 2939 | ASSERT_TRUE(channel1->SetOptions(options_all)); |
| 2940 | cricket::AudioOptions expected_options = options_all; |
| 2941 | cricket::AudioOptions actual_options; |
| 2942 | ASSERT_TRUE(channel1->GetOptions(&actual_options)); |
| 2943 | EXPECT_EQ(expected_options, actual_options); |
| 2944 | ASSERT_TRUE(channel2->SetOptions(options_all)); |
| 2945 | ASSERT_TRUE(channel2->GetOptions(&actual_options)); |
| 2946 | EXPECT_EQ(expected_options, actual_options); |
| 2947 | |
| 2948 | // unset NS |
| 2949 | cricket::AudioOptions options_no_ns; |
| 2950 | options_no_ns.noise_suppression.Set(false); |
| 2951 | ASSERT_TRUE(channel1->SetOptions(options_no_ns)); |
| 2952 | |
| 2953 | expected_options.echo_cancellation.Set(true); |
| 2954 | expected_options.auto_gain_control.Set(true); |
| 2955 | expected_options.noise_suppression.Set(false); |
| 2956 | ASSERT_TRUE(channel1->GetOptions(&actual_options)); |
| 2957 | EXPECT_EQ(expected_options, actual_options); |
| 2958 | |
| 2959 | // unset AGC |
| 2960 | cricket::AudioOptions options_no_agc; |
| 2961 | options_no_agc.auto_gain_control.Set(false); |
| 2962 | ASSERT_TRUE(channel2->SetOptions(options_no_agc)); |
| 2963 | |
| 2964 | expected_options.echo_cancellation.Set(true); |
| 2965 | expected_options.auto_gain_control.Set(false); |
| 2966 | expected_options.noise_suppression.Set(true); |
| 2967 | ASSERT_TRUE(channel2->GetOptions(&actual_options)); |
| 2968 | EXPECT_EQ(expected_options, actual_options); |
| 2969 | |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 2970 | ASSERT_TRUE(engine_.SetOptions(options_all)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2971 | bool ec_enabled; |
| 2972 | webrtc::EcModes ec_mode; |
| 2973 | bool agc_enabled; |
| 2974 | webrtc::AgcModes agc_mode; |
| 2975 | bool ns_enabled; |
| 2976 | webrtc::NsModes ns_mode; |
| 2977 | voe_.GetEcStatus(ec_enabled, ec_mode); |
| 2978 | voe_.GetAgcStatus(agc_enabled, agc_mode); |
| 2979 | voe_.GetNsStatus(ns_enabled, ns_mode); |
| 2980 | EXPECT_TRUE(ec_enabled); |
| 2981 | EXPECT_TRUE(agc_enabled); |
| 2982 | EXPECT_TRUE(ns_enabled); |
| 2983 | |
| 2984 | channel1->SetSend(cricket::SEND_MICROPHONE); |
| 2985 | voe_.GetEcStatus(ec_enabled, ec_mode); |
| 2986 | voe_.GetAgcStatus(agc_enabled, agc_mode); |
| 2987 | voe_.GetNsStatus(ns_enabled, ns_mode); |
| 2988 | EXPECT_TRUE(ec_enabled); |
| 2989 | EXPECT_TRUE(agc_enabled); |
| 2990 | EXPECT_FALSE(ns_enabled); |
| 2991 | |
| 2992 | channel1->SetSend(cricket::SEND_NOTHING); |
| 2993 | voe_.GetEcStatus(ec_enabled, ec_mode); |
| 2994 | voe_.GetAgcStatus(agc_enabled, agc_mode); |
| 2995 | voe_.GetNsStatus(ns_enabled, ns_mode); |
| 2996 | EXPECT_TRUE(ec_enabled); |
| 2997 | EXPECT_TRUE(agc_enabled); |
| 2998 | EXPECT_TRUE(ns_enabled); |
| 2999 | |
| 3000 | channel2->SetSend(cricket::SEND_MICROPHONE); |
| 3001 | voe_.GetEcStatus(ec_enabled, ec_mode); |
| 3002 | voe_.GetAgcStatus(agc_enabled, agc_mode); |
| 3003 | voe_.GetNsStatus(ns_enabled, ns_mode); |
| 3004 | EXPECT_TRUE(ec_enabled); |
| 3005 | EXPECT_FALSE(agc_enabled); |
| 3006 | EXPECT_TRUE(ns_enabled); |
| 3007 | |
| 3008 | channel2->SetSend(cricket::SEND_NOTHING); |
| 3009 | voe_.GetEcStatus(ec_enabled, ec_mode); |
| 3010 | voe_.GetAgcStatus(agc_enabled, agc_mode); |
| 3011 | voe_.GetNsStatus(ns_enabled, ns_mode); |
| 3012 | EXPECT_TRUE(ec_enabled); |
| 3013 | EXPECT_TRUE(agc_enabled); |
| 3014 | EXPECT_TRUE(ns_enabled); |
| 3015 | |
| 3016 | // Make sure settings take effect while we are sending. |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 3017 | ASSERT_TRUE(engine_.SetOptions(options_all)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3018 | cricket::AudioOptions options_no_agc_nor_ns; |
| 3019 | options_no_agc_nor_ns.auto_gain_control.Set(false); |
| 3020 | options_no_agc_nor_ns.noise_suppression.Set(false); |
| 3021 | channel2->SetSend(cricket::SEND_MICROPHONE); |
| 3022 | channel2->SetOptions(options_no_agc_nor_ns); |
| 3023 | |
| 3024 | expected_options.echo_cancellation.Set(true); |
| 3025 | expected_options.auto_gain_control.Set(false); |
| 3026 | expected_options.noise_suppression.Set(false); |
| 3027 | ASSERT_TRUE(channel2->GetOptions(&actual_options)); |
| 3028 | EXPECT_EQ(expected_options, actual_options); |
| 3029 | voe_.GetEcStatus(ec_enabled, ec_mode); |
| 3030 | voe_.GetAgcStatus(agc_enabled, agc_mode); |
| 3031 | voe_.GetNsStatus(ns_enabled, ns_mode); |
| 3032 | EXPECT_TRUE(ec_enabled); |
| 3033 | EXPECT_FALSE(agc_enabled); |
| 3034 | EXPECT_FALSE(ns_enabled); |
| 3035 | } |
| 3036 | |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 3037 | // This test verifies DSCP settings are properly applied on voice media channel. |
| 3038 | TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) { |
| 3039 | EXPECT_TRUE(SetupEngine()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3040 | rtc::scoped_ptr<cricket::VoiceMediaChannel> channel( |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 3041 | engine_.CreateChannel()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3042 | rtc::scoped_ptr<cricket::FakeNetworkInterface> network_interface( |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 3043 | new cricket::FakeNetworkInterface); |
| 3044 | channel->SetInterface(network_interface.get()); |
| 3045 | cricket::AudioOptions options; |
| 3046 | options.dscp.Set(true); |
| 3047 | EXPECT_TRUE(channel->SetOptions(options)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3048 | EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp()); |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 3049 | // Verify previous value is not modified if dscp option is not set. |
| 3050 | cricket::AudioOptions options1; |
| 3051 | EXPECT_TRUE(channel->SetOptions(options1)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3052 | EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp()); |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 3053 | options.dscp.Set(false); |
| 3054 | EXPECT_TRUE(channel->SetOptions(options)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3055 | EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp()); |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
wu@webrtc.org | 1d1ffc9 | 2013-10-16 18:12:02 +0000 | [diff] [blame] | 3058 | TEST(WebRtcVoiceEngineTest, TestDefaultOptionsBeforeInit) { |
| 3059 | cricket::WebRtcVoiceEngine engine; |
| 3060 | cricket::AudioOptions options = engine.GetOptions(); |
| 3061 | // The default options should have at least a few things set. We purposefully |
| 3062 | // don't check the option values here, though. |
| 3063 | EXPECT_TRUE(options.echo_cancellation.IsSet()); |
| 3064 | EXPECT_TRUE(options.auto_gain_control.IsSet()); |
| 3065 | EXPECT_TRUE(options.noise_suppression.IsSet()); |
| 3066 | } |
| 3067 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3068 | // Test that GetReceiveChannelNum returns the default channel for the first |
| 3069 | // recv stream in 1-1 calls. |
| 3070 | TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelNumIn1To1Calls) { |
| 3071 | EXPECT_TRUE(SetupEngine()); |
| 3072 | cricket::WebRtcVoiceMediaChannel* media_channel = |
| 3073 | static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); |
| 3074 | // Test that GetChannelNum returns the default channel if the SSRC is unknown. |
| 3075 | EXPECT_EQ(media_channel->voe_channel(), |
| 3076 | media_channel->GetReceiveChannelNum(0)); |
| 3077 | cricket::StreamParams stream; |
| 3078 | stream.ssrcs.push_back(kSsrc2); |
| 3079 | EXPECT_TRUE(channel_->AddRecvStream(stream)); |
| 3080 | EXPECT_EQ(media_channel->voe_channel(), |
| 3081 | media_channel->GetReceiveChannelNum(kSsrc2)); |
| 3082 | } |
| 3083 | |
| 3084 | // Test that GetReceiveChannelNum doesn't return the default channel for the |
| 3085 | // first recv stream in conference calls. |
| 3086 | TEST_F(WebRtcVoiceEngineTestFake, TestGetChannelNumInConferenceCalls) { |
| 3087 | EXPECT_TRUE(SetupEngine()); |
| 3088 | EXPECT_TRUE(channel_->SetOptions(options_conference_)); |
| 3089 | cricket::StreamParams stream; |
| 3090 | stream.ssrcs.push_back(kSsrc2); |
| 3091 | EXPECT_TRUE(channel_->AddRecvStream(stream)); |
| 3092 | cricket::WebRtcVoiceMediaChannel* media_channel = |
| 3093 | static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); |
| 3094 | EXPECT_LT(media_channel->voe_channel(), |
| 3095 | media_channel->GetReceiveChannelNum(kSsrc2)); |
| 3096 | } |
| 3097 | |
| 3098 | TEST_F(WebRtcVoiceEngineTestFake, SetOutputScaling) { |
| 3099 | EXPECT_TRUE(SetupEngine()); |
| 3100 | double left, right; |
| 3101 | EXPECT_TRUE(channel_->SetOutputScaling(0, 1, 2)); |
| 3102 | EXPECT_TRUE(channel_->GetOutputScaling(0, &left, &right)); |
| 3103 | EXPECT_DOUBLE_EQ(1, left); |
| 3104 | EXPECT_DOUBLE_EQ(2, right); |
| 3105 | |
| 3106 | EXPECT_FALSE(channel_->SetOutputScaling(kSsrc2, 1, 2)); |
| 3107 | cricket::StreamParams stream; |
| 3108 | stream.ssrcs.push_back(kSsrc2); |
| 3109 | EXPECT_TRUE(channel_->AddRecvStream(stream)); |
| 3110 | |
| 3111 | EXPECT_TRUE(channel_->SetOutputScaling(kSsrc2, 2, 1)); |
| 3112 | EXPECT_TRUE(channel_->GetOutputScaling(kSsrc2, &left, &right)); |
| 3113 | EXPECT_DOUBLE_EQ(2, left); |
| 3114 | EXPECT_DOUBLE_EQ(1, right); |
| 3115 | } |
| 3116 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3117 | // Tests for the actual WebRtc VoE library. |
| 3118 | |
| 3119 | // Tests that the library initializes and shuts down properly. |
| 3120 | TEST(WebRtcVoiceEngineTest, StartupShutdown) { |
| 3121 | cricket::WebRtcVoiceEngine engine; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3122 | EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3123 | cricket::VoiceMediaChannel* channel = engine.CreateChannel(); |
| 3124 | EXPECT_TRUE(channel != NULL); |
| 3125 | delete channel; |
| 3126 | engine.Terminate(); |
| 3127 | |
| 3128 | // Reinit to catch regression where VoiceEngineObserver reference is lost |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3129 | EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3130 | engine.Terminate(); |
| 3131 | } |
| 3132 | |
| 3133 | // Tests that the logging from the library is cleartext. |
| 3134 | TEST(WebRtcVoiceEngineTest, DISABLED_HasUnencryptedLogging) { |
| 3135 | cricket::WebRtcVoiceEngine engine; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3136 | rtc::scoped_ptr<rtc::MemoryStream> stream( |
| 3137 | new rtc::MemoryStream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3138 | size_t size = 0; |
| 3139 | bool cleartext = true; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3140 | rtc::LogMessage::AddLogToStream(stream.get(), rtc::LS_VERBOSE); |
| 3141 | engine.SetLogging(rtc::LS_VERBOSE, ""); |
| 3142 | EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3143 | EXPECT_TRUE(stream->GetSize(&size)); |
| 3144 | EXPECT_GT(size, 0U); |
| 3145 | engine.Terminate(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3146 | rtc::LogMessage::RemoveLogToStream(stream.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3147 | const char* buf = stream->GetBuffer(); |
| 3148 | for (size_t i = 0; i < size && cleartext; ++i) { |
| 3149 | int ch = static_cast<int>(buf[i]); |
| 3150 | ASSERT_GE(ch, 0) << "Out of bounds character in WebRtc VoE log: " |
| 3151 | << std::hex << ch; |
| 3152 | cleartext = (isprint(ch) || isspace(ch)); |
| 3153 | } |
| 3154 | EXPECT_TRUE(cleartext); |
| 3155 | } |
| 3156 | |
| 3157 | // Tests we do not see any references to a monitor thread being spun up |
| 3158 | // when initiating the engine. |
| 3159 | TEST(WebRtcVoiceEngineTest, HasNoMonitorThread) { |
| 3160 | cricket::WebRtcVoiceEngine engine; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3161 | rtc::scoped_ptr<rtc::MemoryStream> stream( |
| 3162 | new rtc::MemoryStream); |
| 3163 | rtc::LogMessage::AddLogToStream(stream.get(), rtc::LS_VERBOSE); |
| 3164 | engine.SetLogging(rtc::LS_VERBOSE, ""); |
| 3165 | EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3166 | engine.Terminate(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3167 | rtc::LogMessage::RemoveLogToStream(stream.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3168 | |
| 3169 | size_t size = 0; |
| 3170 | EXPECT_TRUE(stream->GetSize(&size)); |
| 3171 | EXPECT_GT(size, 0U); |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 3172 | const std::string logs(stream->GetBuffer(), size); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3173 | EXPECT_NE(std::string::npos, logs.find("ProcessThread")); |
| 3174 | } |
| 3175 | |
| 3176 | // Tests that the library is configured with the codecs we want. |
| 3177 | TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { |
| 3178 | cricket::WebRtcVoiceEngine engine; |
| 3179 | // Check codecs by name. |
| 3180 | EXPECT_TRUE(engine.FindCodec( |
| 3181 | cricket::AudioCodec(96, "OPUS", 48000, 0, 2, 0))); |
| 3182 | EXPECT_TRUE(engine.FindCodec( |
| 3183 | cricket::AudioCodec(96, "ISAC", 16000, 0, 1, 0))); |
| 3184 | EXPECT_TRUE(engine.FindCodec( |
| 3185 | cricket::AudioCodec(96, "ISAC", 32000, 0, 1, 0))); |
| 3186 | // Check that name matching is case-insensitive. |
| 3187 | EXPECT_TRUE(engine.FindCodec( |
| 3188 | cricket::AudioCodec(96, "ILBC", 8000, 0, 1, 0))); |
| 3189 | EXPECT_TRUE(engine.FindCodec( |
| 3190 | cricket::AudioCodec(96, "iLBC", 8000, 0, 1, 0))); |
| 3191 | EXPECT_TRUE(engine.FindCodec( |
| 3192 | cricket::AudioCodec(96, "PCMU", 8000, 0, 1, 0))); |
| 3193 | EXPECT_TRUE(engine.FindCodec( |
| 3194 | cricket::AudioCodec(96, "PCMA", 8000, 0, 1, 0))); |
| 3195 | EXPECT_TRUE(engine.FindCodec( |
| 3196 | cricket::AudioCodec(96, "G722", 16000, 0, 1, 0))); |
| 3197 | EXPECT_TRUE(engine.FindCodec( |
| 3198 | cricket::AudioCodec(96, "red", 8000, 0, 1, 0))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3199 | EXPECT_TRUE(engine.FindCodec( |
| 3200 | cricket::AudioCodec(96, "CN", 32000, 0, 1, 0))); |
| 3201 | EXPECT_TRUE(engine.FindCodec( |
| 3202 | cricket::AudioCodec(96, "CN", 16000, 0, 1, 0))); |
| 3203 | EXPECT_TRUE(engine.FindCodec( |
| 3204 | cricket::AudioCodec(96, "CN", 8000, 0, 1, 0))); |
| 3205 | EXPECT_TRUE(engine.FindCodec( |
| 3206 | cricket::AudioCodec(96, "telephone-event", 8000, 0, 1, 0))); |
| 3207 | // Check codecs with an id by id. |
| 3208 | EXPECT_TRUE(engine.FindCodec( |
| 3209 | cricket::AudioCodec(0, "", 8000, 0, 1, 0))); // PCMU |
| 3210 | EXPECT_TRUE(engine.FindCodec( |
| 3211 | cricket::AudioCodec(8, "", 8000, 0, 1, 0))); // PCMA |
| 3212 | EXPECT_TRUE(engine.FindCodec( |
| 3213 | cricket::AudioCodec(9, "", 16000, 0, 1, 0))); // G722 |
| 3214 | EXPECT_TRUE(engine.FindCodec( |
| 3215 | cricket::AudioCodec(13, "", 8000, 0, 1, 0))); // CN |
| 3216 | // Check sample/bitrate matching. |
| 3217 | EXPECT_TRUE(engine.FindCodec( |
| 3218 | cricket::AudioCodec(0, "PCMU", 8000, 64000, 1, 0))); |
| 3219 | // Check that bad codecs fail. |
| 3220 | EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(99, "ABCD", 0, 0, 1, 0))); |
| 3221 | EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(88, "", 0, 0, 1, 0))); |
| 3222 | EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 0, 2, 0))); |
| 3223 | EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 5000, 0, 1, 0))); |
| 3224 | EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 5000, 1, 0))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3225 | // Verify the payload id of common audio codecs, including CN, ISAC, and G722. |
| 3226 | for (std::vector<cricket::AudioCodec>::const_iterator it = |
| 3227 | engine.codecs().begin(); it != engine.codecs().end(); ++it) { |
| 3228 | if (it->name == "CN" && it->clockrate == 16000) { |
| 3229 | EXPECT_EQ(105, it->id); |
| 3230 | } else if (it->name == "CN" && it->clockrate == 32000) { |
| 3231 | EXPECT_EQ(106, it->id); |
| 3232 | } else if (it->name == "ISAC" && it->clockrate == 16000) { |
| 3233 | EXPECT_EQ(103, it->id); |
| 3234 | } else if (it->name == "ISAC" && it->clockrate == 32000) { |
| 3235 | EXPECT_EQ(104, it->id); |
| 3236 | } else if (it->name == "G722" && it->clockrate == 16000) { |
| 3237 | EXPECT_EQ(9, it->id); |
| 3238 | } else if (it->name == "telephone-event") { |
| 3239 | EXPECT_EQ(126, it->id); |
| 3240 | } else if (it->name == "red") { |
| 3241 | EXPECT_EQ(127, it->id); |
| 3242 | } else if (it->name == "opus") { |
| 3243 | EXPECT_EQ(111, it->id); |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 3244 | ASSERT_TRUE(it->params.find("minptime") != it->params.end()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3245 | EXPECT_EQ("10", it->params.find("minptime")->second); |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 3246 | ASSERT_TRUE(it->params.find("maxptime") != it->params.end()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3247 | EXPECT_EQ("60", it->params.find("maxptime")->second); |
| 3248 | } |
| 3249 | } |
| 3250 | |
| 3251 | engine.Terminate(); |
| 3252 | } |
| 3253 | |
| 3254 | // Tests that VoE supports at least 32 channels |
| 3255 | TEST(WebRtcVoiceEngineTest, Has32Channels) { |
| 3256 | cricket::WebRtcVoiceEngine engine; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3257 | EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3258 | |
| 3259 | cricket::VoiceMediaChannel* channels[32]; |
| 3260 | int num_channels = 0; |
| 3261 | |
| 3262 | while (num_channels < ARRAY_SIZE(channels)) { |
| 3263 | cricket::VoiceMediaChannel* channel = engine.CreateChannel(); |
| 3264 | if (!channel) |
| 3265 | break; |
| 3266 | |
| 3267 | channels[num_channels++] = channel; |
| 3268 | } |
| 3269 | |
| 3270 | int expected = ARRAY_SIZE(channels); |
| 3271 | EXPECT_EQ(expected, num_channels); |
| 3272 | |
| 3273 | while (num_channels > 0) { |
| 3274 | delete channels[--num_channels]; |
| 3275 | } |
| 3276 | |
| 3277 | engine.Terminate(); |
| 3278 | } |
| 3279 | |
| 3280 | // Test that we set our preferred codecs properly. |
| 3281 | TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { |
| 3282 | cricket::WebRtcVoiceEngine engine; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3283 | EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3284 | cricket::WebRtcVoiceMediaChannel channel(&engine); |
| 3285 | EXPECT_TRUE(channel.SetRecvCodecs(engine.codecs())); |
| 3286 | } |
| 3287 | |
| 3288 | #ifdef WIN32 |
| 3289 | // Test our workarounds to WebRtc VoE' munging of the coinit count |
| 3290 | TEST(WebRtcVoiceEngineTest, CoInitialize) { |
| 3291 | cricket::WebRtcVoiceEngine* engine = new cricket::WebRtcVoiceEngine(); |
| 3292 | |
| 3293 | // Initial refcount should be 0. |
| 3294 | EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED)); |
| 3295 | |
| 3296 | // Engine should start even with COM already inited. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3297 | EXPECT_TRUE(engine->Init(rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3298 | engine->Terminate(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3299 | EXPECT_TRUE(engine->Init(rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3300 | engine->Terminate(); |
| 3301 | |
| 3302 | // Refcount after terminate should be 1 (in reality 3); test if it is nonzero. |
| 3303 | EXPECT_EQ(S_FALSE, CoInitializeEx(NULL, COINIT_MULTITHREADED)); |
| 3304 | // Decrement refcount to (hopefully) 0. |
| 3305 | CoUninitialize(); |
| 3306 | CoUninitialize(); |
| 3307 | delete engine; |
| 3308 | |
| 3309 | // Ensure refcount is 0. |
| 3310 | EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED)); |
| 3311 | CoUninitialize(); |
| 3312 | } |
| 3313 | #endif |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 3314 | |
| 3315 | TEST_F(WebRtcVoiceEngineTestFake, ChangeCombinedAudioVideoBweOption) { |
| 3316 | // Test that changing the combined_audio_video_bwe option results in the |
| 3317 | // expected state changes in VoiceEngine. |
| 3318 | cricket::ViEWrapper vie; |
| 3319 | const int kVieCh = 667; |
| 3320 | |
| 3321 | EXPECT_TRUE(SetupEngine()); |
| 3322 | cricket::WebRtcVoiceMediaChannel* media_channel = |
| 3323 | static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); |
| 3324 | EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie.engine(), |
| 3325 | kVieCh)); |
| 3326 | EXPECT_TRUE(media_channel->AddRecvStream( |
| 3327 | cricket::StreamParams::CreateLegacy(2))); |
| 3328 | int recv_ch = voe_.GetLastChannel(); |
| 3329 | |
| 3330 | // Combined BWE should not be set up yet. |
| 3331 | EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch)); |
| 3332 | EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch)); |
| 3333 | |
| 3334 | // Enable combined BWE option - now it should be set up. |
| 3335 | cricket::AudioOptions options; |
| 3336 | options.combined_audio_video_bwe.Set(true); |
| 3337 | EXPECT_TRUE(media_channel->SetOptions(options)); |
| 3338 | EXPECT_EQ(vie.network(), voe_.GetViENetwork(recv_ch)); |
| 3339 | EXPECT_EQ(kVieCh, voe_.GetVideoChannel(recv_ch)); |
| 3340 | |
| 3341 | // Disable combined BWE option - should be disabled again. |
| 3342 | options.combined_audio_video_bwe.Set(false); |
| 3343 | EXPECT_TRUE(media_channel->SetOptions(options)); |
| 3344 | EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch)); |
| 3345 | EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch)); |
| 3346 | |
| 3347 | EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1)); |
| 3348 | } |
| 3349 | |
| 3350 | TEST_F(WebRtcVoiceEngineTestFake, SetupSharedBandwidthEstimation) { |
| 3351 | // Test that calling SetupSharedBandwidthEstimation() on the voice media |
| 3352 | // channel results in the expected state changes in VoiceEngine. |
| 3353 | cricket::ViEWrapper vie1; |
| 3354 | cricket::ViEWrapper vie2; |
| 3355 | const int kVieCh1 = 667; |
| 3356 | const int kVieCh2 = 70; |
| 3357 | |
| 3358 | EXPECT_TRUE(SetupEngine()); |
| 3359 | cricket::WebRtcVoiceMediaChannel* media_channel = |
| 3360 | static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); |
| 3361 | cricket::AudioOptions options; |
| 3362 | options.combined_audio_video_bwe.Set(true); |
| 3363 | EXPECT_TRUE(media_channel->SetOptions(options)); |
| 3364 | EXPECT_TRUE(media_channel->AddRecvStream( |
| 3365 | cricket::StreamParams::CreateLegacy(2))); |
| 3366 | int recv_ch = voe_.GetLastChannel(); |
| 3367 | |
| 3368 | // Combined BWE should not be set up yet. |
| 3369 | EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch)); |
| 3370 | EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch)); |
| 3371 | |
| 3372 | // Register - should be enabled. |
| 3373 | EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie1.engine(), |
| 3374 | kVieCh1)); |
| 3375 | EXPECT_EQ(vie1.network(), voe_.GetViENetwork(recv_ch)); |
| 3376 | EXPECT_EQ(kVieCh1, voe_.GetVideoChannel(recv_ch)); |
| 3377 | |
| 3378 | // Re-register - should still be enabled. |
| 3379 | EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie2.engine(), |
| 3380 | kVieCh2)); |
| 3381 | EXPECT_EQ(vie2.network(), voe_.GetViENetwork(recv_ch)); |
| 3382 | EXPECT_EQ(kVieCh2, voe_.GetVideoChannel(recv_ch)); |
| 3383 | |
| 3384 | // Unregister - should be disabled again. |
| 3385 | EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1)); |
| 3386 | EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch)); |
| 3387 | EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch)); |
| 3388 | } |
| 3389 | |
| 3390 | TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBweForNewRecvStreams) { |
| 3391 | // Test that adding receive streams after enabling combined bandwidth |
| 3392 | // estimation will correctly configure each channel. |
| 3393 | cricket::ViEWrapper vie; |
| 3394 | const int kVieCh = 667; |
| 3395 | |
| 3396 | EXPECT_TRUE(SetupEngine()); |
| 3397 | cricket::WebRtcVoiceMediaChannel* media_channel = |
| 3398 | static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); |
| 3399 | EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie.engine(), |
| 3400 | kVieCh)); |
| 3401 | cricket::AudioOptions options; |
| 3402 | options.combined_audio_video_bwe.Set(true); |
| 3403 | EXPECT_TRUE(media_channel->SetOptions(options)); |
| 3404 | |
| 3405 | static const uint32 kSsrcs[] = {1, 2, 3, 4}; |
| 3406 | int voe_channels[ARRAY_SIZE(kSsrcs)] = {0}; |
| 3407 | for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs); ++i) { |
| 3408 | EXPECT_TRUE(media_channel->AddRecvStream( |
| 3409 | cricket::StreamParams::CreateLegacy(kSsrcs[i]))); |
| 3410 | int recv_ch = media_channel->GetReceiveChannelNum(kSsrcs[i]); |
| 3411 | EXPECT_NE(-1, recv_ch); |
| 3412 | voe_channels[i] = recv_ch; |
| 3413 | EXPECT_EQ(vie.network(), voe_.GetViENetwork(recv_ch)); |
| 3414 | EXPECT_EQ(kVieCh, voe_.GetVideoChannel(recv_ch)); |
| 3415 | } |
| 3416 | |
| 3417 | EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1)); |
| 3418 | |
| 3419 | for (unsigned int i = 0; i < ARRAY_SIZE(voe_channels); ++i) { |
| 3420 | EXPECT_EQ(NULL, voe_.GetViENetwork(voe_channels[i])); |
| 3421 | EXPECT_EQ(-1, voe_.GetVideoChannel(voe_channels[i])); |
| 3422 | } |
| 3423 | } |