OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 14 matching lines...) Expand all Loading... |
25 const CodecInst kDefaultCodecInst = {0, "pcmu", 8000, kPacketSizeSamples, | 25 const CodecInst kDefaultCodecInst = {0, "pcmu", 8000, kPacketSizeSamples, |
26 1, 64000}; | 26 1, 64000}; |
27 const int kCngPt = 13; | 27 const int kCngPt = 13; |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 class RentACodecTestF : public ::testing::Test { | 30 class RentACodecTestF : public ::testing::Test { |
31 protected: | 31 protected: |
32 void CreateCodec() { | 32 void CreateCodec() { |
33 speech_encoder_ = rent_a_codec_.RentEncoder(kDefaultCodecInst); | 33 speech_encoder_ = rent_a_codec_.RentEncoder(kDefaultCodecInst); |
34 ASSERT_TRUE(speech_encoder_); | 34 ASSERT_TRUE(speech_encoder_); |
35 encoder_ = rent_a_codec_.RentEncoderStack( | 35 RentACodec::StackParameters param; |
36 speech_encoder_, rtc::Optional<RentACodec::CngConfig>( | 36 param.use_cng = true; |
37 RentACodec::CngConfig{kCngPt, VADNormal}), | 37 encoder_ = rent_a_codec_.RentEncoderStack(speech_encoder_, ¶m); |
38 rtc::Optional<int>()); | |
39 } | 38 } |
40 | 39 |
41 void EncodeAndVerify(size_t expected_out_length, | 40 void EncodeAndVerify(size_t expected_out_length, |
42 uint32_t expected_timestamp, | 41 uint32_t expected_timestamp, |
43 int expected_payload_type, | 42 int expected_payload_type, |
44 int expected_send_even_if_empty) { | 43 int expected_send_even_if_empty) { |
45 uint8_t out[kPacketSizeSamples]; | 44 uint8_t out[kPacketSizeSamples]; |
46 AudioEncoder::EncodedInfo encoded_info; | 45 AudioEncoder::EncodedInfo encoded_info; |
47 encoded_info = | 46 encoded_info = |
48 encoder_->Encode(timestamp_, kZeroData, kPacketSizeSamples, out); | 47 encoder_->Encode(timestamp_, kZeroData, kPacketSizeSamples, out); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 expected_timestamp += 2 * kDataLengthSamples; | 96 expected_timestamp += 2 * kDataLengthSamples; |
98 { | 97 { |
99 SCOPED_TRACE("Fourth encoding"); | 98 SCOPED_TRACE("Fourth encoding"); |
100 EncodeAndVerify(0, expected_timestamp, kCngPt, 1); | 99 EncodeAndVerify(0, expected_timestamp, kCngPt, 1); |
101 } | 100 } |
102 } | 101 } |
103 | 102 |
104 TEST(RentACodecTest, ExternalEncoder) { | 103 TEST(RentACodecTest, ExternalEncoder) { |
105 MockAudioEncoder external_encoder; | 104 MockAudioEncoder external_encoder; |
106 RentACodec rac; | 105 RentACodec rac; |
107 EXPECT_EQ(&external_encoder, | 106 RentACodec::StackParameters param; |
108 rac.RentEncoderStack(&external_encoder, | 107 EXPECT_EQ(&external_encoder, rac.RentEncoderStack(&external_encoder, ¶m)); |
109 rtc::Optional<RentACodec::CngConfig>(), | |
110 rtc::Optional<int>())); | |
111 const int kSampleRateHz = 8000; | 108 const int kSampleRateHz = 8000; |
112 const int kPacketSizeSamples = kSampleRateHz / 100; | 109 const int kPacketSizeSamples = kSampleRateHz / 100; |
113 int16_t audio[kPacketSizeSamples] = {0}; | 110 int16_t audio[kPacketSizeSamples] = {0}; |
114 uint8_t encoded[kPacketSizeSamples]; | 111 uint8_t encoded[kPacketSizeSamples]; |
115 AudioEncoder::EncodedInfo info; | 112 AudioEncoder::EncodedInfo info; |
116 EXPECT_CALL(external_encoder, SampleRateHz()) | 113 EXPECT_CALL(external_encoder, SampleRateHz()) |
117 .WillRepeatedly(Return(kSampleRateHz)); | 114 .WillRepeatedly(Return(kSampleRateHz)); |
118 EXPECT_CALL(external_encoder, NumChannels()).WillRepeatedly(Return(1)); | 115 EXPECT_CALL(external_encoder, NumChannels()).WillRepeatedly(Return(1)); |
119 | 116 |
120 { | 117 { |
(...skipping 15 matching lines...) Expand all Loading... |
136 | 133 |
137 info = rac.GetEncoderStack()->Encode(0, audio, arraysize(encoded), encoded); | 134 info = rac.GetEncoderStack()->Encode(0, audio, arraysize(encoded), encoded); |
138 EXPECT_EQ(0u, info.encoded_timestamp); | 135 EXPECT_EQ(0u, info.encoded_timestamp); |
139 external_encoder.Mark("A"); | 136 external_encoder.Mark("A"); |
140 | 137 |
141 // Change to internal encoder. | 138 // Change to internal encoder. |
142 CodecInst codec_inst = kDefaultCodecInst; | 139 CodecInst codec_inst = kDefaultCodecInst; |
143 codec_inst.pacsize = kPacketSizeSamples; | 140 codec_inst.pacsize = kPacketSizeSamples; |
144 AudioEncoder* enc = rac.RentEncoder(codec_inst); | 141 AudioEncoder* enc = rac.RentEncoder(codec_inst); |
145 ASSERT_TRUE(enc); | 142 ASSERT_TRUE(enc); |
146 EXPECT_EQ(enc, | 143 EXPECT_EQ(enc, rac.RentEncoderStack(enc, ¶m)); |
147 rac.RentEncoderStack(enc, rtc::Optional<RentACodec::CngConfig>(), | |
148 rtc::Optional<int>())); | |
149 | 144 |
150 // Don't expect any more calls to the external encoder. | 145 // Don't expect any more calls to the external encoder. |
151 info = rac.GetEncoderStack()->Encode(1, audio, arraysize(encoded), encoded); | 146 info = rac.GetEncoderStack()->Encode(1, audio, arraysize(encoded), encoded); |
152 external_encoder.Mark("B"); | 147 external_encoder.Mark("B"); |
153 | 148 |
154 // Change back to external encoder again. | 149 // Change back to external encoder again. |
155 EXPECT_EQ(&external_encoder, | 150 EXPECT_EQ(&external_encoder, rac.RentEncoderStack(&external_encoder, ¶m)); |
156 rac.RentEncoderStack(&external_encoder, | |
157 rtc::Optional<RentACodec::CngConfig>(), | |
158 rtc::Optional<int>())); | |
159 info = rac.GetEncoderStack()->Encode(2, audio, arraysize(encoded), encoded); | 151 info = rac.GetEncoderStack()->Encode(2, audio, arraysize(encoded), encoded); |
160 EXPECT_EQ(2u, info.encoded_timestamp); | 152 EXPECT_EQ(2u, info.encoded_timestamp); |
161 } | 153 } |
162 | 154 |
163 // Verify that the speech encoder's Reset method is called when CNG or RED | 155 // Verify that the speech encoder's Reset method is called when CNG or RED |
164 // (or both) are switched on, but not when they're switched off. | 156 // (or both) are switched on, but not when they're switched off. |
165 void TestCngAndRedResetSpeechEncoder(bool use_cng, bool use_red) { | 157 void TestCngAndRedResetSpeechEncoder(bool use_cng, bool use_red) { |
166 MockAudioEncoder speech_encoder; | 158 MockAudioEncoder speech_encoder; |
167 EXPECT_CALL(speech_encoder, NumChannels()).WillRepeatedly(Return(1)); | 159 EXPECT_CALL(speech_encoder, NumChannels()).WillRepeatedly(Return(1)); |
168 EXPECT_CALL(speech_encoder, Max10MsFramesInAPacket()) | 160 EXPECT_CALL(speech_encoder, Max10MsFramesInAPacket()) |
169 .WillRepeatedly(Return(2)); | 161 .WillRepeatedly(Return(2)); |
170 EXPECT_CALL(speech_encoder, SampleRateHz()).WillRepeatedly(Return(8000)); | 162 EXPECT_CALL(speech_encoder, SampleRateHz()).WillRepeatedly(Return(8000)); |
171 { | 163 { |
172 ::testing::InSequence s; | 164 ::testing::InSequence s; |
173 EXPECT_CALL(speech_encoder, Mark("disabled")); | 165 EXPECT_CALL(speech_encoder, Mark("disabled")); |
174 EXPECT_CALL(speech_encoder, Mark("enabled")); | 166 EXPECT_CALL(speech_encoder, Mark("enabled")); |
175 if (use_cng || use_red) | 167 if (use_cng || use_red) |
176 EXPECT_CALL(speech_encoder, Reset()); | 168 EXPECT_CALL(speech_encoder, Reset()); |
177 EXPECT_CALL(speech_encoder, Die()); | 169 EXPECT_CALL(speech_encoder, Die()); |
178 } | 170 } |
179 | 171 |
180 auto cng_cfg = use_cng ? rtc::Optional<RentACodec::CngConfig>( | 172 RentACodec::StackParameters param1, param2; |
181 RentACodec::CngConfig{17, VADNormal}) | 173 param2.use_cng = use_cng; |
182 : rtc::Optional<RentACodec::CngConfig>(); | 174 param2.use_red = use_red; |
183 auto red_pt = use_red ? rtc::Optional<int>(19) : rtc::Optional<int>(); | |
184 speech_encoder.Mark("disabled"); | 175 speech_encoder.Mark("disabled"); |
185 RentACodec rac; | 176 RentACodec rac; |
186 rac.RentEncoderStack(&speech_encoder, rtc::Optional<RentACodec::CngConfig>(), | 177 rac.RentEncoderStack(&speech_encoder, ¶m1); |
187 rtc::Optional<int>()); | |
188 speech_encoder.Mark("enabled"); | 178 speech_encoder.Mark("enabled"); |
189 rac.RentEncoderStack(&speech_encoder, cng_cfg, red_pt); | 179 rac.RentEncoderStack(&speech_encoder, ¶m2); |
190 } | 180 } |
191 | 181 |
192 TEST(RentACodecTest, CngResetsSpeechEncoder) { | 182 TEST(RentACodecTest, CngResetsSpeechEncoder) { |
193 TestCngAndRedResetSpeechEncoder(true, false); | 183 TestCngAndRedResetSpeechEncoder(true, false); |
194 } | 184 } |
195 | 185 |
196 TEST(RentACodecTest, RedResetsSpeechEncoder) { | 186 TEST(RentACodecTest, RedResetsSpeechEncoder) { |
197 TestCngAndRedResetSpeechEncoder(false, true); | 187 TestCngAndRedResetSpeechEncoder(false, true); |
198 } | 188 } |
199 | 189 |
200 TEST(RentACodecTest, CngAndRedResetsSpeechEncoder) { | 190 TEST(RentACodecTest, CngAndRedResetsSpeechEncoder) { |
201 TestCngAndRedResetSpeechEncoder(true, true); | 191 TestCngAndRedResetSpeechEncoder(true, true); |
202 } | 192 } |
203 | 193 |
204 TEST(RentACodecTest, NoCngAndRedNoSpeechEncoderReset) { | 194 TEST(RentACodecTest, NoCngAndRedNoSpeechEncoderReset) { |
205 TestCngAndRedResetSpeechEncoder(false, false); | 195 TestCngAndRedResetSpeechEncoder(false, false); |
206 } | 196 } |
207 | 197 |
208 TEST(RentACodecTest, RentEncoderError) { | 198 TEST(RentACodecTest, RentEncoderError) { |
209 const CodecInst codec_inst = { | 199 const CodecInst codec_inst = { |
210 0, "Robert'); DROP TABLE Students;", 8000, 160, 1, 64000}; | 200 0, "Robert'); DROP TABLE Students;", 8000, 160, 1, 64000}; |
211 RentACodec rent_a_codec; | 201 RentACodec rent_a_codec; |
212 EXPECT_FALSE(rent_a_codec.RentEncoder(codec_inst)); | 202 EXPECT_FALSE(rent_a_codec.RentEncoder(codec_inst)); |
213 } | 203 } |
214 | 204 |
215 } // namespace acm2 | 205 } // namespace acm2 |
216 } // namespace webrtc | 206 } // namespace webrtc |
OLD | NEW |