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" |
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::VideoCapture::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 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 } |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 natural_size_.width(), | 254 natural_size_.width(), |
255 natural_size_.height(), | 255 natural_size_.height(), |
256 buf->timestamp - start_time_, | 256 buf->timestamp - start_time_, |
257 base::TimeDelta::FromMilliseconds(0)); | 257 base::TimeDelta::FromMilliseconds(0)); |
258 | 258 |
259 last_frame_timestamp_ = buf->timestamp; | 259 last_frame_timestamp_ = buf->timestamp; |
260 uint8* buffer = buf->memory_pointer; | 260 uint8* buffer = buf->memory_pointer; |
261 | 261 |
262 // Assume YV12 format. Note that camera gives YUV and media pipeline video | 262 // Assume YV12 format. Note that camera gives YUV and media pipeline video |
263 // renderer asks for YVU. The following code did the conversion. | 263 // renderer asks for YVU. The following code did the conversion. |
264 DCHECK_EQ(capability_.raw_type, media::VideoFrame::I420); | 264 DCHECK_EQ(capability_.color, media::VideoFrame::I420); |
265 int y_width = buf->width; | 265 int y_width = buf->width; |
266 int y_height = buf->height; | 266 int y_height = buf->height; |
267 int uv_width = buf->width / 2; | 267 int uv_width = buf->width / 2; |
268 int uv_height = buf->height / 2; // YV12 format. | 268 int uv_height = buf->height / 2; // YV12 format. |
269 CopyYPlane(buffer, y_width, y_height, video_frame); | 269 CopyYPlane(buffer, y_width, y_height, video_frame); |
270 buffer += y_width * y_height; | 270 buffer += y_width * y_height; |
271 CopyUPlane(buffer, uv_width, uv_height, video_frame); | 271 CopyUPlane(buffer, uv_width, uv_height, video_frame); |
272 buffer += uv_width * uv_height; | 272 buffer += uv_width * uv_height; |
273 CopyVPlane(buffer, uv_width, uv_height, video_frame); | 273 CopyVPlane(buffer, uv_width, uv_height, video_frame); |
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 ReadCB read_cb = read_cb_; | 282 ReadCB read_cb = read_cb_; |
283 read_cb_.Reset(); | 283 read_cb_.Reset(); |
284 read_cb.Run(video_frame); | 284 read_cb.Run(video_frame); |
285 } | 285 } |
OLD | NEW |