OLD | NEW |
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 |
11 #include "webrtc/modules/audio_coding/neteq/decoder_database.h" | 11 #include "webrtc/modules/audio_coding/neteq/decoder_database.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <stdlib.h> | 14 #include <stdlib.h> |
15 | 15 |
16 #include <string> | 16 #include <string> |
17 | 17 |
18 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 #include "webrtc/modules/audio_coding/neteq/mock/mock_audio_decoder.h" | 21 #include "webrtc/modules/audio_coding/neteq/mock/mock_audio_decoder.h" |
| 22 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" |
| 23 #include "webrtc/modules/audio_coding/codecs/mock_audio_decoder_factory.h" |
22 | 24 |
23 namespace webrtc { | 25 namespace webrtc { |
24 | 26 |
25 TEST(DecoderDatabase, CreateAndDestroy) { | 27 TEST(DecoderDatabase, CreateAndDestroy) { |
26 DecoderDatabase db; | 28 std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory); |
| 29 DecoderDatabase db(std::move(factory)); |
27 EXPECT_EQ(0, db.Size()); | 30 EXPECT_EQ(0, db.Size()); |
28 EXPECT_TRUE(db.Empty()); | 31 EXPECT_TRUE(db.Empty()); |
29 } | 32 } |
30 | 33 |
31 TEST(DecoderDatabase, InsertAndRemove) { | 34 TEST(DecoderDatabase, InsertAndRemove) { |
32 DecoderDatabase db; | 35 std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory); |
| 36 DecoderDatabase db(std::move(factory)); |
33 const uint8_t kPayloadType = 0; | 37 const uint8_t kPayloadType = 0; |
34 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; | 38 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; |
35 EXPECT_EQ( | 39 EXPECT_EQ( |
36 DecoderDatabase::kOK, | 40 DecoderDatabase::kOK, |
37 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName)); | 41 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName)); |
38 EXPECT_EQ(1, db.Size()); | 42 EXPECT_EQ(1, db.Size()); |
39 EXPECT_FALSE(db.Empty()); | 43 EXPECT_FALSE(db.Empty()); |
40 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType)); | 44 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType)); |
41 EXPECT_EQ(0, db.Size()); | 45 EXPECT_EQ(0, db.Size()); |
42 EXPECT_TRUE(db.Empty()); | 46 EXPECT_TRUE(db.Empty()); |
43 } | 47 } |
44 | 48 |
45 TEST(DecoderDatabase, GetDecoderInfo) { | 49 TEST(DecoderDatabase, GetDecoderInfo) { |
46 DecoderDatabase db; | 50 std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory); |
| 51 DecoderDatabase db(std::move(factory)); |
47 const uint8_t kPayloadType = 0; | 52 const uint8_t kPayloadType = 0; |
48 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; | 53 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; |
49 EXPECT_EQ( | 54 EXPECT_EQ( |
50 DecoderDatabase::kOK, | 55 DecoderDatabase::kOK, |
51 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName)); | 56 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName)); |
52 const DecoderDatabase::DecoderInfo* info; | 57 const DecoderDatabase::DecoderInfo* info; |
53 info = db.GetDecoderInfo(kPayloadType); | 58 info = db.GetDecoderInfo(kPayloadType); |
54 ASSERT_TRUE(info != NULL); | 59 ASSERT_TRUE(info != NULL); |
55 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type); | 60 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type); |
56 EXPECT_EQ(nullptr, info->external_decoder); | 61 EXPECT_EQ(nullptr, info->external_decoder); |
57 EXPECT_EQ(8000, info->fs_hz); | 62 EXPECT_EQ(8000, info->fs_hz); |
58 EXPECT_EQ(kCodecName, info->name); | 63 EXPECT_EQ(kCodecName, info->name); |
59 info = db.GetDecoderInfo(kPayloadType + 1); // Other payload type. | 64 info = db.GetDecoderInfo(kPayloadType + 1); // Other payload type. |
60 EXPECT_TRUE(info == NULL); // Should not be found. | 65 EXPECT_TRUE(info == NULL); // Should not be found. |
61 } | 66 } |
62 | 67 |
63 TEST(DecoderDatabase, GetRtpPayloadType) { | 68 TEST(DecoderDatabase, GetRtpPayloadType) { |
64 DecoderDatabase db; | 69 std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory); |
| 70 DecoderDatabase db(std::move(factory)); |
65 const uint8_t kPayloadType = 0; | 71 const uint8_t kPayloadType = 0; |
66 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; | 72 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; |
67 EXPECT_EQ( | 73 EXPECT_EQ( |
68 DecoderDatabase::kOK, | 74 DecoderDatabase::kOK, |
69 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName)); | 75 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName)); |
70 EXPECT_EQ(kPayloadType, db.GetRtpPayloadType(NetEqDecoder::kDecoderPCMu)); | 76 EXPECT_EQ(kPayloadType, db.GetRtpPayloadType(NetEqDecoder::kDecoderPCMu)); |
71 const uint8_t expected_value = DecoderDatabase::kRtpPayloadTypeError; | 77 const uint8_t expected_value = DecoderDatabase::kRtpPayloadTypeError; |
72 EXPECT_EQ(expected_value, | 78 EXPECT_EQ(expected_value, |
73 db.GetRtpPayloadType( | 79 db.GetRtpPayloadType( |
74 NetEqDecoder::kDecoderISAC)); // iSAC is not registered. | 80 NetEqDecoder::kDecoderISAC)); // iSAC is not registered. |
75 } | 81 } |
76 | 82 |
77 TEST(DecoderDatabase, GetDecoder) { | 83 TEST(DecoderDatabase, GetDecoder) { |
78 DecoderDatabase db; | 84 DecoderDatabase db(CreateBuiltinAudioDecoderFactory()); |
79 const uint8_t kPayloadType = 0; | 85 const uint8_t kPayloadType = 0; |
80 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; | 86 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; |
81 EXPECT_EQ(DecoderDatabase::kOK, | 87 EXPECT_EQ(DecoderDatabase::kOK, |
82 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCM16B, | 88 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCM16B, |
83 kCodecName)); | 89 kCodecName)); |
84 AudioDecoder* dec = db.GetDecoder(kPayloadType); | 90 AudioDecoder* dec = db.GetDecoder(kPayloadType); |
85 ASSERT_TRUE(dec != NULL); | 91 ASSERT_TRUE(dec != NULL); |
86 } | 92 } |
87 | 93 |
88 TEST(DecoderDatabase, TypeTests) { | 94 TEST(DecoderDatabase, TypeTests) { |
89 DecoderDatabase db; | 95 std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory); |
| 96 DecoderDatabase db(std::move(factory)); |
90 const uint8_t kPayloadTypePcmU = 0; | 97 const uint8_t kPayloadTypePcmU = 0; |
91 const uint8_t kPayloadTypeCng = 13; | 98 const uint8_t kPayloadTypeCng = 13; |
92 const uint8_t kPayloadTypeDtmf = 100; | 99 const uint8_t kPayloadTypeDtmf = 100; |
93 const uint8_t kPayloadTypeRed = 101; | 100 const uint8_t kPayloadTypeRed = 101; |
94 const uint8_t kPayloadNotUsed = 102; | 101 const uint8_t kPayloadNotUsed = 102; |
95 // Load into database. | 102 // Load into database. |
96 EXPECT_EQ( | 103 EXPECT_EQ( |
97 DecoderDatabase::kOK, | 104 DecoderDatabase::kOK, |
98 db.RegisterPayload(kPayloadTypePcmU, NetEqDecoder::kDecoderPCMu, "pcmu")); | 105 db.RegisterPayload(kPayloadTypePcmU, NetEqDecoder::kDecoderPCMu, "pcmu")); |
99 EXPECT_EQ(DecoderDatabase::kOK, | 106 EXPECT_EQ(DecoderDatabase::kOK, |
(...skipping 14 matching lines...) Expand all Loading... |
114 EXPECT_FALSE(db.IsDtmf(kPayloadTypePcmU)); | 121 EXPECT_FALSE(db.IsDtmf(kPayloadTypePcmU)); |
115 EXPECT_FALSE(db.IsRed(kPayloadTypePcmU)); | 122 EXPECT_FALSE(db.IsRed(kPayloadTypePcmU)); |
116 EXPECT_FALSE(db.IsType(kPayloadTypePcmU, NetEqDecoder::kDecoderISAC)); | 123 EXPECT_FALSE(db.IsType(kPayloadTypePcmU, NetEqDecoder::kDecoderISAC)); |
117 EXPECT_TRUE(db.IsType(kPayloadTypePcmU, NetEqDecoder::kDecoderPCMu)); | 124 EXPECT_TRUE(db.IsType(kPayloadTypePcmU, NetEqDecoder::kDecoderPCMu)); |
118 EXPECT_TRUE(db.IsComfortNoise(kPayloadTypeCng)); | 125 EXPECT_TRUE(db.IsComfortNoise(kPayloadTypeCng)); |
119 EXPECT_TRUE(db.IsDtmf(kPayloadTypeDtmf)); | 126 EXPECT_TRUE(db.IsDtmf(kPayloadTypeDtmf)); |
120 EXPECT_TRUE(db.IsRed(kPayloadTypeRed)); | 127 EXPECT_TRUE(db.IsRed(kPayloadTypeRed)); |
121 } | 128 } |
122 | 129 |
123 TEST(DecoderDatabase, ExternalDecoder) { | 130 TEST(DecoderDatabase, ExternalDecoder) { |
124 DecoderDatabase db; | 131 std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory); |
| 132 DecoderDatabase db(std::move(factory)); |
125 const uint8_t kPayloadType = 0; | 133 const uint8_t kPayloadType = 0; |
126 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; | 134 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; |
127 MockAudioDecoder decoder; | 135 MockAudioDecoder decoder; |
128 // Load into database. | 136 // Load into database. |
129 EXPECT_EQ(DecoderDatabase::kOK, | 137 EXPECT_EQ(DecoderDatabase::kOK, |
130 db.InsertExternal(kPayloadType, NetEqDecoder::kDecoderPCMu, | 138 db.InsertExternal(kPayloadType, NetEqDecoder::kDecoderPCMu, |
131 kCodecName, 8000, &decoder)); | 139 kCodecName, 8000, &decoder)); |
132 EXPECT_EQ(1, db.Size()); | 140 EXPECT_EQ(1, db.Size()); |
133 // Get decoder and make sure we get the external one. | 141 // Get decoder and make sure we get the external one. |
134 EXPECT_EQ(&decoder, db.GetDecoder(kPayloadType)); | 142 EXPECT_EQ(&decoder, db.GetDecoder(kPayloadType)); |
135 // Get the decoder info struct and check it too. | 143 // Get the decoder info struct and check it too. |
136 const DecoderDatabase::DecoderInfo* info; | 144 const DecoderDatabase::DecoderInfo* info; |
137 info = db.GetDecoderInfo(kPayloadType); | 145 info = db.GetDecoderInfo(kPayloadType); |
138 ASSERT_TRUE(info != NULL); | 146 ASSERT_TRUE(info != NULL); |
139 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type); | 147 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type); |
140 EXPECT_EQ(kCodecName, info->name); | 148 EXPECT_EQ(kCodecName, info->name); |
141 EXPECT_EQ(&decoder, info->external_decoder); | 149 EXPECT_EQ(&decoder, info->external_decoder); |
142 EXPECT_EQ(8000, info->fs_hz); | 150 EXPECT_EQ(8000, info->fs_hz); |
143 // Expect not to delete the decoder when removing it from the database, since | 151 // Expect not to delete the decoder when removing it from the database, since |
144 // it was declared externally. | 152 // it was declared externally. |
145 EXPECT_CALL(decoder, Die()).Times(0); | 153 EXPECT_CALL(decoder, Die()).Times(0); |
146 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType)); | 154 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType)); |
147 EXPECT_TRUE(db.Empty()); | 155 EXPECT_TRUE(db.Empty()); |
148 | 156 |
149 EXPECT_CALL(decoder, Die()).Times(1); // Will be called when |db| is deleted. | 157 EXPECT_CALL(decoder, Die()).Times(1); // Will be called when |db| is deleted. |
150 } | 158 } |
151 | 159 |
152 TEST(DecoderDatabase, CheckPayloadTypes) { | 160 TEST(DecoderDatabase, CheckPayloadTypes) { |
153 DecoderDatabase db; | 161 std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory); |
| 162 DecoderDatabase db(std::move(factory)); |
154 // Load a number of payloads into the database. Payload types are 0, 1, ..., | 163 // Load a number of payloads into the database. Payload types are 0, 1, ..., |
155 // while the decoder type is the same for all payload types (this does not | 164 // while the decoder type is the same for all payload types (this does not |
156 // matter for the test). | 165 // matter for the test). |
157 const int kNumPayloads = 10; | 166 const int kNumPayloads = 10; |
158 for (uint8_t payload_type = 0; payload_type < kNumPayloads; ++payload_type) { | 167 for (uint8_t payload_type = 0; payload_type < kNumPayloads; ++payload_type) { |
159 EXPECT_EQ( | 168 EXPECT_EQ( |
160 DecoderDatabase::kOK, | 169 DecoderDatabase::kOK, |
161 db.RegisterPayload(payload_type, NetEqDecoder::kDecoderArbitrary, "")); | 170 db.RegisterPayload(payload_type, NetEqDecoder::kDecoderArbitrary, "")); |
162 } | 171 } |
163 PacketList packet_list; | 172 PacketList packet_list; |
(...skipping 23 matching lines...) Expand all Loading... |
187 } | 196 } |
188 | 197 |
189 #if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX) | 198 #if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX) |
190 #define IF_ISAC(x) x | 199 #define IF_ISAC(x) x |
191 #else | 200 #else |
192 #define IF_ISAC(x) DISABLED_##x | 201 #define IF_ISAC(x) DISABLED_##x |
193 #endif | 202 #endif |
194 | 203 |
195 // Test the methods for setting and getting active speech and CNG decoders. | 204 // Test the methods for setting and getting active speech and CNG decoders. |
196 TEST(DecoderDatabase, IF_ISAC(ActiveDecoders)) { | 205 TEST(DecoderDatabase, IF_ISAC(ActiveDecoders)) { |
197 DecoderDatabase db; | 206 DecoderDatabase db(CreateBuiltinAudioDecoderFactory()); |
198 // Load payload types. | 207 // Load payload types. |
199 ASSERT_EQ(DecoderDatabase::kOK, | 208 ASSERT_EQ(DecoderDatabase::kOK, |
200 db.RegisterPayload(0, NetEqDecoder::kDecoderPCMu, "pcmu")); | 209 db.RegisterPayload(0, NetEqDecoder::kDecoderPCMu, "pcmu")); |
201 ASSERT_EQ(DecoderDatabase::kOK, | 210 ASSERT_EQ(DecoderDatabase::kOK, |
202 db.RegisterPayload(103, NetEqDecoder::kDecoderISAC, "isac")); | 211 db.RegisterPayload(103, NetEqDecoder::kDecoderISAC, "isac")); |
203 ASSERT_EQ(DecoderDatabase::kOK, | 212 ASSERT_EQ(DecoderDatabase::kOK, |
204 db.RegisterPayload(13, NetEqDecoder::kDecoderCNGnb, "cng-nb")); | 213 db.RegisterPayload(13, NetEqDecoder::kDecoderCNGnb, "cng-nb")); |
205 // Verify that no decoders are active from the start. | 214 // Verify that no decoders are active from the start. |
206 EXPECT_EQ(NULL, db.GetActiveDecoder()); | 215 EXPECT_EQ(NULL, db.GetActiveDecoder()); |
207 EXPECT_EQ(NULL, db.GetActiveCngDecoder()); | 216 EXPECT_EQ(NULL, db.GetActiveCngDecoder()); |
(...skipping 30 matching lines...) Expand all Loading... |
238 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(13)); | 247 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(13)); |
239 EXPECT_EQ(NULL, db.GetActiveCngDecoder()); | 248 EXPECT_EQ(NULL, db.GetActiveCngDecoder()); |
240 | 249 |
241 // Try to set non-existing codecs as active. | 250 // Try to set non-existing codecs as active. |
242 EXPECT_EQ(DecoderDatabase::kDecoderNotFound, | 251 EXPECT_EQ(DecoderDatabase::kDecoderNotFound, |
243 db.SetActiveDecoder(17, &changed)); | 252 db.SetActiveDecoder(17, &changed)); |
244 EXPECT_EQ(DecoderDatabase::kDecoderNotFound, | 253 EXPECT_EQ(DecoderDatabase::kDecoderNotFound, |
245 db.SetActiveCngDecoder(17)); | 254 db.SetActiveCngDecoder(17)); |
246 } | 255 } |
247 } // namespace webrtc | 256 } // namespace webrtc |
OLD | NEW |