Commit f18100b1 authored by xhwang@chromium.org's avatar xhwang@chromium.org

Stop DecryptingDemuxerStream in AudioRendererImpl::Stop().

BUG=343669, 343617
TEST=none
R=ddorwin@chromium.org

Review URL: https://codereview.chromium.org/163433004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251469 0039d316-1c4b-4281-b951-d872f2087c98
parent 92dfa6fc
...@@ -216,6 +216,19 @@ void AudioRendererImpl::Stop(const base::Closure& callback) { ...@@ -216,6 +216,19 @@ void AudioRendererImpl::Stop(const base::Closure& callback) {
sink_ = NULL; sink_ = NULL;
} }
if (decrypting_demuxer_stream_) {
decrypting_demuxer_stream_->Stop(
base::Bind(&AudioRendererImpl::StopDecoder, weak_this_));
return;
}
StopDecoder();
}
void AudioRendererImpl::StopDecoder() {
DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK(!stop_cb_.is_null());
if (decoder_) { if (decoder_) {
decoder_->Stop(base::ResetAndReturn(&stop_cb_)); decoder_->Stop(base::ResetAndReturn(&stop_cb_));
return; return;
......
...@@ -184,6 +184,9 @@ class MEDIA_EXPORT AudioRendererImpl ...@@ -184,6 +184,9 @@ class MEDIA_EXPORT AudioRendererImpl
// Called when the |decoder_|.Reset() has completed. // Called when the |decoder_|.Reset() has completed.
void ResetDecoderDone(); void ResetDecoderDone();
// Stops the |decoder_| if present. Ensures |stop_cb_| is called.
void StopDecoder();
scoped_refptr<base::SingleThreadTaskRunner> task_runner_; scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
base::WeakPtrFactory<AudioRendererImpl> weak_factory_; base::WeakPtrFactory<AudioRendererImpl> weak_factory_;
base::WeakPtr<AudioRendererImpl> weak_this_; base::WeakPtr<AudioRendererImpl> weak_this_;
......
...@@ -123,7 +123,7 @@ void DecoderSelector<StreamType>::Abort() { ...@@ -123,7 +123,7 @@ void DecoderSelector<StreamType>::Abort() {
if (decoder_) { if (decoder_) {
// |decrypted_stream_| is either NULL or already initialized. We don't // |decrypted_stream_| is either NULL or already initialized. We don't
// need to Reset() |decrypted_stream_| in either case. // need to Stop() |decrypted_stream_| in either case.
decoder_->Stop(base::Bind(&DecoderSelector<StreamType>::ReturnNullDecoder, decoder_->Stop(base::Bind(&DecoderSelector<StreamType>::ReturnNullDecoder,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
return; return;
......
...@@ -116,7 +116,8 @@ void DecryptingDemuxerStream::Stop(const base::Closure& closure) { ...@@ -116,7 +116,8 @@ void DecryptingDemuxerStream::Stop(const base::Closure& closure) {
DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK(state_ != kUninitialized) << state_; DCHECK(state_ != kUninitialized) << state_;
// Invalidate all weak pointers so that pending callbacks won't fire. // Invalidate all weak pointers so that pending callbacks won't be fired into
// this object.
weak_factory_.InvalidateWeakPtrs(); weak_factory_.InvalidateWeakPtrs();
// At this point the render thread is likely paused (in WebMediaPlayerImpl's // At this point the render thread is likely paused (in WebMediaPlayerImpl's
...@@ -124,6 +125,9 @@ void DecryptingDemuxerStream::Stop(const base::Closure& closure) { ...@@ -124,6 +125,9 @@ void DecryptingDemuxerStream::Stop(const base::Closure& closure) {
// render thread to process messages to complete (such as PPAPI methods). // render thread to process messages to complete (such as PPAPI methods).
if (decryptor_) { if (decryptor_) {
// Clear the callback. // Clear the callback.
// TODO(xhwang): Since we invalidate all weak pointers during Stop(),
// canceling NewKeyCB seems unnecessary. Clean this up in all Decrypting*
// classes.
decryptor_->RegisterNewKeyCB(GetDecryptorStreamType(), decryptor_->RegisterNewKeyCB(GetDecryptorStreamType(),
Decryptor::NewKeyCB()); Decryptor::NewKeyCB());
decryptor_->CancelDecrypt(GetDecryptorStreamType()); decryptor_->CancelDecrypt(GetDecryptorStreamType());
......
...@@ -50,6 +50,9 @@ ACTION_P(ReturnBuffer, buffer) { ...@@ -50,6 +50,9 @@ ACTION_P(ReturnBuffer, buffer) {
arg0.Run(buffer.get() ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer); arg0.Run(buffer.get() ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer);
} }
// Sets the |decryptor| if the DecryptorReadyCB (arg0) is not null. Sets
// |is_decryptor_set| to true if a non-NULL |decryptor| has been set through the
// callback.
ACTION_P2(SetDecryptorIfNotNull, decryptor, is_decryptor_set) { ACTION_P2(SetDecryptorIfNotNull, decryptor, is_decryptor_set) {
if (!arg0.is_null()) if (!arg0.is_null())
arg0.Run(decryptor); arg0.Run(decryptor);
...@@ -110,6 +113,7 @@ class DecryptingDemuxerStreamTest : public testing::Test { ...@@ -110,6 +113,7 @@ class DecryptingDemuxerStreamTest : public testing::Test {
void Initialize() { void Initialize() {
EXPECT_CALL(*this, RequestDecryptorNotification(_)) EXPECT_CALL(*this, RequestDecryptorNotification(_))
.WillOnce(SetDecryptorIfNotNull(decryptor_.get(), &is_decryptor_set_)); .WillOnce(SetDecryptorIfNotNull(decryptor_.get(), &is_decryptor_set_));
// TODO(xhwang): Use WillOnce after we remove the cancellation of NewKeyCB.
EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _))
.WillRepeatedly(SaveArg<1>(&key_added_cb_)); .WillRepeatedly(SaveArg<1>(&key_added_cb_));
...@@ -251,7 +255,7 @@ class DecryptingDemuxerStreamTest : public testing::Test { ...@@ -251,7 +255,7 @@ class DecryptingDemuxerStreamTest : public testing::Test {
base::MessageLoop message_loop_; base::MessageLoop message_loop_;
scoped_ptr<DecryptingDemuxerStream> demuxer_stream_; scoped_ptr<DecryptingDemuxerStream> demuxer_stream_;
scoped_ptr<StrictMock<MockDecryptor> > decryptor_; scoped_ptr<StrictMock<MockDecryptor> > decryptor_;
// Whether a valid Decryptor is set to the |demuxer_stream_|. // Whether a valid Decryptor has been set in the |demuxer_stream_|.
bool is_decryptor_set_; bool is_decryptor_set_;
scoped_ptr<StrictMock<MockDemuxerStream> > input_audio_stream_; scoped_ptr<StrictMock<MockDemuxerStream> > input_audio_stream_;
scoped_ptr<StrictMock<MockDemuxerStream> > input_video_stream_; scoped_ptr<StrictMock<MockDemuxerStream> > input_video_stream_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment