mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-02 07:27:19 +08:00
Update sample processing bookkeeping when recovering the AAudio audio device
This commit is contained in:
@@ -171,12 +171,9 @@ static void AAUDIO_WaitDevice(SDL_AudioDevice *device)
|
|||||||
|
|
||||||
static int BuildAAudioStream(SDL_AudioDevice *device);
|
static int BuildAAudioStream(SDL_AudioDevice *device);
|
||||||
|
|
||||||
static int RecoverAAudioDeviceIfFailed(SDL_AudioDevice *device)
|
static int RecoverAAudioDevice(SDL_AudioDevice *device)
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *hidden = device->hidden;
|
struct SDL_PrivateAudioData *hidden = device->hidden;
|
||||||
const aaudio_result_t err = (aaudio_result_t) SDL_AtomicGet(&hidden->error_callback_triggered);
|
|
||||||
if (err) {
|
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_AUDIO, "aaudio: Audio device triggered error %d (%s)", (int) err, ctx.AAudio_convertResultToText(err));
|
|
||||||
|
|
||||||
// attempt to build a new stream, in case there's a new default device.
|
// attempt to build a new stream, in case there's a new default device.
|
||||||
ctx.AAudioStream_requestStop(hidden->stream);
|
ctx.AAudioStream_requestStop(hidden->stream);
|
||||||
@@ -193,7 +190,7 @@ static int RecoverAAudioDeviceIfFailed(SDL_AudioDevice *device)
|
|||||||
SDL_AudioSpec prevspec;
|
SDL_AudioSpec prevspec;
|
||||||
SDL_copyp(&prevspec, &device->spec);
|
SDL_copyp(&prevspec, &device->spec);
|
||||||
|
|
||||||
if (BuildAAudioStream(device) == -1) {
|
if (BuildAAudioStream(device) < 0) {
|
||||||
return -1; // oh well, we tried.
|
return -1; // oh well, we tried.
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,14 +202,9 @@ static int RecoverAAudioDeviceIfFailed(SDL_AudioDevice *device)
|
|||||||
|
|
||||||
device->sample_frames = prev_sample_frames;
|
device->sample_frames = prev_sample_frames;
|
||||||
SDL_copyp(&device->spec, &prevspec);
|
SDL_copyp(&device->spec, &prevspec);
|
||||||
if (SDL_AudioDeviceFormatChangedAlreadyLocked(device, &newspec, new_sample_frames) == -1) {
|
if (SDL_AudioDeviceFormatChangedAlreadyLocked(device, &newspec, new_sample_frames) < 0) {
|
||||||
return -1; // ugh
|
return -1; // ugh
|
||||||
}
|
}
|
||||||
|
|
||||||
// we're recovering from PlayDevice, so wait until the data callback fires so we know we fed the pending buffer to the device.
|
|
||||||
SDL_WaitSemaphore(device->hidden->semaphore);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,12 +214,17 @@ static int AAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int b
|
|||||||
struct SDL_PrivateAudioData *hidden = device->hidden;
|
struct SDL_PrivateAudioData *hidden = device->hidden;
|
||||||
|
|
||||||
// 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 (RecoverAAudioDeviceIfFailed(device) == -1) {
|
const aaudio_result_t err = (aaudio_result_t) SDL_AtomicGet(&hidden->error_callback_triggered);
|
||||||
|
if (err) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_AUDIO, "aaudio: Audio device triggered error %d (%s)", (int) err, ctx.AAudio_convertResultToText(err));
|
||||||
|
|
||||||
|
if (RecoverAAudioDevice(device) < 0) {
|
||||||
return -1; // oh well, we went down hard.
|
return -1; // oh well, we went down hard.
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
SDL_MemoryBarrierRelease();
|
SDL_MemoryBarrierRelease();
|
||||||
hidden->processed_bytes += buflen;
|
hidden->processed_bytes += buflen;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,6 +355,8 @@ static int BuildAAudioStream(SDL_AudioDevice *device)
|
|||||||
if (hidden->mixbuf == NULL) {
|
if (hidden->mixbuf == NULL) {
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
}
|
}
|
||||||
|
hidden->processed_bytes = 0;
|
||||||
|
hidden->callback_bytes = 0;
|
||||||
|
|
||||||
hidden->semaphore = SDL_CreateSemaphore(iscapture ? 0 : hidden->num_buffers);
|
hidden->semaphore = SDL_CreateSemaphore(iscapture ? 0 : hidden->num_buffers);
|
||||||
if (!hidden->semaphore) {
|
if (!hidden->semaphore) {
|
||||||
|
|||||||
Reference in New Issue
Block a user