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

Side by Side Diff: webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng_unittest.cc

Issue 1881003003: Reland Remove the deprecated EncodeInternal interface from AudioEncoder (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Renamed ApproximateEncodedBytes to SufficientOutputBufferSize in Opus Created 4 years, 8 months 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) 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;
29 static const size_t kMaxNumSamples = 48 * 10 * 2; // 10 ms @ 48 kHz stereo. 28 static const size_t kMaxNumSamples = 48 * 10 * 2; // 10 ms @ 48 kHz stereo.
30 static const size_t kMockReturnEncodedBytes = 17; 29 static const size_t kMockReturnEncodedBytes = 17;
31 static const int kCngPayloadType = 18; 30 static const int kCngPayloadType = 18;
32 } 31 }
33 32
34 class AudioEncoderCngTest : public ::testing::Test { 33 class AudioEncoderCngTest : public ::testing::Test {
35 protected: 34 protected:
36 AudioEncoderCngTest() 35 AudioEncoderCngTest()
37 : mock_encoder_owner_(new MockAudioEncoder), 36 : mock_encoder_owner_(new MockAudioEncoder),
38 mock_encoder_(mock_encoder_owner_.get()), 37 mock_encoder_(mock_encoder_owner_.get()),
(...skipping 28 matching lines...) Expand all
67 num_audio_samples_10ms_ = static_cast<size_t>(10 * sample_rate_hz_ / 1000); 66 num_audio_samples_10ms_ = static_cast<size_t>(10 * sample_rate_hz_ / 1000);
68 ASSERT_LE(num_audio_samples_10ms_, kMaxNumSamples); 67 ASSERT_LE(num_audio_samples_10ms_, kMaxNumSamples);
69 if (config.speech_encoder) { 68 if (config.speech_encoder) {
70 EXPECT_CALL(*mock_encoder_, SampleRateHz()) 69 EXPECT_CALL(*mock_encoder_, SampleRateHz())
71 .WillRepeatedly(Return(sample_rate_hz_)); 70 .WillRepeatedly(Return(sample_rate_hz_));
72 // Max10MsFramesInAPacket() is just used to verify that the SID frame 71 // Max10MsFramesInAPacket() is just used to verify that the SID frame
73 // period is not too small. The return value does not matter that much, 72 // period is not too small. The return value does not matter that much,
74 // as long as it is smaller than 10. 73 // as long as it is smaller than 10.
75 EXPECT_CALL(*mock_encoder_, Max10MsFramesInAPacket()) 74 EXPECT_CALL(*mock_encoder_, Max10MsFramesInAPacket())
76 .WillOnce(Return(1u)); 75 .WillOnce(Return(1u));
77 EXPECT_CALL(*mock_encoder_, MaxEncodedBytes())
78 .WillRepeatedly(Return(kMockMaxEncodedBytes));
79 } 76 }
80 cng_.reset(new AudioEncoderCng(std::move(config))); 77 cng_.reset(new AudioEncoderCng(std::move(config)));
81 } 78 }
82 79
83 void Encode() { 80 void Encode() {
84 ASSERT_TRUE(cng_) << "Must call CreateCng() first."; 81 ASSERT_TRUE(cng_) << "Must call CreateCng() first.";
85 encoded_info_ = cng_->Encode( 82 encoded_info_ = cng_->Encode(
86 timestamp_, 83 timestamp_,
87 rtc::ArrayView<const int16_t>(audio_, num_audio_samples_10ms_), 84 rtc::ArrayView<const int16_t>(audio_, num_audio_samples_10ms_),
88 &encoded_); 85 &encoded_);
89 timestamp_ += static_cast<uint32_t>(num_audio_samples_10ms_); 86 timestamp_ += static_cast<uint32_t>(num_audio_samples_10ms_);
90 } 87 }
91 88
92 // Expect |num_calls| calls to the encoder, all successful. The last call 89 // Expect |num_calls| calls to the encoder, all successful. The last call
93 // claims to have encoded |kMockMaxEncodedBytes| bytes, and all the preceding 90 // claims to have encoded |kMockReturnEncodedBytes| bytes, and all the
94 // ones 0 bytes. 91 // preceding ones 0 bytes.
95 void ExpectEncodeCalls(size_t num_calls) { 92 void ExpectEncodeCalls(size_t num_calls) {
96 InSequence s; 93 InSequence s;
97 AudioEncoder::EncodedInfo info; 94 AudioEncoder::EncodedInfo info;
98 for (size_t j = 0; j < num_calls - 1; ++j) { 95 for (size_t j = 0; j < num_calls - 1; ++j) {
99 EXPECT_CALL(*mock_encoder_, EncodeImpl(_, _, _)) 96 EXPECT_CALL(*mock_encoder_, EncodeImpl(_, _, _))
100 .WillOnce(Return(info)); 97 .WillOnce(Return(info));
101 } 98 }
102 info.encoded_bytes = kMockReturnEncodedBytes; 99 info.encoded_bytes = kMockReturnEncodedBytes;
103 EXPECT_CALL(*mock_encoder_, EncodeImpl(_, _, _)) 100 EXPECT_CALL(*mock_encoder_, EncodeImpl(_, _, _))
104 .WillOnce( 101 .WillOnce(
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 .WillRepeatedly(Return(7U)); 495 .WillRepeatedly(Return(7U));
499 for (int i = 0; i < 6; ++i) 496 for (int i = 0; i < 6; ++i)
500 Encode(); 497 Encode();
501 EXPECT_DEATH(Encode(), 498 EXPECT_DEATH(Encode(),
502 "Frame size cannot be larger than 60 ms when using VAD/CNG."); 499 "Frame size cannot be larger than 60 ms when using VAD/CNG.");
503 } 500 }
504 501
505 #endif // GTEST_HAS_DEATH_TEST 502 #endif // GTEST_HAS_DEATH_TEST
506 503
507 } // namespace webrtc 504 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698