]>
| Commit | Line | Data |
|---|---|---|
| a3f1cbda MG |
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 | ||
| eed4cab1 MG |
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 | ||
| a3f1cbda MG |
19 | MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile PREFIX = op_ |
| 20 | ||
| 21 | PROTOTYPES: ENABLE | |
| 22 | INCLUDE: const-xs.inc | |
| 23 | ||
| eed4cab1 | 24 | Audio::Opusfile |
| a3f1cbda MG |
25 | op_open_file(path) |
| 26 | const char *path; | |
| 27 | PREINIT: | |
| 28 | int err; | |
| 5fbea9a2 MG |
29 | C_ARGS: |
| 30 | path, &err | |
| 31 | POSTCALL: | |
| a3f1cbda MG |
32 | if(err) |
| 33 | croak("op_open_file returned error %d\n", err); | |
| 5fbea9a2 | 34 | |
| eed4cab1 | 35 | Audio::Opusfile |
| 5fbea9a2 MG |
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; | |
| a3f1cbda MG |
55 | OUTPUT: |
| 56 | RETVAL | |
| 57 | ||
| 5fbea9a2 | 58 | |
| a3f1cbda MG |
59 | void |
| 60 | DESTROY(of) | |
| eed4cab1 | 61 | Audio::Opusfile of; |
| a3f1cbda MG |
62 | CODE: |
| 63 | op_free(of); | |
| 64 | ||
| 5fbea9a2 MG |
65 | bool |
| 66 | op_seekable(of) | |
| eed4cab1 | 67 | Audio::Opusfile of; |
| 5fbea9a2 MG |
68 | |
| 69 | int | |
| 70 | op_link_count(of) | |
| eed4cab1 | 71 | Audio::Opusfile of; |
| 5fbea9a2 MG |
72 | |
| 73 | int | |
| 74 | op_serialno(of, li = -1) | |
| eed4cab1 | 75 | Audio::Opusfile of; |
| 5fbea9a2 MG |
76 | int li; |
| 77 | ||
| dc986a40 MG |
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; | |
| 9fc88b29 MG |
84 | POSTCALL: |
| 85 | if(RETVAL < 0) | |
| 86 | croak("op_current_link returned error %ld\n", RETVAL); | |
| dc986a40 MG |
87 | |
| 88 | long | |
| 89 | op_pcm_total(of, li = -1) | |
| 90 | Audio::Opusfile of; | |
| 91 | int li; | |
| 9fc88b29 MG |
92 | POSTCALL: |
| 93 | if(RETVAL < 0) | |
| 94 | croak("op_current_link returned error %ld\n", RETVAL); | |
| dc986a40 | 95 | |
| eed4cab1 | 96 | Audio::Opusfile::Head |
| a3f1cbda | 97 | op_head(of, li = -1) |
| eed4cab1 | 98 | Audio::Opusfile of; |
| a3f1cbda MG |
99 | int li; |
| 100 | ||
| eed4cab1 | 101 | Audio::Opusfile::Tags |
| a3f1cbda | 102 | op_tags(of, li = -1) |
| eed4cab1 | 103 | Audio::Opusfile of; |
| a3f1cbda MG |
104 | int li; |
| 105 | ||
| 9fc88b29 MG |
106 | int |
| 107 | op_current_link(of) | |
| 108 | Audio::Opusfile of; | |
| 109 | POSTCALL: | |
| 110 | if(RETVAL < 0) | |
| 111 | croak("op_current_link returned error %ld\n", RETVAL); | |
| dc986a40 MG |
112 | |
| 113 | int | |
| 114 | op_bitrate(of, li = -1) | |
| 115 | Audio::Opusfile of; | |
| 116 | int li; | |
| 9fc88b29 MG |
117 | POSTCALL: |
| 118 | if(RETVAL < 0) | |
| 119 | croak("op_bitrate returned error %ld\n", RETVAL); | |
| dc986a40 | 120 | |
| 318673cc MG |
121 | long |
| 122 | op_bitrate_instant(of) | |
| 123 | Audio::Opusfile of; | |
| 124 | POSTCALL: | |
| 125 | if(RETVAL < 0) | |
| 126 | croak("op_bitrate_instant returned error %ld\n", RETVAL); | |
| 127 | ||
| 128 | long | |
| 129 | op_raw_tell(of) | |
| 130 | Audio::Opusfile of; | |
| 131 | POSTCALL: | |
| 132 | if(RETVAL < 0) | |
| 133 | croak("op_raw_tell returned error %ld\n", RETVAL); | |
| 134 | ||
| 135 | long | |
| 136 | op_pcm_tell(of) | |
| 137 | Audio::Opusfile of; | |
| 138 | POSTCALL: | |
| 139 | if(RETVAL < 0) | |
| 140 | croak("op_pcm_tell returned error %ld\n", RETVAL); | |
| 141 | ||
| 142 | NO_OUTPUT int | |
| 143 | op_raw_seek(of, offset) | |
| 144 | Audio::Opusfile of; | |
| 145 | long offset; | |
| 146 | POSTCALL: | |
| 147 | if(RETVAL) | |
| 148 | croak("op_raw_seek returned error %d\n", RETVAL); | |
| 149 | ||
| 150 | NO_OUTPUT int | |
| 151 | op_pcm_seek(of, offset) | |
| 152 | Audio::Opusfile of; | |
| 153 | long offset; | |
| 154 | POSTCALL: | |
| 155 | if(RETVAL) | |
| 156 | croak("op_pcm_seek returned error %d\n", RETVAL); | |
| 157 | ||
| 158 | NO_OUTPUT int | |
| 159 | op_set_gain_offset(of, gain_type, gain_offset_q8) | |
| 160 | Audio::Opusfile of; | |
| 161 | int gain_type; | |
| 162 | int gain_offset_q8; | |
| 163 | POSTCALL: | |
| 164 | if(RETVAL) | |
| 165 | croak("op_set_gain_offset returned error %d\n", RETVAL); | |
| 166 | ||
| 167 | void | |
| 168 | op_set_dither_enabled(of, enabled) | |
| 169 | Audio::Opusfile of; | |
| 170 | int enabled; | |
| 171 | ||
| 172 | ||
| 173 | void | |
| 174 | op_read(of, bufsize = 1024 * 1024) | |
| 175 | Audio::Opusfile of; | |
| 176 | int bufsize; | |
| 177 | PREINIT: | |
| 178 | opus_int16* buf; | |
| 179 | int li, ret, chans, i; | |
| 180 | PPCODE: | |
| 181 | Newx(buf, bufsize, opus_int16); | |
| 182 | ret = op_read(of, buf, bufsize, &li); | |
| 183 | if(ret < 0) | |
| 184 | croak("op_read returned error %d\n", ret); | |
| 185 | chans = op_channel_count(of, li); | |
| 186 | EXTEND(SP, chans * ret + 1); | |
| 187 | PUSHs(sv_2mortal(newSViv(li))); | |
| 188 | for(i = 0 ; i < chans * ret ; i++) | |
| 189 | PUSHs(sv_2mortal(newSViv(buf[i]))); | |
| 190 | ||
| 191 | void | |
| 192 | op_read_float(of, bufsize = 1024 * 1024) | |
| 193 | Audio::Opusfile of; | |
| 194 | int bufsize; | |
| 195 | PREINIT: | |
| 196 | float* buf; | |
| 197 | int li, ret, chans, i; | |
| 198 | PPCODE: | |
| 199 | Newx(buf, bufsize, float); | |
| 200 | ret = op_read_float(of, buf, bufsize, &li); | |
| 201 | if(ret < 0) | |
| 202 | croak("op_read_float returned error %d\n", ret); | |
| 203 | chans = op_channel_count(of, li); | |
| 204 | EXTEND(SP, chans * ret + 1); | |
| 205 | PUSHs(sv_2mortal(newSViv(li))); | |
| 206 | for(i = 0 ; i < chans * ret ; i++) | |
| 207 | PUSHs(sv_2mortal(newSVnv(buf[i]))); | |
| 208 | ||
| 209 | void | |
| 210 | op_read_stereo(of, bufsize = 1024 * 1024) | |
| 211 | Audio::Opusfile of; | |
| 212 | int bufsize; | |
| 213 | PREINIT: | |
| 214 | opus_int16* buf; | |
| 215 | int ret, i; | |
| 216 | PPCODE: | |
| 217 | Newx(buf, bufsize, opus_int16); | |
| 218 | ret = op_read_stereo(of, buf, bufsize); | |
| 219 | if(ret < 0) | |
| 220 | croak("op_read_stereo returned error %d\n", ret); | |
| 221 | EXTEND(SP, 2 * ret); | |
| 222 | for(i = 0 ; i < 2 * ret ; i++) | |
| 223 | PUSHs(sv_2mortal(newSViv(buf[i]))); | |
| 224 | ||
| 225 | void | |
| 226 | op_read_float_stereo(of, bufsize = 1024 * 1024) | |
| 227 | Audio::Opusfile of; | |
| 228 | int bufsize; | |
| 229 | PREINIT: | |
| 230 | float* buf; | |
| 231 | int ret, i; | |
| 232 | PPCODE: | |
| 233 | Newx(buf, bufsize, float); | |
| 234 | ret = op_read_float_stereo(of, buf, bufsize); | |
| 235 | if(ret < 0) | |
| 236 | croak("op_read_float_stereo returned error %d\n", ret); | |
| 237 | EXTEND(SP, 2 * ret); | |
| 238 | for(i = 0 ; i < 2 * ret ; i++) | |
| 239 | PUSHs(sv_2mortal(newSVnv(buf[i]))); | |
| 240 | ||
| 241 | ||
| dc986a40 | 242 | |
| a3f1cbda MG |
243 | MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::Tags PREFIX = opus_tags_ |
| 244 | ||
| 245 | int | |
| 246 | opus_tags_query_count(tags, tag) | |
| eed4cab1 | 247 | Audio::Opusfile::Tags tags; |
| a3f1cbda MG |
248 | const char* tag; |
| 249 | ||
| 250 | const char* | |
| 251 | opus_tags_query(tags, tag, count = 0) | |
| eed4cab1 | 252 | Audio::Opusfile::Tags tags; |
| a3f1cbda MG |
253 | const char* tag; |
| 254 | int count; | |
| 2f4b5b1b MG |
255 | |
| 256 | MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::PictureTag PREFIX = opus_picture_tag_ | |
| 257 | ||
| eed4cab1 | 258 | Audio::Opusfile::PictureTag |
| 2f4b5b1b MG |
259 | opus_picture_tag_parse(tag) |
| 260 | const char *tag; | |
| 261 | PREINIT: | |
| 262 | OpusPictureTag *pic; | |
| 263 | int err; | |
| 264 | CODE: | |
| 265 | Newx(pic, 1, OpusPictureTag); | |
| 266 | if(err = opus_picture_tag_parse(pic, tag)) | |
| 267 | croak("opus_picture_tag_parse returned error %d\n", err); | |
| 268 | RETVAL = pic; | |
| 269 | OUTPUT: | |
| 270 | RETVAL | |
| 271 | ||
| 272 | void | |
| 273 | DESTROY(pic) | |
| eed4cab1 | 274 | Audio::Opusfile::PictureTag pic |
| 2f4b5b1b MG |
275 | CODE: |
| 276 | Safefree(pic); | |
| 277 | ||
| 278 | int | |
| 279 | type(pic) | |
| eed4cab1 | 280 | Audio::Opusfile::PictureTag pic; |
| 2f4b5b1b MG |
281 | CODE: |
| 282 | RETVAL = pic->type; | |
| 283 | OUTPUT: | |
| 284 | RETVAL | |
| 285 | ||
| 286 | const char* | |
| 287 | mime_type(pic) | |
| eed4cab1 | 288 | Audio::Opusfile::PictureTag pic; |
| 2f4b5b1b MG |
289 | CODE: |
| 290 | RETVAL = pic->mime_type; | |
| 291 | OUTPUT: | |
| 292 | RETVAL | |
| 293 | ||
| 294 | const char* | |
| 295 | description(pic) | |
| eed4cab1 | 296 | Audio::Opusfile::PictureTag pic; |
| 2f4b5b1b MG |
297 | CODE: |
| 298 | RETVAL = pic->description; | |
| 299 | OUTPUT: | |
| 300 | RETVAL | |
| 301 | ||
| 302 | int | |
| 303 | width(pic) | |
| eed4cab1 | 304 | Audio::Opusfile::PictureTag pic; |
| 2f4b5b1b MG |
305 | CODE: |
| 306 | RETVAL = pic->width; | |
| 307 | OUTPUT: | |
| 308 | RETVAL | |
| 309 | ||
| 310 | int | |
| 311 | height(pic) | |
| eed4cab1 | 312 | Audio::Opusfile::PictureTag pic; |
| 2f4b5b1b MG |
313 | CODE: |
| 314 | RETVAL = pic->height; | |
| 315 | OUTPUT: | |
| 316 | RETVAL | |
| 317 | ||
| 318 | int | |
| 319 | depth(pic) | |
| eed4cab1 | 320 | Audio::Opusfile::PictureTag pic; |
| 2f4b5b1b MG |
321 | CODE: |
| 322 | RETVAL = pic->depth; | |
| 323 | OUTPUT: | |
| 324 | RETVAL | |
| 325 | ||
| 326 | int | |
| 327 | colors(pic) | |
| eed4cab1 | 328 | Audio::Opusfile::PictureTag pic; |
| 2f4b5b1b MG |
329 | CODE: |
| 330 | RETVAL = pic->colors; | |
| 331 | OUTPUT: | |
| 332 | RETVAL | |
| 333 | ||
| 334 | int | |
| 335 | data_length(pic) | |
| eed4cab1 | 336 | Audio::Opusfile::PictureTag pic; |
| 2f4b5b1b MG |
337 | CODE: |
| 338 | RETVAL = pic->data_length; | |
| 339 | OUTPUT: | |
| 340 | RETVAL | |
| 341 | ||
| 342 | SV* | |
| 343 | data(pic) | |
| eed4cab1 | 344 | Audio::Opusfile::PictureTag pic; |
| 2f4b5b1b MG |
345 | CODE: |
| 346 | RETVAL = newSVpvn(pic->data, pic->data_length); | |
| 347 | OUTPUT: | |
| 348 | RETVAL | |
| 349 | ||
| 350 | int | |
| 351 | format(pic) | |
| eed4cab1 | 352 | Audio::Opusfile::PictureTag pic; |
| 2f4b5b1b MG |
353 | CODE: |
| 354 | RETVAL = pic->format; | |
| 355 | OUTPUT: | |
| 356 | RETVAL | |
| 357 | ||
| 358 | MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::Head | |
| 359 | ||
| 360 | int | |
| 361 | version(head) | |
| eed4cab1 | 362 | Audio::Opusfile::Head head; |
| 2f4b5b1b MG |
363 | CODE: |
| 364 | RETVAL = head->version; | |
| 365 | OUTPUT: | |
| 366 | RETVAL | |
| 367 | ||
| 368 | int | |
| 369 | channel_count(head) | |
| eed4cab1 | 370 | Audio::Opusfile::Head head; |
| 2f4b5b1b MG |
371 | CODE: |
| 372 | RETVAL = head->channel_count; | |
| 373 | OUTPUT: | |
| 374 | RETVAL | |
| 375 | ||
| 376 | unsigned | |
| 377 | pre_skip(head) | |
| eed4cab1 | 378 | Audio::Opusfile::Head head; |
| 2f4b5b1b MG |
379 | CODE: |
| 380 | RETVAL = head->pre_skip; | |
| 381 | OUTPUT: | |
| 382 | RETVAL | |
| 383 | ||
| 384 | unsigned | |
| 385 | input_sample_rate(head) | |
| eed4cab1 | 386 | Audio::Opusfile::Head head; |
| 2f4b5b1b MG |
387 | CODE: |
| 388 | RETVAL = head->input_sample_rate; | |
| 389 | OUTPUT: | |
| 390 | RETVAL | |
| 391 | ||
| aca25728 MG |
392 | int |
| 393 | output_gain(head) | |
| 394 | Audio::Opusfile::Head head; | |
| 395 | CODE: | |
| 396 | RETVAL = head->output_gain; | |
| 397 | OUTPUT: | |
| 398 | RETVAL | |
| 399 | ||
| 2f4b5b1b MG |
400 | int |
| 401 | mapping_family(head) | |
| eed4cab1 | 402 | Audio::Opusfile::Head head; |
| 2f4b5b1b MG |
403 | CODE: |
| 404 | RETVAL = head->mapping_family; | |
| 405 | OUTPUT: | |
| 406 | RETVAL | |
| 407 | ||
| 408 | int | |
| 409 | stream_count(head) | |
| eed4cab1 | 410 | Audio::Opusfile::Head head; |
| 2f4b5b1b MG |
411 | CODE: |
| 412 | RETVAL = head->stream_count; | |
| 413 | OUTPUT: | |
| 414 | RETVAL | |
| 415 | ||
| 416 | int | |
| 417 | coupled_count(head) | |
| eed4cab1 | 418 | Audio::Opusfile::Head head; |
| 2f4b5b1b MG |
419 | CODE: |
| 420 | RETVAL = head->coupled_count; | |
| 421 | OUTPUT: | |
| 422 | RETVAL | |
| 423 | ||
| 424 | int | |
| 425 | mapping(head, k) | |
| eed4cab1 | 426 | Audio::Opusfile::Head head; |
| b6589960 | 427 | unsigned k; |
| 2f4b5b1b | 428 | CODE: |
| b6589960 MG |
429 | if(k >= OPUS_CHANNEL_COUNT_MAX) |
| 430 | croak("k must be less than %d\n", (int)OPUS_CHANNEL_COUNT_MAX); | |
| 2f4b5b1b MG |
431 | RETVAL = (int) head->mapping[k]; |
| 432 | OUTPUT: | |
| 433 | RETVAL |