libavdevice/v4l2.c File Reference

Video4Linux2 grab interface. More...

#include "config.h"
#include "libavformat/internal.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <linux/videodev2.h>
#include <time.h>
#include "libavutil/imgutils.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "avdevice.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
#include "libavutil/avstring.h"

Go to the source code of this file.

Data Structures

struct  video_data
struct  buff_data
struct  fmt_map

Defines

#define v4l2_open   open
#define v4l2_close   close
#define v4l2_dup   dup
#define v4l2_ioctl   ioctl
#define v4l2_read   read
#define v4l2_mmap   mmap
#define v4l2_munmap   munmap
#define OFFSET(x)   offsetof(struct video_data, x)
#define DEC   AV_OPT_FLAG_DECODING_PARAM

Enumerations

enum  io_method { io_read, io_mmap, io_userptr }

Functions

static int device_open (AVFormatContext *ctx, uint32_t *capabilities)
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 PixelFormat pix_fmt, enum CodecID codec_id)
static enum PixelFormat fmt_v4l2ff (uint32_t v4l2_fmt, enum CodecID codec_id)
static enum CodecID fmt_v4l2codec (uint32_t v4l2_fmt)
static int mmap_init (AVFormatContext *ctx)
static int read_init (AVFormatContext *ctx)
static void mmap_release_buffer (AVPacket *pkt)
static int mmap_read_frame (AVFormatContext *ctx, AVPacket *pkt)
static int 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, AVFormatParameters *ap)
static uint32_t device_try_init (AVFormatContext *s1, enum PixelFormat pix_fmt, int *width, int *height, enum CodecID *codec_id)
static int v4l2_read_header (AVFormatContext *s1, AVFormatParameters *ap)
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


Detailed Description

Video4Linux2 grab interface.

