arts: backed out audio capture support.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 04 Aug 2016 11:51:17 -0400
changeset 10254c2730130a448
parent 10253 0e83beda6d8b
child 10255 9530fc07da6c
arts: backed out audio capture support.

Turns out that libartsc isn't thread-safe, so if we run a capture and playback
device at the same time, it often crashes in arts's internal event loop.

We could throw mutexes around the read/write calls, but these are meant to
block, so one device could cause serious latency and stutter in the other.

Since this audio target isn't in high-demand (Ubuntu hasn't offered a libartsc
package for years), I'm just backing out the capture support. If someone needs
it, they can pull it out of the revision history.
src/audio/arts/SDL_artsaudio.c
     1.1 --- a/src/audio/arts/SDL_artsaudio.c	Wed Aug 03 16:54:10 2016 -0400
     1.2 +++ b/src/audio/arts/SDL_artsaudio.c	Thu Aug 04 11:51:17 2016 -0400
     1.3 @@ -54,16 +54,12 @@
     1.4  static arts_stream_t(*SDL_NAME(arts_play_stream)) (int rate, int bits,
     1.5                                                     int channels,
     1.6                                                     const char *name);
     1.7 -static arts_stream_t(*SDL_NAME(arts_record_stream)) (int rate, int bits,
     1.8 -                                                   int channels,
     1.9 -                                                   const char *name);
    1.10  static int (*SDL_NAME(arts_stream_set)) (arts_stream_t s,
    1.11                                           arts_parameter_t param, int value);
    1.12  static int (*SDL_NAME(arts_stream_get)) (arts_stream_t s,
    1.13                                           arts_parameter_t param);
    1.14  static int (*SDL_NAME(arts_write)) (arts_stream_t s, const void *buffer,
    1.15                                      int count);
    1.16 -static int (*SDL_NAME(arts_read)) (arts_stream_t s, void *buffer, int count);
    1.17  static void (*SDL_NAME(arts_close_stream)) (arts_stream_t s);
    1.18  static int (*SDL_NAME(arts_suspend))(void);
    1.19  static int (*SDL_NAME(arts_suspended)) (void);
    1.20 @@ -79,11 +75,9 @@
    1.21      SDL_ARTS_SYM(arts_init),
    1.22      SDL_ARTS_SYM(arts_free),
    1.23      SDL_ARTS_SYM(arts_play_stream),
    1.24 -    SDL_ARTS_SYM(arts_record_stream),
    1.25      SDL_ARTS_SYM(arts_stream_set),
    1.26      SDL_ARTS_SYM(arts_stream_get),
    1.27      SDL_ARTS_SYM(arts_write),
    1.28 -    SDL_ARTS_SYM(arts_read),
    1.29      SDL_ARTS_SYM(arts_close_stream),
    1.30      SDL_ARTS_SYM(arts_suspend),
    1.31      SDL_ARTS_SYM(arts_suspended),
    1.32 @@ -205,27 +199,6 @@
    1.33      return (this->hidden->mixbuf);
    1.34  }
    1.35  
    1.36 -static int
    1.37 -ARTS_CaptureFromDevice(_THIS, void *buffer, int buflen)
    1.38 -{
    1.39 -    return SDL_NAME(arts_read) (this->hidden->stream, buffer, buflen);
    1.40 -}
    1.41 -
    1.42 -static void
    1.43 -ARTS_FlushCapture(_THIS)
    1.44 -{
    1.45 -    arts_stream_t stream = this->hidden->stream;
    1.46 -    int remain = SDL_NAME(arts_stream_get)(stream, ARTS_P_BUFFER_SPACE);
    1.47 -    Uint8 buf[512];
    1.48 -    while (remain > 0) {
    1.49 -        const int len = SDL_min(sizeof (buf), remain);
    1.50 -        const int br = SDL_NAME(arts_read)(stream, buf, len);
    1.51 -        if (br <= 0) {
    1.52 -            return;  /* oh well. */
    1.53 -        }
    1.54 -        remain -= br;
    1.55 -    }
    1.56 -}
    1.57  
    1.58  static void
    1.59  ARTS_CloseDevice(_THIS)
    1.60 @@ -305,20 +278,19 @@
    1.61                              SDL_NAME(arts_error_text) (rc));
    1.62      }
    1.63  
    1.64 -    if (iscapture) {
    1.65 -        this->hidden->stream = SDL_NAME(arts_record_stream) (this->spec.freq,
    1.66 -                                                             bits,
    1.67 -                                                             this->spec.channels,
    1.68 -                                                             "SDL");
    1.69 -    } else {
    1.70 -        this->hidden->stream = SDL_NAME(arts_play_stream) (this->spec.freq,
    1.71 -                                                           bits,
    1.72 -                                                           this->spec.channels,
    1.73 -                                                           "SDL");
    1.74 -        /* Play nothing so we have at least one write (server bug workaround). */
    1.75 -        SDL_NAME(arts_write) (this->hidden->stream, "", 0);
    1.76 +    if (!ARTS_Suspend()) {
    1.77 +        ARTS_CloseDevice(this);
    1.78 +        return SDL_SetError("ARTS can not open audio device");
    1.79      }
    1.80  
    1.81 +    this->hidden->stream = SDL_NAME(arts_play_stream) (this->spec.freq,
    1.82 +                                                       bits,
    1.83 +                                                       this->spec.channels,
    1.84 +                                                       "SDL");
    1.85 +
    1.86 +    /* Play nothing so we have at least one write (server bug workaround). */
    1.87 +    SDL_NAME(arts_write) (this->hidden->stream, "", 0);
    1.88 +
    1.89      /* Calculate the final parameters for this audio specification */
    1.90      SDL_CalculateAudioSpec(&this->spec);
    1.91  
    1.92 @@ -397,12 +369,7 @@
    1.93      impl->CloseDevice = ARTS_CloseDevice;
    1.94      impl->WaitDone = ARTS_WaitDone;
    1.95      impl->Deinitialize = ARTS_Deinitialize;
    1.96 -    impl->CaptureFromDevice = ARTS_CaptureFromDevice;
    1.97 -    impl->FlushCapture = ARTS_FlushCapture;
    1.98 -
    1.99      impl->OnlyHasDefaultOutputDevice = 1;
   1.100 -    impl->OnlyHasDefaultInputDevice = 1;
   1.101 -    impl->HasCaptureSupport = 1;
   1.102  
   1.103      return 1;   /* this audio target is available. */
   1.104  }