| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_base.h" | 5 #include "media/filters/video_renderer_base.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/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
| 12 #include "media/base/buffers.h" | 12 #include "media/base/buffers.h" |
| 13 #include "media/base/limits.h" | 13 #include "media/base/limits.h" |
| 14 #include "media/base/pipeline.h" | 14 #include "media/base/pipeline.h" |
| 15 #include "media/base/video_frame.h" | 15 #include "media/base/video_frame.h" |
| 16 #include "media/filters/decrypting_demuxer_stream.h" | 16 #include "media/filters/decrypting_demuxer_stream.h" |
| 17 | 17 |
| 18 namespace media { | 18 namespace media { |
| 19 | 19 |
| 20 base::TimeDelta VideoRendererBase::kMaxLastFrameDuration() { | 20 base::TimeDelta VideoRendererBase::kMaxLastFrameDuration() { |
| 21 return base::TimeDelta::FromMilliseconds(250); | 21 return base::TimeDelta::FromMilliseconds(250); |
| 22 } | 22 } |
| 23 | 23 |
| 24 VideoRendererBase::VideoRendererBase( | 24 VideoRendererBase::VideoRendererBase( |
| 25 const scoped_refptr<base::MessageLoopProxy>& message_loop, | 25 const scoped_refptr<base::MessageLoopProxy>& message_loop, |
| 26 ScopedVector<VideoDecoder> decoders, |
| 26 const SetDecryptorReadyCB& set_decryptor_ready_cb, | 27 const SetDecryptorReadyCB& set_decryptor_ready_cb, |
| 27 const PaintCB& paint_cb, | 28 const PaintCB& paint_cb, |
| 28 const SetOpaqueCB& set_opaque_cb, | 29 const SetOpaqueCB& set_opaque_cb, |
| 29 bool drop_frames) | 30 bool drop_frames) |
| 30 : message_loop_(message_loop), | 31 : message_loop_(message_loop), |
| 31 weak_factory_(this), | 32 weak_factory_(this), |
| 32 video_frame_stream_(new VideoFrameStream(message_loop, | 33 video_frame_stream_(new VideoFrameStream( |
| 33 set_decryptor_ready_cb)), | 34 message_loop, decoders.Pass(), set_decryptor_ready_cb)), |
| 34 received_end_of_stream_(false), | 35 received_end_of_stream_(false), |
| 35 frame_available_(&lock_), | 36 frame_available_(&lock_), |
| 36 state_(kUninitialized), | 37 state_(kUninitialized), |
| 37 thread_(base::kNullThreadHandle), | 38 thread_(base::kNullThreadHandle), |
| 38 pending_read_(false), | 39 pending_read_(false), |
| 39 drop_frames_(drop_frames), | 40 drop_frames_(drop_frames), |
| 40 playback_rate_(0), | 41 playback_rate_(0), |
| 41 paint_cb_(paint_cb), | 42 paint_cb_(paint_cb), |
| 42 set_opaque_cb_(set_opaque_cb), | 43 set_opaque_cb_(set_opaque_cb), |
| 43 last_timestamp_(kNoTimestamp()) { | 44 last_timestamp_(kNoTimestamp()) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 DCHECK(!cb.is_null()); | 130 DCHECK(!cb.is_null()); |
| 130 DCHECK(preroll_cb_.is_null()); | 131 DCHECK(preroll_cb_.is_null()); |
| 131 | 132 |
| 132 state_ = kPrerolling; | 133 state_ = kPrerolling; |
| 133 preroll_cb_ = cb; | 134 preroll_cb_ = cb; |
| 134 preroll_timestamp_ = time; | 135 preroll_timestamp_ = time; |
| 135 AttemptRead_Locked(); | 136 AttemptRead_Locked(); |
| 136 } | 137 } |
| 137 | 138 |
| 138 void VideoRendererBase::Initialize(const scoped_refptr<DemuxerStream>& stream, | 139 void VideoRendererBase::Initialize(const scoped_refptr<DemuxerStream>& stream, |
| 139 const VideoDecoderList& decoders, | |
| 140 const PipelineStatusCB& init_cb, | 140 const PipelineStatusCB& init_cb, |
| 141 const StatisticsCB& statistics_cb, | 141 const StatisticsCB& statistics_cb, |
| 142 const TimeCB& max_time_cb, | 142 const TimeCB& max_time_cb, |
| 143 const NaturalSizeChangedCB& size_changed_cb, | 143 const NaturalSizeChangedCB& size_changed_cb, |
| 144 const base::Closure& ended_cb, | 144 const base::Closure& ended_cb, |
| 145 const PipelineStatusCB& error_cb, | 145 const PipelineStatusCB& error_cb, |
| 146 const TimeDeltaCB& get_time_cb, | 146 const TimeDeltaCB& get_time_cb, |
| 147 const TimeDeltaCB& get_duration_cb) { | 147 const TimeDeltaCB& get_duration_cb) { |
| 148 DCHECK(message_loop_->BelongsToCurrentThread()); | 148 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 149 base::AutoLock auto_lock(lock_); | 149 base::AutoLock auto_lock(lock_); |
| 150 DCHECK(stream); | 150 DCHECK(stream); |
| 151 DCHECK(!decoders.empty()); | |
| 152 DCHECK_EQ(stream->type(), DemuxerStream::VIDEO); | 151 DCHECK_EQ(stream->type(), DemuxerStream::VIDEO); |
| 153 DCHECK(!init_cb.is_null()); | 152 DCHECK(!init_cb.is_null()); |
| 154 DCHECK(!statistics_cb.is_null()); | 153 DCHECK(!statistics_cb.is_null()); |
| 155 DCHECK(!max_time_cb.is_null()); | 154 DCHECK(!max_time_cb.is_null()); |
| 156 DCHECK(!size_changed_cb.is_null()); | 155 DCHECK(!size_changed_cb.is_null()); |
| 157 DCHECK(!ended_cb.is_null()); | 156 DCHECK(!ended_cb.is_null()); |
| 158 DCHECK(!get_time_cb.is_null()); | 157 DCHECK(!get_time_cb.is_null()); |
| 159 DCHECK(!get_duration_cb.is_null()); | 158 DCHECK(!get_duration_cb.is_null()); |
| 160 DCHECK_EQ(kUninitialized, state_); | 159 DCHECK_EQ(kUninitialized, state_); |
| 161 | 160 |
| 162 weak_this_ = weak_factory_.GetWeakPtr(); | 161 weak_this_ = weak_factory_.GetWeakPtr(); |
| 163 init_cb_ = init_cb; | 162 init_cb_ = init_cb; |
| 164 statistics_cb_ = statistics_cb; | 163 statistics_cb_ = statistics_cb; |
| 165 max_time_cb_ = max_time_cb; | 164 max_time_cb_ = max_time_cb; |
| 166 size_changed_cb_ = size_changed_cb; | 165 size_changed_cb_ = size_changed_cb; |
| 167 ended_cb_ = ended_cb; | 166 ended_cb_ = ended_cb; |
| 168 error_cb_ = error_cb; | 167 error_cb_ = error_cb; |
| 169 get_time_cb_ = get_time_cb; | 168 get_time_cb_ = get_time_cb; |
| 170 get_duration_cb_ = get_duration_cb; | 169 get_duration_cb_ = get_duration_cb; |
| 171 state_ = kInitializing; | 170 state_ = kInitializing; |
| 172 | 171 |
| 173 video_frame_stream_->Initialize( | 172 video_frame_stream_->Initialize( |
| 174 stream, | 173 stream, |
| 175 decoders, | |
| 176 statistics_cb, | 174 statistics_cb, |
| 177 base::Bind(&VideoRendererBase::OnVideoFrameStreamInitialized, | 175 base::Bind(&VideoRendererBase::OnVideoFrameStreamInitialized, |
| 178 weak_this_)); | 176 weak_this_)); |
| 179 } | 177 } |
| 180 | 178 |
| 181 void VideoRendererBase::OnVideoFrameStreamInitialized(bool success, | 179 void VideoRendererBase::OnVideoFrameStreamInitialized(bool success, |
| 182 bool has_alpha) { | 180 bool has_alpha) { |
| 183 DCHECK(message_loop_->BelongsToCurrentThread()); | 181 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 184 base::AutoLock auto_lock(lock_); | 182 base::AutoLock auto_lock(lock_); |
| 185 | 183 |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 // Because we might remain in the prerolled state for an undetermined amount | 530 // Because we might remain in the prerolled state for an undetermined amount |
| 533 // of time (e.g., we seeked while paused), we'll paint the first prerolled | 531 // of time (e.g., we seeked while paused), we'll paint the first prerolled |
| 534 // frame. | 532 // frame. |
| 535 if (!ready_frames_.empty()) | 533 if (!ready_frames_.empty()) |
| 536 PaintNextReadyFrame_Locked(); | 534 PaintNextReadyFrame_Locked(); |
| 537 | 535 |
| 538 base::ResetAndReturn(&preroll_cb_).Run(PIPELINE_OK); | 536 base::ResetAndReturn(&preroll_cb_).Run(PIPELINE_OK); |
| 539 } | 537 } |
| 540 | 538 |
| 541 } // namespace media | 539 } // namespace media |
| OLD | NEW |