2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 #include "ad_internal.h"
33 #include "loader/wine/windef.h"
35 static const ad_info_t info
= {
39 "Florian Schneider, Arpad Gereoffy, Alex Beregszaszi, Donnie Smith",
40 "binary real audio codecs"
45 /* These functions are required for loading Real binary libs.
46 * Add forward declarations to avoid warnings with -Wmissing-prototypes. */
47 void *__builtin_new(unsigned long size
);
48 void __builtin_delete(void *ize
);
49 void *__builtin_vec_new(unsigned long size
);
50 void __builtin_vec_delete(void *mem
);
51 void __pure_virtual(void);
53 void *__builtin_new(unsigned long size
)
58 void __builtin_delete(void* ize
)
63 void *__builtin_vec_new(unsigned long size
)
68 void __builtin_vec_delete(void *mem
)
73 void __pure_virtual(void)
75 printf("FATAL: __pure_virtual() called!\n");
79 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
80 void ___brk_addr(void);
81 void ___brk_addr(void) {exit(0);}
82 char **__environ
={NULL
};
88 static unsigned long (*raCloseCodec
)(void*);
89 static unsigned long (*raDecode
)(void*, char*,unsigned long,char*,unsigned int*,long);
90 static unsigned long (*raFreeDecoder
)(void*);
91 //static unsigned long (*raGetNumberOfFlavors2)(void);
92 static unsigned long (*raInitDecoder
)(void*, void*);
93 static unsigned long (*raOpenCodec
)(void*);
94 static unsigned long (*raOpenCodec2
)(void*, void*);
95 static unsigned long (*raSetFlavor
)(void*,unsigned long);
96 static void (*raSetDLLAccessPath
)(char*);
97 static void (*raSetPwd
)(char*,char*);
98 #ifdef CONFIG_WIN32DLL
99 static unsigned long WINAPI (*wraCloseCodec
)(void*);
100 static unsigned long WINAPI (*wraDecode
)(void*, char*,unsigned long,char*,unsigned int*,long);
101 static unsigned long WINAPI (*wraFreeDecoder
)(void*);
102 static unsigned long WINAPI (*wraInitDecoder
)(void*, void*);
103 static unsigned long WINAPI (*wraOpenCodec
)(void*);
104 static unsigned long WINAPI (*wraOpenCodec2
)(void*, void*);
105 static unsigned long WINAPI (*wraSetFlavor
)(void*,unsigned long);
106 static void WINAPI (*wraSetDLLAccessPath
)(char*);
107 static void WINAPI (*wraSetPwd
)(char*,char*);
109 static int dll_type
= 0; /* 0 = unix dlopen, 1 = win32 dll */
112 static void *rv_handle
= NULL
;
128 Probably the linux .so-s were compiled with old GCC without setting
129 packing, so it adds 2 bytes padding after the quality field.
130 In windows it seems that there's no padding in it.
135 /* linux dlls doesn't need packing */
136 typedef struct /*__attribute__((__packed__))*/ {
141 /* 2bytes padding here, by gcc */
148 /* windows dlls need packed structs (no padding) */
149 typedef struct __attribute__((__packed__
)) {
162 static int load_syms_linux(char *path
)
166 mp_msg(MSGT_DECVIDEO
, MSGL_V
, "opening shared obj '%s'\n", path
);
167 handle
= dlopen(path
, RTLD_LAZY
);
170 mp_msg(MSGT_DECVIDEO
, MSGL_WARN
, "Error: %s\n", dlerror());
174 raCloseCodec
= dlsym(handle
, "RACloseCodec");
175 raDecode
= dlsym(handle
, "RADecode");
176 raFreeDecoder
= dlsym(handle
, "RAFreeDecoder");
177 raOpenCodec
= dlsym(handle
, "RAOpenCodec");
178 raOpenCodec2
= dlsym(handle
, "RAOpenCodec2");
179 raInitDecoder
= dlsym(handle
, "RAInitDecoder");
180 raSetFlavor
= dlsym(handle
, "RASetFlavor");
181 raSetDLLAccessPath
= dlsym(handle
, "SetDLLAccessPath");
182 raSetPwd
= dlsym(handle
, "RASetPwd"); // optional, used by SIPR
184 if (raCloseCodec
&& raDecode
&& raFreeDecoder
&&
185 (raOpenCodec
||raOpenCodec2
) && raSetFlavor
&&
186 /*raSetDLLAccessPath &&*/ raInitDecoder
)
192 mp_msg(MSGT_DECAUDIO
,MSGL_WARN
,"Cannot resolve symbols - incompatible dll: %s\n",path
);
198 #ifdef CONFIG_WIN32DLL
201 #include "loader/ldt_keeper.h"
203 void* WINAPI
LoadLibraryA(char* name
);
204 void* WINAPI
GetProcAddress(void* handle
,char *func
);
205 int WINAPI
FreeLibrary(void *handle
);
207 static int load_syms_windows(char *path
)
211 mp_msg(MSGT_DECVIDEO
, MSGL_V
, "opening win32 dll '%s'\n", path
);
215 handle
= LoadLibraryA(path
);
218 mp_msg(MSGT_DECVIDEO
, MSGL_WARN
, "Error loading dll\n");
222 wraCloseCodec
= GetProcAddress(handle
, "RACloseCodec");
223 wraDecode
= GetProcAddress(handle
, "RADecode");
224 wraFreeDecoder
= GetProcAddress(handle
, "RAFreeDecoder");
225 wraOpenCodec
= GetProcAddress(handle
, "RAOpenCodec");
226 wraOpenCodec2
= GetProcAddress(handle
, "RAOpenCodec2");
227 wraInitDecoder
= GetProcAddress(handle
, "RAInitDecoder");
228 wraSetFlavor
= GetProcAddress(handle
, "RASetFlavor");
229 wraSetDLLAccessPath
= GetProcAddress(handle
, "SetDLLAccessPath");
230 wraSetPwd
= GetProcAddress(handle
, "RASetPwd"); // optional, used by SIPR
232 if (wraCloseCodec
&& wraDecode
&& wraFreeDecoder
&&
233 (wraOpenCodec
|| wraOpenCodec2
) && wraSetFlavor
&&
234 /*wraSetDLLAccessPath &&*/ wraInitDecoder
)
241 mp_msg(MSGT_DECAUDIO
,MSGL_WARN
,"Cannot resolve symbols - incompatible dll: %s\n",path
);
249 static int preinit(sh_audio_t
*sh
){
250 // let's check if the driver is available, return 0 if not.
251 // (you should do that if you use external lib(s) which is optional)
255 path
= malloc(strlen(codec_path
) + strlen(sh
->codec
->dll
) + 2);
257 sprintf(path
, "%s/%s", codec_path
, sh
->codec
->dll
);
259 /* first try to load linux dlls, if failed and we're supporting win32 dlls,
260 then try to load the windows ones */
263 if (strstr(sh
->codec
->dll
,".dll") || !load_syms_linux(path
))
265 #ifdef CONFIG_WIN32DLL
266 if (!load_syms_windows(sh
->codec
->dll
))
269 mp_msg(MSGT_DECVIDEO
, MSGL_ERR
, MSGTR_MissingDLLcodec
, sh
->codec
->dll
);
270 mp_msg(MSGT_DECVIDEO
, MSGL_HINT
, "Read the RealAudio section of the DOCS!\n");
275 #ifdef CONFIG_WIN32DLL
276 if((raSetDLLAccessPath
&& dll_type
== 0) || (wraSetDLLAccessPath
&& dll_type
== 1)){
278 if(raSetDLLAccessPath
){
281 path
= realloc(path
, strlen(codec_path
) + 13);
282 sprintf(path
, "DT_Codecs=%s", codec_path
);
283 if(path
[strlen(path
)-1]!='/'){
284 path
[strlen(path
)+1]=0;
285 path
[strlen(path
)]='/';
287 path
[strlen(path
)+1]=0;
288 #ifdef CONFIG_WIN32DLL
292 for (i
=0; i
< strlen(path
); i
++)
293 if (path
[i
] == '/') path
[i
] = '\\';
294 wraSetDLLAccessPath(path
);
298 raSetDLLAccessPath(path
);
301 #ifdef CONFIG_WIN32DLL
304 sprintf(path
, "%s\\", codec_path
);
305 result
= wraOpenCodec2(&sh
->context
, path
);
307 result
=wraOpenCodec(&sh
->context
);
311 sprintf(path
, "%s/", codec_path
);
312 result
= raOpenCodec2(&sh
->context
, path
);
314 result
=raOpenCodec(&sh
->context
);
316 mp_msg(MSGT_DECAUDIO
,MSGL_WARN
,"Decoder open failed, error code: 0x%X\n",result
);
319 // printf("opencodec ok (result: %x)\n", result);
320 free(path
); /* after this it isn't used anymore */
322 sh
->samplerate
=sh
->wf
->nSamplesPerSec
;
323 sh
->samplesize
=sh
->wf
->wBitsPerSample
/8;
324 sh
->channels
=sh
->wf
->nChannels
;
327 ra_init_t init_data
={
328 sh
->wf
->nSamplesPerSec
,
329 sh
->wf
->wBitsPerSample
,
332 sh
->wf
->nBlockAlign
, // subpacket size
333 sh
->wf
->nBlockAlign
, // coded frame size
334 sh
->wf
->cbSize
, // codec data length
335 (char*)(sh
->wf
+1) // extras
337 #ifdef CONFIG_WIN32DLL
338 wra_init_t winit_data
={
339 sh
->wf
->nSamplesPerSec
,
340 sh
->wf
->wBitsPerSample
,
343 sh
->wf
->nBlockAlign
, // subpacket size
344 sh
->wf
->nBlockAlign
, // coded frame size
345 sh
->wf
->cbSize
, // codec data length
346 (char*)(sh
->wf
+1) // extras
349 #ifdef CONFIG_WIN32DLL
351 result
=wraInitDecoder(sh
->context
,&winit_data
);
354 result
=raInitDecoder(sh
->context
,&init_data
);
357 mp_msg(MSGT_DECAUDIO
,MSGL_WARN
,"Decoder init failed, error code: 0x%X\n",result
);
360 // printf("initdecoder ok (result: %x)\n", result);
363 #ifdef CONFIG_WIN32DLL
364 if((raSetPwd
&& dll_type
== 0) || (wraSetPwd
&& dll_type
== 1)){
369 #ifdef CONFIG_WIN32DLL
371 wraSetPwd(sh
->context
,"Ardubancel Quazanga");
374 raSetPwd(sh
->context
,"Ardubancel Quazanga"); // set password... lol.
377 if (sh
->format
== mmioFOURCC('s','i','p','r')) {
380 if (sh
->wf
->nAvgBytesPerSec
> 1531)
382 else if (sh
->wf
->nAvgBytesPerSec
> 937)
384 else if (sh
->wf
->nAvgBytesPerSec
> 719)
388 mp_msg(MSGT_DECAUDIO
,MSGL_V
,"Got sipr flavor %d from bitrate %d\n",flavor
, sh
->wf
->nAvgBytesPerSec
);
390 #ifdef CONFIG_WIN32DLL
392 result
=wraSetFlavor(sh
->context
,flavor
);
395 result
=raSetFlavor(sh
->context
,flavor
);
397 mp_msg(MSGT_DECAUDIO
,MSGL_WARN
,"Decoder flavor setup failed, error code: 0x%X\n",result
);
402 sh
->i_bps
=sh
->wf
->nAvgBytesPerSec
;
404 sh
->audio_out_minsize
=128000; // no idea how to get... :(
405 sh
->audio_in_minsize
= sh
->wf
->nBlockAlign
;
407 return 1; // return values: 1=OK 0=ERROR
410 static int init(sh_audio_t
*sh_audio
){
411 // initialize the decoder, set tables etc...
413 // you can store HANDLE or private struct pointer at sh->context
414 // you can access WAVEFORMATEX header at sh->wf
416 // set sample format/rate parameters if you didn't do it in preinit() yet.
418 return 1; // return values: 1=OK 0=ERROR
421 static void uninit(sh_audio_t
*sh
){
422 // uninit the decoder etc...
423 // again: you don't have to free() a_in_buffer here! it's done by the core.
424 #ifdef CONFIG_WIN32DLL
427 if (wraFreeDecoder
) wraFreeDecoder(sh
->context
);
428 if (wraCloseCodec
) wraCloseCodec(sh
->context
);
432 if (raFreeDecoder
) raFreeDecoder(sh
->context
);
433 if (raCloseCodec
) raCloseCodec(sh
->context
);
436 #ifdef CONFIG_WIN32DLL
439 if (rv_handle
) FreeLibrary(rv_handle
);
442 // this dlclose() causes some memory corruption, and crashes soon (in caller):
443 // if (rv_handle) dlclose(rv_handle);
447 static int decode_audio(sh_audio_t
*sh
,unsigned char *buf
,int minlen
,int maxlen
){
451 if(sh
->a_in_buffer_len
<=0){
455 demux_read_data(sh
->ds
, sh
->a_in_buffer
, sh
->wf
->nBlockAlign
);
456 sh
->a_in_buffer_size
=
457 sh
->a_in_buffer_len
=sh
->wf
->nBlockAlign
;
460 #ifdef CONFIG_WIN32DLL
462 result
=wraDecode(sh
->context
, sh
->a_in_buffer
+sh
->a_in_buffer_size
-sh
->a_in_buffer_len
, sh
->wf
->nBlockAlign
,
466 result
=raDecode(sh
->context
, sh
->a_in_buffer
+sh
->a_in_buffer_size
-sh
->a_in_buffer_len
, sh
->wf
->nBlockAlign
,
468 sh
->a_in_buffer_len
-=sh
->wf
->nBlockAlign
;
470 // printf("radecode: %d bytes, res=0x%X \n",len,result);
472 return len
; // return value: number of _bytes_ written to output buffer,
473 // or -1 for EOF (or uncorrectable error)
476 static int control(sh_audio_t
*sh
,int cmd
,void* arg
, ...){
477 // various optional functions you MAY implement:
479 case ADCTRL_RESYNC_STREAM
:
480 // it is called once after seeking, to resync.
481 // Note: sh_audio->a_in_buffer_len=0; is done _before_ this call!
483 case ADCTRL_SKIP_FRAME
:
484 // it is called to skip (jump over) small amount (1/10 sec or 1 frame)
485 // of audio data - used to sync audio to video after seeking
486 // if you don't return CONTROL_TRUE, it will defaults to:
487 // ds_fill_buffer(sh_audio->ds); // skip 1 demux packet
490 return CONTROL_UNKNOWN
;