| 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 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 } | 762 } |
| 763 } | 763 } |
| 764 | 764 |
| 765 bool AudioRendererImpl::IsBeforeStartTime( | 765 bool AudioRendererImpl::IsBeforeStartTime( |
| 766 const scoped_refptr<AudioBuffer>& buffer) { | 766 const scoped_refptr<AudioBuffer>& buffer) { |
| 767 DCHECK_EQ(state_, kPlaying); | 767 DCHECK_EQ(state_, kPlaying); |
| 768 return buffer.get() && !buffer->end_of_stream() && | 768 return buffer.get() && !buffer->end_of_stream() && |
| 769 (buffer->timestamp() + buffer->duration()) < start_timestamp_; | 769 (buffer->timestamp() + buffer->duration()) < start_timestamp_; |
| 770 } | 770 } |
| 771 | 771 |
| 772 int AudioRendererImpl::Render(base::TimeDelta delay, | 772 int AudioRendererImpl::Render(AudioBus* audio_bus, |
| 773 base::TimeTicks delay_timestamp, | 773 uint32_t frames_delayed, |
| 774 int prior_frames_skipped, | 774 uint32_t frames_skipped) { |
| 775 AudioBus* audio_bus) { | |
| 776 const int frames_requested = audio_bus->frames(); | 775 const int frames_requested = audio_bus->frames(); |
| 777 DVLOG(4) << __func__ << " delay:" << delay | 776 DVLOG(4) << __func__ << " frames_delayed:" << frames_delayed |
| 778 << " prior_frames_skipped:" << prior_frames_skipped | 777 << " frames_skipped:" << frames_skipped |
| 779 << " frames_requested:" << frames_requested; | 778 << " frames_requested:" << frames_requested; |
| 780 | 779 |
| 781 int frames_written = 0; | 780 int frames_written = 0; |
| 782 { | 781 { |
| 783 base::AutoLock auto_lock(lock_); | 782 base::AutoLock auto_lock(lock_); |
| 784 last_render_time_ = tick_clock_->NowTicks(); | 783 last_render_time_ = tick_clock_->NowTicks(); |
| 785 | 784 |
| 786 int64_t frames_delayed = AudioTimestampHelper::TimeToFrames( | |
| 787 delay, audio_parameters_.sample_rate()); | |
| 788 | |
| 789 if (!stop_rendering_time_.is_null()) { | 785 if (!stop_rendering_time_.is_null()) { |
| 790 audio_clock_->CompensateForSuspendedWrites( | 786 audio_clock_->CompensateForSuspendedWrites( |
| 791 last_render_time_ - stop_rendering_time_, frames_delayed); | 787 last_render_time_ - stop_rendering_time_, frames_delayed); |
| 792 stop_rendering_time_ = base::TimeTicks(); | 788 stop_rendering_time_ = base::TimeTicks(); |
| 793 } | 789 } |
| 794 | 790 |
| 795 // Ensure Stop() hasn't destroyed our |algorithm_| on the pipeline thread. | 791 // Ensure Stop() hasn't destroyed our |algorithm_| on the pipeline thread. |
| 796 if (!algorithm_) { | 792 if (!algorithm_) { |
| 797 audio_clock_->WroteAudio(0, frames_requested, frames_delayed, | 793 audio_clock_->WroteAudio(0, frames_requested, frames_delayed, |
| 798 playback_rate_); | 794 playback_rate_); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 DCHECK_NE(buffering_state_, buffering_state); | 973 DCHECK_NE(buffering_state_, buffering_state); |
| 978 lock_.AssertAcquired(); | 974 lock_.AssertAcquired(); |
| 979 buffering_state_ = buffering_state; | 975 buffering_state_ = buffering_state; |
| 980 | 976 |
| 981 task_runner_->PostTask( | 977 task_runner_->PostTask( |
| 982 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, | 978 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, |
| 983 weak_factory_.GetWeakPtr(), buffering_state_)); | 979 weak_factory_.GetWeakPtr(), buffering_state_)); |
| 984 } | 980 } |
| 985 | 981 |
| 986 } // namespace media | 982 } // namespace media |
| OLD | NEW |