mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-22 00:06:36 +00:00
pvr2d: Port to 0.11
Handles GstVideoMeta and GstVideoCropMeta Provides GstBufferPool New GstPVRMeta to handle the wrapped PVR mem_src
This commit is contained in:
parent
27b677d179
commit
ff026e0801
6 changed files with 797 additions and 795 deletions
|
@ -69,6 +69,34 @@ gst_ducati_alloc_2d (gint width, gint height, guint * sz)
|
|||
return MemMgr_Alloc (block, 2);
|
||||
}
|
||||
|
||||
static struct
|
||||
{
|
||||
PVR2DERROR code;
|
||||
const gchar *errstring;
|
||||
} pvr2derrorcodestring[] = {
|
||||
{
|
||||
PVR2D_OK, "OK (0)"}, {
|
||||
PVR2DERROR_INVALID_PARAMETER, "Invalid Parameter (-1)"}, {
|
||||
PVR2DERROR_DEVICE_UNAVAILABLE, "Device Unavailable (-2)"}, {
|
||||
PVR2DERROR_INVALID_CONTEXT, "Invalid Context (-3)"}, {
|
||||
PVR2DERROR_MEMORY_UNAVAILABLE, "Memory Unavailable (-4)"}, {
|
||||
PVR2DERROR_DEVICE_NOT_PRESENT, "Device not present (-5)"}, {
|
||||
PVR2DERROR_IOCTL_ERROR, "ioctl Error (-6)"}, {
|
||||
PVR2DERROR_GENERIC_ERROR, "Generic Error (-7)"}, {
|
||||
PVR2DERROR_BLT_NOTCOMPLETE, "blt not complete (-8)"}, {
|
||||
PVR2DERROR_HW_FEATURE_NOT_SUPPORTED, "Hardware feature not supported (-9)"}, {
|
||||
PVR2DERROR_NOT_YET_IMPLEMENTED, "Not yet implemented (-10)"}, {
|
||||
PVR2DERROR_MAPPING_FAILED, "Mapping failed (-11)"}
|
||||
};
|
||||
|
||||
const gchar *
|
||||
gst_pvr2d_error_get_string (PVR2DERROR code)
|
||||
{
|
||||
if (code <= PVR2D_OK && code >= PVR2DERROR_MAPPING_FAILED)
|
||||
return pvr2derrorcodestring[PVR2D_OK - code].errstring;
|
||||
return "Uknown Error";
|
||||
}
|
||||
|
||||
/* PACKAGE: this is usually set by autotools depending on some _INIT macro
|
||||
* in configure.ac and then written into and defined in config.h, but we can
|
||||
* just set it ourselves here in case someone doesn't use autotools to
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <tiler.h>
|
||||
#include <tilermem.h>
|
||||
#include <memmgr.h>
|
||||
#include "pvr2d.h"
|
||||
|
||||
|
||||
#include <gst/gst.h>
|
||||
|
||||
|
@ -37,6 +39,8 @@ G_BEGIN_DECLS
|
|||
void * gst_ducati_alloc_1d (gint sz);
|
||||
void * gst_ducati_alloc_2d (gint width, gint height, guint * sz);
|
||||
|
||||
const gchar * gst_pvr2d_error_get_string (PVR2DERROR code);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_DUCATI_H__ */
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (c) 2010, Texas Instruments Incorporated
|
||||
* Copyright (c) 2011, Collabora Ltd
|
||||
* @author: Edward Hervey <edward@collabora.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -17,304 +19,351 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "gstpvrbufferpool.h"
|
||||
|
||||
/* Debugging category */
|
||||
#include <gst/gstinfo.h>
|
||||
|
||||
/* Helper functions */
|
||||
#include <gst/video/video.h>
|
||||
#include <gst/video/gstvideometa.h>
|
||||
#include <gst/video/gstvideopool.h>
|
||||
|
||||
|
||||
GST_DEBUG_CATEGORY_EXTERN (gst_debug_pvrvideosink);
|
||||
#define GST_CAT_DEFAULT gst_debug_pvrvideosink
|
||||
|
||||
/*
|
||||
* GstDucatiBuffer
|
||||
*/
|
||||
|
||||
static GstBufferClass *buffer_parent_class;
|
||||
|
||||
/* Get the original buffer, or whatever is the best output buffer.
|
||||
* Consumes the input reference, produces the output reference
|
||||
*/
|
||||
GstBuffer *
|
||||
gst_ducati_buffer_get (GstDucatiBuffer * self)
|
||||
static void
|
||||
gst_pvr_meta_free (GstPVRMeta * meta, GstBuffer * buffer)
|
||||
{
|
||||
if (self->orig) {
|
||||
// TODO copy to orig buffer.. if needed.
|
||||
gst_buffer_unref (self->orig);
|
||||
self->orig = NULL;
|
||||
}
|
||||
return GST_BUFFER (self);
|
||||
}
|
||||
GstPVRVideoSink *pvrsink = (GstPVRVideoSink *) meta->sink;
|
||||
|
||||
PVR2DMEMINFO *
|
||||
gst_ducati_buffer_get_meminfo (GstDucatiBuffer * self)
|
||||
{
|
||||
return self->src_mem;
|
||||
}
|
||||
GST_LOG ("Releasing PVRMeta for buffer %p (src_mem:%p)",
|
||||
buffer, meta->src_mem);
|
||||
|
||||
|
||||
static GstDucatiBuffer *
|
||||
gst_ducati_buffer_new (GstPvrBufferPool * pool)
|
||||
{
|
||||
if (meta->src_mem) {
|
||||
PVR2DERROR pvr_error;
|
||||
GstDucatiBuffer *self = (GstDucatiBuffer *)
|
||||
gst_mini_object_new (GST_TYPE_DUCATIBUFFER);
|
||||
|
||||
GST_LOG_OBJECT (pool->element, "creating buffer %p in pool %p", self, pool);
|
||||
GST_OBJECT_LOCK (pvrsink);
|
||||
if (pvrsink->dcontext == NULL || pvrsink->dcontext->pvr_context == NULL) {
|
||||
GST_OBJECT_UNLOCK (pvrsink);
|
||||
goto done;
|
||||
}
|
||||
pvr_error = PVR2DMemFree (pvrsink->dcontext->pvr_context, meta->src_mem);
|
||||
GST_OBJECT_UNLOCK (pvrsink);
|
||||
|
||||
self->pool = (GstPvrBufferPool *)
|
||||
gst_mini_object_ref (GST_MINI_OBJECT (pool));
|
||||
if (pvr_error != PVR2D_OK)
|
||||
GST_ERROR ("Failed to unwrap PVR memory buffer. Error : %s",
|
||||
gst_pvr2d_error_get_string (pvr_error));
|
||||
}
|
||||
|
||||
GST_BUFFER_DATA (self) = gst_ducati_alloc_1d (pool->size);
|
||||
GST_BUFFER_SIZE (self) = pool->size;
|
||||
GST_LOG_OBJECT (pool->element, "width=%d, height=%d and size=%d",
|
||||
pool->padded_width, pool->padded_height, pool->size);
|
||||
done:
|
||||
gst_pvrvideosink_untrack_buffer (pvrsink, buffer);
|
||||
gst_object_unref (pvrsink);
|
||||
}
|
||||
|
||||
const GstMetaInfo *
|
||||
gst_pvr_meta_get_info (void)
|
||||
{
|
||||
static const GstMetaInfo *pvr_meta_info = NULL;
|
||||
|
||||
if (pvr_meta_info == NULL) {
|
||||
pvr_meta_info = gst_meta_register ("GstPVRMeta", "GstPVRMeta",
|
||||
sizeof (GstPVRMeta),
|
||||
(GstMetaInitFunction) NULL,
|
||||
(GstMetaFreeFunction) gst_pvr_meta_free,
|
||||
(GstMetaCopyFunction) NULL, (GstMetaTransformFunction) NULL);
|
||||
}
|
||||
return pvr_meta_info;
|
||||
|
||||
}
|
||||
|
||||
/* Wrap existing buffers */
|
||||
GstPVRMeta *
|
||||
gst_buffer_add_pvr_meta (GstBuffer * buffer, GstElement * sink)
|
||||
{
|
||||
guint8 *data;
|
||||
gsize size;
|
||||
GstPVRMeta *meta;
|
||||
PVR2DERROR pvr_error;
|
||||
GstPVRVideoSink *pvrsink = (GstPVRVideoSink *) sink;
|
||||
|
||||
g_return_val_if_fail (gst_buffer_n_memory (buffer) > 0, NULL);
|
||||
g_return_val_if_fail (pvrsink != NULL, NULL);
|
||||
|
||||
GST_LOG_OBJECT (pvrsink, "Adding PVRMeta to buffer %p", buffer);
|
||||
|
||||
/* Add the meta */
|
||||
meta = (GstPVRMeta *) gst_buffer_add_meta (buffer, GST_PVR_META_INFO, NULL);
|
||||
meta->src_mem = NULL;
|
||||
meta->sink = gst_object_ref (pvrsink);
|
||||
gst_pvrvideosink_track_buffer (pvrsink, buffer);
|
||||
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
||||
|
||||
GST_LOG_OBJECT (pvrsink, "data:%p, size:%" G_GSIZE_FORMAT, data, size);
|
||||
|
||||
GST_OBJECT_LOCK (pvrsink);
|
||||
if (pvrsink->dcontext == NULL || pvrsink->dcontext->pvr_context == NULL)
|
||||
goto no_pvr_context;
|
||||
/* Map the memory and wrap it */
|
||||
pvr_error =
|
||||
PVR2DMemWrap (pool->pvr_context, GST_BUFFER_DATA (self), 0, pool->size,
|
||||
NULL, &(self->src_mem));
|
||||
if (pvr_error != PVR2D_OK) {
|
||||
GST_LOG_OBJECT (pool->element, "Failed to Wrap buffer memory"
|
||||
"returned %d", pvr_error);
|
||||
} else {
|
||||
self->wrapped = TRUE;
|
||||
}
|
||||
PVR2DMemWrap (pvrsink->dcontext->pvr_context, data, 0, size, NULL,
|
||||
&(meta->src_mem));
|
||||
GST_OBJECT_UNLOCK (pvrsink);
|
||||
|
||||
gst_buffer_set_caps (GST_BUFFER (self), pool->caps);
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
|
||||
return self;
|
||||
}
|
||||
if (pvr_error != PVR2D_OK)
|
||||
goto wrap_error;
|
||||
|
||||
return meta;
|
||||
|
||||
static void
|
||||
gst_ducati_buffer_finalize (GstDucatiBuffer * self)
|
||||
wrap_error:
|
||||
{
|
||||
PVR2DERROR pvr_error;
|
||||
GstPvrBufferPool *pool = self->pool;
|
||||
gboolean resuscitated = FALSE;
|
||||
GST_WARNING_OBJECT (pvrsink, "Failed to Wrap buffer memory. Error : %s",
|
||||
gst_pvr2d_error_get_string (pvr_error));
|
||||
gst_buffer_remove_meta (buffer, (GstMeta *) meta);
|
||||
|
||||
GST_LOG_OBJECT (pool->element, "finalizing buffer %p", self);
|
||||
|
||||
GST_PVR_BUFFERPOOL_LOCK (pool);
|
||||
g_queue_remove (pool->used_buffers, self);
|
||||
if (pool->running) {
|
||||
resuscitated = TRUE;
|
||||
|
||||
GST_LOG_OBJECT (pool->element, "reviving buffer %p", self);
|
||||
|
||||
g_queue_push_head (pool->free_buffers, self);
|
||||
} else {
|
||||
GST_LOG_OBJECT (pool->element, "the pool is shutting down");
|
||||
}
|
||||
GST_PVR_BUFFERPOOL_UNLOCK (pool);
|
||||
|
||||
if (resuscitated) {
|
||||
GST_LOG_OBJECT (pool->element, "reviving buffer %p, %d", self, index);
|
||||
gst_buffer_ref (GST_BUFFER (self));
|
||||
GST_BUFFER_SIZE (self) = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!resuscitated) {
|
||||
GST_LOG_OBJECT (pool->element,
|
||||
"buffer %p (data %p, len %u) not recovered, freeing",
|
||||
self, GST_BUFFER_DATA (self), GST_BUFFER_SIZE (self));
|
||||
|
||||
if (self->wrapped) {
|
||||
pvr_error = PVR2DMemFree (pool->pvr_context, self->src_mem);
|
||||
if (pvr_error != PVR2D_OK) {
|
||||
GST_ERROR_OBJECT (pool->element, "Failed to Unwrap buffer memory"
|
||||
"returned %d", pvr_error);
|
||||
}
|
||||
self->wrapped = FALSE;
|
||||
}
|
||||
MemMgr_Free ((void *) GST_BUFFER_DATA (self));
|
||||
GST_BUFFER_DATA (self) = NULL;
|
||||
gst_mini_object_unref (GST_MINI_OBJECT (pool));
|
||||
GST_MINI_OBJECT_CLASS (buffer_parent_class)->finalize (GST_MINI_OBJECT
|
||||
(self));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_ducati_buffer_class_init (gpointer g_class, gpointer class_data)
|
||||
no_pvr_context:
|
||||
{
|
||||
GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class);
|
||||
|
||||
buffer_parent_class = g_type_class_peek_parent (g_class);
|
||||
|
||||
mini_object_class->finalize = (GstMiniObjectFinalizeFunction)
|
||||
GST_DEBUG_FUNCPTR (gst_ducati_buffer_finalize);
|
||||
GST_OBJECT_UNLOCK (pvrsink);
|
||||
GST_WARNING_OBJECT (pvrsink, "No PVR2D context available");
|
||||
gst_buffer_remove_meta (buffer, (GstMeta *) meta);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GType
|
||||
gst_ducati_buffer_get_type (void)
|
||||
{
|
||||
static GType type;
|
||||
|
||||
if (G_UNLIKELY (type == 0)) {
|
||||
static const GTypeInfo info = {
|
||||
.class_size = sizeof (GstBufferClass),
|
||||
.class_init = gst_ducati_buffer_class_init,
|
||||
.instance_size = sizeof (GstDucatiBuffer),
|
||||
};
|
||||
type = g_type_register_static (GST_TYPE_BUFFER,
|
||||
"GstDucatiBufferPvrsink", &info, 0);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/*
|
||||
* GstDucatiBufferPool
|
||||
*/
|
||||
static void gst_pvr_buffer_pool_finalize (GObject * object);
|
||||
|
||||
static GstMiniObjectClass *bufferpool_parent_class = NULL;
|
||||
#define gst_pvr_buffer_pool_parent_class parent_class
|
||||
G_DEFINE_TYPE (GstPVRBufferPool, gst_pvr_buffer_pool, GST_TYPE_BUFFER_POOL);
|
||||
static const gchar **
|
||||
pvr_buffer_pool_get_options (GstBufferPool * pool)
|
||||
{
|
||||
static const gchar *options[] = { GST_BUFFER_POOL_OPTION_VIDEO_META,
|
||||
GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT, NULL
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
pvr_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
||||
{
|
||||
GstPVRBufferPool *pvrpool = GST_PVR_BUFFER_POOL_CAST (pool);
|
||||
GstVideoInfo info;
|
||||
guint size, align;
|
||||
gboolean ret;
|
||||
const GstCaps *caps;
|
||||
|
||||
if (!gst_buffer_pool_config_get (config, &caps, &size, NULL, NULL, NULL,
|
||||
&align))
|
||||
goto wrong_config;
|
||||
|
||||
if (caps == NULL)
|
||||
goto no_caps;
|
||||
|
||||
/* now parse the caps from the config */
|
||||
if (!gst_video_info_from_caps (&info, caps))
|
||||
goto wrong_caps;
|
||||
|
||||
GST_LOG_OBJECT (pool, "%dx%d, size:%u, align:%u caps %" GST_PTR_FORMAT,
|
||||
info.width, info.height, size, align, caps);
|
||||
|
||||
if (pvrpool->caps)
|
||||
gst_caps_unref (pvrpool->caps);
|
||||
pvrpool->caps = gst_caps_copy (caps);
|
||||
pvrpool->info = info;
|
||||
pvrpool->size = size;
|
||||
pvrpool->align = align;
|
||||
pvrpool->padded_width = GST_VIDEO_INFO_WIDTH (&info);
|
||||
pvrpool->padded_height = GST_VIDEO_INFO_HEIGHT (&info);
|
||||
|
||||
/* enable metadata based on config of the pool */
|
||||
pvrpool->add_metavideo =
|
||||
gst_buffer_pool_config_has_option (config,
|
||||
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
||||
|
||||
#if 0
|
||||
/* parse extra alignment info */
|
||||
priv->need_alignment = gst_buffer_pool_config_has_option (config,
|
||||
GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
|
||||
|
||||
if (priv->need_alignment) {
|
||||
gst_buffer_pool_config_get_video_alignment (config, &priv->align);
|
||||
|
||||
GST_LOG_OBJECT (pool, "padding %u-%ux%u-%u", priv->align.padding_top,
|
||||
priv->align.padding_left, priv->align.padding_left,
|
||||
priv->align.padding_bottom);
|
||||
|
||||
/* we need the video metadata too now */
|
||||
priv->add_metavideo = TRUE;
|
||||
}
|
||||
|
||||
/* add the padding */
|
||||
priv->padded_width =
|
||||
GST_VIDEO_INFO_WIDTH (&info) + priv->align.padding_left +
|
||||
priv->align.padding_right;
|
||||
priv->padded_height =
|
||||
GST_VIDEO_INFO_HEIGHT (&info) + priv->align.padding_top +
|
||||
priv->align.padding_bottom;
|
||||
#endif
|
||||
|
||||
GST_DEBUG_OBJECT (pool, "before calling parent class");
|
||||
|
||||
ret = GST_BUFFER_POOL_CLASS (parent_class)->set_config (pool, config);
|
||||
|
||||
GST_DEBUG_OBJECT (pool, "parent_class returned %d", ret);
|
||||
|
||||
return ret;
|
||||
|
||||
/* 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
|
||||
pvr_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
|
||||
GstBufferPoolParams * params)
|
||||
{
|
||||
GstPVRBufferPool *pvrpool = GST_PVR_BUFFER_POOL_CAST (pool);
|
||||
GstVideoInfo *info;
|
||||
GstBuffer *pvr;
|
||||
GstPVRMeta *meta;
|
||||
|
||||
info = &pvrpool->info;
|
||||
|
||||
pvr = gst_buffer_new_allocate (NULL, pvrpool->size, pvrpool->align);
|
||||
meta = gst_buffer_add_pvr_meta (pvr, pvrpool->pvrsink);
|
||||
if (meta == NULL) {
|
||||
gst_buffer_unref (pvr);
|
||||
goto no_buffer;
|
||||
}
|
||||
|
||||
if (pvrpool->add_metavideo) {
|
||||
GstVideoMeta *meta;
|
||||
|
||||
GST_DEBUG_OBJECT (pool, "adding GstVideoMeta");
|
||||
/* these are just the defaults for now */
|
||||
meta = gst_buffer_add_video_meta (pvr, 0, GST_VIDEO_INFO_FORMAT (info),
|
||||
pvrpool->padded_width, pvrpool->padded_height);
|
||||
if (G_UNLIKELY (meta == NULL))
|
||||
GST_WARNING_OBJECT (pool, "Failed to add GstVideoMeta");
|
||||
|
||||
#if 0
|
||||
const GstVideoFormatInfo *vinfo = info->finfo;
|
||||
gint i;
|
||||
|
||||
if (pvrpool->need_alignment) {
|
||||
meta->width = GST_VIDEO_INFO_WIDTH (&pvrpool->info);
|
||||
meta->height = GST_VIDEO_INFO_HEIGHT (&pvrpool->info);
|
||||
|
||||
/* FIXME, not quite correct, NV12 would apply the vedge twice on the second
|
||||
* plane */
|
||||
for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++) {
|
||||
gint vedge, hedge, plane;
|
||||
|
||||
hedge =
|
||||
GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (vinfo, i,
|
||||
pvrpool->align.padding_left);
|
||||
vedge =
|
||||
GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (vinfo, i,
|
||||
pvrpool->align.padding_top);
|
||||
plane = GST_VIDEO_FORMAT_INFO_PLANE (vinfo, i);
|
||||
|
||||
GST_LOG_OBJECT (pool, "comp %d, plane %d: hedge %d, vedge %d", i,
|
||||
plane, hedge, vedge);
|
||||
|
||||
meta->offset[plane] += (vedge * meta->stride[plane]) + hedge;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
*buffer = pvr;
|
||||
|
||||
return GST_FLOW_OK;
|
||||
|
||||
/* ERROR */
|
||||
no_buffer:
|
||||
{
|
||||
GST_WARNING_OBJECT (pool, "can't create image");
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/** create new bufferpool
|
||||
* @element : the element that owns this pool
|
||||
* @caps: the caps to set on the buffer
|
||||
* @num_buffers: the requested number of buffers in the pool
|
||||
*/
|
||||
GstPvrBufferPool *
|
||||
gst_pvr_bufferpool_new (GstElement * element, GstCaps * caps, gint num_buffers,
|
||||
gint size, PVR2DCONTEXTHANDLE pvr_context)
|
||||
GstBufferPool *
|
||||
gst_pvr_buffer_pool_new (GstElement * pvrsink)
|
||||
{
|
||||
GstPvrBufferPool *self = (GstPvrBufferPool *)
|
||||
gst_mini_object_new (GST_TYPE_PVRBUFFERPOOL);
|
||||
GstStructure *s = gst_caps_get_structure (caps, 0);
|
||||
GstPVRBufferPool *pool;
|
||||
|
||||
self->element = gst_object_ref (element);
|
||||
gst_structure_get_int (s, "width", &self->padded_width);
|
||||
gst_structure_get_int (s, "height", &self->padded_height);
|
||||
self->caps = gst_caps_ref (caps);
|
||||
self->size = size;
|
||||
self->pvr_context = pvr_context;
|
||||
g_return_val_if_fail (GST_IS_PVRVIDEOSINK (pvrsink), NULL);
|
||||
|
||||
self->free_buffers = g_queue_new ();
|
||||
self->used_buffers = g_queue_new ();
|
||||
self->lock = g_mutex_new ();
|
||||
self->running = TRUE;
|
||||
GST_DEBUG_OBJECT (pvrsink, "Creating new GstPVRBufferPool");
|
||||
|
||||
return self;
|
||||
pool = g_object_new (GST_TYPE_PVR_BUFFER_POOL, NULL);
|
||||
pool->pvrsink = gst_object_ref (pvrsink);
|
||||
|
||||
return GST_BUFFER_POOL_CAST (pool);
|
||||
}
|
||||
|
||||
static void
|
||||
unwrap_buffer (gpointer buffer, gpointer user_data)
|
||||
gst_pvr_buffer_pool_class_init (GstPVRBufferPoolClass * klass)
|
||||
{
|
||||
PVR2DERROR pvr_error;
|
||||
GstDucatiBuffer *buf = GST_DUCATIBUFFER (buffer);
|
||||
GstPvrBufferPool *pool = (GstPvrBufferPool *) user_data;
|
||||
GObjectClass *gobject_class = (GObjectClass *) klass;
|
||||
GstBufferPoolClass *gstbufferpool_class = (GstBufferPoolClass *) klass;
|
||||
|
||||
if (buf->wrapped) {
|
||||
pvr_error = PVR2DMemFree (pool->pvr_context, buf->src_mem);
|
||||
if (pvr_error != PVR2D_OK) {
|
||||
GST_ERROR_OBJECT (pool->element, "Failed to Unwrap buffer memory"
|
||||
"returned %d", pvr_error);
|
||||
}
|
||||
buf->wrapped = FALSE;
|
||||
}
|
||||
}
|
||||
gobject_class->finalize = gst_pvr_buffer_pool_finalize;
|
||||
|
||||
void
|
||||
gst_pvr_bufferpool_stop_running (GstPvrBufferPool * self, gboolean unwrap)
|
||||
{
|
||||
gboolean empty = FALSE;
|
||||
|
||||
g_return_if_fail (self);
|
||||
|
||||
GST_PVR_BUFFERPOOL_LOCK (self);
|
||||
self->running = FALSE;
|
||||
GST_PVR_BUFFERPOOL_UNLOCK (self);
|
||||
|
||||
GST_DEBUG_OBJECT (self->element, "free available buffers");
|
||||
|
||||
/* free all buffers on the freelist */
|
||||
while (!empty) {
|
||||
GstDucatiBuffer *buf;
|
||||
GST_PVR_BUFFERPOOL_LOCK (self);
|
||||
buf = g_queue_pop_head (self->free_buffers);
|
||||
GST_PVR_BUFFERPOOL_UNLOCK (self);
|
||||
if (buf)
|
||||
gst_buffer_unref (GST_BUFFER (buf));
|
||||
else
|
||||
empty = TRUE;
|
||||
}
|
||||
|
||||
if (unwrap)
|
||||
g_queue_foreach (self->used_buffers, unwrap_buffer, self);
|
||||
|
||||
gst_mini_object_unref (GST_MINI_OBJECT (self));
|
||||
}
|
||||
|
||||
/** get buffer from bufferpool, allocate new buffer if needed */
|
||||
GstDucatiBuffer *
|
||||
gst_pvr_bufferpool_get (GstPvrBufferPool * self, GstBuffer * orig)
|
||||
{
|
||||
GstDucatiBuffer *buf = NULL;
|
||||
|
||||
g_return_val_if_fail (self, NULL);
|
||||
|
||||
GST_PVR_BUFFERPOOL_LOCK (self);
|
||||
if (self->running) {
|
||||
/* re-use a buffer off the freelist if any are available
|
||||
*/
|
||||
buf = g_queue_pop_head (self->free_buffers);
|
||||
if (!buf)
|
||||
buf = gst_ducati_buffer_new (self);
|
||||
buf->orig = orig;
|
||||
g_queue_push_head (self->used_buffers, buf);
|
||||
}
|
||||
GST_PVR_BUFFERPOOL_UNLOCK (self);
|
||||
|
||||
if (buf && orig) {
|
||||
GST_BUFFER_TIMESTAMP (buf) = GST_BUFFER_TIMESTAMP (orig);
|
||||
GST_BUFFER_DURATION (buf) = GST_BUFFER_DURATION (orig);
|
||||
}
|
||||
GST_BUFFER_SIZE (buf) = self->size;
|
||||
|
||||
return buf;
|
||||
gstbufferpool_class->get_options = pvr_buffer_pool_get_options;
|
||||
gstbufferpool_class->set_config = pvr_buffer_pool_set_config;
|
||||
gstbufferpool_class->alloc_buffer = pvr_buffer_pool_alloc;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_pvr_bufferpool_finalize (GstPvrBufferPool * self)
|
||||
gst_pvr_buffer_pool_init (GstPVRBufferPool * pool)
|
||||
{
|
||||
GST_DEBUG_OBJECT (self->element, "destroy bufferpool");
|
||||
g_mutex_free (self->lock);
|
||||
self->lock = NULL;
|
||||
|
||||
g_queue_free (self->free_buffers);
|
||||
self->free_buffers = NULL;
|
||||
g_queue_free (self->used_buffers);
|
||||
self->used_buffers = NULL;
|
||||
|
||||
gst_caps_unref (self->caps);
|
||||
self->caps = NULL;
|
||||
gst_object_unref (self->element);
|
||||
self->element = NULL;
|
||||
|
||||
GST_MINI_OBJECT_CLASS (bufferpool_parent_class)->finalize (GST_MINI_OBJECT
|
||||
(self));
|
||||
}
|
||||
|
||||
static void
|
||||
gst_pvr_bufferpool_class_init (gpointer g_class, gpointer class_data)
|
||||
gst_pvr_buffer_pool_finalize (GObject * object)
|
||||
{
|
||||
GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class);
|
||||
GstPVRBufferPool *pool = GST_PVR_BUFFER_POOL_CAST (object);
|
||||
|
||||
bufferpool_parent_class = g_type_class_peek_parent (g_class);
|
||||
GST_LOG_OBJECT (pool, "finalize PVR buffer pool %p", pool);
|
||||
|
||||
mini_object_class->finalize = (GstMiniObjectFinalizeFunction)
|
||||
GST_DEBUG_FUNCPTR (gst_pvr_bufferpool_finalize);
|
||||
}
|
||||
|
||||
GType
|
||||
gst_pvr_bufferpool_get_type (void)
|
||||
{
|
||||
static GType type;
|
||||
|
||||
if (G_UNLIKELY (type == 0)) {
|
||||
static const GTypeInfo info = {
|
||||
.class_size = sizeof (GstMiniObjectClass),
|
||||
.class_init = gst_pvr_bufferpool_class_init,
|
||||
.instance_size = sizeof (GstPvrBufferPool),
|
||||
};
|
||||
type = g_type_register_static (GST_TYPE_MINI_OBJECT,
|
||||
"GstPvrBufferPool", &info, 0);
|
||||
}
|
||||
return type;
|
||||
if (pool->caps)
|
||||
gst_caps_unref (pool->caps);
|
||||
gst_object_unref (pool->pvrsink);
|
||||
|
||||
G_OBJECT_CLASS (gst_pvr_buffer_pool_parent_class)->finalize (object);
|
||||
}
|
||||
|
|
|
@ -26,63 +26,56 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
GType gst_ducati_buffer_get_type (void);
|
||||
#define GST_TYPE_DUCATIBUFFER (gst_ducati_buffer_get_type())
|
||||
#define GST_IS_DUCATIBUFFER(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_DUCATIBUFFER))
|
||||
#define GST_DUCATIBUFFER(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_DUCATIBUFFER, GstDucatiBuffer))
|
||||
typedef struct _GstPVRMeta GstPVRMeta;
|
||||
|
||||
GType gst_pvr_bufferpool_get_type (void);
|
||||
#define GST_TYPE_PVRBUFFERPOOL (gst_pvr_bufferpool_get_type())
|
||||
#define GST_IS_PVRBUFFERPOOL(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PVRBUFFERPOOL))
|
||||
#define GST_PVRBUFFERPOOL(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PVRBUFFERPOOL, \
|
||||
GstPvrBufferPool))
|
||||
typedef struct _GstPVRBufferPool GstPVRBufferPool;
|
||||
typedef struct _GstPVRBufferPoolClass GstPVRBufferPoolClass;
|
||||
|
||||
typedef struct _GstPvrBufferPool GstPvrBufferPool;
|
||||
typedef struct _GstDucatiBuffer GstDucatiBuffer;
|
||||
#include "gstpvrvideosink.h"
|
||||
|
||||
struct _GstPvrBufferPool
|
||||
const GstMetaInfo * gst_pvr_meta_get_info (void);
|
||||
#define GST_PVR_META_INFO (gst_pvr_meta_get_info())
|
||||
|
||||
#define gst_buffer_get_pvr_meta(b) ((GstPVRMeta*)gst_buffer_get_meta((b),GST_PVR_META_INFO))
|
||||
|
||||
struct _GstPVRMeta
|
||||
{
|
||||
GstMiniObject parent;
|
||||
GstMeta meta;
|
||||
|
||||
PVR2DMEMINFO *src_mem; /* Memory wrapped by pvr */
|
||||
GstElement *sink; /* sink, holds a ref */
|
||||
};
|
||||
|
||||
GstPVRMeta *
|
||||
gst_buffer_add_pvr_meta(GstBuffer *buffer, GstElement *pvrsink);
|
||||
|
||||
#define GST_TYPE_PVR_BUFFER_POOL (gst_pvr_buffer_pool_get_type())
|
||||
#define GST_IS_PVR_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PVR_BUFFER_POOL))
|
||||
#define GST_PVR_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PVR_BUFFER_POOL, GstPVRBufferPool))
|
||||
#define GST_PVR_BUFFER_POOL_CAST(obj) ((GstPVRBufferPool*)(obj))
|
||||
|
||||
struct _GstPVRBufferPool
|
||||
{
|
||||
GstBufferPool parent;
|
||||
|
||||
/* output (padded) size including any codec padding: */
|
||||
gint padded_width, padded_height;
|
||||
gint size;
|
||||
PVR2DCONTEXTHANDLE pvr_context;
|
||||
guint size, align;
|
||||
|
||||
GstElement *pvrsink;
|
||||
|
||||
GstCaps *caps;
|
||||
GMutex *lock;
|
||||
gboolean running; /* with lock */
|
||||
GstElement *element; /* the element that owns us.. */
|
||||
GQueue *free_buffers;
|
||||
GQueue *used_buffers;
|
||||
guint buffer_count;
|
||||
GstVideoInfo info;
|
||||
gboolean add_metavideo;
|
||||
};
|
||||
|
||||
GstPvrBufferPool * gst_pvr_bufferpool_new (GstElement * element,
|
||||
GstCaps * caps, gint num_buffers, gint size,
|
||||
PVR2DCONTEXTHANDLE pvr_context);
|
||||
void gst_pvr_bufferpool_stop_running (GstPvrBufferPool * pool, gboolean unwrap);
|
||||
GstDucatiBuffer * gst_pvr_bufferpool_get (GstPvrBufferPool * self,
|
||||
GstBuffer * orig);
|
||||
|
||||
#define GST_PVR_BUFFERPOOL_LOCK(self) g_mutex_lock ((self)->lock)
|
||||
#define GST_PVR_BUFFERPOOL_UNLOCK(self) g_mutex_unlock ((self)->lock)
|
||||
|
||||
struct _GstDucatiBuffer {
|
||||
GstBuffer parent;
|
||||
|
||||
GstPvrBufferPool *pool; /* buffer-pool that this buffer belongs to */
|
||||
GstBuffer *orig; /* original buffer, if we need to copy output */
|
||||
PVR2DMEMINFO *src_mem; /* Memory wrapped by pvr */
|
||||
gboolean wrapped;
|
||||
struct _GstPVRBufferPoolClass
|
||||
{
|
||||
GstBufferPoolClass parent_class;
|
||||
};
|
||||
|
||||
GstBuffer * gst_ducati_buffer_get (GstDucatiBuffer * self);
|
||||
PVR2DMEMINFO * gst_ducati_buffer_get_meminfo (GstDucatiBuffer * self);
|
||||
GType gst_pvr_buffer_pool_get_type (void);
|
||||
GstBufferPool *gst_pvr_buffer_pool_new (GstElement *pvrsink);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -25,7 +25,6 @@
|
|||
|
||||
#include <gst/video/gstvideosink.h>
|
||||
#include <gst/video/video.h>
|
||||
#include "gstpvrbufferpool.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
@ -98,7 +97,6 @@ struct _GstXWindow
|
|||
* @fps_d: the framerate fraction denominator
|
||||
* @flow_lock: used to protect data flow routines from external calls such as
|
||||
* events from @event_thread or methods from the #GstXOverlay interface
|
||||
* @pool_lock: used to protect the buffer pool
|
||||
* @x_lock: used to protect X calls
|
||||
* @buffer_pool: a list of #GstPVRVideoBuffer that could be reused at next buffer
|
||||
* allocation call
|
||||
|
@ -115,20 +113,12 @@ struct _GstPVRVideoSink
|
|||
gboolean running;
|
||||
|
||||
/* Framerate numerator and denominator */
|
||||
GstVideoFormat format;
|
||||
gint fps_n;
|
||||
gint fps_d;
|
||||
gint rowstride;
|
||||
GstVideoInfo info;
|
||||
|
||||
GThread *event_thread;
|
||||
GMutex *flow_lock;
|
||||
|
||||
GMutex *pool_lock;
|
||||
GstPvrBufferPool *buffer_pool;
|
||||
gboolean pool_invalid;
|
||||
gint num_buffers;
|
||||
gboolean num_buffers_can_change;
|
||||
gint min_queued_bufs;
|
||||
GstBufferPool *pool;
|
||||
|
||||
gboolean keep_aspect;
|
||||
|
||||
|
@ -143,6 +133,9 @@ struct _GstPVRVideoSink
|
|||
gboolean redraw_borders;
|
||||
GstBuffer *current_buffer;
|
||||
|
||||
/* List of buffer using GstPVRMeta on ourselves */
|
||||
GList *metabuffers;
|
||||
|
||||
WSEGLDrawableParams render_params;
|
||||
};
|
||||
|
||||
|
@ -153,5 +146,8 @@ struct _GstPVRVideoSinkClass
|
|||
|
||||
GType gst_pvrvideosink_get_type (void);
|
||||
|
||||
void gst_pvrvideosink_track_buffer (GstPVRVideoSink * pvrsink, GstBuffer * buffer);
|
||||
void gst_pvrvideosink_untrack_buffer (GstPVRVideoSink * pvrsink, GstBuffer * buffer);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* __GST_PVRVIDEOSINK_H__ */
|
||||
|
|
Loading…
Reference in a new issue