miniobject: port to 0.11

Use buffer private data instead of subclassing.
This commit is contained in:
Wim Taymans 2011-02-24 13:51:32 +01:00
parent 8131d1157f
commit d90a388289
7 changed files with 178 additions and 246 deletions

View file

@ -52,23 +52,24 @@
GST_DEBUG_CATEGORY_EXTERN (v4l2_debug);
#define GST_CAT_DEFAULT v4l2_debug
/*
* GstV4l2Buffer:
*/
static GstBufferClass *v4l2buffer_parent_class = NULL;
static void
gst_v4l2_buffer_finalize (GstV4l2Buffer * buffer)
gst_v4l2_buffer_dispose (GstBuffer * buffer)
{
GstV4l2Data *data;
GstV4l2BufferPool *pool;
gboolean resuscitated = FALSE;
gint index;
pool = buffer->pool;
data = GST_V4L2_GET_DATA (buffer);
g_assert (data != NULL);
index = buffer->vbuffer.index;
pool = data->pool;
index = data->vbuffer.index;
GST_LOG_OBJECT (pool->v4l2elem, "finalizing buffer %p %d", buffer, index);
@ -95,7 +96,7 @@ gst_v4l2_buffer_finalize (GstV4l2Buffer * buffer)
if (resuscitated) {
/* FIXME: check that the caps didn't change */
GST_LOG_OBJECT (pool->v4l2elem, "reviving buffer %p, %d", buffer, index);
gst_buffer_ref (GST_BUFFER (buffer));
gst_buffer_ref (buffer);
GST_BUFFER_SIZE (buffer) = 0;
pool->buffers[index] = buffer;
}
@ -105,96 +106,65 @@ gst_v4l2_buffer_finalize (GstV4l2Buffer * buffer)
if (!resuscitated) {
GST_LOG_OBJECT (pool->v4l2elem,
"buffer %p (data %p, len %u) not recovered, unmapping",
buffer, GST_BUFFER_DATA (buffer), buffer->vbuffer.length);
gst_mini_object_unref (GST_MINI_OBJECT (pool));
v4l2_munmap ((void *) GST_BUFFER_DATA (buffer), buffer->vbuffer.length);
buffer, GST_BUFFER_DATA (buffer), data->vbuffer.length);
v4l2_munmap ((void *) GST_BUFFER_DATA (buffer), data->vbuffer.length);
GST_MINI_OBJECT_CLASS (v4l2buffer_parent_class)->finalize (GST_MINI_OBJECT
(buffer));
g_object_unref (pool);
g_slice_free (GstV4l2Data, data);
buffer->owner_priv = NULL;
}
}
static void
gst_v4l2_buffer_class_init (gpointer g_class, gpointer class_data)
{
GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class);
v4l2buffer_parent_class = g_type_class_peek_parent (g_class);
mini_object_class->finalize = (GstMiniObjectFinalizeFunction)
gst_v4l2_buffer_finalize;
}
GType
gst_v4l2_buffer_get_type (void)
{
static GType _gst_v4l2_buffer_type;
if (G_UNLIKELY (_gst_v4l2_buffer_type == 0)) {
static const GTypeInfo v4l2_buffer_info = {
sizeof (GstBufferClass),
NULL,
NULL,
gst_v4l2_buffer_class_init,
NULL,
NULL,
sizeof (GstV4l2Buffer),
0,
NULL,
NULL
};
_gst_v4l2_buffer_type = g_type_register_static (GST_TYPE_BUFFER,
"GstV4l2Buffer", &v4l2_buffer_info, 0);
}
return _gst_v4l2_buffer_type;
}
static GstV4l2Buffer *
static GstBuffer *
gst_v4l2_buffer_new (GstV4l2BufferPool * pool, guint index, GstCaps * caps)
{
GstV4l2Buffer *ret;
guint8 *data;
GstV4l2Data *data;
GstBuffer *ret;
guint8 *mem;
ret = (GstV4l2Buffer *) gst_mini_object_new (GST_TYPE_V4L2_BUFFER);
ret = gst_buffer_new ();
data = g_slice_new (GstV4l2Data);
ret->owner_priv = data;
GST_MINI_OBJECT_CAST (ret)->dispose =
(GstMiniObjectDisposeFunction) gst_v4l2_buffer_dispose;
GST_LOG_OBJECT (pool->v4l2elem, "creating buffer %u, %p in pool %p", index,
ret, pool);
ret->pool =
(GstV4l2BufferPool *) gst_mini_object_ref (GST_MINI_OBJECT (pool));
data->pool = (GstV4l2BufferPool *) g_object_ref (pool);
ret->vbuffer.index = index;
ret->vbuffer.type = pool->type;
ret->vbuffer.memory = V4L2_MEMORY_MMAP;
data->vbuffer.index = index;
data->vbuffer.type = pool->type;
data->vbuffer.memory = V4L2_MEMORY_MMAP;
if (v4l2_ioctl (pool->video_fd, VIDIOC_QUERYBUF, &ret->vbuffer) < 0)
if (v4l2_ioctl (pool->video_fd, VIDIOC_QUERYBUF, &data->vbuffer) < 0)
goto querybuf_failed;
GST_LOG_OBJECT (pool->v4l2elem, " index: %u", ret->vbuffer.index);
GST_LOG_OBJECT (pool->v4l2elem, " type: %d", ret->vbuffer.type);
GST_LOG_OBJECT (pool->v4l2elem, " bytesused: %u", ret->vbuffer.bytesused);
GST_LOG_OBJECT (pool->v4l2elem, " flags: %08x", ret->vbuffer.flags);
GST_LOG_OBJECT (pool->v4l2elem, " field: %d", ret->vbuffer.field);
GST_LOG_OBJECT (pool->v4l2elem, " memory: %d", ret->vbuffer.memory);
if (ret->vbuffer.memory == V4L2_MEMORY_MMAP)
GST_LOG_OBJECT (pool->v4l2elem, " index: %u", data->vbuffer.index);
GST_LOG_OBJECT (pool->v4l2elem, " type: %d", data->vbuffer.type);
GST_LOG_OBJECT (pool->v4l2elem, " bytesused: %u", data->vbuffer.bytesused);
GST_LOG_OBJECT (pool->v4l2elem, " flags: %08x", data->vbuffer.flags);
GST_LOG_OBJECT (pool->v4l2elem, " field: %d", data->vbuffer.field);
GST_LOG_OBJECT (pool->v4l2elem, " memory: %d", data->vbuffer.memory);
if (data->vbuffer.memory == V4L2_MEMORY_MMAP)
GST_LOG_OBJECT (pool->v4l2elem, " MMAP offset: %u",
ret->vbuffer.m.offset);
GST_LOG_OBJECT (pool->v4l2elem, " length: %u", ret->vbuffer.length);
GST_LOG_OBJECT (pool->v4l2elem, " input: %u", ret->vbuffer.input);
data->vbuffer.m.offset);
GST_LOG_OBJECT (pool->v4l2elem, " length: %u", data->vbuffer.length);
GST_LOG_OBJECT (pool->v4l2elem, " input: %u", data->vbuffer.input);
data = (guint8 *) v4l2_mmap (0, ret->vbuffer.length,
mem = (guint8 *) v4l2_mmap (0, data->vbuffer.length,
PROT_READ | PROT_WRITE, MAP_SHARED, pool->video_fd,
ret->vbuffer.m.offset);
data->vbuffer.m.offset);
if (data == MAP_FAILED)
if (mem == MAP_FAILED)
goto mmap_failed;
GST_BUFFER_DATA (ret) = data;
GST_BUFFER_SIZE (ret) = ret->vbuffer.length;
GST_BUFFER_DATA (ret) = mem;
GST_BUFFER_SIZE (ret) = data->vbuffer.length;
GST_BUFFER_FLAG_SET (ret, GST_BUFFER_FLAG_READONLY);
gst_buffer_set_caps (GST_BUFFER (ret), caps);
gst_buffer_set_caps (ret, caps);
return ret;
@ -204,7 +174,7 @@ querybuf_failed:
gint errnosave = errno;
GST_WARNING ("Failed QUERYBUF: %s", g_strerror (errnosave));
gst_buffer_unref (GST_BUFFER (ret));
gst_buffer_unref (ret);
errno = errnosave;
return NULL;
}
@ -213,7 +183,7 @@ mmap_failed:
gint errnosave = errno;
GST_WARNING ("Failed to mmap: %s", g_strerror (errnosave));
gst_buffer_unref (GST_BUFFER (ret));
gst_buffer_unref (ret);
errno = errnosave;
return NULL;
}
@ -224,11 +194,13 @@ mmap_failed:
* GstV4l2BufferPool:
*/
static GstMiniObjectClass *buffer_pool_parent_class = NULL;
static GObjectClass *buffer_pool_parent_class = NULL;
static void
gst_v4l2_buffer_pool_finalize (GstV4l2BufferPool * pool)
gst_v4l2_buffer_pool_finalize (GObject * object)
{
GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (object);
g_mutex_free (pool->lock);
pool->lock = NULL;
@ -243,8 +215,7 @@ gst_v4l2_buffer_pool_finalize (GstV4l2BufferPool * pool)
pool->buffers = NULL;
}
GST_MINI_OBJECT_CLASS (buffer_pool_parent_class)->finalize (GST_MINI_OBJECT
(pool));
buffer_pool_parent_class->finalize (object);
}
static void
@ -258,12 +229,11 @@ gst_v4l2_buffer_pool_init (GstV4l2BufferPool * pool, gpointer g_class)
static void
gst_v4l2_buffer_pool_class_init (gpointer g_class, gpointer class_data)
{
GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class);
GObjectClass *object_class = G_OBJECT_CLASS (g_class);
buffer_pool_parent_class = g_type_class_peek_parent (g_class);
mini_object_class->finalize = (GstMiniObjectFinalizeFunction)
gst_v4l2_buffer_pool_finalize;
object_class->finalize = gst_v4l2_buffer_pool_finalize;
}
GType
@ -273,7 +243,7 @@ gst_v4l2_buffer_pool_get_type (void)
if (G_UNLIKELY (_gst_v4l2_buffer_pool_type == 0)) {
static const GTypeInfo v4l2_buffer_pool_info = {
sizeof (GstMiniObjectClass),
sizeof (GObjectClass),
NULL,
NULL,
gst_v4l2_buffer_pool_class_init,
@ -284,7 +254,7 @@ gst_v4l2_buffer_pool_get_type (void)
(GInstanceInitFunc) gst_v4l2_buffer_pool_init,
NULL
};
_gst_v4l2_buffer_pool_type = g_type_register_static (GST_TYPE_MINI_OBJECT,
_gst_v4l2_buffer_pool_type = g_type_register_static (G_TYPE_OBJECT,
"GstV4l2BufferPool", &v4l2_buffer_pool_info, 0);
}
return _gst_v4l2_buffer_pool_type;
@ -335,7 +305,7 @@ gst_v4l2_buffer_pool_new (GstElement * v4l2elem, gint fd, gint num_buffers,
gint n;
struct v4l2_requestbuffers breq;
pool = (GstV4l2BufferPool *) gst_mini_object_new (GST_TYPE_V4L2_BUFFER_POOL);
pool = (GstV4l2BufferPool *) g_object_new (GST_TYPE_V4L2_BUFFER_POOL, NULL);
pool->video_fd = v4l2_dup (fd);
if (pool->video_fd < 0)
@ -370,7 +340,7 @@ gst_v4l2_buffer_pool_new (GstElement * v4l2elem, gint fd, gint num_buffers,
pool->requeuebuf = requeuebuf;
pool->type = type;
pool->buffer_count = num_buffers;
pool->buffers = g_new0 (GstV4l2Buffer *, num_buffers);
pool->buffers = g_new0 (GstBuffer *, num_buffers);
pool->avail_buffers = g_async_queue_new ();
/* now, map the buffers: */
@ -389,7 +359,7 @@ dup_failed:
{
gint errnosave = errno;
gst_mini_object_unref (GST_MINI_OBJECT (pool));
g_object_unref (pool);
errno = errnosave;
@ -461,7 +431,7 @@ gst_v4l2_buffer_pool_destroy (GstV4l2BufferPool * pool)
gst_buffer_unref (buf);
}
gst_mini_object_unref (GST_MINI_OBJECT (pool));
g_object_unref (pool);
}
/**
@ -472,10 +442,10 @@ gst_v4l2_buffer_pool_destroy (GstV4l2BufferPool * pool)
*
* Get an available buffer in the pool
*/
GstV4l2Buffer *
GstBuffer *
gst_v4l2_buffer_pool_get (GstV4l2BufferPool * pool, gboolean blocking)
{
GstV4l2Buffer *buf;
GstBuffer *buf;
if (blocking) {
buf = g_async_queue_pop (pool->avail_buffers);
@ -485,7 +455,7 @@ gst_v4l2_buffer_pool_get (GstV4l2BufferPool * pool, gboolean blocking)
if (buf) {
GST_V4L2_BUFFER_POOL_LOCK (pool);
GST_BUFFER_SIZE (buf) = buf->vbuffer.length;
GST_BUFFER_SIZE (buf) = GST_V4L2_GET_DATA (buf)->vbuffer.length;
GST_BUFFER_FLAG_UNSET (buf, 0xffffffff);
GST_V4L2_BUFFER_POOL_UNLOCK (pool);
}
@ -506,11 +476,14 @@ gst_v4l2_buffer_pool_get (GstV4l2BufferPool * pool, gboolean blocking)
* Returns: %TRUE for success
*/
gboolean
gst_v4l2_buffer_pool_qbuf (GstV4l2BufferPool * pool, GstV4l2Buffer * buf)
gst_v4l2_buffer_pool_qbuf (GstV4l2BufferPool * pool, GstBuffer * buf)
{
GST_LOG_OBJECT (pool->v4l2elem, "enqueue pool buffer %d", buf->vbuffer.index);
GstV4l2Data *data = GST_V4L2_GET_DATA (buf);
if (v4l2_ioctl (pool->video_fd, VIDIOC_QBUF, &buf->vbuffer) < 0)
GST_LOG_OBJECT (pool->v4l2elem, "enqueue pool buffer %d",
data->vbuffer.index);
if (v4l2_ioctl (pool->video_fd, VIDIOC_QBUF, &data->vbuffer) < 0)
return FALSE;
pool->num_live_buffers--;
@ -530,18 +503,17 @@ gst_v4l2_buffer_pool_qbuf (GstV4l2BufferPool * pool, GstV4l2Buffer * buf)
*
* Returns: a buffer
*/
GstV4l2Buffer *
GstBuffer *
gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool * pool)
{
GstV4l2Object *v4l2object = get_v4l2_object (pool->v4l2elem);
GstV4l2Buffer *pool_buffer;
GstBuffer *pool_buffer;
struct v4l2_buffer buffer;
memset (&buffer, 0x00, sizeof (buffer));
buffer.type = pool->type;
buffer.memory = V4L2_MEMORY_MMAP;
if (v4l2_ioctl (pool->video_fd, VIDIOC_DQBUF, &buffer) >= 0) {
GST_V4L2_BUFFER_POOL_LOCK (pool);

View file

@ -46,12 +46,12 @@ GType gst_v4l2_buffer_pool_get_type (void);
typedef struct _GstV4l2BufferPool GstV4l2BufferPool;
typedef struct _GstV4l2Buffer GstV4l2Buffer;
typedef struct _GstV4l2Data GstV4l2Data;
struct _GstV4l2BufferPool
{
GstMiniObject parent;
GObject parent;
GstElement *v4l2elem; /* the v4l2 src/sink that owns us.. maybe we should be owned by v4l2object? */
gboolean requeuebuf; /* if true, unusued buffers are automatically re-QBUF'd */
@ -63,12 +63,12 @@ struct _GstV4l2BufferPool
GAsyncQueue* avail_buffers;/* pool of available buffers, not with the driver and which aren't held outside the bufferpool */
gint video_fd; /* a dup(2) of the v4l2object's video_fd */
guint buffer_count;
GstV4l2Buffer **buffers;
GstBuffer **buffers;
};
struct _GstV4l2Buffer {
GstBuffer buffer;
#define GST_V4L2_GET_DATA(buf) ((GstV4l2Data *) (GST_BUFFER_CAST (buf)->owner_priv))
struct _GstV4l2Data {
struct v4l2_buffer vbuffer;
/* FIXME: have GstV4l2Src* instead, as this has GstV4l2BufferPool* */
@ -82,9 +82,9 @@ void gst_v4l2_buffer_pool_destroy (GstV4l2BufferPool * pool);
GstV4l2BufferPool *gst_v4l2_buffer_pool_new (GstElement *v4l2elem, gint fd, gint num_buffers, GstCaps * caps, gboolean requeuebuf, enum v4l2_buf_type type);
GstV4l2Buffer *gst_v4l2_buffer_pool_get (GstV4l2BufferPool *pool, gboolean blocking);
gboolean gst_v4l2_buffer_pool_qbuf (GstV4l2BufferPool *pool, GstV4l2Buffer *buf);
GstV4l2Buffer *gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool *pool);
GstBuffer *gst_v4l2_buffer_pool_get (GstV4l2BufferPool *pool, gboolean blocking);
gboolean gst_v4l2_buffer_pool_qbuf (GstV4l2BufferPool *pool, GstBuffer *buf);
GstBuffer *gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool *pool);
gint gst_v4l2_buffer_pool_available_buffers (GstV4l2BufferPool *pool);

View file

@ -66,7 +66,7 @@ static gboolean
gst_v4l2src_buffer_pool_activate (GstV4l2BufferPool * pool,
GstV4l2Src * v4l2src)
{
GstV4l2Buffer *buf;
GstBuffer *buf;
while ((buf = gst_v4l2_buffer_pool_get (pool, FALSE)) != NULL)
if (!gst_v4l2_buffer_pool_qbuf (pool, buf))
@ -81,7 +81,8 @@ queue_failed:
(_("Could not enqueue buffers in device '%s'."),
v4l2src->v4l2object->videodev),
("enqueing buffer %d/%d failed: %s",
buf->vbuffer.index, v4l2src->num_buffers, g_strerror (errno)));
GST_V4L2_GET_DATA (buf)->vbuffer.index, v4l2src->num_buffers,
g_strerror (errno)));
return FALSE;
}
}

View file

@ -80,24 +80,24 @@ static void gst_ximage_src_clear_bufpool (GstXImageSrc * ximagesrc);
/* Called when a buffer is returned from the pipeline */
static void
gst_ximage_src_return_buf (GstXImageSrc * ximagesrc,
GstXImageSrcBuffer * ximage)
gst_ximage_src_return_buf (GstXImageSrc * ximagesrc, GstBuffer * ximage)
{
GstXImageData *data = GST_XIMAGE_GET_DATA (ximage);
/* If our geometry changed we can't reuse that image. */
if ((ximage->width != ximagesrc->width) ||
(ximage->height != ximagesrc->height)) {
if ((data->width != ximagesrc->width) || (data->height != ximagesrc->height)) {
GST_DEBUG_OBJECT (ximagesrc,
"destroy image %p as its size changed %dx%d vs current %dx%d",
ximage, ximage->width, ximage->height,
ximagesrc->width, ximagesrc->height);
ximage, data->width, data->height, ximagesrc->width, ximagesrc->height);
g_mutex_lock (ximagesrc->x_lock);
gst_ximageutil_ximage_destroy (ximagesrc->xcontext, ximage);
g_slice_free (GstXImageData, data);
g_mutex_unlock (ximagesrc->x_lock);
} else {
/* In that case we can reuse the image and add it to our image pool. */
GST_LOG_OBJECT (ximagesrc, "recycling image %p in pool", ximage);
/* need to increment the refcount again to recycle */
gst_buffer_ref (GST_BUFFER (ximage));
gst_buffer_ref (ximage);
g_mutex_lock (ximagesrc->pool_lock);
ximagesrc->buffer_pool = g_slist_prepend (ximagesrc->buffer_pool, ximage);
g_mutex_unlock (ximagesrc->pool_lock);
@ -358,17 +358,20 @@ composite_pixel (GstXContext * xcontext, guchar * dest, guchar * src)
/* Retrieve an XImageSrcBuffer, preferably from our
* pool of existing images and populate it from the window */
static GstXImageSrcBuffer *
static GstBuffer *
gst_ximage_src_ximage_get (GstXImageSrc * ximagesrc)
{
GstXImageSrcBuffer *ximage = NULL;
GstBuffer *ximage = NULL;
GstXImageData *data;
g_mutex_lock (ximagesrc->pool_lock);
while (ximagesrc->buffer_pool != NULL) {
ximage = ximagesrc->buffer_pool->data;
if ((ximage->width != ximagesrc->width) ||
(ximage->height != ximagesrc->height)) {
data = GST_XIMAGE_GET_DATA (ximage);
if ((data->width != ximagesrc->width) ||
(data->height != ximagesrc->height)) {
gst_ximage_buffer_free (ximage);
}
@ -413,13 +416,16 @@ gst_ximage_src_ximage_get (GstXImageSrc * ximagesrc)
gst_value_get_fraction_numerator (xcontext->par),
gst_value_get_fraction_denominator (xcontext->par), NULL);
gst_buffer_set_caps (GST_BUFFER (ximage), caps);
gst_buffer_set_caps (ximage, caps);
g_mutex_unlock (ximagesrc->x_lock);
gst_caps_unref (caps);
}
g_return_val_if_fail (GST_IS_XIMAGE_SRC (ximagesrc), NULL);
data = GST_XIMAGE_GET_DATA (ximage);
#ifdef HAVE_XDAMAGE
if (ximagesrc->have_xdamage && ximagesrc->use_damage &&
ximagesrc->last_ximage != NULL) {
@ -492,7 +498,7 @@ gst_ximage_src_ximage_get (GstXImageSrc * ximagesrc)
startx, starty, width, height);
XGetSubImage (ximagesrc->xcontext->disp, ximagesrc->xwindow,
startx, starty, width, height, AllPlanes, ZPixmap,
ximage->ximage, startx - ximagesrc->startx,
data->ximage, startx - ximagesrc->startx,
starty - ximagesrc->starty);
}
} else {
@ -504,7 +510,7 @@ gst_ximage_src_ximage_get (GstXImageSrc * ximagesrc)
XGetSubImage (ximagesrc->xcontext->disp, ximagesrc->xwindow,
rects[i].x, rects[i].y,
rects[i].width, rects[i].height,
AllPlanes, ZPixmap, ximage->ximage, rects[i].x, rects[i].y);
AllPlanes, ZPixmap, data->ximage, rects[i].x, rects[i].y);
}
}
free (rects);
@ -566,14 +572,14 @@ gst_ximage_src_ximage_get (GstXImageSrc * ximagesrc)
GST_DEBUG_OBJECT (ximagesrc, "Removing cursor from %d,%d", x, y);
XGetSubImage (ximagesrc->xcontext->disp, ximagesrc->xwindow,
startx, starty, iwidth, iheight, AllPlanes, ZPixmap,
ximage->ximage, startx - ximagesrc->startx,
data->ximage, startx - ximagesrc->startx,
starty - ximagesrc->starty);
}
} else {
GST_DEBUG_OBJECT (ximagesrc, "Removing cursor from %d,%d", x, y);
XGetSubImage (ximagesrc->xcontext->disp, ximagesrc->xwindow,
x, y, width, height, AllPlanes, ZPixmap, ximage->ximage, x, y);
x, y, width, height, AllPlanes, ZPixmap, data->ximage, x, y);
}
}
#endif
@ -586,7 +592,7 @@ gst_ximage_src_ximage_get (GstXImageSrc * ximagesrc)
if (ximagesrc->xcontext->use_xshm) {
GST_DEBUG_OBJECT (ximagesrc, "Retrieving screen using XShm");
XShmGetImage (ximagesrc->xcontext->disp, ximagesrc->xwindow,
ximage->ximage, ximagesrc->startx, ximagesrc->starty, AllPlanes);
data->ximage, ximagesrc->startx, ximagesrc->starty, AllPlanes);
} else
#endif /* HAVE_XSHM */
@ -595,9 +601,9 @@ gst_ximage_src_ximage_get (GstXImageSrc * ximagesrc)
if (ximagesrc->remote) {
XGetSubImage (ximagesrc->xcontext->disp, ximagesrc->xwindow,
ximagesrc->startx, ximagesrc->starty, ximagesrc->width,
ximagesrc->height, AllPlanes, ZPixmap, ximage->ximage, 0, 0);
ximagesrc->height, AllPlanes, ZPixmap, data->ximage, 0, 0);
} else {
ximage->ximage =
data->ximage =
XGetImage (ximagesrc->xcontext->disp, ximagesrc->xwindow,
ximagesrc->startx, ximagesrc->starty, ximagesrc->width,
ximagesrc->height, AllPlanes, ZPixmap);
@ -677,7 +683,7 @@ gst_ximage_src_ximage_get (GstXImageSrc * ximagesrc)
(guint8 *) & (ximagesrc->cursor_image->pixels[((j -
cy) * ximagesrc->cursor_image->width + (i - cx))]);
dest =
(guint8 *) & (ximage->ximage->data[((j -
(guint8 *) & (data->ximage->data[((j -
ximagesrc->starty) * ximagesrc->width + (i -
ximagesrc->startx)) * (ximagesrc->xcontext->bpp /
8)]);
@ -708,7 +714,7 @@ static GstFlowReturn
gst_ximage_src_create (GstPushSrc * bs, GstBuffer ** buf)
{
GstXImageSrc *s = GST_XIMAGE_SRC (bs);
GstXImageSrcBuffer *image;
GstBuffer *image;
GstClockTime base_time;
GstClockTime next_capture_ts;
GstClockTime dur;
@ -889,7 +895,7 @@ gst_ximage_src_clear_bufpool (GstXImageSrc * ximagesrc)
{
g_mutex_lock (ximagesrc->pool_lock);
while (ximagesrc->buffer_pool != NULL) {
GstXImageSrcBuffer *ximage = ximagesrc->buffer_pool->data;
GstBuffer *ximage = ximagesrc->buffer_pool->data;
gst_ximage_buffer_free (ximage);

View file

@ -95,7 +95,7 @@ struct _GstXImageSrc
int damage_event_base;
XserverRegion damage_region;
GC damage_copy_gc;
GstXImageSrcBuffer *last_ximage;
GstBuffer *last_ximage;
#endif
};

View file

@ -296,154 +296,112 @@ ximageutil_calculate_pixel_aspect_ratio (GstXContext * xcontext)
gst_value_get_fraction_denominator (xcontext->par));
}
static GstBufferClass *ximagesrc_buffer_parent_class = NULL;
static void
gst_ximagesrc_buffer_finalize (GstXImageSrcBuffer * ximage)
gst_ximagesrc_buffer_dispose (GstBuffer * ximage)
{
GstElement *parent;
GstXImageData *data = GST_XIMAGE_GET_DATA (ximage);
g_return_if_fail (ximage != NULL);
parent = ximage->parent;
parent = data->parent;
if (parent == NULL) {
g_warning ("XImageSrcBuffer->ximagesrc == NULL");
goto beach;
}
if (ximage->return_func)
ximage->return_func (parent, ximage);
if (data->return_func)
data->return_func (parent, ximage);
beach:
GST_MINI_OBJECT_CLASS (ximagesrc_buffer_parent_class)->finalize
(GST_MINI_OBJECT (ximage));
return;
}
void
gst_ximage_buffer_free (GstXImageSrcBuffer * ximage)
gst_ximage_buffer_free (GstBuffer * ximage)
{
GstXImageData *data = GST_XIMAGE_GET_DATA (ximage);
/* make sure it is not recycled */
ximage->width = -1;
ximage->height = -1;
gst_buffer_unref (GST_BUFFER (ximage));
}
static void
gst_ximagesrc_buffer_init (GstXImageSrcBuffer * ximage_buffer, gpointer g_class)
{
#ifdef HAVE_XSHM
ximage_buffer->SHMInfo.shmaddr = ((void *) -1);
ximage_buffer->SHMInfo.shmid = -1;
#endif
}
static void
gst_ximagesrc_buffer_class_init (gpointer g_class, gpointer class_data)
{
GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class);
ximagesrc_buffer_parent_class = g_type_class_peek_parent (g_class);
mini_object_class->finalize = (GstMiniObjectFinalizeFunction)
gst_ximagesrc_buffer_finalize;
}
static GType
gst_ximagesrc_buffer_get_type (void)
{
static GType _gst_ximagesrc_buffer_type;
if (G_UNLIKELY (_gst_ximagesrc_buffer_type == 0)) {
static const GTypeInfo ximagesrc_buffer_info = {
sizeof (GstBufferClass),
NULL,
NULL,
gst_ximagesrc_buffer_class_init,
NULL,
NULL,
sizeof (GstXImageSrcBuffer),
0,
(GInstanceInitFunc) gst_ximagesrc_buffer_init,
NULL
};
_gst_ximagesrc_buffer_type = g_type_register_static (GST_TYPE_BUFFER,
"GstXImageSrcBuffer", &ximagesrc_buffer_info, 0);
}
return _gst_ximagesrc_buffer_type;
data->width = -1;
data->height = -1;
gst_buffer_unref (ximage);
}
/* This function handles GstXImageSrcBuffer creation depending on XShm availability */
GstXImageSrcBuffer *
GstBuffer *
gst_ximageutil_ximage_new (GstXContext * xcontext,
GstElement * parent, int width, int height, BufferReturnFunc return_func)
{
GstXImageSrcBuffer *ximage = NULL;
GstBuffer *ximage = NULL;
GstXImageData *data;
gboolean succeeded = FALSE;
ximage =
(GstXImageSrcBuffer *) gst_mini_object_new (GST_TYPE_XIMAGESRC_BUFFER);
ximage = gst_buffer_new ();
data = g_slice_new (GstXImageData);
ximage->owner_priv = data;
GST_MINI_OBJECT_CAST (ximage)->dispose =
(GstMiniObjectDisposeFunction) gst_ximagesrc_buffer_dispose;
ximage->width = width;
ximage->height = height;
data->width = width;
data->height = height;
#ifdef HAVE_XSHM
data->SHMInfo.shmaddr = ((void *) -1);
data->SHMInfo.shmid = -1;
if (xcontext->use_xshm) {
ximage->ximage = XShmCreateImage (xcontext->disp,
data->ximage = XShmCreateImage (xcontext->disp,
xcontext->visual, xcontext->depth,
ZPixmap, NULL, &ximage->SHMInfo, ximage->width, ximage->height);
if (!ximage->ximage) {
ZPixmap, NULL, &data->SHMInfo, data->width, data->height);
if (!data->ximage) {
goto beach;
}
/* we have to use the returned bytes_per_line for our shm size */
ximage->size = ximage->ximage->bytes_per_line * ximage->ximage->height;
ximage->SHMInfo.shmid = shmget (IPC_PRIVATE, ximage->size,
IPC_CREAT | 0777);
if (ximage->SHMInfo.shmid == -1)
data->size = data->ximage->bytes_per_line * data->ximage->height;
data->SHMInfo.shmid = shmget (IPC_PRIVATE, data->size, IPC_CREAT | 0777);
if (data->SHMInfo.shmid == -1)
goto beach;
ximage->SHMInfo.shmaddr = shmat (ximage->SHMInfo.shmid, 0, 0);
if (ximage->SHMInfo.shmaddr == ((void *) -1))
data->SHMInfo.shmaddr = shmat (data->SHMInfo.shmid, 0, 0);
if (data->SHMInfo.shmaddr == ((void *) -1))
goto beach;
/* Delete the SHM segment. It will actually go away automatically
* when we detach now */
shmctl (ximage->SHMInfo.shmid, IPC_RMID, 0);
shmctl (data->SHMInfo.shmid, IPC_RMID, 0);
ximage->ximage->data = ximage->SHMInfo.shmaddr;
ximage->SHMInfo.readOnly = FALSE;
data->ximage->data = data->SHMInfo.shmaddr;
data->SHMInfo.readOnly = FALSE;
if (XShmAttach (xcontext->disp, &ximage->SHMInfo) == 0)
if (XShmAttach (xcontext->disp, &data->SHMInfo) == 0)
goto beach;
XSync (xcontext->disp, FALSE);
} else
#endif /* HAVE_XSHM */
{
ximage->ximage = XCreateImage (xcontext->disp,
data->ximage = XCreateImage (xcontext->disp,
xcontext->visual,
xcontext->depth,
ZPixmap, 0, NULL, ximage->width, ximage->height, xcontext->bpp, 0);
if (!ximage->ximage)
ZPixmap, 0, NULL, data->width, data->height, xcontext->bpp, 0);
if (!data->ximage)
goto beach;
/* we have to use the returned bytes_per_line for our image size */
ximage->size = ximage->ximage->bytes_per_line * ximage->ximage->height;
ximage->ximage->data = g_malloc (ximage->size);
data->size = data->ximage->bytes_per_line * data->ximage->height;
data->ximage->data = g_malloc (data->size);
XSync (xcontext->disp, FALSE);
}
succeeded = TRUE;
GST_BUFFER_DATA (ximage) = (guchar *) ximage->ximage->data;
GST_BUFFER_SIZE (ximage) = ximage->size;
GST_BUFFER_DATA (ximage) = (guchar *) data->ximage->data;
GST_BUFFER_SIZE (ximage) = data->size;
/* Keep a ref to our src */
ximage->parent = gst_object_ref (parent);
ximage->return_func = return_func;
data->parent = gst_object_ref (parent);
data->return_func = return_func;
beach:
if (!succeeded) {
gst_ximage_buffer_free (ximage);
@ -455,9 +413,12 @@ beach:
/* This function destroys a GstXImageBuffer handling XShm availability */
void
gst_ximageutil_ximage_destroy (GstXContext * xcontext,
GstXImageSrcBuffer * ximage)
gst_ximageutil_ximage_destroy (GstXContext * xcontext, GstBuffer * ximage)
{
GstXImageData *data;
data = GST_XIMAGE_GET_DATA (ximage);
/* We might have some buffers destroyed after changing state to NULL */
if (!xcontext)
goto beach;
@ -466,28 +427,28 @@ gst_ximageutil_ximage_destroy (GstXContext * xcontext,
#ifdef HAVE_XSHM
if (xcontext->use_xshm) {
if (ximage->SHMInfo.shmaddr != ((void *) -1)) {
XShmDetach (xcontext->disp, &ximage->SHMInfo);
if (data->SHMInfo.shmaddr != ((void *) -1)) {
XShmDetach (xcontext->disp, &data->SHMInfo);
XSync (xcontext->disp, 0);
shmdt (ximage->SHMInfo.shmaddr);
shmdt (data->SHMInfo.shmaddr);
}
if (ximage->ximage)
XDestroyImage (ximage->ximage);
if (data->ximage)
XDestroyImage (data->ximage);
} else
#endif /* HAVE_XSHM */
{
if (ximage->ximage) {
XDestroyImage (ximage->ximage);
if (data->ximage) {
XDestroyImage (data->ximage);
}
}
XSync (xcontext->disp, FALSE);
beach:
if (ximage->parent) {
if (data->parent) {
/* Release the ref to our parent */
gst_object_unref (ximage->parent);
ximage->parent = NULL;
gst_object_unref (data->parent);
data->parent = NULL;
}
return;

View file

@ -43,7 +43,7 @@ G_BEGIN_DECLS
typedef struct _GstXContext GstXContext;
typedef struct _GstXWindow GstXWindow;
typedef struct _GstXImage GstXImage;
typedef struct _GstXImageSrcBuffer GstXImageSrcBuffer;
typedef struct _GstXImageData GstXImageData;
/* Global X Context stuff */
/**
@ -130,21 +130,20 @@ void ximageutil_calculate_pixel_aspect_ratio (GstXContext * xcontext);
/* custom ximagesrc buffer, copied from ximagesink */
/* BufferReturnFunc is called when a buffer is finalised */
typedef void (*BufferReturnFunc) (GstElement *parent, GstXImageSrcBuffer *buf);
typedef void (*BufferReturnFunc) (GstElement *parent, GstBuffer *buf);
#define GST_XIMAGE_GET_DATA(buf) ((GstXImageData *) (GST_BUFFER_CAST(buf)->owner_priv))
/**
* GstXImageSrcBuffer:
* GstXImageData:
* @parent: a reference to the element we belong to
* @ximage: the XImage of this buffer
* @width: the width in pixels of XImage @ximage
* @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.
* Extra data attached to buffers containing additional information about an XImage.
*/
struct _GstXImageSrcBuffer {
GstBuffer buffer;
struct _GstXImageData {
/* Reference to the ximagesrc we belong to */
GstElement *parent;
@ -156,26 +155,19 @@ struct _GstXImageSrcBuffer {
gint width, height;
size_t size;
BufferReturnFunc return_func;
};
GstXImageSrcBuffer *gst_ximageutil_ximage_new (GstXContext *xcontext,
GstBuffer *gst_ximageutil_ximage_new (GstXContext *xcontext,
GstElement *parent, int width, int height, BufferReturnFunc return_func);
void gst_ximageutil_ximage_destroy (GstXContext *xcontext,
GstXImageSrcBuffer * ximage);
GstBuffer * ximage);
/* Call to manually release a buffer */
void gst_ximage_buffer_free (GstXImageSrcBuffer *ximage);
#define GST_TYPE_XIMAGESRC_BUFFER (gst_ximagesrc_buffer_get_type())
#define GST_IS_XIMAGESRC_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_XIMAGESRC_BUFFER))
#define GST_IS_XIMAGESRC_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_XIMAGESRC_BUFFER))
#define GST_XIMAGESRC_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_XIMAGESRC_BUFFER, GstXImageSrcBuffer))
#define GST_XIMAGESRC_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_XIMAGESRC_BUFFER, GstXImageSrcBufferClass))
#define GST_XIMAGESRC_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_XIMAGESRC_BUFFER, GstXImageSrcBufferClass))
void gst_ximage_buffer_free (GstBuffer *ximage);
G_END_DECLS