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

Side by Side Diff: webrtc/modules/audio_coding/neteq/test/neteq_opus_quality_test.cc

Issue 1725143003: Changed AudioEncoder::Encode to take an rtc::Buffer* instead of uint8_t* and a maximum size. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Reverted unnecessary change to buffer_unittest.cc Created 4 years, 9 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
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 RegisterFlagValidator(&FLAGS_sub_packets, &ValidateSubPackets); 97 RegisterFlagValidator(&FLAGS_sub_packets, &ValidateSubPackets);
98 98
99 } // namepsace 99 } // namepsace
100 100
101 class NetEqOpusQualityTest : public NetEqQualityTest { 101 class NetEqOpusQualityTest : public NetEqQualityTest {
102 protected: 102 protected:
103 NetEqOpusQualityTest(); 103 NetEqOpusQualityTest();
104 void SetUp() override; 104 void SetUp() override;
105 void TearDown() override; 105 void TearDown() override;
106 virtual int EncodeBlock(int16_t* in_data, size_t block_size_samples, 106 virtual int EncodeBlock(int16_t* in_data, size_t block_size_samples,
107 uint8_t* payload, size_t max_bytes); 107 rtc::Buffer* payload, size_t max_bytes);
108 private: 108 private:
109 WebRtcOpusEncInst* opus_encoder_; 109 WebRtcOpusEncInst* opus_encoder_;
110 OpusRepacketizer* repacketizer_; 110 OpusRepacketizer* repacketizer_;
111 size_t sub_block_size_samples_; 111 size_t sub_block_size_samples_;
112 int bit_rate_kbps_; 112 int bit_rate_kbps_;
113 bool fec_; 113 bool fec_;
114 bool dtx_; 114 bool dtx_;
115 int complexity_; 115 int complexity_;
116 int maxplaybackrate_; 116 int maxplaybackrate_;
117 int target_loss_rate_; 117 int target_loss_rate_;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 168
169 void NetEqOpusQualityTest::TearDown() { 169 void NetEqOpusQualityTest::TearDown() {
170 // Free memory. 170 // Free memory.
171 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); 171 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
172 opus_repacketizer_destroy(repacketizer_); 172 opus_repacketizer_destroy(repacketizer_);
173 NetEqQualityTest::TearDown(); 173 NetEqQualityTest::TearDown();
174 } 174 }
175 175
176 int NetEqOpusQualityTest::EncodeBlock(int16_t* in_data, 176 int NetEqOpusQualityTest::EncodeBlock(int16_t* in_data,
177 size_t block_size_samples, 177 size_t block_size_samples,
178 uint8_t* payload, size_t max_bytes) { 178 rtc::Buffer* payload, size_t max_bytes) {
179 EXPECT_EQ(block_size_samples, sub_block_size_samples_ * sub_packets_); 179 EXPECT_EQ(block_size_samples, sub_block_size_samples_ * sub_packets_);
180 int16_t* pointer = in_data; 180 int16_t* pointer = in_data;
181 int value; 181 int value;
182 opus_repacketizer_init(repacketizer_); 182 opus_repacketizer_init(repacketizer_);
183 for (int idx = 0; idx < sub_packets_; idx++) { 183 for (int idx = 0; idx < sub_packets_; idx++) {
184 value = WebRtcOpus_Encode(opus_encoder_, pointer, sub_block_size_samples_, 184 payload->AppendData(max_bytes, [&] (rtc::ArrayView<uint8_t> payload) {
185 max_bytes, payload); 185 value = WebRtcOpus_Encode(opus_encoder_,
186 Log() << "Encoded a frame with Opus mode " 186 pointer, sub_block_size_samples_,
187 << (value == 0 ? 0 : payload[0] >> 3) 187 max_bytes, payload.data());
188 << std::endl; 188
189 if (OPUS_OK != opus_repacketizer_cat(repacketizer_, payload, value)) { 189 Log() << "Encoded a frame with Opus mode "
190 << (value == 0 ? 0 : payload[0] >> 3)
191 << std::endl;
192
193 return (value >= 0) ? static_cast<size_t>(value) : 0;
194 });
195
196 if (OPUS_OK != opus_repacketizer_cat(repacketizer_,
197 payload->data(), value)) {
190 opus_repacketizer_init(repacketizer_); 198 opus_repacketizer_init(repacketizer_);
191 // If the repacketization fails, we discard this frame. 199 // If the repacketization fails, we discard this frame.
192 return 0; 200 return 0;
193 } 201 }
194 pointer += sub_block_size_samples_ * channels_; 202 pointer += sub_block_size_samples_ * channels_;
195 } 203 }
196 value = opus_repacketizer_out(repacketizer_, payload, 204 value = opus_repacketizer_out(repacketizer_, payload->data(),
197 static_cast<opus_int32>(max_bytes)); 205 static_cast<opus_int32>(max_bytes));
198 EXPECT_GE(value, 0); 206 EXPECT_GE(value, 0);
199 return value; 207 return value;
200 } 208 }
201 209
202 TEST_F(NetEqOpusQualityTest, Test) { 210 TEST_F(NetEqOpusQualityTest, Test) {
203 Simulate(); 211 Simulate();
204 } 212 }
205 213
206 } // namespace test 214 } // namespace test
207 } // namespace webrtc 215 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698