Mercurial > mplayer.hg
annotate libvo/vo_caca.c @ 20024:996cb6bc8e4f
r20028: faacopts :object is in the range 1..4, not 0..3
author | kraymer |
---|---|
date | Wed, 04 Oct 2006 09:10:44 +0000 |
parents | 0dc175cbeed8 |
children | ad7747bce52d |
rev | line source |
---|---|
12129 | 1 /* |
2 * MPlayer | |
3 * | |
4 * Video driver for libcaca | |
5 * | |
6 * by Pigeon <pigeon@pigeond.net> | |
7 * | |
8 * Some functions/codes/ideas are from x11 and aalib vo | |
9 * | |
10 * TODO: support those draw_alpha stuff? | |
11 * | |
12 */ | |
13 | |
14 #include <stdio.h> | |
15 #include <stdlib.h> | |
16 #include <sys/stat.h> | |
17 #include <unistd.h> | |
18 #include <string.h> | |
19 #include <time.h> | |
20 #include <errno.h> | |
21 | |
22 #include "config.h" | |
23 #include "video_out.h" | |
24 #include "video_out_internal.h" | |
25 #include "sub.h" | |
26 | |
27 #include "osdep/keycodes.h" | |
28 #include "mp_msg.h" | |
29 | |
30 #include <caca.h> | |
19979
0dc175cbeed8
vo_caca: use the pre-1.x compatibility layer so recent
corey
parents:
19053
diff
changeset
|
31 #ifdef CACA_API_VERSION_1 |
0dc175cbeed8
vo_caca: use the pre-1.x compatibility layer so recent
corey
parents:
19053
diff
changeset
|
32 /* Include the pre-1.x compatibility header. |
0dc175cbeed8
vo_caca: use the pre-1.x compatibility layer so recent
corey
parents:
19053
diff
changeset
|
33 * Once libcaca 1.x is widespread, vo_caca should be fully |
0dc175cbeed8
vo_caca: use the pre-1.x compatibility layer so recent
corey
parents:
19053
diff
changeset
|
34 * converted to the new API. A patch exists: |
0dc175cbeed8
vo_caca: use the pre-1.x compatibility layer so recent
corey
parents:
19053
diff
changeset
|
35 * http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2006-July/044674.html |
0dc175cbeed8
vo_caca: use the pre-1.x compatibility layer so recent
corey
parents:
19053
diff
changeset
|
36 */ |
0dc175cbeed8
vo_caca: use the pre-1.x compatibility layer so recent
corey
parents:
19053
diff
changeset
|
37 #include <caca0.h> |
0dc175cbeed8
vo_caca: use the pre-1.x compatibility layer so recent
corey
parents:
19053
diff
changeset
|
38 #endif |
12129 | 39 |
40 static vo_info_t info = { | |
41 "libcaca", | |
42 "caca", | |
43 "Pigeon <pigeon@pigeond.net>", | |
44 "" | |
45 }; | |
46 | |
47 LIBVO_EXTERN (caca) | |
48 | |
49 /* caca stuff */ | |
50 static struct caca_bitmap *cbitmap = NULL; | |
51 | |
52 /* image infos */ | |
53 static int image_format; | |
54 static int image_width; | |
55 static int image_height; | |
56 | |
57 static int screen_w, screen_h; | |
58 | |
59 /* We want 24bpp always for now */ | |
60 static unsigned int bpp = 24; | |
61 static unsigned int depth = 3; | |
62 static unsigned int rmask = 0xff0000; | |
63 static unsigned int gmask = 0x00ff00; | |
64 static unsigned int bmask = 0x0000ff; | |
65 static unsigned int amask = 0; | |
66 | |
67 #define MESSAGE_SIZE 512 | |
68 #define MESSAGE_DURATION 5 | |
69 | |
70 static time_t stoposd = 0; | |
71 static int showosdmessage = 0; | |
72 static char osdmessagetext[MESSAGE_SIZE]; | |
73 static char posbar[MESSAGE_SIZE]; | |
74 | |
75 static int osdx = 0, osdy = 0; | |
76 static int posbary = 2; | |
77 | |
19053
75327b24e06f
marks several string parameters as const, as they are not modified inside the function, Patch by Stefan Huehner, stefan AT huehner-org
reynaldo
parents:
16171
diff
changeset
|
78 static void osdmessage(int duration, const char *fmt, ...) |
12129 | 79 { |
80 /* | |
81 * for outputting a centered string at the bottom | |
82 * of our window for a while | |
83 */ | |
84 va_list ar; | |
85 char m[MESSAGE_SIZE]; | |
86 | |
87 va_start(ar, fmt); | |
88 vsprintf(m, fmt, ar); | |
89 va_end(ar); | |
90 strcpy(osdmessagetext, m); | |
91 | |
92 showosdmessage = 1; | |
93 stoposd = time(NULL) + duration; | |
94 osdx = (screen_w - strlen (osdmessagetext)) / 2; | |
95 posbar[0] = '\0'; | |
96 } | |
97 | |
19053
75327b24e06f
marks several string parameters as const, as they are not modified inside the function, Patch by Stefan Huehner, stefan AT huehner-org
reynaldo
parents:
16171
diff
changeset
|
98 static void osdpercent(int duration, int min, int max, int val, const char *desc, const char *unit) |
12129 | 99 { |
100 /* | |
101 * prints a bar for setting values | |
102 */ | |
103 float step; | |
104 int where, i; | |
105 | |
106 step = (float)screen_w / (float)(max - min); | |
107 where = (val - min) * step; | |
108 osdmessage (duration, "%s: %i%s", desc, val, unit); | |
109 posbar[0] = '|'; | |
110 posbar[screen_w - 1] = '|'; | |
111 | |
112 for (i = 0; i < screen_w; i++) | |
113 { | |
114 if (i == where) | |
115 posbar[i] = '#'; | |
116 else | |
117 posbar[i] = '-'; | |
118 } | |
119 | |
120 if (where != 0) | |
121 posbar[0] = '|'; | |
122 | |
123 if (where != (screen_w - 1)) | |
124 posbar[screen_w - 1] = '|'; | |
125 | |
126 posbar[screen_w] = '\0'; | |
127 } | |
128 | |
129 static int resize () | |
130 { | |
131 screen_w = caca_get_width(); | |
132 screen_h = caca_get_height(); | |
133 | |
134 if (cbitmap) | |
135 caca_free_bitmap(cbitmap); | |
136 | |
137 cbitmap = caca_create_bitmap(bpp, image_width, image_height, | |
138 depth * image_width, rmask, gmask, bmask, | |
139 amask); | |
140 | |
141 if (!cbitmap) | |
142 mp_msg(MSGT_VO, MSGL_FATAL, "vo_caca: caca_create_bitmap failed!\n"); | |
143 | |
144 return 0; | |
145 } | |
146 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
147 static int config(uint32_t width, uint32_t height, uint32_t d_width, |
15212
05aa13cdf92f
replace VO and VF numeric flags with #defined identifiers
henry
parents:
12129
diff
changeset
|
148 uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
12129 | 149 { |
150 image_height = height; | |
151 image_width = width; | |
152 image_format = format; | |
153 | |
154 showosdmessage = 0; | |
155 posbar[0] = '\0'; | |
156 | |
157 return resize (); | |
158 } | |
159 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
160 static int draw_frame(uint8_t *src[]) |
12129 | 161 { |
162 caca_draw_bitmap(0, 0, screen_w, screen_h, cbitmap, src[0]); | |
163 return 0; | |
164 } | |
165 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
166 static int draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y) |
12129 | 167 { |
168 return 0; | |
169 } | |
170 | |
171 static void flip_page(void) | |
172 { | |
173 | |
174 if (showosdmessage) | |
175 { | |
176 if (time(NULL) >= stoposd) | |
177 { | |
178 showosdmessage = 0; | |
179 if (posbar) | |
180 posbar[0] = '\0'; | |
181 } else { | |
182 caca_putstr(osdx, osdy, osdmessagetext); | |
183 | |
184 if (posbar) | |
185 caca_putstr(0, posbary, posbar); | |
186 } | |
187 } | |
188 | |
189 caca_refresh(); | |
190 } | |
191 | |
192 static void check_events (void) | |
193 { | |
194 unsigned int cev; | |
195 | |
196 if ((cev = caca_get_event(CACA_EVENT_ANY))) | |
197 { | |
198 if (cev & CACA_EVENT_RESIZE) | |
199 { | |
200 caca_refresh(); | |
201 resize(); | |
202 } else if (cev & CACA_EVENT_KEY_RELEASE) | |
203 { | |
204 int key = (cev & 0x00ffffff); | |
205 enum caca_feature cf; | |
206 | |
207 switch (key) { | |
208 case 'd': | |
209 case 'D': | |
210 /* Toggle dithering method */ | |
211 cf = 1 + caca_get_feature(CACA_DITHERING); | |
212 if (cf > CACA_DITHERING_MAX) | |
213 cf = CACA_DITHERING_MIN; | |
214 caca_set_feature(cf); | |
215 osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf)); | |
216 break; | |
217 | |
218 case 'a': | |
219 case 'A': | |
220 /* Toggle antialiasing method */ | |
221 cf = 1 + caca_get_feature(CACA_ANTIALIASING); | |
222 if (cf > CACA_ANTIALIASING_MAX) | |
223 cf = CACA_ANTIALIASING_MIN; | |
224 caca_set_feature(cf); | |
225 osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf)); | |
226 break; | |
227 | |
228 case 'b': | |
229 case 'B': | |
230 /* Toggle background method */ | |
231 cf = 1 + caca_get_feature(CACA_BACKGROUND); | |
232 if (cf > CACA_BACKGROUND_MAX) | |
233 cf = CACA_BACKGROUND_MIN; | |
234 caca_set_feature(cf); | |
235 osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf)); | |
236 break; | |
237 | |
238 case CACA_KEY_UP: | |
239 mplayer_put_key(KEY_UP); | |
240 break; | |
241 case CACA_KEY_DOWN: | |
242 mplayer_put_key(KEY_DOWN); | |
243 break; | |
244 case CACA_KEY_LEFT: | |
245 mplayer_put_key(KEY_LEFT); | |
246 break; | |
247 case CACA_KEY_RIGHT: | |
248 mplayer_put_key(KEY_RIGHT); | |
249 break; | |
250 case CACA_KEY_ESCAPE: | |
251 mplayer_put_key(KEY_ESC); | |
252 break; | |
253 case CACA_KEY_PAGEUP: | |
254 mplayer_put_key(KEY_PAGE_UP); | |
255 break; | |
256 case CACA_KEY_PAGEDOWN: | |
257 mplayer_put_key(KEY_PAGE_DOWN); | |
258 break; | |
259 case CACA_KEY_RETURN: | |
260 mplayer_put_key(KEY_ENTER); | |
261 break; | |
262 case CACA_KEY_HOME: | |
263 mplayer_put_key(KEY_HOME); | |
264 break; | |
265 case CACA_KEY_END: | |
266 mplayer_put_key(KEY_END); | |
267 break; | |
268 default: | |
269 if (key <= 255) | |
270 mplayer_put_key (key); | |
271 break; | |
272 } | |
273 } | |
274 } | |
275 } | |
276 | |
277 static void uninit(void) | |
278 { | |
279 caca_free_bitmap(cbitmap); | |
280 cbitmap = NULL; | |
281 caca_end(); | |
282 } | |
283 | |
284 | |
285 static void draw_osd(void) | |
286 { | |
287 #ifdef USE_OSD | |
288 if (vo_osd_progbar_type != -1) | |
289 osdpercent(MESSAGE_DURATION, 0, 255, | |
290 vo_osd_progbar_value, __sub_osd_names[vo_osd_progbar_type], | |
291 ""); | |
292 #endif | |
293 } | |
294 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
295 static int preinit(const char *arg) |
12129 | 296 { |
297 if (arg) | |
298 { | |
299 mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: Unknown subdevice: %s\n", arg); | |
300 return ENOSYS; | |
301 } | |
302 | |
303 if (caca_init()) | |
304 { | |
305 mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: failed to initialize\n"); | |
306 return ENOSYS; | |
307 } | |
308 | |
309 caca_set_window_title("MPlayer"); | |
310 | |
311 /* Default libcaca features */ | |
312 caca_set_feature(CACA_ANTIALIASING_PREFILTER); | |
313 caca_set_feature(CACA_DITHERING_RANDOM); | |
314 | |
315 return 0; | |
316 } | |
317 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
318 static int query_format(uint32_t format) |
12129 | 319 { |
320 if (format == IMGFMT_BGR24) | |
321 return | |
322 #ifdef USE_OSD | |
323 VFCAP_OSD | | |
324 #endif | |
325 VFCAP_CSP_SUPPORTED; | |
326 | |
327 return 0; | |
328 } | |
329 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
330 static int control(uint32_t request, void *data, ...) |
12129 | 331 { |
332 switch(request) | |
333 { | |
334 case VOCTRL_QUERY_FORMAT: | |
335 return query_format(*((uint32_t *)data)); | |
336 default: | |
337 return VO_NOTIMPL; | |
338 } | |
339 } |