1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

Add some error handling to sys_usbd

This commit is contained in:
RipleyTom 2022-04-13 23:18:03 +02:00 committed by Megamouse
parent 57aee92bfe
commit 91768c025c

View File

@ -119,7 +119,7 @@ private:
std::map<u32, UsbPipe> open_pipes;
// Transfers infos
shared_mutex mutex_transfers;
std::array<UsbTransfer, 0x44> transfers;
std::array<UsbTransfer, MAX_SYS_USBD_TRANSFERS> transfers;
std::vector<UsbTransfer*> fake_transfers;
// Queue of pending usbd events
@ -143,13 +143,28 @@ void LIBUSB_CALL callback_transfer(struct libusb_transfer* transfer)
usb_handler_thread::usb_handler_thread()
{
if (libusb_init(&ctx) < 0)
if (int res = libusb_init(&ctx); res < 0)
{
sys_usbd.error("Failed to initialize sys_usbd: %s", libusb_error_name(res));
return;
}
for (u32 index = 0; index < MAX_SYS_USBD_TRANSFERS; index++)
{
transfers[index].transfer = libusb_alloc_transfer(8);
transfers[index].transfer_id = index;
}
// look if any device which we could be interested in is actually connected
libusb_device** list = nullptr;
ssize_t ndev = libusb_get_device_list(ctx, &list);
if (ndev < 0)
{
sys_usbd.error("Failed to get device list: %s", libusb_error_name(ndev));
return;
}
std::array<u8, 7> location{};
auto get_new_location = [&]() -> const std::array<u8, 7>&
@ -164,7 +179,11 @@ usb_handler_thread::usb_handler_thread()
for (ssize_t index = 0; index < ndev; index++)
{
libusb_device_descriptor desc;
libusb_get_device_descriptor(list[index], &desc);
if (int res = libusb_get_device_descriptor(list[index], &desc); res < 0)
{
sys_usbd.error("Failed to get device descriptor: %s", libusb_error_name(res));
continue;
}
auto check_device = [&](const u16 id_vendor, const u16 id_product_min, const u16 id_product_max, const char* s_name) -> bool
{
@ -190,11 +209,11 @@ usb_handler_thread::usb_handler_thread()
check_device(0x0E6F, 0x200A, 0x200A, "Kamen Rider Summonride Portal");
// Cameras
//check_device(0x1415, 0x0020, 0x2000, "Sony Playstation Eye"); // TODO: verifiy
// check_device(0x1415, 0x0020, 0x2000, "Sony Playstation Eye"); // TODO: verifiy
// Music devices
check_device(0x1415, 0x0000, 0x0000, "SingStar Microphone");
//check_device(0x1415, 0x0020, 0x0020, "SingStar Microphone Wireless"); // TODO: verifiy
// check_device(0x1415, 0x0020, 0x0020, "SingStar Microphone Wireless"); // TODO: verifiy
check_device(0x12BA, 0x0100, 0x0100, "Guitar Hero Guitar");
check_device(0x12BA, 0x0120, 0x0120, "Guitar Hero Drums");
check_device(0x12BA, 0x074B, 0x074B, "Guitar Hero Live Guitar");
@ -288,12 +307,6 @@ usb_handler_thread::usb_handler_thread()
sys_usbd.notice("Adding emulated Buzz! buzzer (5-7 players)");
usb_devices.push_back(std::make_shared<usb_device_buzz>(4, 6, get_new_location()));
}
for (u32 index = 0; index < MAX_SYS_USBD_TRANSFERS; index++)
{
transfers[index].transfer = libusb_alloc_transfer(8);
transfers[index].transfer_id = index;
}
}
usb_handler_thread::~usb_handler_thread()