1 /*****************************************************************************
2 * vout_aa.c: Aa video output display method for testing purposes
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: aa.c,v 1.4 2002/05/27 18:26:31 sam Exp $
7 * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <errno.h> /* ENOMEM */
28 #include <stdlib.h> /* free() */
29 #include <string.h> /* strerror() */
33 #include <videolan/vlc.h>
36 #include "video_output.h"
37 #include "interface.h"
39 /*****************************************************************************
40 * Capabilities defined in the other files.
41 *****************************************************************************/
42 static void vout_getfunctions ( function_list_t * p_function_list );
44 /*****************************************************************************
45 * Build configuration tree.
46 *****************************************************************************/
52 SET_DESCRIPTION( _("ASCII-art video output module") )
53 ADD_CAPABILITY( VOUT, 10 )
55 ADD_SHORTCUT( "aalib" )
60 vout_getfunctions( &p_module->p_functions->vout );
64 MODULE_DEACTIVATE_START
65 MODULE_DEACTIVATE_STOP
67 /*****************************************************************************
68 * vout_sys_t: aa video output method descriptor
69 *****************************************************************************
70 * This structure is part of the video output thread descriptor.
71 * It describes the aa specific properties of an output thread.
72 *****************************************************************************/
73 typedef struct vout_sys_s
75 struct aa_context* aa_context;
77 int i_width; /* width of main window */
78 int i_height; /* height of main window */
82 /*****************************************************************************
84 *****************************************************************************/
85 static int vout_Create ( struct vout_thread_s * );
86 static int vout_Init ( struct vout_thread_s * );
87 static void vout_End ( struct vout_thread_s * );
88 static void vout_Destroy ( struct vout_thread_s * );
89 static int vout_Manage ( struct vout_thread_s * );
90 static void vout_Render ( struct vout_thread_s *, struct picture_s * );
91 static void vout_Display ( struct vout_thread_s *, struct picture_s * );
93 static void SetPalette ( struct vout_thread_s *, u16 *, u16 *, u16 * );
95 /*****************************************************************************
96 * Functions exported as capabilities. They are declared as static so that
97 * we don't pollute the namespace too much.
98 *****************************************************************************/
99 static void vout_getfunctions( function_list_t * p_function_list )
101 p_function_list->functions.vout.pf_create = vout_Create;
102 p_function_list->functions.vout.pf_init = vout_Init;
103 p_function_list->functions.vout.pf_end = vout_End;
104 p_function_list->functions.vout.pf_destroy = vout_Destroy;
105 p_function_list->functions.vout.pf_manage = vout_Manage;
106 p_function_list->functions.vout.pf_render = vout_Render;
107 p_function_list->functions.vout.pf_display = vout_Display;
110 /*****************************************************************************
111 * vout_Create: allocates aa video thread output method
112 *****************************************************************************
113 * This function allocates and initializes a aa vout method.
114 *****************************************************************************/
115 static int vout_Create( vout_thread_t *p_vout )
117 /* Allocate structure */
118 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
119 if( p_vout->p_sys == NULL )
121 intf_ErrMsg("error: %s", strerror(ENOMEM) );
125 /* Don't parse any options, but take $AAOPTS into account */
126 aa_parseoptions( NULL, NULL, NULL, NULL );
128 if (!(p_vout->p_sys->aa_context = aa_autoinit(&aa_defparams)))
130 intf_ErrMsg( "vout error: cannot initialize AA-lib. Sorry" );
134 p_vout->p_sys->i_width = aa_imgwidth(p_vout->p_sys->aa_context);
135 p_vout->p_sys->i_height = aa_imgheight(p_vout->p_sys->aa_context);
136 aa_autoinitkbd( p_vout->p_sys->aa_context, 0 );
137 aa_autoinitmouse( p_vout->p_sys->aa_context, AA_MOUSEPRESSMASK );
138 aa_hidemouse( p_vout->p_sys->aa_context );
142 /*****************************************************************************
143 * vout_Init: initialize aa video thread output method
144 *****************************************************************************/
145 static int vout_Init( vout_thread_t *p_vout )
148 picture_t *p_pic = NULL;
150 I_OUTPUTPICTURES = 0;
152 p_vout->output.i_chroma = FOURCC_RGB2;
153 p_vout->output.i_width = p_vout->p_sys->i_width;
154 p_vout->output.i_height = p_vout->p_sys->i_height;
155 p_vout->output.i_aspect = p_vout->p_sys->i_width
156 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
157 p_vout->output.pf_setpalette = SetPalette;
159 /* Find an empty picture slot */
160 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
162 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
164 p_pic = p_vout->p_picture + i_index;
174 /* Allocate the picture */
175 p_pic->p->p_pixels = aa_image( p_vout->p_sys->aa_context );
176 p_pic->p->i_pixel_bytes = 1;
177 p_pic->p->i_lines = p_vout->p_sys->i_height;
178 p_pic->p->i_pitch = p_vout->p_sys->i_width;
179 p_pic->p->b_margin = 0;
182 p_pic->i_status = DESTROYED_PICTURE;
183 p_pic->i_type = DIRECT_PICTURE;
185 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
191 /*****************************************************************************
192 * vout_End: terminate aa video thread output method
193 *****************************************************************************/
194 static void vout_End( vout_thread_t *p_vout )
199 /*****************************************************************************
200 * vout_Destroy: destroy aa video thread output method
201 *****************************************************************************
202 * Terminate an output method created by AaCreateOutputMethod
203 *****************************************************************************/
204 static void vout_Destroy( vout_thread_t *p_vout )
206 aa_close( p_vout->p_sys->aa_context );
207 free( p_vout->p_sys );
210 /*****************************************************************************
211 * vout_Manage: handle aa events
212 *****************************************************************************
213 * This function should be called regularly by video output thread. It manages
214 * console events. It returns a non null value on error.
215 *****************************************************************************/
216 static int vout_Manage( vout_thread_t *p_vout )
219 event = aa_getevent( p_vout->p_sys->aa_context, 0 );
223 aa_getmouse( p_vout->p_sys->aa_context, &x, &y, &b );
224 if ( b & AA_BUTTON3 ) {
225 vlc_mutex_lock( &p_main->p_intf->change_lock );
226 p_main->p_intf->b_menu_change = 1;
227 vlc_mutex_unlock( &p_main->p_intf->change_lock );
231 p_vout->i_changes |= VOUT_SIZE_CHANGE;
232 aa_resize( p_vout->p_sys->aa_context );
233 p_vout->p_sys->i_width = aa_imgwidth( p_vout->p_sys->aa_context );
234 p_vout->p_sys->i_height = aa_imgheight( p_vout->p_sys->aa_context );
242 /*****************************************************************************
243 * vout_Render: render previously calculated output
244 *****************************************************************************/
245 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
247 aa_fastrender( p_vout->p_sys->aa_context, 0, 0,
248 aa_imgwidth( p_vout->p_sys->aa_context ),
249 aa_imgheight( p_vout->p_sys->aa_context ) );
252 /*****************************************************************************
253 * vout_Display: displays previously rendered output
254 *****************************************************************************/
255 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
257 /* No need to do anything, the fake direct buffers stay as they are */
258 int i_width, i_height, i_x, i_y;
260 vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
261 &i_x, &i_y, &i_width, &i_height );
263 aa_flush(p_vout->p_sys->aa_context);
266 /*****************************************************************************
267 * SetPalette: set the 8bpp palette
268 *****************************************************************************/
269 static void SetPalette( vout_thread_t *p_vout, u16 *red, u16 *green, u16 *blue )
273 /* Fill colors with color information */
274 for( i = 0; i < 256; i++ )
276 aa_setpalette( p_vout->p_sys->palette, 256 -i,
277 red[ i ], green[ i ], blue[ i ] );