Part of this file is based on the V4L2 video capture example (http://v4l2spec.bytesex.org/v4l2spec/capture.c)

Thanks to Michael Niedermayer for providing the mapping between V4L2_PIX_FMT_* and PIX_FMT_*

Definition in file v4l2.c.


Define Documentation

#define DEC   AV_OPT_FLAG_DECODING_PARAM

Definition at line 717 of file v4l2.c.

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

Definition at line 716 of file v4l2.c.

#define v4l2_close   close

Definition at line 62 of file v4l2.c.

Referenced by device_open(), v4l2_read_close(), and v4l2_read_header().

#define v4l2_dup   dup

Definition at line 63 of file v4l2.c.

#define v4l2_ioctl   ioctl

#define v4l2_mmap   mmap

Definition at line 66 of file v4l2.c.

Referenced by mmap_init().

#define v4l2_munmap   munmap

Definition at line 67 of file v4l2.c.

Referenced by mmap_close().

#define v4l2_open   open

Definition at line 61 of file v4l2.c.

Referenced by device_open().

#define v4l2_read   read

Definition at line 65 of file v4l2.c.


Enumeration Type Documentation

enum io_method

Enumerator:
io_read 
io_mmap 
io_userptr 

Definition at line 72 of file v4l2.c.


Function Documentation

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

Definition at line 181 of file v4l2.c.

Referenced by device_try_init().

static int device_open ( AVFormatContext ctx,
uint32_t *  capabilities 
) [static]

Definition at line 127 of file v4l2.c.

Referenced by v4l2_read_header().

static uint32_t device_try_init ( AVFormatContext s1,
enum PixelFormat  pix_fmt,
int *  width,
int *  height,
enum CodecID codec_id 
) [static]

Definition at line 550 of file v4l2.c.

Referenced by v4l2_read_header().

static int first_field ( int  fd  )  [static]

Definition at line 208 of file v4l2.c.

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

static uint32_t fmt_ff2v4l ( enum PixelFormat  pix_fmt,
enum CodecID  codec_id 
) [static]

Definition at line 224 of file v4l2.c.

Referenced by device_try_init().

static enum CodecID fmt_v4l2codec ( uint32_t  v4l2_fmt  )  [static]

Definition at line 254 of file v4l2.c.

Referenced by device_try_init().

static enum PixelFormat fmt_v4l2ff ( uint32_t  v4l2_fmt,
enum CodecID  codec_id 
) [static]

Definition at line 240 of file v4l2.c.

Referenced by v4l2_read_header().

static void mmap_close ( struct video_data s  )  [static]

Definition at line 445 of file v4l2.c.

Referenced by v4l2_read_close().

static int mmap_init ( AVFormatContext ctx  )  [static]

Definition at line 267 of file v4l2.c.

Referenced by v4l2_read_header().

static int mmap_read_frame ( AVFormatContext ctx,
AVPacket pkt 
) [static]

Definition at line 361 of file v4l2.c.

Referenced by v4l2_read_packet().

static void mmap_release_buffer ( AVPacket pkt  )  [static]

Definition at line 337 of file v4l2.c.

Referenced by mmap_read_frame().

static int mmap_start ( AVFormatContext ctx  )  [static]

Definition at line 415 of file v4l2.c.

Referenced by v4l2_read_header().

static int read_frame ( AVFormatContext ctx,
AVPacket pkt 
) [static]

Definition at line 410 of file v4l2.c.

Referenced by v4l2_read_packet(), and vid_read_packet().

static int read_init ( AVFormatContext ctx  )  [static]

Definition at line 332 of file v4l2.c.

Referenced by v4l2_read_header().

static int v4l2_read_close ( AVFormatContext s1  )  [static]

Definition at line 704 of file v4l2.c.

static int v4l2_read_header ( AVFormatContext s1,
AVFormatParameters ap 
) [static]

Definition at line 582 of file v4l2.c.

static int v4l2_read_packet ( AVFormatContext s1,
AVPacket pkt 
) [static]

Definition at line 676 of file v4l2.c.

static int v4l2_set_parameters ( AVFormatContext s1,
AVFormatParameters ap 
) [static]

Definition at line 462 of file v4l2.c.

Referenced by v4l2_read_header().


Variable Documentation

const int desired_video_buffers = 256 [static]

Definition at line 70 of file v4l2.c.

Referenced by mmap_init().

Initial value:

 {
    .name           = "video4linux2,v4l2",
    .long_name      = NULL_IF_CONFIG_SMALL("Video4Linux2 device grab"),
    .priv_data_size = sizeof(struct video_data),
    .read_header    = v4l2_read_header,
    .read_packet    = v4l2_read_packet,
    .read_close     = v4l2_read_close,
    .flags          = AVFMT_NOFILE,
    .priv_class     = &v4l2_class,
}

Definition at line 735 of file v4l2.c.

struct fmt_map fmt_conversion_table[] [static]

Initial value:

 {
    
    { PIX_FMT_YUV420P, CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV420  },
    { PIX_FMT_YUV422P, CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV422P },
    { PIX_FMT_YUYV422, CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUYV    },
    { PIX_FMT_UYVY422, CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_UYVY    },
    { PIX_FMT_YUV411P, CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV411P },
    { PIX_FMT_YUV410P, CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV410  },
    { PIX_FMT_RGB555,  CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB555  },
    { PIX_FMT_RGB565,  CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB565  },
    { PIX_FMT_BGR24,   CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR24   },
    { PIX_FMT_RGB24,   CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB24   },
    { PIX_FMT_BGRA,    CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR32   },
    { PIX_FMT_GRAY8,   CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_GREY    },
    { PIX_FMT_NV12,    CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_NV12    },
    { PIX_FMT_NONE,    CODEC_ID_MJPEG,    V4L2_PIX_FMT_MJPEG   },
    { PIX_FMT_NONE,    CODEC_ID_MJPEG,    V4L2_PIX_FMT_JPEG    },
}

Definition at line 108 of file v4l2.c.

const AVOption options[] [static]

Initial value:

 {
    { "standard", "", OFFSET(standard), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
    { "channel",  "", OFFSET(channel),  AV_OPT_TYPE_INT,    {.dbl = 0 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
    { "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", "", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
    { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
    { NULL },
}

Definition at line 719 of file v4l2.c.

const AVClass v4l2_class [static]

Initial value:

 {
    .class_name = "V4L2 indev",
    .item_name  = av_default_item_name,
    .option     = options,
    .version    = LIBAVUTIL_VERSION_INT,
}

Definition at line 728 of file v4l2.c.


Generated on Fri Oct 26 02:43:50 2012 for FFmpeg by  doxygen 1.5.8