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

Side by Side Diff: media/filters/video_renderer_impl.cc

Issue 534073002: Switch to using media::TimeSource inside media::RendererImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix bad rebase Created 6 years, 3 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/filters/video_renderer_impl.h ('k') | media/filters/video_renderer_impl_unittest.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/filters/video_renderer_impl.h" 5 #include "media/filters/video_renderer_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 state_ = kPlaying; 104 state_ = kPlaying;
105 start_timestamp_ = get_time_cb_.Run(); 105 start_timestamp_ = get_time_cb_.Run();
106 AttemptRead_Locked(); 106 AttemptRead_Locked();
107 } 107 }
108 108
109 void VideoRendererImpl::Initialize(DemuxerStream* stream, 109 void VideoRendererImpl::Initialize(DemuxerStream* stream,
110 bool low_delay, 110 bool low_delay,
111 const PipelineStatusCB& init_cb, 111 const PipelineStatusCB& init_cb,
112 const StatisticsCB& statistics_cb, 112 const StatisticsCB& statistics_cb,
113 const TimeCB& max_time_cb,
114 const BufferingStateCB& buffering_state_cb, 113 const BufferingStateCB& buffering_state_cb,
115 const base::Closure& ended_cb, 114 const base::Closure& ended_cb,
116 const PipelineStatusCB& error_cb, 115 const PipelineStatusCB& error_cb,
117 const TimeDeltaCB& get_time_cb, 116 const TimeDeltaCB& get_time_cb) {
118 const TimeDeltaCB& get_duration_cb) {
119 DCHECK(task_runner_->BelongsToCurrentThread()); 117 DCHECK(task_runner_->BelongsToCurrentThread());
120 base::AutoLock auto_lock(lock_); 118 base::AutoLock auto_lock(lock_);
121 DCHECK(stream); 119 DCHECK(stream);
122 DCHECK_EQ(stream->type(), DemuxerStream::VIDEO); 120 DCHECK_EQ(stream->type(), DemuxerStream::VIDEO);
123 DCHECK(!init_cb.is_null()); 121 DCHECK(!init_cb.is_null());
124 DCHECK(!statistics_cb.is_null()); 122 DCHECK(!statistics_cb.is_null());
125 DCHECK(!max_time_cb.is_null());
126 DCHECK(!buffering_state_cb.is_null()); 123 DCHECK(!buffering_state_cb.is_null());
127 DCHECK(!ended_cb.is_null()); 124 DCHECK(!ended_cb.is_null());
128 DCHECK(!get_time_cb.is_null()); 125 DCHECK(!get_time_cb.is_null());
129 DCHECK(!get_duration_cb.is_null());
130 DCHECK_EQ(kUninitialized, state_); 126 DCHECK_EQ(kUninitialized, state_);
131 127
132 low_delay_ = low_delay; 128 low_delay_ = low_delay;
133 129
134 // Always post |init_cb_| because |this| could be destroyed if initialization 130 // Always post |init_cb_| because |this| could be destroyed if initialization
135 // failed. 131 // failed.
136 init_cb_ = BindToCurrentLoop(init_cb); 132 init_cb_ = BindToCurrentLoop(init_cb);
137 133
138 statistics_cb_ = statistics_cb; 134 statistics_cb_ = statistics_cb;
139 max_time_cb_ = max_time_cb;
140 buffering_state_cb_ = buffering_state_cb; 135 buffering_state_cb_ = buffering_state_cb;
141 ended_cb_ = ended_cb; 136 ended_cb_ = ended_cb;
142 error_cb_ = error_cb; 137 error_cb_ = error_cb;
143 get_time_cb_ = get_time_cb; 138 get_time_cb_ = get_time_cb;
144 get_duration_cb_ = get_duration_cb;
145 state_ = kInitializing; 139 state_ = kInitializing;
146 140
147 video_frame_stream_->Initialize( 141 video_frame_stream_->Initialize(
148 stream, 142 stream,
149 low_delay, 143 low_delay,
150 statistics_cb, 144 statistics_cb,
151 base::Bind(&VideoRendererImpl::OnVideoFrameStreamInitialized, 145 base::Bind(&VideoRendererImpl::OnVideoFrameStreamInitialized,
152 weak_factory_.GetWeakPtr())); 146 weak_factory_.GetWeakPtr()));
153 } 147 }
154 148
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 return received_end_of_stream_ || 352 return received_end_of_stream_ ||
359 !video_frame_stream_->CanReadWithoutStalling() || 353 !video_frame_stream_->CanReadWithoutStalling() ||
360 ready_frames_.size() >= static_cast<size_t>(limits::kMaxVideoFrames) || 354 ready_frames_.size() >= static_cast<size_t>(limits::kMaxVideoFrames) ||
361 (low_delay_ && ready_frames_.size() > 0); 355 (low_delay_ && ready_frames_.size() > 0);
362 } 356 }
363 357
364 void VideoRendererImpl::TransitionToHaveEnough_Locked() { 358 void VideoRendererImpl::TransitionToHaveEnough_Locked() {
365 DCHECK(task_runner_->BelongsToCurrentThread()); 359 DCHECK(task_runner_->BelongsToCurrentThread());
366 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); 360 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING);
367 361
368 if (received_end_of_stream_)
369 max_time_cb_.Run(get_duration_cb_.Run());
370
371 if (!ready_frames_.empty()) { 362 if (!ready_frames_.empty()) {
372 // Max time isn't reported while we're in a have nothing state as we could
373 // be discarding frames to find |start_timestamp_|.
374 if (!received_end_of_stream_) {
375 base::TimeDelta max_timestamp = ready_frames_[0]->timestamp();
376 for (size_t i = 1; i < ready_frames_.size(); ++i) {
377 if (ready_frames_[i]->timestamp() > max_timestamp)
378 max_timestamp = ready_frames_[i]->timestamp();
379 }
380 max_time_cb_.Run(max_timestamp);
381 }
382
383 // Because the clock might remain paused in for an undetermined amount 363 // Because the clock might remain paused in for an undetermined amount
384 // of time (e.g., seeking while paused), paint the first frame. 364 // of time (e.g., seeking while paused), paint the first frame.
385 PaintNextReadyFrame_Locked(); 365 PaintNextReadyFrame_Locked();
386 } 366 }
387 367
388 buffering_state_ = BUFFERING_HAVE_ENOUGH; 368 buffering_state_ = BUFFERING_HAVE_ENOUGH;
389 buffering_state_cb_.Run(BUFFERING_HAVE_ENOUGH); 369 buffering_state_cb_.Run(BUFFERING_HAVE_ENOUGH);
390 } 370 }
391 371
392 void VideoRendererImpl::AddReadyFrame_Locked( 372 void VideoRendererImpl::AddReadyFrame_Locked(
393 const scoped_refptr<VideoFrame>& frame) { 373 const scoped_refptr<VideoFrame>& frame) {
394 DCHECK(task_runner_->BelongsToCurrentThread()); 374 DCHECK(task_runner_->BelongsToCurrentThread());
395 lock_.AssertAcquired(); 375 lock_.AssertAcquired();
396 DCHECK(!frame->end_of_stream()); 376 DCHECK(!frame->end_of_stream());
397 377
398 // Adjust the incoming frame if its rendering stop time is past the duration
399 // of the video itself. This is typically the last frame of the video and
400 // occurs if the container specifies a duration that isn't a multiple of the
401 // frame rate. Another way for this to happen is for the container to state
402 // a smaller duration than the largest packet timestamp.
403 base::TimeDelta duration = get_duration_cb_.Run();
404 if (frame->timestamp() > duration) {
405 frame->set_timestamp(duration);
406 }
407
408 ready_frames_.push_back(frame); 378 ready_frames_.push_back(frame);
409 DCHECK_LE(ready_frames_.size(), 379 DCHECK_LE(ready_frames_.size(),
410 static_cast<size_t>(limits::kMaxVideoFrames)); 380 static_cast<size_t>(limits::kMaxVideoFrames));
411 381
412 // FrameReady() may add frames but discard them when we're decoding frames to
413 // reach |start_timestamp_|. In this case we'll only want to update the max
414 // time when we know we've reached |start_timestamp_| and have buffered enough
415 // frames to being playback.
416 if (buffering_state_ == BUFFERING_HAVE_ENOUGH)
417 max_time_cb_.Run(frame->timestamp());
418
419 // Avoid needlessly waking up |thread_| unless playing. 382 // Avoid needlessly waking up |thread_| unless playing.
420 if (state_ == kPlaying) 383 if (state_ == kPlaying)
421 frame_available_.Signal(); 384 frame_available_.Signal();
422 } 385 }
423 386
424 void VideoRendererImpl::AttemptRead() { 387 void VideoRendererImpl::AttemptRead() {
425 base::AutoLock auto_lock(lock_); 388 base::AutoLock auto_lock(lock_);
426 AttemptRead_Locked(); 389 AttemptRead_Locked();
427 } 390 }
428 391
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 task_runner_->PostTask(FROM_HERE, base::Bind(statistics_cb_, statistics)); 441 task_runner_->PostTask(FROM_HERE, base::Bind(statistics_cb_, statistics));
479 442
480 frames_decoded_ = 0; 443 frames_decoded_ = 0;
481 frames_dropped_ = 0; 444 frames_dropped_ = 0;
482 } 445 }
483 446
484 frame_available_.TimedWait(wait_duration); 447 frame_available_.TimedWait(wait_duration);
485 } 448 }
486 449
487 } // namespace media 450 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/video_renderer_impl.h ('k') | media/filters/video_renderer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698