| 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 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 return 0; | 779 return 0; |
| 780 } | 780 } |
| 781 | 781 |
| 782 // Mute audio by returning 0 when not playing. | 782 // Mute audio by returning 0 when not playing. |
| 783 if (state_ != kPlaying) { | 783 if (state_ != kPlaying) { |
| 784 audio_clock_->WroteAudio(0, frames_requested, frames_delayed, | 784 audio_clock_->WroteAudio(0, frames_requested, frames_delayed, |
| 785 playback_rate_); | 785 playback_rate_); |
| 786 return 0; | 786 return 0; |
| 787 } | 787 } |
| 788 | 788 |
| 789 // Delay playback by writing silence if we haven't reached the first | |
| 790 // timestamp yet; this can occur if the video starts before the audio. | |
| 791 if (algorithm_->frames_buffered() > 0) { | 789 if (algorithm_->frames_buffered() > 0) { |
| 792 CHECK_NE(first_packet_timestamp_, kNoTimestamp); | |
| 793 CHECK_GE(first_packet_timestamp_, base::TimeDelta()); | 790 CHECK_GE(first_packet_timestamp_, base::TimeDelta()); |
| 791 |
| 792 // Delay playback by writing silence if we haven't reached the first |
| 793 // timestamp yet; this can occur if the video starts before the audio. |
| 794 const base::TimeDelta play_delay = | 794 const base::TimeDelta play_delay = |
| 795 first_packet_timestamp_ - audio_clock_->back_timestamp(); | 795 first_packet_timestamp_ - audio_clock_->back_timestamp(); |
| 796 if (play_delay > base::TimeDelta()) { | 796 if (play_delay > base::TimeDelta()) { |
| 797 DCHECK_EQ(frames_written, 0); | 797 DCHECK_EQ(frames_written, 0); |
| 798 | 798 |
| 799 // Don't multiply |play_delay| out since it can be a huge value on | 799 // Don't multiply |play_delay| out since it can be a huge value on |
| 800 // poorly encoded media and multiplying by the sample rate could cause | 800 // poorly encoded media and multiplying by the sample rate could cause |
| 801 // the value to overflow. | 801 // the value to overflow. |
| 802 if (play_delay.InSecondsF() > static_cast<double>(frames_requested) / | 802 if (play_delay.InSecondsF() > static_cast<double>(frames_requested) / |
| 803 audio_parameters_.sample_rate()) { | 803 audio_parameters_.sample_rate()) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 DCHECK_NE(buffering_state_, buffering_state); | 947 DCHECK_NE(buffering_state_, buffering_state); |
| 948 lock_.AssertAcquired(); | 948 lock_.AssertAcquired(); |
| 949 buffering_state_ = buffering_state; | 949 buffering_state_ = buffering_state; |
| 950 | 950 |
| 951 task_runner_->PostTask( | 951 task_runner_->PostTask( |
| 952 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, | 952 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, |
| 953 weak_factory_.GetWeakPtr(), buffering_state_)); | 953 weak_factory_.GetWeakPtr(), buffering_state_)); |
| 954 } | 954 } |
| 955 | 955 |
| 956 } // namespace media | 956 } // namespace media |
| OLD | NEW |