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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 task_runner_->PostTask(FROM_HERE, | 84 task_runner_->PostTask(FROM_HERE, |
85 base::Bind(&base::PowerMonitor::AddObserver, | 85 base::Bind(&base::PowerMonitor::AddObserver, |
86 base::Unretained(monitor), this)); | 86 base::Unretained(monitor), this)); |
87 } | 87 } |
88 #endif | 88 #endif |
89 // Do not add anything below this line since the above actions are only safe | 89 // Do not add anything below this line since the above actions are only safe |
90 // as the last lines of the constructor. | 90 // as the last lines of the constructor. |
91 } | 91 } |
92 | 92 |
93 AudioRendererImpl::~AudioRendererImpl() { | 93 AudioRendererImpl::~AudioRendererImpl() { |
94 DVLOG(1) << __FUNCTION__; | 94 DVLOG(1) << __func__; |
95 DCHECK(task_runner_->BelongsToCurrentThread()); | 95 DCHECK(task_runner_->BelongsToCurrentThread()); |
96 #if !defined(OS_ANDROID) | 96 #if !defined(OS_ANDROID) |
97 if (base::PowerMonitor::Get()) | 97 if (base::PowerMonitor::Get()) |
98 base::PowerMonitor::Get()->RemoveObserver(this); | 98 base::PowerMonitor::Get()->RemoveObserver(this); |
99 #endif | 99 #endif |
100 | 100 |
101 // If Render() is in progress, this call will wait for Render() to finish. | 101 // If Render() is in progress, this call will wait for Render() to finish. |
102 // After this call, the |sink_| will not call back into |this| anymore. | 102 // After this call, the |sink_| will not call back into |this| anymore. |
103 sink_->Stop(); | 103 sink_->Stop(); |
104 | 104 |
105 if (!init_cb_.is_null()) | 105 if (!init_cb_.is_null()) |
106 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); | 106 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); |
107 } | 107 } |
108 | 108 |
109 void AudioRendererImpl::StartTicking() { | 109 void AudioRendererImpl::StartTicking() { |
110 DVLOG(1) << __FUNCTION__; | 110 DVLOG(1) << __func__; |
111 DCHECK(task_runner_->BelongsToCurrentThread()); | 111 DCHECK(task_runner_->BelongsToCurrentThread()); |
112 DCHECK(!rendering_); | 112 DCHECK(!rendering_); |
113 rendering_ = true; | 113 rendering_ = true; |
114 | 114 |
115 base::AutoLock auto_lock(lock_); | 115 base::AutoLock auto_lock(lock_); |
116 // Wait for an eventual call to SetPlaybackRate() to start rendering. | 116 // Wait for an eventual call to SetPlaybackRate() to start rendering. |
117 if (playback_rate_ == 0) { | 117 if (playback_rate_ == 0) { |
118 DCHECK(!sink_playing_); | 118 DCHECK(!sink_playing_); |
119 return; | 119 return; |
120 } | 120 } |
121 | 121 |
122 StartRendering_Locked(); | 122 StartRendering_Locked(); |
123 } | 123 } |
124 | 124 |
125 void AudioRendererImpl::StartRendering_Locked() { | 125 void AudioRendererImpl::StartRendering_Locked() { |
126 DVLOG(1) << __FUNCTION__; | 126 DVLOG(1) << __func__; |
127 DCHECK(task_runner_->BelongsToCurrentThread()); | 127 DCHECK(task_runner_->BelongsToCurrentThread()); |
128 DCHECK_EQ(state_, kPlaying); | 128 DCHECK_EQ(state_, kPlaying); |
129 DCHECK(!sink_playing_); | 129 DCHECK(!sink_playing_); |
130 DCHECK_NE(playback_rate_, 0.0); | 130 DCHECK_NE(playback_rate_, 0.0); |
131 lock_.AssertAcquired(); | 131 lock_.AssertAcquired(); |
132 | 132 |
133 sink_playing_ = true; | 133 sink_playing_ = true; |
134 | 134 |
135 base::AutoUnlock auto_unlock(lock_); | 135 base::AutoUnlock auto_unlock(lock_); |
136 sink_->Play(); | 136 sink_->Play(); |
137 } | 137 } |
138 | 138 |
139 void AudioRendererImpl::StopTicking() { | 139 void AudioRendererImpl::StopTicking() { |
140 DVLOG(1) << __FUNCTION__; | 140 DVLOG(1) << __func__; |
141 DCHECK(task_runner_->BelongsToCurrentThread()); | 141 DCHECK(task_runner_->BelongsToCurrentThread()); |
142 DCHECK(rendering_); | 142 DCHECK(rendering_); |
143 rendering_ = false; | 143 rendering_ = false; |
144 | 144 |
145 base::AutoLock auto_lock(lock_); | 145 base::AutoLock auto_lock(lock_); |
146 // Rendering should have already been stopped with a zero playback rate. | 146 // Rendering should have already been stopped with a zero playback rate. |
147 if (playback_rate_ == 0) { | 147 if (playback_rate_ == 0) { |
148 DCHECK(!sink_playing_); | 148 DCHECK(!sink_playing_); |
149 return; | 149 return; |
150 } | 150 } |
151 | 151 |
152 StopRendering_Locked(); | 152 StopRendering_Locked(); |
153 } | 153 } |
154 | 154 |
155 void AudioRendererImpl::StopRendering_Locked() { | 155 void AudioRendererImpl::StopRendering_Locked() { |
156 DCHECK(task_runner_->BelongsToCurrentThread()); | 156 DCHECK(task_runner_->BelongsToCurrentThread()); |
157 DCHECK_EQ(state_, kPlaying); | 157 DCHECK_EQ(state_, kPlaying); |
158 DCHECK(sink_playing_); | 158 DCHECK(sink_playing_); |
159 lock_.AssertAcquired(); | 159 lock_.AssertAcquired(); |
160 | 160 |
161 sink_playing_ = false; | 161 sink_playing_ = false; |
162 | 162 |
163 base::AutoUnlock auto_unlock(lock_); | 163 base::AutoUnlock auto_unlock(lock_); |
164 sink_->Pause(); | 164 sink_->Pause(); |
165 stop_rendering_time_ = last_render_time_; | 165 stop_rendering_time_ = last_render_time_; |
166 } | 166 } |
167 | 167 |
168 void AudioRendererImpl::SetMediaTime(base::TimeDelta time) { | 168 void AudioRendererImpl::SetMediaTime(base::TimeDelta time) { |
169 DVLOG(1) << __FUNCTION__ << "(" << time << ")"; | 169 DVLOG(1) << __func__ << "(" << time << ")"; |
170 DCHECK(task_runner_->BelongsToCurrentThread()); | 170 DCHECK(task_runner_->BelongsToCurrentThread()); |
171 | 171 |
172 base::AutoLock auto_lock(lock_); | 172 base::AutoLock auto_lock(lock_); |
173 DCHECK(!rendering_); | 173 DCHECK(!rendering_); |
174 DCHECK_EQ(state_, kFlushed); | 174 DCHECK_EQ(state_, kFlushed); |
175 | 175 |
176 start_timestamp_ = time; | 176 start_timestamp_ = time; |
177 ended_timestamp_ = kInfiniteDuration; | 177 ended_timestamp_ = kInfiniteDuration; |
178 last_render_time_ = stop_rendering_time_ = base::TimeTicks(); | 178 last_render_time_ = stop_rendering_time_ = base::TimeTicks(); |
179 first_packet_timestamp_ = kNoTimestamp; | 179 first_packet_timestamp_ = kNoTimestamp; |
(...skipping 14 matching lines...) Expand all Loading... |
194 current_media_time = audio_clock_->back_timestamp(); | 194 current_media_time = audio_clock_->back_timestamp(); |
195 } | 195 } |
196 | 196 |
197 // Clamp current media time to the last reported value, this prevents higher | 197 // Clamp current media time to the last reported value, this prevents higher |
198 // level clients from seeing time go backwards based on inaccurate or spurious | 198 // level clients from seeing time go backwards based on inaccurate or spurious |
199 // delay values reported to the AudioClock. | 199 // delay values reported to the AudioClock. |
200 // | 200 // |
201 // It is expected that such events are transient and will be recovered as | 201 // It is expected that such events are transient and will be recovered as |
202 // rendering continues over time. | 202 // rendering continues over time. |
203 if (current_media_time < last_media_timestamp_) { | 203 if (current_media_time < last_media_timestamp_) { |
204 DVLOG(2) << __FUNCTION__ << ": " << last_media_timestamp_ | 204 DVLOG(2) << __func__ << ": " << last_media_timestamp_ |
205 << " (clamped), actual: " << current_media_time; | 205 << " (clamped), actual: " << current_media_time; |
206 return last_media_timestamp_; | 206 return last_media_timestamp_; |
207 } | 207 } |
208 | 208 |
209 DVLOG(2) << __FUNCTION__ << ": " << current_media_time; | 209 DVLOG(2) << __func__ << ": " << current_media_time; |
210 last_media_timestamp_ = current_media_time; | 210 last_media_timestamp_ = current_media_time; |
211 return current_media_time; | 211 return current_media_time; |
212 } | 212 } |
213 | 213 |
214 bool AudioRendererImpl::GetWallClockTimes( | 214 bool AudioRendererImpl::GetWallClockTimes( |
215 const std::vector<base::TimeDelta>& media_timestamps, | 215 const std::vector<base::TimeDelta>& media_timestamps, |
216 std::vector<base::TimeTicks>* wall_clock_times) { | 216 std::vector<base::TimeTicks>* wall_clock_times) { |
217 base::AutoLock auto_lock(lock_); | 217 base::AutoLock auto_lock(lock_); |
218 DCHECK(wall_clock_times->empty()); | 218 DCHECK(wall_clock_times->empty()); |
219 | 219 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 } | 268 } |
269 | 269 |
270 return is_time_moving; | 270 return is_time_moving; |
271 } | 271 } |
272 | 272 |
273 TimeSource* AudioRendererImpl::GetTimeSource() { | 273 TimeSource* AudioRendererImpl::GetTimeSource() { |
274 return this; | 274 return this; |
275 } | 275 } |
276 | 276 |
277 void AudioRendererImpl::Flush(const base::Closure& callback) { | 277 void AudioRendererImpl::Flush(const base::Closure& callback) { |
278 DVLOG(1) << __FUNCTION__; | 278 DVLOG(1) << __func__; |
279 DCHECK(task_runner_->BelongsToCurrentThread()); | 279 DCHECK(task_runner_->BelongsToCurrentThread()); |
280 | 280 |
281 base::AutoLock auto_lock(lock_); | 281 base::AutoLock auto_lock(lock_); |
282 DCHECK_EQ(state_, kPlaying); | 282 DCHECK_EQ(state_, kPlaying); |
283 DCHECK(flush_cb_.is_null()); | 283 DCHECK(flush_cb_.is_null()); |
284 | 284 |
285 flush_cb_ = callback; | 285 flush_cb_ = callback; |
286 ChangeState_Locked(kFlushing); | 286 ChangeState_Locked(kFlushing); |
287 | 287 |
288 if (pending_read_) | 288 if (pending_read_) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 buffer_converter_->Reset(); | 324 buffer_converter_->Reset(); |
325 algorithm_->FlushBuffers(); | 325 algorithm_->FlushBuffers(); |
326 } | 326 } |
327 | 327 |
328 // Changes in buffering state are always posted. Flush callback must only be | 328 // Changes in buffering state are always posted. Flush callback must only be |
329 // run after buffering state has been set back to nothing. | 329 // run after buffering state has been set back to nothing. |
330 task_runner_->PostTask(FROM_HERE, base::ResetAndReturn(&flush_cb_)); | 330 task_runner_->PostTask(FROM_HERE, base::ResetAndReturn(&flush_cb_)); |
331 } | 331 } |
332 | 332 |
333 void AudioRendererImpl::StartPlaying() { | 333 void AudioRendererImpl::StartPlaying() { |
334 DVLOG(1) << __FUNCTION__; | 334 DVLOG(1) << __func__; |
335 DCHECK(task_runner_->BelongsToCurrentThread()); | 335 DCHECK(task_runner_->BelongsToCurrentThread()); |
336 | 336 |
337 base::AutoLock auto_lock(lock_); | 337 base::AutoLock auto_lock(lock_); |
338 DCHECK(!sink_playing_); | 338 DCHECK(!sink_playing_); |
339 DCHECK_EQ(state_, kFlushed); | 339 DCHECK_EQ(state_, kFlushed); |
340 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); | 340 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); |
341 DCHECK(!pending_read_) << "Pending read must complete before seeking"; | 341 DCHECK(!pending_read_) << "Pending read must complete before seeking"; |
342 | 342 |
343 ChangeState_Locked(kPlaying); | 343 ChangeState_Locked(kPlaying); |
344 AttemptRead_Locked(); | 344 AttemptRead_Locked(); |
345 } | 345 } |
346 | 346 |
347 void AudioRendererImpl::Initialize(DemuxerStream* stream, | 347 void AudioRendererImpl::Initialize(DemuxerStream* stream, |
348 CdmContext* cdm_context, | 348 CdmContext* cdm_context, |
349 RendererClient* client, | 349 RendererClient* client, |
350 const PipelineStatusCB& init_cb) { | 350 const PipelineStatusCB& init_cb) { |
351 DVLOG(1) << __FUNCTION__; | 351 DVLOG(1) << __func__; |
352 DCHECK(task_runner_->BelongsToCurrentThread()); | 352 DCHECK(task_runner_->BelongsToCurrentThread()); |
353 DCHECK(client); | 353 DCHECK(client); |
354 DCHECK(stream); | 354 DCHECK(stream); |
355 DCHECK_EQ(stream->type(), DemuxerStream::AUDIO); | 355 DCHECK_EQ(stream->type(), DemuxerStream::AUDIO); |
356 DCHECK(!init_cb.is_null()); | 356 DCHECK(!init_cb.is_null()); |
357 DCHECK_EQ(kUninitialized, state_); | 357 DCHECK_EQ(kUninitialized, state_); |
358 DCHECK(sink_.get()); | 358 DCHECK(sink_.get()); |
359 | 359 |
360 state_ = kInitializing; | 360 state_ = kInitializing; |
361 client_ = client; | 361 client_ = client; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 audio_buffer_stream_->Initialize( | 453 audio_buffer_stream_->Initialize( |
454 stream, base::Bind(&AudioRendererImpl::OnAudioBufferStreamInitialized, | 454 stream, base::Bind(&AudioRendererImpl::OnAudioBufferStreamInitialized, |
455 weak_factory_.GetWeakPtr()), | 455 weak_factory_.GetWeakPtr()), |
456 cdm_context, base::Bind(&AudioRendererImpl::OnStatisticsUpdate, | 456 cdm_context, base::Bind(&AudioRendererImpl::OnStatisticsUpdate, |
457 weak_factory_.GetWeakPtr()), | 457 weak_factory_.GetWeakPtr()), |
458 base::Bind(&AudioRendererImpl::OnWaitingForDecryptionKey, | 458 base::Bind(&AudioRendererImpl::OnWaitingForDecryptionKey, |
459 weak_factory_.GetWeakPtr())); | 459 weak_factory_.GetWeakPtr())); |
460 } | 460 } |
461 | 461 |
462 void AudioRendererImpl::OnAudioBufferStreamInitialized(bool success) { | 462 void AudioRendererImpl::OnAudioBufferStreamInitialized(bool success) { |
463 DVLOG(1) << __FUNCTION__ << ": " << success; | 463 DVLOG(1) << __func__ << ": " << success; |
464 DCHECK(task_runner_->BelongsToCurrentThread()); | 464 DCHECK(task_runner_->BelongsToCurrentThread()); |
465 | 465 |
466 base::AutoLock auto_lock(lock_); | 466 base::AutoLock auto_lock(lock_); |
467 | 467 |
468 if (!success) { | 468 if (!success) { |
469 state_ = kUninitialized; | 469 state_ = kUninitialized; |
470 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); | 470 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); |
471 return; | 471 return; |
472 } | 472 } |
473 | 473 |
474 if (!audio_parameters_.IsValid()) { | 474 if (!audio_parameters_.IsValid()) { |
475 DVLOG(1) << __FUNCTION__ << ": Invalid audio parameters: " | 475 DVLOG(1) << __func__ << ": Invalid audio parameters: " |
476 << audio_parameters_.AsHumanReadableString(); | 476 << audio_parameters_.AsHumanReadableString(); |
477 ChangeState_Locked(kUninitialized); | 477 ChangeState_Locked(kUninitialized); |
478 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED); | 478 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED); |
479 return; | 479 return; |
480 } | 480 } |
481 | 481 |
482 if (expecting_config_changes_) | 482 if (expecting_config_changes_) |
483 buffer_converter_.reset(new AudioBufferConverter(audio_parameters_)); | 483 buffer_converter_.reset(new AudioBufferConverter(audio_parameters_)); |
484 splicer_.reset(new AudioSplicer(audio_parameters_.sample_rate(), media_log_)); | 484 splicer_.reset(new AudioSplicer(audio_parameters_.sample_rate(), media_log_)); |
485 | 485 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 } | 540 } |
541 | 541 |
542 void AudioRendererImpl::OnResume() { | 542 void AudioRendererImpl::OnResume() { |
543 base::AutoLock auto_lock(lock_); | 543 base::AutoLock auto_lock(lock_); |
544 is_suspending_ = false; | 544 is_suspending_ = false; |
545 } | 545 } |
546 | 546 |
547 void AudioRendererImpl::DecodedAudioReady( | 547 void AudioRendererImpl::DecodedAudioReady( |
548 AudioBufferStream::Status status, | 548 AudioBufferStream::Status status, |
549 const scoped_refptr<AudioBuffer>& buffer) { | 549 const scoped_refptr<AudioBuffer>& buffer) { |
550 DVLOG(2) << __FUNCTION__ << "(" << status << ")"; | 550 DVLOG(2) << __func__ << "(" << status << ")"; |
551 DCHECK(task_runner_->BelongsToCurrentThread()); | 551 DCHECK(task_runner_->BelongsToCurrentThread()); |
552 | 552 |
553 base::AutoLock auto_lock(lock_); | 553 base::AutoLock auto_lock(lock_); |
554 DCHECK(state_ != kUninitialized); | 554 DCHECK(state_ != kUninitialized); |
555 | 555 |
556 CHECK(pending_read_); | 556 CHECK(pending_read_); |
557 pending_read_ = false; | 557 pending_read_ = false; |
558 | 558 |
559 if (status == AudioBufferStream::ABORTED || | 559 if (status == AudioBufferStream::ABORTED || |
560 status == AudioBufferStream::DEMUXER_READ_ABORTED) { | 560 status == AudioBufferStream::DEMUXER_READ_ABORTED) { |
(...skipping 11 matching lines...) Expand all Loading... |
572 | 572 |
573 if (state_ == kFlushing) { | 573 if (state_ == kFlushing) { |
574 ChangeState_Locked(kFlushed); | 574 ChangeState_Locked(kFlushed); |
575 DoFlush_Locked(); | 575 DoFlush_Locked(); |
576 return; | 576 return; |
577 } | 577 } |
578 | 578 |
579 if (expecting_config_changes_) { | 579 if (expecting_config_changes_) { |
580 if (last_decoded_sample_rate_ && | 580 if (last_decoded_sample_rate_ && |
581 buffer->sample_rate() != last_decoded_sample_rate_) { | 581 buffer->sample_rate() != last_decoded_sample_rate_) { |
582 DVLOG(1) << __FUNCTION__ << " Updating audio sample_rate." | 582 DVLOG(1) << __func__ << " Updating audio sample_rate." |
583 << " ts:" << buffer->timestamp().InMicroseconds() | 583 << " ts:" << buffer->timestamp().InMicroseconds() |
584 << " old:" << last_decoded_sample_rate_ | 584 << " old:" << last_decoded_sample_rate_ |
585 << " new:" << buffer->sample_rate(); | 585 << " new:" << buffer->sample_rate(); |
586 OnConfigChange(); | 586 OnConfigChange(); |
587 } | 587 } |
588 last_decoded_sample_rate_ = buffer->sample_rate(); | 588 last_decoded_sample_rate_ = buffer->sample_rate(); |
589 | 589 |
590 DCHECK(buffer_converter_); | 590 DCHECK(buffer_converter_); |
591 buffer_converter_->AddInput(buffer); | 591 buffer_converter_->AddInput(buffer); |
592 while (buffer_converter_->HasNextBuffer()) { | 592 while (buffer_converter_->HasNextBuffer()) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 | 727 |
728 case kPlaying: | 728 case kPlaying: |
729 break; | 729 break; |
730 } | 730 } |
731 | 731 |
732 return !pending_read_ && !received_end_of_stream_ && | 732 return !pending_read_ && !received_end_of_stream_ && |
733 !algorithm_->IsQueueFull(); | 733 !algorithm_->IsQueueFull(); |
734 } | 734 } |
735 | 735 |
736 void AudioRendererImpl::SetPlaybackRate(double playback_rate) { | 736 void AudioRendererImpl::SetPlaybackRate(double playback_rate) { |
737 DVLOG(1) << __FUNCTION__ << "(" << playback_rate << ")"; | 737 DVLOG(1) << __func__ << "(" << playback_rate << ")"; |
738 DCHECK(task_runner_->BelongsToCurrentThread()); | 738 DCHECK(task_runner_->BelongsToCurrentThread()); |
739 DCHECK_GE(playback_rate, 0); | 739 DCHECK_GE(playback_rate, 0); |
740 DCHECK(sink_.get()); | 740 DCHECK(sink_.get()); |
741 | 741 |
742 base::AutoLock auto_lock(lock_); | 742 base::AutoLock auto_lock(lock_); |
743 | 743 |
744 // We have two cases here: | 744 // We have two cases here: |
745 // Play: current_playback_rate == 0 && playback_rate != 0 | 745 // Play: current_playback_rate == 0 && playback_rate != 0 |
746 // Pause: current_playback_rate != 0 && playback_rate == 0 | 746 // Pause: current_playback_rate != 0 && playback_rate == 0 |
747 double current_playback_rate = playback_rate_; | 747 double current_playback_rate = playback_rate_; |
(...skipping 17 matching lines...) Expand all Loading... |
765 const scoped_refptr<AudioBuffer>& buffer) { | 765 const scoped_refptr<AudioBuffer>& buffer) { |
766 DCHECK_EQ(state_, kPlaying); | 766 DCHECK_EQ(state_, kPlaying); |
767 return buffer.get() && !buffer->end_of_stream() && | 767 return buffer.get() && !buffer->end_of_stream() && |
768 (buffer->timestamp() + buffer->duration()) < start_timestamp_; | 768 (buffer->timestamp() + buffer->duration()) < start_timestamp_; |
769 } | 769 } |
770 | 770 |
771 int AudioRendererImpl::Render(AudioBus* audio_bus, | 771 int AudioRendererImpl::Render(AudioBus* audio_bus, |
772 uint32_t frames_delayed, | 772 uint32_t frames_delayed, |
773 uint32_t frames_skipped) { | 773 uint32_t frames_skipped) { |
774 const int frames_requested = audio_bus->frames(); | 774 const int frames_requested = audio_bus->frames(); |
775 DVLOG(4) << __FUNCTION__ << " frames_delayed:" << frames_delayed | 775 DVLOG(4) << __func__ << " frames_delayed:" << frames_delayed |
776 << " frames_skipped:" << frames_skipped | 776 << " frames_skipped:" << frames_skipped |
777 << " frames_requested:" << frames_requested; | 777 << " frames_requested:" << frames_requested; |
778 | 778 |
779 int frames_written = 0; | 779 int frames_written = 0; |
780 { | 780 { |
781 base::AutoLock auto_lock(lock_); | 781 base::AutoLock auto_lock(lock_); |
782 last_render_time_ = tick_clock_->NowTicks(); | 782 last_render_time_ = tick_clock_->NowTicks(); |
783 | 783 |
784 if (!stop_rendering_time_.is_null()) { | 784 if (!stop_rendering_time_.is_null()) { |
785 audio_clock_->CompensateForSuspendedWrites( | 785 audio_clock_->CompensateForSuspendedWrites( |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 MEDIA_LOG(ERROR, media_log_) | 933 MEDIA_LOG(ERROR, media_log_) |
934 << "audio error during playing, status: " | 934 << "audio error during playing, status: " |
935 << MediaLog::PipelineStatusToString(status); | 935 << MediaLog::PipelineStatusToString(status); |
936 client_->OnError(status); | 936 client_->OnError(status); |
937 } | 937 } |
938 return; | 938 return; |
939 } | 939 } |
940 } | 940 } |
941 | 941 |
942 void AudioRendererImpl::ChangeState_Locked(State new_state) { | 942 void AudioRendererImpl::ChangeState_Locked(State new_state) { |
943 DVLOG(1) << __FUNCTION__ << " : " << state_ << " -> " << new_state; | 943 DVLOG(1) << __func__ << " : " << state_ << " -> " << new_state; |
944 lock_.AssertAcquired(); | 944 lock_.AssertAcquired(); |
945 state_ = new_state; | 945 state_ = new_state; |
946 } | 946 } |
947 | 947 |
948 void AudioRendererImpl::OnNewSpliceBuffer(base::TimeDelta splice_timestamp) { | 948 void AudioRendererImpl::OnNewSpliceBuffer(base::TimeDelta splice_timestamp) { |
949 DCHECK(task_runner_->BelongsToCurrentThread()); | 949 DCHECK(task_runner_->BelongsToCurrentThread()); |
950 splicer_->SetSpliceTimestamp(splice_timestamp); | 950 splicer_->SetSpliceTimestamp(splice_timestamp); |
951 } | 951 } |
952 | 952 |
953 void AudioRendererImpl::OnConfigChange() { | 953 void AudioRendererImpl::OnConfigChange() { |
954 DCHECK(task_runner_->BelongsToCurrentThread()); | 954 DCHECK(task_runner_->BelongsToCurrentThread()); |
955 DCHECK(expecting_config_changes_); | 955 DCHECK(expecting_config_changes_); |
956 buffer_converter_->ResetTimestampState(); | 956 buffer_converter_->ResetTimestampState(); |
957 // Drain flushed buffers from the converter so the AudioSplicer receives all | 957 // Drain flushed buffers from the converter so the AudioSplicer receives all |
958 // data ahead of any OnNewSpliceBuffer() calls. Since discontinuities should | 958 // data ahead of any OnNewSpliceBuffer() calls. Since discontinuities should |
959 // only appear after config changes, AddInput() should never fail here. | 959 // only appear after config changes, AddInput() should never fail here. |
960 while (buffer_converter_->HasNextBuffer()) | 960 while (buffer_converter_->HasNextBuffer()) |
961 CHECK(splicer_->AddInput(buffer_converter_->GetNextBuffer())); | 961 CHECK(splicer_->AddInput(buffer_converter_->GetNextBuffer())); |
962 } | 962 } |
963 | 963 |
964 void AudioRendererImpl::SetBufferingState_Locked( | 964 void AudioRendererImpl::SetBufferingState_Locked( |
965 BufferingState buffering_state) { | 965 BufferingState buffering_state) { |
966 DVLOG(1) << __FUNCTION__ << " : " << buffering_state_ << " -> " | 966 DVLOG(1) << __func__ << " : " << buffering_state_ << " -> " |
967 << buffering_state; | 967 << buffering_state; |
968 DCHECK_NE(buffering_state_, buffering_state); | 968 DCHECK_NE(buffering_state_, buffering_state); |
969 lock_.AssertAcquired(); | 969 lock_.AssertAcquired(); |
970 buffering_state_ = buffering_state; | 970 buffering_state_ = buffering_state; |
971 | 971 |
972 task_runner_->PostTask( | 972 task_runner_->PostTask( |
973 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, | 973 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, |
974 weak_factory_.GetWeakPtr(), buffering_state_)); | 974 weak_factory_.GetWeakPtr(), buffering_state_)); |
975 } | 975 } |
976 | 976 |
977 } // namespace media | 977 } // namespace media |
OLD | NEW |