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

Unified Diff: media/filters/ffmpeg_audio_decoder.cc

Issue 126793002: Add Stop() to AudioDecoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handle stop with pending demuxer read Created 6 years, 11 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
« no previous file with comments | « media/filters/ffmpeg_audio_decoder.h ('k') | media/filters/opus_audio_decoder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/ffmpeg_audio_decoder.cc
diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc
index a0e5889eff11aca7e6c84c6bdbf26080ca2fd8c0..7a8d55b8cc7714726a6705a423e0d33265f42eea 100644
--- a/media/filters/ffmpeg_audio_decoder.cc
+++ b/media/filters/ffmpeg_audio_decoder.cc
@@ -118,6 +118,12 @@ void FFmpegAudioDecoder::Read(const ReadCB& read_cb) {
read_cb_ = BindToCurrentLoop(read_cb);
+ // Don't allow further reads after Stop().
DaleCurtis 2014/01/09 21:10:42 Since the renderer / AudioBufferStream will invoke
+ if (!stop_cb_.is_null()) {
+ base::ResetAndReturn(&read_cb_).Run(kAborted, NULL);
+ return;
+ }
+
// If we don't have any queued audio from the last packet we decoded, ask for
// more data from the demuxer to satisfy this read.
if (queued_audio_.empty()) {
@@ -155,12 +161,18 @@ void FFmpegAudioDecoder::Reset(const base::Closure& closure) {
reset_cb.Run();
}
-FFmpegAudioDecoder::~FFmpegAudioDecoder() {
- // TODO(scherkus): should we require Stop() to be called? this might end up
- // getting called on a random thread due to refcounting.
- ReleaseFFmpegResources();
+void FFmpegAudioDecoder::Stop(const base::Closure& closure) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ stop_cb_ = BindToCurrentLoop(closure);
+
+ if (read_cb_.is_null()) {
DaleCurtis 2014/01/09 21:10:42 {} is not necessary on single line conditionals.
+ DoStop();
+ }
+ // Otherwise a demuxer read is pending, we'll wait until it finishes.
}
+FFmpegAudioDecoder::~FFmpegAudioDecoder() {}
+
int FFmpegAudioDecoder::GetAudioBuffer(AVCodecContext* codec,
AVFrame* frame,
int flags) {
@@ -226,6 +238,15 @@ int FFmpegAudioDecoder::GetAudioBuffer(AVCodecContext* codec,
return 0;
}
+void FFmpegAudioDecoder::DoStop() {
+ DCHECK(!stop_cb_.is_null());
+
+ ResetTimestampState();
+ queued_audio_.clear();
+ ReleaseFFmpegResources();
+ base::ResetAndReturn(&stop_cb_).Run();
+}
+
void FFmpegAudioDecoder::ReadFromDemuxerStream() {
DCHECK(!read_cb_.is_null());
demuxer_stream_->Read(base::Bind(
@@ -240,6 +261,14 @@ void FFmpegAudioDecoder::BufferReady(
DCHECK(queued_audio_.empty());
DCHECK_EQ(status != DemuxerStream::kOk, !input.get()) << status;
+ // Stop() is pending, we'll ignore the buffer we just got, fire read_cb_, and
+ // complete the Stop.
+ if (!stop_cb_.is_null()) {
+ base::ResetAndReturn(&read_cb_).Run(kAborted, NULL);
+ DoStop();
+ return;
+ }
+
if (status == DemuxerStream::kAborted) {
DCHECK(!input.get());
base::ResetAndReturn(&read_cb_).Run(kAborted, NULL);
« no previous file with comments | « media/filters/ffmpeg_audio_decoder.h ('k') | media/filters/opus_audio_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698