OLD | NEW |
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/renderers/audio_renderer_impl.h" | 5 #include "media/renderers/audio_renderer_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 } | 731 } |
732 } | 732 } |
733 | 733 |
734 bool AudioRendererImpl::IsBeforeStartTime( | 734 bool AudioRendererImpl::IsBeforeStartTime( |
735 const scoped_refptr<AudioBuffer>& buffer) { | 735 const scoped_refptr<AudioBuffer>& buffer) { |
736 DCHECK_EQ(state_, kPlaying); | 736 DCHECK_EQ(state_, kPlaying); |
737 return buffer.get() && !buffer->end_of_stream() && | 737 return buffer.get() && !buffer->end_of_stream() && |
738 (buffer->timestamp() + buffer->duration()) < start_timestamp_; | 738 (buffer->timestamp() + buffer->duration()) < start_timestamp_; |
739 } | 739 } |
740 | 740 |
741 int AudioRendererImpl::Render(AudioBus* audio_bus, | 741 int AudioRendererImpl::Render(base::TimeDelta delay, |
742 uint32_t frames_delayed, | 742 base::TimeTicks delay_timestamp, |
743 uint32_t frames_skipped) { | 743 int prior_frames_skipped, |
| 744 AudioBus* audio_bus) { |
744 const int frames_requested = audio_bus->frames(); | 745 const int frames_requested = audio_bus->frames(); |
745 DVLOG(4) << __func__ << " frames_delayed:" << frames_delayed | 746 DVLOG(4) << __func__ << " delay:" << delay |
746 << " frames_skipped:" << frames_skipped | 747 << " prior_frames_skipped:" << prior_frames_skipped |
747 << " frames_requested:" << frames_requested; | 748 << " frames_requested:" << frames_requested; |
748 | 749 |
749 int frames_written = 0; | 750 int frames_written = 0; |
750 { | 751 { |
751 base::AutoLock auto_lock(lock_); | 752 base::AutoLock auto_lock(lock_); |
752 last_render_time_ = tick_clock_->NowTicks(); | 753 last_render_time_ = tick_clock_->NowTicks(); |
753 | 754 |
| 755 int64_t frames_delayed = AudioTimestampHelper::TimeToFrames( |
| 756 delay, audio_parameters_.sample_rate()); |
| 757 |
754 if (!stop_rendering_time_.is_null()) { | 758 if (!stop_rendering_time_.is_null()) { |
755 audio_clock_->CompensateForSuspendedWrites( | 759 audio_clock_->CompensateForSuspendedWrites( |
756 last_render_time_ - stop_rendering_time_, frames_delayed); | 760 last_render_time_ - stop_rendering_time_, frames_delayed); |
757 stop_rendering_time_ = base::TimeTicks(); | 761 stop_rendering_time_ = base::TimeTicks(); |
758 } | 762 } |
759 | 763 |
760 // Ensure Stop() hasn't destroyed our |algorithm_| on the pipeline thread. | 764 // Ensure Stop() hasn't destroyed our |algorithm_| on the pipeline thread. |
761 if (!algorithm_) { | 765 if (!algorithm_) { |
762 audio_clock_->WroteAudio(0, frames_requested, frames_delayed, | 766 audio_clock_->WroteAudio(0, frames_requested, frames_delayed, |
763 playback_rate_); | 767 playback_rate_); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 DCHECK_NE(buffering_state_, buffering_state); | 936 DCHECK_NE(buffering_state_, buffering_state); |
933 lock_.AssertAcquired(); | 937 lock_.AssertAcquired(); |
934 buffering_state_ = buffering_state; | 938 buffering_state_ = buffering_state; |
935 | 939 |
936 task_runner_->PostTask( | 940 task_runner_->PostTask( |
937 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, | 941 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, |
938 weak_factory_.GetWeakPtr(), buffering_state_)); | 942 weak_factory_.GetWeakPtr(), buffering_state_)); |
939 } | 943 } |
940 | 944 |
941 } // namespace media | 945 } // namespace media |
OLD | NEW |