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 GstDfbSurface * surface);
137 static GstVideoSinkClass *parent_class = NULL;
138 static GstBufferClass *surface_parent_class = NULL;
140 #ifndef GST_DISABLE_GST_DEBUG
142 gst_dfbvideosink_get_format_name (DFBSurfacePixelFormat format)
189 #endif /* GST_DISABLE_GST_DEBUG */
191 /* Creates miniobject and our internal surface */
192 static GstDfbSurface *
193 gst_dfbvideosink_surface_create (GstDfbVideoSink * dfbvideosink, GstCaps * caps,
196 GstDfbSurface *surface = NULL;
197 GstStructure *structure = NULL;
199 DFBSurfaceDescription s_dsc;
202 gboolean succeeded = FALSE;
204 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), NULL);
206 surface = (GstDfbSurface *) gst_mini_object_new (GST_TYPE_DFBSURFACE);
208 /* Keep a ref to our sink */
209 surface->dfbvideosink = gst_object_ref (dfbvideosink);
210 /* Surface is not locked yet */
211 surface->locked = FALSE;
213 structure = gst_caps_get_structure (caps, 0);
215 if (!gst_structure_get_int (structure, "width", &surface->width) ||
216 !gst_structure_get_int (structure, "height", &surface->height)) {
217 GST_WARNING_OBJECT (dfbvideosink, "failed getting geometry from caps %"
218 GST_PTR_FORMAT, caps);
222 /* Pixel format from caps */
223 surface->pixel_format = gst_dfbvideosink_get_format_from_caps (caps);
224 if (surface->pixel_format == DSPF_UNKNOWN) {
228 if (!dfbvideosink->dfb) {
229 GST_DEBUG_OBJECT (dfbvideosink, "no DirectFB context to create a surface");
233 /* Creating an internal surface which will be used as GstBuffer, we used
234 the detected pixel format and video dimensions */
237 DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_HEIGHT /*| DSDESC_CAPS */ ;
239 s_dsc.pixelformat = surface->pixel_format;
240 s_dsc.width = surface->width;
241 s_dsc.height = surface->height;
242 /*s_dsc.caps = DSCAPS_VIDEOONLY; */
244 ret = dfbvideosink->dfb->CreateSurface (dfbvideosink->dfb, &s_dsc,
247 GST_WARNING_OBJECT (dfbvideosink, "failed creating a DirectFB surface");
248 surface->surface = NULL;
252 /* Clearing surface */
253 surface->surface->Clear (surface->surface, 0x00, 0x00, 0x00, 0xFF);
255 /* Locking the surface to acquire the memory pointer */
256 surface->surface->Lock (surface->surface, DSLF_WRITE, &data, &pitch);
257 surface->locked = TRUE;
258 GST_BUFFER_DATA (surface) = data;
259 GST_BUFFER_SIZE (surface) = pitch * surface->height;
261 /* Be carefull here. If size is different from the surface size
262 (pitch * height), we can't use that surface through buffer alloc system
263 or we are going to run into serious stride issues */
264 if (GST_BUFFER_SIZE (surface) != size) {
265 GST_WARNING_OBJECT (dfbvideosink, "DirectFB surface size (%dx%d=%d) "
266 "differs from GStreamer requested size %u", pitch, surface->height,
267 GST_BUFFER_SIZE (surface), (guint) size);
271 GST_DEBUG_OBJECT (dfbvideosink, "creating a %dx%d surface (%p) with %s "
272 "pixel format, line pitch %d", surface->width, surface->height, surface,
273 gst_dfbvideosink_get_format_name (surface->pixel_format), pitch);
281 /* We allocate a standard buffer ourselves to store it in our buffer pool,
282 this is an optimisation for memory allocation */
283 GST_BUFFER (surface)->malloc_data = g_malloc (size);
284 GST_BUFFER_DATA (surface) = GST_BUFFER (surface)->malloc_data;
285 GST_BUFFER_SIZE (surface) = size;
286 if (surface->surface) {
287 if (surface->locked) {
288 surface->surface->Unlock (surface->surface);
289 surface->locked = FALSE;
291 surface->surface->Release (surface->surface);
292 surface->surface = NULL;
294 GST_DEBUG_OBJECT (dfbvideosink, "allocating a buffer (%p) of %u bytes",
295 surface, (guint) size);
301 gst_dfbvideosink_surface_destroy (dfbvideosink, surface);
307 /* We are called from the finalize method of miniobject, the object will be
308 * destroyed so we just have to clean our internal stuff */
310 gst_dfbvideosink_surface_destroy (GstDfbVideoSink * dfbvideosink,
311 GstDfbSurface * surface)
313 g_return_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink));
315 /* Release our internal surface */
316 if (surface->surface) {
317 if (surface->locked) {
318 surface->surface->Unlock (surface->surface);
319 surface->locked = FALSE;
321 surface->surface->Release (surface->surface);
322 surface->surface = NULL;
325 if (surface->dfbvideosink) {
326 /* Release the ref to our sink */
327 surface->dfbvideosink = NULL;
328 gst_object_unref (dfbvideosink);
331 GST_MINI_OBJECT_CLASS (surface_parent_class)->finalize (GST_MINI_OBJECT
336 gst_dfbvideosink_event_thread (GstDfbVideoSink * dfbvideosink)
340 while (dfbvideosink->running) {
341 /* Wait for an event with a 50 ms timeout */
342 dfbvideosink->event_buffer->
343 WaitForEventWithTimeout (dfbvideosink->event_buffer, 0, 50);
345 /* Do we have an event ? */
346 ret = dfbvideosink->event_buffer->HasEvent (dfbvideosink->event_buffer);
351 GST_DEBUG_OBJECT (dfbvideosink, "we have an event");
353 ret = dfbvideosink->event_buffer->GetEvent (dfbvideosink->event_buffer,
355 if (ret != DFB_OK) { /* Error */
356 GST_WARNING_OBJECT (dfbvideosink, "failed when getting event from "
358 } else { /* Handle event */
359 if (event.input.type == DIET_KEYPRESS) {
360 switch (event.input.key_symbol) {
363 GST_ELEMENT_ERROR (dfbvideosink, RESOURCE, OPEN_WRITE,
364 ("Video output device is gone."),
365 ("We were running fullscreen and user "
366 "pressed the ESC key, stopping playback."));
369 GST_DEBUG_OBJECT (dfbvideosink, "key press event %c !",
370 event.input.key_symbol);
371 gst_navigation_send_key_event (GST_NAVIGATION (dfbvideosink),
372 "key-press", "prout");
374 } else if (event.input.type == DIET_BUTTONPRESS) {
377 dfbvideosink->layer->GetCursorPosition (dfbvideosink->layer, &x, &y);
379 GST_DEBUG_OBJECT (dfbvideosink, "button %d pressed at %dx%d",
380 event.input.button, x, y);
382 gst_navigation_send_mouse_event (GST_NAVIGATION (dfbvideosink),
383 "mouse-button-press", event.input.button, x, y);
384 } else if (event.input.type == DIET_BUTTONRELEASE) {
387 dfbvideosink->layer->GetCursorPosition (dfbvideosink->layer, &x, &y);
389 GST_DEBUG_OBJECT (dfbvideosink, "button %d released at %dx%d",
390 event.input.button, x, y);
392 gst_navigation_send_mouse_event (GST_NAVIGATION (dfbvideosink),
393 "mouse-button-release", event.input.button, x, y);
394 } else if (event.input.type == DIET_AXISMOTION) {
397 dfbvideosink->layer->GetCursorPosition (dfbvideosink->layer, &x, &y);
398 gst_navigation_send_mouse_event (GST_NAVIGATION (dfbvideosink),
399 "mouse-move", 0, x, y);
401 GST_WARNING_OBJECT (dfbvideosink, "unhandled event type %d",
410 static DFBEnumerationResult
411 gst_dfbvideosink_enum_layers (DFBDisplayLayerID id,
412 DFBDisplayLayerDescription desc, void *data)
414 GstDfbVideoSink *dfbvideosink = NULL;
415 IDirectFBDisplayLayer *layer = NULL;
416 DFBDisplayLayerConfig dlc;
418 gboolean backbuffer = FALSE;
420 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (data), DFENUM_CANCEL);
422 dfbvideosink = GST_DFBVIDEOSINK (data);
424 GST_DEBUG_OBJECT (dfbvideosink, "inspecting display layer %d with name: %s",
427 if ((desc.type & DLTF_VIDEO) && (desc.caps & DLCAPS_SURFACE)) {
428 GST_DEBUG_OBJECT (dfbvideosink,
429 "this layer can handle live video and has a surface");
431 if (desc.caps & DLCAPS_SURFACE) {
432 GST_DEBUG_OBJECT (dfbvideosink,
433 "this layer can not handle live video but has a surface");
435 GST_DEBUG_OBJECT (dfbvideosink, "no we can't use that layer, really...");
440 ret = dfbvideosink->dfb->GetDisplayLayer (dfbvideosink->dfb, id, &layer);
442 GST_WARNING_OBJECT (dfbvideosink, "failed getting display layer %s",
447 ret = layer->GetConfiguration (layer, &dlc);
449 GST_WARNING_OBJECT (dfbvideosink,
450 "failed getting display layer configuration");
454 if ((dlc.flags & DLCONF_BUFFERMODE) && (dlc.buffermode & DLBM_FRONTONLY)) {
455 GST_DEBUG_OBJECT (dfbvideosink, "no backbuffer");
457 if ((dlc.flags & DLCONF_BUFFERMODE) && (dlc.buffermode & DLBM_BACKVIDEO)) {
458 GST_DEBUG_OBJECT (dfbvideosink, "backbuffer is in video memory");
461 if ((dlc.flags & DLCONF_BUFFERMODE) && (dlc.buffermode & DLBM_BACKSYSTEM)) {
462 GST_DEBUG_OBJECT (dfbvideosink, "backbuffer is in system memory");
465 if ((dlc.flags & DLCONF_BUFFERMODE) && (dlc.buffermode & DLBM_TRIPLE)) {
466 GST_DEBUG_OBJECT (dfbvideosink, "triple buffering");
470 /* If the primary is suitable we prefer using it */
471 if (dfbvideosink->layer_id != DLID_PRIMARY) {
472 GST_DEBUG_OBJECT (dfbvideosink, "selecting layer named %s", desc.name);
473 dfbvideosink->layer_id = id;
474 dfbvideosink->backbuffer = backbuffer;
476 GST_DEBUG_OBJECT (dfbvideosink, "layer %s is suitable but the primary "
477 "is currently selected and we prefer that one", desc.name);
482 layer->Release (layer);
487 static DFBEnumerationResult
488 gst_dfbvideosink_enum_vmodes (gint width, gint height, gint bpp, void *data)
490 GstDfbVideoSink *dfbvideosink = NULL;
491 GstDfbVMode *vmode = NULL;
493 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (data), DFENUM_CANCEL);
495 dfbvideosink = GST_DFBVIDEOSINK (data);
497 GST_DEBUG_OBJECT (dfbvideosink, "adding video mode %dx%d at %d bpp", width,
499 vmode = g_new0 (GstDfbVMode, 1);
500 vmode->width = width;
501 vmode->height = height;
504 /* We need to know the maximum video geometry we can accept for the caps */
505 if (width > dfbvideosink->out_width) {
506 dfbvideosink->out_width = width;
508 if (height > dfbvideosink->out_height) {
509 dfbvideosink->out_height = height;
512 dfbvideosink->vmodes = g_slist_append (dfbvideosink->vmodes, vmode);
517 static DFBEnumerationResult
518 gst_dfbvideosink_enum_devices (DFBInputDeviceID id,
519 DFBInputDeviceDescription desc, void *data)
521 GstDfbVideoSink *dfbvideosink = NULL;
522 IDirectFBInputDevice *device = NULL;
525 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (data), DFENUM_CANCEL);
527 dfbvideosink = GST_DFBVIDEOSINK (data);
529 GST_DEBUG_OBJECT (dfbvideosink, "detected input device %s from vendor %s",
530 desc.name, desc.vendor);
532 /* Get that input device */
533 ret = dfbvideosink->dfb->GetInputDevice (dfbvideosink->dfb, id, &device);
535 GST_WARNING_OBJECT (dfbvideosink, "failed when getting input device id %d",
540 ret = device->AttachEventBuffer (device, dfbvideosink->event_buffer);
542 GST_WARNING_OBJECT (dfbvideosink, "failed when attaching input device "
543 "%d to our event buffer", id);
548 device->Release (device);
554 gst_dfbvideosink_setup (GstDfbVideoSink * dfbvideosink)
558 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), FALSE);
560 dfbvideosink->video_width = 0;
561 dfbvideosink->video_height = 0;
562 dfbvideosink->out_width = 0;
563 dfbvideosink->out_height = 0;
564 dfbvideosink->fps_d = 0;
565 dfbvideosink->fps_n = 0;
566 dfbvideosink->hw_scaling = FALSE;
567 dfbvideosink->backbuffer = FALSE;
568 dfbvideosink->pixel_format = DSPF_UNKNOWN;
570 /* If we do it all by ourself we create the DirectFB context, get the
571 primary layer and use a fullscreen configuration */
572 if (!dfbvideosink->ext_surface) {
573 GST_DEBUG_OBJECT (dfbvideosink, "no external surface, taking over "
574 "DirectFB fullscreen");
575 if (!dfbvideosink->dfb) {
576 DFBGraphicsDeviceDescription hw_caps;
577 char *argv[] = { (char *) "-", (char *) "--dfb:quiet", NULL };
581 GST_DEBUG_OBJECT (dfbvideosink, "initializing DirectFB");
584 ret = DirectFBInit (&argc, &args);
587 GST_WARNING_OBJECT (dfbvideosink, "DirectFB initialization failed");
591 ret = DirectFBCreate (&(dfbvideosink->dfb));
594 GST_WARNING_OBJECT (dfbvideosink, "failed creating the DirectFB "
599 /* Get Hardware capabilities */
600 ret = dfbvideosink->dfb->GetDeviceDescription (dfbvideosink->dfb,
604 GST_WARNING_OBJECT (dfbvideosink, "failed grabbing the hardware "
609 GST_DEBUG_OBJECT (dfbvideosink, "video card %s from vendor %s detected "
610 "with %d bytes of video memory", hw_caps.name, hw_caps.vendor,
611 hw_caps.video_memory);
613 if (hw_caps.acceleration_mask & DFXL_BLIT) {
614 GST_DEBUG_OBJECT (dfbvideosink, "Blit is accelerated");
616 if (hw_caps.acceleration_mask & DFXL_STRETCHBLIT) {
617 GST_DEBUG_OBJECT (dfbvideosink, "StretchBlit is accelerated");
618 dfbvideosink->hw_scaling = TRUE;
620 GST_DEBUG_OBJECT (dfbvideosink, "StretchBlit is not accelerated");
621 dfbvideosink->hw_scaling = FALSE;
624 dfbvideosink->layer_id = -1;
626 /* Inspect all the Display layers */
627 dfbvideosink->dfb->EnumDisplayLayers (dfbvideosink->dfb,
628 gst_dfbvideosink_enum_layers, dfbvideosink);
629 /* Inspect all Video modes */
630 dfbvideosink->dfb->EnumVideoModes (dfbvideosink->dfb,
631 gst_dfbvideosink_enum_vmodes, dfbvideosink);
633 /* Create an event buffer for input */
634 dfbvideosink->dfb->CreateEventBuffer (dfbvideosink->dfb,
635 &dfbvideosink->event_buffer);
637 /* Inspect all Input devices */
638 dfbvideosink->dfb->EnumInputDevices (dfbvideosink->dfb,
639 gst_dfbvideosink_enum_devices, dfbvideosink);
640 /* Create a thread to handle those events */
641 dfbvideosink->event_thread = g_thread_create (
642 (GThreadFunc) gst_dfbvideosink_event_thread,
643 dfbvideosink, TRUE, NULL);
645 if (!dfbvideosink->layer) {
646 GList *channels_list = NULL;
647 DFBDisplayLayerDescription dl_desc;
649 /* Get the best Display Layer */
650 ret = dfbvideosink->dfb->GetDisplayLayer (dfbvideosink->dfb,
651 dfbvideosink->layer_id, &dfbvideosink->layer);
653 GST_WARNING_OBJECT (dfbvideosink, "failed getting display layer");
657 ret = dfbvideosink->layer->SetCooperativeLevel (dfbvideosink->layer,
661 GST_WARNING_OBJECT (dfbvideosink, "failed setting display layer to "
666 dfbvideosink->layer->GetDescription (dfbvideosink->layer, &dl_desc);
668 /* Check that this layer is able to do colorbalance settings */
669 if (dl_desc.caps & DLCAPS_BRIGHTNESS) {
670 channels_list = g_list_append (channels_list, (char *) "BRIGHTNESS");
672 if (dl_desc.caps & DLCAPS_CONTRAST) {
673 channels_list = g_list_append (channels_list, (char *) "CONTRAST");
675 if (dl_desc.caps & DLCAPS_HUE) {
676 channels_list = g_list_append (channels_list, (char *) "HUE");
678 if (dl_desc.caps & DLCAPS_SATURATION) {
679 channels_list = g_list_append (channels_list, (char *) "SATURATION");
683 GList *walk = channels_list;
685 /* Generate Color balance channel list */
687 GstColorBalanceChannel *channel = NULL;
689 GST_DEBUG_OBJECT (dfbvideosink, "adding %s as a colorbalance channel",
690 (const char *) walk->data);
692 channel = g_object_new (GST_TYPE_COLOR_BALANCE_CHANNEL, NULL);
693 channel->label = g_strdup (walk->data);
694 channel->min_value = 0x0000;
695 channel->max_value = 0xFFFF;
697 dfbvideosink->cb_channels = g_list_append (dfbvideosink->cb_channels,
700 walk = g_list_next (walk);
703 /* If the colorbalance settings have not been touched we get current
704 values as defaults and update our internal variables */
705 if (!dfbvideosink->cb_changed) {
706 DFBColorAdjustment cb_adjust;
708 ret = dfbvideosink->layer->GetColorAdjustment (dfbvideosink->layer,
712 GST_WARNING_OBJECT (dfbvideosink, "failed when getting color "
713 "adjustment from layer");
716 if (cb_adjust.flags & DCAF_BRIGHTNESS) {
717 dfbvideosink->brightness = cb_adjust.brightness;
719 dfbvideosink->brightness = 0x8000;
721 if (cb_adjust.flags & DCAF_CONTRAST) {
722 dfbvideosink->contrast = cb_adjust.contrast;
724 dfbvideosink->contrast = 0x8000;
726 if (cb_adjust.flags & DCAF_HUE) {
727 dfbvideosink->hue = cb_adjust.hue;
729 dfbvideosink->hue = 0x8000;
731 if (cb_adjust.flags & DCAF_SATURATION) {
732 dfbvideosink->saturation = cb_adjust.saturation;
734 dfbvideosink->saturation = 0x8000;
736 GST_DEBUG_OBJECT (dfbvideosink, "brightness %d, contrast %d, "
737 "hue %d, saturation %d", dfbvideosink->brightness,
738 dfbvideosink->contrast, dfbvideosink->hue,
739 dfbvideosink->saturation);
742 g_list_free (channels_list);
744 gst_dfbvideosink_update_colorbalance (dfbvideosink);
747 dfbvideosink->layer->SetBackgroundColor (dfbvideosink->layer,
748 0x00, 0x00, 0x00, 0xFF);
750 dfbvideosink->layer->EnableCursor (dfbvideosink->layer, TRUE);
752 GST_DEBUG_OBJECT (dfbvideosink, "getting primary surface");
753 dfbvideosink->layer->GetSurface (dfbvideosink->layer,
754 &dfbvideosink->primary);
756 dfbvideosink->primary->SetBlittingFlags (dfbvideosink->primary,
760 dfbvideosink->primary->GetPixelFormat (dfbvideosink->primary,
761 &dfbvideosink->pixel_format);
763 DFBSurfaceCapabilities s_caps;
765 GST_DEBUG_OBJECT (dfbvideosink, "getting pixel format from foreign "
766 "surface %p", dfbvideosink->ext_surface);
767 dfbvideosink->ext_surface->GetPixelFormat (dfbvideosink->ext_surface,
768 &dfbvideosink->pixel_format);
769 dfbvideosink->ext_surface->GetSize (dfbvideosink->ext_surface,
770 &dfbvideosink->out_width, &dfbvideosink->out_height);
771 dfbvideosink->ext_surface->GetCapabilities (dfbvideosink->ext_surface,
773 if ((s_caps & DSCAPS_DOUBLE) || (s_caps & DSCAPS_TRIPLE)) {
774 dfbvideosink->backbuffer = TRUE;
776 dfbvideosink->backbuffer = FALSE;
778 GST_DEBUG_OBJECT (dfbvideosink, "external surface is %dx%d and uses %s "
779 "pixel format", dfbvideosink->out_width, dfbvideosink->out_height,
780 gst_dfbvideosink_get_format_name (dfbvideosink->pixel_format));
783 dfbvideosink->setup = TRUE;
786 return dfbvideosink->setup;
790 gst_dfbvideosink_cleanup (GstDfbVideoSink * dfbvideosink)
792 g_return_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink));
794 GST_DEBUG_OBJECT (dfbvideosink, "cleaning up DirectFB environment");
796 /* Wait for our event thread */
797 if (dfbvideosink->event_thread) {
798 g_thread_join (dfbvideosink->event_thread);
799 dfbvideosink->event_thread = NULL;
802 if (dfbvideosink->event_buffer) {
803 dfbvideosink->event_buffer->Release (dfbvideosink->event_buffer);
804 dfbvideosink->event_buffer = NULL;
807 if (dfbvideosink->vmodes) {
808 GSList *walk = dfbvideosink->vmodes;
812 walk = g_slist_next (walk);
814 g_slist_free (dfbvideosink->vmodes);
815 dfbvideosink->vmodes = NULL;
818 if (dfbvideosink->cb_channels) {
819 GList *walk = dfbvideosink->cb_channels;
822 GstColorBalanceChannel *channel = walk->data;
824 g_object_unref (channel);
825 walk = g_list_next (walk);
827 g_list_free (dfbvideosink->cb_channels);
828 dfbvideosink->cb_channels = NULL;
831 if (dfbvideosink->buffer_pool) {
832 gst_dfbvideosink_bufferpool_clear (dfbvideosink);
835 if (dfbvideosink->primary) {
836 dfbvideosink->primary->Release (dfbvideosink->primary);
837 dfbvideosink->primary = NULL;
840 if (dfbvideosink->layer) {
841 dfbvideosink->layer->EnableCursor (dfbvideosink->layer, FALSE);
842 dfbvideosink->layer->Release (dfbvideosink->layer);
843 dfbvideosink->layer = NULL;
846 if (dfbvideosink->dfb) {
847 dfbvideosink->dfb->Release (dfbvideosink->dfb);
848 dfbvideosink->dfb = NULL;
851 dfbvideosink->setup = FALSE;
854 static DFBSurfacePixelFormat
855 gst_dfbvideosink_get_format_from_caps (GstCaps * caps)
857 GstStructure *structure;
859 DFBSurfacePixelFormat pixel_format = DSPF_UNKNOWN;
861 g_return_val_if_fail (GST_IS_CAPS (caps), DSPF_UNKNOWN);
863 structure = gst_caps_get_structure (caps, 0);
865 if (gst_structure_has_name (structure, "video/x-raw-rgb")) {
868 ret = gst_structure_get_int (structure, "bpp", &bpp);
869 ret &= gst_structure_get_int (structure, "depth", &depth);
877 pixel_format = DSPF_RGB16;
880 pixel_format = DSPF_RGB24;
884 pixel_format = DSPF_RGB32;
885 } else if (depth == 32) {
886 pixel_format = DSPF_ARGB;
892 GST_WARNING ("unhandled RGB format, bpp %d, depth %d", bpp, depth);
895 } else if (gst_structure_has_name (structure, "video/x-raw-yuv")) {
898 ret = gst_structure_get_fourcc (structure, "format", &fourcc);
901 GST_WARNING ("failed grabbing fourcc from caps %" GST_PTR_FORMAT, caps);
906 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
907 pixel_format = DSPF_I420;
909 case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
910 pixel_format = DSPF_YV12;
912 case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
913 pixel_format = DSPF_YUY2;
915 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
916 pixel_format = DSPF_UYVY;
919 GST_WARNING ("unhandled YUV format %" GST_FOURCC_FORMAT,
920 GST_FOURCC_ARGS (fourcc));
924 GST_WARNING ("unknown caps name received %" GST_PTR_FORMAT, caps);
933 gst_dfbvideosink_get_caps_from_format (DFBSurfacePixelFormat format)
935 GstCaps *caps = NULL;
936 gboolean is_rgb = FALSE, is_yuv = FALSE;
940 g_return_val_if_fail (format != DSPF_UNKNOWN, NULL);
965 fourcc = GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
969 fourcc = GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y');
973 fourcc = GST_MAKE_FOURCC ('I', '4', '2', '0');
977 fourcc = GST_MAKE_FOURCC ('Y', 'V', '1', '2');
980 GST_WARNING ("unknown pixel format %s",
981 gst_dfbvideosink_get_format_name (format));
986 caps = gst_caps_new_simple ("video/x-raw-rgb",
987 "bpp", G_TYPE_INT, bpp, "depth", G_TYPE_INT, depth, NULL);
989 caps = gst_caps_new_simple ("video/x-raw-yuv",
990 "format", GST_TYPE_FOURCC, fourcc, NULL);
992 GST_WARNING ("neither rgb nor yuv, something strange here");
1000 gst_dfbvideosink_can_blit_from_format (GstDfbVideoSink * dfbvideosink,
1001 DFBSurfacePixelFormat format)
1003 gboolean res = FALSE;
1005 IDirectFBSurface *surface = NULL;
1006 DFBSurfaceDescription s_dsc;
1007 DFBAccelerationMask mask;
1008 DFBDisplayLayerConfig dlc, prev_dlc;
1010 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), FALSE);
1012 /* Create a surface of desired format */
1013 s_dsc.flags = DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_HEIGHT;
1014 s_dsc.pixelformat = format;
1018 ret = dfbvideosink->dfb->CreateSurface (dfbvideosink->dfb, &s_dsc, &surface);
1019 if (ret != DFB_OK) {
1020 GST_WARNING_OBJECT (dfbvideosink, "failed creating surface with format %s",
1021 gst_dfbvideosink_get_format_name (format));
1025 /* Backup layer configuration */
1026 ret = dfbvideosink->layer->GetConfiguration (dfbvideosink->layer, &prev_dlc);
1027 if (ret != DFB_OK) {
1028 GST_WARNING_OBJECT (dfbvideosink, "failed when getting current layer "
1033 /* Test configuration of the layer to this pixel format */
1034 dlc.flags = DLCONF_PIXELFORMAT;
1035 dlc.pixelformat = format;
1037 ret = dfbvideosink->layer->TestConfiguration (dfbvideosink->layer, &dlc,
1039 if (ret != DFB_OK) {
1040 GST_DEBUG_OBJECT (dfbvideosink, "our layer refuses to operate in pixel "
1041 "format %s", gst_dfbvideosink_get_format_name (format));
1045 ret = dfbvideosink->layer->SetConfiguration (dfbvideosink->layer, &dlc);
1046 if (ret != DFB_OK) {
1047 GST_WARNING_OBJECT (dfbvideosink, "our layer refuses to operate in pixel "
1048 "format, though this format was successfully tested earlied %s",
1049 gst_dfbvideosink_get_format_name (format));
1053 ret = dfbvideosink->primary->GetAccelerationMask (dfbvideosink->primary,
1055 if (ret != DFB_OK) {
1056 GST_WARNING_OBJECT (dfbvideosink, "failed getting acceleration mask");
1060 /* Blitting from this format to our primary is accelerated */
1061 if (mask & DFXL_BLIT) {
1062 GST_DEBUG_OBJECT (dfbvideosink, "blitting from format %s to our primary "
1063 "is accelerated", gst_dfbvideosink_get_format_name (format));
1066 GST_DEBUG_OBJECT (dfbvideosink, "blitting from format %s to our primary "
1067 "is not accelerated", gst_dfbvideosink_get_format_name (format));
1071 /* Restore original layer configuration */
1072 ret = dfbvideosink->layer->SetConfiguration (dfbvideosink->layer, &prev_dlc);
1073 if (ret != DFB_OK) {
1074 GST_WARNING_OBJECT (dfbvideosink, "failed when restoring layer "
1081 surface->Release (surface);
1087 gst_dfbvideosink_get_best_vmode (GstDfbVideoSink * dfbvideosink, gint v_width,
1088 gint v_height, GstDfbVMode * best_vmode)
1090 GSList *walk = NULL;
1091 gboolean ret = FALSE;
1092 gint width, height, bpp;
1093 GstDfbVMode *vmode = NULL;
1095 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), FALSE);
1097 if (!dfbvideosink->vmodes) {
1101 walk = dfbvideosink->vmodes;
1103 vmode = (GstDfbVMode *) walk->data;
1106 width = vmode->width;
1107 height = vmode->height;
1111 gint wgap, hgap, best_wgap, best_hgap;
1113 vmode = (GstDfbVMode *) walk->data;
1115 /* What are the gaps */
1116 wgap = abs (vmode->width - v_width);
1117 hgap = abs (vmode->height - v_height);
1118 best_wgap = abs (width - v_width);
1119 best_hgap = abs (height - v_height);
1121 /* If this mode is better we ll use that */
1122 if (wgap + hgap < best_wgap + best_hgap) {
1123 width = vmode->width;
1124 height = vmode->height;
1128 walk = g_slist_next (walk);
1131 GST_DEBUG_OBJECT (dfbvideosink, "found video mode %dx%d for input at %dx%d",
1132 width, height, v_width, v_height);
1134 best_vmode->width = width;
1135 best_vmode->height = height;
1136 best_vmode->bpp = bpp;
1145 gst_dfbvideosink_getcaps (GstBaseSink * bsink)
1147 GstDfbVideoSink *dfbvideosink;
1148 GstCaps *caps = NULL;
1151 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1153 if (!dfbvideosink->setup) {
1154 caps = gst_caps_copy (gst_pad_get_pad_template_caps (GST_VIDEO_SINK_PAD
1156 GST_DEBUG_OBJECT (dfbvideosink, "getcaps called and we are not setup yet, "
1157 "returning template %" GST_PTR_FORMAT, caps);
1160 GST_DEBUG_OBJECT (dfbvideosink, "getcaps called, checking our internal "
1162 if (dfbvideosink->ext_surface) {
1163 /* We are not rendering to our own surface, returning this surface's
1165 caps = gst_dfbvideosink_get_caps_from_format (dfbvideosink->pixel_format);
1167 /* Try some formats */
1168 caps = gst_caps_new_empty ();
1170 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_RGB16)) {
1171 gst_caps_append (caps,
1172 gst_dfbvideosink_get_caps_from_format (DSPF_RGB16));
1174 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_RGB24)) {
1175 gst_caps_append (caps,
1176 gst_dfbvideosink_get_caps_from_format (DSPF_RGB24));
1178 /* There's something wrong with RGB32, ffmpegcolorspace ?
1179 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_RGB32)) {
1180 gst_caps_append (caps,
1181 gst_dfbvideosink_get_caps_from_format (DSPF_RGB32));
1183 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_ARGB)) {
1184 gst_caps_append (caps,
1185 gst_dfbvideosink_get_caps_from_format (DSPF_ARGB));
1187 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_YUY2)) {
1188 gst_caps_append (caps,
1189 gst_dfbvideosink_get_caps_from_format (DSPF_YUY2));
1191 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_UYVY)) {
1192 gst_caps_append (caps,
1193 gst_dfbvideosink_get_caps_from_format (DSPF_UYVY));
1195 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_I420)) {
1196 gst_caps_append (caps,
1197 gst_dfbvideosink_get_caps_from_format (DSPF_I420));
1199 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_YV12)) {
1200 gst_caps_append (caps,
1201 gst_dfbvideosink_get_caps_from_format (DSPF_YV12));
1206 for (i = 0; i < gst_caps_get_size (caps); i++) {
1207 GstStructure *structure = gst_caps_get_structure (caps, i);
1209 gst_structure_set (structure,
1210 "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
1211 "height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
1212 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
1214 if (!dfbvideosink->hw_scaling && dfbvideosink->par) {
1217 nom = gst_value_get_fraction_numerator (dfbvideosink->par);
1218 den = gst_value_get_fraction_denominator (dfbvideosink->par);
1219 gst_structure_set (structure, "pixel-aspect-ratio",
1220 GST_TYPE_FRACTION, nom, den, NULL);
1224 GST_DEBUG_OBJECT (dfbvideosink, "returning our caps %" GST_PTR_FORMAT, caps);
1231 gst_dfbvideosink_setcaps (GstBaseSink * bsink, GstCaps * caps)
1233 GstDfbVideoSink *dfbvideosink;
1234 GstStructure *structure;
1235 gboolean res, result = FALSE;
1236 gint video_width, video_height;
1237 const GValue *framerate;
1238 DFBSurfacePixelFormat pixel_format = DSPF_UNKNOWN;
1240 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1242 structure = gst_caps_get_structure (caps, 0);
1243 res = gst_structure_get_int (structure, "width", &video_width);
1244 res &= gst_structure_get_int (structure, "height", &video_height);
1245 framerate = gst_structure_get_value (structure, "framerate");
1246 res &= (framerate != NULL);
1251 dfbvideosink->fps_n = gst_value_get_fraction_numerator (framerate);
1252 dfbvideosink->fps_d = gst_value_get_fraction_denominator (framerate);
1254 pixel_format = gst_dfbvideosink_get_format_from_caps (caps);
1256 GST_DEBUG_OBJECT (dfbvideosink, "setcaps called with %" GST_PTR_FORMAT, caps);
1257 GST_DEBUG_OBJECT (dfbvideosink, "our format is: %dx%d %s video at %d/%d fps",
1258 video_width, video_height,
1259 gst_dfbvideosink_get_format_name (pixel_format), dfbvideosink->fps_n,
1260 dfbvideosink->fps_d);
1262 if (dfbvideosink->hw_scaling && dfbvideosink->par) {
1263 gint video_par_n, video_par_d; /* video's PAR */
1264 gint display_par_n, display_par_d; /* display's PAR */
1266 GValue display_ratio = { 0, }; /* display w/h ratio */
1267 const GValue *caps_par;
1269 /* get aspect ratio from caps if it's present, and
1270 * convert video width and height to a display width and height
1271 * using wd / hd = wv / hv * PARv / PARd
1272 * the ratio wd / hd will be stored in display_ratio */
1273 g_value_init (&display_ratio, GST_TYPE_FRACTION);
1275 /* get video's PAR */
1276 caps_par = gst_structure_get_value (structure, "pixel-aspect-ratio");
1278 video_par_n = gst_value_get_fraction_numerator (caps_par);
1279 video_par_d = gst_value_get_fraction_denominator (caps_par);
1284 /* get display's PAR */
1285 if (dfbvideosink->par) {
1286 display_par_n = gst_value_get_fraction_numerator (dfbvideosink->par);
1287 display_par_d = gst_value_get_fraction_denominator (dfbvideosink->par);
1293 gst_value_set_fraction (&display_ratio,
1294 video_width * video_par_n * display_par_d,
1295 video_height * video_par_d * display_par_n);
1297 num = gst_value_get_fraction_numerator (&display_ratio);
1298 den = gst_value_get_fraction_denominator (&display_ratio);
1299 GST_DEBUG_OBJECT (dfbvideosink,
1300 "video width/height: %dx%d, calculated display ratio: %d/%d",
1301 video_width, video_height, num, den);
1303 /* now find a width x height that respects this display ratio.
1304 * prefer those that have one of w/h the same as the incoming video
1305 * using wd / hd = num / den */
1307 /* start with same height, because of interlaced video */
1308 /* check hd / den is an integer scale factor, and scale wd with the PAR */
1309 if (video_height % den == 0) {
1310 GST_DEBUG_OBJECT (dfbvideosink, "keeping video height");
1311 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_height * num / den;
1312 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_height;
1313 } else if (video_width % num == 0) {
1314 GST_DEBUG_OBJECT (dfbvideosink, "keeping video width");
1315 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_width;
1316 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_width * den / num;
1318 GST_DEBUG_OBJECT (dfbvideosink, "approximating while keeping height");
1319 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_height * num / den;
1320 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_height;
1322 GST_DEBUG_OBJECT (dfbvideosink, "scaling to %dx%d",
1323 GST_VIDEO_SINK_WIDTH (dfbvideosink),
1324 GST_VIDEO_SINK_HEIGHT (dfbvideosink));
1326 if (dfbvideosink->par) {
1329 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
1331 if (gst_value_compare (par, dfbvideosink->par) != GST_VALUE_EQUAL) {
1336 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_width;
1337 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_height;
1340 /* Try to adapt the video mode to the video geometry */
1341 if (dfbvideosink->dfb) {
1345 GST_DEBUG_OBJECT (dfbvideosink, "trying to adapt the video mode to video "
1348 /* Set video mode and layer configuration appropriately */
1349 if (gst_dfbvideosink_get_best_vmode (dfbvideosink,
1350 GST_VIDEO_SINK_WIDTH (dfbvideosink),
1351 GST_VIDEO_SINK_HEIGHT (dfbvideosink), &vmode)) {
1352 DFBDisplayLayerConfig lc;
1353 gint width, height, bpp;
1355 width = vmode.width;
1356 height = vmode.height;
1359 GST_DEBUG_OBJECT (dfbvideosink, "setting video mode to %dx%d at %d bpp",
1360 width, height, bpp);
1362 ret = dfbvideosink->dfb->SetVideoMode (dfbvideosink->dfb, width,
1364 if (ret != DFB_OK) {
1365 GST_WARNING_OBJECT (dfbvideosink, "failed setting video mode %dx%d "
1366 "at %d bpp", width, height, bpp);
1369 lc.flags = DLCONF_PIXELFORMAT;
1370 lc.pixelformat = pixel_format;
1372 ret = dfbvideosink->layer->SetConfiguration (dfbvideosink->layer, &lc);
1373 if (ret != DFB_OK) {
1374 GST_WARNING_OBJECT (dfbvideosink, "failed setting layer pixelformat "
1375 "to %s", gst_dfbvideosink_get_format_name (pixel_format));
1377 dfbvideosink->layer->GetConfiguration (dfbvideosink->layer, &lc);
1378 dfbvideosink->out_width = lc.width;
1379 dfbvideosink->out_height = lc.height;
1380 dfbvideosink->pixel_format = lc.pixelformat;
1381 GST_DEBUG_OBJECT (dfbvideosink, "layer %d now configured to %dx%d %s",
1382 dfbvideosink->layer_id, lc.width, lc.height,
1383 gst_dfbvideosink_get_format_name (lc.pixelformat));
1388 if (pixel_format != dfbvideosink->pixel_format) {
1389 GST_WARNING_OBJECT (dfbvideosink, "setcaps sent us a different pixel "
1390 "format %s", gst_dfbvideosink_get_format_name (pixel_format));
1394 dfbvideosink->video_width = video_width;
1395 dfbvideosink->video_height = video_height;
1405 GST_INFO_OBJECT (dfbvideosink, "pixel aspect ratio does not match");
1410 static GstStateChangeReturn
1411 gst_dfbvideosink_change_state (GstElement * element, GstStateChange transition)
1413 GstDfbVideoSink *dfbvideosink;
1414 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1416 dfbvideosink = GST_DFBVIDEOSINK (element);
1418 switch (transition) {
1419 case GST_STATE_CHANGE_NULL_TO_READY:
1420 dfbvideosink->running = TRUE;
1421 if (!dfbvideosink->setup) {
1422 if (!gst_dfbvideosink_setup (dfbvideosink)) {
1423 GST_DEBUG_OBJECT (dfbvideosink, "setup failed when changing state "
1424 "from NULL to READY");
1425 GST_ELEMENT_ERROR (dfbvideosink, RESOURCE, OPEN_WRITE,
1426 (NULL), ("Failed initializing DirectFB system"));
1427 return GST_STATE_CHANGE_FAILURE;
1431 case GST_STATE_CHANGE_READY_TO_PAUSED:
1432 /* Blank surface if we have one */
1433 if (dfbvideosink->ext_surface) {
1434 dfbvideosink->ext_surface->Clear (dfbvideosink->ext_surface,
1435 0x00, 0x00, 0x00, 0xFF);
1437 if (dfbvideosink->primary) {
1438 dfbvideosink->primary->Clear (dfbvideosink->primary, 0x00, 0x00,
1442 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1448 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1449 if (ret == GST_STATE_CHANGE_FAILURE)
1452 switch (transition) {
1453 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1455 case GST_STATE_CHANGE_PAUSED_TO_READY:
1456 dfbvideosink->fps_d = 0;
1457 dfbvideosink->fps_n = 0;
1458 dfbvideosink->video_width = 0;
1459 dfbvideosink->video_height = 0;
1461 if (dfbvideosink->buffer_pool) {
1462 gst_dfbvideosink_bufferpool_clear (dfbvideosink);
1465 case GST_STATE_CHANGE_READY_TO_NULL:
1466 dfbvideosink->running = FALSE;
1467 if (dfbvideosink->setup) {
1468 gst_dfbvideosink_cleanup (dfbvideosink);
1479 gst_dfbvideosink_get_times (GstBaseSink * bsink, GstBuffer * buf,
1480 GstClockTime * start, GstClockTime * end)
1482 GstDfbVideoSink *dfbvideosink;
1484 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1486 if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
1487 *start = GST_BUFFER_TIMESTAMP (buf);
1488 if (GST_BUFFER_DURATION_IS_VALID (buf)) {
1489 *end = *start + GST_BUFFER_DURATION (buf);
1491 if (dfbvideosink->fps_n > 0) {
1493 *start + (GST_SECOND * dfbvideosink->fps_d) / dfbvideosink->fps_n;
1499 static GstFlowReturn
1500 gst_dfbvideosink_show_frame (GstBaseSink * bsink, GstBuffer * buf)
1502 GstDfbVideoSink *dfbvideosink = NULL;
1504 GstVideoRectangle dst, src, result;
1505 GstFlowReturn ret = GST_FLOW_OK;
1506 gboolean mem_cpy = TRUE;
1508 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1510 if (!dfbvideosink->setup) {
1511 ret = GST_FLOW_UNEXPECTED;
1515 /* Is that a buffer we allocated ourselves ? */
1516 if (GST_IS_DFBSURFACE (buf)) {
1517 GstDfbSurface *tmp_surface = GST_DFBSURFACE (buf);
1519 /* Does it have a surface ? */
1520 if (tmp_surface->surface) {
1522 GST_DEBUG_OBJECT (dfbvideosink, "we have a buffer (%p) we allocated "
1523 "ourselves and it has a surface, no memcpy then", buf);
1525 /* No surface, that's a malloc */
1526 GST_DEBUG_OBJECT (dfbvideosink, "we have a buffer (%p) we allocated "
1527 "ourselves but it does not hold a surface", buf);
1531 GST_DEBUG_OBJECT (dfbvideosink, "we have a buffer (%p) we did not allocate",
1536 IDirectFBSurface *dest = NULL, *surface = NULL;
1538 gint dest_pitch, src_pitch, line;
1539 GstStructure *structure;
1541 /* As we are not blitting no acceleration is possible. If the surface is
1542 * too small we do clipping, if it's too big we center. Theoretically as
1543 * we are using buffer_alloc, there's a chance that we have been able to
1544 * do reverse caps negotiation */
1546 if (dfbvideosink->ext_surface) {
1547 surface = dfbvideosink->ext_surface;
1548 GST_DEBUG_OBJECT (dfbvideosink, "memcpy to an external surface "
1549 "subsurface (vsync %d)", dfbvideosink->vsync);
1551 surface = dfbvideosink->primary;
1552 GST_DEBUG_OBJECT (dfbvideosink, "memcpy to a primary subsurface "
1553 "(vsync %d)", dfbvideosink->vsync);
1556 /* Get the video frame geometry from the buffer caps */
1557 structure = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0);
1559 gst_structure_get_int (structure, "width", &src.w);
1560 gst_structure_get_int (structure, "height", &src.h);
1562 src.w = dfbvideosink->video_width;
1563 src.h = dfbvideosink->video_height;
1565 res = surface->GetSize (surface, &dst.w, &dst.h);
1568 gst_video_sink_center_rect (src, dst, &result, FALSE);
1571 surface->GetSubSurface (surface, (DFBRectangle *) (void *) &result,
1573 if (res != DFB_OK) {
1574 GST_WARNING_OBJECT (dfbvideosink, "failed when getting a sub surface");
1575 ret = GST_FLOW_UNEXPECTED;
1579 /* If we are not using Flip we wait for VSYNC before blit */
1580 if (!dfbvideosink->backbuffer && dfbvideosink->vsync) {
1581 dfbvideosink->layer->WaitForSync (dfbvideosink->layer);
1584 res = dest->Lock (dest, DSLF_WRITE, (void *) &data, &dest_pitch);
1585 if (res != DFB_OK) {
1586 GST_WARNING_OBJECT (dfbvideosink, "failed locking the external "
1587 "subsurface for writing");
1588 ret = GST_FLOW_ERROR;
1592 /* Source video rowbytes */
1593 src_pitch = GST_BUFFER_SIZE (buf) / src.h;
1595 /* Write each line respecting subsurface pitch */
1596 for (line = 0; line < result.h; line++) {
1597 /* We do clipping */
1598 memcpy (data, GST_BUFFER_DATA (buf) + (line * src_pitch),
1599 MIN (src_pitch, dest_pitch));
1603 res = dest->Unlock (dest);
1605 res = dest->Release (dest);
1607 if (dfbvideosink->backbuffer) {
1608 if (dfbvideosink->vsync) {
1609 res = surface->Flip (surface, NULL, DSFLIP_ONSYNC);
1611 res = surface->Flip (surface, NULL, DSFLIP_NONE);
1615 /* Else we will [Stretch]Blit to our primary */
1616 GstDfbSurface *surface = GST_DFBSURFACE (buf);
1618 GST_DEBUG_OBJECT (dfbvideosink, "blitting to a primary surface (vsync %d)",
1619 dfbvideosink->vsync);
1621 src.w = GST_VIDEO_SINK_WIDTH (dfbvideosink);
1622 src.h = GST_VIDEO_SINK_HEIGHT (dfbvideosink);
1624 dfbvideosink->primary->GetSize (dfbvideosink->primary, &dst.w, &dst.h);
1626 /* Unlocking surface before blit */
1627 if (surface->locked) {
1628 surface->surface->Unlock (surface->surface);
1629 surface->locked = FALSE;
1632 gst_video_sink_center_rect (src, dst, &result, dfbvideosink->hw_scaling);
1634 /* If we are not using Flip we wait for VSYNC before blit */
1635 if (!dfbvideosink->backbuffer && dfbvideosink->vsync) {
1636 dfbvideosink->layer->WaitForSync (dfbvideosink->layer);
1639 if (dfbvideosink->hw_scaling) {
1640 dfbvideosink->primary->StretchBlit (dfbvideosink->primary,
1641 surface->surface, NULL, (DFBRectangle *) (void *) &result);
1645 clip.x = clip.y = 0;
1648 dfbvideosink->primary->Blit (dfbvideosink->primary, surface->surface,
1649 &clip, result.x, result.y);
1652 if (dfbvideosink->backbuffer) {
1653 if (dfbvideosink->vsync) {
1654 dfbvideosink->primary->Flip (dfbvideosink->primary, NULL,
1657 dfbvideosink->primary->Flip (dfbvideosink->primary, NULL, DSFLIP_NONE);
1667 gst_dfbvideosink_bufferpool_clear (GstDfbVideoSink * dfbvideosink)
1669 g_mutex_lock (dfbvideosink->pool_lock);
1670 while (dfbvideosink->buffer_pool) {
1671 GstDfbSurface *surface = dfbvideosink->buffer_pool->data;
1673 dfbvideosink->buffer_pool = g_slist_delete_link (dfbvideosink->buffer_pool,
1674 dfbvideosink->buffer_pool);
1675 gst_dfbvideosink_surface_destroy (dfbvideosink, surface);
1677 g_mutex_unlock (dfbvideosink->pool_lock);
1680 /* For every buffer request we create a custom buffer containing and
1681 * IDirectFBSurface or allocate a previously created one that's not used
1683 static GstFlowReturn
1684 gst_dfbvideosink_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size,
1685 GstCaps * caps, GstBuffer ** buf)
1687 GstDfbVideoSink *dfbvideosink;
1688 GstDfbSurface *surface = NULL;
1689 GstFlowReturn ret = GST_FLOW_OK;
1691 gboolean rev_nego = FALSE;
1694 GstCaps *desired_caps = NULL;
1695 GstStructure *structure = NULL;
1697 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1699 GST_LOG_OBJECT (dfbvideosink, "a buffer of %u bytes was requested with caps "
1700 "%" GST_PTR_FORMAT " and offset %" G_GUINT64_FORMAT, size, caps, offset);
1702 if (G_UNLIKELY (!dfbvideosink->setup)) {
1703 GST_DEBUG_OBJECT (dfbvideosink, "we are not setup yet, can't allocate!");
1708 desired_caps = gst_caps_copy (caps);
1710 structure = gst_caps_get_structure (desired_caps, 0);
1712 if (gst_structure_get_int (structure, "width", &width) &&
1713 gst_structure_get_int (structure, "height", &height)) {
1714 GstVideoRectangle dst, src, result;
1717 /* If we can do hardware scaling we don't do reverse negotiation */
1718 if (dfbvideosink->hw_scaling) {
1722 /* Our desired geometry respects aspect ratio */
1725 /* We should adapt the destination to the most suitable video mode */
1726 if (gst_dfbvideosink_get_best_vmode (dfbvideosink, width, height, &vmode)) {
1727 dst.w = vmode.width;
1728 dst.h = vmode.height;
1730 if (dfbvideosink->ext_surface) {
1731 dfbvideosink->ext_surface->GetSize (dfbvideosink->ext_surface, &dst.w,
1734 dfbvideosink->primary->GetSize (dfbvideosink->primary, &dst.w, &dst.h);
1736 dfbvideosink->out_width = dst.w;
1737 dfbvideosink->out_height = dst.h;
1740 gst_video_sink_center_rect (src, dst, &result, TRUE);
1742 if (width != result.w || height != result.h) {
1743 GstPad *peer = gst_pad_get_peer (GST_VIDEO_SINK_PAD (dfbvideosink));
1745 if (!GST_IS_PAD (peer)) {
1746 /* Is this situation possible ? */
1750 GST_DEBUG_OBJECT (dfbvideosink, "we would love to receive a %dx%d video",
1751 result.w, result.h);
1752 gst_structure_set (structure, "width", G_TYPE_INT, result.w, NULL);
1753 gst_structure_set (structure, "height", G_TYPE_INT, result.h, NULL);
1755 /* PAR property overrides the X calculated one */
1756 if (dfbvideosink->par) {
1759 nom = gst_value_get_fraction_numerator (dfbvideosink->par);
1760 den = gst_value_get_fraction_denominator (dfbvideosink->par);
1761 gst_structure_set (structure, "pixel-aspect-ratio",
1762 GST_TYPE_FRACTION, nom, den, NULL);
1765 if (gst_pad_accept_caps (peer, desired_caps)) {
1768 bpp = size / height / width;
1772 size = bpp * width * height;
1773 GST_DEBUG_OBJECT (dfbvideosink, "peed pad accepts our desired caps %"
1774 GST_PTR_FORMAT " buffer size is now %d bytes", desired_caps, size);
1776 GST_DEBUG_OBJECT (dfbvideosink, "peer pad does not accept our "
1777 "desired caps %" GST_PTR_FORMAT, desired_caps);
1779 width = dfbvideosink->video_width;
1780 height = dfbvideosink->video_height;
1782 gst_object_unref (peer);
1787 /* Inspect our buffer pool */
1788 g_mutex_lock (dfbvideosink->pool_lock);
1789 while (dfbvideosink->buffer_pool) {
1790 surface = (GstDfbSurface *) dfbvideosink->buffer_pool->data;
1793 /* Removing from the pool */
1794 dfbvideosink->buffer_pool =
1795 g_slist_delete_link (dfbvideosink->buffer_pool,
1796 dfbvideosink->buffer_pool);
1798 /* If the surface is invalid for our need, destroy */
1799 if ((surface->width != width) ||
1800 (surface->height != height) ||
1801 (surface->pixel_format != dfbvideosink->pixel_format)) {
1802 gst_dfbvideosink_surface_destroy (dfbvideosink, surface);
1805 /* We found a suitable surface */
1810 g_mutex_unlock (dfbvideosink->pool_lock);
1812 /* We haven't found anything, creating a new one */
1815 surface = gst_dfbvideosink_surface_create (dfbvideosink, desired_caps,
1818 surface = gst_dfbvideosink_surface_create (dfbvideosink, caps, size);
1821 /* Now we should have a surface, set appropriate caps on it */
1824 gst_buffer_set_caps (GST_BUFFER (surface), desired_caps);
1826 gst_buffer_set_caps (GST_BUFFER (surface), caps);
1830 *buf = GST_BUFFER (surface);
1832 gst_caps_unref (desired_caps);
1837 /* Our subclass of GstBuffer */
1840 gst_dfbsurface_finalize (GstDfbSurface * surface)
1842 GstDfbVideoSink *dfbvideosink = NULL;
1844 g_return_if_fail (surface != NULL);
1846 dfbvideosink = surface->dfbvideosink;
1847 if (!dfbvideosink) {
1848 GST_WARNING_OBJECT (surface, "no sink found");
1852 /* If our geometry changed we can't reuse that image. */
1853 if ((surface->width != dfbvideosink->video_width) ||
1854 (surface->height != dfbvideosink->video_height) ||
1855 (surface->pixel_format != dfbvideosink->pixel_format)) {
1856 GST_DEBUG_OBJECT (dfbvideosink, "destroy surface %p as its size changed "
1857 "%dx%d vs current %dx%d", surface, surface->width, surface->height,
1858 dfbvideosink->video_width, dfbvideosink->video_height);
1859 gst_dfbvideosink_surface_destroy (dfbvideosink, surface);
1861 /* In that case we can reuse the image and add it to our image pool. */
1862 GST_DEBUG_OBJECT (dfbvideosink, "recycling surface %p in pool", surface);
1863 /* need to increment the refcount again to recycle */
1864 gst_buffer_ref (GST_BUFFER (surface));
1865 g_mutex_lock (dfbvideosink->pool_lock);
1866 dfbvideosink->buffer_pool = g_slist_prepend (dfbvideosink->buffer_pool,
1868 g_mutex_unlock (dfbvideosink->pool_lock);
1876 gst_dfbsurface_init (GstDfbSurface * surface, gpointer g_class)
1878 surface->surface = NULL;
1880 surface->height = 0;
1881 surface->pixel_format = DSPF_UNKNOWN;
1882 surface->dfbvideosink = NULL;
1886 gst_dfbsurface_class_init (gpointer g_class, gpointer class_data)
1888 GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class);
1890 surface_parent_class = g_type_class_peek_parent (g_class);
1892 mini_object_class->finalize = (GstMiniObjectFinalizeFunction)
1893 gst_dfbsurface_finalize;
1897 gst_dfbsurface_get_type (void)
1899 static GType _gst_dfbsurface_type;
1901 if (G_UNLIKELY (_gst_dfbsurface_type == 0)) {
1902 static const GTypeInfo dfbsurface_info = {
1903 sizeof (GstBufferClass),
1906 gst_dfbsurface_class_init,
1909 sizeof (GstDfbSurface),
1911 (GInstanceInitFunc) gst_dfbsurface_init,
1914 _gst_dfbsurface_type = g_type_register_static (GST_TYPE_BUFFER,
1915 "GstDfbSurface", &dfbsurface_info, 0);
1917 return _gst_dfbsurface_type;
1920 /* Interfaces stuff */
1923 gst_dfbvideosink_interface_supported (GstImplementsInterface * iface,
1926 g_assert (type == GST_TYPE_NAVIGATION || type == GST_TYPE_COLOR_BALANCE);
1931 gst_dfbvideosink_interface_init (GstImplementsInterfaceClass * klass)
1933 klass->supported = gst_dfbvideosink_interface_supported;
1937 gst_dfbvideosink_navigation_send_event (GstNavigation * navigation,
1938 GstStructure * structure)
1940 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (navigation);
1942 GstVideoRectangle src, dst, result;
1943 double x, y, old_x, old_y;
1946 src.w = GST_VIDEO_SINK_WIDTH (dfbvideosink);
1947 src.h = GST_VIDEO_SINK_HEIGHT (dfbvideosink);
1948 dst.w = dfbvideosink->out_width;
1949 dst.h = dfbvideosink->out_height;
1950 gst_video_sink_center_rect (src, dst, &result, dfbvideosink->hw_scaling);
1952 event = gst_event_new_navigation (structure);
1954 /* Our coordinates can be wrong here if we centered the video */
1956 /* Converting pointer coordinates to the non scaled geometry */
1957 if (gst_structure_get_double (structure, "pointer_x", &old_x)) {
1960 if (x >= result.x && x <= (result.x + result.w)) {
1962 x *= dfbvideosink->video_width;
1967 GST_DEBUG_OBJECT (dfbvideosink, "translated navigation event x "
1968 "coordinate from %f to %f", old_x, x);
1969 gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE, x, NULL);
1971 if (gst_structure_get_double (structure, "pointer_y", &old_y)) {
1974 if (y >= result.y && y <= (result.y + result.h)) {
1976 y *= dfbvideosink->video_height;
1981 GST_DEBUG_OBJECT (dfbvideosink, "translated navigation event y "
1982 "coordinate from %fd to %fd", old_y, y);
1983 gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE, y, NULL);
1986 pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (dfbvideosink));
1988 if (GST_IS_PAD (pad) && GST_IS_EVENT (event)) {
1989 gst_pad_send_event (pad, event);
1991 gst_object_unref (pad);
1996 gst_dfbvideosink_navigation_init (GstNavigationInterface * iface)
1998 iface->send_event = gst_dfbvideosink_navigation_send_event;
2002 gst_dfbvideosink_update_colorbalance (GstDfbVideoSink * dfbvideosink)
2004 g_return_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink));
2006 if (dfbvideosink->layer) {
2007 DFBColorAdjustment cb_adjust;
2009 cb_adjust.flags = DCAF_NONE;
2011 if (dfbvideosink->brightness >= 0) {
2012 cb_adjust.flags |= DCAF_BRIGHTNESS;
2014 if (dfbvideosink->contrast >= 0) {
2015 cb_adjust.flags |= DCAF_CONTRAST;
2017 if (dfbvideosink->hue >= 0) {
2018 cb_adjust.flags |= DCAF_HUE;
2020 if (dfbvideosink->saturation >= 0) {
2021 cb_adjust.flags |= DCAF_SATURATION;
2024 cb_adjust.brightness = dfbvideosink->brightness;
2025 cb_adjust.contrast = dfbvideosink->contrast;
2026 cb_adjust.hue = dfbvideosink->hue;
2027 cb_adjust.saturation = dfbvideosink->saturation;
2029 GST_DEBUG_OBJECT (dfbvideosink, "updating colorbalance: flags %d "
2030 "brightness %d contrast %d hue %d saturation %d", cb_adjust.flags,
2031 cb_adjust.brightness, cb_adjust.contrast, cb_adjust.hue,
2032 cb_adjust.saturation);
2033 dfbvideosink->layer->SetColorAdjustment (dfbvideosink->layer, &cb_adjust);
2037 static const GList *
2038 gst_dfbvideosink_colorbalance_list_channels (GstColorBalance * balance)
2040 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (balance);
2042 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), NULL);
2044 return dfbvideosink->cb_channels;
2048 gst_dfbvideosink_colorbalance_set_value (GstColorBalance * balance,
2049 GstColorBalanceChannel * channel, gint value)
2051 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (balance);
2053 g_return_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink));
2054 g_return_if_fail (channel->label != NULL);
2056 dfbvideosink->cb_changed = TRUE;
2058 if (g_ascii_strcasecmp (channel->label, "HUE") == 0) {
2059 dfbvideosink->hue = value;
2060 } else if (g_ascii_strcasecmp (channel->label, "SATURATION") == 0) {
2061 dfbvideosink->saturation = value;
2062 } else if (g_ascii_strcasecmp (channel->label, "CONTRAST") == 0) {
2063 dfbvideosink->contrast = value;
2064 } else if (g_ascii_strcasecmp (channel->label, "BRIGHTNESS") == 0) {
2065 dfbvideosink->brightness = value;
2067 GST_WARNING_OBJECT (dfbvideosink, "got an unknown channel %s",
2072 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2076 gst_dfbvideosink_colorbalance_get_value (GstColorBalance * balance,
2077 GstColorBalanceChannel * channel)
2079 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (balance);
2082 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), 0);
2083 g_return_val_if_fail (channel->label != NULL, 0);
2085 if (g_ascii_strcasecmp (channel->label, "HUE") == 0) {
2086 value = dfbvideosink->hue;
2087 } else if (g_ascii_strcasecmp (channel->label, "SATURATION") == 0) {
2088 value = dfbvideosink->saturation;
2089 } else if (g_ascii_strcasecmp (channel->label, "CONTRAST") == 0) {
2090 value = dfbvideosink->contrast;
2091 } else if (g_ascii_strcasecmp (channel->label, "BRIGHTNESS") == 0) {
2092 value = dfbvideosink->brightness;
2094 GST_WARNING_OBJECT (dfbvideosink, "got an unknown channel %s",
2102 gst_dfbvideosink_colorbalance_init (GstColorBalanceClass * iface)
2104 GST_COLOR_BALANCE_TYPE (iface) = GST_COLOR_BALANCE_HARDWARE;
2105 iface->list_channels = gst_dfbvideosink_colorbalance_list_channels;
2106 iface->set_value = gst_dfbvideosink_colorbalance_set_value;
2107 iface->get_value = gst_dfbvideosink_colorbalance_get_value;
2113 gst_dfbvideosink_set_property (GObject * object, guint prop_id,
2114 const GValue * value, GParamSpec * pspec)
2116 GstDfbVideoSink *dfbvideosink;
2118 g_return_if_fail (GST_IS_DFBVIDEOSINK (object));
2119 dfbvideosink = GST_DFBVIDEOSINK (object);
2123 dfbvideosink->ext_surface = g_value_get_pointer (value);
2126 dfbvideosink->hue = g_value_get_int (value);
2127 dfbvideosink->cb_changed = TRUE;
2128 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2131 dfbvideosink->contrast = g_value_get_int (value);
2132 dfbvideosink->cb_changed = TRUE;
2133 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2135 case ARG_BRIGHTNESS:
2136 dfbvideosink->brightness = g_value_get_int (value);
2137 dfbvideosink->cb_changed = TRUE;
2138 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2140 case ARG_SATURATION:
2141 dfbvideosink->saturation = g_value_get_int (value);
2142 dfbvideosink->cb_changed = TRUE;
2143 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2145 case ARG_PIXEL_ASPECT_RATIO:
2146 g_free (dfbvideosink->par);
2147 dfbvideosink->par = g_new0 (GValue, 1);
2148 g_value_init (dfbvideosink->par, GST_TYPE_FRACTION);
2149 if (!g_value_transform (value, dfbvideosink->par)) {
2150 GST_WARNING_OBJECT (dfbvideosink, "Could not transform string to "
2152 gst_value_set_fraction (dfbvideosink->par, 1, 1);
2154 GST_DEBUG_OBJECT (dfbvideosink, "set PAR to %d/%d",
2155 gst_value_get_fraction_numerator (dfbvideosink->par),
2156 gst_value_get_fraction_denominator (dfbvideosink->par));
2159 dfbvideosink->vsync = g_value_get_boolean (value);
2162 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2168 gst_dfbvideosink_get_property (GObject * object, guint prop_id,
2169 GValue * value, GParamSpec * pspec)
2171 GstDfbVideoSink *dfbvideosink;
2173 g_return_if_fail (GST_IS_DFBVIDEOSINK (object));
2174 dfbvideosink = GST_DFBVIDEOSINK (object);
2178 g_value_set_int (value, dfbvideosink->hue);
2181 g_value_set_int (value, dfbvideosink->contrast);
2183 case ARG_BRIGHTNESS:
2184 g_value_set_int (value, dfbvideosink->brightness);
2186 case ARG_SATURATION:
2187 g_value_set_int (value, dfbvideosink->saturation);
2189 case ARG_PIXEL_ASPECT_RATIO:
2190 if (dfbvideosink->par)
2191 g_value_transform (dfbvideosink->par, value);
2194 g_value_set_boolean (value, dfbvideosink->vsync);
2197 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2202 /* =========================================== */
2204 /* Init & Class init */
2206 /* =========================================== */
2208 gst_dfbvideosink_finalize (GObject * object)
2210 GstDfbVideoSink *dfbvideosink;
2212 dfbvideosink = GST_DFBVIDEOSINK (object);
2214 if (dfbvideosink->par) {
2215 g_free (dfbvideosink->par);
2216 dfbvideosink->par = NULL;
2218 if (dfbvideosink->pool_lock) {
2219 g_mutex_free (dfbvideosink->pool_lock);
2220 dfbvideosink->pool_lock = NULL;
2222 if (dfbvideosink->setup) {
2223 gst_dfbvideosink_cleanup (dfbvideosink);
2226 G_OBJECT_CLASS (parent_class)->finalize (object);
2230 gst_dfbvideosink_init (GstDfbVideoSink * dfbvideosink)
2232 dfbvideosink->pool_lock = g_mutex_new ();
2233 dfbvideosink->buffer_pool = NULL;
2234 dfbvideosink->video_height = dfbvideosink->out_width = 0;
2235 dfbvideosink->video_width = dfbvideosink->out_height = 0;
2236 dfbvideosink->fps_d = 0;
2237 dfbvideosink->fps_n = 0;
2239 dfbvideosink->dfb = NULL;
2240 dfbvideosink->vmodes = NULL;
2241 dfbvideosink->layer_id = -1;
2242 dfbvideosink->layer = NULL;
2243 dfbvideosink->primary = NULL;
2244 dfbvideosink->event_buffer = NULL;
2245 dfbvideosink->event_thread = NULL;
2247 dfbvideosink->ext_surface = NULL;
2249 dfbvideosink->pixel_format = DSPF_UNKNOWN;
2251 dfbvideosink->hw_scaling = FALSE;
2252 dfbvideosink->backbuffer = FALSE;
2253 dfbvideosink->vsync = TRUE;
2254 dfbvideosink->setup = FALSE;
2255 dfbvideosink->running = FALSE;
2257 dfbvideosink->cb_channels = NULL;
2258 dfbvideosink->brightness = -1;
2259 dfbvideosink->contrast = -1;
2260 dfbvideosink->hue = -1;
2261 dfbvideosink->saturation = -1;
2263 dfbvideosink->par = NULL;
2267 gst_dfbvideosink_base_init (gpointer g_class)
2269 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
2271 gst_element_class_set_details_simple (element_class, "DirectFB video sink",
2273 "A DirectFB based videosink", "Julien Moutte <julien@moutte.net>");
2275 gst_element_class_add_pad_template (element_class,
2276 gst_static_pad_template_get (&gst_dfbvideosink_sink_template_factory));
2280 gst_dfbvideosink_class_init (GstDfbVideoSinkClass * klass)
2282 GObjectClass *gobject_class;
2283 GstElementClass *gstelement_class;
2284 GstBaseSinkClass *gstbasesink_class;
2286 gobject_class = (GObjectClass *) klass;
2287 gstelement_class = (GstElementClass *) klass;
2288 gstbasesink_class = (GstBaseSinkClass *) klass;
2290 parent_class = g_type_class_peek_parent (klass);
2292 gobject_class->finalize = gst_dfbvideosink_finalize;
2293 gobject_class->set_property = gst_dfbvideosink_set_property;
2294 gobject_class->get_property = gst_dfbvideosink_get_property;
2296 g_object_class_install_property (gobject_class, ARG_SURFACE,
2297 g_param_spec_pointer ("surface", "Surface",
2298 "The target surface for video", G_PARAM_WRITABLE));
2299 g_object_class_install_property (gobject_class, ARG_CONTRAST,
2300 g_param_spec_int ("contrast", "Contrast", "The contrast of the video",
2301 0x0000, 0xFFFF, 0x8000, G_PARAM_READWRITE));
2302 g_object_class_install_property (gobject_class, ARG_BRIGHTNESS,
2303 g_param_spec_int ("brightness", "Brightness",
2304 "The brightness of the video", 0x0000, 0xFFFF, 0x8000,
2305 G_PARAM_READWRITE));
2306 g_object_class_install_property (gobject_class, ARG_HUE,
2307 g_param_spec_int ("hue", "Hue", "The hue of the video", 0x0000, 0xFFFF,
2308 0x8000, G_PARAM_READWRITE));
2309 g_object_class_install_property (gobject_class, ARG_SATURATION,
2310 g_param_spec_int ("saturation", "Saturation",
2311 "The saturation of the video", 0x0000, 0xFFFF, 0x8000,
2312 G_PARAM_READWRITE));
2313 g_object_class_install_property (gobject_class, ARG_PIXEL_ASPECT_RATIO,
2314 g_param_spec_string ("pixel-aspect-ratio", "Pixel Aspect Ratio",
2315 "The pixel aspect ratio of the device", "1/1", G_PARAM_READWRITE));
2316 g_object_class_install_property (gobject_class, ARG_VSYNC,
2317 g_param_spec_boolean ("vsync", "Vertical synchronisation",
2318 "Wait for next vertical sync to draw frames", TRUE,
2319 G_PARAM_READWRITE));
2321 gstelement_class->change_state = gst_dfbvideosink_change_state;
2323 gstbasesink_class->get_caps = gst_dfbvideosink_getcaps;
2324 gstbasesink_class->set_caps = gst_dfbvideosink_setcaps;
2325 gstbasesink_class->buffer_alloc = gst_dfbvideosink_buffer_alloc;
2326 gstbasesink_class->get_times = gst_dfbvideosink_get_times;
2327 gstbasesink_class->preroll = gst_dfbvideosink_show_frame;
2328 gstbasesink_class->render = gst_dfbvideosink_show_frame;
2331 /* ============================================================= */
2333 /* Public Methods */
2335 /* ============================================================= */
2337 /* =========================================== */
2339 /* Object typing & Creation */
2341 /* =========================================== */
2344 gst_dfbvideosink_get_type (void)
2346 static GType dfbvideosink_type = 0;
2348 if (!dfbvideosink_type) {
2349 static const GTypeInfo dfbvideosink_info = {
2350 sizeof (GstDfbVideoSinkClass),
2351 gst_dfbvideosink_base_init,
2353 (GClassInitFunc) gst_dfbvideosink_class_init,
2356 sizeof (GstDfbVideoSink),
2358 (GInstanceInitFunc) gst_dfbvideosink_init,
2360 static const GInterfaceInfo iface_info = {
2361 (GInterfaceInitFunc) gst_dfbvideosink_interface_init,
2365 static const GInterfaceInfo navigation_info = {
2366 (GInterfaceInitFunc) gst_dfbvideosink_navigation_init,
2370 static const GInterfaceInfo colorbalance_info = {
2371 (GInterfaceInitFunc) gst_dfbvideosink_colorbalance_init,
2376 dfbvideosink_type = g_type_register_static (GST_TYPE_VIDEO_SINK,
2377 "GstDfbVideoSink", &dfbvideosink_info, 0);
2379 g_type_add_interface_static (dfbvideosink_type,
2380 GST_TYPE_IMPLEMENTS_INTERFACE, &iface_info);
2381 g_type_add_interface_static (dfbvideosink_type, GST_TYPE_NAVIGATION,
2383 g_type_add_interface_static (dfbvideosink_type, GST_TYPE_COLOR_BALANCE,
2384 &colorbalance_info);
2387 return dfbvideosink_type;
2391 plugin_init (GstPlugin * plugin)
2393 if (!gst_element_register (plugin, "dfbvideosink", GST_RANK_MARGINAL,
2394 GST_TYPE_DFBVIDEOSINK))
2397 GST_DEBUG_CATEGORY_INIT (dfbvideosink_debug, "dfbvideosink", 0,
2398 "DirectFB video sink element");
2403 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
2406 "DirectFB video output plugin",
2407 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)