Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(950)

Unified Diff: media/filters/ffmpeg_audio_decoder.cc

Issue 297553002: Add callback in VideoDecoder and AudioDecoder to return decoded frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/filters/ffmpeg_audio_decoder.cc
diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc
index 00832a05abf048953b45fce0b040667b3ded9679..30673a7b0c1da213770ab76c0a62358db02dc49b 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,24 @@ 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());
+ decode_cb_bound.Run(kOk);
return;
}
if (!buffer) {
xhwang 2014/06/05 21:53:50 hmm, should this ever happen?
Sergey Ulanov 2014/06/06 22:49:40 Done.
- decode_cb_bound.Run(kAborted, NULL);
+ decode_cb_bound.Run(kAborted);
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 +250,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;
}
@@ -278,30 +271,20 @@ void FFmpegAudioDecoder::DecodeBuffer(
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 (state_ == kFlushCodec) {
+ state_ = kDecodeFinished;
+ output_cb_.Run(AudioBuffer::CreateEOSBuffer());
xhwang 2014/06/05 21:53:50 should we keep calling FFmpegDecode(EOS) until the
Sergey Ulanov 2014/06/06 22:49:40 There is a loop in FFmpegDecode() which should flu
}
- 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 +345,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;
}
@@ -386,9 +368,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);

Powered by Google App Engine
This is Rietveld 408576698