Chromium Code Reviews| Index: media/filters/audio_decoder_unittest.cc |
| diff --git a/media/filters/audio_decoder_unittest.cc b/media/filters/audio_decoder_unittest.cc |
| index 5f3e96df8811b6f67fbc57849cd00a5ea48461ae..1b5fcef0ad7f7a70f1496af2a34567cd5d3e848a 100644 |
| --- a/media/filters/audio_decoder_unittest.cc |
| +++ b/media/filters/audio_decoder_unittest.cc |
| @@ -5,7 +5,6 @@ |
| #include <stddef.h> |
| #include <stdint.h> |
| -#include <deque> |
| #include <vector> |
| #include "base/bind.h" |
| @@ -16,6 +15,7 @@ |
| #include "base/run_loop.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/sys_byteorder.h" |
| +#include "base/threading/platform_thread.h" |
| #include "build/build_config.h" |
| #include "media/base/audio_buffer.h" |
| #include "media/base/audio_bus.h" |
| @@ -32,6 +32,10 @@ |
| #include "media/filters/opus_audio_decoder.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#if defined(OS_ANDROID) |
| +#include "media/filters/android/media_codec_audio_decoder.h" |
| +#endif |
| + |
| namespace media { |
| // The number of packets to read and then decode from each file. |
| @@ -44,6 +48,9 @@ static const uint8_t kOpusExtraData[] = { |
| enum AudioDecoderType { |
| FFMPEG, |
| OPUS, |
| +#if defined(OS_ANDROID) |
| + MEDIA_CODEC, |
| +#endif |
| }; |
| struct DecodedBufferExpectations { |
| @@ -113,6 +120,11 @@ class AudioDecoderTest : public testing::TestWithParam<DecoderTestData> { |
| decoder_.reset( |
| new OpusAudioDecoder(message_loop_.task_runner())); |
| break; |
| +#if defined(OS_ANDROID) |
| + case MEDIA_CODEC: |
| + decoder_.reset(new MediaCodecAudioDecoder(message_loop_.task_runner())); |
| + break; |
| +#endif |
| } |
| } |
| @@ -129,10 +141,22 @@ class AudioDecoderTest : public testing::TestWithParam<DecoderTestData> { |
| decoder_->Decode( |
| buffer, |
| base::Bind(&AudioDecoderTest::DecodeFinished, base::Unretained(this))); |
| - base::RunLoop().RunUntilIdle(); |
| + WaitForDecodeResponse(); |
| ASSERT_FALSE(pending_decode_); |
| } |
| + void WaitForDecodeResponse() { |
|
liberato (no reviews please)
2016/02/29 17:08:57
"do work for 100msec" seems flaky. i see that the
Tima Vaisburd
2016/02/29 21:01:03
I think that mocking MediaCodec is a good idea, as
liberato (no reviews please)
2016/03/01 22:20:39
i was thinking about a very simple MediaCodec mock
Tima Vaisburd
2016/03/01 23:35:33
Even if the MediaCodec returns the output buffer i
liberato (no reviews please)
2016/03/02 15:02:01
flakiness: a delay of 100msec seems like something
|
| + const base::TimeDelta timeout = base::TimeDelta::FromMilliseconds(100); |
| + const base::TimeDelta sleep_time = base::TimeDelta::FromMilliseconds(10); |
| + |
| + for (int i = 0; i < timeout / sleep_time; ++i) { |
|
liberato (no reviews please)
2016/02/29 17:08:57
not sure if ::Sleep guarantees not to wake up earl
Tima Vaisburd
2016/02/29 21:01:03
Yes, I was not sure whether to use the Sleep(), or
liberato (no reviews please)
2016/03/02 15:02:01
i think that i like dale's suggestion better than
|
| + base::RunLoop().RunUntilIdle(); |
| + if (!pending_decode_) |
| + break; |
| + base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); |
| + } |
| + } |
| + |
| void SendEndOfStream() { |
| DecodeBuffer(DecoderBuffer::CreateEOSBuffer()); |
| } |
| @@ -331,20 +355,19 @@ TEST_P(AudioDecoderTest, ProduceAudioSamples) { |
| // Run the test multiple times with a seek back to the beginning in between. |
| std::vector<std::string> decoded_audio_md5_hashes; |
| for (int i = 0; i < 2; ++i) { |
| - for (size_t j = 0; j < kDecodeRuns; ++j) { |
| - do { |
| - Decode(); |
| - ASSERT_EQ(last_decode_status(), AudioDecoder::kOk); |
| - // Some codecs have a multiple buffer delay and require an extra |
| - // Decode() step to extract the desired number of output buffers. |
| - } while (j == 0 && decoded_audio_size() == 0); |
| - |
| - // On the first pass record the exact MD5 hash for each decoded buffer. |
| - if (i == 0) |
| + // Run decoder until we get at least |kDecodeRuns| output buffers. |
| + do { |
| + Decode(); |
| + ASSERT_EQ(last_decode_status(), AudioDecoder::kOk); |
| + } while (decoded_audio_size() < kDecodeRuns); |
|
liberato (no reviews please)
2016/02/29 17:08:57
why did this change?
does MediaCodec have a varia
Tima Vaisburd
2016/02/29 21:01:03
I think first. See below.
|
| + |
| + // On the first pass record the exact MD5 hash for each decoded buffer. |
| + if (i == 0) { |
| + for (size_t j = 0; j < kDecodeRuns; ++j) |
| decoded_audio_md5_hashes.push_back(GetDecodedAudioMD5(j)); |
| } |
| - ASSERT_EQ(kDecodeRuns, decoded_audio_size()); |
| + ASSERT_LE(kDecodeRuns, decoded_audio_size()); |
|
liberato (no reviews please)
2016/02/29 17:08:57
why can't we guarantee EQ here? is it because one
Tima Vaisburd
2016/02/29 21:01:03
As far as I understand, this is the consequence of
liberato (no reviews please)
2016/03/01 22:20:39
i don't think eq is important, but it's probably w
Tima Vaisburd
2016/03/01 23:35:33
I went a little deeper to see why we cannot ASSERT
|
| // On the first pass verify the basic audio hash and sample info. On the |
| // second, verify the exact MD5 sum for each packet. It shouldn't change. |
| @@ -354,7 +377,6 @@ TEST_P(AudioDecoderTest, ProduceAudioSamples) { |
| } |
| SendEndOfStream(); |
| - ASSERT_EQ(kDecodeRuns, decoded_audio_size()); |
| // Seek back to the beginning. Calls Reset() on the decoder. |
| Seek(start_timestamp()); |
| @@ -455,8 +477,20 @@ INSTANTIATE_TEST_CASE_P(OpusAudioDecoderBehavioralTest, |
| OpusAudioDecoderBehavioralTest, |
| testing::ValuesIn(kOpusBehavioralTest)); |
| +#if defined(OS_ANDROID) |
| + |
| +const DecoderTestData kMediaCodecTests[] = { |
| + {MEDIA_CODEC, kCodecOpus, "bear-opus.ogg", kBearOpusExpectations, 24, 48000, |
| + CHANNEL_LAYOUT_STEREO}, |
| +}; |
| + |
| +INSTANTIATE_TEST_CASE_P(MediaCodecAudioDecoderTest, |
| + AudioDecoderTest, |
| + testing::ValuesIn(kMediaCodecTests)); |
| + |
| +#else // !defined(OS_ANDROID) |
| + |
| // Disable all FFmpeg decoder tests on Android. http://crbug.com/570762. |
| -#if !defined(OS_ANDROID) |
| #if defined(USE_PROPRIETARY_CODECS) |
| const DecodedBufferExpectations kSfxMp3Expectations[] = { |