mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-24 19:14:40 +00:00
better error handling for sceAudioOutput
This commit is contained in:
parent
23ca947d96
commit
f4364af462
@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include <common/assert.h>
|
#include <common/assert.h>
|
||||||
|
#include <core/libraries/error_codes.h>
|
||||||
#include "sdl_audio.h"
|
#include "sdl_audio.h"
|
||||||
|
|
||||||
namespace Audio {
|
namespace Audio {
|
||||||
@ -90,9 +91,13 @@ int SDLAudio::AudioOutOpen(int type, u32 samples_num, u32 freq,
|
|||||||
s32 SDLAudio::AudioOutOutput(s32 handle, const void* ptr) {
|
s32 SDLAudio::AudioOutOutput(s32 handle, const void* ptr) {
|
||||||
std::scoped_lock lock{m_mutex};
|
std::scoped_lock lock{m_mutex};
|
||||||
auto& port = portsOut[handle - 1];
|
auto& port = portsOut[handle - 1];
|
||||||
if (!port.isOpen || ptr == nullptr)
|
if (!port.isOpen) {
|
||||||
|
return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT;
|
||||||
|
}
|
||||||
|
if (ptr == nullptr) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
// TODO mixing channels
|
||||||
int result = SDL_PutAudioStreamData(port.stream, ptr,
|
int result = SDL_PutAudioStreamData(port.stream, ptr,
|
||||||
port.samples_num * port.sample_size * port.channels_num);
|
port.samples_num * port.sample_size * port.channels_num);
|
||||||
// TODO find a correct value 8192 is estimated
|
// TODO find a correct value 8192 is estimated
|
||||||
|
@ -34,7 +34,8 @@ private:
|
|||||||
SDL_AudioStream* stream = nullptr;
|
SDL_AudioStream* stream = nullptr;
|
||||||
};
|
};
|
||||||
std::mutex m_mutex;
|
std::mutex m_mutex;
|
||||||
std::array<PortOut, 8> portsOut; // main support up to 8 ports
|
std::array<PortOut, 22> portsOut; // main up to 8 ports , BGM 1 port , voice up to 4 ports ,
|
||||||
|
// personal up to 4 ports , padspk up to 5 ports , aux 1 port
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Audio
|
} // namespace Audio
|
@ -231,10 +231,30 @@ s32 PS4_SYSV_ABI sceAudioOutOpen(UserService::OrbisUserServiceUserId user_id,
|
|||||||
OrbisAudioOutPort port_type, s32 index, u32 length,
|
OrbisAudioOutPort port_type, s32 index, u32 length,
|
||||||
u32 sample_rate, OrbisAudioOutParam param_type) {
|
u32 sample_rate, OrbisAudioOutParam param_type) {
|
||||||
LOG_INFO(Lib_AudioOut,
|
LOG_INFO(Lib_AudioOut,
|
||||||
"AudioOutOpen id = {} port_type = {} index = {} lengh t= {} sample_rate = {} "
|
"AudioOutOpen id = {} port_type = {} index = {} lenght= {} sample_rate = {} "
|
||||||
"param_type = {}",
|
"param_type = {}",
|
||||||
user_id, GetAudioOutPort(port_type), index, length, sample_rate,
|
user_id, GetAudioOutPort(port_type), index, length, sample_rate,
|
||||||
GetAudioOutParam(param_type));
|
GetAudioOutParam(param_type));
|
||||||
|
if ((port_type < 0 || port_type > 4) && (port_type != 127)) {
|
||||||
|
LOG_ERROR(Lib_AudioOut, "Invalid port type");
|
||||||
|
return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT_TYPE;
|
||||||
|
}
|
||||||
|
if (sample_rate != 48000) {
|
||||||
|
LOG_ERROR(Lib_AudioOut, "Invalid sample rate");
|
||||||
|
return ORBIS_AUDIO_OUT_ERROR_INVALID_SAMPLE_FREQ;
|
||||||
|
}
|
||||||
|
if (param_type < 0 || param_type > 7) {
|
||||||
|
LOG_ERROR(Lib_AudioOut, "Invalid format");
|
||||||
|
return ORBIS_AUDIO_OUT_ERROR_INVALID_FORMAT;
|
||||||
|
}
|
||||||
|
if (length != 256 && length != 512 && length != 768 && length != 1024 && length != 1280 &&
|
||||||
|
length != 1536 && length != 1792 && length != 2048) {
|
||||||
|
LOG_ERROR(Lib_AudioOut, "Invalid length");
|
||||||
|
return ORBIS_AUDIO_OUT_ERROR_INVALID_SIZE;
|
||||||
|
}
|
||||||
|
if (index != 0) {
|
||||||
|
LOG_ERROR(Lib_AudioOut, "index is not valid !=0 {}", index);
|
||||||
|
}
|
||||||
int result = audio->AudioOutOpen(port_type, length, sample_rate, param_type);
|
int result = audio->AudioOutOpen(port_type, length, sample_rate, param_type);
|
||||||
if (result == -1) {
|
if (result == -1) {
|
||||||
LOG_ERROR(Lib_AudioOut, "Audio ports are full");
|
LOG_ERROR(Lib_AudioOut, "Audio ports are full");
|
||||||
|
Loading…
Reference in New Issue
Block a user