1 /*****************************************************************************
2 * intf_sdl.c: SDL interface plugin
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: intf_sdl.c,v 1.34 2001/03/02 02:49:11 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"
54 void intf_SDL_Keymap( intf_thread_t * p_intf );
56 /*****************************************************************************
57 * intf_SDLCreate: initialize and create SDL interface
58 *****************************************************************************/
59 int intf_SDLCreate( intf_thread_t *p_intf )
61 /* Check that b_video is set */
62 if( !p_main->b_video )
64 intf_ErrMsg( "error: SDL interface requires a video output thread" );
68 /* Spawn video output thread */
69 p_intf->p_vout = vout_CreateThread( main_GetPszVariable( VOUT_DISPLAY_VAR,
71 main_GetIntVariable( VOUT_WIDTH_VAR,
73 main_GetIntVariable( VOUT_HEIGHT_VAR,
74 VOUT_HEIGHT_DEFAULT ),
77 if( p_intf->p_vout == NULL ) /* error */
79 intf_ErrMsg( "error: can't create video output thread" );
80 free( p_intf->p_sys );
83 intf_SDL_Keymap( p_intf );
87 /*****************************************************************************
88 * intf_SDLDestroy: destroy interface
89 *****************************************************************************/
90 void intf_SDLDestroy( intf_thread_t *p_intf )
92 /* Close input thread, if any (blocking) */
95 input_DestroyThread( p_intf->p_input, NULL );
98 /* Close video output thread, if any (blocking) */
101 vout_DestroyThread( p_intf->p_vout, NULL );
106 /*****************************************************************************
107 * intf_SDLManage: event loop
108 *****************************************************************************/
109 void intf_SDLManage( intf_thread_t *p_intf )
111 SDL_Event event; /* SDL event */
115 while ( SDL_PollEvent(&event) )
119 case SDL_VIDEORESIZE: /* Resizing of window */
120 intf_Msg( "intf: video display resized (%dx%d)", event.resize.w
122 vlc_mutex_lock( &p_intf->p_vout->change_lock );
123 p_intf->p_vout->i_width = event.resize.w;
124 p_intf->p_vout->i_height = event.resize.h;
125 p_intf->p_vout->i_changes |= VOUT_SIZE_CHANGE;
126 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
129 case SDL_KEYDOWN: /* if a key is pressed */
130 i_key = event.key.keysym.sym;
134 case SDLK_f: /* switch to fullscreen */
135 vlc_mutex_lock( &p_intf->p_vout->change_lock );
136 p_intf->p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
137 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
140 case SDLK_y: /* switch to hard YUV */
141 vlc_mutex_lock( &p_intf->p_vout->change_lock );
142 p_intf->p_vout->i_changes |= VOUT_YUV_CHANGE;
143 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
146 /* FIXME : this is temporary */
148 if( p_intf->p_input->stream.control.i_status == PLAYING_S )
150 input_Pause( p_intf->p_input );
154 input_Play( p_intf->p_input );
159 i_rate = p_intf->p_input->stream.control.i_rate/2;
160 if ( i_rate >= MINIMAL_RATE )
162 input_Forward( p_intf->p_input, i_rate );
167 i_rate = p_intf->p_input->stream.control.i_rate*2;
168 if ( i_rate <= MAXIMAL_RATE )
170 /* Compensation of int truncature */
171 if ( i_rate > 500 && i_rate < 1000 )
173 input_Forward( p_intf->p_input, i_rate );
179 input_Seek( p_intf->p_input,
180 p_intf->p_input->stream.i_tell
181 + p_intf->p_input->stream.i_size / 20 );
187 input_Seek( p_intf->p_input,
188 p_intf->p_input->stream.i_tell
189 - p_intf->p_input->stream.i_size / 20 );
193 if( intf_ProcessKey( p_intf, (char )i_key ) )
195 intf_DbgMsg( "unhandled key '%c' (%i)", (char)i_key, i_key );
201 case SDL_MOUSEBUTTONDOWN:
202 if( event.button.button == SDL_BUTTON_MIDDLE )
204 vlc_mutex_lock( &p_intf->p_vout->change_lock );
205 p_intf->p_vout->i_changes |= VOUT_CURSOR_CHANGE;
206 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
211 intf_ProcessKey( p_intf, SDLK_q );
220 void intf_SDL_Keymap(intf_thread_t * p_intf )
222 /* p_intf->p_intf_getKey = intf_getKey; */
223 intf_AssignKey(p_intf, SDLK_q, INTF_KEY_QUIT, 0);
224 intf_AssignKey(p_intf, SDLK_ESCAPE, INTF_KEY_QUIT, 0);
225 /* intf_AssignKey(p_intf,3,'Q'); */
226 intf_AssignKey(p_intf, SDLK_0, INTF_KEY_SET_CHANNEL,0);
227 intf_AssignKey(p_intf, SDLK_1, INTF_KEY_SET_CHANNEL,1);
228 intf_AssignKey(p_intf, SDLK_2, INTF_KEY_SET_CHANNEL,2);
229 intf_AssignKey(p_intf, SDLK_3, INTF_KEY_SET_CHANNEL,3);
230 intf_AssignKey(p_intf, SDLK_4, INTF_KEY_SET_CHANNEL,4);
231 intf_AssignKey(p_intf, SDLK_5, INTF_KEY_SET_CHANNEL,5);
232 intf_AssignKey(p_intf, SDLK_6, INTF_KEY_SET_CHANNEL,6);
233 intf_AssignKey(p_intf, SDLK_7, INTF_KEY_SET_CHANNEL,7);
234 intf_AssignKey(p_intf, SDLK_8, INTF_KEY_SET_CHANNEL,8);
235 intf_AssignKey(p_intf, SDLK_9, INTF_KEY_SET_CHANNEL,9);
236 intf_AssignKey(p_intf, SDLK_PLUS, INTF_KEY_INC_VOLUME, 0);
237 intf_AssignKey(p_intf, SDLK_MINUS, INTF_KEY_DEC_VOLUME, 0);
238 /* Numpad keys support */
239 intf_AssignKey(p_intf, 14, INTF_KEY_INC_VOLUME, 0);
240 intf_AssignKey(p_intf, 13, INTF_KEY_DEC_VOLUME, 0);
242 intf_AssignKey(p_intf, SDLK_m, INTF_KEY_TOGGLE_VOLUME, 0);
243 /* intf_AssignKey(p_intf,'M','M'); */
244 intf_AssignKey(p_intf, SDLK_g, INTF_KEY_DEC_GAMMA, 0);
245 /* intf_AssignKey(p_intf,'G','G'); */
246 intf_AssignKey(p_intf, SDLK_c, INTF_KEY_TOGGLE_GRAYSCALE, 0);
247 intf_AssignKey(p_intf, SDLK_SPACE, INTF_KEY_TOGGLE_INTERFACE, 0);
248 intf_AssignKey(p_intf, SDLK_i, INTF_KEY_TOGGLE_INFO, 0);
249 intf_AssignKey(p_intf, SDLK_s, INTF_KEY_TOGGLE_SCALING, 0);