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

Unified Diff: media/filters/opus_audio_decoder.cc

Issue 126793002: Add Stop() to AudioDecoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
Index: media/filters/opus_audio_decoder.cc
diff --git a/media/filters/opus_audio_decoder.cc b/media/filters/opus_audio_decoder.cc
index e427c0abacae566b9941bdc6632d0892d573f70f..198160d288cb706502f1e4471f0966f3952bef34 100644
--- a/media/filters/opus_audio_decoder.cc
+++ b/media/filters/opus_audio_decoder.cc
@@ -298,6 +298,8 @@ void OpusAudioDecoder::Read(const ReadCB& read_cb) {
DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK(!read_cb.is_null());
CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported.";
+ DCHECK(stop_cb_.is_null());
+ DCHECK(reset_cb_.is_null());
xhwang 2014/01/10 22:14:15 nit: switch the order to these two
read_cb_ = BindToCurrentLoop(read_cb);
ReadFromDemuxerStream();
@@ -320,17 +322,53 @@ int OpusAudioDecoder::samples_per_second() {
void OpusAudioDecoder::Reset(const base::Closure& closure) {
DCHECK(task_runner_->BelongsToCurrentThread());
- base::Closure reset_cb = BindToCurrentLoop(closure);
+ DCHECK(reset_cb_.is_null());
+ reset_cb_ = BindToCurrentLoop(closure);
+
+ if (read_cb_.is_null())
+ DoReset();
+ // Otherwise we have to wait for the pending demuxer read.
+}
+
+void OpusAudioDecoder::Stop(const base::Closure& closure) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK(stop_cb_.is_null());
+ stop_cb_ = BindToCurrentLoop(closure);
+
+ if (read_cb_.is_null()) {
+ if (!reset_cb_.is_null())
+ DoReset();
+ else
+ DoStop();
+ }
+ // Otherwise we have to wait for the pending demuxer read.
+}
+
+OpusAudioDecoder::~OpusAudioDecoder() {}
+
+void OpusAudioDecoder::DoReset() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK(!reset_cb_.is_null());
+ DCHECK(read_cb_.is_null());
opus_multistream_decoder_ctl(opus_decoder_, OPUS_RESET_STATE);
ResetTimestampState();
- reset_cb.Run();
+ base::ResetAndReturn(&reset_cb_).Run();
+
+ if (!stop_cb_.is_null())
+ DoStop();
}
-OpusAudioDecoder::~OpusAudioDecoder() {
- // TODO(scherkus): should we require Stop() to be called? this might end up
- // getting called on a random thread due to refcounting.
+void OpusAudioDecoder::DoStop() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK(!stop_cb_.is_null());
+ DCHECK(read_cb_.is_null());
+ DCHECK(reset_cb_.is_null());
+
+ opus_multistream_decoder_ctl(opus_decoder_, OPUS_RESET_STATE);
+ ResetTimestampState();
CloseDecoder();
+ base::ResetAndReturn(&stop_cb_).Run();
}
void OpusAudioDecoder::ReadFromDemuxerStream() {
@@ -345,6 +383,20 @@ void OpusAudioDecoder::BufferReady(
DCHECK(!read_cb_.is_null());
DCHECK_EQ(status != DemuxerStream::kOk, !input.get()) << status;
+ // Drop the buffer, fire |read_cb_| and complete the pending Reset().
+ if (!reset_cb_.is_null()) {
+ base::ResetAndReturn(&read_cb_).Run(kAborted, NULL);
+ DoReset();
+ return;
+ }
+
+ // Drop the buffer, fire |read_cb_| and complete the pending 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);
« media/filters/ffmpeg_audio_decoder.cc ('K') | « media/filters/opus_audio_decoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698