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

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

Issue 1143223007: media: Reland "Simplify {Audio|Video}Decoder initialization callback." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 <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 30 matching lines...) Expand all
41 decryptor_(NULL), 41 decryptor_(NULL),
42 key_added_while_decode_pending_(false), 42 key_added_while_decode_pending_(false),
43 weak_factory_(this) { 43 weak_factory_(this) {
44 } 44 }
45 45
46 std::string DecryptingAudioDecoder::GetDisplayName() const { 46 std::string DecryptingAudioDecoder::GetDisplayName() const {
47 return "DecryptingAudioDecoder"; 47 return "DecryptingAudioDecoder";
48 } 48 }
49 49
50 void DecryptingAudioDecoder::Initialize(const AudioDecoderConfig& config, 50 void DecryptingAudioDecoder::Initialize(const AudioDecoderConfig& config,
51 const PipelineStatusCB& status_cb, 51 const InitCB& init_cb,
52 const OutputCB& output_cb) { 52 const OutputCB& output_cb) {
53 DVLOG(2) << "Initialize()"; 53 DVLOG(2) << "Initialize()";
54 DCHECK(task_runner_->BelongsToCurrentThread()); 54 DCHECK(task_runner_->BelongsToCurrentThread());
55 DCHECK(decode_cb_.is_null()); 55 DCHECK(decode_cb_.is_null());
56 DCHECK(reset_cb_.is_null()); 56 DCHECK(reset_cb_.is_null());
57 57
58 weak_this_ = weak_factory_.GetWeakPtr(); 58 weak_this_ = weak_factory_.GetWeakPtr();
59 init_cb_ = BindToCurrentLoop(status_cb); 59 init_cb_ = BindToCurrentLoop(init_cb);
60 output_cb_ = BindToCurrentLoop(output_cb); 60 output_cb_ = BindToCurrentLoop(output_cb);
61 61
62 if (!config.IsValidConfig()) { 62 if (!config.IsValidConfig()) {
63 DLOG(ERROR) << "Invalid audio stream config."; 63 DLOG(ERROR) << "Invalid audio stream config.";
64 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_DECODE); 64 base::ResetAndReturn(&init_cb_).Run(false);
65 return; 65 return;
66 } 66 }
67 67
68 // DecryptingAudioDecoder only accepts potentially encrypted stream. 68 // DecryptingAudioDecoder only accepts potentially encrypted stream.
69 if (!config.is_encrypted()) { 69 if (!config.is_encrypted()) {
70 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 70 base::ResetAndReturn(&init_cb_).Run(false);
71 return; 71 return;
72 } 72 }
73 73
74 config_ = config; 74 config_ = config;
75 75
76 if (state_ == kUninitialized) { 76 if (state_ == kUninitialized) {
77 state_ = kDecryptorRequested; 77 state_ = kDecryptorRequested;
78 set_decryptor_ready_cb_.Run(BindToCurrentLoop( 78 set_decryptor_ready_cb_.Run(BindToCurrentLoop(
79 base::Bind(&DecryptingAudioDecoder::SetDecryptor, weak_this_))); 79 base::Bind(&DecryptingAudioDecoder::SetDecryptor, weak_this_)));
80 return; 80 return;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 return; 155 return;
156 156
157 if (decryptor_) { 157 if (decryptor_) {
158 decryptor_->DeinitializeDecoder(Decryptor::kAudio); 158 decryptor_->DeinitializeDecoder(Decryptor::kAudio);
159 decryptor_ = NULL; 159 decryptor_ = NULL;
160 } 160 }
161 if (!set_decryptor_ready_cb_.is_null()) 161 if (!set_decryptor_ready_cb_.is_null())
162 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB()); 162 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB());
163 pending_buffer_to_decode_ = NULL; 163 pending_buffer_to_decode_ = NULL;
164 if (!init_cb_.is_null()) 164 if (!init_cb_.is_null())
165 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 165 base::ResetAndReturn(&init_cb_).Run(false);
166 if (!decode_cb_.is_null()) 166 if (!decode_cb_.is_null())
167 base::ResetAndReturn(&decode_cb_).Run(kAborted); 167 base::ResetAndReturn(&decode_cb_).Run(kAborted);
168 if (!reset_cb_.is_null()) 168 if (!reset_cb_.is_null())
169 base::ResetAndReturn(&reset_cb_).Run(); 169 base::ResetAndReturn(&reset_cb_).Run();
170 } 170 }
171 171
172 void DecryptingAudioDecoder::SetDecryptor( 172 void DecryptingAudioDecoder::SetDecryptor(
173 Decryptor* decryptor, 173 Decryptor* decryptor,
174 const DecryptorAttachedCB& decryptor_attached_cb) { 174 const DecryptorAttachedCB& decryptor_attached_cb) {
175 DVLOG(2) << "SetDecryptor()"; 175 DVLOG(2) << "SetDecryptor()";
176 DCHECK(task_runner_->BelongsToCurrentThread()); 176 DCHECK(task_runner_->BelongsToCurrentThread());
177 DCHECK_EQ(state_, kDecryptorRequested) << state_; 177 DCHECK_EQ(state_, kDecryptorRequested) << state_;
178 DCHECK(!init_cb_.is_null()); 178 DCHECK(!init_cb_.is_null());
179 DCHECK(!set_decryptor_ready_cb_.is_null()); 179 DCHECK(!set_decryptor_ready_cb_.is_null());
180 180
181 set_decryptor_ready_cb_.Reset(); 181 set_decryptor_ready_cb_.Reset();
182 182
183 if (!decryptor) { 183 if (!decryptor) {
184 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 184 base::ResetAndReturn(&init_cb_).Run(false);
185 state_ = kError; 185 state_ = kError;
186 decryptor_attached_cb.Run(false); 186 decryptor_attached_cb.Run(false);
187 return; 187 return;
188 } 188 }
189 189
190 decryptor_ = decryptor; 190 decryptor_ = decryptor;
191 191
192 InitializeDecoder(); 192 InitializeDecoder();
193 decryptor_attached_cb.Run(true); 193 decryptor_attached_cb.Run(true);
194 } 194 }
195 195
196 void DecryptingAudioDecoder::InitializeDecoder() { 196 void DecryptingAudioDecoder::InitializeDecoder() {
197 state_ = kPendingDecoderInit; 197 state_ = kPendingDecoderInit;
198 decryptor_->InitializeAudioDecoder( 198 decryptor_->InitializeAudioDecoder(
199 config_, 199 config_,
200 BindToCurrentLoop(base::Bind( 200 BindToCurrentLoop(base::Bind(
201 &DecryptingAudioDecoder::FinishInitialization, weak_this_))); 201 &DecryptingAudioDecoder::FinishInitialization, weak_this_)));
202 } 202 }
203 203
204 void DecryptingAudioDecoder::FinishInitialization(bool success) { 204 void DecryptingAudioDecoder::FinishInitialization(bool success) {
205 DVLOG(2) << "FinishInitialization()"; 205 DVLOG(2) << "FinishInitialization()";
206 DCHECK(task_runner_->BelongsToCurrentThread()); 206 DCHECK(task_runner_->BelongsToCurrentThread());
207 DCHECK(state_ == kPendingDecoderInit) << state_; 207 DCHECK(state_ == kPendingDecoderInit) << state_;
208 DCHECK(!init_cb_.is_null()); 208 DCHECK(!init_cb_.is_null());
209 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. 209 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished.
210 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished. 210 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished.
211 211
212 if (!success) { 212 if (!success) {
213 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 213 base::ResetAndReturn(&init_cb_).Run(false);
214 decryptor_ = NULL; 214 decryptor_ = NULL;
215 state_ = kError; 215 state_ = kError;
216 return; 216 return;
217 } 217 }
218 218
219 // Success! 219 // Success!
220 timestamp_helper_.reset( 220 timestamp_helper_.reset(
221 new AudioTimestampHelper(config_.samples_per_second())); 221 new AudioTimestampHelper(config_.samples_per_second()));
222 222
223 decryptor_->RegisterNewKeyCB( 223 decryptor_->RegisterNewKeyCB(
224 Decryptor::kAudio, 224 Decryptor::kAudio,
225 BindToCurrentLoop( 225 BindToCurrentLoop(
226 base::Bind(&DecryptingAudioDecoder::OnKeyAdded, weak_this_))); 226 base::Bind(&DecryptingAudioDecoder::OnKeyAdded, weak_this_)));
227 227
228 state_ = kIdle; 228 state_ = kIdle;
229 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); 229 base::ResetAndReturn(&init_cb_).Run(true);
230 } 230 }
231 231
232 void DecryptingAudioDecoder::DecodePendingBuffer() { 232 void DecryptingAudioDecoder::DecodePendingBuffer() {
233 DCHECK(task_runner_->BelongsToCurrentThread()); 233 DCHECK(task_runner_->BelongsToCurrentThread());
234 DCHECK_EQ(state_, kPendingDecode) << state_; 234 DCHECK_EQ(state_, kPendingDecode) << state_;
235 235
236 int buffer_size = 0; 236 int buffer_size = 0;
237 if (!pending_buffer_to_decode_->end_of_stream()) { 237 if (!pending_buffer_to_decode_->end_of_stream()) {
238 buffer_size = pending_buffer_to_decode_->data_size(); 238 buffer_size = pending_buffer_to_decode_->data_size();
239 } 239 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } 358 }
359 359
360 frame->set_timestamp(current_time); 360 frame->set_timestamp(current_time);
361 timestamp_helper_->AddFrames(frame->frame_count()); 361 timestamp_helper_->AddFrames(frame->frame_count());
362 362
363 output_cb_.Run(frame); 363 output_cb_.Run(frame);
364 } 364 }
365 } 365 }
366 366
367 } // namespace media 367 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/decrypting_audio_decoder.h ('k') | media/filters/decrypting_audio_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698