Chromium Code Reviews| Index: media/capture/video/linux/v4l2_capture_delegate.h |
| diff --git a/media/capture/video/linux/v4l2_capture_delegate.h b/media/capture/video/linux/v4l2_capture_delegate.h |
| index 56af8e55c92c9ed3df6a22f62d4b0ba3e4548122..774acc83c9883030f488a950076c394de721dfc9 100644 |
| --- a/media/capture/video/linux/v4l2_capture_delegate.h |
| +++ b/media/capture/video/linux/v4l2_capture_delegate.h |
| @@ -11,6 +11,7 @@ |
| #include "base/files/scoped_file.h" |
| #include "base/macros.h" |
| #include "base/memory/ref_counted.h" |
|
perkj_chrome
2016/02/12 11:01:40
remove ref_counted.h ?
|
| +#include "base/memory/weak_ptr.h" |
| #include "build/build_config.h" |
| #include "media/capture/video/video_capture_device.h" |
| @@ -29,15 +30,9 @@ namespace media { |
| // Class doing the actual Linux capture using V4L2 API. V4L2 SPLANE/MPLANE |
| // capture specifics are implemented in derived classes. Created and destroyed |
| // on the owner's thread, otherwise living and operating on |v4l2_task_runner_|. |
| -class V4L2CaptureDelegate |
| - : public base::RefCountedThreadSafe<V4L2CaptureDelegate> { |
| +class V4L2CaptureDelegate final |
| + : public base::SupportsWeakPtr<V4L2CaptureDelegate> { |
|
perkj_chrome
2016/02/12 11:01:40
Use weakptr factory instead to make sure weak ptrs
mcasas
2016/02/12 21:32:43
Actually on second thoughts and seeing your other
|
| public: |
| - // Creates the appropiate VideoCaptureDelegate according to parameters. |
| - static scoped_refptr<V4L2CaptureDelegate> CreateV4L2CaptureDelegate( |
| - const VideoCaptureDevice::Name& device_name, |
| - const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, |
| - int power_line_frequency); |
| - |
| // Retrieves the #planes for a given |fourcc|, or 0 if unknown. |
| static size_t GetNumPlanesForFourCc(uint32_t fourcc); |
| // Returns the Chrome pixel format for |v4l2_fourcc| or PIXEL_FORMAT_UNKNOWN. |
| @@ -48,6 +43,12 @@ class V4L2CaptureDelegate |
| // preference, with MJPEG prioritised depending on |prefer_mjpeg|. |
| static std::list<uint32_t> GetListOfUsableFourCcs(bool prefer_mjpeg); |
| + V4L2CaptureDelegate( |
| + const VideoCaptureDevice::Name& device_name, |
| + const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, |
| + int power_line_frequency); |
| + ~V4L2CaptureDelegate(); |
| + |
| // Forward-to versions of VideoCaptureDevice virtual methods. |
| void AllocateAndStart(int width, |
| int height, |
| @@ -57,99 +58,16 @@ 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. |
| - // 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. |
| - virtual bool Init(int fd, const v4l2_buffer& buffer) = 0; |
| - |
| - const uint8_t* GetPlaneStart(size_t plane) const { |
| - DCHECK_LT(plane, planes_.size()); |
| - return planes_[plane].start; |
| - } |
| - |
| - size_t GetPlanePayloadSize(size_t plane) const { |
| - DCHECK_LT(plane, planes_.size()); |
| - return planes_[plane].payload_size; |
| - } |
| - |
| - void SetPlanePayloadSize(size_t plane, size_t payload_size) { |
| - DCHECK_LT(plane, planes_.size()); |
| - DCHECK_LE(payload_size, planes_[plane].length); |
| - planes_[plane].payload_size = payload_size; |
| - } |
| - |
| - protected: |
| - friend class base::RefCounted<BufferTracker>; |
| - virtual ~BufferTracker(); |
| - // Adds a given mmap()ed plane to |planes_|. |
| - void AddMmapedPlane(uint8_t* const start, size_t length); |
| - |
| - private: |
| - struct Plane { |
| - uint8_t* start; |
| - size_t length; |
| - size_t payload_size; |
| - }; |
| - std::vector<Plane> planes_; |
| - }; |
| - |
| - V4L2CaptureDelegate( |
| - const VideoCaptureDevice::Name& device_name, |
| - const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, |
| - int power_line_frequency); |
| - virtual ~V4L2CaptureDelegate(); |
| - |
| - // Creates the necessary, planarity-specific, internal tracking schemes, |
| - virtual scoped_refptr<BufferTracker> CreateBufferTracker() const = 0; |
| - |
| - // Fill in |format| with the given parameters, in a planarity dependent way. |
| - virtual bool FillV4L2Format(v4l2_format* format, |
| - uint32_t width, |
| - 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; |
| - |
| - // Fetch the number of bytes occupied by data in |buffer| and set to |
| - // |buffer_tracker|. |
| - 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; |
| - |
| - // 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(); } |
| - int rotation() const { return rotation_; } |
| - |
| private: |
| - friend class base::RefCountedThreadSafe<V4L2CaptureDelegate>; |
| - |
| - // Returns the input |fourcc| as a std::string four char representation. |
| - static std::string FourccToString(uint32_t fourcc); |
| // VIDIOC_QUERYBUFs a buffer from V4L2, creates a BufferTracker for it and |
| // enqueues it (VIDIOC_QBUF) back into V4L2. |
| 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 DoCapture(); |
| + |
| void SetErrorState(const tracked_objects::Location& from_here, |
| const std::string& reason); |
| - const v4l2_buf_type capture_type_; |
| const scoped_refptr<base::SingleThreadTaskRunner> v4l2_task_runner_; |
| const VideoCaptureDevice::Name device_name_; |
| const int power_line_frequency_; |
| @@ -161,6 +79,7 @@ class V4L2CaptureDelegate |
| base::ScopedFD device_fd_; |
| // Vector of BufferTracker to keep track of mmap()ed pointers and their use. |
| + class BufferTracker; |
| std::vector<scoped_refptr<BufferTracker>> buffer_tracker_pool_; |
| bool is_capturing_; |