Chromium Code Reviews| 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 "media/capture/video/video_capture_device_client.h" | 5 #include "media/capture/video/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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "media/base/bind_to_current_loop.h" | 17 #include "media/base/bind_to_current_loop.h" |
| 18 #include "media/base/video_frame.h" | 18 #include "media/base/video_frame.h" |
| 19 #include "media/capture/video/video_capture_buffer_handle.h" | 19 #include "media/capture/video/video_capture_buffer_handle.h" |
| 20 #include "media/capture/video/video_capture_buffer_pool.h" | 20 #include "media/capture/video/video_capture_buffer_pool.h" |
| 21 #include "media/capture/video/video_capture_jpeg_decoder.h" | 21 #include "media/capture/video/video_capture_jpeg_decoder.h" |
| 22 #include "media/capture/video/video_frame_receiver.h" | 22 #include "media/capture/video/video_frame_receiver.h" |
| 23 #include "media/capture/video_capture_types.h" | 23 #include "media/capture/video_capture_types.h" |
| 24 #include "mojo/public/cpp/system/platform_handle.h" | |
| 24 #include "third_party/libyuv/include/libyuv.h" | 25 #include "third_party/libyuv/include/libyuv.h" |
| 25 | 26 |
| 26 using media::VideoCaptureFormat; | 27 using media::VideoCaptureFormat; |
| 27 using media::VideoFrame; | 28 using media::VideoFrame; |
| 28 using media::VideoFrameMetadata; | 29 using media::VideoFrameMetadata; |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 bool IsFormatSupported(media::VideoPixelFormat pixel_format) { | 33 bool IsFormatSupported(media::VideoPixelFormat pixel_format) { |
| 33 return (pixel_format == media::PIXEL_FORMAT_I420 || | 34 return (pixel_format == media::PIXEL_FORMAT_I420 || |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 return nullptr; | 289 return nullptr; |
| 289 return base::WrapUnique<Buffer>( | 290 return base::WrapUnique<Buffer>( |
| 290 new AutoReleaseBuffer(buffer_pool_, buffer_id, frame_feedback_id)); | 291 new AutoReleaseBuffer(buffer_pool_, buffer_id, frame_feedback_id)); |
| 291 } | 292 } |
| 292 | 293 |
| 293 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer( | 294 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer( |
| 294 std::unique_ptr<Buffer> buffer, | 295 std::unique_ptr<Buffer> buffer, |
| 295 const VideoCaptureFormat& format, | 296 const VideoCaptureFormat& format, |
| 296 base::TimeTicks reference_time, | 297 base::TimeTicks reference_time, |
| 297 base::TimeDelta timestamp) { | 298 base::TimeDelta timestamp) { |
| 298 DCHECK(IsFormatSupported(format.pixel_format)); | 299 OnIncomingCapturedBufferExt(std::move(buffer), format, reference_time, |
| 299 DCHECK_EQ(media::PIXEL_STORAGE_CPU, format.pixel_storage); | 300 timestamp, gfx::Rect(format.frame_size), |
| 301 VideoFrameMetadata()); | |
| 302 } | |
| 300 | 303 |
| 301 scoped_refptr<VideoFrame> frame; | 304 void VideoCaptureDeviceClient::OnIncomingCapturedBufferExt( |
| 302 if (buffer->IsBackedByVideoFrame()) { | 305 std::unique_ptr<Buffer> buffer, |
| 303 frame = buffer->GetVideoFrame(); | 306 const VideoCaptureFormat& format, |
| 304 frame->set_timestamp(timestamp); | 307 base::TimeTicks reference_time, |
| 305 } else { | 308 base::TimeDelta timestamp, |
| 306 frame = VideoFrame::WrapExternalSharedMemory( | 309 gfx::Rect visible_rect, |
| 307 format.pixel_format, format.frame_size, gfx::Rect(format.frame_size), | 310 const VideoFrameMetadata& additional_metadata) { |
| 308 format.frame_size, reinterpret_cast<uint8_t*>(buffer->data()), | 311 scoped_refptr<media::VideoFrame> frame = |
| 309 VideoFrame::AllocationSize(format.pixel_format, format.frame_size), | 312 media::VideoFrame::WrapExternalSharedMemory( |
| 310 base::SharedMemory::NULLHandle(), 0u, timestamp); | 313 format.pixel_format, // format |
| 311 } | 314 format.frame_size, // coded_size |
| 312 if (!frame) | 315 visible_rect, // visible_rect |
| 313 return; | 316 format.frame_size, // natural_size |
| 317 static_cast<uint8_t*>(buffer->data()), // data | |
| 318 buffer->mapped_size(), // data_size | |
| 319 base::SharedMemory::NULLHandle(), // handle | |
|
miu
2017/01/10 23:32:19
This could either be great or not:
Great in that
chfremer
2017/01/10 23:45:29
In this case, I think it is okay to not attach a r
| |
| 320 0u, // shared_memory_offset | |
| 321 timestamp); // timestamp | |
| 322 frame->metadata()->MergeMetadataFrom(&additional_metadata); | |
| 314 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, | 323 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, |
| 315 format.frame_rate); | 324 format.frame_rate); |
| 316 frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, | 325 frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, |
| 317 reference_time); | 326 reference_time); |
| 318 OnIncomingCapturedVideoFrame(std::move(buffer), std::move(frame)); | |
| 319 } | |
| 320 | 327 |
| 321 void VideoCaptureDeviceClient::OnIncomingCapturedVideoFrame( | |
| 322 std::unique_ptr<Buffer> buffer, | |
| 323 scoped_refptr<VideoFrame> frame) { | |
| 324 receiver_->OnIncomingCapturedVideoFrame(std::move(buffer), std::move(frame)); | 328 receiver_->OnIncomingCapturedVideoFrame(std::move(buffer), std::move(frame)); |
| 325 } | 329 } |
| 326 | 330 |
| 327 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> | 331 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> |
| 328 VideoCaptureDeviceClient::ResurrectLastOutputBuffer( | 332 VideoCaptureDeviceClient::ResurrectLastOutputBuffer( |
| 329 const gfx::Size& dimensions, | 333 const gfx::Size& dimensions, |
| 330 media::VideoPixelFormat format, | 334 media::VideoPixelFormat format, |
| 331 media::VideoPixelStorage storage, | 335 media::VideoPixelStorage storage, |
| 332 int new_frame_feedback_id) { | 336 int new_frame_feedback_id) { |
| 333 const int buffer_id = | 337 const int buffer_id = |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 return; | 415 return; |
| 412 memcpy(buffer->data(), data, length); | 416 memcpy(buffer->data(), data, length); |
| 413 const VideoCaptureFormat output_format = | 417 const VideoCaptureFormat output_format = |
| 414 VideoCaptureFormat(format.frame_size, format.frame_rate, | 418 VideoCaptureFormat(format.frame_size, format.frame_rate, |
| 415 media::PIXEL_FORMAT_Y16, media::PIXEL_STORAGE_CPU); | 419 media::PIXEL_FORMAT_Y16, media::PIXEL_STORAGE_CPU); |
| 416 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, | 420 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, |
| 417 timestamp); | 421 timestamp); |
| 418 } | 422 } |
| 419 | 423 |
| 420 } // namespace media | 424 } // namespace media |
| OLD | NEW |