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

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: Remove method AsClientBuffer() 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
« no previous file with comments | « media/capture/video/video_capture_device.h ('k') | services/video_capture/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 26 matching lines...) Expand all
37 int buffer_id) 37 int buffer_id)
38 : id_(buffer_id), 38 : id_(buffer_id),
39 pool_(pool), 39 pool_(pool),
40 buffer_handle_(pool_->GetBufferHandle(buffer_id)) { 40 buffer_handle_(pool_->GetBufferHandle(buffer_id)) {
41 DCHECK(pool_.get()); 41 DCHECK(pool_.get());
42 } 42 }
43 int id() const override { return id_; } 43 int id() const override { return id_; }
44 gfx::Size dimensions() const override { return buffer_handle_->dimensions(); } 44 gfx::Size dimensions() const override { return buffer_handle_->dimensions(); }
45 size_t mapped_size() const override { return buffer_handle_->mapped_size(); } 45 size_t mapped_size() const override { return buffer_handle_->mapped_size(); }
46 void* data(int plane) override { return buffer_handle_->data(plane); } 46 void* data(int plane) override { return buffer_handle_->data(plane); }
47 ClientBuffer AsClientBuffer(int plane) override {
48 return buffer_handle_->AsClientBuffer(plane);
49 }
50 #if defined(OS_POSIX) && !defined(OS_MACOSX) 47 #if defined(OS_POSIX) && !defined(OS_MACOSX)
51 base::FileDescriptor AsPlatformFile() override { 48 base::FileDescriptor AsPlatformFile() override {
52 return buffer_handle_->AsPlatformFile(); 49 return buffer_handle_->AsPlatformFile();
53 } 50 }
54 #endif 51 #endif
52 bool IsBackedByVideoFrame() const override {
53 return buffer_handle_->IsBackedByVideoFrame();
54 }
55 scoped_refptr<VideoFrame> GetVideoFrame() override {
56 return buffer_handle_->GetVideoFrame();
57 }
55 58
56 private: 59 private:
57 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); } 60 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); }
58 61
59 const int id_; 62 const int id_;
60 const scoped_refptr<VideoCaptureBufferPool> pool_; 63 const scoped_refptr<VideoCaptureBufferPool> pool_;
61 const std::unique_ptr<VideoCaptureBufferHandle> buffer_handle_; 64 const std::unique_ptr<VideoCaptureBufferHandle> buffer_handle_;
62 }; 65 };
63 66
64 VideoCaptureDeviceClient::VideoCaptureDeviceClient( 67 VideoCaptureDeviceClient::VideoCaptureDeviceClient(
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 275
273 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer( 276 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer(
274 std::unique_ptr<Buffer> buffer, 277 std::unique_ptr<Buffer> buffer,
275 const VideoCaptureFormat& frame_format, 278 const VideoCaptureFormat& frame_format,
276 base::TimeTicks reference_time, 279 base::TimeTicks reference_time,
277 base::TimeDelta timestamp) { 280 base::TimeDelta timestamp) {
278 // Currently, only I420 pixel format is supported. 281 // Currently, only I420 pixel format is supported.
279 DCHECK_EQ(media::PIXEL_FORMAT_I420, frame_format.pixel_format); 282 DCHECK_EQ(media::PIXEL_FORMAT_I420, frame_format.pixel_format);
280 DCHECK_EQ(media::PIXEL_STORAGE_CPU, frame_format.pixel_storage); 283 DCHECK_EQ(media::PIXEL_STORAGE_CPU, frame_format.pixel_storage);
281 284
282 scoped_refptr<VideoFrame> frame = VideoFrame::WrapExternalSharedMemory( 285 scoped_refptr<VideoFrame> frame;
283 media::PIXEL_FORMAT_I420, frame_format.frame_size, 286 if (buffer->IsBackedByVideoFrame()) {
284 gfx::Rect(frame_format.frame_size), frame_format.frame_size, 287 frame = buffer->GetVideoFrame();
285 reinterpret_cast<uint8_t*>(buffer->data()), 288 frame->set_timestamp(timestamp);
286 VideoFrame::AllocationSize(media::PIXEL_FORMAT_I420, 289 } else {
287 frame_format.frame_size), 290 frame = VideoFrame::WrapExternalSharedMemory(
288 base::SharedMemory::NULLHandle(), 0u, timestamp); 291 media::PIXEL_FORMAT_I420, frame_format.frame_size,
292 gfx::Rect(frame_format.frame_size), frame_format.frame_size,
293 reinterpret_cast<uint8_t*>(buffer->data()),
294 VideoFrame::AllocationSize(media::PIXEL_FORMAT_I420,
295 frame_format.frame_size),
296 base::SharedMemory::NULLHandle(), 0u, timestamp);
297 }
289 if (!frame) 298 if (!frame)
290 return; 299 return;
291 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, 300 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE,
292 frame_format.frame_rate); 301 frame_format.frame_rate);
293 frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, 302 frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME,
294 reference_time); 303 reference_time);
295 OnIncomingCapturedVideoFrame(std::move(buffer), frame); 304 OnIncomingCapturedVideoFrame(std::move(buffer), frame);
296 } 305 }
297 306
298 void VideoCaptureDeviceClient::OnIncomingCapturedVideoFrame( 307 void VideoCaptureDeviceClient::OnIncomingCapturedVideoFrame(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 *u_plane_data = 366 *u_plane_data =
358 *y_plane_data + 367 *y_plane_data +
359 VideoFrame::PlaneSize(format, VideoFrame::kYPlane, dimensions).GetArea(); 368 VideoFrame::PlaneSize(format, VideoFrame::kYPlane, dimensions).GetArea();
360 *v_plane_data = 369 *v_plane_data =
361 *u_plane_data + 370 *u_plane_data +
362 VideoFrame::PlaneSize(format, VideoFrame::kUPlane, dimensions).GetArea(); 371 VideoFrame::PlaneSize(format, VideoFrame::kUPlane, dimensions).GetArea();
363 return buffer; 372 return buffer;
364 } 373 }
365 374
366 } // namespace media 375 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/video_capture_device.h ('k') | services/video_capture/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698