3991
|
1 /*
|
|
2 * vidixlib.c
|
|
3 * VIDIXLib - Library for VIDeo Interface for *niX
|
|
4 * This interface is introduced as universal one to MPEG decoder,
|
|
5 * BES == Back End Scaler and YUV2RGB hw accelerators.
|
|
6 * In the future it may be expanded up to capturing and audio things.
|
|
7 * Main goal of this this interface imlpementation is providing DGA
|
|
8 * everywhere where it's possible (unlike X11 and other).
|
|
9 * Copyright 2002 Nick Kurshev
|
|
10 * Licence: GPL
|
|
11 * This interface is based on v4l2, fbvid.h, mga_vid.h projects
|
|
12 * and personally my ideas.
|
|
13 * NOTE: This interface is introduces as APP interface.
|
|
14 * Don't use it for driver.
|
|
15 * It provides multistreaming. This mean that APP can handle
|
|
16 * several streams simultaneously. (Example: Video capturing and video
|
|
17 * playback or capturing, video playback, audio encoding and so on).
|
|
18 */
|
|
19 #include <stdlib.h>
|
|
20 #include <stdio.h>
|
|
21 #include <errno.h>
|
|
22 #include <string.h>
|
|
23
|
|
24 #include <dlfcn.h> /* GLIBC specific. Exists under cygwin too! */
|
|
25 #include <dirent.h>
|
|
26
|
|
27 #include "vidixlib.h"
|
|
28
|
|
29
|
|
30 typedef struct vdl_stream_s
|
|
31 {
|
|
32 void * handle;
|
|
33 int (*get_caps)(vidix_capability_t *);
|
|
34 int (*query_fourcc)(vidix_fourcc_t *);
|
|
35 int (*config_playback)(const vidix_playback_t *);
|
|
36 int (*map_playback)(vidix_dga_t *);
|
|
37 int (*playback_on)( void );
|
|
38 int (*playback_off)( void );
|
|
39 /* Functions below can be missed in driver ;) */
|
|
40 int (*init)(void);
|
|
41 void (*destroy)(void);
|
|
42 int (*frame_sel)( unsigned frame_idx );
|
|
43 int (*get_eq)( vidix_video_eq_t * );
|
|
44 int (*set_eq)( const vidix_video_eq_t * );
|
|
45 int (*copy_frame)( const vidix_dma_t * );
|
|
46 }vdl_stream_t;
|
|
47
|
|
48 #define t_vdl(p) (((vdl_stream_t *)p))
|
|
49
|
|
50 extern unsigned vdlGetVersion( void )
|
|
51 {
|
|
52 return VIDIX_VERSION;
|
|
53 }
|
|
54
|
|
55 static int vdl_fill_driver(VDL_HANDLE stream)
|
|
56 {
|
|
57 t_vdl(stream)->init = dlsym(t_vdl(stream)->handle,"vixInit");
|
|
58 t_vdl(stream)->destroy = dlsym(t_vdl(stream)->handle,"vixDestroy");
|
|
59 t_vdl(stream)->get_caps = dlsym(t_vdl(stream)->handle,"vixGetCapability");
|
|
60 t_vdl(stream)->query_fourcc = dlsym(t_vdl(stream)->handle,"vixQueryFourcc");
|
|
61 t_vdl(stream)->config_playback= dlsym(t_vdl(stream)->handle,"vixConfigPlayback");
|
|
62 t_vdl(stream)->map_playback = dlsym(t_vdl(stream)->handle,"vixMapPlayback");
|
|
63 t_vdl(stream)->playback_on = dlsym(t_vdl(stream)->handle,"vixPlaybackOn");
|
|
64 t_vdl(stream)->playback_off = dlsym(t_vdl(stream)->handle,"vixPlaybackOff");
|
|
65 t_vdl(stream)->frame_sel = dlsym(t_vdl(stream)->handle,"vixPlaybackFrameSelect");
|
|
66 t_vdl(stream)->get_eq = dlsym(t_vdl(stream)->handle,"vixPlaybackGetEq");
|
|
67 t_vdl(stream)->set_eq = dlsym(t_vdl(stream)->handle,"vixPlaybackSetEq");
|
|
68 t_vdl(stream)->copy_frame = dlsym(t_vdl(stream)->handle,"vixPlaybackCopyFrame");
|
|
69 /* check driver viability */
|
|
70 if(!( t_vdl(stream)->get_caps && t_vdl(stream)->query_fourcc && t_vdl(stream)->config_playback &&
|
|
71 t_vdl(stream)->map_playback && t_vdl(stream)->playback_on && t_vdl(stream)->playback_off))
|
|
72 return 0;
|
|
73 return 1;
|
|
74 }
|
|
75
|
|
76 static int vdl_probe_driver(VDL_HANDLE stream,const char *path,const char *name,unsigned cap)
|
|
77 {
|
|
78 char drv_name[FILENAME_MAX];
|
|
79 vidix_capability_t vid_cap;
|
|
80 unsigned (*_ver)(void);
|
|
81 int (*_probe)(void);
|
|
82 int (*_cap)(vidix_capability_t*);
|
|
83 strcpy(drv_name,path);
|
|
84 strcat(drv_name,name);
|
|
85 if(!(t_vdl(stream)->handle = dlopen(drv_name,RTLD_NOW|RTLD_GLOBAL))) return 0;
|
|
86 _ver = dlsym(t_vdl(stream)->handle,"vixGetVersion");
|
|
87 _probe = dlsym(t_vdl(stream)->handle,"vixProbe");
|
|
88 _cap = dlsym(t_vdl(stream)->handle,"vixGetCapability");
|
|
89 if(_ver) { if((*_ver)() != VIDIX_VERSION) { err: dlclose(t_vdl(stream)->handle); t_vdl(stream)->handle = 0; return 0; } }
|
|
90 else goto err;
|
|
91 if(_probe) { if((*_probe)() != 0) goto err; }
|
|
92 else goto err;
|
|
93 if(_cap) { if((*_cap)(&vid_cap) != 0) goto err; }
|
|
94 else goto err;
|
|
95 if((vid_cap.type & cap) != cap) goto err;
|
|
96 return 1;
|
|
97 }
|
|
98
|
|
99 static int vdl_find_driver(VDL_HANDLE stream,const char *path,unsigned cap)
|
|
100 {
|
|
101 DIR *dstream;
|
|
102 struct dirent *name;
|
|
103 int done = 0;
|
|
104 if(!(dstream = opendir(path))) return 0;
|
|
105 while(!done)
|
|
106 {
|
|
107 name = readdir(dstream);
|
|
108 if(name) { if(vdl_probe_driver(stream,path,name->d_name,cap)) break; }
|
|
109 else done = 1;
|
|
110 }
|
|
111 closedir(dstream);
|
|
112 return done?0:1;
|
|
113 }
|
|
114
|
|
115 VDL_HANDLE vdlOpen(const char *path,const char *name,unsigned cap)
|
|
116 {
|
|
117 vdl_stream_t *stream;
|
|
118 char drv_name[FILENAME_MAX];
|
|
119 if(!(stream = malloc(sizeof(vdl_stream_t)))) return NULL;
|
|
120 memset(stream,0,sizeof(vdl_stream_t));
|
|
121 if(name)
|
|
122 {
|
|
123 unsigned (*ver)(void);
|
|
124 unsigned version = 0;
|
|
125 strcpy(drv_name,path);
|
|
126 strcat(drv_name,name);
|
|
127 if(!(t_vdl(stream)->handle = dlopen(drv_name,RTLD_NOW|RTLD_GLOBAL)))
|
|
128 {
|
|
129 err:
|
|
130 free(stream);
|
|
131 return NULL;
|
|
132 }
|
|
133 ver = dlsym(t_vdl(stream)->handle,"vixGetVersion");
|
|
134 if(ver) version = (*ver)();
|
|
135 if(version != VIDIX_VERSION)
|
|
136 {
|
|
137 drv_err:
|
|
138 if(t_vdl(stream)->handle) dlclose(t_vdl(stream)->handle);
|
|
139 goto err;
|
|
140 }
|
|
141 fill:
|
|
142 if(!vdl_fill_driver(stream)) goto drv_err;
|
|
143 }
|
|
144 else
|
|
145 if(vdl_find_driver(stream,path,cap)) goto fill;
|
|
146 else goto err;
|
|
147 if(t_vdl(stream)->init) t_vdl(stream)->init();
|
|
148 return stream;
|
|
149 }
|
|
150
|
|
151 void vdlClose(VDL_HANDLE stream)
|
|
152 {
|
|
153 if(t_vdl(stream)->destroy) t_vdl(stream)->destroy();
|
|
154 dlclose(t_vdl(stream)->handle);
|
|
155 memset(stream,0,sizeof(vdl_stream_t)); /* <- it's not stupid */
|
|
156 free(stream);
|
|
157 }
|
|
158
|
|
159 int vdlGetCapability(VDL_HANDLE handle, vidix_capability_t *cap)
|
|
160 {
|
|
161 return t_vdl(handle)->get_caps(cap);
|
|
162 }
|
|
163
|
|
164 int vdlQueryFourcc(VDL_HANDLE handle,vidix_fourcc_t *f)
|
|
165 {
|
|
166 return t_vdl(handle)->query_fourcc(f);
|
|
167 }
|
|
168
|
|
169 int vdlConfigPlayback(VDL_HANDLE handle,const vidix_playback_t *p)
|
|
170 {
|
|
171 return t_vdl(handle)->config_playback(p);
|
|
172 }
|
|
173
|
|
174 int vdlMapPlayback(VDL_HANDLE handle,vidix_dga_t *m)
|
|
175 {
|
|
176 return t_vdl(handle)->map_playback(m);
|
|
177 }
|
|
178
|
|
179 int vdlPlaybackOn(VDL_HANDLE handle)
|
|
180 {
|
|
181 return t_vdl(handle)->playback_on();
|
|
182 }
|
|
183
|
|
184 int vdlPlaybackOff(VDL_HANDLE handle)
|
|
185 {
|
|
186 return t_vdl(handle)->playback_off();
|
|
187 }
|
|
188
|
|
189 int vdlPlaybackFrameSelect(VDL_HANDLE handle, unsigned frame_idx )
|
|
190 {
|
|
191 return t_vdl(handle)->frame_sel ? t_vdl(handle)->frame_sel(frame_idx) : ENOSYS;
|
|
192 }
|
|
193
|
|
194 int vdlPlaybackGetEq(VDL_HANDLE handle, vidix_video_eq_t * e)
|
|
195 {
|
|
196 return t_vdl(handle)->get_eq ? t_vdl(handle)->get_eq(e) : ENOSYS;
|
|
197 }
|
|
198
|
|
199 int vdlPlaybackSetEq(VDL_HANDLE handle, const vidix_video_eq_t * e)
|
|
200 {
|
|
201 return t_vdl(handle)->set_eq ? t_vdl(handle)->set_eq(e) : ENOSYS;
|
|
202 }
|
|
203
|
|
204 int vdlPlaybackCopyFrame(VDL_HANDLE handle, const vidix_dma_t * f)
|
|
205 {
|
|
206 return t_vdl(handle)->copy_frame ? t_vdl(handle)->copy_frame(f) : ENOSYS;
|
|
207 }
|