Ogg-Vorbis-LibVorbis
view release on metacpan or search on metacpan
LibVorbis.xs view on Meta::CPAN
/* http://www.xiph.org/ogg/vorbis/doc/vorbisfile/ov_callbacks.html */
ov_callbacks vorbis_callbacks = {
ovcb_read,
ovcb_seek,
ovcb_close,
ovcb_tell
};
/* Allow multiple instances of the decoder object. Stuff each filehandle into (void*)stream */
typedef struct {
int is_streaming;
int bytes_streamed;
int last_bitstream;
PerlIO *stream;
} ocvb_datasource;
typedef PerlIO * OutputStream;
typedef PerlIO * InputStream;
static int _arr_rows;
LibVorbis.xs view on Meta::CPAN
read_bytes = PerlIO_read(datasource->stream, ptr, size * nmemb);
datasource->bytes_streamed += read_bytes;
return read_bytes;
}
static int ovcb_seek(void *vdatasource, ogg_int64_t offset, int whence) {
ocvb_datasource *datasource = vdatasource;
if (datasource->is_streaming) {
return -1;
}
/* For some reason PerlIO_seek fails miserably here. < 5.8.1 works */
/* return PerlIO_seek(datasource->stream, offset, whence); */
return fseek(PerlIO_findFILE(datasource->stream), offset, whence);
}
static int ovcb_close(void *vdatasource) {
ocvb_datasource *datasource = vdatasource;
return PerlIO_close(datasource->stream);
}
static long ovcb_tell(void *vdatasource) {
ocvb_datasource *datasource = vdatasource;
if (datasource->is_streaming) {
return datasource->bytes_streamed;
}
return PerlIO_tell(datasource->stream);
}
static void * get_mortalspace ( size_t nbytes ) {
SV * mortal;
mortal = sv_2mortal( NEWSV(0, nbytes ) );
return (void *) SvPVX( mortal );
LibVorbis.xs view on Meta::CPAN
/* check and see if a pathname was passed in, otherwise it might be a
* IO::Socket subclass, or even a *FH Glob */
if (SvOK(path) && (SvTYPE(SvRV(path)) != SVt_PVGV)) {
if ((datasource->stream = PerlIO_open((char*)SvPV_nolen(path), "r")) == NULL) {
safefree(vf);
fprintf(stderr, "failed on open: [%d] - [%s]\n", errno, strerror(errno));
XSRETURN_UNDEF;
}
datasource->is_streaming = 0;
} else if (SvOK(path)) {
/* Did we get a Glob, or a IO::Socket subclass? */
if (sv_isobject(path) && sv_derived_from(path, "IO::Socket")) {
datasource->is_streaming = 1;
} else {
datasource->is_streaming = 0;
}
/* dereference and get the SV* that contains the Magic & FH,
* then pull the fd from the PerlIO object */
datasource->stream = IoIFP(GvIOp(SvRV(path)));
} else {
fp = PerlIO_findFILE((PerlIO *)IoIFP(sv_2io(path)));
/* check whether it is a valid file handler */
LibVorbis.xs view on Meta::CPAN
/* check and see if a pathname was passed in, otherwise it might be a
* IO::Socket subclass, or even a *FH Glob */
if (SvOK(path) && (SvTYPE(SvRV(path)) != SVt_PVGV)) {
if ((datasource->stream = PerlIO_open((char*)SvPV_nolen(path), "r")) == NULL) {
safefree(vf);
printf("failed on open: [%d] - [%s]\n", errno, strerror(errno));
XSRETURN_UNDEF;
}
datasource->is_streaming = 0;
} else if (SvOK(path)) {
/* Did we get a Glob, or a IO::Socket subclass? */
if (sv_isobject(path) && sv_derived_from(path, "IO::Socket")) {
datasource->is_streaming = 1;
} else {
datasource->is_streaming = 0;
}
/* dereference and get the SV* that contains the Magic & FH,
* then pull the fd from the PerlIO object */
datasource->stream = IoIFP(GvIOp(SvRV(path)));
} else {
fp = PerlIO_findFILE((PerlIO *)IoIFP(sv_2io(path)));
/* check whether it is a valid file handler */
( run in 0.241 second using v1.01-cache-2.11-cpan-4d50c553e7e )