Libav
Data Structures | Macros | Functions | Variables
avfoundation_dec.m File Reference
#import <AVFoundation/AVFoundation.h>
#include <pthread.h>
#include "libavformat/avformat.h"
#include "libavformat/internal.h"
#include "libavutil/log.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
#include "libavutil/time.h"
#include "avdevice.h"

Go to the source code of this file.

Data Structures

struct  AVPixelFormatMap
 
struct  AVFoundationCaptureContext
 
class  VideoCapture
 

Macros

#define AUDIO_DEVICES   1
 
#define VIDEO_DEVICES   2
 
#define ALL_DEVICES   AUDIO_DEVICES | VIDEO_DEVICES
 
#define OFFSET(x)   offsetof(AVFoundationCaptureContext, x)
 
#define DEC   AV_OPT_FLAG_DECODING_PARAM
 

Functions

static enum AVPixelFormat core_video_to_pix_fmt (OSType core_video_fmt)
 
static OSType pix_fmt_to_core_video (enum AVPixelFormat pix_fmt)
 
static void list_capture_devices_by_type (AVFormatContext *s, NSString *type)
 
static int avfoundation_list_capture_devices (AVFormatContext *s)
 
static int list_formats (AVFormatContext *s)
 
static void lock_frames (AVFoundationCaptureContext *ctx)
 
static void unlock_frames (AVFoundationCaptureContext *ctx)
 
static bool configure_video_device (AVFormatContext *s, AVCaptureDevice *video_device)
 Configure the video device. More...
 
static void print_supported_formats (AVFormatContext *s, AVCaptureDevice *device)
 
static int setup_stream (AVFormatContext *s, AVCaptureDevice *device)
 
static int get_video_config (AVFormatContext *s)
 
static void destroy_context (AVFoundationCaptureContext *ctx)
 
static int setup_default_stream (AVFormatContext *s)
 
static AVCaptureDevice * create_device (AVFormatContext *s)
 Try to open device given in filename Two supported formats: "device_unique_id" or "[device_unique_id]". More...
 
static int setup_streams (AVFormatContext *s)
 
static int avfoundation_read_header (AVFormatContext *s)
 
static int avfoundation_read_packet (AVFormatContext *s, AVPacket *pkt)
 
static int avfoundation_read_close (AVFormatContext *s)
 

Variables

static const struct AVPixelFormatMap pixel_format_map []
 
static const AVOption options []
 
static const AVClass avfoundation_class
 
AVInputFormat ff_avfoundation_demuxer
 

Macro Definition Documentation

◆ AUDIO_DEVICES

#define AUDIO_DEVICES   1

Definition at line 115 of file avfoundation_dec.m.

Referenced by avfoundation_list_capture_devices().

◆ VIDEO_DEVICES

#define VIDEO_DEVICES   2

Definition at line 116 of file avfoundation_dec.m.

Referenced by avfoundation_list_capture_devices().

◆ ALL_DEVICES

#define ALL_DEVICES   AUDIO_DEVICES | VIDEO_DEVICES

Definition at line 117 of file avfoundation_dec.m.

◆ OFFSET

#define OFFSET (   x)    offsetof(AVFoundationCaptureContext, x)

Definition at line 119 of file avfoundation_dec.m.

◆ DEC

#define DEC   AV_OPT_FLAG_DECODING_PARAM

Definition at line 120 of file avfoundation_dec.m.

Function Documentation

◆ core_video_to_pix_fmt()

static enum AVPixelFormat core_video_to_pix_fmt ( OSType  core_video_fmt)
static

Definition at line 72 of file avfoundation_dec.m.

Referenced by list_formats(), and setup_stream().

◆ pix_fmt_to_core_video()

static OSType pix_fmt_to_core_video ( enum AVPixelFormat  pix_fmt)
static

Definition at line 81 of file avfoundation_dec.m.

◆ list_capture_devices_by_type()

static void list_capture_devices_by_type ( AVFormatContext s,
NSString *  type 
)
static

Definition at line 133 of file avfoundation_dec.m.

Referenced by avfoundation_list_capture_devices().

