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 static DFBSurfacePixelFormat gst_dfbvideosink_get_format_from_caps (GstCaps *
127 static void gst_dfbvideosink_update_colorbalance (GstDfbVideoSink *
129 static void gst_dfbvideosink_navigation_init (GstNavigationInterface * iface);
130 static void gst_dfbvideosink_colorbalance_init (GstColorBalanceInterface
132 static const char *gst_dfbvideosink_get_format_name (DFBSurfacePixelFormat
135 #define gst_dfbvideosink_parent_class parent_class
138 gst_meta_dfbsurface_api_get_type (void)
140 static volatile GType type;
141 static const gchar *tags[] = { "memory", NULL };
143 if (g_once_init_enter (&type)) {
144 GType _type = gst_meta_api_type_register ("GstMetaDfbSurfaceAPI", tags);
145 g_once_init_leave (&type, _type);
152 gst_meta_dfbsurface_get_info (void)
154 static const GstMetaInfo *meta_info = NULL;
156 if (g_once_init_enter (&meta_info)) {
157 const GstMetaInfo *meta =
158 gst_meta_register (gst_meta_dfbsurface_api_get_type (),
159 "GstMetaDfbSurface", sizeof (GstMetaDfbSurface),
160 (GstMetaInitFunction) NULL, (GstMetaFreeFunction) NULL,
161 (GstMetaTransformFunction) NULL);
162 g_once_init_leave (&meta_info, meta);
167 G_DEFINE_TYPE (GstDfbBufferPool, gst_dfb_buffer_pool, GST_TYPE_BUFFER_POOL);
170 gst_dfb_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
172 GstDfbBufferPool *dfbpool = GST_DFB_BUFFER_POOL_CAST (pool);
174 DFBSurfacePixelFormat pixel_format = DSPF_UNKNOWN;
177 DFBSurfaceDescription s_dsc;
178 IDirectFBSurface *surface;
186 if (!dfbpool->dfbvideosink->setup) {
187 GST_WARNING_OBJECT (pool, "DirectFB hasn't been initialized yet.");
191 if (!gst_buffer_pool_config_get_params (config, &caps, NULL, &min_buffers,
193 GST_WARNING_OBJECT (pool, "invalid config");
197 pixel_format = gst_dfbvideosink_get_format_from_caps (caps);
199 if (!gst_video_info_from_caps (&info, caps)) {
200 GST_WARNING_OBJECT (pool, "failed getting video info from caps %"
201 GST_PTR_FORMAT, caps);
205 width = GST_VIDEO_INFO_WIDTH (&info);
206 height = GST_VIDEO_INFO_HEIGHT (&info);
208 /* temporarily create a surface to get the pitch */
209 s_dsc.flags = DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_HEIGHT;
210 s_dsc.pixelformat = pixel_format;
212 s_dsc.height = height;
214 ret = dfbpool->dfbvideosink->dfb->CreateSurface (dfbpool->dfbvideosink->dfb,
217 GST_WARNING_OBJECT (pool, "failed creating surface with format %s",
218 gst_dfbvideosink_get_format_name (pixel_format));
222 ret = surface->Lock (surface, DSLF_READ, &data, &pitch);
224 GST_WARNING_OBJECT (pool, "failed locking the surface");
225 surface->Release (surface);
228 surface->Unlock (surface);
229 surface->Release (surface);
231 switch (GST_VIDEO_INFO_FORMAT (&info)) {
232 case GST_VIDEO_FORMAT_I420:
233 case GST_VIDEO_FORMAT_YV12:
234 case GST_VIDEO_FORMAT_NV12:
235 size = pitch * height * 3 / 2;
238 size = pitch * height;
242 gst_buffer_pool_config_set_params (config, caps, size, min_buffers,
245 dfbpool->caps = gst_caps_ref (caps);
247 return GST_BUFFER_POOL_CLASS (gst_dfb_buffer_pool_parent_class)->set_config
252 gst_dfb_buffer_pool_free_buffer (GstBufferPool * bpool, GstBuffer * surface)
254 GstMetaDfbSurface *meta;
256 meta = GST_META_DFBSURFACE_GET (surface);
258 /* Release our internal surface */
261 meta->surface->Unlock (meta->surface);
262 meta->locked = FALSE;
264 meta->surface->Release (meta->surface);
267 if (meta->dfbvideosink)
268 /* Release the ref to our sink */
269 gst_object_unref (meta->dfbvideosink);
271 GST_BUFFER_POOL_CLASS (gst_dfb_buffer_pool_parent_class)->free_buffer (bpool,
276 gst_dfb_buffer_pool_alloc_buffer (GstBufferPool * bpool,
277 GstBuffer ** buffer, GstBufferPoolAcquireParams * params)
279 GstDfbBufferPool *dfbpool = GST_DFB_BUFFER_POOL_CAST (bpool);
281 GstMetaDfbSurface *meta;
282 GstStructure *structure;
284 DFBSurfaceDescription s_dsc;
287 GstFlowReturn result = GST_FLOW_ERROR;
289 gsize offset[GST_VIDEO_MAX_PLANES] = { 0 };
290 gint stride[GST_VIDEO_MAX_PLANES] = { 0 };
292 gsize plane_size[GST_VIDEO_MAX_PLANES] = { 0 };
295 GstVideoFormat format;
298 surface = gst_buffer_new ();
299 meta = GST_META_DFBSURFACE_ADD (surface);
301 /* Keep a ref to our sink */
302 meta->dfbvideosink = gst_object_ref (dfbpool->dfbvideosink);
303 /* Surface is not locked yet */
304 meta->locked = FALSE;
306 structure = gst_caps_get_structure (dfbpool->caps, 0);
308 if (!gst_structure_get_int (structure, "width", &meta->width) ||
309 !gst_structure_get_int (structure, "height", &meta->height)) {
310 GST_WARNING_OBJECT (bpool, "failed getting geometry from caps %"
311 GST_PTR_FORMAT, dfbpool->caps);
315 /* Pixel format from caps */
316 meta->pixel_format = gst_dfbvideosink_get_format_from_caps (dfbpool->caps);
317 if (meta->pixel_format == DSPF_UNKNOWN) {
321 if (!dfbpool->dfbvideosink->dfb) {
322 GST_DEBUG_OBJECT (bpool, "no DirectFB context to create a surface");
326 /* Creating an internal surface which will be used as GstBuffer, we used
327 the detected pixel format and video dimensions */
329 s_dsc.flags = DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_HEIGHT;
331 s_dsc.pixelformat = meta->pixel_format;
332 s_dsc.width = meta->width;
333 s_dsc.height = meta->height;
336 dfbpool->dfbvideosink->dfb->CreateSurface (dfbpool->dfbvideosink->dfb,
337 &s_dsc, &meta->surface);
339 GST_WARNING_OBJECT (bpool, "failed creating a DirectFB surface");
340 meta->surface = NULL;
344 /* Clearing surface */
345 meta->surface->Clear (meta->surface, 0x00, 0x00, 0x00, 0xFF);
347 /* Locking the surface to acquire the memory pointer */
348 meta->surface->Lock (meta->surface, DSLF_WRITE, &data, &pitch);
351 GST_DEBUG_OBJECT (bpool, "creating a %dx%d surface (%p) with %s "
352 "pixel format, line pitch %d", meta->width, meta->height, surface,
353 gst_dfbvideosink_get_format_name (meta->pixel_format), pitch);
355 structure = gst_caps_get_structure (dfbpool->caps, 0);
356 str = gst_structure_get_string (structure, "format");
358 GST_WARNING ("failed grabbing fourcc from caps %" GST_PTR_FORMAT,
360 return GST_FLOW_ERROR;
363 format = gst_video_format_from_string (str);
365 case GST_VIDEO_FORMAT_I420:
366 case GST_VIDEO_FORMAT_YV12:
367 offset[1] = pitch * meta->height;
368 offset[2] = offset[1] + pitch / 2 * meta->height / 2;
370 stride[1] = stride[2] = pitch / 2;
372 plane_size[0] = offset[1];
373 plane_size[1] = plane_size[2] = plane_size[0] / 4;
374 max_size = plane_size[0] * 3 / 2;
377 case GST_VIDEO_FORMAT_NV12:
378 offset[1] = pitch * meta->height;
379 stride[0] = stride[1] = pitch;
381 plane_size[0] = offset[1];
382 plane_size[1] = pitch * meta->height / 2;
383 max_size = plane_size[0] * 3 / 2;
388 plane_size[0] = max_size = pitch * meta->height;
393 for (i = 0; i < n_planes; i++) {
394 gst_buffer_append_memory (surface,
395 gst_memory_new_wrapped (0, data, max_size, offset[i], plane_size[i],
399 gst_buffer_add_video_meta_full (surface, GST_VIDEO_FRAME_FLAG_NONE,
400 format, meta->width, meta->height, n_planes, offset, stride);
402 result = GST_FLOW_OK;
408 /* We allocate a standard buffer ourselves to store it in our buffer pool,
409 this is an optimisation for memory allocation */
410 alloc_size = meta->width * meta->height;
411 surface = gst_buffer_new_allocate (NULL, alloc_size, NULL);
412 if (surface == NULL) {
413 GST_WARNING_OBJECT (bpool, "failed allocating a gstbuffer");
419 meta->surface->Unlock (meta->surface);
420 meta->locked = FALSE;
422 meta->surface->Release (meta->surface);
423 meta->surface = NULL;
425 GST_DEBUG_OBJECT (bpool, "allocating a buffer (%p) of %u bytes",
426 surface, (guint) alloc_size);
428 result = GST_FLOW_OK;
431 if (result != GST_FLOW_OK) {
432 gst_dfb_buffer_pool_free_buffer (bpool, surface);
440 static GstBufferPool *
441 gst_dfb_buffer_pool_new (GstDfbVideoSink * dfbvideosink)
443 GstDfbBufferPool *pool;
445 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), NULL);
447 pool = g_object_new (GST_TYPE_DFB_BUFFER_POOL, NULL);
448 pool->dfbvideosink = gst_object_ref (dfbvideosink);
450 GST_LOG_OBJECT (pool, "new dfb buffer pool %p", pool);
452 return GST_BUFFER_POOL_CAST (pool);
456 gst_dfb_buffer_pool_finalize (GObject * object)
458 GstDfbBufferPool *pool = GST_DFB_BUFFER_POOL_CAST (object);
461 gst_caps_unref (pool->caps);
462 gst_object_unref (pool->dfbvideosink);
464 G_OBJECT_CLASS (gst_dfb_buffer_pool_parent_class)->finalize (object);
468 gst_dfb_buffer_pool_init (GstDfbBufferPool * pool)
474 gst_dfb_buffer_pool_class_init (GstDfbBufferPoolClass * klass)
476 GObjectClass *gobject_class = (GObjectClass *) klass;
477 GstBufferPoolClass *gstbufferpool_class = (GstBufferPoolClass *) klass;
479 gobject_class->finalize = gst_dfb_buffer_pool_finalize;
481 gstbufferpool_class->alloc_buffer = gst_dfb_buffer_pool_alloc_buffer;
482 gstbufferpool_class->set_config = gst_dfb_buffer_pool_set_config;
483 gstbufferpool_class->free_buffer = gst_dfb_buffer_pool_free_buffer;
486 G_DEFINE_TYPE_WITH_CODE (GstDfbVideoSink, gst_dfbvideosink, GST_TYPE_VIDEO_SINK,
487 G_IMPLEMENT_INTERFACE (GST_TYPE_NAVIGATION,
488 gst_dfbvideosink_navigation_init);
489 G_IMPLEMENT_INTERFACE (GST_TYPE_COLOR_BALANCE,
490 gst_dfbvideosink_colorbalance_init));
492 #ifndef GST_DISABLE_GST_DEBUG
494 gst_dfbvideosink_get_format_name (DFBSurfacePixelFormat format)
541 #endif /* GST_DISABLE_GST_DEBUG */
544 gst_dfbvideosink_event_thread (GstDfbVideoSink * dfbvideosink)
548 while (dfbvideosink->running) {
549 /* Wait for an event with a 50 ms timeout */
550 dfbvideosink->event_buffer->
551 WaitForEventWithTimeout (dfbvideosink->event_buffer, 0, 50);
553 /* Do we have an event ? */
554 ret = dfbvideosink->event_buffer->HasEvent (dfbvideosink->event_buffer);
559 GST_DEBUG_OBJECT (dfbvideosink, "we have an event");
561 ret = dfbvideosink->event_buffer->GetEvent (dfbvideosink->event_buffer,
563 if (ret != DFB_OK) { /* Error */
564 GST_WARNING_OBJECT (dfbvideosink, "failed when getting event from "
566 } else { /* Handle event */
567 if (event.input.type == DIET_KEYPRESS) {
568 switch (event.input.key_symbol) {
571 GST_ELEMENT_ERROR (dfbvideosink, RESOURCE, OPEN_WRITE,
572 ("Video output device is gone."),
573 ("We were running fullscreen and user "
574 "pressed the ESC key, stopping playback."));
577 GST_DEBUG_OBJECT (dfbvideosink, "key press event %c !",
578 event.input.key_symbol);
579 gst_navigation_send_key_event (GST_NAVIGATION (dfbvideosink),
580 "key-press", "prout");
582 } else if (event.input.type == DIET_BUTTONPRESS) {
585 dfbvideosink->layer->GetCursorPosition (dfbvideosink->layer, &x, &y);
587 GST_DEBUG_OBJECT (dfbvideosink, "button %d pressed at %dx%d",
588 event.input.button, x, y);
590 gst_navigation_send_mouse_event (GST_NAVIGATION (dfbvideosink),
591 "mouse-button-press", event.input.button, x, y);
592 } else if (event.input.type == DIET_BUTTONRELEASE) {
595 dfbvideosink->layer->GetCursorPosition (dfbvideosink->layer, &x, &y);
597 GST_DEBUG_OBJECT (dfbvideosink, "button %d released at %dx%d",
598 event.input.button, x, y);
600 gst_navigation_send_mouse_event (GST_NAVIGATION (dfbvideosink),
601 "mouse-button-release", event.input.button, x, y);
602 } else if (event.input.type == DIET_AXISMOTION) {
605 dfbvideosink->layer->GetCursorPosition (dfbvideosink->layer, &x, &y);
606 gst_navigation_send_mouse_event (GST_NAVIGATION (dfbvideosink),
607 "mouse-move", 0, x, y);
609 GST_WARNING_OBJECT (dfbvideosink, "unhandled event type %d",
618 static DFBEnumerationResult
619 gst_dfbvideosink_enum_layers (DFBDisplayLayerID id,
620 DFBDisplayLayerDescription desc, void *data)
622 GstDfbVideoSink *dfbvideosink = NULL;
623 IDirectFBDisplayLayer *layer = NULL;
624 DFBDisplayLayerConfig dlc;
626 gboolean backbuffer = FALSE;
628 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (data), DFENUM_CANCEL);
630 dfbvideosink = GST_DFBVIDEOSINK (data);
632 GST_DEBUG_OBJECT (dfbvideosink, "inspecting display layer %d with name: %s",
635 if ((desc.type & DLTF_VIDEO) && (desc.caps & DLCAPS_SURFACE)) {
636 GST_DEBUG_OBJECT (dfbvideosink,
637 "this layer can handle live video and has a surface");
639 if (desc.caps & DLCAPS_SURFACE) {
640 GST_DEBUG_OBJECT (dfbvideosink,
641 "this layer can not handle live video but has a surface");
643 GST_DEBUG_OBJECT (dfbvideosink, "no we can't use that layer, really...");
648 ret = dfbvideosink->dfb->GetDisplayLayer (dfbvideosink->dfb, id, &layer);
650 GST_WARNING_OBJECT (dfbvideosink, "failed getting display layer %s",
655 ret = layer->GetConfiguration (layer, &dlc);
657 GST_WARNING_OBJECT (dfbvideosink,
658 "failed getting display layer configuration");
662 if ((dlc.flags & DLCONF_BUFFERMODE) && (dlc.buffermode & DLBM_FRONTONLY)) {
663 GST_DEBUG_OBJECT (dfbvideosink, "no backbuffer");
665 if ((dlc.flags & DLCONF_BUFFERMODE) && (dlc.buffermode & DLBM_BACKVIDEO)) {
666 GST_DEBUG_OBJECT (dfbvideosink, "backbuffer is in video memory");
669 if ((dlc.flags & DLCONF_BUFFERMODE) && (dlc.buffermode & DLBM_BACKSYSTEM)) {
670 GST_DEBUG_OBJECT (dfbvideosink, "backbuffer is in system memory");
673 if ((dlc.flags & DLCONF_BUFFERMODE) && (dlc.buffermode & DLBM_TRIPLE)) {
674 GST_DEBUG_OBJECT (dfbvideosink, "triple buffering");
678 /* If the primary is suitable we prefer using it */
679 if (dfbvideosink->layer_id != DLID_PRIMARY) {
680 GST_DEBUG_OBJECT (dfbvideosink, "selecting layer named %s", desc.name);
681 dfbvideosink->layer_id = id;
682 dfbvideosink->backbuffer = backbuffer;
684 GST_DEBUG_OBJECT (dfbvideosink, "layer %s is suitable but the primary "
685 "is currently selected and we prefer that one", desc.name);
690 layer->Release (layer);
695 static DFBEnumerationResult
696 gst_dfbvideosink_enum_vmodes (gint width, gint height, gint bpp, void *data)
698 GstDfbVideoSink *dfbvideosink = NULL;
699 GstDfbVMode *vmode = NULL;
701 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (data), DFENUM_CANCEL);
703 dfbvideosink = GST_DFBVIDEOSINK (data);
705 GST_DEBUG_OBJECT (dfbvideosink, "adding video mode %dx%d at %d bpp", width,
707 vmode = g_new0 (GstDfbVMode, 1);
708 vmode->width = width;
709 vmode->height = height;
712 /* We need to know the maximum video geometry we can accept for the caps */
713 if (width > dfbvideosink->out_width) {
714 dfbvideosink->out_width = width;
716 if (height > dfbvideosink->out_height) {
717 dfbvideosink->out_height = height;
720 dfbvideosink->vmodes = g_slist_append (dfbvideosink->vmodes, vmode);
725 static DFBEnumerationResult
726 gst_dfbvideosink_enum_devices (DFBInputDeviceID id,
727 DFBInputDeviceDescription desc, void *data)
729 GstDfbVideoSink *dfbvideosink = NULL;
730 IDirectFBInputDevice *device = NULL;
733 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (data), DFENUM_CANCEL);
735 dfbvideosink = GST_DFBVIDEOSINK (data);
737 GST_DEBUG_OBJECT (dfbvideosink, "detected input device %s from vendor %s",
738 desc.name, desc.vendor);
740 /* Get that input device */
741 ret = dfbvideosink->dfb->GetInputDevice (dfbvideosink->dfb, id, &device);
743 GST_WARNING_OBJECT (dfbvideosink, "failed when getting input device id %d",
748 ret = device->AttachEventBuffer (device, dfbvideosink->event_buffer);
750 GST_WARNING_OBJECT (dfbvideosink, "failed when attaching input device "
751 "%d to our event buffer", id);
756 device->Release (device);
762 gst_dfbvideosink_setup (GstDfbVideoSink * dfbvideosink)
766 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), FALSE);
768 dfbvideosink->video_width = 0;
769 dfbvideosink->video_height = 0;
770 dfbvideosink->out_width = 0;
771 dfbvideosink->out_height = 0;
772 dfbvideosink->fps_d = 0;
773 dfbvideosink->fps_n = 0;
774 dfbvideosink->hw_scaling = FALSE;
775 dfbvideosink->backbuffer = FALSE;
776 dfbvideosink->pixel_format = DSPF_UNKNOWN;
778 /* If we do it all by ourself we create the DirectFB context, get the
779 primary layer and use a fullscreen configuration */
780 if (!dfbvideosink->ext_surface) {
781 GST_DEBUG_OBJECT (dfbvideosink, "no external surface, taking over "
782 "DirectFB fullscreen");
783 if (!dfbvideosink->dfb) {
784 DFBGraphicsDeviceDescription hw_caps;
785 char *argv[] = { (char *) "-", (char *) "--dfb:quiet",
786 (char *) "--dfb:no-sighandler", NULL
791 GST_DEBUG_OBJECT (dfbvideosink, "initializing DirectFB");
794 ret = DirectFBInit (&argc, &args);
797 GST_WARNING_OBJECT (dfbvideosink, "DirectFB initialization failed");
801 ret = DirectFBCreate (&(dfbvideosink->dfb));
804 GST_WARNING_OBJECT (dfbvideosink, "failed creating the DirectFB "
809 /* Get Hardware capabilities */
810 ret = dfbvideosink->dfb->GetDeviceDescription (dfbvideosink->dfb,
814 GST_WARNING_OBJECT (dfbvideosink, "failed grabbing the hardware "
819 GST_DEBUG_OBJECT (dfbvideosink, "video card %s from vendor %s detected "
820 "with %d bytes of video memory", hw_caps.name, hw_caps.vendor,
821 hw_caps.video_memory);
823 if (hw_caps.acceleration_mask & DFXL_BLIT) {
824 GST_DEBUG_OBJECT (dfbvideosink, "Blit is accelerated");
826 if (hw_caps.acceleration_mask & DFXL_STRETCHBLIT) {
827 GST_DEBUG_OBJECT (dfbvideosink, "StretchBlit is accelerated");
828 dfbvideosink->hw_scaling = TRUE;
830 GST_DEBUG_OBJECT (dfbvideosink, "StretchBlit is not accelerated");
831 dfbvideosink->hw_scaling = FALSE;
834 dfbvideosink->layer_id = -1;
836 /* Inspect all the Display layers */
837 dfbvideosink->dfb->EnumDisplayLayers (dfbvideosink->dfb,
838 gst_dfbvideosink_enum_layers, dfbvideosink);
839 /* Inspect all Video modes */
840 dfbvideosink->dfb->EnumVideoModes (dfbvideosink->dfb,
841 gst_dfbvideosink_enum_vmodes, dfbvideosink);
843 /* Create an event buffer for input */
844 dfbvideosink->dfb->CreateEventBuffer (dfbvideosink->dfb,
845 &dfbvideosink->event_buffer);
847 /* Inspect all Input devices */
848 dfbvideosink->dfb->EnumInputDevices (dfbvideosink->dfb,
849 gst_dfbvideosink_enum_devices, dfbvideosink);
850 /* Create a thread to handle those events */
851 dfbvideosink->event_thread = g_thread_create (
852 (GThreadFunc) gst_dfbvideosink_event_thread,
853 dfbvideosink, TRUE, NULL);
855 if (!dfbvideosink->layer) {
856 GList *channels_list = NULL;
857 DFBDisplayLayerDescription dl_desc;
859 /* Get the best Display Layer */
860 ret = dfbvideosink->dfb->GetDisplayLayer (dfbvideosink->dfb,
861 dfbvideosink->layer_id, &dfbvideosink->layer);
863 GST_WARNING_OBJECT (dfbvideosink, "failed getting display layer");
867 if (dfbvideosink->layer_mode == LAYER_MODE_EXCLUSIVE ||
868 dfbvideosink->layer_mode == LAYER_MODE_ADMINISTRATIVE)
869 ret = dfbvideosink->layer->SetCooperativeLevel (dfbvideosink->layer,
870 dfbvideosink->layer_mode);
872 GST_ERROR_OBJECT (dfbvideosink, "invalid layer cooperative level");
877 GST_WARNING_OBJECT (dfbvideosink, "failed setting display layer to "
882 dfbvideosink->layer->GetDescription (dfbvideosink->layer, &dl_desc);
884 /* Check that this layer is able to do colorbalance settings */
885 if (dl_desc.caps & DLCAPS_BRIGHTNESS) {
886 channels_list = g_list_append (channels_list, (char *) "BRIGHTNESS");
888 if (dl_desc.caps & DLCAPS_CONTRAST) {
889 channels_list = g_list_append (channels_list, (char *) "CONTRAST");
891 if (dl_desc.caps & DLCAPS_HUE) {
892 channels_list = g_list_append (channels_list, (char *) "HUE");
894 if (dl_desc.caps & DLCAPS_SATURATION) {
895 channels_list = g_list_append (channels_list, (char *) "SATURATION");
899 GList *walk = channels_list;
901 /* Generate Color balance channel list */
903 GstColorBalanceChannel *channel = NULL;
905 GST_DEBUG_OBJECT (dfbvideosink, "adding %s as a colorbalance channel",
906 (const char *) walk->data);
908 channel = g_object_new (GST_TYPE_COLOR_BALANCE_CHANNEL, NULL);
909 channel->label = g_strdup (walk->data);
910 channel->min_value = 0x0000;
911 channel->max_value = 0xFFFF;
913 dfbvideosink->cb_channels = g_list_append (dfbvideosink->cb_channels,
916 walk = g_list_next (walk);
919 /* If the colorbalance settings have not been touched we get current
920 values as defaults and update our internal variables */
921 if (!dfbvideosink->cb_changed) {
922 DFBColorAdjustment cb_adjust;
924 ret = dfbvideosink->layer->GetColorAdjustment (dfbvideosink->layer,
928 GST_WARNING_OBJECT (dfbvideosink, "failed when getting color "
929 "adjustment from layer");
932 if (cb_adjust.flags & DCAF_BRIGHTNESS) {
933 dfbvideosink->brightness = cb_adjust.brightness;
935 dfbvideosink->brightness = 0x8000;
937 if (cb_adjust.flags & DCAF_CONTRAST) {
938 dfbvideosink->contrast = cb_adjust.contrast;
940 dfbvideosink->contrast = 0x8000;
942 if (cb_adjust.flags & DCAF_HUE) {
943 dfbvideosink->hue = cb_adjust.hue;
945 dfbvideosink->hue = 0x8000;
947 if (cb_adjust.flags & DCAF_SATURATION) {
948 dfbvideosink->saturation = cb_adjust.saturation;
950 dfbvideosink->saturation = 0x8000;
952 GST_DEBUG_OBJECT (dfbvideosink, "brightness %d, contrast %d, "
953 "hue %d, saturation %d", dfbvideosink->brightness,
954 dfbvideosink->contrast, dfbvideosink->hue,
955 dfbvideosink->saturation);
958 g_list_free (channels_list);
960 gst_dfbvideosink_update_colorbalance (dfbvideosink);
963 dfbvideosink->layer->SetBackgroundColor (dfbvideosink->layer,
964 0x00, 0x00, 0x00, 0xFF);
966 #if (DIRECTFB_VER >= GST_DFBVIDEOSINK_VER (1,6,0))
967 if (dfbvideosink->layer_mode == LAYER_MODE_ADMINISTRATIVE)
969 dfbvideosink->layer->EnableCursor (dfbvideosink->layer, TRUE);
971 GST_DEBUG_OBJECT (dfbvideosink, "getting primary surface");
972 dfbvideosink->layer->GetSurface (dfbvideosink->layer,
973 &dfbvideosink->primary);
975 dfbvideosink->primary->SetBlittingFlags (dfbvideosink->primary,
979 dfbvideosink->primary->GetPixelFormat (dfbvideosink->primary,
980 &dfbvideosink->pixel_format);
982 DFBSurfaceCapabilities s_caps;
984 GST_DEBUG_OBJECT (dfbvideosink, "getting pixel format from foreign "
985 "surface %p", dfbvideosink->ext_surface);
986 dfbvideosink->ext_surface->GetPixelFormat (dfbvideosink->ext_surface,
987 &dfbvideosink->pixel_format);
988 dfbvideosink->ext_surface->GetSize (dfbvideosink->ext_surface,
989 &dfbvideosink->out_width, &dfbvideosink->out_height);
990 dfbvideosink->ext_surface->GetCapabilities (dfbvideosink->ext_surface,
992 if ((s_caps & DSCAPS_DOUBLE) || (s_caps & DSCAPS_TRIPLE)) {
993 dfbvideosink->backbuffer = TRUE;
995 dfbvideosink->backbuffer = FALSE;
997 GST_DEBUG_OBJECT (dfbvideosink, "external surface is %dx%d and uses %s "
998 "pixel format", dfbvideosink->out_width, dfbvideosink->out_height,
999 gst_dfbvideosink_get_format_name (dfbvideosink->pixel_format));
1002 dfbvideosink->setup = TRUE;
1005 return dfbvideosink->setup;
1009 gst_dfbvideosink_cleanup (GstDfbVideoSink * dfbvideosink)
1011 g_return_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink));
1013 GST_DEBUG_OBJECT (dfbvideosink, "cleaning up DirectFB environment");
1015 /* Wait for our event thread */
1016 if (dfbvideosink->event_thread) {
1017 g_thread_join (dfbvideosink->event_thread);
1018 dfbvideosink->event_thread = NULL;
1021 if (dfbvideosink->event_buffer) {
1022 dfbvideosink->event_buffer->Release (dfbvideosink->event_buffer);
1023 dfbvideosink->event_buffer = NULL;
1026 if (dfbvideosink->vmodes) {
1027 GSList *walk = dfbvideosink->vmodes;
1030 g_free (walk->data);
1031 walk = g_slist_next (walk);
1033 g_slist_free (dfbvideosink->vmodes);
1034 dfbvideosink->vmodes = NULL;
1037 if (dfbvideosink->cb_channels) {
1038 GList *walk = dfbvideosink->cb_channels;
1041 GstColorBalanceChannel *channel = walk->data;
1043 g_object_unref (channel);
1044 walk = g_list_next (walk);
1046 g_list_free (dfbvideosink->cb_channels);
1047 dfbvideosink->cb_channels = NULL;
1050 if (dfbvideosink->pool) {
1051 gst_object_unref (dfbvideosink->pool);
1052 dfbvideosink->pool = NULL;
1055 if (dfbvideosink->primary) {
1056 dfbvideosink->primary->Release (dfbvideosink->primary);
1057 dfbvideosink->primary = NULL;
1060 if (dfbvideosink->layer) {
1061 #if (DIRECTFB_VER >= GST_DFBVIDEOSINK_VER (1,6,0))
1062 if (dfbvideosink->layer_mode == LAYER_MODE_ADMINISTRATIVE)
1064 dfbvideosink->layer->EnableCursor (dfbvideosink->layer, FALSE);
1065 dfbvideosink->layer->Release (dfbvideosink->layer);
1066 dfbvideosink->layer = NULL;
1069 if (dfbvideosink->dfb) {
1070 dfbvideosink->dfb->Release (dfbvideosink->dfb);
1071 dfbvideosink->dfb = NULL;
1074 dfbvideosink->setup = FALSE;
1077 static DFBSurfacePixelFormat
1078 gst_dfbvideosink_get_format_from_caps (GstCaps * caps)
1080 GstStructure *structure;
1081 DFBSurfacePixelFormat pixel_format = DSPF_UNKNOWN;
1083 GstVideoFormat format;
1085 g_return_val_if_fail (GST_IS_CAPS (caps), DSPF_UNKNOWN);
1087 structure = gst_caps_get_structure (caps, 0);
1088 str = gst_structure_get_string (structure, "format");
1090 GST_WARNING ("failed grabbing fourcc from caps %" GST_PTR_FORMAT, caps);
1091 return DSPF_UNKNOWN;
1094 format = gst_video_format_from_string (str);
1096 case GST_VIDEO_FORMAT_RGB16:
1097 pixel_format = DSPF_RGB16;
1099 case GST_VIDEO_FORMAT_RGB:
1100 pixel_format = DSPF_RGB24;
1102 case GST_VIDEO_FORMAT_xRGB:
1103 pixel_format = DSPF_RGB32;
1105 case GST_VIDEO_FORMAT_ARGB:
1106 pixel_format = DSPF_ARGB;
1108 case GST_VIDEO_FORMAT_I420:
1109 pixel_format = DSPF_I420;
1111 case GST_VIDEO_FORMAT_YV12:
1112 pixel_format = DSPF_YV12;
1114 case GST_VIDEO_FORMAT_YUY2:
1115 pixel_format = DSPF_YUY2;
1117 case GST_VIDEO_FORMAT_UYVY:
1118 pixel_format = DSPF_UYVY;
1120 case GST_VIDEO_FORMAT_NV12:
1121 pixel_format = DSPF_NV12;
1124 GST_WARNING ("unhandled pixel format %s", str);
1125 return DSPF_UNKNOWN;
1128 return pixel_format;
1132 gst_dfbvideosink_get_caps_from_format (DFBSurfacePixelFormat format)
1136 g_return_val_if_fail (format != DSPF_UNKNOWN, NULL);
1140 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_RGB16);
1143 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_RGB);
1146 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_xRGB);
1149 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_ARGB);
1152 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_YUY2);
1155 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_UYVY);
1158 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_I420);
1161 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_YV12);
1164 fourcc = gst_video_format_to_string (GST_VIDEO_FORMAT_NV12);
1167 GST_WARNING ("unknown pixel format %s",
1168 gst_dfbvideosink_get_format_name (format));
1172 return gst_caps_new_simple ("video/x-raw", "format", G_TYPE_STRING, fourcc,
1177 gst_dfbvideosink_can_blit_from_format (GstDfbVideoSink * dfbvideosink,
1178 DFBSurfacePixelFormat format, gboolean accelerated)
1180 gboolean res = FALSE;
1182 IDirectFBSurface *surface = NULL;
1183 DFBSurfaceDescription s_dsc;
1184 DFBAccelerationMask mask;
1185 DFBDisplayLayerConfig dlc, prev_dlc;
1187 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), FALSE);
1189 /* Create a surface of desired format */
1190 s_dsc.flags = DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_HEIGHT;
1191 s_dsc.pixelformat = format;
1195 ret = dfbvideosink->dfb->CreateSurface (dfbvideosink->dfb, &s_dsc, &surface);
1196 if (ret != DFB_OK) {
1197 GST_WARNING_OBJECT (dfbvideosink, "failed creating surface with format %s",
1198 gst_dfbvideosink_get_format_name (format));
1202 /* Backup layer configuration */
1203 ret = dfbvideosink->layer->GetConfiguration (dfbvideosink->layer, &prev_dlc);
1204 if (ret != DFB_OK) {
1205 GST_WARNING_OBJECT (dfbvideosink, "failed when getting current layer "
1210 /* Test configuration of the layer to this pixel format */
1211 dlc.flags = DLCONF_PIXELFORMAT;
1212 dlc.pixelformat = format;
1214 ret = dfbvideosink->layer->TestConfiguration (dfbvideosink->layer, &dlc,
1216 if (ret != DFB_OK) {
1217 GST_DEBUG_OBJECT (dfbvideosink, "our layer refuses to operate in pixel "
1218 "format %s", gst_dfbvideosink_get_format_name (format));
1222 ret = dfbvideosink->layer->SetConfiguration (dfbvideosink->layer, &dlc);
1223 if (ret != DFB_OK) {
1224 GST_WARNING_OBJECT (dfbvideosink, "our layer refuses to operate in pixel "
1225 "format, though this format was successfully tested earlied %s",
1226 gst_dfbvideosink_get_format_name (format));
1230 ret = dfbvideosink->primary->GetAccelerationMask (dfbvideosink->primary,
1232 if (ret != DFB_OK) {
1233 GST_WARNING_OBJECT (dfbvideosink, "failed getting acceleration mask");
1237 /* Blitting from this format to our primary is accelerated */
1238 if ((mask & DFXL_BLIT) && accelerated) {
1239 GST_DEBUG_OBJECT (dfbvideosink, "blitting from format %s to our primary "
1240 "is accelerated", gst_dfbvideosink_get_format_name (format));
1242 } else if (!accelerated) {
1243 GST_DEBUG_OBJECT (dfbvideosink, "blitting from format %s to our primary "
1244 "is not accelerated", gst_dfbvideosink_get_format_name (format));
1248 /* Restore original layer configuration */
1249 ret = dfbvideosink->layer->SetConfiguration (dfbvideosink->layer, &prev_dlc);
1250 if (ret != DFB_OK) {
1251 GST_WARNING_OBJECT (dfbvideosink, "failed when restoring layer "
1258 surface->Release (surface);
1264 gst_dfbvideosink_get_best_vmode (GstDfbVideoSink * dfbvideosink, gint v_width,
1265 gint v_height, GstDfbVMode * best_vmode)
1267 GSList *walk = NULL;
1268 gboolean ret = FALSE;
1269 gint width, height, bpp;
1270 GstDfbVMode *vmode = NULL;
1272 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), FALSE);
1274 if (!dfbvideosink->vmodes) {
1278 walk = dfbvideosink->vmodes;
1280 vmode = (GstDfbVMode *) walk->data;
1283 width = vmode->width;
1284 height = vmode->height;
1288 gint wgap, hgap, best_wgap, best_hgap;
1290 vmode = (GstDfbVMode *) walk->data;
1292 /* What are the gaps */
1293 wgap = abs (vmode->width - v_width);
1294 hgap = abs (vmode->height - v_height);
1295 best_wgap = abs (width - v_width);
1296 best_hgap = abs (height - v_height);
1298 /* If this mode is better we ll use that */
1299 if (wgap + hgap < best_wgap + best_hgap) {
1300 width = vmode->width;
1301 height = vmode->height;
1305 walk = g_slist_next (walk);
1308 GST_DEBUG_OBJECT (dfbvideosink, "found video mode %dx%d for input at %dx%d",
1309 width, height, v_width, v_height);
1311 best_vmode->width = width;
1312 best_vmode->height = height;
1313 best_vmode->bpp = bpp;
1322 gst_dfbvideosink_getcaps (GstBaseSink * bsink, GstCaps * filter)
1324 GstDfbVideoSink *dfbvideosink;
1325 GstCaps *caps = NULL;
1326 GstCaps *returned_caps;
1329 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1331 if (!dfbvideosink->setup) {
1332 caps = gst_caps_copy (gst_pad_get_pad_template_caps (GST_VIDEO_SINK_PAD
1334 GST_DEBUG_OBJECT (dfbvideosink, "getcaps called and we are not setup yet, "
1335 "returning template %" GST_PTR_FORMAT, caps);
1338 GST_DEBUG_OBJECT (dfbvideosink, "getcaps called, checking our internal "
1340 if (dfbvideosink->ext_surface) {
1341 /* We are not rendering to our own surface, returning this surface's
1343 caps = gst_dfbvideosink_get_caps_from_format (dfbvideosink->pixel_format);
1345 /* Try some formats */
1346 gboolean accelerated = TRUE;
1347 caps = gst_caps_new_empty ();
1350 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_RGB16,
1352 gst_caps_append (caps,
1353 gst_dfbvideosink_get_caps_from_format (DSPF_RGB16));
1355 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_RGB24,
1357 gst_caps_append (caps,
1358 gst_dfbvideosink_get_caps_from_format (DSPF_RGB24));
1360 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_RGB32,
1362 gst_caps_append (caps,
1363 gst_dfbvideosink_get_caps_from_format (DSPF_RGB32));
1365 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_ARGB,
1367 gst_caps_append (caps,
1368 gst_dfbvideosink_get_caps_from_format (DSPF_ARGB));
1370 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_NV12,
1372 gst_caps_append (caps,
1373 gst_dfbvideosink_get_caps_from_format (DSPF_NV12));
1375 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_YUY2,
1377 gst_caps_append (caps,
1378 gst_dfbvideosink_get_caps_from_format (DSPF_YUY2));
1380 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_UYVY,
1382 gst_caps_append (caps,
1383 gst_dfbvideosink_get_caps_from_format (DSPF_UYVY));
1385 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_I420,
1387 gst_caps_append (caps,
1388 gst_dfbvideosink_get_caps_from_format (DSPF_I420));
1390 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_YV12,
1392 gst_caps_append (caps,
1393 gst_dfbvideosink_get_caps_from_format (DSPF_YV12));
1395 accelerated = !accelerated;
1396 } while (accelerated == FALSE);
1400 for (i = 0; i < gst_caps_get_size (caps); i++) {
1401 GstStructure *structure = gst_caps_get_structure (caps, i);
1403 gst_structure_set (structure,
1404 "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
1405 "height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
1406 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
1408 if (!dfbvideosink->hw_scaling && dfbvideosink->par) {
1411 nom = gst_value_get_fraction_numerator (dfbvideosink->par);
1412 den = gst_value_get_fraction_denominator (dfbvideosink->par);
1413 gst_structure_set (structure, "pixel-aspect-ratio",
1414 GST_TYPE_FRACTION, nom, den, NULL);
1420 returned_caps = gst_caps_intersect_full (filter, caps,
1421 GST_CAPS_INTERSECT_FIRST);
1422 gst_caps_unref (caps);
1424 returned_caps = caps;
1426 GST_DEBUG_OBJECT (dfbvideosink, "returning our caps %" GST_PTR_FORMAT,
1429 return returned_caps;
1433 gst_dfbvideosink_setcaps (GstBaseSink * bsink, GstCaps * caps)
1435 GstDfbVideoSink *dfbvideosink;
1436 GstStructure *structure;
1437 gboolean res, result = FALSE;
1438 gint video_width, video_height;
1439 const GValue *framerate;
1440 DFBSurfacePixelFormat pixel_format = DSPF_UNKNOWN;
1442 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1444 structure = gst_caps_get_structure (caps, 0);
1445 res = gst_structure_get_int (structure, "width", &video_width);
1446 res &= gst_structure_get_int (structure, "height", &video_height);
1447 framerate = gst_structure_get_value (structure, "framerate");
1448 res &= (framerate != NULL);
1453 dfbvideosink->fps_n = gst_value_get_fraction_numerator (framerate);
1454 dfbvideosink->fps_d = gst_value_get_fraction_denominator (framerate);
1456 pixel_format = gst_dfbvideosink_get_format_from_caps (caps);
1458 GST_DEBUG_OBJECT (dfbvideosink, "setcaps called with %" GST_PTR_FORMAT, caps);
1459 GST_DEBUG_OBJECT (dfbvideosink, "our format is: %dx%d %s video at %d/%d fps",
1460 video_width, video_height,
1461 gst_dfbvideosink_get_format_name (pixel_format), dfbvideosink->fps_n,
1462 dfbvideosink->fps_d);
1464 if (dfbvideosink->hw_scaling && dfbvideosink->par) {
1465 gint video_par_n, video_par_d; /* video's PAR */
1466 gint display_par_n, display_par_d; /* display's PAR */
1468 GValue display_ratio = { 0, }; /* display w/h ratio */
1469 const GValue *caps_par;
1471 /* get aspect ratio from caps if it's present, and
1472 * convert video width and height to a display width and height
1473 * using wd / hd = wv / hv * PARv / PARd
1474 * the ratio wd / hd will be stored in display_ratio */
1475 g_value_init (&display_ratio, GST_TYPE_FRACTION);
1477 /* get video's PAR */
1478 caps_par = gst_structure_get_value (structure, "pixel-aspect-ratio");
1480 video_par_n = gst_value_get_fraction_numerator (caps_par);
1481 video_par_d = gst_value_get_fraction_denominator (caps_par);
1486 /* get display's PAR */
1487 if (dfbvideosink->par) {
1488 display_par_n = gst_value_get_fraction_numerator (dfbvideosink->par);
1489 display_par_d = gst_value_get_fraction_denominator (dfbvideosink->par);
1495 gst_value_set_fraction (&display_ratio,
1496 video_width * video_par_n * display_par_d,
1497 video_height * video_par_d * display_par_n);
1499 num = gst_value_get_fraction_numerator (&display_ratio);
1500 den = gst_value_get_fraction_denominator (&display_ratio);
1501 GST_DEBUG_OBJECT (dfbvideosink,
1502 "video width/height: %dx%d, calculated display ratio: %d/%d",
1503 video_width, video_height, num, den);
1505 /* now find a width x height that respects this display ratio.
1506 * prefer those that have one of w/h the same as the incoming video
1507 * using wd / hd = num / den */
1509 /* start with same height, because of interlaced video */
1510 /* check hd / den is an integer scale factor, and scale wd with the PAR */
1511 if (video_height % den == 0) {
1512 GST_DEBUG_OBJECT (dfbvideosink, "keeping video height");
1513 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_height * num / den;
1514 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_height;
1515 } else if (video_width % num == 0) {
1516 GST_DEBUG_OBJECT (dfbvideosink, "keeping video width");
1517 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_width;
1518 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_width * den / num;
1520 GST_DEBUG_OBJECT (dfbvideosink, "approximating while keeping height");
1521 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_height * num / den;
1522 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_height;
1524 GST_DEBUG_OBJECT (dfbvideosink, "scaling to %dx%d",
1525 GST_VIDEO_SINK_WIDTH (dfbvideosink),
1526 GST_VIDEO_SINK_HEIGHT (dfbvideosink));
1528 if (dfbvideosink->par) {
1531 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
1533 if (gst_value_compare (par, dfbvideosink->par) != GST_VALUE_EQUAL) {
1538 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_width;
1539 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_height;
1542 /* Try to adapt the video mode to the video geometry */
1543 if (dfbvideosink->dfb) {
1546 DFBDisplayLayerConfig lc;
1548 GST_DEBUG_OBJECT (dfbvideosink, "trying to adapt the video mode to video "
1551 /* Set video mode and layer configuration appropriately */
1552 if (gst_dfbvideosink_get_best_vmode (dfbvideosink,
1553 GST_VIDEO_SINK_WIDTH (dfbvideosink),
1554 GST_VIDEO_SINK_HEIGHT (dfbvideosink), &vmode)) {
1555 gint width, height, bpp;
1557 width = vmode.width;
1558 height = vmode.height;
1561 GST_DEBUG_OBJECT (dfbvideosink, "setting video mode to %dx%d at %d bpp",
1562 width, height, bpp);
1564 ret = dfbvideosink->dfb->SetVideoMode (dfbvideosink->dfb, width,
1566 if (ret != DFB_OK) {
1567 GST_WARNING_OBJECT (dfbvideosink, "failed setting video mode %dx%d "
1568 "at %d bpp", width, height, bpp);
1572 lc.flags = DLCONF_PIXELFORMAT;
1573 lc.pixelformat = pixel_format;
1575 ret = dfbvideosink->layer->SetConfiguration (dfbvideosink->layer, &lc);
1576 if (ret != DFB_OK) {
1577 GST_WARNING_OBJECT (dfbvideosink, "failed setting layer pixelformat "
1578 "to %s", gst_dfbvideosink_get_format_name (pixel_format));
1580 dfbvideosink->layer->GetConfiguration (dfbvideosink->layer, &lc);
1581 dfbvideosink->out_width = lc.width;
1582 dfbvideosink->out_height = lc.height;
1583 dfbvideosink->pixel_format = lc.pixelformat;
1584 GST_DEBUG_OBJECT (dfbvideosink, "layer %d now configured to %dx%d %s",
1585 dfbvideosink->layer_id, lc.width, lc.height,
1586 gst_dfbvideosink_get_format_name (lc.pixelformat));
1590 if (pixel_format != dfbvideosink->pixel_format) {
1591 GST_WARNING_OBJECT (dfbvideosink, "setcaps sent us a different pixel "
1592 "format %s", gst_dfbvideosink_get_format_name (pixel_format));
1596 dfbvideosink->video_width = video_width;
1597 dfbvideosink->video_height = video_height;
1599 if (dfbvideosink->pool) {
1600 if (gst_buffer_pool_is_active (dfbvideosink->pool))
1601 gst_buffer_pool_set_active (dfbvideosink->pool, FALSE);
1602 gst_object_unref (dfbvideosink->pool);
1605 /* create a new buffer pool of DirectFB surface */
1606 dfbvideosink->pool = gst_dfb_buffer_pool_new (dfbvideosink);
1608 structure = gst_buffer_pool_get_config (dfbvideosink->pool);
1609 gst_buffer_pool_config_set_params (structure, caps, 0, 0, 0);
1610 if (!gst_buffer_pool_set_config (dfbvideosink->pool, structure)) {
1611 GST_WARNING_OBJECT (dfbvideosink,
1612 "failed to set buffer pool configuration");
1615 if (!gst_buffer_pool_set_active (dfbvideosink->pool, TRUE)) {
1616 GST_WARNING_OBJECT (dfbvideosink, "failed to activate buffer pool");
1628 GST_INFO_OBJECT (dfbvideosink, "pixel aspect ratio does not match");
1633 static GstStateChangeReturn
1634 gst_dfbvideosink_change_state (GstElement * element, GstStateChange transition)
1636 GstDfbVideoSink *dfbvideosink;
1637 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1639 dfbvideosink = GST_DFBVIDEOSINK (element);
1641 switch (transition) {
1642 case GST_STATE_CHANGE_NULL_TO_READY:
1643 dfbvideosink->running = TRUE;
1644 if (!dfbvideosink->setup) {
1645 if (!gst_dfbvideosink_setup (dfbvideosink)) {
1646 GST_DEBUG_OBJECT (dfbvideosink, "setup failed when changing state "
1647 "from NULL to READY");
1648 GST_ELEMENT_ERROR (dfbvideosink, RESOURCE, OPEN_WRITE,
1649 (NULL), ("Failed initializing DirectFB system"));
1650 return GST_STATE_CHANGE_FAILURE;
1654 case GST_STATE_CHANGE_READY_TO_PAUSED:
1655 /* Blank surface if we have one */
1656 if (dfbvideosink->ext_surface) {
1657 dfbvideosink->ext_surface->Clear (dfbvideosink->ext_surface,
1658 0x00, 0x00, 0x00, 0xFF);
1660 if (dfbvideosink->primary) {
1661 dfbvideosink->primary->Clear (dfbvideosink->primary, 0x00, 0x00,
1665 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1671 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1672 if (ret == GST_STATE_CHANGE_FAILURE)
1675 switch (transition) {
1676 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1678 case GST_STATE_CHANGE_PAUSED_TO_READY:
1679 dfbvideosink->fps_d = 0;
1680 dfbvideosink->fps_n = 0;
1681 dfbvideosink->video_width = 0;
1682 dfbvideosink->video_height = 0;
1683 if (dfbvideosink->pool)
1684 gst_buffer_pool_set_active (dfbvideosink->pool, FALSE);
1686 case GST_STATE_CHANGE_READY_TO_NULL:
1687 dfbvideosink->running = FALSE;
1688 if (dfbvideosink->setup) {
1689 gst_dfbvideosink_cleanup (dfbvideosink);
1700 gst_dfbvideosink_get_times (GstBaseSink * bsink, GstBuffer * buf,
1701 GstClockTime * start, GstClockTime * end)
1703 GstDfbVideoSink *dfbvideosink;
1705 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1707 if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
1708 *start = GST_BUFFER_TIMESTAMP (buf);
1709 if (GST_BUFFER_DURATION_IS_VALID (buf)) {
1710 *end = *start + GST_BUFFER_DURATION (buf);
1712 if (dfbvideosink->fps_n > 0) {
1714 *start + (GST_SECOND * dfbvideosink->fps_d) / dfbvideosink->fps_n;
1720 static GstFlowReturn
1721 gst_dfbvideosink_show_frame (GstBaseSink * bsink, GstBuffer * buf)
1723 GstDfbVideoSink *dfbvideosink = NULL;
1725 GstVideoRectangle dst, src, result;
1726 GstFlowReturn ret = GST_FLOW_OK;
1727 gboolean mem_cpy = TRUE;
1728 GstMetaDfbSurface *meta;
1730 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1732 if (!dfbvideosink->setup) {
1737 meta = GST_META_DFBSURFACE_GET (buf);
1739 /* Is that a buffer we allocated ourselves ? */
1741 /* Does it have a surface ? */
1742 if (meta->surface) {
1744 GST_DEBUG_OBJECT (dfbvideosink, "we have a buffer (%p) we allocated "
1745 "ourselves and it has a surface, no memcpy then", buf);
1747 /* No surface, that's a malloc */
1748 GST_DEBUG_OBJECT (dfbvideosink, "we have a buffer (%p) we allocated "
1749 "ourselves but it does not hold a surface", buf);
1753 GST_DEBUG_OBJECT (dfbvideosink, "we have a buffer (%p) we did not allocate",
1758 IDirectFBSurface *dest = NULL, *surface = NULL;
1760 gint dest_pitch, line;
1761 GstStructure *structure;
1764 GstVideoInfo src_info;
1765 GstVideoFrame src_frame;
1767 GstVideoFormat format;
1768 guint offset[GST_VIDEO_MAX_PLANES] = { 0 };
1769 guint stride[GST_VIDEO_MAX_PLANES] = { 0 };
1771 /* As we are not blitting no acceleration is possible. If the surface is
1772 * too small we do clipping, if it's too big we center. Theoretically as
1773 * we are using propose_allocation, there's a chance that we have been
1774 * able to do reverse caps negotiation */
1776 if (dfbvideosink->ext_surface) {
1777 surface = dfbvideosink->ext_surface;
1778 GST_DEBUG_OBJECT (dfbvideosink, "memcpy to an external surface "
1779 "subsurface (vsync %d)", dfbvideosink->vsync);
1781 surface = dfbvideosink->primary;
1782 GST_DEBUG_OBJECT (dfbvideosink, "memcpy to a primary subsurface "
1783 "(vsync %d)", dfbvideosink->vsync);
1786 /* Get the video frame geometry from the buffer caps */
1787 caps = gst_pad_get_current_caps (GST_BASE_SINK_PAD (bsink));
1788 structure = gst_caps_get_structure (caps, 0);
1790 gst_structure_get_int (structure, "width", &src.w);
1791 gst_structure_get_int (structure, "height", &src.h);
1793 src.w = dfbvideosink->video_width;
1794 src.h = dfbvideosink->video_height;
1796 gst_caps_unref (caps);
1797 res = surface->GetSize (surface, &dst.w, &dst.h);
1800 gst_video_sink_center_rect (src, dst, &result, FALSE);
1803 surface->GetSubSurface (surface, (DFBRectangle *) (void *) &result,
1805 if (res != DFB_OK) {
1806 GST_WARNING_OBJECT (dfbvideosink, "failed when getting a sub surface");
1811 /* If we are not using Flip we wait for VSYNC before blit */
1812 if (!dfbvideosink->backbuffer && dfbvideosink->vsync) {
1813 dfbvideosink->layer->WaitForSync (dfbvideosink->layer);
1816 res = dest->Lock (dest, DSLF_WRITE, (void *) &data, &dest_pitch);
1817 if (res != DFB_OK) {
1818 GST_WARNING_OBJECT (dfbvideosink, "failed locking the external "
1819 "subsurface for writing");
1820 ret = GST_FLOW_ERROR;
1824 caps = gst_pad_get_current_caps (GST_BASE_SINK_PAD (bsink));
1825 if (!gst_video_info_from_caps (&src_info, caps)) {
1826 GST_WARNING_OBJECT (dfbvideosink, "failed getting video info");
1827 ret = GST_FLOW_ERROR;
1831 str = gst_structure_get_string (structure, "format");
1833 GST_WARNING ("failed grabbing fourcc from caps %" GST_PTR_FORMAT, caps);
1834 ret = GST_FLOW_ERROR;
1837 format = gst_video_format_from_string (str);
1839 gst_caps_unref (caps);
1841 if (!gst_video_frame_map (&src_frame, &src_info, buf, GST_MAP_READ)) {
1842 GST_WARNING_OBJECT (dfbvideosink, "failed mapping frame");
1843 ret = GST_FLOW_ERROR;
1848 case GST_VIDEO_FORMAT_I420:
1849 case GST_VIDEO_FORMAT_YV12:
1850 offset[1] = dest_pitch * ((dfbvideosink->out_height - result.y) +
1852 offset[2] = offset[1] + dest_pitch * dfbvideosink->out_height / 4;
1853 stride[0] = dest_pitch;
1854 stride[1] = stride[2] = dest_pitch / 2;
1856 case GST_VIDEO_FORMAT_NV12:
1857 offset[1] = dest_pitch * (dfbvideosink->out_height - result.y / 2);
1858 stride[0] = stride[1] = dest_pitch;
1861 stride[0] = dest_pitch;
1866 for (plane = 0; plane < src_info.finfo->n_planes; plane++) {
1872 w_buf = data + offset[plane];
1874 plane_h = GST_VIDEO_FRAME_COMP_HEIGHT (&src_frame, plane);
1875 size = MIN (src_info.stride[plane], stride[plane]);
1877 /* Write each line respecting subsurface pitch */
1878 for (plane_line = 0; line < result.h || plane_line < plane_h;
1879 line++, plane_line++) {
1880 /* We do clipping */
1881 memcpy (w_buf, (gchar *) src_frame.data[plane] +
1882 (plane_line * src_info.stride[plane]), size);
1883 w_buf += stride[plane];
1887 gst_video_frame_unmap (&src_frame);
1889 res = dest->Unlock (dest);
1891 dest->Release (dest);
1893 if (dfbvideosink->backbuffer) {
1894 if (dfbvideosink->vsync) {
1895 res = surface->Flip (surface, NULL, DSFLIP_ONSYNC);
1897 res = surface->Flip (surface, NULL, DSFLIP_NONE);
1901 /* Else we will [Stretch]Blit to our primary */
1902 GST_DEBUG_OBJECT (dfbvideosink, "blitting to a primary surface (vsync %d)",
1903 dfbvideosink->vsync);
1905 src.w = GST_VIDEO_SINK_WIDTH (dfbvideosink);
1906 src.h = GST_VIDEO_SINK_HEIGHT (dfbvideosink);
1908 dfbvideosink->primary->GetSize (dfbvideosink->primary, &dst.w, &dst.h);
1910 /* Unlocking surface before blit */
1912 meta->surface->Unlock (meta->surface);
1913 meta->locked = FALSE;
1916 gst_video_sink_center_rect (src, dst, &result, dfbvideosink->hw_scaling);
1918 /* If we are not using Flip we wait for VSYNC before blit */
1919 if (!dfbvideosink->backbuffer && dfbvideosink->vsync) {
1920 dfbvideosink->layer->WaitForSync (dfbvideosink->layer);
1923 if (dfbvideosink->hw_scaling) {
1924 dfbvideosink->primary->StretchBlit (dfbvideosink->primary,
1925 meta->surface, NULL, (DFBRectangle *) (void *) &result);
1929 clip.x = clip.y = 0;
1932 dfbvideosink->primary->Blit (dfbvideosink->primary, meta->surface,
1933 &clip, result.x, result.y);
1936 if (dfbvideosink->backbuffer) {
1937 if (dfbvideosink->vsync) {
1938 dfbvideosink->primary->Flip (dfbvideosink->primary, NULL,
1941 dfbvideosink->primary->Flip (dfbvideosink->primary, NULL, DSFLIP_NONE);
1951 gst_dfbvideosink_navigation_send_event (GstNavigation * navigation,
1952 GstStructure * structure)
1954 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (navigation);
1956 GstVideoRectangle src, dst, result;
1957 double x, y, old_x, old_y;
1960 src.w = GST_VIDEO_SINK_WIDTH (dfbvideosink);
1961 src.h = GST_VIDEO_SINK_HEIGHT (dfbvideosink);
1962 dst.w = dfbvideosink->out_width;
1963 dst.h = dfbvideosink->out_height;
1964 gst_video_sink_center_rect (src, dst, &result, dfbvideosink->hw_scaling);
1966 event = gst_event_new_navigation (structure);
1968 /* Our coordinates can be wrong here if we centered the video */
1970 /* Converting pointer coordinates to the non scaled geometry */
1971 if (gst_structure_get_double (structure, "pointer_x", &old_x)) {
1974 if (x >= result.x && x <= (result.x + result.w)) {
1976 x *= dfbvideosink->video_width;
1981 GST_DEBUG_OBJECT (dfbvideosink, "translated navigation event x "
1982 "coordinate from %f to %f", old_x, x);
1983 gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE, x, NULL);
1985 if (gst_structure_get_double (structure, "pointer_y", &old_y)) {
1988 if (y >= result.y && y <= (result.y + result.h)) {
1990 y *= dfbvideosink->video_height;
1995 GST_DEBUG_OBJECT (dfbvideosink, "translated navigation event y "
1996 "coordinate from %fd to %fd", old_y, y);
1997 gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE, y, NULL);
2000 pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (dfbvideosink));
2002 if (GST_IS_PAD (pad) && GST_IS_EVENT (event)) {
2003 gst_pad_send_event (pad, event);
2005 gst_object_unref (pad);
2010 gst_dfbvideosink_navigation_init (GstNavigationInterface * iface)
2012 iface->send_event = gst_dfbvideosink_navigation_send_event;
2016 gst_dfbvideosink_update_colorbalance (GstDfbVideoSink * dfbvideosink)
2018 g_return_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink));
2020 if (dfbvideosink->layer) {
2021 DFBColorAdjustment cb_adjust;
2023 cb_adjust.flags = DCAF_NONE;
2025 if (dfbvideosink->brightness >= 0) {
2026 cb_adjust.flags |= DCAF_BRIGHTNESS;
2028 if (dfbvideosink->contrast >= 0) {
2029 cb_adjust.flags |= DCAF_CONTRAST;
2031 if (dfbvideosink->hue >= 0) {
2032 cb_adjust.flags |= DCAF_HUE;
2034 if (dfbvideosink->saturation >= 0) {
2035 cb_adjust.flags |= DCAF_SATURATION;
2038 cb_adjust.brightness = dfbvideosink->brightness;
2039 cb_adjust.contrast = dfbvideosink->contrast;
2040 cb_adjust.hue = dfbvideosink->hue;
2041 cb_adjust.saturation = dfbvideosink->saturation;
2043 GST_DEBUG_OBJECT (dfbvideosink, "updating colorbalance: flags %d "
2044 "brightness %d contrast %d hue %d saturation %d", cb_adjust.flags,
2045 cb_adjust.brightness, cb_adjust.contrast, cb_adjust.hue,
2046 cb_adjust.saturation);
2047 dfbvideosink->layer->SetColorAdjustment (dfbvideosink->layer, &cb_adjust);
2051 static const GList *
2052 gst_dfbvideosink_colorbalance_list_channels (GstColorBalance * balance)
2054 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (balance);
2056 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), NULL);
2058 return dfbvideosink->cb_channels;
2062 gst_dfbvideosink_colorbalance_set_value (GstColorBalance * balance,
2063 GstColorBalanceChannel * channel, gint value)
2065 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (balance);
2067 g_return_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink));
2068 g_return_if_fail (channel->label != NULL);
2070 dfbvideosink->cb_changed = TRUE;
2072 if (g_ascii_strcasecmp (channel->label, "HUE") == 0) {
2073 dfbvideosink->hue = value;
2074 } else if (g_ascii_strcasecmp (channel->label, "SATURATION") == 0) {
2075 dfbvideosink->saturation = value;
2076 } else if (g_ascii_strcasecmp (channel->label, "CONTRAST") == 0) {
2077 dfbvideosink->contrast = value;
2078 } else if (g_ascii_strcasecmp (channel->label, "BRIGHTNESS") == 0) {
2079 dfbvideosink->brightness = value;
2081 GST_WARNING_OBJECT (dfbvideosink, "got an unknown channel %s",
2086 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2090 gst_dfbvideosink_colorbalance_get_value (GstColorBalance * balance,
2091 GstColorBalanceChannel * channel)
2093 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (balance);
2096 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), 0);
2097 g_return_val_if_fail (channel->label != NULL, 0);
2099 if (g_ascii_strcasecmp (channel->label, "HUE") == 0) {
2100 value = dfbvideosink->hue;
2101 } else if (g_ascii_strcasecmp (channel->label, "SATURATION") == 0) {
2102 value = dfbvideosink->saturation;
2103 } else if (g_ascii_strcasecmp (channel->label, "CONTRAST") == 0) {
2104 value = dfbvideosink->contrast;
2105 } else if (g_ascii_strcasecmp (channel->label, "BRIGHTNESS") == 0) {
2106 value = dfbvideosink->brightness;
2108 GST_WARNING_OBJECT (dfbvideosink, "got an unknown channel %s",
2115 static GstColorBalanceType
2116 gst_dfbvideosink_colorbalance_get_balance_type (GstColorBalance * balance)
2118 return GST_COLOR_BALANCE_HARDWARE;
2122 gst_dfbvideosink_colorbalance_init (GstColorBalanceInterface * iface)
2124 iface->list_channels = gst_dfbvideosink_colorbalance_list_channels;
2125 iface->set_value = gst_dfbvideosink_colorbalance_set_value;
2126 iface->get_value = gst_dfbvideosink_colorbalance_get_value;
2127 iface->get_balance_type = gst_dfbvideosink_colorbalance_get_balance_type;
2133 gst_dfbvideosink_set_property (GObject * object, guint prop_id,
2134 const GValue * value, GParamSpec * pspec)
2136 GstDfbVideoSink *dfbvideosink;
2138 g_return_if_fail (GST_IS_DFBVIDEOSINK (object));
2139 dfbvideosink = GST_DFBVIDEOSINK (object);
2143 dfbvideosink->ext_surface = g_value_get_pointer (value);
2146 dfbvideosink->hue = g_value_get_int (value);
2147 dfbvideosink->cb_changed = TRUE;
2148 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2151 dfbvideosink->contrast = g_value_get_int (value);
2152 dfbvideosink->cb_changed = TRUE;
2153 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2155 case ARG_BRIGHTNESS:
2156 dfbvideosink->brightness = g_value_get_int (value);
2157 dfbvideosink->cb_changed = TRUE;
2158 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2160 case ARG_SATURATION:
2161 dfbvideosink->saturation = g_value_get_int (value);
2162 dfbvideosink->cb_changed = TRUE;
2163 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2165 case ARG_PIXEL_ASPECT_RATIO:
2166 g_free (dfbvideosink->par);
2167 dfbvideosink->par = g_new0 (GValue, 1);
2168 g_value_init (dfbvideosink->par, GST_TYPE_FRACTION);
2169 if (!g_value_transform (value, dfbvideosink->par)) {
2170 GST_WARNING_OBJECT (dfbvideosink, "Could not transform string to "
2172 gst_value_set_fraction (dfbvideosink->par, 1, 1);
2174 GST_DEBUG_OBJECT (dfbvideosink, "set PAR to %d/%d",
2175 gst_value_get_fraction_numerator (dfbvideosink->par),
2176 gst_value_get_fraction_denominator (dfbvideosink->par));
2179 dfbvideosink->vsync = g_value_get_boolean (value);
2181 case ARG_LAYER_MODE:
2183 const char *str = g_value_get_string (value);
2185 if (strncmp (str, "administrative", strlen ("administrative")) == 0)
2186 dfbvideosink->layer_mode = LAYER_MODE_ADMINISTRATIVE;
2187 else if (strncmp (str, "exclusive", strlen ("exclusive")) == 0)
2188 dfbvideosink->layer_mode = LAYER_MODE_EXCLUSIVE;
2190 dfbvideosink->layer_mode = LAYER_MODE_INVALID;
2194 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2200 gst_dfbvideosink_get_property (GObject * object, guint prop_id,
2201 GValue * value, GParamSpec * pspec)
2203 GstDfbVideoSink *dfbvideosink;
2205 g_return_if_fail (GST_IS_DFBVIDEOSINK (object));
2206 dfbvideosink = GST_DFBVIDEOSINK (object);
2210 g_value_set_int (value, dfbvideosink->hue);
2213 g_value_set_int (value, dfbvideosink->contrast);
2215 case ARG_BRIGHTNESS:
2216 g_value_set_int (value, dfbvideosink->brightness);
2218 case ARG_SATURATION:
2219 g_value_set_int (value, dfbvideosink->saturation);
2221 case ARG_PIXEL_ASPECT_RATIO:
2222 if (dfbvideosink->par)
2223 g_value_transform (dfbvideosink->par, value);
2226 g_value_set_boolean (value, dfbvideosink->vsync);
2228 case ARG_LAYER_MODE:
2229 if (dfbvideosink->layer_mode == LAYER_MODE_EXCLUSIVE)
2230 g_value_set_string (value, "exclusive");
2231 else if (dfbvideosink->layer_mode == LAYER_MODE_ADMINISTRATIVE)
2232 g_value_set_string (value, "administrative");
2234 g_value_set_string (value, "invalid");
2237 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2243 gst_dfbvideosink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
2245 GstDfbVideoSink *dfbvideosink;
2246 GstBufferPool *pool;
2251 dfbvideosink = GST_DFBVIDEOSINK (bsink);
2253 gst_query_parse_allocation (query, &caps, &need_pool);
2255 if ((pool = dfbvideosink->pool))
2256 gst_object_ref (pool);
2260 GstStructure *config;
2262 /* we had a pool, check caps */
2263 config = gst_buffer_pool_get_config (pool);
2264 gst_buffer_pool_config_get_params (config, &pcaps, &size, NULL, NULL);
2266 GST_DEBUG_OBJECT (dfbvideosink,
2267 "buffer pool configuration caps %" GST_PTR_FORMAT, pcaps);
2268 if (!gst_caps_is_equal (caps, pcaps)) {
2269 gst_structure_free (config);
2270 gst_object_unref (pool);
2271 GST_WARNING_OBJECT (dfbvideosink, "pool has different caps");
2274 gst_structure_free (config);
2277 gst_query_add_allocation_pool (query, pool, size, 1, 0);
2279 /* we also support various metadata */
2280 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
2283 gst_object_unref (pool);
2288 /* =========================================== */
2290 /* Init & Class init */
2292 /* =========================================== */
2294 gst_dfbvideosink_finalize (GObject * object)
2296 GstDfbVideoSink *dfbvideosink;
2298 dfbvideosink = GST_DFBVIDEOSINK (object);
2300 if (dfbvideosink->par) {
2301 g_free (dfbvideosink->par);
2302 dfbvideosink->par = NULL;
2304 if (dfbvideosink->setup) {
2305 gst_dfbvideosink_cleanup (dfbvideosink);
2308 G_OBJECT_CLASS (parent_class)->finalize (object);
2312 gst_dfbvideosink_init (GstDfbVideoSink * dfbvideosink)
2314 dfbvideosink->pool = NULL;
2316 dfbvideosink->video_height = dfbvideosink->out_height = 0;
2317 dfbvideosink->video_width = dfbvideosink->out_width = 0;
2318 dfbvideosink->fps_d = 0;
2319 dfbvideosink->fps_n = 0;
2321 dfbvideosink->dfb = NULL;
2322 dfbvideosink->vmodes = NULL;
2323 dfbvideosink->layer_id = -1;
2324 dfbvideosink->layer = NULL;
2325 dfbvideosink->primary = NULL;
2326 dfbvideosink->event_buffer = NULL;
2327 dfbvideosink->event_thread = NULL;
2329 dfbvideosink->ext_surface = NULL;
2331 dfbvideosink->pixel_format = DSPF_UNKNOWN;
2333 dfbvideosink->hw_scaling = FALSE;
2334 dfbvideosink->backbuffer = FALSE;
2335 dfbvideosink->vsync = TRUE;
2336 dfbvideosink->setup = FALSE;
2337 dfbvideosink->running = FALSE;
2339 dfbvideosink->cb_channels = NULL;
2340 dfbvideosink->brightness = -1;
2341 dfbvideosink->contrast = -1;
2342 dfbvideosink->hue = -1;
2343 dfbvideosink->saturation = -1;
2345 dfbvideosink->par = NULL;
2347 dfbvideosink->layer_mode = LAYER_MODE_EXCLUSIVE;
2351 gst_dfbvideosink_class_init (GstDfbVideoSinkClass * klass)
2353 GObjectClass *gobject_class;
2354 GstElementClass *gstelement_class;
2355 GstBaseSinkClass *gstbasesink_class;
2357 gobject_class = (GObjectClass *) klass;
2358 gstelement_class = (GstElementClass *) klass;
2359 gstbasesink_class = (GstBaseSinkClass *) klass;
2361 parent_class = g_type_class_peek_parent (klass);
2363 gobject_class->finalize = gst_dfbvideosink_finalize;
2364 gobject_class->set_property = gst_dfbvideosink_set_property;
2365 gobject_class->get_property = gst_dfbvideosink_get_property;
2367 g_object_class_install_property (gobject_class, ARG_SURFACE,
2368 g_param_spec_pointer ("surface", "Surface",
2369 "The target surface for video",
2370 G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
2371 g_object_class_install_property (gobject_class, ARG_CONTRAST,
2372 g_param_spec_int ("contrast", "Contrast", "The contrast of the video",
2373 0x0000, 0xFFFF, 0x8000, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2374 g_object_class_install_property (gobject_class, ARG_BRIGHTNESS,
2375 g_param_spec_int ("brightness", "Brightness",
2376 "The brightness of the video", 0x0000, 0xFFFF, 0x8000,
2377 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2378 g_object_class_install_property (gobject_class, ARG_HUE,
2379 g_param_spec_int ("hue", "Hue", "The hue of the video", 0x0000, 0xFFFF,
2380 0x8000, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2381 g_object_class_install_property (gobject_class, ARG_SATURATION,
2382 g_param_spec_int ("saturation", "Saturation",
2383 "The saturation of the video", 0x0000, 0xFFFF, 0x8000,
2384 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2385 g_object_class_install_property (gobject_class, ARG_PIXEL_ASPECT_RATIO,
2386 g_param_spec_string ("pixel-aspect-ratio", "Pixel Aspect Ratio",
2387 "The pixel aspect ratio of the device", "1/1",
2388 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2389 g_object_class_install_property (gobject_class, ARG_VSYNC,
2390 g_param_spec_boolean ("vsync", "Vertical synchronisation",
2391 "Wait for next vertical sync to draw frames", TRUE,
2392 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2393 g_object_class_install_property (gobject_class, ARG_LAYER_MODE,
2394 g_param_spec_string ("layer-mode",
2395 "The layer cooperative level (administrative or exclusive)",
2396 "The cooperative level handling the access permission (When the cursor is required, you have to set to 'administrative')",
2397 "exclusive", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2399 gst_element_class_set_static_metadata (gstelement_class,
2400 "DirectFB video sink", "Sink/Video", "A DirectFB based videosink",
2401 "Julien Moutte <julien@moutte.net>");
2403 gst_element_class_add_pad_template (gstelement_class,
2404 gst_static_pad_template_get (&gst_dfbvideosink_sink_template_factory));
2406 gstelement_class->change_state = gst_dfbvideosink_change_state;
2408 gstbasesink_class->get_caps = gst_dfbvideosink_getcaps;
2409 gstbasesink_class->set_caps = gst_dfbvideosink_setcaps;
2410 gstbasesink_class->get_times = gst_dfbvideosink_get_times;
2411 gstbasesink_class->preroll = gst_dfbvideosink_show_frame;
2412 gstbasesink_class->render = gst_dfbvideosink_show_frame;
2413 gstbasesink_class->propose_allocation = gst_dfbvideosink_propose_allocation;
2417 plugin_init (GstPlugin * plugin)
2419 if (!gst_element_register (plugin, "dfbvideosink", GST_RANK_MARGINAL,
2420 GST_TYPE_DFBVIDEOSINK))
2423 GST_DEBUG_CATEGORY_INIT (dfbvideosink_debug, "dfbvideosink", 0,
2424 "DirectFB video sink element");
2429 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
2432 "DirectFB video output plugin",
2433 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)