Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/renderers/video_renderer_impl.h" | 5 #include "media/renderers/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/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 base::FieldTrialList::FindFullName("NewVideoRendererTrial"); | 37 base::FieldTrialList::FindFullName("NewVideoRendererTrial"); |
| 38 const bool disabled_via_cli = | 38 const bool disabled_via_cli = |
| 39 base::CommandLine::ForCurrentProcess()->HasSwitch( | 39 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 40 switches::kDisableNewVideoRenderer); | 40 switches::kDisableNewVideoRenderer); |
| 41 return !disabled_via_cli && | 41 return !disabled_via_cli && |
| 42 !base::StartsWith(group_name, "Disabled", | 42 !base::StartsWith(group_name, "Disabled", |
| 43 base::CompareCase::SENSITIVE); | 43 base::CompareCase::SENSITIVE); |
| 44 } | 44 } |
| 45 | 45 |
| 46 VideoRendererImpl::VideoRendererImpl( | 46 VideoRendererImpl::VideoRendererImpl( |
| 47 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 47 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, |
| 48 const scoped_refptr<base::TaskRunner>& worker_task_runner, | |
| 48 VideoRendererSink* sink, | 49 VideoRendererSink* sink, |
| 49 ScopedVector<VideoDecoder> decoders, | 50 ScopedVector<VideoDecoder> decoders, |
| 50 bool drop_frames, | 51 bool drop_frames, |
| 51 const scoped_refptr<GpuVideoAcceleratorFactories>& gpu_factories, | 52 const scoped_refptr<GpuVideoAcceleratorFactories>& gpu_factories, |
| 52 const scoped_refptr<MediaLog>& media_log) | 53 const scoped_refptr<MediaLog>& media_log) |
| 53 : task_runner_(task_runner), | 54 : task_runner_(media_task_runner), |
| 54 use_new_video_renderering_path_(ShouldUseVideoRenderingPath()), | 55 use_new_video_renderering_path_(ShouldUseVideoRenderingPath()), |
| 55 sink_(sink), | 56 sink_(sink), |
| 56 sink_started_(false), | 57 sink_started_(false), |
| 57 video_frame_stream_( | 58 video_frame_stream_( |
| 58 new VideoFrameStream(task_runner, decoders.Pass(), media_log)), | 59 new VideoFrameStream(media_task_runner, decoders.Pass(), media_log)), |
| 59 gpu_memory_buffer_pool_( | 60 gpu_memory_buffer_pool_( |
| 60 new GpuMemoryBufferVideoFramePool(task_runner, gpu_factories)), | 61 new GpuMemoryBufferVideoFramePool(media_task_runner, |
| 62 worker_task_runner, | |
| 63 gpu_factories)), | |
| 61 media_log_(media_log), | 64 media_log_(media_log), |
| 62 low_delay_(false), | 65 low_delay_(false), |
| 63 received_end_of_stream_(false), | 66 received_end_of_stream_(false), |
| 64 rendered_end_of_stream_(false), | 67 rendered_end_of_stream_(false), |
| 65 frame_available_(&lock_), | 68 frame_available_(&lock_), |
| 66 state_(kUninitialized), | 69 state_(kUninitialized), |
| 67 thread_(), | 70 thread_(), |
| 68 pending_read_(false), | 71 pending_read_(false), |
| 69 drop_frames_(drop_frames), | 72 drop_frames_(drop_frames), |
| 70 buffering_state_(BUFFERING_HAVE_NOTHING), | 73 buffering_state_(BUFFERING_HAVE_NOTHING), |
| 71 frames_decoded_(0), | 74 frames_decoded_(0), |
| 72 frames_dropped_(0), | 75 frames_dropped_(0), |
| 73 is_shutting_down_(false), | 76 is_shutting_down_(false), |
| 74 tick_clock_(new base::DefaultTickClock()), | 77 tick_clock_(new base::DefaultTickClock()), |
| 75 was_background_rendering_(false), | 78 was_background_rendering_(false), |
| 76 time_progressing_(false), | 79 time_progressing_(false), |
| 77 render_first_frame_and_stop_(false), | 80 render_first_frame_and_stop_(false), |
| 78 posted_maybe_stop_after_first_paint_(false), | 81 posted_maybe_stop_after_first_paint_(false), |
| 79 weak_factory_(this) { | 82 weak_factory_(this) {} |
| 80 } | |
| 81 | 83 |
| 82 VideoRendererImpl::~VideoRendererImpl() { | 84 VideoRendererImpl::~VideoRendererImpl() { |
| 83 DCHECK(task_runner_->BelongsToCurrentThread()); | 85 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 84 | 86 |
| 85 if (!use_new_video_renderering_path_) { | 87 if (!use_new_video_renderering_path_) { |
| 86 base::AutoLock auto_lock(lock_); | 88 base::AutoLock auto_lock(lock_); |
| 87 is_shutting_down_ = true; | 89 is_shutting_down_ = true; |
| 88 frame_available_.Signal(); | 90 frame_available_.Signal(); |
| 89 } | 91 } |
| 90 | 92 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 last_media_time_ = ConvertMediaTimestamp(ready_frames_.front()->timestamp()); | 469 last_media_time_ = ConvertMediaTimestamp(ready_frames_.front()->timestamp()); |
| 468 | 470 |
| 469 ready_frames_.pop_front(); | 471 ready_frames_.pop_front(); |
| 470 frames_dropped_++; | 472 frames_dropped_++; |
| 471 | 473 |
| 472 task_runner_->PostTask( | 474 task_runner_->PostTask( |
| 473 FROM_HERE, | 475 FROM_HERE, |
| 474 base::Bind(&VideoRendererImpl::AttemptRead, weak_factory_.GetWeakPtr())); | 476 base::Bind(&VideoRendererImpl::AttemptRead, weak_factory_.GetWeakPtr())); |
| 475 } | 477 } |
| 476 | 478 |
| 479 void VideoRendererImpl::FrameReadyForCopyingToGpuMemoryBuffers( | |
| 480 VideoFrameStream::Status status, | |
| 481 const scoped_refptr<VideoFrame>& frame) { | |
| 482 if (status != VideoFrameStream::OK || start_timestamp_ > frame->timestamp()) { | |
|
DaleCurtis
2015/08/17 18:01:30
Notably, the very first frame might not be in a GM
Daniele Castagna
2015/08/19 21:31:25
Ack.
| |
| 483 VideoRendererImpl::FrameReady(status, frame); | |
| 484 return; | |
| 485 } | |
| 486 | |
| 487 DCHECK(frame); | |
| 488 gpu_memory_buffer_pool_->MaybeCreateHardwareFrame( | |
| 489 frame, base::Bind(&VideoRendererImpl::FrameReady, | |
| 490 weak_factory_.GetWeakPtr(), status)); | |
| 491 } | |
| 492 | |
| 477 void VideoRendererImpl::FrameReady(VideoFrameStream::Status status, | 493 void VideoRendererImpl::FrameReady(VideoFrameStream::Status status, |
| 478 const scoped_refptr<VideoFrame>& frame) { | 494 const scoped_refptr<VideoFrame>& frame) { |
| 479 DCHECK(task_runner_->BelongsToCurrentThread()); | 495 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 480 bool start_sink = false; | 496 bool start_sink = false; |
| 481 { | 497 { |
| 482 base::AutoLock auto_lock(lock_); | 498 base::AutoLock auto_lock(lock_); |
| 483 DCHECK_NE(state_, kUninitialized); | 499 DCHECK_NE(state_, kUninitialized); |
| 484 DCHECK_NE(state_, kFlushed); | 500 DCHECK_NE(state_, kFlushed); |
| 485 | 501 |
| 486 CHECK(pending_read_); | 502 CHECK(pending_read_); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 | 694 |
| 679 if (pending_read_ || received_end_of_stream_) | 695 if (pending_read_ || received_end_of_stream_) |
| 680 return; | 696 return; |
| 681 | 697 |
| 682 if (HaveReachedBufferingCap()) | 698 if (HaveReachedBufferingCap()) |
| 683 return; | 699 return; |
| 684 | 700 |
| 685 switch (state_) { | 701 switch (state_) { |
| 686 case kPlaying: | 702 case kPlaying: |
| 687 pending_read_ = true; | 703 pending_read_ = true; |
| 688 video_frame_stream_->Read(base::Bind(&VideoRendererImpl::FrameReady, | 704 |
| 689 weak_factory_.GetWeakPtr())); | 705 video_frame_stream_->Read( |
| 706 base::Bind(&VideoRendererImpl::FrameReadyForCopyingToGpuMemoryBuffers, | |
| 707 weak_factory_.GetWeakPtr())); | |
| 690 return; | 708 return; |
| 691 | 709 |
| 692 case kUninitialized: | 710 case kUninitialized: |
| 693 case kInitializing: | 711 case kInitializing: |
| 694 case kFlushing: | 712 case kFlushing: |
| 695 case kFlushed: | 713 case kFlushed: |
| 696 return; | 714 return; |
| 697 } | 715 } |
| 698 } | 716 } |
| 699 | 717 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 804 base::TimeTicks VideoRendererImpl::ConvertMediaTimestamp( | 822 base::TimeTicks VideoRendererImpl::ConvertMediaTimestamp( |
| 805 base::TimeDelta media_time) { | 823 base::TimeDelta media_time) { |
| 806 std::vector<base::TimeDelta> media_times(1, media_time); | 824 std::vector<base::TimeDelta> media_times(1, media_time); |
| 807 std::vector<base::TimeTicks> wall_clock_times; | 825 std::vector<base::TimeTicks> wall_clock_times; |
| 808 if (!wall_clock_time_cb_.Run(media_times, &wall_clock_times)) | 826 if (!wall_clock_time_cb_.Run(media_times, &wall_clock_times)) |
| 809 return base::TimeTicks(); | 827 return base::TimeTicks(); |
| 810 return wall_clock_times[0]; | 828 return wall_clock_times[0]; |
| 811 } | 829 } |
| 812 | 830 |
| 813 } // namespace media | 831 } // namespace media |
| OLD | NEW |