24 #include <linux/videodev2.h>
25 #include <sys/ioctl.h>
36 #define USEC_PER_SEC 1000000
73 avbuf->
buf.timestamp.tv_usec;
80 enum v4l2_ycbcr_encoding ycbcr;
81 enum v4l2_colorspace cs;
83 cs = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
87 ycbcr = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
92 case V4L2_YCBCR_ENC_XV709:
94 case V4L2_YCBCR_ENC_XV601:
114 enum v4l2_quantization qt;
116 qt = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
132 enum v4l2_ycbcr_encoding ycbcr;
133 enum v4l2_colorspace cs;
135 cs = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
139 ycbcr = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
150 case V4L2_COLORSPACE_BT2020:
151 if (ycbcr == V4L2_YCBCR_ENC_BT2020_CONST_LUM)
164 enum v4l2_ycbcr_encoding ycbcr;
165 enum v4l2_xfer_func xfer;
166 enum v4l2_colorspace cs;
168 cs = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
172 ycbcr = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
176 xfer = V4L2_TYPE_IS_MULTIPLANAR(buf->
buf.type) ?
197 case V4L2_YCBCR_ENC_XV709:
262 unsigned int bytesused,
length;
272 if (V4L2_TYPE_IS_MULTIPLANAR(out->
buf.type)) {
276 out->
buf.bytesused = bytesused;
334 frame->
key_frame = !!(avbuf->
buf.flags & V4L2_BUF_FLAG_KEYFRAME);
347 if (avbuf->
buf.flags & V4L2_BUF_FLAG_ERROR) {
364 pkt->
size = V4L2_TYPE_IS_MULTIPLANAR(avbuf->
buf.type) ? avbuf->
buf.m.planes[0].bytesused : avbuf->
buf.bytesused;
367 if (avbuf->
buf.flags & V4L2_BUF_FLAG_KEYFRAME)
370 if (avbuf->
buf.flags & V4L2_BUF_FLAG_ERROR) {
391 out->
flags = V4L2_BUF_FLAG_KEYFRAME;
401 avbuf->
buf.memory = V4L2_MEMORY_MMAP;
405 if (V4L2_TYPE_IS_MULTIPLANAR(ctx->
type)) {
406 avbuf->
buf.length = VIDEO_MAX_PLANES;
414 if (V4L2_TYPE_IS_MULTIPLANAR(ctx->
type)) {
429 ctx->
format.fmt.pix_mp.plane_fmt[i].bytesperline :
430 ctx->
format.fmt.pix.bytesperline;
432 if (V4L2_TYPE_IS_MULTIPLANAR(ctx->
type)) {
435 PROT_READ | PROT_WRITE, MAP_SHARED,
440 PROT_READ | PROT_WRITE, MAP_SHARED,
450 if (V4L2_TYPE_IS_OUTPUT(ctx->
type))
453 if (V4L2_TYPE_IS_MULTIPLANAR(ctx->
type)) {
458 avbuf->
buf.bytesused = avbuf->
planes[0].bytesused;
459 avbuf->
buf.length = avbuf->
planes[0].length;
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
static AVCodecContext * logger(V4L2Buffer *buf)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
This structure describes decoded (raw) audio or video data.
const char * name
context name.
ptrdiff_t const GLvoid * data
static int v4l2_bufref_to_buf(V4L2Buffer *out, int plane, const uint8_t *data, int size, AVBufferRef *bref)
static enum AVColorTransferCharacteristic v4l2_get_color_trc(V4L2Buffer *buf)
int ff_v4l2_buffer_buf_to_avpkt(AVPacket *pkt, V4L2Buffer *avbuf)
Extracts the data from a V4L2Buffer to an AVPacket.
int ff_v4l2_buffer_initialize(V4L2Buffer *avbuf, int index)
Initializes a V4L2Buffer.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
int width
Width and height of the frames it produces (in case of a capture context, e.g.
int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, V4L2Buffer *out)
Extracts the data from an AVFrame to a V4L2Buffer.
enum V4L2Buffer_status status
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
static enum AVColorSpace v4l2_get_color_space(V4L2Buffer *buf)
AVColorTransferCharacteristic
Color Transfer Characteristic.
functionally identical to above
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
static uint64_t v4l2_get_pts(V4L2Buffer *avbuf)
AVColorSpace
YUV colorspace type.
static enum AVColorPrimaries v4l2_get_color_primaries(V4L2Buffer *buf)
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
struct V4L2Buffer::V4L2Plane_info plane_info[VIDEO_MAX_PLANES]
int ff_v4l2_buffer_enqueue(V4L2Buffer *avbuf)
Enqueues a V4L2Buffer.
AVColorRange
MPEG vs JPEG YUV range.
AVColorPrimaries
Chromaticity coordinates of the source primaries.
struct V4L2Context * context
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static enum AVColorRange v4l2_get_color_range(V4L2Buffer *buf)
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
ITU-R BT1361 Extended Colour Gamut.
#define atomic_load(object)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
int ff_v4l2_buffer_buf_to_avframe(AVFrame *frame, V4L2Buffer *avbuf)
Extracts the data from a V4L2Buffer to an AVFrame.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
enum AVColorSpace colorspace
YUV colorspace type.
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
#define atomic_fetch_sub(object, operand)
enum AVPixelFormat av_pix_fmt
AVPixelFormat corresponding to this buffer context.
int flags
A combination of AV_PKT_FLAG values.
int streamon
Whether the stream has been started (VIDIOC_STREAMON has been sent).
AVBufferRef * context_ref
ITU-R BT2020 non-constant luminance system.
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
struct v4l2_plane planes[VIDEO_MAX_PLANES]
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
the normal 2^n-1 "JPEG" YUV ranges
struct v4l2_format format
Format returned by the driver after initializing the buffer context.
#define atomic_fetch_add_explicit(object, operand, order)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
#define atomic_fetch_add(object, operand)
atomic_uint context_refcount
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
Libavcodec external API header.
#define atomic_fetch_sub_explicit(object, operand, order)
functionally identical to above
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
uint8_t * data
The data buffer.
V4L2Buffer (wrapper for v4l2_buffer management)
static int v4l2_buf_to_bufref(V4L2Buffer *in, int plane, AVBufferRef **buf)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
int ff_v4l2_buffer_avpkt_to_buf(const AVPacket *pkt, V4L2Buffer *out)
Extracts the data from an AVPacket to a V4L2Buffer.
#define container_of(ptr, type, member)
Rational number (pair of numerator and denominator).
#define FF_DECODE_ERROR_INVALID_BITSTREAM
int decode_error_flags
decode error flags of the frame, set to a combination of FF_DECODE_ERROR_xxx flags if the decoder pro...
int size
Size of data in bytes.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
the normal 219*2^(n-8) "MPEG" YUV ranges
ITU-R BT2020 constant luminance system.
A reference to a data buffer.
IEC 61966-2-1 (sRGB or sYCC)
common internal api header.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
int key_frame
1 -> keyframe, 0-> not
enum AVColorPrimaries color_primaries
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static V4L2m2mContext * buf_to_m2mctx(V4L2Buffer *buf)
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
enum AVColorTransferCharacteristic color_trc
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static void v4l2_free_buffer(void *opaque, uint8_t *unused)
static void v4l2_set_pts(V4L2Buffer *out, int64_t pts)
#define AV_NOPTS_VALUE
Undefined timestamp value.
enum v4l2_buf_type type
Type of this buffer context.