]> git.sesse.net Git - vlc/blobdiff - plugins/sdl/aout_sdl.c
(0.2.92 branch)
[vlc] / plugins / sdl / aout_sdl.c
index d78b0c491000a10e1086f0ba1cfc131e42f19ce5..1085e2d1992c6f53f3e9b7804713515220855bc5 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * aout_sdl.c : audio sdl functions library
  *****************************************************************************
- * Copyright (C) 1999, 2000 VideoLAN
- * $Id: aout_sdl.c,v 1.16 2001/07/25 19:14:06 massiot Exp $
+ * Copyright (C) 1999-2001 VideoLAN
+ * $Id: aout_sdl.c,v 1.20.2.1 2001/12/18 00:51:19 sam Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
 #include <stdio.h>                                           /* "intf_msg.h" */
 #include <stdlib.h>                            /* calloc(), malloc(), free() */
 
-#ifdef HAVE_SDL_SDL_H
-#   include <SDL/SDL.h>
-#elif defined(HAVE_SDL11_SDL_H)
-#   include <SDL11/SDL.h>
-#elif defined(HAVE_SDL12_SDL_H)
-#   include <SDL12/SDL.h>
-#else
-#    error
-#endif
+#include SDL_INCLUDE_FILE
 
-#include "config.h"
 #include "common.h"                                     /* boolean_t, byte_t */
+#include "intf_msg.h"                        /* intf_DbgMsg(), intf_ErrMsg() */
 #include "threads.h"
 #include "mtime.h"
 #include "tests.h"
 
 #include "audio_output.h"                                   /* aout_thread_t */
 
-#include "intf_msg.h"                        /* intf_DbgMsg(), intf_ErrMsg() */
-#include "main.h"
-
 #include "modules.h"
 #include "modules_export.h"
 
@@ -118,7 +107,14 @@ static int aout_Probe( probedata_t *p_data )
 {
 #if 0
     SDL_AudioSpec desired, obtained;
+#endif
+
+    if( SDL_WasInit( SDL_INIT_AUDIO ) != 0 )
+    {
+        return( 0 );
+    }
 
+#if 0
     /* Start AudioSDL */
     if( SDL_Init(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE) != 0 )
     {
@@ -165,7 +161,7 @@ static int aout_Open( aout_thread_t *p_aout )
     SDL_AudioSpec desired;
     int i_channels = p_aout->b_stereo ? 2 : 1;
 
-   /* Allocate structure */
+    /* Allocate structure */
     p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
 
     if( p_aout->p_sys == NULL )
@@ -174,6 +170,23 @@ static int aout_Open( aout_thread_t *p_aout )
         return( 1 );
     }
 
+    /* Initialize library */
+    if( SDL_Init( SDL_INIT_AUDIO
+#ifndef WIN32
+    /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/
+                | SDL_INIT_EVENTTHREAD
+#endif
+#ifdef DEBUG
+    /* In debug mode you may want vlc to dump a core instead of staying
+     * stuck */
+                | SDL_INIT_NOPARACHUTE
+#endif
+                ) < 0 )
+    {
+        intf_ErrMsg( "aout error: can't initialize SDL (%s)", SDL_GetError() );+        free( p_aout->p_sys );
+        return( 1 );
+    }
+
     p_aout->p_sys->i_audio_end = 0;
     p_aout->p_sys->audio_buf = malloc( OVERFLOWLIMIT );
 
@@ -241,6 +254,8 @@ static int aout_SetFormat( aout_thread_t *p_aout )
     if( SDL_OpenAudio( &desired, NULL ) < 0 )
     {
         p_aout->p_sys->b_active = 0;
+        SDL_QuitSubSystem( SDL_INIT_AUDIO );
+        free( p_aout->p_sys );
         return( -1 );
     }
 
@@ -306,6 +321,8 @@ static void aout_Close( aout_thread_t *p_aout )
 
     SDL_CloseAudio();
 
+    SDL_QuitSubSystem( SDL_INIT_AUDIO );
+
     free( p_aout->p_sys );                              /* Close the Output. */
 }