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.1 2002/03/19 14:00:50 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"
38 #define AA_MAX_DIRECTBUFFERS 1
40 /*****************************************************************************
41 * Capabilities defined in the other files.
42 *****************************************************************************/
43 static void vout_getfunctions ( function_list_t * p_function_list );
45 /*****************************************************************************
46 * Build configuration tree.
47 *****************************************************************************/
53 SET_DESCRIPTION( "ASCII-art video output module" )
54 ADD_CAPABILITY( VOUT, 10 )
56 ADD_SHORTCUT( "aalib" )
61 vout_getfunctions( &p_module->p_functions->vout );
65 MODULE_DEACTIVATE_START
66 MODULE_DEACTIVATE_STOP
68 /*****************************************************************************
69 * vout_sys_t: aa video output method descriptor
70 *****************************************************************************
71 * This structure is part of the video output thread descriptor.
72 * It describes the aa specific properties of an output thread.
73 *****************************************************************************/
74 typedef struct vout_sys_s
76 struct aa_context* aa_context;
78 int i_width; /* width of main window */
79 int i_height; /* height of main window */
83 /*****************************************************************************
85 *****************************************************************************/
86 static int vout_Create ( struct vout_thread_s * );
87 static int vout_Init ( struct vout_thread_s * );
88 static void vout_End ( struct vout_thread_s * );
89 static void vout_Destroy ( struct vout_thread_s * );
90 static int vout_Manage ( struct vout_thread_s * );
91 static void vout_Render ( struct vout_thread_s *, struct picture_s * );
92 static void vout_Display ( struct vout_thread_s *, struct picture_s * );
94 static int NewPicture ( struct vout_thread_s *, struct picture_s * );
95 static void SetPalette ( struct vout_thread_s *, u16 *, u16 *, u16 * );
97 /*****************************************************************************
98 * Functions exported as capabilities. They are declared as static so that
99 * we don't pollute the namespace too much.
100 *****************************************************************************/
101 static void vout_getfunctions( function_list_t * p_function_list )
103 p_function_list->functions.vout.pf_create = vout_Create;
104 p_function_list->functions.vout.pf_init = vout_Init;
105 p_function_list->functions.vout.pf_end = vout_End;
106 p_function_list->functions.vout.pf_destroy = vout_Destroy;
107 p_function_list->functions.vout.pf_manage = vout_Manage;
108 p_function_list->functions.vout.pf_render = vout_Render;
109 p_function_list->functions.vout.pf_display = vout_Display;
112 /*****************************************************************************
113 * vout_Create: allocates aa video thread output method
114 *****************************************************************************
115 * This function allocates and initializes a aa vout method.
116 *****************************************************************************/
117 static int vout_Create( vout_thread_t *p_vout )
119 /* Allocate structure */
120 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
121 if( p_vout->p_sys == NULL )
123 intf_ErrMsg("error: %s", strerror(ENOMEM) );
127 if (!(p_vout->p_sys->aa_context = aa_autoinit(&aa_defparams))) {
128 intf_ErrMsg("error: Cannot initialize AA-lib. Sorry");
131 p_vout->p_sys->i_width = aa_imgwidth(p_vout->p_sys->aa_context);
132 p_vout->p_sys->i_height = aa_imgheight(p_vout->p_sys->aa_context);
137 /*****************************************************************************
138 * vout_Init: initialize aa video thread output method
139 *****************************************************************************/
140 static int vout_Init( vout_thread_t *p_vout )
145 I_OUTPUTPICTURES = 0;
147 p_vout->output.i_chroma = FOURCC_RGB2;
148 p_vout->output.i_width = p_vout->p_sys->i_width;
149 p_vout->output.i_height = p_vout->p_sys->i_height;
150 p_vout->output.i_aspect = p_vout->p_sys->i_width
151 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
152 p_vout->output.pf_setpalette = SetPalette;
155 /* Try to initialize AA_MAX_DIRECTBUFFERS direct buffers */
156 while( I_OUTPUTPICTURES < AA_MAX_DIRECTBUFFERS )
160 /* Find an empty picture slot */
161 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
163 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
165 p_pic = p_vout->p_picture + i_index;
170 /* Allocate the picture */
171 if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
176 p_pic->i_status = DESTROYED_PICTURE;
177 p_pic->i_type = DIRECT_PICTURE;
179 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
187 /*****************************************************************************
188 * vout_End: terminate aa video thread output method
189 *****************************************************************************/
190 static void vout_End( vout_thread_t *p_vout )
195 /*****************************************************************************
196 * vout_Destroy: destroy aa video thread output method
197 *****************************************************************************
198 * Terminate an output method created by AaCreateOutputMethod
199 *****************************************************************************/
200 static void vout_Destroy( vout_thread_t *p_vout )
202 aa_close(p_vout->p_sys->aa_context);
203 free( p_vout->p_sys );
206 /*****************************************************************************
207 * vout_Manage: handle aa events
208 *****************************************************************************
209 * This function should be called regularly by video output thread. It manages
210 * console events. It returns a non null value on error.
211 *****************************************************************************/
212 static int vout_Manage( vout_thread_t *p_vout )
217 /*****************************************************************************
218 * vout_Render: render previously calculated output
219 *****************************************************************************/
220 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
225 /*****************************************************************************
226 * vout_Display: displays previously rendered output
227 *****************************************************************************/
228 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
230 /* No need to do anything, the fake direct buffers stay as they are */
231 int i_width, i_height, i_x, i_y;
233 vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
234 &i_x, &i_y, &i_width, &i_height );
235 // p_vout->p_sys->aa_context->imagebuffer = p_pic->p_data;
236 aa_fastrender(p_vout->p_sys->aa_context, 0, 0, aa_scrwidth(p_vout->p_sys->aa_context),
237 aa_scrheight(p_vout->p_sys->aa_context));
238 aa_flush(p_vout->p_sys->aa_context);
242 /*****************************************************************************
243 * NewPicture: allocate a picture
244 *****************************************************************************
245 * Returns 0 on success, -1 otherwise
246 *****************************************************************************/
247 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
249 p_pic->p->p_pixels = aa_image(p_vout->p_sys->aa_context);
250 p_pic->p->i_pixel_bytes = 1;
251 p_pic->p->i_lines = p_vout->p_sys->i_height;
252 p_pic->p->i_pitch = p_vout->p_sys->i_width;
253 p_pic->p->b_margin = 0;
259 /*****************************************************************************
260 * SetPalette: set the 8bpp palette
261 *****************************************************************************/
262 static void SetPalette( vout_thread_t *p_vout, u16 *red, u16 *green, u16 *blue )
266 /* Fill colors with color information */
267 for( i = 0; i < 256; i++ )
269 aa_setpalette( p_vout->p_sys->palette, 256 -i,
270 red[ i ], green[ i ], blue[ i ] );