mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 08:46:40 +00:00
xvimagesink: use bufferpool
Improve bufferpool handling in ximagesink. Implement bufferpool handling on xvimagesink. Based on patches from benjamin gaignard <benjamin.gaignard@linaro.org>
This commit is contained in:
parent
0f3fdf18e0
commit
15c49a4d63
11 changed files with 1007 additions and 790 deletions
|
@ -17,8 +17,6 @@
|
|||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -27,6 +25,7 @@
|
|||
|
||||
GST_DEBUG_CATEGORY (gst_debug_ximagepool);
|
||||
GST_DEBUG_CATEGORY (gst_debug_ximagesink);
|
||||
GST_DEBUG_CATEGORY_STATIC (GST_CAT_PERFORMANCE);
|
||||
|
||||
static gboolean
|
||||
plugin_init (GstPlugin * plugin)
|
||||
|
@ -40,6 +39,8 @@ plugin_init (GstPlugin * plugin)
|
|||
GST_DEBUG_CATEGORY_INIT (gst_debug_ximagepool, "ximagepool", 0,
|
||||
"ximagepool object");
|
||||
|
||||
GST_DEBUG_CATEGORY_GET (GST_CAT_PERFORMANCE, "GST_PERFORMANCE");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ GST_DEBUG_CATEGORY_EXTERN (gst_debug_ximagepool);
|
|||
|
||||
static void gst_meta_ximage_free (GstMetaXImage * meta, GstBuffer * buffer);
|
||||
|
||||
/* ximage buffers */
|
||||
/* ximage metadata */
|
||||
const GstMetaInfo *
|
||||
gst_meta_ximage_get_info (void)
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ gst_meta_ximage_get_info (void)
|
|||
}
|
||||
|
||||
/* X11 stuff */
|
||||
static gboolean error_caught;
|
||||
static gboolean error_caught = FALSE;
|
||||
|
||||
static int
|
||||
gst_ximagesink_handle_xerror (Display * display, XErrorEvent * xevent)
|
||||
|
@ -133,6 +133,9 @@ gst_buffer_add_meta_ximage (GstBuffer * buffer, GstXImageSink * ximagesink,
|
|||
* This way, it will be deleted as soon as we detach later, and not
|
||||
* leaked if we crash. */
|
||||
shmctl (meta->SHMInfo.shmid, IPC_RMID, NULL);
|
||||
|
||||
GST_DEBUG_OBJECT (ximagesink, "XServer ShmAttached to 0x%x, id 0x%lx",
|
||||
meta->SHMInfo.shmid, meta->SHMInfo.shmseg);
|
||||
} else
|
||||
#endif /* HAVE_XSHM */
|
||||
{
|
||||
|
@ -225,7 +228,7 @@ shmat_failed:
|
|||
}
|
||||
xattach_failed:
|
||||
{
|
||||
/* Clean up shm seg */
|
||||
/* Clean up the shared memory segment */
|
||||
shmctl (meta->SHMInfo.shmid, IPC_RMID, NULL);
|
||||
g_mutex_unlock (ximagesink->x_lock);
|
||||
|
||||
|
@ -248,9 +251,11 @@ gst_meta_ximage_free (GstMetaXImage * meta, GstBuffer * buffer)
|
|||
/* Hold the object lock to ensure the XContext doesn't disappear */
|
||||
GST_OBJECT_LOCK (ximagesink);
|
||||
/* We might have some buffers destroyed after changing state to NULL */
|
||||
if (!ximagesink->xcontext) {
|
||||
if (ximagesink->xcontext == NULL) {
|
||||
GST_DEBUG_OBJECT (ximagesink, "Destroying XImage after XContext");
|
||||
#ifdef HAVE_XSHM
|
||||
/* Need to free the shared memory segment even if the x context
|
||||
* was already cleaned up */
|
||||
if (meta->SHMInfo.shmaddr != ((void *) -1)) {
|
||||
shmdt (meta->SHMInfo.shmaddr);
|
||||
}
|
||||
|
@ -263,14 +268,15 @@ gst_meta_ximage_free (GstMetaXImage * meta, GstBuffer * buffer)
|
|||
#ifdef HAVE_XSHM
|
||||
if (ximagesink->xcontext->use_xshm) {
|
||||
if (meta->SHMInfo.shmaddr != ((void *) -1)) {
|
||||
GST_DEBUG_OBJECT (ximagesink, "XServer ShmDetaching from 0x%x id 0x%lx",
|
||||
meta->SHMInfo.shmid, meta->SHMInfo.shmseg);
|
||||
XShmDetach (ximagesink->xcontext->disp, &meta->SHMInfo);
|
||||
XSync (ximagesink->xcontext->disp, 0);
|
||||
XSync (ximagesink->xcontext->disp, FALSE);
|
||||
shmdt (meta->SHMInfo.shmaddr);
|
||||
meta->SHMInfo.shmaddr = (void *) -1;
|
||||
}
|
||||
if (meta->ximage)
|
||||
XDestroyImage (meta->ximage);
|
||||
|
||||
} else
|
||||
#endif /* HAVE_XSHM */
|
||||
{
|
||||
|
@ -302,7 +308,9 @@ gst_ximage_buffer_new (GstXImageSink * ximagesink, gint width, gint height)
|
|||
return buffer;
|
||||
}
|
||||
|
||||
#ifdef HAVE_XSHM /* Check that XShm calls actually work */
|
||||
#ifdef HAVE_XSHM
|
||||
/* This function checks that it is actually really possible to create an image
|
||||
using XShm */
|
||||
gboolean
|
||||
gst_ximagesink_check_xshm_calls (GstXImageSink * ximagesink,
|
||||
GstXContext * xcontext)
|
||||
|
@ -351,7 +359,7 @@ gst_ximagesink_check_xshm_calls (GstXImageSink * ximagesink,
|
|||
SHMInfo.shmaddr = shmat (SHMInfo.shmid, NULL, 0);
|
||||
if (SHMInfo.shmaddr == ((void *) -1)) {
|
||||
GST_WARNING ("Failed to shmat: %s", g_strerror (errno));
|
||||
/* Clean up shm seg */
|
||||
/* Clean up the shared memory segment */
|
||||
shmctl (SHMInfo.shmid, IPC_RMID, NULL);
|
||||
goto beach;
|
||||
}
|
||||
|
@ -361,7 +369,7 @@ gst_ximagesink_check_xshm_calls (GstXImageSink * ximagesink,
|
|||
|
||||
if (XShmAttach (xcontext->disp, &SHMInfo) == 0) {
|
||||
GST_WARNING ("Failed to XShmAttach");
|
||||
/* Clean up shm seg */
|
||||
/* Clean up the shared memory segment */
|
||||
shmctl (SHMInfo.shmid, IPC_RMID, NULL);
|
||||
goto beach;
|
||||
}
|
||||
|
@ -369,24 +377,33 @@ gst_ximagesink_check_xshm_calls (GstXImageSink * ximagesink,
|
|||
/* Sync to ensure we see any errors we caused */
|
||||
XSync (xcontext->disp, FALSE);
|
||||
|
||||
/* Delete the shared memory segment as soon as everyone is attached.
|
||||
/* Delete the shared memory segment as soon as everyone is attached.
|
||||
* This way, it will be deleted as soon as we detach later, and not
|
||||
* leaked if we crash. */
|
||||
shmctl (SHMInfo.shmid, IPC_RMID, NULL);
|
||||
|
||||
if (!error_caught) {
|
||||
GST_DEBUG ("XServer ShmAttached to 0x%x, id 0x%lx", SHMInfo.shmid,
|
||||
SHMInfo.shmseg);
|
||||
|
||||
did_attach = TRUE;
|
||||
/* store whether we succeeded in result */
|
||||
result = TRUE;
|
||||
} else {
|
||||
GST_WARNING ("MIT-SHM extension check failed at XShmAttach. "
|
||||
"Not using shared memory.");
|
||||
}
|
||||
|
||||
beach:
|
||||
/* Sync to ensure we swallow any errors we caused and reset error_caught */
|
||||
XSync (xcontext->disp, FALSE);
|
||||
|
||||
error_caught = FALSE;
|
||||
XSetErrorHandler (handler);
|
||||
|
||||
if (did_attach) {
|
||||
GST_DEBUG ("XServer ShmDetaching from 0x%x id 0x%lx",
|
||||
SHMInfo.shmid, SHMInfo.shmseg);
|
||||
XShmDetach (xcontext->disp, &SHMInfo);
|
||||
XSync (xcontext->disp, FALSE);
|
||||
}
|
||||
|
|
|
@ -62,12 +62,13 @@ GstMetaXImage * gst_buffer_add_meta_ximage (GstBuffer *buffer, GstXImageSink *
|
|||
* @height: the height in pixels of XImage @ximage
|
||||
* @size: the size in bytes of XImage @ximage
|
||||
*
|
||||
* Subclass of #GstBuffer containing additional information about an XImage.
|
||||
* Subclass of #GstMeta containing additional information about an XImage.
|
||||
*/
|
||||
struct _GstMetaXImage
|
||||
{
|
||||
GstMeta meta;
|
||||
|
||||
/* Reference to the ximagesink we belong to */
|
||||
GstXImageSink *sink;
|
||||
|
||||
XImage *ximage;
|
||||
|
|
|
@ -208,8 +208,6 @@ gst_ximagesink_ximage_put (GstXImageSink * ximagesink, GstBuffer * ximage)
|
|||
GstVideoRectangle src, dst, result;
|
||||
gboolean draw_border = FALSE;
|
||||
|
||||
g_return_val_if_fail (GST_IS_XIMAGESINK (ximagesink), FALSE);
|
||||
|
||||
/* We take the flow_lock. If expose is in there we don't want to run
|
||||
concurrently from the data flow thread */
|
||||
g_mutex_lock (ximagesink->flow_lock);
|
||||
|
@ -229,7 +227,7 @@ gst_ximagesink_ximage_put (GstXImageSink * ximagesink, GstBuffer * ximage)
|
|||
if (ximage && ximagesink->cur_image != ximage) {
|
||||
if (ximagesink->cur_image) {
|
||||
GST_LOG_OBJECT (ximagesink, "unreffing %p", ximagesink->cur_image);
|
||||
gst_buffer_unref (GST_BUFFER_CAST (ximagesink->cur_image));
|
||||
gst_buffer_unref (ximagesink->cur_image);
|
||||
}
|
||||
GST_LOG_OBJECT (ximagesink, "reffing %p as our current image", ximage);
|
||||
ximagesink->cur_image = gst_buffer_ref (ximage);
|
||||
|
@ -247,6 +245,7 @@ gst_ximagesink_ximage_put (GstXImageSink * ximagesink, GstBuffer * ximage)
|
|||
}
|
||||
|
||||
meta = gst_buffer_get_meta_ximage (ximage);
|
||||
|
||||
src.w = meta->width;
|
||||
src.h = meta->height;
|
||||
dst.w = ximagesink->xwindow->width;
|
||||
|
@ -303,7 +302,8 @@ gst_ximagesink_xwindow_decorate (GstXImageSink * ximagesink,
|
|||
|
||||
g_mutex_lock (ximagesink->x_lock);
|
||||
|
||||
hints_atom = XInternAtom (ximagesink->xcontext->disp, "_MOTIF_WM_HINTS", 1);
|
||||
hints_atom = XInternAtom (ximagesink->xcontext->disp, "_MOTIF_WM_HINTS",
|
||||
True);
|
||||
if (hints_atom == None) {
|
||||
g_mutex_unlock (ximagesink->x_lock);
|
||||
return FALSE;
|
||||
|
@ -586,7 +586,6 @@ gst_ximagesink_handle_xevents (GstXImageSink * ximagesink)
|
|||
g_mutex_unlock (ximagesink->x_lock);
|
||||
gst_navigation_send_key_event (GST_NAVIGATION (ximagesink),
|
||||
e.type == KeyPress ? "key-press" : "key-release", key_str);
|
||||
|
||||
} else {
|
||||
gst_navigation_send_key_event (GST_NAVIGATION (ximagesink),
|
||||
e.type == KeyPress ? "key-press" : "key-release", "unknown");
|
||||
|
@ -600,6 +599,7 @@ gst_ximagesink_handle_xevents (GstXImageSink * ximagesink)
|
|||
g_mutex_lock (ximagesink->x_lock);
|
||||
}
|
||||
|
||||
/* Handle Expose */
|
||||
while (XCheckWindowEvent (ximagesink->xcontext->disp,
|
||||
ximagesink->xwindow->win, ExposureMask | StructureNotifyMask, &e)) {
|
||||
switch (e.type) {
|
||||
|
@ -830,7 +830,7 @@ gst_ximagesink_xcontext_get (GstXImageSink * ximagesink)
|
|||
g_mutex_unlock (ximagesink->x_lock);
|
||||
g_free (xcontext->par);
|
||||
g_free (xcontext);
|
||||
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE,
|
||||
GST_ELEMENT_ERROR (ximagesink, RESOURCE, SETTINGS,
|
||||
("Could not get supported pixmap formats"), (NULL));
|
||||
return NULL;
|
||||
}
|
||||
|
@ -854,7 +854,7 @@ gst_ximagesink_xcontext_get (GstXImageSink * ximagesink)
|
|||
xcontext->use_xshm = TRUE;
|
||||
GST_DEBUG ("ximagesink is using XShm extension");
|
||||
} else
|
||||
#endif
|
||||
#endif /* HAVE_XSHM */
|
||||
{
|
||||
xcontext->use_xshm = FALSE;
|
||||
GST_DEBUG ("ximagesink is not using XShm extension");
|
||||
|
@ -982,9 +982,9 @@ static gboolean
|
|||
gst_ximagesink_setcaps (GstBaseSink * bsink, GstCaps * caps)
|
||||
{
|
||||
GstXImageSink *ximagesink;
|
||||
gboolean ret = TRUE;
|
||||
GstStructure *structure;
|
||||
GstBufferPool *newpool, *oldpool;
|
||||
gboolean ret = TRUE;
|
||||
const GValue *par;
|
||||
gint new_width, new_height;
|
||||
const GValue *fps;
|
||||
|
@ -1008,6 +1008,7 @@ gst_ximagesink_setcaps (GstBaseSink * bsink, GstCaps * caps)
|
|||
ret &= gst_structure_get_int (structure, "height", &new_height);
|
||||
fps = gst_structure_get_value (structure, "framerate");
|
||||
ret &= (fps != NULL);
|
||||
|
||||
if (!ret)
|
||||
return FALSE;
|
||||
|
||||
|
@ -1052,7 +1053,6 @@ gst_ximagesink_setcaps (GstBaseSink * bsink, GstCaps * caps)
|
|||
}
|
||||
/* Remember to draw borders for next frame */
|
||||
ximagesink->draw_border = TRUE;
|
||||
g_mutex_unlock (ximagesink->flow_lock);
|
||||
|
||||
/* create a new pool for the new configuration */
|
||||
newpool = gst_ximage_buffer_pool_new (ximagesink);
|
||||
|
@ -1074,6 +1074,8 @@ gst_ximagesink_setcaps (GstBaseSink * bsink, GstCaps * caps)
|
|||
gst_buffer_pool_set_active (oldpool, FALSE);
|
||||
gst_object_unref (oldpool);
|
||||
}
|
||||
g_mutex_unlock (ximagesink->flow_lock);
|
||||
|
||||
return TRUE;
|
||||
|
||||
/* ERRORS */
|
||||
|
@ -1096,11 +1098,13 @@ invalid_size:
|
|||
config_failed:
|
||||
{
|
||||
GST_ERROR_OBJECT (ximagesink, "failed to set config.");
|
||||
g_mutex_unlock (ximagesink->flow_lock);
|
||||
return FALSE;
|
||||
}
|
||||
activate_failed:
|
||||
{
|
||||
GST_ERROR_OBJECT (ximagesink, "failed to activate bufferpool.");
|
||||
g_mutex_unlock (ximagesink->flow_lock);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -1108,15 +1112,14 @@ activate_failed:
|
|||
static GstStateChangeReturn
|
||||
gst_ximagesink_change_state (GstElement * element, GstStateChange transition)
|
||||
{
|
||||
GstXImageSink *ximagesink;
|
||||
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
||||
GstXImageSink *ximagesink;
|
||||
GstXContext *xcontext = NULL;
|
||||
|
||||
ximagesink = GST_XIMAGESINK (element);
|
||||
|
||||
switch (transition) {
|
||||
case GST_STATE_CHANGE_NULL_TO_READY:
|
||||
|
||||
/* Initializing the XContext */
|
||||
if (ximagesink->xcontext == NULL) {
|
||||
xcontext = gst_ximagesink_xcontext_get (ximagesink);
|
||||
|
@ -1160,6 +1163,9 @@ gst_ximagesink_change_state (GstElement * element, GstStateChange transition)
|
|||
ximagesink->fps_d = 1;
|
||||
GST_VIDEO_SINK_WIDTH (ximagesink) = 0;
|
||||
GST_VIDEO_SINK_HEIGHT (ximagesink) = 0;
|
||||
g_mutex_lock (ximagesink->flow_lock);
|
||||
gst_buffer_pool_set_active (ximagesink->pool, FALSE);
|
||||
g_mutex_unlock (ximagesink->flow_lock);
|
||||
break;
|
||||
case GST_STATE_CHANGE_READY_TO_NULL:
|
||||
gst_ximagesink_reset (ximagesink);
|
||||
|
@ -1201,15 +1207,8 @@ gst_ximagesink_show_frame (GstVideoSink * vsink, GstBuffer * buf)
|
|||
GstXImageSink *ximagesink;
|
||||
GstMetaXImage *meta;
|
||||
|
||||
g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
|
||||
|
||||
ximagesink = GST_XIMAGESINK (vsink);
|
||||
|
||||
/* This shouldn't really happen because state changes will fail
|
||||
* if the xcontext can't be allocated */
|
||||
if (!ximagesink->xcontext)
|
||||
return GST_FLOW_ERROR;
|
||||
|
||||
meta = gst_buffer_get_meta_ximage (buf);
|
||||
|
||||
if (meta) {
|
||||
|
@ -1811,16 +1810,17 @@ gst_ximagesink_reset (GstXImageSink * ximagesink)
|
|||
g_thread_join (thread);
|
||||
|
||||
if (ximagesink->cur_image) {
|
||||
gst_buffer_unref (GST_BUFFER_CAST (ximagesink->cur_image));
|
||||
gst_buffer_unref (ximagesink->cur_image);
|
||||
ximagesink->cur_image = NULL;
|
||||
}
|
||||
|
||||
g_mutex_lock (ximagesink->flow_lock);
|
||||
|
||||
if (ximagesink->pool) {
|
||||
gst_object_unref (ximagesink->pool);
|
||||
ximagesink->pool = NULL;
|
||||
}
|
||||
|
||||
g_mutex_lock (ximagesink->flow_lock);
|
||||
if (ximagesink->xwindow) {
|
||||
gst_ximagesink_xwindow_clear (ximagesink, ximagesink->xwindow);
|
||||
gst_ximagesink_xwindow_destroy (ximagesink, ximagesink->xwindow);
|
||||
|
|
|
@ -129,7 +129,6 @@ struct _GstXWindow
|
|||
GC gc;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* GstXImageSink:
|
||||
* @display_name: the name of the Display we want to render to
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
plugin_LTLIBRARIES = libgstxvimagesink.la
|
||||
|
||||
libgstxvimagesink_la_SOURCES = xvimagesink.c
|
||||
libgstxvimagesink_la_SOURCES = xvimagesink.c xvimage.c xvimagepool.c
|
||||
libgstxvimagesink_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(X_CFLAGS)
|
||||
libgstxvimagesink_la_LIBADD = \
|
||||
$(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-$(GST_MAJORMINOR).la \
|
||||
|
@ -12,4 +12,4 @@ libgstxvimagesink_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
|||
libgstxvimagesink_la_DEPENDENCIES = $(top_builddir)/gst-libs/gst/video/libgstvideo-$(GST_MAJORMINOR).la
|
||||
libgstxvimagesink_la_LIBTOOLFLAGS = --tag=disable-static
|
||||
|
||||
noinst_HEADERS = xvimagesink.h
|
||||
noinst_HEADERS = xvimagesink.h xvimagepool.h
|
||||
|
|
51
sys/xvimage/xvimage.c
Normal file
51
sys/xvimage/xvimage.c
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <2003> Julien Moutte <julien@moutte.net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "xvimagesink.h"
|
||||
|
||||
GST_DEBUG_CATEGORY (gst_debug_xvimagepool);
|
||||
GST_DEBUG_CATEGORY (gst_debug_xvimagesink);
|
||||
GST_DEBUG_CATEGORY_STATIC (GST_CAT_PERFORMANCE);
|
||||
|
||||
static gboolean
|
||||
plugin_init (GstPlugin * plugin)
|
||||
{
|
||||
if (!gst_element_register (plugin, "xvimagesink",
|
||||
GST_RANK_PRIMARY, GST_TYPE_XVIMAGESINK))
|
||||
return FALSE;
|
||||
|
||||
GST_DEBUG_CATEGORY_INIT (gst_debug_xvimagesink, "xvimagesink", 0,
|
||||
"xvimagesink element");
|
||||
GST_DEBUG_CATEGORY_INIT (gst_debug_xvimagepool, "xvimagepool", 0,
|
||||
"xvimagepool object");
|
||||
|
||||
GST_DEBUG_CATEGORY_GET (GST_CAT_PERFORMANCE, "GST_PERFORMANCE");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
"xvimagesink",
|
||||
"XFree86 video output plugin using Xv extension",
|
||||
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|
642
sys/xvimage/xvimagepool.c
Normal file
642
sys/xvimage/xvimagepool.c
Normal file
|
@ -0,0 +1,642 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <2005> Julien Moutte <julien@moutte.net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
/* Object header */
|
||||
#include "xvimagesink.h"
|
||||
|
||||
/* Debugging category */
|
||||
#include <gst/gstinfo.h>
|
||||
|
||||
GST_DEBUG_CATEGORY_EXTERN (gst_debug_xvimagepool);
|
||||
#define GST_CAT_DEFAULT gst_debug_xvimagepool
|
||||
|
||||
static void gst_meta_xvimage_free (GstMetaXvImage * meta, GstBuffer * buffer);
|
||||
|
||||
/* xvimage metadata */
|
||||
const GstMetaInfo *
|
||||
gst_meta_xvimage_get_info (void)
|
||||
{
|
||||
static const GstMetaInfo *meta_xvimage_info = NULL;
|
||||
|
||||
if (meta_xvimage_info == NULL) {
|
||||
meta_xvimage_info = gst_meta_register ("GstMetaXvImage", "GstMetaXvImage",
|
||||
sizeof (GstMetaXvImage),
|
||||
(GstMetaInitFunction) NULL,
|
||||
(GstMetaFreeFunction) gst_meta_xvimage_free,
|
||||
(GstMetaCopyFunction) NULL,
|
||||
(GstMetaTransformFunction) NULL,
|
||||
(GstMetaSerializeFunction) NULL, (GstMetaDeserializeFunction) NULL);
|
||||
}
|
||||
return meta_xvimage_info;
|
||||
}
|
||||
|
||||
/* X11 stuff */
|
||||
static gboolean error_caught = FALSE;
|
||||
|
||||
static int
|
||||
gst_xvimagesink_handle_xerror (Display * display, XErrorEvent * xevent)
|
||||
{
|
||||
char error_msg[1024];
|
||||
|
||||
XGetErrorText (display, xevent->error_code, error_msg, 1024);
|
||||
GST_DEBUG ("xvimagesink triggered an XError. error: %s", error_msg);
|
||||
error_caught = TRUE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
GstMetaXvImage *
|
||||
gst_buffer_add_meta_xvimage (GstBuffer * buffer, GstXvImageSink * xvimagesink,
|
||||
gint width, gint height, gint im_format)
|
||||
{
|
||||
int (*handler) (Display *, XErrorEvent *);
|
||||
gboolean success = FALSE;
|
||||
GstXContext *xcontext;
|
||||
GstMetaXvImage *meta;
|
||||
|
||||
xcontext = xvimagesink->xcontext;
|
||||
|
||||
meta =
|
||||
(GstMetaXvImage *) gst_buffer_add_meta (buffer, GST_META_INFO_XVIMAGE,
|
||||
NULL);
|
||||
#ifdef HAVE_XSHM
|
||||
meta->SHMInfo.shmaddr = ((void *) -1);
|
||||
meta->SHMInfo.shmid = -1;
|
||||
#endif
|
||||
meta->width = width;
|
||||
meta->height = height;
|
||||
meta->sink = gst_object_ref (xvimagesink);
|
||||
meta->im_format = im_format;
|
||||
|
||||
GST_DEBUG_OBJECT (xvimagesink, "creating image %p (%dx%d)", buffer,
|
||||
meta->width, meta->height);
|
||||
|
||||
g_mutex_lock (xvimagesink->x_lock);
|
||||
|
||||
/* Setting an error handler to catch failure */
|
||||
error_caught = FALSE;
|
||||
handler = XSetErrorHandler (gst_xvimagesink_handle_xerror);
|
||||
|
||||
#ifdef HAVE_XSHM
|
||||
if (xcontext->use_xshm) {
|
||||
int expected_size;
|
||||
|
||||
meta->xvimage = XvShmCreateImage (xcontext->disp,
|
||||
xcontext->xv_port_id,
|
||||
meta->im_format, NULL, meta->width, meta->height, &meta->SHMInfo);
|
||||
if (!meta->xvimage || error_caught)
|
||||
goto create_failed;
|
||||
|
||||
/* we have to use the returned data_size for our shm size */
|
||||
meta->size = meta->xvimage->data_size;
|
||||
GST_LOG_OBJECT (xvimagesink, "XShm image size is %" G_GSIZE_FORMAT,
|
||||
meta->size);
|
||||
|
||||
/* calculate the expected size. This is only for sanity checking the
|
||||
* number we get from X. */
|
||||
switch (meta->im_format) {
|
||||
case GST_MAKE_FOURCC ('I', '4', '2', '0'):
|
||||
case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
|
||||
{
|
||||
gint pitches[3];
|
||||
gint offsets[3];
|
||||
guint plane;
|
||||
|
||||
offsets[0] = 0;
|
||||
pitches[0] = GST_ROUND_UP_4 (meta->width);
|
||||
offsets[1] = offsets[0] + pitches[0] * GST_ROUND_UP_2 (meta->height);
|
||||
pitches[1] = GST_ROUND_UP_8 (meta->width) / 2;
|
||||
offsets[2] =
|
||||
offsets[1] + pitches[1] * GST_ROUND_UP_2 (meta->height) / 2;
|
||||
pitches[2] = GST_ROUND_UP_8 (pitches[0]) / 2;
|
||||
|
||||
expected_size =
|
||||
offsets[2] + pitches[2] * GST_ROUND_UP_2 (meta->height) / 2;
|
||||
|
||||
for (plane = 0; plane < meta->xvimage->num_planes; plane++) {
|
||||
GST_DEBUG_OBJECT (xvimagesink,
|
||||
"Plane %u has a expected pitch of %d bytes, " "offset of %d",
|
||||
plane, pitches[plane], offsets[plane]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
|
||||
case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
|
||||
expected_size = meta->height * GST_ROUND_UP_4 (meta->width * 2);
|
||||
break;
|
||||
default:
|
||||
expected_size = 0;
|
||||
break;
|
||||
}
|
||||
if (expected_size != 0 && meta->size != expected_size) {
|
||||
GST_WARNING_OBJECT (xvimagesink,
|
||||
"unexpected XShm image size (got %" G_GSIZE_FORMAT ", expected %d)",
|
||||
meta->size, expected_size);
|
||||
}
|
||||
|
||||
/* Be verbose about our XvImage stride */
|
||||
{
|
||||
guint plane;
|
||||
|
||||
for (plane = 0; plane < meta->xvimage->num_planes; plane++) {
|
||||
GST_DEBUG_OBJECT (xvimagesink, "Plane %u has a pitch of %d bytes, "
|
||||
"offset of %d", plane, meta->xvimage->pitches[plane],
|
||||
meta->xvimage->offsets[plane]);
|
||||
}
|
||||
}
|
||||
|
||||
/* get shared memory */
|
||||
meta->SHMInfo.shmid = shmget (IPC_PRIVATE, meta->size, IPC_CREAT | 0777);
|
||||
if (meta->SHMInfo.shmid == -1)
|
||||
goto shmget_failed;
|
||||
|
||||
/* attach */
|
||||
meta->SHMInfo.shmaddr = shmat (meta->SHMInfo.shmid, NULL, 0);
|
||||
if (meta->SHMInfo.shmaddr == ((void *) -1))
|
||||
goto shmat_failed;
|
||||
|
||||
/* now we can set up the image data */
|
||||
meta->xvimage->data = meta->SHMInfo.shmaddr;
|
||||
meta->SHMInfo.readOnly = FALSE;
|
||||
|
||||
if (XShmAttach (xcontext->disp, &meta->SHMInfo) == 0)
|
||||
goto xattach_failed;
|
||||
|
||||
XSync (xcontext->disp, FALSE);
|
||||
|
||||
/* Delete the shared memory segment as soon as we everyone is attached.
|
||||
* This way, it will be deleted as soon as we detach later, and not
|
||||
* leaked if we crash. */
|
||||
shmctl (meta->SHMInfo.shmid, IPC_RMID, NULL);
|
||||
|
||||
GST_DEBUG_OBJECT (xvimagesink, "XServer ShmAttached to 0x%x, id 0x%lx",
|
||||
meta->SHMInfo.shmid, meta->SHMInfo.shmseg);
|
||||
} else
|
||||
#endif /* HAVE_XSHM */
|
||||
{
|
||||
meta->xvimage = XvCreateImage (xcontext->disp,
|
||||
xcontext->xv_port_id, meta->im_format, NULL, meta->width, meta->height);
|
||||
if (!meta->xvimage || error_caught)
|
||||
goto create_failed;
|
||||
|
||||
/* we have to use the returned data_size for our image size */
|
||||
meta->size = meta->xvimage->data_size;
|
||||
meta->xvimage->data = g_malloc (meta->size);
|
||||
|
||||
XSync (xcontext->disp, FALSE);
|
||||
}
|
||||
|
||||
/* Reset error handler */
|
||||
error_caught = FALSE;
|
||||
XSetErrorHandler (handler);
|
||||
|
||||
gst_buffer_take_memory (buffer,
|
||||
gst_memory_new_wrapped (0, meta->xvimage->data, NULL,
|
||||
meta->size, 0, meta->size));
|
||||
|
||||
g_mutex_unlock (xvimagesink->x_lock);
|
||||
|
||||
success = TRUE;
|
||||
|
||||
beach:
|
||||
if (!success)
|
||||
meta = NULL;
|
||||
|
||||
return meta;
|
||||
|
||||
/* ERRORS */
|
||||
create_failed:
|
||||
{
|
||||
g_mutex_unlock (xvimagesink->x_lock);
|
||||
/* Reset error handler */
|
||||
error_caught = FALSE;
|
||||
XSetErrorHandler (handler);
|
||||
/* Push an error */
|
||||
GST_ELEMENT_ERROR (xvimagesink, RESOURCE, WRITE,
|
||||
("Failed to create output image buffer of %dx%d pixels",
|
||||
meta->width, meta->height),
|
||||
("could not XvShmCreateImage a %dx%d image", meta->width,
|
||||
meta->height));
|
||||
goto beach;
|
||||
}
|
||||
shmget_failed:
|
||||
{
|
||||
g_mutex_unlock (xvimagesink->x_lock);
|
||||
GST_ELEMENT_ERROR (xvimagesink, RESOURCE, WRITE,
|
||||
("Failed to create output image buffer of %dx%d pixels",
|
||||
meta->width, meta->height),
|
||||
("could not get shared memory of %" G_GSIZE_FORMAT " bytes",
|
||||
meta->size));
|
||||
goto beach;
|
||||
}
|
||||
shmat_failed:
|
||||
{
|
||||
g_mutex_unlock (xvimagesink->x_lock);
|
||||
GST_ELEMENT_ERROR (xvimagesink, RESOURCE, WRITE,
|
||||
("Failed to create output image buffer of %dx%d pixels",
|
||||
meta->width, meta->height),
|
||||
("Failed to shmat: %s", g_strerror (errno)));
|
||||
/* Clean up the shared memory segment */
|
||||
shmctl (meta->SHMInfo.shmid, IPC_RMID, NULL);
|
||||
goto beach;
|
||||
}
|
||||
xattach_failed:
|
||||
{
|
||||
/* Clean up the shared memory segment */
|
||||
shmctl (meta->SHMInfo.shmid, IPC_RMID, NULL);
|
||||
g_mutex_unlock (xvimagesink->x_lock);
|
||||
|
||||
GST_ELEMENT_ERROR (xvimagesink, RESOURCE, WRITE,
|
||||
("Failed to create output image buffer of %dx%d pixels",
|
||||
meta->width, meta->height), ("Failed to XShmAttach"));
|
||||
goto beach;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_meta_xvimage_free (GstMetaXvImage * meta, GstBuffer * buffer)
|
||||
{
|
||||
GstXvImageSink *xvimagesink;
|
||||
|
||||
xvimagesink = meta->sink;
|
||||
|
||||
GST_DEBUG_OBJECT (xvimagesink, "free meta on buffer %p", buffer);
|
||||
|
||||
/* Hold the object lock to ensure the XContext doesn't disappear */
|
||||
GST_OBJECT_LOCK (xvimagesink);
|
||||
/* We might have some buffers destroyed after changing state to NULL */
|
||||
if (xvimagesink->xcontext == NULL) {
|
||||
GST_DEBUG_OBJECT (xvimagesink, "Destroying XvImage after Xcontext");
|
||||
#ifdef HAVE_XSHM
|
||||
/* Need to free the shared memory segment even if the x context
|
||||
* was already cleaned up */
|
||||
if (meta->SHMInfo.shmaddr != ((void *) -1)) {
|
||||
shmdt (meta->SHMInfo.shmaddr);
|
||||
}
|
||||
#endif
|
||||
goto beach;
|
||||
}
|
||||
|
||||
g_mutex_lock (xvimagesink->x_lock);
|
||||
|
||||
#ifdef HAVE_XSHM
|
||||
if (xvimagesink->xcontext->use_xshm) {
|
||||
if (meta->SHMInfo.shmaddr != ((void *) -1)) {
|
||||
GST_DEBUG_OBJECT (xvimagesink, "XServer ShmDetaching from 0x%x id 0x%lx",
|
||||
meta->SHMInfo.shmid, meta->SHMInfo.shmseg);
|
||||
XShmDetach (xvimagesink->xcontext->disp, &meta->SHMInfo);
|
||||
XSync (xvimagesink->xcontext->disp, FALSE);
|
||||
shmdt (meta->SHMInfo.shmaddr);
|
||||
meta->SHMInfo.shmaddr = (void *) -1;
|
||||
}
|
||||
if (meta->xvimage)
|
||||
XFree (meta->xvimage);
|
||||
} else
|
||||
#endif /* HAVE_XSHM */
|
||||
{
|
||||
if (meta->xvimage) {
|
||||
g_free (meta->xvimage->data);
|
||||
XFree (meta->xvimage);
|
||||
}
|
||||
}
|
||||
|
||||
XSync (xvimagesink->xcontext->disp, FALSE);
|
||||
|
||||
g_mutex_unlock (xvimagesink->x_lock);
|
||||
|
||||
beach:
|
||||
GST_OBJECT_UNLOCK (xvimagesink);
|
||||
}
|
||||
|
||||
GstBuffer *
|
||||
gst_xvimage_buffer_new (GstXvImageSink * xvimagesink, gint width, gint height,
|
||||
gint im_format)
|
||||
{
|
||||
GstBuffer *buffer;
|
||||
GstMetaXvImage *meta;
|
||||
|
||||
buffer = gst_buffer_new ();
|
||||
meta =
|
||||
gst_buffer_add_meta_xvimage (buffer, xvimagesink, width, height,
|
||||
im_format);
|
||||
if (meta == NULL) {
|
||||
gst_buffer_unref (buffer);
|
||||
buffer = NULL;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#ifdef HAVE_XSHM
|
||||
/* This function checks that it is actually really possible to create an image
|
||||
using XShm */
|
||||
gboolean
|
||||
gst_xvimagesink_check_xshm_calls (GstXvImageSink * xvimagesink,
|
||||
GstXContext * xcontext)
|
||||
{
|
||||
XvImage *xvimage;
|
||||
XShmSegmentInfo SHMInfo;
|
||||
size_t size;
|
||||
int (*handler) (Display *, XErrorEvent *);
|
||||
gboolean result = FALSE;
|
||||
gboolean did_attach = FALSE;
|
||||
|
||||
g_return_val_if_fail (xcontext != NULL, FALSE);
|
||||
|
||||
/* Sync to ensure any older errors are already processed */
|
||||
XSync (xcontext->disp, FALSE);
|
||||
|
||||
/* Set defaults so we don't free these later unnecessarily */
|
||||
SHMInfo.shmaddr = ((void *) -1);
|
||||
SHMInfo.shmid = -1;
|
||||
|
||||
/* Setting an error handler to catch failure */
|
||||
error_caught = FALSE;
|
||||
handler = XSetErrorHandler (gst_xvimagesink_handle_xerror);
|
||||
|
||||
/* Trying to create a 1x1 picture */
|
||||
GST_DEBUG ("XvShmCreateImage of 1x1");
|
||||
xvimage = XvShmCreateImage (xcontext->disp, xcontext->xv_port_id,
|
||||
xcontext->im_format, NULL, 1, 1, &SHMInfo);
|
||||
|
||||
/* Might cause an error, sync to ensure it is noticed */
|
||||
XSync (xcontext->disp, FALSE);
|
||||
if (!xvimage || error_caught) {
|
||||
GST_WARNING ("could not XvShmCreateImage a 1x1 image");
|
||||
goto beach;
|
||||
}
|
||||
size = xvimage->data_size;
|
||||
|
||||
SHMInfo.shmid = shmget (IPC_PRIVATE, size, IPC_CREAT | 0777);
|
||||
if (SHMInfo.shmid == -1) {
|
||||
GST_WARNING ("could not get shared memory of %" G_GSIZE_FORMAT " bytes",
|
||||
size);
|
||||
goto beach;
|
||||
}
|
||||
|
||||
SHMInfo.shmaddr = shmat (SHMInfo.shmid, NULL, 0);
|
||||
if (SHMInfo.shmaddr == ((void *) -1)) {
|
||||
GST_WARNING ("Failed to shmat: %s", g_strerror (errno));
|
||||
/* Clean up the shared memory segment */
|
||||
shmctl (SHMInfo.shmid, IPC_RMID, NULL);
|
||||
goto beach;
|
||||
}
|
||||
|
||||
xvimage->data = SHMInfo.shmaddr;
|
||||
SHMInfo.readOnly = FALSE;
|
||||
|
||||
if (XShmAttach (xcontext->disp, &SHMInfo) == 0) {
|
||||
GST_WARNING ("Failed to XShmAttach");
|
||||
/* Clean up the shared memory segment */
|
||||
shmctl (SHMInfo.shmid, IPC_RMID, NULL);
|
||||
goto beach;
|
||||
}
|
||||
|
||||
/* Sync to ensure we see any errors we caused */
|
||||
XSync (xcontext->disp, FALSE);
|
||||
|
||||
/* Delete the shared memory segment as soon as everyone is attached.
|
||||
* This way, it will be deleted as soon as we detach later, and not
|
||||
* leaked if we crash. */
|
||||
shmctl (SHMInfo.shmid, IPC_RMID, NULL);
|
||||
|
||||
if (!error_caught) {
|
||||
GST_DEBUG ("XServer ShmAttached to 0x%x, id 0x%lx", SHMInfo.shmid,
|
||||
SHMInfo.shmseg);
|
||||
|
||||
did_attach = TRUE;
|
||||
/* store whether we succeeded in result */
|
||||
result = TRUE;
|
||||
} else {
|
||||
GST_WARNING ("MIT-SHM extension check failed at XShmAttach. "
|
||||
"Not using shared memory.");
|
||||
}
|
||||
|
||||
beach:
|
||||
/* Sync to ensure we swallow any errors we caused and reset error_caught */
|
||||
XSync (xcontext->disp, FALSE);
|
||||
|
||||
error_caught = FALSE;
|
||||
XSetErrorHandler (handler);
|
||||
|
||||
if (did_attach) {
|
||||
GST_DEBUG ("XServer ShmDetaching from 0x%x id 0x%lx",
|
||||
SHMInfo.shmid, SHMInfo.shmseg);
|
||||
XShmDetach (xcontext->disp, &SHMInfo);
|
||||
XSync (xcontext->disp, FALSE);
|
||||
}
|
||||
if (SHMInfo.shmaddr != ((void *) -1))
|
||||
shmdt (SHMInfo.shmaddr);
|
||||
if (xvimage)
|
||||
XFree (xvimage);
|
||||
return result;
|
||||
}
|
||||
#endif /* HAVE_XSHM */
|
||||
|
||||
/* bufferpool */
|
||||
static void gst_xvimage_buffer_pool_finalize (GObject * object);
|
||||
|
||||
#define GST_XVIMAGE_BUFFER_POOL_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_XVIMAGE_BUFFER_POOL, GstXvImageBufferPoolPrivate))
|
||||
|
||||
struct _GstXvImageBufferPoolPrivate
|
||||
{
|
||||
GstCaps *caps;
|
||||
gint width, height;
|
||||
gint im_format;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (GstXvImageBufferPool, gst_xvimage_buffer_pool,
|
||||
GST_TYPE_BUFFER_POOL);
|
||||
|
||||
static gboolean
|
||||
xvimage_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
||||
{
|
||||
GstXvImageBufferPool *xvpool = GST_XVIMAGE_BUFFER_POOL_CAST (pool);
|
||||
GstXvImageBufferPoolPrivate *priv = xvpool->priv;
|
||||
GstStructure *structure;
|
||||
gint width, height;
|
||||
const GstCaps *caps;
|
||||
|
||||
if (!gst_buffer_pool_config_get (config, &caps, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL))
|
||||
goto wrong_config;
|
||||
|
||||
if (caps == NULL)
|
||||
goto no_caps;
|
||||
|
||||
/* now parse the caps from the config */
|
||||
structure = gst_caps_get_structure (caps, 0);
|
||||
|
||||
if (!gst_structure_get_int (structure, "width", &width) ||
|
||||
!gst_structure_get_int (structure, "height", &height))
|
||||
goto wrong_caps;
|
||||
|
||||
GST_LOG_OBJECT (pool, "%dx%d, caps %" GST_PTR_FORMAT, width, height, caps);
|
||||
|
||||
/* keep track of the width and height and caps */
|
||||
if (priv->caps)
|
||||
gst_caps_unref (priv->caps);
|
||||
priv->caps = gst_caps_copy (caps);
|
||||
priv->width = width;
|
||||
priv->height = height;
|
||||
priv->im_format =
|
||||
gst_xvimagesink_get_format_from_caps (xvpool->sink, (GstCaps *) caps);
|
||||
|
||||
if (priv->im_format == -1) {
|
||||
GST_WARNING_OBJECT (xvpool->sink, "failed to get format from caps %"
|
||||
GST_PTR_FORMAT, caps);
|
||||
GST_ELEMENT_ERROR (xvpool->sink, RESOURCE, WRITE,
|
||||
("Failed to create output image buffer of %dx%d pixels",
|
||||
priv->width, priv->height), ("Invalid input caps"));
|
||||
goto wrong_config;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
/* ERRORS */
|
||||
wrong_config:
|
||||
{
|
||||
GST_WARNING_OBJECT (pool, "invalid config");
|
||||
return FALSE;
|
||||
}
|
||||
no_caps:
|
||||
{
|
||||
GST_WARNING_OBJECT (pool, "no caps in config");
|
||||
return FALSE;
|
||||
}
|
||||
wrong_caps:
|
||||
{
|
||||
GST_WARNING_OBJECT (pool,
|
||||
"failed getting geometry from caps %" GST_PTR_FORMAT, caps);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* This function handles GstXImageBuffer creation depending on XShm availability */
|
||||
static GstFlowReturn
|
||||
xvimage_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
|
||||
GstBufferPoolParams * params)
|
||||
{
|
||||
GstXvImageBufferPool *xvpool = GST_XVIMAGE_BUFFER_POOL_CAST (pool);
|
||||
GstXvImageBufferPoolPrivate *priv = xvpool->priv;
|
||||
GstBuffer *xvimage;
|
||||
|
||||
xvimage =
|
||||
gst_xvimage_buffer_new (xvpool->sink, priv->width, priv->height,
|
||||
priv->im_format);
|
||||
if (xvimage == NULL)
|
||||
goto no_buffer;
|
||||
|
||||
*buffer = xvimage;
|
||||
|
||||
return GST_FLOW_OK;
|
||||
|
||||
/* ERROR */
|
||||
no_buffer:
|
||||
{
|
||||
GST_WARNING_OBJECT (pool, "can't create image");
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
xvimage_buffer_pool_free (GstBufferPool * pool, GstBuffer * buffer)
|
||||
{
|
||||
gst_buffer_unref (buffer);
|
||||
}
|
||||
|
||||
GstBufferPool *
|
||||
gst_xvimage_buffer_pool_new (GstXvImageSink * xvimagesink)
|
||||
{
|
||||
GstXvImageBufferPool *pool;
|
||||
|
||||
g_return_val_if_fail (GST_IS_XVIMAGESINK (xvimagesink), NULL);
|
||||
|
||||
pool = g_object_new (GST_TYPE_XVIMAGE_BUFFER_POOL, NULL);
|
||||
pool->sink = gst_object_ref (xvimagesink);
|
||||
|
||||
GST_LOG_OBJECT (pool, "new XvImage buffer pool %p", pool);
|
||||
|
||||
return GST_BUFFER_POOL_CAST (pool);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_xvimage_buffer_pool_class_init (GstXvImageBufferPoolClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = (GObjectClass *) klass;
|
||||
GstBufferPoolClass *gstbufferpool_class = (GstBufferPoolClass *) klass;
|
||||
|
||||
g_type_class_add_private (klass, sizeof (GstXvImageBufferPoolPrivate));
|
||||
|
||||
gobject_class->finalize = gst_xvimage_buffer_pool_finalize;
|
||||
|
||||
gstbufferpool_class->set_config = xvimage_buffer_pool_set_config;
|
||||
gstbufferpool_class->alloc_buffer = xvimage_buffer_pool_alloc;
|
||||
gstbufferpool_class->free_buffer = xvimage_buffer_pool_free;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_xvimage_buffer_pool_init (GstXvImageBufferPool * pool)
|
||||
{
|
||||
pool->priv = GST_XVIMAGE_BUFFER_POOL_GET_PRIVATE (pool);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_xvimage_buffer_pool_finalize (GObject * object)
|
||||
{
|
||||
GstXvImageBufferPool *pool = GST_XVIMAGE_BUFFER_POOL_CAST (object);
|
||||
GstXvImageBufferPoolPrivate *priv = pool->priv;
|
||||
|
||||
GST_LOG_OBJECT (pool, "finalize XvImage buffer pool %p", pool);
|
||||
|
||||
if (priv->caps)
|
||||
gst_caps_unref (priv->caps);
|
||||
gst_object_unref (pool->sink);
|
||||
|
||||
G_OBJECT_CLASS (gst_xvimage_buffer_pool_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
/* This function tries to get a format matching with a given caps in the
|
||||
supported list of formats we generated in gst_xvimagesink_get_xv_support */
|
||||
gint
|
||||
gst_xvimagesink_get_format_from_caps (GstXvImageSink * xvimagesink,
|
||||
GstCaps * caps)
|
||||
{
|
||||
GList *list = NULL;
|
||||
|
||||
g_return_val_if_fail (GST_IS_XVIMAGESINK (xvimagesink), 0);
|
||||
|
||||
list = xvimagesink->xcontext->formats_list;
|
||||
|
||||
while (list) {
|
||||
GstXvImageFormat *format = list->data;
|
||||
|
||||
if (format) {
|
||||
if (gst_caps_can_intersect (caps, format->caps)) {
|
||||
return format->format;
|
||||
}
|
||||
}
|
||||
list = g_list_next (list);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
120
sys/xvimage/xvimagepool.h
Normal file
120
sys/xvimage/xvimagepool.h
Normal file
|
@ -0,0 +1,120 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <2005> Julien Moutte <julien@moutte.net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GST_XVIMAGEPOOL_H__
|
||||
#define __GST_XVIMAGEPOOL_H__
|
||||
|
||||
#ifdef HAVE_XSHM
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#endif /* HAVE_XSHM */
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
#ifdef HAVE_XSHM
|
||||
#include <X11/extensions/XShm.h>
|
||||
#endif /* HAVE_XSHM */
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GstMetaXvImage GstMetaXvImage;
|
||||
|
||||
typedef struct _GstXvImageBufferPool GstXvImageBufferPool;
|
||||
typedef struct _GstXvImageBufferPoolClass GstXvImageBufferPoolClass;
|
||||
typedef struct _GstXvImageBufferPoolPrivate GstXvImageBufferPoolPrivate;
|
||||
|
||||
#include "xvimagesink.h"
|
||||
|
||||
const GstMetaInfo * gst_meta_xvimage_get_info (void);
|
||||
#define GST_META_INFO_XVIMAGE (gst_meta_xvimage_get_info())
|
||||
|
||||
#define gst_buffer_get_meta_xvimage(b) ((GstMetaXvImage*)gst_buffer_get_meta((b),GST_META_INFO_XVIMAGE))
|
||||
GstMetaXvImage * gst_buffer_add_meta_xvimage (GstBuffer *buffer, GstXvImageSink * xvimagesink,
|
||||
gint width, gint height, gint im_format);
|
||||
|
||||
/**
|
||||
* GstMetaXvImage:
|
||||
* @sink: a reference to the our #GstXvImageSink
|
||||
* @xvimage: the XvImage of this buffer
|
||||
* @width: the width in pixels of XvImage @xvimage
|
||||
* @height: the height in pixels of XvImage @xvimage
|
||||
* @im_format: the format of XvImage @xvimage
|
||||
* @size: the size in bytes of XvImage @xvimage
|
||||
*
|
||||
* Subclass of #GstMeta containing additional information about an XvImage.
|
||||
*/
|
||||
struct _GstMetaXvImage
|
||||
{
|
||||
GstMeta meta;
|
||||
|
||||
/* Reference to the xvimagesink we belong to */
|
||||
GstXvImageSink *sink;
|
||||
|
||||
XvImage *xvimage;
|
||||
|
||||
#ifdef HAVE_XSHM
|
||||
XShmSegmentInfo SHMInfo;
|
||||
#endif /* HAVE_XSHM */
|
||||
|
||||
gint width, height, im_format;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
GstBuffer *gst_xvimage_buffer_new (GstXvImageSink *xvimagesink, gint width, gint height,
|
||||
gint in_format);
|
||||
|
||||
/* buffer pool functions */
|
||||
#define GST_TYPE_XVIMAGE_BUFFER_POOL (gst_xvimage_buffer_pool_get_type())
|
||||
#define GST_IS_XVIMAGE_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_XVIMAGE_BUFFER_POOL))
|
||||
#define GST_XVIMAGE_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_XVIMAGE_BUFFER_POOL, GstXvImageBufferPool))
|
||||
#define GST_XVIMAGE_BUFFER_POOL_CAST(obj) ((GstXvImageBufferPool*)(obj))
|
||||
|
||||
struct _GstXvImageBufferPool
|
||||
{
|
||||
GstBufferPool bufferpool;
|
||||
|
||||
GstXvImageSink *sink;
|
||||
|
||||
GstXvImageBufferPoolPrivate *priv;
|
||||
};
|
||||
|
||||
struct _GstXvImageBufferPoolClass
|
||||
{
|
||||
GstBufferPoolClass parent_class;
|
||||
};
|
||||
|
||||
GType gst_xvimage_buffer_pool_get_type (void);
|
||||
|
||||
GstBufferPool *gst_xvimage_buffer_pool_new (GstXvImageSink * xvimagesink);
|
||||
|
||||
gboolean gst_xvimagesink_check_xshm_calls (GstXvImageSink * xvimagesink,
|
||||
GstXContext * xcontext);
|
||||
|
||||
gint gst_xvimagesink_get_format_from_caps (GstXvImageSink * xvimagesink,
|
||||
GstCaps * caps);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__GST_XVIMAGEPOOL_H__*/
|
File diff suppressed because it is too large
Load diff
|
@ -43,7 +43,6 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_XVIMAGESINK \
|
||||
(gst_xvimagesink_get_type())
|
||||
#define GST_XVIMAGESINK(obj) \
|
||||
|
@ -54,15 +53,15 @@ G_BEGIN_DECLS
|
|||
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_XVIMAGESINK))
|
||||
#define GST_IS_XVIMAGESINK_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_XVIMAGESINK))
|
||||
|
||||
typedef struct _GstXContext GstXContext;
|
||||
typedef struct _GstXWindow GstXWindow;
|
||||
typedef struct _GstXvImageFormat GstXvImageFormat;
|
||||
typedef struct _GstMetaXvImage GstMetaXvImage;
|
||||
|
||||
typedef struct _GstXvImageSink GstXvImageSink;
|
||||
typedef struct _GstXvImageSinkClass GstXvImageSinkClass;
|
||||
|
||||
#include "xvimagepool.h"
|
||||
|
||||
/*
|
||||
* GstXContext:
|
||||
* @disp: the X11 Display of this context
|
||||
|
@ -92,7 +91,8 @@ typedef struct _GstXvImageSinkClass GstXvImageSinkClass;
|
|||
* Structure used to store various informations collected/calculated for a
|
||||
* Display.
|
||||
*/
|
||||
struct _GstXContext {
|
||||
struct _GstXContext
|
||||
{
|
||||
Display *disp;
|
||||
|
||||
Screen *screen;
|
||||
|
@ -116,7 +116,7 @@ struct _GstXContext {
|
|||
|
||||
XvPortID xv_port_id;
|
||||
guint nb_adaptors;
|
||||
gchar ** adaptors;
|
||||
gchar **adaptors;
|
||||
gint im_format;
|
||||
|
||||
GList *formats_list;
|
||||
|
@ -142,7 +142,8 @@ struct _GstXContext {
|
|||
*
|
||||
* Structure used to store informations about a Window.
|
||||
*/
|
||||
struct _GstXWindow {
|
||||
struct _GstXWindow
|
||||
{
|
||||
Window win;
|
||||
gint width, height;
|
||||
gboolean internal;
|
||||
|
@ -156,51 +157,18 @@ struct _GstXWindow {
|
|||
*
|
||||
* Structure storing image format to #GstCaps association.
|
||||
*/
|
||||
struct _GstXvImageFormat {
|
||||
struct _GstXvImageFormat
|
||||
{
|
||||
gint format;
|
||||
GstCaps *caps;
|
||||
};
|
||||
|
||||
/**
|
||||
* GstXImageData:
|
||||
* @xvimagesink: a reference to our #GstXvImageSink
|
||||
* @xvimage: the XvImage of this buffer
|
||||
* @width: the width in pixels of XvImage @xvimage
|
||||
* @height: the height in pixels of XvImage @xvimage
|
||||
* @im_format: the image format of XvImage @xvimage
|
||||
* @size: the size in bytes of XvImage @xvimage
|
||||
*
|
||||
* Structure with additional information about an XvImage.
|
||||
*/
|
||||
struct _GstMetaXvImage {
|
||||
GstMeta meta;
|
||||
|
||||
/* Reference to the xvimagesink we belong to */
|
||||
GstXvImageSink *xvimagesink;
|
||||
|
||||
XvImage *xvimage;
|
||||
|
||||
#ifdef HAVE_XSHM
|
||||
XShmSegmentInfo SHMInfo;
|
||||
#endif /* HAVE_XSHM */
|
||||
|
||||
gint width, height, im_format;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
const GstMetaInfo * gst_meta_xvimage_get_info (void);
|
||||
|
||||
#define GST_META_XVIMAGE_GET(buf) ((GstMetaXvImage *)gst_buffer_get_meta(buf,gst_meta_xvimage_get_info()))
|
||||
#define GST_META_XVIMAGE_ADD(buf) ((GstMetaXvImage *)gst_buffer_add_meta(buf,gst_meta_xvimage_get_info(), NULL))
|
||||
|
||||
|
||||
/**
|
||||
* GstXvImageSink:
|
||||
* @display_name: the name of the Display we want to render to
|
||||
* @xcontext: our instance's #GstXContext
|
||||
* @xwindow: the #GstXWindow we are rendering to
|
||||
* @xvimage: internal #GstXvImage used to store incoming buffers and render when
|
||||
* not using the buffer_alloc optimization mechanism
|
||||
* @cur_image: a reference to the last #GstXvImage that was put to @xwindow. It
|
||||
* is used when Expose events are received to redraw the latest video frame
|
||||
* @event_thread: a thread listening for events on @xwindow and handling them
|
||||
|
@ -230,7 +198,8 @@ const GstMetaInfo * gst_meta_xvimage_get_info (void);
|
|||
*
|
||||
* The #GstXvImageSink data structure.
|
||||
*/
|
||||
struct _GstXvImageSink {
|
||||
struct _GstXvImageSink
|
||||
{
|
||||
/* Our element stuff */
|
||||
GstVideoSink videosink;
|
||||
|
||||
|
@ -255,9 +224,8 @@ struct _GstXvImageSink {
|
|||
/* object-set pixel aspect ratio */
|
||||
GValue *par;
|
||||
|
||||
GMutex *pool_lock;
|
||||
gboolean pool_invalid;
|
||||
GSList *image_pool;
|
||||
/* the buffer pool */
|
||||
GstBufferPool *pool;
|
||||
|
||||
gboolean synchronous;
|
||||
gboolean double_buffer;
|
||||
|
@ -282,14 +250,14 @@ struct _GstXvImageSink {
|
|||
/* port attributes */
|
||||
gboolean autopaint_colorkey;
|
||||
gint colorkey;
|
||||
|
||||
|
||||
gboolean draw_borders;
|
||||
|
||||
|
||||
/* port features */
|
||||
gboolean have_autopaint_colorkey;
|
||||
gboolean have_colorkey;
|
||||
gboolean have_double_buffer;
|
||||
|
||||
|
||||
/* stream metadata */
|
||||
gchar *media_title;
|
||||
|
||||
|
@ -298,12 +266,12 @@ struct _GstXvImageSink {
|
|||
gboolean have_render_rect;
|
||||
};
|
||||
|
||||
struct _GstXvImageSinkClass {
|
||||
struct _GstXvImageSinkClass
|
||||
{
|
||||
GstVideoSinkClass parent_class;
|
||||
};
|
||||
|
||||
GType gst_xvimagesink_get_type(void);
|
||||
GType gst_xvimagesink_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_XVIMAGESINK_H__ */
|
||||
|
|
Loading…
Reference in a new issue