Add common helpers for supporting V4L2 Request API hwaccels. Basic flow for initialization follow the kernel Memory-to-memory Stateless Video Decoder Interface > Initialization [1]. In init video devices is probed and when a capable device is found it is initialized for decoding. Codec specific CONTROLs may be set to assist kernel driver. A supported CAPTURE format is selected. A hw frame ctx is created and CAPTURE buffers is allocated. OUTPUT buffers and request objects for a circular queue is also allocated. In frame_params a buffer pool is created and configured to allocate CAPTURE buffers. In flush all queued OUTPUT and CAPTURE buffers is dequeued. In uninit any pending request is flushed, also video and media device is closed. The media device is not closed when ownership of the media_fd has been transfered to the hwdevice. [1] https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/dev-stateless-decoder.html#initialization Co-developed-by: Jernej Skrabec <jernej.skrabec@gmail.com> Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com> Co-developed-by: Alex Bee <knaerzche@gmail.com> Signed-off-by: Alex Bee <knaerzche@gmail.com> Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
84 lines
2.7 KiB
C
84 lines
2.7 KiB
C
/*
|
|
* This file is part of FFmpeg.
|
|
*
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
#ifndef AVCODEC_V4L2_REQUEST_H
|
|
#define AVCODEC_V4L2_REQUEST_H
|
|
|
|
#include <stdatomic.h>
|
|
#include <stdbool.h>
|
|
|
|
#include <linux/videodev2.h>
|
|
|
|
#include "libavutil/hwcontext_drm.h"
|
|
#include "libavutil/thread.h"
|
|
|
|
typedef struct V4L2RequestBuffer {
|
|
int index;
|
|
int fd;
|
|
uint8_t *addr;
|
|
uint32_t width;
|
|
uint32_t height;
|
|
uint32_t size;
|
|
uint32_t used;
|
|
uint32_t capabilities;
|
|
struct v4l2_buffer buffer;
|
|
} V4L2RequestBuffer;
|
|
|
|
typedef struct V4L2RequestContext {
|
|
const AVClass *av_class;
|
|
AVBufferRef *device_ref;
|
|
int media_fd;
|
|
int video_fd;
|
|
struct v4l2_format format;
|
|
enum v4l2_buf_type output_type;
|
|
AVMutex mutex;
|
|
V4L2RequestBuffer output[4];
|
|
atomic_int_least8_t next_output;
|
|
atomic_uint_least32_t queued_output;
|
|
atomic_uint_least32_t queued_request;
|
|
atomic_uint_least64_t queued_capture;
|
|
int (*post_probe)(AVCodecContext *avctx);
|
|
} V4L2RequestContext;
|
|
|
|
typedef struct V4L2RequestPictureContext {
|
|
V4L2RequestBuffer *output;
|
|
V4L2RequestBuffer *capture;
|
|
} V4L2RequestPictureContext;
|
|
|
|
int ff_v4l2_request_query_control(AVCodecContext *avctx,
|
|
struct v4l2_query_ext_ctrl *control);
|
|
|
|
int ff_v4l2_request_query_control_default_value(AVCodecContext *avctx,
|
|
uint32_t id);
|
|
|
|
int ff_v4l2_request_set_request_controls(V4L2RequestContext *ctx, int request_fd,
|
|
struct v4l2_ext_control *control, int count);
|
|
|
|
int ff_v4l2_request_set_controls(AVCodecContext *avctx,
|
|
struct v4l2_ext_control *control, int count);
|
|
|
|
int ff_v4l2_request_frame_params(AVCodecContext *avctx,
|
|
AVBufferRef *hw_frames_ctx);
|
|
|
|
int ff_v4l2_request_uninit(AVCodecContext *avctx);
|
|
|
|
int ff_v4l2_request_init(AVCodecContext *avctx,
|
|
uint32_t pixelformat, uint32_t buffersize,
|
|
struct v4l2_ext_control *control, int count);
|
|
|
|
#endif /* AVCODEC_V4L2_REQUEST_H */
|