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

Side by Side Diff: media/gpu/v4l2_device.h

Issue 2398883002: Add support for multiple V4L2 video devices of the same type. (Closed)
Patch Set: Address comments, reorganize V4L2Device::Type. 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // This file defines the V4L2Device interface which is used by the 5 // This file defines the V4L2Device interface which is used by the
6 // V4L2DecodeAccelerator class to delegate/pass the device specific 6 // V4L2DecodeAccelerator class to delegate/pass the device specific
7 // handling of any of the functionalities. 7 // handling of any of the functionalities.
8 8
9 #ifndef MEDIA_GPU_V4L2_DEVICE_H_ 9 #ifndef MEDIA_GPU_V4L2_DEVICE_H_
10 #define MEDIA_GPU_V4L2_DEVICE_H_ 10 #define MEDIA_GPU_V4L2_DEVICE_H_
11 11
12 #include <stddef.h> 12 #include <stddef.h>
13 #include <stdint.h> 13 #include <stdint.h>
14 14
15 #include <linux/videodev2.h> 15 #include <linux/videodev2.h>
16 16
17 #include "base/files/scoped_file.h" 17 #include "base/files/scoped_file.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "media/base/video_decoder_config.h" 19 #include "media/base/video_decoder_config.h"
20 #include "media/base/video_frame.h" 20 #include "media/base/video_frame.h"
21 #include "media/gpu/media_gpu_export.h" 21 #include "media/gpu/media_gpu_export.h"
22 #include "media/video/video_decode_accelerator.h" 22 #include "media/video/video_decode_accelerator.h"
23 #include "media/video/video_encode_accelerator.h"
23 #include "ui/gfx/geometry/size.h" 24 #include "ui/gfx/geometry/size.h"
24 #include "ui/gl/gl_bindings.h" 25 #include "ui/gl/gl_bindings.h"
25 26
26 // TODO(posciak): remove this once V4L2 headers are updated. 27 // TODO(posciak): remove this once V4L2 headers are updated.
27 #define V4L2_PIX_FMT_VP9 v4l2_fourcc('V', 'P', '9', '0') 28 #define V4L2_PIX_FMT_VP9 v4l2_fourcc('V', 'P', '9', '0')
28 #define V4L2_PIX_FMT_H264_SLICE v4l2_fourcc('S', '2', '6', '4') 29 #define V4L2_PIX_FMT_H264_SLICE v4l2_fourcc('S', '2', '6', '4')
29 #define V4L2_PIX_FMT_VP8_FRAME v4l2_fourcc('V', 'P', '8', 'F') 30 #define V4L2_PIX_FMT_VP8_FRAME v4l2_fourcc('V', 'P', '8', 'F')
30 #define V4L2_PIX_FMT_MT21 v4l2_fourcc('M', 'T', '2', '1') 31 #define V4L2_PIX_FMT_MT21 v4l2_fourcc('M', 'T', '2', '1')
31 32
32 namespace media { 33 namespace media {
33 34
34 class MEDIA_GPU_EXPORT V4L2Device 35 class MEDIA_GPU_EXPORT V4L2Device
35 : public base::RefCountedThreadSafe<V4L2Device> { 36 : public base::RefCountedThreadSafe<V4L2Device> {
36 public: 37 public:
37 // Utility format conversion functions 38 // Utility format conversion functions
38 static VideoPixelFormat V4L2PixFmtToVideoPixelFormat(uint32_t format); 39 static VideoPixelFormat V4L2PixFmtToVideoPixelFormat(uint32_t format);
39 static uint32_t VideoPixelFormatToV4L2PixFmt(VideoPixelFormat format); 40 static uint32_t VideoPixelFormatToV4L2PixFmt(VideoPixelFormat format);
40 static uint32_t VideoCodecProfileToV4L2PixFmt(VideoCodecProfile profile, 41 static uint32_t VideoCodecProfileToV4L2PixFmt(VideoCodecProfile profile,
41 bool slice_based); 42 bool slice_based);
43 std::vector<VideoCodecProfile> V4L2PixFmtToVideoCodecProfiles(
44 uint32_t pix_fmt,
45 bool is_encoder);
42 static uint32_t V4L2PixFmtToDrmFormat(uint32_t format); 46 static uint32_t V4L2PixFmtToDrmFormat(uint32_t format);
43 // Convert format requirements requested by a V4L2 device to gfx::Size. 47 // Convert format requirements requested by a V4L2 device to gfx::Size.
44 static gfx::Size CodedSizeFromV4L2Format(struct v4l2_format format); 48 static gfx::Size CodedSizeFromV4L2Format(struct v4l2_format format);
45 49
46 enum Type { 50 enum class Type {
47 kDecoder, 51 kDecoder,
48 kEncoder, 52 kEncoder,
49 kImageProcessor, 53 kImageProcessor,
50 kJpegDecoder, 54 kJpegDecoder,
51 }; 55 };
52 56
53 // Creates and initializes an appropriate V4L2Device of |type| for the 57 // Create and initialize an appropriate V4L2Device instance for the current
kcwu 2016/10/07 11:19:05 s/Create/Creates/, s/initialize/initializes/
Pawel Osciak 2016/10/11 06:13:46 My personal preference when writing docs is usuall
kcwu 2016/10/11 06:45:06 It's style guide's suggestion. I don't feel strong
54 // current platform and returns a scoped_refptr<V4L2Device> on success, or 58 // platform, or return nullptr if not available.
55 // NULL. 59 static scoped_refptr<V4L2Device> Create();
56 static scoped_refptr<V4L2Device> Create(Type type); 60
61 // Open a V4L2 device of |type| for use with |v4l2_pixfmt|.
62 // Return true on success.
kcwu 2016/10/07 11:19:05 Add comment the dtor will close automatically. Oth
Pawel Osciak 2016/10/11 06:13:46 Done.
63 virtual bool Open(Type type, uint32_t v4l2_pixfmt) = 0;
57 64
58 // Parameters and return value are the same as for the standard ioctl() system 65 // Parameters and return value are the same as for the standard ioctl() system
59 // call. 66 // call.
60 virtual int Ioctl(int request, void* arg) = 0; 67 virtual int Ioctl(int request, void* arg) = 0;
61 68
62 // This method sleeps until either: 69 // This method sleeps until either:
63 // - SetDevicePollInterrupt() is called (on another thread), 70 // - SetDevicePollInterrupt() is called (on another thread),
64 // - |poll_device| is true, and there is new data to be read from the device, 71 // - |poll_device| is true, and there is new data to be read from the device,
65 // or an event from the device has arrived; in the latter case 72 // or an event from the device has arrived; in the latter case
66 // |*event_pending| will be set to true. 73 // |*event_pending| will be set to true.
(...skipping 11 matching lines...) Expand all
78 virtual bool ClearDevicePollInterrupt() = 0; 85 virtual bool ClearDevicePollInterrupt() = 0;
79 86
80 // Wrappers for standard mmap/munmap system calls. 87 // Wrappers for standard mmap/munmap system calls.
81 virtual void* Mmap(void* addr, 88 virtual void* Mmap(void* addr,
82 unsigned int len, 89 unsigned int len,
83 int prot, 90 int prot,
84 int flags, 91 int flags,
85 unsigned int offset) = 0; 92 unsigned int offset) = 0;
86 virtual void Munmap(void* addr, unsigned int len) = 0; 93 virtual void Munmap(void* addr, unsigned int len) = 0;
87 94
88 // Initializes the V4L2Device to operate as a device of |type|.
89 // Returns true on success.
90 virtual bool Initialize() = 0;
91
92 // Return a vector of dmabuf file descriptors, exported for V4L2 buffer with 95 // Return a vector of dmabuf file descriptors, exported for V4L2 buffer with
93 // |index|, assuming the buffer contains |num_planes| V4L2 planes and is of 96 // |index|, assuming the buffer contains |num_planes| V4L2 planes and is of
94 // |type|. Return an empty vector on failure. 97 // |type|. Return an empty vector on failure.
95 // The caller is responsible for closing the file descriptors after use. 98 // The caller is responsible for closing the file descriptors after use.
96 virtual std::vector<base::ScopedFD> GetDmabufsForV4L2Buffer( 99 virtual std::vector<base::ScopedFD> GetDmabufsForV4L2Buffer(
97 int index, 100 int index,
98 size_t num_planes, 101 size_t num_planes,
99 enum v4l2_buf_type type) = 0; 102 enum v4l2_buf_type type) = 0;
100 103
101 // Return true if the given V4L2 pixfmt can be used in CreateEGLImage() 104 // Return true if the given V4L2 pixfmt can be used in CreateEGLImage()
(...skipping 16 matching lines...) Expand all
118 uint32_t v4l2_pixfmt, 121 uint32_t v4l2_pixfmt,
119 const std::vector<base::ScopedFD>& dmabuf_fds) = 0; 122 const std::vector<base::ScopedFD>& dmabuf_fds) = 0;
120 123
121 // Destroys the EGLImageKHR. 124 // Destroys the EGLImageKHR.
122 virtual EGLBoolean DestroyEGLImage(EGLDisplay egl_display, 125 virtual EGLBoolean DestroyEGLImage(EGLDisplay egl_display,
123 EGLImageKHR egl_image) = 0; 126 EGLImageKHR egl_image) = 0;
124 127
125 // Returns the supported texture target for the V4L2Device. 128 // Returns the supported texture target for the V4L2Device.
126 virtual GLenum GetTextureTarget() = 0; 129 virtual GLenum GetTextureTarget() = 0;
127 130
128 // Returns the preferred V4L2 input format or 0 if don't care. 131 // Returns the preferred V4L2 input format for |type| or 0 if none.
129 virtual uint32_t PreferredInputFormat() = 0; 132 virtual uint32_t PreferredInputFormat(Type type) = 0;
133
134 // NOTE: The below methods to query capabilities have a side effect of
135 // closing the previously-open device, if any, and should not be called after
136 // Open().
137 // TODO(posciak): fix this.
130 138
131 // Get minimum and maximum resolution for fourcc |pixelformat| and store to 139 // Get minimum and maximum resolution for fourcc |pixelformat| and store to
132 // |min_resolution| and |max_resolution|. 140 // |min_resolution| and |max_resolution|.
133 void GetSupportedResolution(uint32_t pixelformat, 141 void GetSupportedResolution(uint32_t pixelformat,
134 gfx::Size* min_resolution, 142 gfx::Size* min_resolution,
135 gfx::Size* max_resolution); 143 gfx::Size* max_resolution);
136 144
145 // Return V4L2 pixelformats supported by the available image processor
146 // devices for |buf_type|.
147 virtual std::vector<uint32_t> GetSupportedImageProcessorPixelformats(
148 v4l2_buf_type buf_type) = 0;
149
137 // Return supported profiles for decoder, including only profiles for given 150 // Return supported profiles for decoder, including only profiles for given
138 // fourcc |pixelformats|. 151 // fourcc |pixelformats|.
139 VideoDecodeAccelerator::SupportedProfiles GetSupportedDecodeProfiles( 152 virtual VideoDecodeAccelerator::SupportedProfiles GetSupportedDecodeProfiles(
153 const size_t num_formats,
154 const uint32_t pixelformats[]) = 0;
155
156 // Return supported profiles for encoder.
157 virtual VideoEncodeAccelerator::SupportedProfiles
158 GetSupportedEncodeProfiles() = 0;
159
160 // Return true if image processing is supported, false otherwise.
161 virtual bool IsImageProcessingSupported() = 0;
162
163 // Return true if JPEG decoding is supported, false otherwise.
164 virtual bool IsJpegDecodingSupported() = 0;
165
166 protected:
167 friend class base::RefCountedThreadSafe<V4L2Device>;
168 V4L2Device();
169 virtual ~V4L2Device();
170
171 virtual bool Initialize() = 0;
kcwu 2016/10/07 11:19:05 Please keep its comments for children classes.
Pawel Osciak 2016/10/11 06:13:46 Done.
172
173 VideoDecodeAccelerator::SupportedProfiles EnumerateSupportedDecodeProfiles(
140 const size_t num_formats, 174 const size_t num_formats,
141 const uint32_t pixelformats[]); 175 const uint32_t pixelformats[]);
142 176
143 // Return true if the device supports |profile|, taking into account only 177 VideoEncodeAccelerator::SupportedProfiles EnumerateSupportedEncodeProfiles();
144 // fourccs from the given array of |pixelformats| of size |num_formats|.
145 bool SupportsDecodeProfileForV4L2PixelFormats(VideoCodecProfile profile,
146 const size_t num_formats,
147 const uint32_t pixelformats[]);
148 178
149 protected: 179 std::vector<uint32_t> EnumerateSupportedPixelformats(v4l2_buf_type buf_type);
150 friend class base::RefCountedThreadSafe<V4L2Device>;
151 explicit V4L2Device(Type type);
152 virtual ~V4L2Device();
153
154 const Type type_;
155 }; 180 };
156 181
157 } // namespace media 182 } // namespace media
158 183
159 #endif // MEDIA_GPU_V4L2_DEVICE_H_ 184 #endif // MEDIA_GPU_V4L2_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698