Add basic GstVaapiVideoBuffer.

This commit is contained in:
gb 2010-03-12 23:48:50 +00:00
parent 809933a46b
commit c465394864
3 changed files with 281 additions and 0 deletions

View file

@ -9,6 +9,7 @@ libgstvaapi_source_c = \
gstvaapisubpicture.c \
gstvaapisurface.c \
gstvaapisurfacepool.c \
gstvaapivideobuffer.c \
gstvaapivideopool.c \
vaapi_utils.c \
$(NULL)
@ -22,6 +23,7 @@ libgstvaapi_source_h = \
gstvaapisubpicture.h \
gstvaapisurface.h \
gstvaapisurfacepool.h \
gstvaapivideobuffer.h \
gstvaapivideopool.h \
vaapi_debug.h \
vaapi_utils.h \

View file

@ -0,0 +1,188 @@
/*
* gstvaapivideobuffer.c - Gst VA video buffer
*
* gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "gstvaapivideobuffer.h"
#define DEBUG 1
#include "vaapi_debug.h"
G_DEFINE_TYPE(GstVaapiVideoBuffer, gst_vaapi_video_buffer, GST_TYPE_BUFFER);
#define GST_VAAPI_VIDEO_BUFFER_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
GST_VAAPI_TYPE_VIDEO_BUFFER, \
GstVaapiVideoBufferPrivate))
struct _GstVaapiVideoBufferPrivate {
GstVaapiVideoPool *pool;
guint pool_type;
GstVaapiImage *image;
GstVaapiSurface *surface;
guint flags;
};
enum {
POOL_TYPE_NONE,
POOL_TYPE_IMAGE,
POOL_TYPE_SURFACE
};
static void
gst_vaapi_video_buffer_finalize(GstMiniObject *object)
{
GstVaapiVideoBufferPrivate *priv = GST_VAAPI_VIDEO_BUFFER(object)->priv;
GstMiniObjectClass *parent_class;
if (priv->image) {
if (priv->pool_type == POOL_TYPE_IMAGE)
gst_vaapi_video_pool_put_object(priv->pool, priv->image);
else
g_object_unref(priv->image);
priv->image = NULL;
}
if (priv->surface) {
if (priv->pool_type == POOL_TYPE_SURFACE)
gst_vaapi_video_pool_put_object(priv->pool, priv->surface);
else
g_object_unref(priv->surface);
priv->surface = NULL;
}
if (priv->pool) {
g_object_unref(priv->pool);
priv->pool = NULL;
}
parent_class = GST_MINI_OBJECT_CLASS(gst_vaapi_video_buffer_parent_class);
if (parent_class->finalize)
parent_class->finalize(object);
}
static void
gst_vaapi_video_buffer_class_init(GstVaapiVideoBufferClass *klass)
{
GstMiniObjectClass * const object_class = GST_MINI_OBJECT_CLASS(klass);
g_type_class_add_private(klass, sizeof(GstVaapiVideoBufferPrivate));
object_class->finalize = gst_vaapi_video_buffer_finalize;
}
static void
gst_vaapi_video_buffer_init(GstVaapiVideoBuffer *buffer)
{
GstVaapiVideoBufferPrivate *priv;
priv = GST_VAAPI_VIDEO_BUFFER_GET_PRIVATE(buffer);
buffer->priv = priv;
priv->pool = NULL;
priv->image = NULL;
priv->surface = NULL;
}
static GstBuffer *
gst_vaapi_video_buffer_new(
GstVaapiVideoPool *pool,
GstVaapiImage *image,
GstVaapiSurface *surface
)
{
gpointer vobject = NULL;
GstMiniObject *object;
GstVaapiVideoBuffer *buffer;
GstVaapiVideoBufferPrivate *priv;
object = gst_mini_object_new(GST_VAAPI_TYPE_VIDEO_BUFFER);
if (!object)
return NULL;
buffer = GST_VAAPI_VIDEO_BUFFER(object);
priv = buffer->priv;
priv->pool = pool;
priv->pool_type = POOL_TYPE_NONE;
priv->image = image;
priv->surface = surface;
if (pool) {
vobject = gst_vaapi_video_pool_get_object(pool);
if (!vobject)
goto error;
if (GST_VAAPI_IS_IMAGE(vobject)) {
priv->pool_type = POOL_TYPE_IMAGE;
priv->image = vobject;
}
else if (GST_VAAPI_IS_SURFACE(vobject)) {
priv->pool_type = POOL_TYPE_SURFACE;
priv->surface = vobject;
}
else
goto error;
}
return GST_BUFFER(buffer);
error:
if (vobject)
gst_vaapi_video_pool_put_object(pool, vobject);
gst_mini_object_unref(object);
return NULL;
}
GstBuffer *
gst_vaapi_video_buffer_new_from_pool(GstVaapiVideoPool *pool)
{
g_return_val_if_fail(GST_VAAPI_IS_VIDEO_POOL(pool), NULL);
return gst_vaapi_video_buffer_new(g_object_ref(pool), NULL, NULL);
}
GstBuffer *
gst_vaapi_video_buffer_new_with_image(GstVaapiImage *image)
{
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), NULL);
return gst_vaapi_video_buffer_new(NULL, g_object_ref(image), NULL);
}
GstBuffer *
gst_vaapi_video_buffer_new_with_surface(GstVaapiSurface *surface)
{
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), NULL);
return gst_vaapi_video_buffer_new(NULL, NULL, g_object_ref(surface));
}
GstVaapiImage *
gst_vaapi_video_buffer_get_image(GstVaapiVideoBuffer *buffer)
{
g_return_val_if_fail(GST_VAAPI_IS_VIDEO_BUFFER(buffer), NULL);
return buffer->priv->image;
}
GstVaapiSurface *
gst_vaapi_video_buffer_get_surface(GstVaapiVideoBuffer *buffer)
{
g_return_val_if_fail(GST_VAAPI_IS_VIDEO_BUFFER(buffer), NULL);
return buffer->priv->surface;
}

View file

@ -0,0 +1,91 @@
/*
* gstvaapivideobuffer.h - Gstreamer/VA video buffer
*
* gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef GST_VAAPI_VIDEO_BUFFER_H
#define GST_VAAPI_VIDEO_BUFFER_H
#include <gst/gstbuffer.h>
#include <gst/vaapi/gstvaapiimage.h>
#include <gst/vaapi/gstvaapisurface.h>
#include <gst/vaapi/gstvaapivideopool.h>
G_BEGIN_DECLS
#define GST_VAAPI_TYPE_VIDEO_BUFFER \
(gst_vaapi_video_buffer_get_type())
#define GST_VAAPI_VIDEO_BUFFER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_VIDEO_BUFFER, \
GstVaapiVideoBuffer))
#define GST_VAAPI_VIDEO_BUFFER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_VIDEO_BUFFER, \
GstVaapiVideoBufferClass))
#define GST_VAAPI_IS_VIDEO_BUFFER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_VIDEO_BUFFER))
#define GST_VAAPI_IS_VIDEO_BUFFER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_VIDEO_BUFFER))
#define GST_VAAPI_VIDEO_BUFFER_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_VIDEO_BUFFER, \
GstVaapiVideoBufferClass))
typedef struct _GstVaapiVideoBuffer GstVaapiVideoBuffer;
typedef struct _GstVaapiVideoBufferPrivate GstVaapiVideoBufferPrivate;
typedef struct _GstVaapiVideoBufferClass GstVaapiVideoBufferClass;
struct _GstVaapiVideoBuffer {
/*< private >*/
GstBuffer parent_instance;
GstVaapiVideoBufferPrivate *priv;
};
struct _GstVaapiVideoBufferClass {
/*< private >*/
GstBufferClass parent_class;
};
GType
gst_vaapi_video_buffer_get_type(void);
GstBuffer *
gst_vaapi_video_buffer_new_from_pool(GstVaapiVideoPool *pool);
GstBuffer *
gst_vaapi_video_buffer_new_with_image(GstVaapiImage *image);
GstBuffer *
gst_vaapi_video_buffer_new_with_surface(GstVaapiSurface *surface);
GstVaapiImage *
gst_vaapi_video_buffer_get_image(GstVaapiVideoBuffer *buffer);
GstVaapiSurface *
gst_vaapi_video_buffer_get_surface(GstVaapiVideoBuffer *buffer);
G_END_DECLS
#endif /* GST_VAAPI_VIDEO_BUFFER_H */