| Index: media/video/capture/linux/v4l2_capture_delegate.h
|
| diff --git a/media/video/capture/linux/v4l2_capture_delegate.h b/media/video/capture/linux/v4l2_capture_delegate.h
|
| index 9d65bb248539d708bd794e883d152810fe113fd1..42777900169a863ecd19d7a6518f0414d66ed012 100644
|
| --- a/media/video/capture/linux/v4l2_capture_delegate.h
|
| +++ b/media/video/capture/linux/v4l2_capture_delegate.h
|
| @@ -24,10 +24,13 @@ namespace media {
|
| class V4L2CaptureDelegate
|
| : public base::RefCountedThreadSafe<V4L2CaptureDelegate> {
|
| public:
|
| - // Creates the appropiate VideoCaptureDelegate according to parameters.
|
| + // Creates the appropiate VideoCaptureDelegate according to parameters. The
|
| + // caller instructs via |allow_using_dma_bufs| if DmaBufs should be used.
|
| static scoped_refptr<V4L2CaptureDelegate> CreateV4L2CaptureDelegate(
|
| const VideoCaptureDevice::Name& device_name,
|
| const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner,
|
| + VideoCaptureDevice::Client* client,
|
| + bool allow_using_dma_bufs,
|
| int power_line_frequency);
|
|
|
| // Retrieves the #planes for a given |fourcc|, or 0 if unknown.
|
| @@ -49,16 +52,17 @@ class V4L2CaptureDelegate
|
| void SetRotation(int rotation);
|
|
|
| protected:
|
| - // Class keeping track of SPLANE/MPLANE V4L2 buffers, mmap()ed on construction
|
| - // and munmap()ed on destruction. Destruction is syntactically equal for
|
| - // S/MPLANE but not construction, so this is implemented in derived classes.
|
| + // Class keeping track of SPLANE/MPLANE V4L2 buffers, mappable or not. Non
|
| + // mappable buffer keep track of the associated |fd|.
|
| + // Mappable buffers are mmap()ed on Init() and munmap()ed on destruction.
|
| + // Destruction is syntactically equal for S/MPLANE but not construction, so
|
| + // this must be implemented in derived classes.
|
| // Internally it has a vector of planes, which for SPLANE will contain only
|
| // one element.
|
| class BufferTracker : public base::RefCounted<BufferTracker> {
|
| public:
|
| BufferTracker();
|
| - // Abstract method to mmap() given |fd| according to |buffer|, planarity
|
| - // specific.
|
| + // Abstract method to init the BufferTracker according to |buffer|.
|
| virtual bool Init(int fd, const v4l2_buffer& buffer) = 0;
|
|
|
| uint8_t* const GetPlaneStart(size_t plane) const {
|
| @@ -66,6 +70,11 @@ class V4L2CaptureDelegate
|
| return planes_[plane].start;
|
| }
|
|
|
| + int const GetPlaneFd(size_t plane) const {
|
| + DCHECK_LT(plane, planes_.size());
|
| + return planes_[plane].fd;
|
| + }
|
| +
|
| size_t GetPlanePayloadSize(size_t plane) const {
|
| DCHECK_LT(plane, planes_.size());
|
| return planes_[plane].payload_size;
|
| @@ -82,12 +91,17 @@ class V4L2CaptureDelegate
|
| virtual ~BufferTracker();
|
| // Adds a given mmap()ed plane to |planes_|.
|
| void AddMmapedPlane(uint8_t* const start, size_t length);
|
| + void AddNonMmapedPlane(int fd);
|
|
|
| private:
|
| + // A Plane can be composed of |start| and |length|, for mappable resources
|
| + // (basically, memory), or by a |fd and a |capture_buffer|, for non mappable
|
| + // resources (dma-buf).|length| is needed for munmap().
|
| struct Plane {
|
| uint8_t* start;
|
| size_t length;
|
| size_t payload_size;
|
| + int fd;
|
| };
|
| std::vector<Plane> planes_;
|
| };
|
| @@ -95,6 +109,7 @@ class V4L2CaptureDelegate
|
| V4L2CaptureDelegate(
|
| const VideoCaptureDevice::Name& device_name,
|
| const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner,
|
| + v4l2_memory memory_type,
|
| int power_line_frequency);
|
| virtual ~V4L2CaptureDelegate();
|
|
|
| @@ -107,23 +122,25 @@ class V4L2CaptureDelegate
|
| uint32_t height,
|
| uint32_t pixelformat_fourcc) const = 0;
|
|
|
| - // Finish filling |buffer| struct with planarity-dependent data.
|
| - virtual void FinishFillingV4L2Buffer(v4l2_buffer* buffer) const = 0;
|
| + // Finish filling |buffer| struct with planarity-dependent data. Underlying
|
| + // implementation might need to know if it's for enqueueing, to allocate
|
| + // resources.
|
| + virtual void FinishFillingV4L2Buffer(v4l2_buffer* buffer,
|
| + bool for_enqueue) const = 0;
|
|
|
| - // Fetch the number of bytes occupied by data in |buffer| and set to
|
| - // |buffer_tracker|.
|
| + // Set |buffer_tracker|s payload size from |buffer|.
|
| virtual void SetPayloadSize(
|
| const scoped_refptr<BufferTracker>& buffer_tracker,
|
| const v4l2_buffer& buffer) const = 0;
|
|
|
| // Sends the captured |buffer| to the |client_|, synchronously.
|
| - virtual void SendBuffer(
|
| - const scoped_refptr<BufferTracker>& buffer_tracker,
|
| - const v4l2_format& format) const = 0;
|
| + virtual void SendBuffer(const scoped_refptr<BufferTracker>& buffer_tracker,
|
| + const v4l2_format& format) const = 0;
|
|
|
| // A few accessors for SendBuffer()'s to access private member variables.
|
| VideoCaptureFormat capture_format() const { return capture_format_; }
|
| VideoCaptureDevice::Client* client() const { return client_.get(); }
|
| + v4l2_memory memory_type() const { return memory_type_; }
|
| int rotation() const { return rotation_; }
|
|
|
| private:
|
| @@ -136,7 +153,7 @@ class V4L2CaptureDelegate
|
| bool MapAndQueueBuffer(int index);
|
| // Fills all common parts of |buffer|. Delegates to FinishFillingV4L2Buffer()
|
| // for filling in the planar-dependent parts.
|
| - void FillV4L2Buffer(v4l2_buffer* buffer, int i) const;
|
| + void FillV4L2Buffer(v4l2_buffer* buffer, int i, bool for_enqueue) const;
|
| void DoCapture();
|
| void SetErrorState(const std::string& reason);
|
|
|
| @@ -151,6 +168,9 @@ class V4L2CaptureDelegate
|
| scoped_ptr<VideoCaptureDevice::Client> client_;
|
| base::ScopedFD device_fd_;
|
|
|
| + // Memory Type (DmaBuf or Mmap) configured on ctor.
|
| + const v4l2_memory memory_type_;
|
| +
|
| // Vector of BufferTracker to keep track of mmap()ed pointers and their use.
|
| std::vector<scoped_refptr<BufferTracker>> buffer_tracker_pool_;
|
|
|
|
|