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

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

Issue 418143005: media: Introduce Renderer interface and RendererImpl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add real RendererImpl Created 6 years, 5 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 | Annotate | Revision Log
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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 if (state_ != kPlaying || buffering_state_ != BUFFERING_HAVE_ENOUGH) { 195 if (state_ != kPlaying || buffering_state_ != BUFFERING_HAVE_ENOUGH) {
196 UpdateStatsAndWait_Locked(kIdleTimeDelta); 196 UpdateStatsAndWait_Locked(kIdleTimeDelta);
197 continue; 197 continue;
198 } 198 }
199 199
200 // Remain idle until we have the next frame ready for rendering. 200 // Remain idle until we have the next frame ready for rendering.
201 if (ready_frames_.empty()) { 201 if (ready_frames_.empty()) {
202 if (received_end_of_stream_) { 202 if (received_end_of_stream_) {
203 if (!rendered_end_of_stream_) { 203 if (!rendered_end_of_stream_) {
204 rendered_end_of_stream_ = true; 204 rendered_end_of_stream_ = true;
205 ended_cb_.Run(); 205 task_runner_->PostTask(FROM_HERE, ended_cb_);
206 } 206 }
207 } else { 207 } else {
208 buffering_state_ = BUFFERING_HAVE_NOTHING; 208 buffering_state_ = BUFFERING_HAVE_NOTHING;
209 task_runner_->PostTask( 209 task_runner_->PostTask(
210 FROM_HERE, base::Bind(buffering_state_cb_, BUFFERING_HAVE_NOTHING)); 210 FROM_HERE, base::Bind(buffering_state_cb_, BUFFERING_HAVE_NOTHING));
211 } 211 }
212 212
213 UpdateStatsAndWait_Locked(kIdleTimeDelta); 213 UpdateStatsAndWait_Locked(kIdleTimeDelta);
214 continue; 214 continue;
215 } 215 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 frames_decoded_++; 276 frames_decoded_++;
277 frames_dropped_++; 277 frames_dropped_++;
278 278
279 task_runner_->PostTask( 279 task_runner_->PostTask(
280 FROM_HERE, 280 FROM_HERE,
281 base::Bind(&VideoRendererImpl::AttemptRead, weak_factory_.GetWeakPtr())); 281 base::Bind(&VideoRendererImpl::AttemptRead, weak_factory_.GetWeakPtr()));
282 } 282 }
283 283
284 void VideoRendererImpl::FrameReady(VideoFrameStream::Status status, 284 void VideoRendererImpl::FrameReady(VideoFrameStream::Status status,
285 const scoped_refptr<VideoFrame>& frame) { 285 const scoped_refptr<VideoFrame>& frame) {
286 DCHECK(task_runner_->BelongsToCurrentThread());
286 base::AutoLock auto_lock(lock_); 287 base::AutoLock auto_lock(lock_);
287 DCHECK_NE(state_, kUninitialized); 288 DCHECK_NE(state_, kUninitialized);
288 DCHECK_NE(state_, kFlushed); 289 DCHECK_NE(state_, kFlushed);
289 290
290 CHECK(pending_read_); 291 CHECK(pending_read_);
291 pending_read_ = false; 292 pending_read_ = false;
292 293
293 if (status == VideoFrameStream::DECODE_ERROR || 294 if (status == VideoFrameStream::DECODE_ERROR ||
294 status == VideoFrameStream::DECRYPT_ERROR) { 295 status == VideoFrameStream::DECRYPT_ERROR) {
295 DCHECK(!frame.get()); 296 DCHECK(!frame.get());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 338
338 bool VideoRendererImpl::HaveEnoughData_Locked() { 339 bool VideoRendererImpl::HaveEnoughData_Locked() {
339 DCHECK_EQ(state_, kPlaying); 340 DCHECK_EQ(state_, kPlaying);
340 return received_end_of_stream_ || 341 return received_end_of_stream_ ||
341 !video_frame_stream_->CanReadWithoutStalling() || 342 !video_frame_stream_->CanReadWithoutStalling() ||
342 ready_frames_.size() >= static_cast<size_t>(limits::kMaxVideoFrames) || 343 ready_frames_.size() >= static_cast<size_t>(limits::kMaxVideoFrames) ||
343 (low_delay_ && ready_frames_.size() > 0); 344 (low_delay_ && ready_frames_.size() > 0);
344 } 345 }
345 346
346 void VideoRendererImpl::TransitionToHaveEnough_Locked() { 347 void VideoRendererImpl::TransitionToHaveEnough_Locked() {
348 DCHECK(task_runner_->BelongsToCurrentThread());
347 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); 349 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING);
348 350
349 if (received_end_of_stream_) 351 if (received_end_of_stream_)
350 max_time_cb_.Run(get_duration_cb_.Run()); 352 max_time_cb_.Run(get_duration_cb_.Run());
351 353
352 if (!ready_frames_.empty()) { 354 if (!ready_frames_.empty()) {
353 // Max time isn't reported while we're in a have nothing state as we could 355 // Max time isn't reported while we're in a have nothing state as we could
354 // be discarding frames to find |start_timestamp_|. 356 // be discarding frames to find |start_timestamp_|.
355 if (!received_end_of_stream_) { 357 if (!received_end_of_stream_) {
356 base::TimeDelta max_timestamp = ready_frames_[0]->timestamp(); 358 base::TimeDelta max_timestamp = ready_frames_[0]->timestamp();
357 for (size_t i = 1; i < ready_frames_.size(); ++i) { 359 for (size_t i = 1; i < ready_frames_.size(); ++i) {
358 if (ready_frames_[i]->timestamp() > max_timestamp) 360 if (ready_frames_[i]->timestamp() > max_timestamp)
359 max_timestamp = ready_frames_[i]->timestamp(); 361 max_timestamp = ready_frames_[i]->timestamp();
360 } 362 }
361 max_time_cb_.Run(max_timestamp); 363 max_time_cb_.Run(max_timestamp);
362 } 364 }
363 365
364 // Because the clock might remain paused in for an undetermined amount 366 // Because the clock might remain paused in for an undetermined amount
365 // of time (e.g., seeking while paused), paint the first frame. 367 // of time (e.g., seeking while paused), paint the first frame.
366 PaintNextReadyFrame_Locked(); 368 PaintNextReadyFrame_Locked();
367 } 369 }
368 370
369 buffering_state_ = BUFFERING_HAVE_ENOUGH; 371 buffering_state_ = BUFFERING_HAVE_ENOUGH;
370 buffering_state_cb_.Run(BUFFERING_HAVE_ENOUGH); 372 buffering_state_cb_.Run(BUFFERING_HAVE_ENOUGH);
371 } 373 }
372 374
373 void VideoRendererImpl::AddReadyFrame_Locked( 375 void VideoRendererImpl::AddReadyFrame_Locked(
374 const scoped_refptr<VideoFrame>& frame) { 376 const scoped_refptr<VideoFrame>& frame) {
377 DCHECK(task_runner_->BelongsToCurrentThread());
375 lock_.AssertAcquired(); 378 lock_.AssertAcquired();
376 DCHECK(!frame->end_of_stream()); 379 DCHECK(!frame->end_of_stream());
377 380
378 // Adjust the incoming frame if its rendering stop time is past the duration 381 // Adjust the incoming frame if its rendering stop time is past the duration
379 // of the video itself. This is typically the last frame of the video and 382 // of the video itself. This is typically the last frame of the video and
380 // occurs if the container specifies a duration that isn't a multiple of the 383 // occurs if the container specifies a duration that isn't a multiple of the
381 // frame rate. Another way for this to happen is for the container to state 384 // frame rate. Another way for this to happen is for the container to state
382 // a smaller duration than the largest packet timestamp. 385 // a smaller duration than the largest packet timestamp.
383 base::TimeDelta duration = get_duration_cb_.Run(); 386 base::TimeDelta duration = get_duration_cb_.Run();
384 if (frame->timestamp() > duration) { 387 if (frame->timestamp() > duration) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 void VideoRendererImpl::UpdateStatsAndWait_Locked( 450 void VideoRendererImpl::UpdateStatsAndWait_Locked(
448 base::TimeDelta wait_duration) { 451 base::TimeDelta wait_duration) {
449 lock_.AssertAcquired(); 452 lock_.AssertAcquired();
450 DCHECK_GE(frames_decoded_, 0); 453 DCHECK_GE(frames_decoded_, 0);
451 DCHECK_LE(frames_dropped_, frames_decoded_); 454 DCHECK_LE(frames_dropped_, frames_decoded_);
452 455
453 if (frames_decoded_) { 456 if (frames_decoded_) {
454 PipelineStatistics statistics; 457 PipelineStatistics statistics;
455 statistics.video_frames_decoded = frames_decoded_; 458 statistics.video_frames_decoded = frames_decoded_;
456 statistics.video_frames_dropped = frames_dropped_; 459 statistics.video_frames_dropped = frames_dropped_;
457 statistics_cb_.Run(statistics); 460 task_runner_->PostTask(FROM_HERE, base::Bind(statistics_cb_, statistics));
458 461
459 frames_decoded_ = 0; 462 frames_decoded_ = 0;
460 frames_dropped_ = 0; 463 frames_dropped_ = 0;
461 } 464 }
462 465
463 frame_available_.TimedWait(wait_duration); 466 frame_available_.TimedWait(wait_duration);
464 } 467 }
465 468
466 } // namespace media 469 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698