FFmpeg
Loading...
Searching...
No Matches
avfoundation.m File Reference

AVFoundation input device. More...

#include "config.h"
import <AVFoundation/AVFoundation.h>
#include <pthread.h>
#include "libavutil/channel_layout.h"
#include "libavutil/mem.h"
#include "libavutil/pixdesc.h"
#include "libavutil/opt.h"
#include "libavutil/avstring.h"
#include "libavformat/demux.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
 FrameReceiver class - delegate for AVCaptureSession. More...
 
class  AVFAudioReceiver
 AudioReceiver 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 int parse_device_name (AVFormatContext *s)
 
static int configure_video_device (AVFormatContext *s, AVCaptureDevice *video_device)
 Configure the video device.
 
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 NSArray * getDevicesWithMediaType (AVMediaType mediaType)
 
static int64_t avf_usb_location_for_serial (const char *serial)
 
static NSString * avf_usb_serial_for_location (uint32_t location)
 
static AVCaptureDevice * avf_video_device_with_serial (const char *serial, NSArray *devices, NSArray *devices_muxed, int *is_muxed)
 
static NSString * avf_audio_serial_for_uid (NSString *uid)
 
static AVCaptureDevice * avf_audio_device_with_serial (const char *serial, NSArray *devices)
 
static AVCaptureDevice * avf_device_with_uid (const char *uid, NSArray *devices, NSArray *devices_muxed, int *is_muxed)
 
static NSString * avf_device_listing_serial (AVCaptureDevice *device)
 
static void avf_log_device_entry (AVFContext *ctx, int index, AVCaptureDevice *device)
 
static int avf_device_from_id (AVFContext *ctx, AVMediaType media_type, NSArray *devices, NSArray *devices_muxed, const char *id, AVCaptureDevice **device, int *is_muxed)
 
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
 
const FFInputFormat 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

◆ INTERLEAVE_OUTPUT

#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) { \
unlock_frames(ctx); \
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 AVPacket * pkt
#define sample
#define AVERROR(e)
Definition error.h:45
static int shift(int a, int b)
Definition bonk.c:261
unsigned bps
Definition movenc.c:2074
#define av_malloc(s)
Definition ops_static.c:52
uint8_t * data
Definition packet.h:603
#define src
Definition vp8dsp.c:248
static AVFormatContext * ctx
Definition movenc.c:49
for(y=0;y< h;y++)
Definition vf_mcdeint.c:284
static double c[64]

Referenced by avf_read_packet().

Function Documentation

◆ lock_frames()

◆ unlock_frames()

◆ destroy_context()

static void destroy_context ( AVFContext * ctx)
static

Definition at line 322 of file avfoundation.m.

Referenced by avf_close(), and avf_read_header().

◆ parse_device_name()

static int parse_device_name ( AVFormatContext * s)
static

Definition at line 361 of file avfoundation.m.

Referenced by avf_read_header(), and dshow_read_header().

◆ configure_video_device()

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 389 of file avfoundation.m.

Referenced by add_video_device().

◆ add_video_device()

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

Definition at line 486 of file avfoundation.m.

Referenced by avf_read_header().

◆ add_audio_device()

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

Definition at line 633 of file avfoundation.m.

Referenced by avf_read_header().

◆ get_video_config()

static int get_video_config ( AVFormatContext * s)
static

Definition at line 677 of file avfoundation.m.

Referenced by avf_read_header().

◆ get_audio_config()

static int get_audio_config ( AVFormatContext * s)
static

Definition at line 723 of file avfoundation.m.

Referenced by avf_read_header().

◆ getDevicesWithMediaType()

static NSArray * getDevicesWithMediaType ( AVMediaType mediaType)
static

Definition at line 810 of file avfoundation.m.

Referenced by avf_read_header().

◆ avf_usb_location_for_serial()

static int64_t avf_usb_location_for_serial ( const char * serial)
static

Definition at line 915 of file avfoundation.m.

Referenced by avf_video_device_with_serial().

◆ avf_usb_serial_for_location()

static NSString * avf_usb_serial_for_location ( uint32_t location)
static

Definition at line 945 of file avfoundation.m.

Referenced by avf_device_listing_serial().

◆ avf_video_device_with_serial()

static AVCaptureDevice * avf_video_device_with_serial ( const char * serial,
NSArray * devices,
NSArray * devices_muxed,
int * is_muxed )
static

Definition at line 952 of file avfoundation.m.

Referenced by avf_device_from_id().

◆ avf_audio_serial_for_uid()

static NSString * avf_audio_serial_for_uid ( NSString * uid)
static

Definition at line 990 of file avfoundation.m.

Referenced by avf_audio_device_with_serial(), and avf_device_listing_serial().

◆ avf_audio_device_with_serial()

