28 #import <AVFoundation/AVFoundation.h> 76 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 135 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 136 AVCaptureDeviceTransportControlsPlaybackMode observed_mode;
160 - (
void) captureOutput:(AVCaptureOutput *)captureOutput
161 didOutputSampleBuffer:(CMSampleBufferRef)videoFrame
162 fromConnection:(AVCaptureConnection *)connection;
170 if (
self = [super
init]) {
174 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 176 NSString *keyPath = NSStringFromSelector(
@selector(transportControlsPlaybackMode));
177 NSKeyValueObservingOptions
options = NSKeyValueObservingOptionNew;
179 [
_context->observed_device addObserver: self
191 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 193 NSString *keyPath = NSStringFromSelector(
@selector(transportControlsPlaybackMode));
194 [
_context->observed_device removeObserver: self forKeyPath: keyPath];
200 - (
void)observeValueForKeyPath:(NSString *)keyPath
202 change:(NSDictionary *)change
203 context:(
void *)context {
205 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 206 AVCaptureDeviceTransportControlsPlaybackMode
mode =
207 [change[NSKeyValueChangeNewKey] integerValue];
209 if (mode !=
_context->observed_mode) {
210 if (mode == AVCaptureDeviceTransportControlsNotPlayingMode) {
217 [
super observeValueForKeyPath: keyPath
224 - (
void) captureOutput:(AVCaptureOutput *)captureOutput
225 didOutputSampleBuffer:(CMSampleBufferRef)videoFrame
226 fromConnection:(AVCaptureConnection *)connection
252 - (
void) captureOutput:(AVCaptureOutput *)captureOutput
253 didOutputSampleBuffer:(CMSampleBufferRef)audioFrame
254 fromConnection:(AVCaptureConnection *)connection;
262 if (
self = [super
init]) {
268 - (
void) captureOutput:(AVCaptureOutput *)captureOutput
269 didOutputSampleBuffer:(CMSampleBufferRef)audioFrame
270 fromConnection:(AVCaptureConnection *)connection
289 [ctx->capture_session stopRunning];
291 [ctx->capture_session release];
292 [ctx->video_output release];
293 [ctx->audio_output release];
294 [ctx->avf_delegate release];
295 [ctx->avf_audio_delegate release];
341 NSObject *range = nil;
343 NSObject *selected_range = nil;
344 NSObject *selected_format = nil;
350 for (format
in [video_device valueForKey:
@"formats"]) {
351 CMFormatDescriptionRef formatDescription;
352 CMVideoDimensions dimensions;
354 formatDescription = (CMFormatDescriptionRef) [format performSelector:
@selector(formatDescription)];
355 dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
358 (dimensions.width == ctx->
width && dimensions.height == ctx->
height)) {
362 for (range
in [format valueForKey:
@"videoSupportedFrameRateRanges"]) {
363 double max_framerate;
365 [[range valueForKey:@"maxFrameRate"] getValue:&max_framerate];
367 selected_range = range;
374 if (!selected_format) {
375 av_log(s,
AV_LOG_ERROR,
"Selected video size (%dx%d) is not supported by the device.\n",
377 goto unsupported_format;
380 if (!selected_range) {
386 goto unsupported_format;
390 if ([video_device lockForConfiguration:
NULL] == YES) {
391 if (selected_format) {
392 [video_device setValue:selected_format forKey:@"activeFormat"];
394 if (selected_range) {
395 NSValue *min_frame_duration = [selected_range valueForKey:@"minFrameDuration"];
396 [video_device setValue:min_frame_duration forKey:@"activeVideoMinFrameDuration"];
397 [video_device setValue:min_frame_duration forKey:@"activeVideoMaxFrameDuration"];
403 }
@catch(NSException *e) {
404 av_log(ctx,
AV_LOG_WARNING,
"Configuration of video device failed, falling back to default.\n");
412 for (format
in [video_device valueForKey:
@"formats"]) {
413 CMFormatDescriptionRef formatDescription;
414 CMVideoDimensions dimensions;
416 formatDescription = (CMFormatDescriptionRef) [format performSelector:
@selector(formatDescription)];
417 dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
419 for (range
in [format valueForKey:
@"videoSupportedFrameRateRanges"]) {
420 double min_framerate;
421 double max_framerate;
423 [[range valueForKey:@"minFrameRate"] getValue:&min_framerate];
424 [[range valueForKey:@"maxFrameRate"] getValue:&max_framerate];
426 dimensions.width, dimensions.height,
427 min_framerate, max_framerate);
437 NSError *
error = nil;
438 AVCaptureInput* capture_input = nil;
440 NSNumber *pixel_format;
441 NSDictionary *capture_dict;
442 dispatch_queue_t queue;
445 capture_input = (AVCaptureInput*) [[[AVCaptureDeviceInput alloc] initWithDevice:video_device
error:&
error] autorelease];
447 capture_input = (AVCaptureInput*) video_device;
450 if (!capture_input) {
452 [[
error localizedDescription] UTF8String]);
457 [ctx->capture_session addInput:capture_input];
464 ctx->
video_output = [[AVCaptureVideoDataOutput alloc] init];
476 }
@catch (NSException *exception) {
477 if (![[exception
name] isEqualToString:NSUndefinedKeyException]) {
488 pxl_fmt_spec = avf_pixel_formats[i];
495 av_log(s,
AV_LOG_ERROR,
"Selected pixel format (%s) is not supported by AVFoundation.\n",
501 if ([[ctx->
video_output availableVideoCVPixelFormatTypes] indexOfObject:[NSNumber numberWithInt:pxl_fmt_spec.avf_id]] == NSNotFound) {
502 av_log(s,
AV_LOG_ERROR,
"Selected pixel format (%s) is not supported by the input device.\n",
508 for (NSNumber *pxl_fmt
in [ctx->
video_output availableVideoCVPixelFormatTypes]) {
512 if ([pxl_fmt intValue] == avf_pixel_formats[
i].
avf_id) {
513 pxl_fmt_dummy = avf_pixel_formats[i];
523 pxl_fmt_spec = pxl_fmt_dummy;
543 pixel_format = [NSNumber numberWithUnsignedInt:pxl_fmt_spec.avf_id];
544 capture_dict = [NSDictionary dictionaryWithObject:pixel_format
545 forKey:(id)kCVPixelBufferPixelFormatTypeKey];
547 [ctx->video_output setVideoSettings:capture_dict];
549 [ctx->video_output setAlwaysDiscardsLateVideoFrames:ctx->drop_late_frames];
551 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 554 int trans_ctrl = [video_device transportControlsSupported];
555 AVCaptureDeviceTransportControlsPlaybackMode trans_mode = [video_device transportControlsPlaybackMode];
558 ctx->observed_mode = trans_mode;
566 queue = dispatch_queue_create(
"avf_queue",
NULL);
567 [ctx->video_output setSampleBufferDelegate:ctx->avf_delegate queue:queue];
568 dispatch_release(queue);
571 [ctx->capture_session addOutput:ctx->video_output];
583 NSError *
error = nil;
584 AVCaptureDeviceInput* audio_dev_input = [[[AVCaptureDeviceInput alloc] initWithDevice:audio_device
error:&
error] autorelease];
585 dispatch_queue_t queue;
587 if (!audio_dev_input) {
589 [[
error localizedDescription] UTF8String]);
594 [ctx->capture_session addInput:audio_dev_input];
601 ctx->
audio_output = [[AVCaptureAudioDataOutput alloc] init];
610 queue = dispatch_queue_create(
"avf_audio_queue",
NULL);
611 [ctx->audio_output setSampleBufferDelegate:ctx->avf_audio_delegate queue:queue];
612 dispatch_release(queue);
615 [ctx->capture_session addOutput:ctx->audio_output];
627 CVImageBufferRef image_buffer;
628 CMBlockBufferRef block_buffer;
629 CGSize image_buffer_size;
638 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, YES);
647 image_buffer = CMSampleBufferGetImageBuffer(ctx->
current_frame);
648 block_buffer = CMSampleBufferGetDataBuffer(ctx->
current_frame);
651 image_buffer_size = CVImageBufferGetEncodedSize(image_buffer);
655 stream->codecpar->width = (
int)image_buffer_size.width;
656 stream->codecpar->height = (
int)image_buffer_size.height;
675 CMFormatDescriptionRef format_desc;
684 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, YES);
694 const AudioStreamBasicDescription *basic_desc = CMAudioFormatDescriptionGetStreamBasicDescription(format_desc);
702 stream->codecpar->sample_rate = basic_desc->mSampleRate;
703 stream->codecpar->channels = basic_desc->mChannelsPerFrame;
708 ctx->
audio_float = basic_desc->mFormatFlags & kAudioFormatFlagIsFloat;
709 ctx->
audio_be = basic_desc->mFormatFlags & kAudioFormatFlagIsBigEndian;
711 ctx->
audio_packed = basic_desc->mFormatFlags & kAudioFormatFlagIsPacked;
714 if (basic_desc->mFormatID == kAudioFormatLinearPCM &&
719 }
else if (basic_desc->mFormatID == kAudioFormatLinearPCM &&
724 }
else if (basic_desc->mFormatID == kAudioFormatLinearPCM &&
729 }
else if (basic_desc->mFormatID == kAudioFormatLinearPCM &&
759 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
760 uint32_t num_screens = 0;
762 AVCaptureDevice *video_device = nil;
763 AVCaptureDevice *audio_device = nil;
765 NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
766 NSArray *devices_muxed = [AVCaptureDevice devicesWithMediaType:AVMediaTypeMuxed];
774 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 775 CGGetActiveDisplayList(0,
NULL, &num_screens);
782 for (AVCaptureDevice *device
in devices) {
783 const char *
name = [[device localizedName] UTF8String];
784 index = [devices indexOfObject:device];
787 for (AVCaptureDevice *device
in devices_muxed) {
788 const char *
name = [[device localizedName] UTF8String];
789 index = [devices count] + [devices_muxed indexOfObject:device];
792 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 793 if (num_screens > 0) {
794 CGDirectDisplayID screens[num_screens];
795 CGGetActiveDisplayList(num_screens, screens, &num_screens);
796 for (
int i = 0;
i < num_screens;
i++) {
803 devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
804 for (AVCaptureDevice *device
in devices) {
805 const char *
name = [[device localizedName] UTF8String];
806 int index = [devices indexOfObject:device];
826 video_device = [devices objectAtIndex:ctx->video_device_index];
828 video_device = [devices_muxed objectAtIndex:(ctx->video_device_index - [devices count])];
832 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 833 CGDirectDisplayID screens[num_screens];
834 CGGetActiveDisplayList(num_screens, screens, &num_screens);
835 AVCaptureScreenInput* capture_screen_input = [[[AVCaptureScreenInput alloc] initWithDisplayID:screens[ctx->video_device_index - ctx->
num_video_devices]] autorelease];
841 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 843 capture_screen_input.capturesCursor = YES;
845 capture_screen_input.capturesCursor = NO;
850 capture_screen_input.capturesMouseClicks = YES;
852 capture_screen_input.capturesMouseClicks = NO;
855 video_device = (AVCaptureDevice*) capture_screen_input;
865 video_device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
868 for (AVCaptureDevice *device
in devices) {
870 video_device = device;
875 for (AVCaptureDevice *device
in devices_muxed) {
877 video_device = device;
883 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 887 if(sscanf(ctx->
video_filename,
"Capture screen %d", &idx) && idx < num_screens) {
888 CGDirectDisplayID screens[num_screens];
889 CGGetActiveDisplayList(num_screens, screens, &num_screens);
890 AVCaptureScreenInput* capture_screen_input = [[[AVCaptureScreenInput alloc] initWithDisplayID:screens[idx]] autorelease];
891 video_device = (AVCaptureDevice*) capture_screen_input;
899 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 901 capture_screen_input.capturesCursor = YES;
903 capture_screen_input.capturesCursor = NO;
908 capture_screen_input.capturesMouseClicks = YES;
910 capture_screen_input.capturesMouseClicks = NO;
925 NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
932 audio_device = [devices objectAtIndex:ctx->audio_device_index];
936 audio_device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
938 NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
940 for (AVCaptureDevice *device
in devices) {
942 audio_device = device;
955 if (!video_device && !audio_device) {
968 av_log(s,
AV_LOG_DEBUG,
"audio device '%s' opened\n", [[audio_device localizedName] UTF8String]);
980 [ctx->capture_session startRunning];
985 [video_device unlockForConfiguration];
1007 CVPixelBufferRef image_buffer,
1011 int src_linesize[4];
1013 int width = CVPixelBufferGetWidth(image_buffer);
1014 int height = CVPixelBufferGetHeight(image_buffer);
1017 memset(src_linesize, 0,
sizeof(src_linesize));
1018 memset(src_data, 0,
sizeof(src_data));
1020 status = CVPixelBufferLockBaseAddress(image_buffer, 0);
1021 if (status != kCVReturnSuccess) {
1022 av_log(s,
AV_LOG_ERROR,
"Could not lock base address: %d (%dx%d)\n", status, width, height);
1026 if (CVPixelBufferIsPlanar(image_buffer)) {
1027 size_t plane_count = CVPixelBufferGetPlaneCount(image_buffer);
1029 for(i = 0; i < plane_count; i++){
1030 src_linesize[i] = CVPixelBufferGetBytesPerRowOfPlane(image_buffer, i);
1031 src_data[i] = CVPixelBufferGetBaseAddressOfPlane(image_buffer, i);
1034 src_linesize[0] = CVPixelBufferGetBytesPerRow(image_buffer);
1035 src_data[0] = CVPixelBufferGetBaseAddress(image_buffer);
1039 src_data, src_linesize,
1044 CVPixelBufferUnlockBaseAddress(image_buffer, 0);
1054 CVImageBufferRef image_buffer;
1055 CMBlockBufferRef block_buffer;
1062 image_buffer = CMSampleBufferGetImageBuffer(ctx->
current_frame);
1063 block_buffer = CMSampleBufferGetDataBuffer(ctx->
current_frame);
1065 if (image_buffer != nil) {
1066 length = (
int)CVPixelBufferGetDataSize(image_buffer);
1067 }
else if (block_buffer != nil) {
1068 length = (
int)CMBlockBufferGetDataLength(block_buffer);
1080 if (CMSampleBufferGetOutputSampleTimingInfoArray(ctx->
current_frame, 1, &timing_info, &count) == noErr) {
1082 pkt->
pts = pkt->
dts =
av_rescale_q(timing_info.presentationTimeStamp.value, timebase_q, avf_time_base_q);
1092 OSStatus
ret = CMBlockBufferCopyDataBytes(block_buffer, 0, pkt->
size, pkt->
data);
1093 if (ret != kCMBlockBufferNoErr) {
1104 int block_buffer_size = CMBlockBufferGetDataLength(block_buffer);
1106 if (!block_buffer || !block_buffer_size) {
1121 if (CMSampleBufferGetOutputSampleTimingInfoArray(ctx->
current_audio_frame, 1, &timing_info, &count) == noErr) {
1123 pkt->
pts = pkt->
dts =
av_rescale_q(timing_info.presentationTimeStamp.value, timebase_q, avf_time_base_q);
1133 if (ret != kCMBlockBufferNoErr) {
1140 #define INTERLEAVE_OUTPUT(bps) \ 1142 int##bps##_t **src; \ 1143 int##bps##_t *dest; \ 1144 src = av_malloc(ctx->audio_channels * sizeof(int##bps##_t*)); \ 1145 if (!src) return AVERROR(EIO); \ 1146 for (c = 0; c < ctx->audio_channels; c++) { \ 1147 src[c] = ((int##bps##_t*)ctx->audio_buffer) + c * num_samples; \ 1149 dest = (int##bps##_t*)pkt->data; \ 1150 shift = bps - ctx->audio_bits_per_sample; \ 1151 for (sample = 0; sample < num_samples; sample++) \ 1152 for (c = 0; c < ctx->audio_channels; c++) \ 1153 *dest++ = src[c][sample] << shift; \ 1163 OSStatus
ret = CMBlockBufferCopyDataBytes(block_buffer, 0, pkt->
size, pkt->
data);
1164 if (ret != kCMBlockBufferNoErr) {
1197 {
"audio_device_index",
"select audio device by index for devices with same name (starts at 0)", offsetof(
AVFContext, audio_device_index),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
1201 {
"capture_cursor",
"capture the screen cursor", offsetof(
AVFContext, capture_cursor),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
1202 {
"capture_mouse_clicks",
"capture the screen mouse clicks", offsetof(
AVFContext, capture_mouse_clicks),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
1203 {
"capture_raw_data",
"capture the raw data from device connection", offsetof(
AVFContext, capture_raw_data),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
1204 {
"drop_late_frames",
"drop frames that are available later than expected", offsetof(
AVFContext, drop_late_frames),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
1218 .
name =
"avfoundation",
1225 .priv_class = &avf_class,
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
static const struct AVFPixelFormatSpec avf_pixel_formats[]
static void lock_frames(AVFContext *ctx)
static int shift(int a, int b)
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
#define pthread_mutex_lock(a)
AVCaptureSession * capture_session
int av_image_copy_to_buffer(uint8_t *dst, int dst_size, const uint8_t *const src_data[4], const int src_linesize[4], enum AVPixelFormat pix_fmt, int width, int height, int align)
Copy image data from an image into a buffer.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
packed RGB 8:8:8, 24bpp, RGBRGB...
static av_cold int init(AVCodecContext *avctx)
int audio_frames_captured
static const AVOption options[]
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined ...
static int add_video_device(AVFormatContext *s, AVCaptureDevice *video_device)
const char * av_default_item_name(void *ptr)
Return the context name.
CMSampleBufferRef current_audio_frame
static int get_audio_config(AVFormatContext *s)
int audio_non_interleaved
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
static void error(const char *err)
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 format(the sample packing is implied by the sample format) and sample rate.The lists are not just lists
AudioReciever class - delegate for AVCaptureSession.
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
static int configure_video_device(AVFormatContext *s, AVCaptureDevice *video_device)
Configure the video device.
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
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
static double av_q2d(AVRational a)
Convert an AVRational to a double.
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
static int copy_cvpixelbuffer(AVFormatContext *s, CVPixelBufferRef image_buffer, AVPacket *pkt)
static void parse_device_name(AVFormatContext *s)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
AVInputFormat ff_avfoundation_demuxer
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Main libavdevice API header.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static __device__ float fabs(float a)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
char * url
input or output URL.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
static int avf_read_header(AVFormatContext *s)
#define AV_PIX_FMT_YUV444P10
int flags
A combination of AV_PKT_FLAG values.
common internal API header
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
static const int avf_time_base
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
packed RGB 8:8:8, 24bpp, BGRBGR...
int audio_bits_per_sample
#define pthread_mutex_unlock(a)
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big...
static int read_header(FFV1Context *f)
int64_t av_gettime(void)
Get the current time in microseconds.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
static int add_audio_device(AVFormatContext *s, AVCaptureDevice *audio_device)
#define AV_LOG_INFO
Standard information.
char * av_strdup(const char *s)
Duplicate a string.
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
static AVRational av_make_q(int num, int den)
Create an AVRational.
static const AVRational avf_time_base_q
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
AVCaptureVideoDataOutput * video_output
pthread_mutex_t frame_lock
static int get_video_config(AVFormatContext *s)
static const AVClass avf_class
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
#define INTERLEAVE_OUTPUT(bps)
Rational number (pair of numerator and denominator).
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
static void unlock_frames(AVFContext *ctx)
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
offset must point to AVRational
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
FrameReciever class - delegate for AVCaptureSession.
offset must point to two consecutive integers
CMSampleBufferRef current_frame
#define flags(name, subs,...)
#define AV_PIX_FMT_YUV422P10
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
enum AVPixelFormat pixel_format
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok()...
static int FUNC() timing_info(CodedBitstreamContext *ctx, RWContext *rw, AV1RawTimingInfo *current)
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
AVCaptureAudioDataOutput * audio_output
static void destroy_context(AVFContext *ctx)
static int avf_read_packet(AVFormatContext *s, AVPacket *pkt)
void * priv_data
Format private data.
AVCaptureDevice * observed_device
static int avf_close(AVFormatContext *s)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
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
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your local context
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
#define AVERROR_EXTERNAL
Generic error in an external library.
AVPixelFormat
Pixel format.
This structure stores compressed data.
mode
Use these values in ebur128_init (or'ed).
#define AV_PIX_FMT_YUV422P16
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...