From: Luca Barbato <[email protected]>
Just to test the build system changes, try to leverage ARC.
---
configure | 7 +++
libavdevice/Makefile | 1 +
libavdevice/alldevices.c | 1 +
libavdevice/avfoundation_dec.m | 104 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 113 insertions(+)
create mode 100644 libavdevice/avfoundation_dec.m
diff --git a/configure b/configure
index 1aaf9ef..7bdc523 100755
--- a/configure
+++ b/configure
@@ -1453,6 +1453,7 @@ HAVE_LIST_PUB="
"
HEADERS_LIST="
+ AVFoundation_AVFoundation_h
alsa_asoundlib_h
altivec_h
arpa_inet_h
@@ -2264,6 +2265,7 @@ xwma_demuxer_select="riffdec"
# indevs / outdevs
alsa_indev_deps="alsa_asoundlib_h snd_pcm_htimestamp"
alsa_outdev_deps="alsa_asoundlib_h"
+avfoundation_indev_deps="AVFoundation_AVFoundation_h"
bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h
dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
dv1394_indev_deps="dv1394"
dv1394_indev_select="dv_demuxer"
@@ -4557,6 +4559,11 @@ check_header linux/fb.h
check_header linux/videodev2.h
check_struct linux/videodev2.h "struct v4l2_frmivalenum" discrete
+check_header AVFoundation/AVFoundation.h &&
+ check_objcflags -fobjc-arc &&
+ add_extralibs -framework Foundation -framework AVFoundation || \
+ disable AVFoundation_AVFoundation_h
+
check_header sys/videoio.h
check_func_headers "windows.h vfw.h" capCreateCaptureWindow
"$vfwcap_indev_extralibs"
diff --git a/libavdevice/Makefile b/libavdevice/Makefile
index dfd56be..40c5260 100644
--- a/libavdevice/Makefile
+++ b/libavdevice/Makefile
@@ -9,6 +9,7 @@ OBJS = alldevices.o
\
# input/output devices
OBJS-$(CONFIG_ALSA_INDEV) += alsa_dec.o alsa.o
OBJS-$(CONFIG_ALSA_OUTDEV) += alsa_enc.o alsa.o
+OBJS-$(CONFIG_AVFOUNDATION_INDEV) += avfoundation_dec.o
OBJS-$(CONFIG_BKTR_INDEV) += bktr.o
OBJS-$(CONFIG_DV1394_INDEV) += dv1394.o
OBJS-$(CONFIG_FBDEV_INDEV) += fbdev.o
diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index 5dbe277..8439b5b 100644
--- a/libavdevice/alldevices.c
+++ b/libavdevice/alldevices.c
@@ -48,6 +48,7 @@ void avdevice_register_all(void)
/* devices */
REGISTER_INOUTDEV(ALSA, alsa);
+ REGISTER_INDEV (AVFOUNDATION, avfoundation);
REGISTER_INDEV (BKTR, bktr);
REGISTER_INDEV (DV1394, dv1394);
REGISTER_INDEV (FBDEV, fbdev);
diff --git a/libavdevice/avfoundation_dec.m b/libavdevice/avfoundation_dec.m
new file mode 100644
index 0000000..5e5f0fa
--- /dev/null
+++ b/libavdevice/avfoundation_dec.m
@@ -0,0 +1,104 @@
+/*
+ * AVFoundation input device
+ * Copyright (c) 2015 Luca Barbato
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#import <AVFoundation/AVFoundation.h>
+
+#include "libavformat/avformat.h"
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
+
+#include "avdevice.h"
+
+
+typedef struct AVFoundationCaptureContext {
+ AVClass *class;
+ int list_devices;
+} AVFoundationCaptureContext;
+
+#define AUDIO_DEVICES 1
+#define VIDEO_DEVICES 2
+#define ALL_DEVICES AUDIO_DEVICES|VIDEO_DEVICES
+
+#define OFFSET(x) offsetof(AVFoundationCaptureContext, x)
+#define DEC AV_OPT_FLAG_DECODING_PARAM
+static const AVOption options[] = {
+ { "list_devices", "List available devices and exit", OFFSET(list_devices),
AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, DEC, "list_devices" },
+ { "all", "Show all the supported devices", OFFSET(list_devices),
AV_OPT_TYPE_CONST, {.i64 = ALL_DEVICES }, 0, INT_MAX, DEC, "list_devices" },
+ { "audio", "Show only the audio devices", OFFSET(list_devices),
AV_OPT_TYPE_CONST, {.i64 = AUDIO_DEVICES }, 0, INT_MAX, DEC, "list_devices" },
+ { "video", "Show only the video devices", OFFSET(list_devices),
AV_OPT_TYPE_CONST, {.i64 = VIDEO_DEVICES }, 0, INT_MAX, DEC, "list_devices" },
+ { NULL },
+};
+
+
+static void list_capture_devices_by_type(AVFormatContext *s, NSString *type)
+{
+ NSArray *devices = [AVCaptureDevice devicesWithMediaType:type];
+
+ av_log(s, AV_LOG_INFO, "Type: %s\n", [type UTF8String]);
+ for (AVCaptureDevice *device in devices) {
+
+ av_log(s, AV_LOG_INFO, "uniqueID: %s\nname: %s\nformat:\n",
+ [[device uniqueID] UTF8String],
+ [[device localizedName] UTF8String]);
+
+ for (AVCaptureDeviceFormat *format in device.formats)
+ av_log(s, AV_LOG_INFO, "\t%s\n",
+ [[NSString stringWithFormat:@"%@", format] UTF8String]);
+ }
+}
+
+static int avfoundation_list_capture_devices(AVFormatContext *s)
+{
+ AVFoundationCaptureContext *ctx = s->priv_data;
+
+ if (ctx->list_devices & AUDIO_DEVICES)
+ list_capture_devices_by_type(s, AVMediaTypeAudio);
+
+ if (ctx->list_devices & VIDEO_DEVICES)
+ list_capture_devices_by_type(s, AVMediaTypeVideo);
+
+ return AVERROR_EXIT;
+}
+
+
+
+static int avfoundation_read_header(AVFormatContext *s)
+{
+ return avfoundation_list_capture_devices(s);
+}
+
+static const AVClass avfoundation_class = {
+ .class_name = "AVFoundation AVCaptureDevice indev",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+AVInputFormat ff_avfoundation_demuxer = {
+ .name = "avfoundation",
+ .long_name = NULL_IF_CONFIG_SMALL("AVFoundation AVCaptureDevice
grab"),
+ .priv_data_size = sizeof(AVFoundationCaptureContext),
+ .read_header = avfoundation_read_header,
+// .read_packet = avfoundation_read_packet,
+// .read_close = avfoundation_read_close,
+ .flags = AVFMT_NOFILE,
+ .priv_class = &avfoundation_class,
+};
--
2.6.2
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel