Changeset 2fa6c9ce280b037c058eed166bfc51e7c70c5d14
- Timestamp:
- 19/08/02 13:13:45 (6 years ago)
- git-parent:
- Files:
-
- include/vlc/vlc.h (modified) (3 diffs)
- src/libvlc.c (modified) (15 diffs)
- src/misc/cpu.c (modified) (17 diffs)
- src/vlc.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
include/vlc/vlc.h
r005be13 r2fa6c9c 3 3 ***************************************************************************** 4 4 * Copyright (C) 1998, 1999, 2000 VideoLAN 5 * $Id: vlc.h,v 1. 8 2002/08/14 17:06:53sam Exp $5 * $Id: vlc.h,v 1.9 2002/08/19 11:13:44 sam Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or modify … … 115 115 vlc_error_t vlc_init ( int, char *[] ); 116 116 vlc_error_t vlc_run ( void ); 117 vlc_error_t vlc_die ( void ); 117 118 vlc_error_t vlc_stop ( void ); 118 119 vlc_error_t vlc_end ( void ); … … 130 131 vlc_error_t vlc_init_r ( vlc_t *, int, char *[] ); 131 132 vlc_error_t vlc_run_r ( vlc_t * ); 133 vlc_error_t vlc_die_r ( vlc_t * ); 132 134 vlc_error_t vlc_stop_r ( vlc_t * ); 133 135 vlc_error_t vlc_end_r ( vlc_t * ); src/libvlc.c
r3dff442 r2fa6c9c 3 3 ***************************************************************************** 4 4 * Copyright (C) 1998-2002 VideoLAN 5 * $Id: libvlc.c,v 1.2 7 2002/08/18 13:49:20sam Exp $5 * $Id: libvlc.c,v 1.28 2002/08/19 11:13:45 sam Exp $ 6 6 * 7 7 * Authors: Vincent Seguin <seguin@via.ecp.fr> … … 38 38 #include <string.h> /* strerror() */ 39 39 #include <stdlib.h> /* free() */ 40 #include <signal.h> /* SIGHUP, SIGINT, SIGKILL */41 40 42 41 #include <vlc/vlc.h> … … 103 102 static void Version ( void ); 104 103 105 #ifndef WIN32106 static void InitSignalHandler ( void );107 static void FatalSignalHandler ( int i_signal );108 #endif109 110 104 #ifdef WIN32 111 105 static void ShowConsole ( void ); … … 116 110 ***************************************************************************** 117 111 * This function allocates a vlc_t structure and returns NULL in case of 118 * failure. Also, the thread system and the signal handlers areinitialized.112 * failure. Also, the thread system is initialized. 119 113 *****************************************************************************/ 120 114 vlc_error_t vlc_create( void ) 121 115 { 122 vlc_t * p_vlc = vlc_create_r(); 123 return p_vlc ? VLC_SUCCESS : VLC_EGENERIC; 116 vlc_t * p_vlc; 117 vlc_bool_t b_failed = VLC_FALSE; 118 119 /* This gives us a rather good protection against concurrent calls, but 120 * an additional check will be necessary for complete thread safety. */ 121 if( i_vlc ) 122 { 123 return VLC_EGENERIC; 124 } 125 126 p_vlc = vlc_create_r(); 127 128 if( p_vlc == NULL ) 129 { 130 return VLC_EGENERIC; 131 } 132 133 /* We have created an object, which ensures us that p_global_lock has 134 * been properly initialized. We can now atomically check that we are 135 * the only p_vlc object. */ 136 vlc_mutex_lock( p_vlc->p_global_lock ); 137 if( i_vlc != 1 ) 138 { 139 b_failed = VLC_TRUE; 140 } 141 vlc_mutex_unlock( p_vlc->p_global_lock ); 142 143 /* There can be only one */ 144 if( b_failed ) 145 { 146 vlc_destroy_r( p_vlc ); 147 return VLC_EGENERIC; 148 } 149 150 return VLC_SUCCESS; 124 151 } 125 152 … … 149 176 vlc_mutex_init( p_vlc, &p_vlc->config_lock ); 150 177 vlc_mutex_init( p_vlc, &p_vlc->structure_lock ); 151 152 /* Set signal handling policy for all threads */153 #ifndef WIN32154 InitSignalHandler( );155 #endif156 178 157 179 /* Store our newly allocated structure in the global list */ … … 181 203 vlc_error_t vlc_init( int i_argc, char *ppsz_argv[] ) 182 204 { 183 return vlc_init_r( ( i_vlc == 1 ) ? *pp_vlc: NULL, i_argc, ppsz_argv );205 return vlc_init_r( ( i_vlc == 1 ) ? pp_vlc[0] : NULL, i_argc, ppsz_argv ); 184 206 } 185 207 … … 197 219 return VLC_ESTATUS; 198 220 } 199 200 fprintf( stderr, COPYRIGHT_MESSAGE "\n" );201 221 202 222 /* Guess what CPU we have */ … … 512 532 vlc_error_t vlc_run( void ) 513 533 { 514 return vlc_run_r( ( i_vlc == 1 ) ? *pp_vlc: NULL );534 return vlc_run_r( ( i_vlc == 1 ) ? pp_vlc[0] : NULL ); 515 535 } 516 536 … … 540 560 vlc_error_t vlc_add_intf( const char *psz_module, vlc_bool_t b_block ) 541 561 { 542 return vlc_add_intf_r( ( i_vlc == 1 ) ? *pp_vlc: NULL,562 return vlc_add_intf_r( ( i_vlc == 1 ) ? pp_vlc[0] : NULL, 543 563 psz_module, b_block ); 544 564 } … … 603 623 vlc_error_t vlc_stop( void ) 604 624 { 605 return vlc_stop_r( ( i_vlc == 1 ) ? *pp_vlc: NULL );625 return vlc_stop_r( ( i_vlc == 1 ) ? pp_vlc[0] : NULL ); 606 626 } 607 627 … … 680 700 vlc_error_t vlc_end( void ) 681 701 { 682 return vlc_end_r( ( i_vlc == 1 ) ? *pp_vlc: NULL );702 return vlc_end_r( ( i_vlc == 1 ) ? pp_vlc[0] : NULL ); 683 703 } 684 704 … … 738 758 vlc_error_t vlc_destroy( void ) 739 759 { 740 return vlc_destroy_r( ( i_vlc == 1 ) ? *pp_vlc: NULL );760 return vlc_destroy_r( ( i_vlc == 1 ) ? pp_vlc[0] : NULL ); 741 761 } 742 762 … … 803 823 } 804 824 825 /***************************************************************************** 826 * vlc_die: ask vlc to die. 827 ***************************************************************************** 828 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other 829 * task. It is your duty to call vlc_end and vlc_destroy afterwards. 830 *****************************************************************************/ 831 vlc_error_t vlc_die( void ) 832 { 833 return vlc_die_r( ( i_vlc == 1 ) ? pp_vlc[0] : NULL ); 834 } 835 836 vlc_error_t vlc_die_r( vlc_t *p_vlc ) 837 { 838 if( !p_vlc ) 839 { 840 fprintf( stderr, "error: invalid status (!EXIST)\n" ); 841 return VLC_ESTATUS; 842 } 843 844 p_vlc->b_die = VLC_TRUE; 845 846 return VLC_SUCCESS; 847 } 848 849 /***************************************************************************** 850 * vlc_status: return the current vlc status. 851 ***************************************************************************** 852 * This function returns the current value of p_vlc->i_status. 853 *****************************************************************************/ 805 854 vlc_status_t vlc_status( void ) 806 855 { 807 return vlc_status_r( ( i_vlc == 1 ) ? *pp_vlc: NULL );856 return vlc_status_r( ( i_vlc == 1 ) ? pp_vlc[0] : NULL ); 808 857 } 809 858 … … 818 867 } 819 868 869 /***************************************************************************** 870 * vlc_add_target: adds a target for playing. 871 ***************************************************************************** 872 * This function adds psz_target to the current playlist. If a playlist does 873 * not exist, it will create one. 874 *****************************************************************************/ 820 875 vlc_error_t vlc_add_target( const char *psz_target, int i_mode, int i_pos ) 821 876 { 822 return vlc_add_target_r( ( i_vlc == 1 ) ? *pp_vlc: NULL,877 return vlc_add_target_r( ( i_vlc == 1 ) ? pp_vlc[0] : NULL, 823 878 psz_target, i_mode, i_pos ); 824 879 } … … 1178 1233 #endif 1179 1234 1180 #ifndef WIN321181 /*****************************************************************************1182 * InitSignalHandler: system signal handler initialization1183 *****************************************************************************1184 * Set the signal handlers. SIGTERM is not intercepted, because we need at1185 * at least a method to kill the program when all other methods failed, and1186 * when we don't want to use SIGKILL.1187 *****************************************************************************/1188 static void InitSignalHandler( void )1189 {1190 /* Termination signals */1191 signal( SIGINT, FatalSignalHandler );1192 signal( SIGHUP, FatalSignalHandler );1193 signal( SIGQUIT, FatalSignalHandler );1194 1195 /* Other signals */1196 signal( SIGALRM, SIG_IGN );1197 signal( SIGPIPE, SIG_IGN );1198 }1199 1200 /*****************************************************************************1201 * FatalSignalHandler: system signal handler1202 *****************************************************************************1203 * This function is called when a fatal signal is received by the program.1204 * It tries to end the program in a clean way.1205 *****************************************************************************/1206 static void FatalSignalHandler( int i_signal )1207 {1208 static mtime_t abort_time = 0;1209 static volatile vlc_bool_t b_die = VLC_FALSE;1210 int i_index;1211 1212 /* Once a signal has been trapped, the termination sequence will be1213 * armed and following signals will be ignored to avoid sending messages1214 * to an interface having been destroyed */1215 1216 if( !b_die )1217 {1218 b_die = VLC_TRUE;1219 abort_time = mdate();1220 1221 fprintf( stderr, "signal %d received, terminating libvlc - do it "1222 "again in case your process gets stuck\n", i_signal );1223 1224 /* Try to terminate everything - this is done by requesting the end of1225 * all the p_vlc structures */1226 for( i_index = 0 ; i_index < i_vlc ; i_index++ )1227 {1228 /* Acknowledge the signal received */1229 pp_vlc[ i_index ]->b_die = VLC_TRUE;1230 }1231 }1232 else if( mdate() > abort_time + 1000000 )1233 {1234 /* If user asks again 1 second later, die badly */1235 signal( SIGINT, SIG_IGN );1236 signal( SIGHUP, SIG_IGN );1237 signal( SIGQUIT, SIG_IGN );1238 1239 fprintf( stderr, "user insisted too much, dying badly\n" );1240 1241 exit( 1 );1242 }1243 }1244 #endif1245 src/misc/cpu.c
rb9e9cb4 r2fa6c9c 3 3 ***************************************************************************** 4 4 * Copyright (C) 1998-2002 VideoLAN 5 * $Id: cpu.c,v 1. 4 2002/06/07 14:30:41sam Exp $5 * $Id: cpu.c,v 1.5 2002/08/19 11:13:45 sam Exp $ 6 6 * 7 7 * Authors: Samuel Hocevar <sam@zoy.org> … … 44 44 * Local prototypes 45 45 *****************************************************************************/ 46 static void IllegalSignalHandler( int i_signal ); 46 static void SigHandler ( int ); 47 static u32 Capabilities ( vlc_object_t * ); 47 48 48 49 /***************************************************************************** … … 56 57 57 58 /***************************************************************************** 58 * CPUCapabilities: list the processors MMX support and other capabilities 59 * CPUCapabilities: get the CPU capabilities 60 ***************************************************************************** 61 * This function is a wrapper around Capabilities(). 62 *****************************************************************************/ 63 u32 __CPUCapabilities( vlc_object_t *p_this ) 64 { 65 u32 i_capabilities; 66 67 vlc_mutex_lock( p_this->p_vlc->p_global_lock ); 68 i_capabilities = Capabilities( p_this ); 69 vlc_mutex_unlock( p_this->p_vlc->p_global_lock ); 70 71 return i_capabilities; 72 } 73 74 /***************************************************************************** 75 * Capabilities: list the processors MMX support and other capabilities 59 76 ***************************************************************************** 60 77 * This function is called to list extensions the CPU may have. 61 78 *****************************************************************************/ 62 u32 __CPUCapabilities( vlc_object_t *p_this )79 static u32 Capabilities( vlc_object_t *p_this ) 63 80 { 64 81 volatile u32 i_capabilities = CPU_CAPABILITY_NONE; … … 113 130 : "cc" ); 114 131 132 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) 133 sighandler_t pf_sigill = signal( SIGILL, SigHandler ); 134 # endif 135 115 136 i_capabilities |= CPU_CAPABILITY_FPU; 116 117 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )118 signal( SIGILL, IllegalSignalHandler );119 # endif120 137 121 138 /* test for a 486 CPU */ … … 139 156 { 140 157 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) 141 signal( SIGILL, NULL);158 signal( SIGILL, pf_sigill ); 142 159 # endif 143 160 return i_capabilities; … … 152 169 { 153 170 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) 154 signal( SIGILL, NULL);171 signal( SIGILL, pf_sigill ); 155 172 # endif 156 173 return i_capabilities; … … 170 187 { 171 188 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) 172 signal( SIGILL, NULL);189 signal( SIGILL, pf_sigill ); 173 190 # endif 174 191 return i_capabilities; … … 186 203 i_illegal = 0; 187 204 188 vlc_mutex_lock( p_this->p_vlc->p_global_lock );189 205 if( setjmp( env ) == 0 ) 190 206 { … … 192 208 __asm__ __volatile__ ( "xorps %%xmm0,%%xmm0\n" : : ); 193 209 } 194 vlc_mutex_unlock( p_this->p_vlc->p_global_lock );195 210 196 211 if( i_illegal == 0 ) … … 207 222 { 208 223 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) 209 signal( SIGILL, NULL);224 signal( SIGILL, pf_sigill ); 210 225 # endif 211 226 return i_capabilities; … … 221 236 i_illegal = 0; 222 237 223 vlc_mutex_lock( p_this->p_vlc->p_global_lock );224 238 if( setjmp( env ) == 0 ) 225 239 { … … 227 241 __asm__ __volatile__ ( "pfadd %%mm0,%%mm0\n" "femms\n" : : ); 228 242 } 229 vlc_mutex_unlock( p_this->p_vlc->p_global_lock );230 243 231 244 if( i_illegal == 0 ) … … 242 255 243 256 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW ) 244 signal( SIGILL, NULL);257 signal( SIGILL, pf_sigill ); 245 258 # endif 246 259 return i_capabilities; … … 248 261 #elif defined( __powerpc__ ) 249 262 263 # ifdef CAN_COMPILE_ALTIVEC 264 sighandler_t pf_sigill = signal( SIGILL, SigHandler ); 265 250 266 i_capabilities |= CPU_CAPABILITY_FPU; 251 267 252 # ifdef CAN_COMPILE_ALTIVEC253 signal( SIGILL, IllegalSignalHandler );254 255 268 i_illegal = 0; 256 269 257 vlc_mutex_lock( p_this->p_vlc->p_global_lock );258 270 if( setjmp( env ) == 0 ) 259 271 { … … 263 275 : "r" (-1)); 264 276 } 265 vlc_mutex_unlock( p_this->p_vlc->p_global_lock );266 277 267 278 if( i_illegal == 0 ) … … 270 281 } 271 282 272 signal( SIGILL, NULL);283 signal( SIGILL, pf_sigill ); 273 284 # endif 274 285 … … 288 299 289 300 /***************************************************************************** 290 * IllegalSignalHandler: system signal handler301 * SigHandler: system signal handler 291 302 ***************************************************************************** 292 303 * This function is called when an illegal instruction signal is received by 293 304 * the program. We use this function to test OS and CPU capabilities 294 305 *****************************************************************************/ 295 static void IllegalSignalHandler( int i_signal )306 static void SigHandler( int i_signal ) 296 307 { 297 308 /* Acknowledge the signal received */ src/vlc.c
r7689bc9 r2fa6c9c 3 3 ***************************************************************************** 4 4 * Copyright (C) 1998-2001 VideoLAN 5 * $Id: vlc.c,v 1. 8 2002/08/08 00:35:11sam Exp $5 * $Id: vlc.c,v 1.9 2002/08/19 11:13:45 sam Exp $ 6 6 * 7 7 * Authors: Vincent Seguin <seguin@via.ecp.fr> 8 8 * Samuel Hocevar <sam@zoy.org> 9 9 * Gildas Bazin <gbazin@netcourrier.com> 10 * Lots of other people, see the libvlc AUTHORS file 10 11 * 11 12 * This program is free software; you can redistribute it and/or modify … … 23 24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. 24 25 *****************************************************************************/ 26 25 27 #include <signal.h> /* SIGHUP, SIGINT, SIGKILL */ 26 28 #include <stdio.h> /* fprintf() */ 27 29 #include <stdlib.h> /* putenv(), strtol(), */ 30 #include <signal.h> /* SIGHUP, SIGINT, SIGKILL */ 28 31 29 32 #include <vlc/vlc.h> 30 33 31 34 /***************************************************************************** 35 * Local prototypes. 36 *****************************************************************************/ 37 #ifndef WIN32 38 static void SigHandler ( int i_signal ); 39 #endif 40 41 /***************************************************************************** 32 42 * main: parse command line, start interface and spawn threads 33 43 *****************************************************************************/ 34 int main( int i_argc, char *ppsz_argv[])44 int main( int i_argc, char *ppsz_argv[] ) 35 45 { 36 46 vlc_error_t err; 47 48 fprintf( stderr, COPYRIGHT_MESSAGE "\n" ); 37 49 38 50 #ifdef SYS_LINUX … … 46 58 #endif 47 59 48 /* Create thevlc structure */60 /* Create a libvlc structure */ 49 61 err = vlc_create(); 50 62 if( err != VLC_SUCCESS ) … … 53 65 } 54 66 55 /* Initialize vlc */ 67 #ifndef WIN32 68 /* Set the signal handlers. SIGTERM is not intercepted, because we need at 69 * least one method to kill the program when all other methods failed, and 70 * when we don't want to use SIGKILL. 71 * Note that we set the signals after the vlc_create call. */ 72 signal( SIGINT, SigHandler ); 73 signal( SIGHUP, SigHandler ); 74 signal( SIGQUIT, SigHandler ); 75 76 /* Other signals */ 77 signal( SIGALRM, SIG_IGN ); 78 signal( SIGPIPE, SIG_IGN ); 79 #endif 80 81 /* Initialize libvlc */ 56 82 err = vlc_init( i_argc, ppsz_argv ); 57 83 if( err != VLC_SUCCESS ) … … 61 87 } 62 88 63 /* Run vlc, in non-blocking mode */89 /* Run libvlc, in non-blocking mode */ 64 90 err = vlc_run(); 65 91 … … 84 110 vlc_end(); 85 111 86 /* Destroy the vlc structure */112 /* Destroy the libvlc structure */ 87 113 vlc_destroy(); 88 114 … … 90 116 } 91 117 118 #ifndef WIN32 119 /***************************************************************************** 120 * SigHandler: system signal handler 121 ***************************************************************************** 122 * This function is called when a fatal signal is received by the program. 123 * It tries to end the program in a clean way. 124 *****************************************************************************/ 125 static void SigHandler( int i_signal ) 126 { 127 static mtime_t abort_time = 0; 128 static volatile vlc_bool_t b_die = VLC_FALSE; 129 130 /* Once a signal has been trapped, the termination sequence will be 131 * armed and subsequent signals will be ignored to avoid sending signals 132 * to a libvlc structure having been destroyed */ 133 134 if( !b_die ) 135 { 136 b_die = VLC_TRUE; 137 abort_time = mdate(); 138 139 fprintf( stderr, "signal %d received, terminating vlc - do it " 140 "again in case it gets stuck\n", i_signal ); 141 142 /* Acknowledge the signal received */ 143 vlc_die(); 144 } 145 else if( mdate() > abort_time + 1000000 ) 146 { 147 /* If user asks again 1 second later, die badly */ 148 signal( SIGINT, SIG_DFL ); 149 signal( SIGHUP, SIG_DFL ); 150 signal( SIGQUIT, SIG_DFL ); 151 signal( SIGALRM, SIG_DFL ); 152 signal( SIGPIPE, SIG_DFL ); 153 154 fprintf( stderr, "user insisted too much, dying badly\n" ); 155 156 exit( 1 ); 157 } 158 } 159 #endif 160
