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

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

Issue 177333003: Add support for midstream audio configuration changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ABS
Patch Set: Created 6 years, 9 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 24 matching lines...) Expand all
35 } 35 }
36 36
37 DecryptingAudioDecoder::DecryptingAudioDecoder( 37 DecryptingAudioDecoder::DecryptingAudioDecoder(
38 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 38 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
39 const SetDecryptorReadyCB& set_decryptor_ready_cb) 39 const SetDecryptorReadyCB& set_decryptor_ready_cb)
40 : task_runner_(task_runner), 40 : task_runner_(task_runner),
41 state_(kUninitialized), 41 state_(kUninitialized),
42 set_decryptor_ready_cb_(set_decryptor_ready_cb), 42 set_decryptor_ready_cb_(set_decryptor_ready_cb),
43 decryptor_(NULL), 43 decryptor_(NULL),
44 key_added_while_decode_pending_(false), 44 key_added_while_decode_pending_(false),
45 bits_per_channel_(0),
46 channel_layout_(CHANNEL_LAYOUT_NONE),
47 samples_per_second_(0),
48 weak_factory_(this) {} 45 weak_factory_(this) {}
49 46
50 void DecryptingAudioDecoder::Initialize(const AudioDecoderConfig& config, 47 void DecryptingAudioDecoder::Initialize(const AudioDecoderConfig& config,
51 const PipelineStatusCB& status_cb) { 48 const PipelineStatusCB& status_cb) {
52 DVLOG(2) << "Initialize()"; 49 DVLOG(2) << "Initialize()";
53 DCHECK(task_runner_->BelongsToCurrentThread()); 50 DCHECK(task_runner_->BelongsToCurrentThread());
54 DCHECK(decode_cb_.is_null()); 51 DCHECK(decode_cb_.is_null());
55 DCHECK(reset_cb_.is_null()); 52 DCHECK(reset_cb_.is_null());
56 53
57 weak_this_ = weak_factory_.GetWeakPtr(); 54 weak_this_ = weak_factory_.GetWeakPtr();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 179 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
183 if (!decode_cb_.is_null()) 180 if (!decode_cb_.is_null())
184 base::ResetAndReturn(&decode_cb_).Run(kAborted, NULL); 181 base::ResetAndReturn(&decode_cb_).Run(kAborted, NULL);
185 if (!reset_cb_.is_null()) 182 if (!reset_cb_.is_null())
186 base::ResetAndReturn(&reset_cb_).Run(); 183 base::ResetAndReturn(&reset_cb_).Run();
187 184
188 state_ = kStopped; 185 state_ = kStopped;
189 task_runner_->PostTask(FROM_HERE, closure); 186 task_runner_->PostTask(FROM_HERE, closure);
190 } 187 }
191 188
192 int DecryptingAudioDecoder::bits_per_channel() {
193 DCHECK(task_runner_->BelongsToCurrentThread());
194 return bits_per_channel_;
195 }
196
197 ChannelLayout DecryptingAudioDecoder::channel_layout() {
198 DCHECK(task_runner_->BelongsToCurrentThread());
199 return channel_layout_;
200 }
201
202 int DecryptingAudioDecoder::samples_per_second() {
203 DCHECK(task_runner_->BelongsToCurrentThread());
204 return samples_per_second_;
205 }
206
207 DecryptingAudioDecoder::~DecryptingAudioDecoder() { 189 DecryptingAudioDecoder::~DecryptingAudioDecoder() {
208 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_; 190 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_;
209 } 191 }
210 192
211 void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) { 193 void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) {
212 DVLOG(2) << "SetDecryptor()"; 194 DVLOG(2) << "SetDecryptor()";
213 DCHECK(task_runner_->BelongsToCurrentThread()); 195 DCHECK(task_runner_->BelongsToCurrentThread());
214 DCHECK_EQ(state_, kDecryptorRequested) << state_; 196 DCHECK_EQ(state_, kDecryptorRequested) << state_;
215 DCHECK(!init_cb_.is_null()); 197 DCHECK(!init_cb_.is_null());
216 DCHECK(!set_decryptor_ready_cb_.is_null()); 198 DCHECK(!set_decryptor_ready_cb_.is_null());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. 235 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished.
254 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished. 236 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished.
255 237
256 if (!success) { 238 if (!success) {
257 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 239 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
258 state_ = kStopped; 240 state_ = kStopped;
259 return; 241 return;
260 } 242 }
261 243
262 // Success! 244 // Success!
263 UpdateDecoderConfig(); 245 timestamp_helper_.reset(
246 new AudioTimestampHelper(config_.samples_per_second()));
264 247
265 decryptor_->RegisterNewKeyCB( 248 decryptor_->RegisterNewKeyCB(
266 Decryptor::kAudio, 249 Decryptor::kAudio,
267 BindToCurrentLoop( 250 BindToCurrentLoop(
268 base::Bind(&DecryptingAudioDecoder::OnKeyAdded, weak_this_))); 251 base::Bind(&DecryptingAudioDecoder::OnKeyAdded, weak_this_)));
269 252
270 state_ = kIdle; 253 state_ = kIdle;
271 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); 254 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK);
272 } 255 }
273 256
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 } 356 }
374 357
375 void DecryptingAudioDecoder::DoReset() { 358 void DecryptingAudioDecoder::DoReset() {
376 DCHECK(init_cb_.is_null()); 359 DCHECK(init_cb_.is_null());
377 DCHECK(decode_cb_.is_null()); 360 DCHECK(decode_cb_.is_null());
378 timestamp_helper_->SetBaseTimestamp(kNoTimestamp()); 361 timestamp_helper_->SetBaseTimestamp(kNoTimestamp());
379 state_ = kIdle; 362 state_ = kIdle;
380 base::ResetAndReturn(&reset_cb_).Run(); 363 base::ResetAndReturn(&reset_cb_).Run();
381 } 364 }
382 365
383 void DecryptingAudioDecoder::UpdateDecoderConfig() {
384 bits_per_channel_ = kSupportedBitsPerChannel;
385 channel_layout_ = config_.channel_layout();
386 samples_per_second_ = config_.samples_per_second();
387 timestamp_helper_.reset(new AudioTimestampHelper(samples_per_second_));
388 }
389
390 void DecryptingAudioDecoder::EnqueueFrames( 366 void DecryptingAudioDecoder::EnqueueFrames(
391 const Decryptor::AudioBuffers& frames) { 367 const Decryptor::AudioBuffers& frames) {
392 queued_audio_frames_ = frames; 368 queued_audio_frames_ = frames;
393 369
394 for (Decryptor::AudioBuffers::iterator iter = queued_audio_frames_.begin(); 370 for (Decryptor::AudioBuffers::iterator iter = queued_audio_frames_.begin();
395 iter != queued_audio_frames_.end(); 371 iter != queued_audio_frames_.end();
396 ++iter) { 372 ++iter) {
397 scoped_refptr<AudioBuffer>& frame = *iter; 373 scoped_refptr<AudioBuffer>& frame = *iter;
398 374
399 DCHECK(!frame->end_of_stream()) << "EOS frame returned."; 375 DCHECK(!frame->end_of_stream()) << "EOS frame returned.";
400 DCHECK_GT(frame->frame_count(), 0) << "Empty frame returned."; 376 DCHECK_GT(frame->frame_count(), 0) << "Empty frame returned.";
401 377
402 base::TimeDelta current_time = timestamp_helper_->GetTimestamp(); 378 base::TimeDelta current_time = timestamp_helper_->GetTimestamp();
403 if (IsOutOfSync(current_time, frame->timestamp())) { 379 if (IsOutOfSync(current_time, frame->timestamp())) {
404 DVLOG(1) << "Timestamp returned by the decoder (" 380 DVLOG(1) << "Timestamp returned by the decoder ("
405 << frame->timestamp().InMilliseconds() << " ms)" 381 << frame->timestamp().InMilliseconds() << " ms)"
406 << " does not match the input timestamp and number of samples" 382 << " does not match the input timestamp and number of samples"
407 << " decoded (" << current_time.InMilliseconds() << " ms)."; 383 << " decoded (" << current_time.InMilliseconds() << " ms).";
408 } 384 }
409 385
410 frame->set_timestamp(current_time); 386 frame->set_timestamp(current_time);
411 frame->set_duration( 387 frame->set_duration(
412 timestamp_helper_->GetFrameDuration(frame->frame_count())); 388 timestamp_helper_->GetFrameDuration(frame->frame_count()));
413 timestamp_helper_->AddFrames(frame->frame_count()); 389 timestamp_helper_->AddFrames(frame->frame_count());
414 } 390 }
415 } 391 }
416 392
417 } // namespace media 393 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698