Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/filters/decrypting_demuxer_stream.h" | 5 #include "media/filters/decrypting_demuxer_stream.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 read_cb_ = BindToCurrentLoop(read_cb); | 68 read_cb_ = BindToCurrentLoop(read_cb); |
| 69 state_ = kPendingDemuxerRead; | 69 state_ = kPendingDemuxerRead; |
| 70 demuxer_stream_->Read( | 70 demuxer_stream_->Read( |
| 71 base::Bind(&DecryptingDemuxerStream::DecryptBuffer, weak_this_)); | 71 base::Bind(&DecryptingDemuxerStream::DecryptBuffer, weak_this_)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void DecryptingDemuxerStream::Reset(const base::Closure& closure) { | 74 void DecryptingDemuxerStream::Reset(const base::Closure& closure) { |
| 75 DVLOG(2) << __FUNCTION__ << " - state: " << state_; | 75 DVLOG(2) << __FUNCTION__ << " - state: " << state_; |
| 76 DCHECK(task_runner_->BelongsToCurrentThread()); | 76 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 77 DCHECK(state_ != kUninitialized) << state_; | 77 DCHECK(state_ != kUninitialized) << state_; |
| 78 DCHECK(state_ != kStopped) << state_; | |
| 78 DCHECK(reset_cb_.is_null()); | 79 DCHECK(reset_cb_.is_null()); |
| 79 | 80 |
| 80 reset_cb_ = BindToCurrentLoop(closure); | 81 reset_cb_ = BindToCurrentLoop(closure); |
| 81 | 82 |
| 83 // TODO(xhwang): This should not happen. Remove it, DCHECK against the | |
| 84 // condition and clean up related tests. | |
| 82 if (state_ == kDecryptorRequested) { | 85 if (state_ == kDecryptorRequested) { |
| 83 DCHECK(!init_cb_.is_null()); | 86 DCHECK(!init_cb_.is_null()); |
| 84 set_decryptor_ready_cb_.Run(DecryptorReadyCB()); | 87 set_decryptor_ready_cb_.Run(DecryptorReadyCB()); |
| 85 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); | 88 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); |
| 86 DoReset(); | 89 DoReset(); |
| 87 return; | 90 return; |
| 88 } | 91 } |
| 89 | 92 |
| 90 decryptor_->CancelDecrypt(GetDecryptorStreamType()); | 93 decryptor_->CancelDecrypt(GetDecryptorStreamType()); |
| 91 | 94 |
| 92 // Reset() cannot complete if the read callback is still pending. | 95 // Reset() cannot complete if the read callback is still pending. |
| 93 // Defer the resetting process in this case. The |reset_cb_| will be fired | 96 // Defer the resetting process in this case. The |reset_cb_| will be fired |
| 94 // after the read callback is fired - see DoDecryptBuffer() and | 97 // after the read callback is fired - see DoDecryptBuffer() and |
| 95 // DoDeliverBuffer(). | 98 // DoDeliverBuffer(). |
| 96 if (state_ == kPendingDemuxerRead || state_ == kPendingDecrypt) { | 99 if (state_ == kPendingDemuxerRead || state_ == kPendingDecrypt) { |
| 97 DCHECK(!read_cb_.is_null()); | 100 DCHECK(!read_cb_.is_null()); |
| 98 return; | 101 return; |
| 99 } | 102 } |
| 100 | 103 |
| 101 if (state_ == kWaitingForKey) { | 104 if (state_ == kWaitingForKey) { |
| 102 DCHECK(!read_cb_.is_null()); | 105 DCHECK(!read_cb_.is_null()); |
| 103 pending_buffer_to_decrypt_ = NULL; | 106 pending_buffer_to_decrypt_ = NULL; |
| 104 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); | 107 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); |
| 105 } | 108 } |
| 106 | 109 |
| 107 DCHECK(read_cb_.is_null()); | 110 DCHECK(read_cb_.is_null()); |
| 108 DoReset(); | 111 DoReset(); |
| 109 } | 112 } |
| 110 | 113 |
| 114 void DecryptingDemuxerStream::Stop(const base::Closure& closure) { | |
| 115 DVLOG(2) << __FUNCTION__ << " - state: " << state_; | |
| 116 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 117 DCHECK(state_ != kUninitialized) << state_; | |
| 118 | |
| 119 // Invalidate all weak pointers so that pending callbacks won't fire. | |
|
ddorwin
2014/02/14 04:17:59
...so that callbacks won't be fired into this obje
xhwang
2014/02/14 18:47:26
Done.
| |
| 120 weak_factory_.InvalidateWeakPtrs(); | |
| 121 | |
| 122 // At this point the render thread is likely paused (in WebMediaPlayerImpl's | |
| 123 // Destroy()), so running |closure| can't wait for anything that requires the | |
| 124 // render thread to process messages to complete (such as PPAPI methods). | |
| 125 if (decryptor_) { | |
| 126 // Clear the callback. | |
| 127 decryptor_->RegisterNewKeyCB(GetDecryptorStreamType(), | |
|
ddorwin
2014/02/14 04:17:59
Per the discussion in PS1, maybe we should remove
xhwang
2014/02/14 18:47:26
Added TODO since we also need to clean up other De
| |
| 128 Decryptor::NewKeyCB()); | |
| 129 decryptor_->CancelDecrypt(GetDecryptorStreamType()); | |
| 130 decryptor_ = NULL; | |
| 131 } | |
| 132 if (!set_decryptor_ready_cb_.is_null()) | |
| 133 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB()); | |
| 134 if (!init_cb_.is_null()) | |
| 135 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); | |
| 136 if (!read_cb_.is_null()) | |
| 137 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); | |
| 138 if (!reset_cb_.is_null()) | |
| 139 base::ResetAndReturn(&reset_cb_).Run(); | |
| 140 pending_buffer_to_decrypt_ = NULL; | |
| 141 | |
| 142 state_ = kStopped; | |
| 143 BindToCurrentLoop(closure).Run(); | |
| 144 } | |
| 145 | |
| 111 AudioDecoderConfig DecryptingDemuxerStream::audio_decoder_config() { | 146 AudioDecoderConfig DecryptingDemuxerStream::audio_decoder_config() { |
| 112 DCHECK(state_ != kUninitialized && state_ != kDecryptorRequested) << state_; | 147 DCHECK(state_ != kUninitialized && state_ != kDecryptorRequested) << state_; |
| 113 CHECK_EQ(demuxer_stream_->type(), AUDIO); | 148 CHECK_EQ(demuxer_stream_->type(), AUDIO); |
| 114 return audio_config_; | 149 return audio_config_; |
| 115 } | 150 } |
| 116 | 151 |
| 117 VideoDecoderConfig DecryptingDemuxerStream::video_decoder_config() { | 152 VideoDecoderConfig DecryptingDemuxerStream::video_decoder_config() { |
| 118 DCHECK(state_ != kUninitialized && state_ != kDecryptorRequested) << state_; | 153 DCHECK(state_ != kUninitialized && state_ != kDecryptorRequested) << state_; |
| 119 CHECK_EQ(demuxer_stream_->type(), VIDEO); | 154 CHECK_EQ(demuxer_stream_->type(), VIDEO); |
| 120 return video_config_; | 155 return video_config_; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 break; | 389 break; |
| 355 } | 390 } |
| 356 | 391 |
| 357 default: | 392 default: |
| 358 NOTREACHED(); | 393 NOTREACHED(); |
| 359 return; | 394 return; |
| 360 } | 395 } |
| 361 } | 396 } |
| 362 | 397 |
| 363 } // namespace media | 398 } // namespace media |
| OLD | NEW |