1511
|
1 /*
|
|
2 * MPlayer
|
|
3 *
|
|
4 * Video driver for AAlib - alpha version
|
|
5 *
|
|
6 * by Folke Ashberg <folke@ashberg.de>
|
|
7 *
|
|
8 * Code started: Sun Aug 12 2001
|
|
9 *
|
|
10 */
|
|
11
|
|
12 #include <stdio.h>
|
|
13 #include <stdlib.h>
|
|
14
|
|
15
|
|
16 #include <limits.h>
|
|
17 #include <math.h>
|
|
18 #include <stdarg.h>
|
|
19 #include <time.h>
|
|
20 #include <string.h>
|
|
21
|
|
22 #include "config.h"
|
|
23 #include "video_out.h"
|
|
24 #include "video_out_internal.h"
|
|
25 #include "yuv2rgb.h"
|
|
26 #include "sub.h"
|
|
27
|
|
28 #include "linux/keycodes.h"
|
|
29 #include <aalib.h>
|
|
30
|
|
31 #define RGB 0
|
|
32 #define BGR 1
|
|
33
|
|
34 #define DO_INC(val,max,step) if (val + step <=max) val+=step; else val=max;
|
|
35 #define DO_DEC(val,min,step) if (val - step >=min) val-=step; else val=min;
|
|
36
|
|
37 #define MESSAGE_DURATION 3
|
|
38 #define MESSAGE_SIZE 512
|
|
39 #define MESSAGE_DEKO " +++ %s +++ "
|
|
40
|
|
41
|
|
42
|
|
43 LIBVO_EXTERN(aa)
|
|
44
|
|
45 static vo_info_t vo_info = {
|
|
46 "AAlib",
|
|
47 "aa",
|
|
48 "Folke Ashberg <folke@ashberg.de>",
|
|
49 ""
|
|
50 };
|
|
51
|
|
52 /* aa's main context we use */
|
|
53 aa_context *c;
|
|
54 aa_renderparams *p;
|
|
55 static int fast =0;
|
|
56 /* used for YV12 streams for the converted RGB image */
|
|
57 uint8_t * convertbuf=NULL;
|
|
58
|
|
59 /* image infos */
|
|
60 static int image_format, bpp=24;
|
|
61 static int image_width;
|
|
62 static int image_height;
|
|
63 static int bppmul;
|
|
64
|
|
65 /* osd stuff */
|
|
66 time_t stoposd = 0;
|
|
67 static int showosd = 0;
|
|
68 char osdtext[MESSAGE_SIZE];
|
|
69 char posbar[MESSAGE_SIZE];
|
|
70 static int osdx, osdy;
|
|
71
|
|
72 /* for resizing/scaling */
|
|
73 static int *stx;
|
|
74 static int *sty;
|
|
75 double accum;
|
|
76
|
|
77 /* our version of the playmodes :) */
|
|
78 static char * osdmodes[] ={ ">", "\"", "#", "-" , "+" };
|
|
79
|
|
80 extern void mplayer_put_key(int code);
|
|
81
|
|
82
|
|
83 void
|
|
84 resize(void){
|
|
85 /*
|
|
86 * this function is called by aa lib if windows resizes
|
|
87 * further during init, because here we have to calculate
|
|
88 * a little bit
|
|
89 */
|
|
90
|
|
91 int i;
|
|
92 aa_resize(c);
|
|
93
|
|
94 showosd=0;
|
|
95 osdy=aa_scrheight(c) - ( aa_scrheight(c)/10 );
|
|
96
|
|
97 /* now calculating the needed values for resizing */
|
|
98
|
|
99 /* We only need to use floating point to determine the correct
|
|
100 stretch vector for one line's worth. */
|
|
101 stx = (int *) malloc(sizeof(int) * image_width);
|
|
102 sty = (int *) malloc(sizeof(int) * image_height);
|
|
103 accum = 0;
|
|
104 for (i=0; (i < image_width); i++) {
|
|
105 int got;
|
|
106 accum += (double)aa_imgwidth(c)/(double)image_width;
|
|
107 got = (int) floor(accum);
|
|
108 stx[i] = got;
|
|
109 accum -= got;
|
|
110 }
|
|
111 accum = 0;
|
|
112 for (i=0; (i < image_height); i++) {
|
|
113 int got;
|
|
114 accum += (double)aa_imgheight(c)/(double)image_height;
|
|
115 got = (int) floor(accum);
|
|
116 sty[i] = got;
|
|
117 accum -= got;
|
|
118 }
|
|
119 }
|
|
120
|
|
121 void
|
|
122 osdmessage(int duration, int deko, char *fmt, ...)
|
|
123 {
|
|
124 /*
|
|
125 * for outputting a centered string at the bottom
|
|
126 * of our window for a while
|
|
127 */
|
|
128 va_list ar;
|
|
129 char m[MESSAGE_SIZE];
|
|
130 va_start(ar, fmt);
|
|
131 vsprintf(m, fmt, ar);
|
|
132 va_end(ar);
|
|
133 if (deko==1) sprintf(osdtext, MESSAGE_DEKO , m);
|
|
134 else strcpy(osdtext, m);
|
|
135 showosd=1;
|
|
136 stoposd = time(NULL) + duration;
|
|
137 osdx=(aa_scrwidth(c) / 2) - (strlen(osdtext) / 2 ) ;
|
|
138 posbar[0]='\0';
|
|
139 }
|
|
140
|
|
141 void
|
|
142 osdpercent(int duration, int deko, int min, int max, int val, char * desc, char * unit)
|
|
143 {
|
|
144 /*
|
|
145 * prints a bar for setting values
|
|
146 */
|
|
147 float step;
|
|
148 int where;
|
|
149 char m[MESSAGE_SIZE];
|
|
150 int i;
|
|
151 step=(float)aa_scrwidth(c) /(float)(max-min);
|
|
152 where=(val-min)*step;
|
|
153 sprintf(m,"%s: %i%s",desc, val, unit);
|
|
154 if (deko==1) sprintf(osdtext, MESSAGE_DEKO , m);
|
|
155 else strcpy(osdtext, m);
|
|
156 posbar[0]='|';
|
|
157 posbar[aa_scrwidth(c)-1]='|';
|
|
158 for (i=0;i<aa_scrwidth(c);i++){
|
|
159 if (i==where) posbar[i]='#';
|
|
160 else posbar[i]='-';
|
|
161 }
|
|
162 if (where!=0) posbar[0]='|';
|
|
163 if (where!=(aa_scrwidth(c)-1) ) posbar[aa_scrwidth(c)-1]='|';
|
|
164 /* snipp */
|
|
165 posbar[aa_scrwidth(c)]='\0';
|
|
166 showosd=1;
|
|
167 stoposd = time(NULL) + duration;
|
|
168 osdx=(aa_scrwidth(c) / 2) - (strlen(osdtext) / 2 ) ;
|
|
169 }
|
|
170
|
|
171 static uint32_t
|
|
172 init(uint32_t width, uint32_t height, uint32_t d_width,
|
|
173 uint32_t d_height, uint32_t fullscreen, char *title,
|
|
174 uint32_t format) {
|
|
175 /*
|
|
176 * main init
|
|
177 * called by mplayer
|
|
178 */
|
|
179
|
|
180 switch(format) {
|
|
181 case IMGFMT_BGR24:
|
|
182 bpp = 24;
|
|
183 break;
|
|
184 case IMGFMT_RGB24:
|
|
185 bpp = 24;
|
|
186 break;
|
|
187 case IMGFMT_YV12:
|
|
188 bpp = 24;
|
|
189 /* YUV ? then initialize what we will need */
|
|
190 convertbuf=malloc(width*height*3);
|
|
191 yuv2rgb_init(24,MODE_BGR);
|
|
192 break;
|
|
193 default:
|
|
194 return 1;
|
|
195 }
|
|
196 bppmul=bpp/8;
|
|
197
|
|
198 /* initializing of aalib */
|
|
199 aa_recommendhidisplay("curses");
|
|
200 aa_recommendhidisplay("X11");
|
|
201 aa_recommendlowdisplay("linux");
|
|
202
|
|
203
|
|
204 c = aa_autoinit(&aa_defparams);
|
|
205 aa_resizehandler(c, (void *)resize);
|
|
206
|
|
207 if (c == NULL) {
|
|
208 printf("Can not intialize aalib\n");
|
|
209 return 0;
|
|
210 }
|
|
211 if (!aa_autoinitkbd(c,0)) {
|
|
212 printf("Can not intialize keyboard\n");
|
|
213 aa_close(c);
|
|
214 return 0;
|
|
215 }
|
|
216 /*
|
|
217 if (!aa_autoinitmouse(c,0)) {
|
|
218 printf("Can not intialize mouse\n");
|
|
219 aa_close(c);
|
|
220 return 0;
|
|
221 }
|
|
222 */
|
|
223 aa_hidecursor(c);
|
|
224 p = aa_getrenderparams();
|
|
225
|
|
226 if ((strstr(c->driver->name,"curses")) || (strstr(c->driver->name,"libux")))
|
|
227 freopen("/dev/null", "w", stderr);
|
|
228
|
|
229 image_height = height;
|
|
230 image_width = width;
|
|
231 image_format = format;
|
|
232
|
|
233 /* needed by prepare_image */
|
|
234 stx = (int *) malloc(sizeof(int) * image_width);
|
|
235 sty = (int *) malloc(sizeof(int) * image_height);
|
|
236
|
|
237 /* nothing will change its size, be we need some values initialized */
|
|
238 resize();
|
|
239
|
|
240 /* say hello */
|
|
241 osdmessage(5, 1, "Welcome to ASCII ARTS MPlayer");
|
|
242
|
|
243 printf("VO: screendriver: %s\n", c->driver->name);
|
|
244 printf("VO: keyboarddriver: %s\n", c->kbddriver->name);
|
|
245 //printf("VO: mousedriver: %s\n", c->mousedriver->name);
|
|
246
|
|
247 printf(
|
|
248 "\n"
|
|
249 "\tAA-MPlayer Keys:\n"
|
|
250 "\t1 : fast rendering\n"
|
|
251 "\t2 : dithering\n"
|
|
252 "\t3 : invert image\n"
|
|
253 "\t4 : contrast -\n"
|
|
254 "\t5 : contrast +\n"
|
|
255 "\t6 : brightness -\n"
|
|
256 "\t7 : brightness +\n"
|
|
257 "\n"
|
|
258 "All other keys are MPlayer standart\n"
|
|
259
|
|
260
|
|
261 );
|
|
262
|
|
263 return 0;
|
|
264 }
|
|
265
|
|
266 static uint32_t
|
|
267 query_format(uint32_t format) {
|
|
268 /*
|
|
269 * ...are we able to... ?
|
|
270 * called by mplayer
|
|
271 */
|
|
272 switch(format){
|
|
273 case IMGFMT_YV12:
|
|
274 case IMGFMT_RGB|24:
|
|
275 case IMGFMT_BGR|24:
|
|
276 return 1;
|
|
277 }
|
|
278 return 0;
|
|
279 }
|
|
280
|
|
281 static const vo_info_t*
|
|
282 get_info(void) {
|
|
283 /* who i am? */
|
|
284 return (&vo_info);
|
|
285 }
|
|
286
|
|
287 int
|
|
288 prepare_image(uint8_t *data, int inx, int iny, int outx, int outy){
|
|
289 /*
|
|
290 * copies an RGB-Image to the aalib imagebuffer
|
|
291 * also scaling an grayscaling is done here
|
|
292 * show_image calls us
|
|
293 */
|
|
294
|
|
295 int value;
|
|
296 int x, y;
|
|
297 int tox, toy;
|
|
298 int ydest;
|
|
299 int i;
|
|
300 int pos;
|
|
301
|
|
302 toy = 0;
|
|
303 for (y=0; (y < (0 + iny)); y++) {
|
|
304 for (ydest=0; (ydest < sty[y-0]); ydest++) {
|
|
305 tox = 0;
|
|
306 for (x=0; (x < (0 + inx)); x++) {
|
|
307 if (!stx[x - 0]) {
|
|
308 continue;
|
|
309 }
|
|
310 pos=3*(inx*y)+(3*x);
|
|
311 value=(data[pos]+data[pos+1]+data[pos+2])/3;
|
|
312 for (i=0; (i < stx[x - 0]); i++) {
|
|
313 //printf("ToX: %i, ToY %i, i=%i, stx=%i, x=%i\n", tox, toy, i, stx[x], x);
|
|
314 c->imagebuffer[(toy*outx) +tox]=value;
|
|
315 tox++;
|
|
316 }
|
|
317 }
|
|
318 toy++;
|
|
319 }
|
|
320 }
|
|
321 return 0;
|
|
322 }
|
|
323
|
|
324 void
|
|
325 printosd()
|
|
326 {
|
|
327 /*
|
|
328 * places the mplayer status osd
|
|
329 */
|
|
330 if (vo_osd_text){
|
|
331 if (vo_osd_text[0]-1<=5)
|
|
332 aa_puts(c, 0,0, AA_BOLDFONT, osdmodes[vo_osd_text[0]-1]);
|
|
333 else aa_puts(c, 0,0, AA_BOLDFONT, "?");
|
|
334 aa_puts(c,1,0, AA_BOLDFONT, vo_osd_text+1);
|
|
335 aa_puts(c,strlen(vo_osd_text),0, AA_BOLDFONT, " ");
|
|
336 }
|
|
337 }
|
|
338
|
|
339 void
|
|
340 show_image(uint8_t * src){
|
|
341 /*
|
|
342 * every frame (flip_page/draw_frame) we will be called
|
|
343 */
|
|
344
|
|
345 /* events? */
|
|
346 check_events();
|
|
347
|
|
348 /* RGB->gray , scaling/resizing, stores data in aalib imgbuf */
|
|
349 prepare_image( src, image_width, image_height,
|
|
350 aa_imgwidth(c), aa_imgheight(c) );
|
|
351
|
|
352 /* Now 'ASCIInate' the image */
|
|
353 if (fast)
|
|
354 aa_fastrender(c, 0, 0, aa_scrwidth(c), aa_scrheight(c) );
|
|
355 else
|
|
356 aa_render(c, p, 0, 0, aa_scrwidth(c), aa_scrheight(c));
|
|
357
|
|
358 /* do we have to put our osd to aa's txtbuf ? */
|
|
359 if (showosd)
|
|
360 {
|
|
361 if (time(NULL)>=stoposd ) showosd=0;
|
|
362 /* update osd */
|
|
363 aa_puts(c, osdx, osdy, AA_SPECIAL, osdtext);
|
|
364 /* posbar? */
|
|
365 if (posbar[0]!='\0')
|
|
366 aa_puts(c, 0, osdy + 1, AA_SPECIAL, posbar);
|
|
367 }
|
|
368 /* and the real OSD, but only the time & playmode */
|
|
369 printosd();
|
|
370
|
|
371 /* print out */
|
|
372 aa_flush(c);
|
|
373 }
|
|
374
|
|
375 static uint32_t
|
|
376 draw_frame(uint8_t *src[]) {
|
|
377 /*
|
|
378 * RGB-Video's Only
|
|
379 * src[0] is handled bu prepare_image
|
|
380 */
|
|
381 show_image(src[0]);
|
|
382 return 0;
|
|
383 }
|
|
384
|
|
385 static uint32_t
|
|
386 draw_slice(uint8_t *src[], int stride[],
|
|
387 int w, int h, int x, int y) {
|
|
388 /*
|
|
389 * for MPGEGS YV12
|
|
390 * draw a rectangle converted to RGB to a
|
|
391 * temporary RGB Buffer
|
|
392 */
|
|
393 uint8_t *dst;
|
|
394
|
|
395 dst = convertbuf+(image_width * y + x) * 3;
|
|
396 yuv2rgb(dst,src[0],src[1],src[2],w,h,image_width*3,stride[0],stride[1]);
|
|
397
|
|
398 return 0;
|
|
399 }
|
|
400
|
|
401 static void
|
|
402 flip_page(void) {
|
|
403 /*
|
|
404 * wow! another ready Image, so draw it !
|
|
405 */
|
|
406 if(image_format == IMGFMT_YV12)
|
|
407 show_image(convertbuf);
|
|
408 }
|
|
409
|
|
410 static void
|
|
411 check_events(void) {
|
|
412 /*
|
|
413 * any events?
|
|
414 * called by show_image and mplayer
|
|
415 */
|
|
416 int key;
|
|
417 while ((key=aa_getevent(c,0))!=AA_NONE ){
|
|
418 if (key>255){
|
|
419 /* some conversations */
|
|
420 switch (key) {
|
|
421 case AA_UP:
|
|
422 mplayer_put_key(KEY_UP);
|
|
423 break;
|
|
424 case AA_DOWN:
|
|
425 mplayer_put_key(KEY_DOWN);
|
|
426 break;
|
|
427 case AA_LEFT:
|
|
428 mplayer_put_key(KEY_LEFT);
|
|
429 break;
|
|
430 case AA_RIGHT:
|
|
431 mplayer_put_key(KEY_RIGHT);
|
|
432 break;
|
|
433 case AA_ESC:
|
|
434 mplayer_put_key(KEY_ESC);
|
|
435 break;
|
|
436 case 65765:
|
|
437 mplayer_put_key(KEY_PAGE_UP);
|
|
438 break;
|
|
439 case 65766:
|
|
440 mplayer_put_key(KEY_PAGE_DOWN);
|
|
441 break;
|
|
442 default:
|
|
443 continue; /* aa lib special key */
|
|
444 break;
|
|
445 }
|
|
446 }
|
|
447 switch (key) {
|
|
448 /* AA image controls */
|
|
449 case '1':
|
|
450 fast=!fast;
|
|
451 osdmessage(MESSAGE_DURATION, 1, "Fast mode is now %s", fast==1 ? "on" : "off");
|
|
452 break;
|
|
453 case '2':
|
|
454 if (p->dither==AA_FLOYD_S){
|
|
455 p->dither=AA_NONE;
|
|
456 osdmessage(MESSAGE_DURATION, 1, "Dithering: Off");
|
|
457 }else if (p->dither==AA_NONE){
|
|
458 p->dither=AA_ERRORDISTRIB;
|
|
459 osdmessage(MESSAGE_DURATION, 1, "Dithering: Error Distribution");
|
|
460 }else if (p->dither==AA_ERRORDISTRIB){
|
|
461 p->dither=AA_FLOYD_S;
|
|
462 osdmessage(MESSAGE_DURATION, 1, "Dithering: Floyd Steinberg");
|
|
463 }
|
|
464 break;
|
|
465 case '3':
|
|
466 p->inversion=!p->inversion;
|
|
467 osdmessage(MESSAGE_DURATION, 1, "Invert mode is now %s",
|
|
468 p->inversion==1 ? "on" : "off");
|
|
469 break;
|
|
470
|
|
471 case '4': /* contrast */
|
|
472 DO_DEC(p->contrast,0,1);
|
|
473 osdpercent(MESSAGE_DURATION, 1, 0, 255, p->contrast, "AA-Contrast", "");
|
|
474
|
|
475 break;
|
|
476 case '5': /* contrast */
|
|
477 DO_INC(p->contrast,255,1);
|
|
478 osdpercent(MESSAGE_DURATION, 1, 0, 255, p->contrast, "AA-Contrast", "");
|
|
479 break;
|
|
480 case '6': /* brightness */
|
|
481 DO_DEC(p->bright,0,1);
|
|
482 osdpercent(MESSAGE_DURATION, 1, 0, 255, p->bright, "AA-Brightnes", "");
|
|
483 break;
|
|
484 case '7': /* brightness */
|
|
485 DO_INC(p->bright,255,1);
|
|
486 osdpercent(MESSAGE_DURATION, 1, 0, 255, p->bright, "AA-Brightnes", "");
|
|
487 break;
|
|
488
|
|
489 default :
|
|
490 /* nothing if we're interested in?
|
|
491 * the mplayer should handle it!
|
|
492 */
|
|
493 mplayer_put_key(key);
|
|
494 break;
|
|
495 }
|
|
496 }
|
|
497 }
|
|
498
|
|
499 static void
|
|
500 uninit(void) {
|
|
501 /*
|
|
502 * THE END
|
|
503 */
|
|
504 aa_close(c);
|
|
505 free(stx);
|
|
506 free(sty);
|
|
507 if (convertbuf!=NULL) free(convertbuf);
|
|
508 if (strstr(c->driver->name,"curses") || strstr(c->driver->name,"libux"))
|
|
509 freopen("/dev/tty", "w", stderr);
|
|
510 }
|
|
511
|
|
512 static void
|
|
513 draw_osd(void){
|
|
514 }
|