Remove legacy parameter from add_string()
[vlc/asuraparaju-public.git] / modules / video_output / aa.c
blob420767b587ead5383276bd47a4d67cb171294f02
1 /*****************************************************************************
2 * aa.c: "vout display" module using aalib
3 *****************************************************************************
4 * Copyright (C) 2002-2009 the VideoLAN team
5 * $Id$
7 * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_vout_display.h>
34 #include <vlc_picture_pool.h>
36 #include <assert.h>
37 #include <aalib.h>
39 #ifndef WIN32
40 # ifdef X_DISPLAY_MISSING
41 # error Xlib required due to XInitThreads
42 # endif
43 # include <vlc_xlib.h>
44 #endif
46 /* TODO
47 * - what about RGB palette ?
49 /*****************************************************************************
50 * Module descriptor
51 *****************************************************************************/
52 static int Open (vlc_object_t *);
53 static void Close(vlc_object_t *);
55 vlc_module_begin()
56 set_shortname(N_("ASCII Art"))
57 set_category(CAT_VIDEO)
58 set_subcategory(SUBCAT_VIDEO_VOUT)
59 set_description(N_("ASCII-art video output"))
60 set_capability("vout display", 10)
61 add_shortcut("aalib")
62 set_callbacks(Open, Close)
63 vlc_module_end()
65 /*****************************************************************************
66 * Local prototypes
67 *****************************************************************************/
68 static picture_pool_t *Pool (vout_display_t *, unsigned);
69 static void Prepare(vout_display_t *, picture_t *);
70 static void PictureDisplay(vout_display_t *, picture_t *);
71 static int Control(vout_display_t *, int, va_list);
73 /* */
74 static void Manage(vout_display_t *);
76 /* */
77 struct vout_display_sys_t {
78 struct aa_context* aa_context;
79 aa_palette palette;
81 vout_display_cfg_t state;
82 picture_pool_t *pool;
85 /**
86 * This function allocates and initializes a aa vout method.
88 static int Open(vlc_object_t *object)
90 vout_display_t *vd = (vout_display_t *)object;
91 vout_display_sys_t *sys;
93 #ifndef WIN32
94 if (!vlc_xlib_init (object))
95 return VLC_EGENERIC;
96 #endif
98 /* Allocate structure */
99 vd->sys = sys = calloc(1, sizeof(*sys));
100 if (!sys)
101 return VLC_ENOMEM;
103 /* Don't parse any options, but take $AAOPTS into account */
104 aa_parseoptions(NULL, NULL, NULL, NULL);
106 /* */
107 sys->aa_context = aa_autoinit(&aa_defparams);
108 if (!sys->aa_context) {
109 msg_Err(vd, "cannot initialize aalib");
110 goto error;
112 vout_display_DeleteWindow(vd, NULL);
114 aa_autoinitkbd(sys->aa_context, 0);
115 aa_autoinitmouse(sys->aa_context, AA_MOUSEALLMASK);
117 /* */
118 video_format_t fmt = vd->fmt;
119 fmt.i_chroma = VLC_CODEC_RGB8;
120 fmt.i_width = aa_imgwidth(sys->aa_context);
121 fmt.i_height = aa_imgheight(sys->aa_context);
123 /* */
124 vout_display_info_t info = vd->info;
125 info.has_pictures_invalid = true;
127 /* Setup vout_display now that everything is fine */
128 vd->fmt = fmt;
129 vd->info = info;
131 vd->pool = Pool;
132 vd->prepare = Prepare;
133 vd->display = PictureDisplay;
134 vd->control = Control;
135 vd->manage = Manage;
137 /* Inspect initial configuration and send correction events
138 * FIXME how to handle aspect ratio with aa ? */
139 sys->state = *vd->cfg;
140 sys->state.is_fullscreen = false;
141 vout_display_SendEventFullscreen(vd, false);
142 vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height, false);
144 return VLC_SUCCESS;
146 error:
147 if (sys && sys->aa_context)
148 aa_close(sys->aa_context);
149 free(sys);
150 return VLC_EGENERIC;
154 * Close a aa video output method
156 static void Close(vlc_object_t *object)
158 vout_display_t *vd = (vout_display_t *)object;
159 vout_display_sys_t *sys = vd->sys;
161 if (sys->pool)
162 picture_pool_Delete(sys->pool);
163 aa_close(sys->aa_context);
164 free(sys);
168 * Return a pool of direct buffers
170 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
172 vout_display_sys_t *sys = vd->sys;
173 VLC_UNUSED(count);
175 if (!sys->pool) {
176 picture_resource_t rsc;
178 memset(&rsc, 0, sizeof(rsc));
179 rsc.p[0].p_pixels = aa_image(sys->aa_context);
180 rsc.p[0].i_pitch = aa_imgwidth(sys->aa_context);
181 rsc.p[0].i_lines = aa_imgheight(sys->aa_context);
183 picture_t *p_picture = picture_NewFromResource(&vd->fmt, &rsc);
184 if (!p_picture)
185 return NULL;
187 sys->pool = picture_pool_New(1, &p_picture);
189 return sys->pool;
193 * Prepare a picture for display */
194 static void Prepare(vout_display_t *vd, picture_t *picture)
196 vout_display_sys_t *sys = vd->sys;
198 assert(vd->fmt.i_width == aa_imgwidth(sys->aa_context) &&
199 vd->fmt.i_height == aa_imgheight(sys->aa_context));
201 #if 0
202 if (picture->format.p_palette) {
203 for (int i = 0; i < 256; i++) {
204 aa_setpalette(vd->sys->palette, 256 - i,
205 red[ i ], green[ i ], blue[ i ]);
208 #else
209 VLC_UNUSED(picture);
210 #endif
212 aa_fastrender(sys->aa_context, 0, 0,
213 vd->fmt.i_width, vd->fmt.i_height);
217 * Display a picture
219 static void PictureDisplay(vout_display_t *vd, picture_t *picture)
221 vout_display_sys_t *sys = vd->sys;
223 aa_flush(sys->aa_context);
224 picture_Release(picture);
228 * Control for vout display
230 static int Control(vout_display_t *vd, int query, va_list args)
232 VLC_UNUSED(args);
233 vout_display_sys_t *sys = vd->sys;
235 switch (query) {
236 case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
237 /* We have to ignore what is requested */
238 vout_display_SendEventPicturesInvalid(vd);
239 return VLC_SUCCESS;
241 case VOUT_DISPLAY_RESET_PICTURES:
242 if (sys->pool)
243 picture_pool_Delete(sys->pool);
244 sys->pool = NULL;
246 vd->fmt.i_width = aa_imgwidth(sys->aa_context);
247 vd->fmt.i_height = aa_imgheight(sys->aa_context);
248 return VLC_SUCCESS;
250 case VOUT_DISPLAY_HIDE_MOUSE:
251 aa_hidemouse(sys->aa_context);
252 return VLC_SUCCESS;
254 default:
255 msg_Err(vd, "Unsupported query in vout display aalib");
256 return VLC_EGENERIC;
262 * Proccess pending event
264 static void Manage(vout_display_t *vd)
266 vout_display_sys_t *sys = vd->sys;
268 for (;;) {
269 const int event = aa_getevent(sys->aa_context, 0);
270 if (!event)
271 return;
273 switch (event) {
274 case AA_MOUSE: {
275 int x, y;
276 int button;
277 int vlc;
278 aa_getmouse(sys->aa_context, &x, &y, &button);
280 vlc = 0;
281 if (button & AA_BUTTON1)
282 vlc |= 1 << MOUSE_BUTTON_LEFT;
283 if (button & AA_BUTTON2)
284 vlc |= 1 << MOUSE_BUTTON_CENTER;
285 if (button & AA_BUTTON3)
286 vlc |= 1 << MOUSE_BUTTON_RIGHT;
288 vout_display_SendEventMouseState(vd, x, y, vlc);
290 aa_showcursor(sys->aa_context); /* Not perfect, we show it on click too */
291 break;
294 case AA_RESIZE:
295 aa_resize(sys->aa_context);
296 vout_display_SendEventDisplaySize(vd,
297 aa_imgwidth(sys->aa_context),
298 aa_imgheight(sys->aa_context), false);
299 break;
301 /* TODO keys support to complete */
302 case AA_UP:
303 vout_display_SendEventKey(vd, KEY_UP);
304 break;
305 case AA_DOWN:
306 vout_display_SendEventKey(vd, KEY_DOWN);
307 break;
308 case AA_RIGHT:
309 vout_display_SendEventKey(vd, KEY_RIGHT);
310 break;
311 case AA_LEFT:
312 vout_display_SendEventKey(vd, KEY_LEFT);
313 break;
314 case AA_BACKSPACE:
315 vout_display_SendEventKey(vd, KEY_BACKSPACE);
316 break;
317 case AA_ESC:
318 vout_display_SendEventKey(vd, KEY_ESC);
319 break;
320 default:
321 if (event >= 0x20 && event <= 0x7f)
322 vout_display_SendEventKey(vd, event);
323 break;