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() { |
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(AudioDecoder::kOk, 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 decoded_audio_.push_back(buffer); |
| 109 } |
| 110 |
| 111 void DecodeFinished(AudioDecoder::Status status) { |
104 EXPECT_TRUE(pending_decode_); | 112 EXPECT_TRUE(pending_decode_); |
105 pending_decode_ = false; | 113 pending_decode_ = false; |
106 | 114 |
107 if (status == AudioDecoder::kNotEnoughData) { | 115 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 } | 116 } |
124 | 117 |
125 void ResetFinished() { | 118 void ResetFinished() { |
126 EXPECT_TRUE(pending_reset_); | 119 EXPECT_TRUE(pending_reset_); |
127 // Reset should always finish after Decode. | 120 // Reset should always finish after Decode. |
128 EXPECT_FALSE(pending_decode_); | 121 EXPECT_FALSE(pending_decode_); |
129 | 122 |
130 pending_reset_ = false; | 123 pending_reset_ = false; |
131 } | 124 } |
132 | 125 |
(...skipping 11 matching lines...) Expand all Loading... |
144 | 137 |
145 base::MessageLoop message_loop_; | 138 base::MessageLoop message_loop_; |
146 scoped_ptr<FFmpegAudioDecoder> decoder_; | 139 scoped_ptr<FFmpegAudioDecoder> decoder_; |
147 bool pending_decode_; | 140 bool pending_decode_; |
148 bool pending_reset_; | 141 bool pending_reset_; |
149 | 142 |
150 scoped_refptr<DecoderBuffer> vorbis_extradata_; | 143 scoped_refptr<DecoderBuffer> vorbis_extradata_; |
151 | 144 |
152 std::deque<scoped_refptr<DecoderBuffer> > encoded_audio_; | 145 std::deque<scoped_refptr<DecoderBuffer> > encoded_audio_; |
153 std::deque<scoped_refptr<AudioBuffer> > decoded_audio_; | 146 std::deque<scoped_refptr<AudioBuffer> > decoded_audio_; |
| 147 AudioDecoder::Status last_decode_status_; |
154 }; | 148 }; |
155 | 149 |
156 TEST_F(FFmpegAudioDecoderTest, Initialize) { | 150 TEST_F(FFmpegAudioDecoderTest, Initialize) { |
157 AudioDecoderConfig config(kCodecVorbis, | 151 AudioDecoderConfig config(kCodecVorbis, |
158 kSampleFormatPlanarF32, | 152 kSampleFormatPlanarF32, |
159 CHANNEL_LAYOUT_STEREO, | 153 CHANNEL_LAYOUT_STEREO, |
160 44100, | 154 44100, |
161 vorbis_extradata_->data(), | 155 vorbis_extradata_->data(), |
162 vorbis_extradata_->data_size(), | 156 vorbis_extradata_->data_size(), |
163 false); // Not encrypted. | 157 false); // Not encrypted. |
164 Stop(); | 158 Stop(); |
165 } | 159 } |
166 | 160 |
167 TEST_F(FFmpegAudioDecoderTest, ProduceAudioSamples) { | 161 TEST_F(FFmpegAudioDecoderTest, ProduceAudioSamples) { |
168 // Vorbis requires N+1 packets to produce audio data for N packets. | 162 // Vorbis requires N+1 packets to produce audio data for N packets. |
169 // | 163 // |
170 // This will should result in the demuxer receiving three reads for two | 164 // This will should result in the demuxer receiving three reads for two |
171 // requests to produce audio samples. | 165 // requests to produce audio samples. |
172 Decode(); | 166 Decode(); |
173 Decode(); | 167 Decode(); |
174 Decode(); | 168 Decode(); |
| 169 Decode(); |
175 | 170 |
176 ASSERT_EQ(3u, decoded_audio_.size()); | 171 ASSERT_EQ(3u, decoded_audio_.size()); |
177 ExpectDecodedAudio(0, 0, 2902); | 172 ExpectDecodedAudio(0, 0, 2902); |
178 ExpectDecodedAudio(1, 2902, 13061); | 173 ExpectDecodedAudio(1, 2902, 13061); |
179 ExpectDecodedAudio(2, 15963, 23219); | 174 ExpectDecodedAudio(2, 15963, 23219); |
180 | 175 |
181 // Call one more time to trigger EOS. | 176 // Call one more time to trigger EOS. |
182 Decode(); | 177 Decode(); |
183 ASSERT_EQ(4u, decoded_audio_.size()); | 178 ASSERT_EQ(5u, decoded_audio_.size()); |
184 ExpectEndOfStream(3); | 179 ExpectEndOfStream(3); |
185 Stop(); | 180 Stop(); |
186 } | 181 } |
187 | 182 |
188 TEST_F(FFmpegAudioDecoderTest, DecodeAbort) { | |
189 encoded_audio_.clear(); | |
190 encoded_audio_.push_back(NULL); | |
191 Decode(); | |
192 | |
193 EXPECT_EQ(decoded_audio_.size(), 1u); | |
194 EXPECT_TRUE(decoded_audio_[0].get() == NULL); | |
195 Stop(); | |
196 } | |
197 | |
198 TEST_F(FFmpegAudioDecoderTest, PendingDecode_Stop) { | 183 TEST_F(FFmpegAudioDecoderTest, PendingDecode_Stop) { |
199 Decode(); | 184 Decode(); |
200 Stop(); | 185 Stop(); |
201 SatisfyPendingDecode(); | 186 SatisfyPendingDecode(); |
202 } | 187 } |
203 | 188 |
204 TEST_F(FFmpegAudioDecoderTest, PendingDecode_Reset) { | 189 TEST_F(FFmpegAudioDecoderTest, PendingDecode_Reset) { |
205 Decode(); | 190 Decode(); |
206 Reset(); | 191 Reset(); |
207 SatisfyPendingDecode(); | 192 SatisfyPendingDecode(); |
208 Stop(); | 193 Stop(); |
209 } | 194 } |
210 | 195 |
211 TEST_F(FFmpegAudioDecoderTest, PendingDecode_ResetStop) { | 196 TEST_F(FFmpegAudioDecoderTest, PendingDecode_ResetStop) { |
212 Decode(); | 197 Decode(); |
213 Reset(); | 198 Reset(); |
214 Stop(); | 199 Stop(); |
215 SatisfyPendingDecode(); | 200 SatisfyPendingDecode(); |
216 } | 201 } |
217 | 202 |
218 } // namespace media | 203 } // namespace media |
OLD | NEW |