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

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

Powered by Google App Engine
This is Rietveld 408576698