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

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

Issue 1424083002: Make an enum class out of NetEqDecoder, and hide the neteq_decoders_ table (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 5 years, 1 month 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/timestamp_scaler.h" 11 #include "webrtc/modules/audio_coding/neteq/timestamp_scaler.h"
12 12
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webrtc/modules/audio_coding/neteq/mock/mock_decoder_database.h" 15 #include "webrtc/modules/audio_coding/neteq/mock/mock_decoder_database.h"
16 #include "webrtc/modules/audio_coding/neteq/packet.h" 16 #include "webrtc/modules/audio_coding/neteq/packet.h"
17 17
18 using ::testing::Return; 18 using ::testing::Return;
19 using ::testing::ReturnNull; 19 using ::testing::ReturnNull;
20 using ::testing::_; 20 using ::testing::_;
21 21
22 namespace webrtc { 22 namespace webrtc {
23 23
24 TEST(TimestampScaler, TestNoScaling) { 24 TEST(TimestampScaler, TestNoScaling) {
25 MockDecoderDatabase db; 25 MockDecoderDatabase db;
26 DecoderDatabase::DecoderInfo info; 26 DecoderDatabase::DecoderInfo info;
27 info.codec_type = kDecoderPCMu; // Does not use scaled timestamps. 27 info.codec_type =
28 NetEqDecoder::kDecoderPCMu; // Does not use scaled timestamps.
28 static const uint8_t kRtpPayloadType = 0; 29 static const uint8_t kRtpPayloadType = 0;
29 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType)) 30 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType))
30 .WillRepeatedly(Return(&info)); 31 .WillRepeatedly(Return(&info));
31 32
32 TimestampScaler scaler(db); 33 TimestampScaler scaler(db);
33 // Test both sides of the timestamp wrap-around. 34 // Test both sides of the timestamp wrap-around.
34 for (uint32_t timestamp = 0xFFFFFFFF - 5; timestamp != 5; ++timestamp) { 35 for (uint32_t timestamp = 0xFFFFFFFF - 5; timestamp != 5; ++timestamp) {
35 // Scale to internal timestamp. 36 // Scale to internal timestamp.
36 EXPECT_EQ(timestamp, scaler.ToInternal(timestamp, kRtpPayloadType)); 37 EXPECT_EQ(timestamp, scaler.ToInternal(timestamp, kRtpPayloadType));
37 // Scale back. 38 // Scale back.
38 EXPECT_EQ(timestamp, scaler.ToExternal(timestamp)); 39 EXPECT_EQ(timestamp, scaler.ToExternal(timestamp));
39 } 40 }
40 41
41 EXPECT_CALL(db, Die()); // Called when database object is deleted. 42 EXPECT_CALL(db, Die()); // Called when database object is deleted.
42 } 43 }
43 44
44 TEST(TimestampScaler, TestNoScalingLargeStep) { 45 TEST(TimestampScaler, TestNoScalingLargeStep) {
45 MockDecoderDatabase db; 46 MockDecoderDatabase db;
46 DecoderDatabase::DecoderInfo info; 47 DecoderDatabase::DecoderInfo info;
47 info.codec_type = kDecoderPCMu; // Does not use scaled timestamps. 48 info.codec_type =
49 NetEqDecoder::kDecoderPCMu; // Does not use scaled timestamps.
48 static const uint8_t kRtpPayloadType = 0; 50 static const uint8_t kRtpPayloadType = 0;
49 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType)) 51 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType))
50 .WillRepeatedly(Return(&info)); 52 .WillRepeatedly(Return(&info));
51 53
52 TimestampScaler scaler(db); 54 TimestampScaler scaler(db);
53 // Test both sides of the timestamp wrap-around. 55 // Test both sides of the timestamp wrap-around.
54 static const uint32_t kStep = 160; 56 static const uint32_t kStep = 160;
55 uint32_t start_timestamp = 0; 57 uint32_t start_timestamp = 0;
56 // |external_timestamp| will be a large positive value. 58 // |external_timestamp| will be a large positive value.
57 start_timestamp = start_timestamp - 5 * kStep; 59 start_timestamp = start_timestamp - 5 * kStep;
58 for (uint32_t timestamp = start_timestamp; timestamp != 5 * kStep; 60 for (uint32_t timestamp = start_timestamp; timestamp != 5 * kStep;
59 timestamp += kStep) { 61 timestamp += kStep) {
60 // Scale to internal timestamp. 62 // Scale to internal timestamp.
61 EXPECT_EQ(timestamp, scaler.ToInternal(timestamp, kRtpPayloadType)); 63 EXPECT_EQ(timestamp, scaler.ToInternal(timestamp, kRtpPayloadType));
62 // Scale back. 64 // Scale back.
63 EXPECT_EQ(timestamp, scaler.ToExternal(timestamp)); 65 EXPECT_EQ(timestamp, scaler.ToExternal(timestamp));
64 } 66 }
65 67
66 EXPECT_CALL(db, Die()); // Called when database object is deleted. 68 EXPECT_CALL(db, Die()); // Called when database object is deleted.
67 } 69 }
68 70
69 TEST(TimestampScaler, TestG722) { 71 TEST(TimestampScaler, TestG722) {
70 MockDecoderDatabase db; 72 MockDecoderDatabase db;
71 DecoderDatabase::DecoderInfo info; 73 DecoderDatabase::DecoderInfo info;
72 info.codec_type = kDecoderG722; // Uses a factor 2 scaling. 74 info.codec_type = NetEqDecoder::kDecoderG722; // Uses a factor 2 scaling.
73 static const uint8_t kRtpPayloadType = 17; 75 static const uint8_t kRtpPayloadType = 17;
74 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType)) 76 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType))
75 .WillRepeatedly(Return(&info)); 77 .WillRepeatedly(Return(&info));
76 78
77 TimestampScaler scaler(db); 79 TimestampScaler scaler(db);
78 // Test both sides of the timestamp wrap-around. 80 // Test both sides of the timestamp wrap-around.
79 uint32_t external_timestamp = 0xFFFFFFFF - 5; 81 uint32_t external_timestamp = 0xFFFFFFFF - 5;
80 uint32_t internal_timestamp = external_timestamp; 82 uint32_t internal_timestamp = external_timestamp;
81 for (; external_timestamp != 5; ++external_timestamp) { 83 for (; external_timestamp != 5; ++external_timestamp) {
82 // Scale to internal timestamp. 84 // Scale to internal timestamp.
83 EXPECT_EQ(internal_timestamp, 85 EXPECT_EQ(internal_timestamp,
84 scaler.ToInternal(external_timestamp, kRtpPayloadType)); 86 scaler.ToInternal(external_timestamp, kRtpPayloadType));
85 // Scale back. 87 // Scale back.
86 EXPECT_EQ(external_timestamp, scaler.ToExternal(internal_timestamp)); 88 EXPECT_EQ(external_timestamp, scaler.ToExternal(internal_timestamp));
87 internal_timestamp += 2; 89 internal_timestamp += 2;
88 } 90 }
89 91
90 EXPECT_CALL(db, Die()); // Called when database object is deleted. 92 EXPECT_CALL(db, Die()); // Called when database object is deleted.
91 } 93 }
92 94
93 TEST(TimestampScaler, TestG722LargeStep) { 95 TEST(TimestampScaler, TestG722LargeStep) {
94 MockDecoderDatabase db; 96 MockDecoderDatabase db;
95 DecoderDatabase::DecoderInfo info; 97 DecoderDatabase::DecoderInfo info;
96 info.codec_type = kDecoderG722; // Uses a factor 2 scaling. 98 info.codec_type = NetEqDecoder::kDecoderG722; // Uses a factor 2 scaling.
97 static const uint8_t kRtpPayloadType = 17; 99 static const uint8_t kRtpPayloadType = 17;
98 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType)) 100 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType))
99 .WillRepeatedly(Return(&info)); 101 .WillRepeatedly(Return(&info));
100 102
101 TimestampScaler scaler(db); 103 TimestampScaler scaler(db);
102 // Test both sides of the timestamp wrap-around. 104 // Test both sides of the timestamp wrap-around.
103 static const uint32_t kStep = 320; 105 static const uint32_t kStep = 320;
104 uint32_t external_timestamp = 0; 106 uint32_t external_timestamp = 0;
105 // |external_timestamp| will be a large positive value. 107 // |external_timestamp| will be a large positive value.
106 external_timestamp = external_timestamp - 5 * kStep; 108 external_timestamp = external_timestamp - 5 * kStep;
107 uint32_t internal_timestamp = external_timestamp; 109 uint32_t internal_timestamp = external_timestamp;
108 for (; external_timestamp != 5 * kStep; external_timestamp += kStep) { 110 for (; external_timestamp != 5 * kStep; external_timestamp += kStep) {
109 // Scale to internal timestamp. 111 // Scale to internal timestamp.
110 EXPECT_EQ(internal_timestamp, 112 EXPECT_EQ(internal_timestamp,
111 scaler.ToInternal(external_timestamp, kRtpPayloadType)); 113 scaler.ToInternal(external_timestamp, kRtpPayloadType));
112 // Scale back. 114 // Scale back.
113 EXPECT_EQ(external_timestamp, scaler.ToExternal(internal_timestamp)); 115 EXPECT_EQ(external_timestamp, scaler.ToExternal(internal_timestamp));
114 // Internal timestamp should be incremented with twice the step. 116 // Internal timestamp should be incremented with twice the step.
115 internal_timestamp += 2 * kStep; 117 internal_timestamp += 2 * kStep;
116 } 118 }
117 119
118 EXPECT_CALL(db, Die()); // Called when database object is deleted. 120 EXPECT_CALL(db, Die()); // Called when database object is deleted.
119 } 121 }
120 122
121 TEST(TimestampScaler, TestG722WithCng) { 123 TEST(TimestampScaler, TestG722WithCng) {
122 MockDecoderDatabase db; 124 MockDecoderDatabase db;
123 DecoderDatabase::DecoderInfo info_g722, info_cng; 125 DecoderDatabase::DecoderInfo info_g722, info_cng;
124 info_g722.codec_type = kDecoderG722; // Uses a factor 2 scaling. 126 info_g722.codec_type =
125 info_cng.codec_type = kDecoderCNGwb; 127 NetEqDecoder::kDecoderG722; // Uses a factor 2 scaling.
128 info_cng.codec_type = NetEqDecoder::kDecoderCNGwb;
126 static const uint8_t kRtpPayloadTypeG722 = 17; 129 static const uint8_t kRtpPayloadTypeG722 = 17;
127 static const uint8_t kRtpPayloadTypeCng = 13; 130 static const uint8_t kRtpPayloadTypeCng = 13;
128 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadTypeG722)) 131 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadTypeG722))
129 .WillRepeatedly(Return(&info_g722)); 132 .WillRepeatedly(Return(&info_g722));
130 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadTypeCng)) 133 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadTypeCng))
131 .WillRepeatedly(Return(&info_cng)); 134 .WillRepeatedly(Return(&info_cng));
132 135
133 TimestampScaler scaler(db); 136 TimestampScaler scaler(db);
134 // Test both sides of the timestamp wrap-around. 137 // Test both sides of the timestamp wrap-around.
135 uint32_t external_timestamp = 0xFFFFFFFF - 5; 138 uint32_t external_timestamp = 0xFFFFFFFF - 5;
(...skipping 19 matching lines...) Expand all
155 158
156 EXPECT_CALL(db, Die()); // Called when database object is deleted. 159 EXPECT_CALL(db, Die()); // Called when database object is deleted.
157 } 160 }
158 161
159 // Make sure that the method ToInternal(Packet* packet) is wired up correctly. 162 // Make sure that the method ToInternal(Packet* packet) is wired up correctly.
160 // Since it is simply calling the other ToInternal method, we are not doing 163 // Since it is simply calling the other ToInternal method, we are not doing
161 // as many tests here. 164 // as many tests here.
162 TEST(TimestampScaler, TestG722Packet) { 165 TEST(TimestampScaler, TestG722Packet) {
163 MockDecoderDatabase db; 166 MockDecoderDatabase db;
164 DecoderDatabase::DecoderInfo info; 167 DecoderDatabase::DecoderInfo info;
165 info.codec_type = kDecoderG722; // Does uses a factor 2 scaling. 168 info.codec_type =
169 NetEqDecoder::kDecoderG722; // Does uses a factor 2 scaling.
166 static const uint8_t kRtpPayloadType = 17; 170 static const uint8_t kRtpPayloadType = 17;
167 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType)) 171 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType))
168 .WillRepeatedly(Return(&info)); 172 .WillRepeatedly(Return(&info));
169 173
170 TimestampScaler scaler(db); 174 TimestampScaler scaler(db);
171 // Test both sides of the timestamp wrap-around. 175 // Test both sides of the timestamp wrap-around.
172 uint32_t external_timestamp = 0xFFFFFFFF - 5; 176 uint32_t external_timestamp = 0xFFFFFFFF - 5;
173 uint32_t internal_timestamp = external_timestamp; 177 uint32_t internal_timestamp = external_timestamp;
174 Packet packet; 178 Packet packet;
175 packet.header.payloadType = kRtpPayloadType; 179 packet.header.payloadType = kRtpPayloadType;
176 for (; external_timestamp != 5; ++external_timestamp) { 180 for (; external_timestamp != 5; ++external_timestamp) {
177 packet.header.timestamp = external_timestamp; 181 packet.header.timestamp = external_timestamp;
178 // Scale to internal timestamp. 182 // Scale to internal timestamp.
179 scaler.ToInternal(&packet); 183 scaler.ToInternal(&packet);
180 EXPECT_EQ(internal_timestamp, packet.header.timestamp); 184 EXPECT_EQ(internal_timestamp, packet.header.timestamp);
181 internal_timestamp += 2; 185 internal_timestamp += 2;
182 } 186 }
183 187
184 EXPECT_CALL(db, Die()); // Called when database object is deleted. 188 EXPECT_CALL(db, Die()); // Called when database object is deleted.
185 } 189 }
186 190
187 // Make sure that the method ToInternal(PacketList* packet_list) is wired up 191 // Make sure that the method ToInternal(PacketList* packet_list) is wired up
188 // correctly. Since it is simply calling the ToInternal(Packet* packet) method, 192 // correctly. Since it is simply calling the ToInternal(Packet* packet) method,
189 // we are not doing as many tests here. 193 // we are not doing as many tests here.
190 TEST(TimestampScaler, TestG722PacketList) { 194 TEST(TimestampScaler, TestG722PacketList) {
191 MockDecoderDatabase db; 195 MockDecoderDatabase db;
192 DecoderDatabase::DecoderInfo info; 196 DecoderDatabase::DecoderInfo info;
193 info.codec_type = kDecoderG722; // Uses a factor 2 scaling. 197 info.codec_type = NetEqDecoder::kDecoderG722; // Uses a factor 2 scaling.
194 static const uint8_t kRtpPayloadType = 17; 198 static const uint8_t kRtpPayloadType = 17;
195 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType)) 199 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType))
196 .WillRepeatedly(Return(&info)); 200 .WillRepeatedly(Return(&info));
197 201
198 TimestampScaler scaler(db); 202 TimestampScaler scaler(db);
199 // Test both sides of the timestamp wrap-around. 203 // Test both sides of the timestamp wrap-around.
200 uint32_t external_timestamp = 0xFFFFFFFF - 5; 204 uint32_t external_timestamp = 0xFFFFFFFF - 5;
201 uint32_t internal_timestamp = external_timestamp; 205 uint32_t internal_timestamp = external_timestamp;
202 Packet packet1; 206 Packet packet1;
203 packet1.header.payloadType = kRtpPayloadType; 207 packet1.header.payloadType = kRtpPayloadType;
204 packet1.header.timestamp = external_timestamp; 208 packet1.header.timestamp = external_timestamp;
205 Packet packet2; 209 Packet packet2;
206 packet2.header.payloadType = kRtpPayloadType; 210 packet2.header.payloadType = kRtpPayloadType;
207 packet2.header.timestamp = external_timestamp + 10; 211 packet2.header.timestamp = external_timestamp + 10;
208 PacketList packet_list; 212 PacketList packet_list;
209 packet_list.push_back(&packet1); 213 packet_list.push_back(&packet1);
210 packet_list.push_back(&packet2); 214 packet_list.push_back(&packet2);
211 215
212 scaler.ToInternal(&packet_list); 216 scaler.ToInternal(&packet_list);
213 EXPECT_EQ(internal_timestamp, packet1.header.timestamp); 217 EXPECT_EQ(internal_timestamp, packet1.header.timestamp);
214 EXPECT_EQ(internal_timestamp + 20, packet2.header.timestamp); 218 EXPECT_EQ(internal_timestamp + 20, packet2.header.timestamp);
215 219
216 EXPECT_CALL(db, Die()); // Called when database object is deleted. 220 EXPECT_CALL(db, Die()); // Called when database object is deleted.
217 } 221 }
218 222
219 TEST(TimestampScaler, TestG722Reset) { 223 TEST(TimestampScaler, TestG722Reset) {
220 MockDecoderDatabase db; 224 MockDecoderDatabase db;
221 DecoderDatabase::DecoderInfo info; 225 DecoderDatabase::DecoderInfo info;
222 info.codec_type = kDecoderG722; // Uses a factor 2 scaling. 226 info.codec_type = NetEqDecoder::kDecoderG722; // Uses a factor 2 scaling.
223 static const uint8_t kRtpPayloadType = 17; 227 static const uint8_t kRtpPayloadType = 17;
224 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType)) 228 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType))
225 .WillRepeatedly(Return(&info)); 229 .WillRepeatedly(Return(&info));
226 230
227 TimestampScaler scaler(db); 231 TimestampScaler scaler(db);
228 // Test both sides of the timestamp wrap-around. 232 // Test both sides of the timestamp wrap-around.
229 uint32_t external_timestamp = 0xFFFFFFFF - 5; 233 uint32_t external_timestamp = 0xFFFFFFFF - 5;
230 uint32_t internal_timestamp = external_timestamp; 234 uint32_t internal_timestamp = external_timestamp;
231 for (; external_timestamp != 5; ++external_timestamp) { 235 for (; external_timestamp != 5; ++external_timestamp) {
232 // Scale to internal timestamp. 236 // Scale to internal timestamp.
(...skipping 19 matching lines...) Expand all
252 EXPECT_CALL(db, Die()); // Called when database object is deleted. 256 EXPECT_CALL(db, Die()); // Called when database object is deleted.
253 } 257 }
254 258
255 // TODO(minyue): This test becomes trivial since Opus does not need a timestamp 259 // TODO(minyue): This test becomes trivial since Opus does not need a timestamp
256 // scaler. Therefore, this test may be removed in future. There is no harm to 260 // scaler. Therefore, this test may be removed in future. There is no harm to
257 // keep it, since it can be taken as a test case for the situation of a trivial 261 // keep it, since it can be taken as a test case for the situation of a trivial
258 // timestamp scaler. 262 // timestamp scaler.
259 TEST(TimestampScaler, TestOpusLargeStep) { 263 TEST(TimestampScaler, TestOpusLargeStep) {
260 MockDecoderDatabase db; 264 MockDecoderDatabase db;
261 DecoderDatabase::DecoderInfo info; 265 DecoderDatabase::DecoderInfo info;
262 info.codec_type = kDecoderOpus; 266 info.codec_type = NetEqDecoder::kDecoderOpus;
263 static const uint8_t kRtpPayloadType = 17; 267 static const uint8_t kRtpPayloadType = 17;
264 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType)) 268 EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType))
265 .WillRepeatedly(Return(&info)); 269 .WillRepeatedly(Return(&info));
266 270
267 TimestampScaler scaler(db); 271 TimestampScaler scaler(db);
268 // Test both sides of the timestamp wrap-around. 272 // Test both sides of the timestamp wrap-around.
269 static const uint32_t kStep = 960; 273 static const uint32_t kStep = 960;
270 uint32_t external_timestamp = 0; 274 uint32_t external_timestamp = 0;
271 // |external_timestamp| will be a large positive value. 275 // |external_timestamp| will be a large positive value.
272 external_timestamp = external_timestamp - 5 * kStep; 276 external_timestamp = external_timestamp - 5 * kStep;
(...skipping 20 matching lines...) Expand all
293 uint32_t timestamp = 4711; // Some number. 297 uint32_t timestamp = 4711; // Some number.
294 EXPECT_EQ(timestamp, scaler.ToInternal(timestamp, kRtpPayloadType)); 298 EXPECT_EQ(timestamp, scaler.ToInternal(timestamp, kRtpPayloadType));
295 299
296 Packet* packet = NULL; 300 Packet* packet = NULL;
297 scaler.ToInternal(packet); // Should not crash. That's all we can test. 301 scaler.ToInternal(packet); // Should not crash. That's all we can test.
298 302
299 EXPECT_CALL(db, Die()); // Called when database object is deleted. 303 EXPECT_CALL(db, Die()); // Called when database object is deleted.
300 } 304 }
301 305
302 } // namespace webrtc 306 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698