mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 22:36:33 +00:00
fix define
Original commit message from CVS: fix define
This commit is contained in:
parent
799a576f2a
commit
fa97ee389e
2 changed files with 175 additions and 304 deletions
|
@ -36,6 +36,12 @@ static GstElementDetails gst_ximagesink_details = GST_ELEMENT_DETAILS (
|
||||||
"Julien Moutte <julien@moutte.net>"
|
"Julien Moutte <julien@moutte.net>"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
ARG_0,
|
||||||
|
ARG_DISPLAY_NAME
|
||||||
|
};
|
||||||
|
|
||||||
/* Default template - initiated with class struct to allow gst-register to work
|
/* Default template - initiated with class struct to allow gst-register to work
|
||||||
without X running */
|
without X running */
|
||||||
GST_PAD_TEMPLATE_FACTORY (gst_ximagesink_sink_template_factory,
|
GST_PAD_TEMPLATE_FACTORY (gst_ximagesink_sink_template_factory,
|
||||||
|
@ -74,30 +80,18 @@ gst_ximagesink_interface_init (GstInterfaceClass *klass)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_ximagesink_navigation_send_event (GstNavigation *navigation, GstStructure *structure)
|
gst_ximagesink_navigation_send_event (GstNavigation *navigation, GstCaps *caps)
|
||||||
{
|
{
|
||||||
GstXImageSink *ximagesink = GST_XIMAGESINK (navigation);
|
GstXImageSink *ximagesink = GST_XIMAGESINK (navigation);
|
||||||
XWindowAttributes attr;
|
|
||||||
GstEvent *event;
|
GstEvent *event;
|
||||||
double x, y;
|
|
||||||
|
|
||||||
g_mutex_lock (ximagesink->x_lock);
|
|
||||||
XGetWindowAttributes (ximagesink->xcontext->disp,
|
|
||||||
ximagesink->xwindow->win, &attr);
|
|
||||||
g_mutex_unlock (ximagesink->x_lock);
|
|
||||||
|
|
||||||
event = gst_event_new (GST_EVENT_NAVIGATION);
|
event = gst_event_new (GST_EVENT_NAVIGATION);
|
||||||
event->event_data.structure.structure = structure;
|
/*GST_EVENT_TIMESTAMP (event) = 0;*/
|
||||||
if(gst_structure_get_double(structure, "pointer_x", &x)){
|
event->event_data.caps.caps = caps;
|
||||||
x *= ximagesink->width;
|
|
||||||
x /= attr.width;
|
/* FIXME
|
||||||
gst_structure_set(structure, "pointer_x", G_TYPE_DOUBLE, x, NULL);
|
* Obviously, the pointer x,y coordinates need to be adjusted by the
|
||||||
}
|
* window size and relation to the bounding window. */
|
||||||
if(gst_structure_get_double(structure, "pointer_y", &y)){
|
|
||||||
y *= ximagesink->height;
|
|
||||||
y /= attr.height;
|
|
||||||
gst_structure_set(structure, "pointer_y", G_TYPE_DOUBLE, y, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
gst_pad_send_event (gst_pad_get_peer (ximagesink->sinkpad), event);
|
gst_pad_send_event (gst_pad_get_peer (ximagesink->sinkpad), event);
|
||||||
}
|
}
|
||||||
|
@ -110,7 +104,6 @@ gst_ximagesink_navigation_init (GstNavigationInterface *iface)
|
||||||
|
|
||||||
/* X11 stuff */
|
/* X11 stuff */
|
||||||
|
|
||||||
/* This function handles GstXImage creation depending on XShm availability */
|
|
||||||
static GstXImage *
|
static GstXImage *
|
||||||
gst_ximagesink_ximage_new (GstXImageSink *ximagesink, gint width, gint height)
|
gst_ximagesink_ximage_new (GstXImageSink *ximagesink, gint width, gint height)
|
||||||
{
|
{
|
||||||
|
@ -127,9 +120,22 @@ gst_ximagesink_ximage_new (GstXImageSink *ximagesink, gint width, gint height)
|
||||||
|
|
||||||
g_mutex_lock (ximagesink->x_lock);
|
g_mutex_lock (ximagesink->x_lock);
|
||||||
|
|
||||||
ximage->size = (ximagesink->xcontext->bpp / 8) * ximage->width * ximage->height;
|
GstXImage *ximage = NULL;
|
||||||
|
|
||||||
#ifdef HAVE_XSHM
|
g_return_val_if_fail (ximagesink != NULL, NULL);
|
||||||
|
g_return_val_if_fail (GST_IS_XIMAGESINK (ximagesink), NULL);
|
||||||
|
|
||||||
|
ximage = g_new0 (GstXImage, 1);
|
||||||
|
|
||||||
|
ximage->width = width;
|
||||||
|
ximage->height = height;
|
||||||
|
ximage->data = NULL;
|
||||||
|
|
||||||
|
g_mutex_lock (ximagesink->x_lock);
|
||||||
|
|
||||||
|
ximage->size = (ximagesink->xcontext->bpp / 8) * ximage->width * ximage->height;
|
||||||
|
|
||||||
|
#ifdef HAVE_SHM
|
||||||
if (ximagesink->xcontext->use_xshm)
|
if (ximagesink->xcontext->use_xshm)
|
||||||
{
|
{
|
||||||
ximage->ximage = XShmCreateImage (ximagesink->xcontext->disp,
|
ximage->ximage = XShmCreateImage (ximagesink->xcontext->disp,
|
||||||
|
@ -170,7 +176,9 @@ gst_ximagesink_ximage_new (GstXImageSink *ximagesink, gint width, gint height)
|
||||||
ximage->width, ximage->height,
|
ximage->width, ximage->height,
|
||||||
ximagesink->xcontext->bpp,
|
ximagesink->xcontext->bpp,
|
||||||
ximage->width * (ximagesink->xcontext->bpp / 8));
|
ximage->width * (ximagesink->xcontext->bpp / 8));
|
||||||
#endif /* HAVE_XSHM */
|
|
||||||
|
GST_DEBUG ("ximagesink creating an image without XShm");
|
||||||
|
#endif /* HAVE_SHM */
|
||||||
|
|
||||||
if (ximage->ximage)
|
if (ximage->ximage)
|
||||||
{
|
{
|
||||||
|
@ -201,7 +209,7 @@ gst_ximagesink_ximage_destroy (GstXImageSink *ximagesink, GstXImage *ximage)
|
||||||
|
|
||||||
g_mutex_lock (ximagesink->x_lock);
|
g_mutex_lock (ximagesink->x_lock);
|
||||||
|
|
||||||
#ifdef HAVE_XSHM
|
#ifdef HAVE_SHM
|
||||||
if (ximagesink->xcontext->use_xshm)
|
if (ximagesink->xcontext->use_xshm)
|
||||||
{
|
{
|
||||||
if (ximage->SHMInfo.shmaddr)
|
if (ximage->SHMInfo.shmaddr)
|
||||||
|
@ -224,7 +232,7 @@ gst_ximagesink_ximage_destroy (GstXImageSink *ximagesink, GstXImage *ximage)
|
||||||
#else
|
#else
|
||||||
if (ximage->ximage)
|
if (ximage->ximage)
|
||||||
XDestroyImage (ximage->ximage);
|
XDestroyImage (ximage->ximage);
|
||||||
#endif /* HAVE_XSHM */
|
#endif /* HAVE_SHM */
|
||||||
|
|
||||||
g_mutex_unlock (ximagesink->x_lock);
|
g_mutex_unlock (ximagesink->x_lock);
|
||||||
|
|
||||||
|
@ -251,7 +259,7 @@ gst_ximagesink_ximage_put (GstXImageSink *ximagesink, GstXImage *ximage)
|
||||||
x = MAX (0, (attr.width - ximage->width) / 2);
|
x = MAX (0, (attr.width - ximage->width) / 2);
|
||||||
y = MAX (0, (attr.height - ximage->height) / 2);
|
y = MAX (0, (attr.height - ximage->height) / 2);
|
||||||
|
|
||||||
#ifdef HAVE_XSHM
|
#ifdef HAVE_SHM
|
||||||
if (ximagesink->xcontext->use_xshm)
|
if (ximagesink->xcontext->use_xshm)
|
||||||
{
|
{
|
||||||
XShmPutImage (ximagesink->xcontext->disp, ximagesink->xwindow->win,
|
XShmPutImage (ximagesink->xcontext->disp, ximagesink->xwindow->win,
|
||||||
|
@ -269,9 +277,9 @@ gst_ximagesink_ximage_put (GstXImageSink *ximagesink, GstXImage *ximage)
|
||||||
XPutImage (ximagesink->xcontext->disp, ximagesink->xwindow->win,
|
XPutImage (ximagesink->xcontext->disp, ximagesink->xwindow->win,
|
||||||
ximagesink->xwindow->gc, ximage->ximage,
|
ximagesink->xwindow->gc, ximage->ximage,
|
||||||
0, 0, x, y, ximage->width, ximage->height);
|
0, 0, x, y, ximage->width, ximage->height);
|
||||||
#endif /* HAVE_XSHM */
|
#endif /* HAVE_SHM */
|
||||||
|
|
||||||
XSync(ximagesink->xcontext->disp, FALSE);
|
XSync (ximagesink->xcontext->disp, FALSE);
|
||||||
|
|
||||||
g_mutex_unlock (ximagesink->x_lock);
|
g_mutex_unlock (ximagesink->x_lock);
|
||||||
}
|
}
|
||||||
|
@ -450,10 +458,10 @@ gst_ximagesink_handle_xevents (GstXImageSink *ximagesink, GstPad *pad)
|
||||||
g_mutex_unlock (ximagesink->x_lock);
|
g_mutex_unlock (ximagesink->x_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function get the X Display and global infos about it. Everything is
|
/* This function gets the X Display and global infos about it. Everything is
|
||||||
stored in our object and will be cleaned when the object is disposed. Note
|
stored in our object and will be cleaned when the object is disposed. Note
|
||||||
here that caps for supported format are generated without any window or
|
here that caps for supported format are generated without any window or
|
||||||
image creation */
|
image creation. */
|
||||||
static GstXContext *
|
static GstXContext *
|
||||||
gst_ximagesink_xcontext_get (GstXImageSink *ximagesink)
|
gst_ximagesink_xcontext_get (GstXImageSink *ximagesink)
|
||||||
{
|
{
|
||||||
|
@ -507,7 +515,7 @@ gst_ximagesink_xcontext_get (GstXImageSink *ximagesink)
|
||||||
|
|
||||||
xcontext->endianness = (ImageByteOrder (xcontext->disp) == LSBFirst) ? G_LITTLE_ENDIAN:G_BIG_ENDIAN;
|
xcontext->endianness = (ImageByteOrder (xcontext->disp) == LSBFirst) ? G_LITTLE_ENDIAN:G_BIG_ENDIAN;
|
||||||
|
|
||||||
#ifdef HAVE_XSHM
|
#ifdef HAVE_SHM
|
||||||
/* Search for XShm extension support */
|
/* Search for XShm extension support */
|
||||||
if (XQueryExtension (xcontext->disp, "MIT-SHM", &i, &i, &i))
|
if (XQueryExtension (xcontext->disp, "MIT-SHM", &i, &i, &i))
|
||||||
{
|
{
|
||||||
|
@ -519,7 +527,7 @@ gst_ximagesink_xcontext_get (GstXImageSink *ximagesink)
|
||||||
xcontext->use_xshm = FALSE;
|
xcontext->use_xshm = FALSE;
|
||||||
GST_DEBUG ("ximagesink is not using XShm extension");
|
GST_DEBUG ("ximagesink is not using XShm extension");
|
||||||
}
|
}
|
||||||
#endif /* HAVE_XSHM */
|
#endif /* HAVE_SHM */
|
||||||
|
|
||||||
/* What the hell is that ? */
|
/* What the hell is that ? */
|
||||||
if (xcontext->endianness == G_LITTLE_ENDIAN && xcontext->depth == 24)
|
if (xcontext->endianness == G_LITTLE_ENDIAN && xcontext->depth == 24)
|
||||||
|
@ -564,116 +572,133 @@ gst_ximagesink_xcontext_clear (GstXImageSink *ximagesink)
|
||||||
|
|
||||||
XCloseDisplay (ximagesink->xcontext->disp);
|
XCloseDisplay (ximagesink->xcontext->disp);
|
||||||
|
|
||||||
g_mutex_unlock (ximagesink->x_lock);
|
GstClockID id = gst_clock_new_single_shot_id (ximagesink->clock, time);
|
||||||
|
gst_element_clock_wait (GST_ELEMENT (ximagesink), id, NULL);
|
||||||
|
gst_clock_id_free (id);
|
||||||
|
}
|
||||||
|
|
||||||
ximagesink->xcontext = NULL;
|
/* If we have a pool and the image is from this pool, simply put it. */
|
||||||
}
|
if ( (ximagesink->bufferpool) &&
|
||||||
|
(GST_BUFFER_BUFFERPOOL (buf) == ximagesink->bufferpool) )
|
||||||
/* Element stuff */
|
gst_ximagesink_ximage_put (ximagesink, GST_BUFFER_POOL_PRIVATE (buf));
|
||||||
|
else /* Else we have to copy the data into our private image, */
|
||||||
static GstCaps *
|
{ /* if we have one... */
|
||||||
gst_ximagesink_getcaps (GstPad *pad, GstCaps *caps)
|
if (ximagesink->ximage)
|
||||||
{
|
{
|
||||||
GstXImageSink *ximagesink;
|
memcpy (ximagesink->ximage->ximage->data,
|
||||||
|
GST_BUFFER_DATA (buf),
|
||||||
ximagesink = GST_XIMAGESINK (gst_pad_get_parent (pad));
|
MIN (GST_BUFFER_SIZE (buf), ximagesink->ximage->size));
|
||||||
|
gst_ximagesink_ximage_put (ximagesink, ximagesink->ximage);
|
||||||
if (ximagesink->xcontext)
|
}
|
||||||
return gst_caps_copy (ximagesink->xcontext->caps);
|
else /* No image available. Something went wrong during capsnego ! */
|
||||||
|
{
|
||||||
return GST_CAPS_NEW ("ximagesink_rgbsink", "video/x-raw-rgb",
|
gst_buffer_unref (buf);
|
||||||
"framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT),
|
gst_element_error (GST_ELEMENT (ximagesink), "no image to draw");
|
||||||
"width", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
return;
|
||||||
"height", GST_PROPS_INT_RANGE (0, G_MAXINT));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static GstPadLinkReturn
|
|
||||||
gst_ximagesink_sinkconnect (GstPad *pad, GstCaps *caps)
|
|
||||||
{
|
|
||||||
GstXImageSink *ximagesink;
|
|
||||||
|
|
||||||
ximagesink = GST_XIMAGESINK (gst_pad_get_parent (pad));
|
|
||||||
|
|
||||||
/* we are not going to act on variable caps */
|
|
||||||
if (!GST_CAPS_IS_FIXED (caps))
|
|
||||||
return GST_PAD_LINK_DELAYED;
|
|
||||||
if (GST_CAPS_IS_CHAINED (caps))
|
|
||||||
return GST_PAD_LINK_DELAYED;
|
|
||||||
|
|
||||||
GST_DEBUG ("sinkconnect %s with %s", gst_caps_to_string(caps),
|
|
||||||
gst_caps_to_string(ximagesink->xcontext->caps));
|
|
||||||
|
|
||||||
if (!gst_caps_get_int (caps, "width", &ximagesink->width))
|
|
||||||
return GST_PAD_LINK_REFUSED;
|
|
||||||
if (!gst_caps_get_int (caps, "height", &ximagesink->height))
|
|
||||||
return GST_PAD_LINK_REFUSED;
|
|
||||||
|
|
||||||
if (gst_caps_has_fixed_property (caps, "pixel_width"))
|
|
||||||
gst_caps_get_int (caps, "pixel_width", &ximagesink->pixel_width);
|
|
||||||
else
|
|
||||||
ximagesink->pixel_width = 1;
|
|
||||||
|
|
||||||
if (gst_caps_has_fixed_property (caps, "pixel_height"))
|
|
||||||
gst_caps_get_int (caps, "pixel_height", &ximagesink->pixel_height);
|
|
||||||
else
|
|
||||||
ximagesink->pixel_height = 1;
|
|
||||||
|
|
||||||
/* Creating our window and our image */
|
|
||||||
if (!ximagesink->xwindow)
|
|
||||||
ximagesink->xwindow = gst_ximagesink_xwindow_new (ximagesink,
|
|
||||||
ximagesink->width,
|
|
||||||
ximagesink->height);
|
|
||||||
else
|
|
||||||
{ /* We resize our window only if size has changed, preventing us from
|
|
||||||
infinite loops with XConfigure events.
|
|
||||||
if ( (ximagesink->width != ximagesink->xwindow->width) ||
|
|
||||||
(ximagesink->height != ximagesink->xwindow->height) )
|
|
||||||
gst_ximagesink_xwindow_resize (ximagesink, ximagesink->xwindow,
|
|
||||||
ximagesink->width, ximagesink->height);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (ximagesink->ximage) &&
|
gst_buffer_unref (buf);
|
||||||
( (ximagesink->width != ximagesink->ximage->width) ||
|
|
||||||
(ximagesink->height != ximagesink->ximage->height) ) )
|
|
||||||
{ /* We renew our ximage only if size changed */
|
|
||||||
gst_ximagesink_ximage_destroy (ximagesink, ximagesink->ximage);
|
|
||||||
|
|
||||||
ximagesink->ximage = gst_ximagesink_ximage_new (ximagesink,
|
|
||||||
ximagesink->width,
|
|
||||||
ximagesink->height);
|
|
||||||
}
|
|
||||||
else if (!ximagesink->ximage) /* If no ximage, creating one */
|
|
||||||
ximagesink->ximage = gst_ximagesink_ximage_new (ximagesink,
|
|
||||||
ximagesink->width,
|
|
||||||
ximagesink->height);
|
|
||||||
|
|
||||||
return GST_PAD_LINK_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstElementStateReturn
|
static void
|
||||||
gst_ximagesink_change_state (GstElement *element)
|
gst_ximagesink_get_property (GObject *object, guint prop_id,
|
||||||
|
GValue *value, GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
GstXImageSink *ximagesink;
|
||||||
|
|
||||||
|
g_return_if_fail (GST_IS_XIMAGESINK (object));
|
||||||
|
|
||||||
|
ximagesink = GST_XIMAGESINK (object);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_ximagesink_set_clock (GstElement *element, GstClock *clock)
|
||||||
{
|
{
|
||||||
GstXImageSink *ximagesink;
|
GstXImageSink *ximagesink;
|
||||||
|
|
||||||
ximagesink = GST_XIMAGESINK (element);
|
ximagesink = GST_XIMAGESINK (element);
|
||||||
|
|
||||||
|
ximagesink->clock = clock;
|
||||||
|
}
|
||||||
|
|
||||||
switch (GST_STATE_TRANSITION (element)) {
|
static GstBuffer*
|
||||||
case GST_STATE_NULL_TO_READY:
|
gst_ximagesink_buffer_new (GstBufferPool *pool,
|
||||||
/* Initializing the XContext */
|
gint64 location, guint size, gpointer user_data)
|
||||||
ximagesink->xcontext = gst_ximagesink_xcontext_get (ximagesink);
|
{
|
||||||
if (!ximagesink->xcontext)
|
GstXImageSink *ximagesink;
|
||||||
return GST_STATE_FAILURE;
|
GstBuffer *buffer;
|
||||||
break;
|
GstXImage *ximage = NULL;
|
||||||
case GST_STATE_READY_TO_PAUSED:
|
gboolean not_found = TRUE;
|
||||||
break;
|
|
||||||
case GST_STATE_PAUSED_TO_PLAYING:
|
ximagesink = GST_XIMAGESINK (user_data);
|
||||||
break;
|
|
||||||
case GST_STATE_PLAYING_TO_PAUSED:
|
g_mutex_lock (ximagesink->pool_lock);
|
||||||
break;
|
|
||||||
case GST_STATE_PAUSED_TO_READY:
|
/* Walking through the pool cleaning unsuable images and searching for a
|
||||||
break;
|
suitable one */
|
||||||
case GST_STATE_READY_TO_NULL:
|
while (not_found && ximagesink->image_pool)
|
||||||
break;
|
{
|
||||||
|
ximage = ximagesink->image_pool->data;
|
||||||
|
|
||||||
|
if (ximage)
|
||||||
|
{
|
||||||
|
/* Removing from the pool */
|
||||||
|
ximagesink->image_pool = g_slist_delete_link (ximagesink->image_pool,
|
||||||
|
ximagesink->image_pool);
|
||||||
|
|
||||||
|
if ( (ximage->width != ximagesink->width) ||
|
||||||
|
(ximage->height != ximagesink->height) )
|
||||||
|
{ /* This image is unusable. Destroying... */
|
||||||
|
gst_ximagesink_ximage_destroy (ximagesink, ximage);
|
||||||
|
ximage = NULL;
|
||||||
|
}
|
||||||
|
else /* We found a suitable image */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_mutex_unlock (ximagesink->pool_lock);
|
||||||
|
|
||||||
|
if (!ximage) /* We didn't find a suitable image in the pool. Creating... */
|
||||||
|
ximage = gst_ximagesink_ximage_new (ximagesink,
|
||||||
|
ximagesink->width,
|
||||||
|
ximagesink->height);
|
||||||
|
|
||||||
|
if (ximage)
|
||||||
|
{
|
||||||
|
buffer = gst_buffer_new ();
|
||||||
|
GST_BUFFER_POOL_PRIVATE (buffer) = ximage;
|
||||||
|
GST_BUFFER_DATA (buffer) = ximage->ximage->data;
|
||||||
|
GST_BUFFER_SIZE (buffer) = ximage->size;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_ximagesink_buffer_free (GstBufferPool *pool,
|
||||||
|
GstBuffer *buffer, gpointer user_data)
|
||||||
|
{
|
||||||
|
GstXImageSink *ximagesink;
|
||||||
|
GstXImage *ximage;
|
||||||
|
|
||||||
|
ximagesink = GST_XIMAGESINK (user_data);
|
||||||
|
|
||||||
|
ximage = GST_BUFFER_POOL_PRIVATE (buffer);
|
||||||
|
|
||||||
|
/* If our geometry changed we can't reuse that image. */
|
||||||
|
if ( (ximage->width != ximagesink->width) ||
|
||||||
|
(ximage->height != ximagesink->height) )
|
||||||
|
{
|
||||||
|
gst_ximagesink_ximage_destroy (ximagesink, ximage);
|
||||||
|
}
|
||||||
|
else /* If it didn't we can reuse the image and add it to our image pool. */
|
||||||
|
{
|
||||||
|
g_mutex_lock (ximagesink->pool_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent_class->change_state)
|
if (parent_class->change_state)
|
||||||
|
@ -794,161 +819,6 @@ gst_ximagesink_buffer_new (GstBufferPool *pool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_mutex_unlock (ximagesink->pool_lock);
|
|
||||||
|
|
||||||
if (!ximage) /* We found no suitable image in the pool. Creating... */
|
|
||||||
ximage = gst_ximagesink_ximage_new (ximagesink,
|
|
||||||
ximagesink->width,
|
|
||||||
ximagesink->height);
|
|
||||||
|
|
||||||
if (ximage)
|
|
||||||
{
|
|
||||||
buffer = gst_buffer_new ();
|
|
||||||
GST_BUFFER_POOL_PRIVATE (buffer) = ximage;
|
|
||||||
GST_BUFFER_DATA (buffer) = ximage->ximage->data;
|
|
||||||
GST_BUFFER_SIZE (buffer) = ximage->size;
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_ximagesink_buffer_free (GstBufferPool *pool,
|
|
||||||
GstBuffer *buffer, gpointer user_data)
|
|
||||||
{
|
|
||||||
GstXImageSink *ximagesink;
|
|
||||||
GstXImage *ximage;
|
|
||||||
|
|
||||||
ximagesink = GST_XIMAGESINK (user_data);
|
|
||||||
|
|
||||||
ximage = GST_BUFFER_POOL_PRIVATE (buffer);
|
|
||||||
|
|
||||||
/* If our geometry changed we can't reuse that image. */
|
|
||||||
if ( (ximage->width != ximagesink->width) ||
|
|
||||||
(ximage->height != ximagesink->height) )
|
|
||||||
gst_ximagesink_ximage_destroy (ximagesink, ximage);
|
|
||||||
else /* In that case we can reuse the image and add it to our image pool. */
|
|
||||||
{
|
|
||||||
g_mutex_lock (ximagesink->pool_lock);
|
|
||||||
ximagesink->image_pool = g_slist_prepend (ximagesink->image_pool, ximage);
|
|
||||||
g_mutex_unlock (ximagesink->pool_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_BUFFER_DATA (buffer) = NULL;
|
|
||||||
|
|
||||||
gst_buffer_default_free (buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_ximagesink_imagepool_clear (GstXImageSink *ximagesink)
|
|
||||||
{
|
|
||||||
g_mutex_lock(ximagesink->pool_lock);
|
|
||||||
|
|
||||||
while (ximagesink->image_pool)
|
|
||||||
{
|
|
||||||
GstXImage *ximage = ximagesink->image_pool->data;
|
|
||||||
ximagesink->image_pool = g_slist_delete_link (ximagesink->image_pool,
|
|
||||||
ximagesink->image_pool);
|
|
||||||
gst_ximagesink_ximage_destroy (ximagesink, ximage);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_mutex_unlock(ximagesink->pool_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstBufferPool*
|
|
||||||
gst_ximagesink_get_bufferpool (GstPad *pad)
|
|
||||||
{
|
|
||||||
GstXImageSink *ximagesink;
|
|
||||||
|
|
||||||
ximagesink = GST_XIMAGESINK (gst_pad_get_parent (pad));
|
|
||||||
|
|
||||||
if (!ximagesink->bufferpool) {
|
|
||||||
ximagesink->bufferpool = gst_buffer_pool_new (
|
|
||||||
NULL, /* free */
|
|
||||||
NULL, /* copy */
|
|
||||||
(GstBufferPoolBufferNewFunction) gst_ximagesink_buffer_new,
|
|
||||||
NULL, /* buffer copy, the default is fine */
|
|
||||||
(GstBufferPoolBufferFreeFunction) gst_ximagesink_buffer_free,
|
|
||||||
ximagesink);
|
|
||||||
|
|
||||||
ximagesink->image_pool = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
gst_buffer_pool_ref (ximagesink->bufferpool);
|
|
||||||
|
|
||||||
return ximagesink->bufferpool;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* =========================================== */
|
|
||||||
/* */
|
|
||||||
/* Init & Class init */
|
|
||||||
/* */
|
|
||||||
/* =========================================== */
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_ximagesink_dispose (GObject *object)
|
|
||||||
{
|
|
||||||
GstXImageSink *ximagesink;
|
|
||||||
|
|
||||||
ximagesink = GST_XIMAGESINK (object);
|
|
||||||
|
|
||||||
if (ximagesink->ximage)
|
|
||||||
{
|
|
||||||
gst_ximagesink_ximage_destroy (ximagesink, ximagesink->ximage);
|
|
||||||
ximagesink->ximage = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ximagesink->image_pool)
|
|
||||||
gst_ximagesink_imagepool_clear (ximagesink);
|
|
||||||
|
|
||||||
if (ximagesink->xwindow)
|
|
||||||
{
|
|
||||||
gst_ximagesink_xwindow_destroy (ximagesink, ximagesink->xwindow);
|
|
||||||
ximagesink->xwindow = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ximagesink->xcontext)
|
|
||||||
gst_ximagesink_xcontext_clear (ximagesink);
|
|
||||||
|
|
||||||
g_mutex_free (ximagesink->x_lock);
|
|
||||||
g_mutex_free (ximagesink->pool_lock);
|
|
||||||
|
|
||||||
if (ximagesink->bufferpool)
|
|
||||||
gst_buffer_pool_free (ximagesink->bufferpool);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_ximagesink_init (GstXImageSink *ximagesink)
|
|
||||||
{
|
|
||||||
ximagesink->sinkpad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (
|
|
||||||
gst_ximagesink_sink_template_factory),
|
|
||||||
"sink");
|
|
||||||
gst_element_add_pad (GST_ELEMENT (ximagesink), ximagesink->sinkpad);
|
|
||||||
|
|
||||||
gst_pad_set_chain_function (ximagesink->sinkpad, gst_ximagesink_chain);
|
|
||||||
gst_pad_set_link_function (ximagesink->sinkpad, gst_ximagesink_sinkconnect);
|
|
||||||
gst_pad_set_getcaps_function (ximagesink->sinkpad, gst_ximagesink_getcaps);
|
|
||||||
gst_pad_set_bufferpool_function (ximagesink->sinkpad,
|
|
||||||
gst_ximagesink_get_bufferpool);
|
|
||||||
|
|
||||||
ximagesink->xcontext = NULL;
|
|
||||||
ximagesink->xwindow = NULL;
|
|
||||||
ximagesink->ximage = NULL;
|
|
||||||
ximagesink->clock = NULL;
|
|
||||||
|
|
||||||
ximagesink->width = ximagesink->height = 0;
|
|
||||||
|
|
||||||
ximagesink->x_lock = g_mutex_new ();
|
|
||||||
|
|
||||||
ximagesink->pixel_width = ximagesink->pixel_height = 1;
|
|
||||||
|
|
||||||
ximagesink->image_pool = NULL;
|
|
||||||
ximagesink->pool_lock = g_mutex_new ();
|
|
||||||
|
|
||||||
GST_FLAG_SET(ximagesink, GST_ELEMENT_THREAD_SUGGESTED);
|
|
||||||
GST_FLAG_SET(ximagesink, GST_ELEMENT_EVENT_AWARE);
|
GST_FLAG_SET(ximagesink, GST_ELEMENT_EVENT_AWARE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -973,9 +843,13 @@ gst_ximagesink_class_init (GstXImageSinkClass *klass)
|
||||||
gstelement_class = (GstElementClass *) klass;
|
gstelement_class = (GstElementClass *) klass;
|
||||||
|
|
||||||
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
||||||
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DISPLAY_NAME,
|
||||||
|
g_param_spec_string ("displayname", "displayname", "Name of display to use",
|
||||||
|
NULL, G_PARAM_READABLE));
|
||||||
|
|
||||||
|
gobject_class->set_property = gst_ximagesink_set_property;
|
||||||
|
gobject_class->get_property = gst_ximagesink_get_property;
|
||||||
|
|
||||||
gobject_class->dispose = gst_ximagesink_dispose;
|
|
||||||
|
|
||||||
gstelement_class->change_state = gst_ximagesink_change_state;
|
gstelement_class->change_state = gst_ximagesink_change_state;
|
||||||
gstelement_class->set_clock = gst_ximagesink_set_clock;
|
gstelement_class->set_clock = gst_ximagesink_set_clock;
|
||||||
}
|
}
|
||||||
|
@ -1026,9 +900,10 @@ gst_ximagesink_get_type (void)
|
||||||
NULL,
|
NULL,
|
||||||
};*/
|
};*/
|
||||||
|
|
||||||
ximagesink_type = g_type_register_static (GST_TYPE_ELEMENT,
|
ximagesink_type = g_type_register_static(GST_TYPE_ELEMENT,
|
||||||
"GstXImageSink",
|
"GstXImageSink",
|
||||||
&ximagesink_info, 0);
|
&ximagesink_info,
|
||||||
|
0);
|
||||||
|
|
||||||
g_type_add_interface_static (ximagesink_type, GST_TYPE_INTERFACE,
|
g_type_add_interface_static (ximagesink_type, GST_TYPE_INTERFACE,
|
||||||
&iface_info);
|
&iface_info);
|
||||||
|
@ -1044,8 +919,7 @@ gst_ximagesink_get_type (void)
|
||||||
static gboolean
|
static gboolean
|
||||||
plugin_init (GstPlugin *plugin)
|
plugin_init (GstPlugin *plugin)
|
||||||
{
|
{
|
||||||
if (!gst_element_register (plugin, "ximagesink",
|
if (!gst_element_register (plugin, "ximagesink", GST_RANK_NONE, GST_TYPE_XIMAGESINK))
|
||||||
GST_RANK_SECONDARY, GST_TYPE_XIMAGESINK))
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
@ -22,20 +22,17 @@
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
|
||||||
/* FIXME : We should have a configure test for shm support */
|
#ifdef HAVE_SHM
|
||||||
#define HAVE_XSHM
|
|
||||||
|
|
||||||
#ifdef HAVE_XSHM
|
|
||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
#include <sys/shm.h>
|
#include <sys/shm.h>
|
||||||
#endif /* HAVE_XSHM */
|
#endif /* HAVE_SHM */
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
|
|
||||||
#ifdef HAVE_XSHM
|
#ifdef HAVE_SHM
|
||||||
#include <X11/extensions/XShm.h>
|
#include <X11/extensions/XShm.h>
|
||||||
#endif /* HAVE_XSHM */
|
#endif /* HAVE_SHM */
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -93,9 +90,9 @@ struct _GstXWindow {
|
||||||
struct _GstXImage {
|
struct _GstXImage {
|
||||||
XImage *ximage;
|
XImage *ximage;
|
||||||
|
|
||||||
#ifdef HAVE_XSHM
|
#ifdef HAVE_SHM
|
||||||
XShmSegmentInfo SHMInfo;
|
XShmSegmentInfo SHMInfo;
|
||||||
#endif /* HAVE_XSHM */
|
#endif /* HAVE_SHM */
|
||||||
|
|
||||||
char *data;
|
char *data;
|
||||||
gint width, height, size;
|
gint width, height, size;
|
||||||
|
@ -128,7 +125,7 @@ struct _GstXImageSinkClass {
|
||||||
GstElementClass parent_class;
|
GstElementClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gst_ximagesink_get_type(void);
|
GType gst_ximagesink_get_type (void);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue