Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "webrtc/common_types.h" | |
| 13 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | 14 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
| 14 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" | 15 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" |
| 15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 16 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| 16 #include "webrtc/modules/rtp_rtcp/source/mock/mock_rtp_payload_strategy.h" | 17 #include "webrtc/modules/rtp_rtcp/source/mock/mock_rtp_payload_strategy.h" |
| 17 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 18 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
| 18 #include "webrtc/test/gmock.h" | 19 #include "webrtc/test/gmock.h" |
| 19 #include "webrtc/test/gtest.h" | 20 #include "webrtc/test/gtest.h" |
| 20 | 21 |
| 21 namespace webrtc { | 22 namespace webrtc { |
| 22 | 23 |
| 23 using ::testing::Eq; | 24 using ::testing::Eq; |
| 24 using ::testing::Return; | 25 using ::testing::Return; |
| 26 using ::testing::StrEq; | |
| 25 using ::testing::_; | 27 using ::testing::_; |
| 26 | 28 |
| 27 static const char* kTypicalPayloadName = "name"; | 29 static const char* kTypicalPayloadName = "name"; |
| 28 static const size_t kTypicalChannels = 1; | 30 static const size_t kTypicalChannels = 1; |
| 29 static const int kTypicalFrequency = 44000; | 31 static const int kTypicalFrequency = 44000; |
| 30 static const int kTypicalRate = 32 * 1024; | 32 static const int kTypicalRate = 32 * 1024; |
| 33 static const CodecInst kTypicalAudioCodec = {-1 /* pltype */, "name", | |
| 34 kTypicalFrequency, 0 /* pacsize */, | |
| 35 kTypicalChannels, kTypicalRate}; | |
| 31 | 36 |
| 32 class RtpPayloadRegistryTest : public ::testing::Test { | 37 class RtpPayloadRegistryTest : public ::testing::Test { |
| 33 public: | 38 public: |
| 34 void SetUp() { | 39 void SetUp() { |
| 35 // Note: the payload registry takes ownership of the strategy. | 40 // Note: the payload registry takes ownership of the strategy. |
| 36 mock_payload_strategy_ = new testing::NiceMock<MockRTPPayloadStrategy>(); | 41 mock_payload_strategy_ = new testing::NiceMock<MockRTPPayloadStrategy>(); |
| 37 rtp_payload_registry_.reset(new RTPPayloadRegistry(mock_payload_strategy_)); | 42 rtp_payload_registry_.reset(new RTPPayloadRegistry(mock_payload_strategy_)); |
| 38 } | 43 } |
| 39 | 44 |
| 40 protected: | 45 protected: |
| 41 RtpUtility::Payload* ExpectReturnOfTypicalAudioPayload(uint8_t payload_type, | 46 RtpUtility::Payload* ExpectReturnOfTypicalAudioPayload(uint8_t payload_type, |
| 42 uint32_t rate) { | 47 uint32_t rate) { |
| 43 bool audio = true; | 48 bool audio = true; |
| 44 RtpUtility::Payload returned_payload = { | 49 RtpUtility::Payload returned_payload = { |
| 45 "name", | 50 "name", |
| 46 audio, | 51 audio, |
| 47 {// Initialize the audio struct in this case. | 52 {// Initialize the audio struct in this case. |
| 48 {kTypicalFrequency, kTypicalChannels, rate}}}; | 53 {kTypicalFrequency, kTypicalChannels, rate}}}; |
| 49 | 54 |
| 50 // Note: we return a new payload since the payload registry takes ownership | 55 // Note: we return a new payload since the payload registry takes ownership |
| 51 // of the created object. | 56 // of the created object. |
| 52 RtpUtility::Payload* returned_payload_on_heap = | 57 RtpUtility::Payload* returned_payload_on_heap = |
| 53 new RtpUtility::Payload(returned_payload); | 58 new RtpUtility::Payload(returned_payload); |
| 54 EXPECT_CALL(*mock_payload_strategy_, | 59 EXPECT_CALL(*mock_payload_strategy_, |
| 55 CreatePayloadType(kTypicalPayloadName, payload_type, | 60 CreatePayloadType(StrEq(kTypicalPayloadName), payload_type, |
| 56 kTypicalFrequency, kTypicalChannels, rate)) | 61 kTypicalFrequency, kTypicalChannels, rate)) |
| 57 .WillOnce(Return(returned_payload_on_heap)); | 62 .WillOnce(Return(returned_payload_on_heap)); |
| 58 return returned_payload_on_heap; | 63 return returned_payload_on_heap; |
| 59 } | 64 } |
| 60 | 65 |
| 61 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_; | 66 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_; |
| 62 testing::NiceMock<MockRTPPayloadStrategy>* mock_payload_strategy_; | 67 testing::NiceMock<MockRTPPayloadStrategy>* mock_payload_strategy_; |
| 63 }; | 68 }; |
| 64 | 69 |
| 65 TEST_F(RtpPayloadRegistryTest, RegistersAndRemembersPayloadsUntilDeregistered) { | 70 TEST_F(RtpPayloadRegistryTest, |
| 71 RegistersAndRemembersVideoPayloadsUntilDeregistered) { | |
| 72 const uint8_t payload_type = 97; | |
| 73 RtpUtility::Payload returned_video_payload = { | |
| 74 "VP8", false /* audio */, {{kRtpVideoVp8}}}; | |
| 75 // Note: The payload registry takes ownership of this object in | |
| 76 // RegisterReceivePayload. | |
| 77 RtpUtility::Payload* returned_video_payload_on_heap = | |
| 78 new RtpUtility::Payload(returned_video_payload); | |
| 79 EXPECT_CALL( | |
| 80 *mock_payload_strategy_, | |
| 81 CreatePayloadType(StrEq("VP8"), payload_type, kVideoPayloadTypeFrequency, | |
| 82 0 /* channels */, 0 /* rate */)) | |
| 83 .WillOnce(Return(returned_video_payload_on_heap)); | |
| 84 | |
| 85 VideoCodec video_codec; | |
| 86 video_codec.codecType = kVideoCodecVP8; | |
| 87 strcpy(video_codec.plName, "VP8"); | |
| 88 video_codec.plType = payload_type; | |
| 89 | |
| 90 EXPECT_EQ(0, rtp_payload_registry_->RegisterReceivePayload(video_codec)); | |
| 91 | |
| 92 const RtpUtility::Payload* retrieved_payload = | |
| 93 rtp_payload_registry_->PayloadTypeToPayload(payload_type); | |
| 94 EXPECT_TRUE(retrieved_payload); | |
| 95 | |
| 96 // We should get back the exact pointer to the payload returned by the | |
| 97 // payload strategy. | |
| 98 EXPECT_EQ(returned_video_payload_on_heap, retrieved_payload); | |
| 99 | |
| 100 // Now forget about it and verify it's gone. | |
| 101 EXPECT_EQ(0, rtp_payload_registry_->DeRegisterReceivePayload(payload_type)); | |
| 102 EXPECT_FALSE(rtp_payload_registry_->PayloadTypeToPayload(payload_type)); | |
| 103 } | |
| 104 | |
| 105 TEST_F(RtpPayloadRegistryTest, | |
| 106 RegistersAndRemembersAudioPayloadsUntilDeregistered) { | |
| 66 uint8_t payload_type = 97; | 107 uint8_t payload_type = 97; |
| 67 RtpUtility::Payload* returned_payload_on_heap = | 108 RtpUtility::Payload* returned_payload_on_heap = |
| 68 ExpectReturnOfTypicalAudioPayload(payload_type, kTypicalRate); | 109 ExpectReturnOfTypicalAudioPayload(payload_type, kTypicalRate); |
| 69 | 110 |
| 70 bool new_payload_created = false; | 111 bool new_payload_created = false; |
| 112 CodecInst audio_codec = kTypicalAudioCodec; | |
| 113 audio_codec.pltype = payload_type; | |
| 71 EXPECT_EQ(0, rtp_payload_registry_->RegisterReceivePayload( | 114 EXPECT_EQ(0, rtp_payload_registry_->RegisterReceivePayload( |
| 72 kTypicalPayloadName, payload_type, kTypicalFrequency, | 115 audio_codec, &new_payload_created)); |
| 73 kTypicalChannels, kTypicalRate, &new_payload_created)); | |
| 74 | 116 |
| 75 EXPECT_TRUE(new_payload_created) << "A new payload WAS created."; | 117 EXPECT_TRUE(new_payload_created) << "A new payload WAS created."; |
| 76 | 118 |
| 77 const RtpUtility::Payload* retrieved_payload = | 119 const RtpUtility::Payload* retrieved_payload = |
| 78 rtp_payload_registry_->PayloadTypeToPayload(payload_type); | 120 rtp_payload_registry_->PayloadTypeToPayload(payload_type); |
| 79 EXPECT_TRUE(retrieved_payload); | 121 EXPECT_TRUE(retrieved_payload); |
| 80 | 122 |
| 81 // We should get back the exact pointer to the payload returned by the | 123 // We should get back the exact pointer to the payload returned by the |
| 82 // payload strategy. | 124 // payload strategy. |
| 83 EXPECT_EQ(returned_payload_on_heap, retrieved_payload); | 125 EXPECT_EQ(returned_payload_on_heap, retrieved_payload); |
| 84 | 126 |
| 85 // Now forget about it and verify it's gone. | 127 // Now forget about it and verify it's gone. |
| 86 EXPECT_EQ(0, rtp_payload_registry_->DeRegisterReceivePayload(payload_type)); | 128 EXPECT_EQ(0, rtp_payload_registry_->DeRegisterReceivePayload(payload_type)); |
| 87 EXPECT_FALSE(rtp_payload_registry_->PayloadTypeToPayload(payload_type)); | 129 EXPECT_FALSE(rtp_payload_registry_->PayloadTypeToPayload(payload_type)); |
| 88 } | 130 } |
| 89 | 131 |
| 90 TEST_F(RtpPayloadRegistryTest, AudioRedWorkProperly) { | 132 TEST_F(RtpPayloadRegistryTest, AudioRedWorkProperly) { |
| 91 const uint8_t kRedPayloadType = 127; | 133 const uint8_t kRedPayloadType = 127; |
| 92 const int kRedSampleRate = 8000; | 134 const int kRedSampleRate = 8000; |
| 93 const size_t kRedChannels = 1; | 135 const size_t kRedChannels = 1; |
| 94 const int kRedBitRate = 0; | 136 const int kRedBitRate = 0; |
| 95 | 137 |
| 96 // This creates an audio RTP payload strategy. | 138 // This creates an audio RTP payload strategy. |
| 97 rtp_payload_registry_.reset( | 139 rtp_payload_registry_.reset( |
| 98 new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(true))); | 140 new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(true))); |
| 99 | 141 |
| 100 bool new_payload_created = false; | 142 bool new_payload_created = false; |
| 143 CodecInst red_audio_codec; | |
| 144 strcpy(red_audio_codec.plname, "red"); | |
| 145 red_audio_codec.pltype = kRedPayloadType; | |
| 146 red_audio_codec.plfreq = kRedSampleRate; | |
| 147 red_audio_codec.channels = kRedChannels; | |
| 148 red_audio_codec.rate = kRedBitRate; | |
| 101 EXPECT_EQ(0, rtp_payload_registry_->RegisterReceivePayload( | 149 EXPECT_EQ(0, rtp_payload_registry_->RegisterReceivePayload( |
| 102 "red", kRedPayloadType, kRedSampleRate, kRedChannels, | 150 red_audio_codec, &new_payload_created)); |
| 103 kRedBitRate, &new_payload_created)); | |
| 104 EXPECT_TRUE(new_payload_created); | 151 EXPECT_TRUE(new_payload_created); |
| 105 | 152 |
| 106 EXPECT_EQ(kRedPayloadType, rtp_payload_registry_->red_payload_type()); | 153 EXPECT_EQ(kRedPayloadType, rtp_payload_registry_->red_payload_type()); |
| 107 | 154 |
| 108 const RtpUtility::Payload* retrieved_payload = | 155 const RtpUtility::Payload* retrieved_payload = |
| 109 rtp_payload_registry_->PayloadTypeToPayload(kRedPayloadType); | 156 rtp_payload_registry_->PayloadTypeToPayload(kRedPayloadType); |
| 110 EXPECT_TRUE(retrieved_payload); | 157 EXPECT_TRUE(retrieved_payload); |
| 111 EXPECT_TRUE(retrieved_payload->audio); | 158 EXPECT_TRUE(retrieved_payload->audio); |
| 112 EXPECT_STRCASEEQ("red", retrieved_payload->name); | 159 EXPECT_STRCASEEQ("red", retrieved_payload->name); |
| 113 | 160 |
| 114 // Sample rate is correctly registered. | 161 // Sample rate is correctly registered. |
| 115 EXPECT_EQ(kRedSampleRate, | 162 EXPECT_EQ(kRedSampleRate, |
| 116 rtp_payload_registry_->GetPayloadTypeFrequency(kRedPayloadType)); | 163 rtp_payload_registry_->GetPayloadTypeFrequency(kRedPayloadType)); |
| 117 } | 164 } |
| 118 | 165 |
| 119 TEST_F(RtpPayloadRegistryTest, | 166 TEST_F(RtpPayloadRegistryTest, |
| 120 DoesNotAcceptSamePayloadTypeTwiceExceptIfPayloadIsCompatible) { | 167 DoesNotAcceptSamePayloadTypeTwiceExceptIfPayloadIsCompatible) { |
| 121 uint8_t payload_type = 97; | 168 uint8_t payload_type = 97; |
| 122 | 169 |
| 123 bool ignored = false; | 170 bool ignored = false; |
| 124 RtpUtility::Payload* first_payload_on_heap = | 171 RtpUtility::Payload* first_payload_on_heap = |
| 125 ExpectReturnOfTypicalAudioPayload(payload_type, kTypicalRate); | 172 ExpectReturnOfTypicalAudioPayload(payload_type, kTypicalRate); |
| 126 EXPECT_EQ(0, rtp_payload_registry_->RegisterReceivePayload( | 173 CodecInst audio_codec = kTypicalAudioCodec; |
| 127 kTypicalPayloadName, payload_type, kTypicalFrequency, | 174 audio_codec.pltype = payload_type; |
| 128 kTypicalChannels, kTypicalRate, &ignored)); | 175 EXPECT_EQ( |
| 176 0, rtp_payload_registry_->RegisterReceivePayload(audio_codec, &ignored)); | |
| 129 | 177 |
| 130 EXPECT_EQ(-1, rtp_payload_registry_->RegisterReceivePayload( | 178 EXPECT_EQ( |
| 131 kTypicalPayloadName, payload_type, kTypicalFrequency, | 179 -1, rtp_payload_registry_->RegisterReceivePayload(audio_codec, &ignored)) |
| 132 kTypicalChannels, kTypicalRate, &ignored)) | |
| 133 << "Adding same codec twice = bad."; | 180 << "Adding same codec twice = bad."; |
| 134 | 181 |
| 135 RtpUtility::Payload* second_payload_on_heap = | 182 RtpUtility::Payload* second_payload_on_heap = |
| 136 ExpectReturnOfTypicalAudioPayload(payload_type - 1, kTypicalRate); | 183 ExpectReturnOfTypicalAudioPayload(payload_type - 1, kTypicalRate); |
| 137 EXPECT_EQ(0, rtp_payload_registry_->RegisterReceivePayload( | 184 CodecInst audio_codec_2 = kTypicalAudioCodec; |
| 138 kTypicalPayloadName, payload_type - 1, kTypicalFrequency, | 185 audio_codec_2.pltype = payload_type - 1; |
| 139 kTypicalChannels, kTypicalRate, &ignored)) | 186 EXPECT_EQ( |
| 187 0, rtp_payload_registry_->RegisterReceivePayload(audio_codec_2, &ignored)) | |
| 140 << "With a different payload type is fine though."; | 188 << "With a different payload type is fine though."; |
| 141 | 189 |
| 142 // Ensure both payloads are preserved. | 190 // Ensure both payloads are preserved. |
| 143 const RtpUtility::Payload* retrieved_payload = | 191 const RtpUtility::Payload* retrieved_payload = |
| 144 rtp_payload_registry_->PayloadTypeToPayload(payload_type); | 192 rtp_payload_registry_->PayloadTypeToPayload(payload_type); |
| 145 EXPECT_TRUE(retrieved_payload); | 193 EXPECT_TRUE(retrieved_payload); |
| 146 EXPECT_EQ(first_payload_on_heap, retrieved_payload); | 194 EXPECT_EQ(first_payload_on_heap, retrieved_payload); |
| 147 retrieved_payload = | 195 retrieved_payload = |
| 148 rtp_payload_registry_->PayloadTypeToPayload(payload_type - 1); | 196 rtp_payload_registry_->PayloadTypeToPayload(payload_type - 1); |
| 149 EXPECT_TRUE(retrieved_payload); | 197 EXPECT_TRUE(retrieved_payload); |
| 150 EXPECT_EQ(second_payload_on_heap, retrieved_payload); | 198 EXPECT_EQ(second_payload_on_heap, retrieved_payload); |
| 151 | 199 |
| 152 // Ok, update the rate for one of the codecs. If either the incoming rate or | 200 // Ok, update the rate for one of the codecs. If either the incoming rate or |
| 153 // the stored rate is zero it's not really an error to register the same | 201 // the stored rate is zero it's not really an error to register the same |
| 154 // codec twice, and in that case roughly the following happens. | 202 // codec twice, and in that case roughly the following happens. |
| 155 ON_CALL(*mock_payload_strategy_, PayloadIsCompatible(_, _, _, _)) | 203 ON_CALL(*mock_payload_strategy_, PayloadIsCompatible(_, _, _, _)) |
| 156 .WillByDefault(Return(true)); | 204 .WillByDefault(Return(true)); |
| 157 EXPECT_CALL(*mock_payload_strategy_, | 205 EXPECT_CALL(*mock_payload_strategy_, |
| 158 UpdatePayloadRate(first_payload_on_heap, kTypicalRate)); | 206 UpdatePayloadRate(first_payload_on_heap, kTypicalRate)); |
| 159 EXPECT_EQ(0, rtp_payload_registry_->RegisterReceivePayload( | 207 EXPECT_EQ( |
| 160 kTypicalPayloadName, payload_type, kTypicalFrequency, | 208 0, rtp_payload_registry_->RegisterReceivePayload(audio_codec, &ignored)); |
| 161 kTypicalChannels, kTypicalRate, &ignored)); | |
| 162 } | 209 } |
| 163 | 210 |
| 164 TEST_F(RtpPayloadRegistryTest, | 211 TEST_F(RtpPayloadRegistryTest, |
| 165 RemovesCompatibleCodecsOnRegistryIfCodecsMustBeUnique) { | 212 RemovesCompatibleCodecsOnRegistryIfCodecsMustBeUnique) { |
| 166 ON_CALL(*mock_payload_strategy_, PayloadIsCompatible(_, _, _, _)) | 213 ON_CALL(*mock_payload_strategy_, PayloadIsCompatible(_, _, _, _)) |
| 167 .WillByDefault(Return(true)); | 214 .WillByDefault(Return(true)); |
| 168 ON_CALL(*mock_payload_strategy_, CodecsMustBeUnique()) | 215 ON_CALL(*mock_payload_strategy_, CodecsMustBeUnique()) |
| 169 .WillByDefault(Return(true)); | 216 .WillByDefault(Return(true)); |
| 170 | 217 |
| 171 uint8_t payload_type = 97; | 218 uint8_t payload_type = 97; |
| 172 | 219 |
| 173 bool ignored = false; | 220 bool ignored = false; |
| 174 ExpectReturnOfTypicalAudioPayload(payload_type, kTypicalRate); | 221 ExpectReturnOfTypicalAudioPayload(payload_type, kTypicalRate); |
| 175 EXPECT_EQ(0, rtp_payload_registry_->RegisterReceivePayload( | 222 CodecInst audio_codec = kTypicalAudioCodec; |
| 176 kTypicalPayloadName, payload_type, kTypicalFrequency, | 223 audio_codec.pltype = payload_type; |
| 177 kTypicalChannels, kTypicalRate, &ignored)); | 224 EXPECT_EQ( |
| 225 0, rtp_payload_registry_->RegisterReceivePayload(audio_codec, &ignored)); | |
| 178 ExpectReturnOfTypicalAudioPayload(payload_type - 1, kTypicalRate); | 226 ExpectReturnOfTypicalAudioPayload(payload_type - 1, kTypicalRate); |
| 179 EXPECT_EQ(0, rtp_payload_registry_->RegisterReceivePayload( | 227 CodecInst audio_codec_2 = kTypicalAudioCodec; |
| 180 kTypicalPayloadName, payload_type - 1, kTypicalFrequency, | 228 audio_codec_2.pltype = payload_type - 1; |
| 181 kTypicalChannels, kTypicalRate, &ignored)); | 229 EXPECT_EQ(0, rtp_payload_registry_->RegisterReceivePayload(audio_codec_2, |
| 230 &ignored)); | |
| 182 | 231 |
| 183 EXPECT_FALSE(rtp_payload_registry_->PayloadTypeToPayload(payload_type)) | 232 EXPECT_FALSE(rtp_payload_registry_->PayloadTypeToPayload(payload_type)) |
| 184 << "The first payload should be " | 233 << "The first payload should be " |
| 185 "deregistered because the only thing that differs is payload type."; | 234 "deregistered because the only thing that differs is payload type."; |
| 186 EXPECT_TRUE(rtp_payload_registry_->PayloadTypeToPayload(payload_type - 1)) | 235 EXPECT_TRUE(rtp_payload_registry_->PayloadTypeToPayload(payload_type - 1)) |
| 187 << "The second payload should still be registered though."; | 236 << "The second payload should still be registered though."; |
| 188 | 237 |
| 189 // Now ensure non-compatible codecs aren't removed. | 238 // Now ensure non-compatible codecs aren't removed. |
| 190 ON_CALL(*mock_payload_strategy_, PayloadIsCompatible(_, _, _, _)) | 239 ON_CALL(*mock_payload_strategy_, PayloadIsCompatible(_, _, _, _)) |
| 191 .WillByDefault(Return(false)); | 240 .WillByDefault(Return(false)); |
| 192 ExpectReturnOfTypicalAudioPayload(payload_type + 1, kTypicalRate); | 241 ExpectReturnOfTypicalAudioPayload(payload_type + 1, kTypicalRate); |
| 193 EXPECT_EQ(0, rtp_payload_registry_->RegisterReceivePayload( | 242 CodecInst audio_codec_3 = kTypicalAudioCodec; |
| 194 kTypicalPayloadName, payload_type + 1, kTypicalFrequency, | 243 audio_codec_3.pltype = payload_type + 1; |
| 195 kTypicalChannels, kTypicalRate, &ignored)); | 244 EXPECT_EQ(0, rtp_payload_registry_->RegisterReceivePayload(audio_codec_3, |
| 245 &ignored)); | |
| 196 | 246 |
| 197 EXPECT_TRUE(rtp_payload_registry_->PayloadTypeToPayload(payload_type - 1)) | 247 EXPECT_TRUE(rtp_payload_registry_->PayloadTypeToPayload(payload_type - 1)) |
| 198 << "Not compatible; both payloads should be kept."; | 248 << "Not compatible; both payloads should be kept."; |
| 199 EXPECT_TRUE(rtp_payload_registry_->PayloadTypeToPayload(payload_type + 1)) | 249 EXPECT_TRUE(rtp_payload_registry_->PayloadTypeToPayload(payload_type + 1)) |
| 200 << "Not compatible; both payloads should be kept."; | 250 << "Not compatible; both payloads should be kept."; |
| 201 } | 251 } |
| 202 | 252 |
| 203 TEST_F(RtpPayloadRegistryTest, | 253 TEST_F(RtpPayloadRegistryTest, |
| 204 LastReceivedCodecTypesAreResetWhenRegisteringNewPayloadTypes) { | 254 LastReceivedCodecTypesAreResetWhenRegisteringNewPayloadTypes) { |
| 205 rtp_payload_registry_->set_last_received_payload_type(17); | 255 rtp_payload_registry_->set_last_received_payload_type(17); |
| 206 EXPECT_EQ(17, rtp_payload_registry_->last_received_payload_type()); | 256 EXPECT_EQ(17, rtp_payload_registry_->last_received_payload_type()); |
| 207 | 257 |
| 208 bool media_type_unchanged = rtp_payload_registry_->ReportMediaPayloadType(18); | 258 bool media_type_unchanged = rtp_payload_registry_->ReportMediaPayloadType(18); |
| 209 EXPECT_FALSE(media_type_unchanged); | 259 EXPECT_FALSE(media_type_unchanged); |
| 210 media_type_unchanged = rtp_payload_registry_->ReportMediaPayloadType(18); | 260 media_type_unchanged = rtp_payload_registry_->ReportMediaPayloadType(18); |
| 211 EXPECT_TRUE(media_type_unchanged); | 261 EXPECT_TRUE(media_type_unchanged); |
| 212 | 262 |
| 213 bool ignored; | 263 bool ignored; |
| 214 ExpectReturnOfTypicalAudioPayload(34, kTypicalRate); | 264 ExpectReturnOfTypicalAudioPayload(34, kTypicalRate); |
| 215 EXPECT_EQ(0, rtp_payload_registry_->RegisterReceivePayload( | 265 CodecInst audio_codec = kTypicalAudioCodec; |
| 216 kTypicalPayloadName, 34, kTypicalFrequency, kTypicalChannels, | 266 audio_codec.pltype = 34; |
| 217 kTypicalRate, &ignored)); | 267 EXPECT_EQ( |
| 268 0, rtp_payload_registry_->RegisterReceivePayload(audio_codec, &ignored)); | |
| 218 | 269 |
| 219 EXPECT_EQ(-1, rtp_payload_registry_->last_received_payload_type()); | 270 EXPECT_EQ(-1, rtp_payload_registry_->last_received_payload_type()); |
| 220 media_type_unchanged = rtp_payload_registry_->ReportMediaPayloadType(18); | 271 media_type_unchanged = rtp_payload_registry_->ReportMediaPayloadType(18); |
| 221 EXPECT_FALSE(media_type_unchanged); | 272 EXPECT_FALSE(media_type_unchanged); |
| 222 } | 273 } |
| 223 | 274 |
| 224 class ParameterizedRtpPayloadRegistryTest | 275 class ParameterizedRtpPayloadRegistryTest |
| 225 : public RtpPayloadRegistryTest, | 276 : public RtpPayloadRegistryTest, |
| 226 public ::testing::WithParamInterface<int> {}; | 277 public ::testing::WithParamInterface<int> {}; |
| 227 | 278 |
| 228 TEST_P(ParameterizedRtpPayloadRegistryTest, | 279 TEST_P(ParameterizedRtpPayloadRegistryTest, |
| 229 FailsToRegisterKnownPayloadsWeAreNotInterestedIn) { | 280 FailsToRegisterKnownPayloadsWeAreNotInterestedIn) { |
| 230 int payload_type = GetParam(); | 281 int payload_type = GetParam(); |
| 231 | 282 |
| 232 bool ignored; | 283 bool ignored; |
| 233 EXPECT_EQ(-1, rtp_payload_registry_->RegisterReceivePayload( | 284 CodecInst audio_codec; |
| 234 "whatever", static_cast<uint8_t>(payload_type), 19, 1, 17, | 285 strcpy(audio_codec.plname, "whatever"); |
| 235 &ignored)); | 286 audio_codec.pltype = static_cast<uint8_t>(payload_type); |
| 287 audio_codec.plfreq = 19; | |
| 288 audio_codec.channels = 1; | |
| 289 audio_codec.rate = 17; | |
| 290 EXPECT_EQ( | |
| 291 -1, rtp_payload_registry_->RegisterReceivePayload(audio_codec, &ignored)); | |
| 236 } | 292 } |
| 237 | 293 |
| 238 INSTANTIATE_TEST_CASE_P(TestKnownBadPayloadTypes, | 294 INSTANTIATE_TEST_CASE_P(TestKnownBadPayloadTypes, |
| 239 ParameterizedRtpPayloadRegistryTest, | 295 ParameterizedRtpPayloadRegistryTest, |
| 240 testing::Values(64, 72, 73, 74, 75, 76, 77, 78, 79)); | 296 testing::Values(64, 72, 73, 74, 75, 76, 77, 78, 79)); |
| 241 | 297 |
| 242 class RtpPayloadRegistryGenericTest | 298 class RtpPayloadRegistryGenericTest |
| 243 : public RtpPayloadRegistryTest, | 299 : public RtpPayloadRegistryTest, |
| 244 public ::testing::WithParamInterface<int> {}; | 300 public ::testing::WithParamInterface<int> {}; |
| 245 | 301 |
| 246 TEST_P(RtpPayloadRegistryGenericTest, RegisterGenericReceivePayloadType) { | 302 TEST_P(RtpPayloadRegistryGenericTest, RegisterGenericReceivePayloadType) { |
| 247 int payload_type = GetParam(); | 303 const uint8_t payload_type = static_cast<uint8_t>(GetParam()); |
|
danilchap
2016/11/23 17:12:50
better to leave payload_type as int,
should also b
magjed_webrtc
2016/11/24 09:39:40
Done.
| |
| 248 | |
| 249 bool ignored; | 304 bool ignored; |
| 250 | 305 CodecInst audio_codec; |
| 251 EXPECT_EQ(0, rtp_payload_registry_->RegisterReceivePayload( | 306 // Dummy values, except for payload_type. |
| 252 "generic-codec", static_cast<int8_t>(payload_type), 19, 1, | 307 strcpy(audio_codec.plname, "generic-codec"); |
| 253 17, &ignored)); // dummy values, except for payload_type | 308 audio_codec.pltype = payload_type; |
| 309 audio_codec.plfreq = 19; | |
| 310 audio_codec.channels = 1; | |
| 311 audio_codec.rate = 17; | |
| 312 EXPECT_EQ( | |
| 313 0, rtp_payload_registry_->RegisterReceivePayload(audio_codec, &ignored)); | |
| 254 } | 314 } |
| 255 | 315 |
| 256 // Generates an RTX packet for the given length and original sequence number. | 316 // Generates an RTX packet for the given length and original sequence number. |
| 257 // The RTX sequence number and ssrc will use the default value of 9999. The | 317 // The RTX sequence number and ssrc will use the default value of 9999. The |
| 258 // caller takes ownership of the returned buffer. | 318 // caller takes ownership of the returned buffer. |
| 259 const uint8_t* GenerateRtxPacket(size_t header_length, | 319 const uint8_t* GenerateRtxPacket(size_t header_length, |
| 260 size_t payload_length, | 320 size_t payload_length, |
| 261 uint16_t original_sequence_number) { | 321 uint16_t original_sequence_number) { |
| 262 uint8_t* packet = | 322 uint8_t* packet = |
| 263 new uint8_t[kRtxHeaderSize + header_length + payload_length](); | 323 new uint8_t[kRtxHeaderSize + header_length + payload_length](); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 rtp_payload_registry_->SetRtxPayloadType(105, 95); | 408 rtp_payload_registry_->SetRtxPayloadType(105, 95); |
| 349 TestRtxPacket(rtp_payload_registry_.get(), 105, 95, true); | 409 TestRtxPacket(rtp_payload_registry_.get(), 105, 95, true); |
| 350 TestRtxPacket(rtp_payload_registry_.get(), 106, 0, false); | 410 TestRtxPacket(rtp_payload_registry_.get(), 106, 0, false); |
| 351 } | 411 } |
| 352 | 412 |
| 353 INSTANTIATE_TEST_CASE_P(TestDynamicRange, | 413 INSTANTIATE_TEST_CASE_P(TestDynamicRange, |
| 354 RtpPayloadRegistryGenericTest, | 414 RtpPayloadRegistryGenericTest, |
| 355 testing::Range(96, 127 + 1)); | 415 testing::Range(96, 127 + 1)); |
| 356 | 416 |
| 357 } // namespace webrtc | 417 } // namespace webrtc |
| OLD | NEW |