1 /* GStreamer DirectFB plugin
2 * Copyright (C) 2005 Julien MOUTTE <julien@moutte.net>
3 * Copyright (C) 2013 Kazunori Kobayashi <kkobayas@igel.co.jp>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 * SECTION:element-dfbvideosink
24 * DfbVideoSink renders video frames using the
25 * <ulink url="http://www.directfb.org/">DirectFB</ulink> library.
26 * Rendering can happen in two different modes :
30 * Standalone: this mode will take complete control of the monitor forcing
31 * <ulink url="http://www.directfb.org/">DirectFB</ulink> to fullscreen layout.
32 * This is convenient to test using the gst-launch command line tool or
33 * other simple applications. It is possible to interrupt playback while
34 * being in this mode by pressing the Escape key.
37 * This mode handles navigation events for every input device supported by
38 * the <ulink url="http://www.directfb.org/">DirectFB</ulink> library, it will
39 * look for available video modes in the fb.modes file and try to switch
40 * the framebuffer video mode to the most suitable one. Depending on
41 * hardware acceleration capabilities the element will handle scaling or not.
42 * If no acceleration is available it will do clipping or centering of the
43 * video frames respecting the original aspect ratio.
48 * Embedded: this mode will render video frames in a
49 * #GstDfbVideoSink:surface provided by the
50 * application developer. This is a more advanced usage of the element and
51 * it is required to integrate video playback in existing
52 * <ulink url="http://www.directfb.org/">DirectFB</ulink> applications.
55 * When using this mode the element just renders to the
56 * #GstDfbVideoSink:surface provided by the
57 * application, that means it won't handle navigation events and won't resize
58 * the #GstDfbVideoSink:surface to fit video
59 * frames geometry. Application has to implement the necessary code to grab
60 * informations about the negotiated geometry and resize there
61 * #GstDfbVideoSink:surface accordingly.
65 * For both modes the element implements a buffer pool allocation system to
66 * optimize memory allocation time and handle reverse negotiation. Indeed if
67 * you insert an element like videoscale in the pipeline the video sink will
68 * negotiate with it to try get a scaled video for either the fullscreen layout
69 * or the application provided external #GstDfbVideoSink:surface.
72 * <title>Example application</title>
74 * <include xmlns="http://www.w3.org/2003/XInclude" href="element-dfb-example.xml" />
78 * <title>Example pipelines</title>
80 * gst-launch -v videotestsrc ! dfbvideosink hue=20000 saturation=40000 brightness=25000
81 * ]| test the colorbalance interface implementation in dfbvideosink
89 #include <gst/video/video.h>
92 #include "dfbvideosink.h"
97 /* Debugging category */
98 GST_DEBUG_CATEGORY_STATIC (dfbvideosink_debug);
99 #define GST_CAT_DEFAULT dfbvideosink_debug
101 /* Default template */
102 static GstStaticPadTemplate gst_dfbvideosink_sink_template_factory =
103 GST_STATIC_PAD_TEMPLATE ("sink",
106 GST_STATIC_CAPS ("video/x-raw, "
107 "framerate = (fraction) [ 0, MAX ], "
108 "width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ]")
111 /* Signals and args */
120 ARG_PIXEL_ASPECT_RATIO,
125 #define DEFAULT_LAYER_MODE LAYER_MODE_EXCLUSIVE
127 static DFBSurfacePixelFormat gst_dfbvideosink_get_format_from_caps (GstCaps *
129 static void gst_dfbvideosink_update_colorbalance (GstDfbVideoSink *
131 static void gst_dfbvideosink_navigation_init (GstNavigationInterface * iface);
132 static void gst_dfbvideosink_colorbalance_init (GstColorBalanceInterface
134 static const char *gst_dfbvideosink_get_format_name (DFBSurfacePixelFormat
137 #define gst_dfbvideosink_parent_class parent_class
140 gst_dfbvideosink_layer_mode_get_type (void)
143 static const GEnumValue values[] = {
145 {DLSCL_EXCLUSIVE, "DLSCL_EXCLUSIVE", "exclusive"},
146 {DLSCL_ADMINISTRATIVE, "DLSCL_ADMINISTRATIVE", "administrative"},
150 if (g_once_init_enter (&id)) {
151 GType tmp = g_enum_register_static ("GstDfbVideoSinkLayerMode", values);
152 g_once_init_leave (&id, tmp);
159 gst_meta_dfbsurface_api_get_type (void)
161 static volatile GType type;
162 static const gchar *tags[] = { "memory", NULL };
164 if (g_once_init_enter (&type)) {
165 GType _type = gst_meta_api_type_register ("GstMetaDfbSurfaceAPI", tags);
166 g_once_init_leave (&type, _type);
173 gst_meta_dfbsurface_get_info (void)
175 static const GstMetaInfo *meta_info = NULL;
177 if (g_once_init_enter (&meta_info)) {
178 const GstMetaInfo *meta =
179 gst_meta_register (gst_meta_dfbsurface_api_get_type (),
180 "GstMetaDfbSurface", sizeof (GstMetaDfbSurface),
181 (GstMetaInitFunction) NULL, (GstMetaFreeFunction) NULL,
182 (GstMetaTransformFunction) NULL);
183 g_once_init_leave (&meta_info, meta);
188 G_DEFINE_TYPE (GstDfbBufferPool, gst_dfb_buffer_pool, GST_TYPE_BUFFER_POOL);
191 gst_dfb_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
193 GstDfbBufferPool *dfbpool = GST_DFB_BUFFER_POOL_CAST (pool);
195 DFBSurfacePixelFormat pixel_format = DSPF_UNKNOWN;
198 DFBSurfaceDescription s_dsc;
199 IDirectFBSurface *surface;
207 if (!dfbpool->dfbvideosink->setup) {
208 GST_WARNING_OBJECT (pool, "DirectFB hasn't been initialized yet.");
212 if (!gst_buffer_pool_config_get_params (config, &caps, NULL, &min_buffers,
214 GST_WARNING_OBJECT (pool, "invalid config");
218 pixel_format = gst_dfbvideosink_get_format_from_caps (caps);
220 if (!gst_video_info_from_caps (&info, caps)) {
221 GST_WARNING_OBJECT (pool, "failed getting video info from caps %"
222 GST_PTR_FORMAT, caps);
226 width = GST_VIDEO_INFO_WIDTH (&info);
227 height = GST_VIDEO_INFO_HEIGHT (&info);
229 /* temporarily create a surface to get the pitch */
230 s_dsc.flags = DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_HEIGHT;
231 s_dsc.pixelformat = pixel_format;
233 s_dsc.height = height;
235 ret = dfbpool->dfbvideosink->dfb->CreateSurface (dfbpool->dfbvideosink->dfb,
238 GST_WARNING_OBJECT (pool, "failed creating surface with format %s",
239 gst_dfbvideosink_get_format_name (pixel_format));
243 ret = surface->Lock (surface, DSLF_READ, &data, &pitch);
245 GST_WARNING_OBJECT (pool, "failed locking the surface");
246 surface->Release (surface);
249 surface->Unlock (surface);
250 surface->Release (surface);
252 switch (GST_VIDEO_INFO_FORMAT (&info)) {
253 case GST_VIDEO_FORMAT_I420:
254 case GST_VIDEO_FORMAT_YV12:
255 case GST_VIDEO_FORMAT_NV12:
256 size = pitch * height * 3 / 2;
259 size = pitch * height;
263 gst_buffer_pool_config_set_params (config, caps, size, min_buffers,
266 dfbpool->caps = gst_caps_ref (caps);
268 return GST_BUFFER_POOL_CLASS (gst_dfb_buffer_pool_parent_class)->set_config
273 gst_dfb_buffer_pool_free_buffer (GstBufferPool * bpool, GstBuffer * surface)
275 GstMetaDfbSurface *meta;
277 meta = GST_META_DFBSURFACE_GET (surface);
279 /* Release our internal surface */
282 meta->surface->Unlock (meta->surface);
283 meta->locked = FALSE;
285 meta->surface->Release (meta->surface);
288 if (meta->dfbvideosink)
289 /* Release the ref to our sink */
290 gst_object_unref (meta->dfbvideosink);
292 GST_BUFFER_POOL_CLASS (gst_dfb_buffer_pool_parent_class)->free_buffer (bpool,
297 gst_dfb_buffer_pool_alloc_buffer (GstBufferPool * bpool,
298 GstBuffer ** buffer, GstBufferPoolAcquireParams * params)
300 GstDfbBufferPool *dfbpool = GST_DFB_BUFFER_POOL_CAST (bpool);
302 GstMetaDfbSurface *meta;
303 GstStructure *structure;
305 DFBSurfaceDescription s_dsc;
308 GstFlowReturn result = GST_FLOW_ERROR;
310 gsize offset[GST_VIDEO_MAX_PLANES] = { 0 };
311 gint stride[GST_VIDEO_MAX_PLANES] = { 0 };
313 gsize plane_size[GST_VIDEO_MAX_PLANES] = { 0 };
316 GstVideoFormat format;
319 surface = gst_buffer_new ();
320 meta = GST_META_DFBSURFACE_ADD (surface);
322 /* Keep a ref to our sink */
323 meta->dfbvideosink = gst_object_ref (dfbpool->dfbvideosink);
324 /* Surface is not locked yet */
325 meta->locked = FALSE;
327 structure = gst_caps_get_structure (dfbpool->caps, 0);
329 if (!gst_structure_get_int (structure, "width", &meta->width) ||
330 !gst_structure_get_int (structure, "height", &meta->height)) {
331 GST_WARNING_OBJECT (bpool, "failed getting geometry from caps %"
332 GST_PTR_FORMAT, dfbpool->caps);
336 /* Pixel format from caps */
337 meta->pixel_format = gst_dfbvideosink_get_format_from_caps (dfbpool->caps);
338 if (meta->pixel_format == DSPF_UNKNOWN) {
342 if (!dfbpool->dfbvideosink->dfb) {
343 GST_DEBUG_OBJECT (bpool, "no DirectFB context to create a surface");
347 /* Creating an internal surface which will be used as GstBuffer, we used
348 the detected pixel format and video dimensions */
350 s_dsc.flags = DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_HEIGHT;
352 s_dsc.pixelformat = meta->pixel_format;
353 s_dsc.width = meta->width;
354 s_dsc.height = meta->height;
357 dfbpool->dfbvideosink->dfb->CreateSurface (dfbpool->dfbvideosink->dfb,
358 &s_dsc, &meta->surface);
360 GST_WARNING_OBJECT (bpool, "failed creating a DirectFB surface");
361 meta->surface = NULL;
365 /* Clearing surface */
366 meta->surface->Clear (meta->surface, 0x00, 0x00, 0x00, 0xFF);
368 /* Locking the surface to acquire the memory pointer */
369 meta->surface->Lock (meta->surface, DSLF_WRITE, &data, &pitch);
372 GST_DEBUG_OBJECT (bpool, "creating a %dx%d surface (%p) with %s "
373 "pixel format, line pitch %d", meta->width, meta->height, surface,
374 gst_dfbvideosink_get_format_name (meta->pixel_format), pitch);
376 structure = gst_caps_get_structure (dfbpool->caps, 0);
377 str = gst_structure_get_string (structure, "format");
379 GST_WARNING ("failed grabbing fourcc from caps %" GST_PTR_FORMAT,
381 return GST_FLOW_ERROR;
384 format = gst_video_format_from_string (str);
386 case GST_VIDEO_FORMAT_I420:
387 case GST_VIDEO_FORMAT_YV12:
388 offset[1] = pitch * meta->height;
389 offset[2] = offset[1] + pitch / 2 * meta->height / 2;
391 stride[1] = stride[2] = pitch / 2;
393 plane_size[0] = offset[1];
394 plane_size[1] = plane_size[2] = plane_size[0] / 4;
395 max_size = plane_size[0] * 3 / 2;
398 case GST_VIDEO_FORMAT_NV12:
399 offset[1] = pitch * meta->height;
400 stride[0] = stride[1] = pitch;
402 plane_size[0] = offset[1];
403 plane_size[1] = pitch * meta->height / 2;
404 max_size = plane_size[0] * 3 / 2;
409 plane_size[0] = max_size = pitch * meta->height;
414 for (i = 0; i < n_planes; i++) {
415 gst_buffer_append_memory (surface,
416 gst_memory_new_wrapped (0, data, max_size, offset[i], plane_size[i],
420 gst_buffer_add_video_meta_full (surface, GST_VIDEO_FRAME_FLAG_NONE,
421 format, meta->width, meta->height, n_planes, offset, stride);
423 result = GST_FLOW_OK;
429 /* We allocate a standard buffer ourselves to store it in our buffer pool,
430 this is an optimisation for memory allocation */
431 alloc_size = meta->width * meta->height;
432 surface = gst_buffer_new_allocate (NULL, alloc_size, NULL);
433 if (surface == NULL) {
434 GST_WARNING_OBJECT (bpool, "failed allocating a gstbuffer");
440 meta->surface->Unlock (meta->surface);
441 meta->locked = FALSE;
443 meta->surface->Release (meta->surface);
444 meta->surface = NULL;
446 GST_DEBUG_OBJECT (bpool, "allocating a buffer (%p) of %u bytes",
447 surface, (guint) alloc_size);
449 result = GST_FLOW_OK;
452 if (result != GST_FLOW_OK) {
453 gst_dfb_buffer_pool_free_buffer (bpool, surface);
461 static GstBufferPool *
462 gst_dfb_buffer_pool_new (GstDfbVideoSink * dfbvideosink)
464 GstDfbBufferPool *pool;
466 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), NULL);
468 pool = g_object_new (GST_TYPE_DFB_BUFFER_POOL, NULL);
469 pool->dfbvideosink = gst_object_ref (dfbvideosink);
471 GST_LOG_OBJECT (pool, "new dfb buffer pool %p", pool);
473 return GST_BUFFER_POOL_CAST (pool);
477 gst_dfb_buffer_pool_finalize (GObject * object)
479 GstDfbBufferPool *pool = GST_DFB_BUFFER_POOL_CAST (object);
482 gst_caps_unref (pool->caps);
483 gst_object_unref (pool->dfbvideosink);
485 G_OBJECT_CLASS (gst_dfb_buffer_pool_parent_class)->finalize (object);
489 gst_dfb_buffer_pool_init (GstDfbBufferPool * pool)
495 gst_dfb_buffer_pool_class_init (GstDfbBufferPoolClass * klass)
497 GObjectClass *gobject_class = (GObjectClass *) klass;
498 GstBufferPoolClass *gstbufferpool_class = (GstBufferPoolClass *) klass;
500 gobject_class->finalize = gst_dfb_buffer_pool_finalize;
502 gstbufferpool_class->alloc_buffer = gst_dfb_buffer_pool_alloc_buffer;
503 gstbufferpool_class->set_config = gst_dfb_buffer_pool_set_config;
504 gstbufferpool_class->free_buffer = gst_dfb_buffer_pool_free_buffer;
507 G_DEFINE_TYPE_WITH_CODE (GstDfbVideoSink, gst_dfbvideosink, GST_TYPE_VIDEO_SINK,
508 G_IMPLEMENT_INTERFACE (GST_TYPE_NAVIGATION,
509 gst_dfbvideosink_navigation_init);
510 G_IMPLEMENT_INTERFACE (GST_TYPE_COLOR_BALANCE,
511 gst_dfbvideosink_colorbalance_init));
513 #ifndef GST_DISABLE_GST_DEBUG
515 gst_dfbvideosink_get_format_name (DFBSurfacePixelFormat format)
562 #endif /* GST_DISABLE_GST_DEBUG */
565 gst_dfbvideosink_event_thread (GstDfbVideoSink * dfbvideosink)
569 while (dfbvideosink->running) {
570 /* Wait for an event with a 50 ms timeout */
571 dfbvideosink->event_buffer->WaitForEventWithTimeout (dfbvideosink->
572 event_buffer, 0, 50);
574 /* Do we have an event ? */
575 ret = dfbvideosink->event_buffer->HasEvent (dfbvideosink->event_buffer);
580 GST_DEBUG_OBJECT (dfbvideosink, "we have an event");
582 ret = dfbvideosink->event_buffer->GetEvent (dfbvideosink->event_buffer,
584 if (ret != DFB_OK) { /* Error */
585 GST_WARNING_OBJECT (dfbvideosink, "failed when getting event from "
587 } else { /* Handle event */
588 if (event.input.type == DIET_KEYPRESS) {
589 switch (event.input.key_symbol) {
592 GST_ELEMENT_ERROR (dfbvideosink, RESOURCE, OPEN_WRITE,
593 ("Video output device is gone."),
594 ("We were running fullscreen and user "
595 "pressed the ESC key, stopping playback."));
598 GST_DEBUG_OBJECT (dfbvideosink, "key press event %c !",
599 event.input.key_symbol);
600 gst_navigation_send_key_event (GST_NAVIGATION (dfbvideosink),
601 "key-press", "prout");
603 } else if (event.input.type == DIET_BUTTONPRESS) {
606 dfbvideosink->layer->GetCursorPosition (dfbvideosink->layer, &x, &y);
608 GST_DEBUG_OBJECT (dfbvideosink, "button %d pressed at %dx%d",
609 event.input.button, x, y);
611 gst_navigation_send_mouse_event (GST_NAVIGATION (dfbvideosink),
612 "mouse-button-press", event.input.button, x, y);
613 } else if (event.input.type == DIET_BUTTONRELEASE) {
616 dfbvideosink->layer->GetCursorPosition (dfbvideosink->layer, &x, &y);
618 GST_DEBUG_OBJECT (dfbvideosink, "button %d released at %dx%d",
619 event.input.button, x, y);
621 gst_navigation_send_mouse_event (GST_NAVIGATION (dfbvideosink),
622 "mouse-button-release", event.input.button, x, y);
623 } else if (event.input.type == DIET_AXISMOTION) {
626 dfbvideosink->layer->GetCursorPosition (dfbvideosink->layer, &x, &y);
627 gst_navigation_send_mouse_event (GST_NAVIGATION (dfbvideosink),
628 "mouse-move", 0, x, y);
630 GST_WARNING_OBJECT (dfbvideosink, "unhandled event type %d",
639 static DFBEnumerationResult
640 gst_dfbvideosink_enum_layers (DFBDisplayLayerID id,
641 DFBDisplayLayerDescription desc, void *data)
643 GstDfbVideoSink *dfbvideosink = NULL;
644 IDirectFBDisplayLayer *layer = NULL;
645 DFBDisplayLayerConfig dlc;
647 gboolean backbuffer = FALSE;
649 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (data), DFENUM_CANCEL);
651 dfbvideosink = GST_DFBVIDEOSINK (data);
653 GST_DEBUG_OBJECT (dfbvideosink, "inspecting display layer %d with name: %s",
656 if ((desc.type & DLTF_VIDEO) && (desc.caps & DLCAPS_SURFACE)) {
657 GST_DEBUG_OBJECT (dfbvideosink,
658 "this layer can handle live video and has a surface");
660 if (desc.caps & DLCAPS_SURFACE) {
661 GST_DEBUG_OBJECT (dfbvideosink,
662 "this layer can not handle live video but has a surface");
664 GST_DEBUG_OBJECT (dfbvideosink, "no we can't use that layer, really...");
669 ret = dfbvideosink->dfb->GetDisplayLayer (dfbvideosink->dfb, id, &layer);
671 GST_WARNING_OBJECT (dfbvideosink, "failed getting display layer %s",
676 ret = layer->GetConfiguration (layer, &dlc);
678 GST_WARNING_OBJECT (dfbvideosink,
679 "failed getting display layer configuration");
683 if ((dlc.flags & DLCONF_BUFFERMODE) && (dlc.buffermode & DLBM_FRONTONLY)) {
684 GST_DEBUG_OBJECT (dfbvideosink, "no backbuffer");
686 if ((dlc.flags & DLCONF_BUFFERMODE) && (dlc.buffermode & DLBM_BACKVIDEO)) {
687 GST_DEBUG_OBJECT (dfbvideosink, "backbuffer is in video memory");
690 if ((dlc.flags & DLCONF_BUFFERMODE) && (dlc.buffermode & DLBM_BACKSYSTEM)) {
691 GST_DEBUG_OBJECT (dfbvideosink, "backbuffer is in system memory");
694 if ((dlc.flags & DLCONF_BUFFERMODE) && (dlc.buffermode & DLBM_TRIPLE)) {
695 GST_DEBUG_OBJECT (dfbvideosink, "triple buffering");
699 /* If the primary is suitable we prefer using it */
700 if (dfbvideosink->layer_id != DLID_PRIMARY) {
701 GST_DEBUG_OBJECT (dfbvideosink, "selecting layer named %s", desc.name);
702 dfbvideosink->layer_id = id;
703 dfbvideosink->backbuffer = backbuffer;
705 GST_DEBUG_OBJECT (dfbvideosink, "layer %s is suitable but the primary "
706 "is currently selected and we prefer that one", desc.name);
711 layer->Release (layer);
716 static DFBEnumerationResult
717 gst_dfbvideosink_enum_vmodes (gint width, gint height, gint bpp, void *data)
719 GstDfbVideoSink *dfbvideosink = NULL;
720 GstDfbVMode *vmode = NULL;
722 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (data), DFENUM_CANCEL);
724 dfbvideosink = GST_DFBVIDEOSINK (data);
726 GST_DEBUG_OBJECT (dfbvideosink, "adding video mode %dx%d at %d bpp", width,
728 vmode = g_new0 (GstDfbVMode, 1);
729 vmode->width = width;
730 vmode->height = height;
733 /* We need to know the maximum video geometry we can accept for the caps */
734 if (width > dfbvideosink->out_width) {
735 dfbvideosink->out_width = width;
737 if (height > dfbvideosink->out_height) {
738 dfbvideosink->out_height = height;
741 dfbvideosink->vmodes = g_slist_append (dfbvideosink->vmodes, vmode);
746 static DFBEnumerationResult
747 gst_dfbvideosink_enum_devices (DFBInputDeviceID id,
748 DFBInputDeviceDescription desc, void *data)
750 GstDfbVideoSink *dfbvideosink = NULL;
751 IDirectFBInputDevice *device = NULL;
754 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (data), DFENUM_CANCEL);
756 dfbvideosink = GST_DFBVIDEOSINK (data);
758 GST_DEBUG_OBJECT (dfbvideosink, "detected input device %s from vendor %s",
759 desc.name, desc.vendor);
761 /* Get that input device */
762 ret = dfbvideosink->dfb->GetInputDevice (dfbvideosink->dfb, id, &device);
764 GST_WARNING_OBJECT (dfbvideosink, "failed when getting input device id %d",
769 ret = device->AttachEventBuffer (device, dfbvideosink->event_buffer);
771 GST_WARNING_OBJECT (dfbvideosink, "failed when attaching input device "
772 "%d to our event buffer", id);
777 device->Release (device);
783 gst_dfbvideosink_setup (GstDfbVideoSink * dfbvideosink)
787 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), FALSE);
789 dfbvideosink->video_width = 0;
790 dfbvideosink->video_height = 0;
791 dfbvideosink->out_width = 0;
792 dfbvideosink->out_height = 0;
793 dfbvideosink->fps_d = 0;
794 dfbvideosink->fps_n = 0;
795 dfbvideosink->hw_scaling = FALSE;
796 dfbvideosink->backbuffer = FALSE;
797 dfbvideosink->pixel_format = DSPF_UNKNOWN;
799 /* If we do it all by ourself we create the DirectFB context, get the
800 primary layer and use a fullscreen configuration */
801 if (!dfbvideosink->ext_surface) {
802 GST_DEBUG_OBJECT (dfbvideosink, "no external surface, taking over "
803 "DirectFB fullscreen");
804 if (!dfbvideosink->dfb) {
805 DFBGraphicsDeviceDescription hw_caps;
806 char *argv[] = { (char *) "-", (char *) "--dfb:quiet",
807 (char *) "--dfb:no-sighandler", NULL
812 GST_DEBUG_OBJECT (dfbvideosink, "initializing DirectFB");
815 ret = DirectFBInit (&argc, &args);
818 GST_WARNING_OBJECT (dfbvideosink, "DirectFB initialization failed");
822 ret = DirectFBCreate (&(dfbvideosink->dfb));
825 GST_WARNING_OBJECT (dfbvideosink, "failed creating the DirectFB "
830 /* Get Hardware capabilities */
831 ret = dfbvideosink->dfb->GetDeviceDescription (dfbvideosink->dfb,
835 GST_WARNING_OBJECT (dfbvideosink, "failed grabbing the hardware "
840 GST_DEBUG_OBJECT (dfbvideosink, "video card %s from vendor %s detected "
841 "with %d bytes of video memory", hw_caps.name, hw_caps.vendor,
842 hw_caps.video_memory);
844 if (hw_caps.acceleration_mask & DFXL_BLIT) {
845 GST_DEBUG_OBJECT (dfbvideosink, "Blit is accelerated");
847 if (hw_caps.acceleration_mask & DFXL_STRETCHBLIT) {
848 GST_DEBUG_OBJECT (dfbvideosink, "StretchBlit is accelerated");
849 dfbvideosink->hw_scaling = TRUE;
851 GST_DEBUG_OBJECT (dfbvideosink, "StretchBlit is not accelerated");
852 dfbvideosink->hw_scaling = FALSE;
855 dfbvideosink->layer_id = -1;
857 /* Inspect all the Display layers */
858 dfbvideosink->dfb->EnumDisplayLayers (dfbvideosink->dfb,
859 gst_dfbvideosink_enum_layers, dfbvideosink);
860 /* Inspect all Video modes */
861 dfbvideosink->dfb->EnumVideoModes (dfbvideosink->dfb,
862 gst_dfbvideosink_enum_vmodes, dfbvideosink);
864 /* Create an event buffer for input */
865 dfbvideosink->dfb->CreateEventBuffer (dfbvideosink->dfb,
866 &dfbvideosink->event_buffer);
868 /* Inspect all Input devices */
869 dfbvideosink->dfb->EnumInputDevices (dfbvideosink->dfb,
870 gst_dfbvideosink_enum_devices, dfbvideosink);
871 /* Create a thread to handle those events */
872 dfbvideosink->event_thread = g_thread_new ("dfbvsink-events",
873 (GThreadFunc) gst_dfbvideosink_event_thread, dfbvideosink);
875 if (!dfbvideosink->layer) {
876 GList *channels_list = NULL;
877 DFBDisplayLayerDescription dl_desc;
879 /* Get the best Display Layer */
880 ret = dfbvideosink->dfb->GetDisplayLayer (dfbvideosink->dfb,
881 dfbvideosink->layer_id, &dfbvideosink->layer);
883 GST_WARNING_OBJECT (dfbvideosink, "failed getting display layer");
887 if (dfbvideosink->layer_mode == LAYER_MODE_EXCLUSIVE ||
888 dfbvideosink->layer_mode == LAYER_MODE_ADMINISTRATIVE)
889 ret = dfbvideosink->layer->SetCooperativeLevel (dfbvideosink->layer,
890 dfbvideosink->layer_mode);
892 GST_ERROR_OBJECT (dfbvideosink, "invalid layer cooperative level");
897 GST_WARNING_OBJECT (dfbvideosink, "failed setting display layer to "
902 dfbvideosink->layer->GetDescription (dfbvideosink->layer, &dl_desc);
904 /* Check that this layer is able to do colorbalance settings */
905 if (dl_desc.caps & DLCAPS_BRIGHTNESS) {
906 channels_list = g_list_append (channels_list, (char *) "BRIGHTNESS");
908 if (dl_desc.caps & DLCAPS_CONTRAST) {
909 channels_list = g_list_append (channels_list, (char *) "CONTRAST");
911 if (dl_desc.caps & DLCAPS_HUE) {
912 channels_list = g_list_append (channels_list, (char *) "HUE");
914 if (dl_desc.caps & DLCAPS_SATURATION) {
915 channels_list = g_list_append (channels_list, (char *) "SATURATION");
919 GList *walk = channels_list;
921 /* Generate Color balance channel list */
923 GstColorBalanceChannel *channel = NULL;
925 GST_DEBUG_OBJECT (dfbvideosink, "adding %s as a colorbalance channel",
926 (const char *) walk->data);
928 channel = g_object_new (GST_TYPE_COLOR_BALANCE_CHANNEL, NULL);
929 channel->label = g_strdup (walk->data);
930 channel->min_value = 0x0000;
931 channel->max_value = 0xFFFF;
933 dfbvideosink->cb_channels = g_list_append (dfbvideosink->cb_channels,
936 walk = g_list_next (walk);
939 /* If the colorbalance settings have not been touched we get current
940 values as defaults and update our internal variables */
941 if (!dfbvideosink->cb_changed) {
942 DFBColorAdjustment cb_adjust;
944 ret = dfbvideosink->layer->GetColorAdjustment (dfbvideosink->layer,
948 GST_WARNING_OBJECT (dfbvideosink, "failed when getting color "
949 "adjustment from layer");
952 if (cb_adjust.flags & DCAF_BRIGHTNESS) {
953 dfbvideosink->brightness = cb_adjust.brightness;
955 dfbvideosink->brightness = 0x8000;
957 if (cb_adjust.flags & DCAF_CONTRAST) {
958 dfbvideosink->contrast = cb_adjust.contrast;
960 dfbvideosink->contrast = 0x8000;
962 if (cb_adjust.flags & DCAF_HUE) {
963 dfbvideosink->hue = cb_adjust.hue;
965 dfbvideosink->hue = 0x8000;
967 if (cb_adjust.flags & DCAF_SATURATION) {
968 dfbvideosink->saturation = cb_adjust.saturation;
970 dfbvideosink->saturation = 0x8000;
972 GST_DEBUG_OBJECT (dfbvideosink, "brightness %d, contrast %d, "
973 "hue %d, saturation %d", dfbvideosink->brightness,
974 dfbvideosink->contrast, dfbvideosink->hue,
975 dfbvideosink->saturation);
978 g_list_free (channels_list);
980 gst_dfbvideosink_update_colorbalance (dfbvideosink);
983 dfbvideosink->layer->SetBackgroundColor (dfbvideosink->layer,
984 0x00, 0x00, 0x00, 0xFF);
986 #if (DIRECTFB_VER >= GST_DFBVIDEOSINK_VER (1,6,0))
987 if (dfbvideosink->layer_mode == LAYER_MODE_ADMINISTRATIVE)
989 dfbvideosink->layer->EnableCursor (dfbvideosink->layer, TRUE);
991 GST_DEBUG_OBJECT (dfbvideosink, "getting primary surface");
992 dfbvideosink->layer->GetSurface (dfbvideosink->layer,
993 &dfbvideosink->primary);
995 dfbvideosink->primary->SetBlittingFlags (dfbvideosink->primary,
999 dfbvideosink->primary->GetPixelFormat (dfbvideosink->primary,
1000 &dfbvideosink->pixel_format);
1002 DFBSurfaceCapabilities s_caps;
1004 GST_DEBUG_OBJECT (dfbvideosink, "getting pixel format from foreign "
1005 "surface %p", dfbvideosink->ext_surface);
1006 dfbvideosink->ext_surface->GetPixelFormat (dfbvideosink->ext_surface,
1007 &dfbvideosink->pixel_format);
1008 dfbvideosink->ext_surface->GetSize (dfbvideosink->ext_surface,
1009 &dfbvideosink->out_width, &dfbvideosink->out_height);
1010 dfbvideosink->ext_surface->GetCapabilities (dfbvideosink->ext_surface,
1012 if ((s_caps & DSCAPS_DOUBLE) || (s_caps & DSCAPS_TRIPLE)) {
1013 dfbvideosink->backbuffer = TRUE;
1015 dfbvideosink->backbuffer = FALSE;
1017 GST_DEBUG_OBJECT (dfbvideosink, "external surface is %dx%d and uses %s "
1018 "pixel format", dfbvideosink->out_width, dfbvideosink->out_height,
1019 gst_dfbvideosink_get_format_name (dfbvideosink->pixel_format));
1022 dfbvideosink->setup = TRUE;
1025 return dfbvideosink->setup;
1029 gst_dfbvideosink_cleanup (GstDfbVideoSink * dfbvideosink)
1031 g_return_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink));
1033 GST_DEBUG_OBJECT (dfbvideosink, "cleaning up DirectFB environment");
1035 /* Wait for our event thread */
1036 if (dfbvideosink->event_thread) {
1037 g_thread_join (dfbvideosink->event_thread);
1038 dfbvideosink->event_thread = NULL;
1041 if (dfbvideosink->event_buffer) {
1042 dfbvideosink->event_buffer->Release (dfbvideosink->event_buffer);
1043 dfbvideosink->event_buffer = NULL;
1046 if (dfbvideosink->vmodes) {
1047 GSList *walk = dfbvideosink->vmodes;
1050 g_free (walk->data);
1051 walk = g_slist_next (walk);
1053 g_slist_free (dfbvideosink->vmodes);
1054 dfbvideosink->vmodes = NULL;
1057 if (dfbvideosink->cb_channels) {
1058 GList *walk = dfbvideosink->cb_channels;
1061 GstColorBalanceChannel *channel = walk->data;
1063 g_object_unref (channel);
1064 walk = g_list_next (walk);
1066 g_list_free (dfbvideosink->cb_channels);
1067 dfbvideosink->cb_channels = NULL;
1070 if (dfbvideosink->pool) {
1071 gst_object_unref (dfbvideosink->pool);
1072 dfbvideosink->pool = NULL;
1075 if (dfbvideosink->primary) {
1076 dfbvideosink->primary->Release (dfbvideosink->primary);
1077 dfbvideosink->primary = NULL;
1080 if (dfbvideosink->layer) {
1081 #if (DIRECTFB_VER >= GST_DFBVIDEOSINK_VER (1,6,0))
1082 if (dfbvideosink->layer_mode == LAYER_MODE_ADMINISTRATIVE)
1084 dfbvideosink->layer->EnableCursor (dfbvideosink->layer, FALSE);
1085 dfbvideosink->layer->Release (dfbvideosink->layer);
1086 dfbvideosink->layer = NULL;
1089 if (dfbvideosink->dfb) {
1090 dfbvideosink->dfb->Release (dfbvideosink->dfb);
1091 dfbvideosink->dfb = NULL;
1094 dfbvideosink->setup = FALSE;
1097 static DFBSurfacePixelFormat
1098 gst_dfbvideosink_get_format_from_caps (GstCaps * caps)
1100 GstStructure *structure;
1101 DFBSurfacePixelFormat pixel_format = DSPF_UNKNOWN;
1103 GstVideoFormat format;
1105 g_return_val_if_fail (GST_IS_CAPS (caps), DSPF_UNKNOWN);
1107 structure = gst_caps_get_structure (caps, 0);
1108 str = gst_structure_get_string (structure, "format");
1110 GST_WARNING ("failed grabbing fourcc from caps %" GST_PTR_FORMAT, caps);
1111 return DSPF_UNKNOWN;
1114 format = gst_video_format_from_string (str);
1116 case GST_VIDEO_FORMAT_RGB16:
1117 pixel_format = DSPF_RGB16;
1119 case GST_VIDEO_FORMAT_RGB:
1120 pixel_format = DSPF_RGB24;
1122 case GST_VIDEO_FORMAT_xRGB:
1123 pixel_format = DSPF_RGB32;
1125 case GST_VIDEO_FORMAT_ARGB:
1126 pixel_format = DSPF_ARGB;
1128 case GST_VIDEO_FORMAT_I420:
1129 pixel_format = DSPF_I420;
1131 case GST_VIDEO_FORMAT_YV12:
1132 pixel_format = DSPF_YV12;
1134 case GST_VIDEO_FORMAT_YUY2:
1135 pixel_format = DSPF_YUY2;
1137 case GST_VIDEO_FORMAT_UYVY:
1138 pixel_format = DSPF_UYVY;
1140 case GST_VIDEO_FORMAT_NV12:
1141 pixel_format = DSPF_NV12;
1144 GST_WARNING ("unhandled pixel format %s", str);
1145 return DSPF_UNKNOWN;
1148 return pixel_format;
1152 gst_dfbvideosink_get_caps_from_format (DFBSurfacePixelFormat format)
1156 g_return_val_if_fail (format != DSPF_UNKNOWN, NULL);
1160 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_RGB16);
1163 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_RGB);
1166 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_xRGB);
1169 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_ARGB);
1172 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_YUY2);
1175 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_UYVY);
1178 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_I420);
1181 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_YV12);
1184 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_NV12);
1187 GST_WARNING ("unknown pixel format %s",
1188 gst_dfbvideosink_get_format_name (format));
1192 return gst_caps_new_simple ("video/x-raw", "format", G_TYPE_STRING, fourcc,
1197 gst_dfbvideosink_can_blit_from_format (GstDfbVideoSink * dfbvideosink,
1198 DFBSurfacePixelFormat format, gboolean accelerated)
1200 gboolean res = FALSE;
1202 IDirectFBSurface *surface = NULL;
1203 DFBSurfaceDescription s_dsc;
1204 DFBAccelerationMask mask;
1205 DFBDisplayLayerConfig dlc, prev_dlc;
1207 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), FALSE);
1209 /* Create a surface of desired format */
1210 s_dsc.flags = DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_HEIGHT;
1211 s_dsc.pixelformat = format;
1215 ret = dfbvideosink->dfb->CreateSurface (dfbvideosink->dfb, &s_dsc, &surface);
1216 if (ret != DFB_OK) {
1217 GST_WARNING_OBJECT (dfbvideosink, "failed creating surface with format %s",
1218 gst_dfbvideosink_get_format_name (format));
1222 /* Backup layer configuration */
1223 ret = dfbvideosink->layer->GetConfiguration (dfbvideosink->layer, &prev_dlc);
1224 if (ret != DFB_OK) {
1225 GST_WARNING_OBJECT (dfbvideosink, "failed when getting current layer "
1230 /* Test configuration of the layer to this pixel format */
1231 dlc.flags = DLCONF_PIXELFORMAT;
1232 dlc.pixelformat = format;
1234 ret = dfbvideosink->layer->TestConfiguration (dfbvideosink->layer, &dlc,
1236 if (ret != DFB_OK) {
1237 GST_DEBUG_OBJECT (dfbvideosink, "our layer refuses to operate in pixel "
1238 "format %s", gst_dfbvideosink_get_format_name (format));
1242 ret = dfbvideosink->layer->SetConfiguration (dfbvideosink->layer, &dlc);
1243 if (ret != DFB_OK) {
1244 GST_WARNING_OBJECT (dfbvideosink, "our layer refuses to operate in pixel "
1245 "format, though this format was successfully tested earlied %s",
1246 gst_dfbvideosink_get_format_name (format));
1250 ret = dfbvideosink->primary->GetAccelerationMask (dfbvideosink->primary,
1252 if (ret != DFB_OK) {
1253 GST_WARNING_OBJECT (dfbvideosink, "failed getting acceleration mask");
1257 /* Blitting from this format to our primary is accelerated */
1258 if ((mask & DFXL_BLIT) && accelerated) {
1259 GST_DEBUG_OBJECT (dfbvideosink, "blitting from format %s to our primary "
1260 "is accelerated", gst_dfbvideosink_get_format_name (format));
1262 } else if (!accelerated) {
1263 GST_DEBUG_OBJECT (dfbvideosink, "blitting from format %s to our primary "
1264 "is not accelerated", gst_dfbvideosink_get_format_name (format));
1268 /* Restore original layer configuration */
1269 ret = dfbvideosink->layer->SetConfiguration (dfbvideosink->layer, &prev_dlc);
1270 if (ret != DFB_OK) {
1271 GST_WARNING_OBJECT (dfbvideosink, "failed when restoring layer "
1278 surface->Release (surface);
1284 gst_dfbvideosink_get_best_vmode (GstDfbVideoSink * dfbvideosink, gint v_width,
1285 gint v_height, GstDfbVMode * best_vmode)
1287 GSList *walk = NULL;
1288 gboolean ret = FALSE;
1289 gint width, height, bpp;
1290 GstDfbVMode *vmode = NULL;
1292 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), FALSE);
1294 if (!dfbvideosink->vmodes) {
1298 walk = dfbvideosink->vmodes;
1300 vmode = (GstDfbVMode *) walk->data;
1303 width = vmode->width;
1304 height = vmode->height;
1308 gint wgap, hgap, best_wgap, best_hgap;
1310 vmode = (GstDfbVMode *) walk->data;
1312 /* What are the gaps */
1313 wgap = abs (vmode->width - v_width);
1314 hgap = abs (vmode->height - v_height);
1315 best_wgap = abs (width - v_width);
1316 best_hgap = abs (height - v_height);
1318 /* If this mode is better we ll use that */
1319 if (wgap + hgap < best_wgap + best_hgap) {
1320 width = vmode->width;
1321 height = vmode->height;
1325 walk = g_slist_next (walk);
1328 GST_DEBUG_OBJECT (dfbvideosink, "found video mode %dx%d for input at %dx%d",
1329 width, height, v_width, v_height);
1331 best_vmode->width = width;
1332 best_vmode->height = height;
1333 best_vmode->bpp = bpp;
1342 gst_dfbvideosink_getcaps (GstBaseSink * bsink, GstCaps * filter)
1344 GstDfbVideoSink *dfbvideosink;
1345 GstCaps *caps = NULL;
1346 GstCaps *returned_caps;
1349 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1351 if (!dfbvideosink->setup) {
1353 gst_pad_get_pad_template_caps (GST_VIDEO_SINK_PAD (dfbvideosink));
1354 caps = gst_caps_copy (tcaps);
1355 gst_caps_unref (tcaps);
1356 GST_DEBUG_OBJECT (dfbvideosink, "getcaps called and we are not setup yet, "
1357 "returning template %" GST_PTR_FORMAT, caps);
1360 GST_DEBUG_OBJECT (dfbvideosink, "getcaps called, checking our internal "
1362 if (dfbvideosink->ext_surface) {
1363 /* We are not rendering to our own surface, returning this surface's
1365 caps = gst_dfbvideosink_get_caps_from_format (dfbvideosink->pixel_format);
1367 /* Try some formats */
1368 gboolean accelerated = TRUE;
1369 caps = gst_caps_new_empty ();
1372 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_RGB16,
1374 gst_caps_append (caps,
1375 gst_dfbvideosink_get_caps_from_format (DSPF_RGB16));
1377 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_RGB24,
1379 gst_caps_append (caps,
1380 gst_dfbvideosink_get_caps_from_format (DSPF_RGB24));
1382 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_RGB32,
1384 gst_caps_append (caps,
1385 gst_dfbvideosink_get_caps_from_format (DSPF_RGB32));
1387 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_ARGB,
1389 gst_caps_append (caps,
1390 gst_dfbvideosink_get_caps_from_format (DSPF_ARGB));
1392 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_NV12,
1394 gst_caps_append (caps,
1395 gst_dfbvideosink_get_caps_from_format (DSPF_NV12));
1397 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_YUY2,
1399 gst_caps_append (caps,
1400 gst_dfbvideosink_get_caps_from_format (DSPF_YUY2));
1402 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_UYVY,
1404 gst_caps_append (caps,
1405 gst_dfbvideosink_get_caps_from_format (DSPF_UYVY));
1407 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_I420,
1409 gst_caps_append (caps,
1410 gst_dfbvideosink_get_caps_from_format (DSPF_I420));
1412 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_YV12,
1414 gst_caps_append (caps,
1415 gst_dfbvideosink_get_caps_from_format (DSPF_YV12));
1417 accelerated = !accelerated;
1418 } while (accelerated == FALSE);
1422 for (i = 0; i < gst_caps_get_size (caps); i++) {
1423 GstStructure *structure = gst_caps_get_structure (caps, i);
1425 gst_structure_set (structure,
1426 "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
1427 "height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
1428 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
1430 if (!dfbvideosink->hw_scaling && dfbvideosink->par) {
1433 nom = gst_value_get_fraction_numerator (dfbvideosink->par);
1434 den = gst_value_get_fraction_denominator (dfbvideosink->par);
1435 gst_structure_set (structure, "pixel-aspect-ratio",
1436 GST_TYPE_FRACTION, nom, den, NULL);
1442 returned_caps = gst_caps_intersect_full (filter, caps,
1443 GST_CAPS_INTERSECT_FIRST);
1444 gst_caps_unref (caps);
1446 returned_caps = caps;
1448 GST_DEBUG_OBJECT (dfbvideosink, "returning our caps %" GST_PTR_FORMAT,
1451 return returned_caps;
1455 gst_dfbvideosink_setcaps (GstBaseSink * bsink, GstCaps * caps)
1457 GstDfbVideoSink *dfbvideosink;
1458 GstStructure *structure;
1459 gboolean res, result = FALSE;
1460 gint video_width, video_height;
1461 const GValue *framerate;
1462 DFBSurfacePixelFormat pixel_format = DSPF_UNKNOWN;
1464 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1466 structure = gst_caps_get_structure (caps, 0);
1467 res = gst_structure_get_int (structure, "width", &video_width);
1468 res &= gst_structure_get_int (structure, "height", &video_height);
1469 framerate = gst_structure_get_value (structure, "framerate");
1470 res &= (framerate != NULL);
1475 dfbvideosink->fps_n = gst_value_get_fraction_numerator (framerate);
1476 dfbvideosink->fps_d = gst_value_get_fraction_denominator (framerate);
1478 pixel_format = gst_dfbvideosink_get_format_from_caps (caps);
1480 GST_DEBUG_OBJECT (dfbvideosink, "setcaps called with %" GST_PTR_FORMAT, caps);
1481 GST_DEBUG_OBJECT (dfbvideosink, "our format is: %dx%d %s video at %d/%d fps",
1482 video_width, video_height,
1483 gst_dfbvideosink_get_format_name (pixel_format), dfbvideosink->fps_n,
1484 dfbvideosink->fps_d);
1486 if (dfbvideosink->hw_scaling && dfbvideosink->par) {
1487 gint video_par_n, video_par_d; /* video's PAR */
1488 gint display_par_n, display_par_d; /* display's PAR */
1490 GValue display_ratio = { 0, }; /* display w/h ratio */
1491 const GValue *caps_par;
1493 /* get aspect ratio from caps if it's present, and
1494 * convert video width and height to a display width and height
1495 * using wd / hd = wv / hv * PARv / PARd
1496 * the ratio wd / hd will be stored in display_ratio */
1497 g_value_init (&display_ratio, GST_TYPE_FRACTION);
1499 /* get video's PAR */
1500 caps_par = gst_structure_get_value (structure, "pixel-aspect-ratio");
1502 video_par_n = gst_value_get_fraction_numerator (caps_par);
1503 video_par_d = gst_value_get_fraction_denominator (caps_par);
1508 /* get display's PAR */
1509 if (dfbvideosink->par) {
1510 display_par_n = gst_value_get_fraction_numerator (dfbvideosink->par);
1511 display_par_d = gst_value_get_fraction_denominator (dfbvideosink->par);
1517 gst_value_set_fraction (&display_ratio,
1518 video_width * video_par_n * display_par_d,
1519 video_height * video_par_d * display_par_n);
1521 num = gst_value_get_fraction_numerator (&display_ratio);
1522 den = gst_value_get_fraction_denominator (&display_ratio);
1523 GST_DEBUG_OBJECT (dfbvideosink,
1524 "video width/height: %dx%d, calculated display ratio: %d/%d",
1525 video_width, video_height, num, den);
1527 /* now find a width x height that respects this display ratio.
1528 * prefer those that have one of w/h the same as the incoming video
1529 * using wd / hd = num / den */
1531 /* start with same height, because of interlaced video */
1532 /* check hd / den is an integer scale factor, and scale wd with the PAR */
1533 if (video_height % den == 0) {
1534 GST_DEBUG_OBJECT (dfbvideosink, "keeping video height");
1535 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_height * num / den;
1536 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_height;
1537 } else if (video_width % num == 0) {
1538 GST_DEBUG_OBJECT (dfbvideosink, "keeping video width");
1539 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_width;
1540 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_width * den / num;
1542 GST_DEBUG_OBJECT (dfbvideosink, "approximating while keeping height");
1543 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_height * num / den;
1544 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_height;
1546 GST_DEBUG_OBJECT (dfbvideosink, "scaling to %dx%d",
1547 GST_VIDEO_SINK_WIDTH (dfbvideosink),
1548 GST_VIDEO_SINK_HEIGHT (dfbvideosink));
1550 if (dfbvideosink->par) {
1553 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
1555 if (gst_value_compare (par, dfbvideosink->par) != GST_VALUE_EQUAL) {
1560 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_width;
1561 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_height;
1564 /* Try to adapt the video mode to the video geometry */
1565 if (dfbvideosink->dfb) {
1568 DFBDisplayLayerConfig lc;
1570 GST_DEBUG_OBJECT (dfbvideosink, "trying to adapt the video mode to video "
1573 /* Set video mode and layer configuration appropriately */
1574 if (gst_dfbvideosink_get_best_vmode (dfbvideosink,
1575 GST_VIDEO_SINK_WIDTH (dfbvideosink),
1576 GST_VIDEO_SINK_HEIGHT (dfbvideosink), &vmode)) {
1577 gint width, height, bpp;
1579 width = vmode.width;
1580 height = vmode.height;
1583 GST_DEBUG_OBJECT (dfbvideosink, "setting video mode to %dx%d at %d bpp",
1584 width, height, bpp);
1586 ret = dfbvideosink->dfb->SetVideoMode (dfbvideosink->dfb, width,
1588 if (ret != DFB_OK) {
1589 GST_WARNING_OBJECT (dfbvideosink, "failed setting video mode %dx%d "
1590 "at %d bpp", width, height, bpp);
1594 lc.flags = DLCONF_PIXELFORMAT;
1595 lc.pixelformat = pixel_format;
1597 ret = dfbvideosink->layer->SetConfiguration (dfbvideosink->layer, &lc);
1598 if (ret != DFB_OK) {
1599 GST_WARNING_OBJECT (dfbvideosink, "failed setting layer pixelformat "
1600 "to %s", gst_dfbvideosink_get_format_name (pixel_format));
1602 dfbvideosink->layer->GetConfiguration (dfbvideosink->layer, &lc);
1603 dfbvideosink->out_width = lc.width;
1604 dfbvideosink->out_height = lc.height;
1605 dfbvideosink->pixel_format = lc.pixelformat;
1606 GST_DEBUG_OBJECT (dfbvideosink, "layer %d now configured to %dx%d %s",
1607 dfbvideosink->layer_id, lc.width, lc.height,
1608 gst_dfbvideosink_get_format_name (lc.pixelformat));
1612 if (pixel_format != dfbvideosink->pixel_format) {
1613 GST_WARNING_OBJECT (dfbvideosink, "setcaps sent us a different pixel "
1614 "format %s", gst_dfbvideosink_get_format_name (pixel_format));
1618 dfbvideosink->video_width = video_width;
1619 dfbvideosink->video_height = video_height;
1621 if (dfbvideosink->pool) {
1622 if (gst_buffer_pool_is_active (dfbvideosink->pool))
1623 gst_buffer_pool_set_active (dfbvideosink->pool, FALSE);
1624 gst_object_unref (dfbvideosink->pool);
1627 /* create a new buffer pool of DirectFB surface */
1628 dfbvideosink->pool = gst_dfb_buffer_pool_new (dfbvideosink);
1630 structure = gst_buffer_pool_get_config (dfbvideosink->pool);
1631 gst_buffer_pool_config_set_params (structure, caps, 0, 0, 0);
1632 if (!gst_buffer_pool_set_config (dfbvideosink->pool, structure)) {
1633 GST_WARNING_OBJECT (dfbvideosink,
1634 "failed to set buffer pool configuration");
1637 if (!gst_buffer_pool_set_active (dfbvideosink->pool, TRUE)) {
1638 GST_WARNING_OBJECT (dfbvideosink, "failed to activate buffer pool");
1650 GST_INFO_OBJECT (dfbvideosink, "pixel aspect ratio does not match");
1655 static GstStateChangeReturn
1656 gst_dfbvideosink_change_state (GstElement * element, GstStateChange transition)
1658 GstDfbVideoSink *dfbvideosink;
1659 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1661 dfbvideosink = GST_DFBVIDEOSINK (element);
1663 switch (transition) {
1664 case GST_STATE_CHANGE_NULL_TO_READY:
1665 dfbvideosink->running = TRUE;
1666 if (!dfbvideosink->setup) {
1667 if (!gst_dfbvideosink_setup (dfbvideosink)) {
1668 GST_DEBUG_OBJECT (dfbvideosink, "setup failed when changing state "
1669 "from NULL to READY");
1670 GST_ELEMENT_ERROR (dfbvideosink, RESOURCE, OPEN_WRITE,
1671 (NULL), ("Failed initializing DirectFB system"));
1672 return GST_STATE_CHANGE_FAILURE;
1676 case GST_STATE_CHANGE_READY_TO_PAUSED:
1677 /* Blank surface if we have one */
1678 if (dfbvideosink->ext_surface) {
1679 dfbvideosink->ext_surface->Clear (dfbvideosink->ext_surface,
1680 0x00, 0x00, 0x00, 0xFF);
1682 if (dfbvideosink->primary) {
1683 dfbvideosink->primary->Clear (dfbvideosink->primary, 0x00, 0x00,
1687 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1693 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1694 if (ret == GST_STATE_CHANGE_FAILURE)
1697 switch (transition) {
1698 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1700 case GST_STATE_CHANGE_PAUSED_TO_READY:
1701 dfbvideosink->fps_d = 0;
1702 dfbvideosink->fps_n = 0;
1703 dfbvideosink->video_width = 0;
1704 dfbvideosink->video_height = 0;
1705 if (dfbvideosink->pool)
1706 gst_buffer_pool_set_active (dfbvideosink->pool, FALSE);
1708 case GST_STATE_CHANGE_READY_TO_NULL:
1709 dfbvideosink->running = FALSE;
1710 if (dfbvideosink->setup) {
1711 gst_dfbvideosink_cleanup (dfbvideosink);
1722 gst_dfbvideosink_get_times (GstBaseSink * bsink, GstBuffer * buf,
1723 GstClockTime * start, GstClockTime * end)
1725 GstDfbVideoSink *dfbvideosink;
1727 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1729 if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
1730 *start = GST_BUFFER_TIMESTAMP (buf);
1731 if (GST_BUFFER_DURATION_IS_VALID (buf)) {
1732 *end = *start + GST_BUFFER_DURATION (buf);
1734 if (dfbvideosink->fps_n > 0) {
1736 *start + (GST_SECOND * dfbvideosink->fps_d) / dfbvideosink->fps_n;
1742 static GstFlowReturn
1743 gst_dfbvideosink_show_frame (GstBaseSink * bsink, GstBuffer * buf)
1745 GstDfbVideoSink *dfbvideosink = NULL;
1747 GstVideoRectangle dst = { 0, };
1748 GstVideoRectangle src = { 0, };
1749 GstVideoRectangle result;
1750 GstFlowReturn ret = GST_FLOW_OK;
1751 gboolean mem_cpy = TRUE;
1752 GstMetaDfbSurface *meta;
1754 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1756 if (!dfbvideosink->setup) {
1761 meta = GST_META_DFBSURFACE_GET (buf);
1763 /* Is that a buffer we allocated ourselves ? */
1765 /* Does it have a surface ? */
1766 if (meta->surface) {
1768 GST_DEBUG_OBJECT (dfbvideosink, "we have a buffer (%p) we allocated "
1769 "ourselves and it has a surface, no memcpy then", buf);
1771 /* No surface, that's a malloc */
1772 GST_DEBUG_OBJECT (dfbvideosink, "we have a buffer (%p) we allocated "
1773 "ourselves but it does not hold a surface", buf);
1777 GST_DEBUG_OBJECT (dfbvideosink, "we have a buffer (%p) we did not allocate",
1782 IDirectFBSurface *dest = NULL, *surface = NULL;
1784 gint dest_pitch, line;
1785 GstStructure *structure;
1788 GstVideoInfo src_info;
1789 GstVideoFrame src_frame;
1791 GstVideoFormat format;
1792 guint offset[GST_VIDEO_MAX_PLANES] = { 0 };
1793 guint stride[GST_VIDEO_MAX_PLANES] = { 0 };
1795 /* As we are not blitting no acceleration is possible. If the surface is
1796 * too small we do clipping, if it's too big we center. Theoretically as
1797 * we are using propose_allocation, there's a chance that we have been
1798 * able to do reverse caps negotiation */
1800 if (dfbvideosink->ext_surface) {
1801 surface = dfbvideosink->ext_surface;
1802 GST_DEBUG_OBJECT (dfbvideosink, "memcpy to an external surface "
1803 "subsurface (vsync %d)", dfbvideosink->vsync);
1805 surface = dfbvideosink->primary;
1806 GST_DEBUG_OBJECT (dfbvideosink, "memcpy to a primary subsurface "
1807 "(vsync %d)", dfbvideosink->vsync);
1810 /* Get the video frame geometry from the buffer caps */
1811 caps = gst_pad_get_current_caps (GST_BASE_SINK_PAD (bsink));
1812 structure = gst_caps_get_structure (caps, 0);
1814 gst_structure_get_int (structure, "width", &src.w);
1815 gst_structure_get_int (structure, "height", &src.h);
1817 src.w = dfbvideosink->video_width;
1818 src.h = dfbvideosink->video_height;
1820 gst_caps_unref (caps);
1821 res = surface->GetSize (surface, &dst.w, &dst.h);
1824 gst_video_sink_center_rect (src, dst, &result, FALSE);
1827 surface->GetSubSurface (surface, (DFBRectangle *) (void *) &result,
1829 if (res != DFB_OK) {
1830 GST_WARNING_OBJECT (dfbvideosink, "failed when getting a sub surface");
1835 /* If we are not using Flip we wait for VSYNC before blit */
1836 if (!dfbvideosink->backbuffer && dfbvideosink->vsync) {
1837 dfbvideosink->layer->WaitForSync (dfbvideosink->layer);
1840 res = dest->Lock (dest, DSLF_WRITE, (void *) &data, &dest_pitch);
1841 if (res != DFB_OK) {
1842 GST_WARNING_OBJECT (dfbvideosink, "failed locking the external "
1843 "subsurface for writing");
1844 ret = GST_FLOW_ERROR;
1848 caps = gst_pad_get_current_caps (GST_BASE_SINK_PAD (bsink));
1849 if (!gst_video_info_from_caps (&src_info, caps)) {
1850 GST_WARNING_OBJECT (dfbvideosink, "failed getting video info");
1851 ret = GST_FLOW_ERROR;
1855 str = gst_structure_get_string (structure, "format");
1857 GST_WARNING ("failed grabbing fourcc from caps %" GST_PTR_FORMAT, caps);
1858 ret = GST_FLOW_ERROR;
1861 format = gst_video_format_from_string (str);
1863 gst_caps_unref (caps);
1865 if (!gst_video_frame_map (&src_frame, &src_info, buf, GST_MAP_READ)) {
1866 GST_WARNING_OBJECT (dfbvideosink, "failed mapping frame");
1867 ret = GST_FLOW_ERROR;
1872 case GST_VIDEO_FORMAT_I420:
1873 case GST_VIDEO_FORMAT_YV12:
1874 offset[1] = dest_pitch * ((dfbvideosink->out_height - result.y) +
1876 offset[2] = offset[1] + dest_pitch * dfbvideosink->out_height / 4;
1877 stride[0] = dest_pitch;
1878 stride[1] = stride[2] = dest_pitch / 2;
1880 case GST_VIDEO_FORMAT_NV12:
1881 offset[1] = dest_pitch * (dfbvideosink->out_height - result.y / 2);
1882 stride[0] = stride[1] = dest_pitch;
1885 stride[0] = dest_pitch;
1890 for (plane = 0; plane < src_info.finfo->n_planes; plane++) {
1896 w_buf = data + offset[plane];
1898 plane_h = GST_VIDEO_FRAME_COMP_HEIGHT (&src_frame, plane);
1899 size = MIN (src_info.stride[plane], stride[plane]);
1901 /* Write each line respecting subsurface pitch */
1902 for (plane_line = 0; line < result.h || plane_line < plane_h;
1903 line++, plane_line++) {
1904 /* We do clipping */
1905 memcpy (w_buf, (gchar *) src_frame.data[plane] +
1906 (plane_line * src_info.stride[plane]), size);
1907 w_buf += stride[plane];
1911 gst_video_frame_unmap (&src_frame);
1913 res = dest->Unlock (dest);
1915 dest->Release (dest);
1917 if (dfbvideosink->backbuffer) {
1918 if (dfbvideosink->vsync) {
1919 res = surface->Flip (surface, NULL, DSFLIP_ONSYNC);
1921 res = surface->Flip (surface, NULL, DSFLIP_NONE);
1925 /* Else we will [Stretch]Blit to our primary */
1926 GST_DEBUG_OBJECT (dfbvideosink, "blitting to a primary surface (vsync %d)",
1927 dfbvideosink->vsync);
1929 src.w = GST_VIDEO_SINK_WIDTH (dfbvideosink);
1930 src.h = GST_VIDEO_SINK_HEIGHT (dfbvideosink);
1932 dfbvideosink->primary->GetSize (dfbvideosink->primary, &dst.w, &dst.h);
1934 /* Unlocking surface before blit */
1936 meta->surface->Unlock (meta->surface);
1937 meta->locked = FALSE;
1940 gst_video_sink_center_rect (src, dst, &result, dfbvideosink->hw_scaling);
1942 /* If we are not using Flip we wait for VSYNC before blit */
1943 if (!dfbvideosink->backbuffer && dfbvideosink->vsync) {
1944 dfbvideosink->layer->WaitForSync (dfbvideosink->layer);
1947 if (dfbvideosink->hw_scaling) {
1948 dfbvideosink->primary->StretchBlit (dfbvideosink->primary,
1949 meta->surface, NULL, (DFBRectangle *) (void *) &result);
1953 clip.x = clip.y = 0;
1956 dfbvideosink->primary->Blit (dfbvideosink->primary, meta->surface,
1957 &clip, result.x, result.y);
1960 if (dfbvideosink->backbuffer) {
1961 if (dfbvideosink->vsync) {
1962 dfbvideosink->primary->Flip (dfbvideosink->primary, NULL,
1965 dfbvideosink->primary->Flip (dfbvideosink->primary, NULL, DSFLIP_NONE);
1975 gst_dfbvideosink_navigation_send_event (GstNavigation * navigation,
1976 GstStructure * structure)
1978 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (navigation);
1980 GstVideoRectangle dst = { 0, };
1981 GstVideoRectangle src = { 0, };
1982 GstVideoRectangle result;
1983 double x, y, old_x, old_y;
1986 src.w = GST_VIDEO_SINK_WIDTH (dfbvideosink);
1987 src.h = GST_VIDEO_SINK_HEIGHT (dfbvideosink);
1988 dst.w = dfbvideosink->out_width;
1989 dst.h = dfbvideosink->out_height;
1990 gst_video_sink_center_rect (src, dst, &result, dfbvideosink->hw_scaling);
1992 event = gst_event_new_navigation (structure);
1994 /* Our coordinates can be wrong here if we centered the video */
1996 /* Converting pointer coordinates to the non scaled geometry */
1997 if (gst_structure_get_double (structure, "pointer_x", &old_x)) {
2000 if (x >= result.x && x <= (result.x + result.w)) {
2002 x *= dfbvideosink->video_width;
2007 GST_DEBUG_OBJECT (dfbvideosink, "translated navigation event x "
2008 "coordinate from %f to %f", old_x, x);
2009 gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE, x, NULL);
2011 if (gst_structure_get_double (structure, "pointer_y", &old_y)) {
2014 if (y >= result.y && y <= (result.y + result.h)) {
2016 y *= dfbvideosink->video_height;
2021 GST_DEBUG_OBJECT (dfbvideosink, "translated navigation event y "
2022 "coordinate from %fd to %fd", old_y, y);
2023 gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE, y, NULL);
2026 pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (dfbvideosink));
2028 if (GST_IS_PAD (pad) && GST_IS_EVENT (event)) {
2029 gst_pad_send_event (pad, event);
2031 gst_object_unref (pad);
2036 gst_dfbvideosink_navigation_init (GstNavigationInterface * iface)
2038 iface->send_event = gst_dfbvideosink_navigation_send_event;
2042 gst_dfbvideosink_update_colorbalance (GstDfbVideoSink * dfbvideosink)
2044 g_return_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink));
2046 if (dfbvideosink->layer) {
2047 DFBColorAdjustment cb_adjust;
2049 cb_adjust.flags = DCAF_NONE;
2051 if (dfbvideosink->brightness >= 0) {
2052 cb_adjust.flags |= DCAF_BRIGHTNESS;
2054 if (dfbvideosink->contrast >= 0) {
2055 cb_adjust.flags |= DCAF_CONTRAST;
2057 if (dfbvideosink->hue >= 0) {
2058 cb_adjust.flags |= DCAF_HUE;
2060 if (dfbvideosink->saturation >= 0) {
2061 cb_adjust.flags |= DCAF_SATURATION;
2064 cb_adjust.brightness = dfbvideosink->brightness;
2065 cb_adjust.contrast = dfbvideosink->contrast;
2066 cb_adjust.hue = dfbvideosink->hue;
2067 cb_adjust.saturation = dfbvideosink->saturation;
2069 GST_DEBUG_OBJECT (dfbvideosink, "updating colorbalance: flags %d "
2070 "brightness %d contrast %d hue %d saturation %d", cb_adjust.flags,
2071 cb_adjust.brightness, cb_adjust.contrast, cb_adjust.hue,
2072 cb_adjust.saturation);
2073 dfbvideosink->layer->SetColorAdjustment (dfbvideosink->layer, &cb_adjust);
2077 static const GList *
2078 gst_dfbvideosink_colorbalance_list_channels (GstColorBalance * balance)
2080 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (balance);
2082 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), NULL);
2084 return dfbvideosink->cb_channels;
2088 gst_dfbvideosink_colorbalance_set_value (GstColorBalance * balance,
2089 GstColorBalanceChannel * channel, gint value)
2091 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (balance);
2093 g_return_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink));
2094 g_return_if_fail (channel->label != NULL);
2096 dfbvideosink->cb_changed = TRUE;
2098 if (g_ascii_strcasecmp (channel->label, "HUE") == 0) {
2099 dfbvideosink->hue = value;
2100 } else if (g_ascii_strcasecmp (channel->label, "SATURATION") == 0) {
2101 dfbvideosink->saturation = value;
2102 } else if (g_ascii_strcasecmp (channel->label, "CONTRAST") == 0) {
2103 dfbvideosink->contrast = value;
2104 } else if (g_ascii_strcasecmp (channel->label, "BRIGHTNESS") == 0) {
2105 dfbvideosink->brightness = value;
2107 GST_WARNING_OBJECT (dfbvideosink, "got an unknown channel %s",
2112 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2116 gst_dfbvideosink_colorbalance_get_value (GstColorBalance * balance,
2117 GstColorBalanceChannel * channel)
2119 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (balance);
2122 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), 0);
2123 g_return_val_if_fail (channel->label != NULL, 0);
2125 if (g_ascii_strcasecmp (channel->label, "HUE") == 0) {
2126 value = dfbvideosink->hue;
2127 } else if (g_ascii_strcasecmp (channel->label, "SATURATION") == 0) {
2128 value = dfbvideosink->saturation;
2129 } else if (g_ascii_strcasecmp (channel->label, "CONTRAST") == 0) {
2130 value = dfbvideosink->contrast;
2131 } else if (g_ascii_strcasecmp (channel->label, "BRIGHTNESS") == 0) {
2132 value = dfbvideosink->brightness;
2134 GST_WARNING_OBJECT (dfbvideosink, "got an unknown channel %s",
2141 static GstColorBalanceType
2142 gst_dfbvideosink_colorbalance_get_balance_type (GstColorBalance * balance)
2144 return GST_COLOR_BALANCE_HARDWARE;
2148 gst_dfbvideosink_colorbalance_init (GstColorBalanceInterface * iface)
2150 iface->list_channels = gst_dfbvideosink_colorbalance_list_channels;
2151 iface->set_value = gst_dfbvideosink_colorbalance_set_value;
2152 iface->get_value = gst_dfbvideosink_colorbalance_get_value;
2153 iface->get_balance_type = gst_dfbvideosink_colorbalance_get_balance_type;
2159 gst_dfbvideosink_set_property (GObject * object, guint prop_id,
2160 const GValue * value, GParamSpec * pspec)
2162 GstDfbVideoSink *dfbvideosink;
2164 g_return_if_fail (GST_IS_DFBVIDEOSINK (object));
2165 dfbvideosink = GST_DFBVIDEOSINK (object);
2169 dfbvideosink->ext_surface = g_value_get_pointer (value);
2172 dfbvideosink->hue = g_value_get_int (value);
2173 dfbvideosink->cb_changed = TRUE;
2174 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2177 dfbvideosink->contrast = g_value_get_int (value);
2178 dfbvideosink->cb_changed = TRUE;
2179 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2181 case ARG_BRIGHTNESS:
2182 dfbvideosink->brightness = g_value_get_int (value);
2183 dfbvideosink->cb_changed = TRUE;
2184 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2186 case ARG_SATURATION:
2187 dfbvideosink->saturation = g_value_get_int (value);
2188 dfbvideosink->cb_changed = TRUE;
2189 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2191 case ARG_PIXEL_ASPECT_RATIO:
2192 g_free (dfbvideosink->par);
2193 dfbvideosink->par = g_new0 (GValue, 1);
2194 g_value_init (dfbvideosink->par, GST_TYPE_FRACTION);
2195 if (!g_value_transform (value, dfbvideosink->par)) {
2196 GST_WARNING_OBJECT (dfbvideosink, "Could not transform string to "
2198 gst_value_set_fraction (dfbvideosink->par, 1, 1);
2200 GST_DEBUG_OBJECT (dfbvideosink, "set PAR to %d/%d",
2201 gst_value_get_fraction_numerator (dfbvideosink->par),
2202 gst_value_get_fraction_denominator (dfbvideosink->par));
2205 dfbvideosink->vsync = g_value_get_boolean (value);
2207 case ARG_LAYER_MODE:
2208 dfbvideosink->layer_mode = g_value_get_enum (value);
2211 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2217 gst_dfbvideosink_get_property (GObject * object, guint prop_id,
2218 GValue * value, GParamSpec * pspec)
2220 GstDfbVideoSink *dfbvideosink;
2222 g_return_if_fail (GST_IS_DFBVIDEOSINK (object));
2223 dfbvideosink = GST_DFBVIDEOSINK (object);
2227 g_value_set_int (value, dfbvideosink->hue);
2230 g_value_set_int (value, dfbvideosink->contrast);
2232 case ARG_BRIGHTNESS:
2233 g_value_set_int (value, dfbvideosink->brightness);
2235 case ARG_SATURATION:
2236 g_value_set_int (value, dfbvideosink->saturation);
2238 case ARG_PIXEL_ASPECT_RATIO:
2239 if (dfbvideosink->par)
2240 g_value_transform (dfbvideosink->par, value);
2243 g_value_set_boolean (value, dfbvideosink->vsync);
2245 case ARG_LAYER_MODE:
2246 g_value_set_enum (value, dfbvideosink->layer_mode);
2249 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2255 gst_dfbvideosink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
2257 GstDfbVideoSink *dfbvideosink;
2258 GstBufferPool *pool;
2263 dfbvideosink = GST_DFBVIDEOSINK (bsink);
2265 gst_query_parse_allocation (query, &caps, &need_pool);
2267 if ((pool = dfbvideosink->pool))
2268 gst_object_ref (pool);
2272 GstStructure *config;
2274 /* we had a pool, check caps */
2275 config = gst_buffer_pool_get_config (pool);
2276 gst_buffer_pool_config_get_params (config, &pcaps, &size, NULL, NULL);
2278 GST_DEBUG_OBJECT (dfbvideosink,
2279 "buffer pool configuration caps %" GST_PTR_FORMAT, pcaps);
2280 if (!gst_caps_is_equal (caps, pcaps)) {
2281 gst_structure_free (config);
2282 gst_object_unref (pool);
2283 GST_WARNING_OBJECT (dfbvideosink, "pool has different caps");
2286 gst_structure_free (config);
2289 gst_query_add_allocation_pool (query, pool, size, 1, 0);
2291 /* we also support various metadata */
2292 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
2295 gst_object_unref (pool);
2300 /* =========================================== */
2302 /* Init & Class init */
2304 /* =========================================== */
2306 gst_dfbvideosink_finalize (GObject * object)
2308 GstDfbVideoSink *dfbvideosink;
2310 dfbvideosink = GST_DFBVIDEOSINK (object);
2312 if (dfbvideosink->par) {
2313 g_free (dfbvideosink->par);
2314 dfbvideosink->par = NULL;
2316 if (dfbvideosink->setup) {
2317 gst_dfbvideosink_cleanup (dfbvideosink);
2320 G_OBJECT_CLASS (parent_class)->finalize (object);
2324 gst_dfbvideosink_init (GstDfbVideoSink * dfbvideosink)
2326 dfbvideosink->pool = NULL;
2328 dfbvideosink->video_height = dfbvideosink->out_height = 0;
2329 dfbvideosink->video_width = dfbvideosink->out_width = 0;
2330 dfbvideosink->fps_d = 0;
2331 dfbvideosink->fps_n = 0;
2333 dfbvideosink->dfb = NULL;
2334 dfbvideosink->vmodes = NULL;
2335 dfbvideosink->layer_id = -1;
2336 dfbvideosink->layer = NULL;
2337 dfbvideosink->primary = NULL;
2338 dfbvideosink->event_buffer = NULL;
2339 dfbvideosink->event_thread = NULL;
2341 dfbvideosink->ext_surface = NULL;
2343 dfbvideosink->pixel_format = DSPF_UNKNOWN;
2345 dfbvideosink->hw_scaling = FALSE;
2346 dfbvideosink->backbuffer = FALSE;
2347 dfbvideosink->vsync = TRUE;
2348 dfbvideosink->setup = FALSE;
2349 dfbvideosink->running = FALSE;
2351 dfbvideosink->cb_channels = NULL;
2352 dfbvideosink->brightness = -1;
2353 dfbvideosink->contrast = -1;
2354 dfbvideosink->hue = -1;
2355 dfbvideosink->saturation = -1;
2357 dfbvideosink->par = NULL;
2359 dfbvideosink->layer_mode = DEFAULT_LAYER_MODE;
2363 gst_dfbvideosink_class_init (GstDfbVideoSinkClass * klass)
2365 GObjectClass *gobject_class;
2366 GstElementClass *gstelement_class;
2367 GstBaseSinkClass *gstbasesink_class;
2369 gobject_class = (GObjectClass *) klass;
2370 gstelement_class = (GstElementClass *) klass;
2371 gstbasesink_class = (GstBaseSinkClass *) klass;
2373 parent_class = g_type_class_peek_parent (klass);
2375 gobject_class->finalize = gst_dfbvideosink_finalize;
2376 gobject_class->set_property = gst_dfbvideosink_set_property;
2377 gobject_class->get_property = gst_dfbvideosink_get_property;
2379 g_object_class_install_property (gobject_class, ARG_SURFACE,
2380 g_param_spec_pointer ("surface", "Surface",
2381 "The target surface for video",
2382 G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
2383 g_object_class_install_property (gobject_class, ARG_CONTRAST,
2384 g_param_spec_int ("contrast", "Contrast", "The contrast of the video",
2385 0x0000, 0xFFFF, 0x8000, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2386 g_object_class_install_property (gobject_class, ARG_BRIGHTNESS,
2387 g_param_spec_int ("brightness", "Brightness",
2388 "The brightness of the video", 0x0000, 0xFFFF, 0x8000,
2389 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2390 g_object_class_install_property (gobject_class, ARG_HUE,
2391 g_param_spec_int ("hue", "Hue", "The hue of the video", 0x0000, 0xFFFF,
2392 0x8000, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2393 g_object_class_install_property (gobject_class, ARG_SATURATION,
2394 g_param_spec_int ("saturation", "Saturation",
2395 "The saturation of the video", 0x0000, 0xFFFF, 0x8000,
2396 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2397 g_object_class_install_property (gobject_class, ARG_PIXEL_ASPECT_RATIO,
2398 g_param_spec_string ("pixel-aspect-ratio", "Pixel Aspect Ratio",
2399 "The pixel aspect ratio of the device", "1/1",
2400 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2401 g_object_class_install_property (gobject_class, ARG_VSYNC,
2402 g_param_spec_boolean ("vsync", "Vertical synchronisation",
2403 "Wait for next vertical sync to draw frames", TRUE,
2404 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2405 g_object_class_install_property (gobject_class, ARG_LAYER_MODE,
2406 g_param_spec_enum ("layer-mode",
2407 "The layer cooperative level (administrative or exclusive)",
2408 "The cooperative level handling the access permission (set this to "
2409 "'administrative' when the cursor is required)",
2410 gst_dfbvideosink_layer_mode_get_type (), DEFAULT_LAYER_MODE,
2411 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2413 gst_element_class_set_static_metadata (gstelement_class,
2414 "DirectFB video sink", "Sink/Video", "A DirectFB based videosink",
2415 "Julien Moutte <julien@moutte.net>");
2417 gst_element_class_add_pad_template (gstelement_class,
2418 gst_static_pad_template_get (&gst_dfbvideosink_sink_template_factory));
2420 gstelement_class->change_state = gst_dfbvideosink_change_state;
2422 gstbasesink_class->get_caps = gst_dfbvideosink_getcaps;
2423 gstbasesink_class->set_caps = gst_dfbvideosink_setcaps;
2424 gstbasesink_class->get_times = gst_dfbvideosink_get_times;
2425 gstbasesink_class->preroll = gst_dfbvideosink_show_frame;
2426 gstbasesink_class->render = gst_dfbvideosink_show_frame;
2427 gstbasesink_class->propose_allocation = gst_dfbvideosink_propose_allocation;
2431 plugin_init (GstPlugin * plugin)
2433 if (!gst_element_register (plugin, "dfbvideosink", GST_RANK_MARGINAL,
2434 GST_TYPE_DFBVIDEOSINK))
2437 GST_DEBUG_CATEGORY_INIT (dfbvideosink_debug, "dfbvideosink", 0,
2438 "DirectFB video sink element");
2443 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
2446 "DirectFB video output plugin",
2447 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)