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

Unified Diff: media/filters/decrypting_audio_decoder.cc

Issue 126793002: Add Stop() to AudioDecoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove extraneous #include 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/decrypting_audio_decoder.h ('k') | media/filters/decrypting_audio_decoder_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/decrypting_audio_decoder.cc
diff --git a/media/filters/decrypting_audio_decoder.cc b/media/filters/decrypting_audio_decoder.cc
index 63c3c43912c9d5828bbb86bebb3eb410cde97485..92c0ae681858189235f5c5310b8268409f500d97 100644
--- a/media/filters/decrypting_audio_decoder.cc
+++ b/media/filters/decrypting_audio_decoder.cc
@@ -120,7 +120,7 @@ void DecryptingAudioDecoder::Reset(const base::Closure& closure) {
DCHECK(init_cb_.is_null()); // No Reset() during pending initialization.
DCHECK(reset_cb_.is_null());
- reset_cb_ = closure;
+ reset_cb_ = BindToCurrentLoop(closure);
decryptor_->ResetDecoder(Decryptor::kAudio);
@@ -145,6 +145,28 @@ void DecryptingAudioDecoder::Reset(const base::Closure& closure) {
DoReset();
}
+void DecryptingAudioDecoder::Stop(const base::Closure& closure) {
+ DVLOG(2) << "Stop() - state: " << state_;
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ if (decryptor_) {
+ decryptor_->RegisterNewKeyCB(Decryptor::kAudio, Decryptor::NewKeyCB());
+ decryptor_->DeinitializeDecoder(Decryptor::kAudio);
+ decryptor_ = NULL;
+ }
+ if (!set_decryptor_ready_cb_.is_null())
+ base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB());
+ pending_buffer_to_decode_ = NULL;
+ if (!init_cb_.is_null())
+ base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
+ if (!read_cb_.is_null())
+ base::ResetAndReturn(&read_cb_).Run(kAborted, NULL);
+ if (!reset_cb_.is_null())
+ base::ResetAndReturn(&reset_cb_).Run();
+ state_ = kStopped;
+ task_runner_->PostTask(FROM_HERE, closure);
+}
+
int DecryptingAudioDecoder::bits_per_channel() {
DCHECK(task_runner_->BelongsToCurrentThread());
return bits_per_channel_;
@@ -161,11 +183,16 @@ int DecryptingAudioDecoder::samples_per_second() {
}
DecryptingAudioDecoder::~DecryptingAudioDecoder() {
+ DCHECK(state_ == kUninitialized || state_ == kStopped) << state_;
}
void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) {
DVLOG(2) << "SetDecryptor()";
DCHECK(task_runner_->BelongsToCurrentThread());
+
+ if (state_ == kStopped)
+ return;
+
DCHECK_EQ(state_, kDecryptorRequested) << state_;
DCHECK(!init_cb_.is_null());
DCHECK(!set_decryptor_ready_cb_.is_null());
@@ -175,7 +202,7 @@ void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) {
if (!decryptor) {
base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
// TODO(xhwang): Add kError state. See http://crbug.com/251503
- state_ = kDecodeFinished;
+ state_ = kStopped;
return;
}
@@ -205,6 +232,10 @@ void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) {
void DecryptingAudioDecoder::FinishInitialization(bool success) {
DVLOG(2) << "FinishInitialization()";
DCHECK(task_runner_->BelongsToCurrentThread());
+
+ if (state_ == kStopped)
+ return;
+
DCHECK_EQ(state_, kPendingDecoderInit) << state_;
DCHECK(!init_cb_.is_null());
DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished.
@@ -212,7 +243,7 @@ void DecryptingAudioDecoder::FinishInitialization(bool success) {
if (!success) {
base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
- state_ = kDecodeFinished;
+ state_ = kStopped;
return;
}
@@ -344,6 +375,10 @@ void DecryptingAudioDecoder::DeliverFrame(
const Decryptor::AudioBuffers& frames) {
DVLOG(3) << "DeliverFrame() - status: " << status;
DCHECK(task_runner_->BelongsToCurrentThread());
+
+ if (state_ == kStopped)
+ return;
+
DCHECK_EQ(state_, kPendingDecode) << state_;
DCHECK(!read_cb_.is_null());
DCHECK(pending_buffer_to_decode_.get());
« no previous file with comments | « media/filters/decrypting_audio_decoder.h ('k') | media/filters/decrypting_audio_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698