Search
SailfishOS Open Build Service
>
Projects
>
home:sledge
:
branches:nemo:devel:hw:ti:omap4:common
>
gst-plugins-base
> 0034-New-dmabuf-helper-library.patch
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File 0034-New-dmabuf-helper-library.patch of Package gst-plugins-base
From 8de95c9d2dcb8068dd4db1146412fe9d14dd59fc Mon Sep 17 00:00:00 2001 From: Rob Clark <rob@ti.com> Date: Tue, 12 Jun 2012 20:08:02 -0500 Subject: [PATCH] New dmabuf helper library Add gst-libs/gst/dmabuf which contains helpers to attach and retrieve dmabuf handles to/from buffers. --- configure.ac | 3 + gst-libs/gst/Makefile.am | 1 + gst-libs/gst/dmabuf/Makefile.am | 21 +++ gst-libs/gst/dmabuf/dmabuf.c | 163 ++++++++++++++++++++ gst-libs/gst/dmabuf/dmabuf.h | 101 ++++++++++++ pkgconfig/Makefile.am | 3 + pkgconfig/gstreamer-dmabuf-uninstalled.pc.in | 16 ++ pkgconfig/gstreamer-dmabuf.pc.in | 16 ++ pkgconfig/gstreamer-plugins-base-uninstalled.pc.in | 4 +- pkgconfig/gstreamer-plugins-base.pc.in | 2 +- 10 files changed, 327 insertions(+), 3 deletions(-) create mode 100644 gst-libs/gst/dmabuf/Makefile.am create mode 100644 gst-libs/gst/dmabuf/dmabuf.c create mode 100644 gst-libs/gst/dmabuf/dmabuf.h create mode 100644 pkgconfig/gstreamer-dmabuf-uninstalled.pc.in create mode 100644 pkgconfig/gstreamer-dmabuf.pc.in diff --git a/configure.ac b/configure.ac index aa854ce..068ccd8 100644 --- a/configure.ac +++ b/configure.ac @@ -980,6 +980,7 @@ gst-libs/gst/tag/Makefile gst-libs/gst/pbutils/Makefile gst-libs/gst/pbutils/gstpluginsbaseversion.h gst-libs/gst/video/Makefile +gst-libs/gst/dmabuf/Makefile tools/Makefile pkgconfig/Makefile pkgconfig/gstreamer-audio.pc @@ -988,6 +989,8 @@ pkgconfig/gstreamer-app.pc pkgconfig/gstreamer-app-uninstalled.pc pkgconfig/gstreamer-cdda.pc pkgconfig/gstreamer-cdda-uninstalled.pc +pkgconfig/gstreamer-dmabuf.pc +pkgconfig/gstreamer-dmabuf-uninstalled.pc pkgconfig/gstreamer-fft.pc pkgconfig/gstreamer-fft-uninstalled.pc pkgconfig/gstreamer-floatcast.pc diff --git a/gst-libs/gst/Makefile.am b/gst-libs/gst/Makefile.am index 0984251..b4de632 100644 --- a/gst-libs/gst/Makefile.am +++ b/gst-libs/gst/Makefile.am @@ -13,6 +13,7 @@ SUBDIRS = \ sdp \ rtsp \ video \ + dmabuf \ pbutils \ audio \ riff \ diff --git a/gst-libs/gst/dmabuf/Makefile.am b/gst-libs/gst/dmabuf/Makefile.am new file mode 100644 index 0000000..8993ca4 --- /dev/null +++ b/gst-libs/gst/dmabuf/Makefile.am @@ -0,0 +1,21 @@ +lib_LTLIBRARIES = libgstdmabuf-@GST_MAJORMINOR@.la + +libgstdmabuf_@GST_MAJORMINOR@_la_SOURCES = \ + dmabuf.c +libgstdmabuf_@GST_MAJORMINOR@includedir = $(includedir)/gstreamer-@GST_MAJORMINOR@/gst/dmabuf +libgstdmabuf_@GST_MAJORMINOR@include_HEADERS = \ + dmabuf.h + +libgstdmabuf_@GST_MAJORMINOR@_la_CFLAGS = \ + $(GST_PLUGINS_BASE_CFLAGS)\ + $(GST_BASE_CFLAGS) \ + $(GST_CFLAGS) + +libgstdmabuf_@GST_MAJORMINOR@_la_LIBADD = $(GST_BASE_LIBS) \ + $(GST_LIBS) + +libgstdmabuf_@GST_MAJORMINOR@_la_LDFLAGS = \ + $(GST_LIB_LDFLAGS) \ + $(GST_ALL_LDFLAGS) \ + $(GST_LT_LDFLAGS) + diff --git a/gst-libs/gst/dmabuf/dmabuf.c b/gst-libs/gst/dmabuf/dmabuf.c new file mode 100644 index 0000000..57a3b99 --- /dev/null +++ b/gst-libs/gst/dmabuf/dmabuf.c @@ -0,0 +1,163 @@ +/* GStreamer dmabuf + * + * Copyright (c) 2012, Texas Instruments Incorporated + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/** + * SECTION:gstdmabuf + * @short_description: GStreamer dmabuf support + * + * Since: 0.10.? + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <unistd.h> + +#include "dmabuf.h" + +struct _GstDmaBuf +{ + GstMiniObject parent; + + int fd; +}; + +struct _GstDmaBufClass +{ + GstMiniObjectClass parent_class; +}; + +#define GST_DMA_BUF_QUARK gst_dma_buf_quark_get_type() +static GST_BOILERPLATE_QUARK (GstDmaBuf, gst_dma_buf_quark); + +#define DMA_BUF_QUARK dma_buf_quark_get_type() +static GST_BOILERPLATE_QUARK (DmaBuf, dma_buf_quark); + +/** + * gst_buffer_set_dma_buf: + * @buf: a #GstBuffer + * @dmabuf: (allow-none): a #GstDmaBuf, or NULL to clear a + * previously-set dmabuf + * + * Sets an dmabuf handle on a buffer. The buffer will obtain its own + * reference to the dmabuf handle, meaning this function does not take + * ownership of @dmabuf. + * + * Since: 0.10.? + */ +void +gst_buffer_set_dma_buf (GstBuffer * buf, GstDmaBuf * dmabuf) +{ + gst_buffer_set_qdata (buf, GST_DMA_BUF_QUARK, + gst_structure_id_new (GST_DMA_BUF_QUARK, + DMA_BUF_QUARK, GST_TYPE_DMA_BUF, dmabuf, NULL)); +} + +/** + * gst_buffer_get_dma_buf: + * @buf: a #GstBuffer + * + * Get the dmabuf handle that has previously been attached to a buffer + * with gst_buffer_set_dma_buf(), usually by another element + * upstream. + * + * Returns: (transfer none): the #GstDmaBuf attached to + * this buffer, or NULL. Does not return a reference to the dmabuf handle, + * caller must obtain her own ref via gst_dma_buf_ref() + * if needed. + * + * Since: 0.10.? + */ +GstDmaBuf * +gst_buffer_get_dma_buf (GstBuffer * buf) +{ + const GstStructure *s; + const GValue *val; + + s = gst_buffer_get_qdata (buf, GST_DMA_BUF_QUARK); + if (s == NULL) + return NULL; + + val = gst_structure_id_get_value (s, DMA_BUF_QUARK); + if (val == NULL) + return NULL; + + return GST_DMA_BUF (gst_value_get_mini_object (val)); +} + +static void +gst_dma_buf_finalize (GstMiniObject * mini_obj) +{ + GstDmaBuf *dmabuf = (GstDmaBuf *) mini_obj; + close (dmabuf->fd); + + /* not chaining up to GstMiniObject's finalize for now, we know it's empty */ +} + +static void +gst_dma_buf_class_init (GstDmaBufClass * klass) +{ + GST_MINI_OBJECT_CLASS (klass)->finalize = gst_dma_buf_finalize; +} + +GST_BOILERPLATE_MINI_OBJECT (GstDmaBuf, gst_dma_buf); + +/** + * gst_dma_buf_new: + * @fd: (transfer full) the dmabuf fd + * + * Creates a new dmabuf handle object, which takes ownership of the + * specified dmabuf file descriptor. When the dmabuf handle object + * is finalized, the dmabuf fd is closed. + * + * Returns: (transfer full): a new #GstDmaBuf. Unref with + * gst_dma_buf_unref() when no longer needed. + * + * Since: 0.10.? + */ +GstDmaBuf * +gst_dma_buf_new (int fd) +{ + GstDmaBuf *dmabuf; + + dmabuf = (GstDmaBuf *) gst_mini_object_new (GST_TYPE_DMA_BUF); + + dmabuf->fd = fd; + + return dmabuf; +} + +/** + * gst_dma_buf_get_fd: + * + * Returns: a the dmabuf file descriptor object; if the caller wants + * to hold on to the handle after the reference on the corresponding + * gst buffer is lost, she should probably dup() the fd. (Although + * it is probably better to hang on to the ref to the GstBuffer and + * let that hold the ref to the dmabuf fd). + * + * Since: 0.10.? + */ +int +gst_dma_buf_get_fd (GstDmaBuf * dmabuf) +{ + return dmabuf->fd; +} diff --git a/gst-libs/gst/dmabuf/dmabuf.h b/gst-libs/gst/dmabuf/dmabuf.h new file mode 100644 index 0000000..e78463f --- /dev/null +++ b/gst-libs/gst/dmabuf/dmabuf.h @@ -0,0 +1,101 @@ +/* GStreamer dmabuf + * + * Copyright (c) 2012, Texas Instruments Incorporated + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_DMA_BUF_H__ +#define __GST_DMA_BUF_H__ + +#include <gst/gst.h> + +G_BEGIN_DECLS + +/** + * GstDmaBuf: + * + * A handle to a dma-buf suitable for sharing across devices. + * + * Since: 0.10.? + */ +#define GST_TYPE_DMA_BUF \ + (gst_dma_buf_get_type ()) +#define GST_DMA_BUF(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DMA_BUF, GstDmaBuf)) +#define GST_IS_DMA_BUF(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DMA_BUF)) + +typedef struct _GstDmaBuf GstDmaBuf; +typedef struct _GstDmaBufClass GstDmaBufClass; + +/** + * gst_dma_buf_ref: + * @dmabuf: a a #GstDmaBuf. + * + * Increases the refcount by one. + * + * Returns: (transfer full): @dmabuf + * + * Since: 0.10.? + */ +#ifdef _FOOL_GTK_DOC_ +G_INLINE_FUNC GstDmaBuf * +gst_dma_buf_ref (GstDmaBuf * dmabuf); +#endif + +static inline GstDmaBuf * +gst_dma_buf_ref (GstDmaBuf * dmabuf) +{ + return (GstDmaBuf *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (dmabuf)); +} + +/** + * gst_dma_buf_unref: + * @dmabuf: (transfer full): a #GstDmaBuf. + * + * Decreases the refcount. If the refcount reaches 0, the dmabuf will be + * freed and closed. + * + * Since: 0.10.? + */ +#ifdef _FOOL_GTK_DOC_ +G_INLINE_FUNC void +gst_dma_buf_unref (GstDmaBuf * dmabuf); +#endif + +static inline void +gst_dma_buf_unref (GstDmaBuf * dmabuf) +{ + gst_mini_object_unref (GST_MINI_OBJECT_CAST (dmabuf)); +} + +GType gst_dma_buf_get_type (void); + +GstDmaBuf * gst_dma_buf_new (int fd); + +int gst_dma_buf_get_fd (GstDmaBuf * buf); + +/* attach/retrieve dmabuf from buffers */ + +void gst_buffer_set_dma_buf (GstBuffer * buf, + GstDmaBuf * dmabuf); + +GstDmaBuf * gst_buffer_get_dma_buf (GstBuffer * buf); + +G_END_DECLS + +#endif /* __GST_DMA_BUF_H__ */ diff --git a/pkgconfig/Makefile.am b/pkgconfig/Makefile.am index 8fb2529..50506fe 100644 --- a/pkgconfig/Makefile.am +++ b/pkgconfig/Makefile.am @@ -3,6 +3,7 @@ pcverfiles = \ gstreamer-audio-@GST_MAJORMINOR@.pc \ gstreamer-app-@GST_MAJORMINOR@.pc \ gstreamer-cdda-@GST_MAJORMINOR@.pc \ + gstreamer-dmabuf-@GST_MAJORMINOR@.pc \ gstreamer-fft-@GST_MAJORMINOR@.pc \ gstreamer-floatcast-@GST_MAJORMINOR@.pc \ gstreamer-interfaces-@GST_MAJORMINOR@.pc \ @@ -19,6 +20,7 @@ pcverfiles_uninstalled = \ gstreamer-audio-@GST_MAJORMINOR@-uninstalled.pc \ gstreamer-app-@GST_MAJORMINOR@-uninstalled.pc \ gstreamer-cdda-@GST_MAJORMINOR@-uninstalled.pc \ + gstreamer-dmabuf-@GST_MAJORMINOR@-uninstalled.pc \ gstreamer-fft-@GST_MAJORMINOR@-uninstalled.pc \ gstreamer-floatcast-@GST_MAJORMINOR@-uninstalled.pc \ gstreamer-interfaces-@GST_MAJORMINOR@-uninstalled.pc \ @@ -52,6 +54,7 @@ pcinfiles = \ gstreamer-audio.pc.in gstreamer-audio-uninstalled.pc.in \ gstreamer-app.pc.in gstreamer-app-uninstalled.pc.in \ gstreamer-cdda.pc.in gstreamer-cdda-uninstalled.pc.in \ + gstreamer-dmabuf.pc.in gstreamer-dmabuf-uninstalled.pc.in \ gstreamer-fft.pc.in gstreamer-fft-uninstalled.pc.in \ gstreamer-floatcast.pc.in gstreamer-floatcast-uninstalled.pc.in \ gstreamer-interfaces.pc.in gstreamer-interfaces-uninstalled.pc.in \ diff --git a/pkgconfig/gstreamer-dmabuf-uninstalled.pc.in b/pkgconfig/gstreamer-dmabuf-uninstalled.pc.in new file mode 100644 index 0000000..4d7f167 --- /dev/null +++ b/pkgconfig/gstreamer-dmabuf-uninstalled.pc.in @@ -0,0 +1,16 @@ +# the standard variables don't make sense for an uninstalled copy +prefix= +exec_prefix= +libdir= +# includedir is builddir because it is used to find gstconfig.h in places +includedir=@abs_top_builddir@/gst-libs +girdir=@abs_top_builddir@/gst-libs/gst/video +typelibdir=@abs_top_builddir@/gst-libs/gst/video + +Name: GStreamer DMA-BUF Library, Uninstalled +Description: Video base classes and helper functions, uninstalled +Version: @VERSION@ +Requires: gstreamer-@GST_MAJORMINOR@ gstreamer-base-@GST_MAJORMINOR@ +Libs: @abs_top_builddir@/gst-libs/gst/dmabuf/libgstdmabuf-@GST_MAJORMINOR@.la +Cflags: -I@abs_top_srcdir@/gst-libs -I@abs_top_builddir@/gst-libs + diff --git a/pkgconfig/gstreamer-dmabuf.pc.in b/pkgconfig/gstreamer-dmabuf.pc.in new file mode 100644 index 0000000..4849538 --- /dev/null +++ b/pkgconfig/gstreamer-dmabuf.pc.in @@ -0,0 +1,16 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@/gstreamer-@GST_MAJORMINOR@ +datarootdir=${prefix}/share +datadir=${datarootdir} +girdir=${datadir}/gir-1.0 +typelibdir=${libdir}/girepository-1.0 + +Name: GStreamer DMA-BUF Library +Description: Video base classes and helper functions +Requires: gstreamer-@GST_MAJORMINOR@ gstreamer-base-@GST_MAJORMINOR@ +Version: @VERSION@ +Libs: -L${libdir} -lgstdmabuf-@GST_MAJORMINOR@ +Cflags: -I${includedir} + diff --git a/pkgconfig/gstreamer-plugins-base-uninstalled.pc.in b/pkgconfig/gstreamer-plugins-base-uninstalled.pc.in index 8a9bea2..b9efabe 100644 --- a/pkgconfig/gstreamer-plugins-base-uninstalled.pc.in +++ b/pkgconfig/gstreamer-plugins-base-uninstalled.pc.in @@ -10,7 +10,7 @@ Name: GStreamer Base Plugins Libraries, Uninstalled Description: Streaming media framework, base plugins libraries, uninstalled Version: @VERSION@ Requires: gstreamer-@GST_MAJORMINOR@ -Libs: -L@abs_top_builddir@/gst-libs/gst/audio -L@abs_top_builddir@/gst-libs/gst/cdda -L@abs_top_builddir@/gst-libs/gst/fft -L@abs_top_builddir@/gst-libs/gst/floatcast -L@abs_top_builddir@/gst-libs/gst/interfaces -L@abs_top_builddir@/gst-libs/gst/netbuffer -L@abs_top_builddir@/gst-libs/gst/riff -L@abs_top_builddir@/gst-libs/gst/rtp -L@abs_top_builddir@/gst-libs/gst/rtsp -L@abs_top_builddir@/gst-libs/gst/sdp -L@abs_top_builddir@/gst-libs/gst/tag -L@abs_top_builddir@/gst-libs/gst/pbutils -L@abs_top_builddir@/gst-libs/gst/video -L@abs_top_builddir@/gst-libs/gst/app +Libs: -L@abs_top_builddir@/gst-libs/gst/audio -L@abs_top_builddir@/gst-libs/gst/cdda -L@abs_top_builddir@/gst-libs/gst/dmabuf -L@abs_top_builddir@/gst-libs/gst/fft -L@abs_top_builddir@/gst-libs/gst/floatcast -L@abs_top_builddir@/gst-libs/gst/interfaces -L@abs_top_builddir@/gst-libs/gst/netbuffer -L@abs_top_builddir@/gst-libs/gst/riff -L@abs_top_builddir@/gst-libs/gst/rtp -L@abs_top_builddir@/gst-libs/gst/rtsp -L@abs_top_builddir@/gst-libs/gst/sdp -L@abs_top_builddir@/gst-libs/gst/tag -L@abs_top_builddir@/gst-libs/gst/pbutils -L@abs_top_builddir@/gst-libs/gst/video -L@abs_top_builddir@/gst-libs/gst/app Cflags: -I@abs_top_srcdir@/gst-libs -I@abs_top_builddir@/gst-libs -libraries=app audio cdda fft floatcast interfaces netbuffer riff rtp rtsp sdp tag pbutils video +libraries=app audio cdda fft dmabuf floatcast interfaces netbuffer riff rtp rtsp sdp tag pbutils video diff --git a/pkgconfig/gstreamer-plugins-base.pc.in b/pkgconfig/gstreamer-plugins-base.pc.in index 4bc6088..70e6d86 100644 --- a/pkgconfig/gstreamer-plugins-base.pc.in +++ b/pkgconfig/gstreamer-plugins-base.pc.in @@ -11,4 +11,4 @@ Version: @VERSION@ Libs: -L${libdir} Cflags: -I${includedir} -libraries=audio cdda fft floatcast interfaces netbuffer riff rtp tag pbutils video +libraries=audio cdda dmabuf fft floatcast interfaces netbuffer riff rtp tag pbutils video -- 1.7.9.5