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
;
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
;
93 if (!vlc_xlib_init (object
))
97 /* Allocate structure */
98 vd
->sys
= sys
= calloc(1, sizeof(*sys
));
102 /* Don't parse any options, but take $AAOPTS into account */
103 aa_parseoptions(NULL
, NULL
, NULL
, NULL
);
106 sys
->aa_context
= aa_autoinit(&aa_defparams
);
107 if (!sys
->aa_context
) {
108 msg_Err(vd
, "cannot initialize aalib");
111 vout_display_DeleteWindow(vd
, NULL
);
113 aa_autoinitkbd(sys
->aa_context
, 0);
114 aa_autoinitmouse(sys
->aa_context
, AA_MOUSEALLMASK
);
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 */
126 vd
->info
.has_pictures_invalid
= true;
127 vd
->info
.needs_event_thread
= true;
130 vd
->prepare
= Prepare
;
131 vd
->display
= PictureDisplay
;
132 vd
->control
= Control
;
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
);
142 if (sys
&& sys
->aa_context
)
143 aa_close(sys
->aa_context
);
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
;
157 picture_pool_Release(sys
->pool
);
158 aa_close(sys
->aa_context
);
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
;
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
);
182 sys
->pool
= picture_pool_New(1, &p_picture
);
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
));
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
]);
206 VLC_UNUSED(subpicture
);
208 aa_fastrender(sys
->aa_context
, 0, 0,
209 vd
->fmt
.i_width
, vd
->fmt
.i_height
);
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
)
230 vout_display_sys_t
*sys
= vd
->sys
;
233 case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE
:
234 /* We have to ignore what is requested */
235 vout_display_SendEventPicturesInvalid(vd
);
238 case VOUT_DISPLAY_RESET_PICTURES
:
240 picture_pool_Release(sys
->pool
);
243 vd
->fmt
.i_width
= aa_imgwidth(sys
->aa_context
);
244 vd
->fmt
.i_height
= aa_imgheight(sys
->aa_context
);
247 case VOUT_DISPLAY_HIDE_MOUSE
:
248 aa_hidemouse(sys
->aa_context
);
252 msg_Err(vd
, "Unsupported query in vout display aalib");
259 * Proccess pending event
261 static void Manage(vout_display_t
*vd
)
263 vout_display_sys_t
*sys
= vd
->sys
;
266 const int event
= aa_getevent(sys
->aa_context
, 0);
275 aa_getmouse(sys
->aa_context
, &x
, &y
, &button
);
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 */
292 aa_resize(sys
->aa_context
);
293 vout_display_SendEventDisplaySize(vd
,
294 aa_imgwidth(sys
->aa_context
),
295 aa_imgheight(sys
->aa_context
));
298 /* TODO keys support to complete */
300 vout_display_SendEventKey(vd
, KEY_UP
);
303 vout_display_SendEventKey(vd
, KEY_DOWN
);
306 vout_display_SendEventKey(vd
, KEY_RIGHT
);
309 vout_display_SendEventKey(vd
, KEY_LEFT
);
312 vout_display_SendEventKey(vd
, KEY_BACKSPACE
);
315 vout_display_SendEventKey(vd
, KEY_ESC
);
318 if (event
>= 0x20 && event
<= 0x7f)
319 vout_display_SendEventKey(vd
, event
);