src/audio/arts/SDL_artsaudio.c
changeset 6152 ff0bc7241515
parent 6138 4c64952a58fb
child 6885 700f1b25f77f
equal deleted inserted replaced
6148:36f5d9fc9c39 6152:ff0bc7241515
    59 static int (*SDL_NAME(arts_stream_get)) (arts_stream_t s,
    59 static int (*SDL_NAME(arts_stream_get)) (arts_stream_t s,
    60                                          arts_parameter_t param);
    60                                          arts_parameter_t param);
    61 static int (*SDL_NAME(arts_write)) (arts_stream_t s, const void *buffer,
    61 static int (*SDL_NAME(arts_write)) (arts_stream_t s, const void *buffer,
    62                                     int count);
    62                                     int count);
    63 static void (*SDL_NAME(arts_close_stream)) (arts_stream_t s);
    63 static void (*SDL_NAME(arts_close_stream)) (arts_stream_t s);
       
    64 static int (*SDL_NAME(arts_suspend))(void);
    64 static int (*SDL_NAME(arts_suspended)) (void);
    65 static int (*SDL_NAME(arts_suspended)) (void);
    65 static const char *(*SDL_NAME(arts_error_text)) (int errorcode);
    66 static const char *(*SDL_NAME(arts_error_text)) (int errorcode);
    66 
    67 
    67 #define SDL_ARTS_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) }
    68 #define SDL_ARTS_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) }
    68 static struct
    69 static struct
    76     SDL_ARTS_SYM(arts_play_stream),
    77     SDL_ARTS_SYM(arts_play_stream),
    77     SDL_ARTS_SYM(arts_stream_set),
    78     SDL_ARTS_SYM(arts_stream_set),
    78     SDL_ARTS_SYM(arts_stream_get),
    79     SDL_ARTS_SYM(arts_stream_get),
    79     SDL_ARTS_SYM(arts_write),
    80     SDL_ARTS_SYM(arts_write),
    80     SDL_ARTS_SYM(arts_close_stream),
    81     SDL_ARTS_SYM(arts_close_stream),
       
    82     SDL_ARTS_SYM(arts_suspend),
    81     SDL_ARTS_SYM(arts_suspended),
    83     SDL_ARTS_SYM(arts_suspended),
    82     SDL_ARTS_SYM(arts_error_text),
    84     SDL_ARTS_SYM(arts_error_text),
    83 /* *INDENT-ON* */
    85 /* *INDENT-ON* */
    84 };
    86 };
    85 
    87 
   214         SDL_free(this->hidden);
   216         SDL_free(this->hidden);
   215         this->hidden = NULL;
   217         this->hidden = NULL;
   216     }
   218     }
   217 }
   219 }
   218 
   220 
       
   221 static int
       
   222 ARTS_Suspend(void)
       
   223 {
       
   224     const Uint32 abortms = SDL_GetTicks() + 3000; /* give up after 3 secs */
       
   225     while ( (!SDL_NAME(arts_suspended)()) && (SDL_GetTicks() < abortms) ) {
       
   226         if ( SDL_NAME(arts_suspend)() ) {
       
   227             break;
       
   228         }
       
   229     }
       
   230     return SDL_NAME(arts_suspended)();
       
   231 }
   219 
   232 
   220 static int
   233 static int
   221 ARTS_OpenDevice(_THIS, const char *devname, int iscapture)
   234 ARTS_OpenDevice(_THIS, const char *devname, int iscapture)
   222 {
   235 {
   223     int rc = 0;
   236     int rc = 0;
   268         SDL_SetError("Unable to initialize ARTS: %s",
   281         SDL_SetError("Unable to initialize ARTS: %s",
   269                      SDL_NAME(arts_error_text) (rc));
   282                      SDL_NAME(arts_error_text) (rc));
   270         return 0;
   283         return 0;
   271     }
   284     }
   272 
   285 
   273     if (!SDL_NAME(arts_suspended) ()) {
   286     if (!ARTS_Suspend()) {
   274         ARTS_CloseDevice(this);
   287         ARTS_CloseDevice(this);
   275         SDL_SetError("ARTS can not open audio device");
   288         SDL_SetError("ARTS can not open audio device");
   276         return 0;
   289         return 0;
   277     }
   290     }
   278 
   291 
   344             SDL_SetError("ARTS: arts_init failed (no audio server?)");
   357             SDL_SetError("ARTS: arts_init failed (no audio server?)");
   345             return 0;
   358             return 0;
   346         }
   359         }
   347 
   360 
   348         /* Play a stream so aRts doesn't crash */
   361         /* Play a stream so aRts doesn't crash */
   349         if (SDL_NAME(arts_suspended) ()) {
   362         if (ARTS_Suspend()) {
   350             arts_stream_t stream;
   363             arts_stream_t stream;
   351             stream = SDL_NAME(arts_play_stream) (44100, 16, 2, "SDL");
   364             stream = SDL_NAME(arts_play_stream) (44100, 16, 2, "SDL");
   352             SDL_NAME(arts_write) (stream, "", 0);
   365             SDL_NAME(arts_write) (stream, "", 0);
   353             SDL_NAME(arts_close_stream) (stream);
   366             SDL_NAME(arts_close_stream) (stream);
   354         }
   367         }