a8bd27b585c8107bb1868060b79a011b641af42b
[audio-opusfile.git] / Opusfile.xs
1 #define PERL_NO_GET_CONTEXT
2 #include "EXTERN.h"
3 #include "perl.h"
4 #include "XSUB.h"
5
6 #include "ppport.h"
7
8 /* op_free is both Perl_op_free and a function in opusfile */
9 #undef op_free
10 #include <opus/opusfile.h>
11
12 #include "const-c.inc"
13
14 typedef OggOpusFile* Audio__Opusfile;
15 typedef const OpusHead* Audio__Opusfile__Head;
16 typedef const OpusTags* Audio__Opusfile__Tags;
17 typedef const OpusPictureTag* Audio__Opusfile__PictureTag;
18
19 MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile PREFIX = op_
20
21 PROTOTYPES: ENABLE
22 INCLUDE: const-xs.inc
23
24 Audio::Opusfile
25 op_open_file(path)
26 const char *path;
27 PREINIT:
28 int err;
29 C_ARGS:
30 path, &err
31 POSTCALL:
32 if(err)
33 croak("op_open_file returned error %d\n", err);
34
35 Audio::Opusfile
36 op_open_memory(const char *data, size_t length(data))
37 PREINIT:
38 int err;
39 C_ARGS:
40 data, XSauto_length_of_data, &err
41 POSTCALL:
42 if(err)
43 croak("op_open_memory returned error %d\n", err);
44
45 bool
46 op_test(const char *data, size_t length(data))
47 PROTOTYPE: $
48 PREINIT:
49 int ret;
50 CODE:
51 ret = op_test (NULL, data, XSauto_length_of_data);
52 if(ret < 0 && ret != OP_ENOTFORMAT && ret != OP_EBADHEADER)
53 croak("op_test returned error %d\n", RETVAL);
54 RETVAL = !ret;
55 OUTPUT:
56 RETVAL
57
58
59 void
60 DESTROY(of)
61 Audio::Opusfile of;
62 CODE:
63 op_free(of);
64
65 bool
66 op_seekable(of)
67 Audio::Opusfile of;
68
69 int
70 op_link_count(of)
71 Audio::Opusfile of;
72
73 int
74 op_serialno(of, li = -1)
75 Audio::Opusfile of;
76 int li;
77
78 # op_channel_count is not exported; it can be obtained via op_head
79
80 long
81 op_raw_total(of, li = -1)
82 Audio::Opusfile of;
83 int li;
84
85 long
86 op_pcm_total(of, li = -1)
87 Audio::Opusfile of;
88 int li;
89
90 Audio::Opusfile::Head
91 op_head(of, li = -1)
92 Audio::Opusfile of;
93 int li;
94
95 Audio::Opusfile::Tags
96 op_tags(of, li = -1)
97 Audio::Opusfile of;
98 int li;
99
100 # op_current_link not exported until we export the decoding API
101
102 int
103 op_bitrate(of, li = -1)
104 Audio::Opusfile of;
105 int li;
106
107 # op_bitrate_instant, op_raw_tell, op_pcm_tell not exported until we
108 # export the decoding API
109
110 MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::Tags PREFIX = opus_tags_
111
112 int
113 opus_tags_query_count(tags, tag)
114 Audio::Opusfile::Tags tags;
115 const char* tag;
116
117 const char*
118 opus_tags_query(tags, tag, count = 0)
119 Audio::Opusfile::Tags tags;
120 const char* tag;
121 int count;
122
123 MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::PictureTag PREFIX = opus_picture_tag_
124
125 Audio::Opusfile::PictureTag
126 opus_picture_tag_parse(tag)
127 const char *tag;
128 PREINIT:
129 OpusPictureTag *pic;
130 int err;
131 CODE:
132 Newx(pic, 1, OpusPictureTag);
133 if(err = opus_picture_tag_parse(pic, tag))
134 croak("opus_picture_tag_parse returned error %d\n", err);
135 RETVAL = pic;
136 OUTPUT:
137 RETVAL
138
139 void
140 DESTROY(pic)
141 Audio::Opusfile::PictureTag pic
142 CODE:
143 Safefree(pic);
144
145 int
146 type(pic)
147 Audio::Opusfile::PictureTag pic;
148 CODE:
149 RETVAL = pic->type;
150 OUTPUT:
151 RETVAL
152
153 const char*
154 mime_type(pic)
155 Audio::Opusfile::PictureTag pic;
156 CODE:
157 RETVAL = pic->mime_type;
158 OUTPUT:
159 RETVAL
160
161 const char*
162 description(pic)
163 Audio::Opusfile::PictureTag pic;
164 CODE:
165 RETVAL = pic->description;
166 OUTPUT:
167 RETVAL
168
169 int
170 width(pic)
171 Audio::Opusfile::PictureTag pic;
172 CODE:
173 RETVAL = pic->width;
174 OUTPUT:
175 RETVAL
176
177 int
178 height(pic)
179 Audio::Opusfile::PictureTag pic;
180 CODE:
181 RETVAL = pic->height;
182 OUTPUT:
183 RETVAL
184
185 int
186 depth(pic)
187 Audio::Opusfile::PictureTag pic;
188 CODE:
189 RETVAL = pic->depth;
190 OUTPUT:
191 RETVAL
192
193 int
194 colors(pic)
195 Audio::Opusfile::PictureTag pic;
196 CODE:
197 RETVAL = pic->colors;
198 OUTPUT:
199 RETVAL
200
201 int
202 data_length(pic)
203 Audio::Opusfile::PictureTag pic;
204 CODE:
205 RETVAL = pic->data_length;
206 OUTPUT:
207 RETVAL
208
209 SV*
210 data(pic)
211 Audio::Opusfile::PictureTag pic;
212 CODE:
213 RETVAL = newSVpvn(pic->data, pic->data_length);
214 OUTPUT:
215 RETVAL
216
217 int
218 format(pic)
219 Audio::Opusfile::PictureTag pic;
220 CODE:
221 RETVAL = pic->format;
222 OUTPUT:
223 RETVAL
224
225 MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::Head
226
227 int
228 version(head)
229 Audio::Opusfile::Head head;
230 CODE:
231 RETVAL = head->version;
232 OUTPUT:
233 RETVAL
234
235 int
236 channel_count(head)
237 Audio::Opusfile::Head head;
238 CODE:
239 RETVAL = head->channel_count;
240 OUTPUT:
241 RETVAL
242
243 unsigned
244 pre_skip(head)
245 Audio::Opusfile::Head head;
246 CODE:
247 RETVAL = head->pre_skip;
248 OUTPUT:
249 RETVAL
250
251 unsigned
252 input_sample_rate(head)
253 Audio::Opusfile::Head head;
254 CODE:
255 RETVAL = head->input_sample_rate;
256 OUTPUT:
257 RETVAL
258
259 int
260 output_gain(head)
261 Audio::Opusfile::Head head;
262 CODE:
263 RETVAL = head->output_gain;
264 OUTPUT:
265 RETVAL
266
267 int
268 mapping_family(head)
269 Audio::Opusfile::Head head;
270 CODE:
271 RETVAL = head->mapping_family;
272 OUTPUT:
273 RETVAL
274
275 int
276 stream_count(head)
277 Audio::Opusfile::Head head;
278 CODE:
279 RETVAL = head->stream_count;
280 OUTPUT:
281 RETVAL
282
283 int
284 coupled_count(head)
285 Audio::Opusfile::Head head;
286 CODE:
287 RETVAL = head->coupled_count;
288 OUTPUT:
289 RETVAL
290
291 int
292 mapping(head, k)
293 Audio::Opusfile::Head head;
294 unsigned k;
295 CODE:
296 if(k >= OPUS_CHANNEL_COUNT_MAX)
297 croak("k must be less than %d\n", (int)OPUS_CHANNEL_COUNT_MAX);
298 RETVAL = (int) head->mapping[k];
299 OUTPUT:
300 RETVAL
This page took 0.027658 seconds and 3 git commands to generate.