mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-23 11:38:28 +00:00
audio: PlayDevice() should return an error code.
Higher level code treats errors as fatal and disconnects the device.
This commit is contained in:
@@ -412,7 +412,7 @@ void SDL_AudioDeviceDisconnected(SDL_AudioDevice *device)
|
|||||||
|
|
||||||
static void SDL_AudioThreadDeinit_Default(SDL_AudioDevice *device) { /* no-op. */ }
|
static void SDL_AudioThreadDeinit_Default(SDL_AudioDevice *device) { /* no-op. */ }
|
||||||
static void SDL_AudioWaitDevice_Default(SDL_AudioDevice *device) { /* no-op. */ }
|
static void SDL_AudioWaitDevice_Default(SDL_AudioDevice *device) { /* no-op. */ }
|
||||||
static void SDL_AudioPlayDevice_Default(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) { /* no-op. */ }
|
static int SDL_AudioPlayDevice_Default(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) { return 0; /* no-op. */ }
|
||||||
static void SDL_AudioWaitCaptureDevice_Default(SDL_AudioDevice *device) { /* no-op. */ }
|
static void SDL_AudioWaitCaptureDevice_Default(SDL_AudioDevice *device) { /* no-op. */ }
|
||||||
static void SDL_AudioFlushCapture_Default(SDL_AudioDevice *device) { /* no-op. */ }
|
static void SDL_AudioFlushCapture_Default(SDL_AudioDevice *device) { /* no-op. */ }
|
||||||
static void SDL_AudioCloseDevice_Default(SDL_AudioDevice *device) { /* no-op. */ }
|
static void SDL_AudioCloseDevice_Default(SDL_AudioDevice *device) { /* no-op. */ }
|
||||||
@@ -731,8 +731,10 @@ SDL_bool SDL_OutputAudioThreadIterate(SDL_AudioDevice *device)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// !!! FIXME: have PlayDevice return a value and do disconnects in here with it.
|
// PlayDevice SHOULD NOT BLOCK, as we are holding a lock right now. Block in WaitDevice instead!
|
||||||
current_audio.impl.PlayDevice(device, mix_buffer, buffer_size); // this SHOULD NOT BLOCK, as we are holding a lock right now. Block in WaitDevice!
|
if (current_audio.impl.PlayDevice(device, mix_buffer, buffer_size) < 0) {
|
||||||
|
retval = SDL_FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_UnlockMutex(device->lock);
|
SDL_UnlockMutex(device->lock);
|
||||||
|
@@ -121,7 +121,7 @@ typedef struct SDL_AudioDriverImpl
|
|||||||
void (*ThreadInit)(SDL_AudioDevice *device); // Called by audio thread at start
|
void (*ThreadInit)(SDL_AudioDevice *device); // Called by audio thread at start
|
||||||
void (*ThreadDeinit)(SDL_AudioDevice *device); // Called by audio thread at end
|
void (*ThreadDeinit)(SDL_AudioDevice *device); // Called by audio thread at end
|
||||||
void (*WaitDevice)(SDL_AudioDevice *device);
|
void (*WaitDevice)(SDL_AudioDevice *device);
|
||||||
void (*PlayDevice)(SDL_AudioDevice *device, const Uint8 *buffer, int buflen); // buffer and buflen are always from GetDeviceBuf, passed here for convenience.
|
int (*PlayDevice)(SDL_AudioDevice *device, const Uint8 *buffer, int buflen); // buffer and buflen are always from GetDeviceBuf, passed here for convenience.
|
||||||
Uint8 *(*GetDeviceBuf)(SDL_AudioDevice *device, int *buffer_size);
|
Uint8 *(*GetDeviceBuf)(SDL_AudioDevice *device, int *buffer_size);
|
||||||
void (*WaitCaptureDevice)(SDL_AudioDevice *device);
|
void (*WaitCaptureDevice)(SDL_AudioDevice *device);
|
||||||
int (*CaptureFromDevice)(SDL_AudioDevice *device, void *buffer, int buflen);
|
int (*CaptureFromDevice)(SDL_AudioDevice *device, void *buffer, int buflen);
|
||||||
|
@@ -111,13 +111,14 @@ static void AAUDIO_WaitDevice(SDL_AudioDevice *device)
|
|||||||
SDL_WaitSemaphore(device->hidden->semaphore);
|
SDL_WaitSemaphore(device->hidden->semaphore);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
static int AAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
||||||
{
|
{
|
||||||
// AAUDIO_dataCallback picks up our work and unblocks AAUDIO_WaitDevice. But make sure we didn't fail here.
|
// AAUDIO_dataCallback picks up our work and unblocks AAUDIO_WaitDevice. But make sure we didn't fail here.
|
||||||
if (SDL_AtomicGet(&device->hidden->error_callback_triggered)) {
|
if (SDL_AtomicGet(&device->hidden->error_callback_triggered)) {
|
||||||
SDL_AtomicSet(&device->hidden->error_callback_triggered, 0);
|
SDL_AtomicSet(&device->hidden->error_callback_triggered, 0);
|
||||||
SDL_AudioDeviceDisconnected(device);
|
return -1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// no need for a FlushCapture implementation, just don't read mixbuf until the next iteration.
|
// no need for a FlushCapture implementation, just don't read mixbuf until the next iteration.
|
||||||
|
@@ -351,7 +351,7 @@ static void ALSA_WaitDevice(SDL_AudioDevice *device)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ALSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
static int ALSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
||||||
{
|
{
|
||||||
SDL_assert(buffer == device->hidden->mixbuf);
|
SDL_assert(buffer == device->hidden->mixbuf);
|
||||||
Uint8 *sample_buf = device->hidden->mixbuf;
|
Uint8 *sample_buf = device->hidden->mixbuf;
|
||||||
@@ -378,8 +378,7 @@ static void ALSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int bu
|
|||||||
SDL_LogError(SDL_LOG_CATEGORY_AUDIO,
|
SDL_LogError(SDL_LOG_CATEGORY_AUDIO,
|
||||||
"ALSA write failed (unrecoverable): %s",
|
"ALSA write failed (unrecoverable): %s",
|
||||||
ALSA_snd_strerror(status));
|
ALSA_snd_strerror(status));
|
||||||
SDL_AudioDeviceDisconnected(device);
|
return -1;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
} else if (status == 0) {
|
} else if (status == 0) {
|
||||||
@@ -391,6 +390,8 @@ static void ALSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int bu
|
|||||||
sample_buf += status * frame_size;
|
sample_buf += status * frame_size;
|
||||||
frames_left -= status;
|
frames_left -= status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 *ALSA_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
static Uint8 *ALSA_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
||||||
|
@@ -87,9 +87,10 @@ static int ANDROIDAUDIO_OpenDevice(SDL_AudioDevice *device)
|
|||||||
|
|
||||||
// !!! FIXME: this needs a WaitDevice implementation.
|
// !!! FIXME: this needs a WaitDevice implementation.
|
||||||
|
|
||||||
static void ANDROIDAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
static int ANDROIDAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
||||||
{
|
{
|
||||||
Android_JNI_WriteAudioBuffer();
|
Android_JNI_WriteAudioBuffer();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 *ANDROIDAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
static Uint8 *ANDROIDAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
||||||
|
@@ -525,7 +525,7 @@ static SDL_bool UpdateAudioSession(SDL_AudioDevice *device, SDL_bool open, SDL_b
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static void COREAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
|
static int COREAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
|
||||||
{
|
{
|
||||||
AudioQueueBufferRef current_buffer = device->hidden->current_buffer;
|
AudioQueueBufferRef current_buffer = device->hidden->current_buffer;
|
||||||
SDL_assert(current_buffer != NULL); // should have been called from OutputBufferReadyCallback
|
SDL_assert(current_buffer != NULL); // should have been called from OutputBufferReadyCallback
|
||||||
@@ -533,6 +533,7 @@ static void COREAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, i
|
|||||||
current_buffer->mAudioDataByteSize = current_buffer->mAudioDataBytesCapacity;
|
current_buffer->mAudioDataByteSize = current_buffer->mAudioDataBytesCapacity;
|
||||||
device->hidden->current_buffer = NULL;
|
device->hidden->current_buffer = NULL;
|
||||||
AudioQueueEnqueueBuffer(device->hidden->audioQueue, current_buffer, 0, NULL);
|
AudioQueueEnqueueBuffer(device->hidden->audioQueue, current_buffer, 0, NULL);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 *COREAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
static Uint8 *COREAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
||||||
|
@@ -285,11 +285,14 @@ static void DSOUND_WaitDevice(SDL_AudioDevice *device)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DSOUND_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
static int DSOUND_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
||||||
{
|
{
|
||||||
// Unlock the buffer, allowing it to play
|
// Unlock the buffer, allowing it to play
|
||||||
SDL_assert(buflen == device->buffer_size);
|
SDL_assert(buflen == device->buffer_size);
|
||||||
IDirectSoundBuffer_Unlock(device->hidden->mixbuf, (LPVOID) buffer, buflen, NULL, 0);
|
if (IDirectSoundBuffer_Unlock(device->hidden->mixbuf, (LPVOID) buffer, buflen, NULL, 0) != DS_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 *DSOUND_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
static Uint8 *DSOUND_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
||||||
|
@@ -40,15 +40,16 @@ static void DISKAUDIO_WaitDevice(SDL_AudioDevice *device)
|
|||||||
SDL_Delay(device->hidden->io_delay);
|
SDL_Delay(device->hidden->io_delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DISKAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
|
static int DISKAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
|
||||||
{
|
{
|
||||||
const int written = (int)SDL_RWwrite(device->hidden->io, buffer, (size_t)buffer_size);
|
const int written = (int)SDL_RWwrite(device->hidden->io, buffer, (size_t)buffer_size);
|
||||||
if (written != buffer_size) { // If we couldn't write, assume fatal error for now
|
if (written != buffer_size) { // If we couldn't write, assume fatal error for now
|
||||||
SDL_AudioDeviceDisconnected(device);
|
return -1;
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_AUDIO
|
#ifdef DEBUG_AUDIO
|
||||||
SDL_Log("DISKAUDIO: Wrote %d bytes of audio data", (int) written);
|
SDL_Log("DISKAUDIO: Wrote %d bytes of audio data", (int) written);
|
||||||
#endif
|
#endif
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 *DISKAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
static Uint8 *DISKAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
||||||
|
@@ -225,17 +225,17 @@ static void DSP_WaitDevice(SDL_AudioDevice *device)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DSP_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
static int DSP_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *h = device->hidden;
|
struct SDL_PrivateAudioData *h = device->hidden;
|
||||||
if (write(h->audio_fd, buffer, buflen) == -1) {
|
if (write(h->audio_fd, buffer, buflen) == -1) {
|
||||||
perror("Audio write");
|
perror("Audio write");
|
||||||
SDL_AudioDeviceDisconnected(device);
|
return -1;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_AUDIO
|
#ifdef DEBUG_AUDIO
|
||||||
fprintf(stderr, "Wrote %d bytes of audio data\n", h->mixlen);
|
fprintf(stderr, "Wrote %d bytes of audio data\n", h->mixlen);
|
||||||
#endif
|
#endif
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 *DSP_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
static Uint8 *DSP_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
||||||
|
@@ -36,7 +36,7 @@ static Uint8 *EMSCRIPTENAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_
|
|||||||
return device->hidden->mixbuf;
|
return device->hidden->mixbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EMSCRIPTENAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
|
static int EMSCRIPTENAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
|
||||||
{
|
{
|
||||||
const int framelen = (SDL_AUDIO_BITSIZE(device->spec.format) / 8) * device->spec.channels;
|
const int framelen = (SDL_AUDIO_BITSIZE(device->spec.format) / 8) * device->spec.channels;
|
||||||
MAIN_THREAD_EM_ASM({
|
MAIN_THREAD_EM_ASM({
|
||||||
@@ -53,6 +53,7 @@ static void EMSCRIPTENAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, buffer, buffer_size / framelen);
|
}, buffer, buffer_size / framelen);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -46,13 +46,14 @@ static Uint8 *HAIKUAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
|||||||
return device->hidden->current_buffer;
|
return device->hidden->current_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HAIKUAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
|
static int HAIKUAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
|
||||||
{
|
{
|
||||||
// We already wrote our output right into the BSoundPlayer's callback's stream. Just clean up our stuff.
|
// We already wrote our output right into the BSoundPlayer's callback's stream. Just clean up our stuff.
|
||||||
SDL_assert(device->hidden->current_buffer != NULL);
|
SDL_assert(device->hidden->current_buffer != NULL);
|
||||||
SDL_assert(device->hidden->current_buffer_len > 0);
|
SDL_assert(device->hidden->current_buffer_len > 0);
|
||||||
device->hidden->current_buffer = NULL;
|
device->hidden->current_buffer = NULL;
|
||||||
device->hidden->current_buffer_len = 0;
|
device->hidden->current_buffer_len = 0;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Haiku callback for handling the audio buffer
|
// The Haiku callback for handling the audio buffer
|
||||||
|
@@ -149,7 +149,7 @@ static int jackProcessPlaybackCallback(jack_nframes_t nframes, void *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void JACK_PlayDevice(SDL_AudioDevice *device, const Uint8 *ui8buffer, int buflen)
|
static int JACK_PlayDevice(SDL_AudioDevice *device, const Uint8 *ui8buffer, int buflen)
|
||||||
{
|
{
|
||||||
const float *buffer = (float *) ui8buffer;
|
const float *buffer = (float *) ui8buffer;
|
||||||
jack_port_t **ports = device->hidden->sdlports;
|
jack_port_t **ports = device->hidden->sdlports;
|
||||||
@@ -167,6 +167,8 @@ static void JACK_PlayDevice(SDL_AudioDevice *device, const Uint8 *ui8buffer, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 *JACK_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
static Uint8 *JACK_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
||||||
|
@@ -176,7 +176,7 @@ static int N3DSAUDIO_OpenDevice(SDL_AudioDevice *device)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void N3DSAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
static int N3DSAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
||||||
{
|
{
|
||||||
contextLock(device);
|
contextLock(device);
|
||||||
|
|
||||||
@@ -196,6 +196,8 @@ static void N3DSAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, i
|
|||||||
DSP_FlushDataCache(device->hidden->waveBuf[nextbuf].data_vaddr, buflen);
|
DSP_FlushDataCache(device->hidden->waveBuf[nextbuf].data_vaddr, buflen);
|
||||||
|
|
||||||
ndspChnWaveBufAdd(0, &device->hidden->waveBuf[nextbuf]);
|
ndspChnWaveBufAdd(0, &device->hidden->waveBuf[nextbuf]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void N3DSAUDIO_WaitDevice(SDL_AudioDevice *device)
|
static void N3DSAUDIO_WaitDevice(SDL_AudioDevice *device)
|
||||||
|
@@ -141,20 +141,18 @@ static void NETBSDAUDIO_WaitDevice(SDL_AudioDevice *device)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void NETBSDAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
static int NETBSDAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *h = device->hidden;
|
struct SDL_PrivateAudioData *h = device->hidden;
|
||||||
const int written = write(h->audio_fd, buffer, buflen);
|
const int written = write(h->audio_fd, buffer, buflen);
|
||||||
if (written == -1) {
|
if (written != buflen) { // Treat even partial writes as fatal errors.
|
||||||
// Non recoverable error has occurred. It should be reported!!!
|
return -1;
|
||||||
SDL_AudioDeviceDisconnected(device);
|
|
||||||
perror("audio");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_AUDIO
|
#ifdef DEBUG_AUDIO
|
||||||
fprintf(stderr, "Wrote %d bytes of audio data\n", written);
|
fprintf(stderr, "Wrote %d bytes of audio data\n", written);
|
||||||
#endif
|
#endif
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 *NETBSDAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
static Uint8 *NETBSDAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
||||||
|
@@ -638,7 +638,7 @@ static void openslES_WaitDevice(SDL_AudioDevice *device)
|
|||||||
SDL_WaitSemaphore(audiodata->playsem);
|
SDL_WaitSemaphore(audiodata->playsem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void openslES_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
static int openslES_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *audiodata = device->hidden;
|
struct SDL_PrivateAudioData *audiodata = device->hidden;
|
||||||
|
|
||||||
@@ -657,6 +657,8 @@ static void openslES_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, in
|
|||||||
if (SL_RESULT_SUCCESS != result) {
|
if (SL_RESULT_SUCCESS != result) {
|
||||||
SDL_PostSemaphore(audiodata->playsem);
|
SDL_PostSemaphore(audiodata->playsem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// n playn sem
|
/// n playn sem
|
||||||
|
@@ -940,7 +940,7 @@ static Uint8 *PIPEWIRE_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
|||||||
return (Uint8 *) spa_buf->datas[0].data;
|
return (Uint8 *) spa_buf->datas[0].data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PIPEWIRE_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
|
static int PIPEWIRE_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
|
||||||
{
|
{
|
||||||
struct pw_stream *stream = device->hidden->stream;
|
struct pw_stream *stream = device->hidden->stream;
|
||||||
struct pw_buffer *pw_buf = device->hidden->pw_buf;
|
struct pw_buffer *pw_buf = device->hidden->pw_buf;
|
||||||
@@ -951,6 +951,8 @@ static void PIPEWIRE_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, in
|
|||||||
|
|
||||||
PIPEWIRE_pw_stream_queue_buffer(stream, pw_buf);
|
PIPEWIRE_pw_stream_queue_buffer(stream, pw_buf);
|
||||||
device->hidden->pw_buf = NULL;
|
device->hidden->pw_buf = NULL;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void output_callback(void *data)
|
static void output_callback(void *data)
|
||||||
|
@@ -85,9 +85,10 @@ static int PS2AUDIO_OpenDevice(SDL_AudioDevice *device)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PS2AUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
static int PS2AUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
||||||
{
|
{
|
||||||
audsrv_play_audio((char *)buffer, buflen);
|
// this returns number of bytes accepted or a negative error. We assume anything other than buflen is a fatal error.
|
||||||
|
return (audsrv_play_audio((char *)buffer, buflen) != buflen) ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PS2AUDIO_WaitDevice(SDL_AudioDevice *device)
|
static void PS2AUDIO_WaitDevice(SDL_AudioDevice *device)
|
||||||
|
@@ -106,14 +106,16 @@ static int PSPAUDIO_OpenDevice(SDL_AudioDevice *device)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PSPAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
static int PSPAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
||||||
{
|
{
|
||||||
|
int rc;
|
||||||
if (!isBasicAudioConfig(&device->spec)) {
|
if (!isBasicAudioConfig(&device->spec)) {
|
||||||
SDL_assert(device->spec.channels == 2);
|
SDL_assert(device->spec.channels == 2);
|
||||||
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, (void *) buffer);
|
rc = sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, (void *) buffer);
|
||||||
} else {
|
} else {
|
||||||
sceAudioOutputPannedBlocking(device->hidden->channel, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, (void *) buffer);
|
rc = sceAudioOutputPannedBlocking(device->hidden->channel, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, (void *) buffer);
|
||||||
}
|
}
|
||||||
|
return (rc == 0) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PSPAUDIO_WaitDevice(SDL_AudioDevice *device)
|
static void PSPAUDIO_WaitDevice(SDL_AudioDevice *device)
|
||||||
|
@@ -388,7 +388,7 @@ static void PULSEAUDIO_WaitDevice(SDL_AudioDevice *device)
|
|||||||
PULSEAUDIO_pa_threaded_mainloop_unlock(pulseaudio_threaded_mainloop);
|
PULSEAUDIO_pa_threaded_mainloop_unlock(pulseaudio_threaded_mainloop);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PULSEAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
|
static int PULSEAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *h = device->hidden;
|
struct SDL_PrivateAudioData *h = device->hidden;
|
||||||
|
|
||||||
@@ -401,14 +401,14 @@ static void PULSEAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer,
|
|||||||
PULSEAUDIO_pa_threaded_mainloop_unlock(pulseaudio_threaded_mainloop);
|
PULSEAUDIO_pa_threaded_mainloop_unlock(pulseaudio_threaded_mainloop);
|
||||||
|
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
SDL_AudioDeviceDisconnected(device);
|
return -1;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*printf("PULSEAUDIO FEED! nbytes=%d\n", buffer_size);*/
|
/*printf("PULSEAUDIO FEED! nbytes=%d\n", buffer_size);*/
|
||||||
h->bytes_requested -= buffer_size;
|
h->bytes_requested -= buffer_size;
|
||||||
|
|
||||||
/*printf("PULSEAUDIO PLAYDEVICE END! written=%d\n", written);*/
|
/*printf("PULSEAUDIO PLAYDEVICE END! written=%d\n", written);*/
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 *PULSEAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
static Uint8 *PULSEAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
||||||
|
@@ -110,10 +110,10 @@ static void QSA_WaitDevice(SDL_AudioDevice *device)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void QSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
static int QSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
||||||
{
|
{
|
||||||
if (SDL_AtomicGet(&device->shutdown) || !device->hidden) {
|
if (SDL_AtomicGet(&device->shutdown) || !device->hidden) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int towrite = buflen;
|
int towrite = buflen;
|
||||||
@@ -125,7 +125,7 @@ static void QSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buf
|
|||||||
// Check if samples playback got stuck somewhere in hardware or in the audio device driver
|
// Check if samples playback got stuck somewhere in hardware or in the audio device driver
|
||||||
if ((errno == EAGAIN) && (bw == 0)) {
|
if ((errno == EAGAIN) && (bw == 0)) {
|
||||||
if (device->hidden->timeout_on_wait) {
|
if (device->hidden->timeout_on_wait) {
|
||||||
return; // oh well, try again next time. !!! FIXME: Should we just disconnect the device in this case?
|
return 0; // oh well, try again next time. !!! FIXME: Should we just disconnect the device in this case?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,17 +145,17 @@ static void QSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buf
|
|||||||
int status = snd_pcm_plugin_status(device->hidden->audio_handle, &cstatus);
|
int status = snd_pcm_plugin_status(device->hidden->audio_handle, &cstatus);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
QSA_SetError("snd_pcm_plugin_status", status);
|
QSA_SetError("snd_pcm_plugin_status", status);
|
||||||
return; // !!! FIXME: disconnect the device?
|
return -1;
|
||||||
} else if ((cstatus.status == SND_PCM_STATUS_UNDERRUN) || (cstatus.status == SND_PCM_STATUS_READY)) {
|
} else if ((cstatus.status == SND_PCM_STATUS_UNDERRUN) || (cstatus.status == SND_PCM_STATUS_READY)) {
|
||||||
status = snd_pcm_plugin_prepare(device->hidden->audio_handle, device->iscapture ? SND_PCM_CHANNEL_CAPTURE : SND_PCM_CHANNEL_PLAYBACK);
|
status = snd_pcm_plugin_prepare(device->hidden->audio_handle, device->iscapture ? SND_PCM_CHANNEL_CAPTURE : SND_PCM_CHANNEL_PLAYBACK);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
QSA_SetError("snd_pcm_plugin_prepare", status);
|
QSA_SetError("snd_pcm_plugin_prepare", status);
|
||||||
return; // !!! FIXME: disconnect the device?
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
return; // !!! FIXME: disconnect the device?
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// we wrote all remaining data
|
// we wrote all remaining data
|
||||||
@@ -165,9 +165,7 @@ static void QSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buf
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we couldn't write, assume fatal error for now
|
// If we couldn't write, assume fatal error for now
|
||||||
if (towrite != 0) {
|
return (towrite != 0) ? -1 : 0;
|
||||||
SDL_AudioDeviceDisconnected(device);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 *QSA_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
static Uint8 *QSA_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
||||||
|
@@ -175,16 +175,17 @@ static void SNDIO_WaitDevice(SDL_AudioDevice *device)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SNDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
static int SNDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
||||||
{
|
{
|
||||||
// !!! FIXME: this should be non-blocking so we can check device->shutdown.
|
// !!! FIXME: this should be non-blocking so we can check device->shutdown.
|
||||||
// this is set to blocking, because we _have_ to send the entire buffer down, but hopefully WaitDevice took most of the delay time.
|
// this is set to blocking, because we _have_ to send the entire buffer down, but hopefully WaitDevice took most of the delay time.
|
||||||
if (SNDIO_sio_write(device->hidden->dev, buffer, buflen) != buflen) {
|
if (SNDIO_sio_write(device->hidden->dev, buffer, buflen) != buflen) {
|
||||||
SDL_AudioDeviceDisconnected(device); // If we couldn't write, assume fatal error for now
|
return -1; // If we couldn't write, assume fatal error for now
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_AUDIO
|
#ifdef DEBUG_AUDIO
|
||||||
fprintf(stderr, "Wrote %d bytes of audio data\n", written);
|
fprintf(stderr, "Wrote %d bytes of audio data\n", written);
|
||||||
#endif
|
#endif
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int SNDIO_CaptureFromDevice(SDL_AudioDevice *device, void *buffer, int buflen)
|
static int SNDIO_CaptureFromDevice(SDL_AudioDevice *device, void *buffer, int buflen)
|
||||||
|
@@ -130,9 +130,9 @@ static int VITAAUD_OpenDevice(SDL_AudioDevice *device)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void VITAAUD_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
|
static int VITAAUD_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
|
||||||
{
|
{
|
||||||
sceAudioOutOutput(device->hidden->port, buffer);
|
return (sceAudioOutOutput(device->hidden->port, buffer) == 0) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function waits until it is possible to write a full sound buffer
|
// This function waits until it is possible to write a full sound buffer
|
||||||
|
@@ -413,12 +413,13 @@ static Uint8 *WASAPI_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
|||||||
return (Uint8 *)buffer;
|
return (Uint8 *)buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WASAPI_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
static int WASAPI_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
||||||
{
|
{
|
||||||
if (device->hidden->render != NULL) { // definitely activated?
|
if (device->hidden->render != NULL) { // definitely activated?
|
||||||
// WasapiFailed() will mark the device for reacquisition or removal elsewhere.
|
// WasapiFailed() will mark the device for reacquisition or removal elsewhere.
|
||||||
WasapiFailed(device, IAudioRenderClient_ReleaseBuffer(device->hidden->render, device->sample_frames, 0));
|
WasapiFailed(device, IAudioRenderClient_ReleaseBuffer(device->hidden->render, device->sample_frames, 0));
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WASAPI_WaitDevice(SDL_AudioDevice *device)
|
static void WASAPI_WaitDevice(SDL_AudioDevice *device)
|
||||||
|
Reference in New Issue
Block a user