1 /* 2 3 Boost Software License - Version 1.0 - August 17th, 2003 4 5 Permission is hereby granted, free of charge, to any person or organization 6 obtaining a copy of the software and accompanying documentation covered by 7 this license (the "Software") to use, reproduce, display, distribute, 8 execute, and transmit the Software, and to prepare derivative works of the 9 Software, and to permit third-parties to whom the Software is furnished to 10 do so, all subject to the following: 11 12 The copyright notices in the Software and this entire statement, including 13 the above license grant, this restriction and the following disclaimer, 14 must be included in all copies of the Software, in whole or in part, and 15 all derivative works of the Software, unless such copies or derivative 16 works are solely in the form of machine-executable object code generated by 17 a source language processor. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 DEALINGS IN THE SOFTWARE. 26 27 */ 28 module derelict.ogg.ogg; 29 30 private { 31 import core.stdc.config; 32 import derelict.util.loader; 33 import derelict.util.system; 34 35 static if(Derelict_OS_Windows) 36 enum libNames = "ogg.dll, libogg-0.dll, libogg.dll"; 37 else static if(Derelict_OS_Mac) 38 enum libNames = "libogg.dylib, libogg.0.dylib"; 39 else static if(Derelict_OS_Posix) 40 enum libNames = "libogg.so, libogg.so.0"; 41 else 42 static assert(0, "Need to implement libogg libnames for this operating system."); 43 } 44 45 alias ogg_int64_t = long; 46 alias ogg_uint64_t = ulong; 47 alias ogg_int32_t = int; 48 alias ogg_uint32_t = uint; 49 alias ogg_int16_t = short; 50 alias ogg_uint16_t = ushort; 51 52 struct ogg_iovec_t { 53 void* iov_base; 54 size_t iov_len; 55 } 56 57 struct oggpack_buffer { 58 c_long endbyte; 59 int endbit; 60 ubyte* buffer; 61 ubyte* ptr; 62 c_long storage; 63 } 64 65 struct ogg_page { 66 ubyte* header; 67 c_long header_len; 68 ubyte* _body; // originally named "body", but that's a keyword in D. 69 c_long body_len; 70 } 71 72 struct ogg_stream_state { 73 ubyte* body_data; 74 c_long body_storage; 75 c_long body_fill; 76 c_long body_returned; 77 int* lacing_vals; 78 ogg_int64_t* granule_vals; 79 c_long lacing_storage; 80 c_long lacing_fill; 81 c_long lacing_packet; 82 c_long lacing_returned; 83 ubyte[282] header; 84 int header_fill; 85 int e_o_s; 86 int b_o_s; 87 c_long serialno; 88 c_long pageno; 89 ogg_int64_t packetno; 90 ogg_int64_t granulepos; 91 } 92 93 struct ogg_packet { 94 ubyte* packet; 95 c_long bytes; 96 c_long b_o_s; 97 c_long e_o_s; 98 ogg_int64_t granulepos; 99 ogg_int64_t packetno; 100 } 101 102 struct ogg_sync_state { 103 ubyte* data; 104 int storage; 105 int fill; 106 int returned; 107 108 int unsynced; 109 int headerbytes; 110 int bodybytes; 111 } 112 113 extern(C) nothrow @nogc { 114 alias da_oggpack_writeinit = void function(oggpack_buffer*); 115 alias da_oggpack_writetrunc = void function(oggpack_buffer*, c_long); 116 alias da_oggpack_writealign = void function(oggpack_buffer*); 117 alias da_oggpack_writecopy = void function(oggpack_buffer*, void*, c_long); 118 alias da_oggpack_reset = void function(oggpack_buffer*); 119 alias da_oggpack_writeclear = void function(oggpack_buffer*); 120 alias da_oggpack_readinit = void function(oggpack_buffer*, ubyte*, int); 121 alias da_oggpack_write = void function(oggpack_buffer*, c_ulong, int); 122 alias da_oggpack_look = c_long function(oggpack_buffer*, int); 123 alias da_oggpack_look1 = c_long function(oggpack_buffer*); 124 alias da_oggpack_adv = void function(oggpack_buffer*, int); 125 alias da_oggpack_adv1 = void function(oggpack_buffer*); 126 alias da_oggpack_read = c_long function(oggpack_buffer*, int); 127 alias da_oggpack_read1 = c_long function(oggpack_buffer*); 128 alias da_oggpack_bytes = c_long function(oggpack_buffer*); 129 alias da_oggpack_bits = c_long function(oggpack_buffer*); 130 alias da_oggpack_get_buffer = ubyte function(oggpack_buffer*); 131 alias da_oggpackB_writeinit = void function(oggpack_buffer*); 132 alias da_oggpackB_writetrunc = void function(oggpack_buffer*, c_long ); 133 alias da_oggpackB_writealign = void function(oggpack_buffer*); 134 alias da_oggpackB_writecopy = void function(oggpack_buffer*, void*, c_long); 135 alias da_oggpackB_reset = void function(oggpack_buffer*); 136 alias da_oggpackB_writeclear = void function(oggpack_buffer*); 137 alias da_oggpackB_readinit = void function(oggpack_buffer*, ubyte*, int); 138 alias da_oggpackB_write = void function(oggpack_buffer*, uint, c_long); 139 alias da_oggpackB_look = c_long function(oggpack_buffer*, int); 140 alias da_oggpackB_look1 = c_long function(oggpack_buffer*); 141 alias da_oggpackB_adv = void function(oggpack_buffer*, int); 142 alias da_oggpackB_adv1 = void function(oggpack_buffer*); 143 alias da_oggpackB_read = c_long function(oggpack_buffer*, int); 144 alias da_oggpackB_read1 = c_long function(oggpack_buffer*); 145 alias da_oggpackB_bytes = c_long function(oggpack_buffer*); 146 alias da_oggpackB_bits = c_long function(oggpack_buffer*); 147 alias da_oggpackB_get_buffer = ubyte function(oggpack_buffer*); 148 alias da_ogg_stream_packetin = int function(ogg_stream_state*, ogg_packet*); 149 alias da_ogg_stream_pageout = int function(ogg_stream_state*, ogg_page*); 150 alias da_ogg_stream_flush = int function(ogg_stream_state*, ogg_page*); 151 alias da_ogg_sync_init = int function(ogg_sync_state*); 152 alias da_ogg_sync_clear = int function(ogg_sync_state*); 153 alias da_ogg_sync_reset = int function(ogg_sync_state*); 154 alias da_ogg_sync_destroy = int function(ogg_sync_state*); 155 alias da_ogg_sync_buffer = byte* function(ogg_sync_state*, c_long); 156 alias da_ogg_sync_wrote = int function(ogg_sync_state*, c_long); 157 alias da_ogg_sync_pageseek = c_long function(ogg_sync_state*,ogg_page*); 158 alias da_ogg_sync_pageout = int function(ogg_sync_state*, ogg_page*); 159 alias da_ogg_stream_pagein = int function(ogg_stream_state*, ogg_page*); 160 alias da_ogg_stream_packetout = int function(ogg_stream_state*,ogg_packet*); 161 alias da_ogg_stream_packetpeek = int function(ogg_stream_state*,ogg_packet*); 162 alias da_ogg_stream_init = int function(ogg_stream_state*,int serialno); 163 alias da_ogg_stream_clear = int function(ogg_stream_state*); 164 alias da_ogg_stream_reset = int function(ogg_stream_state*); 165 alias da_ogg_stream_reset_serialno = int function(ogg_stream_state*,int serialno); 166 alias da_ogg_stream_destroy = int function(ogg_stream_state*); 167 alias da_ogg_stream_eos = int function(ogg_stream_state*); 168 alias da_ogg_page_checksum_set = void function(ogg_page*); 169 alias da_ogg_page_version = int function(ogg_page*); 170 alias da_ogg_page_continued = int function(ogg_page*); 171 alias da_ogg_page_bos = int function(ogg_page*); 172 alias da_ogg_page_eos = int function(ogg_page*); 173 alias da_ogg_page_granulepos = ogg_int64_t function(ogg_page*); 174 alias da_ogg_page_serialno = int function(ogg_page*); 175 alias da_ogg_page_pageno = c_long function(ogg_page*); 176 alias da_ogg_page_packets = int function(ogg_page*); 177 alias da_ogg_packet_clear = void function(ogg_packet*); 178 } 179 180 __gshared { 181 da_oggpack_writeinit oggpack_writeinit; 182 da_oggpack_writetrunc oggpack_writetrunc; 183 da_oggpack_writealign oggpack_writealign; 184 da_oggpack_writecopy oggpack_writecopy; 185 da_oggpack_reset oggpack_reset; 186 da_oggpack_writeclear oggpack_writeclear; 187 da_oggpack_readinit oggpack_readinit; 188 da_oggpack_write oggpack_write; 189 da_oggpack_look oggpack_look; 190 da_oggpack_look1 oggpack_look1; 191 da_oggpack_adv oggpack_adv; 192 da_oggpack_adv1 oggpack_adv1; 193 da_oggpack_read oggpack_read; 194 da_oggpack_read1 oggpack_read1; 195 da_oggpack_bytes oggpack_bytes; 196 da_oggpack_bits oggpack_bits; 197 da_oggpack_get_buffer oggpack_get_buffer; 198 da_oggpackB_writeinit oggpackB_writeinit; 199 da_oggpackB_writetrunc oggpackB_writetrunc; 200 da_oggpackB_writealign oggpackB_writealign; 201 da_oggpackB_writecopy oggpackB_writecopy; 202 da_oggpackB_reset oggpackB_reset; 203 da_oggpackB_writeclear oggpackB_writeclear; 204 da_oggpackB_readinit oggpackB_readinit; 205 da_oggpackB_write oggpackB_write; 206 da_oggpackB_look oggpackB_look; 207 da_oggpackB_look1 oggpackB_look1; 208 da_oggpackB_adv oggpackB_adv; 209 da_oggpackB_adv1 oggpackB_adv1; 210 da_oggpackB_read oggpackB_read; 211 da_oggpackB_read1 oggpackB_read1; 212 da_oggpackB_bytes oggpackB_bytes; 213 da_oggpackB_bits oggpackB_bits; 214 da_oggpackB_get_buffer oggpackB_get_buffer; 215 da_ogg_stream_packetin ogg_stream_packetin; 216 da_ogg_stream_pageout ogg_stream_pageout; 217 da_ogg_stream_flush ogg_stream_flush; 218 da_ogg_sync_init ogg_sync_init; 219 da_ogg_sync_clear ogg_sync_clear; 220 da_ogg_sync_reset ogg_sync_reset; 221 da_ogg_sync_destroy ogg_sync_destroy; 222 da_ogg_sync_buffer ogg_sync_buffer; 223 da_ogg_sync_wrote ogg_sync_wrote; 224 da_ogg_sync_pageseek ogg_sync_pageseek; 225 da_ogg_sync_pageout ogg_sync_pageout; 226 da_ogg_stream_pagein ogg_stream_pagein; 227 da_ogg_stream_packetout ogg_stream_packetout; 228 da_ogg_stream_packetpeek ogg_stream_packetpeek; 229 da_ogg_stream_init ogg_stream_init; 230 da_ogg_stream_clear ogg_stream_clear; 231 da_ogg_stream_reset ogg_stream_reset; 232 da_ogg_stream_reset_serialno ogg_stream_reset_serialno; 233 da_ogg_stream_destroy ogg_stream_destroy; 234 da_ogg_stream_eos ogg_stream_eos; 235 da_ogg_page_checksum_set ogg_page_checksum_set; 236 da_ogg_page_version ogg_page_version; 237 da_ogg_page_continued ogg_page_continued; 238 da_ogg_page_bos ogg_page_bos; 239 da_ogg_page_eos ogg_page_eos; 240 da_ogg_page_granulepos ogg_page_granulepos; 241 da_ogg_page_serialno ogg_page_serialno; 242 da_ogg_page_pageno ogg_page_pageno; 243 da_ogg_page_packets ogg_page_packets; 244 da_ogg_packet_clear ogg_packet_clear; 245 } 246 247 class DerelictOggLoader : SharedLibLoader { 248 public this() { 249 super(libNames); 250 } 251 252 protected override void loadSymbols() { 253 bindFunc(cast(void**)&oggpack_writeinit, "oggpack_writeinit"); 254 //bindFunc(cast(void**)&oggpack_writecheck, "oggpack_writecheck"); 255 bindFunc(cast(void**)&oggpack_writetrunc, "oggpack_writetrunc"); 256 bindFunc(cast(void**)&oggpack_writealign, "oggpack_writealign"); 257 bindFunc(cast(void**)&oggpack_writecopy, "oggpack_writecopy"); 258 bindFunc(cast(void**)&oggpack_reset, "oggpack_reset"); 259 bindFunc(cast(void**)&oggpack_writeclear, "oggpack_writeclear"); 260 bindFunc(cast(void**)&oggpack_readinit, "oggpack_readinit"); 261 bindFunc(cast(void**)&oggpack_write, "oggpack_write"); 262 bindFunc(cast(void**)&oggpack_look, "oggpack_look"); 263 bindFunc(cast(void**)&oggpack_look1, "oggpack_look1"); 264 bindFunc(cast(void**)&oggpack_adv, "oggpack_adv"); 265 bindFunc(cast(void**)&oggpack_adv1, "oggpack_adv1"); 266 bindFunc(cast(void**)&oggpack_read, "oggpack_read"); 267 bindFunc(cast(void**)&oggpack_read1, "oggpack_read1"); 268 bindFunc(cast(void**)&oggpack_bytes, "oggpack_bytes"); 269 bindFunc(cast(void**)&oggpack_bits, "oggpack_bits"); 270 bindFunc(cast(void**)&oggpack_get_buffer, "oggpack_get_buffer"); 271 bindFunc(cast(void**)&oggpackB_writeinit, "oggpackB_writeinit"); 272 // bindFunc(cast(void**)&oggpackB_writecheck, "oggpackB_writecheck"); 273 bindFunc(cast(void**)&oggpackB_writetrunc, "oggpackB_writetrunc"); 274 bindFunc(cast(void**)&oggpackB_writealign, "oggpackB_writealign"); 275 bindFunc(cast(void**)&oggpackB_writecopy, "oggpackB_writecopy"); 276 bindFunc(cast(void**)&oggpackB_reset, "oggpackB_reset"); 277 bindFunc(cast(void**)&oggpackB_writeclear, "oggpackB_writeclear"); 278 bindFunc(cast(void**)&oggpackB_readinit, "oggpackB_readinit"); 279 bindFunc(cast(void**)&oggpackB_write, "oggpackB_write"); 280 bindFunc(cast(void**)&oggpackB_look, "oggpackB_look"); 281 bindFunc(cast(void**)&oggpackB_look1, "oggpackB_look1"); 282 bindFunc(cast(void**)&oggpackB_adv, "oggpackB_adv"); 283 bindFunc(cast(void**)&oggpackB_adv1, "oggpackB_adv1"); 284 bindFunc(cast(void**)&oggpackB_read, "oggpackB_read"); 285 bindFunc(cast(void**)&oggpackB_read1, "oggpackB_read1"); 286 bindFunc(cast(void**)&oggpackB_bytes, "oggpackB_bytes"); 287 bindFunc(cast(void**)&oggpackB_bits, "oggpackB_bits"); 288 bindFunc(cast(void**)&oggpackB_get_buffer, "oggpackB_get_buffer"); 289 bindFunc(cast(void**)&ogg_stream_packetin, "ogg_stream_packetin"); 290 // bindFunc(cast(void**)&ogg_stream_iovecin, "ogg_stream_iovecin"); 291 bindFunc(cast(void**)&ogg_stream_pageout, "ogg_stream_pageout"); 292 // bindFunc(cast(void**)&ogg_stream_pageout_fill, "ogg_stream_pageout_fill"); 293 bindFunc(cast(void**)&ogg_stream_flush, "ogg_stream_flush"); 294 // bindFunc(cast(void**)&ogg_stream_flush_fill, "ogg_stream_flush_fill"); 295 bindFunc(cast(void**)&ogg_sync_init, "ogg_sync_init"); 296 bindFunc(cast(void**)&ogg_sync_clear, "ogg_sync_clear"); 297 bindFunc(cast(void**)&ogg_sync_reset, "ogg_sync_reset"); 298 bindFunc(cast(void**)&ogg_sync_destroy, "ogg_sync_destroy"); 299 // bindFunc(cast(void**)&ogg_sync_check, "ogg_sync_check"); 300 bindFunc(cast(void**)&ogg_sync_buffer, "ogg_sync_buffer"); 301 bindFunc(cast(void**)&ogg_sync_wrote, "ogg_sync_wrote"); 302 bindFunc(cast(void**)&ogg_sync_pageseek, "ogg_sync_pageseek"); 303 bindFunc(cast(void**)&ogg_sync_pageout, "ogg_sync_pageout"); 304 bindFunc(cast(void**)&ogg_stream_pagein, "ogg_stream_pagein"); 305 bindFunc(cast(void**)&ogg_stream_packetout, "ogg_stream_packetout"); 306 bindFunc(cast(void**)&ogg_stream_packetpeek, "ogg_stream_packetpeek"); 307 bindFunc(cast(void**)&ogg_stream_init, "ogg_stream_init"); 308 bindFunc(cast(void**)&ogg_stream_clear, "ogg_stream_clear"); 309 bindFunc(cast(void**)&ogg_stream_reset, "ogg_stream_reset"); 310 bindFunc(cast(void**)&ogg_stream_reset_serialno, "ogg_stream_reset_serialno"); 311 bindFunc(cast(void**)&ogg_stream_destroy, "ogg_stream_destroy"); 312 // bindFunc(cast(void**)&ogg_stream_check, "ogg_stream_check"); 313 bindFunc(cast(void**)&ogg_stream_eos, "ogg_stream_eos"); 314 bindFunc(cast(void**)&ogg_page_checksum_set, "ogg_page_checksum_set"); 315 bindFunc(cast(void**)&ogg_page_version, "ogg_page_version"); 316 bindFunc(cast(void**)&ogg_page_continued, "ogg_page_continued"); 317 bindFunc(cast(void**)&ogg_page_bos, "ogg_page_bos"); 318 bindFunc(cast(void**)&ogg_page_eos, "ogg_page_eos"); 319 bindFunc(cast(void**)&ogg_page_granulepos, "ogg_page_granulepos"); 320 bindFunc(cast(void**)&ogg_page_serialno, "ogg_page_serialno"); 321 bindFunc(cast(void**)&ogg_page_pageno, "ogg_page_pageno"); 322 bindFunc(cast(void**)&ogg_page_packets, "ogg_page_packets"); 323 bindFunc(cast(void**)&ogg_packet_clear, "ogg_packet_clear"); 324 } 325 } 326 327 __gshared DerelictOggLoader DerelictOgg; 328 329 shared static this() { 330 DerelictOgg = new DerelictOggLoader(); 331 }