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

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

Issue 557333002: Revert of 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
« 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,
113 const BufferingStateCB& buffering_state_cb, 114 const BufferingStateCB& buffering_state_cb,
114 const base::Closure& ended_cb, 115 const base::Closure& ended_cb,
115 const PipelineStatusCB& error_cb, 116 const PipelineStatusCB& error_cb,
116 const TimeDeltaCB& get_time_cb) { 117 const TimeDeltaCB& get_time_cb,
118 const TimeDeltaCB& get_duration_cb) {
117 DCHECK(task_runner_->BelongsToCurrentThread()); 119 DCHECK(task_runner_->BelongsToCurrentThread());
118 base::AutoLock auto_lock(lock_); 120 base::AutoLock auto_lock(lock_);
119 DCHECK(stream); 121 DCHECK(stream);
120 DCHECK_EQ(stream->type(), DemuxerStream::VIDEO); 122 DCHECK_EQ(stream->type(), DemuxerStream::VIDEO);
121 DCHECK(!init_cb.is_null()); 123 DCHECK(!init_cb.is_null());
122 DCHECK(!statistics_cb.is_null()); 124 DCHECK(!statistics_cb.is_null());
125 DCHECK(!max_time_cb.is_null());
123 DCHECK(!buffering_state_cb.is_null()); 126 DCHECK(!buffering_state_cb.is_null());
124 DCHECK(!ended_cb.is_null()); 127 DCHECK(!ended_cb.is_null());
125 DCHECK(!get_time_cb.is_null()); 128 DCHECK(!get_time_cb.is_null());
129 DCHECK(!get_duration_cb.is_null());
126 DCHECK_EQ(kUninitialized, state_); 130 DCHECK_EQ(kUninitialized, state_);
127 131
128 low_delay_ = low_delay; 132 low_delay_ = low_delay;
129 133
130 // Always post |init_cb_| because |this| could be destroyed if initialization 134 // Always post |init_cb_| because |this| could be destroyed if initialization
131 // failed. 135 // failed.
132 init_cb_ = BindToCurrentLoop(init_cb); 136 init_cb_ = BindToCurrentLoop(init_cb);
133 137
134 statistics_cb_ = statistics_cb; 138 statistics_cb_ = statistics_cb;
139 max_time_cb_ = max_time_cb;
135 buffering_state_cb_ = buffering_state_cb; 140 buffering_state_cb_ = buffering_state_cb;
136 ended_cb_ = ended_cb; 141 ended_cb_ = ended_cb;
137 error_cb_ = error_cb; 142 error_cb_ = error_cb;
138 get_time_cb_ = get_time_cb; 143 get_time_cb_ = get_time_cb;
144 get_duration_cb_ = get_duration_cb;
139 state_ = kInitializing; 145 state_ = kInitializing;
140 146
141 video_frame_stream_->Initialize( 147 video_frame_stream_->Initialize(
142 stream, 148 stream,
143 low_delay, 149 low_delay,
144 statistics_cb, 150 statistics_cb,
145 base::Bind(&VideoRendererImpl::OnVideoFrameStreamInitialized, 151 base::Bind(&VideoRendererImpl::OnVideoFrameStreamInitialized,
146 weak_factory_.GetWeakPtr())); 152 weak_factory_.GetWeakPtr()));
147 } 153 }
148 154
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 return received_end_of_stream_ || 358 return received_end_of_stream_ ||
353 !video_frame_stream_->CanReadWithoutStalling() || 359 !video_frame_stream_->CanReadWithoutStalling() ||
354 ready_frames_.size() >= static_cast<size_t>(limits::kMaxVideoFrames) || 360 ready_frames_.size() >= static_cast<size_t>(limits::kMaxVideoFrames) ||
355 (low_delay_ && ready_frames_.size() > 0); 361 (low_delay_ && ready_frames_.size() > 0);
356 } 362 }
357 363
358 void VideoRendererImpl::TransitionToHaveEnough_Locked() { 364 void VideoRendererImpl::TransitionToHaveEnough_Locked() {
359 DCHECK(task_runner_->BelongsToCurrentThread()); 365 DCHECK(task_runner_->BelongsToCurrentThread());
360 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); 366 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING);
361 367
368 if (received_end_of_stream_)
369 max_time_cb_.Run(get_duration_cb_.Run());
370
362 if (!ready_frames_.empty()) { 371 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
363 // Because the clock might remain paused in for an undetermined amount 383 // Because the clock might remain paused in for an undetermined amount
364 // of time (e.g., seeking while paused), paint the first frame. 384 // of time (e.g., seeking while paused), paint the first frame.
365 PaintNextReadyFrame_Locked(); 385 PaintNextReadyFrame_Locked();
366 } 386 }
367 387
368 buffering_state_ = BUFFERING_HAVE_ENOUGH; 388 buffering_state_ = BUFFERING_HAVE_ENOUGH;
369 buffering_state_cb_.Run(BUFFERING_HAVE_ENOUGH); 389 buffering_state_cb_.Run(BUFFERING_HAVE_ENOUGH);
370 } 390 }
371 391
372 void VideoRendererImpl::AddReadyFrame_Locked( 392 void VideoRendererImpl::AddReadyFrame_Locked(
373 const scoped_refptr<VideoFrame>& frame) { 393 const scoped_refptr<VideoFrame>& frame) {
374 DCHECK(task_runner_->BelongsToCurrentThread()); 394 DCHECK(task_runner_->BelongsToCurrentThread());
375 lock_.AssertAcquired(); 395 lock_.AssertAcquired();
376 DCHECK(!frame->end_of_stream()); 396 DCHECK(!frame->end_of_stream());
377 397
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
378 ready_frames_.push_back(frame); 408 ready_frames_.push_back(frame);
379 DCHECK_LE(ready_frames_.size(), 409 DCHECK_LE(ready_frames_.size(),
380 static_cast<size_t>(limits::kMaxVideoFrames)); 410 static_cast<size_t>(limits::kMaxVideoFrames));
381 411
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
382 // Avoid needlessly waking up |thread_| unless playing. 419 // Avoid needlessly waking up |thread_| unless playing.
383 if (state_ == kPlaying) 420 if (state_ == kPlaying)
384 frame_available_.Signal(); 421 frame_available_.Signal();
385 } 422 }
386 423
387 void VideoRendererImpl::AttemptRead() { 424 void VideoRendererImpl::AttemptRead() {
388 base::AutoLock auto_lock(lock_); 425 base::AutoLock auto_lock(lock_);
389 AttemptRead_Locked(); 426 AttemptRead_Locked();
390 } 427 }
391 428
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 task_runner_->PostTask(FROM_HERE, base::Bind(statistics_cb_, statistics)); 478 task_runner_->PostTask(FROM_HERE, base::Bind(statistics_cb_, statistics));
442 479
443 frames_decoded_ = 0; 480 frames_decoded_ = 0;
444 frames_dropped_ = 0; 481 frames_dropped_ = 0;
445 } 482 }
446 483
447 frame_available_.TimedWait(wait_duration); 484 frame_available_.TimedWait(wait_duration);
448 } 485 }
449 486
450 } // namespace media 487 } // 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