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" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 FROM_HERE, | 54 FROM_HERE, |
55 base::Bind(&CaptureVideoDecoder::ResetOnDecoderThread, this, closure)); | 55 base::Bind(&CaptureVideoDecoder::ResetOnDecoderThread, this, closure)); |
56 } | 56 } |
57 | 57 |
58 void CaptureVideoDecoder::Stop(const base::Closure& closure) { | 58 void CaptureVideoDecoder::Stop(const base::Closure& closure) { |
59 message_loop_proxy_->PostTask( | 59 message_loop_proxy_->PostTask( |
60 FROM_HERE, | 60 FROM_HERE, |
61 base::Bind(&CaptureVideoDecoder::StopOnDecoderThread, this, closure)); | 61 base::Bind(&CaptureVideoDecoder::StopOnDecoderThread, this, closure)); |
62 } | 62 } |
63 | 63 |
64 const gfx::Size& CaptureVideoDecoder::natural_size() { | |
65 return natural_size_; | |
66 } | |
67 | |
68 void CaptureVideoDecoder::PrepareForShutdownHack() { | 64 void CaptureVideoDecoder::PrepareForShutdownHack() { |
69 message_loop_proxy_->PostTask( | 65 message_loop_proxy_->PostTask( |
70 FROM_HERE, | 66 FROM_HERE, |
71 base::Bind(&CaptureVideoDecoder::PrepareForShutdownHackOnDecoderThread, | 67 base::Bind(&CaptureVideoDecoder::PrepareForShutdownHackOnDecoderThread, |
72 this)); | 68 this)); |
73 } | 69 } |
74 | 70 |
75 void CaptureVideoDecoder::OnStarted(media::VideoCapture* capture) { | 71 void CaptureVideoDecoder::OnStarted(media::VideoCapture* capture) { |
76 NOTIMPLEMENTED(); | 72 NOTIMPLEMENTED(); |
77 } | 73 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 if (state_ == kPaused || shutting_down_) { | 141 if (state_ == kPaused || shutting_down_) { |
146 DeliverFrame(media::VideoFrame::CreateEmptyFrame()); | 142 DeliverFrame(media::VideoFrame::CreateEmptyFrame()); |
147 } | 143 } |
148 } | 144 } |
149 | 145 |
150 void CaptureVideoDecoder::ResetOnDecoderThread(const base::Closure& closure) { | 146 void CaptureVideoDecoder::ResetOnDecoderThread(const base::Closure& closure) { |
151 DVLOG(1) << "ResetOnDecoderThread"; | 147 DVLOG(1) << "ResetOnDecoderThread"; |
152 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 148 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
153 if (!read_cb_.is_null()) { | 149 if (!read_cb_.is_null()) { |
154 scoped_refptr<media::VideoFrame> video_frame = | 150 scoped_refptr<media::VideoFrame> video_frame = |
155 media::VideoFrame::CreateBlackFrame(natural_size_.width(), | 151 media::VideoFrame::CreateBlackFrame(natural_size_); |
156 natural_size_.height()); | |
157 DeliverFrame(video_frame); | 152 DeliverFrame(video_frame); |
158 } | 153 } |
159 closure.Run(); | 154 closure.Run(); |
160 } | 155 } |
161 | 156 |
162 void CaptureVideoDecoder::StopOnDecoderThread(const base::Closure& closure) { | 157 void CaptureVideoDecoder::StopOnDecoderThread(const base::Closure& closure) { |
163 DVLOG(1) << "StopOnDecoderThread"; | 158 DVLOG(1) << "StopOnDecoderThread"; |
164 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 159 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
165 pending_stop_cb_ = closure; | 160 pending_stop_cb_ = closure; |
166 state_ = kStopped; | 161 state_ = kStopped; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 if (!got_first_frame_) { | 228 if (!got_first_frame_) { |
234 start_time_ = buf->timestamp; | 229 start_time_ = buf->timestamp; |
235 got_first_frame_ = true; | 230 got_first_frame_ = true; |
236 } | 231 } |
237 | 232 |
238 // Always allocate a new frame. | 233 // Always allocate a new frame. |
239 // | 234 // |
240 // TODO(scherkus): migrate this to proper buffer recycling. | 235 // TODO(scherkus): migrate this to proper buffer recycling. |
241 scoped_refptr<media::VideoFrame> video_frame = | 236 scoped_refptr<media::VideoFrame> video_frame = |
242 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, | 237 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
243 natural_size_.width(), | 238 natural_size_, natural_size_, |
244 natural_size_.height(), | |
245 buf->timestamp - start_time_); | 239 buf->timestamp - start_time_); |
246 | 240 |
247 last_frame_timestamp_ = buf->timestamp; | 241 last_frame_timestamp_ = buf->timestamp; |
248 uint8* buffer = buf->memory_pointer; | 242 uint8* buffer = buf->memory_pointer; |
249 | 243 |
250 // Assume YV12 format. Note that camera gives YUV and media pipeline video | 244 // Assume YV12 format. Note that camera gives YUV and media pipeline video |
251 // renderer asks for YVU. The following code did the conversion. | 245 // renderer asks for YVU. The following code did the conversion. |
252 DCHECK_EQ(capability_.color, media::VideoCaptureCapability::kI420); | 246 DCHECK_EQ(capability_.color, media::VideoCaptureCapability::kI420); |
253 int y_width = buf->width; | 247 int y_width = buf->width; |
254 int y_height = buf->height; | 248 int y_height = buf->height; |
255 int uv_width = buf->width / 2; | 249 int uv_width = buf->width / 2; |
256 int uv_height = buf->height / 2; // YV12 format. | 250 int uv_height = buf->height / 2; // YV12 format. |
257 CopyYPlane(buffer, y_width, y_height, video_frame); | 251 CopyYPlane(buffer, y_width, y_height, video_frame); |
258 buffer += y_width * y_height; | 252 buffer += y_width * y_height; |
259 CopyUPlane(buffer, uv_width, uv_height, video_frame); | 253 CopyUPlane(buffer, uv_width, uv_height, video_frame); |
260 buffer += uv_width * uv_height; | 254 buffer += uv_width * uv_height; |
261 CopyVPlane(buffer, uv_width, uv_height, video_frame); | 255 CopyVPlane(buffer, uv_width, uv_height, video_frame); |
262 | 256 |
263 DeliverFrame(video_frame); | 257 DeliverFrame(video_frame); |
264 capture->FeedBuffer(buf); | 258 capture->FeedBuffer(buf); |
265 } | 259 } |
266 | 260 |
267 void CaptureVideoDecoder::DeliverFrame( | 261 void CaptureVideoDecoder::DeliverFrame( |
268 const scoped_refptr<media::VideoFrame>& video_frame) { | 262 const scoped_refptr<media::VideoFrame>& video_frame) { |
269 // Reset the callback before running to protect against reentrancy. | 263 // Reset the callback before running to protect against reentrancy. |
270 base::ResetAndReturn(&read_cb_).Run(kOk, video_frame); | 264 base::ResetAndReturn(&read_cb_).Run(kOk, video_frame); |
271 } | 265 } |
OLD | NEW |