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

Side by Side Diff: webrtc/modules/audio_coding/main/acm2/codec_owner_unittest.cc

Issue 1418423010: Pass audio to AudioEncoder::Encode() in an ArrayView (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 5 years, 1 month 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) 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 28 matching lines...) Expand all
39 ASSERT_TRUE( 39 ASSERT_TRUE(
40 codec_owner_.SetEncoders(kDefaultCodecInst, kCngPt, VADNormal, -1)); 40 codec_owner_.SetEncoders(kDefaultCodecInst, kCngPt, VADNormal, -1));
41 } 41 }
42 42
43 void EncodeAndVerify(size_t expected_out_length, 43 void EncodeAndVerify(size_t expected_out_length,
44 uint32_t expected_timestamp, 44 uint32_t expected_timestamp,
45 int expected_payload_type, 45 int expected_payload_type,
46 int expected_send_even_if_empty) { 46 int expected_send_even_if_empty) {
47 uint8_t out[kPacketSizeSamples]; 47 uint8_t out[kPacketSizeSamples];
48 AudioEncoder::EncodedInfo encoded_info; 48 AudioEncoder::EncodedInfo encoded_info;
49 encoded_info = codec_owner_.Encoder()->Encode( 49 encoded_info = codec_owner_.Encoder()->Encode(timestamp_, kZeroData,
50 timestamp_, kZeroData, kDataLengthSamples, kPacketSizeSamples, out); 50 kPacketSizeSamples, out);
51 timestamp_ += kDataLengthSamples; 51 timestamp_ += kDataLengthSamples;
52 EXPECT_TRUE(encoded_info.redundant.empty()); 52 EXPECT_TRUE(encoded_info.redundant.empty());
53 EXPECT_EQ(expected_out_length, encoded_info.encoded_bytes); 53 EXPECT_EQ(expected_out_length, encoded_info.encoded_bytes);
54 EXPECT_EQ(expected_timestamp, encoded_info.encoded_timestamp); 54 EXPECT_EQ(expected_timestamp, encoded_info.encoded_timestamp);
55 if (expected_payload_type >= 0) 55 if (expected_payload_type >= 0)
56 EXPECT_EQ(expected_payload_type, encoded_info.payload_type); 56 EXPECT_EQ(expected_payload_type, encoded_info.payload_type);
57 if (expected_send_even_if_empty >= 0) 57 if (expected_send_even_if_empty >= 0)
58 EXPECT_EQ(static_cast<bool>(expected_send_even_if_empty), 58 EXPECT_EQ(static_cast<bool>(expected_send_even_if_empty),
59 encoded_info.send_even_if_empty); 59 encoded_info.send_even_if_empty);
60 } 60 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 TEST_F(CodecOwnerTest, ExternalEncoder) { 139 TEST_F(CodecOwnerTest, ExternalEncoder) {
140 MockAudioEncoder external_encoder; 140 MockAudioEncoder external_encoder;
141 codec_owner_.SetEncoders(&external_encoder, -1, VADNormal, -1); 141 codec_owner_.SetEncoders(&external_encoder, -1, VADNormal, -1);
142 const int kSampleRateHz = 8000; 142 const int kSampleRateHz = 8000;
143 const int kPacketSizeSamples = kSampleRateHz / 100; 143 const int kPacketSizeSamples = kSampleRateHz / 100;
144 int16_t audio[kPacketSizeSamples] = {0}; 144 int16_t audio[kPacketSizeSamples] = {0};
145 uint8_t encoded[kPacketSizeSamples]; 145 uint8_t encoded[kPacketSizeSamples];
146 AudioEncoder::EncodedInfo info; 146 AudioEncoder::EncodedInfo info;
147 EXPECT_CALL(external_encoder, SampleRateHz()) 147 EXPECT_CALL(external_encoder, SampleRateHz())
148 .WillRepeatedly(Return(kSampleRateHz)); 148 .WillRepeatedly(Return(kSampleRateHz));
149 EXPECT_CALL(external_encoder, NumChannels()).WillRepeatedly(Return(1));
149 150
150 { 151 {
151 InSequence s; 152 InSequence s;
152 info.encoded_timestamp = 0; 153 info.encoded_timestamp = 0;
153 EXPECT_CALL(external_encoder, 154 EXPECT_CALL(external_encoder,
154 EncodeInternal(0, audio, arraysize(encoded), encoded)) 155 EncodeInternal(0, rtc::ArrayView<const int16_t>(audio),
156 arraysize(encoded), encoded))
155 .WillOnce(Return(info)); 157 .WillOnce(Return(info));
156 EXPECT_CALL(external_encoder, Mark("A")); 158 EXPECT_CALL(external_encoder, Mark("A"));
157 EXPECT_CALL(external_encoder, Mark("B")); 159 EXPECT_CALL(external_encoder, Mark("B"));
158 info.encoded_timestamp = 2; 160 info.encoded_timestamp = 2;
159 EXPECT_CALL(external_encoder, 161 EXPECT_CALL(external_encoder,
160 EncodeInternal(2, audio, arraysize(encoded), encoded)) 162 EncodeInternal(2, rtc::ArrayView<const int16_t>(audio),
163 arraysize(encoded), encoded))
161 .WillOnce(Return(info)); 164 .WillOnce(Return(info));
162 EXPECT_CALL(external_encoder, Die()); 165 EXPECT_CALL(external_encoder, Die());
163 } 166 }
164 167
165 info = codec_owner_.Encoder()->Encode(0, audio, arraysize(audio), 168 info = codec_owner_.Encoder()->Encode(0, audio, arraysize(encoded), encoded);
166 arraysize(encoded), encoded);
167 EXPECT_EQ(0u, info.encoded_timestamp); 169 EXPECT_EQ(0u, info.encoded_timestamp);
168 external_encoder.Mark("A"); 170 external_encoder.Mark("A");
169 171
170 // Change to internal encoder. 172 // Change to internal encoder.
171 CodecInst codec_inst = kDefaultCodecInst; 173 CodecInst codec_inst = kDefaultCodecInst;
172 codec_inst.pacsize = kPacketSizeSamples; 174 codec_inst.pacsize = kPacketSizeSamples;
173 ASSERT_TRUE(codec_owner_.SetEncoders(codec_inst, -1, VADNormal, -1)); 175 ASSERT_TRUE(codec_owner_.SetEncoders(codec_inst, -1, VADNormal, -1));
174 // Don't expect any more calls to the external encoder. 176 // Don't expect any more calls to the external encoder.
175 info = codec_owner_.Encoder()->Encode(1, audio, arraysize(audio), 177 info = codec_owner_.Encoder()->Encode(1, audio, arraysize(encoded), encoded);
176 arraysize(encoded), encoded);
177 external_encoder.Mark("B"); 178 external_encoder.Mark("B");
178 179
179 // Change back to external encoder again. 180 // Change back to external encoder again.
180 codec_owner_.SetEncoders(&external_encoder, -1, VADNormal, -1); 181 codec_owner_.SetEncoders(&external_encoder, -1, VADNormal, -1);
181 info = codec_owner_.Encoder()->Encode(2, audio, arraysize(audio), 182 info = codec_owner_.Encoder()->Encode(2, audio, arraysize(encoded), encoded);
182 arraysize(encoded), encoded);
183 EXPECT_EQ(2u, info.encoded_timestamp); 183 EXPECT_EQ(2u, info.encoded_timestamp);
184 } 184 }
185 185
186 TEST_F(CodecOwnerTest, CngResetsSpeechEncoder) { 186 TEST_F(CodecOwnerTest, CngResetsSpeechEncoder) {
187 TestCngAndRedResetSpeechEncoder(true, false); 187 TestCngAndRedResetSpeechEncoder(true, false);
188 } 188 }
189 189
190 TEST_F(CodecOwnerTest, RedResetsSpeechEncoder) { 190 TEST_F(CodecOwnerTest, RedResetsSpeechEncoder) {
191 TestCngAndRedResetSpeechEncoder(false, true); 191 TestCngAndRedResetSpeechEncoder(false, true);
192 } 192 }
193 193
194 TEST_F(CodecOwnerTest, CngAndRedResetsSpeechEncoder) { 194 TEST_F(CodecOwnerTest, CngAndRedResetsSpeechEncoder) {
195 TestCngAndRedResetSpeechEncoder(true, true); 195 TestCngAndRedResetSpeechEncoder(true, true);
196 } 196 }
197 197
198 TEST_F(CodecOwnerTest, NoCngAndRedNoSpeechEncoderReset) { 198 TEST_F(CodecOwnerTest, NoCngAndRedNoSpeechEncoderReset) {
199 TestCngAndRedResetSpeechEncoder(false, false); 199 TestCngAndRedResetSpeechEncoder(false, false);
200 } 200 }
201 201
202 TEST_F(CodecOwnerTest, SetEncodersError) { 202 TEST_F(CodecOwnerTest, SetEncodersError) {
203 CodecInst codec_inst = kDefaultCodecInst; 203 CodecInst codec_inst = kDefaultCodecInst;
204 static const char bad_name[] = "Robert'); DROP TABLE Students;"; 204 static const char bad_name[] = "Robert'); DROP TABLE Students;";
205 std::memcpy(codec_inst.plname, bad_name, sizeof bad_name); 205 std::memcpy(codec_inst.plname, bad_name, sizeof bad_name);
206 EXPECT_FALSE(codec_owner_.SetEncoders(codec_inst, -1, VADNormal, -1)); 206 EXPECT_FALSE(codec_owner_.SetEncoders(codec_inst, -1, VADNormal, -1));
207 } 207 }
208 208
209 } // namespace acm2 209 } // namespace acm2
210 } // namespace webrtc 210 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698