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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_payload_registry_unittest.cc

Issue 2516213002: RTPPayloadRegistry: Stop using the rate to keep track of receive codecs (Closed)
Patch Set: rewrite Created 4 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) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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 10 matching lines...) Expand all
21 namespace webrtc { 21 namespace webrtc {
22 22
23 using ::testing::Eq; 23 using ::testing::Eq;
24 using ::testing::Return; 24 using ::testing::Return;
25 using ::testing::StrEq; 25 using ::testing::StrEq;
26 using ::testing::_; 26 using ::testing::_;
27 27
28 static const char* kTypicalPayloadName = "name"; 28 static const char* kTypicalPayloadName = "name";
29 static const size_t kTypicalChannels = 1; 29 static const size_t kTypicalChannels = 1;
30 static const uint32_t kTypicalFrequency = 44000; 30 static const uint32_t kTypicalFrequency = 44000;
31 static const uint32_t kTypicalRate = 32 * 1024; 31 static const CodecInst kTypicalAudioCodec = {-1 /* pltype */, "name",
32 static const CodecInst kTypicalAudioCodec = {-1 /* pltype */, "name",
33 kTypicalFrequency, 0 /* pacsize */, 32 kTypicalFrequency, 0 /* pacsize */,
34 kTypicalChannels, kTypicalRate}; 33 kTypicalChannels};
35 34
36 TEST(RtpPayloadRegistryTest, 35 TEST(RtpPayloadRegistryTest,
37 RegistersAndRemembersVideoPayloadsUntilDeregistered) { 36 RegistersAndRemembersVideoPayloadsUntilDeregistered) {
38 RTPPayloadRegistry rtp_payload_registry; 37 RTPPayloadRegistry rtp_payload_registry;
39 const uint8_t payload_type = 97; 38 const uint8_t payload_type = 97;
40 VideoCodec video_codec; 39 VideoCodec video_codec;
41 video_codec.codecType = kVideoCodecVP8; 40 video_codec.codecType = kVideoCodecVP8;
42 strncpy(video_codec.plName, "VP8", RTP_PAYLOAD_NAME_SIZE); 41 strncpy(video_codec.plName, "VP8", RTP_PAYLOAD_NAME_SIZE);
43 video_codec.plType = payload_type; 42 video_codec.plType = payload_type;
44 43
(...skipping 27 matching lines...) Expand all
72 71
73 const RtpUtility::Payload* retrieved_payload = 72 const RtpUtility::Payload* retrieved_payload =
74 rtp_payload_registry.PayloadTypeToPayload(payload_type); 73 rtp_payload_registry.PayloadTypeToPayload(payload_type);
75 EXPECT_TRUE(retrieved_payload); 74 EXPECT_TRUE(retrieved_payload);
76 75
77 // We should get back the corresponding payload that we registered. 76 // We should get back the corresponding payload that we registered.
78 EXPECT_STREQ(kTypicalPayloadName, retrieved_payload->name); 77 EXPECT_STREQ(kTypicalPayloadName, retrieved_payload->name);
79 EXPECT_TRUE(retrieved_payload->audio); 78 EXPECT_TRUE(retrieved_payload->audio);
80 EXPECT_EQ(kTypicalFrequency, retrieved_payload->typeSpecific.Audio.frequency); 79 EXPECT_EQ(kTypicalFrequency, retrieved_payload->typeSpecific.Audio.frequency);
81 EXPECT_EQ(kTypicalChannels, retrieved_payload->typeSpecific.Audio.channels); 80 EXPECT_EQ(kTypicalChannels, retrieved_payload->typeSpecific.Audio.channels);
82 EXPECT_EQ(kTypicalRate, retrieved_payload->typeSpecific.Audio.rate);
83 81
84 // Now forget about it and verify it's gone. 82 // Now forget about it and verify it's gone.
85 EXPECT_EQ(0, rtp_payload_registry.DeRegisterReceivePayload(payload_type)); 83 EXPECT_EQ(0, rtp_payload_registry.DeRegisterReceivePayload(payload_type));
86 EXPECT_FALSE(rtp_payload_registry.PayloadTypeToPayload(payload_type)); 84 EXPECT_FALSE(rtp_payload_registry.PayloadTypeToPayload(payload_type));
87 } 85 }
88 86
89 TEST(RtpPayloadRegistryTest, AudioRedWorkProperly) { 87 TEST(RtpPayloadRegistryTest, AudioRedWorkProperly) {
90 const uint8_t kRedPayloadType = 127; 88 const uint8_t kRedPayloadType = 127;
91 const int kRedSampleRate = 8000; 89 const int kRedSampleRate = 8000;
92 const size_t kRedChannels = 1; 90 const size_t kRedChannels = 1;
93 const int kRedBitRate = 0;
94 91
95 RTPPayloadRegistry rtp_payload_registry; 92 RTPPayloadRegistry rtp_payload_registry;
96 93
97 bool new_payload_created = false; 94 bool new_payload_created = false;
98 CodecInst red_audio_codec; 95 CodecInst red_audio_codec;
99 strncpy(red_audio_codec.plname, "red", RTP_PAYLOAD_NAME_SIZE); 96 strncpy(red_audio_codec.plname, "red", RTP_PAYLOAD_NAME_SIZE);
100 red_audio_codec.pltype = kRedPayloadType; 97 red_audio_codec.pltype = kRedPayloadType;
101 red_audio_codec.plfreq = kRedSampleRate; 98 red_audio_codec.plfreq = kRedSampleRate;
102 red_audio_codec.channels = kRedChannels; 99 red_audio_codec.channels = kRedChannels;
103 red_audio_codec.rate = kRedBitRate;
104 EXPECT_EQ(0, rtp_payload_registry.RegisterReceivePayload( 100 EXPECT_EQ(0, rtp_payload_registry.RegisterReceivePayload(
105 red_audio_codec, &new_payload_created)); 101 red_audio_codec, &new_payload_created));
106 EXPECT_TRUE(new_payload_created); 102 EXPECT_TRUE(new_payload_created);
107 103
108 EXPECT_EQ(kRedPayloadType, rtp_payload_registry.red_payload_type()); 104 EXPECT_EQ(kRedPayloadType, rtp_payload_registry.red_payload_type());
109 105
110 const RtpUtility::Payload* retrieved_payload = 106 const RtpUtility::Payload* retrieved_payload =
111 rtp_payload_registry.PayloadTypeToPayload(kRedPayloadType); 107 rtp_payload_registry.PayloadTypeToPayload(kRedPayloadType);
112 EXPECT_TRUE(retrieved_payload); 108 EXPECT_TRUE(retrieved_payload);
113 EXPECT_TRUE(retrieved_payload->audio); 109 EXPECT_TRUE(retrieved_payload->audio);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 << "With a different payload type is fine though."; 141 << "With a different payload type is fine though.";
146 142
147 // Ensure both payloads are preserved. 143 // Ensure both payloads are preserved.
148 const RtpUtility::Payload* retrieved_payload = 144 const RtpUtility::Payload* retrieved_payload =
149 rtp_payload_registry.PayloadTypeToPayload(payload_type); 145 rtp_payload_registry.PayloadTypeToPayload(payload_type);
150 EXPECT_TRUE(retrieved_payload); 146 EXPECT_TRUE(retrieved_payload);
151 EXPECT_STREQ(kTypicalPayloadName, retrieved_payload->name); 147 EXPECT_STREQ(kTypicalPayloadName, retrieved_payload->name);
152 EXPECT_TRUE(retrieved_payload->audio); 148 EXPECT_TRUE(retrieved_payload->audio);
153 EXPECT_EQ(kTypicalFrequency, retrieved_payload->typeSpecific.Audio.frequency); 149 EXPECT_EQ(kTypicalFrequency, retrieved_payload->typeSpecific.Audio.frequency);
154 EXPECT_EQ(kTypicalChannels, retrieved_payload->typeSpecific.Audio.channels); 150 EXPECT_EQ(kTypicalChannels, retrieved_payload->typeSpecific.Audio.channels);
155 EXPECT_EQ(kTypicalRate, retrieved_payload->typeSpecific.Audio.rate);
156 151
157 retrieved_payload = 152 retrieved_payload =
158 rtp_payload_registry.PayloadTypeToPayload(payload_type - 1); 153 rtp_payload_registry.PayloadTypeToPayload(payload_type - 1);
159 EXPECT_TRUE(retrieved_payload); 154 EXPECT_TRUE(retrieved_payload);
160 EXPECT_STREQ(kTypicalPayloadName, retrieved_payload->name); 155 EXPECT_STREQ(kTypicalPayloadName, retrieved_payload->name);
161 EXPECT_TRUE(retrieved_payload->audio); 156 EXPECT_TRUE(retrieved_payload->audio);
162 EXPECT_EQ(kTypicalFrequency + 1, 157 EXPECT_EQ(kTypicalFrequency + 1,
163 retrieved_payload->typeSpecific.Audio.frequency); 158 retrieved_payload->typeSpecific.Audio.frequency);
164 EXPECT_EQ(kTypicalChannels, retrieved_payload->typeSpecific.Audio.channels); 159 EXPECT_EQ(kTypicalChannels, retrieved_payload->typeSpecific.Audio.channels);
165 EXPECT_EQ(kTypicalRate, retrieved_payload->typeSpecific.Audio.rate);
166 160
167 // Ok, update the rate for one of the codecs. If either the incoming rate or 161 // Ok, update the rate for one of the codecs. If either the incoming rate or
168 // the stored rate is zero it's not really an error to register the same 162 // the stored rate is zero it's not really an error to register the same
169 // codec twice, and in that case roughly the following happens. 163 // codec twice, and in that case roughly the following happens.
170 EXPECT_EQ(0, 164 EXPECT_EQ(0,
171 rtp_payload_registry.RegisterReceivePayload(audio_codec, &ignored)); 165 rtp_payload_registry.RegisterReceivePayload(audio_codec, &ignored));
172 } 166 }
173 167
174 TEST(RtpPayloadRegistryTest, 168 TEST(RtpPayloadRegistryTest,
175 RemovesCompatibleCodecsOnRegistryIfCodecsMustBeUnique) { 169 RemovesCompatibleCodecsOnRegistryIfCodecsMustBeUnique) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 TEST_P(ParameterizedRtpPayloadRegistryTest, 228 TEST_P(ParameterizedRtpPayloadRegistryTest,
235 FailsToRegisterKnownPayloadsWeAreNotInterestedIn) { 229 FailsToRegisterKnownPayloadsWeAreNotInterestedIn) {
236 RTPPayloadRegistry rtp_payload_registry; 230 RTPPayloadRegistry rtp_payload_registry;
237 231
238 bool ignored; 232 bool ignored;
239 CodecInst audio_codec; 233 CodecInst audio_codec;
240 strncpy(audio_codec.plname, "whatever", RTP_PAYLOAD_NAME_SIZE); 234 strncpy(audio_codec.plname, "whatever", RTP_PAYLOAD_NAME_SIZE);
241 audio_codec.pltype = GetParam(); 235 audio_codec.pltype = GetParam();
242 audio_codec.plfreq = 1900; 236 audio_codec.plfreq = 1900;
243 audio_codec.channels = 1; 237 audio_codec.channels = 1;
244 audio_codec.rate = 17;
245 EXPECT_EQ(-1, 238 EXPECT_EQ(-1,
246 rtp_payload_registry.RegisterReceivePayload(audio_codec, &ignored)); 239 rtp_payload_registry.RegisterReceivePayload(audio_codec, &ignored));
247 } 240 }
248 241
249 INSTANTIATE_TEST_CASE_P(TestKnownBadPayloadTypes, 242 INSTANTIATE_TEST_CASE_P(TestKnownBadPayloadTypes,
250 ParameterizedRtpPayloadRegistryTest, 243 ParameterizedRtpPayloadRegistryTest,
251 testing::Values(64, 72, 73, 74, 75, 76, 77, 78, 79)); 244 testing::Values(64, 72, 73, 74, 75, 76, 77, 78, 79));
252 245
253 class RtpPayloadRegistryGenericTest : public ::testing::TestWithParam<int> {}; 246 class RtpPayloadRegistryGenericTest : public ::testing::TestWithParam<int> {};
254 247
255 TEST_P(RtpPayloadRegistryGenericTest, RegisterGenericReceivePayloadType) { 248 TEST_P(RtpPayloadRegistryGenericTest, RegisterGenericReceivePayloadType) {
256 RTPPayloadRegistry rtp_payload_registry; 249 RTPPayloadRegistry rtp_payload_registry;
257 250
258 bool ignored; 251 bool ignored;
259 CodecInst audio_codec; 252 CodecInst audio_codec;
260 // Dummy values, except for payload_type. 253 // Dummy values, except for payload_type.
261 strncpy(audio_codec.plname, "generic-codec", RTP_PAYLOAD_NAME_SIZE); 254 strncpy(audio_codec.plname, "generic-codec", RTP_PAYLOAD_NAME_SIZE);
262 audio_codec.pltype = GetParam(); 255 audio_codec.pltype = GetParam();
263 audio_codec.plfreq = 1900; 256 audio_codec.plfreq = 1900;
264 audio_codec.channels = 1; 257 audio_codec.channels = 1;
265 audio_codec.rate = 17;
266 EXPECT_EQ(0, 258 EXPECT_EQ(0,
267 rtp_payload_registry.RegisterReceivePayload(audio_codec, &ignored)); 259 rtp_payload_registry.RegisterReceivePayload(audio_codec, &ignored));
268 } 260 }
269 261
270 // Generates an RTX packet for the given length and original sequence number. 262 // Generates an RTX packet for the given length and original sequence number.
271 // The RTX sequence number and ssrc will use the default value of 9999. The 263 // The RTX sequence number and ssrc will use the default value of 9999. The
272 // caller takes ownership of the returned buffer. 264 // caller takes ownership of the returned buffer.
273 const uint8_t* GenerateRtxPacket(size_t header_length, 265 const uint8_t* GenerateRtxPacket(size_t header_length,
274 size_t payload_length, 266 size_t payload_length,
275 uint16_t original_sequence_number) { 267 uint16_t original_sequence_number) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 rtp_payload_registry.SetRtxPayloadType(105, 95); 356 rtp_payload_registry.SetRtxPayloadType(105, 95);
365 TestRtxPacket(&rtp_payload_registry, 105, 95, true); 357 TestRtxPacket(&rtp_payload_registry, 105, 95, true);
366 TestRtxPacket(&rtp_payload_registry, 106, 0, false); 358 TestRtxPacket(&rtp_payload_registry, 106, 0, false);
367 } 359 }
368 360
369 INSTANTIATE_TEST_CASE_P(TestDynamicRange, 361 INSTANTIATE_TEST_CASE_P(TestDynamicRange,
370 RtpPayloadRegistryGenericTest, 362 RtpPayloadRegistryGenericTest,
371 testing::Range(96, 127 + 1)); 363 testing::Range(96, 127 + 1));
372 364
373 } // namespace webrtc 365 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc ('k') | webrtc/modules/rtp_rtcp/test/testAPI/test_api_audio.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698