1 /*****************************************************************************
2 * aa.c: "vout display" module using aalib
3 *****************************************************************************
4 * Copyright (C) 2002-2009 the VideoLAN team
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 /*****************************************************************************
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)
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
*);
70 static void PictureDisplay(vout_display_t
*, picture_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
);
124 vout_display_info_t info
= vd
->info
;
125 info
.has_pictures_invalid
= true;
127 /* Setup vout_display now that everything is fine */
132 vd
->prepare
= Prepare
;
133 vd
->display
= PictureDisplay
;
134 vd
->control
= Control
;
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);
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_Delete(sys
->pool
);
163 aa_close(sys
->aa_context
);
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
;
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
);
187 sys
->pool
= picture_pool_New(1, &p_picture
);
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
));
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
]);
212 aa_fastrender(sys
->aa_context
, 0, 0,
213 vd
->fmt
.i_width
, vd
->fmt
.i_height
);
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
)
233 vout_display_sys_t
*sys
= vd
->sys
;
236 case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE
:
237 /* We have to ignore what is requested */
238 vout_display_SendEventPicturesInvalid(vd
);
241 case VOUT_DISPLAY_RESET_PICTURES
:
243 picture_pool_Delete(sys
->pool
);
246 vd
->fmt
.i_width
= aa_imgwidth(sys
->aa_context
);
247 vd
->fmt
.i_height
= aa_imgheight(sys
->aa_context
);
250 case VOUT_DISPLAY_HIDE_MOUSE
:
251 aa_hidemouse(sys
->aa_context
);
255 msg_Err(vd
, "Unsupported query in vout display aalib");
262 * Proccess pending event
264 static void Manage(vout_display_t
*vd
)
266 vout_display_sys_t
*sys
= vd
->sys
;
269 const int event
= aa_getevent(sys
->aa_context
, 0);
278 aa_getmouse(sys
->aa_context
, &x
, &y
, &button
);
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 */
295 aa_resize(sys
->aa_context
);
296 vout_display_SendEventDisplaySize(vd
,
297 aa_imgwidth(sys
->aa_context
),
298 aa_imgheight(sys
->aa_context
), false);
301 /* TODO keys support to complete */
303 vout_display_SendEventKey(vd
, KEY_UP
);
306 vout_display_SendEventKey(vd
, KEY_DOWN
);
309 vout_display_SendEventKey(vd
, KEY_RIGHT
);
312 vout_display_SendEventKey(vd
, KEY_LEFT
);
315 vout_display_SendEventKey(vd
, KEY_BACKSPACE
);
318 vout_display_SendEventKey(vd
, KEY_ESC
);
321 if (event
>= 0x20 && event
<= 0x7f)
322 vout_display_SendEventKey(vd
, event
);