◆ avfoundation_list_capture_devices()

static int avfoundation_list_capture_devices ( AVFormatContext s)
static

Definition at line 149 of file avfoundation_dec.m.

Referenced by avfoundation_read_header().

◆ list_formats()

static int list_formats ( AVFormatContext s)
static

Definition at line 162 of file avfoundation_dec.m.

Referenced by avfoundation_read_header().

◆ lock_frames()

static void lock_frames ( AVFoundationCaptureContext ctx)
static

◆ unlock_frames()

static void unlock_frames ( AVFoundationCaptureContext ctx)
static

◆ configure_video_device()

static bool configure_video_device ( AVFormatContext s,
AVCaptureDevice *  video_device 
)
static

Configure the video device.

Definition at line 244 of file avfoundation_dec.m.

Referenced by VideoCapture::captureOutput:didOutputSampleBuffer:fromConnection:, and setup_stream().

◆ print_supported_formats()

static void print_supported_formats ( AVFormatContext s,
AVCaptureDevice *  device 
)
static

Definition at line 315 of file avfoundation_dec.m.

Referenced by configure_video_device(), and setup_stream().

◆ setup_stream()

static int setup_stream ( AVFormatContext s,
AVCaptureDevice *  device 
)
static

◆ get_video_config()

static int get_video_config ( AVFormatContext s)
static

Definition at line 428 of file avfoundation_dec.m.

Referenced by setup_stream(), and setup_streams().

◆ destroy_context()

static void destroy_context ( AVFoundationCaptureContext ctx)
static

Definition at line 467 of file avfoundation_dec.m.

Referenced by avfoundation_read_close(), get_video_config(), and setup_streams().

◆ setup_default_stream()

static int setup_default_stream ( AVFormatContext s)
static

Definition at line 482 of file avfoundation_dec.m.

Referenced by destroy_context(), and setup_streams().

◆ create_device()

static AVCaptureDevice* create_device ( AVFormatContext s)
static

Try to open device given in filename Two supported formats: "device_unique_id" or "[device_unique_id]".

Definition at line 500 of file avfoundation_dec.m.

Referenced by setup_default_stream(), and setup_streams().

◆ setup_streams()

static int setup_streams ( AVFormatContext s)
static

Definition at line 544 of file avfoundation_dec.m.

Referenced by avfoundation_read_header(), and create_device().

◆ avfoundation_read_header()

static int avfoundation_read_header ( AVFormatContext s)
static

Definition at line 587 of file avfoundation_dec.m.

Referenced by setup_streams().

◆ avfoundation_read_packet()

static int avfoundation_read_packet ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 626 of file avfoundation_dec.m.

Referenced by avfoundation_read_header().

◆ avfoundation_read_close()

static int avfoundation_read_close ( AVFormatContext s)
static

Definition at line 663 of file avfoundation_dec.m.

Referenced by avfoundation_read_packet().

Variable Documentation

◆ pixel_format_map

