| 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_video_decoder.h" | 5 #include "media/filters/decrypting_video_decoder.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" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 13 #include "media/base/bind_to_current_loop.h" | 13 #include "media/base/bind_to_current_loop.h" |
| 14 #include "media/base/decoder_buffer.h" | 14 #include "media/base/decoder_buffer.h" |
| 15 #include "media/base/media_log.h" | 15 #include "media/base/media_log.h" |
| 16 #include "media/base/pipeline.h" | 16 #include "media/base/pipeline.h" |
| 17 #include "media/base/video_frame.h" | 17 #include "media/base/video_frame.h" |
| 18 | 18 |
| 19 namespace media { | 19 namespace media { |
| 20 | 20 |
| 21 const char DecryptingVideoDecoder::kDecoderName[] = "DecryptingVideoDecoder"; | 21 const char DecryptingVideoDecoder::kDecoderName[] = "DecryptingVideoDecoder"; |
| 22 | 22 |
| 23 DecryptingVideoDecoder::DecryptingVideoDecoder( | 23 DecryptingVideoDecoder::DecryptingVideoDecoder( |
| 24 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 24 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 25 const scoped_refptr<MediaLog>& media_log, | 25 const scoped_refptr<MediaLog>& media_log, |
| 26 const SetDecryptorReadyCB& set_decryptor_ready_cb, | 26 const SetCdmReadyCB& set_cdm_ready_cb, |
| 27 const base::Closure& waiting_for_decryption_key_cb) | 27 const base::Closure& waiting_for_decryption_key_cb) |
| 28 : task_runner_(task_runner), | 28 : task_runner_(task_runner), |
| 29 media_log_(media_log), | 29 media_log_(media_log), |
| 30 state_(kUninitialized), | 30 state_(kUninitialized), |
| 31 waiting_for_decryption_key_cb_(waiting_for_decryption_key_cb), | 31 waiting_for_decryption_key_cb_(waiting_for_decryption_key_cb), |
| 32 set_decryptor_ready_cb_(set_decryptor_ready_cb), | 32 set_cdm_ready_cb_(set_cdm_ready_cb), |
| 33 decryptor_(NULL), | 33 decryptor_(NULL), |
| 34 key_added_while_decode_pending_(false), | 34 key_added_while_decode_pending_(false), |
| 35 trace_id_(0), | 35 trace_id_(0), |
| 36 weak_factory_(this) { | 36 weak_factory_(this) {} |
| 37 } | |
| 38 | 37 |
| 39 std::string DecryptingVideoDecoder::GetDisplayName() const { | 38 std::string DecryptingVideoDecoder::GetDisplayName() const { |
| 40 return kDecoderName; | 39 return kDecoderName; |
| 41 } | 40 } |
| 42 | 41 |
| 43 void DecryptingVideoDecoder::Initialize(const VideoDecoderConfig& config, | 42 void DecryptingVideoDecoder::Initialize(const VideoDecoderConfig& config, |
| 44 bool /* low_delay */, | 43 bool /* low_delay */, |
| 45 const InitCB& init_cb, | 44 const InitCB& init_cb, |
| 46 const OutputCB& output_cb) { | 45 const OutputCB& output_cb) { |
| 47 DVLOG(2) << "Initialize()"; | 46 DVLOG(2) << "Initialize()"; |
| 48 DCHECK(task_runner_->BelongsToCurrentThread()); | 47 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 49 DCHECK(state_ == kUninitialized || | 48 DCHECK(state_ == kUninitialized || |
| 50 state_ == kIdle || | 49 state_ == kIdle || |
| 51 state_ == kDecodeFinished) << state_; | 50 state_ == kDecodeFinished) << state_; |
| 52 DCHECK(decode_cb_.is_null()); | 51 DCHECK(decode_cb_.is_null()); |
| 53 DCHECK(reset_cb_.is_null()); | 52 DCHECK(reset_cb_.is_null()); |
| 54 DCHECK(config.IsValidConfig()); | 53 DCHECK(config.IsValidConfig()); |
| 55 DCHECK(config.is_encrypted()); | 54 DCHECK(config.is_encrypted()); |
| 56 | 55 |
| 57 init_cb_ = BindToCurrentLoop(init_cb); | 56 init_cb_ = BindToCurrentLoop(init_cb); |
| 58 output_cb_ = BindToCurrentLoop(output_cb); | 57 output_cb_ = BindToCurrentLoop(output_cb); |
| 59 weak_this_ = weak_factory_.GetWeakPtr(); | 58 weak_this_ = weak_factory_.GetWeakPtr(); |
| 60 config_ = config; | 59 config_ = config; |
| 61 | 60 |
| 62 if (state_ == kUninitialized) { | 61 if (state_ == kUninitialized) { |
| 63 state_ = kDecryptorRequested; | 62 state_ = kDecryptorRequested; |
| 64 set_decryptor_ready_cb_.Run(BindToCurrentLoop(base::Bind( | 63 set_cdm_ready_cb_.Run(BindToCurrentLoop( |
| 65 &DecryptingVideoDecoder::SetDecryptor, weak_this_))); | 64 base::Bind(&DecryptingVideoDecoder::SetCdm, weak_this_))); |
| 66 return; | 65 return; |
| 67 } | 66 } |
| 68 | 67 |
| 69 // Reinitialization. | 68 // Reinitialization. |
| 70 decryptor_->DeinitializeDecoder(Decryptor::kVideo); | 69 decryptor_->DeinitializeDecoder(Decryptor::kVideo); |
| 71 state_ = kPendingDecoderInit; | 70 state_ = kPendingDecoderInit; |
| 72 decryptor_->InitializeVideoDecoder(config, BindToCurrentLoop(base::Bind( | 71 decryptor_->InitializeVideoDecoder(config, BindToCurrentLoop(base::Bind( |
| 73 &DecryptingVideoDecoder::FinishInitialization, weak_this_))); | 72 &DecryptingVideoDecoder::FinishInitialization, weak_this_))); |
| 74 } | 73 } |
| 75 | 74 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 DecryptingVideoDecoder::~DecryptingVideoDecoder() { | 137 DecryptingVideoDecoder::~DecryptingVideoDecoder() { |
| 139 DCHECK(task_runner_->BelongsToCurrentThread()); | 138 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 140 | 139 |
| 141 if (state_ == kUninitialized) | 140 if (state_ == kUninitialized) |
| 142 return; | 141 return; |
| 143 | 142 |
| 144 if (decryptor_) { | 143 if (decryptor_) { |
| 145 decryptor_->DeinitializeDecoder(Decryptor::kVideo); | 144 decryptor_->DeinitializeDecoder(Decryptor::kVideo); |
| 146 decryptor_ = NULL; | 145 decryptor_ = NULL; |
| 147 } | 146 } |
| 148 if (!set_decryptor_ready_cb_.is_null()) | 147 if (!set_cdm_ready_cb_.is_null()) |
| 149 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB()); | 148 base::ResetAndReturn(&set_cdm_ready_cb_).Run(CdmReadyCB()); |
| 150 pending_buffer_to_decode_ = NULL; | 149 pending_buffer_to_decode_ = NULL; |
| 151 if (!init_cb_.is_null()) | 150 if (!init_cb_.is_null()) |
| 152 base::ResetAndReturn(&init_cb_).Run(false); | 151 base::ResetAndReturn(&init_cb_).Run(false); |
| 153 if (!decode_cb_.is_null()) | 152 if (!decode_cb_.is_null()) |
| 154 base::ResetAndReturn(&decode_cb_).Run(kAborted); | 153 base::ResetAndReturn(&decode_cb_).Run(kAborted); |
| 155 if (!reset_cb_.is_null()) | 154 if (!reset_cb_.is_null()) |
| 156 base::ResetAndReturn(&reset_cb_).Run(); | 155 base::ResetAndReturn(&reset_cb_).Run(); |
| 157 } | 156 } |
| 158 | 157 |
| 159 void DecryptingVideoDecoder::SetDecryptor( | 158 void DecryptingVideoDecoder::SetCdm(CdmContext* cdm_context, |
| 160 Decryptor* decryptor, | 159 const CdmAttachedCB& cdm_attached_cb) { |
| 161 const DecryptorAttachedCB& decryptor_attached_cb) { | 160 DVLOG(2) << __FUNCTION__; |
| 162 DVLOG(2) << "SetDecryptor()"; | |
| 163 DCHECK(task_runner_->BelongsToCurrentThread()); | 161 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 164 DCHECK_EQ(state_, kDecryptorRequested) << state_; | 162 DCHECK_EQ(state_, kDecryptorRequested) << state_; |
| 165 DCHECK(!init_cb_.is_null()); | 163 DCHECK(!init_cb_.is_null()); |
| 166 DCHECK(!set_decryptor_ready_cb_.is_null()); | 164 DCHECK(!set_cdm_ready_cb_.is_null()); |
| 167 set_decryptor_ready_cb_.Reset(); | 165 set_cdm_ready_cb_.Reset(); |
| 168 | 166 |
| 169 if (!decryptor) { | 167 if (!cdm_context || !cdm_context->GetDecryptor()) { |
| 170 MEDIA_LOG(DEBUG, media_log_) << GetDisplayName() << ": no decryptor set"; | 168 MEDIA_LOG(DEBUG, media_log_) << GetDisplayName() << ": no decryptor set"; |
| 171 base::ResetAndReturn(&init_cb_).Run(false); | 169 base::ResetAndReturn(&init_cb_).Run(false); |
| 172 state_ = kError; | 170 state_ = kError; |
| 173 decryptor_attached_cb.Run(false); | 171 cdm_attached_cb.Run(false); |
| 174 return; | 172 return; |
| 175 } | 173 } |
| 176 | 174 |
| 177 decryptor_ = decryptor; | 175 decryptor_ = cdm_context->GetDecryptor(); |
| 178 | 176 |
| 179 state_ = kPendingDecoderInit; | 177 state_ = kPendingDecoderInit; |
| 180 decryptor_->InitializeVideoDecoder( | 178 decryptor_->InitializeVideoDecoder( |
| 181 config_, | 179 config_, |
| 182 BindToCurrentLoop(base::Bind( | 180 BindToCurrentLoop(base::Bind( |
| 183 &DecryptingVideoDecoder::FinishInitialization, weak_this_))); | 181 &DecryptingVideoDecoder::FinishInitialization, weak_this_))); |
| 184 decryptor_attached_cb.Run(true); | 182 cdm_attached_cb.Run(true); |
| 185 } | 183 } |
| 186 | 184 |
| 187 void DecryptingVideoDecoder::FinishInitialization(bool success) { | 185 void DecryptingVideoDecoder::FinishInitialization(bool success) { |
| 188 DVLOG(2) << "FinishInitialization()"; | 186 DVLOG(2) << "FinishInitialization()"; |
| 189 DCHECK(task_runner_->BelongsToCurrentThread()); | 187 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 190 DCHECK_EQ(state_, kPendingDecoderInit) << state_; | 188 DCHECK_EQ(state_, kPendingDecoderInit) << state_; |
| 191 DCHECK(!init_cb_.is_null()); | 189 DCHECK(!init_cb_.is_null()); |
| 192 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. | 190 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. |
| 193 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished. | 191 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished. |
| 194 | 192 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } | 323 } |
| 326 | 324 |
| 327 void DecryptingVideoDecoder::DoReset() { | 325 void DecryptingVideoDecoder::DoReset() { |
| 328 DCHECK(init_cb_.is_null()); | 326 DCHECK(init_cb_.is_null()); |
| 329 DCHECK(decode_cb_.is_null()); | 327 DCHECK(decode_cb_.is_null()); |
| 330 state_ = kIdle; | 328 state_ = kIdle; |
| 331 base::ResetAndReturn(&reset_cb_).Run(); | 329 base::ResetAndReturn(&reset_cb_).Run(); |
| 332 } | 330 } |
| 333 | 331 |
| 334 } // namespace media | 332 } // namespace media |
| OLD | NEW |