| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 trace_id_(0), | 32 trace_id_(0), |
| 33 weak_factory_(this) { | 33 weak_factory_(this) { |
| 34 } | 34 } |
| 35 | 35 |
| 36 std::string DecryptingVideoDecoder::GetDisplayName() const { | 36 std::string DecryptingVideoDecoder::GetDisplayName() const { |
| 37 return kDecoderName; | 37 return kDecoderName; |
| 38 } | 38 } |
| 39 | 39 |
| 40 void DecryptingVideoDecoder::Initialize(const VideoDecoderConfig& config, | 40 void DecryptingVideoDecoder::Initialize(const VideoDecoderConfig& config, |
| 41 bool /* low_delay */, | 41 bool /* low_delay */, |
| 42 const InitCB& init_cb, | 42 const PipelineStatusCB& status_cb, |
| 43 const OutputCB& output_cb) { | 43 const OutputCB& output_cb) { |
| 44 DVLOG(2) << "Initialize()"; | 44 DVLOG(2) << "Initialize()"; |
| 45 DCHECK(task_runner_->BelongsToCurrentThread()); | 45 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 46 DCHECK(state_ == kUninitialized || | 46 DCHECK(state_ == kUninitialized || |
| 47 state_ == kIdle || | 47 state_ == kIdle || |
| 48 state_ == kDecodeFinished) << state_; | 48 state_ == kDecodeFinished) << state_; |
| 49 DCHECK(decode_cb_.is_null()); | 49 DCHECK(decode_cb_.is_null()); |
| 50 DCHECK(reset_cb_.is_null()); | 50 DCHECK(reset_cb_.is_null()); |
| 51 DCHECK(config.IsValidConfig()); | 51 DCHECK(config.IsValidConfig()); |
| 52 DCHECK(config.is_encrypted()); | 52 DCHECK(config.is_encrypted()); |
| 53 | 53 |
| 54 init_cb_ = BindToCurrentLoop(init_cb); | 54 init_cb_ = BindToCurrentLoop(status_cb); |
| 55 output_cb_ = BindToCurrentLoop(output_cb); | 55 output_cb_ = BindToCurrentLoop(output_cb); |
| 56 weak_this_ = weak_factory_.GetWeakPtr(); | 56 weak_this_ = weak_factory_.GetWeakPtr(); |
| 57 config_ = config; | 57 config_ = config; |
| 58 | 58 |
| 59 if (state_ == kUninitialized) { | 59 if (state_ == kUninitialized) { |
| 60 state_ = kDecryptorRequested; | 60 state_ = kDecryptorRequested; |
| 61 set_decryptor_ready_cb_.Run(BindToCurrentLoop(base::Bind( | 61 set_decryptor_ready_cb_.Run(BindToCurrentLoop(base::Bind( |
| 62 &DecryptingVideoDecoder::SetDecryptor, weak_this_))); | 62 &DecryptingVideoDecoder::SetDecryptor, weak_this_))); |
| 63 return; | 63 return; |
| 64 } | 64 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 return; | 139 return; |
| 140 | 140 |
| 141 if (decryptor_) { | 141 if (decryptor_) { |
| 142 decryptor_->DeinitializeDecoder(Decryptor::kVideo); | 142 decryptor_->DeinitializeDecoder(Decryptor::kVideo); |
| 143 decryptor_ = NULL; | 143 decryptor_ = NULL; |
| 144 } | 144 } |
| 145 if (!set_decryptor_ready_cb_.is_null()) | 145 if (!set_decryptor_ready_cb_.is_null()) |
| 146 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB()); | 146 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB()); |
| 147 pending_buffer_to_decode_ = NULL; | 147 pending_buffer_to_decode_ = NULL; |
| 148 if (!init_cb_.is_null()) | 148 if (!init_cb_.is_null()) |
| 149 base::ResetAndReturn(&init_cb_).Run(false); | 149 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); |
| 150 if (!decode_cb_.is_null()) | 150 if (!decode_cb_.is_null()) |
| 151 base::ResetAndReturn(&decode_cb_).Run(kAborted); | 151 base::ResetAndReturn(&decode_cb_).Run(kAborted); |
| 152 if (!reset_cb_.is_null()) | 152 if (!reset_cb_.is_null()) |
| 153 base::ResetAndReturn(&reset_cb_).Run(); | 153 base::ResetAndReturn(&reset_cb_).Run(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void DecryptingVideoDecoder::SetDecryptor( | 156 void DecryptingVideoDecoder::SetDecryptor( |
| 157 Decryptor* decryptor, | 157 Decryptor* decryptor, |
| 158 const DecryptorAttachedCB& decryptor_attached_cb) { | 158 const DecryptorAttachedCB& decryptor_attached_cb) { |
| 159 DVLOG(2) << "SetDecryptor()"; | 159 DVLOG(2) << "SetDecryptor()"; |
| 160 DCHECK(task_runner_->BelongsToCurrentThread()); | 160 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 161 DCHECK_EQ(state_, kDecryptorRequested) << state_; | 161 DCHECK_EQ(state_, kDecryptorRequested) << state_; |
| 162 DCHECK(!init_cb_.is_null()); | 162 DCHECK(!init_cb_.is_null()); |
| 163 DCHECK(!set_decryptor_ready_cb_.is_null()); | 163 DCHECK(!set_decryptor_ready_cb_.is_null()); |
| 164 set_decryptor_ready_cb_.Reset(); | 164 set_decryptor_ready_cb_.Reset(); |
| 165 | 165 |
| 166 if (!decryptor) { | 166 if (!decryptor) { |
| 167 base::ResetAndReturn(&init_cb_).Run(false); | 167 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); |
| 168 state_ = kError; | 168 state_ = kError; |
| 169 decryptor_attached_cb.Run(false); | 169 decryptor_attached_cb.Run(false); |
| 170 return; | 170 return; |
| 171 } | 171 } |
| 172 | 172 |
| 173 decryptor_ = decryptor; | 173 decryptor_ = decryptor; |
| 174 | 174 |
| 175 state_ = kPendingDecoderInit; | 175 state_ = kPendingDecoderInit; |
| 176 decryptor_->InitializeVideoDecoder( | 176 decryptor_->InitializeVideoDecoder( |
| 177 config_, | 177 config_, |
| 178 BindToCurrentLoop(base::Bind( | 178 BindToCurrentLoop(base::Bind( |
| 179 &DecryptingVideoDecoder::FinishInitialization, weak_this_))); | 179 &DecryptingVideoDecoder::FinishInitialization, weak_this_))); |
| 180 decryptor_attached_cb.Run(true); | 180 decryptor_attached_cb.Run(true); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void DecryptingVideoDecoder::FinishInitialization(bool success) { | 183 void DecryptingVideoDecoder::FinishInitialization(bool success) { |
| 184 DVLOG(2) << "FinishInitialization()"; | 184 DVLOG(2) << "FinishInitialization()"; |
| 185 DCHECK(task_runner_->BelongsToCurrentThread()); | 185 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 186 DCHECK_EQ(state_, kPendingDecoderInit) << state_; | 186 DCHECK_EQ(state_, kPendingDecoderInit) << state_; |
| 187 DCHECK(!init_cb_.is_null()); | 187 DCHECK(!init_cb_.is_null()); |
| 188 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. | 188 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. |
| 189 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished. | 189 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished. |
| 190 | 190 |
| 191 if (!success) { | 191 if (!success) { |
| 192 base::ResetAndReturn(&init_cb_).Run(false); | 192 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); |
| 193 decryptor_ = NULL; | 193 decryptor_ = NULL; |
| 194 state_ = kError; | 194 state_ = kError; |
| 195 return; | 195 return; |
| 196 } | 196 } |
| 197 | 197 |
| 198 decryptor_->RegisterNewKeyCB( | 198 decryptor_->RegisterNewKeyCB( |
| 199 Decryptor::kVideo, | 199 Decryptor::kVideo, |
| 200 BindToCurrentLoop( | 200 BindToCurrentLoop( |
| 201 base::Bind(&DecryptingVideoDecoder::OnKeyAdded, weak_this_))); | 201 base::Bind(&DecryptingVideoDecoder::OnKeyAdded, weak_this_))); |
| 202 | 202 |
| 203 // Success! | 203 // Success! |
| 204 state_ = kIdle; | 204 state_ = kIdle; |
| 205 base::ResetAndReturn(&init_cb_).Run(true); | 205 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); |
| 206 } | 206 } |
| 207 | 207 |
| 208 | 208 |
| 209 void DecryptingVideoDecoder::DecodePendingBuffer() { | 209 void DecryptingVideoDecoder::DecodePendingBuffer() { |
| 210 DCHECK(task_runner_->BelongsToCurrentThread()); | 210 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 211 DCHECK_EQ(state_, kPendingDecode) << state_; | 211 DCHECK_EQ(state_, kPendingDecode) << state_; |
| 212 TRACE_EVENT_ASYNC_BEGIN0( | 212 TRACE_EVENT_ASYNC_BEGIN0( |
| 213 "media", "DecryptingVideoDecoder::DecodePendingBuffer", ++trace_id_); | 213 "media", "DecryptingVideoDecoder::DecodePendingBuffer", ++trace_id_); |
| 214 | 214 |
| 215 int buffer_size = 0; | 215 int buffer_size = 0; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 } | 316 } |
| 317 | 317 |
| 318 void DecryptingVideoDecoder::DoReset() { | 318 void DecryptingVideoDecoder::DoReset() { |
| 319 DCHECK(init_cb_.is_null()); | 319 DCHECK(init_cb_.is_null()); |
| 320 DCHECK(decode_cb_.is_null()); | 320 DCHECK(decode_cb_.is_null()); |
| 321 state_ = kIdle; | 321 state_ = kIdle; |
| 322 base::ResetAndReturn(&reset_cb_).Run(); | 322 base::ResetAndReturn(&reset_cb_).Run(); |
| 323 } | 323 } |
| 324 | 324 |
| 325 } // namespace media | 325 } // namespace media |
| OLD | NEW |