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

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

Issue 1484343003: NetEq: Add codec name and RTP timestamp rate to DecoderInfo (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase Created 5 years 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 14 matching lines...) Expand all
25 25
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 const std::string kCodecName = "Robert\'); DROP TABLE Students;";
36 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu)); 36 EXPECT_EQ(
37 DecoderDatabase::kOK,
38 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName));
37 EXPECT_EQ(1, db.Size()); 39 EXPECT_EQ(1, db.Size());
38 EXPECT_FALSE(db.Empty()); 40 EXPECT_FALSE(db.Empty());
39 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType)); 41 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType));
40 EXPECT_EQ(0, db.Size()); 42 EXPECT_EQ(0, db.Size());
41 EXPECT_TRUE(db.Empty()); 43 EXPECT_TRUE(db.Empty());
42 } 44 }
43 45
44 TEST(DecoderDatabase, GetDecoderInfo) { 46 TEST(DecoderDatabase, GetDecoderInfo) {
45 DecoderDatabase db; 47 DecoderDatabase db;
46 const uint8_t kPayloadType = 0; 48 const uint8_t kPayloadType = 0;
47 EXPECT_EQ(DecoderDatabase::kOK, 49 const std::string kCodecName = "Robert\'); DROP TABLE Students;";
48 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu)); 50 EXPECT_EQ(
51 DecoderDatabase::kOK,
52 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName));
49 const DecoderDatabase::DecoderInfo* info; 53 const DecoderDatabase::DecoderInfo* info;
50 info = db.GetDecoderInfo(kPayloadType); 54 info = db.GetDecoderInfo(kPayloadType);
51 ASSERT_TRUE(info != NULL); 55 ASSERT_TRUE(info != NULL);
52 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type); 56 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type);
53 EXPECT_EQ(NULL, info->decoder); 57 EXPECT_EQ(NULL, info->decoder);
54 EXPECT_EQ(8000, info->fs_hz); 58 EXPECT_EQ(8000, info->fs_hz);
59 EXPECT_EQ(kCodecName, info->name);
55 EXPECT_FALSE(info->external); 60 EXPECT_FALSE(info->external);
56 info = db.GetDecoderInfo(kPayloadType + 1); // Other payload type. 61 info = db.GetDecoderInfo(kPayloadType + 1); // Other payload type.
57 EXPECT_TRUE(info == NULL); // Should not be found. 62 EXPECT_TRUE(info == NULL); // Should not be found.
58 } 63 }
59 64
60 TEST(DecoderDatabase, GetRtpPayloadType) { 65 TEST(DecoderDatabase, GetRtpPayloadType) {
61 DecoderDatabase db; 66 DecoderDatabase db;
62 const uint8_t kPayloadType = 0; 67 const uint8_t kPayloadType = 0;
63 EXPECT_EQ(DecoderDatabase::kOK, 68 const std::string kCodecName = "Robert\'); DROP TABLE Students;";
64 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu)); 69 EXPECT_EQ(
70 DecoderDatabase::kOK,
71 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName));
65 EXPECT_EQ(kPayloadType, db.GetRtpPayloadType(NetEqDecoder::kDecoderPCMu)); 72 EXPECT_EQ(kPayloadType, db.GetRtpPayloadType(NetEqDecoder::kDecoderPCMu));
66 const uint8_t expected_value = DecoderDatabase::kRtpPayloadTypeError; 73 const uint8_t expected_value = DecoderDatabase::kRtpPayloadTypeError;
67 EXPECT_EQ(expected_value, 74 EXPECT_EQ(expected_value,
68 db.GetRtpPayloadType( 75 db.GetRtpPayloadType(
69 NetEqDecoder::kDecoderISAC)); // iSAC is not registered. 76 NetEqDecoder::kDecoderISAC)); // iSAC is not registered.
70 } 77 }
71 78
72 TEST(DecoderDatabase, GetDecoder) { 79 TEST(DecoderDatabase, GetDecoder) {
73 DecoderDatabase db; 80 DecoderDatabase db;
74 const uint8_t kPayloadType = 0; 81 const uint8_t kPayloadType = 0;
82 const std::string kCodecName = "Robert\'); DROP TABLE Students;";
75 EXPECT_EQ(DecoderDatabase::kOK, 83 EXPECT_EQ(DecoderDatabase::kOK,
76 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCM16B)); 84 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCM16B,
85 kCodecName));
77 AudioDecoder* dec = db.GetDecoder(kPayloadType); 86 AudioDecoder* dec = db.GetDecoder(kPayloadType);
78 ASSERT_TRUE(dec != NULL); 87 ASSERT_TRUE(dec != NULL);
79 } 88 }
80 89
81 TEST(DecoderDatabase, TypeTests) { 90 TEST(DecoderDatabase, TypeTests) {
82 DecoderDatabase db; 91 DecoderDatabase db;
83 const uint8_t kPayloadTypePcmU = 0; 92 const uint8_t kPayloadTypePcmU = 0;
84 const uint8_t kPayloadTypeCng = 13; 93 const uint8_t kPayloadTypeCng = 13;
85 const uint8_t kPayloadTypeDtmf = 100; 94 const uint8_t kPayloadTypeDtmf = 100;
86 const uint8_t kPayloadTypeRed = 101; 95 const uint8_t kPayloadTypeRed = 101;
87 const uint8_t kPayloadNotUsed = 102; 96 const uint8_t kPayloadNotUsed = 102;
88 // Load into database. 97 // Load into database.
98 EXPECT_EQ(
99 DecoderDatabase::kOK,
100 db.RegisterPayload(kPayloadTypePcmU, NetEqDecoder::kDecoderPCMu, "pcmu"));
89 EXPECT_EQ(DecoderDatabase::kOK, 101 EXPECT_EQ(DecoderDatabase::kOK,
90 db.RegisterPayload(kPayloadTypePcmU, NetEqDecoder::kDecoderPCMu)); 102 db.RegisterPayload(kPayloadTypeCng, NetEqDecoder::kDecoderCNGnb,
91 EXPECT_EQ(DecoderDatabase::kOK, 103 "cng-nb"));
92 db.RegisterPayload(kPayloadTypeCng, NetEqDecoder::kDecoderCNGnb)); 104 EXPECT_EQ(
93 EXPECT_EQ(DecoderDatabase::kOK, 105 DecoderDatabase::kOK,
94 db.RegisterPayload(kPayloadTypeDtmf, NetEqDecoder::kDecoderAVT)); 106 db.RegisterPayload(kPayloadTypeDtmf, NetEqDecoder::kDecoderAVT, "avt"));
95 EXPECT_EQ(DecoderDatabase::kOK, 107 EXPECT_EQ(
96 db.RegisterPayload(kPayloadTypeRed, NetEqDecoder::kDecoderRED)); 108 DecoderDatabase::kOK,
109 db.RegisterPayload(kPayloadTypeRed, NetEqDecoder::kDecoderRED, "red"));
97 EXPECT_EQ(4, db.Size()); 110 EXPECT_EQ(4, db.Size());
98 // Test. 111 // Test.
99 EXPECT_FALSE(db.IsComfortNoise(kPayloadNotUsed)); 112 EXPECT_FALSE(db.IsComfortNoise(kPayloadNotUsed));
100 EXPECT_FALSE(db.IsDtmf(kPayloadNotUsed)); 113 EXPECT_FALSE(db.IsDtmf(kPayloadNotUsed));
101 EXPECT_FALSE(db.IsRed(kPayloadNotUsed)); 114 EXPECT_FALSE(db.IsRed(kPayloadNotUsed));
102 EXPECT_FALSE(db.IsComfortNoise(kPayloadTypePcmU)); 115 EXPECT_FALSE(db.IsComfortNoise(kPayloadTypePcmU));
103 EXPECT_FALSE(db.IsDtmf(kPayloadTypePcmU)); 116 EXPECT_FALSE(db.IsDtmf(kPayloadTypePcmU));
104 EXPECT_FALSE(db.IsRed(kPayloadTypePcmU)); 117 EXPECT_FALSE(db.IsRed(kPayloadTypePcmU));
105 EXPECT_FALSE(db.IsType(kPayloadTypePcmU, NetEqDecoder::kDecoderISAC)); 118 EXPECT_FALSE(db.IsType(kPayloadTypePcmU, NetEqDecoder::kDecoderISAC));
106 EXPECT_TRUE(db.IsType(kPayloadTypePcmU, NetEqDecoder::kDecoderPCMu)); 119 EXPECT_TRUE(db.IsType(kPayloadTypePcmU, NetEqDecoder::kDecoderPCMu));
107 EXPECT_TRUE(db.IsComfortNoise(kPayloadTypeCng)); 120 EXPECT_TRUE(db.IsComfortNoise(kPayloadTypeCng));
108 EXPECT_TRUE(db.IsDtmf(kPayloadTypeDtmf)); 121 EXPECT_TRUE(db.IsDtmf(kPayloadTypeDtmf));
109 EXPECT_TRUE(db.IsRed(kPayloadTypeRed)); 122 EXPECT_TRUE(db.IsRed(kPayloadTypeRed));
110 } 123 }
111 124
112 TEST(DecoderDatabase, ExternalDecoder) { 125 TEST(DecoderDatabase, ExternalDecoder) {
113 DecoderDatabase db; 126 DecoderDatabase db;
114 const uint8_t kPayloadType = 0; 127 const uint8_t kPayloadType = 0;
128 const std::string kCodecName = "Robert\'); DROP TABLE Students;";
115 MockAudioDecoder decoder; 129 MockAudioDecoder decoder;
116 // Load into database. 130 // Load into database.
117 EXPECT_EQ(DecoderDatabase::kOK, 131 EXPECT_EQ(DecoderDatabase::kOK,
118 db.InsertExternal(kPayloadType, NetEqDecoder::kDecoderPCMu, 8000, 132 db.InsertExternal(kPayloadType, NetEqDecoder::kDecoderPCMu,
119 &decoder)); 133 kCodecName, 8000, &decoder));
120 EXPECT_EQ(1, db.Size()); 134 EXPECT_EQ(1, db.Size());
121 // Get decoder and make sure we get the external one. 135 // Get decoder and make sure we get the external one.
122 EXPECT_EQ(&decoder, db.GetDecoder(kPayloadType)); 136 EXPECT_EQ(&decoder, db.GetDecoder(kPayloadType));
123 // Get the decoder info struct and check it too. 137 // Get the decoder info struct and check it too.
124 const DecoderDatabase::DecoderInfo* info; 138 const DecoderDatabase::DecoderInfo* info;
125 info = db.GetDecoderInfo(kPayloadType); 139 info = db.GetDecoderInfo(kPayloadType);
126 ASSERT_TRUE(info != NULL); 140 ASSERT_TRUE(info != NULL);
127 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type); 141 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type);
142 EXPECT_EQ(kCodecName, info->name);
128 EXPECT_EQ(&decoder, info->decoder); 143 EXPECT_EQ(&decoder, info->decoder);
129 EXPECT_EQ(8000, info->fs_hz); 144 EXPECT_EQ(8000, info->fs_hz);
130 EXPECT_TRUE(info->external); 145 EXPECT_TRUE(info->external);
131 // Expect not to delete the decoder when removing it from the database, since 146 // Expect not to delete the decoder when removing it from the database, since
132 // it was declared externally. 147 // it was declared externally.
133 EXPECT_CALL(decoder, Die()).Times(0); 148 EXPECT_CALL(decoder, Die()).Times(0);
134 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType)); 149 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType));
135 EXPECT_TRUE(db.Empty()); 150 EXPECT_TRUE(db.Empty());
136 151
137 EXPECT_CALL(decoder, Die()).Times(1); // Will be called when |db| is deleted. 152 EXPECT_CALL(decoder, Die()).Times(1); // Will be called when |db| is deleted.
138 } 153 }
139 154
140 TEST(DecoderDatabase, CheckPayloadTypes) { 155 TEST(DecoderDatabase, CheckPayloadTypes) {
141 DecoderDatabase db; 156 DecoderDatabase db;
142 // Load a number of payloads into the database. Payload types are 0, 1, ..., 157 // Load a number of payloads into the database. Payload types are 0, 1, ...,
143 // while the decoder type is the same for all payload types (this does not 158 // while the decoder type is the same for all payload types (this does not
144 // matter for the test). 159 // matter for the test).
145 const int kNumPayloads = 10; 160 const int kNumPayloads = 10;
146 for (uint8_t payload_type = 0; payload_type < kNumPayloads; ++payload_type) { 161 for (uint8_t payload_type = 0; payload_type < kNumPayloads; ++payload_type) {
147 EXPECT_EQ( 162 EXPECT_EQ(
148 DecoderDatabase::kOK, 163 DecoderDatabase::kOK,
149 db.RegisterPayload(payload_type, NetEqDecoder::kDecoderArbitrary)); 164 db.RegisterPayload(payload_type, NetEqDecoder::kDecoderArbitrary, ""));
150 } 165 }
151 PacketList packet_list; 166 PacketList packet_list;
152 for (int i = 0; i < kNumPayloads + 1; ++i) { 167 for (int i = 0; i < kNumPayloads + 1; ++i) {
153 // Create packet with payload type |i|. The last packet will have a payload 168 // Create packet with payload type |i|. The last packet will have a payload
154 // type that is not registered in the decoder database. 169 // type that is not registered in the decoder database.
155 Packet* packet = new Packet; 170 Packet* packet = new Packet;
156 packet->header.payloadType = i; 171 packet->header.payloadType = i;
157 packet_list.push_back(packet); 172 packet_list.push_back(packet);
158 } 173 }
159 174
(...skipping 18 matching lines...) Expand all
178 #define IF_ISAC(x) x 193 #define IF_ISAC(x) x
179 #else 194 #else
180 #define IF_ISAC(x) DISABLED_##x 195 #define IF_ISAC(x) DISABLED_##x
181 #endif 196 #endif
182 197
183 // Test the methods for setting and getting active speech and CNG decoders. 198 // Test the methods for setting and getting active speech and CNG decoders.
184 TEST(DecoderDatabase, IF_ISAC(ActiveDecoders)) { 199 TEST(DecoderDatabase, IF_ISAC(ActiveDecoders)) {
185 DecoderDatabase db; 200 DecoderDatabase db;
186 // Load payload types. 201 // Load payload types.
187 ASSERT_EQ(DecoderDatabase::kOK, 202 ASSERT_EQ(DecoderDatabase::kOK,
188 db.RegisterPayload(0, NetEqDecoder::kDecoderPCMu)); 203 db.RegisterPayload(0, NetEqDecoder::kDecoderPCMu, "pcmu"));
189 ASSERT_EQ(DecoderDatabase::kOK, 204 ASSERT_EQ(DecoderDatabase::kOK,
190 db.RegisterPayload(103, NetEqDecoder::kDecoderISAC)); 205 db.RegisterPayload(103, NetEqDecoder::kDecoderISAC, "isac"));
191 ASSERT_EQ(DecoderDatabase::kOK, 206 ASSERT_EQ(DecoderDatabase::kOK,
192 db.RegisterPayload(13, NetEqDecoder::kDecoderCNGnb)); 207 db.RegisterPayload(13, NetEqDecoder::kDecoderCNGnb, "cng-nb"));
193 // Verify that no decoders are active from the start. 208 // Verify that no decoders are active from the start.
194 EXPECT_EQ(NULL, db.GetActiveDecoder()); 209 EXPECT_EQ(NULL, db.GetActiveDecoder());
195 EXPECT_EQ(NULL, db.GetActiveCngDecoder()); 210 EXPECT_EQ(NULL, db.GetActiveCngDecoder());
196 211
197 // Set active speech codec. 212 // Set active speech codec.
198 bool changed; // Should be true when the active decoder changed. 213 bool changed; // Should be true when the active decoder changed.
199 EXPECT_EQ(DecoderDatabase::kOK, db.SetActiveDecoder(0, &changed)); 214 EXPECT_EQ(DecoderDatabase::kOK, db.SetActiveDecoder(0, &changed));
200 EXPECT_TRUE(changed); 215 EXPECT_TRUE(changed);
201 AudioDecoder* decoder = db.GetActiveDecoder(); 216 AudioDecoder* decoder = db.GetActiveDecoder();
202 ASSERT_FALSE(decoder == NULL); // Should get a decoder here. 217 ASSERT_FALSE(decoder == NULL); // Should get a decoder here.
(...skipping 23 matching lines...) Expand all
226 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(13)); 241 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(13));
227 EXPECT_EQ(NULL, db.GetActiveCngDecoder()); 242 EXPECT_EQ(NULL, db.GetActiveCngDecoder());
228 243
229 // Try to set non-existing codecs as active. 244 // Try to set non-existing codecs as active.
230 EXPECT_EQ(DecoderDatabase::kDecoderNotFound, 245 EXPECT_EQ(DecoderDatabase::kDecoderNotFound,
231 db.SetActiveDecoder(17, &changed)); 246 db.SetActiveDecoder(17, &changed));
232 EXPECT_EQ(DecoderDatabase::kDecoderNotFound, 247 EXPECT_EQ(DecoderDatabase::kDecoderNotFound,
233 db.SetActiveCngDecoder(17)); 248 db.SetActiveCngDecoder(17));
234 } 249 }
235 } // namespace webrtc 250 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/decoder_database.cc ('k') | webrtc/modules/audio_coding/neteq/include/neteq.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698