FFmpeg
Data Structures | Functions
v4l2_context.c File Reference
#include <linux/videodev2.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
#include "libavutil/mem.h"
#include "libavcodec/avcodec.h"
#include "decode.h"
#include "v4l2_buffers.h"
#include "v4l2_fmt.h"
#include "v4l2_m2m.h"

Go to the source code of this file.

Data Structures

struct  v4l2_format_update
 

Functions

static V4L2m2mContextctx_to_m2mctx (V4L2Context *ctx)
 
static AVCodecContextlogger (V4L2Context *ctx)
 
static unsigned int v4l2_get_width (struct v4l2_format *fmt)
 
static unsigned int v4l2_get_height (struct v4l2_format *fmt)
 
static AVRational v4l2_get_sar (V4L2Context *ctx)
 
static unsigned int v4l2_resolution_changed (V4L2Context *ctx, struct v4l2_format *fmt2)
 
static int v4l2_type_supported (V4L2Context *ctx)
 
static int v4l2_get_framesize_compressed (V4L2Context *ctx, int width, int height)
 
static void v4l2_save_to_context (V4L2Context *ctx, struct v4l2_format_update *fmt)
 
static int v4l2_start_decode (V4L2Context *ctx)
 
static int v4l2_handle_event (V4L2Context *ctx)
 handle resolution change event and end of stream event returns 1 if reinit was successful, negative if it failed returns 0 if reinit was not executed More...
 
static int v4l2_stop_decode (V4L2Context *ctx)
 
static int v4l2_stop_encode (V4L2Context *ctx)
 
static V4L2Bufferv4l2_dequeue_v4l2buf (V4L2Context *ctx, int timeout)
 
static V4L2Bufferv4l2_getfree_v4l2buf (V4L2Context *ctx)
 
static int v4l2_release_buffers (V4L2Context *ctx)
 
static int v4l2_try_raw_format (V4L2Context *ctx, enum AVPixelFormat pixfmt)
 
static int v4l2_get_raw_format (V4L2Context *ctx, enum AVPixelFormat *p)
 
static int v4l2_get_coded_format (V4L2Context *ctx, uint32_t *p)
 
int ff_v4l2_context_set_status (V4L2Context *ctx, uint32_t cmd)
 Sets the status of a V4L2Context. More...
 
int ff_v4l2_context_enqueue_frame (V4L2Context *ctx, const AVFrame *frame)
 Enqueues a buffer to a V4L2Context from an AVFrame. More...
 
int ff_v4l2_context_enqueue_packet (V4L2Context *ctx, const AVPacket *pkt)
 Enqueues a buffer to a V4L2Context from an AVPacket. More...
 
int ff_v4l2_context_dequeue_frame (V4L2Context *ctx, AVFrame *frame, int timeout)
 Dequeues a buffer from a V4L2Context to an AVFrame. More...
 
int ff_v4l2_context_dequeue_packet (V4L2Context *ctx, AVPacket *pkt)
 Dequeues a buffer from a V4L2Context to an AVPacket. More...
 
int ff_v4l2_context_get_format (V4L2Context *ctx, int probe)
 Queries the driver for a valid v4l2 format and copies it to the context. More...
 
int ff_v4l2_context_set_format (V4L2Context *ctx)
 Sets the V4L2Context format in the v4l2 driver. More...
 
void ff_v4l2_context_release (V4L2Context *ctx)
 Releases a V4L2Context. More...
 
int ff_v4l2_context_init (V4L2Context *ctx)
 Initializes a V4L2Context. More...
 

Function Documentation

◆ ctx_to_m2mctx()

static V4L2m2mContext* ctx_to_m2mctx ( V4L2Context ctx)
inlinestatic

◆ logger()

static AVCodecContext* logger ( V4L2Context ctx)
inlinestatic

◆ v4l2_get_width()

static unsigned int v4l2_get_width ( struct v4l2_format *  fmt)
inlinestatic

Definition at line 57 of file v4l2_context.c.

Referenced by ff_v4l2_context_init(), v4l2_handle_event(), and v4l2_resolution_changed().

◆ v4l2_get_height()

static unsigned int v4l2_get_height ( struct v4l2_format *  fmt)
inlinestatic

Definition at line 62 of file v4l2_context.c.

Referenced by ff_v4l2_context_init(), v4l2_handle_event(), and v4l2_resolution_changed().

