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