OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/browser/renderer_host/media/video_capture_device_client.h" | 5 #include "content/browser/renderer_host/media/video_capture_device_client.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 void VideoCaptureDeviceClient::OnIncomingCapturedData( | 82 void VideoCaptureDeviceClient::OnIncomingCapturedData( |
83 const uint8_t* data, | 83 const uint8_t* data, |
84 int length, | 84 int length, |
85 const VideoCaptureFormat& frame_format, | 85 const VideoCaptureFormat& frame_format, |
86 int rotation, | 86 int rotation, |
87 const base::TimeTicks& timestamp) { | 87 const base::TimeTicks& timestamp) { |
88 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedData"); | 88 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedData"); |
89 DCHECK_EQ(media::PIXEL_STORAGE_CPU, frame_format.pixel_storage); | 89 DCHECK_EQ(media::PIXEL_STORAGE_CPU, frame_format.pixel_storage); |
90 | 90 |
91 if (last_captured_pixel_format_ != frame_format.pixel_format) { | 91 if (last_captured_pixel_format_ != frame_format.pixel_format) { |
92 OnLog("Pixel format: " + | 92 OnLog(media::VideoPixelFormatToString(frame_format.pixel_format)); |
perkj_chrome
2016/02/12 11:01:40
Does VideoPixelFormatToString include a descriptio
mcasas
2016/02/12 21:32:43
Done.
| |
93 media::VideoPixelFormatToString(frame_format.pixel_format)); | |
94 last_captured_pixel_format_ = frame_format.pixel_format; | 93 last_captured_pixel_format_ = frame_format.pixel_format; |
95 | 94 |
96 if (frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG && | 95 if (frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG && |
97 !external_jpeg_decoder_initialized_) { | 96 !external_jpeg_decoder_initialized_) { |
98 external_jpeg_decoder_initialized_ = true; | 97 external_jpeg_decoder_initialized_ = true; |
99 external_jpeg_decoder_.reset(new VideoCaptureGpuJpegDecoder(base::Bind( | 98 external_jpeg_decoder_.reset(new VideoCaptureGpuJpegDecoder(base::Bind( |
100 &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread, | 99 &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread, |
101 controller_))); | 100 controller_))); |
102 external_jpeg_decoder_->Initialize(); | 101 external_jpeg_decoder_->Initialize(); |
103 } | 102 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 // Windows RGB24 defines blue at lowest byte, | 180 // Windows RGB24 defines blue at lowest byte, |
182 // see https://msdn.microsoft.com/en-us/library/windows/desktop/dd407253 | 181 // see https://msdn.microsoft.com/en-us/library/windows/desktop/dd407253 |
183 #if defined(OS_LINUX) | 182 #if defined(OS_LINUX) |
184 origin_colorspace = libyuv::FOURCC_RAW; | 183 origin_colorspace = libyuv::FOURCC_RAW; |
185 #elif defined(OS_WIN) | 184 #elif defined(OS_WIN) |
186 origin_colorspace = libyuv::FOURCC_24BG; | 185 origin_colorspace = libyuv::FOURCC_24BG; |
187 #else | 186 #else |
188 NOTREACHED() << "RGB24 is only available in Linux and Windows platforms"; | 187 NOTREACHED() << "RGB24 is only available in Linux and Windows platforms"; |
189 #endif | 188 #endif |
190 #if defined(OS_WIN) | 189 #if defined(OS_WIN) |
191 // TODO(wjia): Currently, for RGB24 on WIN, capture device always | 190 // TODO(wjia): Currently, for RGB24 on WIN, capture device always passes |
192 // passes in positive src_width and src_height. Remove this hardcoded | 191 // in positive src_width and src_height. Remove this hardcoded value when |
193 // value when nagative src_height is supported. The negative src_height | 192 // nagative src_height is supported. The negative src_height indicates |
perkj_chrome
2016/02/12 11:01:40
nit s nagative negative
mcasas
2016/02/12 21:32:43
Done.
| |
194 // indicates that vertical flipping is needed. | 193 // that vertical flipping is needed. |
195 flip = true; | 194 flip = true; |
196 #endif | 195 #endif |
197 break; | 196 break; |
198 case media::PIXEL_FORMAT_RGB32: | 197 case media::PIXEL_FORMAT_RGB32: |
199 // Fallback to PIXEL_FORMAT_ARGB setting |flip| in Windows | 198 // Fallback to PIXEL_FORMAT_ARGB setting |flip| in Windows |
200 // platforms. | 199 // platforms. |
201 #if defined(OS_WIN) | 200 #if defined(OS_WIN) |
202 flip = true; | 201 flip = true; |
203 #endif | 202 #endif |
204 case media::PIXEL_FORMAT_ARGB: | 203 case media::PIXEL_FORMAT_ARGB: |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 << media::VideoPixelFormatToString(frame_format.pixel_format); | 248 << media::VideoPixelFormatToString(frame_format.pixel_format); |
250 return; | 249 return; |
251 } | 250 } |
252 | 251 |
253 const VideoCaptureFormat output_format = VideoCaptureFormat( | 252 const VideoCaptureFormat output_format = VideoCaptureFormat( |
254 dimensions, frame_format.frame_rate, | 253 dimensions, frame_format.frame_rate, |
255 media::PIXEL_FORMAT_I420, output_pixel_storage); | 254 media::PIXEL_FORMAT_I420, output_pixel_storage); |
256 OnIncomingCapturedBuffer(std::move(buffer), output_format, timestamp); | 255 OnIncomingCapturedBuffer(std::move(buffer), output_format, timestamp); |
257 } | 256 } |
258 | 257 |
259 void VideoCaptureDeviceClient::OnIncomingCapturedYuvData( | |
260 const uint8_t* y_data, | |
261 const uint8_t* u_data, | |
262 const uint8_t* v_data, | |
263 size_t y_stride, | |
264 size_t u_stride, | |
265 size_t v_stride, | |
266 const VideoCaptureFormat& frame_format, | |
267 int clockwise_rotation, | |
268 const base::TimeTicks& timestamp) { | |
269 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedYuvData"); | |
270 DCHECK_EQ(media::PIXEL_FORMAT_I420, frame_format.pixel_format); | |
271 DCHECK_EQ(media::PIXEL_STORAGE_CPU, frame_format.pixel_storage); | |
272 DCHECK_EQ(0, clockwise_rotation) << "Rotation not supported"; | |
273 | |
274 uint8_t *y_plane_data, *u_plane_data, *v_plane_data; | |
275 scoped_ptr<Buffer> buffer(ReserveI420OutputBuffer( | |
276 frame_format.frame_size, frame_format.pixel_storage, &y_plane_data, | |
277 &u_plane_data, &v_plane_data)); | |
278 if (!buffer.get()) | |
279 return; | |
280 | |
281 const size_t dst_y_stride = | |
282 VideoFrame::RowBytes(VideoFrame::kYPlane, media::PIXEL_FORMAT_I420, | |
283 frame_format.frame_size.width()); | |
284 const size_t dst_u_stride = | |
285 VideoFrame::RowBytes(VideoFrame::kUPlane, media::PIXEL_FORMAT_I420, | |
286 frame_format.frame_size.width()); | |
287 const size_t dst_v_stride = | |
288 VideoFrame::RowBytes(VideoFrame::kVPlane, media::PIXEL_FORMAT_I420, | |
289 frame_format.frame_size.width()); | |
290 DCHECK_GE(y_stride, dst_y_stride); | |
291 DCHECK_GE(u_stride, dst_u_stride); | |
292 DCHECK_GE(v_stride, dst_v_stride); | |
293 | |
294 if (libyuv::I420Copy(y_data, y_stride, | |
295 u_data, u_stride, | |
296 v_data, v_stride, | |
297 y_plane_data, dst_y_stride, | |
298 u_plane_data, dst_u_stride, | |
299 v_plane_data, dst_v_stride, | |
300 frame_format.frame_size.width(), | |
301 frame_format.frame_size.height())) { | |
302 DLOG(WARNING) << "Failed to copy buffer"; | |
303 return; | |
304 } | |
305 | |
306 OnIncomingCapturedBuffer(std::move(buffer), frame_format, timestamp); | |
307 }; | |
308 | |
309 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> | 258 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> |
310 VideoCaptureDeviceClient::ReserveOutputBuffer( | 259 VideoCaptureDeviceClient::ReserveOutputBuffer( |
311 const gfx::Size& frame_size, | 260 const gfx::Size& frame_size, |
312 media::VideoPixelFormat pixel_format, | 261 media::VideoPixelFormat pixel_format, |
313 media::VideoPixelStorage pixel_storage) { | 262 media::VideoPixelStorage pixel_storage) { |
314 DCHECK_GT(frame_size.width(), 0); | 263 DCHECK_GT(frame_size.width(), 0); |
315 DCHECK_GT(frame_size.height(), 0); | 264 DCHECK_GT(frame_size.height(), 0); |
316 // Currently, only I420 pixel format is supported. | 265 // Currently, only I420 pixel format is supported. |
317 DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format); | 266 DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format); |
318 | 267 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kUPlane)); | 405 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kUPlane)); |
457 *v_plane_data = | 406 *v_plane_data = |
458 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kVPlane)); | 407 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kVPlane)); |
459 return buffer; | 408 return buffer; |
460 } | 409 } |
461 NOTREACHED(); | 410 NOTREACHED(); |
462 return scoped_ptr<Buffer>(); | 411 return scoped_ptr<Buffer>(); |
463 } | 412 } |
464 | 413 |
465 } // namespace content | 414 } // namespace content |
OLD | NEW |