annotate vidix/vidixlib.c @ 21388:be5f168e42ae

Use av_int2flt/av_int2dbl to read float values. This is simpler and more correct since it also works for int endianness != float endianness.
author reimar
date Thu, 30 Nov 2006 17:55:00 +0000
parents 1767c271d710
children fa99b3d31d13
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
1 /*
dcc632dd2097 preliminary version
nick
parents:
diff changeset
2 * vidixlib.c
dcc632dd2097 preliminary version
nick
parents:
diff changeset
3 * VIDIXLib - Library for VIDeo Interface for *niX
dcc632dd2097 preliminary version
nick
parents:
diff changeset
4 * This interface is introduced as universal one to MPEG decoder,
dcc632dd2097 preliminary version
nick
parents:
diff changeset
5 * BES == Back End Scaler and YUV2RGB hw accelerators.
dcc632dd2097 preliminary version
nick
parents:
diff changeset
6 * In the future it may be expanded up to capturing and audio things.
dcc632dd2097 preliminary version
nick
parents:
diff changeset
7 * Main goal of this this interface imlpementation is providing DGA
dcc632dd2097 preliminary version
nick
parents:
diff changeset
8 * everywhere where it's possible (unlike X11 and other).
dcc632dd2097 preliminary version
nick
parents:
diff changeset
9 * Copyright 2002 Nick Kurshev
dcc632dd2097 preliminary version
nick
parents:
diff changeset
10 * Licence: GPL
dcc632dd2097 preliminary version
nick
parents:
diff changeset
11 * This interface is based on v4l2, fbvid.h, mga_vid.h projects
dcc632dd2097 preliminary version
nick
parents:
diff changeset
12 * and personally my ideas.
dcc632dd2097 preliminary version
nick
parents:
diff changeset
13 * NOTE: This interface is introduces as APP interface.
dcc632dd2097 preliminary version
nick
parents:
diff changeset
14 * Don't use it for driver.
dcc632dd2097 preliminary version
nick
parents:
diff changeset
15 * It provides multistreaming. This mean that APP can handle
dcc632dd2097 preliminary version
nick
parents:
diff changeset
16 * several streams simultaneously. (Example: Video capturing and video
dcc632dd2097 preliminary version
nick
parents:
diff changeset
17 * playback or capturing, video playback, audio encoding and so on).
dcc632dd2097 preliminary version
nick
parents:
diff changeset
18 */
dcc632dd2097 preliminary version
nick
parents:
diff changeset
19 #include <stdlib.h>
dcc632dd2097 preliminary version
nick
parents:
diff changeset
20 #include <stdio.h>
dcc632dd2097 preliminary version
nick
parents:
diff changeset
21 #include <errno.h>
dcc632dd2097 preliminary version
nick
parents:
diff changeset
22 #include <string.h>
dcc632dd2097 preliminary version
nick
parents:
diff changeset
23
10982
285e298968de Windows port
faust3
parents: 6130
diff changeset
24 #ifndef WIN32
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
25 #include <dlfcn.h> /* GLIBC specific. Exists under cygwin too! */
10982
285e298968de Windows port
faust3
parents: 6130
diff changeset
26 #else
285e298968de Windows port
faust3
parents: 6130
diff changeset
27 #include <windows.h>
285e298968de Windows port
faust3
parents: 6130
diff changeset
28 #define dlsym(h,s) GetProcAddress(h,s)
285e298968de Windows port
faust3
parents: 6130
diff changeset
29 #define dlopen(h,s) LoadLibrary(h)
285e298968de Windows port
faust3
parents: 6130
diff changeset
30 #define dlclose(h) FreeLibrary(h)
285e298968de Windows port
faust3
parents: 6130
diff changeset
31 static char* dlerror(){
285e298968de Windows port
faust3
parents: 6130
diff changeset
32 char errormsg[10];
285e298968de Windows port
faust3
parents: 6130
diff changeset
33 sprintf(errormsg,"%i\n",GetLastError());
285e298968de Windows port
faust3
parents: 6130
diff changeset
34 return errormsg;
285e298968de Windows port
faust3
parents: 6130
diff changeset
35 }
285e298968de Windows port
faust3
parents: 6130
diff changeset
36 #endif
285e298968de Windows port
faust3
parents: 6130
diff changeset
37
285e298968de Windows port
faust3
parents: 6130
diff changeset
38
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
39 #include <dirent.h>
dcc632dd2097 preliminary version
nick
parents:
diff changeset
40
6130
e9a309486f18 openbsd a.out needs underscore for dlsym - patch by Bj«Órn Sandell <biorn@dce.chalmers.se>
arpi
parents: 5872
diff changeset
41 #if defined(__OpenBSD__) && !defined(__ELF__)
e9a309486f18 openbsd a.out needs underscore for dlsym - patch by Bj«Órn Sandell <biorn@dce.chalmers.se>
arpi
parents: 5872
diff changeset
42 #define dlsym(h,s) dlsym(h, "_" s)
e9a309486f18 openbsd a.out needs underscore for dlsym - patch by Bj«Órn Sandell <biorn@dce.chalmers.se>
arpi
parents: 5872
diff changeset
43 #endif
e9a309486f18 openbsd a.out needs underscore for dlsym - patch by Bj«Órn Sandell <biorn@dce.chalmers.se>
arpi
parents: 5872
diff changeset
44
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
45 #include "vidixlib.h"
21372
1767c271d710 Remove bswap.h, use libavutil/bswap.h instead.
diego
parents: 21371
diff changeset
46 #include "../config.h"
1767c271d710 Remove bswap.h, use libavutil/bswap.h instead.
diego
parents: 21371
diff changeset
47 #include "../libavutil/common.h"
1767c271d710 Remove bswap.h, use libavutil/bswap.h instead.
diego
parents: 21371
diff changeset
48 #include "../libavutil/bswap.h"
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
49
4011
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
50 static char drv_name[FILENAME_MAX];
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
51
dcc632dd2097 preliminary version
nick
parents:
diff changeset
52 typedef struct vdl_stream_s
dcc632dd2097 preliminary version
nick
parents:
diff changeset
53 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
54 void * handle;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
55 int (*get_caps)(vidix_capability_t *);
dcc632dd2097 preliminary version
nick
parents:
diff changeset
56 int (*query_fourcc)(vidix_fourcc_t *);
3995
0d9de811e312 minor interface changing
nick
parents: 3991
diff changeset
57 int (*config_playback)(vidix_playback_t *);
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
58 int (*playback_on)( void );
dcc632dd2097 preliminary version
nick
parents:
diff changeset
59 int (*playback_off)( void );
dcc632dd2097 preliminary version
nick
parents:
diff changeset
60 /* Functions below can be missed in driver ;) */
dcc632dd2097 preliminary version
nick
parents:
diff changeset
61 int (*init)(void);
dcc632dd2097 preliminary version
nick
parents:
diff changeset
62 void (*destroy)(void);
dcc632dd2097 preliminary version
nick
parents:
diff changeset
63 int (*frame_sel)( unsigned frame_idx );
dcc632dd2097 preliminary version
nick
parents:
diff changeset
64 int (*get_eq)( vidix_video_eq_t * );
dcc632dd2097 preliminary version
nick
parents:
diff changeset
65 int (*set_eq)( const vidix_video_eq_t * );
4191
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
66 int (*get_deint)( vidix_deinterlace_t * );
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
67 int (*set_deint)( const vidix_deinterlace_t * );
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
68 int (*copy_frame)( const vidix_dma_t * );
4070
b61ba6c256dd Minor interface changes: color and video keys are moved out from playback configuring
nick
parents: 4011
diff changeset
69 int (*get_gkey)( vidix_grkey_t * );
b61ba6c256dd Minor interface changes: color and video keys are moved out from playback configuring
nick
parents: 4011
diff changeset
70 int (*set_gkey)( const vidix_grkey_t * );
4191
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
71 int (*get_num_fx)( unsigned * );
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
72 int (*get_fx)( vidix_oem_fx_t * );
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
73 int (*set_fx)( const vidix_oem_fx_t * );
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
74 }vdl_stream_t;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
75
dcc632dd2097 preliminary version
nick
parents:
diff changeset
76 #define t_vdl(p) (((vdl_stream_t *)p))
dcc632dd2097 preliminary version
nick
parents:
diff changeset
77
dcc632dd2097 preliminary version
nick
parents:
diff changeset
78 extern unsigned vdlGetVersion( void )
dcc632dd2097 preliminary version
nick
parents:
diff changeset
79 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
80 return VIDIX_VERSION;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
81 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
82
dcc632dd2097 preliminary version
nick
parents:
diff changeset
83 static int vdl_fill_driver(VDL_HANDLE stream)
dcc632dd2097 preliminary version
nick
parents:
diff changeset
84 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
85 t_vdl(stream)->init = dlsym(t_vdl(stream)->handle,"vixInit");
dcc632dd2097 preliminary version
nick
parents:
diff changeset
86 t_vdl(stream)->destroy = dlsym(t_vdl(stream)->handle,"vixDestroy");
dcc632dd2097 preliminary version
nick
parents:
diff changeset
87 t_vdl(stream)->get_caps = dlsym(t_vdl(stream)->handle,"vixGetCapability");
dcc632dd2097 preliminary version
nick
parents:
diff changeset
88 t_vdl(stream)->query_fourcc = dlsym(t_vdl(stream)->handle,"vixQueryFourcc");
dcc632dd2097 preliminary version
nick
parents:
diff changeset
89 t_vdl(stream)->config_playback= dlsym(t_vdl(stream)->handle,"vixConfigPlayback");
dcc632dd2097 preliminary version
nick
parents:
diff changeset
90 t_vdl(stream)->playback_on = dlsym(t_vdl(stream)->handle,"vixPlaybackOn");
dcc632dd2097 preliminary version
nick
parents:
diff changeset
91 t_vdl(stream)->playback_off = dlsym(t_vdl(stream)->handle,"vixPlaybackOff");
dcc632dd2097 preliminary version
nick
parents:
diff changeset
92 t_vdl(stream)->frame_sel = dlsym(t_vdl(stream)->handle,"vixPlaybackFrameSelect");
dcc632dd2097 preliminary version
nick
parents:
diff changeset
93 t_vdl(stream)->get_eq = dlsym(t_vdl(stream)->handle,"vixPlaybackGetEq");
dcc632dd2097 preliminary version
nick
parents:
diff changeset
94 t_vdl(stream)->set_eq = dlsym(t_vdl(stream)->handle,"vixPlaybackSetEq");
4070
b61ba6c256dd Minor interface changes: color and video keys are moved out from playback configuring
nick
parents: 4011
diff changeset
95 t_vdl(stream)->get_gkey = dlsym(t_vdl(stream)->handle,"vixGetGrKeys");
b61ba6c256dd Minor interface changes: color and video keys are moved out from playback configuring
nick
parents: 4011
diff changeset
96 t_vdl(stream)->set_gkey = dlsym(t_vdl(stream)->handle,"vixSetGrKeys");
4191
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
97 t_vdl(stream)->get_deint = dlsym(t_vdl(stream)->handle,"vixPlaybackGetDeint");
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
98 t_vdl(stream)->set_deint = dlsym(t_vdl(stream)->handle,"vixPlaybackSetDeint");
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
99 t_vdl(stream)->copy_frame = dlsym(t_vdl(stream)->handle,"vixPlaybackCopyFrame");
4191
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
100 t_vdl(stream)->get_num_fx = dlsym(t_vdl(stream)->handle,"vixQueryNumOemEffects");
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
101 t_vdl(stream)->get_fx = dlsym(t_vdl(stream)->handle,"vixGetOemEffect");
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
102 t_vdl(stream)->set_fx = dlsym(t_vdl(stream)->handle,"vixSetOemEffect");
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
103 /* check driver viability */
3995
0d9de811e312 minor interface changing
nick
parents: 3991
diff changeset
104 if(!( t_vdl(stream)->get_caps && t_vdl(stream)->query_fourcc &&
0d9de811e312 minor interface changing
nick
parents: 3991
diff changeset
105 t_vdl(stream)->config_playback && t_vdl(stream)->playback_on &&
0d9de811e312 minor interface changing
nick
parents: 3991
diff changeset
106 t_vdl(stream)->playback_off))
4011
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
107 {
4509
90386125ec1f using dlerror() instead strerror(), displays unresolved symbol messages
alex
parents: 4191
diff changeset
108 printf("vidixlib: Incomplete driver: some of essential features are missed in it.\n");
4011
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
109 return 0;
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
110 }
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
111 return 1;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
112 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
113
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4547
diff changeset
114 #ifndef RTLD_GLOBAL
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4547
diff changeset
115 #define RTLD_GLOBAL RTLD_LAZY
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4547
diff changeset
116 #endif
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4547
diff changeset
117 #ifndef RTLD_NOW
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4547
diff changeset
118 #define RTLD_NOW RTLD_LAZY
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4547
diff changeset
119 #endif
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4547
diff changeset
120
3995
0d9de811e312 minor interface changing
nick
parents: 3991
diff changeset
121 static int vdl_probe_driver(VDL_HANDLE stream,const char *path,const char *name,unsigned cap,int verbose)
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
122 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
123 vidix_capability_t vid_cap;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
124 unsigned (*_ver)(void);
4191
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
125 int (*_probe)(int,int);
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
126 int (*_cap)(vidix_capability_t*);
12646
9a495bdc3a1e string handling security fixes
diego
parents: 10982
diff changeset
127 strlcpy(drv_name,path, sizeof( drv_name ));
9a495bdc3a1e string handling security fixes
diego
parents: 10982
diff changeset
128 strlcat(drv_name,name, sizeof( drv_name ));
4008
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
129 if(verbose) printf("vidixlib: PROBING: %s\n",drv_name);
4011
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
130 if(!(t_vdl(stream)->handle = dlopen(drv_name,RTLD_LAZY|RTLD_GLOBAL)))
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
131 {
4509
90386125ec1f using dlerror() instead strerror(), displays unresolved symbol messages
alex
parents: 4191
diff changeset
132 if(verbose) printf("vidixlib: %s not driver: %s\n",drv_name,dlerror());
4011
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
133 return 0;
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
134 }
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
135 _ver = dlsym(t_vdl(stream)->handle,"vixGetVersion");
dcc632dd2097 preliminary version
nick
parents:
diff changeset
136 _probe = dlsym(t_vdl(stream)->handle,"vixProbe");
dcc632dd2097 preliminary version
nick
parents:
diff changeset
137 _cap = dlsym(t_vdl(stream)->handle,"vixGetCapability");
4008
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
138 if(_ver)
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
139 {
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
140 if((*_ver)() != VIDIX_VERSION)
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
141 {
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
142 if(verbose) printf("vidixlib: %s has wrong version\n",drv_name);
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
143 err:
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
144 dlclose(t_vdl(stream)->handle);
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
145 t_vdl(stream)->handle = 0;
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
146 return 0;
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
147 }
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
148 }
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
149 else
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
150 {
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
151 fatal_err:
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
152 if(verbose) printf("vidixlib: %s has no function definition\n",drv_name);
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
153 goto err;
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
154 }
4191
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
155 if(_probe) { if((*_probe)(verbose,PROBE_NORMAL) != 0) goto err; }
4008
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
156 else goto fatal_err;
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
157 if(_cap) { if((*_cap)(&vid_cap) != 0) goto err; }
4008
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
158 else goto fatal_err;
4011
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
159 if((vid_cap.type & cap) != cap)
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
160 {
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
161 if(verbose) printf("vidixlib: Found %s but has no required capability\n",drv_name);
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
162 goto err;
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
163 }
4008
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
164 if(verbose) printf("vidixlib: %s probed o'k\n",drv_name);
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
165 return 1;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
166 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
167
3995
0d9de811e312 minor interface changing
nick
parents: 3991
diff changeset
168 static int vdl_find_driver(VDL_HANDLE stream,const char *path,unsigned cap,int verbose)
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
169 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
170 DIR *dstream;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
171 struct dirent *name;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
172 int done = 0;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
173 if(!(dstream = opendir(path))) return 0;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
174 while(!done)
dcc632dd2097 preliminary version
nick
parents:
diff changeset
175 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
176 name = readdir(dstream);
4008
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
177 if(name)
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
178 {
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
179 if(name->d_name[0] != '.')
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
180 if(vdl_probe_driver(stream,path,name->d_name,cap,verbose)) break;
a37207881d10 minor interface changing and verbosing
nick
parents: 3995
diff changeset
181 }
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
182 else done = 1;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
183 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
184 closedir(dstream);
dcc632dd2097 preliminary version
nick
parents:
diff changeset
185 return done?0:1;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
186 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
187
3995
0d9de811e312 minor interface changing
nick
parents: 3991
diff changeset
188 VDL_HANDLE vdlOpen(const char *path,const char *name,unsigned cap,int verbose)
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
189 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
190 vdl_stream_t *stream;
4011
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
191 int errcode;
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
192 if(!(stream = malloc(sizeof(vdl_stream_t)))) return NULL;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
193 memset(stream,0,sizeof(vdl_stream_t));
dcc632dd2097 preliminary version
nick
parents:
diff changeset
194 if(name)
dcc632dd2097 preliminary version
nick
parents:
diff changeset
195 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
196 unsigned (*ver)(void);
4191
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
197 int (*probe)(int,int);
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
198 unsigned version = 0;
12646
9a495bdc3a1e string handling security fixes
diego
parents: 10982
diff changeset
199 strlcpy(drv_name,path, sizeof( drv_name ));
9a495bdc3a1e string handling security fixes
diego
parents: 10982
diff changeset
200 strlcat(drv_name,name, sizeof( drv_name ));
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
201 if(!(t_vdl(stream)->handle = dlopen(drv_name,RTLD_NOW|RTLD_GLOBAL)))
dcc632dd2097 preliminary version
nick
parents:
diff changeset
202 {
4509
90386125ec1f using dlerror() instead strerror(), displays unresolved symbol messages
alex
parents: 4191
diff changeset
203 if (verbose)
90386125ec1f using dlerror() instead strerror(), displays unresolved symbol messages
alex
parents: 4191
diff changeset
204 printf("vidixlib: dlopen error: %s\n", dlerror());
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
205 err:
dcc632dd2097 preliminary version
nick
parents:
diff changeset
206 free(stream);
dcc632dd2097 preliminary version
nick
parents:
diff changeset
207 return NULL;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
208 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
209 ver = dlsym(t_vdl(stream)->handle,"vixGetVersion");
dcc632dd2097 preliminary version
nick
parents:
diff changeset
210 if(ver) version = (*ver)();
dcc632dd2097 preliminary version
nick
parents:
diff changeset
211 if(version != VIDIX_VERSION)
dcc632dd2097 preliminary version
nick
parents:
diff changeset
212 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
213 drv_err:
dcc632dd2097 preliminary version
nick
parents:
diff changeset
214 if(t_vdl(stream)->handle) dlclose(t_vdl(stream)->handle);
dcc632dd2097 preliminary version
nick
parents:
diff changeset
215 goto err;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
216 }
3995
0d9de811e312 minor interface changing
nick
parents: 3991
diff changeset
217 probe = dlsym(t_vdl(stream)->handle,"vixProbe");
4191
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
218 if(probe) { if((*probe)(verbose,PROBE_FORCE)!=0) goto drv_err; }
3995
0d9de811e312 minor interface changing
nick
parents: 3991
diff changeset
219 else goto drv_err;
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
220 fill:
dcc632dd2097 preliminary version
nick
parents:
diff changeset
221 if(!vdl_fill_driver(stream)) goto drv_err;
4011
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
222 goto ok;
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
223 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
224 else
4011
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
225 if(vdl_find_driver(stream,path,cap,verbose))
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
226 {
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
227 if(verbose) printf("vidixlib: will use %s driver\n",drv_name);
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
228 goto fill;
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
229 }
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
230 else goto err;
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
231 ok:
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
232 if(t_vdl(stream)->init)
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
233 {
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
234 if(verbose) printf("vidixlib: Attempt to initialize driver at: %p\n",t_vdl(stream)->init);
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
235 if((errcode=t_vdl(stream)->init())!=0)
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
236 {
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
237 if(verbose) printf("vidixlib: Can't init driver: %s\n",strerror(errcode));
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
238 goto drv_err;
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
239 }
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
240 }
ca163699151f lazy loader works better ;)
nick
parents: 4008
diff changeset
241 if(verbose) printf("vidixlib: '%s'successfully loaded\n",drv_name);
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
242 return stream;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
243 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
244
dcc632dd2097 preliminary version
nick
parents:
diff changeset
245 void vdlClose(VDL_HANDLE stream)
dcc632dd2097 preliminary version
nick
parents:
diff changeset
246 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
247 if(t_vdl(stream)->destroy) t_vdl(stream)->destroy();
dcc632dd2097 preliminary version
nick
parents:
diff changeset
248 dlclose(t_vdl(stream)->handle);
dcc632dd2097 preliminary version
nick
parents:
diff changeset
249 memset(stream,0,sizeof(vdl_stream_t)); /* <- it's not stupid */
dcc632dd2097 preliminary version
nick
parents:
diff changeset
250 free(stream);
dcc632dd2097 preliminary version
nick
parents:
diff changeset
251 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
252
dcc632dd2097 preliminary version
nick
parents:
diff changeset
253 int vdlGetCapability(VDL_HANDLE handle, vidix_capability_t *cap)
dcc632dd2097 preliminary version
nick
parents:
diff changeset
254 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
255 return t_vdl(handle)->get_caps(cap);
dcc632dd2097 preliminary version
nick
parents:
diff changeset
256 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
257
4539
fcd6e49cb3cc mplayer has swapped RGB's fourcc :(
nick
parents: 4509
diff changeset
258 #define MPLAYER_IMGFMT_RGB (('R'<<24)|('G'<<16)|('B'<<8))
fcd6e49cb3cc mplayer has swapped RGB's fourcc :(
nick
parents: 4509
diff changeset
259 #define MPLAYER_IMGFMT_BGR (('B'<<24)|('G'<<16)|('R'<<8))
fcd6e49cb3cc mplayer has swapped RGB's fourcc :(
nick
parents: 4509
diff changeset
260 #define MPLAYER_IMGFMT_RGB_MASK 0xFFFFFF00
fcd6e49cb3cc mplayer has swapped RGB's fourcc :(
nick
parents: 4509
diff changeset
261
4547
nick
parents: 4539
diff changeset
262 static uint32_t normalize_fourcc(uint32_t fourcc)
4539
fcd6e49cb3cc mplayer has swapped RGB's fourcc :(
nick
parents: 4509
diff changeset
263 {
fcd6e49cb3cc mplayer has swapped RGB's fourcc :(
nick
parents: 4509
diff changeset
264 if((fourcc & MPLAYER_IMGFMT_RGB_MASK) == (MPLAYER_IMGFMT_RGB|0) ||
fcd6e49cb3cc mplayer has swapped RGB's fourcc :(
nick
parents: 4509
diff changeset
265 (fourcc & MPLAYER_IMGFMT_RGB_MASK) == (MPLAYER_IMGFMT_BGR|0))
fcd6e49cb3cc mplayer has swapped RGB's fourcc :(
nick
parents: 4509
diff changeset
266 return bswap_32(fourcc);
fcd6e49cb3cc mplayer has swapped RGB's fourcc :(
nick
parents: 4509
diff changeset
267 else return fourcc;
fcd6e49cb3cc mplayer has swapped RGB's fourcc :(
nick
parents: 4509
diff changeset
268 }
fcd6e49cb3cc mplayer has swapped RGB's fourcc :(
nick
parents: 4509
diff changeset
269
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
270 int vdlQueryFourcc(VDL_HANDLE handle,vidix_fourcc_t *f)
dcc632dd2097 preliminary version
nick
parents:
diff changeset
271 {
4547
nick
parents: 4539
diff changeset
272 f->fourcc = normalize_fourcc(f->fourcc);
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
273 return t_vdl(handle)->query_fourcc(f);
dcc632dd2097 preliminary version
nick
parents:
diff changeset
274 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
275
3995
0d9de811e312 minor interface changing
nick
parents: 3991
diff changeset
276 int vdlConfigPlayback(VDL_HANDLE handle,vidix_playback_t *p)
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
277 {
4547
nick
parents: 4539
diff changeset
278 p->fourcc = normalize_fourcc(p->fourcc);
3991
dcc632dd2097 preliminary version
nick
parents:
diff changeset
279 return t_vdl(handle)->config_playback(p);
dcc632dd2097 preliminary version
nick
parents:
diff changeset
280 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
281
dcc632dd2097 preliminary version
nick
parents:
diff changeset
282 int vdlPlaybackOn(VDL_HANDLE handle)
dcc632dd2097 preliminary version
nick
parents:
diff changeset
283 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
284 return t_vdl(handle)->playback_on();
dcc632dd2097 preliminary version
nick
parents:
diff changeset
285 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
286
dcc632dd2097 preliminary version
nick
parents:
diff changeset
287 int vdlPlaybackOff(VDL_HANDLE handle)
dcc632dd2097 preliminary version
nick
parents:
diff changeset
288 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
289 return t_vdl(handle)->playback_off();
dcc632dd2097 preliminary version
nick
parents:
diff changeset
290 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
291
dcc632dd2097 preliminary version
nick
parents:
diff changeset
292 int vdlPlaybackFrameSelect(VDL_HANDLE handle, unsigned frame_idx )
dcc632dd2097 preliminary version
nick
parents:
diff changeset
293 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
294 return t_vdl(handle)->frame_sel ? t_vdl(handle)->frame_sel(frame_idx) : ENOSYS;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
295 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
296
dcc632dd2097 preliminary version
nick
parents:
diff changeset
297 int vdlPlaybackGetEq(VDL_HANDLE handle, vidix_video_eq_t * e)
dcc632dd2097 preliminary version
nick
parents:
diff changeset
298 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
299 return t_vdl(handle)->get_eq ? t_vdl(handle)->get_eq(e) : ENOSYS;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
300 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
301
dcc632dd2097 preliminary version
nick
parents:
diff changeset
302 int vdlPlaybackSetEq(VDL_HANDLE handle, const vidix_video_eq_t * e)
dcc632dd2097 preliminary version
nick
parents:
diff changeset
303 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
304 return t_vdl(handle)->set_eq ? t_vdl(handle)->set_eq(e) : ENOSYS;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
305 }
dcc632dd2097 preliminary version
nick
parents:
diff changeset
306
dcc632dd2097 preliminary version
nick
parents:
diff changeset
307 int vdlPlaybackCopyFrame(VDL_HANDLE handle, const vidix_dma_t * f)
dcc632dd2097 preliminary version
nick
parents:
diff changeset
308 {
dcc632dd2097 preliminary version
nick
parents:
diff changeset
309 return t_vdl(handle)->copy_frame ? t_vdl(handle)->copy_frame(f) : ENOSYS;
dcc632dd2097 preliminary version
nick
parents:
diff changeset
310 }
4070
b61ba6c256dd Minor interface changes: color and video keys are moved out from playback configuring
nick
parents: 4011
diff changeset
311
b61ba6c256dd Minor interface changes: color and video keys are moved out from playback configuring
nick
parents: 4011
diff changeset
312 int vdlGetGrKeys(VDL_HANDLE handle, vidix_grkey_t * k)
b61ba6c256dd Minor interface changes: color and video keys are moved out from playback configuring
nick
parents: 4011
diff changeset
313 {
b61ba6c256dd Minor interface changes: color and video keys are moved out from playback configuring
nick
parents: 4011
diff changeset
314 return t_vdl(handle)->get_gkey ? t_vdl(handle)->get_gkey(k) : ENOSYS;
b61ba6c256dd Minor interface changes: color and video keys are moved out from playback configuring
nick
parents: 4011
diff changeset
315 }
b61ba6c256dd Minor interface changes: color and video keys are moved out from playback configuring
nick
parents: 4011
diff changeset
316
b61ba6c256dd Minor interface changes: color and video keys are moved out from playback configuring
nick
parents: 4011
diff changeset
317 int vdlSetGrKeys(VDL_HANDLE handle, const vidix_grkey_t * k)
b61ba6c256dd Minor interface changes: color and video keys are moved out from playback configuring
nick
parents: 4011
diff changeset
318 {
b61ba6c256dd Minor interface changes: color and video keys are moved out from playback configuring
nick
parents: 4011
diff changeset
319 return t_vdl(handle)->set_gkey ? t_vdl(handle)->set_gkey(k) : ENOSYS;
b61ba6c256dd Minor interface changes: color and video keys are moved out from playback configuring
nick
parents: 4011
diff changeset
320 }
4191
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
321
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
322 int vdlPlaybackGetDeint(VDL_HANDLE handle, vidix_deinterlace_t * d)
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
323 {
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
324 return t_vdl(handle)->get_deint ? t_vdl(handle)->get_deint(d) : ENOSYS;
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
325 }
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
326
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
327 int vdlPlaybackSetDeint(VDL_HANDLE handle, const vidix_deinterlace_t * d)
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
328 {
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
329 return t_vdl(handle)->set_deint ? t_vdl(handle)->set_deint(d) : ENOSYS;
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
330 }
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
331
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
332 int vdlQueryNumOemEffects(VDL_HANDLE handle, unsigned * number )
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
333 {
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
334 return t_vdl(handle)->get_num_fx ? t_vdl(handle)->get_num_fx(number) : ENOSYS;
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
335 }
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
336
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
337 int vdlGetOemEffect(VDL_HANDLE handle, vidix_oem_fx_t * f)
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
338 {
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
339 return t_vdl(handle)->get_fx ? t_vdl(handle)->get_fx(f) : ENOSYS;
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
340 }
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
341
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
342 int vdlSetOemEffect(VDL_HANDLE handle, const vidix_oem_fx_t * f)
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
343 {
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
344 return t_vdl(handle)->set_fx ? t_vdl(handle)->set_fx(f) : ENOSYS;
62a6135d090e + new features and possibility
nick
parents: 4070
diff changeset
345 }