Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Side by Side Diff: webrtc/modules/audio_coding/neteq/decoder_database_unittest.cc

Issue 1424083002: Make an enum class out of NetEqDecoder, and hide the neteq_decoders_ table (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 15 matching lines...) Expand all
26 TEST(DecoderDatabase, CreateAndDestroy) { 26 TEST(DecoderDatabase, CreateAndDestroy) {
27 DecoderDatabase db; 27 DecoderDatabase db;
28 EXPECT_EQ(0, db.Size()); 28 EXPECT_EQ(0, db.Size());
29 EXPECT_TRUE(db.Empty()); 29 EXPECT_TRUE(db.Empty());
30 } 30 }
31 31
32 TEST(DecoderDatabase, InsertAndRemove) { 32 TEST(DecoderDatabase, InsertAndRemove) {
33 DecoderDatabase db; 33 DecoderDatabase db;
34 const uint8_t kPayloadType = 0; 34 const uint8_t kPayloadType = 0;
35 EXPECT_EQ(DecoderDatabase::kOK, 35 EXPECT_EQ(DecoderDatabase::kOK,
36 db.RegisterPayload(kPayloadType, kDecoderPCMu)); 36 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu));
37 EXPECT_EQ(1, db.Size()); 37 EXPECT_EQ(1, db.Size());
38 EXPECT_FALSE(db.Empty()); 38 EXPECT_FALSE(db.Empty());
39 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType)); 39 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType));
40 EXPECT_EQ(0, db.Size()); 40 EXPECT_EQ(0, db.Size());
41 EXPECT_TRUE(db.Empty()); 41 EXPECT_TRUE(db.Empty());
42 } 42 }
43 43
44 TEST(DecoderDatabase, GetDecoderInfo) { 44 TEST(DecoderDatabase, GetDecoderInfo) {
45 DecoderDatabase db; 45 DecoderDatabase db;
46 const uint8_t kPayloadType = 0; 46 const uint8_t kPayloadType = 0;
47 EXPECT_EQ(DecoderDatabase::kOK, 47 EXPECT_EQ(DecoderDatabase::kOK,
48 db.RegisterPayload(kPayloadType, kDecoderPCMu)); 48 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu));
49 const DecoderDatabase::DecoderInfo* info; 49 const DecoderDatabase::DecoderInfo* info;
50 info = db.GetDecoderInfo(kPayloadType); 50 info = db.GetDecoderInfo(kPayloadType);
51 ASSERT_TRUE(info != NULL); 51 ASSERT_TRUE(info != NULL);
52 EXPECT_EQ(kDecoderPCMu, info->codec_type); 52 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type);
53 EXPECT_EQ(NULL, info->decoder); 53 EXPECT_EQ(NULL, info->decoder);
54 EXPECT_EQ(8000, info->fs_hz); 54 EXPECT_EQ(8000, info->fs_hz);
55 EXPECT_FALSE(info->external); 55 EXPECT_FALSE(info->external);
56 info = db.GetDecoderInfo(kPayloadType + 1); // Other payload type. 56 info = db.GetDecoderInfo(kPayloadType + 1); // Other payload type.
57 EXPECT_TRUE(info == NULL); // Should not be found. 57 EXPECT_TRUE(info == NULL); // Should not be found.
58 } 58 }
59 59
60 TEST(DecoderDatabase, GetRtpPayloadType) { 60 TEST(DecoderDatabase, GetRtpPayloadType) {
61 DecoderDatabase db; 61 DecoderDatabase db;
62 const uint8_t kPayloadType = 0; 62 const uint8_t kPayloadType = 0;
63 EXPECT_EQ(DecoderDatabase::kOK, 63 EXPECT_EQ(DecoderDatabase::kOK,
64 db.RegisterPayload(kPayloadType, kDecoderPCMu)); 64 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu));
65 EXPECT_EQ(kPayloadType, db.GetRtpPayloadType(kDecoderPCMu)); 65 EXPECT_EQ(kPayloadType, db.GetRtpPayloadType(NetEqDecoder::kDecoderPCMu));
66 const uint8_t expected_value = DecoderDatabase::kRtpPayloadTypeError; 66 const uint8_t expected_value = DecoderDatabase::kRtpPayloadTypeError;
67 EXPECT_EQ(expected_value, 67 EXPECT_EQ(expected_value,
68 db.GetRtpPayloadType(kDecoderISAC)); // iSAC is not registered. 68 db.GetRtpPayloadType(
69 NetEqDecoder::kDecoderISAC)); // iSAC is not registered.
69 } 70 }
70 71
71 TEST(DecoderDatabase, GetDecoder) { 72 TEST(DecoderDatabase, GetDecoder) {
72 DecoderDatabase db; 73 DecoderDatabase db;
73 const uint8_t kPayloadType = 0; 74 const uint8_t kPayloadType = 0;
74 EXPECT_EQ(DecoderDatabase::kOK, 75 EXPECT_EQ(DecoderDatabase::kOK,
75 db.RegisterPayload(kPayloadType, kDecoderPCM16B)); 76 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCM16B));
76 AudioDecoder* dec = db.GetDecoder(kPayloadType); 77 AudioDecoder* dec = db.GetDecoder(kPayloadType);
77 ASSERT_TRUE(dec != NULL); 78 ASSERT_TRUE(dec != NULL);
78 } 79 }
79 80
80 TEST(DecoderDatabase, TypeTests) { 81 TEST(DecoderDatabase, TypeTests) {
81 DecoderDatabase db; 82 DecoderDatabase db;
82 const uint8_t kPayloadTypePcmU = 0; 83 const uint8_t kPayloadTypePcmU = 0;
83 const uint8_t kPayloadTypeCng = 13; 84 const uint8_t kPayloadTypeCng = 13;
84 const uint8_t kPayloadTypeDtmf = 100; 85 const uint8_t kPayloadTypeDtmf = 100;
85 const uint8_t kPayloadTypeRed = 101; 86 const uint8_t kPayloadTypeRed = 101;
86 const uint8_t kPayloadNotUsed = 102; 87 const uint8_t kPayloadNotUsed = 102;
87 // Load into database. 88 // Load into database.
88 EXPECT_EQ(DecoderDatabase::kOK, 89 EXPECT_EQ(DecoderDatabase::kOK,
89 db.RegisterPayload(kPayloadTypePcmU, kDecoderPCMu)); 90 db.RegisterPayload(kPayloadTypePcmU, NetEqDecoder::kDecoderPCMu));
90 EXPECT_EQ(DecoderDatabase::kOK, 91 EXPECT_EQ(DecoderDatabase::kOK,
91 db.RegisterPayload(kPayloadTypeCng, kDecoderCNGnb)); 92 db.RegisterPayload(kPayloadTypeCng, NetEqDecoder::kDecoderCNGnb));
92 EXPECT_EQ(DecoderDatabase::kOK, 93 EXPECT_EQ(DecoderDatabase::kOK,
93 db.RegisterPayload(kPayloadTypeDtmf, kDecoderAVT)); 94 db.RegisterPayload(kPayloadTypeDtmf, NetEqDecoder::kDecoderAVT));
94 EXPECT_EQ(DecoderDatabase::kOK, 95 EXPECT_EQ(DecoderDatabase::kOK,
95 db.RegisterPayload(kPayloadTypeRed, kDecoderRED)); 96 db.RegisterPayload(kPayloadTypeRed, NetEqDecoder::kDecoderRED));
96 EXPECT_EQ(4, db.Size()); 97 EXPECT_EQ(4, db.Size());
97 // Test. 98 // Test.
98 EXPECT_FALSE(db.IsComfortNoise(kPayloadNotUsed)); 99 EXPECT_FALSE(db.IsComfortNoise(kPayloadNotUsed));
99 EXPECT_FALSE(db.IsDtmf(kPayloadNotUsed)); 100 EXPECT_FALSE(db.IsDtmf(kPayloadNotUsed));
100 EXPECT_FALSE(db.IsRed(kPayloadNotUsed)); 101 EXPECT_FALSE(db.IsRed(kPayloadNotUsed));
101 EXPECT_FALSE(db.IsComfortNoise(kPayloadTypePcmU)); 102 EXPECT_FALSE(db.IsComfortNoise(kPayloadTypePcmU));
102 EXPECT_FALSE(db.IsDtmf(kPayloadTypePcmU)); 103 EXPECT_FALSE(db.IsDtmf(kPayloadTypePcmU));
103 EXPECT_FALSE(db.IsRed(kPayloadTypePcmU)); 104 EXPECT_FALSE(db.IsRed(kPayloadTypePcmU));
104 EXPECT_FALSE(db.IsType(kPayloadTypePcmU, kDecoderISAC)); 105 EXPECT_FALSE(db.IsType(kPayloadTypePcmU, NetEqDecoder::kDecoderISAC));
105 EXPECT_TRUE(db.IsType(kPayloadTypePcmU, kDecoderPCMu)); 106 EXPECT_TRUE(db.IsType(kPayloadTypePcmU, NetEqDecoder::kDecoderPCMu));
106 EXPECT_TRUE(db.IsComfortNoise(kPayloadTypeCng)); 107 EXPECT_TRUE(db.IsComfortNoise(kPayloadTypeCng));
107 EXPECT_TRUE(db.IsDtmf(kPayloadTypeDtmf)); 108 EXPECT_TRUE(db.IsDtmf(kPayloadTypeDtmf));
108 EXPECT_TRUE(db.IsRed(kPayloadTypeRed)); 109 EXPECT_TRUE(db.IsRed(kPayloadTypeRed));
109 } 110 }
110 111
111 TEST(DecoderDatabase, ExternalDecoder) { 112 TEST(DecoderDatabase, ExternalDecoder) {
112 DecoderDatabase db; 113 DecoderDatabase db;
113 const uint8_t kPayloadType = 0; 114 const uint8_t kPayloadType = 0;
114 MockAudioDecoder decoder; 115 MockAudioDecoder decoder;
115 // Load into database. 116 // Load into database.
116 EXPECT_EQ(DecoderDatabase::kOK, 117 EXPECT_EQ(DecoderDatabase::kOK,
117 db.InsertExternal(kPayloadType, kDecoderPCMu, 8000, 118 db.InsertExternal(kPayloadType, NetEqDecoder::kDecoderPCMu, 8000,
118 &decoder)); 119 &decoder));
119 EXPECT_EQ(1, db.Size()); 120 EXPECT_EQ(1, db.Size());
120 // Get decoder and make sure we get the external one. 121 // Get decoder and make sure we get the external one.
121 EXPECT_EQ(&decoder, db.GetDecoder(kPayloadType)); 122 EXPECT_EQ(&decoder, db.GetDecoder(kPayloadType));
122 // Get the decoder info struct and check it too. 123 // Get the decoder info struct and check it too.
123 const DecoderDatabase::DecoderInfo* info; 124 const DecoderDatabase::DecoderInfo* info;
124 info = db.GetDecoderInfo(kPayloadType); 125 info = db.GetDecoderInfo(kPayloadType);
125 ASSERT_TRUE(info != NULL); 126 ASSERT_TRUE(info != NULL);
126 EXPECT_EQ(kDecoderPCMu, info->codec_type); 127 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type);
127 EXPECT_EQ(&decoder, info->decoder); 128 EXPECT_EQ(&decoder, info->decoder);
128 EXPECT_EQ(8000, info->fs_hz); 129 EXPECT_EQ(8000, info->fs_hz);
129 EXPECT_TRUE(info->external); 130 EXPECT_TRUE(info->external);
130 // Expect not to delete the decoder when removing it from the database, since 131 // Expect not to delete the decoder when removing it from the database, since
131 // it was declared externally. 132 // it was declared externally.
132 EXPECT_CALL(decoder, Die()).Times(0); 133 EXPECT_CALL(decoder, Die()).Times(0);
133 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType)); 134 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType));
134 EXPECT_TRUE(db.Empty()); 135 EXPECT_TRUE(db.Empty());
135 136
136 EXPECT_CALL(decoder, Die()).Times(1); // Will be called when |db| is deleted. 137 EXPECT_CALL(decoder, Die()).Times(1); // Will be called when |db| is deleted.
137 } 138 }
138 139
139 TEST(DecoderDatabase, CheckPayloadTypes) { 140 TEST(DecoderDatabase, CheckPayloadTypes) {
140 DecoderDatabase db; 141 DecoderDatabase db;
141 // Load a number of payloads into the database. Payload types are 0, 1, ..., 142 // Load a number of payloads into the database. Payload types are 0, 1, ...,
142 // while the decoder type is the same for all payload types (this does not 143 // while the decoder type is the same for all payload types (this does not
143 // matter for the test). 144 // matter for the test).
144 const int kNumPayloads = 10; 145 const int kNumPayloads = 10;
145 for (uint8_t payload_type = 0; payload_type < kNumPayloads; ++payload_type) { 146 for (uint8_t payload_type = 0; payload_type < kNumPayloads; ++payload_type) {
146 EXPECT_EQ(DecoderDatabase::kOK, 147 EXPECT_EQ(
147 db.RegisterPayload(payload_type, kDecoderArbitrary)); 148 DecoderDatabase::kOK,
149 db.RegisterPayload(payload_type, NetEqDecoder::kDecoderArbitrary));
148 } 150 }
149 PacketList packet_list; 151 PacketList packet_list;
150 for (int i = 0; i < kNumPayloads + 1; ++i) { 152 for (int i = 0; i < kNumPayloads + 1; ++i) {
151 // Create packet with payload type |i|. The last packet will have a payload 153 // Create packet with payload type |i|. The last packet will have a payload
152 // type that is not registered in the decoder database. 154 // type that is not registered in the decoder database.
153 Packet* packet = new Packet; 155 Packet* packet = new Packet;
154 packet->header.payloadType = i; 156 packet->header.payloadType = i;
155 packet_list.push_back(packet); 157 packet_list.push_back(packet);
156 } 158 }
157 159
(...skipping 17 matching lines...) Expand all
175 #if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX) 177 #if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)
176 #define IF_ISAC(x) x 178 #define IF_ISAC(x) x
177 #else 179 #else
178 #define IF_ISAC(x) DISABLED_##x 180 #define IF_ISAC(x) DISABLED_##x
179 #endif 181 #endif
180 182
181 // Test the methods for setting and getting active speech and CNG decoders. 183 // Test the methods for setting and getting active speech and CNG decoders.
182 TEST(DecoderDatabase, IF_ISAC(ActiveDecoders)) { 184 TEST(DecoderDatabase, IF_ISAC(ActiveDecoders)) {
183 DecoderDatabase db; 185 DecoderDatabase db;
184 // Load payload types. 186 // Load payload types.
185 ASSERT_EQ(DecoderDatabase::kOK, db.RegisterPayload(0, kDecoderPCMu)); 187 ASSERT_EQ(DecoderDatabase::kOK,
186 ASSERT_EQ(DecoderDatabase::kOK, db.RegisterPayload(103, kDecoderISAC)); 188 db.RegisterPayload(0, NetEqDecoder::kDecoderPCMu));
187 ASSERT_EQ(DecoderDatabase::kOK, db.RegisterPayload(13, kDecoderCNGnb)); 189 ASSERT_EQ(DecoderDatabase::kOK,
190 db.RegisterPayload(103, NetEqDecoder::kDecoderISAC));
191 ASSERT_EQ(DecoderDatabase::kOK,
192 db.RegisterPayload(13, NetEqDecoder::kDecoderCNGnb));
188 // Verify that no decoders are active from the start. 193 // Verify that no decoders are active from the start.
189 EXPECT_EQ(NULL, db.GetActiveDecoder()); 194 EXPECT_EQ(NULL, db.GetActiveDecoder());
190 EXPECT_EQ(NULL, db.GetActiveCngDecoder()); 195 EXPECT_EQ(NULL, db.GetActiveCngDecoder());
191 196
192 // Set active speech codec. 197 // Set active speech codec.
193 bool changed; // Should be true when the active decoder changed. 198 bool changed; // Should be true when the active decoder changed.
194 EXPECT_EQ(DecoderDatabase::kOK, db.SetActiveDecoder(0, &changed)); 199 EXPECT_EQ(DecoderDatabase::kOK, db.SetActiveDecoder(0, &changed));
195 EXPECT_TRUE(changed); 200 EXPECT_TRUE(changed);
196 AudioDecoder* decoder = db.GetActiveDecoder(); 201 AudioDecoder* decoder = db.GetActiveDecoder();
197 ASSERT_FALSE(decoder == NULL); // Should get a decoder here. 202 ASSERT_FALSE(decoder == NULL); // Should get a decoder here.
(...skipping 23 matching lines...) Expand all
221 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(13)); 226 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(13));
222 EXPECT_EQ(NULL, db.GetActiveCngDecoder()); 227 EXPECT_EQ(NULL, db.GetActiveCngDecoder());
223 228
224 // Try to set non-existing codecs as active. 229 // Try to set non-existing codecs as active.
225 EXPECT_EQ(DecoderDatabase::kDecoderNotFound, 230 EXPECT_EQ(DecoderDatabase::kDecoderNotFound,
226 db.SetActiveDecoder(17, &changed)); 231 db.SetActiveDecoder(17, &changed));
227 EXPECT_EQ(DecoderDatabase::kDecoderNotFound, 232 EXPECT_EQ(DecoderDatabase::kDecoderNotFound,
228 db.SetActiveCngDecoder(17)); 233 db.SetActiveCngDecoder(17));
229 } 234 }
230 } // namespace webrtc 235 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/decoder_database.cc ('k') | webrtc/modules/audio_coding/neteq/delay_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698