2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "webrtc/modules/audio_coding/main/acm2/acm_opus.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h"
21 const CodecInst kOpusCodecInst = {105, "opus", 48000, 960, 1, 32000};
22 // These constants correspond to those used in ACMOpus::SetPacketLossRate().
23 const int kPacketLossRate20 = 20;
24 const int kPacketLossRate10 = 10;
25 const int kPacketLossRate5 = 5;
26 const int kPacketLossRate1 = 1;
27 const int kLossRate20Margin = 2;
28 const int kLossRate10Margin = 1;
29 const int kLossRate5Margin = 1;
32 class AcmOpusTest : public ACMOpus {
34 explicit AcmOpusTest(int16_t codec_id)
35 : ACMOpus(codec_id) {}
37 int packet_loss_rate() { return packet_loss_rate_; }
39 void TestSetPacketLossRate(int from, int to, int expected_return);
42 #ifdef WEBRTC_CODEC_OPUS
43 void AcmOpusTest::TestSetPacketLossRate(int from, int to, int expected_return) {
44 for (int loss = from; loss <= to; (to >= from) ? ++loss : --loss) {
45 EXPECT_EQ(0, SetPacketLossRate(loss));
46 EXPECT_EQ(expected_return, packet_loss_rate());
50 TEST(AcmOpusTest, PacketLossRateOptimized) {
51 AcmOpusTest opus(ACMCodecDB::kOpus);
52 WebRtcACMCodecParams params;
53 memcpy(&(params.codec_inst), &kOpusCodecInst, sizeof(CodecInst));
54 EXPECT_EQ(0, opus.InitEncoder(¶ms, true));
55 EXPECT_EQ(0, opus.SetFEC(true));
57 // Note that the order of the following calls is critical.
58 opus.TestSetPacketLossRate(0, 0, 0);
59 opus.TestSetPacketLossRate(kPacketLossRate1,
60 kPacketLossRate5 + kLossRate5Margin - 1,
62 opus.TestSetPacketLossRate(kPacketLossRate5 + kLossRate5Margin,
63 kPacketLossRate10 + kLossRate10Margin - 1,
65 opus.TestSetPacketLossRate(kPacketLossRate10 + kLossRate10Margin,
66 kPacketLossRate20 + kLossRate20Margin - 1,
68 opus.TestSetPacketLossRate(kPacketLossRate20 + kLossRate20Margin,
71 opus.TestSetPacketLossRate(kPacketLossRate20 + kLossRate20Margin,
72 kPacketLossRate20 - kLossRate20Margin,
74 opus.TestSetPacketLossRate(kPacketLossRate20 - kLossRate20Margin - 1,
75 kPacketLossRate10 - kLossRate10Margin,
77 opus.TestSetPacketLossRate(kPacketLossRate10 - kLossRate10Margin - 1,
78 kPacketLossRate5 - kLossRate5Margin,
80 opus.TestSetPacketLossRate(kPacketLossRate5 - kLossRate5Margin - 1,
83 opus.TestSetPacketLossRate(0, 0, 0);
86 void AcmOpusTest:TestSetPacketLossRate(int /* from */, int /* to */,
87 int /* expected_return */) {
90 #endif // WEBRTC_CODEC_OPUS