Mercurial > mplayer.hg
annotate libvo/vo_caca.c @ 19744:4bba4d2be05a
rename formats.xml into containers.xml
author | gpoirier |
---|---|
date | Fri, 08 Sep 2006 08:39:07 +0000 |
parents | 75327b24e06f |
children | 0dc175cbeed8 |
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> | |
31 | |
32 static vo_info_t info = { | |
33 "libcaca", | |
34 "caca", | |
35 "Pigeon <pigeon@pigeond.net>", | |
36 "" | |
37 }; | |
38 | |
39 LIBVO_EXTERN (caca) | |
40 | |
41 /* caca stuff */ | |
42 static struct caca_bitmap *cbitmap = NULL; | |
43 | |
44 /* image infos */ | |
45 static int image_format; | |
46 static int image_width; | |
47 static int image_height; | |
48 | |
49 static int screen_w, screen_h; | |
50 | |
51 /* We want 24bpp always for now */ | |
52 static unsigned int bpp = 24; | |
53 static unsigned int depth = 3; | |
54 static unsigned int rmask = 0xff0000; | |
55 static unsigned int gmask = 0x00ff00; | |
56 static unsigned int bmask = 0x0000ff; | |
57 static unsigned int amask = 0; | |
58 | |
59 #define MESSAGE_SIZE 512 | |
60 #define MESSAGE_DURATION 5 | |
61 | |
62 static time_t stoposd = 0; | |
63 static int showosdmessage = 0; | |
64 static char osdmessagetext[MESSAGE_SIZE]; | |
65 static char posbar[MESSAGE_SIZE]; | |
66 | |
67 static int osdx = 0, osdy = 0; | |
68 static int posbary = 2; | |
69 | |
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
|
70 static void osdmessage(int duration, const char *fmt, ...) |
12129 | 71 { |
72 /* | |
73 * for outputting a centered string at the bottom | |
74 * of our window for a while | |
75 */ | |
76 va_list ar; | |
77 char m[MESSAGE_SIZE]; | |
78 | |
79 va_start(ar, fmt); | |
80 vsprintf(m, fmt, ar); | |
81 va_end(ar); | |
82 strcpy(osdmessagetext, m); | |
83 | |
84 showosdmessage = 1; | |
85 stoposd = time(NULL) + duration; | |
86 osdx = (screen_w - strlen (osdmessagetext)) / 2; | |
87 posbar[0] = '\0'; | |
88 } | |
89 | |
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
|
90 static void osdpercent(int duration, int min, int max, int val, const char *desc, const char *unit) |
12129 | 91 { |
92 /* | |
93 * prints a bar for setting values | |
94 */ | |
95 float step; | |
96 int where, i; | |
97 | |
98 step = (float)screen_w / (float)(max - min); | |
99 where = (val - min) * step; | |
100 osdmessage (duration, "%s: %i%s", desc, val, unit); | |
101 posbar[0] = '|'; | |
102 posbar[screen_w - 1] = '|'; | |
103 | |
104 for (i = 0; i < screen_w; i++) | |
105 { | |
106 if (i == where) | |
107 posbar[i] = '#'; | |
108 else | |
109 posbar[i] = '-'; | |
110 } | |
111 | |
112 if (where != 0) | |
113 posbar[0] = '|'; | |
114 | |
115 if (where != (screen_w - 1)) | |
116 posbar[screen_w - 1] = '|'; | |
117 | |
118 posbar[screen_w] = '\0'; | |
119 } | |
120 | |
121 static int resize () | |
122 { | |
123 screen_w = caca_get_width(); | |
124 screen_h = caca_get_height(); | |
125 | |
126 if (cbitmap) | |
127 caca_free_bitmap(cbitmap); | |
128 | |
129 cbitmap = caca_create_bitmap(bpp, image_width, image_height, | |
130 depth * image_width, rmask, gmask, bmask, | |
131 amask); | |
132 | |
133 if (!cbitmap) | |
134 mp_msg(MSGT_VO, MSGL_FATAL, "vo_caca: caca_create_bitmap failed!\n"); | |
135 | |
136 return 0; | |
137 } | |
138 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
139 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
|
140 uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
12129 | 141 { |
142 image_height = height; | |
143 image_width = width; | |
144 image_format = format; | |
145 | |
146 showosdmessage = 0; | |
147 posbar[0] = '\0'; | |
148 | |
149 return resize (); | |
150 } | |
151 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
152 static int draw_frame(uint8_t *src[]) |
12129 | 153 { |
154 caca_draw_bitmap(0, 0, screen_w, screen_h, cbitmap, src[0]); | |
155 return 0; | |
156 } | |
157 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
158 static int draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y) |
12129 | 159 { |
160 return 0; | |
161 } | |
162 | |
163 static void flip_page(void) | |
164 { | |
165 | |
166 if (showosdmessage) | |
167 { | |
168 if (time(NULL) >= stoposd) | |
169 { | |
170 showosdmessage = 0; | |
171 if (posbar) | |
172 posbar[0] = '\0'; | |
173 } else { | |
174 caca_putstr(osdx, osdy, osdmessagetext); | |
175 | |
176 if (posbar) | |
177 caca_putstr(0, posbary, posbar); | |
178 } | |
179 } | |
180 | |
181 caca_refresh(); | |
182 } | |
183 | |
184 static void check_events (void) | |
185 { | |
186 unsigned int cev; | |
187 | |
188 if ((cev = caca_get_event(CACA_EVENT_ANY))) | |
189 { | |
190 if (cev & CACA_EVENT_RESIZE) | |
191 { | |
192 caca_refresh(); | |
193 resize(); | |
194 } else if (cev & CACA_EVENT_KEY_RELEASE) | |
195 { | |
196 int key = (cev & 0x00ffffff); | |
197 enum caca_feature cf; | |
198 | |
199 switch (key) { | |
200 case 'd': | |
201 case 'D': | |
202 /* Toggle dithering method */ | |
203 cf = 1 + caca_get_feature(CACA_DITHERING); | |
204 if (cf > CACA_DITHERING_MAX) | |
205 cf = CACA_DITHERING_MIN; | |
206 caca_set_feature(cf); | |
207 osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf)); | |
208 break; | |
209 | |
210 case 'a': | |
211 case 'A': | |
212 /* Toggle antialiasing method */ | |
213 cf = 1 + caca_get_feature(CACA_ANTIALIASING); | |
214 if (cf > CACA_ANTIALIASING_MAX) | |
215 cf = CACA_ANTIALIASING_MIN; | |
216 caca_set_feature(cf); | |
217 osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf)); | |
218 break; | |
219 | |
220 case 'b': | |
221 case 'B': | |
222 /* Toggle background method */ | |
223 cf = 1 + caca_get_feature(CACA_BACKGROUND); | |
224 if (cf > CACA_BACKGROUND_MAX) | |
225 cf = CACA_BACKGROUND_MIN; | |
226 caca_set_feature(cf); | |
227 osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf)); | |
228 break; | |
229 | |
230 case CACA_KEY_UP: | |
231 mplayer_put_key(KEY_UP); | |
232 break; | |
233 case CACA_KEY_DOWN: | |
234 mplayer_put_key(KEY_DOWN); | |
235 break; | |
236 case CACA_KEY_LEFT: | |
237 mplayer_put_key(KEY_LEFT); | |
238 break; | |
239 case CACA_KEY_RIGHT: | |
240 mplayer_put_key(KEY_RIGHT); | |
241 break; | |
242 case CACA_KEY_ESCAPE: | |
243 mplayer_put_key(KEY_ESC); | |
244 break; | |
245 case CACA_KEY_PAGEUP: | |
246 mplayer_put_key(KEY_PAGE_UP); | |
247 break; | |
248 case CACA_KEY_PAGEDOWN: | |
249 mplayer_put_key(KEY_PAGE_DOWN); | |
250 break; | |
251 case CACA_KEY_RETURN: | |
252 mplayer_put_key(KEY_ENTER); | |
253 break; | |
254 case CACA_KEY_HOME: | |
255 mplayer_put_key(KEY_HOME); | |
256 break; | |
257 case CACA_KEY_END: | |
258 mplayer_put_key(KEY_END); | |
259 break; | |
260 default: | |
261 if (key <= 255) | |
262 mplayer_put_key (key); | |
263 break; | |
264 } | |
265 } | |
266 } | |
267 } | |
268 | |
269 static void uninit(void) | |
270 { | |
271 caca_free_bitmap(cbitmap); | |
272 cbitmap = NULL; | |
273 caca_end(); | |
274 } | |
275 | |
276 | |
277 static void draw_osd(void) | |
278 { | |
279 #ifdef USE_OSD | |
280 if (vo_osd_progbar_type != -1) | |
281 osdpercent(MESSAGE_DURATION, 0, 255, | |
282 vo_osd_progbar_value, __sub_osd_names[vo_osd_progbar_type], | |
283 ""); | |
284 #endif | |
285 } | |
286 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
287 static int preinit(const char *arg) |
12129 | 288 { |
289 if (arg) | |
290 { | |
291 mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: Unknown subdevice: %s\n", arg); | |
292 return ENOSYS; | |
293 } | |
294 | |
295 if (caca_init()) | |
296 { | |
297 mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: failed to initialize\n"); | |
298 return ENOSYS; | |
299 } | |
300 | |
301 caca_set_window_title("MPlayer"); | |
302 | |
303 /* Default libcaca features */ | |
304 caca_set_feature(CACA_ANTIALIASING_PREFILTER); | |
305 caca_set_feature(CACA_DITHERING_RANDOM); | |
306 | |
307 return 0; | |
308 } | |
309 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
310 static int query_format(uint32_t format) |
12129 | 311 { |
312 if (format == IMGFMT_BGR24) | |
313 return | |
314 #ifdef USE_OSD | |
315 VFCAP_OSD | | |
316 #endif | |
317 VFCAP_CSP_SUPPORTED; | |
318 | |
319 return 0; | |
320 } | |
321 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
322 static int control(uint32_t request, void *data, ...) |
12129 | 323 { |
324 switch(request) | |
325 { | |
326 case VOCTRL_QUERY_FORMAT: | |
327 return query_format(*((uint32_t *)data)); | |
328 default: | |
329 return VO_NOTIMPL; | |
330 } | |
331 } |