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

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: disable fifo, add <cmath> to fix compile error Created 6 years, 8 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 175 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
179 if (!decode_cb_.is_null()) 176 if (!decode_cb_.is_null())
180 base::ResetAndReturn(&decode_cb_).Run(kAborted, NULL); 177 base::ResetAndReturn(&decode_cb_).Run(kAborted, NULL);
181 if (!reset_cb_.is_null()) 178 if (!reset_cb_.is_null())
182 base::ResetAndReturn(&reset_cb_).Run(); 179 base::ResetAndReturn(&reset_cb_).Run();
183 180
184 state_ = kStopped; 181 state_ = kStopped;
185 task_runner_->PostTask(FROM_HERE, closure); 182 task_runner_->PostTask(FROM_HERE, closure);
186 } 183 }
187 184
188 int DecryptingAudioDecoder::bits_per_channel() {
189 DCHECK(task_runner_->BelongsToCurrentThread());
190 return bits_per_channel_;
191 }
192
193 ChannelLayout DecryptingAudioDecoder::channel_layout() {
194 DCHECK(task_runner_->BelongsToCurrentThread());
195 return channel_layout_;
196 }
197
198 int DecryptingAudioDecoder::samples_per_second() {
199 DCHECK(task_runner_->BelongsToCurrentThread());
200 return samples_per_second_;
201 }
202
203 DecryptingAudioDecoder::~DecryptingAudioDecoder() { 185 DecryptingAudioDecoder::~DecryptingAudioDecoder() {
204 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_; 186 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_;
205 } 187 }
206 188
207 void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) { 189 void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) {
208 DVLOG(2) << "SetDecryptor()"; 190 DVLOG(2) << "SetDecryptor()";
209 DCHECK(task_runner_->BelongsToCurrentThread()); 191 DCHECK(task_runner_->BelongsToCurrentThread());
210 DCHECK_EQ(state_, kDecryptorRequested) << state_; 192 DCHECK_EQ(state_, kDecryptorRequested) << state_;
211 DCHECK(!init_cb_.is_null()); 193 DCHECK(!init_cb_.is_null());
212 DCHECK(!set_decryptor_ready_cb_.is_null()); 194 DCHECK(!set_decryptor_ready_cb_.is_null());
(...skipping 40 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
« 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