OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "webrtc/common_audio/vad/mock/mock_vad.h" | 15 #include "webrtc/common_audio/vad/mock/mock_vad.h" |
16 #include "webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.h" | 16 #include "webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.h" |
17 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h" | 17 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h" |
18 | 18 |
19 using ::testing::Return; | 19 using ::testing::Return; |
20 using ::testing::_; | 20 using ::testing::_; |
21 using ::testing::SetArgPointee; | 21 using ::testing::SetArgPointee; |
22 using ::testing::InSequence; | 22 using ::testing::InSequence; |
23 using ::testing::Invoke; | 23 using ::testing::Invoke; |
24 | 24 |
25 namespace webrtc { | 25 namespace webrtc { |
26 | 26 |
27 namespace { | 27 namespace { |
| 28 static const size_t kMockMaxEncodedBytes = 1000; |
28 static const size_t kMaxNumSamples = 48 * 10 * 2; // 10 ms @ 48 kHz stereo. | 29 static const size_t kMaxNumSamples = 48 * 10 * 2; // 10 ms @ 48 kHz stereo. |
29 static const size_t kMockReturnEncodedBytes = 17; | 30 static const size_t kMockReturnEncodedBytes = 17; |
30 static const int kCngPayloadType = 18; | 31 static const int kCngPayloadType = 18; |
31 } | 32 } |
32 | 33 |
33 class AudioEncoderCngTest : public ::testing::Test { | 34 class AudioEncoderCngTest : public ::testing::Test { |
34 protected: | 35 protected: |
35 AudioEncoderCngTest() | 36 AudioEncoderCngTest() |
36 : mock_encoder_owner_(new MockAudioEncoder), | 37 : mock_encoder_owner_(new MockAudioEncoder), |
37 mock_encoder_(mock_encoder_owner_.get()), | 38 mock_encoder_(mock_encoder_owner_.get()), |
(...skipping 28 matching lines...) Expand all Loading... |
66 num_audio_samples_10ms_ = static_cast<size_t>(10 * sample_rate_hz_ / 1000); | 67 num_audio_samples_10ms_ = static_cast<size_t>(10 * sample_rate_hz_ / 1000); |
67 ASSERT_LE(num_audio_samples_10ms_, kMaxNumSamples); | 68 ASSERT_LE(num_audio_samples_10ms_, kMaxNumSamples); |
68 if (config.speech_encoder) { | 69 if (config.speech_encoder) { |
69 EXPECT_CALL(*mock_encoder_, SampleRateHz()) | 70 EXPECT_CALL(*mock_encoder_, SampleRateHz()) |
70 .WillRepeatedly(Return(sample_rate_hz_)); | 71 .WillRepeatedly(Return(sample_rate_hz_)); |
71 // Max10MsFramesInAPacket() is just used to verify that the SID frame | 72 // Max10MsFramesInAPacket() is just used to verify that the SID frame |
72 // period is not too small. The return value does not matter that much, | 73 // period is not too small. The return value does not matter that much, |
73 // as long as it is smaller than 10. | 74 // as long as it is smaller than 10. |
74 EXPECT_CALL(*mock_encoder_, Max10MsFramesInAPacket()) | 75 EXPECT_CALL(*mock_encoder_, Max10MsFramesInAPacket()) |
75 .WillOnce(Return(1u)); | 76 .WillOnce(Return(1u)); |
| 77 EXPECT_CALL(*mock_encoder_, MaxEncodedBytes()) |
| 78 .WillRepeatedly(Return(kMockMaxEncodedBytes)); |
76 } | 79 } |
77 cng_.reset(new AudioEncoderCng(std::move(config))); | 80 cng_.reset(new AudioEncoderCng(std::move(config))); |
78 } | 81 } |
79 | 82 |
80 void Encode() { | 83 void Encode() { |
81 ASSERT_TRUE(cng_) << "Must call CreateCng() first."; | 84 ASSERT_TRUE(cng_) << "Must call CreateCng() first."; |
82 encoded_info_ = cng_->Encode( | 85 encoded_info_ = cng_->Encode( |
83 timestamp_, | 86 timestamp_, |
84 rtc::ArrayView<const int16_t>(audio_, num_audio_samples_10ms_), | 87 rtc::ArrayView<const int16_t>(audio_, num_audio_samples_10ms_), |
85 &encoded_); | 88 &encoded_); |
86 timestamp_ += static_cast<uint32_t>(num_audio_samples_10ms_); | 89 timestamp_ += static_cast<uint32_t>(num_audio_samples_10ms_); |
87 } | 90 } |
88 | 91 |
89 // Expect |num_calls| calls to the encoder, all successful. The last call | 92 // Expect |num_calls| calls to the encoder, all successful. The last call |
90 // claims to have encoded |kMockReturnEncodedBytes| bytes, and all the | 93 // claims to have encoded |kMockMaxEncodedBytes| bytes, and all the preceding |
91 // preceding ones 0 bytes. | 94 // ones 0 bytes. |
92 void ExpectEncodeCalls(size_t num_calls) { | 95 void ExpectEncodeCalls(size_t num_calls) { |
93 InSequence s; | 96 InSequence s; |
94 AudioEncoder::EncodedInfo info; | 97 AudioEncoder::EncodedInfo info; |
95 for (size_t j = 0; j < num_calls - 1; ++j) { | 98 for (size_t j = 0; j < num_calls - 1; ++j) { |
96 EXPECT_CALL(*mock_encoder_, EncodeImpl(_, _, _)) | 99 EXPECT_CALL(*mock_encoder_, EncodeImpl(_, _, _)) |
97 .WillOnce(Return(info)); | 100 .WillOnce(Return(info)); |
98 } | 101 } |
99 info.encoded_bytes = kMockReturnEncodedBytes; | 102 info.encoded_bytes = kMockReturnEncodedBytes; |
100 EXPECT_CALL(*mock_encoder_, EncodeImpl(_, _, _)) | 103 EXPECT_CALL(*mock_encoder_, EncodeImpl(_, _, _)) |
101 .WillOnce( | 104 .WillOnce( |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 .WillRepeatedly(Return(7U)); | 498 .WillRepeatedly(Return(7U)); |
496 for (int i = 0; i < 6; ++i) | 499 for (int i = 0; i < 6; ++i) |
497 Encode(); | 500 Encode(); |
498 EXPECT_DEATH(Encode(), | 501 EXPECT_DEATH(Encode(), |
499 "Frame size cannot be larger than 60 ms when using VAD/CNG."); | 502 "Frame size cannot be larger than 60 ms when using VAD/CNG."); |
500 } | 503 } |
501 | 504 |
502 #endif // GTEST_HAS_DEATH_TEST | 505 #endif // GTEST_HAS_DEATH_TEST |
503 | 506 |
504 } // namespace webrtc | 507 } // namespace webrtc |
OLD | NEW |