| 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" | 22 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" |
| 23 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h" | 23 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h" |
| 24 | 24 |
| 25 using testing::_; |
| 26 using testing::Invoke; |
| 27 |
| 25 namespace webrtc { | 28 namespace webrtc { |
| 26 | 29 |
| 27 TEST(DecoderDatabase, CreateAndDestroy) { | 30 TEST(DecoderDatabase, CreateAndDestroy) { |
| 28 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>); | 31 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>); |
| 29 EXPECT_EQ(0, db.Size()); | 32 EXPECT_EQ(0, db.Size()); |
| 30 EXPECT_TRUE(db.Empty()); | 33 EXPECT_TRUE(db.Empty()); |
| 31 } | 34 } |
| 32 | 35 |
| 33 TEST(DecoderDatabase, InsertAndRemove) { | 36 TEST(DecoderDatabase, InsertAndRemove) { |
| 34 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>); | 37 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>); |
| 35 const uint8_t kPayloadType = 0; | 38 const uint8_t kPayloadType = 0; |
| 36 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; | 39 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; |
| 37 EXPECT_EQ( | 40 EXPECT_EQ( |
| 38 DecoderDatabase::kOK, | 41 DecoderDatabase::kOK, |
| 39 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName)); | 42 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName)); |
| 40 EXPECT_EQ(1, db.Size()); | 43 EXPECT_EQ(1, db.Size()); |
| 41 EXPECT_FALSE(db.Empty()); | 44 EXPECT_FALSE(db.Empty()); |
| 42 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType)); | 45 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType)); |
| 43 EXPECT_EQ(0, db.Size()); | 46 EXPECT_EQ(0, db.Size()); |
| 44 EXPECT_TRUE(db.Empty()); | 47 EXPECT_TRUE(db.Empty()); |
| 45 } | 48 } |
| 46 | 49 |
| 47 TEST(DecoderDatabase, GetDecoderInfo) { | 50 TEST(DecoderDatabase, GetDecoderInfo) { |
| 48 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>); | 51 rtc::scoped_refptr<MockAudioDecoderFactory> factory( |
| 52 new rtc::RefCountedObject<MockAudioDecoderFactory>); |
| 53 auto* decoder = new MockAudioDecoder; |
| 54 EXPECT_CALL(*factory, MakeAudioDecoderMock(_, _)) |
| 55 .WillOnce(Invoke([decoder](const SdpAudioFormat& format, |
| 56 std::unique_ptr<AudioDecoder>* dec) { |
| 57 EXPECT_EQ("pcmu", format.name); |
| 58 dec->reset(decoder); |
| 59 })); |
| 60 DecoderDatabase db(factory); |
| 49 const uint8_t kPayloadType = 0; | 61 const uint8_t kPayloadType = 0; |
| 50 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; | 62 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; |
| 51 EXPECT_EQ( | 63 EXPECT_EQ( |
| 52 DecoderDatabase::kOK, | 64 DecoderDatabase::kOK, |
| 53 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName)); | 65 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName)); |
| 54 const DecoderDatabase::DecoderInfo* info; | 66 const DecoderDatabase::DecoderInfo* info; |
| 55 info = db.GetDecoderInfo(kPayloadType); | 67 info = db.GetDecoderInfo(kPayloadType); |
| 56 ASSERT_TRUE(info != NULL); | 68 ASSERT_TRUE(info != NULL); |
| 57 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type); | 69 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type); |
| 58 EXPECT_EQ(nullptr, info->external_decoder); | |
| 59 EXPECT_EQ(8000, info->fs_hz); | |
| 60 EXPECT_EQ(kCodecName, info->name); | 70 EXPECT_EQ(kCodecName, info->name); |
| 71 EXPECT_EQ(decoder, db.GetDecoder(kPayloadType)); |
| 61 info = db.GetDecoderInfo(kPayloadType + 1); // Other payload type. | 72 info = db.GetDecoderInfo(kPayloadType + 1); // Other payload type. |
| 62 EXPECT_TRUE(info == NULL); // Should not be found. | 73 EXPECT_TRUE(info == NULL); // Should not be found. |
| 63 } | 74 } |
| 64 | 75 |
| 65 TEST(DecoderDatabase, GetRtpPayloadType) { | 76 TEST(DecoderDatabase, GetRtpPayloadType) { |
| 66 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>); | 77 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>); |
| 67 const uint8_t kPayloadType = 0; | 78 const uint8_t kPayloadType = 0; |
| 68 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; | 79 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; |
| 69 EXPECT_EQ( | 80 EXPECT_EQ( |
| 70 DecoderDatabase::kOK, | 81 DecoderDatabase::kOK, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 kCodecName, 8000, &decoder)); | 144 kCodecName, 8000, &decoder)); |
| 134 EXPECT_EQ(1, db.Size()); | 145 EXPECT_EQ(1, db.Size()); |
| 135 // Get decoder and make sure we get the external one. | 146 // Get decoder and make sure we get the external one. |
| 136 EXPECT_EQ(&decoder, db.GetDecoder(kPayloadType)); | 147 EXPECT_EQ(&decoder, db.GetDecoder(kPayloadType)); |
| 137 // Get the decoder info struct and check it too. | 148 // Get the decoder info struct and check it too. |
| 138 const DecoderDatabase::DecoderInfo* info; | 149 const DecoderDatabase::DecoderInfo* info; |
| 139 info = db.GetDecoderInfo(kPayloadType); | 150 info = db.GetDecoderInfo(kPayloadType); |
| 140 ASSERT_TRUE(info != NULL); | 151 ASSERT_TRUE(info != NULL); |
| 141 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type); | 152 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type); |
| 142 EXPECT_EQ(kCodecName, info->name); | 153 EXPECT_EQ(kCodecName, info->name); |
| 143 EXPECT_EQ(&decoder, info->external_decoder); | |
| 144 EXPECT_EQ(8000, info->fs_hz); | |
| 145 // Expect not to delete the decoder when removing it from the database, since | 154 // Expect not to delete the decoder when removing it from the database, since |
| 146 // it was declared externally. | 155 // it was declared externally. |
| 147 EXPECT_CALL(decoder, Die()).Times(0); | 156 EXPECT_CALL(decoder, Die()).Times(0); |
| 148 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType)); | 157 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType)); |
| 149 EXPECT_TRUE(db.Empty()); | 158 EXPECT_TRUE(db.Empty()); |
| 150 | 159 |
| 151 EXPECT_CALL(decoder, Die()).Times(1); // Will be called when |db| is deleted. | 160 EXPECT_CALL(decoder, Die()).Times(1); // Will be called when |db| is deleted. |
| 152 } | 161 } |
| 153 | 162 |
| 154 TEST(DecoderDatabase, CheckPayloadTypes) { | 163 TEST(DecoderDatabase, CheckPayloadTypes) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(13)); | 249 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(13)); |
| 241 EXPECT_EQ(NULL, db.GetActiveCngDecoder()); | 250 EXPECT_EQ(NULL, db.GetActiveCngDecoder()); |
| 242 | 251 |
| 243 // Try to set non-existing codecs as active. | 252 // Try to set non-existing codecs as active. |
| 244 EXPECT_EQ(DecoderDatabase::kDecoderNotFound, | 253 EXPECT_EQ(DecoderDatabase::kDecoderNotFound, |
| 245 db.SetActiveDecoder(17, &changed)); | 254 db.SetActiveDecoder(17, &changed)); |
| 246 EXPECT_EQ(DecoderDatabase::kDecoderNotFound, | 255 EXPECT_EQ(DecoderDatabase::kDecoderNotFound, |
| 247 db.SetActiveCngDecoder(17)); | 256 db.SetActiveCngDecoder(17)); |
| 248 } | 257 } |
| 249 } // namespace webrtc | 258 } // namespace webrtc |
| OLD | NEW |