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 |
11 #include <cstring> | |
12 | |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "webrtc/base/arraysize.h" | 14 #include "webrtc/base/arraysize.h" |
13 #include "webrtc/base/safe_conversions.h" | 15 #include "webrtc/base/safe_conversions.h" |
14 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h" | 16 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h" |
15 #include "webrtc/modules/audio_coding/main/acm2/codec_owner.h" | 17 #include "webrtc/modules/audio_coding/main/acm2/codec_owner.h" |
16 | 18 |
17 namespace webrtc { | 19 namespace webrtc { |
18 namespace acm2 { | 20 namespace acm2 { |
19 | 21 |
20 using ::testing::Return; | 22 using ::testing::Return; |
21 using ::testing::InSequence; | 23 using ::testing::InSequence; |
22 | 24 |
23 namespace { | 25 namespace { |
24 const int kDataLengthSamples = 80; | 26 const int kDataLengthSamples = 80; |
25 const int kPacketSizeSamples = 2 * kDataLengthSamples; | 27 const int kPacketSizeSamples = 2 * kDataLengthSamples; |
26 const int16_t kZeroData[kDataLengthSamples] = {0}; | 28 const int16_t kZeroData[kDataLengthSamples] = {0}; |
27 const CodecInst kDefaultCodecInst = | 29 const CodecInst kDefaultCodecInst = |
28 {0, "pcmu", 8000, kPacketSizeSamples, 1, 64000}; | 30 {0, "pcmu", 8000, kPacketSizeSamples, 1, 64000}; |
29 const int kCngPt = 13; | 31 const int kCngPt = 13; |
30 } // namespace | 32 } // namespace |
31 | 33 |
32 class CodecOwnerTest : public ::testing::Test { | 34 class CodecOwnerTest : public ::testing::Test { |
33 protected: | 35 protected: |
34 CodecOwnerTest() : timestamp_(0) {} | 36 CodecOwnerTest() : timestamp_(0) {} |
35 | 37 |
36 void CreateCodec() { | 38 void CreateCodec() { |
37 codec_owner_.SetEncoders(kDefaultCodecInst, kCngPt, VADNormal, -1); | 39 ASSERT_TRUE( |
40 codec_owner_.SetEncoders(kDefaultCodecInst, kCngPt, VADNormal, -1)); | |
38 } | 41 } |
39 | 42 |
40 void EncodeAndVerify(size_t expected_out_length, | 43 void EncodeAndVerify(size_t expected_out_length, |
41 uint32_t expected_timestamp, | 44 uint32_t expected_timestamp, |
42 int expected_payload_type, | 45 int expected_payload_type, |
43 int expected_send_even_if_empty) { | 46 int expected_send_even_if_empty) { |
44 uint8_t out[kPacketSizeSamples]; | 47 uint8_t out[kPacketSizeSamples]; |
45 AudioEncoder::EncodedInfo encoded_info; | 48 AudioEncoder::EncodedInfo encoded_info; |
46 encoded_info = codec_owner_.Encoder()->Encode( | 49 encoded_info = codec_owner_.Encoder()->Encode( |
47 timestamp_, kZeroData, kDataLengthSamples, kPacketSizeSamples, out); | 50 timestamp_, kZeroData, kDataLengthSamples, kPacketSizeSamples, out); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 } | 163 } |
161 | 164 |
162 info = codec_owner_.Encoder()->Encode(0, audio, arraysize(audio), | 165 info = codec_owner_.Encoder()->Encode(0, audio, arraysize(audio), |
163 arraysize(encoded), encoded); | 166 arraysize(encoded), encoded); |
164 EXPECT_EQ(0u, info.encoded_timestamp); | 167 EXPECT_EQ(0u, info.encoded_timestamp); |
165 external_encoder.Mark("A"); | 168 external_encoder.Mark("A"); |
166 | 169 |
167 // Change to internal encoder. | 170 // Change to internal encoder. |
168 CodecInst codec_inst = kDefaultCodecInst; | 171 CodecInst codec_inst = kDefaultCodecInst; |
169 codec_inst.pacsize = kPacketSizeSamples; | 172 codec_inst.pacsize = kPacketSizeSamples; |
170 codec_owner_.SetEncoders(codec_inst, -1, VADNormal, -1); | 173 ASSERT_TRUE(codec_owner_.SetEncoders(codec_inst, -1, VADNormal, -1)); |
171 // Don't expect any more calls to the external encoder. | 174 // Don't expect any more calls to the external encoder. |
172 info = codec_owner_.Encoder()->Encode(1, audio, arraysize(audio), | 175 info = codec_owner_.Encoder()->Encode(1, audio, arraysize(audio), |
173 arraysize(encoded), encoded); | 176 arraysize(encoded), encoded); |
174 external_encoder.Mark("B"); | 177 external_encoder.Mark("B"); |
175 | 178 |
176 // Change back to external encoder again. | 179 // Change back to external encoder again. |
177 codec_owner_.SetEncoders(&external_encoder, -1, VADNormal, -1); | 180 codec_owner_.SetEncoders(&external_encoder, -1, VADNormal, -1); |
178 info = codec_owner_.Encoder()->Encode(2, audio, arraysize(audio), | 181 info = codec_owner_.Encoder()->Encode(2, audio, arraysize(audio), |
179 arraysize(encoded), encoded); | 182 arraysize(encoded), encoded); |
180 EXPECT_EQ(2u, info.encoded_timestamp); | 183 EXPECT_EQ(2u, info.encoded_timestamp); |
181 } | 184 } |
182 | 185 |
183 TEST_F(CodecOwnerTest, CngResetsSpeechEncoder) { | 186 TEST_F(CodecOwnerTest, CngResetsSpeechEncoder) { |
184 TestCngAndRedResetSpeechEncoder(true, false); | 187 TestCngAndRedResetSpeechEncoder(true, false); |
185 } | 188 } |
186 | 189 |
187 TEST_F(CodecOwnerTest, RedResetsSpeechEncoder) { | 190 TEST_F(CodecOwnerTest, RedResetsSpeechEncoder) { |
188 TestCngAndRedResetSpeechEncoder(false, true); | 191 TestCngAndRedResetSpeechEncoder(false, true); |
189 } | 192 } |
190 | 193 |
191 TEST_F(CodecOwnerTest, CngAndRedResetsSpeechEncoder) { | 194 TEST_F(CodecOwnerTest, CngAndRedResetsSpeechEncoder) { |
192 TestCngAndRedResetSpeechEncoder(true, true); | 195 TestCngAndRedResetSpeechEncoder(true, true); |
193 } | 196 } |
194 | 197 |
195 TEST_F(CodecOwnerTest, NoCngAndRedNoSpeechEncoderReset) { | 198 TEST_F(CodecOwnerTest, NoCngAndRedNoSpeechEncoderReset) { |
196 TestCngAndRedResetSpeechEncoder(false, false); | 199 TestCngAndRedResetSpeechEncoder(false, false); |
197 } | 200 } |
198 | 201 |
202 TEST_F(CodecOwnerTest, SetEncodersError) { | |
203 CodecInst codec_inst = kDefaultCodecInst; | |
204 static const char bad_name[] = "Robert'); DROP TABLE Students;"; | |
hlundin-webrtc
2015/09/24 11:24:03
Bonus points for the xkcd archaeology!
| |
205 std::memcpy(codec_inst.plname, bad_name, sizeof bad_name); | |
206 EXPECT_FALSE(codec_owner_.SetEncoders(codec_inst, -1, VADNormal, -1)); | |
207 } | |
208 | |
199 } // namespace acm2 | 209 } // namespace acm2 |
200 } // namespace webrtc | 210 } // namespace webrtc |
OLD | NEW |