Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: media/capture/video/video_capture_device_client.cc

Issue 2378943002: Let clients interact with VideoCaptureDeviceClient instead of VideoCaptureDevice (Closed)
Patch Set: mcasas comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 size_t mapped_size() const override { return buffer_handle_->mapped_size(); } 46 size_t mapped_size() const override { return buffer_handle_->mapped_size(); }
47 void* data(int plane) override { return buffer_handle_->data(plane); } 47 void* data(int plane) override { return buffer_handle_->data(plane); }
48 ClientBuffer AsClientBuffer(int plane) override { 48 ClientBuffer AsClientBuffer(int plane) override {
49 return buffer_handle_->AsClientBuffer(plane); 49 return buffer_handle_->AsClientBuffer(plane);
50 } 50 }
51 #if defined(OS_POSIX) && !defined(OS_MACOSX) 51 #if defined(OS_POSIX) && !defined(OS_MACOSX)
52 base::FileDescriptor AsPlatformFile() override { 52 base::FileDescriptor AsPlatformFile() override {
53 return buffer_handle_->AsPlatformFile(); 53 return buffer_handle_->AsPlatformFile();
54 } 54 }
55 #endif 55 #endif
56 bool IsBackedByVideoFrame() const override {
57 return buffer_handle_->IsBackedByVideoFrame();
58 }
59 scoped_refptr<VideoFrame> GetVideoFrame() override {
60 return buffer_handle_->GetVideoFrame();
61 }
56 62
57 private: 63 private:
58 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); } 64 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); }
59 65
60 const int id_; 66 const int id_;
61 const scoped_refptr<VideoCaptureBufferPool> pool_; 67 const scoped_refptr<VideoCaptureBufferPool> pool_;
62 const std::unique_ptr<VideoCaptureBufferHandle> buffer_handle_; 68 const std::unique_ptr<VideoCaptureBufferHandle> buffer_handle_;
63 }; 69 };
64 70
65 VideoCaptureDeviceClient::VideoCaptureDeviceClient( 71 VideoCaptureDeviceClient::VideoCaptureDeviceClient(
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 284
279 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer( 285 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer(
280 std::unique_ptr<Buffer> buffer, 286 std::unique_ptr<Buffer> buffer,
281 const VideoCaptureFormat& frame_format, 287 const VideoCaptureFormat& frame_format,
282 base::TimeTicks reference_time, 288 base::TimeTicks reference_time,
283 base::TimeDelta timestamp) { 289 base::TimeDelta timestamp) {
284 // Currently, only I420 pixel format is supported. 290 // Currently, only I420 pixel format is supported.
285 DCHECK_EQ(media::PIXEL_FORMAT_I420, frame_format.pixel_format); 291 DCHECK_EQ(media::PIXEL_FORMAT_I420, frame_format.pixel_format);
286 292
287 scoped_refptr<VideoFrame> frame; 293 scoped_refptr<VideoFrame> frame;
288 switch (frame_format.pixel_storage) { 294 if (buffer->IsBackedByVideoFrame()) {
289 case media::PIXEL_STORAGE_GPUMEMORYBUFFER: { 295 frame = buffer->GetVideoFrame();
290 // Create a VideoFrame to set the correct storage_type and pixel_format. 296 frame->set_timestamp(timestamp);
291 gfx::GpuMemoryBufferHandle handle; 297 } else {
292 frame = VideoFrame::WrapExternalYuvGpuMemoryBuffers( 298 switch (frame_format.pixel_storage) {
293 media::PIXEL_FORMAT_I420, frame_format.frame_size, 299 case media::PIXEL_STORAGE_GPUMEMORYBUFFER: {
294 gfx::Rect(frame_format.frame_size), frame_format.frame_size, 0, 0, 0, 300 // Create a VideoFrame to set the correct storage_type and pixel_format.
295 reinterpret_cast<uint8_t*>(buffer->data(media::VideoFrame::kYPlane)), 301 gfx::GpuMemoryBufferHandle handle;
296 reinterpret_cast<uint8_t*>(buffer->data(media::VideoFrame::kUPlane)), 302 frame = VideoFrame::WrapExternalYuvGpuMemoryBuffers(
297 reinterpret_cast<uint8_t*>(buffer->data(media::VideoFrame::kVPlane)), 303 media::PIXEL_FORMAT_I420, frame_format.frame_size,
298 handle, handle, handle, timestamp); 304 gfx::Rect(frame_format.frame_size), frame_format.frame_size, 0, 0,
299 break; 305 0, reinterpret_cast<uint8_t*>(
306 buffer->data(media::VideoFrame::kYPlane)),
307 reinterpret_cast<uint8_t*>(
308 buffer->data(media::VideoFrame::kUPlane)),
309 reinterpret_cast<uint8_t*>(
310 buffer->data(media::VideoFrame::kVPlane)),
311 handle, handle, handle, timestamp);
312 break;
313 }
314 case media::PIXEL_STORAGE_CPU:
315 frame = VideoFrame::WrapExternalSharedMemory(
316 media::PIXEL_FORMAT_I420, frame_format.frame_size,
317 gfx::Rect(frame_format.frame_size), frame_format.frame_size,
318 reinterpret_cast<uint8_t*>(buffer->data()),
319 VideoFrame::AllocationSize(media::PIXEL_FORMAT_I420,
320 frame_format.frame_size),
321 base::SharedMemory::NULLHandle(), 0u, timestamp);
322 break;
300 } 323 }
301 case media::PIXEL_STORAGE_CPU:
302 frame = VideoFrame::WrapExternalSharedMemory(
303 media::PIXEL_FORMAT_I420, frame_format.frame_size,
304 gfx::Rect(frame_format.frame_size), frame_format.frame_size,
305 reinterpret_cast<uint8_t*>(buffer->data()),
306 VideoFrame::AllocationSize(media::PIXEL_FORMAT_I420,
307 frame_format.frame_size),
308 base::SharedMemory::NULLHandle(), 0u, timestamp);
309 break;
310 } 324 }
311 if (!frame) 325 if (!frame)
312 return; 326 return;
313 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, 327 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE,
314 frame_format.frame_rate); 328 frame_format.frame_rate);
315 frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, 329 frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME,
316 reference_time); 330 reference_time);
317 OnIncomingCapturedVideoFrame(std::move(buffer), frame); 331 OnIncomingCapturedVideoFrame(std::move(buffer), frame);
318 } 332 }
319 333
320 void VideoCaptureDeviceClient::OnIncomingCapturedVideoFrame( 334 void VideoCaptureDeviceClient::OnIncomingCapturedVideoFrame(
emircan 2016/10/10 18:46:13 As we discussed, lets add a TODO to remove this cl
chfremer 2016/10/11 19:09:07 Done. Added the TODO to the interface.
321 std::unique_ptr<Buffer> buffer, 335 std::unique_ptr<Buffer> buffer,
322 const scoped_refptr<VideoFrame>& frame) { 336 const scoped_refptr<VideoFrame>& frame) {
323 receiver_->OnIncomingCapturedVideoFrame(std::move(buffer), frame); 337 receiver_->OnIncomingCapturedVideoFrame(std::move(buffer), frame);
324 } 338 }
325 339
326 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> 340 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer>
327 VideoCaptureDeviceClient::ResurrectLastOutputBuffer( 341 VideoCaptureDeviceClient::ResurrectLastOutputBuffer(
328 const gfx::Size& dimensions, 342 const gfx::Size& dimensions,
329 media::VideoPixelFormat format, 343 media::VideoPixelFormat format,
330 media::VideoPixelStorage storage) { 344 media::VideoPixelStorage storage) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kUPlane)); 410 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kUPlane));
397 *v_plane_data = 411 *v_plane_data =
398 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kVPlane)); 412 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kVPlane));
399 return buffer; 413 return buffer;
400 } 414 }
401 NOTREACHED(); 415 NOTREACHED();
402 return std::unique_ptr<Buffer>(); 416 return std::unique_ptr<Buffer>();
403 } 417 }
404 418
405 } // namespace media 419 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698