24 #include <linux/videodev2.h>
25 #include <sys/ioctl.h>
41 struct v4l2_selection selection;
58 ret = ioctl(s->
fd, VIDIOC_G_FMT, &capture->
format);
69 selection.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
72 ret = ioctl(s->
fd, VIDIOC_S_SELECTION, &selection);
74 ret = ioctl(s->
fd, VIDIOC_G_SELECTION, &selection);
78 av_log(avctx,
AV_LOG_DEBUG,
"crop output %dx%d\n", selection.r.width, selection.r.height);
80 capture->
height = selection.r.height;
81 capture->
width = selection.r.width;
106 struct v4l2_event_subscription sub;
113 memset(&sub, 0,
sizeof(sub));
114 sub.type = V4L2_EVENT_SOURCE_CHANGE;
115 ret = ioctl(s->
fd, VIDIOC_SUBSCRIBE_EVENT, &sub);
117 if (output->height == 0 || output->width == 0) {
119 "the v4l2 driver does not support VIDIOC_SUBSCRIBE_EVENT\n"
120 "you must provide codec_height and codec_width on input\n");
195 #define OFFSET(x) offsetof(V4L2m2mPriv, x)
196 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
200 {
"num_capture_buffers",
"Number of buffers in the capture context",
205 #define M2MDEC(NAME, LONGNAME, CODEC, bsf_name) \
206 static const AVClass v4l2_m2m_ ## NAME ## _dec_class = {\
207 .class_name = #NAME "_v4l2_m2m_decoder",\
208 .item_name = av_default_item_name,\
210 .version = LIBAVUTIL_VERSION_INT,\
213 AVCodec ff_ ## NAME ## _v4l2m2m_decoder = { \
214 .name = #NAME "_v4l2m2m" ,\
215 .long_name = NULL_IF_CONFIG_SMALL("V4L2 mem2mem " LONGNAME " decoder wrapper"),\
216 .type = AVMEDIA_TYPE_VIDEO,\
218 .priv_data_size = sizeof(V4L2m2mPriv),\
219 .priv_class = &v4l2_m2m_ ## NAME ## _dec_class,\
220 .init = v4l2_decode_init,\
221 .receive_frame = v4l2_receive_frame,\
222 .close = ff_v4l2_m2m_codec_end,\
224 .capabilities = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY, \
225 .wrapper_name = "v4l2m2m", \
enum AVPixelFormat ff_v4l2_format_v4l2_to_avfmt(uint32_t v4l2_fmt, enum AVCodecID avcodec)
static const AVOption options[]
This structure describes decoded (raw) audio or video data.
int coded_width
Bitstream width / height, may be different from width/height e.g.
#define AV_LOG_WARNING
Something somehow does not look correct.
int ff_v4l2_context_init(V4L2Context *ctx)
Initializes a V4L2Context.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int ff_v4l2_context_dequeue_frame(V4L2Context *ctx, AVFrame *frame)
Dequeues a buffer from a V4L2Context to an AVFrame.
int width
Width and height of the frames it produces (in case of a capture context, e.g.
int ff_v4l2_m2m_codec_init(AVCodecContext *avctx)
Probes the video nodes looking for the required codec capabilities.
enum AVCodecID av_codec_id
AVCodecID corresponding to this buffer context.
static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame)
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
#define AVERROR_EOF
End of file.
int ff_v4l2_m2m_create_context(AVCodecContext *avctx, V4L2m2mContext **s)
Allocate a new context and references for a V4L2 M2M instance.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
enum AVPixelFormat av_pix_fmt
AVPixelFormat corresponding to this buffer context.
V4L2Buffer * buffers
Indexed array of V4L2Buffers.
int streamon
Whether the stream has been started (VIDIOC_STREAMON has been sent).
int ff_v4l2_context_enqueue_packet(V4L2Context *ctx, const AVPacket *pkt)
Enqueues a buffer to a V4L2Context from an AVPacket.
preferred ID for MPEG-1/2 video decoding
struct v4l2_format format
Format returned by the driver after initializing the buffer context.
int ff_v4l2_context_set_status(V4L2Context *ctx, uint32_t cmd)
Sets the status of a V4L2Context.
static int v4l2_try_start(AVCodecContext *avctx)
Libavcodec external API header.
main external API structure.
#define M2MDEC(NAME, LONGNAME, CODEC, bsf_name)
static int v4l2_prepare_decoder(V4L2m2mContext *s)
static av_cold int v4l2_decode_init(AVCodecContext *avctx)
#define V4L_M2M_DEFAULT_OPTS
This structure stores compressed data.
enum v4l2_buf_type type
Type of this buffer context.