]> git.sesse.net Git - vlc/blob - plugins/aa/aa.c
video output has better handling of settings. it remembers flags like fullscreen...
[vlc] / plugins / aa / aa.c
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 $
6  *
7  * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <errno.h>                                                 /* ENOMEM */
28 #include <stdlib.h>                                                /* free() */
29 #include <string.h>                                            /* strerror() */
30
31 #include <aalib.h>
32
33 #include <videolan/vlc.h>
34
35 #include "video.h"
36 #include "video_output.h"
37 #include "interface.h"
38
39 /*****************************************************************************
40  * Capabilities defined in the other files.
41  *****************************************************************************/
42 static void vout_getfunctions  ( function_list_t * p_function_list );
43
44 /*****************************************************************************
45  * Build configuration tree.
46  *****************************************************************************/
47 MODULE_CONFIG_START
48 MODULE_CONFIG_STOP
49
50
51 MODULE_INIT_START
52     SET_DESCRIPTION( _("ASCII-art video output module") )
53     ADD_CAPABILITY( VOUT, 10 )
54     ADD_SHORTCUT( "aa" )
55     ADD_SHORTCUT( "aalib" )
56 MODULE_INIT_STOP
57
58
59 MODULE_ACTIVATE_START
60     vout_getfunctions( &p_module->p_functions->vout );
61 MODULE_ACTIVATE_STOP
62
63
64 MODULE_DEACTIVATE_START
65 MODULE_DEACTIVATE_STOP
66
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
74 {
75     struct aa_context*  aa_context;
76     aa_palette          palette;
77     int                 i_width;                     /* width of main window */
78     int                 i_height;                   /* height of main window */
79
80 } vout_sys_t;
81
82 /*****************************************************************************
83  * Local prototypes
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 * );
92
93 static void SetPalette     ( struct vout_thread_s *, u16 *, u16 *, u16 * );
94
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 )
100 {
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;
108 }
109
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 )
116 {
117     /* Allocate structure */
118     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
119     if( p_vout->p_sys == NULL )
120     {
121         intf_ErrMsg("error: %s", strerror(ENOMEM) );
122         return( 1 );
123     }
124
125     /* Don't parse any options, but take $AAOPTS into account */
126     aa_parseoptions( NULL, NULL, NULL, NULL );
127
128     if (!(p_vout->p_sys->aa_context = aa_autoinit(&aa_defparams)))
129     {
130         intf_ErrMsg( "vout error: cannot initialize AA-lib. Sorry" );
131         return( 1 );
132     }
133
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 );
139     return( 0 );
140 }
141
142 /*****************************************************************************
143  * vout_Init: initialize aa video thread output method
144  *****************************************************************************/
145 static int vout_Init( vout_thread_t *p_vout )
146 {
147     int i_index;
148     picture_t *p_pic = NULL;
149
150     I_OUTPUTPICTURES = 0;
151
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;
158
159     /* Find an empty picture slot */
160     for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
161     {
162         if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
163         {
164             p_pic = p_vout->p_picture + i_index;
165             break;
166         }
167     }
168
169     if( p_pic == NULL )
170     {
171         return -1;
172     }
173
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;
180     p_pic->i_planes = 1;
181
182     p_pic->i_status = DESTROYED_PICTURE;
183     p_pic->i_type   = DIRECT_PICTURE;
184
185     PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
186     I_OUTPUTPICTURES++;
187
188     return 0;
189 }
190
191 /*****************************************************************************
192  * vout_End: terminate aa video thread output method
193  *****************************************************************************/
194 static void vout_End( vout_thread_t *p_vout )
195 {
196     ;
197 }
198
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 )
205 {
206     aa_close( p_vout->p_sys->aa_context );
207     free( p_vout->p_sys );
208 }
209
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 )
217 {
218     int event, x, y, b;
219     event = aa_getevent( p_vout->p_sys->aa_context, 0 );
220     switch ( event )
221     {
222     case AA_MOUSE:
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 );
228         }
229         break;
230     case AA_RESIZE:
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 );
235         break;
236     default:
237         break;
238     }
239     return( 0 );
240 }
241
242 /*****************************************************************************
243  * vout_Render: render previously calculated output
244  *****************************************************************************/
245 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
246 {
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 ) );
250 }
251
252 /*****************************************************************************
253  * vout_Display: displays previously rendered output
254  *****************************************************************************/
255 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
256 {
257     /* No need to do anything, the fake direct buffers stay as they are */
258     int i_width, i_height, i_x, i_y;
259
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 );
262
263     aa_flush(p_vout->p_sys->aa_context);
264 }
265
266 /*****************************************************************************
267  * SetPalette: set the 8bpp palette
268  *****************************************************************************/
269 static void SetPalette( vout_thread_t *p_vout, u16 *red, u16 *green, u16 *blue )
270 {
271     int i;
272
273     /* Fill colors with color information */
274     for( i = 0; i < 256; i++ )
275     {
276         aa_setpalette( p_vout->p_sys->palette, 256 -i,
277                        red[ i ], green[ i ], blue[ i ] );
278     }
279 }
280