1 /* GStreamer Wavpack plugin
2 * Copyright (c) 2006 Sebastian Dröge <slomo@circular-chaos.org>
4 * gstwavpackstreamreader.c: stream reader used for decoding
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
26 #include "gstwavpackstreamreader.h"
28 GST_DEBUG_CATEGORY_EXTERN (wavpack_debug);
29 #define GST_CAT_DEFAULT wavpack_debug
32 gst_wavpack_stream_reader_read_bytes (void *id, void *data, int32_t bcount)
34 read_id *rid = (read_id *) id;
35 uint32_t left = rid->length - rid->position;
36 uint32_t to_read = MIN (left, bcount);
38 GST_DEBUG ("Trying to read %d of %d bytes from position %d", bcount,
39 rid->length, rid->position);
42 g_memmove (data, rid->buffer + rid->position, to_read);
43 rid->position += to_read;
46 GST_WARNING ("Couldn't read %d bytes", bcount);
52 gst_wavpack_stream_reader_get_pos (void *id)
54 GST_DEBUG ("Returning position %d", ((read_id *) id)->position);
55 return ((read_id *) id)->position;
59 gst_wavpack_stream_reader_set_pos_abs (void *id, uint32_t pos)
61 GST_WARNING ("Should not be called: tried to set absolute position to %d",
67 gst_wavpack_stream_reader_set_pos_rel (void *id, int32_t delta, int mode)
69 GST_WARNING ("Should not be called: tried to set relative position to %d"
70 " with mode %d", delta, mode);
75 gst_wavpack_stream_reader_push_back_byte (void *id, int c)
77 read_id *rid = (read_id *) id;
79 GST_DEBUG ("Pushing back one byte: 0x%x", c);
82 if (rid->position < 0)
88 gst_wavpack_stream_reader_get_length (void *id)
90 GST_DEBUG ("Returning length %d", ((read_id *) id)->length);
92 return ((read_id *) id)->length;
96 gst_wavpack_stream_reader_can_seek (void *id)
98 GST_DEBUG ("Can't seek");
103 gst_wavpack_stream_reader_write_bytes (void *id, void *data, int32_t bcount)
105 GST_WARNING ("Should not be called, tried to write %d bytes", bcount);
109 WavpackStreamReader *
110 gst_wavpack_stream_reader_new (void)
112 WavpackStreamReader *stream_reader =
113 (WavpackStreamReader *) g_malloc0 (sizeof (WavpackStreamReader));
114 stream_reader->read_bytes = gst_wavpack_stream_reader_read_bytes;
115 stream_reader->get_pos = gst_wavpack_stream_reader_get_pos;
116 stream_reader->set_pos_abs = gst_wavpack_stream_reader_set_pos_abs;
117 stream_reader->set_pos_rel = gst_wavpack_stream_reader_set_pos_rel;
118 stream_reader->push_back_byte = gst_wavpack_stream_reader_push_back_byte;
119 stream_reader->get_length = gst_wavpack_stream_reader_get_length;
120 stream_reader->can_seek = gst_wavpack_stream_reader_can_seek;
121 stream_reader->write_bytes = gst_wavpack_stream_reader_write_bytes;
123 return stream_reader;