Go to the documentation of this file.
24 #include <linux/videodev2.h>
25 #include <sys/ioctl.h>
40 if (cap->capabilities & (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT) &&
41 cap->capabilities & V4L2_CAP_STREAMING)
44 if (cap->capabilities & V4L2_CAP_VIDEO_M2M)
52 if (cap->capabilities & (V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_OUTPUT_MPLANE) &&
53 cap->capabilities & V4L2_CAP_STREAMING)
56 if (cap->capabilities & V4L2_CAP_VIDEO_M2M_MPLANE)
64 struct v4l2_capability cap;
65 void *log_ctx =
s->avctx;
68 s->capture.done =
s->output.done = 0;
69 s->capture.name =
"capture";
70 s->output.name =
"output";
74 memset(&cap, 0,
sizeof(cap));
75 ret = ioctl(
s->fd, VIDIOC_QUERYCAP, &cap);
80 "driver '%s' on card '%s' in %s mode\n", cap.driver, cap.card,
85 s->capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
86 s->output.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
91 s->capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
92 s->output.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
101 void *log_ctx =
s->avctx;
104 s->fd = open(
s->devname, O_RDWR | O_NONBLOCK, 0);
125 if (close(
s->fd) < 0) {
137 void *log_ctx =
s->avctx;
139 struct v4l2_format ofmt, cfmt;
141 s->fd = open(
s->devname, O_RDWR | O_NONBLOCK, 0);
149 ofmt =
s->output.format;
150 cfmt =
s->capture.format;
153 ofmt.fmt.pix_mp.pixelformat :
154 ofmt.fmt.pix.pixelformat),
157 cfmt.fmt.pix_mp.pixelformat :
158 cfmt.fmt.pix.pixelformat),
191 if (close(
s->fd) < 0) {
208 void *log_ctx =
s->avctx;
224 while(
sem_wait(&
s->refsync) == -1 && errno == EINTR);
293 struct dirent *
entry;
298 dirp = opendir(
"/dev");
304 if (strncmp(
entry->d_name,
"video", 5))
318 memset(
s->devname, 0,
sizeof(
s->devname));
static void error(const char *err)
int ff_v4l2_context_init(V4L2Context *ctx)
Initializes a V4L2Context.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int ff_v4l2_m2m_codec_reinit(V4L2m2mContext *s)
Reinitializes the V4L2m2mContext when the driver cannot continue processing with the capture paramete...
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static int v4l2_mplane_video(struct v4l2_capability *cap)
void ff_v4l2_context_release(V4L2Context *ctx)
Releases a V4L2Context.
static int v4l2_probe_driver(V4L2m2mContext *s)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int ff_v4l2_context_set_format(V4L2Context *ctx)
Sets the V4L2Context format in the v4l2 driver.
static int v4l2_splane_video(struct v4l2_capability *cap)
int ff_v4l2_context_get_format(V4L2Context *ctx, int probe)
Queries the driver for a valid v4l2 format and copies it to the context.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static void v4l2_m2m_destroy_context(void *opaque, uint8_t *context)
int ff_v4l2_m2m_codec_init(V4L2m2mPriv *priv)
Probes the video nodes looking for the required codec capabilities.
#define atomic_load(object)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your context
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
static int v4l2_configure_contexts(V4L2m2mContext *s)
static int v4l2_prepare_contexts(V4L2m2mContext *s, int probe)
int ff_v4l2_m2m_create_context(V4L2m2mPriv *priv, V4L2m2mContext **s)
Allocate a new context and references for a V4L2 M2M instance.
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
int av_codec_is_decoder(const AVCodec *codec)
int ff_v4l2_m2m_codec_end(V4L2m2mPriv *priv)
Releases all the codec resources if all AVBufferRefs have been returned to the ctx.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_LOG_INFO
Standard information.
int ff_v4l2_context_set_status(V4L2Context *ctx, uint32_t cmd)
Sets the status of a V4L2Context.
int num_buffers
Readonly after init.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
AVBufferRef * context_ref
#define sem_destroy(psem)
static int probe(const AVProbeData *p)
#define atomic_init(obj, value)
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
#define av_fourcc2str(fourcc)