| 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/demuxer_stream.h" | 10 #include "media/base/demuxer_stream.h" |
| 11 #include "media/base/limits.h" | 11 #include "media/base/limits.h" |
| 12 #include "media/base/video_util.h" | 12 #include "media/base/video_util.h" |
| 13 | 13 |
| 14 using media::CopyYPlane; | 14 using media::CopyYPlane; |
| 15 using media::CopyUPlane; | 15 using media::CopyUPlane; |
| 16 using media::CopyVPlane; | 16 using media::CopyVPlane; |
| 17 | 17 |
| 18 CaptureVideoDecoder::CaptureVideoDecoder( | 18 CaptureVideoDecoder::CaptureVideoDecoder( |
| 19 base::MessageLoopProxy* message_loop_proxy, | 19 base::MessageLoopProxy* message_loop_proxy, |
| 20 media::VideoCaptureSessionId video_stream_id, | 20 media::VideoCaptureSessionId video_stream_id, |
| 21 VideoCaptureImplManager* vc_manager, | 21 VideoCaptureImplManager* vc_manager, |
| 22 const media::VideoCaptureCapability& capability) | 22 const media::VideoCaptureCapability& capability) |
| 23 : message_loop_proxy_(message_loop_proxy), | 23 : message_loop_proxy_(message_loop_proxy), |
| 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 shutting_down_(false), | |
| 30 video_stream_id_(video_stream_id), | 29 video_stream_id_(video_stream_id), |
| 31 capture_engine_(NULL) { | 30 capture_engine_(NULL) { |
| 32 DCHECK(vc_manager); | 31 DCHECK(vc_manager); |
| 33 } | 32 } |
| 34 | 33 |
| 35 void CaptureVideoDecoder::Initialize( | 34 void CaptureVideoDecoder::Initialize( |
| 36 const scoped_refptr<media::DemuxerStream>& stream, | 35 const scoped_refptr<media::DemuxerStream>& stream, |
| 37 const media::PipelineStatusCB& status_cb, | 36 const media::PipelineStatusCB& status_cb, |
| 38 const media::StatisticsCB& statistics_cb) { | 37 const media::StatisticsCB& statistics_cb) { |
| 39 message_loop_proxy_->PostTask( | 38 message_loop_proxy_->PostTask( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 54 FROM_HERE, | 53 FROM_HERE, |
| 55 base::Bind(&CaptureVideoDecoder::ResetOnDecoderThread, this, closure)); | 54 base::Bind(&CaptureVideoDecoder::ResetOnDecoderThread, this, closure)); |
| 56 } | 55 } |
| 57 | 56 |
| 58 void CaptureVideoDecoder::Stop(const base::Closure& closure) { | 57 void CaptureVideoDecoder::Stop(const base::Closure& closure) { |
| 59 message_loop_proxy_->PostTask( | 58 message_loop_proxy_->PostTask( |
| 60 FROM_HERE, | 59 FROM_HERE, |
| 61 base::Bind(&CaptureVideoDecoder::StopOnDecoderThread, this, closure)); | 60 base::Bind(&CaptureVideoDecoder::StopOnDecoderThread, this, closure)); |
| 62 } | 61 } |
| 63 | 62 |
| 64 void CaptureVideoDecoder::PrepareForShutdownHack() { | |
| 65 message_loop_proxy_->PostTask( | |
| 66 FROM_HERE, | |
| 67 base::Bind(&CaptureVideoDecoder::PrepareForShutdownHackOnDecoderThread, | |
| 68 this)); | |
| 69 } | |
| 70 | |
| 71 void CaptureVideoDecoder::OnStarted(media::VideoCapture* capture) { | 63 void CaptureVideoDecoder::OnStarted(media::VideoCapture* capture) { |
| 72 NOTIMPLEMENTED(); | 64 NOTIMPLEMENTED(); |
| 73 } | 65 } |
| 74 | 66 |
| 75 void CaptureVideoDecoder::OnStopped(media::VideoCapture* capture) { | 67 void CaptureVideoDecoder::OnStopped(media::VideoCapture* capture) { |
| 76 message_loop_proxy_->PostTask( | 68 message_loop_proxy_->PostTask( |
| 77 FROM_HERE, | 69 FROM_HERE, |
| 78 base::Bind(&CaptureVideoDecoder::OnStoppedOnDecoderThread, | 70 base::Bind(&CaptureVideoDecoder::OnStoppedOnDecoderThread, |
| 79 this, capture)); | 71 this, capture)); |
| 80 } | 72 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 status_cb.Run(media::PIPELINE_OK); | 124 status_cb.Run(media::PIPELINE_OK); |
| 133 state_ = kNormal; | 125 state_ = kNormal; |
| 134 capture_engine_->StartCapture(this, capability_); | 126 capture_engine_->StartCapture(this, capability_); |
| 135 } | 127 } |
| 136 | 128 |
| 137 void CaptureVideoDecoder::ReadOnDecoderThread(const ReadCB& read_cb) { | 129 void CaptureVideoDecoder::ReadOnDecoderThread(const ReadCB& read_cb) { |
| 138 DCHECK_NE(state_, kUnInitialized); | 130 DCHECK_NE(state_, kUnInitialized); |
| 139 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 131 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 140 CHECK(read_cb_.is_null()); | 132 CHECK(read_cb_.is_null()); |
| 141 read_cb_ = read_cb; | 133 read_cb_ = read_cb; |
| 142 if (state_ == kPaused || shutting_down_) { | 134 if (state_ == kPaused || state_ == kStopped) { |
| 143 DeliverFrame(media::VideoFrame::CreateEmptyFrame()); | 135 DeliverFrame(media::VideoFrame::CreateEmptyFrame()); |
| 144 } | 136 } |
| 145 } | 137 } |
| 146 | 138 |
| 147 void CaptureVideoDecoder::ResetOnDecoderThread(const base::Closure& closure) { | 139 void CaptureVideoDecoder::ResetOnDecoderThread(const base::Closure& closure) { |
| 148 DVLOG(1) << "ResetOnDecoderThread"; | 140 DVLOG(1) << "ResetOnDecoderThread"; |
| 149 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 141 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 150 if (!read_cb_.is_null()) { | 142 if (!read_cb_.is_null()) { |
| 151 scoped_refptr<media::VideoFrame> video_frame = | 143 scoped_refptr<media::VideoFrame> video_frame = |
| 152 media::VideoFrame::CreateBlackFrame(natural_size_); | 144 media::VideoFrame::CreateBlackFrame(natural_size_); |
| 153 DeliverFrame(video_frame); | 145 DeliverFrame(video_frame); |
| 154 } | 146 } |
| 155 closure.Run(); | 147 closure.Run(); |
| 156 } | 148 } |
| 157 | 149 |
| 158 void CaptureVideoDecoder::StopOnDecoderThread(const base::Closure& closure) { | 150 void CaptureVideoDecoder::StopOnDecoderThread(const base::Closure& closure) { |
| 159 DVLOG(1) << "StopOnDecoderThread"; | 151 DVLOG(1) << "StopOnDecoderThread"; |
| 160 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 152 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 161 pending_stop_cb_ = closure; | 153 pending_stop_cb_ = closure; |
| 162 state_ = kStopped; | 154 state_ = kStopped; |
| 155 |
| 156 if (!read_cb_.is_null()) |
| 157 DeliverFrame(media::VideoFrame::CreateEmptyFrame()); |
| 158 |
| 163 capture_engine_->StopCapture(this); | 159 capture_engine_->StopCapture(this); |
| 164 } | 160 } |
| 165 | 161 |
| 166 void CaptureVideoDecoder::PrepareForShutdownHackOnDecoderThread() { | |
| 167 DVLOG(1) << "PrepareForShutdownHackOnDecoderThread"; | |
| 168 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | |
| 169 shutting_down_ = true; | |
| 170 if (!read_cb_.is_null()) { | |
| 171 DeliverFrame(media::VideoFrame::CreateEmptyFrame()); | |
| 172 } | |
| 173 } | |
| 174 | |
| 175 void CaptureVideoDecoder::OnStoppedOnDecoderThread( | 162 void CaptureVideoDecoder::OnStoppedOnDecoderThread( |
| 176 media::VideoCapture* capture) { | 163 media::VideoCapture* capture) { |
| 177 DVLOG(1) << "OnStoppedOnDecoderThread"; | 164 DVLOG(1) << "OnStoppedOnDecoderThread"; |
| 178 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 165 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 179 if (!pending_stop_cb_.is_null()) | 166 if (!pending_stop_cb_.is_null()) |
| 180 base::ResetAndReturn(&pending_stop_cb_).Run(); | 167 base::ResetAndReturn(&pending_stop_cb_).Run(); |
| 181 vc_manager_->RemoveDevice(video_stream_id_, this); | 168 vc_manager_->RemoveDevice(video_stream_id_, this); |
| 182 } | 169 } |
| 183 | 170 |
| 184 void CaptureVideoDecoder::OnPausedOnDecoderThread( | 171 void CaptureVideoDecoder::OnPausedOnDecoderThread( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 244 |
| 258 DeliverFrame(video_frame); | 245 DeliverFrame(video_frame); |
| 259 capture->FeedBuffer(buf); | 246 capture->FeedBuffer(buf); |
| 260 } | 247 } |
| 261 | 248 |
| 262 void CaptureVideoDecoder::DeliverFrame( | 249 void CaptureVideoDecoder::DeliverFrame( |
| 263 const scoped_refptr<media::VideoFrame>& video_frame) { | 250 const scoped_refptr<media::VideoFrame>& video_frame) { |
| 264 // Reset the callback before running to protect against reentrancy. | 251 // Reset the callback before running to protect against reentrancy. |
| 265 base::ResetAndReturn(&read_cb_).Run(kOk, video_frame); | 252 base::ResetAndReturn(&read_cb_).Run(kOk, video_frame); |
| 266 } | 253 } |
| OLD | NEW |