28 #if defined(__clang__)
29 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
32 #import <QTKit/QTKit.h>
42 #define QTKIT_TIMEBASE 100
87 - (
void)captureOutput:(QTCaptureOutput *)captureOutput
88 didOutputVideoFrame:(CVImageBufferRef)videoFrame
89 withSampleBuffer:(QTSampleBuffer *)sampleBuffer
90 fromConnection:(QTCaptureConnection *)connection;
98 if (
self = [super
init]) {
104 - (
void)captureOutput:(QTCaptureOutput *)captureOutput
105 didOutputVideoFrame:(CVImageBufferRef)videoFrame
106 withSampleBuffer:(QTSampleBuffer *)sampleBuffer
107 fromConnection:(QTCaptureConnection *)connection
127 [ctx->capture_session stopRunning];
129 [ctx->capture_session release];
130 [ctx->video_output release];
131 [ctx->qt_delegate release];
146 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
158 NSArray *devices = [QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo];
159 for (QTCaptureDevice *device
in devices) {
160 const char *
name = [[device localizedDisplayName] UTF8String];
161 int index = [devices indexOfObject:device];
168 QTCaptureDevice *video_device = nil;
176 NSArray *devices = [QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo];
183 video_device = [devices objectAtIndex:ctx->video_device_index];
184 }
else if (strncmp(s->
filename,
"", 1) &&
185 strncmp(s->
filename,
"default", 7)) {
186 NSArray *devices = [QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo];
188 for (QTCaptureDevice *device
in devices) {
189 if (!strncmp(s->
filename, [[device localizedDisplayName] UTF8String], strlen(s->
filename))) {
190 video_device = device;
199 video_device = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeMuxed];
202 BOOL success = [video_device open:nil];
206 video_device = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeVideo];
207 success = [video_device open:nil];
215 NSString* dev_display_name = [video_device localizedDisplayName];
221 QTCaptureDeviceInput* capture_dev_input = [[[QTCaptureDeviceInput alloc] initWithDevice:video_device] autorelease];
222 success = [ctx->capture_session addInput:capture_dev_input error:nil];
231 ctx->
video_output = [[QTCaptureDecompressedVideoOutput alloc] init];
233 NSDictionary *captureDictionary = [NSDictionary dictionaryWithObject:
234 [NSNumber numberWithUnsignedInt:kCVPixelFormatType_24RGB]
235 forKey:(id)kCVPixelBufferPixelFormatTypeKey];
237 [ctx->video_output setPixelBufferAttributes:captureDictionary];
241 [ctx->video_output setDelegate:ctx->qt_delegate];
242 [ctx->video_output setAutomaticallyDropsLateVideoFrames:YES];
243 [ctx->video_output setMinimumVideoFrameInterval:1.0/ctx->frame_rate];
245 success = [ctx->capture_session addOutput:ctx->video_output error:nil];
252 [ctx->capture_session startRunning];
256 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, YES);
337 {
"frame_rate",
"set frame rate", offsetof(
CaptureContext, frame_rate),
AV_OPT_TYPE_FLOAT, { .dbl = 30.0 }, 0.1, 30.0,
AV_OPT_TYPE_VIDEO_RATE,
NULL },
338 {
"list_devices",
"list available devices", offsetof(
CaptureContext, list_devices),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1,
AV_OPT_FLAG_DECODING_PARAM,
"list_devices" },
361 .priv_class = &qtkit_class,
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
#define pthread_mutex_lock(a)
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
ptrdiff_t const GLvoid * data
#define LIBAVUTIL_VERSION_INT
packed RGB 8:8:8, 24bpp, RGBRGB...
static av_cold int init(AVCodecContext *avctx)
pthread_mutex_t frame_lock
static void lock_frames(CaptureContext *ctx)
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static int qtkit_read_header(AVFormatContext *s)
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
CaptureContext * _context
static av_cold int read_close(AVFormatContext *ctx)
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static const AVOption options[]
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.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
FrameReciever class - delegate for QTCaptureSession.
static int qtkit_close(AVFormatContext *s)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static const AVClass qtkit_class
int flags
A combination of AV_PKT_FLAG values.
static int qtkit_read_packet(AVFormatContext *s, AVPacket *pkt)
common internal API header
pthread_cond_t frame_wait_cond
char filename[1024]
input or output filename
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
static void destroy_context(CaptureContext *ctx)
QTCaptureSession * capture_session
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
CVImageBufferRef current_frame
#define pthread_mutex_unlock(a)
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)
#define AV_LOG_INFO
Standard information.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
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
offset must point to AVRational
static void unlock_frames(CaptureContext *ctx)
static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
AVInputFormat ff_qtkit_demuxer
void * priv_data
Format private data.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
QTCaptureDecompressedVideoOutput * video_output
This structure stores compressed data.
static const AVRational kQTKitTimeBase_q
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...