1 | {This unit is part of United Openlibraries of Sound (uos)}
|
---|
2 |
|
---|
3 | {This is the Pascal Wrapper + Dynamic loading of OpusURL library.
|
---|
4 | Load library with ou_load() and release with ou_unload().
|
---|
5 | License : modified LGPL.
|
---|
6 | Fred van Stappen / fiens@hotmail.com}
|
---|
7 |
|
---|
8 | unit uos_Opusurl;
|
---|
9 |
|
---|
10 | {$mode objfpc}{$H+}
|
---|
11 |
|
---|
12 | interface
|
---|
13 |
|
---|
14 | uses
|
---|
15 | ctypes, uos_Opusfile, dynlibs, SysUtils;
|
---|
16 |
|
---|
17 | // Error Codes
|
---|
18 | const
|
---|
19 | OP_FALSE = -1;
|
---|
20 | OP_HOLE = -3;
|
---|
21 | OP_EREAD = -128;
|
---|
22 | OP_EFAULT = -129;
|
---|
23 | OP_EIMPL = -130;
|
---|
24 | OP_EINVAL = -131;
|
---|
25 | OP_ENOTVORBIS = -132;
|
---|
26 | OP_EBADHEADER = -133;
|
---|
27 | OP_EVERSION = -134;
|
---|
28 | OP_ENOTAUDIO = -135;
|
---|
29 | OP_EBADPACKET = -136;
|
---|
30 | OP_EBADLINK = -137;
|
---|
31 | OP_ENOSEEK = -138;
|
---|
32 | OP_EBADTIMESTAMP = -139;
|
---|
33 |
|
---|
34 | var
|
---|
35 |
|
---|
36 | op_open_url: function(path: PAnsiChar; out error: Integer): TOpusFile;
|
---|
37 | op_test_url: function(path: PAnsiChar; out error: Integer): TOpusFile;
|
---|
38 |
|
---|
39 | ou_Handle:TLibHandle=dynlibs.NilHandle;
|
---|
40 |
|
---|
41 | ReferenceCounter : cardinal = 0; // Reference counter
|
---|
42 |
|
---|
43 | function ou_IsLoaded : boolean; inline;
|
---|
44 |
|
---|
45 | Function ou_Load(const libfilename:string) :boolean; // load the lib
|
---|
46 |
|
---|
47 | Procedure ou_Unload;
|
---|
48 |
|
---|
49 | implementation
|
---|
50 |
|
---|
51 | function ou_IsLoaded: boolean;
|
---|
52 | begin
|
---|
53 | Result := (ou_Handle <> dynlibs.NilHandle);
|
---|
54 | end;
|
---|
55 |
|
---|
56 | Procedure ou_Unload;
|
---|
57 | begin
|
---|
58 | // < Reference counting
|
---|
59 | if ReferenceCounter > 0 then
|
---|
60 | dec(ReferenceCounter);
|
---|
61 | if ReferenceCounter > 0 then
|
---|
62 | exit;
|
---|
63 | // >
|
---|
64 | if ou_IsLoaded then
|
---|
65 | begin
|
---|
66 | DynLibs.UnloadLibrary(ou_Handle);
|
---|
67 | ou_Handle:=DynLibs.NilHandle;
|
---|
68 | end;
|
---|
69 | end;
|
---|
70 |
|
---|
71 | Function ou_Load (const libfilename:string) :boolean;
|
---|
72 | begin
|
---|
73 | Result := False;
|
---|
74 | if ou_Handle<>0 then
|
---|
75 | begin
|
---|
76 | Inc(ReferenceCounter);
|
---|
77 | result:=true {is it already there ?}
|
---|
78 | end else
|
---|
79 | begin {go & load the library}
|
---|
80 | if Length(libfilename) = 0 then exit;
|
---|
81 | ou_Handle:=DynLibs.SafeLoadLibrary(libfilename); // obtain the handle we want
|
---|
82 | if ou_Handle <> DynLibs.NilHandle then
|
---|
83 | begin {now we tie the functions to the VARs from above}
|
---|
84 | Pointer(op_open_url):=DynLibs.GetProcedureAddress(OU_Handle,PChar('op_open_url'));
|
---|
85 | Pointer(op_test_url):=DynLibs.GetProcedureAddress(OU_Handle,PChar('op_test_url'));
|
---|
86 | end;
|
---|
87 | Result := ou_IsLoaded;
|
---|
88 | ReferenceCounter:=1;
|
---|
89 | end;
|
---|
90 |
|
---|
91 | end;
|
---|
92 |
|
---|
93 | end.
|
---|