FFmpeg
Data Structures | Macros | Functions | Variables
avfoundation.m File Reference

AVFoundation input device. More...

#import <AVFoundation/AVFoundation.h>
#include <pthread.h>
#include "libavutil/pixdesc.h"
#include "libavutil/opt.h"
#include "libavutil/avstring.h"
#include "libavformat/internal.h"
#include "libavutil/internal.h"
#include "libavutil/parseutils.h"
#include "libavutil/time.h"
#include "libavutil/imgutils.h"
#include "avdevice.h"

Go to the source code of this file.

Data Structures

struct  AVFPixelFormatSpec
 
struct  AVFContext
 
class  AVFFrameReceiver
 FrameReciever class - delegate for AVCaptureSession. More...
 
class  AVFAudioReceiver
 AudioReciever class - delegate for AVCaptureSession. More...
 

Macros

#define INTERLEAVE_OUTPUT(bps)
 

Functions

static void lock_frames (AVFContext *ctx)
 
static void unlock_frames (AVFContext *ctx)
 
static void destroy_context (AVFContext *ctx)
 
static void parse_device_name (AVFormatContext *s)
 
static int configure_video_device (AVFormatContext *s, AVCaptureDevice *video_device)
 Configure the video device. More...
 
static int add_video_device (AVFormatContext *s, AVCaptureDevice *video_device)
 
static int add_audio_device (AVFormatContext *s, AVCaptureDevice *audio_device)
 
static int get_video_config (AVFormatContext *s)
 
static int get_audio_config (AVFormatContext *s)
 
static int avf_read_header (AVFormatContext *s)
 
static int copy_cvpixelbuffer (AVFormatContext *s, CVPixelBufferRef image_buffer, AVPacket *pkt)
 
static int avf_read_packet (AVFormatContext *s, AVPacket *pkt)
 
static int avf_close (AVFormatContext *s)
 

Variables

static const int avf_time_base = 1000000
 
static const AVRational avf_time_base_q
 
static const struct AVFPixelFormatSpec avf_pixel_formats []
 
static const AVOption options []
 
static const AVClass avf_class
 
AVInputFormat ff_avfoundation_demuxer
 

Detailed Description

AVFoundation input device.

Author
Thilo Borgmann thilo.nosp@m..bor.nosp@m.gmann.nosp@m.@mai.nosp@m.l.de

Definition in file avfoundation.m.

Macro Definition Documentation

