24#include <linux/videodev2.h>
39#define USEC_PER_SEC 1000000
60 if (
s->avctx->pkt_timebase.num)
61 return s->avctx->pkt_timebase;
62 return s->avctx->time_base;
84 avbuf->
buf.timestamp.tv_usec;
91 enum v4l2_ycbcr_encoding ycbcr;
92 enum v4l2_colorspace cs;
94 cs = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
98 ycbcr = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
103 case V4L2_YCBCR_ENC_XV709:
105 case V4L2_YCBCR_ENC_XV601:
125 enum v4l2_quantization qt;
127 qt = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
143 enum v4l2_ycbcr_encoding ycbcr;
144 enum v4l2_colorspace cs;
146 cs = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
150 ycbcr = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
161 case V4L2_COLORSPACE_BT2020:
162 if (ycbcr == V4L2_YCBCR_ENC_BT2020_CONST_LUM)
175 enum v4l2_ycbcr_encoding ycbcr;
176 enum v4l2_xfer_func xfer;
177 enum v4l2_colorspace cs;
179 cs = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
183 ycbcr = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
187 xfer = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
211 case V4L2_YCBCR_ENC_XV709:
222 enum v4l2_field field = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
227 case V4L2_FIELD_INTERLACED:
228 case V4L2_FIELD_INTERLACED_TB:
231 case V4L2_FIELD_INTERLACED_BT:
249 if (
s->draining && V4L2_TYPE_IS_OUTPUT(avbuf->
context->
type)) {
301 unsigned int bytesused, length;
303 if (plane >=
out->num_planes)
306 length =
out->plane_info[plane].length;
311 if (V4L2_TYPE_IS_MULTIPLANAR(
out->buf.type)) {
312 out->planes[plane].bytesused = bytesused;
313 out->planes[plane].length = length;
315 out->buf.bytesused = bytesused;
316 out->buf.length = length;
366 struct v4l2_format fmt =
out->context->format;
367 int pixel_format = V4L2_TYPE_IS_MULTIPLANAR(fmt.type) ?
368 fmt.fmt.pix_mp.pixelformat : fmt.fmt.pix.pixelformat;
369 int height = V4L2_TYPE_IS_MULTIPLANAR(fmt.type) ?
370 fmt.fmt.pix_mp.height : fmt.fmt.pix.height;
371 int is_planar_format = 0;
373 switch (pixel_format) {
374 case V4L2_PIX_FMT_YUV420M:
375 case V4L2_PIX_FMT_YVU420M:
376#ifdef V4L2_PIX_FMT_YUV422M
377 case V4L2_PIX_FMT_YUV422M:
379#ifdef V4L2_PIX_FMT_YVU422M
380 case V4L2_PIX_FMT_YVU422M:
382#ifdef V4L2_PIX_FMT_YUV444M
383 case V4L2_PIX_FMT_YUV444M:
385#ifdef V4L2_PIX_FMT_YVU444M
386 case V4L2_PIX_FMT_YVU444M:
388 case V4L2_PIX_FMT_NV12M:
389 case V4L2_PIX_FMT_NV21M:
390 case V4L2_PIX_FMT_NV12MT_16X16:
391 case V4L2_PIX_FMT_NV12MT:
392 case V4L2_PIX_FMT_NV16M:
393 case V4L2_PIX_FMT_NV61M:
394 is_planar_format = 1;
397 if (!is_planar_format) {
402 for (
i = 0;
i <
desc->nb_components;
i++)
403 planes_nb =
FFMAX(planes_nb,
desc->comp[
i].plane + 1);
405 for (
i = 0;
i < planes_nb;
i++) {
407 if (
i == 1 ||
i == 2) {
419 for (
i = 0;
i <
out->num_planes;
i++) {
453 if (avbuf->
buf.flags & V4L2_BUF_FLAG_KEYFRAME)
469 if (avbuf->
buf.flags & V4L2_BUF_FLAG_ERROR) {
486 pkt->size = V4L2_TYPE_IS_MULTIPLANAR(avbuf->
buf.type) ? avbuf->
buf.m.planes[0].bytesused : avbuf->
buf.bytesused;
487 pkt->data =
pkt->buf->data;
489 if (avbuf->
buf.flags & V4L2_BUF_FLAG_KEYFRAME)
492 if (avbuf->
buf.flags & V4L2_BUF_FLAG_ERROR) {
513 out->flags = V4L2_BUF_FLAG_KEYFRAME;
523 avbuf->
buf.memory = V4L2_MEMORY_MMAP;
524 avbuf->
buf.type =
ctx->type;
527 if (V4L2_TYPE_IS_MULTIPLANAR(
ctx->type)) {
528 avbuf->
buf.length = VIDEO_MAX_PLANES;
536 if (V4L2_TYPE_IS_MULTIPLANAR(
ctx->type)) {
539 for (
i = 0;
i < avbuf->
buf.length;
i++) {
540 if (avbuf->
buf.m.planes[
i].length)
549 ctx->format.fmt.pix_mp.plane_fmt[
i].bytesperline :
550 ctx->format.fmt.pix.bytesperline;
552 if (V4L2_TYPE_IS_MULTIPLANAR(
ctx->type)) {
555 PROT_READ | PROT_WRITE, MAP_SHARED,
560 PROT_READ | PROT_WRITE, MAP_SHARED,
570 if (V4L2_TYPE_IS_OUTPUT(
ctx->type))
573 if (V4L2_TYPE_IS_MULTIPLANAR(
ctx->type)) {
578 avbuf->
buf.bytesused = avbuf->
planes[0].bytesused;
579 avbuf->
buf.length = avbuf->
planes[0].length;
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define AV_CEIL_RSHIFT(a, b)
#define atomic_fetch_add_explicit(object, operand, order)
#define atomic_load(object)
#define atomic_fetch_sub_explicit(object, operand, order)
#define FF_DECODE_ERROR_INVALID_BITSTREAM
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
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, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define AV_NOPTS_VALUE
Undefined timestamp value.
Macro definitions for various function/variable attributes.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVColorRange
Visual content value range.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_JPEG
Full range content.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_NV21
as above, but U and V bytes are swapped
AVColorPrimaries
Chromaticity coordinates of the source primaries.
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
@ AVCOL_PRI_SMPTE240M
identical to above, also called "SMPTE C" even though it uses D65
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
@ AVCOL_PRI_BT2020
ITU-R BT2020.
@ AVCOL_PRI_BT470M
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
AVColorTransferCharacteristic
Color Transfer Characteristic.
@ AVCOL_TRC_SMPTE170M
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
@ AVCOL_TRC_BT1361_ECG
ITU-R BT1361 Extended Colour Gamut.
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
@ AVCOL_TRC_BT709
also ITU-R BT1361
AVColorSpace
YUV colorspace type.
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
A reference to a data buffer.
main external API structure.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Rational number (pair of numerator and denominator).
V4L2Buffer (wrapper for v4l2_buffer management)
atomic_uint context_refcount
struct V4L2Buffer::V4L2Plane_info plane_info[VIDEO_MAX_PLANES]
enum V4L2Buffer_status status
const struct V4L2m2mContext * context_ref
struct v4l2_plane planes[VIDEO_MAX_PLANES]
struct V4L2Context * context
AVRational sample_aspect_ratio
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.
const char * name
context name.
struct v4l2_format format
Format returned by the driver after initializing the buffer context.
int streamon
Whether the stream has been started (VIDIOC_STREAMON has been sent).
static AVFormatContext * ctx
static void v4l2_free_buffer(void *opaque, uint8_t *unused)
static AVRational v4l2_get_timebase(V4L2Buffer *avbuf)
static int64_t v4l2_get_pts(V4L2Buffer *avbuf)
int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, V4L2Buffer *out)
Extracts the data from an AVFrame to a V4L2Buffer.
int ff_v4l2_buffer_avpkt_to_buf(const AVPacket *pkt, V4L2Buffer *out)
Extracts the data from an AVPacket to a V4L2Buffer.
static enum AVColorSpace v4l2_get_color_space(V4L2Buffer *buf)
int ff_v4l2_buffer_buf_to_avframe(AVFrame *frame, V4L2Buffer *avbuf)
Extracts the data from a V4L2Buffer to an AVFrame.
static AVRational v4l2_timebase
static enum AVColorRange v4l2_get_color_range(V4L2Buffer *buf)
int ff_v4l2_buffer_enqueue(V4L2Buffer *avbuf)
Enqueues a V4L2Buffer.
static V4L2m2mContext * buf_to_m2mctx(V4L2Buffer *buf)
static AVCodecContext * logger(V4L2Buffer *buf)
static int v4l2_bufref_to_buf(V4L2Buffer *out, int plane, const uint8_t *data, int size, int offset)
int ff_v4l2_buffer_initialize(V4L2Buffer *avbuf, int index)
Initializes a V4L2Buffer.
static int v4l2_buffer_swframe_to_buf(const AVFrame *frame, V4L2Buffer *out)
static int v4l2_buf_to_bufref(V4L2Buffer *in, int plane, AVBufferRef **buf)
static void v4l2_set_pts(V4L2Buffer *out, int64_t pts)
static void v4l2_get_interlacing(AVFrame *frame, V4L2Buffer *buf)
static int v4l2_buf_increase_ref(V4L2Buffer *in)
int ff_v4l2_buffer_buf_to_avpkt(AVPacket *pkt, V4L2Buffer *avbuf)
Extracts the data from a V4L2Buffer to an AVPacket.
static enum AVColorTransferCharacteristic v4l2_get_color_trc(V4L2Buffer *buf)
static int v4l2_buffer_buf_to_swframe(AVFrame *frame, V4L2Buffer *avbuf)
static enum AVColorPrimaries v4l2_get_color_primaries(V4L2Buffer *buf)
#define container_of(ptr, type, member)
#define atomic_fetch_sub(object, operand)
#define atomic_fetch_add(object, operand)