Chromium Code Reviews| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 last_decoded_sample_rate_(0), | 50 last_decoded_sample_rate_(0), |
| 51 playback_rate_(0.0), | 51 playback_rate_(0.0), |
| 52 state_(kUninitialized), | 52 state_(kUninitialized), |
| 53 buffering_state_(BUFFERING_HAVE_NOTHING), | 53 buffering_state_(BUFFERING_HAVE_NOTHING), |
| 54 rendering_(false), | 54 rendering_(false), |
| 55 sink_playing_(false), | 55 sink_playing_(false), |
| 56 pending_read_(false), | 56 pending_read_(false), |
| 57 received_end_of_stream_(false), | 57 received_end_of_stream_(false), |
| 58 rendered_end_of_stream_(false), | 58 rendered_end_of_stream_(false), |
| 59 is_suspending_(false), | 59 is_suspending_(false), |
| 60 last_media_time_(kNoTimestamp), | |
| 60 weak_factory_(this) { | 61 weak_factory_(this) { |
| 61 audio_buffer_stream_->set_splice_observer(base::Bind( | 62 audio_buffer_stream_->set_splice_observer(base::Bind( |
| 62 &AudioRendererImpl::OnNewSpliceBuffer, weak_factory_.GetWeakPtr())); | 63 &AudioRendererImpl::OnNewSpliceBuffer, weak_factory_.GetWeakPtr())); |
| 63 audio_buffer_stream_->set_config_change_observer(base::Bind( | 64 audio_buffer_stream_->set_config_change_observer(base::Bind( |
| 64 &AudioRendererImpl::OnConfigChange, weak_factory_.GetWeakPtr())); | 65 &AudioRendererImpl::OnConfigChange, weak_factory_.GetWeakPtr())); |
| 65 | 66 |
| 66 // Tests may not have a power monitor. | 67 // Tests may not have a power monitor. |
| 67 base::PowerMonitor* monitor = base::PowerMonitor::Get(); | 68 base::PowerMonitor* monitor = base::PowerMonitor::Get(); |
| 68 if (!monitor) | 69 if (!monitor) |
| 69 return; | 70 return; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 | 165 |
| 165 base::AutoLock auto_lock(lock_); | 166 base::AutoLock auto_lock(lock_); |
| 166 DCHECK(!rendering_); | 167 DCHECK(!rendering_); |
| 167 DCHECK_EQ(state_, kFlushed); | 168 DCHECK_EQ(state_, kFlushed); |
| 168 | 169 |
| 169 start_timestamp_ = time; | 170 start_timestamp_ = time; |
| 170 ended_timestamp_ = kInfiniteDuration; | 171 ended_timestamp_ = kInfiniteDuration; |
| 171 last_render_time_ = stop_rendering_time_ = base::TimeTicks(); | 172 last_render_time_ = stop_rendering_time_ = base::TimeTicks(); |
| 172 first_packet_timestamp_ = kNoTimestamp; | 173 first_packet_timestamp_ = kNoTimestamp; |
| 173 audio_clock_.reset(new AudioClock(time, audio_parameters_.sample_rate())); | 174 audio_clock_.reset(new AudioClock(time, audio_parameters_.sample_rate())); |
| 175 last_media_time_ = kNoTimestamp; | |
| 174 } | 176 } |
| 175 | 177 |
| 176 base::TimeDelta AudioRendererImpl::CurrentMediaTime() { | 178 base::TimeDelta AudioRendererImpl::CurrentMediaTime() { |
| 177 base::AutoLock auto_lock(lock_); | 179 base::AutoLock auto_lock(lock_); |
| 178 | 180 |
| 181 // Re-use last reported time if rendering has stopped to avoid confusing blink | |
| 182 // layer (avoid currentTime advancing while after signaling buffer underflow). | |
|
sandersd (OOO until July 31)
2016/10/17 23:37:37
Remove 'while'.
chcunningham
2016/10/17 23:49:17
Done.
| |
| 183 // TODO(chcunningham): Do this in blink instead. Patching it here for now | |
| 184 // because HTMLMediaElement's currentTime is a mess. | |
| 185 if (!rendering_ && last_media_time_ != kNoTimestamp) { | |
| 186 // If rendering stops, be sure to at least report the front time of the most | |
| 187 // recently rendered audio buffer. | |
| 188 if (last_media_time_ < audio_clock_->front_timestamp()) | |
| 189 last_media_time_ = audio_clock_->front_timestamp(); | |
| 190 | |
| 191 DVLOG(3) << __func__ << " Returning cached time while rendering stopped:" | |
| 192 << last_media_time_.InMicroseconds(); | |
| 193 return last_media_time_; | |
| 194 } | |
| 195 | |
| 179 // Return the current time based on the known extents of the rendered audio | 196 // Return the current time based on the known extents of the rendered audio |
| 180 // data plus an estimate based on the last time those values were calculated. | 197 // data plus an estimate based on the last time those values were calculated. |
| 181 base::TimeDelta current_media_time = audio_clock_->front_timestamp(); | 198 base::TimeDelta current_media_time = audio_clock_->front_timestamp(); |
| 182 if (!last_render_time_.is_null()) { | 199 if (!last_render_time_.is_null()) { |
| 183 current_media_time += | 200 current_media_time += |
| 184 (tick_clock_->NowTicks() - last_render_time_) * playback_rate_; | 201 (tick_clock_->NowTicks() - last_render_time_) * playback_rate_; |
| 185 if (current_media_time > audio_clock_->back_timestamp()) | 202 if (current_media_time > audio_clock_->back_timestamp()) |
| 186 current_media_time = audio_clock_->back_timestamp(); | 203 current_media_time = audio_clock_->back_timestamp(); |
| 187 } | 204 } |
| 188 | 205 |
| 206 last_media_time_ = current_media_time; | |
| 189 return current_media_time; | 207 return current_media_time; |
| 190 } | 208 } |
| 191 | 209 |
| 192 bool AudioRendererImpl::GetWallClockTimes( | 210 bool AudioRendererImpl::GetWallClockTimes( |
| 193 const std::vector<base::TimeDelta>& media_timestamps, | 211 const std::vector<base::TimeDelta>& media_timestamps, |
| 194 std::vector<base::TimeTicks>* wall_clock_times) { | 212 std::vector<base::TimeTicks>* wall_clock_times) { |
| 195 base::AutoLock auto_lock(lock_); | 213 base::AutoLock auto_lock(lock_); |
| 196 DCHECK(wall_clock_times->empty()); | 214 DCHECK(wall_clock_times->empty()); |
| 197 | 215 |
| 198 // When playback is paused (rate is zero), assume a rate of 1.0. | 216 // When playback is paused (rate is zero), assume a rate of 1.0. |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 : stream->audio_decoder_config().channel_layout(); | 441 : stream->audio_decoder_config().channel_layout(); |
| 424 | 442 |
| 425 audio_parameters_.Reset(hw_params.format(), renderer_channel_layout, | 443 audio_parameters_.Reset(hw_params.format(), renderer_channel_layout, |
| 426 sample_rate, hw_params.bits_per_sample(), | 444 sample_rate, hw_params.bits_per_sample(), |
| 427 media::AudioLatency::GetHighLatencyBufferSize( | 445 media::AudioLatency::GetHighLatencyBufferSize( |
| 428 sample_rate, preferred_buffer_size)); | 446 sample_rate, preferred_buffer_size)); |
| 429 } | 447 } |
| 430 | 448 |
| 431 audio_clock_.reset( | 449 audio_clock_.reset( |
| 432 new AudioClock(base::TimeDelta(), audio_parameters_.sample_rate())); | 450 new AudioClock(base::TimeDelta(), audio_parameters_.sample_rate())); |
| 451 last_media_time_ = kNoTimestamp; | |
| 433 | 452 |
| 434 audio_buffer_stream_->Initialize( | 453 audio_buffer_stream_->Initialize( |
| 435 stream, base::Bind(&AudioRendererImpl::OnAudioBufferStreamInitialized, | 454 stream, base::Bind(&AudioRendererImpl::OnAudioBufferStreamInitialized, |
| 436 weak_factory_.GetWeakPtr()), | 455 weak_factory_.GetWeakPtr()), |
| 437 cdm_context, base::Bind(&AudioRendererImpl::OnStatisticsUpdate, | 456 cdm_context, base::Bind(&AudioRendererImpl::OnStatisticsUpdate, |
| 438 weak_factory_.GetWeakPtr()), | 457 weak_factory_.GetWeakPtr()), |
| 439 base::Bind(&AudioRendererImpl::OnWaitingForDecryptionKey, | 458 base::Bind(&AudioRendererImpl::OnWaitingForDecryptionKey, |
| 440 weak_factory_.GetWeakPtr())); | 459 weak_factory_.GetWeakPtr())); |
| 441 } | 460 } |
| 442 | 461 |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 954 DCHECK_NE(buffering_state_, buffering_state); | 973 DCHECK_NE(buffering_state_, buffering_state); |
| 955 lock_.AssertAcquired(); | 974 lock_.AssertAcquired(); |
| 956 buffering_state_ = buffering_state; | 975 buffering_state_ = buffering_state; |
| 957 | 976 |
| 958 task_runner_->PostTask( | 977 task_runner_->PostTask( |
| 959 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, | 978 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, |
| 960 weak_factory_.GetWeakPtr(), buffering_state_)); | 979 weak_factory_.GetWeakPtr(), buffering_state_)); |
| 961 } | 980 } |
| 962 | 981 |
| 963 } // namespace media | 982 } // namespace media |
| OLD | NEW |