Change return type from void to int for audio function. Eventually set invalid parameter error.

This commit is contained in:
Sylvain 2023-02-08 21:22:01 +01:00 committed by Sam Lantinga
parent 824b9b0a58
commit b305d9e3c0
3 changed files with 59 additions and 34 deletions

View file

@ -554,13 +554,15 @@ extern DECLSPEC SDL_AudioStatus SDLCALL SDL_GetAudioDeviceStatus(SDL_AudioDevice
* callbacks.
*
* \param dev a device opened by SDL_OpenAudioDevice()
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_LockAudioDevice
* \sa SDL_PauseAudioDevice
*/
extern DECLSPEC void SDLCALL SDL_PlayAudioDevice(SDL_AudioDeviceID dev);
extern DECLSPEC int SDLCALL SDL_PlayAudioDevice(SDL_AudioDeviceID dev);
@ -577,13 +579,15 @@ extern DECLSPEC void SDLCALL SDL_PlayAudioDevice(SDL_AudioDeviceID dev);
* in the audio playback. Instead, you should use SDL_LockAudioDevice().
*
* \param dev a device opened by SDL_OpenAudioDevice()
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_LockAudioDevice
* \sa SDL_PlayAudioDevice
*/
extern DECLSPEC void SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev);
extern DECLSPEC int SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev);
/**
@ -1016,6 +1020,8 @@ extern DECLSPEC Uint32 SDLCALL SDL_GetQueuedAudioSize(SDL_AudioDeviceID dev);
* This function always succeeds and thus returns void.
*
* \param dev the device ID of which to clear the audio queue
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
@ -1023,7 +1029,7 @@ extern DECLSPEC Uint32 SDLCALL SDL_GetQueuedAudioSize(SDL_AudioDeviceID dev);
* \sa SDL_QueueAudio
* \sa SDL_DequeueAudio
*/
extern DECLSPEC void SDLCALL SDL_ClearQueuedAudio(SDL_AudioDeviceID dev);
extern DECLSPEC int SDLCALL SDL_ClearQueuedAudio(SDL_AudioDeviceID dev);
/**
@ -1068,12 +1074,14 @@ extern DECLSPEC void SDLCALL SDL_ClearQueuedAudio(SDL_AudioDeviceID dev);
* thread.
*
* \param dev the ID of the device to be locked
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_UnlockAudioDevice
*/
extern DECLSPEC void SDLCALL SDL_LockAudioDevice(SDL_AudioDeviceID dev);
extern DECLSPEC int SDLCALL SDL_LockAudioDevice(SDL_AudioDeviceID dev);
/**
* Use this function to unlock the audio callback function for a specified
@ -1082,12 +1090,14 @@ extern DECLSPEC void SDLCALL SDL_LockAudioDevice(SDL_AudioDeviceID dev);
* This function should be paired with a previous SDL_LockAudioDevice() call.
*
* \param dev the ID of the device to be unlocked
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_LockAudioDevice
*/
extern DECLSPEC void SDLCALL SDL_UnlockAudioDevice(SDL_AudioDeviceID dev);
extern DECLSPEC int SDLCALL SDL_UnlockAudioDevice(SDL_AudioDeviceID dev);
/* @} *//* Audio lock functions */
/**
@ -1107,12 +1117,14 @@ extern DECLSPEC void SDLCALL SDL_UnlockAudioDevice(SDL_AudioDeviceID dev);
* for reuse in a new SDL_OpenAudioDevice() call immediately.
*
* \param dev an audio device previously opened with SDL_OpenAudioDevice()
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_OpenAudioDevice
*/
extern DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID dev);
extern DECLSPEC int SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID dev);
/**
* Convert some audio data of one format to another format.

View file

@ -611,12 +611,11 @@ SDL_GetQueuedAudioSize(SDL_AudioDeviceID devid)
return retval;
}
void SDL_ClearQueuedAudio(SDL_AudioDeviceID devid)
int SDL_ClearQueuedAudio(SDL_AudioDeviceID devid)
{
SDL_AudioDevice *device = get_audio_device(devid);
if (!device) {
return; /* nothing to do. */
return SDL_InvalidParamError("devid");
}
/* Blank out the device and release the mutex. Free it afterwards. */
@ -626,6 +625,7 @@ void SDL_ClearQueuedAudio(SDL_AudioDeviceID devid)
SDL_ClearDataQueue(device->buffer_queue, SDL_AUDIOBUFFERQUEUE_PACKETLEN * 2);
current_audio.impl.UnlockDevice(device);
return 0;
}
#if SDL_AUDIO_DRIVER_ANDROID
@ -981,7 +981,7 @@ int SDL_InitAudio(const char *driver_name)
* Get the current audio driver name
*/
const char *
SDL_GetCurrentAudioDriver()
SDL_GetCurrentAudioDriver(void)
{
return current_audio.name;
}
@ -1518,47 +1518,60 @@ SDL_GetAudioDeviceStatus(SDL_AudioDeviceID devid)
return status;
}
void SDL_PauseAudioDevice(SDL_AudioDeviceID devid)
int SDL_PauseAudioDevice(SDL_AudioDeviceID devid)
{
SDL_AudioDevice *device = get_audio_device(devid);
if (device) {
current_audio.impl.LockDevice(device);
SDL_AtomicSet(&device->paused, 1);
current_audio.impl.UnlockDevice(device);
if (!device) {
return SDL_InvalidParamError("devid");
}
current_audio.impl.LockDevice(device);
SDL_AtomicSet(&device->paused, 1);
current_audio.impl.UnlockDevice(device);
return 0;
}
void SDL_PlayAudioDevice(SDL_AudioDeviceID devid)
int SDL_PlayAudioDevice(SDL_AudioDeviceID devid)
{
SDL_AudioDevice *device = get_audio_device(devid);
if (device) {
current_audio.impl.LockDevice(device);
SDL_AtomicSet(&device->paused, 0);
current_audio.impl.UnlockDevice(device);
if (!device) {
return SDL_InvalidParamError("devid");
}
current_audio.impl.LockDevice(device);
SDL_AtomicSet(&device->paused, 0);
current_audio.impl.UnlockDevice(device);
return 0;
}
void SDL_LockAudioDevice(SDL_AudioDeviceID devid)
int SDL_LockAudioDevice(SDL_AudioDeviceID devid)
{
/* Obtain a lock on the mixing buffers */
SDL_AudioDevice *device = get_audio_device(devid);
if (device) {
current_audio.impl.LockDevice(device);
if (!device) {
return SDL_InvalidParamError("devid");
}
current_audio.impl.LockDevice(device);
return 0;
}
void SDL_UnlockAudioDevice(SDL_AudioDeviceID devid)
int SDL_UnlockAudioDevice(SDL_AudioDeviceID devid)
{
/* Obtain a lock on the mixing buffers */
SDL_AudioDevice *device = get_audio_device(devid);
if (device) {
current_audio.impl.UnlockDevice(device);
if (!device) {
return SDL_InvalidParamError("devid");
}
current_audio.impl.UnlockDevice(device);
return 0;
}
void SDL_CloseAudioDevice(SDL_AudioDeviceID devid)
int SDL_CloseAudioDevice(SDL_AudioDeviceID devid)
{
close_audio_device(get_audio_device(devid));
SDL_AudioDevice *device = get_audio_device(devid);
if (!device) {
return SDL_InvalidParamError("devid");
}
close_audio_device(device);
return 0;
}
void SDL_QuitAudio(void)

View file

@ -143,8 +143,8 @@ SDL_DYNAPI_PROC(void,SDL_ClearAudioStream,(SDL_AudioStream *a),(a),)
SDL_DYNAPI_PROC(void,SDL_ClearComposition,(void),(),)
SDL_DYNAPI_PROC(void,SDL_ClearError,(void),(),)
SDL_DYNAPI_PROC(void,SDL_ClearHints,(void),(),)
SDL_DYNAPI_PROC(void,SDL_ClearQueuedAudio,(SDL_AudioDeviceID a),(a),)
SDL_DYNAPI_PROC(void,SDL_CloseAudioDevice,(SDL_AudioDeviceID a),(a),)
SDL_DYNAPI_PROC(int,SDL_ClearQueuedAudio,(SDL_AudioDeviceID a),(a),return)
SDL_DYNAPI_PROC(int,SDL_CloseAudioDevice,(SDL_AudioDeviceID a),(a),return)
SDL_DYNAPI_PROC(void,SDL_CloseGamepad,(SDL_Gamepad *a),(a),)
SDL_DYNAPI_PROC(int,SDL_CloseJoystick,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_CloseSensor,(SDL_Sensor *a),(a),)
@ -529,7 +529,7 @@ SDL_DYNAPI_PROC(void*,SDL_LoadFile_RW,(SDL_RWops *a, size_t *b, int c),(a,b,c),r
SDL_DYNAPI_PROC(SDL_FunctionPointer,SDL_LoadFunction,(void *a, const char *b),(a,b),return)
SDL_DYNAPI_PROC(void*,SDL_LoadObject,(const char *a),(a),return)
SDL_DYNAPI_PROC(SDL_AudioSpec*,SDL_LoadWAV_RW,(SDL_RWops *a, int b, SDL_AudioSpec *c, Uint8 **d, Uint32 *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(void,SDL_LockAudioDevice,(SDL_AudioDeviceID a),(a),)
SDL_DYNAPI_PROC(int,SDL_LockAudioDevice,(SDL_AudioDeviceID a),(a),return)
SDL_DYNAPI_PROC(void,SDL_LockJoysticks,(void),(),)
SDL_DYNAPI_PROC(int,SDL_LockMutex,(SDL_mutex *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_LockSurface,(SDL_Surface *a),(a),return)
@ -565,7 +565,7 @@ SDL_DYNAPI_PROC(SDL_Gamepad*,SDL_OpenGamepad,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(SDL_Joystick*,SDL_OpenJoystick,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(SDL_Sensor*,SDL_OpenSensor,(SDL_SensorID a),(a),return)
SDL_DYNAPI_PROC(int,SDL_OpenURL,(const char *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_PauseAudioDevice,(SDL_AudioDeviceID a),(a),)
SDL_DYNAPI_PROC(int,SDL_PauseAudioDevice,(SDL_AudioDeviceID a),(a),return)
SDL_DYNAPI_PROC(int,SDL_PeepEvents,(SDL_Event *a, int b, SDL_eventaction c, Uint32 d, Uint32 e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(int,SDL_PollEvent,(SDL_Event *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_PremultiplyAlpha,(int a, int b, Uint32 c, const void *d, int e, Uint32 f, void *g, int h),(a,b,c,d,e,f,g,h),return)
@ -722,7 +722,7 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_TextInputShown,(void),(),return)
SDL_DYNAPI_PROC(SDL_threadID,SDL_ThreadID,(void),(),return)
SDL_DYNAPI_PROC(int,SDL_TryLockMutex,(SDL_mutex *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_UnloadObject,(void *a),(a),)
SDL_DYNAPI_PROC(void,SDL_UnlockAudioDevice,(SDL_AudioDeviceID a),(a),)
SDL_DYNAPI_PROC(int,SDL_UnlockAudioDevice,(SDL_AudioDeviceID a),(a),return)
SDL_DYNAPI_PROC(void,SDL_UnlockJoysticks,(void),(),)
SDL_DYNAPI_PROC(int,SDL_UnlockMutex,(SDL_mutex *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_UnlockSurface,(SDL_Surface *a),(a),)
@ -897,7 +897,7 @@ SDL_DYNAPI_PROC(wchar_t*,SDL_wcsstr,(const wchar_t *a, const wchar_t *b),(a,b),r
SDL_DYNAPI_PROC(double,SDL_modf,(double a, double *b),(a,b),return)
SDL_DYNAPI_PROC(float,SDL_modff,(float a, float *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderVSync,(SDL_Renderer *a, int *b),(a,b),return)
SDL_DYNAPI_PROC(void,SDL_PlayAudioDevice,(SDL_AudioDeviceID a),(a),)
SDL_DYNAPI_PROC(int,SDL_PlayAudioDevice,(SDL_AudioDeviceID a),(a),return)
SDL_DYNAPI_PROC(void*,SDL_aligned_alloc,(size_t a, size_t b),(a,b),return)
SDL_DYNAPI_PROC(void,SDL_aligned_free,(void *a),(a),)
SDL_DYNAPI_PROC(int,SDL_ConvertAudioSamples,(SDL_AudioFormat a, Uint8 b, int c, int d, Uint8 *e, SDL_AudioFormat f, Uint8 g, int h, int *i, Uint8 **j),(a,b,c,d,e,f,g,h,i,j),return)