Ogg-LibOgg
view release on metacpan or search on metacpan
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include<stdio.h>
#include <ogg/ogg.h>
typedef PerlIO * OutputStream;
typedef PerlIO * InputStream;
#define OGG_BUF_SIZE 4096
MODULE = Ogg::LibOgg PACKAGE = Ogg::LibOgg PREFIX = Ogg_LibOgg_
PROTOTYPES: DISABLE
=head1 Ogg::LibOgg
XS Code for Ogg bindings for Perl.
=cut
=head1 Functions (malloc)
Memory Allocation for the Ogg Structures
=cut
=head2 make_ogg_packet
Creates an Ogg Packet.
-Input:
Void
-Output:
Memory address of Ogg Packet.
=cut
void
Ogg_LibOgg_make_ogg_packet()
PREINIT:
ogg_packet *memory;
PPCODE:
New(0, memory, 1, ogg_packet); // it always satisfies with what we have asked
XPUSHs(sv_2mortal(newSViv(PTR2IV(memory)))); // since i am using sv_2mortal, i don't have to worry about leaks
=head2 make_ogg_stream_state
Creates an Ogg Stream State.
-Input:
Void
-Output:
Memory address of Ogg Stream State.
=cut
void
Ogg_LibOgg_make_ogg_stream_state()
PREINIT:
ogg_stream_state *memory;
PPCODE:
New(0, memory, 1, ogg_stream_state);
XPUSHs(sv_2mortal(newSViv(PTR2IV(memory))));
=head2 make_ogg_page
Creates an Ogg Page.
-Input:
Void
-Output:
Memory address of Ogg Page.
=cut
void
Ogg_LibOgg_make_ogg_page()
PREINIT:
ogg_page *memory;
PPCODE:
New(0, memory, 1, ogg_page);
XPUSHs(sv_2mortal(newSViv(PTR2IV(memory))));
=head2 make_ogg_sync_state
Creates an Ogg Sync State.
-Input:
Void
-Output:
Memory address of Ogg Sync State.
=cut
void
Ogg_LibOgg_make_ogg_sync_state()
PREINIT:
ogg_sync_state *memory;
PPCODE:
New(0, memory, 1, ogg_sync_state);
XPUSHs(sv_2mortal(newSViv(PTR2IV(memory))));
=head1 Functions (Bitstream Primitives)
=cut
=head2 ogg_stream_init
This function is used to initialize an ogg_stream_state struct and
allocates appropriate memory in preparation for encoding or decoding.
(http://www.xiph.org/ogg/doc/libogg/ogg_stream_init.html)
-Input:
ogg_stream_state (memory addr)
serial number
-Output:
0 if successful
-1 if unsuccessful
=cut
int
ogg_stream_init(os, serialno)
int os
int serialno
PREINIT:
ogg_stream_state *_os;
CODE:
_os = INT2PTR(ogg_stream_state *, os);
RETVAL = ogg_stream_init(_os, serialno);
OUTPUT:
RETVAL
=head2 ogg_read_page
This function is a B<wrapper around ogg_sync_pageout>. In an actual decoding loop,
this function should be called first to ensure that the buffer is cleared. The
example code below illustrates a clean reading loop which will fill and output pages.
ogg_sync_pageout takes the data stored in the buffer of the ogg_sync_state struct
and inserts them into an ogg_page.
if (ogg_sync_pageout(&oy, &og) != 1) {
buffer = ogg_sync_buffer(&oy, 8192);
bytes = fread(buffer, 1, 8192, stdin);
ogg_sync_wrote(&oy, bytes);
}
-Input:
FILE *
ogg_sync_state
ogg_page
-Output:
-1 buffer overflow or internal error (status of ogg_sync_wrote)
0 all other cases
0, always
=cut
int
Ogg_LibOgg_ogg_sync_destroy(oy)
int oy
PREINIT:
ogg_sync_state *_oy;
CODE:
_oy = INT2PTR(ogg_sync_state *, oy);
RETVAL = ogg_sync_destroy(_oy);
OUTPUT:
RETVAL
=head2 ogg_sync_check
This function is used to check the error or readiness condition of an ogg_sync_state
structure. (http://www.xiph.org/ogg/doc/libogg/ogg_sync_check.html)
-Input:
ogg_sync_state
-Output:
0, is returned if the ogg_sync_state structure is initialized and ready.
!= 0, if the structure was never initialized, or if an unrecoverable internal error
=cut
int
Ogg_LibOgg_ogg_sync_check(oy)
int oy
PREINIT:
ogg_sync_state *_oy;
CODE:
_oy = INT2PTR(ogg_sync_state *, oy);
RETVAL = ogg_sync_check(_oy);
OUTPUT:
RETVAL
=head2 ogg_sync_buffer
This function is used to provide a properly-sized buffer for writing.
(http://www.xiph.org/ogg/doc/libogg/ogg_sync_buffer.html)
-Input:
ogg_sync_state
size
-Output:
Returns a pointer to the newly allocated buffer or NULL on error
=cut
void
Ogg_LibOgg_ogg_sync_buffer(oy, size);
int oy
int size
PREINIT:
ogg_sync_state *_oy;
char *buffer;
PPCODE:
_oy = INT2PTR(ogg_sync_state *, oy);
if((buffer = ogg_sync_buffer(_oy, size)) != NULL) {
XPUSHs(sv_2mortal(newSViv(PTR2IV(buffer))));
} else {
XSRETURN_UNDEF;
}
=head2 ogg_sync_wrote
This function is used to tell the ogg_sync_state struct how many bytes we
wrote into the buffer.
(http://www.xiph.org/ogg/doc/libogg/ogg_sync_wrote.html)
-Input:
ogg_sync_state
bytes
-Output:
-1 if the number of bytes written overflows the internal storage of
the ogg_sync_state struct or an internal error occurred.
0 in all other cases.
=cut
int
Ogg_LibOgg_ogg_sync_wrote(oy, bytes)
int oy
long bytes
PREINIT:
ogg_sync_state *_oy;
CODE:
_oy = INT2PTR(ogg_sync_state *, oy);
RETVAL = ogg_sync_wrote(_oy, bytes);
OUTPUT:
RETVAL
=head2 ogg_sync_pageseek
This function synchronizes the ogg_sync_state struct to the next ogg_page.
(http://www.xiph.org/ogg/doc/libogg/ogg_sync_pageseek.html)
-Input:
ogg_sync_state
ogg_page
-Output:
-n means that we skipped n bytes within the bitstream.
0 means that we need more data, or than an internal error occurred.
n means that the page was synced at the current location,
with a page length of n bytes.
=cut
int
Ogg_LibOgg_ogg_sync_pageseek(oy, og)
int oy
int og
PREINIT:
ogg_sync_state *_oy;
ogg_page *_og;
( run in 0.907 second using v1.01-cache-2.11-cpan-5511b514fd6 )