audio: PlayDevice now passes the buffer, too, for convenience.

main
Ryan C. Gordon 2023-07-03 20:34:15 -04:00
parent e518149d14
commit 258bc9efed
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
5 changed files with 11 additions and 15 deletions

View File

@ -415,7 +415,7 @@ void SDL_AudioDeviceDisconnected(SDL_AudioDevice *device)
static void SDL_AudioThreadInit_Default(SDL_AudioDevice *device) { /* no-op. */ } static void SDL_AudioThreadInit_Default(SDL_AudioDevice *device) { /* no-op. */ }
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, int buffer_size) { /* no-op. */ } static void SDL_AudioPlayDevice_Default(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) { /* 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. */ }
@ -738,7 +738,7 @@ SDL_bool SDL_OutputAudioThreadIterate(SDL_AudioDevice *device)
} }
// !!! FIXME: have PlayDevice return a value and do disconnects in here with it. // !!! FIXME: have PlayDevice return a value and do disconnects in here with it.
current_audio.impl.PlayDevice(device, buffer_size); // this SHOULD NOT BLOCK, as we are holding a lock right now. Block in WaitDevice! current_audio.impl.PlayDevice(device, mix_buffer, buffer_size); // this SHOULD NOT BLOCK, as we are holding a lock right now. Block in WaitDevice!
} }
SDL_UnlockMutex(device->lock); SDL_UnlockMutex(device->lock);

View File

@ -108,7 +108,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, int buffer_size); void (*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);

View File

@ -41,11 +41,9 @@ 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, int buffer_size) static void DISKAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
{ {
const Sint64 written = SDL_RWwrite(device->hidden->io, const Sint64 written = SDL_RWwrite(device->hidden->io, buffer, buffer_size);
device->hidden->mixbuf,
buffer_size);
/* If we couldn't write, assume fatal error for now */ /* If we couldn't write, assume fatal error for now */
if (written != buffer_size) { if (written != buffer_size) {

View File

@ -948,7 +948,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, int buffer_size) static void 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;

View File

@ -388,18 +388,16 @@ 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, int buffer_size) static void PULSEAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
{ {
struct SDL_PrivateAudioData *h = device->hidden; struct SDL_PrivateAudioData *h = device->hidden;
const int available = buffer_size;
int rc;
/*printf("PULSEAUDIO PLAYDEVICE START! mixlen=%d\n", available);*/ /*printf("PULSEAUDIO PLAYDEVICE START! mixlen=%d\n", available);*/
SDL_assert(h->bytes_requested >= available); SDL_assert(h->bytes_requested >= buffer_size);
PULSEAUDIO_pa_threaded_mainloop_lock(pulseaudio_threaded_mainloop); PULSEAUDIO_pa_threaded_mainloop_lock(pulseaudio_threaded_mainloop);
rc = PULSEAUDIO_pa_stream_write(h->stream, h->mixbuf, available, NULL, 0LL, PA_SEEK_RELATIVE); const int rc = PULSEAUDIO_pa_stream_write(h->stream, buffer, buffer_size, NULL, 0LL, PA_SEEK_RELATIVE);
PULSEAUDIO_pa_threaded_mainloop_unlock(pulseaudio_threaded_mainloop); PULSEAUDIO_pa_threaded_mainloop_unlock(pulseaudio_threaded_mainloop);
if (rc < 0) { if (rc < 0) {
@ -407,8 +405,8 @@ static void PULSEAUDIO_PlayDevice(SDL_AudioDevice *device, int buffer_size)
return; return;
} }
/*printf("PULSEAUDIO FEED! nbytes=%u\n", (unsigned int) available);*/ /*printf("PULSEAUDIO FEED! nbytes=%d\n", buffer_size);*/
h->bytes_requested -= available; h->bytes_requested -= buffer_size;
/*printf("PULSEAUDIO PLAYDEVICE END! written=%d\n", written);*/ /*printf("PULSEAUDIO PLAYDEVICE END! written=%d\n", written);*/
} }