Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / common / gpu / media / v4l2_device.h
blob977a4ad7ff8316dab489770e0ea3661d24430ccd
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.
9 #ifndef CONTENT_COMMON_GPU_MEDIA_V4L2_DEVICE_H_
10 #define CONTENT_COMMON_GPU_MEDIA_V4L2_DEVICE_H_
12 #include "base/memory/ref_counted.h"
13 #include "content/common/content_export.h"
14 #include "media/base/video_decoder_config.h"
15 #include "media/base/video_frame.h"
16 #include "media/video/video_decode_accelerator.h"
17 #include "ui/gfx/geometry/size.h"
18 #include "ui/gl/gl_bindings.h"
20 // TODO(posciak): remove this once V4L2 headers are updated.
21 #define V4L2_PIX_FMT_VP9 v4l2_fourcc('V', 'P', '9', '0')
22 #define V4L2_PIX_FMT_H264_SLICE v4l2_fourcc('S', '2', '6', '4')
23 #define V4L2_PIX_FMT_VP8_FRAME v4l2_fourcc('V', 'P', '8', 'F')
25 namespace content {
27 class CONTENT_EXPORT V4L2Device
28 : public base::RefCountedThreadSafe<V4L2Device> {
29 public:
30 // Utility format conversion functions
31 static media::VideoPixelFormat V4L2PixFmtToVideoPixelFormat(uint32 format);
32 static uint32 VideoPixelFormatToV4L2PixFmt(media::VideoPixelFormat format);
33 static uint32 VideoCodecProfileToV4L2PixFmt(media::VideoCodecProfile profile,
34 bool slice_based);
35 static uint32_t V4L2PixFmtToDrmFormat(uint32_t format);
36 // Convert format requirements requested by a V4L2 device to gfx::Size.
37 static gfx::Size CodedSizeFromV4L2Format(struct v4l2_format format);
39 enum Type {
40 kDecoder,
41 kEncoder,
42 kImageProcessor,
43 kJpegDecoder,
46 // Creates and initializes an appropriate V4L2Device of |type| for the
47 // current platform and returns a scoped_ptr<V4L2Device> on success, or NULL.
48 static scoped_refptr<V4L2Device> Create(Type type);
50 // Parameters and return value are the same as for the standard ioctl() system
51 // call.
52 virtual int Ioctl(int request, void* arg) = 0;
54 // This method sleeps until either:
55 // - SetDevicePollInterrupt() is called (on another thread),
56 // - |poll_device| is true, and there is new data to be read from the device,
57 // or an event from the device has arrived; in the latter case
58 // |*event_pending| will be set to true.
59 // Returns false on error, true otherwise.
60 // This method should be called from a separate thread.
61 virtual bool Poll(bool poll_device, bool* event_pending) = 0;
63 // These methods are used to interrupt the thread sleeping on Poll() and force
64 // it to return regardless of device state, which is usually when the client
65 // is no longer interested in what happens with the device (on cleanup,
66 // client state change, etc.). When SetDevicePollInterrupt() is called, Poll()
67 // will return immediately, and any subsequent calls to it will also do so
68 // until ClearDevicePollInterrupt() is called.
69 virtual bool SetDevicePollInterrupt() = 0;
70 virtual bool ClearDevicePollInterrupt() = 0;
72 // Wrappers for standard mmap/munmap system calls.
73 virtual void* Mmap(void* addr,
74 unsigned int len,
75 int prot,
76 int flags,
77 unsigned int offset) = 0;
78 virtual void Munmap(void* addr, unsigned int len) = 0;
80 // Initializes the V4L2Device to operate as a device of |type|.
81 // Returns true on success.
82 virtual bool Initialize() = 0;
84 // Return true if the given V4L2 pixfmt can be used in CreateEGLImage()
85 // for the current platform.
86 virtual bool CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) = 0;
88 // Creates an EGLImageKHR since each V4L2Device may use a different method of
89 // acquiring one and associating it to the given texture. The texture_id is
90 // used to bind the texture to the returned EGLImageKHR. buffer_index can be
91 // used to associate the returned EGLImageKHR by the underlying V4L2Device
92 // implementation.
93 virtual EGLImageKHR CreateEGLImage(EGLDisplay egl_display,
94 EGLContext egl_context,
95 GLuint texture_id,
96 gfx::Size frame_buffer_size,
97 unsigned int buffer_index,
98 uint32_t v4l2_pixfmt,
99 size_t num_v4l2_planes) = 0;
101 // Destroys the EGLImageKHR.
102 virtual EGLBoolean DestroyEGLImage(EGLDisplay egl_display,
103 EGLImageKHR egl_image) = 0;
105 // Returns the supported texture target for the V4L2Device.
106 virtual GLenum GetTextureTarget() = 0;
108 // Returns the preferred V4L2 input format or 0 if don't care.
109 virtual uint32 PreferredInputFormat() = 0;
111 // Get minimum and maximum resolution for fourcc |pixelformat| and store to
112 // |min_resolution| and |max_resolution|.
113 void GetSupportedResolution(uint32_t pixelformat, gfx::Size* min_resolution,
114 gfx::Size* max_resolution);
116 // Return supported profiles for decoder, including only profiles for given
117 // fourcc |pixelformats|.
118 media::VideoDecodeAccelerator::SupportedProfiles GetSupportedDecodeProfiles(
119 const size_t num_formats, const uint32_t pixelformats[]);
121 protected:
122 friend class base::RefCountedThreadSafe<V4L2Device>;
123 explicit V4L2Device(Type type);
124 virtual ~V4L2Device();
126 const Type type_;
129 } // namespace content
131 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_DEVICE_H_