◆ v4l2_get_sar()

static AVRational v4l2_get_sar ( V4L2Context ctx)
static

Definition at line 67 of file v4l2_context.c.

Referenced by v4l2_handle_event().

◆ v4l2_resolution_changed()

static unsigned int v4l2_resolution_changed ( V4L2Context ctx,
struct v4l2_format *  fmt2 
)
inlinestatic

Definition at line 85 of file v4l2_context.c.

Referenced by v4l2_handle_event().

◆ v4l2_type_supported()

static int v4l2_type_supported ( V4L2Context ctx)
inlinestatic

Definition at line 104 of file v4l2_context.c.

Referenced by ff_v4l2_context_init().

◆ v4l2_get_framesize_compressed()

static int v4l2_get_framesize_compressed ( V4L2Context ctx,
int  width,
int  height 
)
inlinestatic

Definition at line 112 of file v4l2_context.c.

Referenced by v4l2_save_to_context().

◆ v4l2_save_to_context()

static void v4l2_save_to_context ( V4L2Context ctx,
struct v4l2_format_update fmt 
)
inlinestatic

Definition at line 126 of file v4l2_context.c.

Referenced by ff_v4l2_context_get_format().

◆ v4l2_start_decode()

static int v4l2_start_decode ( V4L2Context ctx)
static

Definition at line 157 of file v4l2_context.c.

Referenced by v4l2_handle_event().

◆ v4l2_handle_event()

static int v4l2_handle_event ( V4L2Context ctx)
static

handle resolution change event and end of stream event returns 1 if reinit was successful, negative if it failed returns 0 if reinit was not executed

Definition at line 177 of file v4l2_context.c.

Referenced by v4l2_dequeue_v4l2buf().

◆ v4l2_stop_decode()

static int v4l2_stop_decode ( V4L2Context ctx)
static

Definition at line 230 of file v4l2_context.c.

Referenced by ff_v4l2_context_enqueue_packet().

◆ v4l2_stop_encode()

static int v4l2_stop_encode ( V4L2Context ctx)
static

Definition at line 250 of file v4l2_context.c.

Referenced by ff_v4l2_context_enqueue_frame().

◆ v4l2_dequeue_v4l2buf()

static V4L2Buffer* v4l2_dequeue_v4l2buf ( V4L2Context ctx,
int  timeout 
)
static

◆ v4l2_getfree_v4l2buf()

static V4L2Buffer* v4l2_getfree_v4l2buf ( V4L2Context ctx)
static

◆ v4l2_release_buffers()

static int v4l2_release_buffers ( V4L2Context ctx)
static

Definition at line 444 of file v4l2_context.c.

Referenced by ff_v4l2_context_init(), and ff_v4l2_context_release().

◆ v4l2_try_raw_format()

static int v4l2_try_raw_format ( V4L2Context ctx,
enum AVPixelFormat  pixfmt 
)
inlinestatic

Definition at line 467 of file v4l2_context.c.

Referenced by v4l2_get_raw_format().

◆ v4l2_get_raw_format()

static int v4l2_get_raw_format ( V4L2Context ctx,
enum AVPixelFormat p 
)
static

Definition at line 491 of file v4l2_context.c.

Referenced by ff_v4l2_context_get_format().

◆ v4l2_get_coded_format()

static int v4l2_get_coded_format ( V4L2Context ctx,
uint32_t *  p 
)
static

Definition at line 526 of file v4l2_context.c.

Referenced by ff_v4l2_context_get_format().

◆ ff_v4l2_context_set_status()

int ff_v4l2_context_set_status ( V4L2Context ctx,
uint32_t  cmd 
)

Sets the status of a V4L2Context.

Parameters
[in]ctxA pointer to a V4L2Context.
[in]cmdThe status to set (VIDIOC_STREAMON or VIDIOC_STREAMOFF). Warning: If VIDIOC_STREAMOFF is sent to a buffer context that still has some frames buffered, those frames will be dropped.
Returns
0 in case of success, a negative value representing the error otherwise.

Definition at line 563 of file v4l2_context.c.

Referenced by ff_v4l2_m2m_codec_end(), ff_v4l2_m2m_codec_reinit(), v4l2_receive_packet(), v4l2_stop_decode(), v4l2_stop_encode(), and v4l2_try_start().

