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

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

Issue 1882373004: Migrate content/common/gpu/media code to media/gpu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Squash and rebase Created 4 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4 //
5 // This file defines the V4L2Device interface which is used by the
6 // V4L2DecodeAccelerator class to delegate/pass the device specific
7 // handling of any of the functionalities.
8
9 #ifndef CONTENT_COMMON_GPU_MEDIA_V4L2_DEVICE_H_
10 #define CONTENT_COMMON_GPU_MEDIA_V4L2_DEVICE_H_
11
12 #include <stddef.h>
13 #include <stdint.h>
14
15 #include <linux/videodev2.h>
16
17 #include "base/files/scoped_file.h"
18 #include "base/memory/ref_counted.h"
19 #include "content/common/content_export.h"
20 #include "media/base/video_decoder_config.h"
21 #include "media/base/video_frame.h"
22 #include "media/video/video_decode_accelerator.h"
23 #include "ui/gfx/geometry/size.h"
24 #include "ui/gl/gl_bindings.h"
25
26 // 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_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_MT21 v4l2_fourcc('M', 'T', '2', '1')
31
32 namespace content {
33
34 class CONTENT_EXPORT V4L2Device
35 : public base::RefCountedThreadSafe<V4L2Device> {
36 public:
37 // Utility format conversion functions
38 static media::VideoPixelFormat V4L2PixFmtToVideoPixelFormat(uint32_t format);
39 static uint32_t VideoPixelFormatToV4L2PixFmt(media::VideoPixelFormat format);
40 static uint32_t VideoCodecProfileToV4L2PixFmt(
41 media::VideoCodecProfile profile,
42 bool slice_based);
43 static uint32_t V4L2PixFmtToDrmFormat(uint32_t format);
44 // Convert format requirements requested by a V4L2 device to gfx::Size.
45 static gfx::Size CodedSizeFromV4L2Format(struct v4l2_format format);
46
47 enum Type {
48 kDecoder,
49 kEncoder,
50 kImageProcessor,
51 kJpegDecoder,
52 };
53
54 // Creates and initializes an appropriate V4L2Device of |type| for the
55 // current platform and returns a scoped_refptr<V4L2Device> on success, or
56 // NULL.
57 static scoped_refptr<V4L2Device> Create(Type type);
58
59 // Parameters and return value are the same as for the standard ioctl() system
60 // call.
61 virtual int Ioctl(int request, void* arg) = 0;
62
63 // This method sleeps until either:
64 // - SetDevicePollInterrupt() is called (on another thread),
65 // - |poll_device| is true, and there is new data to be read from the device,
66 // or an event from the device has arrived; in the latter case
67 // |*event_pending| will be set to true.
68 // Returns false on error, true otherwise.
69 // This method should be called from a separate thread.
70 virtual bool Poll(bool poll_device, bool* event_pending) = 0;
71
72 // These methods are used to interrupt the thread sleeping on Poll() and force
73 // it to return regardless of device state, which is usually when the client
74 // is no longer interested in what happens with the device (on cleanup,
75 // client state change, etc.). When SetDevicePollInterrupt() is called, Poll()
76 // will return immediately, and any subsequent calls to it will also do so
77 // until ClearDevicePollInterrupt() is called.
78 virtual bool SetDevicePollInterrupt() = 0;
79 virtual bool ClearDevicePollInterrupt() = 0;
80
81 // Wrappers for standard mmap/munmap system calls.
82 virtual void* Mmap(void* addr,
83 unsigned int len,
84 int prot,
85 int flags,
86 unsigned int offset) = 0;
87 virtual void Munmap(void* addr, unsigned int len) = 0;
88
89 // Initializes the V4L2Device to operate as a device of |type|.
90 // Returns true on success.
91 virtual bool Initialize() = 0;
92
93 // Return a vector of dmabuf file descriptors, exported for V4L2 buffer with
94 // |index|, assuming the buffer contains |num_planes| V4L2 planes and is of
95 // |type|. Return an empty vector on failure.
96 // The caller is responsible for closing the file descriptors after use.
97 virtual std::vector<base::ScopedFD> GetDmabufsForV4L2Buffer(
98 int index,
99 size_t num_planes,
100 enum v4l2_buf_type type) = 0;
101
102 // Return true if the given V4L2 pixfmt can be used in CreateEGLImage()
103 // for the current platform.
104 virtual bool CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) = 0;
105
106 // Create an EGLImage from provided |dmabuf_fds| and bind |texture_id| to it.
107 // Some implementations may also require the V4L2 |buffer_index| of the buffer
108 // for which |dmabuf_fds| have been exported.
109 // The caller may choose to close the file descriptors after this method
110 // returns, and may expect the buffers to remain valid for the lifetime of
111 // the created EGLImage.
112 // Return EGL_NO_IMAGE_KHR on failure.
113 virtual EGLImageKHR CreateEGLImage(
114 EGLDisplay egl_display,
115 EGLContext egl_context,
116 GLuint texture_id,
117 const gfx::Size& size,
118 unsigned int buffer_index,
119 uint32_t v4l2_pixfmt,
120 const std::vector<base::ScopedFD>& dmabuf_fds) = 0;
121
122 // Destroys the EGLImageKHR.
123 virtual EGLBoolean DestroyEGLImage(EGLDisplay egl_display,
124 EGLImageKHR egl_image) = 0;
125
126 // Returns the supported texture target for the V4L2Device.
127 virtual GLenum GetTextureTarget() = 0;
128
129 // Returns the preferred V4L2 input format or 0 if don't care.
130 virtual uint32_t PreferredInputFormat() = 0;
131
132 // Get minimum and maximum resolution for fourcc |pixelformat| and store to
133 // |min_resolution| and |max_resolution|.
134 void GetSupportedResolution(uint32_t pixelformat, gfx::Size* min_resolution,
135 gfx::Size* max_resolution);
136
137 // Return supported profiles for decoder, including only profiles for given
138 // fourcc |pixelformats|.
139 media::VideoDecodeAccelerator::SupportedProfiles GetSupportedDecodeProfiles(
140 const size_t num_formats, const uint32_t pixelformats[]);
141
142 // Return true if the device supports |profile|, taking into account only
143 // fourccs from the given array of |pixelformats| of size |num_formats|.
144 bool SupportsDecodeProfileForV4L2PixelFormats(
145 media::VideoCodecProfile profile,
146 const size_t num_formats,
147 const uint32_t pixelformats[]);
148
149 protected:
150 friend class base::RefCountedThreadSafe<V4L2Device>;
151 explicit V4L2Device(Type type);
152 virtual ~V4L2Device();
153
154 const Type type_;
155 };
156
157 } // namespace content
158
159 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698