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>
46 #include "event_thread.h"
49 * - what about RGB palette ?
51 /*****************************************************************************
53 *****************************************************************************/
54 static int Open (vlc_object_t
*);
55 static void Close(vlc_object_t
*);
58 set_shortname(N_("ASCII Art"))
59 set_category(CAT_VIDEO
)
60 set_subcategory(SUBCAT_VIDEO_VOUT
)
61 set_description(N_("ASCII-art video output"))
62 set_capability("vout display", /*10*/0)
64 set_callbacks(Open
, Close
)
67 /*****************************************************************************
69 *****************************************************************************/
70 static picture_pool_t
*Pool (vout_display_t
*, unsigned);
71 static void Prepare(vout_display_t
*, picture_t
*, subpicture_t
*);
72 static void PictureDisplay(vout_display_t
*, picture_t
*, subpicture_t
*);
73 static int Control(vout_display_t
*, int, va_list);
76 static void Manage(vout_display_t
*);
79 struct vout_display_sys_t
{
80 struct aa_context
* aa_context
;
84 vout_display_event_thread_t
*et
;
88 * This function allocates and initializes a aa vout method.
90 static int Open(vlc_object_t
*object
)
92 vout_display_t
*vd
= (vout_display_t
*)object
;
93 vout_display_sys_t
*sys
;
96 if (!vlc_xlib_init (object
))
100 /* Allocate structure */
101 vd
->sys
= sys
= calloc(1, sizeof(*sys
));
105 /* Don't parse any options, but take $AAOPTS into account */
106 aa_parseoptions(NULL
, NULL
, NULL
, NULL
);
109 sys
->aa_context
= aa_autoinit(&aa_defparams
);
110 if (!sys
->aa_context
) {
111 msg_Err(vd
, "cannot initialize aalib");
114 vout_display_DeleteWindow(vd
, NULL
);
116 sys
->et
= VoutDisplayEventCreateThread(vd
);
118 aa_autoinitkbd(sys
->aa_context
, 0);
119 aa_autoinitmouse(sys
->aa_context
, AA_MOUSEALLMASK
);
122 video_format_t fmt
= vd
->fmt
;
123 fmt
.i_chroma
= VLC_CODEC_RGB8
;
124 fmt
.i_width
= aa_imgwidth(sys
->aa_context
);
125 fmt
.i_height
= aa_imgheight(sys
->aa_context
);
126 fmt
.i_visible_width
= fmt
.i_width
;
127 fmt
.i_visible_height
= fmt
.i_height
;
129 /* Setup vout_display now that everything is fine */
131 vd
->info
.has_pictures_invalid
= true;
132 vd
->info
.needs_hide_mouse
= true;
135 vd
->prepare
= Prepare
;
136 vd
->display
= PictureDisplay
;
137 vd
->control
= Control
;
140 /* Inspect initial configuration and send correction events
141 * FIXME how to handle aspect ratio with aa ? */
142 vout_display_SendEventDisplaySize(vd
, fmt
.i_width
, fmt
.i_height
);
147 if (sys
&& sys
->aa_context
)
148 aa_close(sys
->aa_context
);
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
;
162 picture_pool_Release(sys
->pool
);
163 VoutDisplayEventKillThread(sys
->et
);
164 aa_close(sys
->aa_context
);
169 * Return a pool of direct buffers
171 static picture_pool_t
*Pool(vout_display_t
*vd
, unsigned count
)
173 vout_display_sys_t
*sys
= vd
->sys
;
177 picture_resource_t rsc
;
179 memset(&rsc
, 0, sizeof(rsc
));
180 rsc
.p
[0].p_pixels
= aa_image(sys
->aa_context
);
181 rsc
.p
[0].i_pitch
= aa_imgwidth(sys
->aa_context
);
182 rsc
.p
[0].i_lines
= aa_imgheight(sys
->aa_context
);
184 picture_t
*p_picture
= picture_NewFromResource(&vd
->fmt
, &rsc
);
188 sys
->pool
= picture_pool_New(1, &p_picture
);
194 * Prepare a picture for display */
195 static void Prepare(vout_display_t
*vd
, picture_t
*picture
, subpicture_t
*subpicture
)
197 vout_display_sys_t
*sys
= vd
->sys
;
199 assert(vd
->fmt
.i_width
== aa_imgwidth(sys
->aa_context
) &&
200 vd
->fmt
.i_height
== aa_imgheight(sys
->aa_context
));
203 if (picture
->format
.p_palette
) {
204 for (int i
= 0; i
< 256; i
++) {
205 aa_setpalette(vd
->sys
->palette
, 256 - i
,
206 red
[ i
], green
[ i
], blue
[ i
]);
212 VLC_UNUSED(subpicture
);
214 aa_fastrender(sys
->aa_context
, 0, 0,
215 vd
->fmt
.i_width
, vd
->fmt
.i_height
);
221 static void PictureDisplay(vout_display_t
*vd
, picture_t
*picture
, subpicture_t
*subpicture
)
223 vout_display_sys_t
*sys
= vd
->sys
;
225 aa_flush(sys
->aa_context
);
226 picture_Release(picture
);
227 VLC_UNUSED(subpicture
);
231 * Control for vout display
233 static int Control(vout_display_t
*vd
, int query
, va_list args
)
236 vout_display_sys_t
*sys
= vd
->sys
;
239 case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE
:
240 /* We have to ignore what is requested */
241 vout_display_SendEventPicturesInvalid(vd
);
244 case VOUT_DISPLAY_RESET_PICTURES
:
246 picture_pool_Release(sys
->pool
);
249 vd
->fmt
.i_width
= aa_imgwidth(sys
->aa_context
);
250 vd
->fmt
.i_height
= aa_imgheight(sys
->aa_context
);
253 case VOUT_DISPLAY_HIDE_MOUSE
:
254 aa_hidemouse(sys
->aa_context
);
258 msg_Err(vd
, "Unsupported query in vout display aalib");
265 * Proccess pending event
267 static void Manage(vout_display_t
*vd
)
269 vout_display_sys_t
*sys
= vd
->sys
;
272 const int event
= aa_getevent(sys
->aa_context
, 0);
281 aa_getmouse(sys
->aa_context
, &x
, &y
, &button
);
284 if (button
& AA_BUTTON1
)
285 vlc
|= 1 << MOUSE_BUTTON_LEFT
;
286 if (button
& AA_BUTTON2
)
287 vlc
|= 1 << MOUSE_BUTTON_CENTER
;
288 if (button
& AA_BUTTON3
)
289 vlc
|= 1 << MOUSE_BUTTON_RIGHT
;
291 vout_display_SendEventMouseState(vd
, x
, y
, vlc
);
293 aa_showcursor(sys
->aa_context
); /* Not perfect, we show it on click too */
298 aa_resize(sys
->aa_context
);
299 vout_display_SendEventDisplaySize(vd
,
300 aa_imgwidth(sys
->aa_context
),
301 aa_imgheight(sys
->aa_context
));
304 /* TODO keys support to complete */
306 vout_display_SendEventKey(vd
, KEY_UP
);
309 vout_display_SendEventKey(vd
, KEY_DOWN
);
312 vout_display_SendEventKey(vd
, KEY_RIGHT
);
315 vout_display_SendEventKey(vd
, KEY_LEFT
);
318 vout_display_SendEventKey(vd
, KEY_BACKSPACE
);
321 vout_display_SendEventKey(vd
, KEY_ESC
);
324 if (event
>= 0x20 && event
<= 0x7f)
325 vout_display_SendEventKey(vd
, event
);