Mercurial > mplayer.hg
annotate libvo/vo_caca.c @ 29313:7a6f47f74e9b
Kill warnings of possibly unused variables by using av_unused.
author | ramiro |
---|---|
date | Thu, 11 Jun 2009 17:10:54 +0000 |
parents | 0f1b5b68af32 |
children | 597a376752a7 |
rev | line source |
---|---|
12129 | 1 /* |
28446
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
2 * video output driver for libcaca |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
3 * |
12129 | 4 * by Pigeon <pigeon@pigeond.net> |
5 * | |
6 * Some functions/codes/ideas are from x11 and aalib vo | |
7 * | |
28446
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
8 * TODO: support draw_alpha? |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
9 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
10 * This file is part of MPlayer. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
11 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
12 * MPlayer is free software; you can redistribute it and/or modify |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
13 * it under the terms of the GNU General Public License as published by |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
14 * the Free Software Foundation; either version 2 of the License, or |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
15 * (at your option) any later version. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
16 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
17 * MPlayer is distributed in the hope that it will be useful, |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
20 * GNU General Public License for more details. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
21 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
22 * You should have received a copy of the GNU General Public License along |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
23 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25220
diff
changeset
|
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
12129 | 25 */ |
26 | |
27 #include <stdio.h> | |
28 #include <stdlib.h> | |
29 #include <sys/stat.h> | |
30 #include <unistd.h> | |
31 #include <string.h> | |
32 #include <time.h> | |
33 #include <errno.h> | |
34 | |
35 #include "config.h" | |
36 #include "video_out.h" | |
37 #include "video_out_internal.h" | |
38 #include "sub.h" | |
39 | |
40 #include "osdep/keycodes.h" | |
41 #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
|
42 #include "mp_fifo.h" |
12129 | 43 |
44 #include <caca.h> | |
19979
0dc175cbeed8
vo_caca: use the pre-1.x compatibility layer so recent
corey
parents:
19053
diff
changeset
|
45 #ifdef CACA_API_VERSION_1 |
0dc175cbeed8
vo_caca: use the pre-1.x compatibility layer so recent
corey
parents:
19053
diff
changeset
|
46 /* Include the pre-1.x compatibility header. |
0dc175cbeed8
vo_caca: use the pre-1.x compatibility layer so recent
corey
parents:
19053
diff
changeset
|
47 * 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
|
48 * 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
|
49 * 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
|
50 */ |
0dc175cbeed8
vo_caca: use the pre-1.x compatibility layer so recent
corey
parents:
19053
diff
changeset
|
51 #include <caca0.h> |
0dc175cbeed8
vo_caca: use the pre-1.x compatibility layer so recent
corey
parents:
19053
diff
changeset
|
52 #endif |
12129 | 53 |
25216 | 54 static const vo_info_t info = { |
12129 | 55 "libcaca", |
56 "caca", | |
57 "Pigeon <pigeon@pigeond.net>", | |
58 "" | |
59 }; | |
60 | |
25220
c9e9ac2008c2
Mark the vo_functions_t definitions as const where possible.
reimar
parents:
25216
diff
changeset
|
61 const LIBVO_EXTERN (caca) |
12129 | 62 |
63 /* caca stuff */ | |
64 static struct caca_bitmap *cbitmap = NULL; | |
65 | |
66 /* image infos */ | |
67 static int image_format; | |
68 static int image_width; | |
69 static int image_height; | |
70 | |
71 static int screen_w, screen_h; | |
72 | |
73 /* We want 24bpp always for now */ | |
74 static unsigned int bpp = 24; | |
75 static unsigned int depth = 3; | |
76 static unsigned int rmask = 0xff0000; | |
77 static unsigned int gmask = 0x00ff00; | |
78 static unsigned int bmask = 0x0000ff; | |
79 static unsigned int amask = 0; | |
80 | |
81 #define MESSAGE_SIZE 512 | |
82 #define MESSAGE_DURATION 5 | |
83 | |
84 static time_t stoposd = 0; | |
85 static int showosdmessage = 0; | |
86 static char osdmessagetext[MESSAGE_SIZE]; | |
87 static char posbar[MESSAGE_SIZE]; | |
88 | |
89 static int osdx = 0, osdy = 0; | |
90 static int posbary = 2; | |
91 | |
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
|
92 static void osdmessage(int duration, const char *fmt, ...) |
12129 | 93 { |
94 /* | |
95 * for outputting a centered string at the bottom | |
96 * of our window for a while | |
97 */ | |
98 va_list ar; | |
99 char m[MESSAGE_SIZE]; | |
100 | |
101 va_start(ar, fmt); | |
102 vsprintf(m, fmt, ar); | |
103 va_end(ar); | |
104 strcpy(osdmessagetext, m); | |
105 | |
106 showosdmessage = 1; | |
107 stoposd = time(NULL) + duration; | |
108 osdx = (screen_w - strlen (osdmessagetext)) / 2; | |
109 posbar[0] = '\0'; | |
110 } | |
111 | |
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
|
112 static void osdpercent(int duration, int min, int max, int val, const char *desc, const char *unit) |
12129 | 113 { |
114 /* | |
115 * prints a bar for setting values | |
116 */ | |
117 float step; | |
118 int where, i; | |
119 | |
120 step = (float)screen_w / (float)(max - min); | |
121 where = (val - min) * step; | |
122 osdmessage (duration, "%s: %i%s", desc, val, unit); | |
123 posbar[0] = '|'; | |
124 posbar[screen_w - 1] = '|'; | |
125 | |
126 for (i = 0; i < screen_w; i++) | |
127 { | |
128 if (i == where) | |
129 posbar[i] = '#'; | |
130 else | |
131 posbar[i] = '-'; | |
132 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29212
diff
changeset
|
133 |
12129 | 134 if (where != 0) |
135 posbar[0] = '|'; | |
136 | |
137 if (where != (screen_w - 1)) | |
138 posbar[screen_w - 1] = '|'; | |
139 | |
140 posbar[screen_w] = '\0'; | |
141 } | |
142 | |
29212
eda346733b8c
Add missing 'void' to parameterless function declarations.
diego
parents:
28446
diff
changeset
|
143 static int resize(void) |
12129 | 144 { |
145 screen_w = caca_get_width(); | |
146 screen_h = caca_get_height(); | |
147 | |
148 if (cbitmap) | |
149 caca_free_bitmap(cbitmap); | |
150 | |
151 cbitmap = caca_create_bitmap(bpp, image_width, image_height, | |
152 depth * image_width, rmask, gmask, bmask, | |
153 amask); | |
154 | |
155 if (!cbitmap) | |
156 mp_msg(MSGT_VO, MSGL_FATAL, "vo_caca: caca_create_bitmap failed!\n"); | |
157 | |
158 return 0; | |
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 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
|
162 uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
12129 | 163 { |
164 image_height = height; | |
165 image_width = width; | |
166 image_format = format; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29212
diff
changeset
|
167 |
12129 | 168 showosdmessage = 0; |
169 posbar[0] = '\0'; | |
170 | |
171 return resize (); | |
172 } | |
173 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
174 static int draw_frame(uint8_t *src[]) |
12129 | 175 { |
176 caca_draw_bitmap(0, 0, screen_w, screen_h, cbitmap, src[0]); | |
177 return 0; | |
178 } | |
179 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
180 static int draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y) |
12129 | 181 { |
182 return 0; | |
183 } | |
184 | |
185 static void flip_page(void) | |
186 { | |
187 | |
188 if (showosdmessage) | |
189 { | |
190 if (time(NULL) >= stoposd) | |
191 { | |
192 showosdmessage = 0; | |
24032 | 193 if (*posbar) |
12129 | 194 posbar[0] = '\0'; |
195 } else { | |
196 caca_putstr(osdx, osdy, osdmessagetext); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29212
diff
changeset
|
197 |
24032 | 198 if (*posbar) |
12129 | 199 caca_putstr(0, posbary, posbar); |
200 } | |
201 } | |
202 | |
203 caca_refresh(); | |
204 } | |
205 | |
206 static void check_events (void) | |
207 { | |
208 unsigned int cev; | |
209 | |
210 if ((cev = caca_get_event(CACA_EVENT_ANY))) | |
211 { | |
212 if (cev & CACA_EVENT_RESIZE) | |
213 { | |
214 caca_refresh(); | |
215 resize(); | |
216 } else if (cev & CACA_EVENT_KEY_RELEASE) | |
217 { | |
218 int key = (cev & 0x00ffffff); | |
219 enum caca_feature cf; | |
220 | |
221 switch (key) { | |
222 case 'd': | |
223 case 'D': | |
224 /* Toggle dithering method */ | |
225 cf = 1 + caca_get_feature(CACA_DITHERING); | |
226 if (cf > CACA_DITHERING_MAX) | |
227 cf = CACA_DITHERING_MIN; | |
228 caca_set_feature(cf); | |
229 osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf)); | |
230 break; | |
231 | |
232 case 'a': | |
233 case 'A': | |
234 /* Toggle antialiasing method */ | |
235 cf = 1 + caca_get_feature(CACA_ANTIALIASING); | |
236 if (cf > CACA_ANTIALIASING_MAX) | |
237 cf = CACA_ANTIALIASING_MIN; | |
238 caca_set_feature(cf); | |
239 osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf)); | |
240 break; | |
241 | |
242 case 'b': | |
243 case 'B': | |
244 /* Toggle background method */ | |
245 cf = 1 + caca_get_feature(CACA_BACKGROUND); | |
246 if (cf > CACA_BACKGROUND_MAX) | |
247 cf = CACA_BACKGROUND_MIN; | |
248 caca_set_feature(cf); | |
249 osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf)); | |
250 break; | |
251 | |
252 case CACA_KEY_UP: | |
253 mplayer_put_key(KEY_UP); | |
254 break; | |
255 case CACA_KEY_DOWN: | |
256 mplayer_put_key(KEY_DOWN); | |
257 break; | |
258 case CACA_KEY_LEFT: | |
259 mplayer_put_key(KEY_LEFT); | |
260 break; | |
261 case CACA_KEY_RIGHT: | |
262 mplayer_put_key(KEY_RIGHT); | |
263 break; | |
264 case CACA_KEY_ESCAPE: | |
265 mplayer_put_key(KEY_ESC); | |
266 break; | |
267 case CACA_KEY_PAGEUP: | |
268 mplayer_put_key(KEY_PAGE_UP); | |
269 break; | |
270 case CACA_KEY_PAGEDOWN: | |
271 mplayer_put_key(KEY_PAGE_DOWN); | |
272 break; | |
273 case CACA_KEY_RETURN: | |
274 mplayer_put_key(KEY_ENTER); | |
275 break; | |
276 case CACA_KEY_HOME: | |
277 mplayer_put_key(KEY_HOME); | |
278 break; | |
279 case CACA_KEY_END: | |
280 mplayer_put_key(KEY_END); | |
281 break; | |
282 default: | |
283 if (key <= 255) | |
284 mplayer_put_key (key); | |
285 break; | |
286 } | |
287 } | |
288 } | |
289 } | |
290 | |
291 static void uninit(void) | |
292 { | |
293 caca_free_bitmap(cbitmap); | |
294 cbitmap = NULL; | |
295 caca_end(); | |
296 } | |
297 | |
298 | |
299 static void draw_osd(void) | |
300 { | |
301 if (vo_osd_progbar_type != -1) | |
302 osdpercent(MESSAGE_DURATION, 0, 255, | |
24046 | 303 vo_osd_progbar_value, sub_osd_names[vo_osd_progbar_type], |
12129 | 304 ""); |
305 } | |
306 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
307 static int preinit(const char *arg) |
12129 | 308 { |
309 if (arg) | |
310 { | |
311 mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: Unknown subdevice: %s\n", arg); | |
312 return ENOSYS; | |
313 } | |
314 | |
315 if (caca_init()) | |
316 { | |
317 mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: failed to initialize\n"); | |
318 return ENOSYS; | |
319 } | |
320 | |
321 caca_set_window_title("MPlayer"); | |
322 | |
323 /* Default libcaca features */ | |
324 caca_set_feature(CACA_ANTIALIASING_PREFILTER); | |
325 caca_set_feature(CACA_DITHERING_RANDOM); | |
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 query_format(uint32_t format) |
12129 | 331 { |
332 if (format == IMGFMT_BGR24) | |
21161 | 333 return VFCAP_OSD | VFCAP_CSP_SUPPORTED; |
12129 | 334 |
335 return 0; | |
336 } | |
337 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
338 static int control(uint32_t request, void *data, ...) |
12129 | 339 { |
340 switch(request) | |
341 { | |
342 case VOCTRL_QUERY_FORMAT: | |
343 return query_format(*((uint32_t *)data)); | |
344 default: | |
345 return VO_NOTIMPL; | |
346 } | |
347 } |