demux: avi: invalidate skipped chunks
[vlc.git] / modules / video_output / aa.c
blobe4ff1391c3e27084ee8388b7552143c539a4c6d7
1 /*****************************************************************************
2 * aa.c: "vout display" module using aalib
3 *****************************************************************************
4 * Copyright (C) 2002-2009 VLC authors and VideoLAN
5 * $Id$
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 /*****************************************************************************
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*/0)
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 *, subpicture_t *);
70 static void PictureDisplay(vout_display_t *, picture_t *, subpicture_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 picture_pool_t *pool;
84 /**
85 * This function allocates and initializes a aa vout method.
87 static int Open(vlc_object_t *object)
89 vout_display_t *vd = (vout_display_t *)object;
90 vout_display_sys_t *sys;
92 #ifndef _WIN32
93 if (!vlc_xlib_init (object))
94 return VLC_EGENERIC;
95 #endif
97 /* Allocate structure */
98 vd->sys = sys = calloc(1, sizeof(*sys));
99 if (!sys)
100 return VLC_ENOMEM;
102 /* Don't parse any options, but take $AAOPTS into account */
103 aa_parseoptions(NULL, NULL, NULL, NULL);
105 /* */
106 sys->aa_context = aa_autoinit(&aa_defparams);
107 if (!sys->aa_context) {
108 msg_Err(vd, "cannot initialize aalib");
109 goto error;
111 vout_display_DeleteWindow(vd, NULL);
113 aa_autoinitkbd(sys->aa_context, 0);
114 aa_autoinitmouse(sys->aa_context, AA_MOUSEALLMASK);
116 /* */
117 video_format_t fmt = vd->fmt;
118 fmt.i_chroma = VLC_CODEC_RGB8;
119 fmt.i_width = aa_imgwidth(sys->aa_context);
120 fmt.i_height = aa_imgheight(sys->aa_context);
121 fmt.i_visible_width = fmt.i_width;
122 fmt.i_visible_height = fmt.i_height;
124 /* Setup vout_display now that everything is fine */
125 vd->fmt = fmt;
126 vd->info.has_pictures_invalid = true;
127 vd->info.needs_event_thread = true;
129 vd->pool = Pool;
130 vd->prepare = Prepare;
131 vd->display = PictureDisplay;
132 vd->control = Control;
133 vd->manage = Manage;
135 /* Inspect initial configuration and send correction events
136 * FIXME how to handle aspect ratio with aa ? */
137 vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height);
139 return VLC_SUCCESS;
141 error:
142 if (sys && sys->aa_context)
143 aa_close(sys->aa_context);
144 free(sys);
145 return VLC_EGENERIC;
149 * Close a aa video output method
151 static void Close(vlc_object_t *object)
153 vout_display_t *vd = (vout_display_t *)object;
154 vout_display_sys_t *sys = vd->sys;
156 if (sys->pool)
157 picture_pool_Release(sys->pool);
158 aa_close(sys->aa_context);
159 free(sys);
163 * Return a pool of direct buffers
165 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
167 vout_display_sys_t *sys = vd->sys;
168 VLC_UNUSED(count);
170 if (!sys->pool) {
171 picture_resource_t rsc;
173 memset(&rsc, 0, sizeof(rsc));
174 rsc.p[0].p_pixels = aa_image(sys->aa_context);
175 rsc.p[0].i_pitch = aa_imgwidth(sys->aa_context);
176 rsc.p[0].i_lines = aa_imgheight(sys->aa_context);
178 picture_t *p_picture = picture_NewFromResource(&vd->fmt, &rsc);
179 if (!p_picture)
180 return NULL;
182 sys->pool = picture_pool_New(1, &p_picture);
184 return sys->pool;
188 * Prepare a picture for display */
189 static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
191 vout_display_sys_t *sys = vd->sys;
193 assert(vd->fmt.i_width == aa_imgwidth(sys->aa_context) &&
194 vd->fmt.i_height == aa_imgheight(sys->aa_context));
196 #if 0
197 if (picture->format.p_palette) {
198 for (int i = 0; i < 256; i++) {
199 aa_setpalette(vd->sys->palette, 256 - i,
200 red[ i ], green[ i ], blue[ i ]);
203 #else
204 VLC_UNUSED(picture);
205 #endif
206 VLC_UNUSED(subpicture);
208 aa_fastrender(sys->aa_context, 0, 0,
209 vd->fmt.i_width, vd->fmt.i_height);
213 * Display a picture
215 static void PictureDisplay(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
217 vout_display_sys_t *sys = vd->sys;
219 aa_flush(sys->aa_context);
220 picture_Release(picture);
221 VLC_UNUSED(subpicture);
225 * Control for vout display
227 static int Control(vout_display_t *vd, int query, va_list args)
229 VLC_UNUSED(args);
230 vout_display_sys_t *sys = vd->sys;
232 switch (query) {
233 case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
234 /* We have to ignore what is requested */
235 vout_display_SendEventPicturesInvalid(vd);
236 return VLC_SUCCESS;
238 case VOUT_DISPLAY_RESET_PICTURES:
239 if (sys->pool)
240 picture_pool_Release(sys->pool);
241 sys->pool = NULL;
243 vd->fmt.i_width = aa_imgwidth(sys->aa_context);
244 vd->fmt.i_height = aa_imgheight(sys->aa_context);
245 return VLC_SUCCESS;
247 case VOUT_DISPLAY_HIDE_MOUSE:
248 aa_hidemouse(sys->aa_context);
249 return VLC_SUCCESS;
251 default:
252 msg_Err(vd, "Unsupported query in vout display aalib");
253 return VLC_EGENERIC;
259 * Proccess pending event
261 static void Manage(vout_display_t *vd)
263 vout_display_sys_t *sys = vd->sys;
265 for (;;) {
266 const int event = aa_getevent(sys->aa_context, 0);
267 if (!event)
268 return;
270 switch (event) {
271 case AA_MOUSE: {
272 int x, y;
273 int button;
274 int vlc;
275 aa_getmouse(sys->aa_context, &x, &y, &button);
277 vlc = 0;
278 if (button & AA_BUTTON1)
279 vlc |= 1 << MOUSE_BUTTON_LEFT;
280 if (button & AA_BUTTON2)
281 vlc |= 1 << MOUSE_BUTTON_CENTER;
282 if (button & AA_BUTTON3)
283 vlc |= 1 << MOUSE_BUTTON_RIGHT;
285 vout_display_SendEventMouseState(vd, x, y, vlc);
287 aa_showcursor(sys->aa_context); /* Not perfect, we show it on click too */
288 break;
291 case AA_RESIZE:
292 aa_resize(sys->aa_context);
293 vout_display_SendEventDisplaySize(vd,
294 aa_imgwidth(sys->aa_context),
295 aa_imgheight(sys->aa_context));
296 break;
298 /* TODO keys support to complete */
299 case AA_UP:
300 vout_display_SendEventKey(vd, KEY_UP);
301 break;
302 case AA_DOWN:
303 vout_display_SendEventKey(vd, KEY_DOWN);
304 break;
305 case AA_RIGHT:
306 vout_display_SendEventKey(vd, KEY_RIGHT);
307 break;
308 case AA_LEFT:
309 vout_display_SendEventKey(vd, KEY_LEFT);
310 break;
311 case AA_BACKSPACE:
312 vout_display_SendEventKey(vd, KEY_BACKSPACE);
313 break;
314 case AA_ESC:
315 vout_display_SendEventKey(vd, KEY_ESC);
316 break;
317 default:
318 if (event >= 0x20 && event <= 0x7f)
319 vout_display_SendEventKey(vd, event);
320 break;