FFmpeg
Loading...
Searching...
No Matches
v4l2_buffers.c File Reference
#include <linux/videodev2.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include <limits.h>
#include <poll.h>
#include "libavcodec/avcodec.h"
#include "libavutil/attributes.h"
#include "libavutil/imgutils.h"
#include "libavutil/pixdesc.h"
#include "libavutil/refstruct.h"
#include "v4l2_context.h"
#include "v4l2_buffers.h"
#include "v4l2_m2m.h"

Go to the source code of this file.

Macros

#define USEC_PER_SEC   1000000
 

Functions

static V4L2m2mContext * buf_to_m2mctx (V4L2Buffer *buf)
 
static AVCodecContext * logger (V4L2Buffer *buf)
 
static AVRational v4l2_get_timebase (V4L2Buffer *avbuf)
 
static void v4l2_set_pts (V4L2Buffer *out, int64_t pts)
 
static int64_t v4l2_get_pts (V4L2Buffer *avbuf)
 
static enum AVColorPrimaries v4l2_get_color_primaries (V4L2Buffer *buf)
 
static enum AVColorRange v4l2_get_color_range (V4L2Buffer *buf)
 
static enum AVColorSpace v4l2_get_color_space (V4L2Buffer *buf)
 
static enum AVColorTransferCharacteristic v4l2_get_color_trc (V4L2Buffer *buf)
 
static void v4l2_get_interlacing (AVFrame *frame, V4L2Buffer *buf)
 
static void v4l2_free_buffer (void *opaque, uint8_t *unused)
 
static int v4l2_buf_increase_ref (V4L2Buffer *in)
 
static int v4l2_buf_to_bufref (V4L2Buffer *in, int plane, AVBufferRef **buf)
 
static int v4l2_bufref_to_buf (V4L2Buffer *out, int plane, const uint8_t *data, int size, int offset)
 
static int v4l2_buffer_buf_to_swframe (AVFrame *frame, V4L2Buffer *avbuf)
 
static int v4l2_buffer_swframe_to_single_buffer (const AVFrame *frame, V4L2Buffer *out, uint32_t pixel_format, unsigned int width, unsigned int height, unsigned int bytesperline, unsigned int sizeimage)
 Copy a software frame into one contiguous V4L2 memory plane while keeping the visible frame geometry separate from the driver-aligned storage layout.
 
static int v4l2_buffer_swframe_to_planes (const AVFrame *frame, V4L2Buffer *out)
 
static int v4l2_buffer_swframe_to_buf (const AVFrame *frame, V4L2Buffer *out)
 
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_buf_to_avframe (AVFrame *frame, V4L2Buffer *avbuf)
 Extracts the data from a V4L2Buffer to an AVFrame.
 
int ff_v4l2_buffer_buf_to_avpkt (AVPacket *pkt, V4L2Buffer *avbuf)
 Extracts the data from a V4L2Buffer to an AVPacket.
 
int ff_v4l2_buffer_avpkt_to_buf (const AVPacket *pkt, V4L2Buffer *out)
 Extracts the data from an AVPacket to a V4L2Buffer.
 
int ff_v4l2_buffer_initialize (V4L2Buffer *avbuf, int index)
 Initializes a V4L2Buffer.
 
int ff_v4l2_buffer_enqueue (V4L2Buffer *avbuf)
 Enqueues a V4L2Buffer.
 

Variables

static AVRational v4l2_timebase = { 1, USEC_PER_SEC }
 

Macro Definition Documentation

◆ USEC_PER_SEC

#define USEC_PER_SEC   1000000

Definition at line 41 of file v4l2_buffers.c.

Referenced by v4l2_get_pts(), and v4l2_set_pts().

Function Documentation

◆ buf_to_m2mctx()

static V4L2m2mContext * buf_to_m2mctx ( V4L2Buffer * buf)
inlinestatic

◆ logger()

static AVCodecContext * logger ( V4L2Buffer * buf)
inlinestatic

Definition at line 53 of file v4l2_buffers.c.

Referenced by ff_v4l2_buffer_buf_to_avframe(), and ff_v4l2_buffer_buf_to_avpkt().

◆ v4l2_get_timebase()

static AVRational v4l2_get_timebase ( V4L2Buffer * avbuf)
inlinestatic

Definition at line 58 of file v4l2_buffers.c.

Referenced by v4l2_get_pts(), and v4l2_set_pts().

◆ v4l2_set_pts()

static void v4l2_set_pts ( V4L2Buffer * out,
int64_t pts )
inlinestatic

Definition at line 67 of file v4l2_buffers.c.

Referenced by ff_v4l2_buffer_avframe_to_buf(), and ff_v4l2_buffer_avpkt_to_buf().

◆ v4l2_get_pts()

static int64_t v4l2_get_pts ( V4L2Buffer * avbuf)
inlinestatic

Definition at line 80 of file v4l2_buffers.c.

Referenced by ff_v4l2_buffer_buf_to_avframe(), and ff_v4l2_buffer_buf_to_avpkt().

◆ v4l2_get_color_primaries()

static enum AVColorPrimaries v4l2_get_color_primaries ( V4L2Buffer * buf)
static

Definition at line 91 of file v4l2_buffers.c.

Referenced by ff_v4l2_buffer_buf_to_avframe().

◆ v4l2_get_color_range()

static enum AVColorRange v4l2_get_color_range ( V4L2Buffer * buf)
static

Definition at line 125 of file v4l2_buffers.c.

Referenced by ff_v4l2_buffer_buf_to_avframe().

◆ v4l2_get_color_space()

static enum AVColorSpace v4l2_get_color_space ( V4L2Buffer * buf)
static

Definition at line 143 of file v4l2_buffers.c.

Referenced by ff_v4l2_buffer_buf_to_avframe().

