From 57b97beb6db392eca8e0c284218392ad5529193c Mon Sep 17 00:00:00 2001 From: Andoni Morales Alastruey Date: Wed, 24 Apr 2013 18:53:11 +0200 Subject: [PATCH] applemedia: move plugins using private frameworks to applemedia-nonpublic --- configure.ac | 1 + sys/Makefile.am | 2 +- sys/applemedia-nonpublic/Makefile.am | 84 ++++++++ sys/applemedia-nonpublic/bufferfactory.h | 34 ++++ sys/applemedia-nonpublic/bufferfactory.m | 61 ++++++ sys/{applemedia => applemedia-nonpublic}/celapi.c | 0 sys/{applemedia => applemedia-nonpublic}/celapi.h | 0 .../celvideosrc.c | 0 .../celvideosrc.h | 0 sys/applemedia-nonpublic/cmapi.c | 137 +++++++++++++ sys/applemedia-nonpublic/cmapi.h | 212 +++++++++++++++++++++ sys/applemedia-nonpublic/coremediabuffer.c | 143 ++++++++++++++ sys/applemedia-nonpublic/coremediabuffer.h | 53 ++++++ sys/applemedia-nonpublic/coremediactx.c | 134 +++++++++++++ sys/applemedia-nonpublic/coremediactx.h | 93 +++++++++ sys/applemedia-nonpublic/corevideobuffer.c | 140 ++++++++++++++ sys/applemedia-nonpublic/corevideobuffer.h | 51 +++++ sys/applemedia-nonpublic/cvapi.c | 77 ++++++++ sys/applemedia-nonpublic/cvapi.h | 126 ++++++++++++ sys/applemedia-nonpublic/dynapi-internal.h | 42 ++++ sys/applemedia-nonpublic/dynapi.c | 193 +++++++++++++++++++ sys/applemedia-nonpublic/dynapi.h | 65 +++++++ sys/{applemedia => applemedia-nonpublic}/mioapi.c | 0 sys/{applemedia => applemedia-nonpublic}/mioapi.h | 0 .../miovideodevice.c | 0 .../miovideodevice.h | 0 .../miovideosrc.c | 0 .../miovideosrc.h | 0 sys/applemedia-nonpublic/mtapi.c | 80 ++++++++ sys/applemedia-nonpublic/mtapi.h | 96 ++++++++++ sys/applemedia-nonpublic/plugin.m | 66 +++++++ sys/applemedia/Makefile.am | 14 +- sys/applemedia/coremediactx.c | 6 - sys/applemedia/coremediactx.h | 17 -- sys/applemedia/plugin.m | 8 - 35 files changed, 1891 insertions(+), 44 deletions(-) create mode 100644 sys/applemedia-nonpublic/Makefile.am create mode 100644 sys/applemedia-nonpublic/bufferfactory.h create mode 100644 sys/applemedia-nonpublic/bufferfactory.m rename sys/{applemedia => applemedia-nonpublic}/celapi.c (100%) rename sys/{applemedia => applemedia-nonpublic}/celapi.h (100%) rename sys/{applemedia => applemedia-nonpublic}/celvideosrc.c (100%) rename sys/{applemedia => applemedia-nonpublic}/celvideosrc.h (100%) create mode 100644 sys/applemedia-nonpublic/cmapi.c create mode 100644 sys/applemedia-nonpublic/cmapi.h create mode 100644 sys/applemedia-nonpublic/coremediabuffer.c create mode 100644 sys/applemedia-nonpublic/coremediabuffer.h create mode 100644 sys/applemedia-nonpublic/coremediactx.c create mode 100644 sys/applemedia-nonpublic/coremediactx.h create mode 100644 sys/applemedia-nonpublic/corevideobuffer.c create mode 100644 sys/applemedia-nonpublic/corevideobuffer.h create mode 100644 sys/applemedia-nonpublic/cvapi.c create mode 100644 sys/applemedia-nonpublic/cvapi.h create mode 100644 sys/applemedia-nonpublic/dynapi-internal.h create mode 100644 sys/applemedia-nonpublic/dynapi.c create mode 100644 sys/applemedia-nonpublic/dynapi.h rename sys/{applemedia => applemedia-nonpublic}/mioapi.c (100%) rename sys/{applemedia => applemedia-nonpublic}/mioapi.h (100%) rename sys/{applemedia => applemedia-nonpublic}/miovideodevice.c (100%) rename sys/{applemedia => applemedia-nonpublic}/miovideodevice.h (100%) rename sys/{applemedia => applemedia-nonpublic}/miovideosrc.c (100%) rename sys/{applemedia => applemedia-nonpublic}/miovideosrc.h (100%) create mode 100644 sys/applemedia-nonpublic/mtapi.c create mode 100644 sys/applemedia-nonpublic/mtapi.h create mode 100644 sys/applemedia-nonpublic/plugin.m diff --git a/configure.ac b/configure.ac index eac05f4..85870a8 100644 --- a/configure.ac +++ b/configure.ac @@ -2416,6 +2416,7 @@ sys/acmenc/Makefile sys/acmmp3dec/Makefile sys/androidmedia/Makefile sys/applemedia/Makefile +sys/applemedia-nonpublic/Makefile sys/avc/Makefile sys/bluez/Makefile sys/d3dvideosink/Makefile diff --git a/sys/Makefile.am b/sys/Makefile.am index 99c3801..d7f482c 100644 --- a/sys/Makefile.am +++ b/sys/Makefile.am @@ -11,7 +11,7 @@ ANDROID_MEDIA_DIR= endif if USE_APPLE_MEDIA -APPLE_MEDIA_DIR=applemedia +APPLE_MEDIA_DIR=applemedia applemedia-nonpublic else APPLE_MEDIA_DIR= endif diff --git a/sys/applemedia-nonpublic/Makefile.am b/sys/applemedia-nonpublic/Makefile.am new file mode 100644 index 0000000..27283db --- /dev/null +++ b/sys/applemedia-nonpublic/Makefile.am @@ -0,0 +1,84 @@ +plugin_LTLIBRARIES = libgstapplemedia_nonpublic.la + +libgstapplemedia_nonpublic_la_SOURCES = \ + plugin.m \ + bufferfactory.m \ + corevideobuffer.c \ + coremediabuffer.c \ + cvapi.c \ + cmapi.c \ + coremediactx.c \ + dynapi.c + +libgstapplemedia_nonpublic_la_CPPFLAGS = \ + -Dgst_dyn_api_get_type=gst_dyn_api_priv_get_type \ + -Dgst_dyn_api_debug=gst_dyn_api_priv_debug \ + -Dgst_dyn_api_new=gst_dyn_api_priv_new \ + -Dgst_core_media_buffer_new=gst_core_media_buffer_priv_new \ + -Dgst_core_media_buffer_get_type=gst_core_media_buffer_priv_get_type \ + -Dgst_core_media_buffer_get_pixel_buffer=gst_core_media_buffer_priv_get_pixel_buffer\ + -Dgst_core_video_buffer_new=gst_core_video_buffer_priv_new \ + -Dgst_core_video_buffer_get_type=gst_core_video_buffer_priv_get_type \ + -Dgst_core_media_ctx_new=gst_core_media_ctx_priv_new \ + -Dgst_core_media_ctx_get_type=gst_core_media_ctx_priv_get_type + +libgstapplemedia_nonpublic_la_CFLAGS = \ + $(GST_CFLAGS) \ + $(GST_BASE_CFLAGS) \ + $(GST_PLUGINS_BASE_CFLAGS) + + +libgstapplemedia_nonpublic_la_OBJCFLAGS = \ + $(GST_OBJCFLAGS) \ + $(GST_BASE_CFLAGS) \ + $(GST_PLUGINS_BASE_CFLAGS) + +if HAVE_IOS +libgstapplemedia_nonpublic_la_OBJCFLAGS += -fobjc-abi-version=2 -fobjc-legacy-dispatch +endif + +libgstapplemedia_nonpublic_la_LIBADD = \ + $(GST_BASE_LIBS) \ + $(GST_PLUGINS_BASE_LIBS) \ + -lgstvideo-$(GST_API_VERSION) + +libgstapplemedia_nonpublic_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS) + +libgstapplemedia_nonpublic_la_LDFLAGS = \ + $(GST_PLUGIN_LDFLAGS) \ + $(GST_BASE_LDFLAGS) \ + $(GST_PLUGINS_BASE_LDFLAGS) \ + -Wl,-framework -Wl,Foundation \ + -Wl,-framework -Wl,CoreFoundation \ + -Wl,-framework -Wl,CoreVideo + +noinst_HEADERS = \ + miovideosrc.h \ + miovideodevice.h \ + celvideosrc.h \ + bufferfactory.h \ + corevideobuffer.h \ + coremediabuffer.h \ + coremediactx.h \ + mioapi.h \ + mtapi.h \ + celapi.h \ + cvapi.h \ + cmapi.h \ + dynapi.h \ + dynapi-internal.h + +if HAVE_IOS + +libgstapplemedia_nonpublic_la_SOURCES += \ + celvideosrc.c \ + mtapi.c \ + celapi.c + +else + +libgstapplemedia_nonpublic_la_SOURCES += \ + mioapi.c + +endif + diff --git a/sys/applemedia-nonpublic/bufferfactory.h b/sys/applemedia-nonpublic/bufferfactory.h new file mode 100644 index 0000000..132b953 --- /dev/null +++ b/sys/applemedia-nonpublic/bufferfactory.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2010 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#import + +#include + +@interface GstAMBufferFactory : NSObject { + gpointer coreMediaCtx; +} + +- (id)initWithError:(GError **)error; +- (void)finalize; + +- (GstBuffer *)createGstBufferForCoreVideoBuffer:(CFTypeRef)cvbuf; +- (GstBuffer *)createGstBufferForSampleBuffer:(CFTypeRef)sbuf; + +@end diff --git a/sys/applemedia-nonpublic/bufferfactory.m b/sys/applemedia-nonpublic/bufferfactory.m new file mode 100644 index 0000000..7b2e845 --- /dev/null +++ b/sys/applemedia-nonpublic/bufferfactory.m @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2010 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#import "bufferfactory.h" + +#include "coremediabuffer.h" +#include "corevideobuffer.h" + +@implementation GstAMBufferFactory + +- (id)initWithError:(GError **)error +{ + GstCoreMediaCtx *ctx; + + ctx = + gst_core_media_ctx_new (GST_API_CORE_VIDEO | GST_API_CORE_MEDIA, error); + if (ctx == NULL) + return nil; + + if ((self = [super init])) + coreMediaCtx = ctx; + else + g_object_unref (ctx); + + return self; +} + +- (void)finalize +{ + g_object_unref (coreMediaCtx); + + [super finalize]; +} + +- (GstBuffer *)createGstBufferForCoreVideoBuffer:(CFTypeRef)cvbuf +{ + return gst_core_video_buffer_new (coreMediaCtx, (CVBufferRef) cvbuf, NULL); +} + +- (GstBuffer *)createGstBufferForSampleBuffer:(CFTypeRef)sbuf +{ + return gst_core_media_buffer_new (coreMediaCtx, sbuf); +} + +@end diff --git a/sys/applemedia/celapi.c b/sys/applemedia-nonpublic/celapi.c similarity index 100% rename from sys/applemedia/celapi.c rename to sys/applemedia-nonpublic/celapi.c diff --git a/sys/applemedia/celapi.h b/sys/applemedia-nonpublic/celapi.h similarity index 100% rename from sys/applemedia/celapi.h rename to sys/applemedia-nonpublic/celapi.h diff --git a/sys/applemedia/celvideosrc.c b/sys/applemedia-nonpublic/celvideosrc.c similarity index 100% rename from sys/applemedia/celvideosrc.c rename to sys/applemedia-nonpublic/celvideosrc.c diff --git a/sys/applemedia/celvideosrc.h b/sys/applemedia-nonpublic/celvideosrc.h similarity index 100% rename from sys/applemedia/celvideosrc.h rename to sys/applemedia-nonpublic/celvideosrc.h diff --git a/sys/applemedia-nonpublic/cmapi.c b/sys/applemedia-nonpublic/cmapi.c new file mode 100644 index 0000000..15c28ed --- /dev/null +++ b/sys/applemedia-nonpublic/cmapi.c @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2010 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "cmapi.h" + +#include "dynapi-internal.h" + +#include + +#define CM_FRAMEWORK_PATH "/System/Library/Frameworks/" \ + "CoreMedia.framework/CoreMedia" +#define CM_FRAMEWORK_PATH_OLD "/System/Library/PrivateFrameworks/" \ + "CoreMedia.framework/CoreMedia" + +G_DEFINE_TYPE (GstCMApi, gst_cm_api, GST_TYPE_DYN_API); + +static void +gst_cm_api_init (GstCMApi * self) +{ +} + +static void +gst_cm_api_class_init (GstCMApiClass * klass) +{ +} + +#define SYM_SPEC(name) GST_DYN_SYM_SPEC (GstCMApi, name) + +GstCMApi * +gst_cm_api_obtain (GError ** error) +{ + static const GstDynSymSpec symbols[] = { + SYM_SPEC (FigBaseObjectGetVTable), + + SYM_SPEC (CMGetAttachment), + + SYM_SPEC (FigFormatDescriptionRelease), + SYM_SPEC (FigFormatDescriptionRetain), + SYM_SPEC (CMFormatDescriptionEqual), + SYM_SPEC (CMFormatDescriptionGetExtension), + SYM_SPEC (CMFormatDescriptionGetMediaType), + SYM_SPEC (CMFormatDescriptionGetMediaSubType), + + SYM_SPEC (CMVideoFormatDescriptionCreate), + SYM_SPEC + (FigVideoFormatDescriptionCreateWithSampleDescriptionExtensionAtom), + SYM_SPEC (CMVideoFormatDescriptionGetDimensions), + + SYM_SPEC (CMTimeMake), + + SYM_SPEC (CMSampleBufferCreate), + SYM_SPEC (CMSampleBufferDataIsReady), + SYM_SPEC (CMSampleBufferGetDataBuffer), + SYM_SPEC (CMSampleBufferGetFormatDescription), + SYM_SPEC (CMSampleBufferGetImageBuffer), + SYM_SPEC (CMSampleBufferGetNumSamples), + SYM_SPEC (CMSampleBufferGetSampleAttachmentsArray), + SYM_SPEC (CMSampleBufferGetSampleSize), + SYM_SPEC (FigSampleBufferRelease), + SYM_SPEC (FigSampleBufferRetain), + + SYM_SPEC (CMBlockBufferCreateWithMemoryBlock), + SYM_SPEC (CMBlockBufferGetDataLength), + SYM_SPEC (CMBlockBufferGetDataPointer), + SYM_SPEC (FigBlockBufferRelease), + SYM_SPEC (FigBlockBufferRetain), + + SYM_SPEC (CMBufferQueueDequeueAndRetain), + SYM_SPEC (CMBufferQueueGetBufferCount), + SYM_SPEC (CMBufferQueueInstallTrigger), + SYM_SPEC (CMBufferQueueIsEmpty), + SYM_SPEC (FigBufferQueueRelease), + SYM_SPEC (CMBufferQueueRemoveTrigger), + SYM_SPEC (CMBufferQueueSetValidationCallback), + + SYM_SPEC (kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms), + SYM_SPEC (kCMSampleAttachmentKey_DependsOnOthers), + SYM_SPEC (kCMTimeInvalid), + + {NULL, 0}, + }; + GstCMApi *result; + GModule *module; + + /* We cannot stat() the library as it may not be present on the filesystem. + * This is the case on newer versions of iOS where system libraries are all + * part of dyld_shared_cache... */ + module = g_module_open (CM_FRAMEWORK_PATH, 0); + if (module != NULL) { + result = _gst_dyn_api_new (gst_cm_api_get_type (), CM_FRAMEWORK_PATH, + symbols, error); + g_module_close (module); + } else { + GstDynSymSpec *old_symbols; + guint i; + + old_symbols = g_memdup (symbols, sizeof (symbols)); + for (i = 0; old_symbols[i].name != NULL; i++) { + const gchar *name = old_symbols[i].name; + const gchar *translated_name; + + if (g_str_has_prefix (name, "CM")) + translated_name = g_strconcat ("Fig", name + 2, NULL); + else if (g_str_has_prefix (name, "kCM")) + translated_name = g_strconcat ("kFig", name + 3, NULL); + else + translated_name = g_strdup (name); + + old_symbols[i].name = translated_name; + } + + result = _gst_dyn_api_new (gst_cm_api_get_type (), CM_FRAMEWORK_PATH_OLD, + old_symbols, error); + + for (i = 0; old_symbols[i].name != NULL; i++) + g_free ((gpointer) old_symbols[i].name); + g_free (old_symbols); + } + + return result; +} diff --git a/sys/applemedia-nonpublic/cmapi.h b/sys/applemedia-nonpublic/cmapi.h new file mode 100644 index 0000000..92565fc --- /dev/null +++ b/sys/applemedia-nonpublic/cmapi.h @@ -0,0 +1,212 @@ +/* + * Copyright (C) 2010 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __GST_CM_API_H__ +#define __GST_CM_API_H__ + +#include "dynapi.h" + +#include +#include "cvapi.h" + +G_BEGIN_DECLS + +typedef struct _GstCMApi GstCMApi; +typedef struct _GstCMApiClass GstCMApiClass; + +typedef CFTypeRef FigBaseObjectRef; +typedef struct _FigBaseVTable FigBaseVTable; +typedef struct _FigBaseIface FigBaseIface; + +typedef CFTypeRef CMFormatDescriptionRef; +typedef struct _CMVideoDimensions CMVideoDimensions; +typedef struct _CMTime CMTime; + +typedef CFTypeRef CMBufferQueueRef; +typedef SInt32 CMBufferQueueTriggerCondition; +typedef struct _CMBufferQueueTriggerToken *CMBufferQueueTriggerToken; +typedef CFTypeRef CMSampleBufferRef; +typedef CFTypeRef CMBlockBufferRef; + +typedef void (* CMBufferQueueTriggerCallback) (void *triggerRefcon, + CMBufferQueueTriggerToken triggerToken); +typedef Boolean (* CMBufferQueueValidationCallback) (CMBufferQueueRef queue, + CMSampleBufferRef buf, void *refCon); + +enum _FigMediaType +{ + kFigMediaTypeVideo = 'vide' +}; + +enum _FigCodecType +{ + kComponentVideoUnsigned = 'yuvs', + kFigVideoCodecType_JPEG_OpenDML = 'dmb1', + kYUV420vCodecType = '420v' +}; + +enum _CMBufferQueueTriggerCondition +{ + kCMBufferQueueTrigger_WhenDurationBecomesLessThan = 1, + kCMBufferQueueTrigger_WhenDurationBecomesLessThanOrEqualTo = 2, + kCMBufferQueueTrigger_WhenDurationBecomesGreaterThan = 3, + kCMBufferQueueTrigger_WhenDurationBecomesGreaterThanOrEqualTo = 4, + kCMBufferQueueTrigger_WhenMinPresentationTimeStampChanges = 5, + kCMBufferQueueTrigger_WhenMaxPresentationTimeStampChanges = 6, + kCMBufferQueueTrigger_WhenDataBecomesReady = 7, + kCMBufferQueueTrigger_WhenEndOfDataReached = 8, + kCMBufferQueueTrigger_WhenReset = 9, + kCMBufferQueueTrigger_WhenBufferCountBecomesLessThan = 10, + kCMBufferQueueTrigger_WhenBufferCountBecomesGreaterThan = 11 +}; + +struct _FigBaseVTable +{ + gsize unk; + FigBaseIface * base; + void * derived; +}; + +struct _FigBaseIface +{ + gsize unk1; + gsize unk2; + gsize unk3; + OSStatus (* Invalidate) (FigBaseObjectRef obj); + OSStatus (* Finalize) (FigBaseObjectRef obj); + gpointer unk4; + OSStatus (* CopyProperty) (FigBaseObjectRef obj, CFTypeRef key, void *unk, + CFTypeRef * value); + OSStatus (* SetProperty) (FigBaseObjectRef obj, CFTypeRef key, + CFTypeRef value); +}; + +struct _CMVideoDimensions +{ + UInt32 width; + UInt32 height; +}; + +struct _CMTime +{ + UInt8 data[24]; +}; + +struct _GstCMApi +{ + GstDynApi parent; + + FigBaseVTable * (* FigBaseObjectGetVTable) (FigBaseObjectRef obj); + + void * (* CMGetAttachment) (CFTypeRef obj, CFStringRef attachmentKey, + UInt32 * foundWherePtr); + + void (* FigFormatDescriptionRelease) (CMFormatDescriptionRef desc); + CMFormatDescriptionRef (* FigFormatDescriptionRetain) ( + CMFormatDescriptionRef desc); + Boolean (* CMFormatDescriptionEqual) (CMFormatDescriptionRef desc1, + CMFormatDescriptionRef desc2); + CFTypeRef (* CMFormatDescriptionGetExtension) ( + const CMFormatDescriptionRef desc, CFStringRef extensionKey); + UInt32 (* CMFormatDescriptionGetMediaType) ( + const CMFormatDescriptionRef desc); + UInt32 (* CMFormatDescriptionGetMediaSubType) ( + const CMFormatDescriptionRef desc); + + OSStatus (* CMVideoFormatDescriptionCreate) ( + CFAllocatorRef allocator, UInt32 formatId, UInt32 width, UInt32 height, + CFDictionaryRef extensions, CMFormatDescriptionRef * desc); + OSStatus (* FigVideoFormatDescriptionCreateWithSampleDescriptionExtensionAtom) + (CFAllocatorRef allocator, UInt32 formatId, UInt32 width, UInt32 height, + UInt32 atomId, const UInt8 * data, CFIndex len, void *unk1, + CMFormatDescriptionRef * formatDesc); + CMVideoDimensions (* CMVideoFormatDescriptionGetDimensions) ( + const CMFormatDescriptionRef desc); + + CMTime (* CMTimeMake) (int64_t value, int32_t timescale); + + OSStatus (* CMSampleBufferCreate) (CFAllocatorRef allocator, + CMBlockBufferRef blockBuf, Boolean dataReady, + void *makeDataReadyCallback, + void *makeDataReadyRefcon, + CMFormatDescriptionRef fmtDesc, size_t numSamples, + size_t numSampleTimingEntries, + const void *sampleTimingArray, + size_t numSampleSizeEntries, const size_t *sampleSizeArray, + CMSampleBufferRef * sampleBuffer); + Boolean (* CMSampleBufferDataIsReady) ( + const CMSampleBufferRef buf); + CMBlockBufferRef (* CMSampleBufferGetDataBuffer) ( + const CMSampleBufferRef buf); + CMFormatDescriptionRef (* CMSampleBufferGetFormatDescription) ( + const CMSampleBufferRef buf); + CVImageBufferRef (* CMSampleBufferGetImageBuffer) ( + const CMSampleBufferRef buf); + SInt32 (* CMSampleBufferGetNumSamples) ( + const CMSampleBufferRef buf); + CFArrayRef (* CMSampleBufferGetSampleAttachmentsArray) ( + const CMSampleBufferRef buf, SInt32 sampleIndex); + SInt32 (* CMSampleBufferGetSampleSize) ( + const CMSampleBufferRef buf, SInt32 sampleIndex); + void (* FigSampleBufferRelease) (CMSampleBufferRef buf); + CMSampleBufferRef (* FigSampleBufferRetain) (CMSampleBufferRef buf); + + OSStatus (* CMBlockBufferCreateWithMemoryBlock) + (CFAllocatorRef allocator, void * memoryBlock, size_t blockLength, + CFAllocatorRef dataAllocator, void *customBlockSource, + size_t offsetToData, size_t dataLength, + int flags, CMBlockBufferRef * blockBuffer); + SInt32 (* CMBlockBufferGetDataLength) (const CMBlockBufferRef buf); + OSStatus (* CMBlockBufferGetDataPointer) ( + const CMBlockBufferRef buf, UInt32 unk1, UInt32 unk2, UInt32 unk3, + Byte ** dataPtr); + void (* FigBlockBufferRelease) (CMBlockBufferRef buf); + CMBlockBufferRef (* FigBlockBufferRetain) (CMBlockBufferRef buf); + + CMSampleBufferRef (* CMBufferQueueDequeueAndRetain) + (CMBufferQueueRef queue); + CFIndex (* CMBufferQueueGetBufferCount) (CMBufferQueueRef queue); + OSStatus (* CMBufferQueueInstallTrigger) (CMBufferQueueRef queue, + CMBufferQueueTriggerCallback triggerCallback, void * triggerRefCon, + CMBufferQueueTriggerCondition triggerCondition, CMTime triggerTime, + CMBufferQueueTriggerToken * triggerTokenOut); + Boolean (* CMBufferQueueIsEmpty) (CMBufferQueueRef queue); + void (* FigBufferQueueRelease) (CMBufferQueueRef queue); + OSStatus (* CMBufferQueueRemoveTrigger) (CMBufferQueueRef queue, + CMBufferQueueTriggerToken triggerToken); + OSStatus (* CMBufferQueueSetValidationCallback) (CMBufferQueueRef queue, + CMBufferQueueValidationCallback func, void *refCon); + + CFStringRef * kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms; + CFStringRef * kCMSampleAttachmentKey_DependsOnOthers; + CMTime * kCMTimeInvalid; +}; + +struct _GstCMApiClass +{ + GstDynApiClass parent_class; +}; + +GType gst_cm_api_get_type (void); + +GstCMApi * gst_cm_api_obtain (GError ** error); + +G_END_DECLS + +#endif diff --git a/sys/applemedia-nonpublic/coremediabuffer.c b/sys/applemedia-nonpublic/coremediabuffer.c new file mode 100644 index 0000000..a8136ba --- /dev/null +++ b/sys/applemedia-nonpublic/coremediabuffer.c @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2009 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "coremediabuffer.h" + +static void +gst_core_media_meta_free (GstCoreMediaMeta * meta, GstBuffer * buf) +{ + if (meta->image_buf != NULL) { + GstCVApi *cv = meta->ctx->cv; + cv->CVPixelBufferUnlockBaseAddress (meta->image_buf, + kCVPixelBufferLock_ReadOnly); + } + meta->ctx->cm->FigSampleBufferRelease (meta->sample_buf); + g_object_unref (meta->ctx); +} + +GType +gst_core_media_meta_api_get_type (void) +{ + static volatile GType type; + static const gchar *tags[] = { "memory", NULL }; + + if (g_once_init_enter (&type)) { + GType _type = gst_meta_api_type_register ("GstCoreMediaMetaAPI", tags); + g_once_init_leave (&type, _type); + } + return type; +} + +static const GstMetaInfo * +gst_core_media_meta_get_info (void) +{ + static const GstMetaInfo *core_media_meta_info = NULL; + + if (g_once_init_enter (&core_media_meta_info)) { + const GstMetaInfo *meta = gst_meta_register (GST_CORE_MEDIA_META_API_TYPE, + "GstCoreMediaMeta", sizeof (GstCoreMediaMeta), + (GstMetaInitFunction) NULL, + (GstMetaFreeFunction) gst_core_media_meta_free, + (GstMetaTransformFunction) NULL); + g_once_init_leave (&core_media_meta_info, meta); + } + return core_media_meta_info; +} + +GstBuffer * +gst_core_media_buffer_new (GstCoreMediaCtx * ctx, CMSampleBufferRef sample_buf) +{ + GstCVApi *cv = ctx->cv; + GstCMApi *cm = ctx->cm; + CVImageBufferRef image_buf; + CVPixelBufferRef pixel_buf; + CMBlockBufferRef block_buf; + Byte *data = NULL; + UInt32 size; + OSStatus status; + GstBuffer *buf; + GstCoreMediaMeta *meta; + + image_buf = cm->CMSampleBufferGetImageBuffer (sample_buf); + pixel_buf = NULL; + block_buf = cm->CMSampleBufferGetDataBuffer (sample_buf); + + if (image_buf != NULL && + CFGetTypeID (image_buf) == cv->CVPixelBufferGetTypeID ()) { + pixel_buf = (CVPixelBufferRef) image_buf; + + if (cv->CVPixelBufferLockBaseAddress (pixel_buf, + kCVPixelBufferLock_ReadOnly) != kCVReturnSuccess) { + goto error; + } + + if (cv->CVPixelBufferIsPlanar (pixel_buf)) { + gint plane_count, plane_idx; + + data = cv->CVPixelBufferGetBaseAddressOfPlane (pixel_buf, 0); + + size = 0; + plane_count = cv->CVPixelBufferGetPlaneCount (pixel_buf); + for (plane_idx = 0; plane_idx != plane_count; plane_idx++) { + size += cv->CVPixelBufferGetBytesPerRowOfPlane (pixel_buf, plane_idx) * + cv->CVPixelBufferGetHeightOfPlane (pixel_buf, plane_idx); + } + } else { + data = cv->CVPixelBufferGetBaseAddress (pixel_buf); + size = cv->CVPixelBufferGetBytesPerRow (pixel_buf) * + cv->CVPixelBufferGetHeight (pixel_buf); + } + } else if (block_buf != NULL) { + status = cm->CMBlockBufferGetDataPointer (block_buf, 0, 0, 0, &data); + if (status != noErr) + goto error; + size = cm->CMBlockBufferGetDataLength (block_buf); + } else { + goto error; + } + + buf = gst_buffer_new (); + + meta = (GstCoreMediaMeta *) gst_buffer_add_meta (buf, + gst_core_media_meta_get_info (), NULL); + meta->ctx = g_object_ref (ctx); + meta->sample_buf = cm->FigSampleBufferRetain (sample_buf); + meta->image_buf = image_buf; + meta->pixel_buf = pixel_buf; + meta->block_buf = block_buf; + + gst_buffer_append_memory (buf, + gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE, data, + size, 0, size, NULL, NULL)); + + return buf; + +error: + return NULL; +} + +CVPixelBufferRef +gst_core_media_buffer_get_pixel_buffer (GstBuffer * buf) +{ + GstCoreMediaMeta *meta = (GstCoreMediaMeta *) gst_buffer_get_meta (buf, + GST_CORE_MEDIA_META_API_TYPE); + g_return_val_if_fail (meta != NULL, NULL); + + return meta->ctx->cv->CVPixelBufferRetain (meta->pixel_buf); +} diff --git a/sys/applemedia-nonpublic/coremediabuffer.h b/sys/applemedia-nonpublic/coremediabuffer.h new file mode 100644 index 0000000..dffb43f --- /dev/null +++ b/sys/applemedia-nonpublic/coremediabuffer.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2009 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __GST_CORE_MEDIA_BUFFER_H__ +#define __GST_CORE_MEDIA_BUFFER_H__ + +#include + +#include "coremediactx.h" + +G_BEGIN_DECLS + +#define GST_CORE_MEDIA_META_API_TYPE (gst_core_media_meta_api_get_type()) +#define gst_buffer_get_core_media_meta(b) \ + ((GstCoreMediaMeta*)gst_buffer_get_meta((b),GST_CORE_MEDIA_META_API_TYPE)) + +typedef struct _GstCoreMediaMeta +{ + GstMeta meta; + + GstCoreMediaCtx * ctx; + CMSampleBufferRef sample_buf; + CVImageBufferRef image_buf; + CVPixelBufferRef pixel_buf; + CMBlockBufferRef block_buf; +} GstCoreMediaMeta; + + +GstBuffer * gst_core_media_buffer_new (GstCoreMediaCtx * ctx, + CMSampleBufferRef sample_buf); +CVPixelBufferRef gst_core_media_buffer_get_pixel_buffer + (GstBuffer * buf); +GType gst_core_media_meta_api_get_type (void); + +G_END_DECLS + +#endif /* __GST_CORE_MEDIA_BUFFER_H__ */ diff --git a/sys/applemedia-nonpublic/coremediactx.c b/sys/applemedia-nonpublic/coremediactx.c new file mode 100644 index 0000000..ba02e4b --- /dev/null +++ b/sys/applemedia-nonpublic/coremediactx.c @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2010 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "coremediactx.h" + +#include + +typedef struct _GstApiProvider GstApiProvider; + +typedef gpointer (*GstApiProviderObtainFunc) (GError ** error); + +struct _GstApiProvider +{ + GstCoreMediaApi api; + GstApiProviderObtainFunc obtain; + guint offset; +}; + +#define API_PROVIDER(AN, a_n) \ + { GST_API_##AN, (GstApiProviderObtainFunc) gst_##a_n##_api_obtain, \ + G_STRUCT_OFFSET (GstCoreMediaCtx, a_n) } + +static const GstApiProvider api_provider[] = { + API_PROVIDER (CORE_VIDEO, cv), + API_PROVIDER (CORE_MEDIA, cm), +#ifdef HAVE_IOS + API_PROVIDER (MEDIA_TOOLBOX, mt), + API_PROVIDER (CELESTIAL, cel) +#else + API_PROVIDER (MIO, mio), +#endif +}; + +G_DEFINE_TYPE (GstCoreMediaCtx, gst_core_media_ctx, G_TYPE_OBJECT); + +static void +gst_core_media_ctx_init (GstCoreMediaCtx * self) +{ +} + +static void +gst_core_media_ctx_dispose (GObject * object) +{ + GstCoreMediaCtx *self = GST_CORE_MEDIA_CTX_CAST (object); + guint i; + + for (i = 0; i != G_N_ELEMENTS (api_provider); i++) { + const GstApiProvider *ap = &api_provider[i]; + gpointer *api_ptr = (gpointer *) ((guint8 *) self + ap->offset); + + if (*api_ptr != NULL) { + g_object_unref (*api_ptr); + *api_ptr = NULL; + } + } + + G_OBJECT_CLASS (gst_core_media_ctx_parent_class)->dispose (object); +} + +static void +gst_core_media_ctx_class_init (GstCoreMediaCtxClass * klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->dispose = gst_core_media_ctx_dispose; +} + +GstCoreMediaCtx * +gst_core_media_ctx_new (GstCoreMediaApi required_apis, GError ** error) +{ + GstCoreMediaCtx *ctx; + GArray *error_messages; + guint i; + + ctx = g_object_new (GST_TYPE_CORE_MEDIA_CTX, NULL); + + error_messages = g_array_new (TRUE, FALSE, sizeof (gchar *)); + + for (i = 0; i != G_N_ELEMENTS (api_provider); i++) { + const GstApiProvider *ap = &api_provider[i]; + + if ((required_apis & ap->api) != 0) { + gpointer *api_ptr = (gpointer *) ((guint8 *) ctx + ap->offset); + GError *tmp_error = NULL; + + *api_ptr = ap->obtain (&tmp_error); + if (tmp_error != NULL) { + gchar *message_copy = g_strdup (tmp_error->message); + g_array_append_val (error_messages, message_copy); + g_clear_error (&tmp_error); + } + } + } + + if (error_messages->len != 0) { + gchar *errors_joined; + + errors_joined = g_strjoinv ("\n\t* ", (gchar **) error_messages->data); + g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED, + "Could not obtain required API%s:%s%s", + (error_messages->len == 1) ? "" : "s", + (error_messages->len == 1) ? " " : "\n\t* ", errors_joined); + g_free (errors_joined); + + g_object_unref (ctx); + ctx = NULL; + } + + for (i = 0; i != error_messages->len; i++) + g_free (g_array_index (error_messages, gchar *, i)); + g_array_free (error_messages, TRUE); + + return ctx; +} diff --git a/sys/applemedia-nonpublic/coremediactx.h b/sys/applemedia-nonpublic/coremediactx.h new file mode 100644 index 0000000..45640bd --- /dev/null +++ b/sys/applemedia-nonpublic/coremediactx.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2010 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __GST_CORE_MEDIA_CTX_H__ +#define __GST_CORE_MEDIA_CTX_H__ + +#include "cvapi.h" +#include "cmapi.h" + +#include "mioapi.h" + +#include "mtapi.h" +#include "celapi.h" + +#include + +G_BEGIN_DECLS + +#define GST_TYPE_CORE_MEDIA_CTX \ + (gst_core_media_ctx_get_type ()) +#define GST_CORE_MEDIA_CTX(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_CORE_MEDIA_CTX, GstCoreMediaCtx)) +#define GST_CORE_MEDIA_CTX_CAST(obj) \ + ((GstCoreMediaCtx *) (obj)) +#define GST_CORE_MEDIA_CTX_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_CORE_MEDIA_CTX, GstCoreMediaCtxClass)) +#define GST_IS_CORE_MEDIA_CTX(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_CORE_MEDIA_CTX)) +#define GST_IS_CORE_MEDIA_CTX_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_CORE_MEDIA_CTX)) + +typedef struct _GstCoreMediaCtx GstCoreMediaCtx; +typedef struct _GstCoreMediaCtxClass GstCoreMediaCtxClass; + +typedef enum _GstCoreMediaApi GstCoreMediaApi; + +struct _GstCoreMediaCtx +{ + GObject parent; + + /* Common */ + GstCVApi *cv; + GstCMApi *cm; + + /* OS X */ + GstMIOApi *mio; + + /* iPhone */ + GstMTApi *mt; + GstCelApi *cel; +}; + +struct _GstCoreMediaCtxClass +{ + GObjectClass parent_class; +}; + +enum _GstCoreMediaApi +{ + GST_API_CORE_VIDEO = (1 << 0), + GST_API_CORE_MEDIA = (1 << 1), + GST_API_VIDEO_TOOLBOX = (1 << 2), + + GST_API_MIO = (1 << 3), + + GST_API_MEDIA_TOOLBOX = (1 << 4), + GST_API_CELESTIAL = (1 << 5) +}; + +GType gst_core_media_ctx_get_type (void); + +GstCoreMediaCtx * gst_core_media_ctx_new (GstCoreMediaApi required_apis, + GError ** error); + +G_END_DECLS + +#endif diff --git a/sys/applemedia-nonpublic/corevideobuffer.c b/sys/applemedia-nonpublic/corevideobuffer.c new file mode 100644 index 0000000..072fe6b --- /dev/null +++ b/sys/applemedia-nonpublic/corevideobuffer.c @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2010 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "corevideobuffer.h" + +static void +gst_core_video_meta_free (GstCoreVideoMeta * meta, GstBuffer * buf) +{ + GstCVApi *cv = meta->ctx->cv; + + if (meta->pixbuf != NULL) { + cv->CVPixelBufferUnlockBaseAddress (meta->pixbuf, + kCVPixelBufferLock_ReadOnly); + } + + cv->CVBufferRelease (meta->cvbuf); + g_object_unref (meta->ctx); +} + +GType +gst_core_video_meta_api_get_type (void) +{ + static volatile GType type; + static const gchar *tags[] = { "memory", NULL }; + + if (g_once_init_enter (&type)) { + GType _type = gst_meta_api_type_register ("GstCoreVideoMetaAPI", tags); + g_once_init_leave (&type, _type); + } + return type; +} + +static const GstMetaInfo * +gst_core_video_meta_get_info (void) +{ + static const GstMetaInfo *core_video_meta_info = NULL; + + if (g_once_init_enter (&core_video_meta_info)) { + const GstMetaInfo *meta = gst_meta_register (GST_CORE_VIDEO_META_API_TYPE, + "GstCoreVideoMeta", sizeof (GstCoreVideoMeta), + (GstMetaInitFunction) NULL, + (GstMetaFreeFunction) gst_core_video_meta_free, + (GstMetaTransformFunction) NULL); + g_once_init_leave (&core_video_meta_info, meta); + } + return core_video_meta_info; +} + +GstBuffer * +gst_core_video_buffer_new (GstCoreMediaCtx * ctx, CVBufferRef cvbuf, + GstVideoInfo * vinfo) +{ + GstCVApi *cv = ctx->cv; + void *data; + size_t size; + CVPixelBufferRef pixbuf = NULL; + GstBuffer *buf; + GstCoreVideoMeta *meta; + guint width, height, n_planes, i; + gsize offset[GST_VIDEO_MAX_PLANES]; + gint stride[GST_VIDEO_MAX_PLANES]; + + if (CFGetTypeID (cvbuf) != cv->CVPixelBufferGetTypeID ()) + /* TODO: Do we need to handle other buffer types? */ + goto error; + + pixbuf = (CVPixelBufferRef) cvbuf; + + if (cv->CVPixelBufferLockBaseAddress (pixbuf, + kCVPixelBufferLock_ReadOnly) != kCVReturnSuccess) { + goto error; + } + + buf = gst_buffer_new (); + + /* add the corevideo meta to free the underlying corevideo buffer */ + meta = (GstCoreVideoMeta *) gst_buffer_add_meta (buf, + gst_core_video_meta_get_info (), NULL); + meta->ctx = g_object_ref (ctx); + meta->cvbuf = cv->CVBufferRetain (cvbuf); + meta->pixbuf = pixbuf; + + /* set stride, offset and size */ + memset (&offset, 0, sizeof (offset)); + memset (&stride, 0, sizeof (stride)); + + data = cv->CVPixelBufferGetBaseAddress (pixbuf); + height = cv->CVPixelBufferGetHeight (pixbuf); + if (cv->CVPixelBufferIsPlanar (pixbuf)) { + GstVideoInfo tmp_vinfo; + + n_planes = cv->CVPixelBufferGetPlaneCount (pixbuf); + for (i = 0; i < n_planes; ++i) + stride[i] = cv->CVPixelBufferGetBytesPerRowOfPlane (pixbuf, i); + + /* FIXME: don't hardcode NV12 */ + gst_video_info_init (&tmp_vinfo); + gst_video_info_set_format (&tmp_vinfo, + GST_VIDEO_FORMAT_NV12, stride[0], height); + offset[1] = tmp_vinfo.offset[1]; + size = tmp_vinfo.size; + } else { + n_planes = 1; + size = cv->CVPixelBufferGetBytesPerRow (pixbuf) * height; + } + + gst_buffer_append_memory (buf, + gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE, data, + size, 0, size, NULL, NULL)); + + if (vinfo) { + GstVideoMeta *video_meta; + + width = vinfo->width; + video_meta = + gst_buffer_add_video_meta_full (buf, GST_VIDEO_FRAME_FLAG_NONE, + GST_VIDEO_FORMAT_NV12, width, height, n_planes, offset, stride); + } + + return buf; + +error: + return NULL; +} diff --git a/sys/applemedia-nonpublic/corevideobuffer.h b/sys/applemedia-nonpublic/corevideobuffer.h new file mode 100644 index 0000000..844d655 --- /dev/null +++ b/sys/applemedia-nonpublic/corevideobuffer.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2010 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __GST_CORE_VIDEO_BUFFER_H__ +#define __GST_CORE_VIDEO_BUFFER_H__ + +#include +#include +#include + +#include "coremediactx.h" + +G_BEGIN_DECLS + +#define GST_CORE_VIDEO_META_API_TYPE (gst_core_video_meta_api_get_type()) +#define gst_buffer_get_core_video_meta(b) \ + ((GstCoreVideoMeta*)gst_buffer_get_meta((b),GST_CORE_VIDEO_META_API_TYPE)) + +typedef struct _GstCoreVideoMeta +{ + GstMeta meta; + + GstCoreMediaCtx *ctx; + CVBufferRef cvbuf; + CVPixelBufferRef pixbuf; +} GstCoreVideoMeta; + +GstBuffer * gst_core_video_buffer_new (GstCoreMediaCtx * ctx, + CVBufferRef cvbuf, + GstVideoInfo *info); +GType gst_core_video_meta_api_get_type (void); + +G_END_DECLS + +#endif /* __GST_CORE_VIDEO_BUFFER_H__ */ diff --git a/sys/applemedia-nonpublic/cvapi.c b/sys/applemedia-nonpublic/cvapi.c new file mode 100644 index 0000000..998428a --- /dev/null +++ b/sys/applemedia-nonpublic/cvapi.c @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2010 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "cvapi.h" + +#include "dynapi-internal.h" + +#define CV_FRAMEWORK_PATH "/System/Library/Frameworks/CoreVideo.framework/" \ + "CoreVideo" + +G_DEFINE_TYPE (GstCVApi, gst_cv_api, GST_TYPE_DYN_API); + +static void +gst_cv_api_init (GstCVApi * self) +{ +} + +static void +gst_cv_api_class_init (GstCVApiClass * klass) +{ +} + +#define SYM_SPEC(name) GST_DYN_SYM_SPEC (GstCVApi, name) +#define SYM_SPEC_OPTIONAL(name) GST_DYN_SYM_SPEC_OPTIONAL (GstCVApi, name) + +GstCVApi * +gst_cv_api_obtain (GError ** error) +{ + static const GstDynSymSpec symbols[] = { + SYM_SPEC (CVBufferRelease), + SYM_SPEC (CVBufferRetain), + + SYM_SPEC (CVPixelBufferCreateWithBytes), + SYM_SPEC (CVPixelBufferCreateWithPlanarBytes), + SYM_SPEC (CVPixelBufferGetBaseAddress), + SYM_SPEC (CVPixelBufferGetBaseAddressOfPlane), + SYM_SPEC (CVPixelBufferGetBytesPerRow), + SYM_SPEC (CVPixelBufferGetBytesPerRowOfPlane), + SYM_SPEC (CVPixelBufferGetHeight), + SYM_SPEC (CVPixelBufferGetHeightOfPlane), + SYM_SPEC_OPTIONAL (CVPixelBufferGetIOSurface), + SYM_SPEC (CVPixelBufferGetPlaneCount), + SYM_SPEC (CVPixelBufferGetTypeID), + SYM_SPEC (CVPixelBufferIsPlanar), + SYM_SPEC (CVPixelBufferLockBaseAddress), + SYM_SPEC (CVPixelBufferRelease), + SYM_SPEC (CVPixelBufferRetain), + SYM_SPEC (CVPixelBufferUnlockBaseAddress), + + SYM_SPEC (kCVPixelBufferPixelFormatTypeKey), + SYM_SPEC (kCVPixelBufferWidthKey), + SYM_SPEC (kCVPixelBufferHeightKey), + SYM_SPEC (kCVPixelBufferBytesPerRowAlignmentKey), + SYM_SPEC (kCVPixelBufferPlaneAlignmentKey), + + {NULL, 0}, + }; + + return _gst_dyn_api_new (gst_cv_api_get_type (), CV_FRAMEWORK_PATH, symbols, + error); +} diff --git a/sys/applemedia-nonpublic/cvapi.h b/sys/applemedia-nonpublic/cvapi.h new file mode 100644 index 0000000..63c8cba --- /dev/null +++ b/sys/applemedia-nonpublic/cvapi.h @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2010 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __GST_CV_API_H__ +#define __GST_CV_API_H__ + +#include "dynapi.h" + +#include + +G_BEGIN_DECLS + +typedef struct _GstCVApi GstCVApi; +typedef struct _GstCVApiClass GstCVApiClass; + +typedef int32_t CVReturn; + +typedef uint64_t CVOptionFlags; + +typedef struct _CVBuffer * CVBufferRef; +typedef CVBufferRef CVImageBufferRef; +typedef CVImageBufferRef CVPixelBufferRef; + +typedef void (* CVPixelBufferReleaseBytesCallback) (void * releaseRefCon, + const void * baseAddress); + +enum _CVReturn +{ + kCVReturnSuccess = 0 +}; + +enum _CVPixelFormatType +{ + kCVPixelFormatType_420YpCbCr8Planar = 'y420', + kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange = '420v', + kCVPixelFormatType_422YpCbCr8Deprecated = 'yuvs', + kCVPixelFormatType_422YpCbCr8 = '2vuy' +}; + +enum _CVPixelBufferLockFlags +{ + kCVPixelBufferLock_ReadOnly = 0x00000001 +}; + +struct _GstCVApi +{ + GstDynApi parent; + + void (* CVBufferRelease) (CVBufferRef buffer); + CVBufferRef (* CVBufferRetain) (CVBufferRef buffer); + + CVReturn (* CVPixelBufferCreateWithBytes) + (CFAllocatorRef allocator, size_t width, size_t height, + OSType pixelFormatType, void * baseAddress, size_t bytesPerRow, + CVPixelBufferReleaseBytesCallback releaseCallback, + void * releaseRefCon, CFDictionaryRef pixelBufferAttributes, + CVPixelBufferRef * pixelBufferOut); + CVReturn (* CVPixelBufferCreateWithPlanarBytes) + (CFAllocatorRef allocator, size_t width, size_t height, + OSType pixelFormatType, void * dataPtr, size_t dataSize, + size_t numberOfPlanes, void *planeBaseAddress[], + size_t planeWidth[], size_t planeHeight[], + size_t planeBytesPerRow[], + CVPixelBufferReleaseBytesCallback releaseCallback, + void * releaseRefCon, CFDictionaryRef pixelBufferAttributes, + CVPixelBufferRef * pixelBufferOut); + void * (* CVPixelBufferGetBaseAddress) + (CVPixelBufferRef pixelBuffer); + void * (* CVPixelBufferGetBaseAddressOfPlane) + (CVPixelBufferRef pixelBuffer, size_t planeIndex); + size_t (* CVPixelBufferGetBytesPerRow) + (CVPixelBufferRef pixelBuffer); + size_t (* CVPixelBufferGetBytesPerRowOfPlane) + (CVPixelBufferRef pixelBuffer, size_t planeIndex); + size_t (* CVPixelBufferGetHeight) (CVPixelBufferRef pixelBuffer); + size_t (* CVPixelBufferGetHeightOfPlane) + (CVPixelBufferRef pixelBuffer, size_t planeIndex); + void * (* CVPixelBufferGetIOSurface) + (CVPixelBufferRef pixelBuffer); + size_t (* CVPixelBufferGetPlaneCount) + (CVPixelBufferRef pixelBuffer); + CFTypeID (* CVPixelBufferGetTypeID) (void); + Boolean (* CVPixelBufferIsPlanar) (CVPixelBufferRef pixelBuffer); + CVReturn (* CVPixelBufferLockBaseAddress) + (CVPixelBufferRef pixelBuffer, CVOptionFlags lockFlags); + void (* CVPixelBufferRelease) (CVPixelBufferRef pixelBuffer); + CVPixelBufferRef (* CVPixelBufferRetain) + (CVPixelBufferRef pixelBuffer); + CVReturn (* CVPixelBufferUnlockBaseAddress) + (CVPixelBufferRef pixelBuffer, CVOptionFlags unlockFlags); + + CFStringRef * kCVPixelBufferPixelFormatTypeKey; + CFStringRef * kCVPixelBufferWidthKey; + CFStringRef * kCVPixelBufferHeightKey; + CFStringRef * kCVPixelBufferBytesPerRowAlignmentKey; + CFStringRef * kCVPixelBufferPlaneAlignmentKey; +}; + +struct _GstCVApiClass +{ + GstDynApiClass parent_class; +}; + +GType gst_cv_api_get_type (void); + +GstCVApi * gst_cv_api_obtain (GError ** error); + +G_END_DECLS + +#endif diff --git a/sys/applemedia-nonpublic/dynapi-internal.h b/sys/applemedia-nonpublic/dynapi-internal.h new file mode 100644 index 0000000..adcd4f1 --- /dev/null +++ b/sys/applemedia-nonpublic/dynapi-internal.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2010 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __GST_DYN_API_INTERNAL_H__ +#define __GST_DYN_API_INTERNAL_H__ + +#include + +G_BEGIN_DECLS + +typedef struct _GstDynSymSpec GstDynSymSpec; + +struct _GstDynSymSpec +{ + const gchar * name; + guint offset; + gboolean is_required; +}; + +gpointer _gst_dyn_api_new (GType derived_type, const gchar * filename, + const GstDynSymSpec * symbols, GError ** error); + +G_END_DECLS + +#endif + diff --git a/sys/applemedia-nonpublic/dynapi.c b/sys/applemedia-nonpublic/dynapi.c new file mode 100644 index 0000000..2317f80 --- /dev/null +++ b/sys/applemedia-nonpublic/dynapi.c @@ -0,0 +1,193 @@ +/* + * Copyright (C) 2010 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "dynapi.h" + +#include "dynapi-internal.h" + +#include +#include + +GST_DEBUG_CATEGORY (gst_dyn_api_debug); +#define GST_CAT_DEFAULT gst_dyn_api_debug + +enum +{ + PROP_0, + PROP_FILENAME +}; + +struct _GstDynApiPrivate +{ + gchar *filename; + GModule *module; +}; + +G_DEFINE_TYPE (GstDynApi, gst_dyn_api, G_TYPE_OBJECT); + +static void +gst_dyn_api_init (GstDynApi * self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GST_TYPE_DYN_API, + GstDynApiPrivate); +} + +static void +gst_dyn_api_dispose (GObject * object) +{ + GstDynApi *self = GST_DYN_API_CAST (object); + GstDynApiPrivate *priv = self->priv; + + if (priv->module != NULL) { + g_module_close (priv->module); + priv->module = NULL; + } + + G_OBJECT_CLASS (gst_dyn_api_parent_class)->dispose (object); +} + +static void +gst_dyn_api_finalize (GObject * object) +{ + GstDynApi *self = GST_DYN_API_CAST (object); + GstDynApiPrivate *priv = self->priv; + + g_free (priv->filename); + + G_OBJECT_CLASS (gst_dyn_api_parent_class)->finalize (object); +} + +static void +gst_dyn_api_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + GstDynApi *self = GST_DYN_API (object); + + switch (prop_id) { + case PROP_FILENAME: + g_value_set_string (value, self->priv->filename); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_dyn_api_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GstDynApi *self = GST_DYN_API (object); + + switch (prop_id) { + case PROP_FILENAME: + g_free (self->priv->filename); + self->priv->filename = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_dyn_api_class_init (GstDynApiClass * klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->dispose = gst_dyn_api_dispose; + gobject_class->finalize = gst_dyn_api_finalize; + gobject_class->get_property = gst_dyn_api_get_property; + gobject_class->set_property = gst_dyn_api_set_property; + + g_type_class_add_private (klass, sizeof (GstDynApiPrivate)); + + g_object_class_install_property (gobject_class, PROP_FILENAME, + g_param_spec_string ("filename", "Filename", "Filename", NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); +} + +gpointer +_gst_dyn_api_new (GType derived_type, const gchar * filename, + const GstDynSymSpec * symbols, GError ** error) +{ + GstDynApi *api; + GstDynApiPrivate *priv; + guint i; + GArray *names_not_found; + + api = g_object_new (derived_type, "filename", filename, NULL); + priv = api->priv; + + priv->module = g_module_open (priv->filename, 0); + if (priv->module == NULL) + goto open_failed; + + names_not_found = g_array_new (TRUE, FALSE, sizeof (gchar *)); + + for (i = 0; symbols[i].name != NULL; i++) { + const GstDynSymSpec *s = &symbols[i]; + if (!g_module_symbol (priv->module, s->name, + (gpointer *) (((guint8 *) api) + s->offset)) && s->is_required) { + g_array_append_val (names_not_found, s->name); + } + } + + if (names_not_found->len > 0) + goto one_or_more_name_not_found; + + g_array_free (names_not_found, TRUE); + + return api; + + /* ERRORS */ +open_failed: + { + gchar *basename; + + basename = g_path_get_basename (filename); + g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED, + "failed to open %s", basename); + g_free (basename); + + goto any_error; + } +one_or_more_name_not_found: + { + gchar *basename, *names_joined; + + basename = g_path_get_basename (filename); + names_joined = g_strjoinv (", ", (gchar **) names_not_found->data); + g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED, + "missing %u symbol%s in %s: %s", + names_not_found->len, (names_not_found->len == 1) ? "" : "s", + basename, names_joined); + g_free (names_joined); + g_free (basename); + g_array_free (names_not_found, TRUE); + + goto any_error; + } +any_error: + { + g_object_unref (api); + + return NULL; + } +} diff --git a/sys/applemedia-nonpublic/dynapi.h b/sys/applemedia-nonpublic/dynapi.h new file mode 100644 index 0000000..b8eda85 --- /dev/null +++ b/sys/applemedia-nonpublic/dynapi.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2010 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __GST_DYN_API_H__ +#define __GST_DYN_API_H__ + +#include + +G_BEGIN_DECLS + +#define GST_TYPE_DYN_API \ + (gst_dyn_api_get_type ()) +#define GST_DYN_API(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_DYN_API, GstDynApi)) +#define GST_DYN_API_CAST(obj) \ + ((GstDynApi *) (obj)) +#define GST_DYN_API_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DYN_API, GstDynApiClass)) +#define GST_IS_DYN_API(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_DYN_API)) +#define GST_IS_DYN_API_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_DYN_API)) + +#define GST_DYN_SYM_SPEC(type, name) \ + { G_STRINGIFY (name), G_STRUCT_OFFSET (type, name), TRUE } +#define GST_DYN_SYM_SPEC_OPTIONAL(type, name) \ + { G_STRINGIFY (name), G_STRUCT_OFFSET (type, name), FALSE } + +typedef struct _GstDynApi GstDynApi; +typedef struct _GstDynApiClass GstDynApiClass; +typedef struct _GstDynApiPrivate GstDynApiPrivate; + +struct _GstDynApi +{ + GObject parent; + + GstDynApiPrivate * priv; +}; + +struct _GstDynApiClass +{ + GObjectClass parent_class; +}; + +GType gst_dyn_api_get_type (void); + +G_END_DECLS + +#endif diff --git a/sys/applemedia/mioapi.c b/sys/applemedia-nonpublic/mioapi.c similarity index 100% rename from sys/applemedia/mioapi.c rename to sys/applemedia-nonpublic/mioapi.c diff --git a/sys/applemedia/mioapi.h b/sys/applemedia-nonpublic/mioapi.h similarity index 100% rename from sys/applemedia/mioapi.h rename to sys/applemedia-nonpublic/mioapi.h diff --git a/sys/applemedia/miovideodevice.c b/sys/applemedia-nonpublic/miovideodevice.c similarity index 100% rename from sys/applemedia/miovideodevice.c rename to sys/applemedia-nonpublic/miovideodevice.c diff --git a/sys/applemedia/miovideodevice.h b/sys/applemedia-nonpublic/miovideodevice.h similarity index 100% rename from sys/applemedia/miovideodevice.h rename to sys/applemedia-nonpublic/miovideodevice.h diff --git a/sys/applemedia/miovideosrc.c b/sys/applemedia-nonpublic/miovideosrc.c similarity index 100% rename from sys/applemedia/miovideosrc.c rename to sys/applemedia-nonpublic/miovideosrc.c diff --git a/sys/applemedia/miovideosrc.h b/sys/applemedia-nonpublic/miovideosrc.h similarity index 100% rename from sys/applemedia/miovideosrc.h rename to sys/applemedia-nonpublic/miovideosrc.h diff --git a/sys/applemedia-nonpublic/mtapi.c b/sys/applemedia-nonpublic/mtapi.c new file mode 100644 index 0000000..f8cd242 --- /dev/null +++ b/sys/applemedia-nonpublic/mtapi.c @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2010 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "mtapi.h" + +#include "dynapi-internal.h" + +#define MT_FRAMEWORK_PATH "/System/Library/PrivateFrameworks/" \ + "MediaToolbox.framework/MediaToolbox" + +G_DEFINE_TYPE (GstMTApi, gst_mt_api, GST_TYPE_DYN_API); + +static void +gst_mt_api_init (GstMTApi * self) +{ +} + +static void +gst_mt_api_class_init (GstMTApiClass * klass) +{ +} + +#define SYM_SPEC(name) GST_DYN_SYM_SPEC (GstMTApi, name) + +GstMTApi * +gst_mt_api_obtain (GError ** error) +{ + static const GstDynSymSpec symbols[] = { + SYM_SPEC (FigCaptureDeviceGetFigBaseObject), + SYM_SPEC (FigCaptureStreamGetFigBaseObject), + + SYM_SPEC (kFigCaptureDeviceProperty_Clock), + SYM_SPEC (kFigCaptureDeviceProperty_StreamArray), + SYM_SPEC (kFigCaptureStreamProperty_AudioLevelArray), + SYM_SPEC (kFigCaptureStreamProperty_AudioLevelMeteringEnable), + SYM_SPEC (kFigCaptureStreamProperty_AudioLevelUnits), + SYM_SPEC (kFigCaptureStreamProperty_AutoAENow), + SYM_SPEC (kFigCaptureStreamProperty_AutoFocusNow), + SYM_SPEC (kFigCaptureStreamProperty_BufferAllocator), + SYM_SPEC (kFigCaptureStreamProperty_BufferQueue), + SYM_SPEC (kFigCaptureStreamProperty_FixedFrameRate), + SYM_SPEC (kFigCaptureStreamProperty_FormatDescription), + SYM_SPEC (kFigCaptureStreamProperty_FormatIndex), + SYM_SPEC (kFigCaptureStreamProperty_FrameDuration), + SYM_SPEC (kFigCaptureStreamProperty_MaximumFrameRate), + SYM_SPEC (kFigCaptureStreamProperty_MinimumFrameRate), + SYM_SPEC (kFigCaptureStreamProperty_NeedSampleBufferDurations), + SYM_SPEC (kFigCaptureStreamProperty_StillImageBufferQueue), + SYM_SPEC (kFigCaptureStreamProperty_StillImageCaptureNow), + SYM_SPEC (kFigCaptureStreamProperty_SupportedFormatsArray), + SYM_SPEC (kFigSupportedFormat_AudioMaxSampleRate), + SYM_SPEC (kFigSupportedFormat_AudioMinSampleRate), + SYM_SPEC (kFigSupportedFormat_FormatDescription), + SYM_SPEC (kFigSupportedFormat_VideoIsBinned), + SYM_SPEC (kFigSupportedFormat_VideoMaxFrameRate), + SYM_SPEC (kFigSupportedFormat_VideoMinFrameRate), + SYM_SPEC (kFigSupportedFormat_VideoScaleFactor), + + {NULL, 0}, + }; + + return _gst_dyn_api_new (gst_mt_api_get_type (), MT_FRAMEWORK_PATH, symbols, + error); +} diff --git a/sys/applemedia-nonpublic/mtapi.h b/sys/applemedia-nonpublic/mtapi.h new file mode 100644 index 0000000..91d90e9 --- /dev/null +++ b/sys/applemedia-nonpublic/mtapi.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2010 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __GST_MT_API_H__ +#define __GST_MT_API_H__ + +#include "cmapi.h" + +G_BEGIN_DECLS + +typedef struct _GstMTApi GstMTApi; +typedef struct _GstMTApiClass GstMTApiClass; + +typedef struct _FigCaptureDevice * FigCaptureDeviceRef; +typedef struct _FigCaptureStream * FigCaptureStreamRef; +typedef struct _FigCaptureDeviceIface FigCaptureDeviceIface; +typedef struct _FigCaptureStreamIface FigCaptureStreamIface; + +struct _FigCaptureDeviceIface +{ + gsize unk; + OSStatus (* Func1) (FigCaptureDeviceRef stream); +}; + +struct _FigCaptureStreamIface +{ + gsize unk; + OSStatus (* Start) (FigCaptureStreamRef stream); + OSStatus (* Stop) (FigCaptureStreamRef stream); +}; + +struct _GstMTApi +{ + GstDynApi parent; + + FigBaseObjectRef (* FigCaptureDeviceGetFigBaseObject) + (FigCaptureDeviceRef device); + FigBaseObjectRef (* FigCaptureStreamGetFigBaseObject) + (FigCaptureStreamRef stream); + + CFStringRef * kFigCaptureDeviceProperty_Clock; + CFStringRef * kFigCaptureDeviceProperty_StreamArray; + CFStringRef * kFigCaptureStreamProperty_AudioLevelArray; + CFStringRef * kFigCaptureStreamProperty_AudioLevelMeteringEnable; + CFStringRef * kFigCaptureStreamProperty_AudioLevelUnits; + CFStringRef * kFigCaptureStreamProperty_AutoAENow; + CFStringRef * kFigCaptureStreamProperty_AutoFocusNow; + CFStringRef * kFigCaptureStreamProperty_BufferAllocator; + CFStringRef * kFigCaptureStreamProperty_BufferQueue; + CFStringRef * kFigCaptureStreamProperty_FixedFrameRate; + CFStringRef * kFigCaptureStreamProperty_FormatDescription; + CFStringRef * kFigCaptureStreamProperty_FormatIndex; + CFStringRef * kFigCaptureStreamProperty_FrameDuration; + CFStringRef * kFigCaptureStreamProperty_MaximumFrameRate; + CFStringRef * kFigCaptureStreamProperty_MinimumFrameRate; + CFStringRef * kFigCaptureStreamProperty_NeedSampleBufferDurations; + CFStringRef * kFigCaptureStreamProperty_StillImageBufferQueue; + CFStringRef * kFigCaptureStreamProperty_StillImageCaptureNow; + CFStringRef * kFigCaptureStreamProperty_SupportedFormatsArray; + CFStringRef * kFigSupportedFormat_AudioMaxSampleRate; + CFStringRef * kFigSupportedFormat_AudioMinSampleRate; + CFStringRef * kFigSupportedFormat_FormatDescription; + CFStringRef * kFigSupportedFormat_VideoIsBinned; + CFStringRef * kFigSupportedFormat_VideoMaxFrameRate; + CFStringRef * kFigSupportedFormat_VideoMinFrameRate; + CFStringRef * kFigSupportedFormat_VideoScaleFactor; +}; + +struct _GstMTApiClass +{ + GstDynApiClass parent_class; +}; + +GType gst_mt_api_get_type (void); + +GstMTApi * gst_mt_api_obtain (GError ** error); + +G_END_DECLS + +#endif diff --git a/sys/applemedia-nonpublic/plugin.m b/sys/applemedia-nonpublic/plugin.m new file mode 100644 index 0000000..5ece9a5 --- /dev/null +++ b/sys/applemedia-nonpublic/plugin.m @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2009-2010 Ole André Vadla Ravnås + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifdef HAVE_IOS +#include "celvideosrc.h" +#else +#include "miovideosrc.h" +#include +#endif + +#ifndef HAVE_IOS +static void +enable_mt_mode (void) +{ + NSThread * th = [[NSThread alloc] init]; + [th start]; + [th release]; + g_assert ([NSThread isMultiThreaded]); +} +#endif + +static gboolean +plugin_init (GstPlugin * plugin) +{ + gboolean res = TRUE; + +#ifdef HAVE_IOS + res &= gst_element_register (plugin, "celvideosrc", GST_RANK_NONE, + GST_TYPE_CEL_VIDEO_SRC); +#else + enable_mt_mode (); + +#if 0 + res &= gst_element_register (plugin, "miovideosrc", GST_RANK_NONE, + GST_TYPE_MIO_VIDEO_SRC); +#endif +#endif + + return res; +} + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + applemedia, + "Elements for capture and codec access on Apple OS X and iOS using private Frameworks", + plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/") diff --git a/sys/applemedia/Makefile.am b/sys/applemedia/Makefile.am index 977a767..9975428 100644 --- a/sys/applemedia/Makefile.am +++ b/sys/applemedia/Makefile.am @@ -42,10 +42,7 @@ libgstapplemedia_la_LDFLAGS = \ noinst_HEADERS = \ qtkitvideosrc.h \ - miovideosrc.h \ - miovideodevice.h \ avfvideosrc.h \ - celvideosrc.h \ vth264decbin.h \ vth264encbin.h \ vtenc.h \ @@ -57,9 +54,6 @@ noinst_HEADERS = \ coremediactx.h \ cvapi.h \ cmapi.h \ - mioapi.h \ - mtapi.h \ - celapi.h \ vtapi.h \ dynapi.h \ dynapi-internal.h @@ -67,10 +61,7 @@ noinst_HEADERS = \ if HAVE_IOS libgstapplemedia_la_SOURCES += \ - avfvideosrc.m \ - celvideosrc.c \ - mtapi.c \ - celapi.c + avfvideosrc.m libgstapplemedia_la_LDFLAGS += \ -Wl,-framework -Wl,CoreMedia \ @@ -82,8 +73,7 @@ else libgstapplemedia_la_SOURCES += \ qtkitvideosrc.m \ vtenc.c \ - vtdec.c \ - mioapi.c + vtdec.c libgstapplemedia_la_LDFLAGS += \ -Wl,-framework -Wl,Cocoa \ diff --git a/sys/applemedia/coremediactx.c b/sys/applemedia/coremediactx.c index 804a2f3..55e7119 100644 --- a/sys/applemedia/coremediactx.c +++ b/sys/applemedia/coremediactx.c @@ -44,12 +44,6 @@ static const GstApiProvider api_provider[] = { API_PROVIDER (CORE_VIDEO, cv), API_PROVIDER (CORE_MEDIA, cm), API_PROVIDER (VIDEO_TOOLBOX, vt), -#ifdef HAVE_IOS - API_PROVIDER (MEDIA_TOOLBOX, mt), - API_PROVIDER (CELESTIAL, cel) -#else - API_PROVIDER (MIO, mio), -#endif }; G_DEFINE_TYPE (GstCoreMediaCtx, gst_core_media_ctx, G_TYPE_OBJECT); diff --git a/sys/applemedia/coremediactx.h b/sys/applemedia/coremediactx.h index f058bef..45fcf30 100644 --- a/sys/applemedia/coremediactx.h +++ b/sys/applemedia/coremediactx.h @@ -24,11 +24,6 @@ #include "cmapi.h" #include "vtapi.h" -#include "mioapi.h" - -#include "mtapi.h" -#include "celapi.h" - #include G_BEGIN_DECLS @@ -59,13 +54,6 @@ struct _GstCoreMediaCtx GstCVApi *cv; GstCMApi *cm; GstVTApi *vt; - - /* OS X */ - GstMIOApi *mio; - - /* iPhone */ - GstMTApi *mt; - GstCelApi *cel; }; struct _GstCoreMediaCtxClass @@ -78,11 +66,6 @@ enum _GstCoreMediaApi GST_API_CORE_VIDEO = (1 << 0), GST_API_CORE_MEDIA = (1 << 1), GST_API_VIDEO_TOOLBOX = (1 << 2), - - GST_API_MIO = (1 << 3), - - GST_API_MEDIA_TOOLBOX = (1 << 4), - GST_API_CELESTIAL = (1 << 5) }; GType gst_core_media_ctx_get_type (void); diff --git a/sys/applemedia/plugin.m b/sys/applemedia/plugin.m index 5b0d52d..da98244 100644 --- a/sys/applemedia/plugin.m +++ b/sys/applemedia/plugin.m @@ -23,10 +23,8 @@ #ifdef HAVE_IOS #include "avfvideosrc.h" -#include "celvideosrc.h" #else #include "qtkitvideosrc.h" -#include "miovideosrc.h" #include #endif #include "vth264decbin.h" @@ -53,17 +51,11 @@ plugin_init (GstPlugin * plugin) #ifdef HAVE_IOS res = gst_element_register (plugin, "avfvideosrc", GST_RANK_NONE, GST_TYPE_AVF_VIDEO_SRC); - res &= gst_element_register (plugin, "celvideosrc", GST_RANK_NONE, - GST_TYPE_CEL_VIDEO_SRC); #else enable_mt_mode (); res = gst_element_register (plugin, "qtkitvideosrc", GST_RANK_PRIMARY, GST_TYPE_QTKIT_VIDEO_SRC); -#if 0 - res &= gst_element_register (plugin, "miovideosrc", GST_RANK_NONE, - GST_TYPE_MIO_VIDEO_SRC); -#endif #endif #if 0 -- 2.7.4