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

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

Issue 1990803004: Turned AudioDecoderFactory into a RefCounted thing to use with scoped_refptr. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Removed AudioDecoderFactory destructor declaration. Created 4 years, 7 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
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 namespace webrtc { 25 namespace webrtc {
26 26
27 TEST(DecoderDatabase, CreateAndDestroy) { 27 TEST(DecoderDatabase, CreateAndDestroy) {
28 std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory); 28 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
29 DecoderDatabase db(std::move(factory));
30 EXPECT_EQ(0, db.Size()); 29 EXPECT_EQ(0, db.Size());
31 EXPECT_TRUE(db.Empty()); 30 EXPECT_TRUE(db.Empty());
32 } 31 }
33 32
34 TEST(DecoderDatabase, InsertAndRemove) { 33 TEST(DecoderDatabase, InsertAndRemove) {
35 std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory); 34 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
36 DecoderDatabase db(std::move(factory));
37 const uint8_t kPayloadType = 0; 35 const uint8_t kPayloadType = 0;
38 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; 36 const std::string kCodecName = "Robert\'); DROP TABLE Students;";
39 EXPECT_EQ( 37 EXPECT_EQ(
40 DecoderDatabase::kOK, 38 DecoderDatabase::kOK,
41 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName)); 39 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName));
42 EXPECT_EQ(1, db.Size()); 40 EXPECT_EQ(1, db.Size());
43 EXPECT_FALSE(db.Empty()); 41 EXPECT_FALSE(db.Empty());
44 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType)); 42 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType));
45 EXPECT_EQ(0, db.Size()); 43 EXPECT_EQ(0, db.Size());
46 EXPECT_TRUE(db.Empty()); 44 EXPECT_TRUE(db.Empty());
47 } 45 }
48 46
49 TEST(DecoderDatabase, GetDecoderInfo) { 47 TEST(DecoderDatabase, GetDecoderInfo) {
50 std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory); 48 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
51 DecoderDatabase db(std::move(factory));
52 const uint8_t kPayloadType = 0; 49 const uint8_t kPayloadType = 0;
53 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; 50 const std::string kCodecName = "Robert\'); DROP TABLE Students;";
54 EXPECT_EQ( 51 EXPECT_EQ(
55 DecoderDatabase::kOK, 52 DecoderDatabase::kOK,
56 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName)); 53 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName));
57 const DecoderDatabase::DecoderInfo* info; 54 const DecoderDatabase::DecoderInfo* info;
58 info = db.GetDecoderInfo(kPayloadType); 55 info = db.GetDecoderInfo(kPayloadType);
59 ASSERT_TRUE(info != NULL); 56 ASSERT_TRUE(info != NULL);
60 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type); 57 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type);
61 EXPECT_EQ(nullptr, info->external_decoder); 58 EXPECT_EQ(nullptr, info->external_decoder);
62 EXPECT_EQ(8000, info->fs_hz); 59 EXPECT_EQ(8000, info->fs_hz);
63 EXPECT_EQ(kCodecName, info->name); 60 EXPECT_EQ(kCodecName, info->name);
64 info = db.GetDecoderInfo(kPayloadType + 1); // Other payload type. 61 info = db.GetDecoderInfo(kPayloadType + 1); // Other payload type.
65 EXPECT_TRUE(info == NULL); // Should not be found. 62 EXPECT_TRUE(info == NULL); // Should not be found.
66 } 63 }
67 64
68 TEST(DecoderDatabase, GetRtpPayloadType) { 65 TEST(DecoderDatabase, GetRtpPayloadType) {
69 std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory); 66 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
70 DecoderDatabase db(std::move(factory));
71 const uint8_t kPayloadType = 0; 67 const uint8_t kPayloadType = 0;
72 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; 68 const std::string kCodecName = "Robert\'); DROP TABLE Students;";
73 EXPECT_EQ( 69 EXPECT_EQ(
74 DecoderDatabase::kOK, 70 DecoderDatabase::kOK,
75 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName)); 71 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCMu, kCodecName));
76 EXPECT_EQ(kPayloadType, db.GetRtpPayloadType(NetEqDecoder::kDecoderPCMu)); 72 EXPECT_EQ(kPayloadType, db.GetRtpPayloadType(NetEqDecoder::kDecoderPCMu));
77 const uint8_t expected_value = DecoderDatabase::kRtpPayloadTypeError; 73 const uint8_t expected_value = DecoderDatabase::kRtpPayloadTypeError;
78 EXPECT_EQ(expected_value, 74 EXPECT_EQ(expected_value,
79 db.GetRtpPayloadType( 75 db.GetRtpPayloadType(
80 NetEqDecoder::kDecoderISAC)); // iSAC is not registered. 76 NetEqDecoder::kDecoderISAC)); // iSAC is not registered.
81 } 77 }
82 78
83 TEST(DecoderDatabase, GetDecoder) { 79 TEST(DecoderDatabase, GetDecoder) {
84 DecoderDatabase db(CreateBuiltinAudioDecoderFactory()); 80 DecoderDatabase db(CreateBuiltinAudioDecoderFactory());
85 const uint8_t kPayloadType = 0; 81 const uint8_t kPayloadType = 0;
86 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; 82 const std::string kCodecName = "Robert\'); DROP TABLE Students;";
87 EXPECT_EQ(DecoderDatabase::kOK, 83 EXPECT_EQ(DecoderDatabase::kOK,
88 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCM16B, 84 db.RegisterPayload(kPayloadType, NetEqDecoder::kDecoderPCM16B,
89 kCodecName)); 85 kCodecName));
90 AudioDecoder* dec = db.GetDecoder(kPayloadType); 86 AudioDecoder* dec = db.GetDecoder(kPayloadType);
91 ASSERT_TRUE(dec != NULL); 87 ASSERT_TRUE(dec != NULL);
92 } 88 }
93 89
94 TEST(DecoderDatabase, TypeTests) { 90 TEST(DecoderDatabase, TypeTests) {
95 std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory); 91 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
96 DecoderDatabase db(std::move(factory));
97 const uint8_t kPayloadTypePcmU = 0; 92 const uint8_t kPayloadTypePcmU = 0;
98 const uint8_t kPayloadTypeCng = 13; 93 const uint8_t kPayloadTypeCng = 13;
99 const uint8_t kPayloadTypeDtmf = 100; 94 const uint8_t kPayloadTypeDtmf = 100;
100 const uint8_t kPayloadTypeRed = 101; 95 const uint8_t kPayloadTypeRed = 101;
101 const uint8_t kPayloadNotUsed = 102; 96 const uint8_t kPayloadNotUsed = 102;
102 // Load into database. 97 // Load into database.
103 EXPECT_EQ( 98 EXPECT_EQ(
104 DecoderDatabase::kOK, 99 DecoderDatabase::kOK,
105 db.RegisterPayload(kPayloadTypePcmU, NetEqDecoder::kDecoderPCMu, "pcmu")); 100 db.RegisterPayload(kPayloadTypePcmU, NetEqDecoder::kDecoderPCMu, "pcmu"));
106 EXPECT_EQ(DecoderDatabase::kOK, 101 EXPECT_EQ(DecoderDatabase::kOK,
(...skipping 14 matching lines...) Expand all
121 EXPECT_FALSE(db.IsDtmf(kPayloadTypePcmU)); 116 EXPECT_FALSE(db.IsDtmf(kPayloadTypePcmU));
122 EXPECT_FALSE(db.IsRed(kPayloadTypePcmU)); 117 EXPECT_FALSE(db.IsRed(kPayloadTypePcmU));
123 EXPECT_FALSE(db.IsType(kPayloadTypePcmU, NetEqDecoder::kDecoderISAC)); 118 EXPECT_FALSE(db.IsType(kPayloadTypePcmU, NetEqDecoder::kDecoderISAC));
124 EXPECT_TRUE(db.IsType(kPayloadTypePcmU, NetEqDecoder::kDecoderPCMu)); 119 EXPECT_TRUE(db.IsType(kPayloadTypePcmU, NetEqDecoder::kDecoderPCMu));
125 EXPECT_TRUE(db.IsComfortNoise(kPayloadTypeCng)); 120 EXPECT_TRUE(db.IsComfortNoise(kPayloadTypeCng));
126 EXPECT_TRUE(db.IsDtmf(kPayloadTypeDtmf)); 121 EXPECT_TRUE(db.IsDtmf(kPayloadTypeDtmf));
127 EXPECT_TRUE(db.IsRed(kPayloadTypeRed)); 122 EXPECT_TRUE(db.IsRed(kPayloadTypeRed));
128 } 123 }
129 124
130 TEST(DecoderDatabase, ExternalDecoder) { 125 TEST(DecoderDatabase, ExternalDecoder) {
131 std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory); 126 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
132 DecoderDatabase db(std::move(factory));
133 const uint8_t kPayloadType = 0; 127 const uint8_t kPayloadType = 0;
134 const std::string kCodecName = "Robert\'); DROP TABLE Students;"; 128 const std::string kCodecName = "Robert\'); DROP TABLE Students;";
135 MockAudioDecoder decoder; 129 MockAudioDecoder decoder;
136 // Load into database. 130 // Load into database.
137 EXPECT_EQ(DecoderDatabase::kOK, 131 EXPECT_EQ(DecoderDatabase::kOK,
138 db.InsertExternal(kPayloadType, NetEqDecoder::kDecoderPCMu, 132 db.InsertExternal(kPayloadType, NetEqDecoder::kDecoderPCMu,
139 kCodecName, 8000, &decoder)); 133 kCodecName, 8000, &decoder));
140 EXPECT_EQ(1, db.Size()); 134 EXPECT_EQ(1, db.Size());
141 // Get decoder and make sure we get the external one. 135 // Get decoder and make sure we get the external one.
142 EXPECT_EQ(&decoder, db.GetDecoder(kPayloadType)); 136 EXPECT_EQ(&decoder, db.GetDecoder(kPayloadType));
143 // Get the decoder info struct and check it too. 137 // Get the decoder info struct and check it too.
144 const DecoderDatabase::DecoderInfo* info; 138 const DecoderDatabase::DecoderInfo* info;
145 info = db.GetDecoderInfo(kPayloadType); 139 info = db.GetDecoderInfo(kPayloadType);
146 ASSERT_TRUE(info != NULL); 140 ASSERT_TRUE(info != NULL);
147 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type); 141 EXPECT_EQ(NetEqDecoder::kDecoderPCMu, info->codec_type);
148 EXPECT_EQ(kCodecName, info->name); 142 EXPECT_EQ(kCodecName, info->name);
149 EXPECT_EQ(&decoder, info->external_decoder); 143 EXPECT_EQ(&decoder, info->external_decoder);
150 EXPECT_EQ(8000, info->fs_hz); 144 EXPECT_EQ(8000, info->fs_hz);
151 // Expect not to delete the decoder when removing it from the database, since 145 // Expect not to delete the decoder when removing it from the database, since
152 // it was declared externally. 146 // it was declared externally.
153 EXPECT_CALL(decoder, Die()).Times(0); 147 EXPECT_CALL(decoder, Die()).Times(0);
154 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType)); 148 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(kPayloadType));
155 EXPECT_TRUE(db.Empty()); 149 EXPECT_TRUE(db.Empty());
156 150
157 EXPECT_CALL(decoder, Die()).Times(1); // Will be called when |db| is deleted. 151 EXPECT_CALL(decoder, Die()).Times(1); // Will be called when |db| is deleted.
158 } 152 }
159 153
160 TEST(DecoderDatabase, CheckPayloadTypes) { 154 TEST(DecoderDatabase, CheckPayloadTypes) {
161 std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory); 155 DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
162 DecoderDatabase db(std::move(factory));
163 // Load a number of payloads into the database. Payload types are 0, 1, ..., 156 // Load a number of payloads into the database. Payload types are 0, 1, ...,
164 // while the decoder type is the same for all payload types (this does not 157 // while the decoder type is the same for all payload types (this does not
165 // matter for the test). 158 // matter for the test).
166 const int kNumPayloads = 10; 159 const int kNumPayloads = 10;
167 for (uint8_t payload_type = 0; payload_type < kNumPayloads; ++payload_type) { 160 for (uint8_t payload_type = 0; payload_type < kNumPayloads; ++payload_type) {
168 EXPECT_EQ( 161 EXPECT_EQ(
169 DecoderDatabase::kOK, 162 DecoderDatabase::kOK,
170 db.RegisterPayload(payload_type, NetEqDecoder::kDecoderArbitrary, "")); 163 db.RegisterPayload(payload_type, NetEqDecoder::kDecoderArbitrary, ""));
171 } 164 }
172 PacketList packet_list; 165 PacketList packet_list;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(13)); 240 EXPECT_EQ(DecoderDatabase::kOK, db.Remove(13));
248 EXPECT_EQ(NULL, db.GetActiveCngDecoder()); 241 EXPECT_EQ(NULL, db.GetActiveCngDecoder());
249 242
250 // Try to set non-existing codecs as active. 243 // Try to set non-existing codecs as active.
251 EXPECT_EQ(DecoderDatabase::kDecoderNotFound, 244 EXPECT_EQ(DecoderDatabase::kDecoderNotFound,
252 db.SetActiveDecoder(17, &changed)); 245 db.SetActiveDecoder(17, &changed));
253 EXPECT_EQ(DecoderDatabase::kDecoderNotFound, 246 EXPECT_EQ(DecoderDatabase::kDecoderNotFound,
254 db.SetActiveCngDecoder(17)); 247 db.SetActiveCngDecoder(17));
255 } 248 }
256 } // namespace webrtc 249 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/decoder_database.cc ('k') | webrtc/modules/audio_coding/neteq/payload_splitter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698