]> git.sesse.net Git - vlc/blob - plugins/sdl/intf_sdl.c
* More consistency in the p_input->stream management.
[vlc] / plugins / sdl / intf_sdl.c
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 $
6  *
7  * Authors:
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 "defs.h"
28
29 #include <errno.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <SDL/SDL.h>                                /* for all the SDL stuff */
33
34 #include "config.h"
35 #include "common.h"
36 #include "threads.h"
37 #include "mtime.h"
38 #include "plugins.h"
39
40 #include "stream_control.h"
41 #include "input_ext-intf.h"
42
43 #include "video.h"
44 #include "video_output.h"
45
46
47 #include "interface.h"
48 #include "intf_msg.h"
49 #include "keystrokes.h"
50
51 #include "main.h"
52
53 /* local prototype */
54 void intf_SDL_Keymap( intf_thread_t * p_intf );
55
56 /*****************************************************************************
57  * intf_SDLCreate: initialize and create SDL interface
58  *****************************************************************************/
59 int intf_SDLCreate( intf_thread_t *p_intf )
60 {
61     /* Check that b_video is set */
62     if( !p_main->b_video )
63     {
64         intf_ErrMsg( "error: SDL interface requires a video output thread" );
65         return( 1 );
66     }
67
68     /* Spawn video output thread */
69     p_intf->p_vout = vout_CreateThread( main_GetPszVariable( VOUT_DISPLAY_VAR,
70                                                              NULL), 0,
71                                         main_GetIntVariable( VOUT_WIDTH_VAR,
72                                                          VOUT_WIDTH_DEFAULT ),
73                                         main_GetIntVariable( VOUT_HEIGHT_VAR,
74                                                         VOUT_HEIGHT_DEFAULT ),
75                                         NULL, 0, NULL );
76
77     if( p_intf->p_vout == NULL )                                  /* error */
78     {
79         intf_ErrMsg( "error: can't create video output thread" );
80         free( p_intf->p_sys );
81         return( 1 );
82     }
83     intf_SDL_Keymap( p_intf );
84     return( 0 );
85 }
86
87 /*****************************************************************************
88  * intf_SDLDestroy: destroy interface
89  *****************************************************************************/
90 void intf_SDLDestroy( intf_thread_t *p_intf )
91 {
92     /* Close input thread, if any (blocking) */
93     if( p_intf->p_input )
94     {
95         input_DestroyThread( p_intf->p_input, NULL );
96     }
97
98     /* Close video output thread, if any (blocking) */
99     if( p_intf->p_vout )
100     {
101         vout_DestroyThread( p_intf->p_vout, NULL );
102     }
103 }
104
105
106 /*****************************************************************************
107  * intf_SDLManage: event loop
108  *****************************************************************************/
109 void intf_SDLManage( intf_thread_t *p_intf )
110 {
111     SDL_Event event;                                            /* SDL event */
112     Uint8   i_key;
113     int     i_rate;
114  
115     while ( SDL_PollEvent(&event) )
116     {
117         switch (event.type)
118         {
119         case SDL_VIDEORESIZE:                           /* Resizing of window */
120             intf_Msg( "intf: video display resized (%dx%d)", event.resize.w
121                                                            , event.resize.h ); 
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 );
127             break;
128         
129         case SDL_KEYDOWN:                              /* if a key is pressed */
130             i_key = event.key.keysym.sym;
131                
132             switch(i_key) 
133             {
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 );
138                 break;
139                 
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 );
144                 break; 
145
146             /* FIXME : this is temporary */
147             case SDLK_p:
148                 if( p_intf->p_input->stream.control.i_status == PLAYING_S )
149                 {
150                     input_Pause( p_intf->p_input );
151                 }
152                 else
153                 {
154                     input_Play( p_intf->p_input );
155                 }
156                 break;
157
158             case SDLK_a:
159                 i_rate = p_intf->p_input->stream.control.i_rate/2;
160                 if ( i_rate >= MINIMAL_RATE )
161                 {
162                     input_Forward( p_intf->p_input, i_rate );
163                 }
164                 break;
165
166             case SDLK_z:
167                 i_rate = p_intf->p_input->stream.control.i_rate*2;
168                 if ( i_rate <= MAXIMAL_RATE )
169                 {
170                     /* Compensation of int truncature */
171                     if ( i_rate > 500 && i_rate < 1000 )
172                         i_rate = 1000;
173                     input_Forward( p_intf->p_input, i_rate );
174                 }
175                 break;
176
177             case SDLK_j:
178                 /* Jump forwards */
179                 input_Seek( p_intf->p_input,
180                             p_intf->p_input->stream.i_tell
181                              + p_intf->p_input->stream.i_size / 20 );
182                                                            /* gabuzomeu */
183                 break;
184
185             case SDLK_b:
186                 /* Jump backwards */
187                 input_Seek( p_intf->p_input,
188                             p_intf->p_input->stream.i_tell
189                              - p_intf->p_input->stream.i_size / 20 );
190                 break;
191
192             default:
193                 if( intf_ProcessKey( p_intf, (char )i_key ) )
194                 {
195                    intf_DbgMsg( "unhandled key '%c' (%i)", (char)i_key, i_key );
196                 }
197                 break;
198             }
199             break;
200             
201         case SDL_MOUSEBUTTONDOWN:
202             if( event.button.button == SDL_BUTTON_MIDDLE )
203             {
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 );
207             }                                       
208             break;
209             
210         case SDL_QUIT:
211             intf_ProcessKey( p_intf, SDLK_q );
212             break;
213        
214         default:
215             break;
216         }
217     }
218 }
219
220 void intf_SDL_Keymap(intf_thread_t * p_intf )
221 {
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);
241     
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);
250
251 }