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, gboolean accelerated)
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) && accelerated) {
1062 GST_DEBUG_OBJECT (dfbvideosink, "blitting from format %s to our primary "
1063 "is accelerated", gst_dfbvideosink_get_format_name (format));
1065 } else if (!accelerated) {
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 gboolean accelerated = TRUE;
1169 caps = gst_caps_new_empty ();
1172 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_RGB16,
1174 gst_caps_append (caps,
1175 gst_dfbvideosink_get_caps_from_format (DSPF_RGB16));
1177 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_RGB24,
1179 gst_caps_append (caps,
1180 gst_dfbvideosink_get_caps_from_format (DSPF_RGB24));
1182 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_RGB32,
1184 gst_caps_append (caps,
1185 gst_dfbvideosink_get_caps_from_format (DSPF_RGB32));
1187 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_ARGB,
1189 gst_caps_append (caps,
1190 gst_dfbvideosink_get_caps_from_format (DSPF_ARGB));
1192 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_YUY2,
1194 gst_caps_append (caps,
1195 gst_dfbvideosink_get_caps_from_format (DSPF_YUY2));
1197 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_UYVY,
1199 gst_caps_append (caps,
1200 gst_dfbvideosink_get_caps_from_format (DSPF_UYVY));
1202 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_I420,
1204 gst_caps_append (caps,
1205 gst_dfbvideosink_get_caps_from_format (DSPF_I420));
1207 if (gst_dfbvideosink_can_blit_from_format (dfbvideosink, DSPF_YV12,
1209 gst_caps_append (caps,
1210 gst_dfbvideosink_get_caps_from_format (DSPF_YV12));
1212 accelerated = !accelerated;
1213 } while (accelerated == FALSE);
1217 for (i = 0; i < gst_caps_get_size (caps); i++) {
1218 GstStructure *structure = gst_caps_get_structure (caps, i);
1220 gst_structure_set (structure,
1221 "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
1222 "height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
1223 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
1225 if (!dfbvideosink->hw_scaling && dfbvideosink->par) {
1228 nom = gst_value_get_fraction_numerator (dfbvideosink->par);
1229 den = gst_value_get_fraction_denominator (dfbvideosink->par);
1230 gst_structure_set (structure, "pixel-aspect-ratio",
1231 GST_TYPE_FRACTION, nom, den, NULL);
1235 GST_DEBUG_OBJECT (dfbvideosink, "returning our caps %" GST_PTR_FORMAT, caps);
1242 gst_dfbvideosink_setcaps (GstBaseSink * bsink, GstCaps * caps)
1244 GstDfbVideoSink *dfbvideosink;
1245 GstStructure *structure;
1246 gboolean res, result = FALSE;
1247 gint video_width, video_height;
1248 const GValue *framerate;
1249 DFBSurfacePixelFormat pixel_format = DSPF_UNKNOWN;
1251 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1253 structure = gst_caps_get_structure (caps, 0);
1254 res = gst_structure_get_int (structure, "width", &video_width);
1255 res &= gst_structure_get_int (structure, "height", &video_height);
1256 framerate = gst_structure_get_value (structure, "framerate");
1257 res &= (framerate != NULL);
1262 dfbvideosink->fps_n = gst_value_get_fraction_numerator (framerate);
1263 dfbvideosink->fps_d = gst_value_get_fraction_denominator (framerate);
1265 pixel_format = gst_dfbvideosink_get_format_from_caps (caps);
1267 GST_DEBUG_OBJECT (dfbvideosink, "setcaps called with %" GST_PTR_FORMAT, caps);
1268 GST_DEBUG_OBJECT (dfbvideosink, "our format is: %dx%d %s video at %d/%d fps",
1269 video_width, video_height,
1270 gst_dfbvideosink_get_format_name (pixel_format), dfbvideosink->fps_n,
1271 dfbvideosink->fps_d);
1273 if (dfbvideosink->hw_scaling && dfbvideosink->par) {
1274 gint video_par_n, video_par_d; /* video's PAR */
1275 gint display_par_n, display_par_d; /* display's PAR */
1277 GValue display_ratio = { 0, }; /* display w/h ratio */
1278 const GValue *caps_par;
1280 /* get aspect ratio from caps if it's present, and
1281 * convert video width and height to a display width and height
1282 * using wd / hd = wv / hv * PARv / PARd
1283 * the ratio wd / hd will be stored in display_ratio */
1284 g_value_init (&display_ratio, GST_TYPE_FRACTION);
1286 /* get video's PAR */
1287 caps_par = gst_structure_get_value (structure, "pixel-aspect-ratio");
1289 video_par_n = gst_value_get_fraction_numerator (caps_par);
1290 video_par_d = gst_value_get_fraction_denominator (caps_par);
1295 /* get display's PAR */
1296 if (dfbvideosink->par) {
1297 display_par_n = gst_value_get_fraction_numerator (dfbvideosink->par);
1298 display_par_d = gst_value_get_fraction_denominator (dfbvideosink->par);
1304 gst_value_set_fraction (&display_ratio,
1305 video_width * video_par_n * display_par_d,
1306 video_height * video_par_d * display_par_n);
1308 num = gst_value_get_fraction_numerator (&display_ratio);
1309 den = gst_value_get_fraction_denominator (&display_ratio);
1310 GST_DEBUG_OBJECT (dfbvideosink,
1311 "video width/height: %dx%d, calculated display ratio: %d/%d",
1312 video_width, video_height, num, den);
1314 /* now find a width x height that respects this display ratio.
1315 * prefer those that have one of w/h the same as the incoming video
1316 * using wd / hd = num / den */
1318 /* start with same height, because of interlaced video */
1319 /* check hd / den is an integer scale factor, and scale wd with the PAR */
1320 if (video_height % den == 0) {
1321 GST_DEBUG_OBJECT (dfbvideosink, "keeping video height");
1322 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_height * num / den;
1323 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_height;
1324 } else if (video_width % num == 0) {
1325 GST_DEBUG_OBJECT (dfbvideosink, "keeping video width");
1326 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_width;
1327 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_width * den / num;
1329 GST_DEBUG_OBJECT (dfbvideosink, "approximating while keeping height");
1330 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_height * num / den;
1331 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_height;
1333 GST_DEBUG_OBJECT (dfbvideosink, "scaling to %dx%d",
1334 GST_VIDEO_SINK_WIDTH (dfbvideosink),
1335 GST_VIDEO_SINK_HEIGHT (dfbvideosink));
1337 if (dfbvideosink->par) {
1340 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
1342 if (gst_value_compare (par, dfbvideosink->par) != GST_VALUE_EQUAL) {
1347 GST_VIDEO_SINK_WIDTH (dfbvideosink) = video_width;
1348 GST_VIDEO_SINK_HEIGHT (dfbvideosink) = video_height;
1351 /* Try to adapt the video mode to the video geometry */
1352 if (dfbvideosink->dfb) {
1356 GST_DEBUG_OBJECT (dfbvideosink, "trying to adapt the video mode to video "
1359 /* Set video mode and layer configuration appropriately */
1360 if (gst_dfbvideosink_get_best_vmode (dfbvideosink,
1361 GST_VIDEO_SINK_WIDTH (dfbvideosink),
1362 GST_VIDEO_SINK_HEIGHT (dfbvideosink), &vmode)) {
1363 DFBDisplayLayerConfig lc;
1364 gint width, height, bpp;
1366 width = vmode.width;
1367 height = vmode.height;
1370 GST_DEBUG_OBJECT (dfbvideosink, "setting video mode to %dx%d at %d bpp",
1371 width, height, bpp);
1373 ret = dfbvideosink->dfb->SetVideoMode (dfbvideosink->dfb, width,
1375 if (ret != DFB_OK) {
1376 GST_WARNING_OBJECT (dfbvideosink, "failed setting video mode %dx%d "
1377 "at %d bpp", width, height, bpp);
1380 lc.flags = DLCONF_PIXELFORMAT;
1381 lc.pixelformat = pixel_format;
1383 ret = dfbvideosink->layer->SetConfiguration (dfbvideosink->layer, &lc);
1384 if (ret != DFB_OK) {
1385 GST_WARNING_OBJECT (dfbvideosink, "failed setting layer pixelformat "
1386 "to %s", gst_dfbvideosink_get_format_name (pixel_format));
1388 dfbvideosink->layer->GetConfiguration (dfbvideosink->layer, &lc);
1389 dfbvideosink->out_width = lc.width;
1390 dfbvideosink->out_height = lc.height;
1391 dfbvideosink->pixel_format = lc.pixelformat;
1392 GST_DEBUG_OBJECT (dfbvideosink, "layer %d now configured to %dx%d %s",
1393 dfbvideosink->layer_id, lc.width, lc.height,
1394 gst_dfbvideosink_get_format_name (lc.pixelformat));
1399 if (pixel_format != dfbvideosink->pixel_format) {
1400 GST_WARNING_OBJECT (dfbvideosink, "setcaps sent us a different pixel "
1401 "format %s", gst_dfbvideosink_get_format_name (pixel_format));
1405 dfbvideosink->video_width = video_width;
1406 dfbvideosink->video_height = video_height;
1416 GST_INFO_OBJECT (dfbvideosink, "pixel aspect ratio does not match");
1421 static GstStateChangeReturn
1422 gst_dfbvideosink_change_state (GstElement * element, GstStateChange transition)
1424 GstDfbVideoSink *dfbvideosink;
1425 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1427 dfbvideosink = GST_DFBVIDEOSINK (element);
1429 switch (transition) {
1430 case GST_STATE_CHANGE_NULL_TO_READY:
1431 dfbvideosink->running = TRUE;
1432 if (!dfbvideosink->setup) {
1433 if (!gst_dfbvideosink_setup (dfbvideosink)) {
1434 GST_DEBUG_OBJECT (dfbvideosink, "setup failed when changing state "
1435 "from NULL to READY");
1436 GST_ELEMENT_ERROR (dfbvideosink, RESOURCE, OPEN_WRITE,
1437 (NULL), ("Failed initializing DirectFB system"));
1438 return GST_STATE_CHANGE_FAILURE;
1442 case GST_STATE_CHANGE_READY_TO_PAUSED:
1443 /* Blank surface if we have one */
1444 if (dfbvideosink->ext_surface) {
1445 dfbvideosink->ext_surface->Clear (dfbvideosink->ext_surface,
1446 0x00, 0x00, 0x00, 0xFF);
1448 if (dfbvideosink->primary) {
1449 dfbvideosink->primary->Clear (dfbvideosink->primary, 0x00, 0x00,
1453 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1459 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1460 if (ret == GST_STATE_CHANGE_FAILURE)
1463 switch (transition) {
1464 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1466 case GST_STATE_CHANGE_PAUSED_TO_READY:
1467 dfbvideosink->fps_d = 0;
1468 dfbvideosink->fps_n = 0;
1469 dfbvideosink->video_width = 0;
1470 dfbvideosink->video_height = 0;
1472 if (dfbvideosink->buffer_pool) {
1473 gst_dfbvideosink_bufferpool_clear (dfbvideosink);
1476 case GST_STATE_CHANGE_READY_TO_NULL:
1477 dfbvideosink->running = FALSE;
1478 if (dfbvideosink->setup) {
1479 gst_dfbvideosink_cleanup (dfbvideosink);
1490 gst_dfbvideosink_get_times (GstBaseSink * bsink, GstBuffer * buf,
1491 GstClockTime * start, GstClockTime * end)
1493 GstDfbVideoSink *dfbvideosink;
1495 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1497 if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
1498 *start = GST_BUFFER_TIMESTAMP (buf);
1499 if (GST_BUFFER_DURATION_IS_VALID (buf)) {
1500 *end = *start + GST_BUFFER_DURATION (buf);
1502 if (dfbvideosink->fps_n > 0) {
1504 *start + (GST_SECOND * dfbvideosink->fps_d) / dfbvideosink->fps_n;
1510 static GstFlowReturn
1511 gst_dfbvideosink_show_frame (GstBaseSink * bsink, GstBuffer * buf)
1513 GstDfbVideoSink *dfbvideosink = NULL;
1515 GstVideoRectangle dst, src, result;
1516 GstFlowReturn ret = GST_FLOW_OK;
1517 gboolean mem_cpy = TRUE;
1519 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1521 if (!dfbvideosink->setup) {
1522 ret = GST_FLOW_UNEXPECTED;
1526 /* Is that a buffer we allocated ourselves ? */
1527 if (GST_IS_DFBSURFACE (buf)) {
1528 GstDfbSurface *tmp_surface = GST_DFBSURFACE (buf);
1530 /* Does it have a surface ? */
1531 if (tmp_surface->surface) {
1533 GST_DEBUG_OBJECT (dfbvideosink, "we have a buffer (%p) we allocated "
1534 "ourselves and it has a surface, no memcpy then", buf);
1536 /* No surface, that's a malloc */
1537 GST_DEBUG_OBJECT (dfbvideosink, "we have a buffer (%p) we allocated "
1538 "ourselves but it does not hold a surface", buf);
1542 GST_DEBUG_OBJECT (dfbvideosink, "we have a buffer (%p) we did not allocate",
1547 IDirectFBSurface *dest = NULL, *surface = NULL;
1549 gint dest_pitch, src_pitch, line;
1550 GstStructure *structure;
1552 /* As we are not blitting no acceleration is possible. If the surface is
1553 * too small we do clipping, if it's too big we center. Theoretically as
1554 * we are using buffer_alloc, there's a chance that we have been able to
1555 * do reverse caps negotiation */
1557 if (dfbvideosink->ext_surface) {
1558 surface = dfbvideosink->ext_surface;
1559 GST_DEBUG_OBJECT (dfbvideosink, "memcpy to an external surface "
1560 "subsurface (vsync %d)", dfbvideosink->vsync);
1562 surface = dfbvideosink->primary;
1563 GST_DEBUG_OBJECT (dfbvideosink, "memcpy to a primary subsurface "
1564 "(vsync %d)", dfbvideosink->vsync);
1567 /* Get the video frame geometry from the buffer caps */
1568 structure = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0);
1570 gst_structure_get_int (structure, "width", &src.w);
1571 gst_structure_get_int (structure, "height", &src.h);
1573 src.w = dfbvideosink->video_width;
1574 src.h = dfbvideosink->video_height;
1576 res = surface->GetSize (surface, &dst.w, &dst.h);
1579 gst_video_sink_center_rect (src, dst, &result, FALSE);
1582 surface->GetSubSurface (surface, (DFBRectangle *) (void *) &result,
1584 if (res != DFB_OK) {
1585 GST_WARNING_OBJECT (dfbvideosink, "failed when getting a sub surface");
1586 ret = GST_FLOW_UNEXPECTED;
1590 /* If we are not using Flip we wait for VSYNC before blit */
1591 if (!dfbvideosink->backbuffer && dfbvideosink->vsync) {
1592 dfbvideosink->layer->WaitForSync (dfbvideosink->layer);
1595 res = dest->Lock (dest, DSLF_WRITE, (void *) &data, &dest_pitch);
1596 if (res != DFB_OK) {
1597 GST_WARNING_OBJECT (dfbvideosink, "failed locking the external "
1598 "subsurface for writing");
1599 ret = GST_FLOW_ERROR;
1603 /* Source video rowbytes */
1604 src_pitch = GST_BUFFER_SIZE (buf) / src.h;
1606 /* Write each line respecting subsurface pitch */
1607 for (line = 0; line < result.h; line++) {
1608 /* We do clipping */
1609 memcpy (data, GST_BUFFER_DATA (buf) + (line * src_pitch),
1610 MIN (src_pitch, dest_pitch));
1614 res = dest->Unlock (dest);
1616 dest->Release (dest);
1618 if (dfbvideosink->backbuffer) {
1619 if (dfbvideosink->vsync) {
1620 res = surface->Flip (surface, NULL, DSFLIP_ONSYNC);
1622 res = surface->Flip (surface, NULL, DSFLIP_NONE);
1626 /* Else we will [Stretch]Blit to our primary */
1627 GstDfbSurface *surface = GST_DFBSURFACE (buf);
1629 GST_DEBUG_OBJECT (dfbvideosink, "blitting to a primary surface (vsync %d)",
1630 dfbvideosink->vsync);
1632 src.w = GST_VIDEO_SINK_WIDTH (dfbvideosink);
1633 src.h = GST_VIDEO_SINK_HEIGHT (dfbvideosink);
1635 dfbvideosink->primary->GetSize (dfbvideosink->primary, &dst.w, &dst.h);
1637 /* Unlocking surface before blit */
1638 if (surface->locked) {
1639 surface->surface->Unlock (surface->surface);
1640 surface->locked = FALSE;
1643 gst_video_sink_center_rect (src, dst, &result, dfbvideosink->hw_scaling);
1645 /* If we are not using Flip we wait for VSYNC before blit */
1646 if (!dfbvideosink->backbuffer && dfbvideosink->vsync) {
1647 dfbvideosink->layer->WaitForSync (dfbvideosink->layer);
1650 if (dfbvideosink->hw_scaling) {
1651 dfbvideosink->primary->StretchBlit (dfbvideosink->primary,
1652 surface->surface, NULL, (DFBRectangle *) (void *) &result);
1656 clip.x = clip.y = 0;
1659 dfbvideosink->primary->Blit (dfbvideosink->primary, surface->surface,
1660 &clip, result.x, result.y);
1663 if (dfbvideosink->backbuffer) {
1664 if (dfbvideosink->vsync) {
1665 dfbvideosink->primary->Flip (dfbvideosink->primary, NULL,
1668 dfbvideosink->primary->Flip (dfbvideosink->primary, NULL, DSFLIP_NONE);
1678 gst_dfbvideosink_bufferpool_clear (GstDfbVideoSink * dfbvideosink)
1680 g_mutex_lock (dfbvideosink->pool_lock);
1681 while (dfbvideosink->buffer_pool) {
1682 GstDfbSurface *surface = dfbvideosink->buffer_pool->data;
1684 dfbvideosink->buffer_pool = g_slist_delete_link (dfbvideosink->buffer_pool,
1685 dfbvideosink->buffer_pool);
1686 gst_dfbvideosink_surface_destroy (dfbvideosink, surface);
1688 g_mutex_unlock (dfbvideosink->pool_lock);
1691 /* For every buffer request we create a custom buffer containing and
1692 * IDirectFBSurface or allocate a previously created one that's not used
1694 static GstFlowReturn
1695 gst_dfbvideosink_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size,
1696 GstCaps * caps, GstBuffer ** buf)
1698 GstDfbVideoSink *dfbvideosink;
1699 GstDfbSurface *surface = NULL;
1700 GstFlowReturn ret = GST_FLOW_OK;
1702 gboolean rev_nego = FALSE;
1705 GstCaps *desired_caps = NULL;
1706 GstStructure *structure = NULL;
1708 dfbvideosink = GST_DFBVIDEOSINK (bsink);
1710 GST_LOG_OBJECT (dfbvideosink, "a buffer of %u bytes was requested with caps "
1711 "%" GST_PTR_FORMAT " and offset %" G_GUINT64_FORMAT, size, caps, offset);
1713 if (G_UNLIKELY (!dfbvideosink->setup)) {
1714 GST_DEBUG_OBJECT (dfbvideosink, "we are not setup yet, can't allocate!");
1719 desired_caps = gst_caps_copy (caps);
1721 structure = gst_caps_get_structure (desired_caps, 0);
1723 if (gst_structure_get_int (structure, "width", &width) &&
1724 gst_structure_get_int (structure, "height", &height)) {
1725 GstVideoRectangle dst, src, result;
1728 /* If we can do hardware scaling we don't do reverse negotiation */
1729 if (dfbvideosink->hw_scaling) {
1733 /* Our desired geometry respects aspect ratio */
1736 /* We should adapt the destination to the most suitable video mode */
1737 if (gst_dfbvideosink_get_best_vmode (dfbvideosink, width, height, &vmode)) {
1738 dst.w = vmode.width;
1739 dst.h = vmode.height;
1741 if (dfbvideosink->ext_surface) {
1742 dfbvideosink->ext_surface->GetSize (dfbvideosink->ext_surface, &dst.w,
1745 dfbvideosink->primary->GetSize (dfbvideosink->primary, &dst.w, &dst.h);
1747 dfbvideosink->out_width = dst.w;
1748 dfbvideosink->out_height = dst.h;
1751 gst_video_sink_center_rect (src, dst, &result, TRUE);
1753 if (width != result.w || height != result.h) {
1754 GstPad *peer = gst_pad_get_peer (GST_VIDEO_SINK_PAD (dfbvideosink));
1756 if (!GST_IS_PAD (peer)) {
1757 /* Is this situation possible ? */
1761 GST_DEBUG_OBJECT (dfbvideosink, "we would love to receive a %dx%d video",
1762 result.w, result.h);
1763 gst_structure_set (structure, "width", G_TYPE_INT, result.w, NULL);
1764 gst_structure_set (structure, "height", G_TYPE_INT, result.h, NULL);
1766 /* PAR property overrides the X calculated one */
1767 if (dfbvideosink->par) {
1770 nom = gst_value_get_fraction_numerator (dfbvideosink->par);
1771 den = gst_value_get_fraction_denominator (dfbvideosink->par);
1772 gst_structure_set (structure, "pixel-aspect-ratio",
1773 GST_TYPE_FRACTION, nom, den, NULL);
1776 if (gst_pad_accept_caps (peer, desired_caps)) {
1779 bpp = size / height / width;
1783 size = bpp * width * height;
1784 GST_DEBUG_OBJECT (dfbvideosink, "peed pad accepts our desired caps %"
1785 GST_PTR_FORMAT " buffer size is now %d bytes", desired_caps, size);
1787 GST_DEBUG_OBJECT (dfbvideosink, "peer pad does not accept our "
1788 "desired caps %" GST_PTR_FORMAT, desired_caps);
1790 width = dfbvideosink->video_width;
1791 height = dfbvideosink->video_height;
1793 gst_object_unref (peer);
1798 /* Inspect our buffer pool */
1799 g_mutex_lock (dfbvideosink->pool_lock);
1800 while (dfbvideosink->buffer_pool) {
1801 surface = (GstDfbSurface *) dfbvideosink->buffer_pool->data;
1804 /* Removing from the pool */
1805 dfbvideosink->buffer_pool =
1806 g_slist_delete_link (dfbvideosink->buffer_pool,
1807 dfbvideosink->buffer_pool);
1809 /* If the surface is invalid for our need, destroy */
1810 if ((surface->width != width) ||
1811 (surface->height != height) ||
1812 (surface->pixel_format != dfbvideosink->pixel_format)) {
1813 gst_dfbvideosink_surface_destroy (dfbvideosink, surface);
1816 /* We found a suitable surface */
1821 g_mutex_unlock (dfbvideosink->pool_lock);
1823 /* We haven't found anything, creating a new one */
1826 surface = gst_dfbvideosink_surface_create (dfbvideosink, desired_caps,
1829 surface = gst_dfbvideosink_surface_create (dfbvideosink, caps, size);
1832 /* Now we should have a surface, set appropriate caps on it */
1835 gst_buffer_set_caps (GST_BUFFER (surface), desired_caps);
1837 gst_buffer_set_caps (GST_BUFFER (surface), caps);
1841 *buf = GST_BUFFER (surface);
1843 gst_caps_unref (desired_caps);
1848 /* Our subclass of GstBuffer */
1851 gst_dfbsurface_finalize (GstDfbSurface * surface)
1853 GstDfbVideoSink *dfbvideosink = NULL;
1855 g_return_if_fail (surface != NULL);
1857 dfbvideosink = surface->dfbvideosink;
1858 if (!dfbvideosink) {
1859 GST_WARNING_OBJECT (surface, "no sink found");
1863 /* If our geometry changed we can't reuse that image. */
1864 if ((surface->width != dfbvideosink->video_width) ||
1865 (surface->height != dfbvideosink->video_height) ||
1866 (surface->pixel_format != dfbvideosink->pixel_format)) {
1867 GST_DEBUG_OBJECT (dfbvideosink, "destroy surface %p as its size changed "
1868 "%dx%d vs current %dx%d", surface, surface->width, surface->height,
1869 dfbvideosink->video_width, dfbvideosink->video_height);
1870 gst_dfbvideosink_surface_destroy (dfbvideosink, surface);
1872 /* In that case we can reuse the image and add it to our image pool. */
1873 GST_DEBUG_OBJECT (dfbvideosink, "recycling surface %p in pool", surface);
1874 /* need to increment the refcount again to recycle */
1875 gst_buffer_ref (GST_BUFFER (surface));
1876 g_mutex_lock (dfbvideosink->pool_lock);
1877 dfbvideosink->buffer_pool = g_slist_prepend (dfbvideosink->buffer_pool,
1879 g_mutex_unlock (dfbvideosink->pool_lock);
1887 gst_dfbsurface_init (GstDfbSurface * surface, gpointer g_class)
1889 surface->surface = NULL;
1891 surface->height = 0;
1892 surface->pixel_format = DSPF_UNKNOWN;
1893 surface->dfbvideosink = NULL;
1897 gst_dfbsurface_class_init (gpointer g_class, gpointer class_data)
1899 GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class);
1901 surface_parent_class = g_type_class_peek_parent (g_class);
1903 mini_object_class->finalize = (GstMiniObjectFinalizeFunction)
1904 gst_dfbsurface_finalize;
1908 gst_dfbsurface_get_type (void)
1910 static GType _gst_dfbsurface_type;
1912 if (G_UNLIKELY (_gst_dfbsurface_type == 0)) {
1913 static const GTypeInfo dfbsurface_info = {
1914 sizeof (GstBufferClass),
1917 gst_dfbsurface_class_init,
1920 sizeof (GstDfbSurface),
1922 (GInstanceInitFunc) gst_dfbsurface_init,
1925 _gst_dfbsurface_type = g_type_register_static (GST_TYPE_BUFFER,
1926 "GstDfbSurface", &dfbsurface_info, 0);
1928 return _gst_dfbsurface_type;
1931 /* Interfaces stuff */
1934 gst_dfbvideosink_interface_supported (GstImplementsInterface * iface,
1937 g_assert (type == GST_TYPE_NAVIGATION || type == GST_TYPE_COLOR_BALANCE);
1942 gst_dfbvideosink_interface_init (GstImplementsInterfaceClass * klass)
1944 klass->supported = gst_dfbvideosink_interface_supported;
1948 gst_dfbvideosink_navigation_send_event (GstNavigation * navigation,
1949 GstStructure * structure)
1951 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (navigation);
1953 GstVideoRectangle src, dst, result;
1954 double x, y, old_x, old_y;
1957 src.w = GST_VIDEO_SINK_WIDTH (dfbvideosink);
1958 src.h = GST_VIDEO_SINK_HEIGHT (dfbvideosink);
1959 dst.w = dfbvideosink->out_width;
1960 dst.h = dfbvideosink->out_height;
1961 gst_video_sink_center_rect (src, dst, &result, dfbvideosink->hw_scaling);
1963 event = gst_event_new_navigation (structure);
1965 /* Our coordinates can be wrong here if we centered the video */
1967 /* Converting pointer coordinates to the non scaled geometry */
1968 if (gst_structure_get_double (structure, "pointer_x", &old_x)) {
1971 if (x >= result.x && x <= (result.x + result.w)) {
1973 x *= dfbvideosink->video_width;
1978 GST_DEBUG_OBJECT (dfbvideosink, "translated navigation event x "
1979 "coordinate from %f to %f", old_x, x);
1980 gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE, x, NULL);
1982 if (gst_structure_get_double (structure, "pointer_y", &old_y)) {
1985 if (y >= result.y && y <= (result.y + result.h)) {
1987 y *= dfbvideosink->video_height;
1992 GST_DEBUG_OBJECT (dfbvideosink, "translated navigation event y "
1993 "coordinate from %fd to %fd", old_y, y);
1994 gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE, y, NULL);
1997 pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (dfbvideosink));
1999 if (GST_IS_PAD (pad) && GST_IS_EVENT (event)) {
2000 gst_pad_send_event (pad, event);
2002 gst_object_unref (pad);
2007 gst_dfbvideosink_navigation_init (GstNavigationInterface * iface)
2009 iface->send_event = gst_dfbvideosink_navigation_send_event;
2013 gst_dfbvideosink_update_colorbalance (GstDfbVideoSink * dfbvideosink)
2015 g_return_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink));
2017 if (dfbvideosink->layer) {
2018 DFBColorAdjustment cb_adjust;
2020 cb_adjust.flags = DCAF_NONE;
2022 if (dfbvideosink->brightness >= 0) {
2023 cb_adjust.flags |= DCAF_BRIGHTNESS;
2025 if (dfbvideosink->contrast >= 0) {
2026 cb_adjust.flags |= DCAF_CONTRAST;
2028 if (dfbvideosink->hue >= 0) {
2029 cb_adjust.flags |= DCAF_HUE;
2031 if (dfbvideosink->saturation >= 0) {
2032 cb_adjust.flags |= DCAF_SATURATION;
2035 cb_adjust.brightness = dfbvideosink->brightness;
2036 cb_adjust.contrast = dfbvideosink->contrast;
2037 cb_adjust.hue = dfbvideosink->hue;
2038 cb_adjust.saturation = dfbvideosink->saturation;
2040 GST_DEBUG_OBJECT (dfbvideosink, "updating colorbalance: flags %d "
2041 "brightness %d contrast %d hue %d saturation %d", cb_adjust.flags,
2042 cb_adjust.brightness, cb_adjust.contrast, cb_adjust.hue,
2043 cb_adjust.saturation);
2044 dfbvideosink->layer->SetColorAdjustment (dfbvideosink->layer, &cb_adjust);
2048 static const GList *
2049 gst_dfbvideosink_colorbalance_list_channels (GstColorBalance * balance)
2051 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (balance);
2053 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), NULL);
2055 return dfbvideosink->cb_channels;
2059 gst_dfbvideosink_colorbalance_set_value (GstColorBalance * balance,
2060 GstColorBalanceChannel * channel, gint value)
2062 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (balance);
2064 g_return_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink));
2065 g_return_if_fail (channel->label != NULL);
2067 dfbvideosink->cb_changed = TRUE;
2069 if (g_ascii_strcasecmp (channel->label, "HUE") == 0) {
2070 dfbvideosink->hue = value;
2071 } else if (g_ascii_strcasecmp (channel->label, "SATURATION") == 0) {
2072 dfbvideosink->saturation = value;
2073 } else if (g_ascii_strcasecmp (channel->label, "CONTRAST") == 0) {
2074 dfbvideosink->contrast = value;
2075 } else if (g_ascii_strcasecmp (channel->label, "BRIGHTNESS") == 0) {
2076 dfbvideosink->brightness = value;
2078 GST_WARNING_OBJECT (dfbvideosink, "got an unknown channel %s",
2083 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2087 gst_dfbvideosink_colorbalance_get_value (GstColorBalance * balance,
2088 GstColorBalanceChannel * channel)
2090 GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (balance);
2093 g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), 0);
2094 g_return_val_if_fail (channel->label != NULL, 0);
2096 if (g_ascii_strcasecmp (channel->label, "HUE") == 0) {
2097 value = dfbvideosink->hue;
2098 } else if (g_ascii_strcasecmp (channel->label, "SATURATION") == 0) {
2099 value = dfbvideosink->saturation;
2100 } else if (g_ascii_strcasecmp (channel->label, "CONTRAST") == 0) {
2101 value = dfbvideosink->contrast;
2102 } else if (g_ascii_strcasecmp (channel->label, "BRIGHTNESS") == 0) {
2103 value = dfbvideosink->brightness;
2105 GST_WARNING_OBJECT (dfbvideosink, "got an unknown channel %s",
2113 gst_dfbvideosink_colorbalance_init (GstColorBalanceClass * iface)
2115 GST_COLOR_BALANCE_TYPE (iface) = GST_COLOR_BALANCE_HARDWARE;
2116 iface->list_channels = gst_dfbvideosink_colorbalance_list_channels;
2117 iface->set_value = gst_dfbvideosink_colorbalance_set_value;
2118 iface->get_value = gst_dfbvideosink_colorbalance_get_value;
2124 gst_dfbvideosink_set_property (GObject * object, guint prop_id,
2125 const GValue * value, GParamSpec * pspec)
2127 GstDfbVideoSink *dfbvideosink;
2129 g_return_if_fail (GST_IS_DFBVIDEOSINK (object));
2130 dfbvideosink = GST_DFBVIDEOSINK (object);
2134 dfbvideosink->ext_surface = g_value_get_pointer (value);
2137 dfbvideosink->hue = g_value_get_int (value);
2138 dfbvideosink->cb_changed = TRUE;
2139 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2142 dfbvideosink->contrast = g_value_get_int (value);
2143 dfbvideosink->cb_changed = TRUE;
2144 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2146 case ARG_BRIGHTNESS:
2147 dfbvideosink->brightness = g_value_get_int (value);
2148 dfbvideosink->cb_changed = TRUE;
2149 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2151 case ARG_SATURATION:
2152 dfbvideosink->saturation = g_value_get_int (value);
2153 dfbvideosink->cb_changed = TRUE;
2154 gst_dfbvideosink_update_colorbalance (dfbvideosink);
2156 case ARG_PIXEL_ASPECT_RATIO:
2157 g_free (dfbvideosink->par);
2158 dfbvideosink->par = g_new0 (GValue, 1);
2159 g_value_init (dfbvideosink->par, GST_TYPE_FRACTION);
2160 if (!g_value_transform (value, dfbvideosink->par)) {
2161 GST_WARNING_OBJECT (dfbvideosink, "Could not transform string to "
2163 gst_value_set_fraction (dfbvideosink->par, 1, 1);
2165 GST_DEBUG_OBJECT (dfbvideosink, "set PAR to %d/%d",
2166 gst_value_get_fraction_numerator (dfbvideosink->par),
2167 gst_value_get_fraction_denominator (dfbvideosink->par));
2170 dfbvideosink->vsync = g_value_get_boolean (value);
2173 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2179 gst_dfbvideosink_get_property (GObject * object, guint prop_id,
2180 GValue * value, GParamSpec * pspec)
2182 GstDfbVideoSink *dfbvideosink;
2184 g_return_if_fail (GST_IS_DFBVIDEOSINK (object));
2185 dfbvideosink = GST_DFBVIDEOSINK (object);
2189 g_value_set_int (value, dfbvideosink->hue);
2192 g_value_set_int (value, dfbvideosink->contrast);
2194 case ARG_BRIGHTNESS:
2195 g_value_set_int (value, dfbvideosink->brightness);
2197 case ARG_SATURATION:
2198 g_value_set_int (value, dfbvideosink->saturation);
2200 case ARG_PIXEL_ASPECT_RATIO:
2201 if (dfbvideosink->par)
2202 g_value_transform (dfbvideosink->par, value);
2205 g_value_set_boolean (value, dfbvideosink->vsync);
2208 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2213 /* =========================================== */
2215 /* Init & Class init */
2217 /* =========================================== */
2219 gst_dfbvideosink_finalize (GObject * object)
2221 GstDfbVideoSink *dfbvideosink;
2223 dfbvideosink = GST_DFBVIDEOSINK (object);
2225 if (dfbvideosink->par) {
2226 g_free (dfbvideosink->par);
2227 dfbvideosink->par = NULL;
2229 if (dfbvideosink->pool_lock) {
2230 g_mutex_free (dfbvideosink->pool_lock);
2231 dfbvideosink->pool_lock = NULL;
2233 if (dfbvideosink->setup) {
2234 gst_dfbvideosink_cleanup (dfbvideosink);
2237 G_OBJECT_CLASS (parent_class)->finalize (object);
2241 gst_dfbvideosink_init (GstDfbVideoSink * dfbvideosink)
2243 dfbvideosink->pool_lock = g_mutex_new ();
2244 dfbvideosink->buffer_pool = NULL;
2245 dfbvideosink->video_height = dfbvideosink->out_height = 0;
2246 dfbvideosink->video_width = dfbvideosink->out_width = 0;
2247 dfbvideosink->fps_d = 0;
2248 dfbvideosink->fps_n = 0;
2250 dfbvideosink->dfb = NULL;
2251 dfbvideosink->vmodes = NULL;
2252 dfbvideosink->layer_id = -1;
2253 dfbvideosink->layer = NULL;
2254 dfbvideosink->primary = NULL;
2255 dfbvideosink->event_buffer = NULL;
2256 dfbvideosink->event_thread = NULL;
2258 dfbvideosink->ext_surface = NULL;
2260 dfbvideosink->pixel_format = DSPF_UNKNOWN;
2262 dfbvideosink->hw_scaling = FALSE;
2263 dfbvideosink->backbuffer = FALSE;
2264 dfbvideosink->vsync = TRUE;
2265 dfbvideosink->setup = FALSE;
2266 dfbvideosink->running = FALSE;
2268 dfbvideosink->cb_channels = NULL;
2269 dfbvideosink->brightness = -1;
2270 dfbvideosink->contrast = -1;
2271 dfbvideosink->hue = -1;
2272 dfbvideosink->saturation = -1;
2274 dfbvideosink->par = NULL;
2278 gst_dfbvideosink_base_init (gpointer g_class)
2280 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
2282 gst_element_class_set_details_simple (element_class, "DirectFB video sink",
2284 "A DirectFB based videosink", "Julien Moutte <julien@moutte.net>");
2286 gst_element_class_add_static_pad_template (element_class,
2287 &gst_dfbvideosink_sink_template_factory);
2291 gst_dfbvideosink_class_init (GstDfbVideoSinkClass * klass)
2293 GObjectClass *gobject_class;
2294 GstElementClass *gstelement_class;
2295 GstBaseSinkClass *gstbasesink_class;
2297 gobject_class = (GObjectClass *) klass;
2298 gstelement_class = (GstElementClass *) klass;
2299 gstbasesink_class = (GstBaseSinkClass *) klass;
2301 parent_class = g_type_class_peek_parent (klass);
2303 gobject_class->finalize = gst_dfbvideosink_finalize;
2304 gobject_class->set_property = gst_dfbvideosink_set_property;
2305 gobject_class->get_property = gst_dfbvideosink_get_property;
2307 g_object_class_install_property (gobject_class, ARG_SURFACE,
2308 g_param_spec_pointer ("surface", "Surface",
2309 "The target surface for video",
2310 G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
2311 g_object_class_install_property (gobject_class, ARG_CONTRAST,
2312 g_param_spec_int ("contrast", "Contrast", "The contrast of the video",
2313 0x0000, 0xFFFF, 0x8000, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2314 g_object_class_install_property (gobject_class, ARG_BRIGHTNESS,
2315 g_param_spec_int ("brightness", "Brightness",
2316 "The brightness of the video", 0x0000, 0xFFFF, 0x8000,
2317 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2318 g_object_class_install_property (gobject_class, ARG_HUE,
2319 g_param_spec_int ("hue", "Hue", "The hue of the video", 0x0000, 0xFFFF,
2320 0x8000, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2321 g_object_class_install_property (gobject_class, ARG_SATURATION,
2322 g_param_spec_int ("saturation", "Saturation",
2323 "The saturation of the video", 0x0000, 0xFFFF, 0x8000,
2324 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2325 g_object_class_install_property (gobject_class, ARG_PIXEL_ASPECT_RATIO,
2326 g_param_spec_string ("pixel-aspect-ratio", "Pixel Aspect Ratio",
2327 "The pixel aspect ratio of the device", "1/1",
2328 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2329 g_object_class_install_property (gobject_class, ARG_VSYNC,
2330 g_param_spec_boolean ("vsync", "Vertical synchronisation",
2331 "Wait for next vertical sync to draw frames", TRUE,
2332 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2334 gstelement_class->change_state = gst_dfbvideosink_change_state;
2336 gstbasesink_class->get_caps = gst_dfbvideosink_getcaps;
2337 gstbasesink_class->set_caps = gst_dfbvideosink_setcaps;
2338 gstbasesink_class->buffer_alloc = gst_dfbvideosink_buffer_alloc;
2339 gstbasesink_class->get_times = gst_dfbvideosink_get_times;
2340 gstbasesink_class->preroll = gst_dfbvideosink_show_frame;
2341 gstbasesink_class->render = gst_dfbvideosink_show_frame;
2344 /* ============================================================= */
2346 /* Public Methods */
2348 /* ============================================================= */
2350 /* =========================================== */
2352 /* Object typing & Creation */
2354 /* =========================================== */
2357 gst_dfbvideosink_get_type (void)
2359 static GType dfbvideosink_type = 0;
2361 if (!dfbvideosink_type) {
2362 static const GTypeInfo dfbvideosink_info = {
2363 sizeof (GstDfbVideoSinkClass),
2364 gst_dfbvideosink_base_init,
2366 (GClassInitFunc) gst_dfbvideosink_class_init,
2369 sizeof (GstDfbVideoSink),
2371 (GInstanceInitFunc) gst_dfbvideosink_init,
2373 static const GInterfaceInfo iface_info = {
2374 (GInterfaceInitFunc) gst_dfbvideosink_interface_init,
2378 static const GInterfaceInfo navigation_info = {
2379 (GInterfaceInitFunc) gst_dfbvideosink_navigation_init,
2383 static const GInterfaceInfo colorbalance_info = {
2384 (GInterfaceInitFunc) gst_dfbvideosink_colorbalance_init,
2389 dfbvideosink_type = g_type_register_static (GST_TYPE_VIDEO_SINK,
2390 "GstDfbVideoSink", &dfbvideosink_info, 0);
2392 g_type_add_interface_static (dfbvideosink_type,
2393 GST_TYPE_IMPLEMENTS_INTERFACE, &iface_info);
2394 g_type_add_interface_static (dfbvideosink_type, GST_TYPE_NAVIGATION,
2396 g_type_add_interface_static (dfbvideosink_type, GST_TYPE_COLOR_BALANCE,
2397 &colorbalance_info);
2400 return dfbvideosink_type;
2404 plugin_init (GstPlugin * plugin)
2406 if (!gst_element_register (plugin, "dfbvideosink", GST_RANK_MARGINAL,
2407 GST_TYPE_DFBVIDEOSINK))
2410 GST_DEBUG_CATEGORY_INIT (dfbvideosink_debug, "dfbvideosink", 0,
2411 "DirectFB video sink element");
2416 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
2419 "DirectFB video output plugin",
2420 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)