◆ v4l2_get_color_trc()

static enum AVColorTransferCharacteristic v4l2_get_color_trc ( V4L2Buffer * buf)
static

Definition at line 175 of file v4l2_buffers.c.

Referenced by ff_v4l2_buffer_buf_to_avframe().

◆ v4l2_get_interlacing()

static void v4l2_get_interlacing ( AVFrame * frame,
V4L2Buffer * buf )
static

Definition at line 222 of file v4l2_buffers.c.

Referenced by ff_v4l2_buffer_buf_to_avframe().

◆ v4l2_free_buffer()

static void v4l2_free_buffer ( void * opaque,
uint8_t * unused )
static

Definition at line 239 of file v4l2_buffers.c.

Referenced by v4l2_buf_to_bufref().

◆ v4l2_buf_increase_ref()

static int v4l2_buf_increase_ref ( V4L2Buffer * in)
static

Definition at line 263 of file v4l2_buffers.c.

Referenced by v4l2_buf_to_bufref().

◆ v4l2_buf_to_bufref()

static int v4l2_buf_to_bufref ( V4L2Buffer * in,
int plane,
AVBufferRef ** buf )
static

Definition at line 281 of file v4l2_buffers.c.

Referenced by ff_v4l2_buffer_buf_to_avpkt(), and v4l2_buffer_buf_to_swframe().

◆ v4l2_bufref_to_buf()

static int v4l2_bufref_to_buf ( V4L2Buffer * out,
int plane,
const uint8_t * data,
int size,
int offset )
static

Definition at line 301 of file v4l2_buffers.c.

Referenced by ff_v4l2_buffer_avpkt_to_buf().

◆ v4l2_buffer_buf_to_swframe()

static int v4l2_buffer_buf_to_swframe ( AVFrame * frame,
V4L2Buffer * avbuf )
static

Definition at line 324 of file v4l2_buffers.c.

Referenced by ff_v4l2_buffer_buf_to_avframe().

◆ v4l2_buffer_swframe_to_single_buffer()

static int v4l2_buffer_swframe_to_single_buffer ( const AVFrame * frame,
V4L2Buffer * out,
uint32_t pixel_format,
unsigned int width,
unsigned int height,
unsigned int bytesperline,
unsigned int sizeimage )
static

Copy a software frame into one contiguous V4L2 memory plane while keeping the visible frame geometry separate from the driver-aligned storage layout.

Definition at line 369 of file v4l2_buffers.c.

Referenced by v4l2_buffer_swframe_to_buf().

◆ v4l2_buffer_swframe_to_planes()

static int v4l2_buffer_swframe_to_planes ( const AVFrame * frame,
V4L2Buffer * out )
static

Definition at line 474 of file v4l2_buffers.c.

Referenced by v4l2_buffer_swframe_to_buf().

◆ v4l2_buffer_swframe_to_buf()

static int v4l2_buffer_swframe_to_buf ( const AVFrame * frame,
V4L2Buffer * out )
static

Definition at line 510 of file v4l2_buffers.c.

Referenced by ff_v4l2_buffer_avframe_to_buf().

◆ 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.

Parameters
[in]frameAVFrame to get the data from
[in]avbufV4L2Bfuffer to push the information to
Returns
0 in case of success, a negative AVERROR code otherwise

Definition at line 568 of file v4l2_buffers.c.

Referenced by ff_v4l2_context_enqueue_frame().

◆ 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.

Parameters
[in]frameThe AVFRame to push the information to
[in]bufThe V4L2Buffer to get the information from
Returns
0 in case of success, AVERROR(EINVAL) if the number of planes is incorrect, AVERROR(ENOMEM) if the AVBufferRef can't be created.

Definition at line 575 of file v4l2_buffers.c.

Referenced by ff_v4l2_context_dequeue_frame().

◆ 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.

Parameters
[in]pktThe AVPacket to push the information to
[in]bufThe V4L2Buffer to get the information from
Returns
0 in case of success, AVERROR(EINVAL) if the number of planes is incorrect, AVERROR(ENOMEM) if the AVBufferRef can't be created.

Definition at line 611 of file v4l2_buffers.c.

Referenced by ff_v4l2_context_dequeue_packet().

◆ 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.

Parameters
[in]frameAVPacket to get the data from
[in]avbufV4L2Bfuffer to push the information to
Returns
0 in case of success, a negative AVERROR code otherwise

Definition at line 636 of file v4l2_buffers.c.

Referenced by ff_v4l2_context_enqueue_packet().

◆ ff_v4l2_buffer_initialize()

int ff_v4l2_buffer_initialize ( V4L2Buffer * avbuf,
int index )

Initializes a V4L2Buffer.

Parameters
[in]avbufV4L2Bfuffer to initialize
[in]indexv4l2 buffer id
Returns
0 in case of success, a negative AVERROR code otherwise

Definition at line 652 of file v4l2_buffers.c.

Referenced by ff_v4l2_context_init().

◆ ff_v4l2_buffer_enqueue()

int ff_v4l2_buffer_enqueue ( V4L2Buffer * avbuf)

Enqueues a V4L2Buffer.

Parameters
[in]avbufV4L2Bfuffer to push to the driver
Returns
0 in case of success, a negative AVERROR code otherwise

Definition at line 719 of file v4l2_buffers.c.

Referenced by ff_v4l2_buffer_initialize(), ff_v4l2_context_enqueue_frame(), ff_v4l2_context_enqueue_packet(), and v4l2_free_buffer().

Variable Documentation

◆ v4l2_timebase

AVRational v4l2_timebase = { 1, USEC_PER_SEC }
static

Definition at line 44 of file v4l2_buffers.c.

Referenced by v4l2_get_pts(), and v4l2_set_pts().