audio: Assigning a device channel map to an audio stream was quietly failing.

Fixes #10317.
This commit is contained in:
Ryan C. Gordon
2024-07-19 20:25:23 -04:00
parent 6d39c18dd3
commit 068c785491
3 changed files with 7 additions and 3 deletions

View File

@@ -251,7 +251,7 @@ static void UpdateAudioStreamFormatsPhysical(SDL_AudioDevice *device)
// SDL_SetAudioStreamFormat does a ton of validation just to memcpy an audiospec. // SDL_SetAudioStreamFormat does a ton of validation just to memcpy an audiospec.
SDL_LockMutex(stream->lock); SDL_LockMutex(stream->lock);
SDL_copyp(&stream->dst_spec, &spec); SDL_copyp(&stream->dst_spec, &spec);
SDL_SetAudioStreamOutputChannelMap(stream, device->chmap, spec.channels); // this should be fast for normal cases, though! SetAudioStreamChannelMap(stream, &stream->dst_spec, &stream->dst_chmap, device->chmap, spec.channels, -1); // this should be fast for normal cases, though!
SDL_UnlockMutex(stream->lock); SDL_UnlockMutex(stream->lock);
} }
} }

View File

@@ -584,7 +584,7 @@ int SDL_SetAudioStreamFormat(SDL_AudioStream *stream, const SDL_AudioSpec *src_s
return 0; return 0;
} }
static int SetAudioStreamChannelMap(SDL_AudioStream *stream, const SDL_AudioSpec *spec, int **stream_chmap, const int *chmap, int channels, SDL_bool isinput) int SetAudioStreamChannelMap(SDL_AudioStream *stream, const SDL_AudioSpec *spec, int **stream_chmap, const int *chmap, int channels, int isinput)
{ {
if (!stream) { if (!stream) {
return SDL_InvalidParamError("stream"); return SDL_InvalidParamError("stream");
@@ -602,7 +602,7 @@ static int SetAudioStreamChannelMap(SDL_AudioStream *stream, const SDL_AudioSpec
// already have this map, don't allocate/copy it again. // already have this map, don't allocate/copy it again.
} else if (SDL_ChannelMapIsBogus(chmap, channels)) { } else if (SDL_ChannelMapIsBogus(chmap, channels)) {
retval = SDL_SetError("Invalid channel mapping"); retval = SDL_SetError("Invalid channel mapping");
} else if (stream->bound_device && (!!isinput == !!stream->bound_device->physical_device->recording)) { } else if ((isinput != -1) && stream->bound_device && (!!isinput == !!stream->bound_device->physical_device->recording)) {
// quietly refuse to change the format of the end currently bound to a device. // quietly refuse to change the format of the end currently bound to a device.
} else { } else {
if (SDL_ChannelMapIsDefault(chmap, channels)) { if (SDL_ChannelMapIsDefault(chmap, channels)) {

View File

@@ -137,6 +137,10 @@ extern void OnAudioStreamDestroy(SDL_AudioStream *stream);
// This just lets audio playback apply logical device gain at the same time as audiostream gain, so it's one multiplication instead of thousands. // This just lets audio playback apply logical device gain at the same time as audiostream gain, so it's one multiplication instead of thousands.
extern int SDL_GetAudioStreamDataAdjustGain(SDL_AudioStream *stream, void *voidbuf, int len, float extra_gain); extern int SDL_GetAudioStreamDataAdjustGain(SDL_AudioStream *stream, void *voidbuf, int len, float extra_gain);
// This is the bulk of `SDL_SetAudioStream*putChannelMap`'s work, but it lets you skip the check about changing the device end of a stream if isinput==-1.
extern int SetAudioStreamChannelMap(SDL_AudioStream *stream, const SDL_AudioSpec *spec, int **stream_chmap, const int *chmap, int channels, int isinput);
typedef struct SDL_AudioDriverImpl typedef struct SDL_AudioDriverImpl
{ {
void (*DetectDevices)(SDL_AudioDevice **default_playback, SDL_AudioDevice **default_recording); void (*DetectDevices)(SDL_AudioDevice **default_playback, SDL_AudioDevice **default_recording);