meta-agl-profile-telematics: recipes-core: systemd: change canbus systemd match regex
[AGL/meta-agl.git] / meta-agl-bsp / meta-ti / recipes-arago / gstreamer / gstreamer1.0-plugins-bad / 0001-gstdrmallocator-Add-DRM-allocator-support.patch
1 From c5d115bf88f0d2fb64f58b21b72a3195eae98d0a Mon Sep 17 00:00:00 2001
2 From: Pooja Prajod <a0132412@ti.com>
3 Date: Fri, 20 Jan 2017 14:41:45 +0530
4 Subject: [PATCH 1/5] gstdrmallocator: Add DRM allocator support
5
6 Add DRM based allocator support.
7
8 The following changes are included :
9 1. Use DRM dumb buffers and associated APIs for
10 dmabuf allocation.
11 2. Have DRM device fd a member of allocator object
12 3. Allocate GstMemory objects with mem_type as 'dmabuf'
13
14 Signed-off-by: Pooja Prajod <a0132412@ti.com>
15 ---
16  configure.ac                              |   5 +
17  gst-libs/gst/Makefile.am                  |   4 +-
18  gst-libs/gst/drm/Makefile.am              |  33 +++++
19  gst-libs/gst/drm/gstdrmallocator.c        | 206 ++++++++++++++++++++++++++++++
20  gst-libs/gst/drm/gstdrmallocator.h        |  77 +++++++++++
21  pkgconfig/Makefile.am                     |   3 +
22  pkgconfig/gstreamer-drm-uninstalled.pc.in |  11 ++
23  pkgconfig/gstreamer-drm.pc.in             |  12 ++
24  8 files changed, 349 insertions(+), 2 deletions(-)
25  create mode 100644 gst-libs/gst/drm/Makefile.am
26  create mode 100644 gst-libs/gst/drm/gstdrmallocator.c
27  create mode 100644 gst-libs/gst/drm/gstdrmallocator.h
28  create mode 100644 pkgconfig/gstreamer-drm-uninstalled.pc.in
29  create mode 100644 pkgconfig/gstreamer-drm.pc.in
30
31 diff --git a/configure.ac b/configure.ac
32 index 5e85e56..e254605 100644
33 --- a/configure.ac
34 +++ b/configure.ac
35 @@ -621,6 +621,8 @@ if test x$with_egl_module_name != x; then
36    AC_DEFINE_UNQUOTED(GST_GL_LIBEGL_MODULE_NAME, "$with_egl_module_name", [EGL module name])
37  fi
38  
39 +PKG_CHECK_MODULES([DRM], [libdrm libdrm_omap], HAVE_KMS=yes, HAVE_KMS=no)
40 +
41  AC_ARG_ENABLE([wgl],
42       [  --enable-wgl            Enable WGL support @<:@default=auto@:>@],
43       [case "${enableval}" in
44 @@ -3590,6 +3592,7 @@ gst-libs/Makefile
45  gst-libs/gst/Makefile
46  gst-libs/gst/adaptivedemux/Makefile
47  gst-libs/gst/basecamerabinsrc/Makefile
48 +gst-libs/gst/drm/Makefile
49  gst-libs/gst/gl/Makefile
50  gst-libs/gst/gl/android/Makefile
51  gst-libs/gst/gl/cocoa/Makefile
52 @@ -3749,6 +3752,8 @@ pkgconfig/gstreamer-plugins-bad.pc
53  pkgconfig/gstreamer-plugins-bad-uninstalled.pc
54  pkgconfig/gstreamer-codecparsers.pc
55  pkgconfig/gstreamer-codecparsers-uninstalled.pc
56 +pkgconfig/gstreamer-drm.pc
57 +pkgconfig/gstreamer-drm-uninstalled.pc
58  pkgconfig/gstreamer-insertbin.pc
59  pkgconfig/gstreamer-insertbin-uninstalled.pc
60  pkgconfig/gstreamer-gl.pc
61 diff --git a/gst-libs/gst/Makefile.am b/gst-libs/gst/Makefile.am
62 index 7d0b309..5ec3967 100644
63 --- a/gst-libs/gst/Makefile.am
64 +++ b/gst-libs/gst/Makefile.am
65 @@ -11,7 +11,7 @@ WAYLAND_DIR=wayland
66  endif
67  
68  SUBDIRS = uridownloader adaptivedemux interfaces basecamerabinsrc codecparsers \
69 -        insertbin mpegts base video audio player $(GL_DIR) $(WAYLAND_DIR)
70 +        insertbin mpegts base video audio player drm $(GL_DIR) $(WAYLAND_DIR)
71  
72  noinst_HEADERS = gst-i18n-plugin.h gettext.h glib-compat-private.h
73  DIST_SUBDIRS = uridownloader adaptivedemux interfaces gl basecamerabinsrc \
74 @@ -24,7 +24,7 @@ adaptivedemux: uridownloader
75  
76  INDEPENDENT_SUBDIRS = \
77         interfaces basecamerabinsrc codecparsers insertbin uridownloader \
78 -       mpegts base player $(GL_DIR) $(WAYLAND_DIR)
79 +       mpegts base player drm $(GL_DIR) $(WAYLAND_DIR)
80  
81  .PHONY: independent-subdirs $(INDEPENDENT_SUBDIRS)
82  
83 diff --git a/gst-libs/gst/drm/Makefile.am b/gst-libs/gst/drm/Makefile.am
84 new file mode 100644
85 index 0000000..9a45dfb
86 --- /dev/null
87 +++ b/gst-libs/gst/drm/Makefile.am
88 @@ -0,0 +1,33 @@
89 +lib_LTLIBRARIES = libgstdrm-@GST_API_VERSION@.la
90 +
91 +CLEANFILES = $(BUILT_SOURCES)
92 +
93 +libgstdrm_@GST_API_VERSION@_la_SOURCES = \
94 +       gstdrmallocator.c 
95 +
96 +libgstdrm_@GST_API_VERSION@includedir = \
97 +       $(includedir)/gstreamer-@GST_API_VERSION@/gst/drm
98 +
99 +libgstdrm_@GST_API_VERSION@include_HEADERS = \
100 +       gstdrmallocator.h 
101 +
102 +libgstdrm_@GST_API_VERSION@_la_CFLAGS = \
103 +       $(DRM_CFLAGS) \
104 +       $(OMAPDRM_CFLAGS) \
105 +       $(GST_PLUGINS_BAD_CFLAGS) \
106 +       $(GST_PLUGINS_BASE_CFLAGS) \
107 +       -DGST_USE_UNSTABLE_API \
108 +       $(GST_CFLAGS)
109 +
110 +libgstdrm_@GST_API_VERSION@_la_LIBADD = \
111 +       $(DRM_LIBS) \
112 +       $(GST_PLUGINS_BASE_LIBS) \
113 +       $(GST_BASE_LIBS) \
114 +        -lgstallocators-$(GST_API_VERSION) \
115 +       $(GST_LIBS) 
116 +
117 +libgstdrm_@GST_API_VERSION@_la_LDFLAGS = \
118 +       $(DRM_LDFLAGS) \
119 +       $(GST_LIB_LDFLAGS) \
120 +       $(GST_ALL_LDFLAGS) \
121 +       $(GST_LT_LDFLAGS)
122 diff --git a/gst-libs/gst/drm/gstdrmallocator.c b/gst-libs/gst/drm/gstdrmallocator.c
123 new file mode 100644
124 index 0000000..b557ad2
125 --- /dev/null
126 +++ b/gst-libs/gst/drm/gstdrmallocator.c
127 @@ -0,0 +1,206 @@
128 +/*
129 + * GStreamer
130 + *
131 + * Copyright (C) 2012 Texas Instruments
132 + *
133 + * Authors:
134 + *  Pooja Prajod <poojaprajod@ti.com>
135 + *
136 + * This library is free software; you can redistribute it and/or
137 + * modify it under the terms of the GNU Lesser General Public
138 + * License as published by the Free Software Foundation
139 + * version 2.1 of the License.
140 + *
141 + * This library is distributed in the hope that it will be useful,
142 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
143 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
144 + * Lesser General Public License for more details.
145 + *
146 + * You should have received a copy of the GNU Lesser General Public
147 + * License along with this library; if not, write to the Free Software
148 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
149 + */
150 +
151 +/**
152 + * SECTION:GstDRMAllocator
153 + * @short_description: GStreamer DRM allocator support
154 + *
155 + * Since: 1.6.3
156 + */
157 +
158 +
159 +#include "gstdrmallocator.h"
160 +#include <stdio.h>
161 +#include <stdlib.h>
162 +#include <string.h>
163 +#include <errno.h>
164 +#include <unistd.h>
165 +#include <sys/mman.h>
166 +#include <sys/types.h>
167 +
168 +#define INVALID_DRM_FD (-1)
169 +
170 +GST_DEBUG_CATEGORY (drmallocator_debug);
171 +#define GST_CAT_DEFAULT drmallocator_debug
172 +
173 +#define gst_drm_allocator_parent_class parent_class
174 +G_DEFINE_TYPE (GstDRMAllocator, gst_drm_allocator, GST_TYPE_FD_ALLOCATOR);
175 +
176 +static GstMemory *
177 +gst_drm_allocator_alloc (GstAllocator * allocator, gsize size,
178 +    GstAllocationParams * params)
179 +{
180 +  GstDRMAllocator *self = GST_DRM_ALLOCATOR (allocator);
181 +  int fd = -1;
182 +  int DrmDeviceFD = self->DrmDeviceFD;
183 +  GstMemory *mem;
184 +  /* Variable for DRM Dumb Buffers */
185 +
186 +  struct drm_mode_create_dumb creq;
187 +  struct drm_mode_destroy_dumb dreq;
188 +  int ret ;
189 +  
190 +  GST_LOG_OBJECT (self, "DRM Memory alloc");  
191 +  
192 +  memset(&creq, 0, sizeof(struct drm_mode_create_dumb));
193 +  /* 
194 +   We have only total size as argument to _allocator_alloc.
195 +   Since the DDR storage is linear, it is as good as saying
196 +   the buffer is of width = size and height = 1
197 +  */
198 +  creq.width = size;
199 +  creq.height = 1;
200 +  creq.bpp = 8;
201 +
202 +  /* Create a DRM dumb buffer */
203 +  ret = drmIoctl (DrmDeviceFD, DRM_IOCTL_MODE_CREATE_DUMB, &creq);
204 +  if (ret < 0) {
205 +    GST_ERROR_OBJECT (self, "Create DRM dumb buffer failed");
206 +    return NULL;
207 +  }
208 +  /* Get a dmabuf fd from the dumb buffer handle */
209 +  drmPrimeHandleToFD (DrmDeviceFD, creq.handle, DRM_CLOEXEC | O_RDWR, &fd);
210 +
211 +  if (fd < 0) {
212 +    GST_ERROR_OBJECT (self, "Invalid fd returned: %d", fd);
213 +    goto fail;
214 +  }
215 +
216 +  /* Get a dmabuf gstmemory with the fd */
217 +  mem = gst_fd_allocator_alloc (allocator, fd, size, 0);  
218 +
219 +  if (G_UNLIKELY (!mem)) {
220 +    GST_ERROR_OBJECT (self, "GstDmaBufMemory allocation failed");
221 +    close (fd);
222 +    goto fail;
223 +  }
224 +
225 +  return mem;
226 +
227 +  fail:
228 +    memset(&dreq, 0, sizeof(struct drm_mode_destroy_dumb));
229 +    dreq.handle = creq.handle;
230 +    drmIoctl (DrmDeviceFD, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
231 +    return NULL;
232 +}
233 +
234 +static void
235 +gst_drm_allocator_free (GstAllocator * allocator, GstMemory * mem)
236 +{
237 +  GstDRMAllocator *self = GST_DRM_ALLOCATOR (allocator);
238 +  uint32_t handle = 0;
239 +  int DrmDeviceFD = self->DrmDeviceFD;
240 +  int fd = -1;
241 +
242 +  GST_LOG_OBJECT (self, "DRM Memory free");
243 +
244 +  g_return_if_fail (GST_IS_ALLOCATOR (allocator));
245 +  g_return_if_fail (mem != NULL);
246 +  g_return_if_fail (gst_is_drm_memory (mem));
247 +
248 +  fd = gst_fd_memory_get_fd (mem);
249 +  drmPrimeFDToHandle(DrmDeviceFD, fd, &handle);    
250 +
251 +  /* Incase there are some mapped memory, we unmap and ready it to be cleaned*/
252 +  GST_ALLOCATOR_CLASS (parent_class)->free (allocator, mem);
253 +
254 +  if (handle) {
255 +    struct drm_mode_destroy_dumb dreq;
256 +    memset(&dreq, 0, sizeof(struct drm_mode_destroy_dumb));
257 +    dreq.handle = handle;
258 +    drmIoctl (DrmDeviceFD, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
259 +  }
260 +  
261 +  close (fd);
262 +}
263 +
264 +static void
265 +gst_drm_allocator_finalize (GObject * obj)
266 +{
267 +  GstDRMAllocator *self = GST_DRM_ALLOCATOR (obj);
268 +  GST_LOG_OBJECT (obj, "DRM Allocator finalize");
269 +
270 +  close (self->DrmDeviceFD);
271 +  self->DrmDeviceFD = INVALID_DRM_FD;
272 +
273 +  G_OBJECT_CLASS (parent_class)->finalize (obj);
274 +}
275 +
276 +static void
277 +gst_drm_allocator_class_init (GstDRMAllocatorClass * klass)
278 +{
279 +  GstAllocatorClass *drm_alloc = (GstAllocatorClass *) klass;
280 +
281 +  drm_alloc->alloc = GST_DEBUG_FUNCPTR (gst_drm_allocator_alloc);
282 +  drm_alloc->free = GST_DEBUG_FUNCPTR (gst_drm_allocator_free);
283 +  GST_DEBUG_CATEGORY_INIT (drmallocator_debug, "drmallocator", 0,
284 +    "GstDRMAllocator debug");
285 +
286 +}
287 +
288 +static void
289 +gst_drm_allocator_init (GstDRMAllocator * self)
290 +{
291 +  GstAllocator *alloc = GST_ALLOCATOR_CAST (self);
292 +  GObjectClass *object_class = G_OBJECT_CLASS (GST_DRM_ALLOCATOR_GET_CLASS(self));
293 +  
294 +  if (self->DrmDeviceFD <= 0) {
295 +    self->DrmDeviceFD = open("/dev/dri/card0", O_RDWR | O_CLOEXEC);
296 +    if (self->DrmDeviceFD < 0) {
297 +      GST_ERROR_OBJECT (self, "Failed to open DRM device");
298 +    } else {
299 +      drmDropMaster (self->DrmDeviceFD);
300 +    }
301 +  }
302 +
303 +  alloc->mem_type = GST_ALLOCATOR_DMABUF;
304 +
305 +  object_class->finalize = gst_drm_allocator_finalize;
306 +
307 +  GST_OBJECT_FLAG_UNSET (self, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC);
308 +}
309 +
310 +void
311 +gst_drm_allocator_register (void)
312 +{
313 +  gst_allocator_register (GST_ALLOCATOR_DRM,
314 +      g_object_new (GST_TYPE_DRM_ALLOCATOR, NULL));
315 +}
316 +
317 +GstAllocator *
318 +gst_drm_allocator_get (void)
319 +{
320 +  GstAllocator *alloc;
321 +  alloc = gst_allocator_find (GST_ALLOCATOR_DRM);
322 +  if (!alloc) {
323 +    gst_drm_allocator_register();
324 +    alloc = gst_allocator_find (GST_ALLOCATOR_DRM);
325 +  }
326 +  return alloc; 
327 +}
328 +
329 +gboolean
330 +gst_is_drm_memory (GstMemory * mem)
331 +{
332 +  return gst_memory_is_type (mem, GST_ALLOCATOR_DMABUF);
333 +}
334 diff --git a/gst-libs/gst/drm/gstdrmallocator.h b/gst-libs/gst/drm/gstdrmallocator.h
335 new file mode 100644
336 index 0000000..1ca93ba
337 --- /dev/null
338 +++ b/gst-libs/gst/drm/gstdrmallocator.h
339 @@ -0,0 +1,77 @@
340 +/*
341 + * GStreamer
342 + *
343 + * Copyright (C) 2012 Texas Instruments
344 + *
345 + * Authors:
346 + *  Pooja Prajod <poojaprajod@ti.com>
347 + *
348 + * This library is free software; you can redistribute it and/or
349 + * modify it under the terms of the GNU Lesser General Public
350 + * License as published by the Free Software Foundation
351 + * version 2.1 of the License.
352 + *
353 + * This library is distributed in the hope that it will be useful,
354 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
355 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
356 + * Lesser General Public License for more details.
357 + *
358 + * You should have received a copy of the GNU Lesser General Public
359 + * License along with this library; if not, write to the Free Software
360 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
361 + */
362 +
363 +/**
364 + * SECTION:GstDRMAllocator
365 + * @short_description: GStreamer DRM allocator support
366 + *
367 + * Since: 1.6.3
368 + */
369 +
370 +#ifndef __GSTDRMALLOCATOR_H__
371 +#define __GSTDRMALLOCATOR_H__
372 +
373 +#include <gst/gst.h>
374 +#include <gst/video/video.h>
375 +#include <gst/allocators/allocators.h>
376 +#include <stdint.h>
377 +
378 +#include <xf86drm.h>
379 +#include <xf86drmMode.h>
380 +#include <fcntl.h>
381 +
382 +G_BEGIN_DECLS
383 +
384 +#define GST_TYPE_DRM_ALLOCATOR                  (gst_drm_allocator_get_type ())
385 +#define GST_DRM_ALLOCATOR(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_DRM_ALLOCATOR, GstDRMAllocator))
386 +#define GST_IS_DRM_ALLOCATOR(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_DRM_ALLOCATOR))
387 +#define GST_DRM_ALLOCATOR_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DRM_ALLOCATOR, GstDRMAllocatorClass))
388 +#define GST_IS_DRM_ALLOCATOR_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_DRM_ALLOCATOR))
389 +#define GST_DRM_ALLOCATOR_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_DRM_ALLOCATOR, GstDRMAllocatorClass))
390 +
391 +#define GST_ALLOCATOR_DRM "DRM"
392 +
393 +typedef struct _GstDRMAllocator GstDRMAllocator;
394 +typedef struct _GstDRMAllocatorClass GstDRMAllocatorClass;
395 +
396 +struct _GstDRMAllocator
397 +{
398 +  GstFdAllocator parent;
399 +  int DrmDeviceFD;
400 +};
401 +
402 +struct _GstDRMAllocatorClass
403 +{
404 +  GstFdAllocatorClass parent_class;
405 +};
406 +
407 +void gst_drm_allocator_register (void);
408 +GstAllocator * gst_drm_allocator_get (void);
409 +
410 +gboolean gst_is_drm_memory (GstMemory * mem);
411 +
412 +GType gst_drm_allocator_get_type (void);
413 +
414 +G_END_DECLS
415 +
416 +#endif /* __GSTDRMALLOCATOR_H__ */
417 diff --git a/pkgconfig/Makefile.am b/pkgconfig/Makefile.am
418 index 88c7e52..5fdccbf 100644
419 --- a/pkgconfig/Makefile.am
420 +++ b/pkgconfig/Makefile.am
421 @@ -2,6 +2,7 @@
422  ### all of the standard pc files we need to generate
423  pcverfiles =  \
424         gstreamer-plugins-bad-@GST_API_VERSION@.pc \
425 +        gstreamer-drm-@GST_API_VERSION@.pc \
426         gstreamer-codecparsers-@GST_API_VERSION@.pc \
427         gstreamer-insertbin-@GST_API_VERSION@.pc \
428         gstreamer-mpegts-@GST_API_VERSION@.pc \
429 @@ -12,6 +13,7 @@ pcverfiles =  \
430  
431  pcverfiles_uninstalled = \
432         gstreamer-plugins-bad-@GST_API_VERSION@-uninstalled.pc \
433 +        gstreamer-drm-@GST_API_VERSION@-uninstalled.pc \
434         gstreamer-codecparsers-@GST_API_VERSION@-uninstalled.pc \
435         gstreamer-insertbin-@GST_API_VERSION@-uninstalled.pc \
436         gstreamer-mpegts-@GST_API_VERSION@-uninstalled.pc \
437 @@ -43,6 +45,7 @@ pkgconfig_DATA = $(pcverfiles)
438  CLEANFILES = $(pcverfiles) $(pcverfiles_uninstalled)
439  pcinfiles = \
440             gstreamer-plugins-bad.pc.in gstreamer-plugins-bad-uninstalled.pc.in \
441 +           gstreamer-drm.pc.in gstreamer-drm-uninstalled.pc.in \
442             gstreamer-codecparsers.pc.in gstreamer-codecparsers-uninstalled.pc.in \
443             gstreamer-gl.pc.in gstreamer-gl-uninstalled.pc.in \
444             gstreamer-insertbin.pc.in gstreamer-insertbin-uninstalled.pc.in \
445 diff --git a/pkgconfig/gstreamer-drm-uninstalled.pc.in b/pkgconfig/gstreamer-drm-uninstalled.pc.in
446 new file mode 100644
447 index 0000000..9dcf978
448 --- /dev/null
449 +++ b/pkgconfig/gstreamer-drm-uninstalled.pc.in
450 @@ -0,0 +1,11 @@
451 +prefix=
452 +exec_prefix=
453 +libdir=${pcfiledir}/../gst-libs/gst/drm
454 +includedir=${pcfiledir}/../gst-libs
455 +
456 +Name: GStreamer DRM Allocator, Uninstalled
457 +Description: DRM Allocator for GStreamer elements, uninstalled
458 +Requires: gstreamer-@GST_MAJORMINOR@ gstreamer-base-@GST_MAJORMINOR@
459 +Version: @VERSION@
460 +Libs: -L${libdir} ${libdir}/libgstdrm-@GST_MAJORMINOR@.la
461 +Cflags: -I${includedir}
462 diff --git a/pkgconfig/gstreamer-drm.pc.in b/pkgconfig/gstreamer-drm.pc.in
463 new file mode 100644
464 index 0000000..d155e80
465 --- /dev/null
466 +++ b/pkgconfig/gstreamer-drm.pc.in
467 @@ -0,0 +1,12 @@
468 +prefix=@prefix@
469 +exec_prefix=@exec_prefix@
470 +libdir=@libdir@
471 +includedir=@includedir@/gstreamer-@GST_MAJORMINOR@
472 +
473 +Name: GStreamer DRM Allocator
474 +Description: DRM Allocator for GStreamer elements
475 +Requires: gstreamer-@GST_MAJORMINOR@ gstreamer-base-@GST_MAJORMINOR@
476 +Version: @VERSION@
477 +Libs: -L${libdir} -lgstdrm-@GST_MAJORMINOR@
478 +Cflags: -I${includedir}
479 +
480 -- 
481 1.9.1
482