1 From 44ba6f9839a410e981c9c941f099316ebfac2659 Mon Sep 17 00:00:00 2001
2 From: Pooja Prajod <a0132412@ti.com>
3 Date: Fri, 20 Jan 2017 16:18:22 +0530
4 Subject: [PATCH 3/5] gstkmssink: Add support for KMS based sink
6 The following features are enabled:
7 1. Add support for kmssink
8 2. Fix memory leak by using API's that do not hold
10 3. Restrict the number of buffers that will be allocated
12 4. Use Atomic mode setting instead of SetPlane
13 5. Store encoder and plane data as static data to enable
14 same process looping usecase
15 6. Handle usecase where display is disabled by default
17 Signed-off-by: Pooja Prajod <a0132412@ti.com>
20 sys/Makefile.am | 10 +-
21 sys/kms/Makefile.am | 28 ++
22 sys/kms/gstdrmutils.c | 347 +++++++++++++++++++++
23 sys/kms/gstdrmutils.h | 50 +++
24 sys/kms/gstkmsbufferpriv.c | 121 ++++++++
25 sys/kms/gstkmsbufferpriv.h | 64 ++++
26 sys/kms/gstkmssink.c | 740 +++++++++++++++++++++++++++++++++++++++++++++
27 sys/kms/gstkmssink.h | 92 ++++++
28 9 files changed, 1464 insertions(+), 2 deletions(-)
29 create mode 100644 sys/kms/Makefile.am
30 create mode 100644 sys/kms/gstdrmutils.c
31 create mode 100644 sys/kms/gstdrmutils.h
32 create mode 100644 sys/kms/gstkmsbufferpriv.c
33 create mode 100644 sys/kms/gstkmsbufferpriv.h
34 create mode 100644 sys/kms/gstkmssink.c
35 create mode 100644 sys/kms/gstkmssink.h
37 diff --git a/configure.ac b/configure.ac
38 index e254605..9fdfbc7 100644
41 @@ -2324,6 +2324,18 @@ AG_GST_CHECK_FEATURE(KATE, [Kate], kate, [
43 ],,,[AM_CONDITIONAL(USE_TIGER, false)])
48 +translit(dnm, m, l) AM_CONDITIONAL(USE_KMS, true)
49 +AG_GST_CHECK_FEATURE(KMS, [kmssink], kms, [
50 +PKG_CHECK_MODULES([DRM], [libdrm libdrm_omap], HAVE_KMS=yes, HAVE_KMS=no)
51 +PKG_CHECK_MODULES(LIBDCE, [libdce >= 1.0.0], HAVE_KMS=yes, HAVE_KMS=no)
58 translit(dnm, m, l) AM_CONDITIONAL(USE_LADSPA, true)
59 AG_GST_CHECK_FEATURE(LADSPA, [ladspa], ladspa, [
60 @@ -3383,6 +3395,7 @@ AM_CONDITIONAL(USE_GTK3_GL, false)
61 AM_CONDITIONAL(USE_HLS, false)
62 AM_CONDITIONAL(USE_KATE, false)
63 AM_CONDITIONAL(USE_TIGER, false)
64 +AM_CONDITIONAL(USE_KMS, false)
65 AM_CONDITIONAL(USE_LADSPA, false)
66 AM_CONDITIONAL(USE_LV2, false)
67 AM_CONDITIONAL(USE_LIBDE265, false)
68 @@ -3632,6 +3645,7 @@ sys/fbdev/Makefile
76 diff --git a/sys/Makefile.am b/sys/Makefile.am
77 index 32f79fb..325b4af 100644
80 @@ -87,6 +87,12 @@ PVR_DIR=pvr2d
93 @@ -148,10 +154,10 @@ else
97 -SUBDIRS = $(ACM_DIR) $(ANDROID_MEDIA_DIR) $(APPLE_MEDIA_DIR) $(AVC_DIR) $(BLUEZ_DIR) $(D3DVIDEOSINK_DIR) $(DECKLINK_DIR) $(DIRECTSOUND_DIR) $(WINKS_DIR) $(DVB_DIR) $(FBDEV_DIR) $(LINSYS_DIR) $(OPENSLES_DIR) $(PVR_DIR) $(SHM_DIR) $(UVCH264_DIR) $(VCD_DIR) $(VDPAU_DIR) $(WININET_DIR) $(WINSCREENCAP_DIR) $(WASAPI_DIR) $(NVENC_DIR) $(TINYALSA_DIR)
98 +SUBDIRS = $(ACM_DIR) $(ANDROID_MEDIA_DIR) $(APPLE_MEDIA_DIR) $(AVC_DIR) $(BLUEZ_DIR) $(D3DVIDEOSINK_DIR) $(DECKLINK_DIR) $(DIRECTSOUND_DIR) $(WINKS_DIR) $(DVB_DIR) $(FBDEV_DIR) $(LINSYS_DIR) $(OPENSLES_DIR) $(PVR_DIR) $(KMS_DIR) $(SHM_DIR) $(UVCH264_DIR) $(VCD_DIR) $(VDPAU_DIR) $(WININET_DIR) $(WINSCREENCAP_DIR) $(WASAPI_DIR) $(NVENC_DIR) $(TINYALSA_DIR)
100 DIST_SUBDIRS = acmenc acmmp3dec androidmedia applemedia applemedia-nonpublic avc bluez d3dvideosink decklink directsound dvb linsys fbdev dshowdecwrapper dshowsrcwrapper dshowvideosink \
101 - opensles pvr2d shm uvch264 vcd vdpau wasapi wininet winks winscreencap \
102 + opensles pvr2d kms shm uvch264 vcd vdpau wasapi wininet winks winscreencap \
105 include $(top_srcdir)/common/parallel-subdirs.mak
106 diff --git a/sys/kms/Makefile.am b/sys/kms/Makefile.am
108 index 0000000..6d56073
110 +++ b/sys/kms/Makefile.am
112 +plugin_LTLIBRARIES = libgstkmssink.la
114 +libgstkmssink_la_SOURCES = \
116 + gstkmsbufferpriv.c \
119 +libgstkmssink_la_CFLAGS = \
120 + $(GST_PLUGINS_BAD_CFLAGS) \
121 + $(GST_PLUGINS_BASE_CFLAGS) \
122 + $(GST_BASE_CFLAGS) \
127 +libgstkmssink_la_LIBADD = \
128 + $(GST_PLUGINS_BASE_LIBS) \
133 + -lgstvideo-$(GST_API_VERSION) \
134 + $(top_builddir)/gst-libs/gst/drm/libgstdrm-$(GST_API_VERSION).la
136 +libgstkmssink_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
137 +libgstkmssink_la_LIBTOOLFLAGS = --tag=disable-static
139 +noinst_HEADERS = gstkmssink.h gstdrmutils.h gstkmsbufferpriv.h
140 diff --git a/sys/kms/gstdrmutils.c b/sys/kms/gstdrmutils.c
142 index 0000000..0e67a48
144 +++ b/sys/kms/gstdrmutils.c
148 + * Copyright (C) 2012 Texas Instruments
149 + * Copyright (C) 2012 Collabora Ltd
152 + * Alessandro Decina <alessandro.decina@collabora.co.uk>
154 + * This library is free software; you can redistribute it and/or
155 + * modify it under the terms of the GNU Library General Public
156 + * License as published by the Free Software Foundation; either
157 + * version 2 of the License, or (at your option) any later version.
159 + * This library is distributed in the hope that it will be useful,
160 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
161 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
162 + * Library General Public License for more details.
164 + * You should have received a copy of the GNU Library General Public
165 + * License along with this library; if not, write to the
166 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
167 + * Boston, MA 02111-1307, USA.
170 +#include <gst/gst.h>
171 +#include "gstdrmutils.h"
173 +static int stored_enc = 0;
174 +static drmModeEncoder *enc;
175 +static struct plane_data *stored_plane;
177 +GST_DEBUG_CATEGORY_EXTERN (gst_debug_kms_sink);
178 +#define GST_CAT_DEFAULT gst_debug_kms_sink
181 +gst_drm_connector_cleanup (int fd, struct connector *c)
183 + if (c->connector) {
184 + drmModeFreeConnector (c->connector);
185 + c->connector = NULL;
189 + drmModeRmFB (fd, c->fb_id);
193 + omap_bo_del (c->fb_bo);
200 +gst_drm_connector_find_mode_and_plane_helper (int fd,
201 + struct omap_device *dev, int width, int height,
202 + drmModeRes * resources, drmModePlaneRes * plane_resources,
203 + struct connector *c)
205 + int i, best_area = 0, ret;
206 + struct drm_set_client_cap req;
210 + gst_drm_connector_cleanup (fd, c);
212 + req.capability = DRM_CLIENT_CAP_ATOMIC;
214 + ret = ioctl(fd, DRM_IOCTL_SET_CLIENT_CAP, &req);
216 + GST_DEBUG("drm set atomic cap failed");
220 + /* First, find the connector & mode */
221 + c->connector = drmModeGetConnector (fd, c->id);
223 + goto error_no_connector;
225 + if (!c->connector->count_modes)
226 + goto error_no_mode;
228 + /* just look for the highest resolution: */
229 + for (i = 0; i < c->connector->count_modes; i++) {
230 + drmModeModeInfo *mode = &c->connector->modes[i];
231 + int area = mode->hdisplay * mode->vdisplay;
233 + if (area > best_area) {
239 + if (c->mode == NULL) {
240 + /* XXX: just pick the first available mode. Not sure this is correct... */
241 + c->mode = &c->connector->modes[0];
243 + goto error_no_mode;
247 + /* Now get the encoder */
251 + c->connector->encoder_id = stored_enc;
253 + c->encoder = drmModeGetEncoder (fd, c->connector->encoder_id);
255 + stored_enc = c->connector->encoder_id;
259 + for (i = 0; i < c->connector->count_encoders; ++i) {
260 + c->encoder = drmModeGetEncoder(fd, c->connector->encoders[i]);
262 + GST_DEBUG ("Cannot retrieve encoder %u:%u (%d): %m\n",
263 + i, c->connector->encoders[i], errno);
266 + /* iterate all global CRTCs */
267 + for (j = 0; j < resources->count_crtcs; ++j) {
268 + /* check whether this CRTC works with the encoder */
269 + if (!(c->encoder->possible_crtcs & (1 << j)))
271 + crtc = resources->crtcs[j];
276 + stored_enc = c->connector->encoder_id;
278 + goto found_encoder;
286 + goto error_no_encoder;
289 + c->crtc = c->encoder->crtc_id;
291 + /* and figure out which crtc index it is: */
293 + for (i = 0; i < resources->count_crtcs; i++) {
294 + if (c->crtc == (int) resources->crtcs[i]) {
301 + goto error_no_crtc;
303 + if (stored_plane) {
304 + c->pdata = stored_plane;
307 + c->pdata = calloc(sizeof(struct plane_data), 1);
308 + for (i = 0; i < plane_resources->count_planes; i++) {
309 + drmModePlane *plane = drmModeGetPlane (fd, plane_resources->planes[i]);
311 + if (plane->possible_crtcs & (1 << c->pipe)) {
312 + drmModeObjectPropertiesPtr props = drmModeObjectGetProperties(fd, plane_resources->planes[i], DRM_MODE_OBJECT_PLANE);
313 + for(propc = 0; propc < props->count_props; propc++) {
314 + drmModePropertyPtr prop = drmModeGetProperty(fd, props->props[propc]);
315 + if(strcmp(prop->name, "FB_ID") == 0)
316 + c->pdata[0].fb_id_property = props->props[propc];
318 + c->pdata[0].plane = plane_resources->planes[i];
319 + stored_plane = c->pdata;
323 + if (stored_plane == NULL)
324 + goto error_no_plane;
326 + c->fb_bo = omap_bo_new (dev, best_area * 2, OMAP_BO_WC);
328 + uint32_t fourcc = DRM_FORMAT_RGB565;
329 + uint32_t handles[4] = { omap_bo_handle (c->fb_bo) };
330 + uint32_t pitches[4] = { c->mode->hdisplay * 2 };
331 + uint32_t offsets[4] = { 0 };
332 + ret = drmModeAddFB2 (fd, c->mode->hdisplay, c->mode->vdisplay,
333 + fourcc, handles, pitches, offsets, &c->fb_id, 0);
335 + GST_DEBUG ("RGB565 AddFb2 failed");
339 + /* now set the desired mode: */
340 + ret = drmModeSetCrtc (fd, c->crtc, c->fb_id, 0, 0, &c->id, 1, c->mode);
342 + GST_DEBUG ("SetCrtc failed");
348 + gst_drm_connector_cleanup (fd, c);
353 + GST_DEBUG ("could not get connector %s", strerror (errno));
357 + GST_DEBUG ("could not find mode %dx%d (count_modes %d)",
358 + width, height, c->connector->count_modes);
362 + GST_DEBUG ("could not get encoder: %s", strerror (errno));
366 + GST_DEBUG ("couldn't find a crtc");
370 + GST_DEBUG ("couldn't find a plane");
375 +gst_drm_connector_find_mode_and_plane (int fd,
376 + struct omap_device *dev, int width, int height,
377 + drmModeRes * resources, drmModePlaneRes * plane_resources,
378 + struct connector *c)
381 + gboolean found = FALSE;
383 + /* First, find the connector & mode */
385 + /* Any connector */
386 + GST_DEBUG ("Any connector, %d available", resources->count_connectors);
387 + for (i = 0; i < resources->count_connectors; i++) {
388 + GST_DEBUG (" %d", resources->connectors[i]);
390 + for (i = 0; i < resources->count_connectors; i++) {
391 + GST_DEBUG ("Trying connector %d: %d", i, resources->connectors[i]);
392 + c->id = resources->connectors[i];
393 + if (gst_drm_connector_find_mode_and_plane_helper (fd, dev, width, height,
394 + resources, plane_resources, c)) {
395 + GST_DEBUG ("Found suitable connector");
399 + GST_DEBUG ("Connector not suitable");
402 + /* A specific connector */
403 + GST_DEBUG ("Connector %d", c->id);
405 + gst_drm_connector_find_mode_and_plane_helper (fd, dev, width, height,
406 + resources, plane_resources, c);
412 +/* table nicked off libdrm's modetest.c */
414 +static const struct {
416 + const char *type_name;
417 +} connector_type_names[] = {
418 + { DRM_MODE_CONNECTOR_Unknown, "unknown" },
419 + { DRM_MODE_CONNECTOR_VGA, "VGA" },
420 + { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
421 + { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
422 + { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
423 + { DRM_MODE_CONNECTOR_Composite, "composite" },
424 + { DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
425 + { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
426 + { DRM_MODE_CONNECTOR_Component, "component" },
427 + { DRM_MODE_CONNECTOR_9PinDIN, "9-pin-DIN" },
428 + { DRM_MODE_CONNECTOR_DisplayPort, "displayport" },
429 + { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
430 + { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
431 + { DRM_MODE_CONNECTOR_TV, "TV" },
432 + { DRM_MODE_CONNECTOR_eDP, "embedded-displayport" },
437 +gst_drm_connector_find_mode_and_plane_by_name (int fd,
438 + struct omap_device * dev, int width, int height,
439 + drmModeRes * resources, drmModePlaneRes * plane_resources,
440 + struct connector * c, const char *name)
444 + const char *type_name;
445 + int found[G_N_ELEMENTS (connector_type_names)] = { 0 };
447 + /* Find connector from name */
448 + for (i = 0; i < resources->count_connectors; i++) {
449 + GST_DEBUG ("Trying connector %d: %d", i, resources->connectors[i]);
450 + c->id = resources->connectors[i];
451 + c->connector = drmModeGetConnector (fd, c->id);
455 + /* Find type name from this connector */
456 + for (n = 0; n < G_N_ELEMENTS (connector_type_names); n++)
457 + if (connector_type_names[n].type_id == c->connector->connector_type)
459 + if (n == G_N_ELEMENTS (connector_type_names))
462 + type_name = connector_type_names[n].type_name;
463 + GST_DEBUG ("Connector %d has type %s", i, type_name);
466 + drmModeFreeConnector (c->connector);
467 + c->connector = NULL;
469 + /* Try a few different matches, such as modetest and xrandr
470 + output, and also a indexless one matching first found */
471 + snprintf (tmp, sizeof (tmp), "%s-%u", type_name, found[n]);
472 + if (!g_ascii_strcasecmp (tmp, name))
474 + snprintf (tmp, sizeof (tmp), "%s%u", type_name, found[n]);
475 + if (!g_ascii_strcasecmp (tmp, name))
477 + if (!g_ascii_strcasecmp (name, type_name))
483 + if (gst_drm_connector_find_mode_and_plane_helper (fd, dev, width, height,
484 + resources, plane_resources, c)) {
485 + GST_DEBUG ("Found suitable connector");
488 + GST_DEBUG ("Connector not suitable");
493 diff --git a/sys/kms/gstdrmutils.h b/sys/kms/gstdrmutils.h
495 index 0000000..ebc5fc6
497 +++ b/sys/kms/gstdrmutils.h
499 +#ifndef __GST_DRMUTILS_H__
500 +#define __GST_DRMUTILS_H__
503 +#include <xf86drm.h>
511 +#include <libdrm/drm.h>
512 +#include <libdrm/drm_mode.h>
513 +#include <xf86drmMode.h>
514 +#include <omap_drm.h>
515 +#include <omap_drmif.h>
516 +#include <drm_fourcc.h>
517 +#include <gst/gst.h>
518 +#include <sys/ioctl.h>
522 + int fb_id_property;
528 + drmModeConnector *connector;
529 + drmModeModeInfo *mode;
530 + drmModeEncoder *encoder;
532 + struct omap_bo *fb_bo;
535 + struct plane_data *pdata;
538 +void gst_drm_connector_cleanup (int fd, struct connector * c);
539 +gboolean gst_drm_connector_find_mode_and_plane (int fd,
540 + struct omap_device * dev, int width, int height,
541 + drmModeRes * resources, drmModePlaneRes * plane_resources,
542 + struct connector *c);
543 +gboolean gst_drm_connector_find_mode_and_plane_by_name (int fd,
544 + struct omap_device *dev, int width, int height,
545 + drmModeRes * resources, drmModePlaneRes * plane_resources,
546 + struct connector *c, const char *name);
548 +#endif /* __GST_DRMUTILS_H__ */
549 diff --git a/sys/kms/gstkmsbufferpriv.c b/sys/kms/gstkmsbufferpriv.c
551 index 0000000..172a4c3
553 +++ b/sys/kms/gstkmsbufferpriv.c
558 + * Copyright (C) 2012 Texas Instruments
559 + * Copyright (C) 2012 Collabora Ltd
562 + * Alessandro Decina <alessandro.decina@collabora.co.uk>
563 + * Rob Clark <rob.clark@linaro.org>
565 + * This library is free software; you can redistribute it and/or
566 + * modify it under the terms of the GNU Lesser General Public
567 + * License as published by the Free Software Foundation
568 + * version 2.1 of the License.
570 + * This library is distributed in the hope that it will be useful,
571 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
572 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
573 + * Lesser General Public License for more details.
575 + * You should have received a copy of the GNU Lesser General Public
576 + * License along with this library; if not, write to the Free Software
577 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
580 +#ifdef HAVE_CONFIG_H
585 +#include <gst/gst.h>
586 +#include <gst/allocators/allocators.h>
588 +#include <omap_drm.h>
589 +#include <omap_drmif.h>
590 +#include <xf86drmMode.h>
592 +#include "gstkmssink.h"
593 +#include "gstkmsbufferpriv.h"
596 +create_fb (GstKMSBufferPriv * priv, GstKMSSink * sink)
598 + /* TODO get format, etc from caps.. and query device for
599 + * supported formats, and make this all more flexible to
600 + * cope with various formats:
602 + uint32_t fourcc = GST_MAKE_FOURCC ('N', 'V', '1', '2');
604 + uint32_t handles[4] = {
605 + omap_bo_handle (priv->bo), omap_bo_handle (priv->bo),
607 + uint32_t pitches[4] = {
608 + GST_ROUND_UP_4 (sink->input_width), GST_ROUND_UP_4 (sink->input_width),
610 + uint32_t offsets[4] = {
611 + 0, pitches[0] * sink->input_height
614 + return drmModeAddFB2 (priv->fd, sink->input_width, sink->input_height,
615 + fourcc, handles, pitches, offsets, &priv->fb_id, 0);
619 + * gst_kms_buffer_priv:
620 + * @sink: a #GstKMSSink
621 + * @buf: a pointer to #GstBuffer
623 + * Checks if the @buf has a GstMetaDmaBuf metadata set. If it doesn't we return a NULL
624 + * indicating its not a dmabuf buffer. We maintain a hashtable with dmabuf fd as key and
625 + * the GstKMSBufferPriv structure as value
627 + * Returns: the #GstKMSBufferPriv
632 +gst_kms_buffer_priv (GstKMSSink * sink, GstBuffer * buf)
634 + struct omap_bo *bo;
637 + GstKMSBufferPriv * priv;
640 + /* if it isn't a dmabuf buffer that we can import, then there
641 + * is nothing we can do with it:
643 + mem = gst_buffer_peek_memory (buf, 0);
644 + fd_copy = gst_fd_memory_get_fd (mem);
646 + GST_DEBUG_OBJECT (sink, "not importing non dmabuf buffer");
650 + /* lookup the hashtable with fd as key. If present return bo & buffer structure */
651 + priv = g_hash_table_lookup (sink->kmsbufferpriv, (gpointer)fd_copy);
656 + priv = g_malloc0 (sizeof (GstKMSBufferPriv));
657 + bo = omap_bo_from_dmabuf (sink->dev, fd_copy);
663 + if (create_fb (priv, sink)) {
664 + GST_WARNING_OBJECT (sink, "could not create framebuffer: %s",
670 + /* if fd not present, write to hash table fd and the corresponding priv. */
671 + g_hash_table_insert(sink->kmsbufferpriv, (gpointer)fd_copy, priv);
676 diff --git a/sys/kms/gstkmsbufferpriv.h b/sys/kms/gstkmsbufferpriv.h
678 index 0000000..a1070da
680 +++ b/sys/kms/gstkmsbufferpriv.h
685 + * Copyright (C) 2012 Texas Instruments
686 + * Copyright (C) 2012 Collabora Ltd
689 + * Alessandro Decina <alessandro.decina@collabora.co.uk>
690 + * Rob Clark <rob.clark@linaro.org>
692 + * This library is free software; you can redistribute it and/or
693 + * modify it under the terms of the GNU Lesser General Public
694 + * License as published by the Free Software Foundation
695 + * version 2.1 of the License.
697 + * This library is distributed in the hope that it will be useful,
698 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
699 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
700 + * Lesser General Public License for more details.
702 + * You should have received a copy of the GNU Lesser General Public
703 + * License along with this library; if not, write to the Free Software
704 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
707 +#ifndef __GSTKMSBUFFERPRIV_H__
708 +#define __GSTKMSBUFFERPRIV_H__
711 +#include <gst/gst.h>
716 + * per-buffer private data so kmssink can attach a drm_framebuffer
717 + * handle (fb_id) to a buffer, which gets deleted when the buffer
721 +#define GST_TYPE_KMS_BUFFER_PRIV \
722 + (gst_kms_buffer_priv_get_type ())
723 +#define GST_KMS_BUFFER_PRIV(obj) \
724 + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_KMS_BUFFER_PRIV, GstKMSBufferPriv))
725 +#define GST_IS_KMS_BUFFER_PRIV(obj) \
726 + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_KMS_BUFFER_PRIV))
731 + struct omap_bo *bo;
737 +GType gst_kms_buffer_priv_get_type (void);
739 +/* Returns a GstKMSBufferPriv, if it has a dmabuf fd metadata */
740 +GstKMSBufferPriv * gst_kms_buffer_priv (GstKMSSink *sink, GstBuffer * buf);
745 +#endif /* __GSTKMSBUFFERPRIV_H__ */
746 diff --git a/sys/kms/gstkmssink.c b/sys/kms/gstkmssink.c
748 index 0000000..17e6407
750 +++ b/sys/kms/gstkmssink.c
753 + * Copyright (C) 2012 Texas Instruments
754 + * Copyright (C) 2012 Collabora Ltd
757 + * Alessandro Decina <alessandro.decina@collabora.co.uk>
759 + * This library is free software; you can redistribute it and/or
760 + * modify it under the terms of the GNU Library General Public
761 + * License as published by the Free Software Foundation; either
762 + * version 2 of the License, or (at your option) any later version.
764 + * This library is distributed in the hope that it will be useful,
765 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
766 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
767 + * Library General Public License for more details.
769 + * You should have received a copy of the GNU Library General Public
770 + * License along with this library; if not, write to the
771 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
772 + * Boston, MA 02111-1307, USA.
775 + * Alessandro Decina <alessandro.decina@collabora.co.uk>
778 +#ifdef HAVE_CONFIG_H
782 +#include "gstkmssink.h"
783 +#include "gstkmsbufferpriv.h"
786 +#include <omap_drm.h>
787 +#include <omap_drmif.h>
788 +#include <xf86drmMode.h>
790 +static int drm_fd = -1;
791 +static struct omap_device *drm_dev;
794 +GST_DEBUG_CATEGORY (gst_debug_kms_sink);
795 +#define GST_CAT_DEFAULT gst_debug_kms_sink
797 +G_DEFINE_TYPE (GstKMSSink, gst_kms_sink, GST_TYPE_VIDEO_SINK);
799 +static void gst_kms_sink_reset (GstKMSSink * sink);
801 +static GstStaticPadTemplate gst_kms_sink_template_factory =
802 +GST_STATIC_PAD_TEMPLATE ("sink",
805 + GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE("NV12"))
811 + PROP_PIXEL_ASPECT_RATIO,
812 + PROP_FORCE_ASPECT_RATIO,
815 + PROP_CONNECTOR_NAME,
820 +display_bufs_queue (GstKMSSink * sink, GstBuffer * buf)
823 + for (i = 0; i < (NUM_DISPLAY_BUFS - 1); i++)
824 + gst_buffer_replace (&sink->display_bufs[i], sink->display_bufs[i + 1]);
825 + gst_buffer_replace (&sink->display_bufs[i], buf);
829 +display_bufs_free (GstKMSSink * sink)
832 + for (i = 0; i < NUM_DISPLAY_BUFS; i++)
833 + gst_buffer_replace (&sink->display_bufs[i], NULL);
837 +gst_kms_sink_calculate_aspect_ratio (GstKMSSink * sink, gint width,
838 + gint height, gint video_par_n, gint video_par_d)
840 + guint calculated_par_n;
841 + guint calculated_par_d;
843 + if (!gst_video_calculate_display_ratio (&calculated_par_n, &calculated_par_d,
844 + width, height, video_par_n, video_par_d, 1, 1)) {
845 + GST_ELEMENT_ERROR (sink, CORE, NEGOTIATION, (NULL),
846 + ("Error calculating the output display ratio of the video."));
849 + GST_DEBUG_OBJECT (sink,
850 + "video width/height: %dx%d, calculated display ratio: %d/%d",
851 + width, height, calculated_par_n, calculated_par_d);
853 + /* now find a width x height that respects this display ratio.
854 + * prefer those that have one of w/h the same as the incoming video
855 + * using wd / hd = calculated_pad_n / calculated_par_d */
857 + /* start with same height, because of interlaced video */
858 + /* check hd / calculated_par_d is an integer scale factor, and scale wd with the PAR */
859 + if (height % calculated_par_d == 0) {
860 + GST_DEBUG_OBJECT (sink, "keeping video height");
861 + GST_VIDEO_SINK_WIDTH (sink) = (guint)
862 + gst_util_uint64_scale_int (height, calculated_par_n, calculated_par_d);
863 + GST_VIDEO_SINK_HEIGHT (sink) = height;
864 + } else if (width % calculated_par_n == 0) {
865 + GST_DEBUG_OBJECT (sink, "keeping video width");
866 + GST_VIDEO_SINK_WIDTH (sink) = width;
867 + GST_VIDEO_SINK_HEIGHT (sink) = (guint)
868 + gst_util_uint64_scale_int (width, calculated_par_d, calculated_par_n);
870 + GST_DEBUG_OBJECT (sink, "approximating while keeping video height");
871 + GST_VIDEO_SINK_WIDTH (sink) = (guint)
872 + gst_util_uint64_scale_int (height, calculated_par_n, calculated_par_d);
873 + GST_VIDEO_SINK_HEIGHT (sink) = height;
875 + GST_DEBUG_OBJECT (sink, "scaling to %dx%d",
876 + GST_VIDEO_SINK_WIDTH (sink), GST_VIDEO_SINK_HEIGHT (sink));
882 +gst_kms_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
885 + gboolean ret = TRUE;
886 + gint width, height;
889 + GstVideoFormat format;
891 + GstStructure *conf;
895 + sink = GST_KMS_SINK (bsink);
897 + ret = gst_video_info_from_caps (&info, caps);
898 + format = GST_VIDEO_INFO_FORMAT(&info);
899 + width = GST_VIDEO_INFO_WIDTH(&info);
900 + height = GST_VIDEO_INFO_HEIGHT(&info);
901 + fps_n = GST_VIDEO_INFO_FPS_N(&info);
902 + fps_d = GST_VIDEO_INFO_FPS_D(&info);
903 + par_n = GST_VIDEO_INFO_PAR_N(&info);
904 + par_d = GST_VIDEO_INFO_PAR_D(&info);
909 + if (width <= 0 || height <= 0) {
910 + GST_ELEMENT_ERROR (sink, CORE, NEGOTIATION, (NULL),
911 + ("Invalid image size."));
915 + sink->format = format;
916 + sink->par_n = par_n;
917 + sink->par_d = par_d;
918 + sink->src_rect.x = sink->src_rect.y = 0;
919 + sink->src_rect.w = width;
920 + sink->src_rect.h = height;
921 + sink->input_width = width;
922 + sink->input_height = height;
926 + GstAllocator *allocator;
928 + allocator = gst_drm_allocator_get ();
929 + sink->pool = gst_buffer_pool_new ();
930 + conf = gst_buffer_pool_get_config (GST_BUFFER_POOL(sink->pool));
931 + gst_buffer_pool_config_set_params (conf, caps, size, 0, 0);
932 + gst_buffer_pool_config_set_allocator (conf, allocator, NULL);
933 + gst_buffer_pool_set_config (GST_BUFFER_POOL(sink->pool), conf);
935 + gst_object_unref (allocator);
938 + sink->conn.crtc = -1;
943 +gst_kms_sink_get_times (GstBaseSink * bsink, GstBuffer * buf,
944 + GstClockTime * start, GstClockTime * end)
948 + sink = GST_KMS_SINK (bsink);
950 + if (GST_BUFFER_PTS_IS_VALID (buf)) {
951 + *start = GST_BUFFER_PTS (buf);
952 + if (GST_BUFFER_DURATION_IS_VALID (buf)) {
953 + *end = *start + GST_BUFFER_DURATION (buf);
955 + if (sink->fps_n > 0) {
957 + gst_util_uint64_scale_int (GST_SECOND, sink->fps_d, sink->fps_n);
964 +static void page_flip_handler(int fd, unsigned int frame,
965 + unsigned int sec, unsigned int usec, void *data)
967 + int *waiting_for_flip = data;
968 + *waiting_for_flip = 0;
972 +static GstFlowReturn
973 +gst_kms_sink_show_frame (GstVideoSink * vsink, GstBuffer * inbuf)
975 + GstKMSSink *sink = GST_KMS_SINK (vsink);
976 + GstBuffer *buf = NULL;
977 + GstKMSBufferPriv *priv;
978 + GstFlowReturn flow_ret = GST_FLOW_OK;
980 + gint width, height;
981 + GstVideoRectangle *c = &sink->src_rect;
982 + int waiting_for_flip = 1;
985 + drmEventContext evctx = {
986 + .version = DRM_EVENT_CONTEXT_VERSION,
987 + .vblank_handler = 0,
988 + .page_flip_handler = page_flip_handler,
991 + g_mutex_lock (&sink->render_lock);
992 + GstVideoCropMeta* crop = gst_buffer_get_video_crop_meta (inbuf);
997 + if (crop->width >= 0) {
998 + width = crop->width;
1000 + width = sink->input_width;
1002 + if (crop->height >= 0){
1003 + height = crop->height;
1005 + height = sink->input_height;
1008 + width = sink->input_width;
1009 + height = sink->input_height;
1016 + if (!gst_kms_sink_calculate_aspect_ratio (sink, width, height,
1017 + sink->par_n, sink->par_d))
1018 + GST_DEBUG_OBJECT (sink, "calculate aspect ratio failed");
1021 + GST_INFO_OBJECT (sink, "enter");
1023 + if (sink->conn.crtc == -1) {
1024 + if (sink->conn_name) {
1025 + if (!gst_drm_connector_find_mode_and_plane_by_name (sink->fd,
1026 + sink->dev, sink->src_rect.w, sink->src_rect.h,
1027 + sink->resources, sink->plane_resources, &sink->conn,
1029 + goto connector_not_found;
1031 + sink->conn.id = sink->conn_id;
1032 + if (!gst_drm_connector_find_mode_and_plane (sink->fd,
1033 + sink->dev, sink->src_rect.w, sink->src_rect.h,
1034 + sink->resources, sink->plane_resources, &sink->conn))
1035 + goto connector_not_found;
1040 + priv = gst_kms_buffer_priv (sink, inbuf);
1045 + GST_LOG_OBJECT (sink, "not a KMS buffer, slow-path!");
1046 + gst_buffer_pool_acquire_buffer (sink->pool, &buf, NULL);
1048 + GST_BUFFER_PTS (buf) = GST_BUFFER_PTS (inbuf);
1049 + GST_BUFFER_DURATION (buf) = GST_BUFFER_DURATION (inbuf);
1050 + gst_buffer_copy_into (buf, inbuf, GST_BUFFER_COPY_DEEP, 0 ,-1);
1051 + priv = gst_kms_buffer_priv (sink, buf);
1054 + goto add_fb2_failed;
1059 + static GstVideoRectangle dest = { 0 };
1060 + dest.w = sink->conn.mode->hdisplay;
1061 + dest.h = sink->conn.mode->vdisplay;
1063 + gst_video_sink_center_rect (sink->src_rect, dest, &sink->dst_rect,
1065 + ret = drmModeSetPlane (sink->fd, sink->conn.pdata[0].plane,
1066 + sink->conn.crtc, priv->fb_id, 0,
1067 + sink->dst_rect.x, sink->dst_rect.y, sink->dst_rect.w, sink->dst_rect.h,
1068 + sink->src_rect.x << 16, sink->src_rect.y << 16,
1069 + sink->src_rect.w << 16, sink->src_rect.h << 16);
1071 + goto set_plane_failed;
1074 + drmModeAtomicReqPtr m_req = drmModeAtomicAlloc();
1076 + drmModeAtomicAddProperty(m_req, sink->conn.pdata[0].plane,
1077 + sink->conn.pdata[0].fb_id_property,
1080 + drmModeAtomicCommit(sink->fd, m_req, DRM_MODE_ATOMIC_TEST_ONLY, 0);
1081 + drmModeAtomicCommit(sink->fd, m_req, DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_NONBLOCK, &waiting_for_flip);
1082 + drmModeAtomicFree(m_req);
1084 + while (waiting_for_flip) {
1086 + FD_SET(sink->fd, &fds);
1088 + err = select(sink->fd + 1, &fds, NULL, NULL, NULL);
1090 + GST_ERROR_OBJECT (sink,"select err: %s\n", strerror(errno));
1091 + flow_ret = GST_FLOW_ERROR;
1094 + if (FD_ISSET(sink->fd, &fds)) {
1095 + drmHandleEvent(sink->fd, &evctx);
1099 + display_bufs_queue (sink, buf);
1102 + GST_INFO_OBJECT (sink, "exit");
1104 + gst_buffer_unref (buf);
1105 + g_mutex_unlock (&sink->render_lock);
1109 + GST_ELEMENT_ERROR (sink, RESOURCE, FAILED,
1110 + (NULL), ("drmModeAddFB2 failed: %s (%d)", strerror (errno), errno));
1111 + flow_ret = GST_FLOW_ERROR;
1115 + GST_ELEMENT_ERROR (sink, RESOURCE, FAILED,
1116 + (NULL), ("drmModeSetPlane failed: %s (%d)", strerror (errno), errno));
1117 + flow_ret = GST_FLOW_ERROR;
1120 +connector_not_found:
1121 + GST_ELEMENT_ERROR (sink, RESOURCE, NOT_FOUND,
1122 + (NULL), ("connector not found", strerror (errno), errno));
1128 +gst_kms_sink_event (GstBaseSink * bsink, GstEvent * event)
1130 + GstKMSSink *sink = GST_KMS_SINK (bsink);
1132 + switch (GST_EVENT_TYPE (event)) {
1136 + if (GST_BASE_SINK_CLASS (gst_kms_sink_parent_class)->event)
1137 + return GST_BASE_SINK_CLASS (gst_kms_sink_parent_class)->event (bsink,
1144 +gst_kms_sink_set_property (GObject * object, guint prop_id,
1145 + const GValue * value, GParamSpec * pspec)
1149 + g_return_if_fail (GST_IS_KMS_SINK (object));
1151 + sink = GST_KMS_SINK (object);
1153 + switch (prop_id) {
1154 + case PROP_FORCE_ASPECT_RATIO:
1155 + sink->keep_aspect = g_value_get_boolean (value);
1158 + sink->scale = g_value_get_boolean (value);
1160 + case PROP_CONNECTOR:
1161 + sink->conn_id = g_value_get_uint (value);
1163 + case PROP_CONNECTOR_NAME:
1164 + g_free (sink->conn_name);
1165 + sink->conn_name = g_strdup (g_value_get_string (value));
1167 + case PROP_PIXEL_ASPECT_RATIO:
1171 + tmp = g_new0 (GValue, 1);
1172 + g_value_init (tmp, GST_TYPE_FRACTION);
1174 + if (!g_value_transform (value, tmp)) {
1175 + GST_WARNING_OBJECT (sink, "Could not transform string to aspect ratio");
1177 + sink->par_n = gst_value_get_fraction_numerator (tmp);
1178 + sink->par_d = gst_value_get_fraction_denominator (tmp);
1179 + GST_DEBUG_OBJECT (sink, "set PAR to %d/%d", sink->par_n, sink->par_d);
1185 + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1191 +gst_kms_sink_get_property (GObject * object, guint prop_id,
1192 + GValue * value, GParamSpec * pspec)
1196 + g_return_if_fail (GST_IS_KMS_SINK (object));
1198 + sink = GST_KMS_SINK (object);
1200 + switch (prop_id) {
1201 + case PROP_FORCE_ASPECT_RATIO:
1202 + g_value_set_boolean (value, sink->keep_aspect);
1205 + g_value_set_boolean (value, sink->scale);
1207 + case PROP_CONNECTOR:
1208 + g_value_set_uint (value, sink->conn.id);
1210 + case PROP_PIXEL_ASPECT_RATIO:
1212 + char *v = g_strdup_printf ("%d/%d", sink->par_n, sink->par_d);
1213 + g_value_take_string (value, v);
1217 + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1223 +gst_kms_sink_reset (GstKMSSink * sink)
1225 + GST_DEBUG_OBJECT (sink, "reset");
1227 + if (sink->fd != -1) {
1228 + gst_drm_connector_cleanup (sink->fd, &sink->conn);
1230 + memset (&sink->conn, 0, sizeof (struct connector));
1232 + display_bufs_free (sink);
1235 + gst_buffer_pool_set_active (GST_BUFFER_POOL(sink->pool), FALSE);
1236 + gst_object_unref(sink->pool);
1237 + sink->pool = NULL;
1240 + if (sink->plane_resources) {
1241 + drmModeFreePlaneResources (sink->plane_resources);
1242 + sink->plane_resources = NULL;
1245 + if (sink->resources) {
1246 + drmModeFreeResources (sink->resources);
1247 + sink->resources = NULL;
1250 + sink->par_n = sink->par_d = 1;
1251 + sink->src_rect.x = 0;
1252 + sink->src_rect.y = 0;
1253 + sink->src_rect.w = 0;
1254 + sink->src_rect.h = 0;
1255 + sink->input_width = 0;
1256 + sink->input_height = 0;
1257 + sink->format = GST_VIDEO_FORMAT_UNKNOWN;
1259 + memset (&sink->src_rect, 0, sizeof (GstVideoRectangle));
1260 + memset (&sink->dst_rect, 0, sizeof (GstVideoRectangle));
1264 +gst_kms_sink_start (GstBaseSink * bsink)
1268 + sink = GST_KMS_SINK (bsink);
1270 + drm_dev = dce_init ();
1271 + if (drm_dev == NULL)
1272 + goto device_failed;
1274 + sink->dev = drm_dev;
1275 + sink->fd = dce_get_fd ();
1276 + drm_fd = dce_get_fd ();
1279 + sink->resources = drmModeGetResources (sink->fd);
1280 + if (sink->resources == NULL)
1281 + goto resources_failed;
1283 + sink->plane_resources = drmModeGetPlaneResources (sink->fd);
1284 + if (sink->plane_resources == NULL)
1285 + goto plane_resources_failed;
1290 + gst_kms_sink_reset (sink);
1294 + GST_ELEMENT_ERROR (sink, RESOURCE, FAILED,
1295 + (NULL), ("omap_device_new failed"));
1299 + GST_ELEMENT_ERROR (sink, RESOURCE, FAILED,
1300 + (NULL), ("drmModeGetResources failed: %s (%d)", strerror (errno), errno));
1303 +plane_resources_failed:
1304 + GST_ELEMENT_ERROR (sink, RESOURCE, FAILED,
1305 + (NULL), ("drmModeGetPlaneResources failed: %s (%d)",
1306 + strerror (errno), errno));
1311 +gst_kms_sink_stop (GstBaseSink * bsink)
1315 + sink = GST_KMS_SINK (bsink);
1316 + gst_kms_sink_reset (sink);
1323 +gst_kms_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
1326 + GstStructure *conf;
1329 + gboolean need_pool;
1331 + int num_buffers = 0;
1334 + sink = GST_KMS_SINK (bsink);
1336 + GST_DEBUG_OBJECT (sink, "begin");
1338 + gst_query_parse_allocation (query, &caps, &need_pool);
1340 + if (G_UNLIKELY (!caps)) {
1341 + GST_WARNING_OBJECT (sink, "have no caps, doing fallback allocation");
1346 + GstVideoInfo info;
1348 + if (!gst_video_info_from_caps (&info, caps))
1349 + goto invalid_caps;
1351 + GST_LOG_OBJECT (sink,
1352 + "a bufferpool was requested with caps %" GST_PTR_FORMAT, caps);
1354 + /* We already have a pool after set_caps */
1356 + GstStructure *config;
1358 + config = gst_buffer_pool_get_config (sink->pool);
1359 + gst_buffer_pool_config_get_params (config, NULL, &size, &min, &max);
1360 + gst_structure_free (config);
1362 + gst_query_add_allocation_pool (query, sink->pool, size, min, max);
1363 + gst_query_add_allocation_param (query, gst_drm_allocator_get (), NULL);
1366 + GST_LOG_OBJECT (sink, "No bufferpool available");
1373 + GST_DEBUG_OBJECT (sink, "invalid caps specified");
1378 +gst_kms_sink_finalize (GObject * object)
1382 + sink = GST_KMS_SINK (object);
1383 + g_mutex_clear (&sink->render_lock);
1384 + g_free (sink->conn_name);
1385 + if (sink->kmsbufferpriv){
1386 + g_hash_table_destroy (sink->kmsbufferpriv);
1387 + sink->kmsbufferpriv = NULL;
1388 + gst_kms_sink_reset (sink);
1391 + G_OBJECT_CLASS (gst_kms_sink_parent_class)->finalize (object);
1395 +kmsbufferpriv_free_func (GstKMSBufferPriv *priv)
1397 + drmModeRmFB (priv->fd, priv->fb_id);
1398 + omap_bo_del (priv->bo);
1404 +gst_kms_sink_init (GstKMSSink * sink)
1407 + gst_kms_sink_reset (sink);
1408 + sink->kmsbufferpriv = g_hash_table_new_full (g_direct_hash, g_direct_equal,
1409 + NULL, (GDestroyNotify) kmsbufferpriv_free_func);
1410 + g_mutex_init (&sink->render_lock);
1414 +gst_kms_sink_class_init (GstKMSSinkClass * klass)
1416 + GObjectClass *gobject_class;
1417 + GstElementClass *gstelement_class;
1418 + GstBaseSinkClass *gstbasesink_class;
1419 + GstVideoSinkClass *videosink_class;
1421 + gobject_class = (GObjectClass *) klass;
1422 + gstelement_class = (GstElementClass *) klass;
1423 + gstbasesink_class = (GstBaseSinkClass *) klass;
1424 + videosink_class = (GstVideoSinkClass *) klass;
1426 + gobject_class->finalize = gst_kms_sink_finalize;
1427 + gobject_class->set_property = gst_kms_sink_set_property;
1428 + gobject_class->get_property = gst_kms_sink_get_property;
1430 + g_object_class_install_property (gobject_class, PROP_FORCE_ASPECT_RATIO,
1431 + g_param_spec_boolean ("force-aspect-ratio", "Force aspect ratio",
1432 + "When enabled, reverse caps negotiation (scaling) will respect "
1433 + "original aspect ratio", FALSE,
1434 + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1435 + g_object_class_install_property (gobject_class, PROP_PIXEL_ASPECT_RATIO,
1436 + g_param_spec_string ("pixel-aspect-ratio", "Pixel Aspect Ratio",
1437 + "The pixel aspect ratio of the device", "1/1",
1438 + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1439 + g_object_class_install_property (gobject_class, PROP_SCALE,
1440 + g_param_spec_boolean ("scale", "Scale",
1441 + "When true, scale to render fullscreen", FALSE,
1442 + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1443 + g_object_class_install_property (gobject_class, PROP_CONNECTOR,
1444 + g_param_spec_uint ("connector", "Connector",
1445 + "DRM connector id (0 for automatic selection)", 0, G_MAXUINT32, 0,
1446 + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT));
1447 + g_object_class_install_property (gobject_class, PROP_CONNECTOR_NAME,
1448 + g_param_spec_string ("connector-name", "Connector name",
1449 + "DRM connector name (alternative to the connector property, "
1450 + "use $type$index, $type-$index, or $type)", "",
1451 + G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
1453 + gst_element_class_set_details_simple (gstelement_class,
1454 + "Video sink", "Sink/Video",
1455 + "A video sink using the linux kernel mode setting API",
1456 + "Alessandro Decina <alessandro.d@gmail.com>");
1458 + gst_element_class_add_pad_template (gstelement_class,
1459 + gst_static_pad_template_get (&gst_kms_sink_template_factory));
1461 + gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_kms_sink_setcaps);
1462 + gstbasesink_class->get_times = GST_DEBUG_FUNCPTR (gst_kms_sink_get_times);
1463 + gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_kms_sink_event);
1464 + gstbasesink_class->start = GST_DEBUG_FUNCPTR (gst_kms_sink_start);
1465 + gstbasesink_class->stop = GST_DEBUG_FUNCPTR (gst_kms_sink_stop);
1466 + gstbasesink_class->propose_allocation = GST_DEBUG_FUNCPTR (gst_kms_sink_propose_allocation);
1468 + /* disable preroll as it's called before GST_CROP_EVENT has been received, so
1469 + * we end up configuring the wrong mode... (based on padded caps)
1471 + gstbasesink_class->preroll = NULL;
1472 + videosink_class->show_frame = GST_DEBUG_FUNCPTR (gst_kms_sink_show_frame);
1476 +plugin_init (GstPlugin * plugin)
1478 + if (!gst_element_register (plugin, "kmssink",
1479 + GST_RANK_PRIMARY + 1, GST_TYPE_KMS_SINK))
1482 + GST_DEBUG_CATEGORY_INIT (gst_debug_kms_sink, "kmssink", 0, "kmssink element");
1487 +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1488 + GST_VERSION_MINOR,
1490 + "KMS video output element",
1491 + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
1492 diff --git a/sys/kms/gstkmssink.h b/sys/kms/gstkmssink.h
1493 new file mode 100644
1494 index 0000000..9f76839
1496 +++ b/sys/kms/gstkmssink.h
1500 + * Copyright (C) 2012 Texas Instruments
1501 + * Copyright (C) 2012 Collabora Ltd
1504 + * Alessandro Decina <alessandro.decina@collabora.co.uk>
1506 + * This library is free software; you can redistribute it and/or
1507 + * modify it under the terms of the GNU Library General Public
1508 + * License as published by the Free Software Foundation; either
1509 + * version 2 of the License, or (at your option) any later version.
1511 + * This library is distributed in the hope that it will be useful,
1512 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1513 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1514 + * Library General Public License for more details.
1516 + * You should have received a copy of the GNU Library General Public
1517 + * License along with this library; if not, write to the
1518 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1519 + * Boston, MA 02111-1307, USA.
1522 +#ifndef __GST_KMS_SINK_H__
1523 +#define __GST_KMS_SINK_H__
1525 +#include <gst/video/video.h>
1526 +#include <gst/video/gstvideosink.h>
1527 +#include <gst/drm/gstdrmallocator.h>
1530 +#include <stdint.h>
1531 +#include <stdlib.h>
1532 +#include <string.h>
1534 +#include <unistd.h>
1535 +#include <assert.h>
1537 +#include "gstdrmutils.h"
1540 +#define GST_TYPE_KMS_SINK \
1541 + (gst_kms_sink_get_type())
1542 +#define GST_KMS_SINK(obj) \
1543 + (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_KMS_SINK, GstKMSSink))
1544 +#define GST_KMS_SINK_CLASS(klass) \
1545 + (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_KMS_SINK, GstKMSSinkClass))
1546 +#define GST_IS_KMS_SINK(obj) \
1547 + (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_KMS_SINK))
1548 +#define GST_IS_KMS_SINK_CLASS(klass) \
1549 + (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_KMS_SINK))
1550 +typedef struct _GstKMSSink GstKMSSink;
1551 +typedef struct _GstKMSSinkClass GstKMSSinkClass;
1553 +#define NUM_DISPLAY_BUFS 1
1557 + GstVideoSink videosink;
1558 + gint input_width, input_height;
1559 + GstVideoFormat format;
1560 + gint par_n, par_d;
1561 + gint fps_n, fps_d;
1562 + gboolean keep_aspect;
1563 + GstVideoRectangle src_rect;
1564 + GstVideoRectangle dst_rect;
1566 + struct omap_device *dev;
1567 + drmModeRes *resources;
1568 + drmModePlaneRes *plane_resources;
1569 + struct connector conn;
1572 + drmModePlane *plane;
1573 + GstBufferPool *pool;
1574 + GHashTable *kmsbufferpriv;
1575 + /* current displayed buffer and last displayed buffer: */
1576 + GstBuffer *display_bufs[NUM_DISPLAY_BUFS];
1578 + GMutex render_lock;
1581 +struct _GstKMSSinkClass
1583 + GstVideoSinkClass parent_class;
1586 +GType gst_kms_sink_get_type (void);
1589 +#endif /* __GST_KMS_SINK_H__ */