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_VIDEO_DEVICE_H_
10 #define CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DEVICE_H_
12 #include "media/base/video_decoder_config.h"
13 #include "media/base/video_frame.h"
14 #include "ui/gfx/geometry/size.h"
15 #include "ui/gl/gl_bindings.h"
21 // Utility format conversion functions
22 static media::VideoFrame::Format
V4L2PixFmtToVideoFrameFormat(uint32 format
);
23 static uint32
VideoFrameFormatToV4L2PixFmt(media::VideoFrame::Format format
);
24 static uint32
VideoCodecProfileToV4L2PixFmt(media::VideoCodecProfile profile
);
25 // Convert format requirements requested by a V4L2 device to gfx::Size.
26 static gfx::Size
CodedSizeFromV4L2Format(struct v4l2_format format
);
28 virtual ~V4L2Device();
36 // Creates and initializes an appropriate V4L2Device of |type| for the
37 // current platform and returns a scoped_ptr<V4L2Device> on success, or NULL.
38 static scoped_ptr
<V4L2Device
> Create(Type type
);
40 // Parameters and return value are the same as for the standard ioctl() system
42 virtual int Ioctl(int request
, void* arg
) = 0;
44 // This method sleeps until either:
45 // - SetDevicePollInterrupt() is called (on another thread),
46 // - |poll_device| is true, and there is new data to be read from the device,
47 // or an event from the device has arrived; in the latter case
48 // |*event_pending| will be set to true.
49 // Returns false on error, true otherwise.
50 // This method should be called from a separate thread.
51 virtual bool Poll(bool poll_device
, bool* event_pending
) = 0;
53 // These methods are used to interrupt the thread sleeping on Poll() and force
54 // it to return regardless of device state, which is usually when the client
55 // is no longer interested in what happens with the device (on cleanup,
56 // client state change, etc.). When SetDevicePollInterrupt() is called, Poll()
57 // will return immediately, and any subsequent calls to it will also do so
58 // until ClearDevicePollInterrupt() is called.
59 virtual bool SetDevicePollInterrupt() = 0;
60 virtual bool ClearDevicePollInterrupt() = 0;
62 // Wrappers for standard mmap/munmap system calls.
63 virtual void* Mmap(void* addr
,
67 unsigned int offset
) = 0;
68 virtual void Munmap(void* addr
, unsigned int len
) = 0;
70 // Initializes the V4L2Device to operate as a device of |type|.
71 // Returns true on success.
72 virtual bool Initialize() = 0;
74 // Creates an EGLImageKHR since each V4L2Device may use a different method of
75 // acquiring one and associating it to the given texture. The texture_id is
76 // used to bind the texture to the returned EGLImageKHR. buffer_index can be
77 // used to associate the returned EGLImageKHR by the underlying V4L2Device
79 virtual EGLImageKHR
CreateEGLImage(EGLDisplay egl_display
,
80 EGLContext egl_context
,
82 gfx::Size frame_buffer_size
,
83 unsigned int buffer_index
,
84 size_t planes_count
) = 0;
86 // Destroys the EGLImageKHR.
87 virtual EGLBoolean
DestroyEGLImage(EGLDisplay egl_display
,
88 EGLImageKHR egl_image
) = 0;
90 // Returns the supported texture target for the V4L2Device.
91 virtual GLenum
GetTextureTarget() = 0;
93 // Returns the preferred V4L2 input format or 0 if don't care.
94 virtual uint32
PreferredInputFormat() = 0;
96 // Returns the preferred V4L2 output format or 0 if don't care.
97 virtual uint32
PreferredOutputFormat() = 0;
100 } // namespace content
102 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DEVICE_H_