[vlc-devel] [PATCH 2/3] video-chroma: add cvpx to cvpx converter

Victorien Le Couviour--Tuffet victorien.lecouviour.tuffet at gmail.com
Thu Jul 13 13:21:26 CEST 2017


---
 configure.ac                     |   1 +
 modules/video_chroma/Makefile.am |   6 ++
 modules/video_chroma/cvpx_cvpx.c | 123 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+)
 create mode 100644 modules/video_chroma/cvpx_cvpx.c

diff --git a/configure.ac b/configure.ac
index 10fba59b04..a84986f189 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3910,6 +3910,7 @@ dnl  VideoToolbox plugins
 AC_CHECK_HEADERS(VideoToolbox/VideoToolbox.h, [
     VLC_ADD_PLUGIN([videotoolbox])
     VLC_ADD_PLUGIN([cvpx_i420])
+    VLC_ADD_PLUGIN([cvpx_cvpx])
   ])
 
 dnl
diff --git a/modules/video_chroma/Makefile.am b/modules/video_chroma/Makefile.am
index c437423a68..b85c0a5e8d 100644
--- a/modules/video_chroma/Makefile.am
+++ b/modules/video_chroma/Makefile.am
@@ -137,3 +137,9 @@ libcvpx_i420_plugin_la_SOURCES = video_chroma/cvpx_i420.c \
 libcvpx_i420_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(chromadir)' -Wl,-framework,Foundation -Wl,-framework,VideoToolbox -Wl,-framework,CoreMedia -Wl,-framework,CoreVideo
 EXTRA_LTLIBRARIES += libcvpx_i420_plugin.la
 chroma_LTLIBRARIES += $(LTLIBcvpx_i420)
+
+libcvpx_cvpx_plugin_la_SOURCES = video_chroma/cvpx_cvpx.c \
+	codec/vt_utils.c codec/vt_utils.h
+libcvpx_cvpx_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(chromadir)' -Wl,-framework,Foundation -Wl,-framework,VideoToolbox -Wl,-framework,CoreMedia -Wl,-framework,CoreVideo
+EXTRA_LTLIBRARIES += libcvpx_cvpx_plugin.la
+chroma_LTLIBRARIES += $(LTLIBcvpx_cvpx)
diff --git a/modules/video_chroma/cvpx_cvpx.c b/modules/video_chroma/cvpx_cvpx.c
new file mode 100644
index 0000000000..f048469507
--- /dev/null
+++ b/modules/video_chroma/cvpx_cvpx.c
@@ -0,0 +1,123 @@
+/*****************************************************************************
+ * cvpx_cvpx.c: core video buffer to picture converter
+ *****************************************************************************
+ * Copyright (C) 2015-2017 VLC authors, VideoLAN and VideoLabs
+ *
+ * Authors: Victorien Le Couviour--Tuffet <victorien.lecouiour.tuffet at gmail.com>
+ *          Thomas Guillem <thomas at gllm.fr>
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include <QuartzCore/QuartzCore.h>
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_filter.h>
+#include <vlc_picture.h>
+#include <vlc_modules.h>
+#include "../codec/vt_utils.h"
+
+struct filter_sys_t
+{
+    VTPixelTransferSessionRef vttransfer;
+};
+
+static vlc_fourcc_t const supported_chromas[] = { VLC_CODEC_CVPX_BGRA,
+                                                  VLC_CODEC_CVPX_I420,
+                                                  VLC_CODEC_CVPX_NV12,
+                                                  VLC_CODEC_CVPX_UYVY };
+
+static picture_t *
+Filter(filter_t *filter, picture_t *src)
+{
+    CVPixelBufferRef src_cvpx = cvpxpic_get_ref(src);
+    assert(src_cvpx);
+
+    picture_t *dst = filter_NewPicture(filter);
+    if (!dst)
+    {
+        picture_Release(src);
+        return NULL;
+    }
+
+    CVPixelBufferRef dst_cvpx = cvpxpic_get_ref(dst);
+    assert(dst_cvpx);
+
+    if (VTPixelTransferSessionTransferImage(filter->p_sys->vttransfer,
+                                            src_cvpx, dst_cvpx) != noErr)
+    {
+        picture_Release(dst);
+        picture_Release(src);
+        return NULL;
+    }
+
+    picture_CopyProperties(dst, src);
+    picture_Release(src);
+    return dst;
+}
+
+static int
+Open(vlc_object_t *obj)
+{
+    filter_t *filter = (filter_t *)obj;
+
+    unsigned int i;
+#define CHECK_CHROMA(fourcc) \
+    i = 0; \
+    while (i < ARRAY_SIZE(supported_chromas) && \
+           fourcc != supported_chromas[i]) \
+        ++i; \
+    if (i == ARRAY_SIZE(supported_chromas)) \
+        return VLC_EGENERIC; \
+
+    CHECK_CHROMA(filter->fmt_in.video.i_chroma)
+    CHECK_CHROMA(filter->fmt_out.video.i_chroma)
+
+    filter->p_sys = calloc(1, sizeof(filter_sys_t));
+    if (!filter->p_sys)
+        return VLC_ENOMEM;
+
+    if (VTPixelTransferSessionCreate(NULL, &filter->p_sys->vttransfer)
+        != noErr)
+    {
+        free(filter->p_sys);
+        return VLC_EGENERIC;
+    }
+
+    filter->pf_video_filter = Filter;
+
+    return VLC_SUCCESS;
+}
+
+static void
+Close(vlc_object_t *obj)
+{
+    filter_t *filter = (filter_t *)obj;
+
+    VTPixelTransferSessionInvalidate(filter->p_sys->vttransfer);
+    CFRelease(filter->p_sys->vttransfer);
+    free(filter->p_sys);
+}
+
+vlc_module_begin ()
+    set_description("Conversions between CoreVideo buffers")
+    set_capability("video converter", 10)
+    set_callbacks(Open, Close)
+vlc_module_end ()
-- 
2.13.1



More information about the vlc-devel mailing list