2002-06-10 01:32:12 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef USE_REALCODECS
|
|
|
|
|
2003-02-11 15:24:26 +00:00
|
|
|
//#include <stddef.h>
|
2003-05-11 17:58:03 +00:00
|
|
|
#ifdef HAVE_LIBDL
|
2002-06-10 01:32:12 +00:00
|
|
|
#include <dlfcn.h>
|
2003-05-11 17:58:03 +00:00
|
|
|
#endif
|
2003-02-11 15:24:26 +00:00
|
|
|
#include "help_mp.h"
|
2002-06-10 01:32:12 +00:00
|
|
|
|
|
|
|
#include "ad_internal.h"
|
2004-04-30 10:26:26 +00:00
|
|
|
#include "wine/windef.h"
|
2002-06-10 01:32:12 +00:00
|
|
|
|
|
|
|
static ad_info_t info = {
|
2002-06-10 16:40:20 +00:00
|
|
|
"RealAudio decoder",
|
2002-08-30 20:06:22 +00:00
|
|
|
"realaud",
|
2004-06-24 09:19:15 +00:00
|
|
|
"Alex Beregszaszi",
|
|
|
|
"Florian Schneider, Arpad Gereoffy, Alex Beregszaszi, Donnie Smith",
|
2002-06-10 16:40:20 +00:00
|
|
|
"binary real audio codecs"
|
2002-06-10 01:32:12 +00:00
|
|
|
};
|
|
|
|
|
2002-08-30 20:06:22 +00:00
|
|
|
LIBAD_EXTERN(realaud)
|
2002-06-10 01:32:12 +00:00
|
|
|
|
|
|
|
void *__builtin_new(unsigned long size) {
|
|
|
|
return malloc(size);
|
|
|
|
}
|
|
|
|
|
2003-03-09 17:17:39 +00:00
|
|
|
// required for cook's uninit:
|
|
|
|
void __builtin_delete(void* ize) {
|
|
|
|
free(ize);
|
|
|
|
}
|
|
|
|
|
2005-05-25 08:48:32 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
|
2002-06-13 00:14:28 +00:00
|
|
|
void *__ctype_b=NULL;
|
2002-06-10 15:38:20 +00:00
|
|
|
#endif
|
2002-06-10 01:32:12 +00:00
|
|
|
|
2002-09-22 02:33:28 +00:00
|
|
|
static unsigned long (*raCloseCodec)(void*);
|
2002-09-29 19:19:31 +00:00
|
|
|
static unsigned long (*raDecode)(void*, char*,unsigned long,char*,unsigned int*,long);
|
2002-07-17 23:28:37 +00:00
|
|
|
static unsigned long (*raFlush)(unsigned long,unsigned long,unsigned long);
|
2002-09-22 02:33:28 +00:00
|
|
|
static unsigned long (*raFreeDecoder)(void*);
|
2002-09-29 19:19:31 +00:00
|
|
|
static void* (*raGetFlavorProperty)(void*,unsigned long,unsigned long,int*);
|
2002-07-17 23:28:37 +00:00
|
|
|
//static unsigned long (*raGetNumberOfFlavors2)(void);
|
2002-09-22 02:33:28 +00:00
|
|
|
static unsigned long (*raInitDecoder)(void*, void*);
|
2003-02-11 15:24:26 +00:00
|
|
|
static unsigned long (*raOpenCodec)(void*);
|
|
|
|
static unsigned long (*raOpenCodec2)(void*, void*);
|
2002-09-22 02:33:28 +00:00
|
|
|
static unsigned long (*raSetFlavor)(void*,unsigned long);
|
2002-10-16 15:59:04 +00:00
|
|
|
static void (*raSetDLLAccessPath)(char*);
|
2002-08-25 01:12:41 +00:00
|
|
|
static void (*raSetPwd)(char*,char*);
|
2003-02-11 15:24:26 +00:00
|
|
|
#ifdef USE_WIN32DLL
|
|
|
|
static unsigned long WINAPI (*wraCloseCodec)(void*);
|
|
|
|
static unsigned long WINAPI (*wraDecode)(void*, char*,unsigned long,char*,unsigned int*,long);
|
|
|
|
static unsigned long WINAPI (*wraFlush)(unsigned long,unsigned long,unsigned long);
|
|
|
|
static unsigned long WINAPI (*wraFreeDecoder)(void*);
|
|
|
|
static void* WINAPI (*wraGetFlavorProperty)(void*,unsigned long,unsigned long,int*);
|
|
|
|
static unsigned long WINAPI (*wraInitDecoder)(void*, void*);
|
|
|
|
static unsigned long WINAPI (*wraOpenCodec)(void*);
|
|
|
|
static unsigned long WINAPI (*wraOpenCodec2)(void*, void*);
|
|
|
|
static unsigned long WINAPI (*wraSetFlavor)(void*,unsigned long);
|
|
|
|
static void WINAPI (*wraSetDLLAccessPath)(char*);
|
|
|
|
static void WINAPI (*wraSetPwd)(char*,char*);
|
2002-06-10 01:32:12 +00:00
|
|
|
|
2003-02-11 15:24:26 +00:00
|
|
|
static int dll_type = 0; /* 0 = unix dlopen, 1 = win32 dll */
|
|
|
|
#endif
|
2004-06-24 09:19:15 +00:00
|
|
|
|
2003-02-11 15:24:26 +00:00
|
|
|
static void *rv_handle = NULL;
|
|
|
|
|
|
|
|
#if 0
|
2002-06-10 01:32:12 +00:00
|
|
|
typedef struct {
|
|
|
|
int samplerate;
|
|
|
|
short bits;
|
|
|
|
short channels;
|
|
|
|
int unk1;
|
|
|
|
int unk2;
|
|
|
|
int packetsize;
|
|
|
|
int unk3;
|
|
|
|
void* unk4;
|
2003-02-11 15:24:26 +00:00
|
|
|
} ra_init_t ;
|
|
|
|
#else
|
|
|
|
|
|
|
|
/*
|
|
|
|
Probably the linux .so-s were compiled with old GCC without setting
|
|
|
|
packing, so it adds 2 bytes padding after the quality field.
|
|
|
|
In windows it seems that there's no padding in it.
|
|
|
|
|
|
|
|
-- alex
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* linux dlls doesn't need packing */
|
|
|
|
typedef struct /*__attribute__((__packed__))*/ {
|
|
|
|
int samplerate;
|
|
|
|
short bits;
|
|
|
|
short channels;
|
|
|
|
short quality;
|
|
|
|
/* 2bytes padding here, by gcc */
|
|
|
|
int bits_per_frame;
|
|
|
|
int packetsize;
|
|
|
|
int extradata_len;
|
|
|
|
void* extradata;
|
2002-06-10 01:32:12 +00:00
|
|
|
} ra_init_t;
|
|
|
|
|
2003-02-11 15:24:26 +00:00
|
|
|
/* windows dlls need packed structs (no padding) */
|
|
|
|
typedef struct __attribute__((__packed__)) {
|
|
|
|
int samplerate;
|
|
|
|
short bits;
|
|
|
|
short channels;
|
|
|
|
short quality;
|
|
|
|
int bits_per_frame;
|
|
|
|
int packetsize;
|
|
|
|
int extradata_len;
|
|
|
|
void* extradata;
|
|
|
|
} wra_init_t;
|
|
|
|
#endif
|
|
|
|
|
2003-05-11 17:58:03 +00:00
|
|
|
#ifdef HAVE_LIBDL
|
2003-02-11 15:24:26 +00:00
|
|
|
static int load_syms_linux(char *path)
|
|
|
|
{
|
|
|
|
void *handle;
|
|
|
|
|
|
|
|
mp_msg(MSGT_DECVIDEO, MSGL_INFO, "opening shared obj '%s'\n", path);
|
|
|
|
handle = dlopen(path, RTLD_LAZY);
|
|
|
|
if (!handle)
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_DECVIDEO, MSGL_WARN, "Error: %s\n", dlerror());
|
|
|
|
return 0;
|
|
|
|
}
|
2002-06-10 01:32:12 +00:00
|
|
|
|
|
|
|
raCloseCodec = dlsym(handle, "RACloseCodec");
|
|
|
|
raDecode = dlsym(handle, "RADecode");
|
|
|
|
raFlush = dlsym(handle, "RAFlush");
|
|
|
|
raFreeDecoder = dlsym(handle, "RAFreeDecoder");
|
|
|
|
raGetFlavorProperty = dlsym(handle, "RAGetFlavorProperty");
|
2003-02-11 15:24:26 +00:00
|
|
|
raOpenCodec = dlsym(handle, "RAOpenCodec");
|
2003-03-09 17:17:39 +00:00
|
|
|
raOpenCodec2 = dlsym(handle, "RAOpenCodec2");
|
2002-06-10 01:32:12 +00:00
|
|
|
raInitDecoder = dlsym(handle, "RAInitDecoder");
|
|
|
|
raSetFlavor = dlsym(handle, "RASetFlavor");
|
2002-10-16 15:59:04 +00:00
|
|
|
raSetDLLAccessPath = dlsym(handle, "SetDLLAccessPath");
|
2002-08-25 01:12:41 +00:00
|
|
|
raSetPwd = dlsym(handle, "RASetPwd"); // optional, used by SIPR
|
2002-06-10 01:32:12 +00:00
|
|
|
|
2003-04-30 19:45:34 +00:00
|
|
|
if (raCloseCodec && raDecode && /*raFlush && */raFreeDecoder &&
|
2003-03-09 17:17:39 +00:00
|
|
|
raGetFlavorProperty && (raOpenCodec||raOpenCodec2) && raSetFlavor &&
|
2003-02-11 15:24:26 +00:00
|
|
|
/*raSetDLLAccessPath &&*/ raInitDecoder)
|
|
|
|
{
|
|
|
|
rv_handle = handle;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Cannot resolve symbols - incompatible dll: %s\n",path);
|
|
|
|
dlclose(handle);
|
|
|
|
return 0;
|
2003-05-11 17:58:03 +00:00
|
|
|
}
|
|
|
|
#endif
|
2003-02-11 15:24:26 +00:00
|
|
|
|
|
|
|
#ifdef USE_WIN32DLL
|
|
|
|
|
2003-05-11 17:58:03 +00:00
|
|
|
#ifdef WIN32_LOADER
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "loader/ldt_keeper.h"
|
2003-05-11 17:58:03 +00:00
|
|
|
#endif
|
2003-02-11 15:24:26 +00:00
|
|
|
void* WINAPI LoadLibraryA(char* name);
|
|
|
|
void* WINAPI GetProcAddress(void* handle,char *func);
|
|
|
|
int WINAPI FreeLibrary(void *handle);
|
|
|
|
|
2003-08-17 21:18:02 +00:00
|
|
|
static int load_syms_windows(char *path)
|
2003-02-11 15:24:26 +00:00
|
|
|
{
|
|
|
|
void *handle;
|
|
|
|
|
|
|
|
mp_msg(MSGT_DECVIDEO, MSGL_INFO, "opening win32 dll '%s'\n", path);
|
2003-05-11 17:58:03 +00:00
|
|
|
#ifdef WIN32_LOADER
|
2003-02-11 15:24:26 +00:00
|
|
|
Setup_LDT_Keeper();
|
2003-05-11 17:58:03 +00:00
|
|
|
#endif
|
2003-02-11 15:24:26 +00:00
|
|
|
handle = LoadLibraryA(path);
|
|
|
|
if (!handle)
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_DECVIDEO, MSGL_WARN, "Error loading dll\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
wraCloseCodec = GetProcAddress(handle, "RACloseCodec");
|
|
|
|
wraDecode = GetProcAddress(handle, "RADecode");
|
|
|
|
wraFlush = GetProcAddress(handle, "RAFlush");
|
|
|
|
wraFreeDecoder = GetProcAddress(handle, "RAFreeDecoder");
|
|
|
|
wraGetFlavorProperty = GetProcAddress(handle, "RAGetFlavorProperty");
|
|
|
|
wraOpenCodec = GetProcAddress(handle, "RAOpenCodec");
|
2003-03-09 17:17:39 +00:00
|
|
|
wraOpenCodec2 = GetProcAddress(handle, "RAOpenCodec2");
|
2003-02-11 15:24:26 +00:00
|
|
|
wraInitDecoder = GetProcAddress(handle, "RAInitDecoder");
|
|
|
|
wraSetFlavor = GetProcAddress(handle, "RASetFlavor");
|
|
|
|
wraSetDLLAccessPath = GetProcAddress(handle, "SetDLLAccessPath");
|
|
|
|
wraSetPwd = GetProcAddress(handle, "RASetPwd"); // optional, used by SIPR
|
|
|
|
|
2003-05-17 09:41:18 +00:00
|
|
|
if (wraCloseCodec && wraDecode && /*wraFlush && */wraFreeDecoder &&
|
2003-03-09 17:17:39 +00:00
|
|
|
wraGetFlavorProperty && (wraOpenCodec || wraOpenCodec2) && wraSetFlavor &&
|
2003-02-11 15:24:26 +00:00
|
|
|
/*wraSetDLLAccessPath &&*/ wraInitDecoder)
|
|
|
|
{
|
|
|
|
rv_handle = handle;
|
|
|
|
dll_type = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Cannot resolve symbols - incompatible dll: %s\n",path);
|
|
|
|
FreeLibrary(handle);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
2002-06-10 01:32:12 +00:00
|
|
|
|
2004-06-24 09:19:15 +00:00
|
|
|
|
2003-02-11 15:24:26 +00:00
|
|
|
static int preinit(sh_audio_t *sh){
|
|
|
|
// let's check if the driver is available, return 0 if not.
|
|
|
|
// (you should do that if you use external lib(s) which is optional)
|
|
|
|
unsigned int result;
|
|
|
|
int len=0;
|
|
|
|
void* prop;
|
2003-05-12 15:50:40 +00:00
|
|
|
char *path;
|
2003-02-11 15:24:26 +00:00
|
|
|
|
2003-05-12 15:50:40 +00:00
|
|
|
path = malloc(strlen(REALCODEC_PATH)+strlen(sh->codec->dll)+2);
|
|
|
|
if (!path) return 0;
|
2003-02-11 15:24:26 +00:00
|
|
|
sprintf(path, REALCODEC_PATH "/%s", sh->codec->dll);
|
|
|
|
|
|
|
|
/* first try to load linux dlls, if failed and we're supporting win32 dlls,
|
|
|
|
then try to load the windows ones */
|
2004-06-24 09:19:15 +00:00
|
|
|
|
2003-05-11 17:58:03 +00:00
|
|
|
#ifdef HAVE_LIBDL
|
|
|
|
if (strstr(sh->codec->dll,".dll") || !load_syms_linux(path))
|
|
|
|
#endif
|
2003-02-11 15:24:26 +00:00
|
|
|
#ifdef USE_WIN32DLL
|
2003-08-17 21:18:02 +00:00
|
|
|
if (!load_syms_windows(sh->codec->dll))
|
2003-02-11 15:24:26 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MissingDLLcodec, sh->codec->dll);
|
|
|
|
mp_msg(MSGT_DECVIDEO, MSGL_HINT, "Read the RealAudio section of the DOCS!\n");
|
2003-05-12 15:50:40 +00:00
|
|
|
free(path);
|
2003-02-11 15:24:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_WIN32DLL
|
|
|
|
if((raSetDLLAccessPath && dll_type == 0) || (wraSetDLLAccessPath && dll_type == 1)){
|
|
|
|
#else
|
2002-10-16 15:59:04 +00:00
|
|
|
if(raSetDLLAccessPath){
|
2003-02-11 15:24:26 +00:00
|
|
|
#endif
|
2003-05-12 15:50:40 +00:00
|
|
|
int i;
|
2003-02-11 15:24:26 +00:00
|
|
|
// used by 'SIPR'
|
2005-07-21 17:03:43 +00:00
|
|
|
path = realloc(path, strlen(REALCODEC_PATH) + 13);
|
2002-10-16 15:59:04 +00:00
|
|
|
sprintf(path, "DT_Codecs=" REALCODEC_PATH);
|
|
|
|
if(path[strlen(path)-1]!='/'){
|
|
|
|
path[strlen(path)+1]=0;
|
|
|
|
path[strlen(path)]='/';
|
|
|
|
}
|
|
|
|
path[strlen(path)+1]=0;
|
2003-02-11 15:24:26 +00:00
|
|
|
#ifdef USE_WIN32DLL
|
|
|
|
if (dll_type == 1)
|
2003-05-12 15:50:40 +00:00
|
|
|
{
|
|
|
|
for (i=0; i < strlen(path); i++)
|
|
|
|
if (path[i] == '/') path[i] = '\\';
|
2003-02-11 15:24:26 +00:00
|
|
|
wraSetDLLAccessPath(path);
|
2003-05-12 15:50:40 +00:00
|
|
|
}
|
2003-02-11 15:24:26 +00:00
|
|
|
else
|
|
|
|
#endif
|
2002-10-16 15:59:04 +00:00
|
|
|
raSetDLLAccessPath(path);
|
|
|
|
}
|
|
|
|
|
2003-02-11 15:24:26 +00:00
|
|
|
#ifdef USE_WIN32DLL
|
2003-03-09 17:17:39 +00:00
|
|
|
if (dll_type == 1){
|
|
|
|
if(wraOpenCodec2)
|
|
|
|
result=wraOpenCodec2(&sh->context,REALCODEC_PATH "\\");
|
|
|
|
else
|
2003-02-11 15:24:26 +00:00
|
|
|
result=wraOpenCodec(&sh->context);
|
2003-03-09 17:17:39 +00:00
|
|
|
} else
|
2003-02-11 15:24:26 +00:00
|
|
|
#endif
|
2003-03-09 17:17:39 +00:00
|
|
|
if(raOpenCodec2)
|
|
|
|
result=raOpenCodec2(&sh->context,REALCODEC_PATH "/");
|
|
|
|
else
|
|
|
|
result=raOpenCodec(&sh->context);
|
2002-06-10 01:32:12 +00:00
|
|
|
if(result){
|
|
|
|
mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder open failed, error code: 0x%X\n",result);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-02-11 15:24:26 +00:00
|
|
|
// printf("opencodec ok (result: %x)\n", result);
|
2003-05-12 15:50:40 +00:00
|
|
|
free(path); /* after this it isn't used anymore */
|
2002-06-10 01:32:12 +00:00
|
|
|
|
|
|
|
sh->samplerate=sh->wf->nSamplesPerSec;
|
|
|
|
sh->samplesize=sh->wf->wBitsPerSample/8;
|
|
|
|
sh->channels=sh->wf->nChannels;
|
|
|
|
|
2002-09-22 02:33:28 +00:00
|
|
|
{
|
2002-06-10 01:32:12 +00:00
|
|
|
ra_init_t init_data={
|
2003-02-11 15:24:26 +00:00
|
|
|
sh->wf->nSamplesPerSec,
|
|
|
|
sh->wf->wBitsPerSample,
|
|
|
|
sh->wf->nChannels,
|
|
|
|
100, // quality
|
2005-12-09 16:25:37 +00:00
|
|
|
sh->wf->nBlockAlign, // subpacket size
|
|
|
|
sh->wf->nBlockAlign, // coded frame size
|
|
|
|
sh->wf->cbSize, // codec data length
|
|
|
|
(char*)(sh->wf+1) // extras
|
2003-02-11 15:24:26 +00:00
|
|
|
};
|
2004-11-03 02:50:01 +00:00
|
|
|
#ifdef USE_WIN32DLL
|
2003-02-11 15:24:26 +00:00
|
|
|
wra_init_t winit_data={
|
|
|
|
sh->wf->nSamplesPerSec,
|
|
|
|
sh->wf->wBitsPerSample,
|
|
|
|
sh->wf->nChannels,
|
|
|
|
100, // quality
|
2005-12-09 16:25:37 +00:00
|
|
|
sh->wf->nBlockAlign, // subpacket size
|
|
|
|
sh->wf->nBlockAlign, // coded frame size
|
|
|
|
sh->wf->cbSize, // codec data length
|
|
|
|
(char*)(sh->wf+1) // extras
|
2002-06-10 01:32:12 +00:00
|
|
|
};
|
2004-06-24 09:19:15 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_WIN32DLL
|
2003-02-11 15:24:26 +00:00
|
|
|
if (dll_type == 1)
|
|
|
|
result=wraInitDecoder(sh->context,&winit_data);
|
|
|
|
else
|
|
|
|
#endif
|
2002-06-10 01:32:12 +00:00
|
|
|
result=raInitDecoder(sh->context,&init_data);
|
2004-11-03 02:50:01 +00:00
|
|
|
|
2002-06-10 01:32:12 +00:00
|
|
|
if(result){
|
|
|
|
mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder init failed, error code: 0x%X\n",result);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-02-11 15:24:26 +00:00
|
|
|
// printf("initdecoder ok (result: %x)\n", result);
|
2002-06-10 01:32:12 +00:00
|
|
|
}
|
2002-08-25 01:12:41 +00:00
|
|
|
|
2003-02-11 15:24:26 +00:00
|
|
|
#ifdef USE_WIN32DLL
|
|
|
|
if((raSetPwd && dll_type == 0) || (wraSetPwd && dll_type == 1)){
|
|
|
|
#else
|
2002-08-25 01:12:41 +00:00
|
|
|
if(raSetPwd){
|
2003-02-11 15:24:26 +00:00
|
|
|
#endif
|
2002-08-25 01:12:41 +00:00
|
|
|
// used by 'SIPR'
|
2003-02-11 15:24:26 +00:00
|
|
|
#ifdef USE_WIN32DLL
|
|
|
|
if (dll_type == 1)
|
|
|
|
wraSetPwd(sh->context,"Ardubancel Quazanga");
|
|
|
|
else
|
|
|
|
#endif
|
2002-08-25 01:12:41 +00:00
|
|
|
raSetPwd(sh->context,"Ardubancel Quazanga"); // set password... lol.
|
|
|
|
}
|
2002-06-10 01:32:12 +00:00
|
|
|
|
2005-12-09 16:25:37 +00:00
|
|
|
if (sh->format == mmioFOURCC('s','i','p','r')) {
|
|
|
|
short flavor;
|
|
|
|
|
|
|
|
if (sh->wf->nAvgBytesPerSec > 1531)
|
|
|
|
flavor = 3;
|
|
|
|
else if (sh->wf->nAvgBytesPerSec > 937)
|
|
|
|
flavor = 1;
|
|
|
|
else if (sh->wf->nAvgBytesPerSec > 719)
|
|
|
|
flavor = 0;
|
|
|
|
else
|
|
|
|
flavor = 2;
|
|
|
|
mp_msg(MSGT_DECAUDIO,MSGL_V,"Got sipr flavor %d from bitrate %d\n",flavor, sh->wf->nAvgBytesPerSec);
|
|
|
|
|
2003-02-11 15:24:26 +00:00
|
|
|
#ifdef USE_WIN32DLL
|
|
|
|
if (dll_type == 1)
|
2005-12-09 16:25:37 +00:00
|
|
|
result=wraSetFlavor(sh->context,flavor);
|
2003-02-11 15:24:26 +00:00
|
|
|
else
|
|
|
|
#endif
|
2005-12-09 16:25:37 +00:00
|
|
|
result=raSetFlavor(sh->context,flavor);
|
2002-06-10 01:32:12 +00:00
|
|
|
if(result){
|
|
|
|
mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder flavor setup failed, error code: 0x%X\n",result);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-12-09 16:25:37 +00:00
|
|
|
} // sipr flavor
|
2002-06-10 01:32:12 +00:00
|
|
|
|
2005-12-09 16:25:37 +00:00
|
|
|
sh->i_bps=sh->wf->nAvgBytesPerSec;
|
2003-03-09 17:17:39 +00:00
|
|
|
|
2002-06-10 16:40:20 +00:00
|
|
|
sh->audio_out_minsize=128000; // no idea how to get... :(
|
2005-12-09 16:25:37 +00:00
|
|
|
sh->audio_in_minsize = sh->wf->nBlockAlign;
|
2002-06-10 01:32:12 +00:00
|
|
|
|
|
|
|
return 1; // return values: 1=OK 0=ERROR
|
|
|
|
}
|
|
|
|
|
|
|
|
static int init(sh_audio_t *sh_audio){
|
|
|
|
// initialize the decoder, set tables etc...
|
|
|
|
|
|
|
|
// you can store HANDLE or private struct pointer at sh->context
|
|
|
|
// you can access WAVEFORMATEX header at sh->wf
|
|
|
|
|
|
|
|
// set sample format/rate parameters if you didn't do it in preinit() yet.
|
|
|
|
|
|
|
|
return 1; // return values: 1=OK 0=ERROR
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uninit(sh_audio_t *sh){
|
|
|
|
// uninit the decoder etc...
|
|
|
|
// again: you don't have to free() a_in_buffer here! it's done by the core.
|
2003-02-11 15:24:26 +00:00
|
|
|
#ifdef USE_WIN32DLL
|
|
|
|
if (dll_type == 1)
|
|
|
|
{
|
|
|
|
if (wraFreeDecoder) wraFreeDecoder(sh->context);
|
|
|
|
if (wraCloseCodec) wraCloseCodec(sh->context);
|
2003-03-09 17:17:39 +00:00
|
|
|
}
|
2003-02-11 15:24:26 +00:00
|
|
|
#endif
|
2003-03-09 17:17:39 +00:00
|
|
|
|
2003-02-11 15:24:26 +00:00
|
|
|
if (raFreeDecoder) raFreeDecoder(sh->context);
|
|
|
|
if (raCloseCodec) raCloseCodec(sh->context);
|
|
|
|
|
2004-06-24 09:19:15 +00:00
|
|
|
|
2003-02-11 15:24:26 +00:00
|
|
|
#ifdef USE_WIN32DLL
|
|
|
|
if (dll_type == 1)
|
|
|
|
{
|
|
|
|
if (rv_handle) FreeLibrary(rv_handle);
|
|
|
|
} else
|
|
|
|
#endif
|
2003-03-09 17:17:39 +00:00
|
|
|
// this dlclose() causes some memory corruption, and crashes soon (in caller):
|
|
|
|
// if (rv_handle) dlclose(rv_handle);
|
2003-02-11 15:24:26 +00:00
|
|
|
rv_handle = NULL;
|
2002-06-10 01:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen){
|
|
|
|
int result;
|
|
|
|
int len=-1;
|
2002-06-10 02:19:43 +00:00
|
|
|
|
2002-06-10 13:55:18 +00:00
|
|
|
if(sh->a_in_buffer_len<=0){
|
|
|
|
// fill the buffer!
|
|
|
|
demux_read_data(sh->ds, sh->a_in_buffer, sh->wf->nBlockAlign);
|
|
|
|
sh->a_in_buffer_size=
|
|
|
|
sh->a_in_buffer_len=sh->wf->nBlockAlign;
|
|
|
|
}
|
2002-06-10 01:32:12 +00:00
|
|
|
|
2003-02-11 15:24:26 +00:00
|
|
|
#ifdef USE_WIN32DLL
|
|
|
|
if (dll_type == 1)
|
|
|
|
result=wraDecode(sh->context, sh->a_in_buffer+sh->a_in_buffer_size-sh->a_in_buffer_len, sh->wf->nBlockAlign,
|
|
|
|
buf, &len, -1);
|
|
|
|
else
|
|
|
|
#endif
|
2002-06-10 13:55:18 +00:00
|
|
|
result=raDecode(sh->context, sh->a_in_buffer+sh->a_in_buffer_size-sh->a_in_buffer_len, sh->wf->nBlockAlign,
|
2002-06-10 01:32:12 +00:00
|
|
|
buf, &len, -1);
|
2002-06-10 02:19:43 +00:00
|
|
|
sh->a_in_buffer_len-=sh->wf->nBlockAlign;
|
|
|
|
|
2002-06-10 14:52:44 +00:00
|
|
|
// printf("radecode: %d bytes, res=0x%X \n",len,result);
|
2002-06-10 01:32:12 +00:00
|
|
|
|
2002-06-10 02:19:43 +00:00
|
|
|
return len; // return value: number of _bytes_ written to output buffer,
|
2002-06-10 01:32:12 +00:00
|
|
|
// or -1 for EOF (or uncorrectable error)
|
|
|
|
}
|
|
|
|
|
|
|
|
static int control(sh_audio_t *sh,int cmd,void* arg, ...){
|
|
|
|
// various optional functions you MAY implement:
|
|
|
|
switch(cmd){
|
|
|
|
case ADCTRL_RESYNC_STREAM:
|
|
|
|
// it is called once after seeking, to resync.
|
|
|
|
// Note: sh_audio->a_in_buffer_len=0; is done _before_ this call!
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
case ADCTRL_SKIP_FRAME:
|
|
|
|
// it is called to skip (jump over) small amount (1/10 sec or 1 frame)
|
|
|
|
// of audio data - used to sync audio to video after seeking
|
|
|
|
// if you don't return CONTROL_TRUE, it will defaults to:
|
|
|
|
// ds_fill_buffer(sh_audio->ds); // skip 1 demux packet
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
return CONTROL_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|