28 #import <AVFoundation/AVFoundation.h> 76 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 153 - (
void) captureOutput:(AVCaptureOutput *)captureOutput
154 didOutputSampleBuffer:(CMSampleBufferRef)videoFrame
155 fromConnection:(AVCaptureConnection *)connection;
163 if (
self = [super
init]) {
169 - (
void) captureOutput:(AVCaptureOutput *)captureOutput
170 didOutputSampleBuffer:(CMSampleBufferRef)videoFrame
171 fromConnection:(AVCaptureConnection *)connection
199 - (
void) captureOutput:(AVCaptureOutput *)captureOutput
200 didOutputSampleBuffer:(CMSampleBufferRef)audioFrame
201 fromConnection:(AVCaptureConnection *)connection;
209 if (
self = [super
init]) {
215 - (
void) captureOutput:(AVCaptureOutput *)captureOutput
216 didOutputSampleBuffer:(CMSampleBufferRef)audioFrame
217 fromConnection:(AVCaptureConnection *)connection
238 [ctx->capture_session stopRunning];
240 [ctx->capture_session release];
241 [ctx->video_output release];
242 [ctx->audio_output release];
243 [ctx->avf_delegate release];
244 [ctx->avf_audio_delegate release];
291 NSObject *range = nil;
293 NSObject *selected_range = nil;
294 NSObject *selected_format = nil;
300 for (format
in [video_device valueForKey:
@"formats"]) {
301 CMFormatDescriptionRef formatDescription;
302 CMVideoDimensions dimensions;
304 formatDescription = (CMFormatDescriptionRef) [format performSelector:
@selector(formatDescription)];
305 dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
308 (dimensions.width == ctx->
width && dimensions.height == ctx->
height)) {
312 for (range
in [format valueForKey:
@"videoSupportedFrameRateRanges"]) {
313 double max_framerate;
315 [[range valueForKey:@"maxFrameRate"] getValue:&max_framerate];
316 if (fabs (
framerate - max_framerate) < 0.01) {
317 selected_range = range;
324 if (!selected_format) {
325 av_log(s,
AV_LOG_ERROR,
"Selected video size (%dx%d) is not supported by the device.\n",
327 goto unsupported_format;
330 if (!selected_range) {
336 goto unsupported_format;
340 if ([video_device lockForConfiguration:
NULL] == YES) {
341 if (selected_format) {
342 [video_device setValue:selected_format forKey:@"activeFormat"];
344 if (selected_range) {
345 NSValue *min_frame_duration = [selected_range valueForKey:@"minFrameDuration"];
346 [video_device setValue:min_frame_duration forKey:@"activeVideoMinFrameDuration"];
347 [video_device setValue:min_frame_duration forKey:@"activeVideoMaxFrameDuration"];
353 }
@catch(NSException *e) {
354 av_log(ctx,
AV_LOG_WARNING,
"Configuration of video device failed, falling back to default.\n");
362 for (format
in [video_device valueForKey:
@"formats"]) {
363 CMFormatDescriptionRef formatDescription;
364 CMVideoDimensions dimensions;
366 formatDescription = (CMFormatDescriptionRef) [format performSelector:
@selector(formatDescription)];
367 dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
369 for (range
in [format valueForKey:
@"videoSupportedFrameRateRanges"]) {
370 double min_framerate;
371 double max_framerate;
373 [[range valueForKey:@"minFrameRate"] getValue:&min_framerate];
374 [[range valueForKey:@"maxFrameRate"] getValue:&max_framerate];
376 dimensions.width, dimensions.height,
377 min_framerate, max_framerate);
387 NSError *
error = nil;
388 AVCaptureInput* capture_input = nil;
390 NSNumber *pixel_format;
391 NSDictionary *capture_dict;
392 dispatch_queue_t queue;
395 capture_input = (AVCaptureInput*) [[[AVCaptureDeviceInput alloc] initWithDevice:video_device
error:&
error] autorelease];
397 capture_input = (AVCaptureInput*) video_device;
400 if (!capture_input) {
402 [[
error localizedDescription] UTF8String]);
407 [ctx->capture_session addInput:capture_input];
414 ctx->
video_output = [[AVCaptureVideoDataOutput alloc] init];
426 }
@catch (NSException *exception) {
427 if (![[exception
name] isEqualToString:NSUndefinedKeyException]) {
438 pxl_fmt_spec = avf_pixel_formats[i];
445 av_log(s,
AV_LOG_ERROR,
"Selected pixel format (%s) is not supported by AVFoundation.\n",
451 if ([[ctx->
video_output availableVideoCVPixelFormatTypes] indexOfObject:[NSNumber numberWithInt:pxl_fmt_spec.avf_id]] == NSNotFound) {
452 av_log(s,
AV_LOG_ERROR,
"Selected pixel format (%s) is not supported by the input device.\n",
458 for (NSNumber *pxl_fmt
in [ctx->
video_output availableVideoCVPixelFormatTypes]) {
462 if ([pxl_fmt intValue] == avf_pixel_formats[
i].
avf_id) {
463 pxl_fmt_dummy = avf_pixel_formats[i];
473 pxl_fmt_spec = pxl_fmt_dummy;
493 pixel_format = [NSNumber numberWithUnsignedInt:pxl_fmt_spec.avf_id];
494 capture_dict = [NSDictionary dictionaryWithObject:pixel_format
495 forKey:(id)kCVPixelBufferPixelFormatTypeKey];
497 [ctx->video_output setVideoSettings:capture_dict];
499 [ctx->video_output setAlwaysDiscardsLateVideoFrames:YES];
503 queue = dispatch_queue_create(
"avf_queue",
NULL);
504 [ctx->video_output setSampleBufferDelegate:ctx->avf_delegate queue:queue];
505 dispatch_release(queue);
508 [ctx->capture_session addOutput:ctx->video_output];
520 NSError *
error = nil;
521 AVCaptureDeviceInput* audio_dev_input = [[[AVCaptureDeviceInput alloc] initWithDevice:audio_device
error:&
error] autorelease];
522 dispatch_queue_t queue;
524 if (!audio_dev_input) {
526 [[
error localizedDescription] UTF8String]);
531 [ctx->capture_session addInput:audio_dev_input];
538 ctx->
audio_output = [[AVCaptureAudioDataOutput alloc] init];
547 queue = dispatch_queue_create(
"avf_audio_queue",
NULL);
548 [ctx->audio_output setSampleBufferDelegate:ctx->avf_audio_delegate queue:queue];
549 dispatch_release(queue);
552 [ctx->capture_session addOutput:ctx->audio_output];
564 CVImageBufferRef image_buffer;
565 CMBlockBufferRef block_buffer;
566 CGSize image_buffer_size;
575 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, YES);
584 image_buffer = CMSampleBufferGetImageBuffer(ctx->
current_frame);
585 block_buffer = CMSampleBufferGetDataBuffer(ctx->
current_frame);
588 image_buffer_size = CVImageBufferGetEncodedSize(image_buffer);
592 stream->codecpar->width = (
int)image_buffer_size.width;
593 stream->codecpar->height = (
int)image_buffer_size.height;
612 CMFormatDescriptionRef format_desc;
621 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, YES);
631 const AudioStreamBasicDescription *basic_desc = CMAudioFormatDescriptionGetStreamBasicDescription(format_desc);
639 stream->codecpar->sample_rate = basic_desc->mSampleRate;
640 stream->codecpar->channels = basic_desc->mChannelsPerFrame;
645 ctx->
audio_float = basic_desc->mFormatFlags & kAudioFormatFlagIsFloat;
646 ctx->
audio_be = basic_desc->mFormatFlags & kAudioFormatFlagIsBigEndian;
648 ctx->
audio_packed = basic_desc->mFormatFlags & kAudioFormatFlagIsPacked;
651 if (basic_desc->mFormatID == kAudioFormatLinearPCM &&
656 }
else if (basic_desc->mFormatID == kAudioFormatLinearPCM &&
661 }
else if (basic_desc->mFormatID == kAudioFormatLinearPCM &&
666 }
else if (basic_desc->mFormatID == kAudioFormatLinearPCM &&
696 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
698 uint32_t num_screens = 0;
700 AVCaptureDevice *video_device = nil;
701 AVCaptureDevice *audio_device = nil;
703 NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
704 NSArray *devices_muxed = [AVCaptureDevice devicesWithMediaType:AVMediaTypeMuxed];
713 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 714 CGGetActiveDisplayList(0,
NULL, &num_screens);
721 for (AVCaptureDevice *device
in devices) {
722 const char *
name = [[device localizedName] UTF8String];
723 index = [devices indexOfObject:device];
726 for (AVCaptureDevice *device
in devices_muxed) {
727 const char *
name = [[device localizedName] UTF8String];
728 index = [devices count] + [devices_muxed indexOfObject:device];
731 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 732 if (num_screens > 0) {
733 CGDirectDisplayID screens[num_screens];
734 CGGetActiveDisplayList(num_screens, screens, &num_screens);
735 for (
int i = 0;
i < num_screens;
i++) {
742 devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
743 for (AVCaptureDevice *device
in devices) {
744 const char *
name = [[device localizedName] UTF8String];
745 int index = [devices indexOfObject:device];
765 video_device = [devices objectAtIndex:ctx->video_device_index];
767 video_device = [devices_muxed objectAtIndex:(ctx->video_device_index - [devices count])];
771 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 772 CGDirectDisplayID screens[num_screens];
773 CGGetActiveDisplayList(num_screens, screens, &num_screens);
774 AVCaptureScreenInput* capture_screen_input = [[[AVCaptureScreenInput alloc] initWithDisplayID:screens[ctx->video_device_index - ctx->
num_video_devices]] autorelease];
780 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 782 capture_screen_input.capturesCursor = YES;
784 capture_screen_input.capturesCursor = NO;
789 capture_screen_input.capturesMouseClicks = YES;
791 capture_screen_input.capturesMouseClicks = NO;
794 video_device = (AVCaptureDevice*) capture_screen_input;
804 video_device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
807 for (AVCaptureDevice *device
in devices) {
809 video_device = device;
814 for (AVCaptureDevice *device
in devices_muxed) {
816 video_device = device;
822 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 826 if(sscanf(ctx->
video_filename,
"Capture screen %d", &idx) && idx < num_screens) {
827 CGDirectDisplayID screens[num_screens];
828 CGGetActiveDisplayList(num_screens, screens, &num_screens);
829 AVCaptureScreenInput* capture_screen_input = [[[AVCaptureScreenInput alloc] initWithDisplayID:screens[idx]] autorelease];
830 video_device = (AVCaptureDevice*) capture_screen_input;
838 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 840 capture_screen_input.capturesCursor = YES;
842 capture_screen_input.capturesCursor = NO;
847 capture_screen_input.capturesMouseClicks = YES;
849 capture_screen_input.capturesMouseClicks = NO;
864 NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
871 audio_device = [devices objectAtIndex:ctx->audio_device_index];
875 audio_device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
877 NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
879 for (AVCaptureDevice *device
in devices) {
881 audio_device = device;
894 if (!video_device && !audio_device) {
907 av_log(s,
AV_LOG_DEBUG,
"audio device '%s' opened\n", [[audio_device localizedName] UTF8String]);
919 [ctx->capture_session startRunning];
923 if (!capture_screen) {
924 [video_device unlockForConfiguration];
946 CVPixelBufferRef image_buffer,
952 int width = CVPixelBufferGetWidth(image_buffer);
953 int height = CVPixelBufferGetHeight(image_buffer);
956 memset(src_linesize, 0,
sizeof(src_linesize));
957 memset(src_data, 0,
sizeof(src_data));
959 status = CVPixelBufferLockBaseAddress(image_buffer, 0);
960 if (status != kCVReturnSuccess) {
961 av_log(s,
AV_LOG_ERROR,
"Could not lock base address: %d (%dx%d)\n", status, width, height);
965 if (CVPixelBufferIsPlanar(image_buffer)) {
966 size_t plane_count = CVPixelBufferGetPlaneCount(image_buffer);
968 for(i = 0; i < plane_count; i++){
969 src_linesize[i] = CVPixelBufferGetBytesPerRowOfPlane(image_buffer, i);
970 src_data[i] = CVPixelBufferGetBaseAddressOfPlane(image_buffer, i);
973 src_linesize[0] = CVPixelBufferGetBytesPerRow(image_buffer);
974 src_data[0] = CVPixelBufferGetBaseAddress(image_buffer);
978 src_data, src_linesize,
983 CVPixelBufferUnlockBaseAddress(image_buffer, 0);
993 CVImageBufferRef image_buffer;
994 CMBlockBufferRef block_buffer;
1001 image_buffer = CMSampleBufferGetImageBuffer(ctx->
current_frame);
1002 block_buffer = CMSampleBufferGetDataBuffer(ctx->
current_frame);
1004 if (image_buffer != nil) {
1005 length = (
int)CVPixelBufferGetDataSize(image_buffer);
1006 }
else if (block_buffer != nil) {
1007 length = (
int)CMBlockBufferGetDataLength(block_buffer);
1019 if (CMSampleBufferGetOutputSampleTimingInfoArray(ctx->
current_frame, 1, &timing_info, &count) == noErr) {
1021 pkt->
pts = pkt->
dts =
av_rescale_q(timing_info.presentationTimeStamp.value, timebase_q, avf_time_base_q);
1031 OSStatus ret = CMBlockBufferCopyDataBytes(block_buffer, 0, pkt->
size, pkt->
data);
1032 if (ret != kCMBlockBufferNoErr) {
1043 int block_buffer_size = CMBlockBufferGetDataLength(block_buffer);
1045 if (!block_buffer || !block_buffer_size) {
1060 if (CMSampleBufferGetOutputSampleTimingInfoArray(ctx->
current_audio_frame, 1, &timing_info, &count) == noErr) {
1062 pkt->
pts = pkt->
dts =
av_rescale_q(timing_info.presentationTimeStamp.value, timebase_q, avf_time_base_q);
1071 OSStatus ret = CMBlockBufferCopyDataBytes(block_buffer, 0, pkt->
size, ctx->
audio_buffer);
1072 if (ret != kCMBlockBufferNoErr) {
1079 #define INTERLEAVE_OUTPUT(bps) \ 1081 int##bps##_t **src; \ 1082 int##bps##_t *dest; \ 1083 src = av_malloc(ctx->audio_channels * sizeof(int##bps##_t*)); \ 1084 if (!src) return AVERROR(EIO); \ 1085 for (c = 0; c < ctx->audio_channels; c++) { \ 1086 src[c] = ((int##bps##_t*)ctx->audio_buffer) + c * num_samples; \ 1088 dest = (int##bps##_t*)pkt->data; \ 1089 shift = bps - ctx->audio_bits_per_sample; \ 1090 for (sample = 0; sample < num_samples; sample++) \ 1091 for (c = 0; c < ctx->audio_channels; c++) \ 1092 *dest++ = src[c][sample] << shift; \ 1102 OSStatus ret = CMBlockBufferCopyDataBytes(block_buffer, 0, pkt->
size, pkt->
data);
1103 if (ret != kCMBlockBufferNoErr) {
1131 {
"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 },
1135 {
"capture_cursor",
"capture the screen cursor", offsetof(
AVFContext, capture_cursor),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
1136 {
"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 },
1137 {
"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 },
1151 .
name =
"avfoundation",
1158 .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)
static const char * format[]
#define pthread_mutex_lock(a)
AVCaptureSession * capture_session
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
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
AudioReciever class - delegate for AVCaptureSession.
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
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.
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.
static av_cold int read_close(AVFormatContext *ctx)
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
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 i(width, name, range_min, range_max)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#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.
static const int avf_time_base
static int capture_screen(CCaptionSubContext *ctx)
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 void error(const char *err)
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.
typedef void(RENAME(mix_any_func_type))
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)\", 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)
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 av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
static int avf_read_packet(AVFormatContext *s, AVPacket *pkt)
void * priv_data
Format private data.
static int avf_close(AVFormatContext *s)
pthread_cond_t frame_wait_cond
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.
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.
#define AV_PIX_FMT_YUV422P16
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...