24 #include <linux/videodev2.h>
25 #include <sys/ioctl.h>
41 if (cap->capabilities & (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT) &&
42 cap->capabilities & V4L2_CAP_STREAMING)
45 if (cap->capabilities & V4L2_CAP_VIDEO_M2M)
53 if (cap->capabilities & (V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_OUTPUT_MPLANE) &&
54 cap->capabilities & V4L2_CAP_STREAMING)
57 if (cap->capabilities & V4L2_CAP_VIDEO_M2M_MPLANE)
65 struct v4l2_capability cap;
66 void *log_ctx =
s->avctx;
69 s->capture.done =
s->output.done = 0;
70 s->capture.name =
"capture";
71 s->output.name =
"output";
75 memset(&cap, 0,
sizeof(cap));
76 ret = ioctl(
s->fd, VIDIOC_QUERYCAP, &cap);
81 "driver '%s' on card '%s' in %s mode\n", cap.driver, cap.card,
86 s->capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
87 s->output.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
92 s->capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
93 s->output.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
102 void *log_ctx =
s->avctx;
105 s->fd = open(
s->devname, O_RDWR | O_NONBLOCK, 0);
126 if (close(
s->fd) < 0) {
138 void *log_ctx =
s->avctx;
140 struct v4l2_format ofmt, cfmt;
142 s->fd = open(
s->devname, O_RDWR | O_NONBLOCK, 0);
150 ofmt =
s->output.format;
151 cfmt =
s->capture.format;
154 ofmt.fmt.pix_mp.pixelformat :
155 ofmt.fmt.pix.pixelformat),
157 cfmt.fmt.pix_mp.pixelformat :
158 cfmt.fmt.pix.pixelformat));
190 if (close(
s->fd) < 0) {
207 void *log_ctx =
s->avctx;
223 while(
sem_wait(&
s->refsync) == -1 && errno == EINTR);
250 void *log_ctx =
s->avctx;
257 while(
sem_wait(&
s->refsync) == -1 && errno == EINTR);
368 struct dirent *entry;
373 dirp = opendir(
"/dev");
377 for (entry = readdir(dirp); entry; entry = readdir(dirp)) {
379 if (strncmp(entry->d_name,
"video", 5))
382 snprintf(
s->devname,
sizeof(
s->devname),
"/dev/%s", entry->d_name);
393 memset(
s->devname, 0,
sizeof(
s->devname));
static int probe(const AVProbeData *p)
Libavcodec external API header.
#define atomic_load(object)
#define atomic_init(obj, value)
int av_codec_is_decoder(const AVCodec *codec)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_create(uint8_t *data, buffer_size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
#define av_fourcc2str(fourcc)
common internal api header.
#define sem_destroy(psem)
int num_buffers
Readonly after init.
AVBufferRef * context_ref
static void error(const char *err)
void ff_v4l2_context_release(V4L2Context *ctx)
Releases a V4L2Context.
int ff_v4l2_context_get_format(V4L2Context *ctx, int probe)
Queries the driver for a valid v4l2 format and copies it to the context.
int ff_v4l2_context_set_status(V4L2Context *ctx, uint32_t cmd)
Sets the status of a V4L2Context.
int ff_v4l2_context_set_format(V4L2Context *ctx)
Sets the V4L2Context format in the v4l2 driver.
int ff_v4l2_context_init(V4L2Context *ctx)
Initializes a V4L2Context.
static int v4l2_configure_contexts(V4L2m2mContext *s)
int ff_v4l2_m2m_codec_full_reinit(V4L2m2mContext *s)
Reinitializes the V4L2m2mContext when the driver cannot continue processing with the any of the curre...
static void v4l2_m2m_destroy_context(void *opaque, uint8_t *context)
int ff_v4l2_m2m_create_context(V4L2m2mPriv *priv, V4L2m2mContext **s)
Allocate a new context and references for a V4L2 M2M instance.
static int v4l2_prepare_contexts(V4L2m2mContext *s, int probe)
static int v4l2_splane_video(struct v4l2_capability *cap)
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.
static int v4l2_mplane_video(struct v4l2_capability *cap)
int ff_v4l2_m2m_codec_reinit(V4L2m2mContext *s)
Reinitializes the V4L2m2mContext when the driver cannot continue processing with the capture paramete...
static int v4l2_probe_driver(V4L2m2mContext *s)