const struct AVPixelFormatMap pixel_format_map[]
static
Initial value:
= {
{ AV_PIX_FMT_ABGR, kCVPixelFormatType_32ABGR },
{ AV_PIX_FMT_ARGB, kCVPixelFormatType_32ARGB },
{ AV_PIX_FMT_BGR24, kCVPixelFormatType_24BGR },
{ AV_PIX_FMT_BGR48BE, kCVPixelFormatType_48RGB },
{ AV_PIX_FMT_BGRA, kCVPixelFormatType_32BGRA },
{ AV_PIX_FMT_MONOBLACK, kCVPixelFormatType_1Monochrome },
{ AV_PIX_FMT_NV12, kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange },
{ AV_PIX_FMT_RGB24, kCVPixelFormatType_24RGB },
{ AV_PIX_FMT_RGB555BE, kCVPixelFormatType_16BE555 },
{ AV_PIX_FMT_RGB555LE, kCVPixelFormatType_16LE555 },
{ AV_PIX_FMT_RGB565BE, kCVPixelFormatType_16BE565 },
{ AV_PIX_FMT_RGB565LE, kCVPixelFormatType_16LE565 },
{ AV_PIX_FMT_RGBA, kCVPixelFormatType_32RGBA },
{ AV_PIX_FMT_UYVY422, kCVPixelFormatType_422YpCbCr8 },
{ AV_PIX_FMT_YUV420P, kCVPixelFormatType_420YpCbCr8Planar },
{ AV_PIX_FMT_YUV422P10, kCVPixelFormatType_422YpCbCr10 },
{ AV_PIX_FMT_YUV422P16, kCVPixelFormatType_422YpCbCr16 },
{ AV_PIX_FMT_YUV444P, kCVPixelFormatType_444YpCbCr8 },
{ AV_PIX_FMT_YUV444P10, kCVPixelFormatType_444YpCbCr10 },
{ AV_PIX_FMT_YUVA444P, kCVPixelFormatType_4444YpCbCrA8R },
{ AV_PIX_FMT_YUVA444P16LE, kCVPixelFormatType_4444AYpCbCr16 },
{ AV_PIX_FMT_YUYV422, kCVPixelFormatType_422YpCbCr8_yuvs },
}
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:78
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:64
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:61
packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), little-endian, most significant bit to 0 ...
Definition: pixfmt.h:112
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition: pixfmt.h:110
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition: pixfmt.h:109
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:91
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:92
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:86
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:265
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:89
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:90
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:62
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:147
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:170
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:60
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:188
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:264
packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), big-endian, most significant bit to 0 ...
Definition: pixfmt.h:111
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:69
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:59
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:267

Definition at line 43 of file avfoundation_dec.m.

◆ options

const AVOption options[]
static
Initial value:
= {
{ "list_devices", "List available devices and exit", OFFSET(list_devices), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, DEC, "list_devices" },
{ "all", "Show all the supported devices", OFFSET(list_devices), AV_OPT_TYPE_CONST, { .i64 = ALL_DEVICES }, 0, INT_MAX, DEC, "list_devices" },
{ "audio", "Show only the audio devices", OFFSET(list_devices), AV_OPT_TYPE_CONST, { .i64 = AUDIO_DEVICES }, 0, INT_MAX, DEC, "list_devices" },
{ "video", "Show only the video devices", OFFSET(list_devices), AV_OPT_TYPE_CONST, { .i64 = VIDEO_DEVICES }, 0, INT_MAX, DEC, "list_devices" },
{ "list_formats", "List available formats and exit", OFFSET(list_formats), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, DEC, "list_formats" },
{ "pixel_format", "Preferred pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, 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 },
{ "framerate", "A string representing desired framerate", OFFSET(framerate), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, DEC },
{ NULL },
}
#define VIDEO_DEVICES
#define OFFSET(x)
#define DEC
NULL
Definition: eval.c:55
#define AUDIO_DEVICES
static int list_formats(AVFormatContext *s)
#define ALL_DEVICES

Definition at line 121 of file avfoundation_dec.m.

◆ avfoundation_class

const AVClass avfoundation_class
static
Initial value:
= {
.class_name = "AVFoundation AVCaptureDevice indev",
.item_name = av_default_item_name,
.option = options,
}
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
static const AVOption options[]
av_default_item_name
Definition: dnxhdenc.c:55

Definition at line 671 of file avfoundation_dec.m.

Referenced by avfoundation_read_close().

◆ ff_avfoundation_demuxer

AVInputFormat ff_avfoundation_demuxer
Initial value:
= {
.name = "avfoundation",
.long_name = NULL_IF_CONFIG_SMALL("AVFoundation AVCaptureDevice grab"),
.priv_data_size = sizeof(AVFoundationCaptureContext),
.priv_class = &avfoundation_class,
}
static int flags
Definition: log.c:50
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
static int avfoundation_read_close(AVFormatContext *s)
static int avfoundation_read_packet(AVFormatContext *s, AVPacket *pkt)
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:546
static int avfoundation_read_header(AVFormatContext *s)
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
static const AVClass avfoundation_class
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:412

Definition at line 678 of file avfoundation_dec.m.