Use buffer private data instead of subclassing.
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);
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;
}
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);
-
- GST_MINI_OBJECT_CLASS (v4l2buffer_parent_class)->finalize (GST_MINI_OBJECT
- (buffer));
- }
-}
-
-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;
+ buffer, GST_BUFFER_DATA (buffer), data->vbuffer.length);
+ v4l2_munmap ((void *) GST_BUFFER_DATA (buffer), data->vbuffer.length);
- 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);
+ g_object_unref (pool);
+ g_slice_free (GstV4l2Data, data);
+ buffer->owner_priv = NULL;
}
- 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;
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;
}
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;
}
* 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;
pool->buffers = NULL;
}
- GST_MINI_OBJECT_CLASS (buffer_pool_parent_class)->finalize (GST_MINI_OBJECT
- (pool));
+ buffer_pool_parent_class->finalize (object);
}
static void
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
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,
(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;
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)
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: */
{
gint errnosave = errno;
- gst_mini_object_unref (GST_MINI_OBJECT (pool));
+ g_object_unref (pool);
errno = errnosave;
gst_buffer_unref (buf);
}
- gst_mini_object_unref (GST_MINI_OBJECT (pool));
+ g_object_unref (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);
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);
}
* 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);
+
+ GST_LOG_OBJECT (pool->v4l2elem, "enqueue pool buffer %d",
+ data->vbuffer.index);
- if (v4l2_ioctl (pool->video_fd, VIDIOC_QBUF, &buf->vbuffer) < 0)
+ if (v4l2_ioctl (pool->video_fd, VIDIOC_QBUF, &data->vbuffer) < 0)
return FALSE;
pool->num_live_buffers--;
*
* 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);
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 */
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* */
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);
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))
(_("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;
}
}
/* 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);
/* 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);
}
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) {
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 {
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);
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
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 */
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);
(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)]);
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;
{
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);
int damage_event_base;
XserverRegion damage_region;
GC damage_copy_gc;
- GstXImageSrcBuffer *last_ximage;
+ GstBuffer *last_ximage;
#endif
};
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);
/* 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;
#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;
typedef struct _GstXContext GstXContext;
typedef struct _GstXWindow GstXWindow;
typedef struct _GstXImage GstXImage;
-typedef struct _GstXImageSrcBuffer GstXImageSrcBuffer;
+typedef struct _GstXImageData GstXImageData;
/* Global X Context stuff */
/**
/* 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;
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