| Index: media/filters/ffmpeg_audio_decoder.cc
|
| diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc
|
| index 704eefde5f3b84d76253688572b2a222c9f88ddf..b7e5459df0dc6511945c6df3e3b34ac25cb0a8b8 100644
|
| --- a/media/filters/ffmpeg_audio_decoder.cc
|
| +++ b/media/filters/ffmpeg_audio_decoder.cc
|
| @@ -141,7 +141,8 @@ FFmpegAudioDecoder::~FFmpegAudioDecoder() {
|
| }
|
|
|
| void FFmpegAudioDecoder::Initialize(const AudioDecoderConfig& config,
|
| - const PipelineStatusCB& status_cb) {
|
| + const PipelineStatusCB& status_cb,
|
| + const OutputCB& output_cb) {
|
| DCHECK(task_runner_->BelongsToCurrentThread());
|
| DCHECK(!config.is_encrypted());
|
|
|
| @@ -156,6 +157,7 @@ void FFmpegAudioDecoder::Initialize(const AudioDecoderConfig& config,
|
| }
|
|
|
| // Success!
|
| + output_cb_ = BindToCurrentLoop(output_cb);
|
| state_ = kNormal;
|
| initialize_cb.Run(PIPELINE_OK);
|
| }
|
| @@ -168,33 +170,19 @@ void FFmpegAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer,
|
| DecodeCB decode_cb_bound = BindToCurrentLoop(decode_cb);
|
|
|
| if (state_ == kError) {
|
| - decode_cb_bound.Run(kDecodeError, NULL);
|
| + decode_cb_bound.Run(kDecodeError);
|
| return;
|
| }
|
|
|
| - // Return empty frames if decoding has finished.
|
| + // Do nothing if decoding has finished.
|
| if (state_ == kDecodeFinished) {
|
| - decode_cb_bound.Run(kOk, AudioBuffer::CreateEOSBuffer());
|
| - return;
|
| - }
|
| -
|
| - if (!buffer) {
|
| - decode_cb_bound.Run(kAborted, NULL);
|
| + decode_cb_bound.Run(kOk);
|
| return;
|
| }
|
|
|
| DecodeBuffer(buffer, decode_cb_bound);
|
| }
|
|
|
| -scoped_refptr<AudioBuffer> FFmpegAudioDecoder::GetDecodeOutput() {
|
| - DCHECK(task_runner_->BelongsToCurrentThread());
|
| - if (queued_audio_.empty())
|
| - return NULL;
|
| - scoped_refptr<AudioBuffer> out = queued_audio_.front();
|
| - queued_audio_.pop_front();
|
| - return out;
|
| -}
|
| -
|
| void FFmpegAudioDecoder::Reset(const base::Closure& closure) {
|
| DCHECK(task_runner_->BelongsToCurrentThread());
|
|
|
| @@ -257,7 +245,7 @@ void FFmpegAudioDecoder::DecodeBuffer(
|
| // occurs with some damaged files.
|
| if (!buffer->end_of_stream() && buffer->timestamp() == kNoTimestamp()) {
|
| DVLOG(1) << "Received a buffer without timestamps!";
|
| - decode_cb.Run(kDecodeError, NULL);
|
| + decode_cb.Run(kDecodeError);
|
| return;
|
| }
|
|
|
| @@ -271,37 +259,22 @@ void FFmpegAudioDecoder::DecodeBuffer(
|
| discard_helper_->Reset(discard_frames);
|
| }
|
|
|
| - // Transition to kFlushCodec on the first end of stream buffer.
|
| - if (state_ == kNormal && buffer->end_of_stream()) {
|
| - state_ = kFlushCodec;
|
| - }
|
| -
|
| if (!FFmpegDecode(buffer)) {
|
| state_ = kError;
|
| - decode_cb.Run(kDecodeError, NULL);
|
| + decode_cb.Run(kDecodeError);
|
| return;
|
| }
|
|
|
| - if (queued_audio_.empty()) {
|
| - if (state_ == kFlushCodec) {
|
| - DCHECK(buffer->end_of_stream());
|
| - state_ = kDecodeFinished;
|
| - decode_cb.Run(kOk, AudioBuffer::CreateEOSBuffer());
|
| - return;
|
| - }
|
| -
|
| - decode_cb.Run(kNotEnoughData, NULL);
|
| - return;
|
| + if (buffer->end_of_stream()) {
|
| + state_ = kDecodeFinished;
|
| + output_cb_.Run(AudioBuffer::CreateEOSBuffer());
|
| }
|
|
|
| - decode_cb.Run(kOk, queued_audio_.front());
|
| - queued_audio_.pop_front();
|
| + decode_cb.Run(kOk);
|
| }
|
|
|
| bool FFmpegAudioDecoder::FFmpegDecode(
|
| const scoped_refptr<DecoderBuffer>& buffer) {
|
| - DCHECK(queued_audio_.empty());
|
| -
|
| AVPacket packet;
|
| av_init_packet(&packet);
|
| if (buffer->end_of_stream()) {
|
| @@ -362,7 +335,6 @@ bool FFmpegAudioDecoder::FFmpegDecode(
|
| << " the mimetype.";
|
| }
|
| // This is an unrecoverable error, so bail out.
|
| - queued_audio_.clear();
|
| av_frame_unref(av_frame_.get());
|
| return false;
|
| }
|
| @@ -385,9 +357,9 @@ bool FFmpegAudioDecoder::FFmpegDecode(
|
| const int decoded_frames = frame_decoded ? output->frame_count() : 0;
|
| if (IsEndOfStream(result, decoded_frames, buffer)) {
|
| DCHECK_EQ(packet.size, 0);
|
| - queued_audio_.push_back(AudioBuffer::CreateEOSBuffer());
|
| + output_cb_.Run(AudioBuffer::CreateEOSBuffer());
|
| } else if (discard_helper_->ProcessBuffers(buffer, output)) {
|
| - queued_audio_.push_back(output);
|
| + output_cb_.Run(output);
|
| }
|
| } while (packet.size > 0);
|
|
|
|
|