1 /* GStreamer DirectFB plugin
2 * Copyright (C) 2005 Julien MOUTTE <julien@moutte.net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * SECTION:element-dfbvideosink
23 * DfbVideoSink renders video frames using the
24 * <ulink url="http://www.directfb.org/">DirectFB</ulink> library.
25 * Rendering can happen in two different modes :
29 * Standalone: this mode will take complete control of the monitor forcing
30 * <ulink url="http://www.directfb.org/">DirectFB</ulink> to fullscreen layout.
31 * This is convenient to test using the gst-launch command line tool or
32 * other simple applications. It is possible to interrupt playback while
33 * being in this mode by pressing the Escape key.
36 * This mode handles navigation events for every input device supported by
37 * the <ulink url="http://www.directfb.org/">DirectFB</ulink> library, it will
38 * look for available video modes in the fb.modes file and try to switch
39 * the framebuffer video mode to the most suitable one. Depending on
40 * hardware acceleration capabilities the element will handle scaling or not.
41 * If no acceleration is available it will do clipping or centering of the
42 * video frames respecting the original aspect ratio.
47 * Embedded: this mode will render video frames in a
48 * #GstDfbVideoSink:surface provided by the
49 * application developer. This is a more advanced usage of the element and
50 * it is required to integrate video playback in existing
51 * <ulink url="http://www.directfb.org/">DirectFB</ulink> applications.
54 * When using this mode the element just renders to the
55 * #GstDfbVideoSink:surface provided by the
56 * application, that means it won't handle navigation events and won't resize
57 * the #GstDfbVideoSink:surface to fit video
58 * frames geometry. Application has to implement the necessary code to grab
59 * informations about the negotiated geometry and resize there
60 * #GstDfbVideoSink:surface accordingly.
64 * For both modes the element implements a buffer pool allocation system to
65 * optimize memory allocation time and handle reverse negotiation. Indeed if
66 * you insert an element like videoscale in the pipeline the video sink will
67 * negotiate with it to try get a scaled video for either the fullscreen layout
68 * or the application provided external #GstDfbVideoSink:surface.
71 * <title>Example application</title>
73 * <include xmlns="http://www.w3.org/2003/XInclude" href="element-dfb-example.xml" />
77 * <title>Example pipelines</title>
79 * gst-launch -v videotestsrc ! dfbvideosink hue=20000 saturation=40000 brightness=25000
80 * ]| test the colorbalance interface implementation in dfbvideosink
89 #include <gst/interfaces/navigation.h>
90 #include <gst/interfaces/colorbalance.h>
93 #include "dfbvideosink.h"
98 /* Debugging category */
99 GST_DEBUG_CATEGORY_STATIC (dfbvideosink_debug);
100 #define GST_CAT_DEFAULT dfbvideosink_debug
102 /* Default template */
103 static GstStaticPadTemplate gst_dfbvideosink_sink_template_factory =
104 GST_STATIC_PAD_TEMPLATE ("sink",
107 GST_STATIC_CAPS ("video/x-raw-rgb, "
108 "framerate = (fraction) [ 0, MAX ], "
109 "width = (int) [ 1, MAX ], "
110 "height = (int) [ 1, MAX ]; "
112 "framerate = (fraction) [ 0, MAX ], "
113 "width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ]")
116 /* Signals and args */
125 ARG_PIXEL_ASPECT_RATIO,
129 static void gst_dfbvideosink_bufferpool_clear (GstDfbVideoSink * dfbvideosink);
130 static DFBSurfacePixelFormat gst_dfbvideosink_get_format_from_caps (GstCaps *
132 static void gst_dfbvideosink_update_colorbalance (GstDfbVideoSink *
134 static void gst_dfbvideosink_surface_destroy (GstDfbVideoSink * dfbvideosink,
135 GstBuffer * surface);
137 static GstVideoSinkClass *parent_class = NULL;
139 #ifndef GST_DISABLE_GST_DEBUG
141 gst_dfbvideosink_get_format_name (DFBSurfacePixelFormat format)
188 #endif /* GST_DISABLE_GST_DEBUG */
191 gst_dfbsurface_dispose (GstBuffer * surface)
193 GstDfbVideoSink *dfbvideosink = NULL;
194 GstMetaDfbSurface *meta;
196 g_return_if_fail (surface != NULL);
198 meta = GST_META_DFBSURFACE_GET (surface);
200 dfbvideosink = meta->dfbvideosink;
202 GST_WARNING_OBJECT (surface, "no sink found");
206 /* If our geometry changed we can't reuse that image. */
207 if ((meta->width != dfbvideosink->video_width) ||
208 (meta->height != dfbvideosink->video_height) ||
209 (meta->pixel_format != dfbvideosink->pixel_format)) {
210 GST_DEBUG_OBJECT (dfbvideosink, "destroy surface %p as its size changed "
211 "%dx%d vs current %dx%d", surface, meta->width, meta->height,
212 dfbvideosink->video_width, dfbvideosink->video_height);
213 gst_dfbvideosink_surface_destroy (dfbvideosink, surface);
215 /* In that case we can reuse the image and add it to our image pool. */
216 GST_DEBUG_OBJECT (dfbvideosink, "recycling surface %p in pool", surface);
217 /* need to increment the refcount again to recycle */
218 gst_buffer_ref (surface);
219 g_mutex_lock (dfbvideosink->pool_lock);
220 dfbvideosink->buffer_pool = g_slist_prepend (dfbvideosink->buffer_pool,
222 g_mutex_unlock (dfbvideosink->pool_lock);
229 /* Creates miniobject and our internal surface */
231 gst_dfbvideosink_surface_create (GstDfbVideoSink * dfbvideosink, GstCaps * caps,
234 GstBuffer *surface = NULL;
235 GstMetaDfbSurface *meta = NULL;
236 GstStructure *structure = NULL;
238 DFBSurfaceDescription s_dsc;
241 gboolean succeeded = FALSE;
243 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), NULL);
245 surface = gst_buffer_new ();
246 GST_MINI_OBJECT_CAST (surface)->dispose =
247 (GstMiniObjectDisposeFunction) gst_dfbsurface_dispose;
248 meta = GST_META_DFBSURFACE_ADD (surface);
250 /* Keep a ref to our sink */
251 meta->dfbvideosink = gst_object_ref (dfbvideosink);
252 /* Surface is not locked yet */
253 meta->locked = FALSE;
255 structure = gst_caps_get_structure (caps, 0);
257 if (!gst_structure_get_int (structure, "width", &meta->width) ||
258 !gst_structure_get_int (structure, "height", &meta->height)) {
259 GST_WARNING_OBJECT (dfbvideosink, "failed getting geometry from caps %"
260 GST_PTR_FORMAT, caps);
264 /* Pixel format from caps */
265 meta->pixel_format = gst_dfbvideosink_get_format_from_caps (caps);
266 if (meta->pixel_format == DSPF_UNKNOWN) {
270 if (!dfbvideosink->dfb) {
271 GST_DEBUG_OBJECT (dfbvideosink, "no DirectFB context to create a surface");
275 /* Creating an internal surface which will be used as GstBuffer, we used
276 the detected pixel format and video dimensions */
279 DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_HEIGHT /*| DSDESC_CAPS */ ;
281 s_dsc.pixelformat = meta->pixel_format;
282 s_dsc.width = meta->width;
283 s_dsc.height = meta->height;
284 /*s_dsc.caps = DSCAPS_VIDEOONLY; */
286 ret = dfbvideosink->dfb->CreateSurface (dfbvideosink->dfb, &s_dsc,
289 GST_WARNING_OBJECT (dfbvideosink, "failed creating a DirectFB surface");
290 meta->surface = NULL;
294 /* Clearing surface */
295 meta->surface->Clear (meta->surface, 0x00, 0x00, 0x00, 0xFF);
297 /* Locking the surface to acquire the memory pointer */
298 meta->surface->Lock (meta->surface, DSLF_WRITE, &data, &pitch);
300 GST_BUFFER_DATA (surface) = data;
301 GST_BUFFER_SIZE (surface) = pitch * meta->height;
303 /* Be carefull here. If size is different from the surface size
304 (pitch * height), we can't use that surface through buffer alloc system
305 or we are going to run into serious stride issues */
306 if (GST_BUFFER_SIZE (surface) != size) {
307 GST_WARNING_OBJECT (dfbvideosink, "DirectFB surface size (%dx%d=%d) "
308 "differs from GStreamer requested size %u", pitch, meta->height,
309 GST_BUFFER_SIZE (surface), (guint) size);
313 GST_DEBUG_OBJECT (dfbvideosink, "creating a %dx%d surface (%p) with %s "
314 "pixel format, line pitch %d", meta->width, meta->height, surface,
315 gst_dfbvideosink_get_format_name (meta->pixel_format), pitch);
323 /* We allocate a standard buffer ourselves to store it in our buffer pool,
324 this is an optimisation for memory allocation */
325 GST_BUFFER_MALLOCDATA (surface) = g_malloc (size);
326 GST_BUFFER_DATA (surface) = GST_BUFFER_MALLOCDATA (surface);
327 GST_BUFFER_SIZE (surface) = size;
331 meta->surface->Unlock (meta->surface);
332 meta->locked = FALSE;
334 meta->surface->Release (meta->surface);
335 meta->surface = NULL;
337 GST_DEBUG_OBJECT (dfbvideosink, "allocating a buffer (%p) of %u bytes",
338 surface, (guint) size);
344 gst_dfbvideosink_surface_destroy (dfbvideosink, surface);
350 /* We are called from the finalize method of miniobject, the object will be
351 * destroyed so we just have to clean our internal stuff */
353 gst_dfbvideosink_surface_destroy (GstDfbVideoSink * dfbvideosink,
356 GstMetaDfbSurface *meta;
358 g_return_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink));
360 meta = GST_META_DFBSURFACE_GET (surface);
362 /* Release our internal surface */
365 meta->surface->Unlock (meta->surface);
366 meta->locked = FALSE;
368 meta->surface->Release (meta->surface);
369 meta->surface = NULL;
372 if (meta->dfbvideosink) {
373 /* Release the ref to our sink */
374 meta->dfbvideosink = NULL;
375 gst_object_unref (dfbvideosink);
380 gst_dfbvideosink_event_thread (GstDfbVideoSink * dfbvideosink)
384 while (dfbvideosink->running) {
385 /* Wait for an event with a 50 ms timeout */
386 dfbvideosink->event_buffer->
387 WaitForEventWithTimeout (dfbvideosink->event_buffer, 0, 50);
389 /* Do we have an event ? */
390 ret = dfbvideosink->event_buffer->HasEvent (dfbvideosink->event_buffer);
395 GST_DEBUG_OBJECT (dfbvideosink, "we have an event");
397 ret = dfbvideosink->event_buffer->GetEvent (dfbvideosink->event_buffer,
399 if (ret != DFB_OK) { /* Error */
400 GST_WARNING_OBJECT (dfbvideosink, "failed when getting event from "
402 } else { /* Handle event */
403 if (event.input.type == DIET_KEYPRESS) {
404 switch (event.input.key_symbol) {
407 GST_ELEMENT_ERROR (dfbvideosink, RESOURCE, OPEN_WRITE,
408 ("Video output device is gone."),
409 ("We were running fullscreen and user "
410 "pressed the ESC key, stopping playback."));
413 GST_DEBUG_OBJECT (dfbvideosink, "key press event %c !",
414 event.input.key_symbol);
415 gst_navigation_send_key_event (GST_NAVIGATION (dfbvideosink),
416 "key-press", "prout");
418 } else if (event.input.type == DIET_BUTTONPRESS) {
421 dfbvideosink->layer->GetCursorPosition (dfbvideosink->layer, &x, &y);
423 GST_DEBUG_OBJECT (dfbvideosink, "button %d pressed at %dx%d",
424 event.input.button, x, y);
426 gst_navigation_send_mouse_event (GST_NAVIGATION (dfbvideosink),
427 "mouse-button-press", event.input.button, x, y);
428 } else if (event.input.type == DIET_BUTTONRELEASE) {
431 dfbvideosink->layer->GetCursorPosition (dfbvideosink->layer, &x, &y);
433 GST_DEBUG_OBJECT (dfbvideosink, "button %d released at %dx%d",
434 event.input.button, x, y);
436 gst_navigation_send_mouse_event (GST_NAVIGATION (dfbvideosink),
437 "mouse-button-release", event.input.button, x, y);
438 } else if (event.input.type == DIET_AXISMOTION) {
441 dfbvideosink->layer->GetCursorPosition (dfbvideosink->layer, &x, &y);
442 gst_navigation_send_mouse_event (GST_NAVIGATION (dfbvideosink),
443 "mouse-move", 0, x, y);
445 GST_WARNING_OBJECT (dfbvideosink, "unhandled event type %d",
454 static DFBEnumerationResult
455 gst_dfbvideosink_enum_layers (DFBDisplayLayerID id,
456 DFBDisplayLayerDescription desc, void *data)
458 GstDfbVideoSink *dfbvideosink = NULL;
459 IDirectFBDisplayLayer *layer = NULL;
460 DFBDisplayLayerConfig dlc;
462 gboolean backbuffer = FALSE;
464 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (data), DFENUM_CANCEL);
466 dfbvideosink = GST_DFBVIDEOSINK (data);
468 GST_DEBUG_OBJECT (dfbvideosink, "inspecting display layer %d with name: %s",
471 if ((desc.type & DLTF_VIDEO) && (desc.caps & DLCAPS_SURFACE)) {
472 GST_DEBUG_OBJECT (dfbvideosink,
473 "this layer can handle live video and has a surface");
475 if (desc.caps & DLCAPS_SURFACE) {
476 GST_DEBUG_OBJECT (dfbvideosink,
477 "this layer can not handle live video but has a surface");
479 GST_DEBUG_OBJECT (dfbvideosink, "no we can't use that layer, really...");
484 ret = dfbvideosink->dfb->GetDisplayLayer (dfbvideosink->dfb, id, &layer);
486 GST_WARNING_OBJECT (dfbvideosink, "failed getting display layer %s",
491 ret = layer->GetConfiguration (layer, &dlc);
493 GST_WARNING_OBJECT (dfbvideosink,
494 "failed getting display layer configuration");
498 if ((dlc.flags & DLCONF_BUFFERMODE) && (dlc.buffermode & DLBM_FRONTONLY)) {
499 GST_DEBUG_OBJECT (dfbvideosink, "no backbuffer");
501 if ((dlc.flags & DLCONF_BUFFERMODE) && (dlc.buffermode & DLBM_BACKVIDEO)) {
502 GST_DEBUG_OBJECT (dfbvideosink, "backbuffer is in video memory");
505 if ((dlc.flags & DLCONF_BUFFERMODE) && (dlc.buffermode & DLBM_BACKSYSTEM)) {
506 GST_DEBUG_OBJECT (dfbvideosink, "backbuffer is in system memory");
509 if ((dlc.flags & DLCONF_BUFFERMODE) && (dlc.buffermode & DLBM_TRIPLE)) {
510 GST_DEBUG_OBJECT (dfbvideosink, "triple buffering");
514 /* If the primary is suitable we prefer using it */
515 if (dfbvideosink->layer_id != DLID_PRIMARY) {
516 GST_DEBUG_OBJECT (dfbvideosink, "selecting layer named %s", desc.name);
517 dfbvideosink->layer_id = id;
518 dfbvideosink->backbuffer = backbuffer;
520 GST_DEBUG_OBJECT (dfbvideosink, "layer %s is suitable but the primary "
521 "is currently selected and we prefer that one", desc.name);
526 layer->Release (layer);
531 static DFBEnumerationResult
532 gst_dfbvideosink_enum_vmodes (gint width, gint height, gint bpp, void *data)
534 GstDfbVideoSink *dfbvideosink = NULL;
535 GstDfbVMode *vmode = NULL;
537 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (data), DFENUM_CANCEL);
539 dfbvideosink = GST_DFBVIDEOSINK (data);
541 GST_DEBUG_OBJECT (dfbvideosink, "adding video mode %dx%d at %d bpp", width,
543 vmode = g_new0 (GstDfbVMode, 1);
544 vmode->width = width;
545 vmode->height = height;
548 /* We need to know the maximum video geometry we can accept for the caps */
549 if (width > dfbvideosink->out_width) {
550 dfbvideosink->out_width = width;
552 if (height > dfbvideosink->out_height) {
553 dfbvideosink->out_height = height;
556 dfbvideosink->vmodes = g_slist_append (dfbvideosink->vmodes, vmode);
561 static DFBEnumerationResult
562 gst_dfbvideosink_enum_devices (DFBInputDeviceID id,
563 DFBInputDeviceDescription desc, void *data)
565 GstDfbVideoSink *dfbvideosink = NULL;
566 IDirectFBInputDevice *device = NULL;
569 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (data), DFENUM_CANCEL);
571 dfbvideosink = GST_DFBVIDEOSINK (data);
573 GST_DEBUG_OBJECT (dfbvideosink, "detected input device %s from vendor %s",
574 desc.name, desc.vendor);
576 /* Get that input device */
577 ret = dfbvideosink->dfb->GetInputDevice (dfbvideosink->dfb, id, &device);
579 GST_WARNING_OBJECT (dfbvideosink, "failed when getting input device id %d",
584 ret = device->AttachEventBuffer (device, dfbvideosink->event_buffer);
586 GST_WARNING_OBJECT (dfbvideosink, "failed when attaching input device "
587 "%d to our event buffer", id);
592 device->Release (device);
598 gst_dfbvideosink_setup (GstDfbVideoSink * dfbvideosink)
602 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), FALSE);
604 dfbvideosink->video_width = 0;
605 dfbvideosink->video_height = 0;
606 dfbvideosink->out_width = 0;
607 dfbvideosink->out_height = 0;
608 dfbvideosink->fps_d = 0;
609 dfbvideosink->fps_n = 0;
610 dfbvideosink->hw_scaling = FALSE;
611 dfbvideosink->backbuffer = FALSE;
612 dfbvideosink->pixel_format = DSPF_UNKNOWN;
614 /* If we do it all by ourself we create the DirectFB context, get the
615 primary layer and use a fullscreen configuration */
616 if (!dfbvideosink->ext_surface) {
617 GST_DEBUG_OBJECT (dfbvideosink, "no external surface, taking over "
618 "DirectFB fullscreen");
619 if (!dfbvideosink->dfb) {
620 DFBGraphicsDeviceDescription hw_caps;
621 char *argv[] = { (char *) "-", (char *) "--dfb:quiet", NULL };
625 GST_DEBUG_OBJECT (dfbvideosink, "initializing DirectFB");
628 ret = DirectFBInit (&argc, &args);
631 GST_WARNING_OBJECT (dfbvideosink, "DirectFB initialization failed");
635 ret = DirectFBCreate (&(dfbvideosink->dfb));
638 GST_WARNING_OBJECT (dfbvideosink, "failed creating the DirectFB "
643 /* Get Hardware capabilities */
644 ret = dfbvideosink->dfb->GetDeviceDescription (dfbvideosink->dfb,
648 GST_WARNING_OBJECT (dfbvideosink, "failed grabbing the hardware "
653 GST_DEBUG_OBJECT (dfbvideosink, "video card %s from vendor %s detected "
654 "with %d bytes of video memory", hw_caps.name, hw_caps.vendor,
655 hw_caps.video_memory);
657 if (hw_caps.acceleration_mask & DFXL_BLIT) {
658 GST_DEBUG_OBJECT (dfbvideosink, "Blit is accelerated");
660 if (hw_caps.acceleration_mask & DFXL_STRETCHBLIT) {
661 GST_DEBUG_OBJECT (dfbvideosink, "StretchBlit is accelerated");
662 dfbvideosink->hw_scaling = TRUE;
664 GST_DEBUG_OBJECT (dfbvideosink, "StretchBlit is not accelerated");
665 dfbvideosink->hw_scaling = FALSE;
668 dfbvideosink->layer_id = -1;
670 /* Inspect all the Display layers */
671 dfbvideosink->dfb->EnumDisplayLayers (dfbvideosink->dfb,
672 gst_dfbvideosink_enum_layers, dfbvideosink);
673 /* Inspect all Video modes */
674 dfbvideosink->dfb->EnumVideoModes (dfbvideosink->dfb,
675 gst_dfbvideosink_enum_vmodes, dfbvideosink);
677 /* Create an event buffer for input */
678 dfbvideosink->dfb->CreateEventBuffer (dfbvideosink->dfb,
679 &dfbvideosink->event_buffer);
681 /* Inspect all Input devices */
682 dfbvideosink->dfb->EnumInputDevices (dfbvideosink->dfb,
683 gst_dfbvideosink_enum_devices, dfbvideosink);
684 /* Create a thread to handle those events */
685 dfbvideosink->event_thread = g_thread_create (
686 (GThreadFunc) gst_dfbvideosink_event_thread,
687 dfbvideosink, TRUE, NULL);
689 if (!dfbvideosink->layer) {
690 GList *channels_list = NULL;
691 DFBDisplayLayerDescription dl_desc;
693 /* Get the best Display Layer */
694 ret = dfbvideosink->dfb->GetDisplayLayer (dfbvideosink->dfb,
695 dfbvideosink->layer_id, &dfbvideosink->layer);
697 GST_WARNING_OBJECT (dfbvideosink, "failed getting display layer");
701 ret = dfbvideosink->layer->SetCooperativeLevel (dfbvideosink->layer,
705 GST_WARNING_OBJECT (dfbvideosink, "failed setting display layer to "
710 dfbvideosink->layer->GetDescription (dfbvideosink->layer, &dl_desc);
712 /* Check that this layer is able to do colorbalance settings */
713 if (dl_desc.caps & DLCAPS_BRIGHTNESS) {
714 channels_list = g_list_append (channels_list, (char *) "BRIGHTNESS");
716 if (dl_desc.caps & DLCAPS_CONTRAST) {
717 channels_list = g_list_append (channels_list, (char *) "CONTRAST");
719 if (dl_desc.caps & DLCAPS_HUE) {
720 channels_list = g_list_append (channels_list, (char *) "HUE");
722 if (dl_desc.caps & DLCAPS_SATURATION) {
723 channels_list = g_list_append (channels_list, (char *) "SATURATION");
727 GList *walk = channels_list;
729 /* Generate Color balance channel list */
731 GstColorBalanceChannel *channel = NULL;
733 GST_DEBUG_OBJECT (dfbvideosink, "adding %s as a colorbalance channel",
734 (const char *) walk->data);
736 channel = g_object_new (GST_TYPE_COLOR_BALANCE_CHANNEL, NULL);
737 channel->label = g_strdup (walk->data);
738 channel->min_value = 0x0000;
739 channel->max_value = 0xFFFF;
741 dfbvideosink->cb_channels = g_list_append (dfbvideosink->cb_channels,
744 walk = g_list_next (walk);
747 /* If the colorbalance settings have not been touched we get current
748 values as defaults and update our internal variables */
749 if (!dfbvideosink->cb_changed) {
750 DFBColorAdjustment cb_adjust;
752 ret = dfbvideosink->layer->GetColorAdjustment (dfbvideosink->layer,
756 GST_WARNING_OBJECT (dfbvideosink, "failed when getting color "
757 "adjustment from layer");
760 if (cb_adjust.flags & DCAF_BRIGHTNESS) {
761 dfbvideosink->brightness = cb_adjust.brightness;
763 dfbvideosink->brightness = 0x8000;
765 if (cb_adjust.flags & DCAF_CONTRAST) {
766 dfbvideosink->contrast = cb_adjust.contrast;
768 dfbvideosink->contrast = 0x8000;
770 if (cb_adjust.flags & DCAF_HUE) {
771 dfbvideosink->hue = cb_adjust.hue;
773 dfbvideosink->hue = 0x8000;
775 if (cb_adjust.flags & DCAF_SATURATION) {
776 dfbvideosink->saturation = cb_adjust.saturation;
778 dfbvideosink->saturation = 0x8000;
780 GST_DEBUG_OBJECT (dfbvideosink, "brightness %d, contrast %d, "
781 "hue %d, saturation %d", dfbvideosink->brightness,
782 dfbvideosink->contrast, dfbvideosink->hue,
783 dfbvideosink->saturation);
786 g_list_free (channels_list);
788 gst_dfbvideosink_update_colorbalance (dfbvideosink);
791 dfbvideosink->layer->SetBackgroundColor (dfbvideosink->layer,
792 0x00, 0x00, 0x00, 0xFF);
794 dfbvideosink->layer->EnableCursor (dfbvideosink->layer, TRUE);
796 GST_DEBUG_OBJECT (dfbvideosink, "getting primary surface");
797 dfbvideosink->layer->GetSurface (dfbvideosink->layer,
798 &dfbvideosink->primary);
800 dfbvideosink->primary->SetBlittingFlags (dfbvideosink->primary,
804 dfbvideosink->primary->GetPixelFormat (dfbvideosink->primary,
805 &dfbvideosink->pixel_format);
807 DFBSurfaceCapabilities s_caps;
809 GST_DEBUG_OBJECT (dfbvideosink, "getting pixel format from foreign "
810 "surface %p", dfbvideosink->ext_surface);
811 dfbvideosink->ext_surface->GetPixelFormat (dfbvideosink->ext_surface,
812 &dfbvideosink->pixel_format);
813 dfbvideosink->ext_surface->GetSize (dfbvideosink->ext_surface,
814 &dfbvideosink->out_width, &dfbvideosink->out_height);
815 dfbvideosink->ext_surface->GetCapabilities (dfbvideosink->ext_surface,
817 if ((s_caps & DSCAPS_DOUBLE) || (s_caps & DSCAPS_TRIPLE)) {
818 dfbvideosink->backbuffer = TRUE;
820 dfbvideosink->backbuffer = FALSE;
822 GST_DEBUG_OBJECT (dfbvideosink, "external surface is %dx%d and uses %s "
823 "pixel format", dfbvideosink->out_width, dfbvideosink->out_height,
824 gst_dfbvideosink_get_format_name (dfbvideosink->pixel_format));
827 dfbvideosink->setup = TRUE;
830 return dfbvideosink->setup;
834 gst_dfbvideosink_cleanup (GstDfbVideoSink * dfbvideosink)
836 g_return_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink));
838 GST_DEBUG_OBJECT (dfbvideosink, "cleaning up DirectFB environment");
840 /* Wait for our event thread */
841 if (dfbvideosink->event_thread) {
842 g_thread_join (dfbvideosink->event_thread);
843 dfbvideosink->event_thread = NULL;
846 if (dfbvideosink->event_buffer) {
847 dfbvideosink->event_buffer->Release (dfbvideosink->event_buffer);
848 dfbvideosink->event_buffer = NULL;
851 if (dfbvideosink->vmodes) {
852 GSList *walk = dfbvideosink->vmodes;
856 walk = g_slist_next (walk);
858 g_slist_free (dfbvideosink->vmodes);
859 dfbvideosink->vmodes = NULL;
862 if (dfbvideosink->cb_channels) {
863 GList *walk = dfbvideosink->cb_channels;
866 GstColorBalanceChannel *channel = walk->data;
868 g_object_unref (channel);
869 walk = g_list_next (walk);
871 g_list_free (dfbvideosink->cb_channels);
872 dfbvideosink->cb_channels = NULL;
875 if (dfbvideosink->buffer_pool) {
876 gst_dfbvideosink_bufferpool_clear (dfbvideosink);
879 if (dfbvideosink->primary) {
880 dfbvideosink->primary->Release (dfbvideosink->primary);
881 dfbvideosink->primary = NULL;
884 if (dfbvideosink->layer) {
885 dfbvideosink->layer->EnableCursor (dfbvideosink->layer, FALSE);
886 dfbvideosink->layer->Release (dfbvideosink->layer);
887 dfbvideosink->layer = NULL;
890 if (dfbvideosink->dfb) {
891 dfbvideosink->dfb->Release (dfbvideosink->dfb);
892 dfbvideosink->dfb = NULL;
895 dfbvideosink->setup = FALSE;
898 static DFBSurfacePixelFormat
899 gst_dfbvideosink_get_format_from_caps (GstCaps * caps)
901 GstStructure *structure;
903 DFBSurfacePixelFormat pixel_format = DSPF_UNKNOWN;
905 g_return_val_if_fail (GST_IS_CAPS (caps), DSPF_UNKNOWN);
907 structure = gst_caps_get_structure (caps, 0);
909 if (gst_structure_has_name (structure, "video/x-raw-rgb")) {
912 ret = gst_structure_get_int (structure, "bpp", &bpp);
913 ret &= gst_structure_get_int (structure, "depth", &depth);
921 pixel_format = DSPF_RGB16;
924 pixel_format = DSPF_RGB24;
928 pixel_format = DSPF_RGB32;
929 } else if (depth == 32) {
930 pixel_format = DSPF_ARGB;
936 GST_WARNING ("unhandled RGB format, bpp %d, depth %d", bpp, depth);
939 } else if (gst_structure_has_name (structure, "video/x-raw-yuv")) {
942 ret = gst_structure_get_fourcc (structure, "format", &fourcc);
945 GST_WARNING ("failed grabbing fourcc from caps %" GST_PTR_FORMAT, caps);
950 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
951 pixel_format = DSPF_I420;
953 case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
954 pixel_format = DSPF_YV12;
956 case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
957 pixel_format = DSPF_YUY2;
959 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
960 pixel_format = DSPF_UYVY;
963 GST_WARNING ("unhandled YUV format %" GST_FOURCC_FORMAT,
964 GST_FOURCC_ARGS (fourcc));
968 GST_WARNING ("unknown caps name received %" GST_PTR_FORMAT, caps);
977 gst_dfbvideosink_get_caps_from_format (DFBSurfacePixelFormat format)
979 GstCaps *caps = NULL;
980 gboolean is_rgb = FALSE, is_yuv = FALSE;
984 g_return_val_if_fail (format != DSPF_UNKNOWN, NULL);
1009 fourcc = GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
1013 fourcc = GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y');
1017 fourcc = GST_MAKE_FOURCC ('I', '4', '2', '0');
1021 fourcc = GST_MAKE_FOURCC ('Y', 'V', '1', '2');
1024 GST_WARNING ("unknown pixel format %s",
1025 gst_dfbvideosink_get_format_name (format));
1030 caps = gst_caps_new_simple ("video/x-raw-rgb",
1031 "bpp", G_TYPE_INT, bpp, "depth", G_TYPE_INT, depth, NULL);
1032 } else if (is_yuv) {
1033 caps = gst_caps_new_simple ("video/x-raw-yuv",
1034 "format", GST_TYPE_FOURCC, fourcc, NULL);
1036 GST_WARNING ("neither rgb nor yuv, something strange here");
1044 gst_dfbvideosink_can_blit_from_format (GstDfbVideoSink * dfbvideosink,
1045 DFBSurfacePixelFormat format, gboolean accelerated)
1047 gboolean res = FALSE;
1049 IDirectFBSurface *surface = NULL;
1050 DFBSurfaceDescription s_dsc;
1051 DFBAccelerationMask mask;
1052 DFBDisplayLayerConfig dlc, prev_dlc;
1054 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), FALSE);
1056 /* Create a surface of desired format */
1057 s_dsc.flags = DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_HEIGHT;
1058 s_dsc.pixelformat = format;
1062 ret = dfbvideosink->dfb->CreateSurface (dfbvideosink->dfb, &s_dsc, &surface);
1063 if (ret != DFB_OK) {
1064 GST_WARNING_OBJECT (dfbvideosink, "failed creating surface with format %s",
1065 gst_dfbvideosink_get_format_name (format));
1069 /* Backup layer configuration */
1070 ret = dfbvideosink->layer->GetConfiguration (dfbvideosink->layer, &prev_dlc);
1071 if (ret != DFB_OK) {
1072 GST_WARNING_OBJECT (dfbvideosink, "failed when getting current layer "
1077 /* Test configuration of the layer to this pixel format */
1078 dlc.flags = DLCONF_PIXELFORMAT;
1079 dlc.pixelformat = format;
1081 ret = dfbvideosink->layer->TestConfiguration (dfbvideosink->layer, &dlc,
1083 if (ret != DFB_OK) {
1084 GST_DEBUG_OBJECT (dfbvideosink, "our layer refuses to operate in pixel "
1085 "format %s", gst_dfbvideosink_get_format_name (format));
1089 ret = dfbvideosink->layer->SetConfiguration (dfbvideosink->layer, &dlc);
1090 if (ret != DFB_OK) {
1091 GST_WARNING_OBJECT (dfbvideosink, "our layer refuses to operate in pixel "
1092 "format, though this format was successfully tested earlied %s",
1093 gst_dfbvideosink_get_format_name (format));
1097 ret = dfbvideosink->primary->GetAccelerationMask (dfbvideosink->primary,
1099 if (ret != DFB_OK) {
1100 GST_WARNING_OBJECT (dfbvideosink, "failed getting acceleration mask");
1104 /* Blitting from this format to our primary is accelerated */
1105 if ((mask & DFXL_BLIT) && accelerated) {
1106 GST_DEBUG_OBJECT (dfbvideosink, "blitting from format %s to our primary "
1107 "is accelerated", gst_dfbvideosink_get_format_name (format));
1109 } else if (!accelerated) {
1110 GST_DEBUG_OBJECT (dfbvideosink, "blitting from format %s to our primary "
1111 "is not accelerated", gst_dfbvideosink_get_format_name (format));
1115 /* Restore original layer configuration */
1116 ret = dfbvideosink->layer->SetConfiguration (dfbvideosink->layer, &prev_dlc);
1117 if (ret != DFB_OK) {
1118 GST_WARNING_OBJECT (dfbvideosink, "failed when restoring layer "
1125 surface->Release (surface);
1131 gst_dfbvideosink_get_best_vmode (GstDfbVideoSink * dfbvideosink, gint v_width,
1132 gint v_height, GstDfbVMode * best_vmode)
1134 GSList *walk = NULL;
1135 gboolean ret = FALSE;
1136 gint width, height, bpp;
1137 GstDfbVMode *vmode = NULL;
1139 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), FALSE);
1141 if (!dfbvideosink->vmodes) {
1145 walk = dfbvideosink->vmodes;
1147 vmode = (GstDfbVMode *) walk->data;
1150 width = vmode->width;
1151 height = vmode->height;
1155 gint wgap, hgap, best_wgap, best_hgap;
1157 vmode = (GstDfbVMode *) walk->data;
1159 /* What are the gaps */
1160 wgap = abs (vmode->width - v_width);
1161 hgap = abs (vmode->height - v_height);
1162 best_wgap = abs (width - v_width);
1163 best_hgap = abs (height - v_height);
1165 /* If this mode is better we ll use that */
1166 if (wgap + hgap < best_wgap + best_hgap) {
1167 width = vmode->width;
1168 height = vmode->height;
1172 walk = g_slist_next (walk);
1175 GST_DEBUG_OBJECT (dfbvideosink, "found video mode %dx%d for input at %dx%d",
1176 width, height, v_width, v_height);
1178 best_vmode->width = width;
1179 best_vmode->height = height;
1180 best_vmode->bpp = bpp;
1189 gst_dfbvideosink_getcaps (GstBaseSink * bsink)
1191 GstDfbVideoSink *dfbvideosink;
1192 GstCaps *caps = NULL;
1195 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1197 if (!dfbvideosink->setup) {
1198 caps = gst_caps_copy (gst_pad_get_pad_template_caps (GST_VIDEO_SINK_PAD
1200 GST_DEBUG_OBJECT (dfbvideosink, "getcaps called and we are not setup yet, "
1201 "returning template %" GST_PTR_FORMAT, caps);
1204 GST_DEBUG_OBJECT (dfbvideosink, "getcaps called, checking our internal "
1206 if (dfbvideosink->ext_surface) {
1207 /* We are not rendering to our own surface, returning this surface's
1209 caps = gst_dfbvideosink_get_caps_from_format (dfbvideosink->pixel_format);
1211 /* Try some formats */
1212 gboolean accelerated = TRUE;
1213 caps = gst_caps_new_empty ();
1216 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_RGB16,
1218 gst_caps_append (caps,
1219 gst_dfbvideosink_get_caps_from_format (DSPF_RGB16));
1221 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_RGB24,
1223 gst_caps_append (caps,
1224 gst_dfbvideosink_get_caps_from_format (DSPF_RGB24));
1226 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_RGB32,
1228 gst_caps_append (caps,
1229 gst_dfbvideosink_get_caps_from_format (DSPF_RGB32));
1231 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_ARGB,
1233 gst_caps_append (caps,
1234 gst_dfbvideosink_get_caps_from_format (DSPF_ARGB));
1236 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_YUY2,
1238 gst_caps_append (caps,
1239 gst_dfbvideosink_get_caps_from_format (DSPF_YUY2));
1241 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_UYVY,
1243 gst_caps_append (caps,
1244 gst_dfbvideosink_get_caps_from_format (DSPF_UYVY));
1246 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_I420,
1248 gst_caps_append (caps,
1249 gst_dfbvideosink_get_caps_from_format (DSPF_I420));
1251 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_YV12,
1253 gst_caps_append (caps,
1254 gst_dfbvideosink_get_caps_from_format (DSPF_YV12));
1256 accelerated = !accelerated;
1257 } while (accelerated == FALSE);
1261 for (i = 0; i < gst_caps_get_size (caps); i++) {
1262 GstStructure *structure = gst_caps_get_structure (caps, i);
1264 gst_structure_set (structure,
1265 "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
1266 "height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
1267 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
1269 if (!dfbvideosink->hw_scaling && dfbvideosink->par) {
1272 nom = gst_value_get_fraction_numerator (dfbvideosink->par);
1273 den = gst_value_get_fraction_denominator (dfbvideosink->par);
1274 gst_structure_set (structure, "pixel-aspect-ratio",
1275 GST_TYPE_FRACTION, nom, den, NULL);
1279 GST_DEBUG_OBJECT (dfbvideosink, "returning our caps %" GST_PTR_FORMAT, caps);
1286 gst_dfbvideosink_setcaps (GstBaseSink * bsink, GstCaps * caps)
1288 GstDfbVideoSink *dfbvideosink;
1289 GstStructure *structure;
1290 gboolean res, result = FALSE;
1291 gint video_width, video_height;
1292 const GValue *framerate;
1293 DFBSurfacePixelFormat pixel_format = DSPF_UNKNOWN;
1295 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1297 structure = gst_caps_get_structure (caps, 0);
1298 res = gst_structure_get_int (structure, "width", &video_width);
1299 res &= gst_structure_get_int (structure, "height", &video_height);
1300 framerate = gst_structure_get_value (structure, "framerate");
1301 res &= (framerate != NULL);
1306 dfbvideosink->fps_n = gst_value_get_fraction_numerator (framerate);
1307 dfbvideosink->fps_d = gst_value_get_fraction_denominator (framerate);
1309 pixel_format = gst_dfbvideosink_get_format_from_caps (caps);
1311 GST_DEBUG_OBJECT (dfbvideosink, "setcaps called with %" GST_PTR_FORMAT, caps);
1312 GST_DEBUG_OBJECT (dfbvideosink, "our format is: %dx%d %s video at %d/%d fps",
1313 video_width, video_height,
1314 gst_dfbvideosink_get_format_name (pixel_format), dfbvideosink->fps_n,
1315 dfbvideosink->fps_d);
1317 if (dfbvideosink->hw_scaling && dfbvideosink->par) {
1318 gint video_par_n, video_par_d; /* video's PAR */
1319 gint display_par_n, display_par_d; /* display's PAR */
1321 GValue display_ratio = { 0, }; /* display w/h ratio */
1322 const GValue *caps_par;
1324 /* get aspect ratio from caps if it's present, and
1325 * convert video width and height to a display width and height
1326 * using wd / hd = wv / hv * PARv / PARd
1327 * the ratio wd / hd will be stored in display_ratio */
1328 g_value_init (&display_ratio, GST_TYPE_FRACTION);
1330 /* get video's PAR */
1331 caps_par = gst_structure_get_value (structure, "pixel-aspect-ratio");
1333 video_par_n = gst_value_get_fraction_numerator (caps_par);
1334 video_par_d = gst_value_get_fraction_denominator (caps_par);
1339 /* get display's PAR */
1340 if (dfbvideosink->par) {
1341 display_par_n = gst_value_get_fraction_numerator (dfbvideosink->par);
1342 display_par_d = gst_value_get_fraction_denominator (dfbvideosink->par);
1348 gst_value_set_fraction (&display_ratio,
1349 video_width * video_par_n * display_par_d,
1350 video_height * video_par_d * display_par_n);
1352 num = gst_value_get_fraction_numerator (&display_ratio);
1353 den = gst_value_get_fraction_denominator (&display_ratio);
1354 GST_DEBUG_OBJECT (dfbvideosink,
1355 "video width/height: %dx%d, calculated display ratio: %d/%d",
1356 video_width, video_height, num, den);
1358 /* now find a width x height that respects this display ratio.
1359 * prefer those that have one of w/h the same as the incoming video
1360 * using wd / hd = num / den */
1362 /* start with same height, because of interlaced video */
1363 /* check hd / den is an integer scale factor, and scale wd with the PAR */
1364 if (video_height % den == 0) {
1365 GST_DEBUG_OBJECT (dfbvideosink, "keeping video height");
1366 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_height * num / den;
1367 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_height;
1368 } else if (video_width % num == 0) {
1369 GST_DEBUG_OBJECT (dfbvideosink, "keeping video width");
1370 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_width;
1371 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_width * den / num;
1373 GST_DEBUG_OBJECT (dfbvideosink, "approximating while keeping height");
1374 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_height * num / den;
1375 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_height;
1377 GST_DEBUG_OBJECT (dfbvideosink, "scaling to %dx%d",
1378 GST_VIDEO_SINK_WIDTH (dfbvideosink),
1379 GST_VIDEO_SINK_HEIGHT (dfbvideosink));
1381 if (dfbvideosink->par) {
1384 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
1386 if (gst_value_compare (par, dfbvideosink->par) != GST_VALUE_EQUAL) {
1391 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_width;
1392 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_height;
1395 /* Try to adapt the video mode to the video geometry */
1396 if (dfbvideosink->dfb) {
1400 GST_DEBUG_OBJECT (dfbvideosink, "trying to adapt the video mode to video "
1403 /* Set video mode and layer configuration appropriately */
1404 if (gst_dfbvideosink_get_best_vmode (dfbvideosink,
1405 GST_VIDEO_SINK_WIDTH (dfbvideosink),
1406 GST_VIDEO_SINK_HEIGHT (dfbvideosink), &vmode)) {
1407 DFBDisplayLayerConfig lc;
1408 gint width, height, bpp;
1410 width = vmode.width;
1411 height = vmode.height;
1414 GST_DEBUG_OBJECT (dfbvideosink, "setting video mode to %dx%d at %d bpp",
1415 width, height, bpp);
1417 ret = dfbvideosink->dfb->SetVideoMode (dfbvideosink->dfb, width,
1419 if (ret != DFB_OK) {
1420 GST_WARNING_OBJECT (dfbvideosink, "failed setting video mode %dx%d "
1421 "at %d bpp", width, height, bpp);
1424 lc.flags = DLCONF_PIXELFORMAT;
1425 lc.pixelformat = pixel_format;
1427 ret = dfbvideosink->layer->SetConfiguration (dfbvideosink->layer, &lc);
1428 if (ret != DFB_OK) {
1429 GST_WARNING_OBJECT (dfbvideosink, "failed setting layer pixelformat "
1430 "to %s", gst_dfbvideosink_get_format_name (pixel_format));
1432 dfbvideosink->layer->GetConfiguration (dfbvideosink->layer, &lc);
1433 dfbvideosink->out_width = lc.width;
1434 dfbvideosink->out_height = lc.height;
1435 dfbvideosink->pixel_format = lc.pixelformat;
1436 GST_DEBUG_OBJECT (dfbvideosink, "layer %d now configured to %dx%d %s",
1437 dfbvideosink->layer_id, lc.width, lc.height,
1438 gst_dfbvideosink_get_format_name (lc.pixelformat));
1443 if (pixel_format != dfbvideosink->pixel_format) {
1444 GST_WARNING_OBJECT (dfbvideosink, "setcaps sent us a different pixel "
1445 "format %s", gst_dfbvideosink_get_format_name (pixel_format));
1449 dfbvideosink->video_width = video_width;
1450 dfbvideosink->video_height = video_height;
1460 GST_INFO_OBJECT (dfbvideosink, "pixel aspect ratio does not match");
1465 static GstStateChangeReturn
1466 gst_dfbvideosink_change_state (GstElement * element, GstStateChange transition)
1468 GstDfbVideoSink *dfbvideosink;
1469 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1471 dfbvideosink = GST_DFBVIDEOSINK (element);
1473 switch (transition) {
1474 case GST_STATE_CHANGE_NULL_TO_READY:
1475 dfbvideosink->running = TRUE;
1476 if (!dfbvideosink->setup) {
1477 if (!gst_dfbvideosink_setup (dfbvideosink)) {
1478 GST_DEBUG_OBJECT (dfbvideosink, "setup failed when changing state "
1479 "from NULL to READY");
1480 GST_ELEMENT_ERROR (dfbvideosink, RESOURCE, OPEN_WRITE,
1481 (NULL), ("Failed initializing DirectFB system"));
1482 return GST_STATE_CHANGE_FAILURE;
1486 case GST_STATE_CHANGE_READY_TO_PAUSED:
1487 /* Blank surface if we have one */
1488 if (dfbvideosink->ext_surface) {
1489 dfbvideosink->ext_surface->Clear (dfbvideosink->ext_surface,
1490 0x00, 0x00, 0x00, 0xFF);
1492 if (dfbvideosink->primary) {
1493 dfbvideosink->primary->Clear (dfbvideosink->primary, 0x00, 0x00,
1497 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1503 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1504 if (ret == GST_STATE_CHANGE_FAILURE)
1507 switch (transition) {
1508 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1510 case GST_STATE_CHANGE_PAUSED_TO_READY:
1511 dfbvideosink->fps_d = 0;
1512 dfbvideosink->fps_n = 0;
1513 dfbvideosink->video_width = 0;
1514 dfbvideosink->video_height = 0;
1516 if (dfbvideosink->buffer_pool) {
1517 gst_dfbvideosink_bufferpool_clear (dfbvideosink);
1520 case GST_STATE_CHANGE_READY_TO_NULL:
1521 dfbvideosink->running = FALSE;
1522 if (dfbvideosink->setup) {
1523 gst_dfbvideosink_cleanup (dfbvideosink);
1534 gst_dfbvideosink_get_times (GstBaseSink * bsink, GstBuffer * buf,
1535 GstClockTime * start, GstClockTime * end)
1537 GstDfbVideoSink *dfbvideosink;
1539 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1541 if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
1542 *start = GST_BUFFER_TIMESTAMP (buf);
1543 if (GST_BUFFER_DURATION_IS_VALID (buf)) {
1544 *end = *start + GST_BUFFER_DURATION (buf);
1546 if (dfbvideosink->fps_n > 0) {
1548 *start + (GST_SECOND * dfbvideosink->fps_d) / dfbvideosink->fps_n;
1554 static GstFlowReturn
1555 gst_dfbvideosink_show_frame (GstBaseSink * bsink, GstBuffer * buf)
1557 GstDfbVideoSink *dfbvideosink = NULL;
1559 GstVideoRectangle dst, src, result;
1560 GstFlowReturn ret = GST_FLOW_OK;
1561 gboolean mem_cpy = TRUE;
1562 GstMetaDfbSurface *meta;
1564 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1566 if (!dfbvideosink->setup) {
1567 ret = GST_FLOW_UNEXPECTED;
1571 meta = GST_META_DFBSURFACE_GET (buf);
1573 /* Is that a buffer we allocated ourselves ? */
1575 /* Does it have a surface ? */
1576 if (meta->surface) {
1578 GST_DEBUG_OBJECT (dfbvideosink, "we have a buffer (%p) we allocated "
1579 "ourselves and it has a surface, no memcpy then", buf);
1581 /* No surface, that's a malloc */
1582 GST_DEBUG_OBJECT (dfbvideosink, "we have a buffer (%p) we allocated "
1583 "ourselves but it does not hold a surface", buf);
1587 GST_DEBUG_OBJECT (dfbvideosink, "we have a buffer (%p) we did not allocate",
1592 IDirectFBSurface *dest = NULL, *surface = NULL;
1594 gint dest_pitch, src_pitch, line;
1595 GstStructure *structure;
1597 /* As we are not blitting no acceleration is possible. If the surface is
1598 * too small we do clipping, if it's too big we center. Theoretically as
1599 * we are using buffer_alloc, there's a chance that we have been able to
1600 * do reverse caps negotiation */
1602 if (dfbvideosink->ext_surface) {
1603 surface = dfbvideosink->ext_surface;
1604 GST_DEBUG_OBJECT (dfbvideosink, "memcpy to an external surface "
1605 "subsurface (vsync %d)", dfbvideosink->vsync);
1607 surface = dfbvideosink->primary;
1608 GST_DEBUG_OBJECT (dfbvideosink, "memcpy to a primary subsurface "
1609 "(vsync %d)", dfbvideosink->vsync);
1612 /* Get the video frame geometry from the buffer caps */
1613 structure = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0);
1615 gst_structure_get_int (structure, "width", &src.w);
1616 gst_structure_get_int (structure, "height", &src.h);
1618 src.w = dfbvideosink->video_width;
1619 src.h = dfbvideosink->video_height;
1621 res = surface->GetSize (surface, &dst.w, &dst.h);
1624 gst_video_sink_center_rect (src, dst, &result, FALSE);
1627 surface->GetSubSurface (surface, (DFBRectangle *) (void *) &result,
1629 if (res != DFB_OK) {
1630 GST_WARNING_OBJECT (dfbvideosink, "failed when getting a sub surface");
1631 ret = GST_FLOW_UNEXPECTED;
1635 /* If we are not using Flip we wait for VSYNC before blit */
1636 if (!dfbvideosink->backbuffer && dfbvideosink->vsync) {
1637 dfbvideosink->layer->WaitForSync (dfbvideosink->layer);
1640 res = dest->Lock (dest, DSLF_WRITE, (void *) &data, &dest_pitch);
1641 if (res != DFB_OK) {
1642 GST_WARNING_OBJECT (dfbvideosink, "failed locking the external "
1643 "subsurface for writing");
1644 ret = GST_FLOW_ERROR;
1648 /* Source video rowbytes */
1649 src_pitch = GST_BUFFER_SIZE (buf) / src.h;
1651 /* Write each line respecting subsurface pitch */
1652 for (line = 0; line < result.h; line++) {
1653 /* We do clipping */
1654 memcpy (data, GST_BUFFER_DATA (buf) + (line * src_pitch),
1655 MIN (src_pitch, dest_pitch));
1659 res = dest->Unlock (dest);
1661 dest->Release (dest);
1663 if (dfbvideosink->backbuffer) {
1664 if (dfbvideosink->vsync) {
1665 res = surface->Flip (surface, NULL, DSFLIP_ONSYNC);
1667 res = surface->Flip (surface, NULL, DSFLIP_NONE);
1671 /* Else we will [Stretch]Blit to our primary */
1672 GST_DEBUG_OBJECT (dfbvideosink, "blitting to a primary surface (vsync %d)",
1673 dfbvideosink->vsync);
1675 src.w = GST_VIDEO_SINK_WIDTH (dfbvideosink);
1676 src.h = GST_VIDEO_SINK_HEIGHT (dfbvideosink);
1678 dfbvideosink->primary->GetSize (dfbvideosink->primary, &dst.w, &dst.h);
1680 /* Unlocking surface before blit */
1682 meta->surface->Unlock (meta->surface);
1683 meta->locked = FALSE;
1686 gst_video_sink_center_rect (src, dst, &result, dfbvideosink->hw_scaling);
1688 /* If we are not using Flip we wait for VSYNC before blit */
1689 if (!dfbvideosink->backbuffer && dfbvideosink->vsync) {
1690 dfbvideosink->layer->WaitForSync (dfbvideosink->layer);
1693 if (dfbvideosink->hw_scaling) {
1694 dfbvideosink->primary->StretchBlit (dfbvideosink->primary,
1695 meta->surface, NULL, (DFBRectangle *) (void *) &result);
1699 clip.x = clip.y = 0;
1702 dfbvideosink->primary->Blit (dfbvideosink->primary, meta->surface,
1703 &clip, result.x, result.y);
1706 if (dfbvideosink->backbuffer) {
1707 if (dfbvideosink->vsync) {
1708 dfbvideosink->primary->Flip (dfbvideosink->primary, NULL,
1711 dfbvideosink->primary->Flip (dfbvideosink->primary, NULL, DSFLIP_NONE);
1721 gst_dfbvideosink_bufferpool_clear (GstDfbVideoSink * dfbvideosink)
1723 g_mutex_lock (dfbvideosink->pool_lock);
1724 while (dfbvideosink->buffer_pool) {
1725 GstBuffer *surface = dfbvideosink->buffer_pool->data;
1727 dfbvideosink->buffer_pool = g_slist_delete_link (dfbvideosink->buffer_pool,
1728 dfbvideosink->buffer_pool);
1729 gst_dfbvideosink_surface_destroy (dfbvideosink, surface);
1731 g_mutex_unlock (dfbvideosink->pool_lock);
1734 /* For every buffer request we create a custom buffer containing and
1735 * IDirectFBSurface or allocate a previously created one that's not used
1737 static GstFlowReturn
1738 gst_dfbvideosink_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size,
1739 GstCaps * caps, GstBuffer ** buf)
1741 GstDfbVideoSink *dfbvideosink;
1742 GstBuffer *surface = NULL;
1743 GstFlowReturn ret = GST_FLOW_OK;
1745 gboolean rev_nego = FALSE;
1748 GstCaps *desired_caps = NULL;
1749 GstStructure *structure = NULL;
1751 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1753 GST_LOG_OBJECT (dfbvideosink, "a buffer of %u bytes was requested with caps "
1754 "%" GST_PTR_FORMAT " and offset %" G_GUINT64_FORMAT, size, caps, offset);
1756 if (G_UNLIKELY (!dfbvideosink->setup)) {
1757 GST_DEBUG_OBJECT (dfbvideosink, "we are not setup yet, can't allocate!");
1762 desired_caps = gst_caps_copy (caps);
1764 structure = gst_caps_get_structure (desired_caps, 0);
1766 if (gst_structure_get_int (structure, "width", &width) &&
1767 gst_structure_get_int (structure, "height", &height)) {
1768 GstVideoRectangle dst, src, result;
1771 /* If we can do hardware scaling we don't do reverse negotiation */
1772 if (dfbvideosink->hw_scaling) {
1776 /* Our desired geometry respects aspect ratio */
1779 /* We should adapt the destination to the most suitable video mode */
1780 if (gst_dfbvideosink_get_best_vmode (dfbvideosink, width, height, &vmode)) {
1781 dst.w = vmode.width;
1782 dst.h = vmode.height;
1784 if (dfbvideosink->ext_surface) {
1785 dfbvideosink->ext_surface->GetSize (dfbvideosink->ext_surface, &dst.w,
1788 dfbvideosink->primary->GetSize (dfbvideosink->primary, &dst.w, &dst.h);
1790 dfbvideosink->out_width = dst.w;
1791 dfbvideosink->out_height = dst.h;
1794 gst_video_sink_center_rect (src, dst, &result, TRUE);
1796 if (width != result.w || height != result.h) {
1797 GstPad *peer = gst_pad_get_peer (GST_VIDEO_SINK_PAD (dfbvideosink));
1799 if (!GST_IS_PAD (peer)) {
1800 /* Is this situation possible ? */
1804 GST_DEBUG_OBJECT (dfbvideosink, "we would love to receive a %dx%d video",
1805 result.w, result.h);
1806 gst_structure_set (structure, "width", G_TYPE_INT, result.w, NULL);
1807 gst_structure_set (structure, "height", G_TYPE_INT, result.h, NULL);
1809 /* PAR property overrides the X calculated one */
1810 if (dfbvideosink->par) {
1813 nom = gst_value_get_fraction_numerator (dfbvideosink->par);
1814 den = gst_value_get_fraction_denominator (dfbvideosink->par);
1815 gst_structure_set (structure, "pixel-aspect-ratio",
1816 GST_TYPE_FRACTION, nom, den, NULL);
1819 if (gst_pad_accept_caps (peer, desired_caps)) {
1822 bpp = size / height / width;
1826 size = bpp * width * height;
1827 GST_DEBUG_OBJECT (dfbvideosink, "peed pad accepts our desired caps %"
1828 GST_PTR_FORMAT " buffer size is now %d bytes", desired_caps, size);
1830 GST_DEBUG_OBJECT (dfbvideosink, "peer pad does not accept our "
1831 "desired caps %" GST_PTR_FORMAT, desired_caps);
1833 width = dfbvideosink->video_width;
1834 height = dfbvideosink->video_height;
1836 gst_object_unref (peer);
1841 /* Inspect our buffer pool */
1842 g_mutex_lock (dfbvideosink->pool_lock);
1843 while (dfbvideosink->buffer_pool) {
1844 GstMetaDfbSurface *meta;
1846 surface = (GstBuffer *) dfbvideosink->buffer_pool->data;
1849 /* Removing from the pool */
1850 dfbvideosink->buffer_pool =
1851 g_slist_delete_link (dfbvideosink->buffer_pool,
1852 dfbvideosink->buffer_pool);
1854 meta = GST_META_DFBSURFACE_GET (surface);
1856 /* If the surface is invalid for our need, destroy */
1857 if ((meta->width != width) ||
1858 (meta->height != height) ||
1859 (meta->pixel_format != dfbvideosink->pixel_format)) {
1860 gst_dfbvideosink_surface_destroy (dfbvideosink, surface);
1863 /* We found a suitable surface */
1868 g_mutex_unlock (dfbvideosink->pool_lock);
1870 /* We haven't found anything, creating a new one */
1873 surface = gst_dfbvideosink_surface_create (dfbvideosink, desired_caps,
1876 surface = gst_dfbvideosink_surface_create (dfbvideosink, caps, size);
1879 /* Now we should have a surface, set appropriate caps on it */
1882 gst_buffer_set_caps (surface, desired_caps);
1884 gst_buffer_set_caps (surface, caps);
1890 gst_caps_unref (desired_caps);
1897 gst_meta_dfbsurface_get_info (void)
1899 static const GstMetaInfo *meta_info = NULL;
1901 if (g_once_init_enter (&meta_info)) {
1902 const GstMetaInfo *meta =
1903 gst_meta_register ("GstMetaDfbSurface", "GstMetaDfbSurface",
1904 sizeof (GstMetaDfbSurface),
1905 (GstMetaInitFunction) NULL,
1906 (GstMetaFreeFunction) NULL,
1907 (GstMetaTransformFunction) NULL,
1908 (GstMetaSerializeFunction) NULL, (GstMetaDeserializeFunction) NULL);
1909 g_once_init_leave (&meta_info, meta);
1914 /* Interfaces stuff */
1917 gst_dfbvideosink_interface_supported (GstImplementsInterface * iface,
1920 g_assert (type == GST_TYPE_NAVIGATION || type == GST_TYPE_COLOR_BALANCE);
1925 gst_dfbvideosink_interface_init (GstImplementsInterfaceClass * klass)
1927 klass->supported = gst_dfbvideosink_interface_supported;
1931 gst_dfbvideosink_navigation_send_event (GstNavigation * navigation,
1932 GstStructure * structure)
1934 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (navigation);
1936 GstVideoRectangle src, dst, result;
1937 double x, y, old_x, old_y;
1940 src.w = GST_VIDEO_SINK_WIDTH (dfbvideosink);
1941 src.h = GST_VIDEO_SINK_HEIGHT (dfbvideosink);
1942 dst.w = dfbvideosink->out_width;
1943 dst.h = dfbvideosink->out_height;
1944 gst_video_sink_center_rect (src, dst, &result, dfbvideosink->hw_scaling);
1946 event = gst_event_new_navigation (structure);
1948 /* Our coordinates can be wrong here if we centered the video */
1950 /* Converting pointer coordinates to the non scaled geometry */
1951 if (gst_structure_get_double (structure, "pointer_x", &old_x)) {
1954 if (x >= result.x && x <= (result.x + result.w)) {
1956 x *= dfbvideosink->video_width;
1961 GST_DEBUG_OBJECT (dfbvideosink, "translated navigation event x "
1962 "coordinate from %f to %f", old_x, x);
1963 gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE, x, NULL);
1965 if (gst_structure_get_double (structure, "pointer_y", &old_y)) {
1968 if (y >= result.y && y <= (result.y + result.h)) {
1970 y *= dfbvideosink->video_height;
1975 GST_DEBUG_OBJECT (dfbvideosink, "translated navigation event y "
1976 "coordinate from %fd to %fd", old_y, y);
1977 gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE, y, NULL);
1980 pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (dfbvideosink));
1982 if (GST_IS_PAD (pad) && GST_IS_EVENT (event)) {
1983 gst_pad_send_event (pad, event);
1985 gst_object_unref (pad);
1990 gst_dfbvideosink_navigation_init (GstNavigationInterface * iface)
1992 iface->send_event = gst_dfbvideosink_navigation_send_event;
1996 gst_dfbvideosink_update_colorbalance (GstDfbVideoSink * dfbvideosink)
1998 g_return_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink));
2000 if (dfbvideosink->layer) {
2001 DFBColorAdjustment cb_adjust;
2003 cb_adjust.flags = DCAF_NONE;
2005 if (dfbvideosink->brightness >= 0) {
2006 cb_adjust.flags |= DCAF_BRIGHTNESS;
2008 if (dfbvideosink->contrast >= 0) {
2009 cb_adjust.flags |= DCAF_CONTRAST;
2011 if (dfbvideosink->hue >= 0) {
2012 cb_adjust.flags |= DCAF_HUE;
2014 if (dfbvideosink->saturation >= 0) {
2015 cb_adjust.flags |= DCAF_SATURATION;
2018 cb_adjust.brightness = dfbvideosink->brightness;
2019 cb_adjust.contrast = dfbvideosink->contrast;
2020 cb_adjust.hue = dfbvideosink->hue;
2021 cb_adjust.saturation = dfbvideosink->saturation;
2023 GST_DEBUG_OBJECT (dfbvideosink, "updating colorbalance: flags %d "
2024 "brightness %d contrast %d hue %d saturation %d", cb_adjust.flags,
2025 cb_adjust.brightness, cb_adjust.contrast, cb_adjust.hue,
2026 cb_adjust.saturation);
2027 dfbvideosink->layer->SetColorAdjustment (dfbvideosink->layer, &cb_adjust);
2031 static const GList *
2032 gst_dfbvideosink_colorbalance_list_channels (GstColorBalance * balance)
2034 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (balance);
2036 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), NULL);
2038 return dfbvideosink->cb_channels;
2042 gst_dfbvideosink_colorbalance_set_value (GstColorBalance * balance,
2043 GstColorBalanceChannel * channel, gint value)
2045 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (balance);
2047 g_return_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink));
2048 g_return_if_fail (channel->label != NULL);
2050 dfbvideosink->cb_changed = TRUE;
2052 if (g_ascii_strcasecmp (channel->label, "HUE") == 0) {
2053 dfbvideosink->hue = value;
2054 } else if (g_ascii_strcasecmp (channel->label, "SATURATION") == 0) {
2055 dfbvideosink->saturation = value;
2056 } else if (g_ascii_strcasecmp (channel->label, "CONTRAST") == 0) {
2057 dfbvideosink->contrast = value;
2058 } else if (g_ascii_strcasecmp (channel->label, "BRIGHTNESS") == 0) {
2059 dfbvideosink->brightness = value;
2061 GST_WARNING_OBJECT (dfbvideosink, "got an unknown channel %s",
2066 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2070 gst_dfbvideosink_colorbalance_get_value (GstColorBalance * balance,
2071 GstColorBalanceChannel * channel)
2073 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (balance);
2076 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), 0);
2077 g_return_val_if_fail (channel->label != NULL, 0);
2079 if (g_ascii_strcasecmp (channel->label, "HUE") == 0) {
2080 value = dfbvideosink->hue;
2081 } else if (g_ascii_strcasecmp (channel->label, "SATURATION") == 0) {
2082 value = dfbvideosink->saturation;
2083 } else if (g_ascii_strcasecmp (channel->label, "CONTRAST") == 0) {
2084 value = dfbvideosink->contrast;
2085 } else if (g_ascii_strcasecmp (channel->label, "BRIGHTNESS") == 0) {
2086 value = dfbvideosink->brightness;
2088 GST_WARNING_OBJECT (dfbvideosink, "got an unknown channel %s",
2096 gst_dfbvideosink_colorbalance_init (GstColorBalanceInterface * iface)
2098 GST_COLOR_BALANCE_TYPE (iface) = GST_COLOR_BALANCE_HARDWARE;
2099 iface->list_channels = gst_dfbvideosink_colorbalance_list_channels;
2100 iface->set_value = gst_dfbvideosink_colorbalance_set_value;
2101 iface->get_value = gst_dfbvideosink_colorbalance_get_value;
2107 gst_dfbvideosink_set_property (GObject * object, guint prop_id,
2108 const GValue * value, GParamSpec * pspec)
2110 GstDfbVideoSink *dfbvideosink;
2112 g_return_if_fail (GST_IS_DFBVIDEOSINK (object));
2113 dfbvideosink = GST_DFBVIDEOSINK (object);
2117 dfbvideosink->ext_surface = g_value_get_pointer (value);
2120 dfbvideosink->hue = g_value_get_int (value);
2121 dfbvideosink->cb_changed = TRUE;
2122 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2125 dfbvideosink->contrast = g_value_get_int (value);
2126 dfbvideosink->cb_changed = TRUE;
2127 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2129 case ARG_BRIGHTNESS:
2130 dfbvideosink->brightness = g_value_get_int (value);
2131 dfbvideosink->cb_changed = TRUE;
2132 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2134 case ARG_SATURATION:
2135 dfbvideosink->saturation = g_value_get_int (value);
2136 dfbvideosink->cb_changed = TRUE;
2137 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2139 case ARG_PIXEL_ASPECT_RATIO:
2140 g_free (dfbvideosink->par);
2141 dfbvideosink->par = g_new0 (GValue, 1);
2142 g_value_init (dfbvideosink->par, GST_TYPE_FRACTION);
2143 if (!g_value_transform (value, dfbvideosink->par)) {
2144 GST_WARNING_OBJECT (dfbvideosink, "Could not transform string to "
2146 gst_value_set_fraction (dfbvideosink->par, 1, 1);
2148 GST_DEBUG_OBJECT (dfbvideosink, "set PAR to %d/%d",
2149 gst_value_get_fraction_numerator (dfbvideosink->par),
2150 gst_value_get_fraction_denominator (dfbvideosink->par));
2153 dfbvideosink->vsync = g_value_get_boolean (value);
2156 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2162 gst_dfbvideosink_get_property (GObject * object, guint prop_id,
2163 GValue * value, GParamSpec * pspec)
2165 GstDfbVideoSink *dfbvideosink;
2167 g_return_if_fail (GST_IS_DFBVIDEOSINK (object));
2168 dfbvideosink = GST_DFBVIDEOSINK (object);
2172 g_value_set_int (value, dfbvideosink->hue);
2175 g_value_set_int (value, dfbvideosink->contrast);
2177 case ARG_BRIGHTNESS:
2178 g_value_set_int (value, dfbvideosink->brightness);
2180 case ARG_SATURATION:
2181 g_value_set_int (value, dfbvideosink->saturation);
2183 case ARG_PIXEL_ASPECT_RATIO:
2184 if (dfbvideosink->par)
2185 g_value_transform (dfbvideosink->par, value);
2188 g_value_set_boolean (value, dfbvideosink->vsync);
2191 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2196 /* =========================================== */
2198 /* Init & Class init */
2200 /* =========================================== */
2202 gst_dfbvideosink_finalize (GObject * object)
2204 GstDfbVideoSink *dfbvideosink;
2206 dfbvideosink = GST_DFBVIDEOSINK (object);
2208 if (dfbvideosink->par) {
2209 g_free (dfbvideosink->par);
2210 dfbvideosink->par = NULL;
2212 if (dfbvideosink->pool_lock) {
2213 g_mutex_free (dfbvideosink->pool_lock);
2214 dfbvideosink->pool_lock = NULL;
2216 if (dfbvideosink->setup) {
2217 gst_dfbvideosink_cleanup (dfbvideosink);
2220 G_OBJECT_CLASS (parent_class)->finalize (object);
2224 gst_dfbvideosink_init (GstDfbVideoSink * dfbvideosink)
2226 dfbvideosink->pool_lock = g_mutex_new ();
2227 dfbvideosink->buffer_pool = NULL;
2228 dfbvideosink->video_height = dfbvideosink->out_height = 0;
2229 dfbvideosink->video_width = dfbvideosink->out_width = 0;
2230 dfbvideosink->fps_d = 0;
2231 dfbvideosink->fps_n = 0;
2233 dfbvideosink->dfb = NULL;
2234 dfbvideosink->vmodes = NULL;
2235 dfbvideosink->layer_id = -1;
2236 dfbvideosink->layer = NULL;
2237 dfbvideosink->primary = NULL;
2238 dfbvideosink->event_buffer = NULL;
2239 dfbvideosink->event_thread = NULL;
2241 dfbvideosink->ext_surface = NULL;
2243 dfbvideosink->pixel_format = DSPF_UNKNOWN;
2245 dfbvideosink->hw_scaling = FALSE;
2246 dfbvideosink->backbuffer = FALSE;
2247 dfbvideosink->vsync = TRUE;
2248 dfbvideosink->setup = FALSE;
2249 dfbvideosink->running = FALSE;
2251 dfbvideosink->cb_channels = NULL;
2252 dfbvideosink->brightness = -1;
2253 dfbvideosink->contrast = -1;
2254 dfbvideosink->hue = -1;
2255 dfbvideosink->saturation = -1;
2257 dfbvideosink->par = NULL;
2261 gst_dfbvideosink_base_init (gpointer g_class)
2263 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
2265 gst_element_class_set_static_metadata (element_class, "DirectFB video sink",
2267 "A DirectFB based videosink", "Julien Moutte <julien@moutte.net>");
2269 gst_element_class_add_pad_template (element_class,
2270 gst_static_pad_template_get (&gst_dfbvideosink_sink_template_factory));
2274 gst_dfbvideosink_class_init (GstDfbVideoSinkClass * klass)
2276 GObjectClass *gobject_class;
2277 GstElementClass *gstelement_class;
2278 GstBaseSinkClass *gstbasesink_class;
2280 gobject_class = (GObjectClass *) klass;
2281 gstelement_class = (GstElementClass *) klass;
2282 gstbasesink_class = (GstBaseSinkClass *) klass;
2284 parent_class = g_type_class_peek_parent (klass);
2286 gobject_class->finalize = gst_dfbvideosink_finalize;
2287 gobject_class->set_property = gst_dfbvideosink_set_property;
2288 gobject_class->get_property = gst_dfbvideosink_get_property;
2290 g_object_class_install_property (gobject_class, ARG_SURFACE,
2291 g_param_spec_pointer ("surface", "Surface",
2292 "The target surface for video",
2293 G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
2294 g_object_class_install_property (gobject_class, ARG_CONTRAST,
2295 g_param_spec_int ("contrast", "Contrast", "The contrast of the video",
2296 0x0000, 0xFFFF, 0x8000, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2297 g_object_class_install_property (gobject_class, ARG_BRIGHTNESS,
2298 g_param_spec_int ("brightness", "Brightness",
2299 "The brightness of the video", 0x0000, 0xFFFF, 0x8000,
2300 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2301 g_object_class_install_property (gobject_class, ARG_HUE,
2302 g_param_spec_int ("hue", "Hue", "The hue of the video", 0x0000, 0xFFFF,
2303 0x8000, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2304 g_object_class_install_property (gobject_class, ARG_SATURATION,
2305 g_param_spec_int ("saturation", "Saturation",
2306 "The saturation of the video", 0x0000, 0xFFFF, 0x8000,
2307 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2308 g_object_class_install_property (gobject_class, ARG_PIXEL_ASPECT_RATIO,
2309 g_param_spec_string ("pixel-aspect-ratio", "Pixel Aspect Ratio",
2310 "The pixel aspect ratio of the device", "1/1",
2311 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2312 g_object_class_install_property (gobject_class, ARG_VSYNC,
2313 g_param_spec_boolean ("vsync", "Vertical synchronisation",
2314 "Wait for next vertical sync to draw frames", TRUE,
2315 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2317 gstelement_class->change_state = gst_dfbvideosink_change_state;
2319 gstbasesink_class->get_caps = gst_dfbvideosink_getcaps;
2320 gstbasesink_class->set_caps = gst_dfbvideosink_setcaps;
2321 gstbasesink_class->buffer_alloc = gst_dfbvideosink_buffer_alloc;
2322 gstbasesink_class->get_times = gst_dfbvideosink_get_times;
2323 gstbasesink_class->preroll = gst_dfbvideosink_show_frame;
2324 gstbasesink_class->render = gst_dfbvideosink_show_frame;
2327 /* ============================================================= */
2329 /* Public Methods */
2331 /* ============================================================= */
2333 /* =========================================== */
2335 /* Object typing & Creation */
2337 /* =========================================== */
2340 gst_dfbvideosink_get_type (void)
2342 static GType dfbvideosink_type = 0;
2344 if (!dfbvideosink_type) {
2345 static const GTypeInfo dfbvideosink_info = {
2346 sizeof (GstDfbVideoSinkClass),
2347 gst_dfbvideosink_base_init,
2349 (GClassInitFunc) gst_dfbvideosink_class_init,
2352 sizeof (GstDfbVideoSink),
2354 (GInstanceInitFunc) gst_dfbvideosink_init,
2356 static const GInterfaceInfo iface_info = {
2357 (GInterfaceInitFunc) gst_dfbvideosink_interface_init,
2361 static const GInterfaceInfo navigation_info = {
2362 (GInterfaceInitFunc) gst_dfbvideosink_navigation_init,
2366 static const GInterfaceInfo colorbalance_info = {
2367 (GInterfaceInitFunc) gst_dfbvideosink_colorbalance_init,
2372 dfbvideosink_type = g_type_register_static (GST_TYPE_VIDEO_SINK,
2373 "GstDfbVideoSink", &dfbvideosink_info, 0);
2375 g_type_add_interface_static (dfbvideosink_type,
2376 GST_TYPE_IMPLEMENTS_INTERFACE, &iface_info);
2377 g_type_add_interface_static (dfbvideosink_type, GST_TYPE_NAVIGATION,
2379 g_type_add_interface_static (dfbvideosink_type, GST_TYPE_COLOR_BALANCE,
2380 &colorbalance_info);
2383 return dfbvideosink_type;
2387 plugin_init (GstPlugin * plugin)
2389 if (!gst_element_register (plugin, "dfbvideosink", GST_RANK_MARGINAL,
2390 GST_TYPE_DFBVIDEOSINK))
2393 GST_DEBUG_CATEGORY_INIT (dfbvideosink_debug, "dfbvideosink", 0,
2394 "DirectFB video sink element");
2399 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
2402 "DirectFB video output plugin",
2403 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)