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 "ui/gfx/geometry/size.h"
17 #include "ui/gl/gl_bindings.h"
21 class CONTENT_EXPORT V4L2Device
22 : public base::RefCountedThreadSafe
<V4L2Device
> {
24 // Utility format conversion functions
25 static media::VideoFrame::Format
V4L2PixFmtToVideoFrameFormat(uint32 format
);
26 static uint32
VideoFrameFormatToV4L2PixFmt(media::VideoFrame::Format format
);
27 static uint32
VideoCodecProfileToV4L2PixFmt(media::VideoCodecProfile profile
,
29 static uint32_t V4L2PixFmtToDrmFormat(uint32_t format
);
30 // Convert format requirements requested by a V4L2 device to gfx::Size.
31 static gfx::Size
CodedSizeFromV4L2Format(struct v4l2_format format
);
39 // Creates and initializes an appropriate V4L2Device of |type| for the
40 // current platform and returns a scoped_ptr<V4L2Device> on success, or NULL.
41 static scoped_refptr
<V4L2Device
> Create(Type type
);
43 // Parameters and return value are the same as for the standard ioctl() system
45 virtual int Ioctl(int request
, void* arg
) = 0;
47 // This method sleeps until either:
48 // - SetDevicePollInterrupt() is called (on another thread),
49 // - |poll_device| is true, and there is new data to be read from the device,
50 // or an event from the device has arrived; in the latter case
51 // |*event_pending| will be set to true.
52 // Returns false on error, true otherwise.
53 // This method should be called from a separate thread.
54 virtual bool Poll(bool poll_device
, bool* event_pending
) = 0;
56 // These methods are used to interrupt the thread sleeping on Poll() and force
57 // it to return regardless of device state, which is usually when the client
58 // is no longer interested in what happens with the device (on cleanup,
59 // client state change, etc.). When SetDevicePollInterrupt() is called, Poll()
60 // will return immediately, and any subsequent calls to it will also do so
61 // until ClearDevicePollInterrupt() is called.
62 virtual bool SetDevicePollInterrupt() = 0;
63 virtual bool ClearDevicePollInterrupt() = 0;
65 // Wrappers for standard mmap/munmap system calls.
66 virtual void* Mmap(void* addr
,
70 unsigned int offset
) = 0;
71 virtual void Munmap(void* addr
, unsigned int len
) = 0;
73 // Initializes the V4L2Device to operate as a device of |type|.
74 // Returns true on success.
75 virtual bool Initialize() = 0;
77 // Return true if the given V4L2 pixfmt can be used in CreateEGLImage()
78 // for the current platform.
79 virtual bool CanCreateEGLImageFrom(uint32_t v4l2_pixfmt
) = 0;
81 // Creates an EGLImageKHR since each V4L2Device may use a different method of
82 // acquiring one and associating it to the given texture. The texture_id is
83 // used to bind the texture to the returned EGLImageKHR. buffer_index can be
84 // used to associate the returned EGLImageKHR by the underlying V4L2Device
86 virtual EGLImageKHR
CreateEGLImage(EGLDisplay egl_display
,
87 EGLContext egl_context
,
89 gfx::Size frame_buffer_size
,
90 unsigned int buffer_index
,
92 size_t num_v4l2_planes
) = 0;
94 // Destroys the EGLImageKHR.
95 virtual EGLBoolean
DestroyEGLImage(EGLDisplay egl_display
,
96 EGLImageKHR egl_image
) = 0;
98 // Returns the supported texture target for the V4L2Device.
99 virtual GLenum
GetTextureTarget() = 0;
101 // Returns the preferred V4L2 input format or 0 if don't care.
102 virtual uint32
PreferredInputFormat() = 0;
105 friend class base::RefCountedThreadSafe
<V4L2Device
>;
106 virtual ~V4L2Device();
109 } // namespace content
111 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_DEVICE_H_