2001-09-16 14:29:20 +00:00
|
|
|
/* 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 <stdlib.h>
|
|
|
|
|
2001-09-16 18:22:42 +00:00
|
|
|
#include <gst/gstinfo.h>
|
2001-09-16 14:29:20 +00:00
|
|
|
#include "gstbytestream.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_bytestream_new:
|
|
|
|
* @pad: the pad to attach the bytstream to
|
|
|
|
*
|
|
|
|
* creates a bytestream from the given pad
|
|
|
|
*
|
|
|
|
* Returns: a new #GstByteStream object
|
|
|
|
*/
|
2001-09-16 18:22:42 +00:00
|
|
|
GstByteStream*
|
|
|
|
gst_bytestream_new (GstPad *pad)
|
2001-09-16 14:29:20 +00:00
|
|
|
{
|
|
|
|
GstByteStream *bs = g_new (GstByteStream, 1);
|
|
|
|
|
|
|
|
bs->pad = pad;
|
2001-09-16 18:22:42 +00:00
|
|
|
bs->buffer = NULL;
|
2001-09-16 14:29:20 +00:00
|
|
|
bs->index = 0;
|
|
|
|
bs->pos = 0;
|
2001-09-16 18:22:42 +00:00
|
|
|
bs->size = 0;
|
2001-09-16 14:29:20 +00:00
|
|
|
|
|
|
|
return bs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_bytestream_destroy (GstByteStream *bs)
|
|
|
|
{
|
2001-09-16 18:22:42 +00:00
|
|
|
if (bs->buffer) {
|
|
|
|
gst_buffer_unref (bs->buffer);
|
2001-09-16 14:29:20 +00:00
|
|
|
}
|
|
|
|
g_free (bs);
|
|
|
|
}
|
|
|
|
|
2001-09-16 18:22:42 +00:00
|
|
|
GstBuffer*
|
|
|
|
gst_bytestream_bytes_peek (GstByteStream *bs, guint64 len)
|
2001-09-16 14:29:20 +00:00
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
|
|
|
|
|
|
|
while ((bs->index + len) > bs->size) {
|
|
|
|
buf = gst_pad_pull (bs->pad);
|
2001-09-16 18:22:42 +00:00
|
|
|
|
|
|
|
if (!bs->buffer) {
|
|
|
|
bs->buffer = buf;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bs->buffer = gst_buffer_merge (bs->buffer, buf);
|
2001-09-16 14:29:20 +00:00
|
|
|
}
|
2001-09-16 18:22:42 +00:00
|
|
|
bs->size = GST_BUFFER_SIZE (bs->buffer);
|
2001-09-16 14:29:20 +00:00
|
|
|
}
|
|
|
|
|
2001-09-16 18:22:42 +00:00
|
|
|
buf = gst_buffer_create_sub (bs->buffer, bs->index, len);
|
2001-09-16 14:29:20 +00:00
|
|
|
|
2001-09-16 18:22:42 +00:00
|
|
|
return buf;
|
2001-09-16 14:29:20 +00:00
|
|
|
}
|
|
|
|
|
2001-09-16 18:22:42 +00:00
|
|
|
GstBuffer*
|
|
|
|
gst_bytestream_bytes_read (GstByteStream *bs, guint64 len)
|
2001-09-16 14:29:20 +00:00
|
|
|
{
|
2001-09-16 18:22:42 +00:00
|
|
|
GstBuffer *buf;
|
|
|
|
|
|
|
|
buf = gst_bytestream_bytes_peek (bs, len);
|
2001-09-16 14:29:20 +00:00
|
|
|
bs->index += len;
|
|
|
|
bs->pos += len;
|
|
|
|
|
2001-09-16 18:22:42 +00:00
|
|
|
return buf;
|
2001-09-16 14:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_bytestream_bytes_seek (GstByteStream *bs, guint64 offset)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
gst_bytestream_bytes_flush (GstByteStream *bs, guint64 len)
|
|
|
|
{
|
|
|
|
if (len == 0)
|
|
|
|
return len;
|
|
|
|
|
2001-09-16 18:22:42 +00:00
|
|
|
return GST_BUFFER_SIZE (gst_bytestream_bytes_read (bs, len));
|
2001-09-16 14:29:20 +00:00
|
|
|
}
|