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.
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')
27 class CONTENT_EXPORT V4L2Device
28 : public base::RefCountedThreadSafe
<V4L2Device
> {
30 // Utility format conversion functions
31 static media::VideoFrame::Format
V4L2PixFmtToVideoFrameFormat(uint32 format
);
32 static uint32
VideoFrameFormatToV4L2PixFmt(media::VideoFrame::Format format
);
33 static uint32
VideoCodecProfileToV4L2PixFmt(media::VideoCodecProfile profile
,
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
);
45 // Creates and initializes an appropriate V4L2Device of |type| for the
46 // current platform and returns a scoped_ptr<V4L2Device> on success, or NULL.
47 static scoped_refptr
<V4L2Device
> Create(Type type
);
49 // Parameters and return value are the same as for the standard ioctl() system
51 virtual int Ioctl(int request
, void* arg
) = 0;
53 // This method sleeps until either:
54 // - SetDevicePollInterrupt() is called (on another thread),
55 // - |poll_device| is true, and there is new data to be read from the device,
56 // or an event from the device has arrived; in the latter case
57 // |*event_pending| will be set to true.
58 // Returns false on error, true otherwise.
59 // This method should be called from a separate thread.
60 virtual bool Poll(bool poll_device
, bool* event_pending
) = 0;
62 // These methods are used to interrupt the thread sleeping on Poll() and force
63 // it to return regardless of device state, which is usually when the client
64 // is no longer interested in what happens with the device (on cleanup,
65 // client state change, etc.). When SetDevicePollInterrupt() is called, Poll()
66 // will return immediately, and any subsequent calls to it will also do so
67 // until ClearDevicePollInterrupt() is called.
68 virtual bool SetDevicePollInterrupt() = 0;
69 virtual bool ClearDevicePollInterrupt() = 0;
71 // Wrappers for standard mmap/munmap system calls.
72 virtual void* Mmap(void* addr
,
76 unsigned int offset
) = 0;
77 virtual void Munmap(void* addr
, unsigned int len
) = 0;
79 // Initializes the V4L2Device to operate as a device of |type|.
80 // Returns true on success.
81 virtual bool Initialize() = 0;
83 // Return true if the given V4L2 pixfmt can be used in CreateEGLImage()
84 // for the current platform.
85 virtual bool CanCreateEGLImageFrom(uint32_t v4l2_pixfmt
) = 0;
87 // Creates an EGLImageKHR since each V4L2Device may use a different method of
88 // acquiring one and associating it to the given texture. The texture_id is
89 // used to bind the texture to the returned EGLImageKHR. buffer_index can be
90 // used to associate the returned EGLImageKHR by the underlying V4L2Device
92 virtual EGLImageKHR
CreateEGLImage(EGLDisplay egl_display
,
93 EGLContext egl_context
,
95 gfx::Size frame_buffer_size
,
96 unsigned int buffer_index
,
98 size_t num_v4l2_planes
) = 0;
100 // Destroys the EGLImageKHR.
101 virtual EGLBoolean
DestroyEGLImage(EGLDisplay egl_display
,
102 EGLImageKHR egl_image
) = 0;
104 // Returns the supported texture target for the V4L2Device.
105 virtual GLenum
GetTextureTarget() = 0;
107 // Returns the preferred V4L2 input format or 0 if don't care.
108 virtual uint32
PreferredInputFormat() = 0;
110 // Get minimum and maximum resolution for fourcc |pixelformat| and store to
111 // |min_resolution| and |max_resolution|.
112 void GetSupportedResolution(uint32_t pixelformat
, gfx::Size
* min_resolution
,
113 gfx::Size
* max_resolution
);
115 // Return supported profiles for decoder, including only profiles for given
116 // fourcc |pixelformats|.
117 media::VideoDecodeAccelerator::SupportedProfiles
GetSupportedDecodeProfiles(
118 const size_t num_formats
, const uint32_t pixelformats
[]);
121 friend class base::RefCountedThreadSafe
<V4L2Device
>;
122 explicit V4L2Device(Type type
);
123 virtual ~V4L2Device();
128 } // namespace content
130 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_DEVICE_H_