Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <deque> | 5 #include <deque> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 using ::testing::StrictMock; | 22 using ::testing::StrictMock; |
| 23 | 23 |
| 24 namespace media { | 24 namespace media { |
| 25 | 25 |
| 26 class FFmpegAudioDecoderTest : public testing::Test { | 26 class FFmpegAudioDecoderTest : public testing::Test { |
| 27 public: | 27 public: |
| 28 FFmpegAudioDecoderTest() | 28 FFmpegAudioDecoderTest() |
| 29 : decoder_(new FFmpegAudioDecoder(message_loop_.message_loop_proxy(), | 29 : decoder_(new FFmpegAudioDecoder(message_loop_.message_loop_proxy(), |
| 30 LogCB())), | 30 LogCB())), |
| 31 pending_decode_(false), | 31 pending_decode_(false), |
| 32 pending_reset_(false) { | 32 pending_reset_(false), |
| 33 last_decode_status_(AudioDecoder::kOk) { | |
| 33 FFmpegGlue::InitializeFFmpeg(); | 34 FFmpegGlue::InitializeFFmpeg(); |
| 34 | 35 |
| 35 vorbis_extradata_ = ReadTestDataFile("vorbis-extradata"); | 36 vorbis_extradata_ = ReadTestDataFile("vorbis-extradata"); |
| 36 | 37 |
| 37 // Refer to media/test/data/README for details on vorbis test data. | 38 // Refer to media/test/data/README for details on vorbis test data. |
| 38 for (int i = 0; i < 4; ++i) { | 39 for (int i = 0; i < 4; ++i) { |
| 39 scoped_refptr<DecoderBuffer> buffer = | 40 scoped_refptr<DecoderBuffer> buffer = |
| 40 ReadTestDataFile(base::StringPrintf("vorbis-packet-%d", i)); | 41 ReadTestDataFile(base::StringPrintf("vorbis-packet-%d", i)); |
| 41 | 42 |
| 42 if (i < 3) { | 43 if (i < 3) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 62 | 63 |
| 63 void Initialize() { | 64 void Initialize() { |
| 64 AudioDecoderConfig config(kCodecVorbis, | 65 AudioDecoderConfig config(kCodecVorbis, |
| 65 kSampleFormatPlanarF32, | 66 kSampleFormatPlanarF32, |
| 66 CHANNEL_LAYOUT_STEREO, | 67 CHANNEL_LAYOUT_STEREO, |
| 67 44100, | 68 44100, |
| 68 vorbis_extradata_->data(), | 69 vorbis_extradata_->data(), |
| 69 vorbis_extradata_->data_size(), | 70 vorbis_extradata_->data_size(), |
| 70 false); // Not encrypted. | 71 false); // Not encrypted. |
| 71 decoder_->Initialize(config, | 72 decoder_->Initialize(config, |
| 72 NewExpectedStatusCB(PIPELINE_OK)); | 73 NewExpectedStatusCB(PIPELINE_OK), |
| 74 base::Bind(&FFmpegAudioDecoderTest::OnDecoderOutput, | |
| 75 base::Unretained(this))); | |
| 73 base::RunLoop().RunUntilIdle(); | 76 base::RunLoop().RunUntilIdle(); |
| 74 } | 77 } |
| 75 | 78 |
| 76 void SatisfyPendingDecode() { | 79 void SatisfyPendingDecode() { |
| 77 base::RunLoop().RunUntilIdle(); | 80 base::RunLoop().RunUntilIdle(); |
| 78 } | 81 } |
| 79 | 82 |
| 80 void Decode() { | 83 void Decode(AudioDecoder::Status expected_status) { |
| 81 pending_decode_ = true; | 84 pending_decode_ = true; |
| 82 scoped_refptr<DecoderBuffer> buffer(encoded_audio_.front()); | 85 scoped_refptr<DecoderBuffer> buffer(encoded_audio_.front()); |
| 83 encoded_audio_.pop_front(); | 86 encoded_audio_.pop_front(); |
| 84 decoder_->Decode(buffer, | 87 decoder_->Decode(buffer, |
| 85 base::Bind(&FFmpegAudioDecoderTest::DecodeFinished, | 88 base::Bind(&FFmpegAudioDecoderTest::DecodeFinished, |
| 86 base::Unretained(this))); | 89 base::Unretained(this))); |
| 87 base::RunLoop().RunUntilIdle(); | 90 base::RunLoop().RunUntilIdle(); |
| 91 EXPECT_FALSE(pending_decode_); | |
| 92 EXPECT_EQ(expected_status, last_decode_status_); | |
| 88 } | 93 } |
| 89 | 94 |
| 90 void Reset() { | 95 void Reset() { |
| 91 pending_reset_ = true; | 96 pending_reset_ = true; |
| 92 decoder_->Reset(base::Bind( | 97 decoder_->Reset(base::Bind( |
| 93 &FFmpegAudioDecoderTest::ResetFinished, base::Unretained(this))); | 98 &FFmpegAudioDecoderTest::ResetFinished, base::Unretained(this))); |
| 94 base::RunLoop().RunUntilIdle(); | 99 base::RunLoop().RunUntilIdle(); |
| 95 } | 100 } |
| 96 | 101 |
| 97 void Stop() { | 102 void Stop() { |
| 98 decoder_->Stop(); | 103 decoder_->Stop(); |
| 99 base::RunLoop().RunUntilIdle(); | 104 base::RunLoop().RunUntilIdle(); |
| 100 } | 105 } |
| 101 | 106 |
| 102 void DecodeFinished(AudioDecoder::Status status, | 107 void OnDecoderOutput(const scoped_refptr<AudioBuffer>& buffer) { |
| 103 const scoped_refptr<AudioBuffer>& buffer) { | 108 LOG(ERROR) << "Outp"; |
|
xhwang
2014/06/05 21:53:50
rm
Sergey Ulanov
2014/06/06 22:49:40
Done.
| |
| 109 decoded_audio_.push_back(buffer); | |
| 110 } | |
| 111 | |
| 112 void DecodeFinished(AudioDecoder::Status status) { | |
| 113 LOG(ERROR) << "Finished"; | |
|
xhwang
2014/06/05 21:53:50
rm
Sergey Ulanov
2014/06/06 22:49:40
Done.
| |
| 104 EXPECT_TRUE(pending_decode_); | 114 EXPECT_TRUE(pending_decode_); |
| 105 pending_decode_ = false; | 115 pending_decode_ = false; |
| 106 | 116 |
| 107 if (status == AudioDecoder::kNotEnoughData) { | 117 last_decode_status_ = status; |
| 108 EXPECT_TRUE(buffer.get() == NULL); | |
| 109 Decode(); | |
| 110 return; | |
| 111 } | |
| 112 | |
| 113 decoded_audio_.push_back(buffer); | |
| 114 | |
| 115 // If we hit a NULL buffer or have a pending reset, we expect an abort. | |
| 116 if (buffer.get() == NULL || pending_reset_) { | |
| 117 EXPECT_TRUE(buffer.get() == NULL); | |
| 118 EXPECT_EQ(status, AudioDecoder::kAborted); | |
| 119 return; | |
| 120 } | |
| 121 | |
| 122 EXPECT_EQ(status, AudioDecoder::kOk); | |
| 123 } | 118 } |
| 124 | 119 |
| 125 void ResetFinished() { | 120 void ResetFinished() { |
| 126 EXPECT_TRUE(pending_reset_); | 121 EXPECT_TRUE(pending_reset_); |
| 127 // Reset should always finish after Decode. | 122 // Reset should always finish after Decode. |
| 128 EXPECT_FALSE(pending_decode_); | 123 EXPECT_FALSE(pending_decode_); |
| 129 | 124 |
| 130 pending_reset_ = false; | 125 pending_reset_ = false; |
| 131 } | 126 } |
| 132 | 127 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 144 | 139 |
| 145 base::MessageLoop message_loop_; | 140 base::MessageLoop message_loop_; |
| 146 scoped_ptr<FFmpegAudioDecoder> decoder_; | 141 scoped_ptr<FFmpegAudioDecoder> decoder_; |
| 147 bool pending_decode_; | 142 bool pending_decode_; |
| 148 bool pending_reset_; | 143 bool pending_reset_; |
| 149 | 144 |
| 150 scoped_refptr<DecoderBuffer> vorbis_extradata_; | 145 scoped_refptr<DecoderBuffer> vorbis_extradata_; |
| 151 | 146 |
| 152 std::deque<scoped_refptr<DecoderBuffer> > encoded_audio_; | 147 std::deque<scoped_refptr<DecoderBuffer> > encoded_audio_; |
| 153 std::deque<scoped_refptr<AudioBuffer> > decoded_audio_; | 148 std::deque<scoped_refptr<AudioBuffer> > decoded_audio_; |
| 149 AudioDecoder::Status last_decode_status_; | |
| 154 }; | 150 }; |
| 155 | 151 |
| 156 TEST_F(FFmpegAudioDecoderTest, Initialize) { | 152 TEST_F(FFmpegAudioDecoderTest, Initialize) { |
| 157 AudioDecoderConfig config(kCodecVorbis, | 153 AudioDecoderConfig config(kCodecVorbis, |
| 158 kSampleFormatPlanarF32, | 154 kSampleFormatPlanarF32, |
| 159 CHANNEL_LAYOUT_STEREO, | 155 CHANNEL_LAYOUT_STEREO, |
| 160 44100, | 156 44100, |
| 161 vorbis_extradata_->data(), | 157 vorbis_extradata_->data(), |
| 162 vorbis_extradata_->data_size(), | 158 vorbis_extradata_->data_size(), |
| 163 false); // Not encrypted. | 159 false); // Not encrypted. |
| 164 Stop(); | 160 Stop(); |
| 165 } | 161 } |
| 166 | 162 |
| 167 TEST_F(FFmpegAudioDecoderTest, ProduceAudioSamples) { | 163 TEST_F(FFmpegAudioDecoderTest, ProduceAudioSamples) { |
| 168 // Vorbis requires N+1 packets to produce audio data for N packets. | 164 // Vorbis requires N+1 packets to produce audio data for N packets. |
| 169 // | 165 // |
| 170 // This will should result in the demuxer receiving three reads for two | 166 // This will should result in the demuxer receiving three reads for two |
| 171 // requests to produce audio samples. | 167 // requests to produce audio samples. |
| 172 Decode(); | 168 Decode(AudioDecoder::kOk); |
| 173 Decode(); | 169 Decode(AudioDecoder::kOk); |
| 174 Decode(); | 170 Decode(AudioDecoder::kOk); |
| 171 Decode(AudioDecoder::kOk); | |
| 175 | 172 |
| 176 ASSERT_EQ(3u, decoded_audio_.size()); | 173 ASSERT_EQ(3u, decoded_audio_.size()); |
| 177 ExpectDecodedAudio(0, 0, 2902); | 174 ExpectDecodedAudio(0, 0, 2902); |
| 178 ExpectDecodedAudio(1, 2902, 13061); | 175 ExpectDecodedAudio(1, 2902, 13061); |
| 179 ExpectDecodedAudio(2, 15963, 23219); | 176 ExpectDecodedAudio(2, 15963, 23219); |
| 180 | 177 |
| 181 // Call one more time to trigger EOS. | 178 // Call one more time to trigger EOS. |
| 182 Decode(); | 179 Decode(AudioDecoder::kOk); |
| 183 ASSERT_EQ(4u, decoded_audio_.size()); | 180 ASSERT_EQ(5u, decoded_audio_.size()); |
| 184 ExpectEndOfStream(3); | 181 ExpectEndOfStream(3); |
| 185 Stop(); | 182 Stop(); |
| 186 } | 183 } |
| 187 | 184 |
| 188 TEST_F(FFmpegAudioDecoderTest, DecodeAbort) { | 185 TEST_F(FFmpegAudioDecoderTest, DecodeAbort) { |
| 189 encoded_audio_.clear(); | 186 encoded_audio_.clear(); |
| 190 encoded_audio_.push_back(NULL); | 187 encoded_audio_.push_back(NULL); |
| 191 Decode(); | 188 Decode(AudioDecoder::kAborted); |
|
xhwang
2014/06/05 21:53:50
This is probably obsolete. Now DemuxerStream will
Sergey Ulanov
2014/06/06 22:49:40
Done.
| |
| 192 | 189 EXPECT_TRUE(decoded_audio_.empty()); |
| 193 EXPECT_EQ(decoded_audio_.size(), 1u); | |
| 194 EXPECT_TRUE(decoded_audio_[0].get() == NULL); | |
| 195 Stop(); | 190 Stop(); |
| 196 } | 191 } |
| 197 | 192 |
| 198 TEST_F(FFmpegAudioDecoderTest, PendingDecode_Stop) { | 193 TEST_F(FFmpegAudioDecoderTest, PendingDecode_Stop) { |
| 199 Decode(); | 194 Decode(AudioDecoder::kOk); |
| 200 Stop(); | 195 Stop(); |
| 201 SatisfyPendingDecode(); | 196 SatisfyPendingDecode(); |
| 202 } | 197 } |
| 203 | 198 |
| 204 TEST_F(FFmpegAudioDecoderTest, PendingDecode_Reset) { | 199 TEST_F(FFmpegAudioDecoderTest, PendingDecode_Reset) { |
| 205 Decode(); | 200 Decode(AudioDecoder::kOk); |
| 206 Reset(); | 201 Reset(); |
| 207 SatisfyPendingDecode(); | 202 SatisfyPendingDecode(); |
| 208 Stop(); | 203 Stop(); |
| 209 } | 204 } |
| 210 | 205 |
| 211 TEST_F(FFmpegAudioDecoderTest, PendingDecode_ResetStop) { | 206 TEST_F(FFmpegAudioDecoderTest, PendingDecode_ResetStop) { |
| 212 Decode(); | 207 Decode(AudioDecoder::kOk); |
| 213 Reset(); | 208 Reset(); |
| 214 Stop(); | 209 Stop(); |
| 215 SatisfyPendingDecode(); | 210 SatisfyPendingDecode(); |
| 216 } | 211 } |
| 217 | 212 |
| 218 } // namespace media | 213 } // namespace media |
| OLD | NEW |