1 /*****************************************************************************
2 * intf_sdl.c: SDL interface plugin
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: intf_sdl.c,v 1.23 2001/01/15 12:42:57 reno Exp $
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 *****************************************************************************/
32 #include <SDL/SDL.h> /* for all the SDL stuff */
40 #include "stream_control.h"
41 #include "input_ext-intf.h"
44 #include "video_output.h"
47 #include "interface.h"
49 #include "keystrokes.h"
53 typedef struct vout_sys_s
57 SDL_Surface * p_display; /* display device */
58 SDL_Overlay * p_overlay;
59 boolean_t b_fullscreen;
60 boolean_t b_reopen_display;
61 boolean_t b_toggle_fullscreen;
63 /* Buffers informations */
68 void intf_SDL_Keymap( intf_thread_t * p_intf );
69 void intf_SDL_Resize( intf_thread_t * p_intf, int width, int height );
70 void intf_SDL_Fullscreen(intf_thread_t * p_intf);
71 void intf_SDL_YUVSwitch(intf_thread_t * p_intf);
74 /*****************************************************************************
75 * intf_SDLCreate: initialize and create SDL interface
76 *****************************************************************************/
77 int intf_SDLCreate( intf_thread_t *p_intf )
79 /* Check that b_video is set */
80 if( !p_main->b_video )
82 intf_ErrMsg( "error: SDL interface requires a video output thread" );
86 /* Spawn video output thread */
87 p_intf->p_vout = vout_CreateThread( main_GetPszVariable( VOUT_DISPLAY_VAR,
89 main_GetIntVariable( VOUT_WIDTH_VAR,
91 main_GetIntVariable( VOUT_HEIGHT_VAR,
92 VOUT_HEIGHT_DEFAULT ),
95 if( p_intf->p_vout == NULL ) /* error */
97 intf_ErrMsg( "error: can't create video output thread" );
98 free( p_intf->p_sys );
101 intf_SDL_Keymap( p_intf );
105 /*****************************************************************************
106 * intf_SDLDestroy: destroy interface
107 *****************************************************************************/
108 void intf_SDLDestroy( intf_thread_t *p_intf )
110 /* Close input thread, if any (blocking) */
111 if( p_intf->p_input )
113 input_DestroyThread( p_intf->p_input, NULL );
116 /* Close video output thread, if any (blocking) */
119 vout_DestroyThread( p_intf->p_vout, NULL );
124 /*****************************************************************************
125 * intf_SDLManage: event loop
126 *****************************************************************************/
127 void intf_SDLManage( intf_thread_t *p_intf )
129 SDL_Event event; /* SDL event */
132 while ( SDL_PollEvent(&event) )
134 i_key = event.key.keysym.sym; /* forward it */
136 switch (event.type) {
137 case SDL_VIDEORESIZE: /* Resizing of window */
138 intf_SDL_Resize( p_intf, event.resize.w, event.resize.h );
140 case SDL_KEYDOWN: /* if a key is pressed */
142 /* switch to fullscreen */
144 intf_SDL_Fullscreen(p_intf);
147 intf_SDL_YUVSwitch(p_intf);
150 if( intf_ProcessKey( p_intf, (char ) i_key ) )
152 intf_DbgMsg( "unhandled key '%c' (%i)",
153 (char) i_key, i_key );
159 intf_ProcessKey( p_intf, SDLK_q );
167 void intf_SDL_Resize( intf_thread_t * p_intf, int width, int height )
169 intf_Msg( "intf: video display resized (%dx%d)", width, height );
170 vlc_mutex_lock( &p_intf->p_vout->change_lock );
171 p_intf->p_vout->p_sys->i_width = width;
172 p_intf->p_vout->p_sys->i_height = height;
173 p_intf->p_vout->p_sys->b_reopen_display = 1;
174 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
177 void intf_SDL_YUVSwitch(intf_thread_t * p_intf)
179 vlc_mutex_lock( &p_intf->p_vout->change_lock );
180 p_intf->p_vout->b_need_render = 1 - p_intf->p_vout->b_need_render;
181 intf_DbgMsg( "need render now : '%d'",p_intf->p_vout->b_need_render);
182 p_intf->p_vout->p_sys->b_reopen_display = 1;
183 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
185 void intf_SDL_Fullscreen(intf_thread_t * p_intf)
187 vlc_mutex_lock( &p_intf->p_vout->change_lock );
188 p_intf->p_vout->p_sys->b_fullscreen = 1-p_intf->p_vout->p_sys->b_fullscreen;
189 p_intf->p_vout->p_sys->b_toggle_fullscreen = 1;
190 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
193 void intf_SDL_Keymap(intf_thread_t * p_intf )
195 /* p_intf->p_intf_getKey = intf_getKey; */
196 intf_AssignKey(p_intf, SDLK_q, INTF_KEY_QUIT, 0);
197 intf_AssignKey(p_intf, SDLK_ESCAPE, INTF_KEY_QUIT, 0);
198 /* intf_AssignKey(p_intf,3,'Q'); */
199 intf_AssignKey(p_intf, SDLK_0, INTF_KEY_SET_CHANNEL,0);
200 intf_AssignKey(p_intf, SDLK_1, INTF_KEY_SET_CHANNEL,1);
201 intf_AssignKey(p_intf, SDLK_2, INTF_KEY_SET_CHANNEL,2);
202 intf_AssignKey(p_intf, SDLK_3, INTF_KEY_SET_CHANNEL,3);
203 intf_AssignKey(p_intf, SDLK_4, INTF_KEY_SET_CHANNEL,4);
204 intf_AssignKey(p_intf, SDLK_5, INTF_KEY_SET_CHANNEL,5);
205 intf_AssignKey(p_intf, SDLK_6, INTF_KEY_SET_CHANNEL,6);
206 intf_AssignKey(p_intf, SDLK_7, INTF_KEY_SET_CHANNEL,7);
207 intf_AssignKey(p_intf, SDLK_8, INTF_KEY_SET_CHANNEL,8);
208 intf_AssignKey(p_intf, SDLK_9, INTF_KEY_SET_CHANNEL,9);
209 intf_AssignKey(p_intf, SDLK_PLUS, INTF_KEY_INC_VOLUME, 0);
210 intf_AssignKey(p_intf, SDLK_MINUS, INTF_KEY_DEC_VOLUME, 0);
211 intf_AssignKey(p_intf, SDLK_m, INTF_KEY_TOGGLE_VOLUME, 0);
212 /* intf_AssignKey(p_intf,'M','M'); */
213 intf_AssignKey(p_intf, SDLK_g, INTF_KEY_DEC_GAMMA, 0);
214 /* intf_AssignKey(p_intf,'G','G'); */
215 intf_AssignKey(p_intf, SDLK_c, INTF_KEY_TOGGLE_GRAYSCALE, 0);
216 intf_AssignKey(p_intf, SDLK_SPACE, INTF_KEY_TOGGLE_INTERFACE, 0);
217 intf_AssignKey(p_intf, SDLK_i, INTF_KEY_TOGGLE_INFO, 0);
218 intf_AssignKey(p_intf, SDLK_s, INTF_KEY_TOGGLE_SCALING, 0);