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