Index: media/capture/video/video_capture_device.h |
diff --git a/media/capture/video/video_capture_device.h b/media/capture/video/video_capture_device.h |
index 0ac1c3b94b25083d33e3013f4c738d7660979192..3613c7bef649422114425cb0a193494c19136c24 100644 |
--- a/media/capture/video/video_capture_device.h |
+++ b/media/capture/video/video_capture_device.h |
@@ -30,6 +30,7 @@ |
#include "media/capture/capture_export.h" |
#include "media/capture/mojo/image_capture.mojom.h" |
#include "media/capture/video/scoped_result_callback.h" |
+#include "media/capture/video/video_capture_buffer_handle.h" |
#include "media/capture/video/video_capture_device_descriptor.h" |
#include "media/capture/video_capture_types.h" |
#include "mojo/public/cpp/bindings/array.h" |
@@ -47,7 +48,6 @@ class CAPTURE_EXPORT FrameBufferPool { |
virtual void SetBufferHold(int buffer_id) = 0; |
virtual void ReleaseBufferHold(int buffer_id) = 0; |
- virtual mojo::ScopedSharedBufferHandle GetHandleForTransit(int buffer_id) = 0; |
}; |
class CAPTURE_EXPORT VideoFrameConsumerFeedbackObserver { |
@@ -77,6 +77,13 @@ class CAPTURE_EXPORT VideoFrameConsumerFeedbackObserver { |
static constexpr double kNoUtilizationRecorded = -1.0; |
}; |
+class CAPTURE_EXPORT BufferAccessProvider { |
+ public: |
+ virtual ~BufferAccessProvider() {} |
+ virtual mojo::ScopedSharedBufferHandle GetHandleForTransit() = 0; |
+ virtual std::unique_ptr<VideoCaptureBufferHandle> GetReadWriteAccess() = 0; |
+}; |
+ |
class CAPTURE_EXPORT VideoCaptureDevice |
: public VideoFrameConsumerFeedbackObserver { |
public: |
@@ -87,21 +94,21 @@ class CAPTURE_EXPORT VideoCaptureDevice |
// All clients must implement OnError(). |
class CAPTURE_EXPORT Client { |
public: |
- // Memory buffer returned by Client::ReserveOutputBuffer(). |
- class CAPTURE_EXPORT Buffer { |
+ // Move-only struct representing access to and reservation of a buffer. |
+ struct CAPTURE_EXPORT Buffer { |
miu
2016/12/20 22:25:37
Putting the prior two comments together, it then s
miu
2016/12/20 22:25:37
naming: I'd suggest renaming this to BufferPtr bec
miu
2016/12/20 22:25:37
Random thinking out-loud: IIUC the usage cases cor
chfremer
2016/12/22 19:01:20
I like this idea, and I would go with it if I didn
chfremer
2016/12/22 19:01:20
Hmm, the way I see it, VideoCaptureBufferHandle is
chfremer
2016/12/22 19:01:20
I agree this would make sense if we were to follow
miu
2016/12/27 23:38:48
You have a better grasp on the big picture than I
chfremer
2016/12/28 01:06:44
You are making a good point, which makes me realiz
|
public: |
- virtual ~Buffer() = 0; |
- virtual int id() const = 0; |
- virtual int frame_feedback_id() const = 0; |
- virtual gfx::Size dimensions() const = 0; |
- virtual size_t mapped_size() const = 0; |
- virtual void* data(int plane) = 0; |
- void* data() { return data(0); } |
-#if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) |
- virtual base::FileDescriptor AsPlatformFile() = 0; |
-#endif |
- virtual bool IsBackedByVideoFrame() const = 0; |
- virtual scoped_refptr<VideoFrame> GetVideoFrame() = 0; |
+ Buffer(); |
+ Buffer(int buffer_id, |
+ int frame_feedback_id, |
+ std::unique_ptr<BufferAccessProvider> access_provider); |
+ ~Buffer(); |
+ Buffer(Buffer&& other); |
+ Buffer& operator=(Buffer&& other); |
+ |
+ int id; |
miu
2016/12/20 22:25:37
It seems weird to expose these data members public
chfremer
2016/12/22 19:01:20
Done. Maybe my idea of "plain old set of members"
miu
2016/12/27 23:38:48
Seems fine, since the intent is to allow public mo
|
+ int frame_feedback_id; |
+ std::unique_ptr<BufferAccessProvider> access_provider; |
+ bool is_valid() { return access_provider != nullptr; } |
}; |
virtual ~Client() {} |
@@ -139,20 +146,19 @@ class CAPTURE_EXPORT VideoCaptureDevice |
// backing, but functions as a reservation for external input for the |
// purposes of buffer throttling. |
// |
- // The output buffer stays reserved and mapped for use until the Buffer |
- // object is destroyed or returned. |
- virtual std::unique_ptr<Buffer> ReserveOutputBuffer( |
- const gfx::Size& dimensions, |
- VideoPixelFormat format, |
- VideoPixelStorage storage, |
- int frame_feedback_id) = 0; |
+ // The buffer stays reserved for use by the caller as long as it |
+ // holds on to the contained |access_provider|. |
+ virtual Buffer ReserveOutputBuffer(const gfx::Size& dimensions, |
+ VideoPixelFormat format, |
+ VideoPixelStorage storage, |
+ int frame_feedback_id) = 0; |
// Provides VCD::Client with a populated Buffer containing the content of |
// the next video frame. The |buffer| must originate from an earlier call to |
// ReserveOutputBuffer(). |
// See OnIncomingCapturedData for details of |reference_time| and |
// |timestamp|. |
- virtual void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, |
+ virtual void OnIncomingCapturedBuffer(Buffer buffer, |
const VideoCaptureFormat& format, |
base::TimeTicks reference_time, |
base::TimeDelta timestamp) = 0; |
@@ -160,7 +166,7 @@ class CAPTURE_EXPORT VideoCaptureDevice |
// Extended version of OnIncomingCapturedBuffer() allowing clients to |
// pass a custom |visible_rect| and |additional_metadata|. |
virtual void OnIncomingCapturedBufferExt( |
- std::unique_ptr<Buffer> buffer, |
+ Buffer buffer, |
const VideoCaptureFormat& format, |
base::TimeTicks reference_time, |
base::TimeDelta timestamp, |
@@ -172,11 +178,10 @@ class CAPTURE_EXPORT VideoCaptureDevice |
// of the Buffer has not been preserved, or if the |dimensions|, |format|, |
// or |storage| disagree with how it was reserved via ReserveOutputBuffer(). |
// When this operation fails, nullptr will be returned. |
- virtual std::unique_ptr<Buffer> ResurrectLastOutputBuffer( |
- const gfx::Size& dimensions, |
- VideoPixelFormat format, |
- VideoPixelStorage storage, |
- int new_frame_feedback_id) = 0; |
+ virtual Buffer ResurrectLastOutputBuffer(const gfx::Size& dimensions, |
+ VideoPixelFormat format, |
+ VideoPixelStorage storage, |
+ int new_frame_feedback_id) = 0; |
// An error has occurred that cannot be handled and VideoCaptureDevice must |
// be StopAndDeAllocate()-ed. |reason| is a text description of the error. |