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

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

Issue 389613005: Update media::AudioClock API to take time since writing into account. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
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/audio_renderer_impl.h" 5 #include "media/filters/audio_renderer_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 // 3) We haven't already signalled that we've ended 581 // 3) We haven't already signalled that we've ended
582 // 4) We've played all known audio data sent to hardware 582 // 4) We've played all known audio data sent to hardware
583 // 583 //
584 // We use the following conditions to determine underflow: 584 // We use the following conditions to determine underflow:
585 // 1) Algorithm can not fill the audio callback buffer 585 // 1) Algorithm can not fill the audio callback buffer
586 // 2) We have NOT received an end of stream buffer 586 // 2) We have NOT received an end of stream buffer
587 // 3) We are in the kPlaying state 587 // 3) We are in the kPlaying state
588 // 588 //
589 // Otherwise the buffer has data we can send to the device. 589 // Otherwise the buffer has data we can send to the device.
590 const base::TimeDelta media_timestamp_before_filling = 590 const base::TimeDelta media_timestamp_before_filling =
591 audio_clock_->CurrentMediaTimestamp(); 591 audio_clock_->CurrentMediaTimestamp(base::TimeDelta());
592 if (algorithm_->frames_buffered() > 0) { 592 if (algorithm_->frames_buffered() > 0) {
593 frames_written = algorithm_->FillBuffer(audio_bus, requested_frames); 593 frames_written = algorithm_->FillBuffer(audio_bus, requested_frames);
594 audio_clock_->WroteAudio( 594 audio_clock_->WroteAudio(
595 frames_written, delay_frames, playback_rate, algorithm_->GetTime()); 595 frames_written, delay_frames, playback_rate, algorithm_->GetTime());
596 } 596 }
597 audio_clock_->WroteSilence(requested_frames - frames_written, delay_frames); 597 audio_clock_->WroteSilence(requested_frames - frames_written, delay_frames);
598 598
599 if (frames_written == 0) { 599 if (frames_written == 0) {
600 if (received_end_of_stream_ && !rendered_end_of_stream_ && 600 if (received_end_of_stream_ && !rendered_end_of_stream_ &&
601 audio_clock_->CurrentMediaTimestamp() == 601 audio_clock_->CurrentMediaTimestamp(base::TimeDelta()) ==
602 audio_clock_->last_endpoint_timestamp()) { 602 audio_clock_->last_endpoint_timestamp()) {
603 rendered_end_of_stream_ = true; 603 rendered_end_of_stream_ = true;
604 ended_cb_.Run(); 604 ended_cb_.Run();
605 } else if (!received_end_of_stream_ && state_ == kPlaying) { 605 } else if (!received_end_of_stream_ && state_ == kPlaying) {
606 if (buffering_state_ != BUFFERING_HAVE_NOTHING) { 606 if (buffering_state_ != BUFFERING_HAVE_NOTHING) {
607 algorithm_->IncreaseQueueCapacity(); 607 algorithm_->IncreaseQueueCapacity();
608 SetBufferingState_Locked(BUFFERING_HAVE_NOTHING); 608 SetBufferingState_Locked(BUFFERING_HAVE_NOTHING);
609 } 609 }
610 } 610 }
611 } 611 }
612 612
613 if (CanRead_Locked()) { 613 if (CanRead_Locked()) {
614 task_runner_->PostTask(FROM_HERE, 614 task_runner_->PostTask(FROM_HERE,
615 base::Bind(&AudioRendererImpl::AttemptRead, 615 base::Bind(&AudioRendererImpl::AttemptRead,
616 weak_factory_.GetWeakPtr())); 616 weak_factory_.GetWeakPtr()));
617 } 617 }
618 618
619 // We only want to execute |time_cb_| if time has progressed and we haven't 619 // We only want to execute |time_cb_| if time has progressed and we haven't
620 // signaled end of stream yet. 620 // signaled end of stream yet.
621 if (media_timestamp_before_filling != 621 if (media_timestamp_before_filling !=
622 audio_clock_->CurrentMediaTimestamp() && 622 audio_clock_->CurrentMediaTimestamp(base::TimeDelta()) &&
623 !rendered_end_of_stream_) { 623 !rendered_end_of_stream_) {
624 time_cb = base::Bind(time_cb_, 624 time_cb =
625 audio_clock_->CurrentMediaTimestamp(), 625 base::Bind(time_cb_,
626 audio_clock_->last_endpoint_timestamp()); 626 audio_clock_->CurrentMediaTimestamp(base::TimeDelta()),
627 audio_clock_->last_endpoint_timestamp());
627 } 628 }
628 } 629 }
629 630
630 if (!time_cb.is_null()) 631 if (!time_cb.is_null())
631 task_runner_->PostTask(FROM_HERE, time_cb); 632 task_runner_->PostTask(FROM_HERE, time_cb);
632 633
633 DCHECK_LE(frames_written, requested_frames); 634 DCHECK_LE(frames_written, requested_frames);
634 return frames_written; 635 return frames_written;
635 } 636 }
636 637
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 << buffering_state; 701 << buffering_state;
701 DCHECK_NE(buffering_state_, buffering_state); 702 DCHECK_NE(buffering_state_, buffering_state);
702 lock_.AssertAcquired(); 703 lock_.AssertAcquired();
703 buffering_state_ = buffering_state; 704 buffering_state_ = buffering_state;
704 705
705 task_runner_->PostTask(FROM_HERE, 706 task_runner_->PostTask(FROM_HERE,
706 base::Bind(buffering_state_cb_, buffering_state_)); 707 base::Bind(buffering_state_cb_, buffering_state_));
707 } 708 }
708 709
709 } // namespace media 710 } // namespace media
OLDNEW
« media/filters/audio_clock.h ('K') | « media/filters/audio_clock_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698