mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-04 23:30:05 +00:00
1 Add GST_BUFFER_WHERE support to bytestream.
Original commit message from CVS: 1 Add GST_BUFFER_WHERE support to bytestream. 2 Sort live buffers by timestamp. <g> 3 Rename GST_WHERE macro to GST_WHERE_ARGS.
This commit is contained in:
parent
03587e2155
commit
2cbb2ffd35
4 changed files with 69 additions and 34 deletions
|
@ -33,8 +33,8 @@ static GMemChunk *_gst_buffer_chunk;
|
|||
static GMutex *_gst_buffer_chunk_lock;
|
||||
|
||||
#ifdef GST_BUFFER_WHERE
|
||||
static GSList *_debug_live = 0;
|
||||
# define GST_BUFFERS_COUNT (g_slist_length(_debug_live))
|
||||
static GList *_debug_live = 0;
|
||||
# define GST_BUFFERS_COUNT (g_list_length(_debug_live))
|
||||
#else
|
||||
# define GST_BUFFERS_COUNT 1
|
||||
#endif
|
||||
|
@ -74,14 +74,14 @@ _gst_buffer_initialize (void)
|
|||
* Returns: new buffer
|
||||
*/
|
||||
GstBuffer*
|
||||
gst_buffer_new_loc (GST_WHERE)
|
||||
gst_buffer_new_loc (GST_WHERE_ARGS)
|
||||
{
|
||||
GstBuffer *buffer;
|
||||
|
||||
g_mutex_lock (_gst_buffer_chunk_lock);
|
||||
buffer = g_mem_chunk_alloc (_gst_buffer_chunk);
|
||||
#ifdef GST_BUFFER_WHERE
|
||||
_debug_live = g_slist_prepend (_debug_live, buffer);
|
||||
_debug_live = g_list_prepend (_debug_live, buffer);
|
||||
#endif
|
||||
g_mutex_unlock (_gst_buffer_chunk_lock);
|
||||
GST_INFO (GST_CAT_BUFFER,"creating new buffer %p",buffer);
|
||||
|
@ -152,7 +152,7 @@ gst_buffer_new_from_pool (GstBufferPool *pool, guint32 offset, guint32 size)
|
|||
* Returns: new buffer
|
||||
*/
|
||||
GstBuffer*
|
||||
gst_buffer_create_sub_loc (GST_WHERE_
|
||||
gst_buffer_create_sub_loc (GST_WHERE_ARGS_
|
||||
GstBuffer *parent,
|
||||
guint32 offset,
|
||||
guint32 size)
|
||||
|
@ -166,7 +166,7 @@ gst_buffer_create_sub_loc (GST_WHERE_
|
|||
g_mutex_lock (_gst_buffer_chunk_lock);
|
||||
buffer = g_mem_chunk_alloc (_gst_buffer_chunk);
|
||||
#ifdef GST_BUFFER_WHERE
|
||||
_debug_live = g_slist_prepend (_debug_live, buffer);
|
||||
_debug_live = g_list_prepend (_debug_live, buffer);
|
||||
#endif
|
||||
g_mutex_unlock (_gst_buffer_chunk_lock);
|
||||
GST_INFO (GST_CAT_BUFFER,"creating new subbuffer %p from parent %p (size %u, offset %u)",
|
||||
|
@ -228,7 +228,7 @@ gst_buffer_create_sub_loc (GST_WHERE_
|
|||
* Returns: new buffer
|
||||
*/
|
||||
GstBuffer*
|
||||
gst_buffer_append_loc (GST_WHERE_
|
||||
gst_buffer_append_loc (GST_WHERE_ARGS_
|
||||
GstBuffer *buffer,
|
||||
GstBuffer *append)
|
||||
{
|
||||
|
@ -278,7 +278,7 @@ gst_buffer_destroy (GstBuffer *buffer)
|
|||
|
||||
g_return_if_fail (buffer != NULL);
|
||||
|
||||
GST_INFO (GST_CAT_BUFFER, "freeing %sbuffer %p (%ld buffers remain)",
|
||||
GST_INFO (GST_CAT_BUFFER, "freeing %sbuffer %p (%d buffers remain)",
|
||||
(buffer->parent?"sub":""),
|
||||
buffer,
|
||||
GST_BUFFERS_COUNT - 1);
|
||||
|
@ -311,23 +311,42 @@ gst_buffer_destroy (GstBuffer *buffer)
|
|||
g_mutex_lock (_gst_buffer_chunk_lock);
|
||||
g_mem_chunk_free (_gst_buffer_chunk,buffer);
|
||||
#ifdef GST_BUFFER_WHERE
|
||||
_debug_live = g_slist_delete_link (_debug_live,
|
||||
g_slist_find (_debug_live, buffer));
|
||||
_debug_live = g_list_delete_link (_debug_live,
|
||||
g_list_find (_debug_live, buffer));
|
||||
#endif
|
||||
g_mutex_unlock (_gst_buffer_chunk_lock);
|
||||
}
|
||||
|
||||
#ifdef GST_BUFFER_WHERE
|
||||
static gint
|
||||
_compare_buffer (GstBuffer *b1, GstBuffer *b2)
|
||||
{
|
||||
if (b1->timestamp == b2->timestamp)
|
||||
return 0;
|
||||
else if (b1->timestamp > b2->timestamp)
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
void gst_buffer_print_live ()
|
||||
{
|
||||
GSList *elem;
|
||||
GList *sorted;
|
||||
GList *elem;
|
||||
|
||||
for (elem = _debug_live; elem; elem = elem->next) {
|
||||
sorted = g_list_sort (_debug_live, (GCompareFunc) _compare_buffer);
|
||||
// g_slist_sort is broken 20010922
|
||||
|
||||
for (elem = sorted; elem; elem = elem->next) {
|
||||
GstBuffer *buf = elem->data;
|
||||
g_print ("%sbuffer %p created %s:%d data=%p size=0x%lx\n",
|
||||
g_print ("%sbuffer %p created %s:%d data=%p size=0x%x\n",
|
||||
buf->parent? "sub":" ",
|
||||
buf, buf->file, buf->line, buf->data, buf->size);
|
||||
}
|
||||
|
||||
g_print ("(%d buffers)\n", g_list_length (sorted));
|
||||
|
||||
g_list_free (sorted);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -397,7 +416,7 @@ gst_buffer_unref (GstBuffer *buffer)
|
|||
* Returns: new buffer
|
||||
*/
|
||||
GstBuffer *
|
||||
gst_buffer_copy_loc (GST_WHERE_ GstBuffer *buffer)
|
||||
gst_buffer_copy_loc (GST_WHERE_ARGS_ GstBuffer *buffer)
|
||||
{
|
||||
GstBuffer *newbuf;
|
||||
|
||||
|
@ -466,7 +485,7 @@ gst_buffer_is_span_fast (GstBuffer *buf1, GstBuffer *buf2)
|
|||
*/
|
||||
// FIXME need to think about CoW and such...
|
||||
GstBuffer *
|
||||
gst_buffer_span_loc (GST_WHERE_
|
||||
gst_buffer_span_loc (GST_WHERE_ARGS_
|
||||
GstBuffer *buf1, guint32 offset, GstBuffer *buf2, guint32 len)
|
||||
{
|
||||
GstBuffer *newbuf;
|
||||
|
@ -528,7 +547,7 @@ gst_buffer_span_loc (GST_WHERE_
|
|||
* Returns: new buffer that's the concatenation of the source buffers
|
||||
*/
|
||||
GstBuffer *
|
||||
gst_buffer_merge_loc (GST_WHERE_
|
||||
gst_buffer_merge_loc (GST_WHERE_ARGS_
|
||||
GstBuffer *buf1, GstBuffer *buf2)
|
||||
{
|
||||
// we're just a specific case of the more general gst_buffer_span()
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
// Define this to add file:line info to each GstBuffer showing
|
||||
// the location in the source code where the buffer was created.
|
||||
//
|
||||
// #define GST_BUFFER_WHERE
|
||||
#define GST_BUFFER_WHERE
|
||||
//
|
||||
// Then in gdb, you can `call gst_buffer_print_live()' to get a list
|
||||
// of allocated GstBuffers and also the file:line where they were
|
||||
|
@ -153,8 +153,8 @@ struct _GstBuffer {
|
|||
|
||||
#ifdef GST_BUFFER_WHERE
|
||||
|
||||
# define GST_WHERE const gchar *where_file, gint where_line
|
||||
# define GST_WHERE_ GST_WHERE,
|
||||
# define GST_WHERE_ARGS const gchar *where_file, gint where_line
|
||||
# define GST_WHERE_ARGS_ GST_WHERE_ARGS,
|
||||
# define GST_WHERE_VARS where_file, where_line
|
||||
# define GST_WHERE_VARS_ where_file, where_line,
|
||||
|
||||
|
@ -173,8 +173,8 @@ struct _GstBuffer {
|
|||
|
||||
#else /* GST_BUFFER_WHERE */
|
||||
|
||||
# define GST_WHERE
|
||||
# define GST_WHERE_
|
||||
# define GST_WHERE_ARGS
|
||||
# define GST_WHERE_ARGS_
|
||||
# define GST_WHERE_VARS
|
||||
# define GST_WHERE_VARS_
|
||||
|
||||
|
@ -196,11 +196,11 @@ struct _GstBuffer {
|
|||
/* initialisation */
|
||||
void _gst_buffer_initialize (void);
|
||||
/* creating a new buffer from scratch */
|
||||
GstBuffer* gst_buffer_new_loc (GST_WHERE);
|
||||
GstBuffer* gst_buffer_new_loc (GST_WHERE_ARGS);
|
||||
GstBuffer* gst_buffer_new_from_pool (GstBufferPool *pool, guint32 offset, guint32 size);
|
||||
|
||||
/* creating a subbuffer */
|
||||
GstBuffer* gst_buffer_create_sub_loc (GST_WHERE_
|
||||
GstBuffer* gst_buffer_create_sub_loc (GST_WHERE_ARGS_
|
||||
GstBuffer *parent, guint32 offset, guint32 size);
|
||||
|
||||
/* refcounting */
|
||||
|
@ -211,15 +211,15 @@ void gst_buffer_unref (GstBuffer *buffer);
|
|||
void gst_buffer_destroy (GstBuffer *buffer);
|
||||
|
||||
/* copy buffer */
|
||||
GstBuffer* gst_buffer_copy_loc (GST_WHERE_
|
||||
GstBuffer* gst_buffer_copy_loc (GST_WHERE_ARGS_
|
||||
GstBuffer *buffer);
|
||||
|
||||
/* merge, span, or append two buffers, intelligently */
|
||||
GstBuffer* gst_buffer_merge_loc (GST_WHERE_
|
||||
GstBuffer* gst_buffer_merge_loc (GST_WHERE_ARGS_
|
||||
GstBuffer *buf1, GstBuffer *buf2);
|
||||
GstBuffer* gst_buffer_span_loc (GST_WHERE_
|
||||
GstBuffer* gst_buffer_span_loc (GST_WHERE_ARGS_
|
||||
GstBuffer *buf1,guint32 offset,GstBuffer *buf2,guint32 len);
|
||||
GstBuffer* gst_buffer_append_loc (GST_WHERE_
|
||||
GstBuffer* gst_buffer_append_loc (GST_WHERE_ARGS_
|
||||
GstBuffer *buf, GstBuffer *buf2);
|
||||
|
||||
gboolean gst_buffer_is_span_fast (GstBuffer *buf1, GstBuffer *buf2);
|
||||
|
|
|
@ -167,7 +167,7 @@ gst_bytestream_fill_bytes (GstByteStream * bs, guint32 len)
|
|||
|
||||
|
||||
GstBuffer *
|
||||
gst_bytestream_peek (GstByteStream * bs, guint32 len)
|
||||
gst_bytestream_peek_loc (GST_WHERE_ARGS_ GstByteStream * bs, guint32 len)
|
||||
{
|
||||
GstBuffer *headbuf, *retbuf = NULL;
|
||||
|
||||
|
@ -192,14 +192,14 @@ gst_bytestream_peek (GstByteStream * bs, guint32 len)
|
|||
if (len <= bs->headbufavail) {
|
||||
bs_print ("peek: there are enough bytes in headbuf (need %d, have %d)\n", len, bs->headbufavail);
|
||||
// create a sub-buffer of the headbuf
|
||||
retbuf = gst_buffer_create_sub (headbuf, GST_BUFFER_SIZE (headbuf) - bs->headbufavail, len);
|
||||
retbuf = gst_buffer_create_sub_loc (GST_WHERE_VARS_ headbuf, GST_BUFFER_SIZE (headbuf) - bs->headbufavail, len);
|
||||
|
||||
// otherwise we need to figure out how to assemble one
|
||||
}
|
||||
else {
|
||||
bs_print ("peek: current buffer is not big enough for len %d\n", len);
|
||||
|
||||
retbuf = gst_buffer_new ();
|
||||
retbuf = gst_buffer_new_loc (GST_WHERE_VARS);
|
||||
GST_BUFFER_SIZE (retbuf) = len;
|
||||
GST_BUFFER_DATA (retbuf) = gst_bytestream_assemble (bs, len);
|
||||
if (GST_BUFFER_OFFSET (headbuf) != -1)
|
||||
|
@ -343,9 +343,9 @@ gst_bytestream_flush (GstByteStream * bs, guint32 len)
|
|||
}
|
||||
|
||||
GstBuffer *
|
||||
gst_bytestream_read (GstByteStream * bs, guint32 len)
|
||||
gst_bytestream_read_loc (GST_WHERE_ARGS_ GstByteStream * bs, guint32 len)
|
||||
{
|
||||
GstBuffer *buf = gst_bytestream_peek (bs, len);
|
||||
GstBuffer *buf = gst_bytestream_peek_loc (GST_WHERE_VARS_ bs, len);
|
||||
gst_bytestream_flush (bs, len);
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -39,11 +39,27 @@ struct _GstByteStream {
|
|||
GstByteStream* gst_bytestream_new (GstPad *pad);
|
||||
void gst_bytestream_destroy (GstByteStream *bs);
|
||||
|
||||
GstBuffer* gst_bytestream_read (GstByteStream *bs, guint32 len);
|
||||
GstBuffer* gst_bytestream_peek (GstByteStream *bs, guint32 len);
|
||||
GstBuffer* gst_bytestream_read_loc (GST_WHERE_ARGS_ GstByteStream *bs, guint32 len);
|
||||
GstBuffer* gst_bytestream_peek_loc (GST_WHERE_ARGS_ GstByteStream *bs, guint32 len);
|
||||
guint8* gst_bytestream_peek_bytes (GstByteStream *bs, guint32 len);
|
||||
gboolean gst_bytestream_flush (GstByteStream *bs, guint32 len);
|
||||
|
||||
void gst_bytestream_print_status (GstByteStream *bs);
|
||||
|
||||
#ifdef GST_BUFFER_WHERE
|
||||
|
||||
# define gst_bytestream_read(bs, len) \
|
||||
gst_bytestream_read_loc(__FILE__, __LINE__, bs, len)
|
||||
# define gst_bytestream_peek(bs, len) \
|
||||
gst_bytestream_peek_loc(__FILE__, __LINE__, bs, len)
|
||||
|
||||
#else /* GST_BUFFER_WHERE */
|
||||
|
||||
# define gst_bytestream_read(bs, len) \
|
||||
gst_bytestream_read_loc(bs, len)
|
||||
# define gst_bytestream_peek(bs, len) \
|
||||
gst_bytestream_peek_loc(bs, len)
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* __GST_BYTESTREAM_H__ */
|
||||
|
|
Loading…
Reference in a new issue