24 #include <linux/videodev2.h>
25 #include <sys/ioctl.h>
42 struct v4l2_selection selection = { 0 };
59 ret = ioctl(
s->fd, VIDIOC_G_FMT, &capture->
format);
70 selection.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
73 ret = ioctl(
s->fd, VIDIOC_S_SELECTION, &selection);
75 ret = ioctl(
s->fd, VIDIOC_G_SELECTION, &selection);
79 av_log(avctx,
AV_LOG_DEBUG,
"crop output %dx%d\n", selection.r.width, selection.r.height);
81 capture->
height = selection.r.height;
82 capture->
width = selection.r.width;
107 struct v4l2_event_subscription
sub;
114 memset(&
sub, 0,
sizeof(
sub));
115 sub.type = V4L2_EVENT_SOURCE_CHANGE;
116 ret = ioctl(
s->fd, VIDIOC_SUBSCRIBE_EVENT, &
sub);
118 if (output->height == 0 || output->width == 0) {
120 "the v4l2 driver does not support VIDIOC_SUBSCRIBE_EVENT\n"
121 "you must provide codec_height and codec_width on input\n");
126 memset(&
sub, 0,
sizeof(
sub));
127 sub.type = V4L2_EVENT_EOS;
128 ret = ioctl(
s->fd, VIDIOC_SUBSCRIBE_EVENT, &
sub);
131 "the v4l2 driver does not support end of stream VIDIOC_SUBSCRIBE_EVENT\n");
143 if (!
s->buf_pkt.size) {
153 if (ret < 0 && ret !=
AVERROR(EAGAIN))
188 capture = &
s->capture;
219 #define OFFSET(x) offsetof(V4L2m2mPriv, x)
220 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
224 {
"num_capture_buffers",
"Number of buffers in the capture context",
229 #define M2MDEC_CLASS(NAME) \
230 static const AVClass v4l2_m2m_ ## NAME ## _dec_class = { \
231 .class_name = #NAME "_v4l2m2m_decoder", \
232 .item_name = av_default_item_name, \
234 .version = LIBAVUTIL_VERSION_INT, \
237 #define M2MDEC(NAME, LONGNAME, CODEC, bsf_name) \
239 AVCodec ff_ ## NAME ## _v4l2m2m_decoder = { \
240 .name = #NAME "_v4l2m2m" , \
241 .long_name = NULL_IF_CONFIG_SMALL("V4L2 mem2mem " LONGNAME " decoder wrapper"), \
242 .type = AVMEDIA_TYPE_VIDEO, \
244 .priv_data_size = sizeof(V4L2m2mPriv), \
245 .priv_class = &v4l2_m2m_ ## NAME ## _dec_class, \
246 .init = v4l2_decode_init, \
247 .receive_frame = v4l2_receive_frame, \
248 .close = v4l2_decode_close, \
250 .capabilities = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING, \
251 .caps_internal = FF_CODEC_CAP_SETS_PKT_DTS | FF_CODEC_CAP_INIT_CLEANUP, \
252 .wrapper_name = "v4l2m2m", \
Libavcodec external API header.
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
static float sub(float src0, float src1)
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AVERROR_EOF
End of file.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
common internal api header.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int coded_width
Bitstream width / height, may be different from width/height e.g.
This structure describes decoded (raw) audio or video data.
enum AVPixelFormat av_pix_fmt
AVPixelFormat corresponding to this buffer context.
enum v4l2_buf_type type
Type of this buffer context.
int width
Width and height of the frames it produces (in case of a capture context, e.g.
struct v4l2_format format
Format returned by the driver after initializing the buffer context.
enum AVCodecID av_codec_id
AVCodecID 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_dequeue_frame(V4L2Context *ctx, AVFrame *frame, int timeout)
Dequeues a buffer from a V4L2Context to an AVFrame.
int ff_v4l2_context_set_status(V4L2Context *ctx, uint32_t cmd)
Sets the status of a V4L2Context.
int ff_v4l2_context_enqueue_packet(V4L2Context *ctx, const AVPacket *pkt)
Enqueues a buffer to a V4L2Context from an AVPacket.
int ff_v4l2_context_init(V4L2Context *ctx)
Initializes a V4L2Context.
enum AVPixelFormat ff_v4l2_format_v4l2_to_avfmt(uint32_t v4l2_fmt, enum AVCodecID avcodec)
int ff_v4l2_m2m_create_context(V4L2m2mPriv *priv, V4L2m2mContext **s)
Allocate a new context and references for a V4L2 M2M instance.
int ff_v4l2_m2m_codec_init(V4L2m2mPriv *priv)
Probes the video nodes looking for the required codec capabilities.
int ff_v4l2_m2m_codec_end(V4L2m2mPriv *priv)
Releases all the codec resources if all AVBufferRefs have been returned to the ctx.
#define V4L_M2M_DEFAULT_OPTS
static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame)
static const AVOption options[]
static int v4l2_try_start(AVCodecContext *avctx)
#define M2MDEC(NAME, LONGNAME, CODEC, bsf_name)
static av_cold int v4l2_decode_close(AVCodecContext *avctx)
static int v4l2_prepare_decoder(V4L2m2mContext *s)
static av_cold int v4l2_decode_init(AVCodecContext *avctx)