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

Side by Side Diff: media/filters/decrypting_audio_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_audio_decoder.h" 5 #include "media/filters/decrypting_audio_decoder.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <cstdlib> 9 #include <cstdlib>
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 waiting_for_decryption_key_cb_(waiting_for_decryption_key_cb), 43 waiting_for_decryption_key_cb_(waiting_for_decryption_key_cb),
44 decryptor_(NULL), 44 decryptor_(NULL),
45 key_added_while_decode_pending_(false), 45 key_added_while_decode_pending_(false),
46 weak_factory_(this) {} 46 weak_factory_(this) {}
47 47
48 std::string DecryptingAudioDecoder::GetDisplayName() const { 48 std::string DecryptingAudioDecoder::GetDisplayName() const {
49 return "DecryptingAudioDecoder"; 49 return "DecryptingAudioDecoder";
50 } 50 }
51 51
52 void DecryptingAudioDecoder::Initialize(const AudioDecoderConfig& config, 52 void DecryptingAudioDecoder::Initialize(const AudioDecoderConfig& config,
53 const SetCdmReadyCB& set_cdm_ready_cb, 53 CdmContext* cdm_context,
54 const InitCB& init_cb, 54 const InitCB& init_cb,
55 const OutputCB& output_cb) { 55 const OutputCB& output_cb) {
56 DVLOG(2) << "Initialize()"; 56 DVLOG(2) << "Initialize()";
57 DCHECK(task_runner_->BelongsToCurrentThread()); 57 DCHECK(task_runner_->BelongsToCurrentThread());
58 DCHECK(decode_cb_.is_null()); 58 DCHECK(decode_cb_.is_null());
59 DCHECK(reset_cb_.is_null()); 59 DCHECK(reset_cb_.is_null());
60 60
61 weak_this_ = weak_factory_.GetWeakPtr(); 61 weak_this_ = weak_factory_.GetWeakPtr();
62 init_cb_ = BindToCurrentLoop(init_cb); 62 init_cb_ = BindToCurrentLoop(init_cb);
63 output_cb_ = BindToCurrentLoop(output_cb); 63 output_cb_ = BindToCurrentLoop(output_cb);
64 64
65 // TODO(xhwang): We should be able to DCHECK config.IsValidConfig() and
66 // config.is_encrypted().
65 if (!config.IsValidConfig()) { 67 if (!config.IsValidConfig()) {
66 DLOG(ERROR) << "Invalid audio stream config."; 68 DLOG(ERROR) << "Invalid audio stream config.";
67 base::ResetAndReturn(&init_cb_).Run(false); 69 base::ResetAndReturn(&init_cb_).Run(false);
68 return; 70 return;
69 } 71 }
70 72
71 // DecryptingAudioDecoder only accepts potentially encrypted stream. 73 // DecryptingAudioDecoder only accepts potentially encrypted stream.
72 if (!config.is_encrypted()) { 74 if (!config.is_encrypted()) {
73 base::ResetAndReturn(&init_cb_).Run(false); 75 base::ResetAndReturn(&init_cb_).Run(false);
74 return; 76 return;
75 } 77 }
76 78
77 config_ = config; 79 config_ = config;
78 80
79 if (state_ == kUninitialized) { 81 if (state_ == kUninitialized) {
80 DCHECK(!set_cdm_ready_cb.is_null()); 82 DCHECK(cdm_context);
81 state_ = kDecryptorRequested; 83 if (!cdm_context->GetDecryptor()) {
82 set_cdm_ready_cb_ = set_cdm_ready_cb; 84 MEDIA_LOG(DEBUG, media_log_) << GetDisplayName() << ": no decryptor";
83 set_cdm_ready_cb_.Run(BindToCurrentLoop( 85 base::ResetAndReturn(&init_cb_).Run(false);
jrummell 2016/02/03 23:32:28 In SetCdm() state_ was set to kError. Was it inten
xhwang 2016/02/09 22:23:58 Yeah, this is a bit messy. I don't think it matter
84 base::Bind(&DecryptingAudioDecoder::SetCdm, weak_this_))); 86 return;
85 return; 87 }
88
89 decryptor_ = cdm_context->GetDecryptor();
90 } else {
91 // Reinitialization (i.e. upon a config change)
92 decryptor_->DeinitializeDecoder(Decryptor::kAudio);
86 } 93 }
87 94
88 // Reinitialization (i.e. upon a config change)
89 decryptor_->DeinitializeDecoder(Decryptor::kAudio);
90 InitializeDecoder(); 95 InitializeDecoder();
91 } 96 }
92 97
93 void DecryptingAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, 98 void DecryptingAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer,
94 const DecodeCB& decode_cb) { 99 const DecodeCB& decode_cb) {
95 DVLOG(3) << "Decode()"; 100 DVLOG(3) << "Decode()";
96 DCHECK(task_runner_->BelongsToCurrentThread()); 101 DCHECK(task_runner_->BelongsToCurrentThread());
97 DCHECK(state_ == kIdle || state_ == kDecodeFinished) << state_; 102 DCHECK(state_ == kIdle || state_ == kDecodeFinished) << state_;
98 DCHECK(!decode_cb.is_null()); 103 DCHECK(!decode_cb.is_null());
99 CHECK(decode_cb_.is_null()) << "Overlapping decodes are not supported."; 104 CHECK(decode_cb_.is_null()) << "Overlapping decodes are not supported.";
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 DVLOG(2) << __FUNCTION__; 161 DVLOG(2) << __FUNCTION__;
157 DCHECK(task_runner_->BelongsToCurrentThread()); 162 DCHECK(task_runner_->BelongsToCurrentThread());
158 163
159 if (state_ == kUninitialized) 164 if (state_ == kUninitialized)
160 return; 165 return;
161 166
162 if (decryptor_) { 167 if (decryptor_) {
163 decryptor_->DeinitializeDecoder(Decryptor::kAudio); 168 decryptor_->DeinitializeDecoder(Decryptor::kAudio);
164 decryptor_ = NULL; 169 decryptor_ = NULL;
165 } 170 }
166 if (!set_cdm_ready_cb_.is_null())
167 base::ResetAndReturn(&set_cdm_ready_cb_).Run(CdmReadyCB());
168 pending_buffer_to_decode_ = NULL; 171 pending_buffer_to_decode_ = NULL;
169 if (!init_cb_.is_null()) 172 if (!init_cb_.is_null())
170 base::ResetAndReturn(&init_cb_).Run(false); 173 base::ResetAndReturn(&init_cb_).Run(false);
171 if (!decode_cb_.is_null()) 174 if (!decode_cb_.is_null())
172 base::ResetAndReturn(&decode_cb_).Run(kAborted); 175 base::ResetAndReturn(&decode_cb_).Run(kAborted);
173 if (!reset_cb_.is_null()) 176 if (!reset_cb_.is_null())
174 base::ResetAndReturn(&reset_cb_).Run(); 177 base::ResetAndReturn(&reset_cb_).Run();
175 } 178 }
176 179
177 void DecryptingAudioDecoder::SetCdm(CdmContext* cdm_context,
178 const CdmAttachedCB& cdm_attached_cb) {
179 DVLOG(2) << __FUNCTION__;
180 DCHECK(task_runner_->BelongsToCurrentThread());
181 DCHECK_EQ(state_, kDecryptorRequested) << state_;
182 DCHECK(!init_cb_.is_null());
183 DCHECK(!set_cdm_ready_cb_.is_null());
184
185 set_cdm_ready_cb_.Reset();
186
187 if (!cdm_context || !cdm_context->GetDecryptor()) {
188 MEDIA_LOG(DEBUG, media_log_) << GetDisplayName() << ": no decryptor set";
189 base::ResetAndReturn(&init_cb_).Run(false);
190 state_ = kError;
191 cdm_attached_cb.Run(false);
192 return;
193 }
194
195 decryptor_ = cdm_context->GetDecryptor();
196
197 InitializeDecoder();
198 cdm_attached_cb.Run(true);
199 }
200
201 void DecryptingAudioDecoder::InitializeDecoder() { 180 void DecryptingAudioDecoder::InitializeDecoder() {
202 state_ = kPendingDecoderInit; 181 state_ = kPendingDecoderInit;
203 decryptor_->InitializeAudioDecoder( 182 decryptor_->InitializeAudioDecoder(
204 config_, 183 config_,
205 BindToCurrentLoop(base::Bind( 184 BindToCurrentLoop(base::Bind(
206 &DecryptingAudioDecoder::FinishInitialization, weak_this_))); 185 &DecryptingAudioDecoder::FinishInitialization, weak_this_)));
207 } 186 }
208 187
209 void DecryptingAudioDecoder::FinishInitialization(bool success) { 188 void DecryptingAudioDecoder::FinishInitialization(bool success) {
210 DVLOG(2) << "FinishInitialization()"; 189 DVLOG(2) << "FinishInitialization()";
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } 347 }
369 348
370 frame->set_timestamp(current_time); 349 frame->set_timestamp(current_time);
371 timestamp_helper_->AddFrames(frame->frame_count()); 350 timestamp_helper_->AddFrames(frame->frame_count());
372 351
373 output_cb_.Run(frame); 352 output_cb_.Run(frame);
374 } 353 }
375 } 354 }
376 355
377 } // namespace media 356 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698