FFmpeg
Loading...
Searching...
No Matches
v4l2_buffers.c
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#include <linux/videodev2.h>
25#include <sys/ioctl.h>
26#include <sys/mman.h>
27#include <unistd.h>
28#include <fcntl.h>
29#include <poll.h>
30#include "libavcodec/avcodec.h"
32#include "libavutil/pixdesc.h"
33#include "libavutil/refstruct.h"
34#include "v4l2_context.h"
35#include "v4l2_buffers.h"
36#include "v4l2_m2m.h"
37
38#ifndef USEC_PER_SEC
39#define USEC_PER_SEC 1000000
40#endif
41
43
45{
46 return V4L2_TYPE_IS_OUTPUT(buf->context->type) ?
47 container_of(buf->context, V4L2m2mContext, output) :
48 container_of(buf->context, V4L2m2mContext, capture);
49}
50
51static inline AVCodecContext *logger(V4L2Buffer *buf)
52{
53 return buf_to_m2mctx(buf)->avctx;
54}
55
57{
59
60 if (s->avctx->pkt_timebase.num)
61 return s->avctx->pkt_timebase;
62 return s->avctx->time_base;
63}
64
65static inline void v4l2_set_pts(V4L2Buffer *out, int64_t pts)
66{
67 int64_t v4l2_pts;
68
69 if (pts == AV_NOPTS_VALUE)
70 pts = 0;
71
72 /* convert pts to v4l2 timebase */
74 out->buf.timestamp.tv_usec = v4l2_pts % USEC_PER_SEC;
75 out->buf.timestamp.tv_sec = v4l2_pts / USEC_PER_SEC;
76}
77
78static inline int64_t v4l2_get_pts(V4L2Buffer *avbuf)
79{
80 int64_t v4l2_pts;
81
82 /* convert pts back to encoder timebase */
83 v4l2_pts = (int64_t)avbuf->buf.timestamp.tv_sec * USEC_PER_SEC +
84 avbuf->buf.timestamp.tv_usec;
85
86 return av_rescale_q(v4l2_pts, v4l2_timebase, v4l2_get_timebase(avbuf));
87}
88
90{
91 enum v4l2_ycbcr_encoding ycbcr;
92 enum v4l2_colorspace cs;
93
94 cs = V4L2_TYPE_IS_MULTIPLANAR(buf->buf.type) ?
95 buf->context->format.fmt.pix_mp.colorspace :
96 buf->context->format.fmt.pix.colorspace;
97
98 ycbcr = V4L2_TYPE_IS_MULTIPLANAR(buf->buf.type) ?
99 buf->context->format.fmt.pix_mp.ycbcr_enc:
100 buf->context->format.fmt.pix.ycbcr_enc;
101
102 switch(ycbcr) {
103 case V4L2_YCBCR_ENC_XV709:
104 case V4L2_YCBCR_ENC_709: return AVCOL_PRI_BT709;
105 case V4L2_YCBCR_ENC_XV601:
106 case V4L2_YCBCR_ENC_601:return AVCOL_PRI_BT470M;
107 default:
108 break;
109 }
110
111 switch(cs) {
112 case V4L2_COLORSPACE_470_SYSTEM_BG: return AVCOL_PRI_BT470BG;
113 case V4L2_COLORSPACE_SMPTE170M: return AVCOL_PRI_SMPTE170M;
114 case V4L2_COLORSPACE_SMPTE240M: return AVCOL_PRI_SMPTE240M;
115 case V4L2_COLORSPACE_BT2020: return AVCOL_PRI_BT2020;
116 default:
117 break;
118 }
119
121}
122
124{
125 enum v4l2_quantization qt;
126
127 qt = V4L2_TYPE_IS_MULTIPLANAR(buf->buf.type) ?
128 buf->context->format.fmt.pix_mp.quantization :
129 buf->context->format.fmt.pix.quantization;
130
131 switch (qt) {
132 case V4L2_QUANTIZATION_LIM_RANGE: return AVCOL_RANGE_MPEG;
133 case V4L2_QUANTIZATION_FULL_RANGE: return AVCOL_RANGE_JPEG;
134 default:
135 break;
136 }
137
139}
140
142{
143 enum v4l2_ycbcr_encoding ycbcr;
144 enum v4l2_colorspace cs;
145
146 cs = V4L2_TYPE_IS_MULTIPLANAR(buf->buf.type) ?
147 buf->context->format.fmt.pix_mp.colorspace :
148 buf->context->format.fmt.pix.colorspace;
149
150 ycbcr = V4L2_TYPE_IS_MULTIPLANAR(buf->buf.type) ?
151 buf->context->format.fmt.pix_mp.ycbcr_enc:
152 buf->context->format.fmt.pix.ycbcr_enc;
153
154 switch(cs) {
155 case V4L2_COLORSPACE_SRGB: return AVCOL_SPC_RGB;
156 case V4L2_COLORSPACE_REC709: return AVCOL_SPC_BT709;
157 case V4L2_COLORSPACE_470_SYSTEM_M: return AVCOL_SPC_FCC;
158 case V4L2_COLORSPACE_470_SYSTEM_BG: return AVCOL_SPC_BT470BG;
159 case V4L2_COLORSPACE_SMPTE170M: return AVCOL_SPC_SMPTE170M;
160 case V4L2_COLORSPACE_SMPTE240M: return AVCOL_SPC_SMPTE240M;
161 case V4L2_COLORSPACE_BT2020:
162 if (ycbcr == V4L2_YCBCR_ENC_BT2020_CONST_LUM)
163 return AVCOL_SPC_BT2020_CL;
164 else
166 default:
167 break;
168 }
169
171}
172
174{
175 enum v4l2_ycbcr_encoding ycbcr;
176 enum v4l2_xfer_func xfer;
177 enum v4l2_colorspace cs;
178
179 cs = V4L2_TYPE_IS_MULTIPLANAR(buf->buf.type) ?
180 buf->context->format.fmt.pix_mp.colorspace :
181 buf->context->format.fmt.pix.colorspace;
182
183 ycbcr = V4L2_TYPE_IS_MULTIPLANAR(buf->buf.type) ?
184 buf->context->format.fmt.pix_mp.ycbcr_enc:
185 buf->context->format.fmt.pix.ycbcr_enc;
186
187 xfer = V4L2_TYPE_IS_MULTIPLANAR(buf->buf.type) ?
188 buf->context->format.fmt.pix_mp.xfer_func:
189 buf->context->format.fmt.pix.xfer_func;
190
191 switch (xfer) {
192 case V4L2_XFER_FUNC_709: return AVCOL_TRC_BT709;
193 case V4L2_XFER_FUNC_SRGB: return AVCOL_TRC_IEC61966_2_1;
194 case V4L2_XFER_FUNC_SMPTE240M: return AVCOL_TRC_SMPTE240M;
195 case V4L2_XFER_FUNC_NONE: return AVCOL_TRC_LINEAR;
196 case V4L2_XFER_FUNC_SMPTE2084: return AVCOL_TRC_SMPTE2084;
197 default:
198 break;
199 }
200
201 switch (cs) {
202 case V4L2_COLORSPACE_470_SYSTEM_M: return AVCOL_TRC_GAMMA22;
203 case V4L2_COLORSPACE_470_SYSTEM_BG: return AVCOL_TRC_GAMMA28;
204 case V4L2_COLORSPACE_SMPTE170M: return AVCOL_TRC_SMPTE170M;
205 case V4L2_COLORSPACE_SMPTE240M: return AVCOL_TRC_SMPTE240M;
206 default:
207 break;
208 }
209
210 switch (ycbcr) {
211 case V4L2_YCBCR_ENC_XV709:
212 case V4L2_YCBCR_ENC_XV601: return AVCOL_TRC_BT1361_ECG;
213 default:
214 break;
215 }
216
218}
219
221{
222 enum v4l2_field field = V4L2_TYPE_IS_MULTIPLANAR(buf->buf.type) ?
223 buf->context->format.fmt.pix_mp.field :
224 buf->context->format.fmt.pix.field;
225
226 switch (field) {
227 case V4L2_FIELD_INTERLACED:
228 case V4L2_FIELD_INTERLACED_TB:
231 case V4L2_FIELD_INTERLACED_BT:
233 break;
234 }
235}
236
237static void v4l2_free_buffer(void *opaque, uint8_t *unused)
238{
239 V4L2Buffer* avbuf = opaque;
241
242 if (atomic_fetch_sub(&avbuf->context_refcount, 1) == 1) {
243 atomic_fetch_sub_explicit(&s->refcount, 1, memory_order_acq_rel);
244
245 if (s->reinit) {
246 if (!atomic_load(&s->refcount))
247 sem_post(&s->refsync);
248 } else {
249 if (s->draining && V4L2_TYPE_IS_OUTPUT(avbuf->context->type)) {
250 /* no need to queue more buffers to the driver */
251 avbuf->status = V4L2BUF_AVAILABLE;
252 }
253 else if (avbuf->context->streamon)
255 }
256
258 }
259}
260
262{
264
265 if (in->context_ref)
267 else {
268 in->context_ref = av_refstruct_ref(s->self_ref);
269
270 in->context_refcount = 1;
271 }
272
274 atomic_fetch_add_explicit(&s->refcount, 1, memory_order_relaxed);
275
276 return 0;
277}
278
279static int v4l2_buf_to_bufref(V4L2Buffer *in, int plane, AVBufferRef **buf)
280{
281 int ret;
282
283 if (plane >= in->num_planes)
284 return AVERROR(EINVAL);
285
286 /* even though most encoders return 0 in data_offset encoding vp8 does require this value */
287 *buf = av_buffer_create((char *)in->plane_info[plane].mm_addr + in->planes[plane].data_offset,
288 in->plane_info[plane].length, v4l2_free_buffer, in, 0);
289 if (!*buf)
290 return AVERROR(ENOMEM);
291
292 ret = v4l2_buf_increase_ref(in);
293 if (ret)
294 av_buffer_unref(buf);
295
296 return ret;
297}
298
299static int v4l2_bufref_to_buf(V4L2Buffer *out, int plane, const uint8_t* data, int size, int offset)
300{
301 unsigned int bytesused, length;
302
303 if (plane >= out->num_planes)
304 return AVERROR(EINVAL);
305
306 length = out->plane_info[plane].length;
307 bytesused = FFMIN(size+offset, length);
308
309 memcpy((uint8_t*)out->plane_info[plane].mm_addr+offset, data, FFMIN(size, length-offset));
310
311 if (V4L2_TYPE_IS_MULTIPLANAR(out->buf.type)) {
312 out->planes[plane].bytesused = bytesused;
313 out->planes[plane].length = length;
314 } else {
315 out->buf.bytesused = bytesused;
316 out->buf.length = length;
317 }
318
319 return 0;
320}
321
323{
324 int i, ret;
325
326 frame->format = avbuf->context->av_pix_fmt;
327
328 for (i = 0; i < avbuf->num_planes; i++) {
329 ret = v4l2_buf_to_bufref(avbuf, i, &frame->buf[i]);
330 if (ret)
331 return ret;
332
333 frame->linesize[i] = avbuf->plane_info[i].bytesperline;
334 frame->data[i] = frame->buf[i]->data;
335 }
336
337 /* fixup special cases */
338 switch (avbuf->context->av_pix_fmt) {
339 case AV_PIX_FMT_NV12:
340 case AV_PIX_FMT_NV21:
341 if (avbuf->num_planes > 1)
342 break;
343 frame->linesize[1] = avbuf->plane_info[0].bytesperline;
344 frame->data[1] = frame->buf[0]->data + avbuf->plane_info[0].bytesperline * avbuf->context->format.fmt.pix_mp.height;
345 break;
346
348 if (avbuf->num_planes > 1)
349 break;
350 frame->linesize[1] = avbuf->plane_info[0].bytesperline >> 1;
351 frame->linesize[2] = avbuf->plane_info[0].bytesperline >> 1;
352 frame->data[1] = frame->buf[0]->data + avbuf->plane_info[0].bytesperline * avbuf->context->format.fmt.pix_mp.height;
353 frame->data[2] = frame->data[1] + ((avbuf->plane_info[0].bytesperline * avbuf->context->format.fmt.pix_mp.height) >> 2);
354 break;
355
356 default:
357 break;
358 }
359
360 return 0;
361}
362
364{
365 int i, ret;
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;
372
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:
378#endif
379#ifdef V4L2_PIX_FMT_YVU422M
380 case V4L2_PIX_FMT_YVU422M:
381#endif
382#ifdef V4L2_PIX_FMT_YUV444M
383 case V4L2_PIX_FMT_YUV444M:
384#endif
385#ifdef V4L2_PIX_FMT_YVU444M
386 case V4L2_PIX_FMT_YVU444M:
387#endif
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;
395 }
396
397 if (!is_planar_format) {
399 int planes_nb = 0;
400 int offset = 0;
401
402 for (i = 0; i < desc->nb_components; i++)
403 planes_nb = FFMAX(planes_nb, desc->comp[i].plane + 1);
404
405 for (i = 0; i < planes_nb; i++) {
406 int size, h = height;
407 if (i == 1 || i == 2) {
408 h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
409 }
410 size = frame->linesize[i] * h;
411 ret = v4l2_bufref_to_buf(out, 0, frame->data[i], size, offset);
412 if (ret)
413 return ret;
414 offset += size;
415 }
416 return 0;
417 }
418
419 for (i = 0; i < out->num_planes; i++) {
420 ret = v4l2_bufref_to_buf(out, i, frame->buf[i]->data, frame->buf[i]->size, 0);
421 if (ret)
422 return ret;
423 }
424
425 return 0;
426}
427
428/******************************************************************************
429 *
430 * V4L2Buffer interface
431 *
432 ******************************************************************************/
433
440
442{
443 int ret;
444
446
447 /* 1. get references to the actual data */
448 ret = v4l2_buffer_buf_to_swframe(frame, avbuf);
449 if (ret)
450 return ret;
451
452 /* 2. get frame information */
453 if (avbuf->buf.flags & V4L2_BUF_FLAG_KEYFRAME)
454 frame->flags |= AV_FRAME_FLAG_KEY;
455 frame->color_primaries = v4l2_get_color_primaries(avbuf);
456 frame->colorspace = v4l2_get_color_space(avbuf);
457 frame->color_range = v4l2_get_color_range(avbuf);
458 frame->color_trc = v4l2_get_color_trc(avbuf);
459 frame->pts = v4l2_get_pts(avbuf);
460 frame->pkt_dts = AV_NOPTS_VALUE;
462
463 /* these values are updated also during re-init in v4l2_process_driver_event */
464 frame->height = avbuf->context->height;
465 frame->width = avbuf->context->width;
466 frame->sample_aspect_ratio = avbuf->context->sample_aspect_ratio;
467
468 /* 3. report errors upstream */
469 if (avbuf->buf.flags & V4L2_BUF_FLAG_ERROR) {
470 av_log(logger(avbuf), AV_LOG_ERROR, "%s: driver decode error\n", avbuf->context->name);
471 frame->decode_error_flags |= FF_DECODE_ERROR_INVALID_BITSTREAM;
472 }
473
474 return 0;
475}
476
478{
479 int ret;
480
482 ret = v4l2_buf_to_bufref(avbuf, 0, &pkt->buf);
483 if (ret)
484 return ret;
485
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;
488
489 if (avbuf->buf.flags & V4L2_BUF_FLAG_KEYFRAME)
490 pkt->flags |= AV_PKT_FLAG_KEY;
491
492 if (avbuf->buf.flags & V4L2_BUF_FLAG_ERROR) {
493 av_log(logger(avbuf), AV_LOG_ERROR, "%s driver encode error\n", avbuf->context->name);
494 pkt->flags |= AV_PKT_FLAG_CORRUPT;
495 }
496
497 pkt->dts = pkt->pts = v4l2_get_pts(avbuf);
498
499 return 0;
500}
501
503{
504 int ret;
505
506 ret = v4l2_bufref_to_buf(out, 0, pkt->data, pkt->size, 0);
507 if (ret)
508 return ret;
509
510 v4l2_set_pts(out, pkt->pts);
511
512 if (pkt->flags & AV_PKT_FLAG_KEY)
513 out->flags = V4L2_BUF_FLAG_KEYFRAME;
514
515 return 0;
516}
517
519{
520 V4L2Context *ctx = avbuf->context;
521 int ret, i;
522
523 avbuf->buf.memory = V4L2_MEMORY_MMAP;
524 avbuf->buf.type = ctx->type;
525 avbuf->buf.index = index;
526
527 if (V4L2_TYPE_IS_MULTIPLANAR(ctx->type)) {
528 avbuf->buf.length = VIDEO_MAX_PLANES;
529 avbuf->buf.m.planes = avbuf->planes;
530 }
531
532 ret = ioctl(buf_to_m2mctx(avbuf)->fd, VIDIOC_QUERYBUF, &avbuf->buf);
533 if (ret < 0)
534 return AVERROR(errno);
535
536 if (V4L2_TYPE_IS_MULTIPLANAR(ctx->type)) {
537 avbuf->num_planes = 0;
538 /* in MP, the V4L2 API states that buf.length means num_planes */
539 for (i = 0; i < avbuf->buf.length; i++) {
540 if (avbuf->buf.m.planes[i].length)
541 avbuf->num_planes++;
542 }
543 } else
544 avbuf->num_planes = 1;
545
546 for (i = 0; i < avbuf->num_planes; i++) {
547
548 avbuf->plane_info[i].bytesperline = V4L2_TYPE_IS_MULTIPLANAR(ctx->type) ?
549 ctx->format.fmt.pix_mp.plane_fmt[i].bytesperline :
550 ctx->format.fmt.pix.bytesperline;
551
552 if (V4L2_TYPE_IS_MULTIPLANAR(ctx->type)) {
553 avbuf->plane_info[i].length = avbuf->buf.m.planes[i].length;
554 avbuf->plane_info[i].mm_addr = mmap(NULL, avbuf->buf.m.planes[i].length,
555 PROT_READ | PROT_WRITE, MAP_SHARED,
556 buf_to_m2mctx(avbuf)->fd, avbuf->buf.m.planes[i].m.mem_offset);
557 } else {
558 avbuf->plane_info[i].length = avbuf->buf.length;
559 avbuf->plane_info[i].mm_addr = mmap(NULL, avbuf->buf.length,
560 PROT_READ | PROT_WRITE, MAP_SHARED,
561 buf_to_m2mctx(avbuf)->fd, avbuf->buf.m.offset);
562 }
563
564 if (avbuf->plane_info[i].mm_addr == MAP_FAILED)
565 return AVERROR(ENOMEM);
566 }
567
568 avbuf->status = V4L2BUF_AVAILABLE;
569
570 if (V4L2_TYPE_IS_OUTPUT(ctx->type))
571 return 0;
572
573 if (V4L2_TYPE_IS_MULTIPLANAR(ctx->type)) {
574 avbuf->buf.m.planes = avbuf->planes;
575 avbuf->buf.length = avbuf->num_planes;
576
577 } else {
578 avbuf->buf.bytesused = avbuf->planes[0].bytesused;
579 avbuf->buf.length = avbuf->planes[0].length;
580 }
581
582 return ff_v4l2_buffer_enqueue(avbuf);
583}
584
586{
587 int ret;
588
589 avbuf->buf.flags = avbuf->flags;
590
591 ret = ioctl(buf_to_m2mctx(avbuf)->fd, VIDIOC_QBUF, &avbuf->buf);
592 if (ret < 0)
593 return AVERROR(errno);
594
595 avbuf->status = V4L2BUF_IN_DRIVER;
596
597 return 0;
598}
Libavcodec external API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
static AVFrame * frame
#define atomic_fetch_add_explicit(object, operand, order)
Definition stdatomic.h:149
#define atomic_load(object)
Definition stdatomic.h:93
#define atomic_fetch_sub_explicit(object, operand, order)
Definition stdatomic.h:152
#define FF_DECODE_ERROR_INVALID_BITSTREAM
Definition frame.h:760
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition packet.h:651
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:434
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:650
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition buffer.c:139
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.
Definition buffer.c:55
#define AVERROR(e)
Definition error.h:45
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition frame.h:695
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition frame.h:700
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition frame.h:687
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:496
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
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.
Definition avutil.h:247
int index
Definition gxfenc.c:90
unsigned offset
Definition libaomenc.c:763
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
const char * desc
Definition libsvtav1.c:83
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
const char data[16]
Definition mxf.c:149
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
AVColorRange
Visual content value range.
Definition pixfmt.h:748
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:749
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:783
@ 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...
Definition pixfmt.h:96
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_NV21
as above, but U and V bytes are swapped
Definition pixfmt.h:97
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition pixfmt.h:642
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition pixfmt.h:649
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition pixfmt.h:644
@ AVCOL_PRI_SMPTE240M
identical to above, also called "SMPTE C" even though it uses D65
Definition pixfmt.h:651
@ AVCOL_PRI_UNSPECIFIED
Definition pixfmt.h:645
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition pixfmt.h:650
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition pixfmt.h:653
@ AVCOL_PRI_BT470M
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition pixfmt.h:647
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition pixfmt.h:672
@ AVCOL_TRC_SMPTE170M
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
Definition pixfmt.h:679
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition pixfmt.h:689
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition pixfmt.h:677
@ AVCOL_TRC_BT1361_ECG
ITU-R BT1361 Extended Colour Gamut.
Definition pixfmt.h:685
@ AVCOL_TRC_SMPTE240M
Definition pixfmt.h:680
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition pixfmt.h:681
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition pixfmt.h:678
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition pixfmt.h:686
@ AVCOL_TRC_UNSPECIFIED
Definition pixfmt.h:675
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition pixfmt.h:674
AVColorSpace
YUV colorspace type.
Definition pixfmt.h:706
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition pixfmt.h:708
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
Definition pixfmt.h:712
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
Definition pixfmt.h:718
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition pixfmt.h:707
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition pixfmt.h:717
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:709
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition pixfmt.h:713
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition pixfmt.h:711
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
Definition pixfmt.h:714
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition refstruct.c:120
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
Definition refstruct.c:140
#define sem_post(psem)
Definition semaphore.h:26
A reference to a data buffer.
Definition buffer.h:82
main external API structure.
Definition avcodec.h:443
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This structure stores compressed data.
Definition packet.h:580
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
Rational number (pair of numerator and denominator).
Definition rational.h:58
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_buffer buf
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).
AVCodecContext * avctx
Definition v4l2_m2m.h:52
#define av_log(a,...)
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
#define height
Definition dsp.h:89
static int64_t pts
int size
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)
#define USEC_PER_SEC
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)
@ V4L2BUF_AVAILABLE
@ V4L2BUF_IN_DRIVER
@ V4L2BUF_RET_USER
#define container_of(ptr, type, member)
Definition v4l2_m2m.h:35
#define atomic_fetch_sub(object, operand)
Definition stdatomic.h:140
#define atomic_fetch_add(object, operand)
Definition stdatomic.h:137