diff options
author | ben <ben@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2007-04-01 11:06:06 +0000 |
---|---|---|
committer | ben <ben@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2007-04-01 11:06:06 +0000 |
commit | 257a77dc3d0e793d4051521391b3dc7bef59d522 (patch) | |
tree | 5e8a8b96062ea25c1116e0801a0b7cafd1bbc452 /vidix/vidixlib.c | |
parent | cdcae64dc01b9e30d7a2ea3afb14df955a9d9a94 (diff) | |
download | mpv-257a77dc3d0e793d4051521391b3dc7bef59d522.tar.bz2 mpv-257a77dc3d0e793d4051521391b3dc7bef59d522.tar.xz |
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@22875 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'vidix/vidixlib.c')
-rw-r--r-- | vidix/vidixlib.c | 359 |
1 files changed, 140 insertions, 219 deletions
diff --git a/vidix/vidixlib.c b/vidix/vidixlib.c index 90e1cd2879..2da5ca83a7 100644 --- a/vidix/vidixlib.c +++ b/vidix/vidixlib.c @@ -21,238 +21,81 @@ #include <errno.h> #include <string.h> -#ifndef WIN32 -#include <dlfcn.h> /* GLIBC specific. Exists under cygwin too! */ -#else -#include <windows.h> -#define dlsym(h,s) GetProcAddress(h,s) -#define dlopen(h,s) LoadLibrary(h) -#define dlclose(h) FreeLibrary(h) -static char* dlerror(){ - char errormsg[10]; - sprintf(errormsg,"%i\n",GetLastError()); - return errormsg; -} -#endif - - -#include <dirent.h> - -#if defined(__OpenBSD__) && !defined(__ELF__) -#define dlsym(h,s) dlsym(h, "_" s) -#endif - #include "vidixlib.h" +#include "drivers.h" #include "../config.h" #include "../libavutil/common.h" #include "../mpbswap.h" -static char drv_name[FILENAME_MAX]; - -typedef struct vdl_stream_s -{ - void * handle; - int (*get_caps)(vidix_capability_t *); - int (*query_fourcc)(vidix_fourcc_t *); - int (*config_playback)(vidix_playback_t *); - int (*playback_on)( void ); - int (*playback_off)( void ); - /* Functions below can be missed in driver ;) */ - int (*init)(void); - void (*destroy)(void); - int (*frame_sel)( unsigned frame_idx ); - int (*get_eq)( vidix_video_eq_t * ); - int (*set_eq)( const vidix_video_eq_t * ); - int (*get_deint)( vidix_deinterlace_t * ); - int (*set_deint)( const vidix_deinterlace_t * ); - int (*copy_frame)( const vidix_dma_t * ); - int (*get_gkey)( vidix_grkey_t * ); - int (*set_gkey)( const vidix_grkey_t * ); - int (*get_num_fx)( unsigned * ); - int (*get_fx)( vidix_oem_fx_t * ); - int (*set_fx)( const vidix_oem_fx_t * ); -}vdl_stream_t; - -#define t_vdl(p) (((vdl_stream_t *)p)) - -extern unsigned vdlGetVersion( void ) +extern unsigned int vdlGetVersion( void ) { return VIDIX_VERSION; } -static int vdl_fill_driver(VDL_HANDLE stream) +VDL_HANDLE vdlOpen(const char *path,const char *name,unsigned cap,int verbose) { - t_vdl(stream)->init = dlsym(t_vdl(stream)->handle,"vixInit"); - t_vdl(stream)->destroy = dlsym(t_vdl(stream)->handle,"vixDestroy"); - t_vdl(stream)->get_caps = dlsym(t_vdl(stream)->handle,"vixGetCapability"); - t_vdl(stream)->query_fourcc = dlsym(t_vdl(stream)->handle,"vixQueryFourcc"); - t_vdl(stream)->config_playback= dlsym(t_vdl(stream)->handle,"vixConfigPlayback"); - t_vdl(stream)->playback_on = dlsym(t_vdl(stream)->handle,"vixPlaybackOn"); - t_vdl(stream)->playback_off = dlsym(t_vdl(stream)->handle,"vixPlaybackOff"); - t_vdl(stream)->frame_sel = dlsym(t_vdl(stream)->handle,"vixPlaybackFrameSelect"); - t_vdl(stream)->get_eq = dlsym(t_vdl(stream)->handle,"vixPlaybackGetEq"); - t_vdl(stream)->set_eq = dlsym(t_vdl(stream)->handle,"vixPlaybackSetEq"); - t_vdl(stream)->get_gkey = dlsym(t_vdl(stream)->handle,"vixGetGrKeys"); - t_vdl(stream)->set_gkey = dlsym(t_vdl(stream)->handle,"vixSetGrKeys"); - t_vdl(stream)->get_deint = dlsym(t_vdl(stream)->handle,"vixPlaybackGetDeint"); - t_vdl(stream)->set_deint = dlsym(t_vdl(stream)->handle,"vixPlaybackSetDeint"); - t_vdl(stream)->copy_frame = dlsym(t_vdl(stream)->handle,"vixPlaybackCopyFrame"); - t_vdl(stream)->get_num_fx = dlsym(t_vdl(stream)->handle,"vixQueryNumOemEffects"); - t_vdl(stream)->get_fx = dlsym(t_vdl(stream)->handle,"vixGetOemEffect"); - t_vdl(stream)->set_fx = dlsym(t_vdl(stream)->handle,"vixSetOemEffect"); - /* check driver viability */ - if(!( t_vdl(stream)->get_caps && t_vdl(stream)->query_fourcc && - t_vdl(stream)->config_playback && t_vdl(stream)->playback_on && - t_vdl(stream)->playback_off)) - { - printf("vidixlib: Incomplete driver: some of essential features are missed in it.\n"); - return 0; - } - return 1; -} + VDXContext *ctx; -#ifndef RTLD_GLOBAL -#define RTLD_GLOBAL RTLD_LAZY -#endif -#ifndef RTLD_NOW -#define RTLD_NOW RTLD_LAZY -#endif + if (!(ctx = malloc (sizeof (VDXContext)))) + return NULL; + memset (ctx, 0, sizeof (VDXContext)); -static int vdl_probe_driver(VDL_HANDLE stream,const char *path,const char *name,unsigned cap,int verbose) -{ - vidix_capability_t vid_cap; - unsigned (*_ver)(void); - int (*_probe)(int,int); - int (*_cap)(vidix_capability_t*); - strlcpy(drv_name,path, sizeof( drv_name )); - strlcat(drv_name,name, sizeof( drv_name )); - if(verbose) printf("vidixlib: PROBING: %s\n",drv_name); - if(!(t_vdl(stream)->handle = dlopen(drv_name,RTLD_LAZY|RTLD_GLOBAL))) - { - if(verbose) printf("vidixlib: %s not driver: %s\n",drv_name,dlerror()); - return 0; - } - _ver = dlsym(t_vdl(stream)->handle,"vixGetVersion"); - _probe = dlsym(t_vdl(stream)->handle,"vixProbe"); - _cap = dlsym(t_vdl(stream)->handle,"vixGetCapability"); - if(_ver) - { - if((*_ver)() != VIDIX_VERSION) - { - if(verbose) printf("vidixlib: %s has wrong version\n",drv_name); - err: - dlclose(t_vdl(stream)->handle); - t_vdl(stream)->handle = 0; - return 0; - } - } - else + /* register all drivers */ + vidix_register_all_drivers (); + + if (!vidix_find_driver (ctx, name, cap, verbose)) { - fatal_err: - if(verbose) printf("vidixlib: %s has no function definition\n",drv_name); - goto err; + free (ctx); + return NULL; } - if(_probe) { if((*_probe)(verbose,PROBE_NORMAL) != 0) goto err; } - else goto fatal_err; - if(_cap) { if((*_cap)(&vid_cap) != 0) goto err; } - else goto fatal_err; - if((vid_cap.type & cap) != cap) - { - if(verbose) printf("vidixlib: Found %s but has no required capability\n",drv_name); - goto err; - } - if(verbose) printf("vidixlib: %s probed o'k\n",drv_name); - return 1; -} -static int vdl_find_driver(VDL_HANDLE stream,const char *path,unsigned cap,int verbose) -{ - DIR *dstream; - struct dirent *name; - int done = 0; - if(!(dstream = opendir(path))) return 0; - while(!done) + if (verbose) + printf ("vidixlib: will use %s driver\n", ctx->drv->name); + + if (!ctx->drv || !ctx->drv->init) { - name = readdir(dstream); - if(name) - { - if(name->d_name[0] != '.') - if(vdl_probe_driver(stream,path,name->d_name,cap,verbose)) break; - } - else done = 1; + if (verbose) + printf ("vidixlib: Can't init driver\n"); + free (ctx); + return NULL; } - closedir(dstream); - return done?0:1; -} + + if (verbose) + printf ("vidixlib: Attempt to initialize driver at: %p\n", + ctx->drv->init); -VDL_HANDLE vdlOpen(const char *path,const char *name,unsigned cap,int verbose) -{ - vdl_stream_t *stream; - int errcode; - if(!(stream = malloc(sizeof(vdl_stream_t)))) return NULL; - memset(stream,0,sizeof(vdl_stream_t)); - if(name) + if (ctx->drv->init () !=0) { - unsigned (*ver)(void); - int (*probe)(int,int); - unsigned version = 0; - strlcpy(drv_name,path, sizeof( drv_name )); - strlcat(drv_name,name, sizeof( drv_name )); - if(!(t_vdl(stream)->handle = dlopen(drv_name,RTLD_NOW|RTLD_GLOBAL))) - { - if (verbose) - printf("vidixlib: dlopen error: %s\n", dlerror()); - err: - free(stream); - return NULL; - } - ver = dlsym(t_vdl(stream)->handle,"vixGetVersion"); - if(ver) version = (*ver)(); - if(version != VIDIX_VERSION) - { - drv_err: - if(t_vdl(stream)->handle) dlclose(t_vdl(stream)->handle); - goto err; - } - probe = dlsym(t_vdl(stream)->handle,"vixProbe"); - if(probe) { if((*probe)(verbose,PROBE_FORCE)!=0) goto drv_err; } - else goto drv_err; - fill: - if(!vdl_fill_driver(stream)) goto drv_err; - goto ok; + if (verbose) + printf ("vidixlib: Can't init driver\n"); + free (ctx); + return NULL; } - else - if(vdl_find_driver(stream,path,cap,verbose)) - { - if(verbose) printf("vidixlib: will use %s driver\n",drv_name); - goto fill; - } - else goto err; - ok: - if(t_vdl(stream)->init) - { - if(verbose) printf("vidixlib: Attempt to initialize driver at: %p\n",t_vdl(stream)->init); - if((errcode=t_vdl(stream)->init())!=0) - { - if(verbose) printf("vidixlib: Can't init driver: %s\n",strerror(errcode)); - goto drv_err; - } - } - if(verbose) printf("vidixlib: '%s'successfully loaded\n",drv_name); - return stream; + + if (verbose) + printf("vidixlib: '%s'successfully loaded\n", ctx->drv->name); + + return ctx; } void vdlClose(VDL_HANDLE stream) { - if(t_vdl(stream)->destroy) t_vdl(stream)->destroy(); - dlclose(t_vdl(stream)->handle); - memset(stream,0,sizeof(vdl_stream_t)); /* <- it's not stupid */ - free(stream); + VDXContext *ctx; + + ctx = (VDXContext *) stream; + if (ctx->drv->destroy) + ctx->drv->destroy (); + + memset (ctx, 0, sizeof (VDXContext)); /* <- it's not stupid */ + free (ctx); } int vdlGetCapability(VDL_HANDLE handle, vidix_capability_t *cap) { - return t_vdl(handle)->get_caps(cap); + VDXContext *ctx; + + ctx = (VDXContext *) handle; + return ctx->drv->get_caps (cap); } #define MPLAYER_IMGFMT_RGB (('R'<<24)|('G'<<16)|('B'<<8)) @@ -269,77 +112,155 @@ static uint32_t normalize_fourcc(uint32_t fourcc) int vdlQueryFourcc(VDL_HANDLE handle,vidix_fourcc_t *f) { + VDXContext *ctx; + + ctx = (VDXContext *) handle; f->fourcc = normalize_fourcc(f->fourcc); - return t_vdl(handle)->query_fourcc(f); + return ctx->drv->query_fourcc (f); } int vdlConfigPlayback(VDL_HANDLE handle,vidix_playback_t *p) { + VDXContext *ctx; + + ctx = (VDXContext *) handle; p->fourcc = normalize_fourcc(p->fourcc); - return t_vdl(handle)->config_playback(p); + return ctx->drv->config_playback (p); } int vdlPlaybackOn(VDL_HANDLE handle) { - return t_vdl(handle)->playback_on(); + VDXContext *ctx; + + ctx = (VDXContext *) handle; + return ctx->drv->playback_on (); } int vdlPlaybackOff(VDL_HANDLE handle) { - return t_vdl(handle)->playback_off(); + VDXContext *ctx; + + ctx = (VDXContext *) handle; + return ctx->drv->playback_off (); } int vdlPlaybackFrameSelect(VDL_HANDLE handle, unsigned frame_idx ) { - return t_vdl(handle)->frame_sel ? t_vdl(handle)->frame_sel(frame_idx) : ENOSYS; + VDXContext *ctx; + + ctx = (VDXContext *) handle; + if (ctx->drv->frame_sel) + return ctx->drv->frame_sel (frame_idx); + + return ENOSYS; } int vdlPlaybackGetEq(VDL_HANDLE handle, vidix_video_eq_t * e) { - return t_vdl(handle)->get_eq ? t_vdl(handle)->get_eq(e) : ENOSYS; + VDXContext *ctx; + + ctx = (VDXContext *) handle; + if (ctx->drv->get_eq) + return ctx->drv->get_eq (e); + + return ENOSYS; } int vdlPlaybackSetEq(VDL_HANDLE handle, const vidix_video_eq_t * e) { - return t_vdl(handle)->set_eq ? t_vdl(handle)->set_eq(e) : ENOSYS; + VDXContext *ctx; + + ctx = (VDXContext *) handle; + if (ctx->drv->set_eq) + return ctx->drv->set_eq (e); + + return ENOSYS; } int vdlPlaybackCopyFrame(VDL_HANDLE handle, const vidix_dma_t * f) { - return t_vdl(handle)->copy_frame ? t_vdl(handle)->copy_frame(f) : ENOSYS; + VDXContext *ctx; + + ctx = (VDXContext *) handle; + if (ctx->drv->copy_frame) + return ctx->drv->copy_frame (f); + + return ENOSYS; } int vdlGetGrKeys(VDL_HANDLE handle, vidix_grkey_t * k) { - return t_vdl(handle)->get_gkey ? t_vdl(handle)->get_gkey(k) : ENOSYS; + VDXContext *ctx; + + ctx = (VDXContext *) handle; + if (ctx->drv->get_gkey) + return ctx->drv->get_gkey (k); + + return ENOSYS; } int vdlSetGrKeys(VDL_HANDLE handle, const vidix_grkey_t * k) { - return t_vdl(handle)->set_gkey ? t_vdl(handle)->set_gkey(k) : ENOSYS; + VDXContext *ctx; + + ctx = (VDXContext *) handle; + if (ctx->drv->set_gkey) + return ctx->drv->set_gkey (k); + + return ENOSYS; } int vdlPlaybackGetDeint(VDL_HANDLE handle, vidix_deinterlace_t * d) { - return t_vdl(handle)->get_deint ? t_vdl(handle)->get_deint(d) : ENOSYS; + VDXContext *ctx; + + ctx = (VDXContext *) handle; + if (ctx->drv->get_deint) + return ctx->drv->get_deint (d); + + return ENOSYS; } int vdlPlaybackSetDeint(VDL_HANDLE handle, const vidix_deinterlace_t * d) { - return t_vdl(handle)->set_deint ? t_vdl(handle)->set_deint(d) : ENOSYS; + VDXContext *ctx; + + ctx = (VDXContext *) handle; + if (ctx->drv->set_deint) + return ctx->drv->set_deint (d); + + return ENOSYS; } int vdlQueryNumOemEffects(VDL_HANDLE handle, unsigned * number ) { - return t_vdl(handle)->get_num_fx ? t_vdl(handle)->get_num_fx(number) : ENOSYS; + VDXContext *ctx; + + ctx = (VDXContext *) handle; + if (ctx->drv->get_num_fx) + return ctx->drv->get_num_fx (number); + + return ENOSYS; } int vdlGetOemEffect(VDL_HANDLE handle, vidix_oem_fx_t * f) { - return t_vdl(handle)->get_fx ? t_vdl(handle)->get_fx(f) : ENOSYS; + VDXContext *ctx; + + ctx = (VDXContext *) handle; + if (ctx->drv->get_fx) + return ctx->drv->get_fx (f); + + return ENOSYS; } int vdlSetOemEffect(VDL_HANDLE handle, const vidix_oem_fx_t * f) { - return t_vdl(handle)->set_fx ? t_vdl(handle)->set_fx(f) : ENOSYS; + VDXContext *ctx; + + ctx = (VDXContext *) handle; + if (ctx->drv->set_fx) + return ctx->drv->set_fx (f); + + return ENOSYS; } |