OLD | NEW |
---|---|
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 |
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. | |
63 // The device will be closed in the destructor. | |
64 virtual bool Open(Type type, uint32_t v4l2_pixfmt) = 0; | |
57 | 65 |
58 // Parameters and return value are the same as for the standard ioctl() system | 66 // Parameters and return value are the same as for the standard ioctl() system |
59 // call. | 67 // call. |
60 virtual int Ioctl(int request, void* arg) = 0; | 68 virtual int Ioctl(int request, void* arg) = 0; |
61 | 69 |
62 // This method sleeps until either: | 70 // This method sleeps until either: |
63 // - SetDevicePollInterrupt() is called (on another thread), | 71 // - SetDevicePollInterrupt() is called (on another thread), |
64 // - |poll_device| is true, and there is new data to be read from the device, | 72 // - |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 | 73 // or an event from the device has arrived; in the latter case |
66 // |*event_pending| will be set to true. | 74 // |*event_pending| will be set to true. |
(...skipping 11 matching lines...) Expand all Loading... | |
78 virtual bool ClearDevicePollInterrupt() = 0; | 86 virtual bool ClearDevicePollInterrupt() = 0; |
79 | 87 |
80 // Wrappers for standard mmap/munmap system calls. | 88 // Wrappers for standard mmap/munmap system calls. |
81 virtual void* Mmap(void* addr, | 89 virtual void* Mmap(void* addr, |
82 unsigned int len, | 90 unsigned int len, |
83 int prot, | 91 int prot, |
84 int flags, | 92 int flags, |
85 unsigned int offset) = 0; | 93 unsigned int offset) = 0; |
86 virtual void Munmap(void* addr, unsigned int len) = 0; | 94 virtual void Munmap(void* addr, unsigned int len) = 0; |
87 | 95 |
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 | 96 // 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 | 97 // |index|, assuming the buffer contains |num_planes| V4L2 planes and is of |
94 // |type|. Return an empty vector on failure. | 98 // |type|. Return an empty vector on failure. |
95 // The caller is responsible for closing the file descriptors after use. | 99 // The caller is responsible for closing the file descriptors after use. |
96 virtual std::vector<base::ScopedFD> GetDmabufsForV4L2Buffer( | 100 virtual std::vector<base::ScopedFD> GetDmabufsForV4L2Buffer( |
97 int index, | 101 int index, |
98 size_t num_planes, | 102 size_t num_planes, |
99 enum v4l2_buf_type type) = 0; | 103 enum v4l2_buf_type type) = 0; |
100 | 104 |
101 // Return true if the given V4L2 pixfmt can be used in CreateEGLImage() | 105 // Return true if the given V4L2 pixfmt can be used in CreateEGLImage() |
(...skipping 16 matching lines...) Expand all Loading... | |
118 uint32_t v4l2_pixfmt, | 122 uint32_t v4l2_pixfmt, |
119 const std::vector<base::ScopedFD>& dmabuf_fds) = 0; | 123 const std::vector<base::ScopedFD>& dmabuf_fds) = 0; |
120 | 124 |
121 // Destroys the EGLImageKHR. | 125 // Destroys the EGLImageKHR. |
122 virtual EGLBoolean DestroyEGLImage(EGLDisplay egl_display, | 126 virtual EGLBoolean DestroyEGLImage(EGLDisplay egl_display, |
123 EGLImageKHR egl_image) = 0; | 127 EGLImageKHR egl_image) = 0; |
124 | 128 |
125 // Returns the supported texture target for the V4L2Device. | 129 // Returns the supported texture target for the V4L2Device. |
126 virtual GLenum GetTextureTarget() = 0; | 130 virtual GLenum GetTextureTarget() = 0; |
127 | 131 |
128 // Returns the preferred V4L2 input format or 0 if don't care. | 132 // Returns the preferred V4L2 input format for |type| or 0 if none. |
129 virtual uint32_t PreferredInputFormat() = 0; | 133 virtual uint32_t PreferredInputFormat(Type type) = 0; |
134 | |
135 // NOTE: The below methods to query capabilities have a side effect of | |
136 // closing the previously-open device, if any, and should not be called after | |
137 // Open(). | |
138 // TODO(posciak): fix this. | |
130 | 139 |
131 // Get minimum and maximum resolution for fourcc |pixelformat| and store to | 140 // Get minimum and maximum resolution for fourcc |pixelformat| and store to |
132 // |min_resolution| and |max_resolution|. | 141 // |min_resolution| and |max_resolution|. |
133 void GetSupportedResolution(uint32_t pixelformat, | 142 void GetSupportedResolution(uint32_t pixelformat, |
134 gfx::Size* min_resolution, | 143 gfx::Size* min_resolution, |
135 gfx::Size* max_resolution); | 144 gfx::Size* max_resolution); |
136 | 145 |
146 // Return V4L2 pixelformats supported by the available image processor | |
147 // devices for |buf_type|. | |
148 virtual std::vector<uint32_t> GetSupportedImageProcessorPixelformats( | |
149 v4l2_buf_type buf_type) = 0; | |
150 | |
137 // Return supported profiles for decoder, including only profiles for given | 151 // Return supported profiles for decoder, including only profiles for given |
138 // fourcc |pixelformats|. | 152 // fourcc |pixelformats|. |
139 VideoDecodeAccelerator::SupportedProfiles GetSupportedDecodeProfiles( | 153 virtual VideoDecodeAccelerator::SupportedProfiles GetSupportedDecodeProfiles( |
154 const size_t num_formats, | |
155 const uint32_t pixelformats[]) = 0; | |
156 | |
157 // Return supported profiles for encoder. | |
158 virtual VideoEncodeAccelerator::SupportedProfiles | |
159 GetSupportedEncodeProfiles() = 0; | |
160 | |
161 // Return true if image processing is supported, false otherwise. | |
162 virtual bool IsImageProcessingSupported() = 0; | |
163 | |
164 // Return true if JPEG decoding is supported, false otherwise. | |
165 virtual bool IsJpegDecodingSupported() = 0; | |
166 | |
167 protected: | |
168 friend class base::RefCountedThreadSafe<V4L2Device>; | |
169 V4L2Device(); | |
170 virtual ~V4L2Device(); | |
171 | |
172 VideoDecodeAccelerator::SupportedProfiles EnumerateSupportedDecodeProfiles( | |
140 const size_t num_formats, | 173 const size_t num_formats, |
141 const uint32_t pixelformats[]); | 174 const uint32_t pixelformats[]); |
142 | 175 |
143 // Return true if the device supports |profile|, taking into account only | 176 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 | 177 |
149 protected: | 178 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 | 179 |
154 const Type type_; | 180 private: |
181 // Perform platform-specific initialization of the device instance. | |
182 // Return true on success, false on error or if the particular implementation | |
183 // is not available. | |
184 virtual bool Initialize() = 0; | |
kcwu
2016/10/11 06:45:06
I didn't know this could be private. Learnt one mo
| |
155 }; | 185 }; |
156 | 186 |
157 } // namespace media | 187 } // namespace media |
158 | 188 |
159 #endif // MEDIA_GPU_V4L2_DEVICE_H_ | 189 #endif // MEDIA_GPU_V4L2_DEVICE_H_ |
OLD | NEW |