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

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

Issue 1423163004: media: Replace DecryptorReadyCB with CdmReadyCB. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix android Created 5 years, 1 month 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 <cstdlib> 7 #include <cstdlib>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 16 matching lines...) Expand all
27 // Out of sync of 100ms would be pretty noticeable and we should keep any 27 // Out of sync of 100ms would be pretty noticeable and we should keep any
28 // drift below that. 28 // drift below that.
29 const int64 kOutOfSyncThresholdInMilliseconds = 100; 29 const int64 kOutOfSyncThresholdInMilliseconds = 100;
30 return std::abs(timestamp_1.InMilliseconds() - timestamp_2.InMilliseconds()) > 30 return std::abs(timestamp_1.InMilliseconds() - timestamp_2.InMilliseconds()) >
31 kOutOfSyncThresholdInMilliseconds; 31 kOutOfSyncThresholdInMilliseconds;
32 } 32 }
33 33
34 DecryptingAudioDecoder::DecryptingAudioDecoder( 34 DecryptingAudioDecoder::DecryptingAudioDecoder(
35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
36 const scoped_refptr<MediaLog>& media_log, 36 const scoped_refptr<MediaLog>& media_log,
37 const SetDecryptorReadyCB& set_decryptor_ready_cb, 37 const SetCdmReadyCB& set_cdm_ready_cb,
38 const base::Closure& waiting_for_decryption_key_cb) 38 const base::Closure& waiting_for_decryption_key_cb)
39 : task_runner_(task_runner), 39 : task_runner_(task_runner),
40 media_log_(media_log), 40 media_log_(media_log),
41 state_(kUninitialized), 41 state_(kUninitialized),
42 waiting_for_decryption_key_cb_(waiting_for_decryption_key_cb), 42 waiting_for_decryption_key_cb_(waiting_for_decryption_key_cb),
43 set_decryptor_ready_cb_(set_decryptor_ready_cb), 43 set_cdm_ready_cb_(set_cdm_ready_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 }
48 47
49 std::string DecryptingAudioDecoder::GetDisplayName() const { 48 std::string DecryptingAudioDecoder::GetDisplayName() const {
50 return "DecryptingAudioDecoder"; 49 return "DecryptingAudioDecoder";
51 } 50 }
52 51
53 void DecryptingAudioDecoder::Initialize(const AudioDecoderConfig& config, 52 void DecryptingAudioDecoder::Initialize(const AudioDecoderConfig& config,
54 const InitCB& init_cb, 53 const InitCB& init_cb,
55 const OutputCB& output_cb) { 54 const OutputCB& output_cb) {
56 DVLOG(2) << "Initialize()"; 55 DVLOG(2) << "Initialize()";
57 DCHECK(task_runner_->BelongsToCurrentThread()); 56 DCHECK(task_runner_->BelongsToCurrentThread());
(...skipping 13 matching lines...) Expand all
71 // DecryptingAudioDecoder only accepts potentially encrypted stream. 70 // DecryptingAudioDecoder only accepts potentially encrypted stream.
72 if (!config.is_encrypted()) { 71 if (!config.is_encrypted()) {
73 base::ResetAndReturn(&init_cb_).Run(false); 72 base::ResetAndReturn(&init_cb_).Run(false);
74 return; 73 return;
75 } 74 }
76 75
77 config_ = config; 76 config_ = config;
78 77
79 if (state_ == kUninitialized) { 78 if (state_ == kUninitialized) {
80 state_ = kDecryptorRequested; 79 state_ = kDecryptorRequested;
81 set_decryptor_ready_cb_.Run(BindToCurrentLoop( 80 set_cdm_ready_cb_.Run(BindToCurrentLoop(
82 base::Bind(&DecryptingAudioDecoder::SetDecryptor, weak_this_))); 81 base::Bind(&DecryptingAudioDecoder::SetCdm, weak_this_)));
83 return; 82 return;
84 } 83 }
85 84
86 // Reinitialization (i.e. upon a config change) 85 // Reinitialization (i.e. upon a config change)
87 decryptor_->DeinitializeDecoder(Decryptor::kAudio); 86 decryptor_->DeinitializeDecoder(Decryptor::kAudio);
88 InitializeDecoder(); 87 InitializeDecoder();
89 } 88 }
90 89
91 void DecryptingAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, 90 void DecryptingAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer,
92 const DecodeCB& decode_cb) { 91 const DecodeCB& decode_cb) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 DVLOG(2) << __FUNCTION__; 153 DVLOG(2) << __FUNCTION__;
155 DCHECK(task_runner_->BelongsToCurrentThread()); 154 DCHECK(task_runner_->BelongsToCurrentThread());
156 155
157 if (state_ == kUninitialized) 156 if (state_ == kUninitialized)
158 return; 157 return;
159 158
160 if (decryptor_) { 159 if (decryptor_) {
161 decryptor_->DeinitializeDecoder(Decryptor::kAudio); 160 decryptor_->DeinitializeDecoder(Decryptor::kAudio);
162 decryptor_ = NULL; 161 decryptor_ = NULL;
163 } 162 }
164 if (!set_decryptor_ready_cb_.is_null()) 163 if (!set_cdm_ready_cb_.is_null())
165 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB()); 164 base::ResetAndReturn(&set_cdm_ready_cb_).Run(CdmReadyCB());
166 pending_buffer_to_decode_ = NULL; 165 pending_buffer_to_decode_ = NULL;
167 if (!init_cb_.is_null()) 166 if (!init_cb_.is_null())
168 base::ResetAndReturn(&init_cb_).Run(false); 167 base::ResetAndReturn(&init_cb_).Run(false);
169 if (!decode_cb_.is_null()) 168 if (!decode_cb_.is_null())
170 base::ResetAndReturn(&decode_cb_).Run(kAborted); 169 base::ResetAndReturn(&decode_cb_).Run(kAborted);
171 if (!reset_cb_.is_null()) 170 if (!reset_cb_.is_null())
172 base::ResetAndReturn(&reset_cb_).Run(); 171 base::ResetAndReturn(&reset_cb_).Run();
173 } 172 }
174 173
175 void DecryptingAudioDecoder::SetDecryptor( 174 void DecryptingAudioDecoder::SetCdm(CdmContext* cdm_context,
176 Decryptor* decryptor, 175 const CdmAttachedCB& cdm_attached_cb) {
177 const DecryptorAttachedCB& decryptor_attached_cb) { 176 DVLOG(2) << __FUNCTION__;
178 DVLOG(2) << "SetDecryptor()";
179 DCHECK(task_runner_->BelongsToCurrentThread()); 177 DCHECK(task_runner_->BelongsToCurrentThread());
180 DCHECK_EQ(state_, kDecryptorRequested) << state_; 178 DCHECK_EQ(state_, kDecryptorRequested) << state_;
181 DCHECK(!init_cb_.is_null()); 179 DCHECK(!init_cb_.is_null());
182 DCHECK(!set_decryptor_ready_cb_.is_null()); 180 DCHECK(!set_cdm_ready_cb_.is_null());
183 181
184 set_decryptor_ready_cb_.Reset(); 182 set_cdm_ready_cb_.Reset();
185 183
186 if (!decryptor) { 184 if (!cdm_context || !cdm_context->GetDecryptor()) {
187 MEDIA_LOG(DEBUG, media_log_) << GetDisplayName() << ": no decryptor set"; 185 MEDIA_LOG(DEBUG, media_log_) << GetDisplayName() << ": no decryptor set";
188 base::ResetAndReturn(&init_cb_).Run(false); 186 base::ResetAndReturn(&init_cb_).Run(false);
189 state_ = kError; 187 state_ = kError;
190 decryptor_attached_cb.Run(false); 188 cdm_attached_cb.Run(false);
191 return; 189 return;
192 } 190 }
193 191
194 decryptor_ = decryptor; 192 decryptor_ = cdm_context->GetDecryptor();
195 193
196 InitializeDecoder(); 194 InitializeDecoder();
197 decryptor_attached_cb.Run(true); 195 cdm_attached_cb.Run(true);
198 } 196 }
199 197
200 void DecryptingAudioDecoder::InitializeDecoder() { 198 void DecryptingAudioDecoder::InitializeDecoder() {
201 state_ = kPendingDecoderInit; 199 state_ = kPendingDecoderInit;
202 decryptor_->InitializeAudioDecoder( 200 decryptor_->InitializeAudioDecoder(
203 config_, 201 config_,
204 BindToCurrentLoop(base::Bind( 202 BindToCurrentLoop(base::Bind(
205 &DecryptingAudioDecoder::FinishInitialization, weak_this_))); 203 &DecryptingAudioDecoder::FinishInitialization, weak_this_)));
206 } 204 }
207 205
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 365 }
368 366
369 frame->set_timestamp(current_time); 367 frame->set_timestamp(current_time);
370 timestamp_helper_->AddFrames(frame->frame_count()); 368 timestamp_helper_->AddFrames(frame->frame_count());
371 369
372 output_cb_.Run(frame); 370 output_cb_.Run(frame);
373 } 371 }
374 } 372 }
375 373
376 } // namespace media 374 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698