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(); |
DaleCurtis
2016/02/29 21:51:30
Can we instead have DecodeFinished() take a closur
Tima Vaisburd
2016/03/01 01:55:49
I'm sorry, I did not understand. Could you, please
DaleCurtis
2016/03/01 20:25:13
I mean instead of having a spin-loop do:
base
Tima Vaisburd
2016/03/01 23:35:33
Done.
|
ASSERT_FALSE(pending_decode_); |
} |
+ void WaitForDecodeResponse() { |
+ 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) { |
+ 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); |
+ |
+ // 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()); |
// 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[] = { |