[vlc-commits] chroma converter: add CVPixelBuffer to I420 converter

Felix Paul Kühne git at videolan.org
Fri Aug 21 19:10:33 CEST 2015


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Fri Aug 21 18:06:12 2015 +0200| [935211ca0996f3ac4f49462c73798942a721bc3d] | committer: Felix Paul Kühne

chroma converter: add CVPixelBuffer to I420 converter

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=935211ca0996f3ac4f49462c73798942a721bc3d
---

 modules/video_chroma/Makefile.am |    5 ++
 modules/video_chroma/cvpx_i420.c |   96 ++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in                   |    1 +
 3 files changed, 102 insertions(+)

diff --git a/modules/video_chroma/Makefile.am b/modules/video_chroma/Makefile.am
index ae8af04..9c7831b 100644
--- a/modules/video_chroma/Makefile.am
+++ b/modules/video_chroma/Makefile.am
@@ -116,3 +116,8 @@ chroma_LTLIBRARIES += \
 	libd3d11_surface_plugin.la
 endif
 
+if HAVE_DARWIN
+libcvpx_i420_plugin_la_SOURCES = video_chroma/cvpx_i420.c video_chroma/copy.c video_chroma/copy.h
+libcvpx_i420_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(chromadir)' -Wl,-framework,Foundation -Wl,-framework,VideoToolbox -Wl,-framework,CoreMedia -Wl,-framework,CoreVideo
+chroma_LTLIBRARIES += libcvpx_i420_plugin.la
+endif
diff --git a/modules/video_chroma/cvpx_i420.c b/modules/video_chroma/cvpx_i420.c
new file mode 100644
index 0000000..18ed3cf
--- /dev/null
+++ b/modules/video_chroma/cvpx_i420.c
@@ -0,0 +1,96 @@
+/*****************************************************************************
+ * cvpx_i420.c: core video buffer to picture converter
+ *****************************************************************************
+ * Copyright (C) 2015 Videolabs SAS
+ * $Id$
+ *
+ * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
+ *
+ * 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>
+#include <VideoToolbox/VideoToolbox.h>
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_filter.h>
+#include "copy.h"
+
+struct picture_sys_t {
+    CVPixelBufferRef pixelBuffer;
+};
+
+static int  Activate(vlc_object_t * );
+static void CVPX_I420(filter_t *, picture_t *, picture_t *);
+static picture_t *CVPX_I420_Filter( filter_t *, picture_t * );
+
+vlc_module_begin ()
+set_description( N_("Conversions from CoreVideo buffers to I420") )
+set_capability( "video filter2", 10 )
+set_callbacks( Activate, NULL )
+vlc_module_end ()
+
+static int Activate(vlc_object_t *obj)
+{
+    filter_t *p_filter = (filter_t *)obj;
+    if (p_filter->fmt_in.video.i_chroma != VLC_CODEC_CVPX_OPAQUE)
+        return VLC_EGENERIC;
+
+    if (p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height
+        || p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width)
+        return VLC_EGENERIC;
+
+    if (p_filter->fmt_out.video.i_chroma != VLC_CODEC_I420)
+        return VLC_EGENERIC;
+
+    p_filter->pf_video_filter = CVPX_I420_Filter;
+
+    return VLC_SUCCESS;
+}
+
+VIDEO_FILTER_WRAPPER( CVPX_I420 )
+
+static void CVPX_I420(filter_t *p_filter, picture_t *sourcePicture, picture_t *destinationPicture)
+{
+    VLC_UNUSED(p_filter);
+    picture_sys_t *picsys = sourcePicture->p_sys;
+
+    if (picsys == NULL)
+        return;
+
+    if (picsys->pixelBuffer == nil)
+        return;
+
+    uint8_t *pp_plane[2];
+    size_t pi_pitch[2];
+
+    CVPixelBufferLockBaseAddress(picsys->pixelBuffer, 0);
+
+    for (int i = 0; i < 2; i++) {
+        pp_plane[i] = CVPixelBufferGetBaseAddressOfPlane(picsys->pixelBuffer, i);
+        pi_pitch[i] = CVPixelBufferGetBytesPerRowOfPlane(picsys->pixelBuffer, i);
+    }
+
+    CopyFromNv12ToI420(destinationPicture, pp_plane, pi_pitch,
+                       sourcePicture->format.i_width,
+                       sourcePicture->format.i_height);
+
+    CVPixelBufferUnlockBaseAddress(picsys->pixelBuffer, 0);
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3b6ea6c..7d8b26b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1068,6 +1068,7 @@ modules/text_renderer/svg.c
 modules/text_renderer/tdummy.c
 modules/text_renderer/win32text.c
 modules/video_chroma/chain.c
+modules/video_chroma/cvpx_i420.c
 modules/video_chroma/d3d11_surface.c
 modules/video_chroma/dxa9.c
 modules/video_chroma/grey_yuv.c



More information about the vlc-commits mailing list