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 "media/filters/ffmpeg_audio_decoder.h" | 5 #include "media/filters/ffmpeg_audio_decoder.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } | 185 } |
186 | 186 |
187 void FFmpegAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, | 187 void FFmpegAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, |
188 const DecodeCB& decode_cb) { | 188 const DecodeCB& decode_cb) { |
189 DCHECK(task_runner_->BelongsToCurrentThread()); | 189 DCHECK(task_runner_->BelongsToCurrentThread()); |
190 DCHECK(!decode_cb.is_null()); | 190 DCHECK(!decode_cb.is_null()); |
191 CHECK_NE(state_, kUninitialized); | 191 CHECK_NE(state_, kUninitialized); |
192 DecodeCB decode_cb_bound = BindToCurrentLoop(decode_cb); | 192 DecodeCB decode_cb_bound = BindToCurrentLoop(decode_cb); |
193 | 193 |
194 if (state_ == kError) { | 194 if (state_ == kError) { |
195 decode_cb_bound.Run(kDecodeError); | 195 decode_cb_bound.Run(DecodeStatus::DECODE_ERROR); |
196 return; | 196 return; |
197 } | 197 } |
198 | 198 |
199 // Do nothing if decoding has finished. | 199 // Do nothing if decoding has finished. |
200 if (state_ == kDecodeFinished) { | 200 if (state_ == kDecodeFinished) { |
201 decode_cb_bound.Run(kOk); | 201 decode_cb_bound.Run(DecodeStatus::OK); |
202 return; | 202 return; |
203 } | 203 } |
204 | 204 |
205 DecodeBuffer(buffer, decode_cb_bound); | 205 DecodeBuffer(buffer, decode_cb_bound); |
206 } | 206 } |
207 | 207 |
208 void FFmpegAudioDecoder::Reset(const base::Closure& closure) { | 208 void FFmpegAudioDecoder::Reset(const base::Closure& closure) { |
209 DCHECK(task_runner_->BelongsToCurrentThread()); | 209 DCHECK(task_runner_->BelongsToCurrentThread()); |
210 | 210 |
211 avcodec_flush_buffers(codec_context_.get()); | 211 avcodec_flush_buffers(codec_context_.get()); |
212 state_ = kNormal; | 212 state_ = kNormal; |
213 ResetTimestampState(); | 213 ResetTimestampState(); |
214 task_runner_->PostTask(FROM_HERE, closure); | 214 task_runner_->PostTask(FROM_HERE, closure); |
215 } | 215 } |
216 | 216 |
217 void FFmpegAudioDecoder::DecodeBuffer( | 217 void FFmpegAudioDecoder::DecodeBuffer( |
218 const scoped_refptr<DecoderBuffer>& buffer, | 218 const scoped_refptr<DecoderBuffer>& buffer, |
219 const DecodeCB& decode_cb) { | 219 const DecodeCB& decode_cb) { |
220 DCHECK(task_runner_->BelongsToCurrentThread()); | 220 DCHECK(task_runner_->BelongsToCurrentThread()); |
221 DCHECK_NE(state_, kUninitialized); | 221 DCHECK_NE(state_, kUninitialized); |
222 DCHECK_NE(state_, kDecodeFinished); | 222 DCHECK_NE(state_, kDecodeFinished); |
223 DCHECK_NE(state_, kError); | 223 DCHECK_NE(state_, kError); |
224 DCHECK(buffer.get()); | 224 DCHECK(buffer.get()); |
225 | 225 |
226 // Make sure we are notified if http://crbug.com/49709 returns. Issue also | 226 // Make sure we are notified if http://crbug.com/49709 returns. Issue also |
227 // occurs with some damaged files. | 227 // occurs with some damaged files. |
228 if (!buffer->end_of_stream() && buffer->timestamp() == kNoTimestamp()) { | 228 if (!buffer->end_of_stream() && buffer->timestamp() == kNoTimestamp()) { |
229 DVLOG(1) << "Received a buffer without timestamps!"; | 229 DVLOG(1) << "Received a buffer without timestamps!"; |
230 decode_cb.Run(kDecodeError); | 230 decode_cb.Run(DecodeStatus::DECODE_ERROR); |
231 return; | 231 return; |
232 } | 232 } |
233 | 233 |
234 bool has_produced_frame; | 234 bool has_produced_frame; |
235 do { | 235 do { |
236 has_produced_frame = false; | 236 has_produced_frame = false; |
237 if (!FFmpegDecode(buffer, &has_produced_frame)) { | 237 if (!FFmpegDecode(buffer, &has_produced_frame)) { |
238 state_ = kError; | 238 state_ = kError; |
239 decode_cb.Run(kDecodeError); | 239 decode_cb.Run(DecodeStatus::DECODE_ERROR); |
240 return; | 240 return; |
241 } | 241 } |
242 // Repeat to flush the decoder after receiving EOS buffer. | 242 // Repeat to flush the decoder after receiving EOS buffer. |
243 } while (buffer->end_of_stream() && has_produced_frame); | 243 } while (buffer->end_of_stream() && has_produced_frame); |
244 | 244 |
245 if (buffer->end_of_stream()) | 245 if (buffer->end_of_stream()) |
246 state_ = kDecodeFinished; | 246 state_ = kDecodeFinished; |
247 | 247 |
248 decode_cb.Run(kOk); | 248 decode_cb.Run(DecodeStatus::OK); |
249 } | 249 } |
250 | 250 |
251 bool FFmpegAudioDecoder::FFmpegDecode( | 251 bool FFmpegAudioDecoder::FFmpegDecode( |
252 const scoped_refptr<DecoderBuffer>& buffer, | 252 const scoped_refptr<DecoderBuffer>& buffer, |
253 bool* has_produced_frame) { | 253 bool* has_produced_frame) { |
254 DCHECK(!*has_produced_frame); | 254 DCHECK(!*has_produced_frame); |
255 | 255 |
256 AVPacket packet; | 256 AVPacket packet; |
257 av_init_packet(&packet); | 257 av_init_packet(&packet); |
258 if (buffer->end_of_stream()) { | 258 if (buffer->end_of_stream()) { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 return true; | 420 return true; |
421 } | 421 } |
422 | 422 |
423 void FFmpegAudioDecoder::ResetTimestampState() { | 423 void FFmpegAudioDecoder::ResetTimestampState() { |
424 discard_helper_.reset(new AudioDiscardHelper(config_.samples_per_second(), | 424 discard_helper_.reset(new AudioDiscardHelper(config_.samples_per_second(), |
425 config_.codec_delay())); | 425 config_.codec_delay())); |
426 discard_helper_->Reset(config_.codec_delay()); | 426 discard_helper_->Reset(config_.codec_delay()); |
427 } | 427 } |
428 | 428 |
429 } // namespace media | 429 } // namespace media |
OLD | NEW |