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

Side by Side Diff: media/filters/audio_decoder_unittest.cc

Issue 1834303005: Refactor audio and video decoder status into common file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments. 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
« no previous file with comments | « media/filters/android/media_codec_audio_decoder.cc ('k') | media/filters/decoder_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 base::TimeDelta::FromSecondsD(base::ByteSwapToLE32(*skip_samples_ptr) / 129 base::TimeDelta::FromSecondsD(base::ByteSwapToLE32(*skip_samples_ptr) /
130 samples_per_second), 130 samples_per_second),
131 base::TimeDelta())); 131 base::TimeDelta()));
132 } 132 }
133 133
134 class AudioDecoderTest : public testing::TestWithParam<DecoderTestData> { 134 class AudioDecoderTest : public testing::TestWithParam<DecoderTestData> {
135 public: 135 public:
136 AudioDecoderTest() 136 AudioDecoderTest()
137 : pending_decode_(false), 137 : pending_decode_(false),
138 pending_reset_(false), 138 pending_reset_(false),
139 last_decode_status_(AudioDecoder::kDecodeError) { 139 last_decode_status_(DecodeStatus::DECODE_ERROR) {
140 switch (GetParam().decoder_type) { 140 switch (GetParam().decoder_type) {
141 case FFMPEG: 141 case FFMPEG:
142 decoder_.reset(new FFmpegAudioDecoder(message_loop_.task_runner(), 142 decoder_.reset(new FFmpegAudioDecoder(message_loop_.task_runner(),
143 new MediaLog())); 143 new MediaLog()));
144 break; 144 break;
145 case OPUS: 145 case OPUS:
146 decoder_.reset( 146 decoder_.reset(
147 new OpusAudioDecoder(message_loop_.task_runner())); 147 new OpusAudioDecoder(message_loop_.task_runner()));
148 break; 148 break;
149 #if defined(OS_ANDROID) 149 #if defined(OS_ANDROID)
150 case MEDIA_CODEC: 150 case MEDIA_CODEC:
151 decoder_.reset(new MediaCodecAudioDecoder(message_loop_.task_runner())); 151 decoder_.reset(new MediaCodecAudioDecoder(message_loop_.task_runner()));
152 break; 152 break;
153 #endif 153 #endif
154 } 154 }
155 } 155 }
156 156
157 virtual ~AudioDecoderTest() { 157 virtual ~AudioDecoderTest() {
158 EXPECT_FALSE(pending_decode_); 158 EXPECT_FALSE(pending_decode_);
159 EXPECT_FALSE(pending_reset_); 159 EXPECT_FALSE(pending_reset_);
160 } 160 }
161 161
162 protected: 162 protected:
163 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer) { 163 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer) {
164 ASSERT_FALSE(pending_decode_); 164 ASSERT_FALSE(pending_decode_);
165 pending_decode_ = true; 165 pending_decode_ = true;
166 last_decode_status_ = AudioDecoder::kDecodeError; 166 last_decode_status_ = DecodeStatus::DECODE_ERROR;
167 167
168 base::RunLoop run_loop; 168 base::RunLoop run_loop;
169 decoder_->Decode( 169 decoder_->Decode(
170 buffer, base::Bind(&AudioDecoderTest::DecodeFinished, 170 buffer, base::Bind(&AudioDecoderTest::DecodeFinished,
171 base::Unretained(this), run_loop.QuitClosure())); 171 base::Unretained(this), run_loop.QuitClosure()));
172 run_loop.Run(); 172 run_loop.Run();
173 ASSERT_FALSE(pending_decode_); 173 ASSERT_FALSE(pending_decode_);
174 } 174 }
175 175
176 void SendEndOfStream() { 176 void SendEndOfStream() {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 Reset(); 269 Reset();
270 decoded_audio_.clear(); 270 decoded_audio_.clear();
271 ASSERT_TRUE(reader_->SeekForTesting(seek_time)); 271 ASSERT_TRUE(reader_->SeekForTesting(seek_time));
272 } 272 }
273 273
274 void OnDecoderOutput(const scoped_refptr<AudioBuffer>& buffer) { 274 void OnDecoderOutput(const scoped_refptr<AudioBuffer>& buffer) {
275 EXPECT_FALSE(buffer->end_of_stream()); 275 EXPECT_FALSE(buffer->end_of_stream());
276 decoded_audio_.push_back(buffer); 276 decoded_audio_.push_back(buffer);
277 } 277 }
278 278
279 void DecodeFinished(const base::Closure& quit_closure, 279 void DecodeFinished(const base::Closure& quit_closure, DecodeStatus status) {
280 AudioDecoder::Status status) {
281 EXPECT_TRUE(pending_decode_); 280 EXPECT_TRUE(pending_decode_);
282 EXPECT_FALSE(pending_reset_); 281 EXPECT_FALSE(pending_reset_);
283 pending_decode_ = false; 282 pending_decode_ = false;
284 last_decode_status_ = status; 283 last_decode_status_ = status;
285 quit_closure.Run(); 284 quit_closure.Run();
286 } 285 }
287 286
288 void ResetFinished() { 287 void ResetFinished() {
289 EXPECT_TRUE(pending_reset_); 288 EXPECT_TRUE(pending_reset_);
290 EXPECT_FALSE(pending_decode_); 289 EXPECT_FALSE(pending_decode_);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 if (i > 0) 357 if (i > 0)
359 EXPECT_NE(exact_hash, GetDecodedAudioMD5(i - 1)); 358 EXPECT_NE(exact_hash, GetDecodedAudioMD5(i - 1));
360 } 359 }
361 } 360 }
362 361
363 size_t decoded_audio_size() const { return decoded_audio_.size(); } 362 size_t decoded_audio_size() const { return decoded_audio_.size(); }
364 base::TimeDelta start_timestamp() const { return start_timestamp_; } 363 base::TimeDelta start_timestamp() const { return start_timestamp_; }
365 const scoped_refptr<AudioBuffer>& decoded_audio(size_t i) { 364 const scoped_refptr<AudioBuffer>& decoded_audio(size_t i) {
366 return decoded_audio_[i]; 365 return decoded_audio_[i];
367 } 366 }
368 AudioDecoder::Status last_decode_status() const { 367 DecodeStatus last_decode_status() const { return last_decode_status_; }
369 return last_decode_status_;
370 }
371 368
372 private: 369 private:
373 base::MessageLoop message_loop_; 370 base::MessageLoop message_loop_;
374 scoped_refptr<DecoderBuffer> data_; 371 scoped_refptr<DecoderBuffer> data_;
375 scoped_ptr<InMemoryUrlProtocol> protocol_; 372 scoped_ptr<InMemoryUrlProtocol> protocol_;
376 scoped_ptr<AudioFileReader> reader_; 373 scoped_ptr<AudioFileReader> reader_;
377 374
378 scoped_ptr<AudioDecoder> decoder_; 375 scoped_ptr<AudioDecoder> decoder_;
379 bool pending_decode_; 376 bool pending_decode_;
380 bool pending_reset_; 377 bool pending_reset_;
381 AudioDecoder::Status last_decode_status_; 378 DecodeStatus last_decode_status_;
382 379
383 std::deque<scoped_refptr<AudioBuffer> > decoded_audio_; 380 std::deque<scoped_refptr<AudioBuffer> > decoded_audio_;
384 base::TimeDelta start_timestamp_; 381 base::TimeDelta start_timestamp_;
385 382
386 DISALLOW_COPY_AND_ASSIGN(AudioDecoderTest); 383 DISALLOW_COPY_AND_ASSIGN(AudioDecoderTest);
387 }; 384 };
388 385
389 class OpusAudioDecoderBehavioralTest : public AudioDecoderTest {}; 386 class OpusAudioDecoderBehavioralTest : public AudioDecoderTest {};
390 class FFmpegAudioDecoderBehavioralTest : public AudioDecoderTest {}; 387 class FFmpegAudioDecoderBehavioralTest : public AudioDecoderTest {};
391 388
392 TEST_P(AudioDecoderTest, Initialize) { 389 TEST_P(AudioDecoderTest, Initialize) {
393 SKIP_TEST_IF_NO_MEDIA_CODEC(); 390 SKIP_TEST_IF_NO_MEDIA_CODEC();
394 ASSERT_NO_FATAL_FAILURE(Initialize()); 391 ASSERT_NO_FATAL_FAILURE(Initialize());
395 } 392 }
396 393
397 // Verifies decode audio as well as the Decode() -> Reset() sequence. 394 // Verifies decode audio as well as the Decode() -> Reset() sequence.
398 TEST_P(AudioDecoderTest, ProduceAudioSamples) { 395 TEST_P(AudioDecoderTest, ProduceAudioSamples) {
399 SKIP_TEST_IF_NO_MEDIA_CODEC(); 396 SKIP_TEST_IF_NO_MEDIA_CODEC();
400 ASSERT_NO_FATAL_FAILURE(Initialize()); 397 ASSERT_NO_FATAL_FAILURE(Initialize());
401 398
402 // Run the test multiple times with a seek back to the beginning in between. 399 // Run the test multiple times with a seek back to the beginning in between.
403 std::vector<std::string> decoded_audio_md5_hashes; 400 std::vector<std::string> decoded_audio_md5_hashes;
404 for (int i = 0; i < 2; ++i) { 401 for (int i = 0; i < 2; ++i) {
405 // Run decoder until we get at least |kDecodeRuns| output buffers. 402 // Run decoder until we get at least |kDecodeRuns| output buffers.
406 // Keeping Decode() in a loop seems to be the simplest way to guarantee that 403 // Keeping Decode() in a loop seems to be the simplest way to guarantee that
407 // the predefined number of output buffers are produced without draining 404 // the predefined number of output buffers are produced without draining
408 // (i.e. decoding EOS). 405 // (i.e. decoding EOS).
409 do { 406 do {
410 Decode(); 407 Decode();
411 ASSERT_EQ(last_decode_status(), AudioDecoder::kOk); 408 ASSERT_EQ(last_decode_status(), DecodeStatus::OK);
412 } while (decoded_audio_size() < kDecodeRuns); 409 } while (decoded_audio_size() < kDecodeRuns);
413 410
414 // With MediaCodecAudioDecoder the output buffers might appear after 411 // With MediaCodecAudioDecoder the output buffers might appear after
415 // some delay. Since we keep decoding in a loop, the number of output 412 // some delay. Since we keep decoding in a loop, the number of output
416 // buffers when they eventually appear might exceed |kDecodeRuns|. 413 // buffers when they eventually appear might exceed |kDecodeRuns|.
417 ASSERT_LE(kDecodeRuns, decoded_audio_size()); 414 ASSERT_LE(kDecodeRuns, decoded_audio_size());
418 415
419 // On the first pass record the exact MD5 hash for each decoded buffer. 416 // On the first pass record the exact MD5 hash for each decoded buffer.
420 if (i == 0) { 417 if (i == 0) {
421 for (size_t j = 0; j < kDecodeRuns; ++j) 418 for (size_t j = 0; j < kDecodeRuns; ++j)
(...skipping 11 matching lines...) Expand all
433 430
434 // Seek back to the beginning. Calls Reset() on the decoder. 431 // Seek back to the beginning. Calls Reset() on the decoder.
435 Seek(start_timestamp()); 432 Seek(start_timestamp());
436 } 433 }
437 } 434 }
438 435
439 TEST_P(AudioDecoderTest, Decode) { 436 TEST_P(AudioDecoderTest, Decode) {
440 SKIP_TEST_IF_NO_MEDIA_CODEC(); 437 SKIP_TEST_IF_NO_MEDIA_CODEC();
441 ASSERT_NO_FATAL_FAILURE(Initialize()); 438 ASSERT_NO_FATAL_FAILURE(Initialize());
442 Decode(); 439 Decode();
443 EXPECT_EQ(AudioDecoder::kOk, last_decode_status()); 440 EXPECT_EQ(DecodeStatus::OK, last_decode_status());
444 } 441 }
445 442
446 TEST_P(AudioDecoderTest, Reset) { 443 TEST_P(AudioDecoderTest, Reset) {
447 SKIP_TEST_IF_NO_MEDIA_CODEC(); 444 SKIP_TEST_IF_NO_MEDIA_CODEC();
448 ASSERT_NO_FATAL_FAILURE(Initialize()); 445 ASSERT_NO_FATAL_FAILURE(Initialize());
449 Reset(); 446 Reset();
450 } 447 }
451 448
452 TEST_P(AudioDecoderTest, NoTimestamp) { 449 TEST_P(AudioDecoderTest, NoTimestamp) {
453 SKIP_TEST_IF_NO_MEDIA_CODEC(); 450 SKIP_TEST_IF_NO_MEDIA_CODEC();
454 ASSERT_NO_FATAL_FAILURE(Initialize()); 451 ASSERT_NO_FATAL_FAILURE(Initialize());
455 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(0)); 452 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(0));
456 buffer->set_timestamp(kNoTimestamp()); 453 buffer->set_timestamp(kNoTimestamp());
457 DecodeBuffer(buffer); 454 DecodeBuffer(buffer);
458 EXPECT_EQ(AudioDecoder::kDecodeError, last_decode_status()); 455 EXPECT_EQ(DecodeStatus::DECODE_ERROR, last_decode_status());
459 } 456 }
460 457
461 TEST_P(OpusAudioDecoderBehavioralTest, InitializeWithNoCodecDelay) { 458 TEST_P(OpusAudioDecoderBehavioralTest, InitializeWithNoCodecDelay) {
462 ASSERT_EQ(GetParam().decoder_type, OPUS); 459 ASSERT_EQ(GetParam().decoder_type, OPUS);
463 std::vector<uint8_t> extra_data( 460 std::vector<uint8_t> extra_data(
464 kOpusExtraData, 461 kOpusExtraData,
465 kOpusExtraData + arraysize(kOpusExtraData)); 462 kOpusExtraData + arraysize(kOpusExtraData));
466 AudioDecoderConfig decoder_config; 463 AudioDecoderConfig decoder_config;
467 decoder_config.Initialize(kCodecOpus, kSampleFormatF32, CHANNEL_LAYOUT_STEREO, 464 decoder_config.Initialize(kCodecOpus, kSampleFormatF32, CHANNEL_LAYOUT_STEREO,
468 48000, extra_data, Unencrypted(), 465 48000, extra_data, Unencrypted(),
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 }; 618 };
622 619
623 INSTANTIATE_TEST_CASE_P(FFmpegAudioDecoderTest, 620 INSTANTIATE_TEST_CASE_P(FFmpegAudioDecoderTest,
624 AudioDecoderTest, 621 AudioDecoderTest,
625 testing::ValuesIn(kFFmpegTests)); 622 testing::ValuesIn(kFFmpegTests));
626 INSTANTIATE_TEST_CASE_P(FFmpegAudioDecoderBehavioralTest, 623 INSTANTIATE_TEST_CASE_P(FFmpegAudioDecoderBehavioralTest,
627 FFmpegAudioDecoderBehavioralTest, 624 FFmpegAudioDecoderBehavioralTest,
628 testing::ValuesIn(kFFmpegBehavioralTest)); 625 testing::ValuesIn(kFFmpegBehavioralTest));
629 626
630 } // namespace media 627 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/android/media_codec_audio_decoder.cc ('k') | media/filters/decoder_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698