Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: media/renderers/audio_renderer_impl.cc

Issue 2366373003: Not for submission. fastSeek prototype. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/renderers/audio_renderer_impl.h ('k') | media/renderers/renderer_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 sink_->Pause(); 157 sink_->Pause();
158 stop_rendering_time_ = last_render_time_; 158 stop_rendering_time_ = last_render_time_;
159 } 159 }
160 160
161 void AudioRendererImpl::SetMediaTime(base::TimeDelta time) { 161 void AudioRendererImpl::SetMediaTime(base::TimeDelta time) {
162 DVLOG(1) << __func__ << "(" << time << ")"; 162 DVLOG(1) << __func__ << "(" << time << ")";
163 DCHECK(task_runner_->BelongsToCurrentThread()); 163 DCHECK(task_runner_->BelongsToCurrentThread());
164 164
165 base::AutoLock auto_lock(lock_); 165 base::AutoLock auto_lock(lock_);
166 DCHECK(!rendering_); 166 DCHECK(!rendering_);
167 DCHECK_EQ(state_, kFlushed); 167 DCHECK(state_ == kFlushed || state_ == kPlaying);
168 168
169 start_timestamp_ = time; 169 start_timestamp_ = time;
170 ended_timestamp_ = kInfiniteDuration; 170 ended_timestamp_ = kInfiniteDuration;
171 last_render_time_ = stop_rendering_time_ = base::TimeTicks();
172 first_packet_timestamp_ = kNoTimestamp;
173 audio_clock_.reset(new AudioClock(time, audio_parameters_.sample_rate()));
174 }
175
176 void AudioRendererImpl::SetMediaTime_Locked(base::TimeDelta time) {
177 DVLOG(1) << __func__ << "(" << time << ")";
178 DCHECK(task_runner_->BelongsToCurrentThread());
179
180 DCHECK(!rendering_);
181 DCHECK(state_ == kFlushed || state_ == kPlaying);
182
183 start_timestamp_ = time;
184 ended_timestamp_ = kInfiniteDuration;
171 last_render_time_ = stop_rendering_time_ = base::TimeTicks(); 185 last_render_time_ = stop_rendering_time_ = base::TimeTicks();
172 first_packet_timestamp_ = kNoTimestamp; 186 first_packet_timestamp_ = kNoTimestamp;
173 audio_clock_.reset(new AudioClock(time, audio_parameters_.sample_rate())); 187 audio_clock_.reset(new AudioClock(time, audio_parameters_.sample_rate()));
174 } 188 }
175 189
176 base::TimeDelta AudioRendererImpl::CurrentMediaTime() { 190 base::TimeDelta AudioRendererImpl::CurrentMediaTime() {
177 base::AutoLock auto_lock(lock_); 191 base::AutoLock auto_lock(lock_);
178 192
179 // Return the current time based on the known extents of the rendered audio 193 // 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. 194 // data plus an estimate based on the last time those values were calculated.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 if (buffer_converter_) 315 if (buffer_converter_)
302 buffer_converter_->Reset(); 316 buffer_converter_->Reset();
303 algorithm_->FlushBuffers(); 317 algorithm_->FlushBuffers();
304 } 318 }
305 319
306 // Changes in buffering state are always posted. Flush callback must only be 320 // Changes in buffering state are always posted. Flush callback must only be
307 // run after buffering state has been set back to nothing. 321 // run after buffering state has been set back to nothing.
308 task_runner_->PostTask(FROM_HERE, base::ResetAndReturn(&flush_cb_)); 322 task_runner_->PostTask(FROM_HERE, base::ResetAndReturn(&flush_cb_));
309 } 323 }
310 324
311 void AudioRendererImpl::StartPlaying() { 325 void AudioRendererImpl::StartPlayingFrom(StreamPosition position) {
312 DVLOG(1) << __func__; 326 DVLOG(1) << __func__;
313 DCHECK(task_runner_->BelongsToCurrentThread()); 327 DCHECK(task_runner_->BelongsToCurrentThread());
314 328
315 base::AutoLock auto_lock(lock_); 329 base::AutoLock auto_lock(lock_);
316 DCHECK(!sink_playing_); 330 DCHECK(!sink_playing_);
317 DCHECK_EQ(state_, kFlushed); 331 DCHECK_EQ(state_, kFlushed);
318 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); 332 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING);
319 DCHECK(!pending_read_) << "Pending read must complete before seeking"; 333 DCHECK(!pending_read_) << "Pending read must complete before seeking";
320 334
335 start_rendering_from_first_frame_ =
336 position.kind == StreamPosition::Kind::KEY_FRAME_PRECEDING_TIME;
321 ChangeState_Locked(kPlaying); 337 ChangeState_Locked(kPlaying);
322 AttemptRead_Locked(); 338 AttemptRead_Locked();
323 } 339 }
324 340
325 void AudioRendererImpl::Initialize(DemuxerStream* stream, 341 void AudioRendererImpl::Initialize(DemuxerStream* stream,
326 CdmContext* cdm_context, 342 CdmContext* cdm_context,
327 RendererClient* client, 343 RendererClient* client,
328 const PipelineStatusCB& init_cb) { 344 const PipelineStatusCB& init_cb) {
329 DVLOG(1) << __func__; 345 DVLOG(1) << __func__;
330 DCHECK(task_runner_->BelongsToCurrentThread()); 346 DCHECK(task_runner_->BelongsToCurrentThread());
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 MEDIA_LOG(ERROR, media_log_) 603 MEDIA_LOG(ERROR, media_log_)
588 << "Unsupported midstream configuration change!" 604 << "Unsupported midstream configuration change!"
589 << " Sample Rate: " << buffer->sample_rate() << " vs " 605 << " Sample Rate: " << buffer->sample_rate() << " vs "
590 << audio_parameters_.sample_rate() 606 << audio_parameters_.sample_rate()
591 << ", Channels: " << buffer->channel_count() << " vs " 607 << ", Channels: " << buffer->channel_count() << " vs "
592 << audio_parameters_.channels(); 608 << audio_parameters_.channels();
593 HandleAbortedReadOrDecodeError(PIPELINE_ERROR_DECODE); 609 HandleAbortedReadOrDecodeError(PIPELINE_ERROR_DECODE);
594 return; 610 return;
595 } 611 }
596 612
613 if (start_rendering_from_first_frame_) {
614 LOG(ERROR) << "First audio timestamp: " << buffer->timestamp();
615 SetMediaTime_Locked(buffer->timestamp());
616 start_rendering_from_first_frame_ = false;
617 }
618
597 if (!splicer_->AddInput(buffer)) { 619 if (!splicer_->AddInput(buffer)) {
598 HandleAbortedReadOrDecodeError(AUDIO_RENDERER_ERROR_SPLICE_FAILED); 620 HandleAbortedReadOrDecodeError(AUDIO_RENDERER_ERROR_SPLICE_FAILED);
599 return; 621 return;
600 } 622 }
601 } 623 }
602 624
603 if (!splicer_->HasNextBuffer()) { 625 if (!splicer_->HasNextBuffer()) {
604 AttemptRead_Locked(); 626 AttemptRead_Locked();
605 return; 627 return;
606 } 628 }
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 DCHECK_NE(buffering_state_, buffering_state); 969 DCHECK_NE(buffering_state_, buffering_state);
948 lock_.AssertAcquired(); 970 lock_.AssertAcquired();
949 buffering_state_ = buffering_state; 971 buffering_state_ = buffering_state;
950 972
951 task_runner_->PostTask( 973 task_runner_->PostTask(
952 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, 974 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange,
953 weak_factory_.GetWeakPtr(), buffering_state_)); 975 weak_factory_.GetWeakPtr(), buffering_state_));
954 } 976 }
955 977
956 } // namespace media 978 } // namespace media
OLDNEW
« no previous file with comments | « media/renderers/audio_renderer_impl.h ('k') | media/renderers/renderer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698