| 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/location.h" | 10 #include "base/location.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
| 13 #include "base/time/default_tick_clock.h" | 13 #include "base/time/default_tick_clock.h" |
| 14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 15 #include "media/base/bind_to_current_loop.h" | 15 #include "media/base/bind_to_current_loop.h" |
| 16 #include "media/base/buffers.h" | 16 #include "media/base/buffers.h" |
| 17 #include "media/base/limits.h" | 17 #include "media/base/limits.h" |
| 18 #include "media/base/pipeline.h" | 18 #include "media/base/pipeline.h" |
| 19 #include "media/base/video_frame.h" | 19 #include "media/base/video_frame.h" |
| 20 | 20 |
| 21 namespace media { | 21 namespace media { |
| 22 | 22 |
| 23 VideoRendererImpl::VideoRendererImpl( | 23 VideoRendererImpl::VideoRendererImpl( |
| 24 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 24 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 25 VideoRendererSink* sink, | |
| 26 ScopedVector<VideoDecoder> decoders, | 25 ScopedVector<VideoDecoder> decoders, |
| 27 bool drop_frames, | 26 bool drop_frames, |
| 28 const scoped_refptr<MediaLog>& media_log) | 27 const scoped_refptr<MediaLog>& media_log) |
| 29 : task_runner_(task_runner), | 28 : task_runner_(task_runner), |
| 30 sink_(sink), | |
| 31 video_frame_stream_( | 29 video_frame_stream_( |
| 32 new VideoFrameStream(task_runner, decoders.Pass(), media_log)), | 30 new VideoFrameStream(task_runner, decoders.Pass(), media_log)), |
| 33 low_delay_(false), | 31 low_delay_(false), |
| 34 received_end_of_stream_(false), | 32 received_end_of_stream_(false), |
| 35 rendered_end_of_stream_(false), | 33 rendered_end_of_stream_(false), |
| 36 frame_available_(&lock_), | 34 frame_available_(&lock_), |
| 37 state_(kUninitialized), | 35 state_(kUninitialized), |
| 38 thread_(), | 36 thread_(), |
| 39 pending_read_(false), | 37 pending_read_(false), |
| 40 drop_frames_(drop_frames), | 38 drop_frames_(drop_frames), |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 start_timestamp_ = timestamp; | 99 start_timestamp_ = timestamp; |
| 102 AttemptRead_Locked(); | 100 AttemptRead_Locked(); |
| 103 } | 101 } |
| 104 | 102 |
| 105 void VideoRendererImpl::Initialize( | 103 void VideoRendererImpl::Initialize( |
| 106 DemuxerStream* stream, | 104 DemuxerStream* stream, |
| 107 const PipelineStatusCB& init_cb, | 105 const PipelineStatusCB& init_cb, |
| 108 const SetDecryptorReadyCB& set_decryptor_ready_cb, | 106 const SetDecryptorReadyCB& set_decryptor_ready_cb, |
| 109 const StatisticsCB& statistics_cb, | 107 const StatisticsCB& statistics_cb, |
| 110 const BufferingStateCB& buffering_state_cb, | 108 const BufferingStateCB& buffering_state_cb, |
| 109 const PaintCB& paint_cb, |
| 111 const base::Closure& ended_cb, | 110 const base::Closure& ended_cb, |
| 112 const PipelineStatusCB& error_cb, | 111 const PipelineStatusCB& error_cb, |
| 113 const WallClockTimeCB& wall_clock_time_cb, | 112 const WallClockTimeCB& wall_clock_time_cb, |
| 114 const base::Closure& waiting_for_decryption_key_cb) { | 113 const base::Closure& waiting_for_decryption_key_cb) { |
| 115 DCHECK(task_runner_->BelongsToCurrentThread()); | 114 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 116 base::AutoLock auto_lock(lock_); | 115 base::AutoLock auto_lock(lock_); |
| 117 DCHECK(stream); | 116 DCHECK(stream); |
| 118 DCHECK_EQ(stream->type(), DemuxerStream::VIDEO); | 117 DCHECK_EQ(stream->type(), DemuxerStream::VIDEO); |
| 119 DCHECK(!init_cb.is_null()); | 118 DCHECK(!init_cb.is_null()); |
| 120 DCHECK(!statistics_cb.is_null()); | 119 DCHECK(!statistics_cb.is_null()); |
| 121 DCHECK(!buffering_state_cb.is_null()); | 120 DCHECK(!buffering_state_cb.is_null()); |
| 121 DCHECK(!paint_cb.is_null()); |
| 122 DCHECK(!ended_cb.is_null()); | 122 DCHECK(!ended_cb.is_null()); |
| 123 DCHECK(!wall_clock_time_cb.is_null()); | 123 DCHECK(!wall_clock_time_cb.is_null()); |
| 124 DCHECK_EQ(kUninitialized, state_); | 124 DCHECK_EQ(kUninitialized, state_); |
| 125 | 125 |
| 126 low_delay_ = (stream->liveness() == DemuxerStream::LIVENESS_LIVE); | 126 low_delay_ = (stream->liveness() == DemuxerStream::LIVENESS_LIVE); |
| 127 | 127 |
| 128 // Always post |init_cb_| because |this| could be destroyed if initialization | 128 // Always post |init_cb_| because |this| could be destroyed if initialization |
| 129 // failed. | 129 // failed. |
| 130 init_cb_ = BindToCurrentLoop(init_cb); | 130 init_cb_ = BindToCurrentLoop(init_cb); |
| 131 | 131 |
| 132 statistics_cb_ = statistics_cb; | 132 statistics_cb_ = statistics_cb; |
| 133 buffering_state_cb_ = buffering_state_cb; | 133 buffering_state_cb_ = buffering_state_cb; |
| 134 paint_cb_ = base::Bind(&VideoRendererSink::PaintFrameUsingOldRenderingPath, | 134 paint_cb_ = paint_cb, |
| 135 base::Unretained(sink_)); | |
| 136 ended_cb_ = ended_cb; | 135 ended_cb_ = ended_cb; |
| 137 error_cb_ = error_cb; | 136 error_cb_ = error_cb; |
| 138 wall_clock_time_cb_ = wall_clock_time_cb; | 137 wall_clock_time_cb_ = wall_clock_time_cb; |
| 139 state_ = kInitializing; | 138 state_ = kInitializing; |
| 140 | 139 |
| 141 video_frame_stream_->Initialize( | 140 video_frame_stream_->Initialize( |
| 142 stream, base::Bind(&VideoRendererImpl::OnVideoFrameStreamInitialized, | 141 stream, base::Bind(&VideoRendererImpl::OnVideoFrameStreamInitialized, |
| 143 weak_factory_.GetWeakPtr()), | 142 weak_factory_.GetWeakPtr()), |
| 144 set_decryptor_ready_cb, statistics_cb, waiting_for_decryption_key_cb); | 143 set_decryptor_ready_cb, statistics_cb, waiting_for_decryption_key_cb); |
| 145 } | 144 } |
| 146 | 145 |
| 147 scoped_refptr<VideoFrame> VideoRendererImpl::Render( | |
| 148 base::TimeTicks deadline_min, | |
| 149 base::TimeTicks deadline_max) { | |
| 150 // TODO(dalecurtis): Hook this up to the new VideoRendererAlgorithm. | |
| 151 NOTIMPLEMENTED(); | |
| 152 return nullptr; | |
| 153 } | |
| 154 | |
| 155 void VideoRendererImpl::OnFrameDropped() { | |
| 156 // TODO(dalecurtis): Hook this up to the new VideoRendererAlgorithm. | |
| 157 NOTIMPLEMENTED(); | |
| 158 } | |
| 159 | |
| 160 void VideoRendererImpl::CreateVideoThread() { | 146 void VideoRendererImpl::CreateVideoThread() { |
| 161 // This may fail and cause a crash if there are too many threads created in | 147 // This may fail and cause a crash if there are too many threads created in |
| 162 // the current process. See http://crbug.com/443291 | 148 // the current process. See http://crbug.com/443291 |
| 163 CHECK(base::PlatformThread::Create(0, this, &thread_)); | 149 CHECK(base::PlatformThread::Create(0, this, &thread_)); |
| 164 | 150 |
| 165 #if defined(OS_WIN) | 151 #if defined(OS_WIN) |
| 166 // Bump up our priority so our sleeping is more accurate. | 152 // Bump up our priority so our sleeping is more accurate. |
| 167 // TODO(scherkus): find out if this is necessary, but it seems to help. | 153 // TODO(scherkus): find out if this is necessary, but it seems to help. |
| 168 ::SetThreadPriority(thread_.platform_handle(), THREAD_PRIORITY_ABOVE_NORMAL); | 154 ::SetThreadPriority(thread_.platform_handle(), THREAD_PRIORITY_ABOVE_NORMAL); |
| 169 #endif // defined(OS_WIN) | 155 #endif // defined(OS_WIN) |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 task_runner_->PostTask(FROM_HERE, base::Bind(statistics_cb_, statistics)); | 460 task_runner_->PostTask(FROM_HERE, base::Bind(statistics_cb_, statistics)); |
| 475 | 461 |
| 476 frames_decoded_ = 0; | 462 frames_decoded_ = 0; |
| 477 frames_dropped_ = 0; | 463 frames_dropped_ = 0; |
| 478 } | 464 } |
| 479 | 465 |
| 480 frame_available_.TimedWait(wait_duration); | 466 frame_available_.TimedWait(wait_duration); |
| 481 } | 467 } |
| 482 | 468 |
| 483 } // namespace media | 469 } // namespace media |
| OLD | NEW |