1 /*****************************************************************************
2 * aa.c: "vout display" module using aalib
3 *****************************************************************************
4 * Copyright (C) 2002-2009 VLC authors and VideoLAN
7 * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_vout_display.h>
34 #include <vlc_picture_pool.h>
40 # ifdef X_DISPLAY_MISSING
41 # error Xlib required due to XInitThreads
43 # include <vlc_xlib.h>
47 * - what about RGB palette ?
49 /*****************************************************************************
51 *****************************************************************************/
52 static int Open (vlc_object_t *);
53 static void Close(vlc_object_t *);
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*/0)
62 set_callbacks(Open, Close)
65 /*****************************************************************************
67 *****************************************************************************/
68 static picture_pool_t *Pool (vout_display_t *, unsigned);
69 static void Prepare(vout_display_t *, picture_t *, subpicture_t *);
70 static void PictureDisplay(vout_display_t *, picture_t *, subpicture_t *);
71 static int Control(vout_display_t *, int, va_list);
74 static void Manage(vout_display_t *);
77 struct vout_display_sys_t {
78 struct aa_context* aa_context;
81 vout_display_cfg_t state;
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;
94 if (!vlc_xlib_init (object))
98 /* Allocate structure */
99 vd->sys = sys = calloc(1, sizeof(*sys));
103 /* Don't parse any options, but take $AAOPTS into account */
104 aa_parseoptions(NULL, NULL, NULL, NULL);
107 sys->aa_context = aa_autoinit(&aa_defparams);
108 if (!sys->aa_context) {
109 msg_Err(vd, "cannot initialize aalib");
112 vout_display_DeleteWindow(vd, NULL);
114 aa_autoinitkbd(sys->aa_context, 0);
115 aa_autoinitmouse(sys->aa_context, AA_MOUSEALLMASK);
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);
122 fmt.i_visible_width = fmt.i_width;
123 fmt.i_visible_height = fmt.i_height;
126 vout_display_info_t info = vd->info;
127 info.has_pictures_invalid = true;
129 /* Setup vout_display now that everything is fine */
134 vd->prepare = Prepare;
135 vd->display = PictureDisplay;
136 vd->control = Control;
139 /* Inspect initial configuration and send correction events
140 * FIXME how to handle aspect ratio with aa ? */
141 sys->state = *vd->cfg;
142 sys->state.is_fullscreen = false;
143 vout_display_SendEventFullscreen(vd, false);
144 vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height);
149 if (sys && sys->aa_context)
150 aa_close(sys->aa_context);
156 * Close a aa video output method
158 static void Close(vlc_object_t *object)
160 vout_display_t *vd = (vout_display_t *)object;
161 vout_display_sys_t *sys = vd->sys;
164 picture_pool_Release(sys->pool);
165 aa_close(sys->aa_context);
170 * Return a pool of direct buffers
172 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
174 vout_display_sys_t *sys = vd->sys;
178 picture_resource_t rsc;
180 memset(&rsc, 0, sizeof(rsc));
181 rsc.p[0].p_pixels = aa_image(sys->aa_context);
182 rsc.p[0].i_pitch = aa_imgwidth(sys->aa_context);
183 rsc.p[0].i_lines = aa_imgheight(sys->aa_context);
185 picture_t *p_picture = picture_NewFromResource(&vd->fmt, &rsc);
189 sys->pool = picture_pool_New(1, &p_picture);
195 * Prepare a picture for display */
196 static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
198 vout_display_sys_t *sys = vd->sys;
200 assert(vd->fmt.i_width == aa_imgwidth(sys->aa_context) &&
201 vd->fmt.i_height == aa_imgheight(sys->aa_context));
204 if (picture->format.p_palette) {
205 for (int i = 0; i < 256; i++) {
206 aa_setpalette(vd->sys->palette, 256 - i,
207 red[ i ], green[ i ], blue[ i ]);
213 VLC_UNUSED(subpicture);
215 aa_fastrender(sys->aa_context, 0, 0,
216 vd->fmt.i_width, vd->fmt.i_height);
222 static void PictureDisplay(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
224 vout_display_sys_t *sys = vd->sys;
226 aa_flush(sys->aa_context);
227 picture_Release(picture);
228 VLC_UNUSED(subpicture);
232 * Control for vout display
234 static int Control(vout_display_t *vd, int query, va_list args)
237 vout_display_sys_t *sys = vd->sys;
240 case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
241 /* We have to ignore what is requested */
242 vout_display_SendEventPicturesInvalid(vd);
245 case VOUT_DISPLAY_RESET_PICTURES:
247 picture_pool_Release(sys->pool);
250 vd->fmt.i_width = aa_imgwidth(sys->aa_context);
251 vd->fmt.i_height = aa_imgheight(sys->aa_context);
254 case VOUT_DISPLAY_HIDE_MOUSE:
255 aa_hidemouse(sys->aa_context);
259 msg_Err(vd, "Unsupported query in vout display aalib");
266 * Proccess pending event
268 static void Manage(vout_display_t *vd)
270 vout_display_sys_t *sys = vd->sys;
273 const int event = aa_getevent(sys->aa_context, 0);
282 aa_getmouse(sys->aa_context, &x, &y, &button);
285 if (button & AA_BUTTON1)
286 vlc |= 1 << MOUSE_BUTTON_LEFT;
287 if (button & AA_BUTTON2)
288 vlc |= 1 << MOUSE_BUTTON_CENTER;
289 if (button & AA_BUTTON3)
290 vlc |= 1 << MOUSE_BUTTON_RIGHT;
292 vout_display_SendEventMouseState(vd, x, y, vlc);
294 aa_showcursor(sys->aa_context); /* Not perfect, we show it on click too */
299 aa_resize(sys->aa_context);
300 vout_display_SendEventDisplaySize(vd,
301 aa_imgwidth(sys->aa_context),
302 aa_imgheight(sys->aa_context));
305 /* TODO keys support to complete */
307 vout_display_SendEventKey(vd, KEY_UP);
310 vout_display_SendEventKey(vd, KEY_DOWN);
313 vout_display_SendEventKey(vd, KEY_RIGHT);
316 vout_display_SendEventKey(vd, KEY_LEFT);
319 vout_display_SendEventKey(vd, KEY_BACKSPACE);
322 vout_display_SendEventKey(vd, KEY_ESC);
325 if (event >= 0x20 && event <= 0x7f)
326 vout_display_SendEventKey(vd, event);