| 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 27 matching lines...) Expand all Loading... |
| 38 key_added_while_decrypt_pending_(false), | 38 key_added_while_decrypt_pending_(false), |
| 39 weak_factory_(this) {} | 39 weak_factory_(this) {} |
| 40 | 40 |
| 41 std::string DecryptingDemuxerStream::GetDisplayName() const { | 41 std::string DecryptingDemuxerStream::GetDisplayName() const { |
| 42 return "DecryptingDemuxerStream"; | 42 return "DecryptingDemuxerStream"; |
| 43 } | 43 } |
| 44 | 44 |
| 45 void DecryptingDemuxerStream::Initialize(DemuxerStream* stream, | 45 void DecryptingDemuxerStream::Initialize(DemuxerStream* stream, |
| 46 CdmContext* cdm_context, | 46 CdmContext* cdm_context, |
| 47 const PipelineStatusCB& status_cb) { | 47 const PipelineStatusCB& status_cb) { |
| 48 DVLOG(2) << __FUNCTION__; | 48 DVLOG(2) << __func__; |
| 49 DCHECK(task_runner_->BelongsToCurrentThread()); | 49 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 50 DCHECK_EQ(state_, kUninitialized) << state_; | 50 DCHECK_EQ(state_, kUninitialized) << state_; |
| 51 DCHECK(stream); | 51 DCHECK(stream); |
| 52 DCHECK(cdm_context); | 52 DCHECK(cdm_context); |
| 53 DCHECK(!demuxer_stream_); | 53 DCHECK(!demuxer_stream_); |
| 54 | 54 |
| 55 weak_this_ = weak_factory_.GetWeakPtr(); | 55 weak_this_ = weak_factory_.GetWeakPtr(); |
| 56 demuxer_stream_ = stream; | 56 demuxer_stream_ = stream; |
| 57 init_cb_ = BindToCurrentLoop(status_cb); | 57 init_cb_ = BindToCurrentLoop(status_cb); |
| 58 | 58 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 70 decryptor_->RegisterNewKeyCB( | 70 decryptor_->RegisterNewKeyCB( |
| 71 GetDecryptorStreamType(), | 71 GetDecryptorStreamType(), |
| 72 BindToCurrentLoop( | 72 BindToCurrentLoop( |
| 73 base::Bind(&DecryptingDemuxerStream::OnKeyAdded, weak_this_))); | 73 base::Bind(&DecryptingDemuxerStream::OnKeyAdded, weak_this_))); |
| 74 | 74 |
| 75 state_ = kIdle; | 75 state_ = kIdle; |
| 76 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); | 76 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void DecryptingDemuxerStream::Read(const ReadCB& read_cb) { | 79 void DecryptingDemuxerStream::Read(const ReadCB& read_cb) { |
| 80 DVLOG(3) << __FUNCTION__; | 80 DVLOG(3) << __func__; |
| 81 DCHECK(task_runner_->BelongsToCurrentThread()); | 81 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 82 DCHECK_EQ(state_, kIdle) << state_; | 82 DCHECK_EQ(state_, kIdle) << state_; |
| 83 DCHECK(!read_cb.is_null()); | 83 DCHECK(!read_cb.is_null()); |
| 84 CHECK(read_cb_.is_null()) << "Overlapping reads are not supported."; | 84 CHECK(read_cb_.is_null()) << "Overlapping reads are not supported."; |
| 85 | 85 |
| 86 read_cb_ = BindToCurrentLoop(read_cb); | 86 read_cb_ = BindToCurrentLoop(read_cb); |
| 87 state_ = kPendingDemuxerRead; | 87 state_ = kPendingDemuxerRead; |
| 88 demuxer_stream_->Read( | 88 demuxer_stream_->Read( |
| 89 base::Bind(&DecryptingDemuxerStream::DecryptBuffer, weak_this_)); | 89 base::Bind(&DecryptingDemuxerStream::DecryptBuffer, weak_this_)); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void DecryptingDemuxerStream::Reset(const base::Closure& closure) { | 92 void DecryptingDemuxerStream::Reset(const base::Closure& closure) { |
| 93 DVLOG(2) << __FUNCTION__ << " - state: " << state_; | 93 DVLOG(2) << __func__ << " - state: " << state_; |
| 94 DCHECK(task_runner_->BelongsToCurrentThread()); | 94 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 95 DCHECK(state_ != kUninitialized) << state_; | 95 DCHECK(state_ != kUninitialized) << state_; |
| 96 DCHECK(reset_cb_.is_null()); | 96 DCHECK(reset_cb_.is_null()); |
| 97 | 97 |
| 98 reset_cb_ = BindToCurrentLoop(closure); | 98 reset_cb_ = BindToCurrentLoop(closure); |
| 99 | 99 |
| 100 decryptor_->CancelDecrypt(GetDecryptorStreamType()); | 100 decryptor_->CancelDecrypt(GetDecryptorStreamType()); |
| 101 | 101 |
| 102 // Reset() cannot complete if the read callback is still pending. | 102 // Reset() cannot complete if the read callback is still pending. |
| 103 // Defer the resetting process in this case. The |reset_cb_| will be fired | 103 // Defer the resetting process in this case. The |reset_cb_| will be fired |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 base::TimeDelta timestamp) { | 160 base::TimeDelta timestamp) { |
| 161 demuxer_stream_->set_enabled(enabled, timestamp); | 161 demuxer_stream_->set_enabled(enabled, timestamp); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void DecryptingDemuxerStream::SetStreamRestartedCB( | 164 void DecryptingDemuxerStream::SetStreamRestartedCB( |
| 165 const StreamRestartedCB& cb) { | 165 const StreamRestartedCB& cb) { |
| 166 demuxer_stream_->SetStreamRestartedCB(cb); | 166 demuxer_stream_->SetStreamRestartedCB(cb); |
| 167 } | 167 } |
| 168 | 168 |
| 169 DecryptingDemuxerStream::~DecryptingDemuxerStream() { | 169 DecryptingDemuxerStream::~DecryptingDemuxerStream() { |
| 170 DVLOG(2) << __FUNCTION__ << " : state_ = " << state_; | 170 DVLOG(2) << __func__ << " : state_ = " << state_; |
| 171 DCHECK(task_runner_->BelongsToCurrentThread()); | 171 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 172 | 172 |
| 173 if (state_ == kUninitialized) | 173 if (state_ == kUninitialized) |
| 174 return; | 174 return; |
| 175 | 175 |
| 176 if (decryptor_) { | 176 if (decryptor_) { |
| 177 decryptor_->CancelDecrypt(GetDecryptorStreamType()); | 177 decryptor_->CancelDecrypt(GetDecryptorStreamType()); |
| 178 decryptor_ = NULL; | 178 decryptor_ = NULL; |
| 179 } | 179 } |
| 180 if (!init_cb_.is_null()) | 180 if (!init_cb_.is_null()) |
| 181 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); | 181 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); |
| 182 if (!read_cb_.is_null()) | 182 if (!read_cb_.is_null()) |
| 183 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); | 183 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); |
| 184 if (!reset_cb_.is_null()) | 184 if (!reset_cb_.is_null()) |
| 185 base::ResetAndReturn(&reset_cb_).Run(); | 185 base::ResetAndReturn(&reset_cb_).Run(); |
| 186 pending_buffer_to_decrypt_ = NULL; | 186 pending_buffer_to_decrypt_ = NULL; |
| 187 } | 187 } |
| 188 | 188 |
| 189 void DecryptingDemuxerStream::DecryptBuffer( | 189 void DecryptingDemuxerStream::DecryptBuffer( |
| 190 DemuxerStream::Status status, | 190 DemuxerStream::Status status, |
| 191 const scoped_refptr<DecoderBuffer>& buffer) { | 191 const scoped_refptr<DecoderBuffer>& buffer) { |
| 192 DVLOG(3) << __FUNCTION__; | 192 DVLOG(3) << __func__; |
| 193 DCHECK(task_runner_->BelongsToCurrentThread()); | 193 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 194 DCHECK_EQ(state_, kPendingDemuxerRead) << state_; | 194 DCHECK_EQ(state_, kPendingDemuxerRead) << state_; |
| 195 DCHECK(!read_cb_.is_null()); | 195 DCHECK(!read_cb_.is_null()); |
| 196 DCHECK_EQ(buffer.get() != NULL, status == kOk) << status; | 196 DCHECK_EQ(buffer.get() != NULL, status == kOk) << status; |
| 197 | 197 |
| 198 // Even when |!reset_cb_.is_null()|, we need to pass |kConfigChanged| back to | 198 // Even when |!reset_cb_.is_null()|, we need to pass |kConfigChanged| back to |
| 199 // the caller so that the downstream decoder can be properly reinitialized. | 199 // the caller so that the downstream decoder can be properly reinitialized. |
| 200 if (status == kConfigChanged) { | 200 if (status == kConfigChanged) { |
| 201 DVLOG(2) << "DoDecryptBuffer() - kConfigChanged."; | 201 DVLOG(2) << "DoDecryptBuffer() - kConfigChanged."; |
| 202 DCHECK_EQ(demuxer_stream_->type() == AUDIO, audio_config_.IsValidConfig()); | 202 DCHECK_EQ(demuxer_stream_->type() == AUDIO, audio_config_.IsValidConfig()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 decryptor_->Decrypt( | 260 decryptor_->Decrypt( |
| 261 GetDecryptorStreamType(), | 261 GetDecryptorStreamType(), |
| 262 pending_buffer_to_decrypt_, | 262 pending_buffer_to_decrypt_, |
| 263 BindToCurrentLoop( | 263 BindToCurrentLoop( |
| 264 base::Bind(&DecryptingDemuxerStream::DeliverBuffer, weak_this_))); | 264 base::Bind(&DecryptingDemuxerStream::DeliverBuffer, weak_this_))); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void DecryptingDemuxerStream::DeliverBuffer( | 267 void DecryptingDemuxerStream::DeliverBuffer( |
| 268 Decryptor::Status status, | 268 Decryptor::Status status, |
| 269 const scoped_refptr<DecoderBuffer>& decrypted_buffer) { | 269 const scoped_refptr<DecoderBuffer>& decrypted_buffer) { |
| 270 DVLOG(3) << __FUNCTION__ << " - status: " << status; | 270 DVLOG(3) << __func__ << " - status: " << status; |
| 271 DCHECK(task_runner_->BelongsToCurrentThread()); | 271 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 272 DCHECK_EQ(state_, kPendingDecrypt) << state_; | 272 DCHECK_EQ(state_, kPendingDecrypt) << state_; |
| 273 DCHECK_NE(status, Decryptor::kNeedMoreData); | 273 DCHECK_NE(status, Decryptor::kNeedMoreData); |
| 274 DCHECK(!read_cb_.is_null()); | 274 DCHECK(!read_cb_.is_null()); |
| 275 DCHECK(pending_buffer_to_decrypt_.get()); | 275 DCHECK(pending_buffer_to_decrypt_.get()); |
| 276 | 276 |
| 277 bool need_to_try_again_if_nokey = key_added_while_decrypt_pending_; | 277 bool need_to_try_again_if_nokey = key_added_while_decrypt_pending_; |
| 278 key_added_while_decrypt_pending_ = false; | 278 key_added_while_decrypt_pending_ = false; |
| 279 | 279 |
| 280 if (!reset_cb_.is_null()) { | 280 if (!reset_cb_.is_null()) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 break; | 383 break; |
| 384 } | 384 } |
| 385 | 385 |
| 386 default: | 386 default: |
| 387 NOTREACHED(); | 387 NOTREACHED(); |
| 388 return; | 388 return; |
| 389 } | 389 } |
| 390 } | 390 } |
| 391 | 391 |
| 392 } // namespace media | 392 } // namespace media |
| OLD | NEW |