Libav
Data Structures | Macros | Functions | Variables
v4l2.c File Reference
#include "config.h"
#include "libavformat/avformat.h"
#include "libavformat/internal.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <poll.h>
#include <linux/videodev2.h>
#include "libavutil/atomic.h"
#include "libavutil/avassert.h"
#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
#include "libavutil/avstring.h"
#include "libavutil/mathematics.h"

Go to the source code of this file.

Data Structures

struct  video_data
 
struct  buff_data
 
struct  fmt_map
 

Macros

#define V4L_ALLFORMATS   3
 
#define V4L_RAWFORMATS   1
 
#define V4L_COMPFORMATS   2
 
#define OFFSET(x)   offsetof(struct video_data, x)
 
#define DEC   AV_OPT_FLAG_DECODING_PARAM
 

Functions

static int device_open (AVFormatContext *ctx)
 
static int device_init (AVFormatContext *ctx, int *width, int *height, uint32_t pix_fmt)
 
static int first_field (int fd)
 
static uint32_t fmt_ff2v4l (enum AVPixelFormat pix_fmt, enum AVCodecID codec_id)
 
static enum AVPixelFormat fmt_v4l2ff (uint32_t v4l2_fmt, enum AVCodecID codec_id)
 
static enum AVCodecID fmt_v4l2codec (uint32_t v4l2_fmt)
 
static void list_formats (AVFormatContext *ctx, int fd, int type)
 
static int mmap_init (AVFormatContext *ctx)
 
static void mmap_release_buffer (void *opaque, uint8_t *data)
 
static int mmap_read_frame (AVFormatContext *ctx, AVPacket *pkt)
 
static int mmap_start (AVFormatContext *ctx)
 
static void mmap_close (struct video_data *s)
 
static int v4l2_set_parameters (AVFormatContext *s1)
 
static uint32_t device_try_init (AVFormatContext *s1, enum AVPixelFormat pix_fmt, int *width, int *height, enum AVCodecID *codec_id)
 
static int v4l2_read_header (AVFormatContext *s1)
 
static int v4l2_read_packet (AVFormatContext *s1, AVPacket *pkt)
 
static int v4l2_read_close (AVFormatContext *s1)
 

Variables

static const int desired_video_buffers = 256
 
static struct fmt_map fmt_conversion_table []
 
static const AVOption options []
 
static const AVClass v4l2_class
 
AVInputFormat ff_v4l2_demuxer
 

Macro Definition Documentation

§ V4L_ALLFORMATS

#define V4L_ALLFORMATS   3

Definition at line 58 of file v4l2.c.

§ V4L_RAWFORMATS

#define V4L_RAWFORMATS   1

Definition at line 59 of file v4l2.c.

Referenced by list_formats().

§ V4L_COMPFORMATS

#define V4L_COMPFORMATS   2

Definition at line 60 of file v4l2.c.

Referenced by list_formats().

§ OFFSET

#define OFFSET (   x)    offsetof(struct video_data, x)

Definition at line 868 of file v4l2.c.

§ DEC

#define DEC   AV_OPT_FLAG_DECODING_PARAM

Definition at line 869 of file v4l2.c.

Function Documentation

§ device_open()

static int device_open ( AVFormatContext ctx)
static

Definition at line 116 of file v4l2.c.

Referenced by v4l2_read_header().

§ device_init()

static int device_init ( AVFormatContext ctx,
int *  width,
int *  height,
uint32_t  pix_fmt 
)
static

Definition at line 171 of file v4l2.c.

Referenced by device_try_init().

§ first_field()

static int first_field ( int  fd)
static

Definition at line 212 of file v4l2.c.

Referenced by dnxhd_decode_frame(), dnxhd_encode_picture(), and v4l2_read_header().

§ fmt_ff2v4l()

static uint32_t fmt_ff2v4l ( enum AVPixelFormat  pix_fmt,
enum AVCodecID  codec_id 
)
static

Definition at line 228 of file v4l2.c.

Referenced by device_try_init().

§ fmt_v4l2ff()

static enum AVPixelFormat fmt_v4l2ff ( uint32_t  v4l2_fmt,
enum AVCodecID  codec_id 
)
static

Definition at line 244 of file v4l2.c.

Referenced by list_formats(), and v4l2_read_header().

§ fmt_v4l2codec()

static enum AVCodecID fmt_v4l2codec ( uint32_t  v4l2_fmt)
static

Definition at line 258 of file v4l2.c.

Referenced by device_try_init(), and list_formats().

§ list_formats()

static void list_formats ( AVFormatContext ctx,
int  fd,
int  type 
)
static

Definition at line 297 of file v4l2.c.

Referenced by v4l2_read_header().

§ mmap_init()

static int mmap_init ( AVFormatContext ctx)
static

Definition at line 336 of file v4l2.c.

Referenced by v4l2_read_header().

§ mmap_release_buffer()

static void mmap_release_buffer ( void opaque,
uint8_t data 
)
static

Definition at line 420 of file v4l2.c.

Referenced by mmap_read_frame().

§ mmap_read_frame()

static int mmap_read_frame ( AVFormatContext ctx,
AVPacket pkt 
)
static

Definition at line 440 of file v4l2.c.

Referenced by v4l2_read_packet().

§ mmap_start()

static int mmap_start ( AVFormatContext ctx)
static

Definition at line 541 of file v4l2.c.

Referenced by v4l2_read_header().

§ mmap_close()