static AVCaptureDevice * avf_audio_device_with_serial ( const char * serial,
NSArray * devices )
static

Definition at line 996 of file avfoundation.m.

Referenced by avf_device_from_id().

◆ avf_device_with_uid()

static AVCaptureDevice * avf_device_with_uid ( const char * uid,
NSArray * devices,
NSArray * devices_muxed,
int * is_muxed )
static

Definition at line 1007 of file avfoundation.m.

Referenced by avf_device_from_id().

◆ avf_device_listing_serial()

static NSString * avf_device_listing_serial ( AVCaptureDevice * device)
static

Definition at line 1027 of file avfoundation.m.

Referenced by avf_log_device_entry().

◆ avf_log_device_entry()

static void avf_log_device_entry ( AVFContext * ctx,
int index,
AVCaptureDevice * device )
static

Definition at line 1039 of file avfoundation.m.

Referenced by avf_read_header().

◆ avf_device_from_id()

static int avf_device_from_id ( AVFContext * ctx,
AVMediaType media_type,
NSArray * devices,
NSArray * devices_muxed,
const char * id,
AVCaptureDevice ** device,
int * is_muxed )
static

Definition at line 1053 of file avfoundation.m.

Referenced by avf_read_header().

◆ avf_read_header()

static int avf_read_header ( AVFormatContext * s)
static

Definition at line 1085 of file avfoundation.m.

◆ copy_cvpixelbuffer()

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

Definition at line 1341 of file avfoundation.m.

Referenced by avf_read_packet().

◆ avf_read_packet()

static int avf_read_packet ( AVFormatContext * s,
AVPacket * pkt )
static

Definition at line 1384 of file avfoundation.m.

◆ avf_close()

static int avf_close ( AVFormatContext * s)
static

Definition at line 1540 of file avfoundation.m.

Variable Documentation

◆ avf_time_base

const int avf_time_base = 1000000
static

Definition at line 57 of file avfoundation.m.

Referenced by get_audio_config(), and get_video_config().

◆ avf_time_base_q

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

Definition at line 59 of file avfoundation.m.

Referenced by avf_read_packet().

◆ avf_pixel_formats

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 },
}
#define AV_PIX_FMT_YUV422P10
Definition pixfmt.h:546
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition pixfmt.h:96
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
Definition pixfmt.h:83
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition pixfmt.h:265
@ AV_PIX_FMT_RGB555BE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
Definition pixfmt.h:114
@ AV_PIX_FMT_BGR48BE
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:145
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition pixfmt.h:88
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition pixfmt.h:264
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition pixfmt.h:174
@ AV_PIX_FMT_YUVA444P16LE
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition pixfmt.h:192
@ AV_PIX_FMT_RGB565LE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition pixfmt.h:113
@ AV_PIX_FMT_RGB555LE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined
Definition pixfmt.h:115
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition pixfmt.h:263
@ AV_PIX_FMT_RGB565BE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition pixfmt.h:112
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition pixfmt.h:74
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition pixfmt.h:76
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition pixfmt.h:262
#define AV_PIX_FMT_YUV422P16
Definition pixfmt.h:557
#define AV_PIX_FMT_YUV444P10
Definition pixfmt.h:548

Definition at line 69 of file avfoundation.m.

Referenced by add_video_device().

◆ options

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 },
{ "video_device_id", "select video device by prefixed id (uid:<unique ID> or serial:<USB serial number>)", 0x42 , AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
{ "audio_device_id", "select audio device by prefixed id (uid:<unique ID> or serial:<USB serial number>)", 0x42 , AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, 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:355
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
Definition opt.h:302
@ AV_OPT_TYPE_PIXEL_FMT
Underlying C type is enum AVPixelFormat.
Definition opt.h:306
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
Definition opt.h:314
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275

Definition at line 1547 of file avfoundation.m.

Referenced by AVFFrameReceiver::initWithContext:.

◆ avf_class

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

Definition at line 1564 of file avfoundation.m.

◆ ff_avfoundation_demuxer

const FFInputFormat ff_avfoundation_demuxer
Initial value:
= {
.p.name = "avfoundation",
.p.long_name = NULL_IF_CONFIG_SMALL("AVFoundation input device"),
.p.flags = AVFMT_NOFILE,
.p.priv_class = &avf_class,
.priv_data_size = sizeof(AVFContext),
}
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition avformat.h:488
static const AVClass avf_class
static int avf_close(AVFormatContext *s)
static int avf_read_header(AVFormatContext *s)
static int avf_read_packet(AVFormatContext *s, AVPacket *pkt)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static av_cold int read_close(AVFormatContext *ctx)
Definition libcdio.c:143

Definition at line 1572 of file avfoundation.m.