Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(750)

Side by Side Diff: media/filters/decrypting_video_decoder.cc

Issue 1666653002: media: Remove SetCdmReadyCB and CdmReadyCB (part 1). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
32 key_added_while_decode_pending_(false), 32 key_added_while_decode_pending_(false),
33 trace_id_(0), 33 trace_id_(0),
34 weak_factory_(this) {} 34 weak_factory_(this) {}
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 SetCdmReadyCB& set_cdm_ready_cb, 42 CdmContext* cdm_context,
43 const InitCB& init_cb, 43 const InitCB& init_cb,
44 const OutputCB& output_cb) { 44 const OutputCB& output_cb) {
45 DVLOG(2) << __FUNCTION__ << ": " << config.AsHumanReadableString(); 45 DVLOG(2) << __FUNCTION__ << ": " << config.AsHumanReadableString();
46 46
47 DCHECK(task_runner_->BelongsToCurrentThread()); 47 DCHECK(task_runner_->BelongsToCurrentThread());
48 DCHECK(state_ == kUninitialized || 48 DCHECK(state_ == kUninitialized ||
49 state_ == kIdle || 49 state_ == kIdle ||
50 state_ == kDecodeFinished) << state_; 50 state_ == kDecodeFinished) << state_;
51 DCHECK(decode_cb_.is_null()); 51 DCHECK(decode_cb_.is_null());
52 DCHECK(reset_cb_.is_null()); 52 DCHECK(reset_cb_.is_null());
53 DCHECK(config.IsValidConfig()); 53 DCHECK(config.IsValidConfig());
54 DCHECK(config.is_encrypted()); 54 DCHECK(config.is_encrypted());
55 55
56 init_cb_ = BindToCurrentLoop(init_cb); 56 init_cb_ = BindToCurrentLoop(init_cb);
57 output_cb_ = BindToCurrentLoop(output_cb); 57 output_cb_ = BindToCurrentLoop(output_cb);
58 weak_this_ = weak_factory_.GetWeakPtr(); 58 weak_this_ = weak_factory_.GetWeakPtr();
59 config_ = config; 59 config_ = config;
60 60
61 if (state_ == kUninitialized) { 61 if (state_ == kUninitialized) {
62 DCHECK(!set_cdm_ready_cb.is_null()); 62 DCHECK(cdm_context);
63 state_ = kDecryptorRequested; 63 if (!cdm_context->GetDecryptor()) {
64 set_cdm_ready_cb_ = set_cdm_ready_cb; 64 MEDIA_LOG(DEBUG, media_log_) << GetDisplayName() << ": no decryptor";
65 set_cdm_ready_cb_.Run(BindToCurrentLoop( 65 base::ResetAndReturn(&init_cb_).Run(false);
66 base::Bind(&DecryptingVideoDecoder::SetCdm, weak_this_))); 66 return;
67 return; 67 }
68
69 decryptor_ = cdm_context->GetDecryptor();
70 } else {
71 // Reinitialization.
72 decryptor_->DeinitializeDecoder(Decryptor::kVideo);
68 } 73 }
69 74
70 // Reinitialization.
71 decryptor_->DeinitializeDecoder(Decryptor::kVideo);
72 state_ = kPendingDecoderInit; 75 state_ = kPendingDecoderInit;
73 decryptor_->InitializeVideoDecoder(config, BindToCurrentLoop(base::Bind( 76 decryptor_->InitializeVideoDecoder(
74 &DecryptingVideoDecoder::FinishInitialization, weak_this_))); 77 config_, BindToCurrentLoop(base::Bind(
78 &DecryptingVideoDecoder::FinishInitialization, weak_this_)));
75 } 79 }
76 80
77 void DecryptingVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, 81 void DecryptingVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer,
78 const DecodeCB& decode_cb) { 82 const DecodeCB& decode_cb) {
79 DVLOG(3) << "Decode()"; 83 DVLOG(3) << "Decode()";
80 DCHECK(task_runner_->BelongsToCurrentThread()); 84 DCHECK(task_runner_->BelongsToCurrentThread());
81 DCHECK(state_ == kIdle || 85 DCHECK(state_ == kIdle ||
82 state_ == kDecodeFinished || 86 state_ == kDecodeFinished ||
83 state_ == kError) << state_; 87 state_ == kError) << state_;
84 DCHECK(!decode_cb.is_null()); 88 DCHECK(!decode_cb.is_null());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 DecryptingVideoDecoder::~DecryptingVideoDecoder() { 143 DecryptingVideoDecoder::~DecryptingVideoDecoder() {
140 DCHECK(task_runner_->BelongsToCurrentThread()); 144 DCHECK(task_runner_->BelongsToCurrentThread());
141 145
142 if (state_ == kUninitialized) 146 if (state_ == kUninitialized)
143 return; 147 return;
144 148
145 if (decryptor_) { 149 if (decryptor_) {
146 decryptor_->DeinitializeDecoder(Decryptor::kVideo); 150 decryptor_->DeinitializeDecoder(Decryptor::kVideo);
147 decryptor_ = NULL; 151 decryptor_ = NULL;
148 } 152 }
149 if (!set_cdm_ready_cb_.is_null())
150 base::ResetAndReturn(&set_cdm_ready_cb_).Run(CdmReadyCB());
151 pending_buffer_to_decode_ = NULL; 153 pending_buffer_to_decode_ = NULL;
152 if (!init_cb_.is_null()) 154 if (!init_cb_.is_null())
153 base::ResetAndReturn(&init_cb_).Run(false); 155 base::ResetAndReturn(&init_cb_).Run(false);
154 if (!decode_cb_.is_null()) 156 if (!decode_cb_.is_null())
155 base::ResetAndReturn(&decode_cb_).Run(kAborted); 157 base::ResetAndReturn(&decode_cb_).Run(kAborted);
156 if (!reset_cb_.is_null()) 158 if (!reset_cb_.is_null())
157 base::ResetAndReturn(&reset_cb_).Run(); 159 base::ResetAndReturn(&reset_cb_).Run();
158 } 160 }
159 161
160 void DecryptingVideoDecoder::SetCdm(CdmContext* cdm_context,
161 const CdmAttachedCB& cdm_attached_cb) {
162 DVLOG(2) << __FUNCTION__;
163 DCHECK(task_runner_->BelongsToCurrentThread());
164 DCHECK_EQ(state_, kDecryptorRequested) << state_;
165 DCHECK(!init_cb_.is_null());
166 DCHECK(!set_cdm_ready_cb_.is_null());
167 set_cdm_ready_cb_.Reset();
168
169 if (!cdm_context || !cdm_context->GetDecryptor()) {
170 MEDIA_LOG(DEBUG, media_log_) << GetDisplayName() << ": no decryptor set";
171 base::ResetAndReturn(&init_cb_).Run(false);
172 state_ = kError;
173 cdm_attached_cb.Run(false);
174 return;
175 }
176
177 decryptor_ = cdm_context->GetDecryptor();
178
179 state_ = kPendingDecoderInit;
180 decryptor_->InitializeVideoDecoder(
181 config_,
182 BindToCurrentLoop(base::Bind(
183 &DecryptingVideoDecoder::FinishInitialization, weak_this_)));
184 cdm_attached_cb.Run(true);
185 }
186
187 void DecryptingVideoDecoder::FinishInitialization(bool success) { 162 void DecryptingVideoDecoder::FinishInitialization(bool success) {
188 DVLOG(2) << "FinishInitialization()"; 163 DVLOG(2) << "FinishInitialization()";
189 DCHECK(task_runner_->BelongsToCurrentThread()); 164 DCHECK(task_runner_->BelongsToCurrentThread());
190 DCHECK_EQ(state_, kPendingDecoderInit) << state_; 165 DCHECK_EQ(state_, kPendingDecoderInit) << state_;
191 DCHECK(!init_cb_.is_null()); 166 DCHECK(!init_cb_.is_null());
192 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. 167 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished.
193 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished. 168 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished.
194 169
195 if (!success) { 170 if (!success) {
196 MEDIA_LOG(DEBUG, media_log_) << GetDisplayName() 171 MEDIA_LOG(DEBUG, media_log_) << GetDisplayName()
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 } 300 }
326 301
327 void DecryptingVideoDecoder::DoReset() { 302 void DecryptingVideoDecoder::DoReset() {
328 DCHECK(init_cb_.is_null()); 303 DCHECK(init_cb_.is_null());
329 DCHECK(decode_cb_.is_null()); 304 DCHECK(decode_cb_.is_null());
330 state_ = kIdle; 305 state_ = kIdle;
331 base::ResetAndReturn(&reset_cb_).Run(); 306 base::ResetAndReturn(&reset_cb_).Run();
332 } 307 }
333 308
334 } // namespace media 309 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698