| 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 "content/renderer/media/capture_video_decoder.h" | 5 #include "content/renderer/media/capture_video_decoder.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "content/renderer/media/video_capture_impl_manager.h" | 9 #include "content/renderer/media/video_capture_impl_manager.h" |
| 10 #include "media/base/filter_host.h" | 10 #include "media/base/filter_host.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 vc_manager_(vc_manager), | 24 vc_manager_(vc_manager), |
| 25 capability_(capability), | 25 capability_(capability), |
| 26 natural_size_(capability.width, capability.height), | 26 natural_size_(capability.width, capability.height), |
| 27 state_(kUnInitialized), | 27 state_(kUnInitialized), |
| 28 got_first_frame_(false), | 28 got_first_frame_(false), |
| 29 video_stream_id_(video_stream_id), | 29 video_stream_id_(video_stream_id), |
| 30 capture_engine_(NULL) { | 30 capture_engine_(NULL) { |
| 31 DCHECK(vc_manager); | 31 DCHECK(vc_manager); |
| 32 } | 32 } |
| 33 | 33 |
| 34 CaptureVideoDecoder::~CaptureVideoDecoder() {} | |
| 35 | |
| 36 void CaptureVideoDecoder::Initialize( | |
| 37 media::DemuxerStream* demuxer_stream, | |
| 38 const media::PipelineStatusCB& status_cb, | |
| 39 const media::StatisticsCB& statistics_cb) { | |
| 40 message_loop_proxy_->PostTask( | |
| 41 FROM_HERE, | |
| 42 base::Bind(&CaptureVideoDecoder::InitializeOnDecoderThread, | |
| 43 this, make_scoped_refptr(demuxer_stream), | |
| 44 status_cb, statistics_cb)); | |
| 45 } | |
| 46 | |
| 47 void CaptureVideoDecoder::Read(const ReadCB& read_cb) { | |
| 48 message_loop_proxy_->PostTask( | |
| 49 FROM_HERE, | |
| 50 base::Bind(&CaptureVideoDecoder::ReadOnDecoderThread, | |
| 51 this, read_cb)); | |
| 52 } | |
| 53 | |
| 54 const gfx::Size& CaptureVideoDecoder::natural_size() { | |
| 55 return natural_size_; | |
| 56 } | |
| 57 | |
| 58 void CaptureVideoDecoder::Play(const base::Closure& callback) { | 34 void CaptureVideoDecoder::Play(const base::Closure& callback) { |
| 59 message_loop_proxy_->PostTask( | 35 message_loop_proxy_->PostTask( |
| 60 FROM_HERE, | 36 FROM_HERE, |
| 61 base::Bind(&CaptureVideoDecoder::PlayOnDecoderThread, | 37 base::Bind(&CaptureVideoDecoder::PlayOnDecoderThread, |
| 62 this, callback)); | 38 this, callback)); |
| 63 } | 39 } |
| 64 | 40 |
| 41 void CaptureVideoDecoder::Seek(base::TimeDelta time, |
| 42 const media::PipelineStatusCB& cb) { |
| 43 message_loop_proxy_->PostTask( |
| 44 FROM_HERE, |
| 45 base::Bind(&CaptureVideoDecoder::SeekOnDecoderThread, |
| 46 this, time, cb)); |
| 47 } |
| 48 |
| 65 void CaptureVideoDecoder::Pause(const base::Closure& callback) { | 49 void CaptureVideoDecoder::Pause(const base::Closure& callback) { |
| 66 message_loop_proxy_->PostTask( | 50 message_loop_proxy_->PostTask( |
| 67 FROM_HERE, | 51 FROM_HERE, |
| 68 base::Bind(&CaptureVideoDecoder::PauseOnDecoderThread, | 52 base::Bind(&CaptureVideoDecoder::PauseOnDecoderThread, |
| 69 this, callback)); | 53 this, callback)); |
| 70 } | 54 } |
| 71 | 55 |
| 72 void CaptureVideoDecoder::Flush(const base::Closure& callback) { | 56 void CaptureVideoDecoder::Flush(const base::Closure& callback) { |
| 73 message_loop_proxy_->PostTask( | 57 message_loop_proxy_->PostTask( |
| 74 FROM_HERE, | 58 FROM_HERE, |
| 75 base::Bind(&CaptureVideoDecoder::FlushOnDecoderThread, | 59 base::Bind(&CaptureVideoDecoder::FlushOnDecoderThread, |
| 76 this, callback)); | 60 this, callback)); |
| 77 } | 61 } |
| 78 | 62 |
| 79 void CaptureVideoDecoder::Stop(const base::Closure& callback) { | 63 void CaptureVideoDecoder::Stop(const base::Closure& callback) { |
| 80 message_loop_proxy_->PostTask( | 64 message_loop_proxy_->PostTask( |
| 81 FROM_HERE, | 65 FROM_HERE, |
| 82 base::Bind(&CaptureVideoDecoder::StopOnDecoderThread, | 66 base::Bind(&CaptureVideoDecoder::StopOnDecoderThread, |
| 83 this, callback)); | 67 this, callback)); |
| 84 } | 68 } |
| 85 | 69 |
| 86 void CaptureVideoDecoder::Seek(base::TimeDelta time, | 70 void CaptureVideoDecoder::Initialize( |
| 87 const media::PipelineStatusCB& cb) { | 71 media::DemuxerStream* demuxer_stream, |
| 72 const media::PipelineStatusCB& status_cb, |
| 73 const media::StatisticsCB& statistics_cb) { |
| 88 message_loop_proxy_->PostTask( | 74 message_loop_proxy_->PostTask( |
| 89 FROM_HERE, | 75 FROM_HERE, |
| 90 base::Bind(&CaptureVideoDecoder::SeekOnDecoderThread, | 76 base::Bind(&CaptureVideoDecoder::InitializeOnDecoderThread, |
| 91 this, time, cb)); | 77 this, make_scoped_refptr(demuxer_stream), |
| 78 status_cb, statistics_cb)); |
| 79 } |
| 80 |
| 81 void CaptureVideoDecoder::Read(const ReadCB& read_cb) { |
| 82 message_loop_proxy_->PostTask( |
| 83 FROM_HERE, |
| 84 base::Bind(&CaptureVideoDecoder::ReadOnDecoderThread, |
| 85 this, read_cb)); |
| 86 } |
| 87 |
| 88 const gfx::Size& CaptureVideoDecoder::natural_size() { |
| 89 return natural_size_; |
| 92 } | 90 } |
| 93 | 91 |
| 94 void CaptureVideoDecoder::OnStarted(media::VideoCapture* capture) { | 92 void CaptureVideoDecoder::OnStarted(media::VideoCapture* capture) { |
| 95 NOTIMPLEMENTED(); | 93 NOTIMPLEMENTED(); |
| 96 } | 94 } |
| 97 | 95 |
| 98 void CaptureVideoDecoder::OnStopped(media::VideoCapture* capture) { | 96 void CaptureVideoDecoder::OnStopped(media::VideoCapture* capture) { |
| 99 message_loop_proxy_->PostTask( | 97 message_loop_proxy_->PostTask( |
| 100 FROM_HERE, | 98 FROM_HERE, |
| 101 base::Bind(&CaptureVideoDecoder::OnStoppedOnDecoderThread, | 99 base::Bind(&CaptureVideoDecoder::OnStoppedOnDecoderThread, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 127 | 125 |
| 128 void CaptureVideoDecoder::OnDeviceInfoReceived( | 126 void CaptureVideoDecoder::OnDeviceInfoReceived( |
| 129 media::VideoCapture* capture, | 127 media::VideoCapture* capture, |
| 130 const media::VideoCaptureParams& device_info) { | 128 const media::VideoCaptureParams& device_info) { |
| 131 message_loop_proxy_->PostTask( | 129 message_loop_proxy_->PostTask( |
| 132 FROM_HERE, | 130 FROM_HERE, |
| 133 base::Bind(&CaptureVideoDecoder::OnDeviceInfoReceivedOnDecoderThread, | 131 base::Bind(&CaptureVideoDecoder::OnDeviceInfoReceivedOnDecoderThread, |
| 134 this, capture, device_info)); | 132 this, capture, device_info)); |
| 135 } | 133 } |
| 136 | 134 |
| 137 void CaptureVideoDecoder::InitializeOnDecoderThread( | 135 CaptureVideoDecoder::~CaptureVideoDecoder() {} |
| 138 media::DemuxerStream* demuxer_stream, | |
| 139 const media::PipelineStatusCB& status_cb, | |
| 140 const media::StatisticsCB& statistics_cb) { | |
| 141 DVLOG(1) << "InitializeOnDecoderThread"; | |
| 142 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | |
| 143 | |
| 144 capture_engine_ = vc_manager_->AddDevice(video_stream_id_, this); | |
| 145 | |
| 146 statistics_cb_ = statistics_cb; | |
| 147 status_cb.Run(media::PIPELINE_OK); | |
| 148 state_ = kNormal; | |
| 149 capture_engine_->StartCapture(this, capability_); | |
| 150 } | |
| 151 | |
| 152 void CaptureVideoDecoder::ReadOnDecoderThread(const ReadCB& read_cb) { | |
| 153 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | |
| 154 CHECK(read_cb_.is_null()); | |
| 155 read_cb_ = read_cb; | |
| 156 } | |
| 157 | 136 |
| 158 void CaptureVideoDecoder::PlayOnDecoderThread(const base::Closure& callback) { | 137 void CaptureVideoDecoder::PlayOnDecoderThread(const base::Closure& callback) { |
| 159 DVLOG(1) << "PlayOnDecoderThread"; | 138 DVLOG(1) << "PlayOnDecoderThread"; |
| 160 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 139 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 161 callback.Run(); | 140 callback.Run(); |
| 162 } | 141 } |
| 163 | 142 |
| 143 void CaptureVideoDecoder::SeekOnDecoderThread( |
| 144 base::TimeDelta time, |
| 145 const media::PipelineStatusCB& cb) { |
| 146 DVLOG(1) << "SeekOnDecoderThread"; |
| 147 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 148 |
| 149 cb.Run(media::PIPELINE_OK); |
| 150 state_ = kNormal; |
| 151 } |
| 152 |
| 164 void CaptureVideoDecoder::PauseOnDecoderThread(const base::Closure& callback) { | 153 void CaptureVideoDecoder::PauseOnDecoderThread(const base::Closure& callback) { |
| 165 DVLOG(1) << "PauseOnDecoderThread"; | 154 DVLOG(1) << "PauseOnDecoderThread"; |
| 166 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 155 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 167 state_ = kPaused; | 156 state_ = kPaused; |
| 168 callback.Run(); | 157 callback.Run(); |
| 169 } | 158 } |
| 170 | 159 |
| 171 void CaptureVideoDecoder::FlushOnDecoderThread(const base::Closure& callback) { | 160 void CaptureVideoDecoder::FlushOnDecoderThread(const base::Closure& callback) { |
| 172 DVLOG(1) << "FlushOnDecoderThread"; | 161 DVLOG(1) << "FlushOnDecoderThread"; |
| 173 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 162 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 174 if (!read_cb_.is_null()) { | 163 if (!read_cb_.is_null()) { |
| 175 scoped_refptr<media::VideoFrame> video_frame = | 164 scoped_refptr<media::VideoFrame> video_frame = |
| 176 media::VideoFrame::CreateBlackFrame(natural_size_.width(), | 165 media::VideoFrame::CreateBlackFrame(natural_size_.width(), |
| 177 natural_size_.height()); | 166 natural_size_.height()); |
| 178 DeliverFrame(video_frame); | 167 DeliverFrame(video_frame); |
| 179 } | 168 } |
| 180 media::VideoDecoder::Flush(callback); | 169 media::VideoDecoder::Flush(callback); |
| 181 } | 170 } |
| 182 | 171 |
| 183 void CaptureVideoDecoder::StopOnDecoderThread(const base::Closure& callback) { | 172 void CaptureVideoDecoder::StopOnDecoderThread(const base::Closure& callback) { |
| 184 DVLOG(1) << "StopOnDecoderThread"; | 173 DVLOG(1) << "StopOnDecoderThread"; |
| 185 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 174 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 186 pending_stop_cb_ = callback; | 175 pending_stop_cb_ = callback; |
| 187 state_ = kStopped; | 176 state_ = kStopped; |
| 188 capture_engine_->StopCapture(this); | 177 capture_engine_->StopCapture(this); |
| 189 } | 178 } |
| 190 | 179 |
| 191 void CaptureVideoDecoder::SeekOnDecoderThread( | 180 void CaptureVideoDecoder::InitializeOnDecoderThread( |
| 192 base::TimeDelta time, | 181 media::DemuxerStream* demuxer_stream, |
| 193 const media::PipelineStatusCB& cb) { | 182 const media::PipelineStatusCB& status_cb, |
| 194 DVLOG(1) << "SeekOnDecoderThread"; | 183 const media::StatisticsCB& statistics_cb) { |
| 184 DVLOG(1) << "InitializeOnDecoderThread"; |
| 195 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 185 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 196 | 186 |
| 197 cb.Run(media::PIPELINE_OK); | 187 capture_engine_ = vc_manager_->AddDevice(video_stream_id_, this); |
| 188 |
| 189 statistics_cb_ = statistics_cb; |
| 190 status_cb.Run(media::PIPELINE_OK); |
| 198 state_ = kNormal; | 191 state_ = kNormal; |
| 192 capture_engine_->StartCapture(this, capability_); |
| 193 } |
| 194 |
| 195 void CaptureVideoDecoder::ReadOnDecoderThread(const ReadCB& read_cb) { |
| 196 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 197 CHECK(read_cb_.is_null()); |
| 198 read_cb_ = read_cb; |
| 199 } | 199 } |
| 200 | 200 |
| 201 void CaptureVideoDecoder::OnStoppedOnDecoderThread( | 201 void CaptureVideoDecoder::OnStoppedOnDecoderThread( |
| 202 media::VideoCapture* capture) { | 202 media::VideoCapture* capture) { |
| 203 DVLOG(1) << "OnStoppedOnDecoderThread"; | 203 DVLOG(1) << "OnStoppedOnDecoderThread"; |
| 204 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 204 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 205 if (!pending_stop_cb_.is_null()) | 205 if (!pending_stop_cb_.is_null()) |
| 206 base::ResetAndReturn(&pending_stop_cb_).Run(); | 206 base::ResetAndReturn(&pending_stop_cb_).Run(); |
| 207 vc_manager_->RemoveDevice(video_stream_id_, this); | 207 vc_manager_->RemoveDevice(video_stream_id_, this); |
| 208 } | 208 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 274 |
| 275 DeliverFrame(video_frame); | 275 DeliverFrame(video_frame); |
| 276 capture->FeedBuffer(buf); | 276 capture->FeedBuffer(buf); |
| 277 } | 277 } |
| 278 | 278 |
| 279 void CaptureVideoDecoder::DeliverFrame( | 279 void CaptureVideoDecoder::DeliverFrame( |
| 280 const scoped_refptr<media::VideoFrame>& video_frame) { | 280 const scoped_refptr<media::VideoFrame>& video_frame) { |
| 281 // Reset the callback before running to protect against reentrancy. | 281 // Reset the callback before running to protect against reentrancy. |
| 282 base::ResetAndReturn(&read_cb_).Run(kOk, video_frame); | 282 base::ResetAndReturn(&read_cb_).Run(kOk, video_frame); |
| 283 } | 283 } |
| OLD | NEW |