mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 19:51:11 +00:00
- commented out remainder of Meta stuff
Original commit message from CVS: - commented out remainder of Meta stuff - enhanced mem_chunk allocation to round up to nearest 32 bytes this helps ensure that GstBuffers are more likely to be on cache-lines - added free() and copy() function pointers to GstBuffer - added code in _destroy and _copy to use above routines if !NULL - fixed up _copy code to suck less
This commit is contained in:
parent
09588296ae
commit
76cfe49b5e
2 changed files with 71 additions and 19 deletions
|
@ -33,8 +33,13 @@ static GMutex *_gst_buffer_chunk_lock;
|
|||
void
|
||||
_gst_buffer_initialize (void)
|
||||
{
|
||||
_gst_buffer_chunk = g_mem_chunk_new ("GstBuffer", sizeof(GstBuffer),
|
||||
sizeof(GstBuffer) * 16, G_ALLOC_AND_FREE);
|
||||
buffersize = sizeof(GstBuffer);
|
||||
|
||||
// round up to the nearest 32 bytes for cache-line and other efficiencies
|
||||
buffersize = ((buffersize-1 / 32) + 1) * 32;
|
||||
|
||||
_gst_buffer_chunk = g_mem_chunk_new ("GstBuffer", buffersize,
|
||||
buffersize * 32, G_ALLOC_AND_FREE);
|
||||
|
||||
_gst_buffer_chunk_lock = g_mutex_new ();
|
||||
}
|
||||
|
@ -56,7 +61,6 @@ gst_buffer_new(void)
|
|||
g_mutex_unlock (_gst_buffer_chunk_lock);
|
||||
GST_INFO (GST_CAT_BUFFER,"creating new buffer %p",buffer);
|
||||
|
||||
// g_print("allocating new mutex\n");
|
||||
buffer->lock = g_mutex_new ();
|
||||
#ifdef HAVE_ATOMIC_H
|
||||
atomic_set (&buffer->refcount, 1);
|
||||
|
@ -69,9 +73,11 @@ gst_buffer_new(void)
|
|||
buffer->maxsize = 0;
|
||||
buffer->offset = 0;
|
||||
buffer->timestamp = 0;
|
||||
buffer->metas = NULL;
|
||||
// buffer->metas = NULL;
|
||||
buffer->parent = NULL;
|
||||
buffer->pool = NULL;
|
||||
buffer->free = NULL;
|
||||
buffer->copy = NULL;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
@ -134,9 +140,14 @@ gst_buffer_create_sub (GstBuffer *parent,
|
|||
|
||||
// again, for lack of better, copy parent's timestamp
|
||||
buffer->timestamp = parent->timestamp;
|
||||
buffer->maxage = parent->maxage;
|
||||
|
||||
// no metas, this is sane I think
|
||||
buffer->metas = NULL;
|
||||
// buffer->metas = NULL;
|
||||
|
||||
// if the parent buffer is a subbuffer itself, use its parent, a real buffer
|
||||
if (parent->parent != NULL)
|
||||
parent = parent->parent;
|
||||
|
||||
// set parentage and reference the parent
|
||||
buffer->parent = parent;
|
||||
|
@ -203,7 +214,7 @@ gst_buffer_append (GstBuffer *buffer,
|
|||
*/
|
||||
void gst_buffer_destroy (GstBuffer *buffer)
|
||||
{
|
||||
GSList *metas;
|
||||
// GSList *metas;
|
||||
|
||||
g_return_if_fail (buffer != NULL);
|
||||
|
||||
|
@ -213,10 +224,15 @@ void gst_buffer_destroy (GstBuffer *buffer)
|
|||
if (GST_BUFFER_DATA (buffer) &&
|
||||
!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_DONTFREE) &&
|
||||
(buffer->parent == NULL)) {
|
||||
g_free (GST_BUFFER_DATA (buffer));
|
||||
// g_print("freed data in buffer\n");
|
||||
// if there's a free function, use it
|
||||
if (buffer->free != NULL) {
|
||||
(buffer->free)(buffer);
|
||||
} else {
|
||||
g_free (GST_BUFFER_DATA (buffer));
|
||||
}
|
||||
}
|
||||
|
||||
/* DEPRACATED!!!
|
||||
// unreference any metadata attached to this buffer
|
||||
metas = buffer->metas;
|
||||
while (metas) {
|
||||
|
@ -224,6 +240,7 @@ void gst_buffer_destroy (GstBuffer *buffer)
|
|||
metas = g_slist_next (metas);
|
||||
}
|
||||
g_slist_free (buffer->metas);
|
||||
*/
|
||||
|
||||
// unreference the parent if there is one
|
||||
if (buffer->parent != NULL)
|
||||
|
@ -332,7 +349,9 @@ gst_buffer_unref (GstBuffer *buffer)
|
|||
* @meta: the metadata to add to this buffer
|
||||
*
|
||||
* Add the meta data to the buffer.
|
||||
* DEPRACATED!!!
|
||||
*/
|
||||
/* DEPRACATED!!!
|
||||
void
|
||||
gst_buffer_add_meta (GstBuffer *buffer, GstMeta *meta)
|
||||
{
|
||||
|
@ -342,15 +361,18 @@ gst_buffer_add_meta (GstBuffer *buffer, GstMeta *meta)
|
|||
gst_meta_ref (meta);
|
||||
buffer->metas = g_slist_append (buffer->metas,meta);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* gst_buffer_get_metas:
|
||||
* @buffer: the GstBuffer to get the metadata from
|
||||
*
|
||||
* Get the metadatas from the buffer.
|
||||
* DEPRACATED!!!
|
||||
*
|
||||
* Returns: a GSList of metadata
|
||||
*/
|
||||
/* DEPRACATED!!!
|
||||
GSList*
|
||||
gst_buffer_get_metas (GstBuffer *buffer)
|
||||
{
|
||||
|
@ -358,15 +380,18 @@ gst_buffer_get_metas (GstBuffer *buffer)
|
|||
|
||||
return buffer->metas;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* gst_buffer_get_first_meta:
|
||||
* @buffer: the GstBuffer to get the metadata from
|
||||
*
|
||||
* Get the first metadata from the buffer.
|
||||
* DEPRACATED!!!
|
||||
*
|
||||
* Returns: the first metadata from the buffer
|
||||
*/
|
||||
/* DEPRACATED!!!
|
||||
GstMeta*
|
||||
gst_buffer_get_first_meta (GstBuffer *buffer)
|
||||
{
|
||||
|
@ -376,6 +401,7 @@ gst_buffer_get_first_meta (GstBuffer *buffer)
|
|||
return NULL;
|
||||
return GST_META (buffer->metas->data);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* gst_buffer_remove_meta:
|
||||
|
@ -383,7 +409,9 @@ gst_buffer_get_first_meta (GstBuffer *buffer)
|
|||
* @meta: the metadata to remove
|
||||
*
|
||||
* Remove the given metadata from the buffer.
|
||||
* DEPRACATED!!!
|
||||
*/
|
||||
/* DEPRACATED!!!
|
||||
void
|
||||
gst_buffer_remove_meta (GstBuffer *buffer, GstMeta *meta)
|
||||
{
|
||||
|
@ -393,6 +421,7 @@ gst_buffer_remove_meta (GstBuffer *buffer, GstMeta *meta)
|
|||
buffer->metas = g_slist_remove (buffer->metas, meta);
|
||||
gst_meta_unref (meta);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
@ -409,18 +438,29 @@ gst_buffer_copy (GstBuffer *buffer)
|
|||
{
|
||||
GstBuffer *newbuf;
|
||||
|
||||
// allocate a new buffer
|
||||
newbuf = gst_buffer_new();
|
||||
GST_BUFFER_SIZE(newbuf) = GST_BUFFER_SIZE(buffer);
|
||||
GST_BUFFER_DATA(newbuf) = malloc(GST_BUFFER_SIZE(buffer));
|
||||
memcpy(GST_BUFFER_DATA(newbuf),GST_BUFFER_DATA(buffer),GST_BUFFER_SIZE(buffer));
|
||||
GST_BUFFER_MAXSIZE(newbuf) = GST_BUFFER_MAXSIZE(buffer);
|
||||
GST_BUFFER_OFFSET(newbuf) = GST_BUFFER_OFFSET(buffer);
|
||||
GST_BUFFER_TIMESTAMP(newbuf) = GST_BUFFER_TIMESTAMP(buffer);
|
||||
GST_BUFFER_MAXAGE(newbuf) = GST_BUFFER_MAXAGE(buffer);
|
||||
|
||||
// if a copy function exists, use it, else copy the bytes
|
||||
if (buffer->copy != NULL) {
|
||||
(buffer->copy)(buffer,newbuf);
|
||||
} else {
|
||||
// copy the absolute size
|
||||
newbuf->size = buffer->size;
|
||||
// allocate space for the copy
|
||||
newbuf->data = (guchar *)g_malloc (buffer->data);
|
||||
// copy the data straight across
|
||||
memcpy(newbuf,buffer->data,buffer->size);
|
||||
// the new maxsize is the same as the size, since we just malloc'd it
|
||||
newbuf->maxsize = newbuf->size;
|
||||
}
|
||||
newbuf->offset = buffer->offset;
|
||||
newbuf->timestamp = buffer->timestamp;
|
||||
newbuf->maxage = buffer->maxage;
|
||||
|
||||
// since we just created a new buffer, so we have no ties to old stuff
|
||||
GST_BUFFER_PARENT(newbuf) = NULL;
|
||||
GST_BUFFER_POOL(newbuf) = NULL;
|
||||
newbuf->parent = NULL;
|
||||
newbuf->pool = NULL;
|
||||
|
||||
return newbuf;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#define __GST_BUFFER_H__
|
||||
|
||||
#include <gst/gstobject.h>
|
||||
#include <gst/gstmeta.h>
|
||||
//#include <gst/gstmeta.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
|
@ -80,8 +80,14 @@ typedef enum {
|
|||
} GstBufferFlags;
|
||||
|
||||
|
||||
|
||||
typedef struct _GstBuffer GstBuffer;
|
||||
|
||||
|
||||
typedef void (*GstBufferFreeFunc) (GstBuffer *buf);
|
||||
typedef void (*GstBufferCopyFunc) (GstBuffer *srcbuf,GstBuffer *dstbuf);
|
||||
|
||||
|
||||
#include <gst/gstbufferpool.h>
|
||||
|
||||
struct _GstBuffer {
|
||||
|
@ -112,7 +118,7 @@ struct _GstBuffer {
|
|||
guint64 maxage;
|
||||
|
||||
/* pointer to metadata, is really lame right now */
|
||||
GSList *metas;
|
||||
// GSList *metas;
|
||||
|
||||
/* subbuffer support, who's my parent? */
|
||||
GstBuffer *parent;
|
||||
|
@ -120,6 +126,10 @@ struct _GstBuffer {
|
|||
/* this is a pointer to the buffer pool (if any) */
|
||||
GstBufferPool *pool;
|
||||
gpointer pool_private;
|
||||
|
||||
/* utility function pointers */
|
||||
GstBufferFreeFunc free; // free the data associated with the buffer
|
||||
GstBufferCopyFunc copy; // copy the data from one buffer to another
|
||||
};
|
||||
|
||||
/* initialisation */
|
||||
|
@ -146,10 +156,12 @@ void gst_buffer_destroy (GstBuffer *buffer);
|
|||
GstBuffer* gst_buffer_copy (GstBuffer *buffer);
|
||||
|
||||
/* add, retrieve, and remove metadata from the buffer */
|
||||
/* DEPRACATED!!!
|
||||
void gst_buffer_add_meta (GstBuffer *buffer, GstMeta *meta);
|
||||
void gst_buffer_remove_meta (GstBuffer *buffer, GstMeta *meta);
|
||||
GstMeta* gst_buffer_get_first_meta (GstBuffer *buffer);
|
||||
GSList* gst_buffer_get_metas (GstBuffer *buffer);
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue