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

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

Issue 2355503002: Stopped using the NetEqDecoder enum internally in NetEq. (Closed)
Patch Set: Clarified comments. Created 4 years, 3 months 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 })); 74 }));
75 DecoderDatabase db(factory); 75 DecoderDatabase db(factory);
76 const uint8_t kPayloadType = 0; 76 const uint8_t kPayloadType = 0;
77 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; 77 const std::string kCodecName = "Robert\'); DROP TABLE Students;";
78 EXPECT_EQ( 78 EXPECT_EQ(
79 DecoderDatabase::kOK, 79 DecoderDatabase::kOK,
80 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName)); 80 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName));
81 const DecoderDatabase::DecoderInfo* info; 81 const DecoderDatabase::DecoderInfo* info;
82 info = db.GetDecoderInfo(kPayloadType); 82 info = db.GetDecoderInfo(kPayloadType);
83 ASSERT_TRUE(info != NULL); 83 ASSERT_TRUE(info != NULL);
84 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type); 84 EXPECT_TRUE(info->IsType("pcmu"));
85 EXPECT_EQ(kCodecName, info->name); 85 EXPECT_EQ(kCodecName, info->name);
86 EXPECT_EQ(decoder, db.GetDecoder(kPayloadType)); 86 EXPECT_EQ(decoder, db.GetDecoder(kPayloadType));
87 info = db.GetDecoderInfo(kPayloadType + 1); // Other payload type. 87 info = db.GetDecoderInfo(kPayloadType + 1); // Other payload type.
88 EXPECT_TRUE(info == NULL); // Should not be found. 88 EXPECT_TRUE(info == NULL); // Should not be found.
89 } 89 }
90 90
91 TEST(DecoderDatabase, GetRtpPayloadType) {
92 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
93 const uint8_t kPayloadType = 0;
94 const std::string kCodecName = "Robert\'); DROP TABLE Students;";
95 EXPECT_EQ(
96 DecoderDatabase::kOK,
97 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName));
98 EXPECT_EQ(kPayloadType, db.GetRtpPayloadType(NetEqDecoder::kDecoderPCMu));
99 const uint8_t expected_value = DecoderDatabase::kRtpPayloadTypeError;
100 EXPECT_EQ(expected_value,
101 db.GetRtpPayloadType(
102 NetEqDecoder::kDecoderISAC)); // iSAC is not registered.
103 }
104
105 TEST(DecoderDatabase, GetDecoder) { 91 TEST(DecoderDatabase, GetDecoder) {
106 DecoderDatabase db(CreateBuiltinAudioDecoderFactory()); 92 DecoderDatabase db(CreateBuiltinAudioDecoderFactory());
107 const uint8_t kPayloadType = 0; 93 const uint8_t kPayloadType = 0;
108 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; 94 const std::string kCodecName = "Robert\'); DROP TABLE Students;";
109 EXPECT_EQ(DecoderDatabase::kOK, 95 EXPECT_EQ(DecoderDatabase::kOK,
110 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCM16B, 96 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCM16B,
111 kCodecName)); 97 kCodecName));
112 AudioDecoder* dec = db.GetDecoder(kPayloadType); 98 AudioDecoder* dec = db.GetDecoder(kPayloadType);
113 ASSERT_TRUE(dec != NULL); 99 ASSERT_TRUE(dec != NULL);
114 } 100 }
(...skipping 19 matching lines...) Expand all
134 DecoderDatabase::kOK, 120 DecoderDatabase::kOK,
135 db.RegisterPayload(kPayloadTypeRed, NetEqDecoder::kDecoderRED, "red")); 121 db.RegisterPayload(kPayloadTypeRed, NetEqDecoder::kDecoderRED, "red"));
136 EXPECT_EQ(4, db.Size()); 122 EXPECT_EQ(4, db.Size());
137 // Test. 123 // Test.
138 EXPECT_FALSE(db.IsComfortNoise(kPayloadNotUsed)); 124 EXPECT_FALSE(db.IsComfortNoise(kPayloadNotUsed));
139 EXPECT_FALSE(db.IsDtmf(kPayloadNotUsed)); 125 EXPECT_FALSE(db.IsDtmf(kPayloadNotUsed));
140 EXPECT_FALSE(db.IsRed(kPayloadNotUsed)); 126 EXPECT_FALSE(db.IsRed(kPayloadNotUsed));
141 EXPECT_FALSE(db.IsComfortNoise(kPayloadTypePcmU)); 127 EXPECT_FALSE(db.IsComfortNoise(kPayloadTypePcmU));
142 EXPECT_FALSE(db.IsDtmf(kPayloadTypePcmU)); 128 EXPECT_FALSE(db.IsDtmf(kPayloadTypePcmU));
143 EXPECT_FALSE(db.IsRed(kPayloadTypePcmU)); 129 EXPECT_FALSE(db.IsRed(kPayloadTypePcmU));
144 EXPECT_FALSE(db.IsType(kPayloadTypePcmU, NetEqDecoder::kDecoderISAC)); 130 EXPECT_FALSE(db.IsType(kPayloadTypePcmU, "isac"));
145 EXPECT_TRUE(db.IsType(kPayloadTypePcmU, NetEqDecoder::kDecoderPCMu)); 131 EXPECT_TRUE(db.IsType(kPayloadTypePcmU, "pcmu"));
146 EXPECT_TRUE(db.IsComfortNoise(kPayloadTypeCng)); 132 EXPECT_TRUE(db.IsComfortNoise(kPayloadTypeCng));
147 EXPECT_TRUE(db.IsDtmf(kPayloadTypeDtmf)); 133 EXPECT_TRUE(db.IsDtmf(kPayloadTypeDtmf));
148 EXPECT_TRUE(db.IsRed(kPayloadTypeRed)); 134 EXPECT_TRUE(db.IsRed(kPayloadTypeRed));
149 } 135 }
150 136
151 TEST(DecoderDatabase, ExternalDecoder) { 137 TEST(DecoderDatabase, ExternalDecoder) {
152 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>); 138 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
153 const uint8_t kPayloadType = 0; 139 const uint8_t kPayloadType = 0;
154 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; 140 const std::string kCodecName = "Robert\'); DROP TABLE Students;";
155 MockAudioDecoder decoder; 141 MockAudioDecoder decoder;
156 // Load into database. 142 // Load into database.
157 EXPECT_EQ(DecoderDatabase::kOK, 143 EXPECT_EQ(DecoderDatabase::kOK,
158 db.InsertExternal(kPayloadType, NetEqDecoder::kDecoderPCMu, 144 db.InsertExternal(kPayloadType, NetEqDecoder::kDecoderPCMu,
159 kCodecName, &decoder)); 145 kCodecName, &decoder));
160 EXPECT_EQ(1, db.Size()); 146 EXPECT_EQ(1, db.Size());
161 // Get decoder and make sure we get the external one. 147 // Get decoder and make sure we get the external one.
162 EXPECT_EQ(&decoder, db.GetDecoder(kPayloadType)); 148 EXPECT_EQ(&decoder, db.GetDecoder(kPayloadType));
163 // Get the decoder info struct and check it too. 149 // Get the decoder info struct and check it too.
164 const DecoderDatabase::DecoderInfo* info; 150 const DecoderDatabase::DecoderInfo* info;
165 info = db.GetDecoderInfo(kPayloadType); 151 info = db.GetDecoderInfo(kPayloadType);
166 ASSERT_TRUE(info != NULL); 152 ASSERT_TRUE(info != NULL);
167 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type); 153 EXPECT_TRUE(info->IsType("pcmu"));
154 EXPECT_EQ(info->name, kCodecName);
168 EXPECT_EQ(kCodecName, info->name); 155 EXPECT_EQ(kCodecName, info->name);
169 // Expect not to delete the decoder when removing it from the database, since 156 // Expect not to delete the decoder when removing it from the database, since
170 // it was declared externally. 157 // it was declared externally.
171 EXPECT_CALL(decoder, Die()).Times(0); 158 EXPECT_CALL(decoder, Die()).Times(0);
172 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType)); 159 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType));
173 EXPECT_TRUE(db.Empty()); 160 EXPECT_TRUE(db.Empty());
174 161
175 EXPECT_CALL(decoder, Die()).Times(1); // Will be called when |db| is deleted. 162 EXPECT_CALL(decoder, Die()).Times(1); // Will be called when |db| is deleted.
176 } 163 }
177 164
178 TEST(DecoderDatabase, CheckPayloadTypes) { 165 TEST(DecoderDatabase, CheckPayloadTypes) {
179 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>); 166 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
180 // Load a number of payloads into the database. Payload types are 0, 1, ..., 167 // Load a number of payloads into the database. Payload types are 0, 1, ...,
181 // while the decoder type is the same for all payload types (this does not 168 // while the decoder type is the same for all payload types (this does not
182 // matter for the test). 169 // matter for the test).
183 const int kNumPayloads = 10; 170 const int kNumPayloads = 10;
184 for (uint8_t payload_type = 0; payload_type < kNumPayloads; ++payload_type) { 171 for (uint8_t payload_type = 0; payload_type < kNumPayloads; ++payload_type) {
185 EXPECT_EQ( 172 EXPECT_EQ(DecoderDatabase::kOK,
186 DecoderDatabase::kOK, 173 db.RegisterPayload(payload_type, NetEqDecoder::kDecoderPCMu, ""));
187 db.RegisterPayload(payload_type, NetEqDecoder::kDecoderArbitrary, ""));
188 } 174 }
189 PacketList packet_list; 175 PacketList packet_list;
190 for (int i = 0; i < kNumPayloads + 1; ++i) { 176 for (int i = 0; i < kNumPayloads + 1; ++i) {
191 // Create packet with payload type |i|. The last packet will have a payload 177 // Create packet with payload type |i|. The last packet will have a payload
192 // type that is not registered in the decoder database. 178 // type that is not registered in the decoder database.
193 Packet* packet = new Packet; 179 Packet* packet = new Packet;
194 packet->header.payloadType = i; 180 packet->header.payloadType = i;
195 packet_list.push_back(packet); 181 packet_list.push_back(packet);
196 } 182 }
197 183
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(13)); 250 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(13));
265 EXPECT_EQ(NULL, db.GetActiveCngDecoder()); 251 EXPECT_EQ(NULL, db.GetActiveCngDecoder());
266 252
267 // Try to set non-existing codecs as active. 253 // Try to set non-existing codecs as active.
268 EXPECT_EQ(DecoderDatabase::kDecoderNotFound, 254 EXPECT_EQ(DecoderDatabase::kDecoderNotFound,
269 db.SetActiveDecoder(17, &changed)); 255 db.SetActiveDecoder(17, &changed));
270 EXPECT_EQ(DecoderDatabase::kDecoderNotFound, 256 EXPECT_EQ(DecoderDatabase::kDecoderNotFound,
271 db.SetActiveCngDecoder(17)); 257 db.SetActiveCngDecoder(17));
272 } 258 }
273 } // namespace webrtc 259 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/decoder_database.cc ('k') | webrtc/modules/audio_coding/neteq/delay_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698