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

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: Fixes for image processor. 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 // Creates and initializes a V4L2Device class instance to operate on devices
54 // current platform and returns a scoped_refptr<V4L2Device> on success, or 58 // of |type|, returning nullptr on failure.
55 // NULL.
56 static scoped_refptr<V4L2Device> Create(Type type); 59 static scoped_refptr<V4L2Device> Create(Type type);
57 60
61 // Opens an appropriate V4L2 device node of type this class has been created
62 // for, and to be used with |v4l2_pixfmt|. Returns true on success.
63 virtual bool Open(uint32_t v4l2_pixfmt) = 0;
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.
67 // Returns false on error, true otherwise. 74 // Returns false on error, true otherwise.
(...skipping 10 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 25 matching lines...) Expand all
127 130
128 // Returns the preferred V4L2 input format or 0 if don't care. 131 // Returns the preferred V4L2 input format or 0 if don't care.
129 virtual uint32_t PreferredInputFormat() = 0; 132 virtual uint32_t PreferredInputFormat() = 0;
130 133
131 // Get minimum and maximum resolution for fourcc |pixelformat| and store to 134 // Get minimum and maximum resolution for fourcc |pixelformat| and store to
132 // |min_resolution| and |max_resolution|. 135 // |min_resolution| and |max_resolution|.
133 void GetSupportedResolution(uint32_t pixelformat, 136 void GetSupportedResolution(uint32_t pixelformat,
134 gfx::Size* min_resolution, 137 gfx::Size* min_resolution,
135 gfx::Size* max_resolution); 138 gfx::Size* max_resolution);
136 139
140 // Return V4L2 pixelformats supported by the available image processor
141 // devices for |buf_type|.
142 virtual std::vector<uint32_t> GetSupportedImageProcessorPixelformats(
kcwu 2016/10/06 10:40:00 These new added apis all have side-effects. 1. Th
Pawel Osciak 2016/10/07 08:30:24 Yes, I also wasn't happy about 1, it should be han
143 v4l2_buf_type buf_type) = 0;
144
137 // Return supported profiles for decoder, including only profiles for given 145 // Return supported profiles for decoder, including only profiles for given
138 // fourcc |pixelformats|. 146 // fourcc |pixelformats|.
139 VideoDecodeAccelerator::SupportedProfiles GetSupportedDecodeProfiles( 147 virtual VideoDecodeAccelerator::SupportedProfiles GetSupportedDecodeProfiles(
140 const size_t num_formats, 148 const size_t num_formats,
141 const uint32_t pixelformats[]); 149 const uint32_t pixelformats[]) = 0;
142 150
143 // Return true if the device supports |profile|, taking into account only 151 // Return supported profiles for encoder.
144 // fourccs from the given array of |pixelformats| of size |num_formats|. 152 virtual VideoEncodeAccelerator::SupportedProfiles
145 bool SupportsDecodeProfileForV4L2PixelFormats(VideoCodecProfile profile, 153 GetSupportedEncodeProfiles() = 0;
146 const size_t num_formats, 154
147 const uint32_t pixelformats[]); 155 // Return true if JPEG decoding is supported, false otherwise.
156 virtual bool IsJpegDecodingSupported() = 0;
148 157
149 protected: 158 protected:
150 friend class base::RefCountedThreadSafe<V4L2Device>; 159 friend class base::RefCountedThreadSafe<V4L2Device>;
151 explicit V4L2Device(Type type); 160 explicit V4L2Device(Type type);
152 virtual ~V4L2Device(); 161 virtual ~V4L2Device();
153 162
163 virtual bool Initialize() = 0;
164
165 VideoDecodeAccelerator::SupportedProfiles EnumerateSupportedDecodeProfiles(
166 const size_t num_formats,
167 const uint32_t pixelformats[]);
168
169 VideoEncodeAccelerator::SupportedProfiles EnumerateSupportedEncodeProfiles();
170
171 std::vector<uint32_t> EnumerateSupportedPixelformats(v4l2_buf_type buf_type);
172
154 const Type type_; 173 const Type type_;
155 }; 174 };
156 175
157 } // namespace media 176 } // namespace media
158 177
159 #endif // MEDIA_GPU_V4L2_DEVICE_H_ 178 #endif // MEDIA_GPU_V4L2_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698