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