FFmpeg
v4l2_buffers.h
Go to the documentation of this file.
1 /*
2  * V4L2 buffer helper functions.
3  *
4  * Copyright (C) 2017 Alexis Ballier <aballier@gentoo.org>
5  * Copyright (C) 2017 Jorge Ramirez <jorge.ramirez-ortiz@linaro.org>
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #ifndef AVCODEC_V4L2_BUFFERS_H
25 #define AVCODEC_V4L2_BUFFERS_H
26 
27 #include <stdatomic.h>
28 #include <stddef.h>
29 #include <linux/videodev2.h>
30 
31 #include "libavutil/buffer.h"
32 #include "libavutil/frame.h"
33 #include "packet.h"
34 
39 };
40 
41 /**
42  * V4L2Buffer (wrapper for v4l2_buffer management)
43  */
44 typedef struct V4L2Buffer {
45  /* each buffer needs to have a reference to its context */
47 
48  /* This object is refcounted per-plane, so we need to keep track
49  * of how many context-refs we are holding. */
52 
53  /* keep track of the mmap address and mmap length */
54  struct V4L2Plane_info {
56  void * mm_addr;
57  size_t length;
58  } plane_info[VIDEO_MAX_PLANES];
59 
61 
62  /* the v4l2_buffer buf.m.planes pointer uses the planes[] mem */
63  struct v4l2_buffer buf;
64  struct v4l2_plane planes[VIDEO_MAX_PLANES];
65 
66  int flags;
68 
69 } V4L2Buffer;
70 
71 /**
72  * Extracts the data from a V4L2Buffer to an AVFrame
73  *
74  * @param[in] frame The AVFRame to push the information to
75  * @param[in] buf The V4L2Buffer to get the information from
76  *
77  * @returns 0 in case of success, AVERROR(EINVAL) if the number of planes is incorrect,
78  * AVERROR(ENOMEM) if the AVBufferRef can't be created.
79  */
81 
82 /**
83  * Extracts the data from a V4L2Buffer to an AVPacket
84  *
85  * @param[in] pkt The AVPacket to push the information to
86  * @param[in] buf The V4L2Buffer to get the information from
87  *
88  * @returns 0 in case of success, AVERROR(EINVAL) if the number of planes is incorrect,
89  * AVERROR(ENOMEM) if the AVBufferRef can't be created.
90  *
91  */
93 
94 /**
95  * Extracts the data from an AVPacket to a V4L2Buffer
96  *
97  * @param[in] frame AVPacket to get the data from
98  * @param[in] avbuf V4L2Bfuffer to push the information to
99  *
100  * @returns 0 in case of success, a negative AVERROR code otherwise
101  */
103 
104 /**
105  * Extracts the data from an AVFrame to a V4L2Buffer
106  *
107  * @param[in] frame AVFrame to get the data from
108  * @param[in] avbuf V4L2Bfuffer to push the information to
109  *
110  * @returns 0 in case of success, a negative AVERROR code otherwise
111  */
113 
114 /**
115  * Initializes a V4L2Buffer
116  *
117  * @param[in] avbuf V4L2Bfuffer to initialize
118  * @param[in] index v4l2 buffer id
119  *
120  * @returns 0 in case of success, a negative AVERROR code otherwise
121  */
123 
124 /**
125  * Enqueues a V4L2Buffer
126  *
127  * @param[in] avbuf V4L2Bfuffer to push to the driver
128  *
129  * @returns 0 in case of success, a negative AVERROR code otherwise
130  */
132 
133 
134 #endif // AVCODEC_V4L2_BUFFERS_H
V4L2Buffer::num_planes
int num_planes
Definition: v4l2_buffers.h:60
ff_v4l2_buffer_initialize
int ff_v4l2_buffer_initialize(V4L2Buffer *avbuf, int index)
Initializes a V4L2Buffer.
Definition: v4l2_buffers.c:494
out
FILE * out
Definition: movenc.c:54
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
V4L2Buffer::V4L2Plane_info::length
size_t length
Definition: v4l2_buffers.h:57
ff_v4l2_buffer_avframe_to_buf
int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, V4L2Buffer *out)
Extracts the data from an AVFrame to a V4L2Buffer.
Definition: v4l2_buffers.c:411
ff_v4l2_buffer_enqueue
int ff_v4l2_buffer_enqueue(V4L2Buffer *avbuf)
Enqueues a V4L2Buffer.
Definition: v4l2_buffers.c:561
V4L2Buffer::V4L2Plane_info
Definition: v4l2_buffers.h:54
V4L2Buffer::buf
struct v4l2_buffer buf
Definition: v4l2_buffers.h:63
V4L2Buffer::context
struct V4L2Context * context
Definition: v4l2_buffers.h:46
pkt
AVPacket * pkt
Definition: movenc.c:59
V4L2Buffer
V4L2Buffer (wrapper for v4l2_buffer management)
Definition: v4l2_buffers.h:44
V4L2BUF_RET_USER
@ V4L2BUF_RET_USER
Definition: v4l2_buffers.h:38
frame
static AVFrame * frame
Definition: demux_decode.c:54
V4L2Context
Definition: v4l2_context.h:37
V4L2Buffer::V4L2Plane_info::mm_addr
void * mm_addr
Definition: v4l2_buffers.h:56
ff_v4l2_buffer_buf_to_avpkt
int ff_v4l2_buffer_buf_to_avpkt(AVPacket *pkt, V4L2Buffer *buf)
Extracts the data from a V4L2Buffer to an AVPacket.
Definition: v4l2_buffers.c:453
index
int index
Definition: gxfenc.c:89
V4L2BUF_AVAILABLE
@ V4L2BUF_AVAILABLE
Definition: v4l2_buffers.h:36
V4L2Buffer::context_ref
AVBufferRef * context_ref
Definition: v4l2_buffers.h:50
V4L2BUF_IN_DRIVER
@ V4L2BUF_IN_DRIVER
Definition: v4l2_buffers.h:37
frame.h
buffer.h
V4L2Buffer::context_refcount
atomic_uint context_refcount
Definition: v4l2_buffers.h:51
packet.h
plane_info
Definition: vf_edgedetect.c:52
V4L2Buffer::flags
int flags
Definition: v4l2_buffers.h:66
V4L2Buffer::planes
struct v4l2_plane planes[VIDEO_MAX_PLANES]
Definition: v4l2_buffers.h:64
V4L2Buffer::V4L2Plane_info::bytesperline
int bytesperline
Definition: v4l2_buffers.h:55
ff_v4l2_buffer_avpkt_to_buf
int ff_v4l2_buffer_avpkt_to_buf(const AVPacket *pkt, V4L2Buffer *out)
Extracts the data from an AVPacket to a V4L2Buffer.
Definition: v4l2_buffers.c:478
atomic_uint
intptr_t atomic_uint
Definition: stdatomic.h:56
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AVPacket
This structure stores compressed data.
Definition: packet.h:499
ff_v4l2_buffer_buf_to_avframe
int ff_v4l2_buffer_buf_to_avframe(AVFrame *frame, V4L2Buffer *buf)
Extracts the data from a V4L2Buffer to an AVFrame.
Definition: v4l2_buffers.c:418
V4L2Buffer_status
V4L2Buffer_status
Definition: v4l2_buffers.h:35
V4L2Buffer::status
enum V4L2Buffer_status status
Definition: v4l2_buffers.h:67