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

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

Issue 17315021: Refactored DataBuffer to use unix_hacker style methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor DataBuffer Created 7 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 DVLOG(3) << "Read()"; 89 DVLOG(3) << "Read()";
90 DCHECK(message_loop_->BelongsToCurrentThread()); 90 DCHECK(message_loop_->BelongsToCurrentThread());
91 DCHECK(state_ == kIdle || state_ == kDecodeFinished) << state_; 91 DCHECK(state_ == kIdle || state_ == kDecodeFinished) << state_;
92 DCHECK(!read_cb.is_null()); 92 DCHECK(!read_cb.is_null());
93 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; 93 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported.";
94 94
95 read_cb_ = BindToCurrentLoop(read_cb); 95 read_cb_ = BindToCurrentLoop(read_cb);
96 96
97 // Return empty (end-of-stream) frames if decoding has finished. 97 // Return empty (end-of-stream) frames if decoding has finished.
98 if (state_ == kDecodeFinished) { 98 if (state_ == kDecodeFinished) {
99 base::ResetAndReturn(&read_cb_).Run(kOk, DataBuffer::CreateEOSBuffer()); 99 base::ResetAndReturn(&read_cb_).Run(kOk, DataBuffer::create_eos_buffer());
100 return; 100 return;
101 } 101 }
102 102
103 if (!queued_audio_frames_.empty()) { 103 if (!queued_audio_frames_.empty()) {
104 base::ResetAndReturn(&read_cb_).Run(kOk, queued_audio_frames_.front()); 104 base::ResetAndReturn(&read_cb_).Run(kOk, queued_audio_frames_.front());
105 queued_audio_frames_.pop_front(); 105 queued_audio_frames_.pop_front();
106 return; 106 return;
107 } 107 }
108 108
109 state_ = kPendingDemuxerRead; 109 state_ = kPendingDemuxerRead;
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 if (buffer_size) { 389 if (buffer_size) {
390 PipelineStatistics statistics; 390 PipelineStatistics statistics;
391 statistics.audio_bytes_decoded = buffer_size; 391 statistics.audio_bytes_decoded = buffer_size;
392 statistics_cb_.Run(statistics); 392 statistics_cb_.Run(statistics);
393 } 393 }
394 394
395 if (status == Decryptor::kNeedMoreData) { 395 if (status == Decryptor::kNeedMoreData) {
396 DVLOG(2) << "DeliverFrame() - kNeedMoreData"; 396 DVLOG(2) << "DeliverFrame() - kNeedMoreData";
397 if (scoped_pending_buffer_to_decode->IsEndOfStream()) { 397 if (scoped_pending_buffer_to_decode->IsEndOfStream()) {
398 state_ = kDecodeFinished; 398 state_ = kDecodeFinished;
399 base::ResetAndReturn(&read_cb_).Run(kOk, DataBuffer::CreateEOSBuffer()); 399 base::ResetAndReturn(&read_cb_).Run(kOk, DataBuffer::create_eos_buffer());
400 return; 400 return;
401 } 401 }
402 402
403 state_ = kPendingDemuxerRead; 403 state_ = kPendingDemuxerRead;
404 ReadFromDemuxerStream(); 404 ReadFromDemuxerStream();
405 return; 405 return;
406 } 406 }
407 407
408 DCHECK_EQ(status, Decryptor::kSuccess); 408 DCHECK_EQ(status, Decryptor::kSuccess);
409 DCHECK(!frames.empty()); 409 DCHECK(!frames.empty());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 451
452 void DecryptingAudioDecoder::EnqueueFrames( 452 void DecryptingAudioDecoder::EnqueueFrames(
453 const Decryptor::AudioBuffers& frames) { 453 const Decryptor::AudioBuffers& frames) {
454 queued_audio_frames_ = frames; 454 queued_audio_frames_ = frames;
455 455
456 for (Decryptor::AudioBuffers::iterator iter = queued_audio_frames_.begin(); 456 for (Decryptor::AudioBuffers::iterator iter = queued_audio_frames_.begin();
457 iter != queued_audio_frames_.end(); 457 iter != queued_audio_frames_.end();
458 ++iter) { 458 ++iter) {
459 scoped_refptr<DataBuffer>& frame = *iter; 459 scoped_refptr<DataBuffer>& frame = *iter;
460 460
461 DCHECK(!frame->IsEndOfStream()) << "EOS frame returned."; 461 DCHECK(!frame->is_end_of_stream()) << "EOS frame returned.";
462 DCHECK_GT(frame->GetDataSize(), 0) << "Empty frame returned."; 462 DCHECK_GT(frame->get_data_size(), 0) << "Empty frame returned.";
463 463
464 base::TimeDelta cur_timestamp = output_timestamp_base_ + 464 base::TimeDelta cur_timestamp = output_timestamp_base_ +
465 NumberOfSamplesToDuration(total_samples_decoded_); 465 NumberOfSamplesToDuration(total_samples_decoded_);
466 if (IsOutOfSync(cur_timestamp, frame->GetTimestamp())) { 466 if (IsOutOfSync(cur_timestamp, frame->get_timestamp())) {
467 DVLOG(1) << "Timestamp returned by the decoder (" 467 DVLOG(1) << "Timestamp returned by the decoder ("
468 << frame->GetTimestamp().InMilliseconds() << " ms)" 468 << frame->get_timestamp().InMilliseconds() << " ms)"
469 << " does not match the input timestamp and number of samples" 469 << " does not match the input timestamp and number of samples"
470 << " decoded (" << cur_timestamp.InMilliseconds() << " ms)."; 470 << " decoded (" << cur_timestamp.InMilliseconds() << " ms).";
471 } 471 }
472 frame->SetTimestamp(cur_timestamp); 472 frame->set_timestamp(cur_timestamp);
473 473
474 int frame_size = frame->GetDataSize(); 474 int frame_size = frame->get_data_size();
475 DCHECK_EQ(frame_size % bytes_per_sample_, 0) << 475 DCHECK_EQ(frame_size % bytes_per_sample_, 0) <<
476 "Decoder didn't output full samples"; 476 "Decoder didn't output full samples";
477 int samples_decoded = frame_size / bytes_per_sample_; 477 int samples_decoded = frame_size / bytes_per_sample_;
478 total_samples_decoded_ += samples_decoded; 478 total_samples_decoded_ += samples_decoded;
479 479
480 base::TimeDelta next_timestamp = output_timestamp_base_ + 480 base::TimeDelta next_timestamp = output_timestamp_base_ +
481 NumberOfSamplesToDuration(total_samples_decoded_); 481 NumberOfSamplesToDuration(total_samples_decoded_);
482 base::TimeDelta duration = next_timestamp - cur_timestamp; 482 base::TimeDelta duration = next_timestamp - cur_timestamp;
483 frame->SetDuration(duration); 483 frame->set_duration(duration);
484 } 484 }
485 } 485 }
486 486
487 base::TimeDelta DecryptingAudioDecoder::NumberOfSamplesToDuration( 487 base::TimeDelta DecryptingAudioDecoder::NumberOfSamplesToDuration(
488 int number_of_samples) const { 488 int number_of_samples) const {
489 DCHECK(samples_per_second_); 489 DCHECK(samples_per_second_);
490 return base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond * 490 return base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond *
491 number_of_samples / 491 number_of_samples /
492 samples_per_second_); 492 samples_per_second_);
493 } 493 }
494 494
495 } // namespace media 495 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698