1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4 
5 #include <vorbis/vorbisfile.h>
6 
7 typedef int Ogg__Vorbis;
8 
9 static int
not_here(char * s)10 not_here(char *s)
11 {
12     croak("%s not implemented on this architecture", s);
13     return -1;
14 }
15 
16 static double
constant(char * name,int arg)17 constant(char *name, int arg)
18 {
19     errno = 0;
20     switch (*name) {
21     }
22     errno = EINVAL;
23     return 0;
24 
25 not_there:
26     errno = ENOENT;
27     return 0;
28 }
29 
30 
31 MODULE = Ogg::Vorbis    PACKAGE = Ogg::Vorbis   PREFIX = ov_
32 
33 PROTOTYPES: DISABLE
34 
35 double
36 constant(name,arg)
37 	char *		name
38 	int		arg
39 
40 OggVorbis_File*
41 new(CLASS)
42         char *CLASS
43         CODE:
44         RETVAL = (OggVorbis_File*) malloc(sizeof(OggVorbis_File));
45         OUTPUT:
46         RETVAL
47 
48 void
49 DESTROY(self)
50 	OggVorbis_File *self
51     CODE:
52 	safefree(self);
53 
54 int
55 ov_clear(self)
56         OggVorbis_File *self
57 
58 int
59 ov_open(self, file, initial="", ibytes=0)
60         OggVorbis_File *self
61         FILE *file
62         char *initial
63         long ibytes
64         CODE:
65         /* we swapped file and self for an OO interface */
66         RETVAL = ov_open(file, self, initial, ibytes);
67         OUTPUT:
68         RETVAL
69 
70 long
71 ov_streams(self)
72         OggVorbis_File *self
73 
74 long
75 ov_seekable(self)
76         OggVorbis_File *self
77 
78 long
79 ov_bitrate(self, i=-1)
80         OggVorbis_File *self
81         int i
82 
83 long
84 ov_serialnumber(self, i=-1)
85         OggVorbis_File *self
86         int i
87 
88 long
89 ov_bitrate_instant(self)
90         OggVorbis_File *self
91 
92 ogg_int64_t
93 ov_raw_total(self, i=-1)
94         OggVorbis_File *self
95         int i
96 
97 ogg_int64_t
98 ov_pcm_total(self, i=-1)
99         OggVorbis_File *self
100         int i
101 
102 double
103 ov_time_total(self, i=-1)
104         OggVorbis_File *self
105         int i
106 
107 int
108 ov_raw_seek(self, pos)
109         OggVorbis_File *self
110         long pos
111 
112 int
113 ov_pcm_seek_page(self, pos)
114         OggVorbis_File *self
115         ogg_int64_t pos
116 
117 int
118 ov_pcm_seek(self, pos)
119         OggVorbis_File *self
120         ogg_int64_t pos
121 
122 int
123 ov_time_seek(self, seconds)
124         OggVorbis_File *self
125         double seconds
126 
127 int
128 ov_time_seek_page(self, seconds)
129         OggVorbis_File *self
130         double seconds
131 
132 ogg_int64_t
133 ov_raw_tell(self)
134         OggVorbis_File *self
135 
136 ogg_int64_t
137 ov_pcm_tell(self)
138         OggVorbis_File *self
139 
140 double
141 ov_time_tell(self)
142         OggVorbis_File *self
143 
144 vorbis_info *
145 ov_info(self, link=-1)
146         OggVorbis_File *self
147         int link
148 
149 HV *
150 ov_comment(self, link=-1)
151         OggVorbis_File *self
152         int link
153         PREINIT:
154         char *key, *val;
155         int i, keylen, vallen;
156         vorbis_comment *comments;
157         SV *temp;
158         CODE:
159         /* fetch the comments */
160         comments = ov_comment(self, link);
161         RETVAL = newHV();
162         /* store the comments in a hash */
163         for (i=0; i < comments->comments; i++) {
164             key = comments->user_comments[i];
165             if (val = strchr(key, '=')) {
166                 keylen = val - key;
167                 *(val++) = '\0';
168                 vallen = comments->comment_lengths[i] - keylen - 1;
169                 hv_store(RETVAL, key, keylen, newSVpv((char*)val, vallen), 0);
170                 *(--val) = '=';
171             } else {
172                 fprintf(stderr, "warning: invalid comment field #%d\n", i);
173             }
174         }
175         OUTPUT:
176         RETVAL
177 
178 long
179 ov_read(self, buffer, length, bigendianp, word, sgned, bitstream)
180         OggVorbis_File* self
181         SV* buffer
182         int length
183         int bigendianp
184         int word
185         int sgned
186         int &bitstream
187         CODE:
188         /* If buffer is a string, read from the string */
189         if (SvPOKp(buffer)) {
190             RETVAL = ov_read(self, (char*)SvPV(buffer,PL_na), length,
191                              bigendianp, word, sgned, &bitstream);
192         } else {
193         /* otherwise buffer is a reference, de-reference it */
194             RETVAL = ov_read(self, (char*)SvRV(buffer), length,
195                              bigendianp, word, sgned, &bitstream);
196         }
197         OUTPUT:
198         RETVAL
199         bitstream
200 
201 
202 MODULE = Ogg::Vorbis    PACKAGE = Ogg::Vorbis::Info   PREFIX = ov_info_
203 
204 int
205 ov_info_version(self)
206         vorbis_info *self;
207         CODE:
208         RETVAL = self->version;
209         OUTPUT:
210         RETVAL
211 
212 int
213 ov_info_channels(self)
214         vorbis_info *self;
215         CODE:
216         RETVAL = self->channels;
217         OUTPUT:
218         RETVAL
219 
220 int
221 ov_info_rate(self)
222         vorbis_info *self;
223         CODE:
224         RETVAL = self->rate;
225         OUTPUT:
226         RETVAL
227 
228 int
229 ov_info_bitrate_upper(self)
230         vorbis_info *self;
231         CODE:
232         RETVAL = self->bitrate_upper;
233         OUTPUT:
234         RETVAL
235 
236 int
237 ov_info_bitrate_nominal(self)
238         vorbis_info *self;
239         CODE:
240         RETVAL = self->bitrate_nominal;
241         OUTPUT:
242         RETVAL
243 
244 int
245 ov_info_bitrate_lower(self)
246         vorbis_info *self;
247         CODE:
248         RETVAL = self->bitrate_lower;
249         OUTPUT:
250         RETVAL
251 
252