📄 ad_realaud.c
字号:
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include "config.h"#ifdef USE_REALCODECS//#include <stddef.h>#ifdef HAVE_LIBDL#include <dlfcn.h>#endif#include "help_mp.h"#include "ad_internal.h"#include "wine/windef.h"static ad_info_t info = { "RealAudio decoder", "realaud", "Alex Beregszaszi", "Florian Schneider, Arpad Gereoffy, Alex Beregszaszi, Donnie Smith", "binary real audio codecs"};LIBAD_EXTERN(realaud)void *__builtin_new(unsigned long size) { return malloc(size);}// required for cook's uninit:void __builtin_delete(void* ize) { free(ize);}#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)void *__ctype_b=NULL;#endifstatic unsigned long (*raCloseCodec)(void*);static unsigned long (*raDecode)(void*, char*,unsigned long,char*,unsigned int*,long);static unsigned long (*raFlush)(unsigned long,unsigned long,unsigned long);static unsigned long (*raFreeDecoder)(void*);static void* (*raGetFlavorProperty)(void*,unsigned long,unsigned long,int*);//static unsigned long (*raGetNumberOfFlavors2)(void);static unsigned long (*raInitDecoder)(void*, void*);static unsigned long (*raOpenCodec)(void*);static unsigned long (*raOpenCodec2)(void*, void*);static unsigned long (*raSetFlavor)(void*,unsigned long);static void (*raSetDLLAccessPath)(char*);static void (*raSetPwd)(char*,char*);#ifdef USE_WIN32DLLstatic 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*);static int dll_type = 0; /* 0 = unix dlopen, 1 = win32 dll */#endifstatic void *rv_handle = NULL;#if 0typedef struct { int samplerate; short bits; short channels; int unk1; int unk2; int packetsize; int unk3; void* unk4;} 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;} ra_init_t;/* 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#ifdef HAVE_LIBDLstatic 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; } raCloseCodec = dlsym(handle, "RACloseCodec"); raDecode = dlsym(handle, "RADecode"); raFlush = dlsym(handle, "RAFlush"); raFreeDecoder = dlsym(handle, "RAFreeDecoder"); raGetFlavorProperty = dlsym(handle, "RAGetFlavorProperty"); raOpenCodec = dlsym(handle, "RAOpenCodec"); raOpenCodec2 = dlsym(handle, "RAOpenCodec2"); raInitDecoder = dlsym(handle, "RAInitDecoder"); raSetFlavor = dlsym(handle, "RASetFlavor"); raSetDLLAccessPath = dlsym(handle, "SetDLLAccessPath"); raSetPwd = dlsym(handle, "RASetPwd"); // optional, used by SIPR if (raCloseCodec && raDecode && /*raFlush && */raFreeDecoder && raGetFlavorProperty && (raOpenCodec||raOpenCodec2) && raSetFlavor && /*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;}#endif #ifdef USE_WIN32DLL#ifdef WIN32_LOADER#include "../loader/ldt_keeper.h"#endifvoid* WINAPI LoadLibraryA(char* name);void* WINAPI GetProcAddress(void* handle,char *func);int WINAPI FreeLibrary(void *handle);static int load_syms_windows(char *path){ void *handle; mp_msg(MSGT_DECVIDEO, MSGL_INFO, "opening win32 dll '%s'\n", path);#ifdef WIN32_LOADER Setup_LDT_Keeper();#endif 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"); wraOpenCodec2 = GetProcAddress(handle, "RAOpenCodec2"); wraInitDecoder = GetProcAddress(handle, "RAInitDecoder"); wraSetFlavor = GetProcAddress(handle, "RASetFlavor"); wraSetDLLAccessPath = GetProcAddress(handle, "SetDLLAccessPath"); wraSetPwd = GetProcAddress(handle, "RASetPwd"); // optional, used by SIPR if (wraCloseCodec && wraDecode && /*wraFlush && */wraFreeDecoder && wraGetFlavorProperty && (wraOpenCodec || wraOpenCodec2) && wraSetFlavor && /*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; }#endifstatic 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; char *path; path = malloc(strlen(REALCODEC_PATH)+strlen(sh->codec->dll)+2); if (!path) return 0; 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 */ #ifdef HAVE_LIBDL if (strstr(sh->codec->dll,".dll") || !load_syms_linux(path))#endif#ifdef USE_WIN32DLL if (!load_syms_windows(sh->codec->dll))#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"); free(path); return 0; }#ifdef USE_WIN32DLL if((raSetDLLAccessPath && dll_type == 0) || (wraSetDLLAccessPath && dll_type == 1)){#else if(raSetDLLAccessPath){#endif int i; // used by 'SIPR' path = realloc(path, strlen(REALCODEC_PATH) + 12); sprintf(path, "DT_Codecs=" REALCODEC_PATH); if(path[strlen(path)-1]!='/'){ path[strlen(path)+1]=0; path[strlen(path)]='/'; } path[strlen(path)+1]=0;#ifdef USE_WIN32DLL if (dll_type == 1) { for (i=0; i < strlen(path); i++) if (path[i] == '/') path[i] = '\\'; wraSetDLLAccessPath(path); } else#endif raSetDLLAccessPath(path); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -