mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-17 08:11:51 +00:00
cellMic: add nullptr check for data in cell_mic_read
Also rename S to Size for readability
This commit is contained in:
parent
e05239f3d9
commit
cf5a66a204
@ -1144,8 +1144,6 @@ error_code cellMicRemoveNotifyEventQueue(u64 key)
|
||||
|
||||
error_code cell_mic_read(s32 dev_num, vm::ptr<void> data, s32 max_bytes, /*CellMicSignalType*/u32 type)
|
||||
{
|
||||
// TODO: CELL_MICIN_ERROR_PARAM
|
||||
|
||||
auto& mic_thr = g_fxo->get<mic_thread>();
|
||||
const std::lock_guard lock(mic_thr.mutex);
|
||||
if (!mic_thr.init)
|
||||
@ -1159,16 +1157,19 @@ error_code cell_mic_read(s32 dev_num, vm::ptr<void> data, s32 max_bytes, /*CellM
|
||||
if (!device.is_opened() || !(device.get_signal_types() & type))
|
||||
return CELL_MICIN_ERROR_NOT_OPEN;
|
||||
|
||||
if (!data)
|
||||
return not_an_error(0);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case CELLMIC_SIGTYPE_DSP: return not_an_error(device.read_dsp(vm::_ptr<u8>(data.addr()), max_bytes));
|
||||
case CELLMIC_SIGTYPE_AUX: return CELL_OK; // TODO
|
||||
case CELLMIC_SIGTYPE_AUX: return not_an_error(0); // TODO
|
||||
case CELLMIC_SIGTYPE_RAW: return not_an_error(device.read_raw(vm::_ptr<u8>(data.addr()), max_bytes));
|
||||
default:
|
||||
fmt::throw_exception("Invalid CELLMIC_SIGTYPE %d", type);
|
||||
}
|
||||
|
||||
return CELL_OK;
|
||||
return not_an_error(0);
|
||||
}
|
||||
|
||||
error_code cellMicReadRaw(s32 dev_num, vm::ptr<void> data, s32 max_bytes)
|
||||
|
@ -157,8 +157,7 @@ struct CellMicInputStream
|
||||
|
||||
struct CellMicInputDefinition
|
||||
{
|
||||
// TODO: Data types
|
||||
volatile u32 uiDevId;
|
||||
be_t<u32> uiDevId;
|
||||
CellMicInputStream data;
|
||||
CellMicInputFormatI aux_format;
|
||||
CellMicInputFormatI raw_format;
|
||||
@ -182,13 +181,13 @@ struct CellMicStatus
|
||||
// --- End of cell definitions ---
|
||||
|
||||
|
||||
template <usz S>
|
||||
template <usz Size>
|
||||
class simple_ringbuf
|
||||
{
|
||||
public:
|
||||
simple_ringbuf()
|
||||
{
|
||||
m_container.resize(S);
|
||||
m_container.resize(Size);
|
||||
}
|
||||
|
||||
bool has_data() const
|
||||
@ -200,19 +199,19 @@ public:
|
||||
{
|
||||
ensure(buf);
|
||||
|
||||
u32 to_read = size > m_used ? m_used : size;
|
||||
const u32 to_read = size > m_used ? m_used : size;
|
||||
if (!to_read)
|
||||
return 0;
|
||||
|
||||
u8* data = m_container.data();
|
||||
u32 new_tail = m_tail + to_read;
|
||||
const u32 new_tail = m_tail + to_read;
|
||||
|
||||
if (new_tail >= S)
|
||||
if (new_tail >= Size)
|
||||
{
|
||||
u32 first_chunk_size = S - m_tail;
|
||||
const u32 first_chunk_size = Size - m_tail;
|
||||
std::memcpy(buf, data + m_tail, first_chunk_size);
|
||||
std::memcpy(buf + first_chunk_size, data, to_read - first_chunk_size);
|
||||
m_tail = (new_tail - S);
|
||||
m_tail = (new_tail - Size);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -227,15 +226,17 @@ public:
|
||||
|
||||
void write_bytes(const u8* buf, const u32 size)
|
||||
{
|
||||
ensure(size <= S);
|
||||
ensure(size <= Size);
|
||||
|
||||
if (u32 over_size = m_used + size; over_size > S)
|
||||
const u32 over_size = m_used + size;
|
||||
|
||||
if (over_size > Size)
|
||||
{
|
||||
m_tail += (over_size - S);
|
||||
if (m_tail > S)
|
||||
m_tail -= S;
|
||||
m_tail += (over_size - Size);
|
||||
if (m_tail > Size)
|
||||
m_tail -= Size;
|
||||
|
||||
m_used = S;
|
||||
m_used = Size;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -243,14 +244,14 @@ public:
|
||||
}
|
||||
|
||||
u8* data = m_container.data();
|
||||
u32 new_head = m_head + size;
|
||||
const u32 new_head = m_head + size;
|
||||
|
||||
if (new_head >= S)
|
||||
if (new_head >= Size)
|
||||
{
|
||||
u32 first_chunk_size = S - m_head;
|
||||
const u32 first_chunk_size = Size - m_head;
|
||||
std::memcpy(data + m_head, buf, first_chunk_size);
|
||||
std::memcpy(data, buf + first_chunk_size, size - first_chunk_size);
|
||||
m_head = (new_head - S);
|
||||
m_head = (new_head - Size);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user