static void mmap_close ( struct video_data s)
static

Definition at line 576 of file v4l2.c.

Referenced by v4l2_read_close().

§ v4l2_set_parameters()

static int v4l2_set_parameters ( AVFormatContext s1)
static

Definition at line 593 of file v4l2.c.

Referenced by v4l2_read_header().

§ device_try_init()

static uint32_t device_try_init ( AVFormatContext s1,
enum AVPixelFormat  pix_fmt,
int *  width,
int *  height,
enum AVCodecID codec_id 
)
static

Definition at line 695 of file v4l2.c.

Referenced by v4l2_read_header().

§ v4l2_read_header()

static int v4l2_read_header ( AVFormatContext s1)
static

Definition at line 728 of file v4l2.c.

§ v4l2_read_packet()

static int v4l2_read_packet ( AVFormatContext s1,
AVPacket pkt 
)
static

Definition at line 835 of file v4l2.c.

§ v4l2_read_close()

static int v4l2_read_close ( AVFormatContext s1)
static

Definition at line 854 of file v4l2.c.

Variable Documentation

§ desired_video_buffers

const int desired_video_buffers = 256
static

Definition at line 56 of file v4l2.c.

Referenced by mmap_init().

§ fmt_conversion_table

struct fmt_map fmt_conversion_table[]
static
Initial value:
= {
{ AV_PIX_FMT_YUV420P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV420 },
{ AV_PIX_FMT_YUV422P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV422P },
{ AV_PIX_FMT_YUYV422, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUYV },
{ AV_PIX_FMT_UYVY422, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_UYVY },
{ AV_PIX_FMT_YUV411P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV411P },
{ AV_PIX_FMT_YUV410P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV410 },
{ AV_PIX_FMT_RGB555, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB555 },
{ AV_PIX_FMT_RGB565, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB565 },
{ AV_PIX_FMT_BGR24, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR24 },
{ AV_PIX_FMT_RGB24, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB24 },
{ AV_PIX_FMT_BGRA, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR32 },
{ AV_PIX_FMT_GRAY8, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_GREY },
{ AV_PIX_FMT_NV12, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_NV12 },
{ AV_PIX_FMT_NONE, AV_CODEC_ID_MJPEG, V4L2_PIX_FMT_MJPEG },
{ AV_PIX_FMT_NONE, AV_CODEC_ID_MJPEG, V4L2_PIX_FMT_JPEG },
}
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:84
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:67
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:98
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:92
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:69
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:68
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:66
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:71
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:65
Y , 8bpp.
Definition: pixfmt.h:73
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:231
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:72
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:230

Definition at line 97 of file v4l2.c.

§ options

const AVOption options[]
static
Initial value:
= {
{ "standard", "TV standard, used only by analog frame grabber", OFFSET(standard), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC },
{ "channel", "TV channel, used only by frame grabber", OFFSET(channel), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, DEC },
{ "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
{ "pixel_format", "Preferred pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
{ "input_format", "Preferred pixel format (for raw video) or codec name", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
{ "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
{ "list_formats", "List available formats and exit", OFFSET(list_format), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, DEC, "list_formats" },
{ "all", "Show all available formats", OFFSET(list_format), AV_OPT_TYPE_CONST, {.i64 = V4L_ALLFORMATS }, 0, INT_MAX, DEC, "list_formats" },
{ "raw", "Show only non-compressed formats", OFFSET(list_format), AV_OPT_TYPE_CONST, {.i64 = V4L_RAWFORMATS }, 0, INT_MAX, DEC, "list_formats" },
{ "compressed", "Show only compressed formats", OFFSET(list_format), AV_OPT_TYPE_CONST, {.i64 = V4L_COMPFORMATS }, 0, INT_MAX, DEC, "list_formats" },
{ NULL },
}
#define OFFSET(x)
Definition: v4l2.c:868
NULL
Definition: eval.c:55
#define V4L_ALLFORMATS
Definition: v4l2.c:58
int channel
Definition: dv1394.c:40
#define V4L_COMPFORMATS
Definition: v4l2.c:60
#define V4L_RAWFORMATS
Definition: v4l2.c:59
#define DEC
Definition: v4l2.c:869

Definition at line 870 of file v4l2.c.

§ v4l2_class

const AVClass v4l2_class
static
Initial value:
= {
.class_name = "V4L2 indev",
.item_name = av_default_item_name,
.option = options,
}
static const AVOption options[]
Definition: v4l2.c:870
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
av_default_item_name
Definition: dnxhdenc.c:52

Definition at line 884 of file v4l2.c.

§ ff_v4l2_demuxer

AVInputFormat ff_v4l2_demuxer
Initial value:
= {
.name = "video4linux2",
.long_name = NULL_IF_CONFIG_SMALL("Video4Linux2 device grab"),
.priv_data_size = sizeof(struct video_data),
.read_packet = v4l2_read_packet,
.read_close = v4l2_read_close,
.flags = AVFMT_NOFILE,
.priv_class = &v4l2_class,
}
static int v4l2_read_packet(AVFormatContext *s1, AVPacket *pkt)
Definition: v4l2.c:835
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:145
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:544
static const AVClass v4l2_class
Definition: v4l2.c:884
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:409
static int v4l2_read_header(AVFormatContext *s1)
Definition: v4l2.c:728
static int v4l2_read_close(AVFormatContext *s1)
Definition: v4l2.c:854

Definition at line 891 of file v4l2.c.