#define INTERLEAVE_OUTPUT (   bps)
Value:
{ \
int##bps##_t **src; \
int##bps##_t *dest; \
src = av_malloc(ctx->audio_channels * sizeof(int##bps##_t*)); \
if (!src) return AVERROR(EIO); \
for (c = 0; c < ctx->audio_channels; c++) { \
src[c] = ((int##bps##_t*)ctx->audio_buffer) + c * num_samples; \
} \
dest = (int##bps##_t*)pkt->data; \
shift = bps - ctx->audio_bits_per_sample; \
for (sample = 0; sample < num_samples; sample++) \
for (c = 0; c < ctx->audio_channels; c++) \
*dest++ = src[c][sample] << shift; \
av_freep(&src); \
}
static int shift(int a, int b)
Definition: sonic.c:82
int audio_channels
Definition: rtp.c:40
static AVPacket pkt
#define sample
#define av_malloc(s)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
uint8_t * data
Definition: packet.h:363
#define src
Definition: vp8dsp.c:254
AVFormatContext * ctx
Definition: movenc.c:48
if(ret)
int
unsigned bps
Definition: movenc.c:1533
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a it should return
#define av_freep(p)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
for(j=16;j >0;--j)

Referenced by avf_read_packet().

Function Documentation

static void lock_frames ( AVFContext ctx)
static
static void unlock_frames ( AVFContext ctx)
static
static void destroy_context ( AVFContext ctx)
static

Definition at line 287 of file avfoundation.m.

Referenced by avf_close(), and avf_read_header().

static void parse_device_name ( AVFormatContext s)
static

Definition at line 312 of file avfoundation.m.

Referenced by avf_read_header().

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

Configure the video device.

Configure the video device using a run-time approach to access properties since formats, activeFormat are available since iOS >= 7.0 or OSX >= 10.7 and activeVideoMaxFrameDuration is available since i0S >= 7.0 and OSX >= 10.9.

The NSUndefinedKeyException must be handled by the caller of this function.

Definition at line 336 of file avfoundation.m.

Referenced by add_video_device().

static int add_video_device ( AVFormatContext s,
AVCaptureDevice *  video_device 
)
static

Definition at line 433 of file avfoundation.m.

Referenced by avf_read_header().

static int add_audio_device ( AVFormatContext s,
AVCaptureDevice *  audio_device 
)
static

Definition at line 580 of file avfoundation.m.

Referenced by avf_read_header().

static int get_video_config ( AVFormatContext s)
static

Definition at line 624 of file avfoundation.m.

Referenced by avf_read_header().

static int get_audio_config ( AVFormatContext s)
static

Definition at line 672 of file avfoundation.m.

Referenced by avf_read_header().

static int avf_read_header ( AVFormatContext s)
static

Definition at line 757 of file avfoundation.m.

static int copy_cvpixelbuffer ( AVFormatContext s,
CVPixelBufferRef  image_buffer,
AVPacket pkt 
)
static

Definition at line 1006 of file avfoundation.m.

Referenced by avf_read_packet().

static int avf_read_packet ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 1049 of file avfoundation.m.

static int avf_close ( AVFormatContext s)
static

Definition at line 1187 of file avfoundation.m.

Variable Documentation

const int avf_time_base = 1000000
static

Definition at line 41 of file avfoundation.m.

Referenced by get_audio_config(), and get_video_config().

const AVRational avf_time_base_q
static
Initial value:
= {
.num = 1,
}
static const int avf_time_base
Definition: avfoundation.m:41

Definition at line 43 of file avfoundation.m.

const struct AVFPixelFormatSpec avf_pixel_formats[]
static
Initial value:
= {
{ AV_PIX_FMT_MONOBLACK, kCVPixelFormatType_1Monochrome },
{ 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_RGB24, kCVPixelFormatType_24RGB },
{ AV_PIX_FMT_BGR24, kCVPixelFormatType_24BGR },
{ AV_PIX_FMT_0RGB, kCVPixelFormatType_32ARGB },
{ AV_PIX_FMT_BGR0, kCVPixelFormatType_32BGRA },
{ AV_PIX_FMT_0BGR, kCVPixelFormatType_32ABGR },
{ AV_PIX_FMT_RGB0, kCVPixelFormatType_32RGBA },
{ AV_PIX_FMT_BGR48BE, kCVPixelFormatType_48RGB },
{ AV_PIX_FMT_UYVY422, kCVPixelFormatType_422YpCbCr8 },
{ AV_PIX_FMT_YUVA444P, kCVPixelFormatType_4444YpCbCrA8R },
{ AV_PIX_FMT_YUVA444P16LE, kCVPixelFormatType_4444AYpCbCr16 },
{ AV_PIX_FMT_YUV444P, kCVPixelFormatType_444YpCbCr8 },
{ AV_PIX_FMT_YUV422P16, kCVPixelFormatType_422YpCbCr16 },
{ AV_PIX_FMT_YUV422P10, kCVPixelFormatType_422YpCbCr10 },
{ AV_PIX_FMT_YUV444P10, kCVPixelFormatType_444YpCbCr10 },
{ AV_PIX_FMT_YUV420P, kCVPixelFormatType_420YpCbCr8Planar },
{ AV_PIX_FMT_NV12, kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange },
{ AV_PIX_FMT_YUYV422, kCVPixelFormatType_422YpCbCr8_yuvs },
}
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:81
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined ...
Definition: pixfmt.h:108
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:239
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition: pixfmt.h:106
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:238
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition: pixfmt.h:105
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:89
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
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:148
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:177
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:67
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:195
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:240
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
Definition: pixfmt.h:107
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:76
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:237
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:411

Definition at line 53 of file avfoundation.m.

const AVOption options[]
static
Initial value:
= {
{ "list_devices", "list available devices", 0x42, AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
{ "video_device_index", "select video device by index for devices with same name (starts at 0)", 0x42, AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ "audio_device_index", "select audio device by index for devices with same name (starts at 0)", 0x42, AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ "pixel_format", "set pixel format", 0x42, AV_OPT_TYPE_PIXEL_FMT, {.i64 = AV_PIX_FMT_YUV420P}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM},
{ "framerate", "set frame rate", 0x42, AV_OPT_TYPE_VIDEO_RATE, {.str = "ntsc"}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ "video_size", "set video size", 0x42, AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
{ "capture_cursor", "capture the screen cursor", 0x42, AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
{ "capture_mouse_clicks", "capture the screen mouse clicks", 0x42, AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
{ "capture_raw_data", "capture the raw data from device connection", 0x42, AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
{ "drop_late_frames", "drop frames that are available later than expected", 0x42, AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
{ NULL },
}
#define NULL
Definition: coverity.c:32
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:279
offset must point to AVRational
Definition: opt.h:238
offset must point to two consecutive integers
Definition: opt.h:235
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66

Definition at line 1194 of file avfoundation.m.

Referenced by AVFFrameReceiver::initWithContext:.

const AVClass avf_class
static
Initial value:
= {
.class_name = "AVFoundation indev",
.item_name = av_default_item_name,
.option = options,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
static const AVOption options[]
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235

Definition at line 1209 of file avfoundation.m.

AVInputFormat ff_avfoundation_demuxer
Initial value:
= {
.name = "avfoundation",
.long_name = NULL_IF_CONFIG_SMALL("AVFoundation input device"),
.priv_data_size = sizeof(AVFContext),
.priv_class = &avf_class,
}
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:153
static int avf_read_header(AVFormatContext *s)
Definition: avfoundation.m:757
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:527
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
static const AVClass avf_class
#define flags(name, subs,...)
Definition: cbs_av1.c:560
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:458
static int avf_read_packet(AVFormatContext *s, AVPacket *pkt)
static int avf_close(AVFormatContext *s)

Definition at line 1217 of file avfoundation.m.