{This unit is part of United Openlibraries of Sound (uos)}
{This is the Pascal Wrapper + Dynamic loading of OpusFile library.
Load library with of_load() and release with of_unload().
License : modified LGPL.
Fred van Stappen / fiens@hotmail.com}
unit uos_OpusFile;
{$mode objfpc}{$H+}
{$PACKRECORDS C}
interface
uses
ctypes, dynlibs, classes, pipes, SysUtils;
type
TOpusFile = ^OpusFile;
OpusFile = record
end;
const
libop=
{$IFDEF unix}
{$IFDEF darwin}
'libopusfile.0.dylib';
{$ELSE}
'libopusfile.so.0';
{$ENDIF}
{$ELSE}
'opusfile.dll';
{$ENDIF}
// Error Codes
const
OP_FALSE = -1;
OP_HOLE = -3;
OP_EREAD = -128;
OP_EFAULT = -129;
OP_EIMPL = -130;
OP_EINVAL = -131;
OP_ENOTVORBIS = -132;
OP_EBADHEADER = -133;
OP_EVERSION = -134;
OP_ENOTAUDIO = -135;
OP_EBADPACKET = -136;
OP_EBADLINK = -137;
OP_ENOSEEK = -138;
OP_EBADTIMESTAMP = -139;
{
/**A request did not succeed.*/
#define OP_FALSE (-1)
/*Currently not used externally.*/
#define OP_EOF (-2)
/**There was a hole in the page sequence numbers (e.g., a page was corrupt or
missing).*/
#define OP_HOLE (-3)
/**An underlying read, seek, or tell operation failed when it should have
succeeded.*/
#define OP_EREAD (-128)
/**A NULL pointer was passed where one was unexpected, or an
internal memory allocation failed, or an internal library error was
encountered.*/
#define OP_EFAULT (-129)
/**The stream used a feature that is not implemented, such as an unsupported
channel family.*/
#define OP_EIMPL (-130)
/**One or more parameters to a function were invalid.*/
#define OP_EINVAL (-131)
/**A purported Ogg Opus stream did not begin with an Ogg page, a purported
header packet did not start with one of the required strings, "OpusHead" or
"OpusTags", or a link in a chained file was encountered that did not
contain any logical Opus streams.*/
#define OP_ENOTFORMAT (-132)
/**A required header packet was not properly formatted, contained illegal
values, or was missing altogether.*/
#define OP_EBADHEADER (-133)
/**The ID header contained an unrecognized version number.*/
#define OP_EVERSION (-134)
/*Currently not used at all.*/
#define OP_ENOTAUDIO (-135)
/**An audio packet failed to decode properly.
This is usually caused by a multistream Ogg packet where the durations of
the individual Opus packets contained in it are not all the same.*/
#define OP_EBADPACKET (-136)
/**We failed to find data we had seen before, or the bitstream structure was
sufficiently malformed that seeking to the target destination was
impossible.*/
#define OP_EBADLINK (-137)
/**An operation that requires seeking was requested on an unseekable stream.*/
#define OP_ENOSEEK (-138)
/**The first or last granule position of a link failed basic validity checks.*/
#define OP_EBADTIMESTAMP (-139)
}
type
TOP_PIC_FORMAT = (OP_PIC_FORMAT_UNKNOWN = -1, OP_PIC_FORMAT_URL, OP_PIC_FORMAT_JPEG,
OP_PIC_FORMAT_PNG, OP_PIC_FORMAT_GIF);
type
TOpusHead = THandle;
TOpusStream = THandle;
op_read_func = function (stream: Pointer; var buffer; nbytes: cint): cint; cdecl;
op_seek_func = function (stream: Pointer; offset: Int64; whence: cint): cint; cdecl;
op_tell_func = function (stream: Pointer): Int64; cdecl;
op_close_func = function (stream: Pointer): cint; cdecl;
TOpusFileCallbacks = record
read: op_read_func;
seek: op_seek_func;
tell: op_tell_func;
close: op_close_func;
end;
function OpusReadCB(stream: Pointer; var buffer; nbytes: cint): cint; cdecl;
function OpusReadCBuosURL(stream: Pointer; var buffer; nbytes: cint): cint; cdecl;
function OpusReadCBuosMS(stream: Pointer; var buffer; nbytes: cint): cint; cdecl;
function OpusSeekCB(stream: Pointer; offset: Int64; whence: cint): cint; cdecl;
function OpusTellCB(stream: Pointer): Int64; cdecl;
function OpusCloseCB(stream: Pointer): cint; cdecl;
function OpusSeekCBMS(stream: Pointer; offset: Int64; whence: cint): cint; cdecl;
function OpusTellCBMS(stream: Pointer): Int64; cdecl;
const
op_callbacks: TOpusFileCallbacks = (read: @OpusReadCB;
seek: @OpusSeekCB;
tell: @OpusTellCB;
close: nil);
uos_callbacks: TOpusFileCallbacks = (read: @OpusReadCBuosURL;
seek: @OpusSeekCB;
tell: @OpusTellCB;
close: nil);
uos_callbacksms: TOpusFileCallbacks = (read: @OpusReadCBuosms;
seek: @OpusSeekCBms;
tell: @OpusTellCBms;
close: nil);
type
TOpusMSDecoder = Pointer;
op_decode_cb_func = function(ctx: Pointer; decoder: TOpusMSDecoder; pcm : pcfloat; op: Pointer;
nsamples, nchannels, format, li: pcint): cint; cdecl;
TOpusTags = record
user_comments: PPAnsiChar; // The array of comment string vectors
comment_lengths: Pcint; // An array of the corresponding length of each vector, in bytes
comments: cint; // The total number of comment streams
vendor: PAnsiChar; // The null-terminated vendor string. This identifies the software used to encode the stream.
end;
POpusTags = ^TOpusTags;
TOpusPictureTag = record
Pic_Type: cint; { The picture type according to the ID3v2 APIC frame: