USB: Cleanup eyetoy code a bit.

Types, casts, consts.
This commit is contained in:
lightningterror 2024-11-15 15:20:44 +01:00
parent 9c753cb692
commit 8132a8a7f8
3 changed files with 27 additions and 28 deletions

View File

@ -34,10 +34,9 @@ namespace usb_eyetoy
HRESULT DirectShow::CallbackHandler::SampleCB(double time, IMediaSample* sample)
{
HRESULT hr;
unsigned char* buffer;
hr = sample->GetPointer((BYTE**)&buffer);
const HRESULT hr = sample->GetPointer((BYTE**)&buffer);
if (hr != S_OK)
return S_OK;
@ -588,7 +587,7 @@ namespace usb_eyetoy
{
mpeg_mutex.lock();
int len2 = mpeg_buffer.length;
if ((unsigned int)len < mpeg_buffer.length)
if (static_cast<size_t>(len) < mpeg_buffer.length)
len2 = len;
memcpy(buf, mpeg_buffer.start, len2);
mpeg_buffer.length = 0;

View File

@ -26,8 +26,8 @@ namespace usb_eyetoy
std::unique_ptr<VideoDevice> videodev;
USBDevice* mic;
uint8_t regs[0xFF]; //OV519
uint8_t i2c_regs[0xFF]; //OV764x
u8 regs[0xFF]; //OV519
u8 i2c_regs[0xFF]; //OV764x
int hw_camera_running;
int frame_step;
@ -81,10 +81,10 @@ namespace usb_eyetoy
}
else if (s->hw_camera_running && s->subtype == TYPE_OV511P)
{
const int width = 320;
const int height = 240;
constexpr int width = 320;
constexpr int height = 240;
const FrameFormat format = format_yuv400;
const int mirror = 0;
constexpr int mirror = 0;
Console.WriteLn(
"EyeToy : eyetoy_open(); hw=%d, w=%d, h=%d, fmt=%d, mirr=%d", s->hw_camera_running, width, height, format, mirror);
if (s->videodev->Open(width, height, format, mirror) != 0)
@ -111,7 +111,7 @@ namespace usb_eyetoy
s->mic->klass.handle_reset(s->mic);
}
static void webcam_handle_control_eyetoy(USBDevice* dev, USBPacket* p, int request, int value, int index, int length, uint8_t* data)
static void webcam_handle_control_eyetoy(USBDevice* dev, USBPacket* p, int request, int value, int index, int length, u8* data)
{
EYETOYState* s = USB_CONTAINER_OF(dev, EYETOYState, dev);
int ret = 0;
@ -172,9 +172,9 @@ namespace usb_eyetoy
case R518_I2C_CTL:
if (data[0] == 1) // Commit I2C write
{
//uint8_t reg = s->regs[s->regs[R51x_I2C_W_SID]];
uint8_t reg = s->regs[R51x_I2C_SADDR_3];
uint8_t val = s->regs[R51x_I2C_DATA];
//u8 reg = s->regs[s->regs[R51x_I2C_W_SID]];
const u8 reg = s->regs[R51x_I2C_SADDR_3];
const u8 val = s->regs[R51x_I2C_DATA];
if ((reg == 0x12) && (val & 0x80))
{
s->i2c_regs[0x12] = val & ~0x80; //or skip?
@ -194,7 +194,7 @@ namespace usb_eyetoy
else if (s->regs[R518_I2C_CTL] == 0x03 && data[0] == 0x05)
{
//s->regs[s->regs[R51x_I2C_R_SID]] but seems to default to 0x43 (R51x_I2C_SADDR_2)
uint8_t i2c_reg = s->regs[R51x_I2C_SADDR_2];
const u8 i2c_reg = s->regs[R51x_I2C_SADDR_2];
s->regs[R51x_I2C_DATA] = 0;
if (i2c_reg < sizeof(s->i2c_regs))
@ -218,7 +218,7 @@ namespace usb_eyetoy
}
}
static void webcam_handle_control_ov511p(USBDevice* dev, USBPacket* p, int request, int value, int index, int length, uint8_t* data)
static void webcam_handle_control_ov511p(USBDevice* dev, USBPacket* p, int request, int value, int index, int length, u8* data)
{
EYETOYState* s = USB_CONTAINER_OF(dev, EYETOYState, dev);
int ret = 0;
@ -242,8 +242,8 @@ namespace usb_eyetoy
case R511_I2C_CTL:
if (data[0] == 1)
{
uint8_t reg = s->regs[R51x_I2C_SADDR_3];
uint8_t val = s->regs[R51x_I2C_DATA];
u8 reg = s->regs[R51x_I2C_SADDR_3];
const u8 val = s->regs[R51x_I2C_DATA];
if (reg < sizeof(s->i2c_regs))
{
s->i2c_regs[reg] = val;
@ -251,7 +251,7 @@ namespace usb_eyetoy
}
else if (s->regs[R511_I2C_CTL] == 0x03 && data[0] == 0x05)
{
uint8_t i2c_reg = s->regs[R51x_I2C_SADDR_2];
const u8 i2c_reg = s->regs[R51x_I2C_SADDR_2];
s->regs[R51x_I2C_DATA] = 0;
if (i2c_reg < sizeof(s->i2c_regs))
@ -277,8 +277,8 @@ namespace usb_eyetoy
static void webcam_handle_data_eyetoy(USBDevice* dev, USBPacket* p)
{
EYETOYState* s = USB_CONTAINER_OF(dev, EYETOYState, dev);
static const unsigned int max_ep_size = 896;
uint8_t devep = p->ep->nr;
static constexpr unsigned int max_ep_size = 896;
const u8 devep = p->ep->nr;
if (!s->hw_camera_running)
{
@ -346,7 +346,7 @@ namespace usb_eyetoy
static void webcam_handle_data_ov511p(USBDevice* dev, USBPacket* p)
{
EYETOYState* s = USB_CONTAINER_OF(dev, EYETOYState, dev);
uint8_t devep = p->ep->nr;
const u8 devep = p->ep->nr;
if (!s->hw_camera_running)
{

View File

@ -11,7 +11,7 @@
namespace usb_eyetoy
{
static const uint8_t eyetoy_dev_descriptor[] = {
static const u8 eyetoy_dev_descriptor[] = {
0x12, /* bLength */
0x01, /* bDescriptorType */
WBVAL(0x0110), /* bcdUSB */
@ -28,7 +28,7 @@ namespace usb_eyetoy
0x01, /* bNumConfigurations */
};
static const uint8_t eyetoy_config_descriptor[] = {
static const u8 eyetoy_config_descriptor[] = {
0x09, // bLength
0x02, // bDescriptorType (Configuration)
0xB4, 0x00, // wTotalLength 180
@ -215,7 +215,7 @@ namespace usb_eyetoy
0x00, 0x00, // wLockDelay 0
};
static const uint8_t ov511p_dev_descriptor[] = {
static const u8 ov511p_dev_descriptor[] = {
0x12, // bLength
0x01, // bDescriptorType (Device)
0x00, 0x01, // bcdUSB 1.00
@ -232,7 +232,7 @@ namespace usb_eyetoy
0x01, // bNumConfigurations 1
};
static const uint8_t ov511p_config_descriptor[] = {
static const u8 ov511p_config_descriptor[] = {
0x09, // bLength
0x02, // bDescriptorType (Configuration)
0x89, 0x00, // wTotalLength 137
@ -379,7 +379,7 @@ namespace usb_eyetoy
0x01, // bInterval 1 (unit depends on device speed)
};
static const uint8_t ov519_defaults[] = {
static const u8 ov519_defaults[] = {
0xc0, 0x00, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x14, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x98, 0xff, 0x00, 0x03, 0x00, 0x00, 0x1e, 0x01, 0xf1, 0x00, 0x01, 0x00, 0x00, 0x00,
@ -398,7 +398,7 @@ namespace usb_eyetoy
0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const uint8_t ov7648_defaults[] = {
static const u8 ov7648_defaults[] = {
0x00, 0x84, 0x84, 0x84, 0x34, 0x3e, 0x80, 0x8c, 0x00, 0x00, 0x76, 0x48, 0x7b, 0x5b, 0x00, 0x98,
0x57, 0x00, 0x14, 0xa3, 0x04, 0x00, 0x00, 0x1a, 0xba, 0x03, 0xf3, 0x00, 0x7f, 0xa2, 0x00, 0x01,
0xc0, 0x80, 0x80, 0xde, 0x10, 0x8a, 0xa2, 0xe2, 0x20, 0x00, 0x00, 0x00, 0x88, 0x81, 0x00, 0x94,
@ -417,7 +417,7 @@ namespace usb_eyetoy
0x75, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const uint8_t ov511p_defaults[] = {
static const u8 ov511p_defaults[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x27, 0x1d, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x4f, 0x1d, 0x00, 0x01, 0x01, 0x04,
0x01, 0x01, 0x01, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -436,7 +436,7 @@ namespace usb_eyetoy
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const uint8_t ov7620_defaults[] = {
static const u8 ov7620_defaults[] = {
0x00, 0x84, 0x84, 0x84, 0x34, 0x3e, 0x80, 0x8c, 0x00, 0x00, 0x76, 0x48, 0x7b, 0x5b, 0x00, 0x98,
0x57, 0x00, 0x14, 0xa3, 0x04, 0x00, 0x00, 0x1a, 0xba, 0x03, 0xf3, 0x00, 0x7f, 0xa2, 0x00, 0x01,
0xc0, 0x80, 0x80, 0xde, 0x10, 0x8a, 0xa2, 0xe2, 0x20, 0x00, 0x00, 0x00, 0x88, 0x81, 0x00, 0x94,