1 | {This unit is part of United Openlibraries of Sound (uos)}
|
---|
2 |
|
---|
3 | {This is the Dynamic loading version of IceCast_Shout Pascal Wrapper.
|
---|
4 | Load library with sha_load() and release with sh_unload().
|
---|
5 | License : modified LGPL.
|
---|
6 | Fred van Stappen / fiens@hotmail.com }
|
---|
7 |
|
---|
8 | unit uos_shout;
|
---|
9 |
|
---|
10 | {$mode objfpc}{$H+}
|
---|
11 | {$PACKRECORDS C}
|
---|
12 |
|
---|
13 | interface
|
---|
14 |
|
---|
15 | uses
|
---|
16 | dynlibs, CTypes, sysutils;
|
---|
17 |
|
---|
18 | const
|
---|
19 | SHOUT_THREADSAFE = 1;
|
---|
20 | SHOUT_TLS = 1;
|
---|
21 | SHOUTERR_SUCCESS = 0;
|
---|
22 | SHOUTERR_INSANE = -1;
|
---|
23 | SHOUTERR_NOCONNECT = -2;
|
---|
24 | SHOUTERR_NOLOGIN = -3;
|
---|
25 | SHOUTERR_SOCKET = -4;
|
---|
26 | SHOUTERR_MALLOC = -5;
|
---|
27 | SHOUTERR_METADATA = -6;
|
---|
28 | SHOUTERR_CONNECTED = -7;
|
---|
29 | SHOUTERR_UNCONNECTED = -8;
|
---|
30 | SHOUTERR_UNSUPPORTED = -9;
|
---|
31 | SHOUTERR_BUSY = -10;
|
---|
32 | SHOUTERR_NOTLS = -11;
|
---|
33 | SHOUTERR_TLSBADCERT = -12;
|
---|
34 | SHOUTERR_RETRY = -13;
|
---|
35 | SHOUT_FORMAT_OGG = 0;
|
---|
36 | SHOUT_FORMAT_MP3 = 1;
|
---|
37 | SHOUT_FORMAT_WEBM = 2;
|
---|
38 | SHOUT_FORMAT_WEBMAUDIO = 3;
|
---|
39 | SHOUT_FORMAT_VORBIS = SHOUT_FORMAT_OGG;
|
---|
40 | SHOUT_PROTOCOL_HTTP = 0;
|
---|
41 | SHOUT_PROTOCOL_XAUDIOCAST = 1;
|
---|
42 | SHOUT_PROTOCOL_ICY = 2;
|
---|
43 | SHOUT_PROTOCOL_ROARAUDIO = 3;
|
---|
44 | SHOUT_TLS_DISABLED = 0;
|
---|
45 | SHOUT_TLS_AUTO = 1;
|
---|
46 | SHOUT_TLS_AUTO_NO_PLAIN = 2;
|
---|
47 | SHOUT_TLS_RFC2818 = 11;
|
---|
48 | SHOUT_TLS_RFC2817 = 12;
|
---|
49 | SHOUT_AI_BITRATE = 'bitrate';
|
---|
50 | SHOUT_AI_SAMPLERATE = 'samplerate';
|
---|
51 | SHOUT_AI_CHANNELS = 'channels';
|
---|
52 | SHOUT_AI_QUALITY = 'quality';
|
---|
53 | SHOUT_META_NAME = 'name';
|
---|
54 | SHOUT_META_URL = 'url';
|
---|
55 | SHOUT_META_GENRE = 'genre';
|
---|
56 | SHOUT_META_DESCRIPTION = 'description';
|
---|
57 | SHOUT_META_IRC = 'irc';
|
---|
58 | SHOUT_META_AIM = 'aim';
|
---|
59 | SHOUT_META_ICQ = 'icq';
|
---|
60 |
|
---|
61 | type
|
---|
62 | shout_t = pointer;
|
---|
63 | Pshout_t = ^shout_t;
|
---|
64 | {$if defined(cpu64)}
|
---|
65 | cuint64 = qword;
|
---|
66 | size_t = cuint64;
|
---|
67 | {$else}
|
---|
68 | cuint32 = longword;
|
---|
69 | size_t = cuint32;
|
---|
70 | {$endif}
|
---|
71 |
|
---|
72 | psize_t = ^size_t;
|
---|
73 |
|
---|
74 | shout_metadata_t = pointer;
|
---|
75 | Pshout_metadata_t = ^shout_metadata_t;
|
---|
76 |
|
---|
77 | // methods
|
---|
78 | var
|
---|
79 |
|
---|
80 | shout_init: procedure();cdecl;
|
---|
81 | shout_shutdown: procedure();cdecl;
|
---|
82 | shout_version: function(var major:cint; var minor:cint; var patch:cint):pchar;cdecl;
|
---|
83 | shout_new: function(): Pshout_t;cdecl;
|
---|
84 | shout_free: procedure(shhandle :Pshout_t);cdecl;
|
---|
85 | shout_get_error: function(shhandle :Pshout_t):pchar;cdecl;
|
---|
86 | shout_get_errno: function(shhandle :Pshout_t):cint;cdecl;
|
---|
87 | shout_get_connected: function(shhandle :Pshout_t):cint;cdecl;
|
---|
88 | shout_set_host: function(shhandle :Pshout_t; host: pchar):cint;cdecl;
|
---|
89 | shout_get_host: function(shhandle :Pshout_t):pchar;cdecl;
|
---|
90 | shout_set_port: function(shhandle :Pshout_t; port:cushort):cint;cdecl;
|
---|
91 | shout_get_port: function(shhandle :Pshout_t):cushort;cdecl;
|
---|
92 | shout_set_agent: function(shhandle :Pshout_t; agent:pchar):cint;cdecl;
|
---|
93 | shout_get_agent: function(shhandle :Pshout_t):pchar;cdecl;
|
---|
94 | shout_set_tls: function(shhandle :Pshout_t; mode:cint):cint;cdecl;
|
---|
95 | shout_get_tls: function(shhandle :Pshout_t):cint;cdecl;
|
---|
96 | shout_set_ca_directory: function(shhandle :Pshout_t; directory:pchar):cint;cdecl;
|
---|
97 | shout_get_ca_directory: function(shhandle :Pshout_t):pchar;cdecl;
|
---|
98 | shout_set_ca_file: function(shhandle :Pshout_t; thefile:pchar):cint;cdecl;
|
---|
99 | shout_get_ca_file: function(shhandle :Pshout_t):pchar;cdecl;
|
---|
100 | shout_set_allowed_ciphers: function(shhandle :Pshout_t; ciphers:pchar):cint;cdecl;
|
---|
101 | shout_get_allowed_ciphers: function(shhandle :Pshout_t):pchar;cdecl;
|
---|
102 | shout_set_user: function(shhandle :Pshout_t; username:pchar):cint;cdecl;
|
---|
103 | shout_get_user: function(shhandle :Pshout_t):pchar;cdecl;
|
---|
104 | shout_set_password: function(shhandle :Pshout_t; password:pchar):cint;cdecl;
|
---|
105 | shout_get_password: function(shhandle :Pshout_t):pchar;cdecl;
|
---|
106 | shout_set_client_certificate: function(shhandle :Pshout_t; certificate:pchar):cint;cdecl;
|
---|
107 | shout_get_client_certificate: function(shhandle :Pshout_t):pchar;cdecl;
|
---|
108 | shout_set_mount: function(shhandle :Pshout_t; mount:pchar):cint;cdecl;
|
---|
109 | shout_get_mount: function(shhandle :Pshout_t):pchar;cdecl;
|
---|
110 | shout_set_name: function(shhandle :Pshout_t; name:pchar):cint;cdecl;
|
---|
111 | shout_get_name: function(shhandle :Pshout_t):pchar;cdecl;
|
---|
112 | shout_set_url: function(shhandle :Pshout_t; url:pchar):cint;cdecl;
|
---|
113 | shout_get_url: function(shhandle :Pshout_t):pchar;cdecl;
|
---|
114 | shout_set_genre: function(shhandle :Pshout_t; genre:pchar):cint;cdecl;
|
---|
115 | shout_get_genre: function(shhandle :Pshout_t):pchar;cdecl;
|
---|
116 | shout_set_description: function(shhandle :Pshout_t; description:pchar):cint;cdecl;
|
---|
117 | shout_get_description: function(shhandle :Pshout_t):pchar;cdecl;
|
---|
118 | shout_set_dumpfile: function(shhandle :Pshout_t; dumpfile:pchar):cint;cdecl;
|
---|
119 | shout_get_dumpfile: function(shhandle :Pshout_t):pchar;cdecl;
|
---|
120 | shout_set_audio_info: function(shhandle :Pshout_t; name:pchar; value:pchar):cint;cdecl;
|
---|
121 | shout_get_audio_info: function(shhandle :Pshout_t; name:pchar):pchar;cdecl;
|
---|
122 | shout_set_meta: function(shhandle :Pshout_t; name:pchar; value:pchar):cint;cdecl;
|
---|
123 | shout_get_meta: function(shhandle :Pshout_t; name:pchar):pchar;cdecl;
|
---|
124 | shout_set_public: function(shhandle :Pshout_t; make_public:cuint):cint;cdecl;
|
---|
125 | shout_get_public: function(shhandle :Pshout_t):cuint;cdecl;
|
---|
126 | shout_set_format: function(shhandle :Pshout_t; format:cuint):cint;cdecl;
|
---|
127 | shout_get_format: function(shhandle :Pshout_t):cuint;cdecl;
|
---|
128 | shout_set_protocol: function(shhandle :Pshout_t; protocol:cuint):cint;cdecl;
|
---|
129 | shout_get_protocol: function(shhandle :Pshout_t):cuint;cdecl;
|
---|
130 | shout_set_nonblocking: function(shhandle :Pshout_t; nonblocking:cuint):cint;cdecl;
|
---|
131 | shout_get_nonblocking: function(shhandle :Pshout_t):cuint;cdecl;
|
---|
132 | shout_open: function(shhandle :Pshout_t):cint;cdecl;
|
---|
133 | shout_close: function(shhandle :Pshout_t):cint;cdecl;
|
---|
134 | //shout_send: function(shhandle :Pshout_t; data:pcuchar; len:size_t):cint;cdecl;
|
---|
135 | shout_send: function(shhandle :Pshout_t; data:pbyte; len:size_t):cint;cdecl;
|
---|
136 | shout_send_raw: function(shhandle :Pshout_t; data:pcuchar; len:size_t):size_t;cdecl;
|
---|
137 | shout_queuelen: function(shhandle :Pshout_t):size_t;cdecl;
|
---|
138 | shout_sync: procedure(shhandle :Pshout_t);cdecl;
|
---|
139 | shout_delay: function(shhandle :Pshout_t):cint;cdecl;
|
---|
140 | shout_set_metadata: function(shhandle :Pshout_t; var metadata:shout_metadata_t):cint;cdecl;
|
---|
141 | shout_metadata_new: function():Pshout_metadata_t;cdecl;
|
---|
142 | shout_metadata_free: procedure(var shhandle:shout_metadata_t);cdecl;
|
---|
143 | shout_metadata_add: function(var shhandle:shout_metadata_t; name:pchar; value:pchar):cint;cdecl;
|
---|
144 |
|
---|
145 | sh_Handle:TLibHandle=dynlibs.NilHandle; // this will hold our handle for the lib; it functions nicely as a mutli-lib prevention unit as well...
|
---|
146 |
|
---|
147 | ReferenceCounter : cardinal = 0; // Reference counter
|
---|
148 |
|
---|
149 | function sh_IsLoaded : boolean; inline;
|
---|
150 |
|
---|
151 | Function sh_Load(const libfilename:string) :boolean; // load the lib
|
---|
152 |
|
---|
153 | Procedure sh_Unload(); // unload and frees the lib from memory : do not forget to call it before close application.
|
---|
154 |
|
---|
155 |
|
---|
156 | implementation
|
---|
157 |
|
---|
158 | function sh_IsLoaded: boolean;
|
---|
159 | begin
|
---|
160 | Result := (sh_Handle <> dynlibs.NilHandle);
|
---|
161 | end;
|
---|
162 |
|
---|
163 | Function sh_Load (const libfilename:string) :boolean;
|
---|
164 | begin
|
---|
165 | Result := False;
|
---|
166 | if sh_Handle<>0 then
|
---|
167 | begin
|
---|
168 | Inc(ReferenceCounter);
|
---|
169 | result:=true {is it already there ?}
|
---|
170 | end else
|
---|
171 | begin {go & load the library}
|
---|
172 | if Length(libfilename) = 0 then exit;
|
---|
173 | sh_Handle:=DynLibs.SafeLoadLibrary(libfilename); // obtain the handle we want
|
---|
174 | if sh_Handle <> DynLibs.NilHandle then
|
---|
175 | begin {now we tie the functions to the VARs from above}
|
---|
176 |
|
---|
177 | Pointer(shout_init):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_init'));
|
---|
178 | Pointer(shout_shutdown):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_shutdown'));
|
---|
179 | Pointer(shout_version):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_version'));
|
---|
180 | Pointer(shout_new):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_new'));
|
---|
181 | Pointer(shout_free):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_free'));
|
---|
182 | Pointer(shout_get_error):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_error'));
|
---|
183 | Pointer(shout_get_errno):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_errno'));
|
---|
184 | Pointer(shout_get_connected):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_connected'));
|
---|
185 | Pointer(shout_set_host):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_host'));
|
---|
186 | Pointer(shout_get_host):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_host'));
|
---|
187 | Pointer(shout_set_port):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_port'));
|
---|
188 | Pointer(shout_get_port):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_port'));
|
---|
189 | Pointer(shout_set_agent):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_agent'));
|
---|
190 | Pointer(shout_get_agent):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_agent'));
|
---|
191 | Pointer(shout_set_tls):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_tls'));
|
---|
192 | Pointer(shout_get_tls):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_tls'));
|
---|
193 | Pointer(shout_set_ca_directory):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_ca_directory'));
|
---|
194 | Pointer(shout_get_ca_directory):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_ca_directory'));
|
---|
195 | Pointer(shout_set_ca_file):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_ca_file'));
|
---|
196 | Pointer(shout_get_ca_file):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_ca_file'));
|
---|
197 | Pointer(shout_set_allowed_ciphers):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_allowed_ciphers'));
|
---|
198 | Pointer(shout_get_allowed_ciphers):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_allowed_ciphers'));
|
---|
199 | Pointer(shout_set_user):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_user'));
|
---|
200 | Pointer(shout_get_user):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_user'));
|
---|
201 | Pointer(shout_set_password):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_password'));
|
---|
202 | Pointer(shout_get_password):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_password'));
|
---|
203 | Pointer(shout_set_client_certificate):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_client_certificate'));
|
---|
204 | Pointer(shout_get_client_certificate):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_client_certificate'));
|
---|
205 | Pointer(shout_set_mount):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_mount'));
|
---|
206 | Pointer(shout_get_mount):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_mount'));
|
---|
207 | Pointer(shout_set_name):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_name'));
|
---|
208 | Pointer(shout_get_name):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_name'));
|
---|
209 | Pointer(shout_set_url):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_url'));
|
---|
210 | Pointer(shout_get_url):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_url'));
|
---|
211 | Pointer(shout_set_genre):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_genre'));
|
---|
212 | Pointer(shout_get_genre):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_genre'));
|
---|
213 | Pointer(shout_set_description):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_description'));
|
---|
214 | Pointer(shout_get_description):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_description'));
|
---|
215 | Pointer(shout_set_dumpfile):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_dumpfile'));
|
---|
216 | Pointer(shout_get_dumpfile):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_dumpfile'));
|
---|
217 | Pointer(shout_set_audio_info):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_audio_info'));
|
---|
218 | Pointer(shout_get_audio_info):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_audio_info'));
|
---|
219 | Pointer(shout_set_meta):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_meta'));
|
---|
220 | Pointer(shout_get_meta):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_meta'));
|
---|
221 | Pointer(shout_set_public):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_public'));
|
---|
222 | Pointer(shout_get_public):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_public'));
|
---|
223 | Pointer(shout_set_format):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_format'));
|
---|
224 | Pointer(shout_get_format):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_format'));
|
---|
225 | Pointer(shout_set_protocol):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_protocol'));
|
---|
226 | Pointer(shout_get_protocol):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_protocol'));
|
---|
227 | Pointer(shout_set_nonblocking):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_nonblocking'));
|
---|
228 | Pointer(shout_get_nonblocking):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_get_nonblocking'));
|
---|
229 | Pointer(shout_open):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_open'));
|
---|
230 | Pointer(shout_close):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_close'));
|
---|
231 | Pointer(shout_send):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_send'));
|
---|
232 | Pointer(shout_send_raw):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_send_raw'));
|
---|
233 | Pointer(shout_queuelen):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_queuelen'));
|
---|
234 | Pointer(shout_sync):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_sync'));
|
---|
235 | Pointer(shout_delay):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_delay'));
|
---|
236 | Pointer(shout_set_metadata):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_set_metadata'));
|
---|
237 | Pointer(shout_metadata_new):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_metadata_new'));
|
---|
238 | Pointer(shout_metadata_free):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_metadata_free'));
|
---|
239 | Pointer(shout_metadata_add):=DynLibs.GetProcedureAddress(sh_Handle,PChar('shout_metadata_add'));
|
---|
240 |
|
---|
241 | end;
|
---|
242 | Result := sh_IsLoaded;
|
---|
243 | ReferenceCounter:=1;
|
---|
244 | end;
|
---|
245 |
|
---|
246 | end;
|
---|
247 |
|
---|
248 | Procedure sh_Unload;
|
---|
249 | begin
|
---|
250 | // < Reference counting
|
---|
251 | if ReferenceCounter > 0 then
|
---|
252 | dec(ReferenceCounter);
|
---|
253 | if ReferenceCounter > 0 then
|
---|
254 | exit;
|
---|
255 | // >
|
---|
256 | if sh_IsLoaded then
|
---|
257 | begin
|
---|
258 | shout_shutdown();
|
---|
259 | DynLibs.UnloadLibrary(sh_Handle);
|
---|
260 | sh_Handle:=DynLibs.NilHandle;
|
---|
261 | end;
|
---|
262 | end;
|
---|
263 |
|
---|
264 | end.
|
---|