◆ ff_v4l2_context_enqueue_frame()

int ff_v4l2_context_enqueue_frame ( V4L2Context ctx,
const AVFrame f 
)

Enqueues a buffer to a V4L2Context from an AVFrame.

The frame must be non NULL.

Parameters
[in]ctxThe V4L2Context to enqueue to.
[in]fA pointer to an AVFrame to enqueue.
Returns
0 in case of success, a negative error otherwise.

Definition at line 577 of file v4l2_context.c.

Referenced by v4l2_send_frame().

◆ ff_v4l2_context_enqueue_packet()

int ff_v4l2_context_enqueue_packet ( V4L2Context ctx,
const AVPacket pkt 
)

Enqueues a buffer to a V4L2Context from an AVPacket.

The packet must be non NULL. When the size of the pkt is null, the buffer is not queued but a V4L2_DEC_CMD_STOP command is sent instead to the driver.

Parameters
[in]ctxThe V4L2Context to enqueue to.
[in]pktA pointer to an AVPacket.
Returns
0 in case of success, a negative error otherwise.

Definition at line 602 of file v4l2_context.c.

Referenced by v4l2_receive_frame().

◆ ff_v4l2_context_dequeue_frame()

int ff_v4l2_context_dequeue_frame ( V4L2Context ctx,
AVFrame f,
int  timeout 
)

Dequeues a buffer from a V4L2Context to an AVFrame.

The frame must be non NULL.

Parameters
[in]ctxThe V4L2Context to dequeue from.
[in,out]fThe AVFrame to dequeue to.
[in]timeoutThe timeout for dequeue (-1 to block, 0 to return immediately, or milliseconds)
Returns
0 in case of success, AVERROR(EAGAIN) if no buffer was ready, another negative error in case of error.

Definition at line 627 of file v4l2_context.c.

Referenced by v4l2_receive_frame().

◆ ff_v4l2_context_dequeue_packet()

int ff_v4l2_context_dequeue_packet ( V4L2Context ctx,
AVPacket pkt 
)

Dequeues a buffer from a V4L2Context to an AVPacket.

The pkt must be non NULL.

Parameters
[in]ctxThe V4L2Context to dequeue from.
[in,out]pktThe AVPacket to dequeue to.
Returns
0 in case of success, AVERROR(EAGAIN) if no buffer was ready, another negative error in case of error.

Definition at line 647 of file v4l2_context.c.

Referenced by v4l2_receive_packet().

◆ ff_v4l2_context_get_format()

int ff_v4l2_context_get_format ( V4L2Context ctx,
int  probe 
)

Queries the driver for a valid v4l2 format and copies it to the context.

Parameters
[in]ctxA pointer to a V4L2Context. See V4L2Context description for required variables.
[in]probeProbe only and ignore changes to the format.
Returns
0 in case of success, a negative value representing the error otherwise.

Definition at line 667 of file v4l2_context.c.

Referenced by ff_v4l2_m2m_codec_reinit(), and v4l2_probe_driver().

◆ ff_v4l2_context_set_format()

int ff_v4l2_context_set_format ( V4L2Context ctx)

Sets the V4L2Context format in the v4l2 driver.

Parameters
[in]ctxA pointer to a V4L2Context. See V4L2Context description for required variables.
Returns
0 in case of success, a negative value representing the error otherwise.

Definition at line 694 of file v4l2_context.c.

Referenced by ff_v4l2_m2m_codec_reinit(), and v4l2_configure_contexts().

◆ ff_v4l2_context_release()

void ff_v4l2_context_release ( V4L2Context ctx)

Releases a V4L2Context.

Parameters
[in]ctxA pointer to a V4L2Context. The caller is reponsible for freeing it. It must not be used after calling this function.

Definition at line 699 of file v4l2_context.c.

Referenced by ff_v4l2_m2m_codec_end(), ff_v4l2_m2m_codec_reinit(), and v4l2_m2m_destroy_context().

◆ ff_v4l2_context_init()

int ff_v4l2_context_init ( V4L2Context ctx)

Initializes a V4L2Context.

Parameters
[in]ctxA pointer to a V4L2Context. See V4L2Context description for required variables.
Returns
0 in case of success, a negative value representing the error otherwise.

Definition at line 713 of file v4l2_context.c.

Referenced by v4l2_configure_contexts(), and v4l2_try_start().