mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-02 00:32:43 +00:00
Added a plain copy of the bytstream code found in a52dec. it doesn't compile/work yet.
Original commit message from CVS: Added a plain copy of the bytstream code found in a52dec. it doesn't compile/work yet.
This commit is contained in:
parent
f3f3a8fe7d
commit
2377b5d86d
2 changed files with 170 additions and 0 deletions
114
gst/utils/gstbytestream.c
Normal file
114
gst/utils/gstbytestream.c
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
/* GStreamer
|
||||||
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
||||||
|
* 2000 Wim Taymans <wtay@chello.be>
|
||||||
|
*
|
||||||
|
* gstbytestreams.c: Utility functions: gtk_get_property stuff, etc.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the
|
||||||
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "gstbytestreams.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_bytestream_new:
|
||||||
|
* @pad: the pad to attach the bytstream to
|
||||||
|
*
|
||||||
|
* creates a bytestream from the given pad
|
||||||
|
*
|
||||||
|
* Returns: a new #GstByteStream object
|
||||||
|
*/
|
||||||
|
GstByteStream*
|
||||||
|
gst_bytestream_new (GstPad *pad)
|
||||||
|
{
|
||||||
|
GstByteStream *bs = g_new(GstByteStream, 1);
|
||||||
|
|
||||||
|
bs->pad = pad;
|
||||||
|
bs->data = NULL;
|
||||||
|
bs->size = 0;
|
||||||
|
bs->index = 0;
|
||||||
|
|
||||||
|
return bs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_bytestream_destroy (GstByteStream *bs)
|
||||||
|
{
|
||||||
|
if (bs->data) {
|
||||||
|
g_free(bs->data);
|
||||||
|
}
|
||||||
|
g_free(bs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_bytestream_bytes_fill (GstByteStream *bs, guint64 len)
|
||||||
|
{
|
||||||
|
size_t oldlen;
|
||||||
|
GstBuffer *buf;
|
||||||
|
|
||||||
|
while ((bs->index + len) > bs->size) {
|
||||||
|
buf = gst_pad_pull(bs->pad);
|
||||||
|
oldlen = bs->size - bs->index;
|
||||||
|
memmove(bs->data, bs->data + bs->index, oldlen);
|
||||||
|
bs->size = oldlen + GST_BUFFER_SIZE(buf);
|
||||||
|
bs->index = 0;
|
||||||
|
bs->data = realloc(bs->data, bs->size);
|
||||||
|
if (!bs->data) {
|
||||||
|
fprintf(stderr, "realloc failed: d:%p s:%d\n", bs->data, bs->size);
|
||||||
|
}
|
||||||
|
memcpy(bs->data + oldlen, GST_BUFFER_DATA(buf), GST_BUFFER_SIZE(buf));
|
||||||
|
}
|
||||||
|
g_assert ((bs->index + len) <= bs->size);
|
||||||
|
}
|
||||||
|
|
||||||
|
guint8*
|
||||||
|
gst_bytestream_bytes_peek (GstByteStream *bs, guint64 len)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (len > 0, NULL);
|
||||||
|
|
||||||
|
gst_bytestream_bytes_fill (bs, len);
|
||||||
|
|
||||||
|
return gst_bytestream_pos (bs);
|
||||||
|
}
|
||||||
|
|
||||||
|
guint8*
|
||||||
|
gst_bytestream_bytes_read (GstByteStream *bs, guint64 len)
|
||||||
|
{
|
||||||
|
guint8 *ptr;
|
||||||
|
|
||||||
|
g_return_val_if_fail (len > 0, NULL);
|
||||||
|
|
||||||
|
gst_bytestream_bytes_fill(bs, len);
|
||||||
|
ptr = gst_bytestream_pos(bs);
|
||||||
|
bs->index += len;
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gst_bytestream_bytes_seek (GstByteStream *bs, guint64 offset)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_bytestream_bytes_flush (GstByteStream *bs, guint64 len)
|
||||||
|
{
|
||||||
|
gst_bytestream_bytes_read(bs, len);
|
||||||
|
}
|
||||||
|
|
56
gst/utils/gstbytestream.h
Normal file
56
gst/utils/gstbytestream.h
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/* GStreamer
|
||||||
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
||||||
|
* 2000 Wim Taymans <wtay@chello.be>
|
||||||
|
*
|
||||||
|
* gstbytestream.h: Header for various utility functions
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the
|
||||||
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __GST_BYTESTREAM_H__
|
||||||
|
#define __GST_BYTESTREAM_H__
|
||||||
|
|
||||||
|
#include <gst/gstpad.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
typedef struct _GstByteStream GstByteStream;
|
||||||
|
|
||||||
|
struct _GstByteStream
|
||||||
|
{
|
||||||
|
GstPad *pad;
|
||||||
|
guint8 *data;
|
||||||
|
guint64 size;
|
||||||
|
guint64 index;
|
||||||
|
};
|
||||||
|
|
||||||
|
GstByteStream* gst_bytestream_new (GstPad *pad);
|
||||||
|
void gst_bytestream_destroy (GstByteStream *bs);
|
||||||
|
|
||||||
|
guint8* gst_bytestream_bytes_peek (GstByteStream *bs, guint64 len);
|
||||||
|
guint8* gst_bytestream_bytes_read (GstByteStream *bs, guint64 len);
|
||||||
|
gboolean gst_bytestream_bytes_seek (GstByteStream *bs, guint64 offset);
|
||||||
|
void gst_bytestream_bytes_flush (GstByteStream *bs, guint64 len);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
#endif /* __GST_BYTESTREAM_H__ */
|
Loading…
Reference in a new issue