configure.ac: Check for wavpack version and define WAVPACK_OLD_API if necessary.
[platform/upstream/gst-plugins-good.git] / ext / wavpack / gstwavpackstreamreader.c
1 /* GStreamer Wavpack plugin
2  * Copyright (c) 2006 Sebastian Dröge <slomo@circular-chaos.org>
3  *
4  * gstwavpackstreamreader.c: stream reader used for decoding
5  *
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.
10  *
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.
15  *
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.
20  */
21
22 #include <string.h>
23 #include <math.h>
24 #include <gst/gst.h>
25
26 #include "gstwavpackstreamreader.h"
27
28 static int32_t
29 gst_wavpack_stream_reader_read_bytes (void *id, void *data, int32_t bcount)
30 {
31   read_id *rid = (read_id *) id;
32   uint32_t left = rid->length - rid->position;
33   uint32_t to_read = MIN (left, bcount);
34
35   if (to_read > 0) {
36     g_memmove (data, rid->buffer + rid->position, to_read);
37     rid->position += to_read;
38     return to_read;
39   } else {
40     return 0;
41   }
42 }
43
44 static uint32_t
45 gst_wavpack_stream_reader_get_pos (void *id)
46 {
47   return ((read_id *) id)->position;
48 }
49
50 static int
51 gst_wavpack_stream_reader_set_pos_abs (void *id, uint32_t pos)
52 {
53   return -1;
54 }
55
56 static int
57 gst_wavpack_stream_reader_set_pos_rel (void *id, int32_t delta, int mode)
58 {
59   return -1;
60 }
61
62 static int
63 gst_wavpack_stream_reader_push_back_byte (void *id, int c)
64 {
65   read_id *rid = (read_id *) id;
66
67   rid->position -= 1;
68   if (rid->position < 0)
69     rid->position = 0;
70   return rid->position;
71 }
72
73 static uint32_t
74 gst_wavpack_stream_reader_get_length (void *id)
75 {
76   return ((read_id *) id)->length;
77 }
78
79 static int
80 gst_wavpack_stream_reader_can_seek (void *id)
81 {
82   return FALSE;
83 }
84
85 static int32_t
86 gst_wavpack_stream_reader_write_bytes (void *id, void *data, int32_t bcount)
87 {
88   return 0;
89 }
90
91 WavpackStreamReader *
92 gst_wavpack_stream_reader_new ()
93 {
94   WavpackStreamReader *stream_reader =
95       (WavpackStreamReader *) g_malloc0 (sizeof (WavpackStreamReader));
96   stream_reader->read_bytes = gst_wavpack_stream_reader_read_bytes;
97   stream_reader->get_pos = gst_wavpack_stream_reader_get_pos;
98   stream_reader->set_pos_abs = gst_wavpack_stream_reader_set_pos_abs;
99   stream_reader->set_pos_rel = gst_wavpack_stream_reader_set_pos_rel;
100   stream_reader->push_back_byte = gst_wavpack_stream_reader_push_back_byte;
101   stream_reader->get_length = gst_wavpack_stream_reader_get_length;
102   stream_reader->can_seek = gst_wavpack_stream_reader_can_seek;
103   stream_reader->write_bytes = gst_wavpack_stream_reader_write_bytes;
104
105   return stream_reader;
106 }