* extracted some private methods to have a more readable code

* fixed negative parameter values handling
* clean up and method shuffle


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42703 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2011-08-30 22:10:46 +00:00
parent f7ca82dc00
commit 67eb6cdee8
2 changed files with 334 additions and 358 deletions
@@ -755,68 +755,178 @@ UVCCamDevice::_SelectIdleAlternate()
}
UVCCamDeviceAddon::UVCCamDeviceAddon(WebCamMediaAddOn* webcam)
: CamDeviceAddon(webcam)
void
UVCCamDevice::_AddProcessingParameter(BParameterGroup* group,
int32 index, const usbvc_processing_unit_descriptor* descriptor)
{
printf("UVCCamDeviceAddon::UVCCamDeviceAddon(WebCamMediaAddOn* webcam)\n");
SetSupportedDevices(kSupportedDevices);
BParameterGroup* subgroup;
BContinuousParameter* p;
uint16 wValue = 0; // Control Selector
float minValue = 0.0;
float maxValue = 100.0;
if (descriptor->controlSize >= 1) {
if (descriptor->controls[0] & 1) {
// debug_printf("\tBRIGHTNESS\n");
fBrightness = _AddParameter(group, &subgroup, index,
PU_BRIGHTNESS_CONTROL, "Brightness");
}
if (descriptor->controls[0] & 2) {
// debug_printf("\tCONSTRAST\n");
fContrast = _AddParameter(group, &subgroup, index + 1,
PU_CONTRAST_CONTROL, "Contrast");
}
if (descriptor->controls[0] & 4) {
// debug_printf("\tHUE\n");
fHue = _AddParameter(group, &subgroup, index + 2,
PU_HUE_CONTROL, "Hue");
if (descriptor->controlSize >= 2) {
if (descriptor->controls[1] & 8) {
fHueAuto = _AddAutoParameter(subgroup, index + 3,
PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL);
}
}
}
if (descriptor->controls[0] & 8) {
// debug_printf("\tSATURATION\n");
fSaturation = _AddParameter(group, &subgroup, index + 4,
PU_SATURATION_CONTROL, "Saturation");
}
if (descriptor->controls[0] & 16) {
// debug_printf("\tSHARPNESS\n");
fSharpness = _AddParameter(group, &subgroup, index + 5,
PU_SHARPNESS_CONTROL, "Sharpness");
}
if (descriptor->controls[0] & 32) {
// debug_printf("\tGamma\n");
fGamma = _AddParameter(group, &subgroup, index + 6,
PU_GAMMA_CONTROL, "Gamma");
}
if (descriptor->controls[0] & 64) {
// debug_printf("\tWHITE BALANCE TEMPERATURE\n");
fWBTemp = _AddParameter(group, &subgroup, index + 7,
PU_WHITE_BALANCE_TEMPERATURE_CONTROL, "WB Temperature");
if (descriptor->controlSize >= 2) {
if (descriptor->controls[1] & 16) {
fWBTempAuto = _AddAutoParameter(subgroup, index + 8,
PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL);
}
}
}
if (descriptor->controls[0] & 128) {
// debug_printf("\tWhite Balance Component\n");
fWBComponent = _AddParameter(group, &subgroup, index + 9,
PU_WHITE_BALANCE_COMPONENT_CONTROL, "WB Component");
if (descriptor->controlSize >= 2) {
if (descriptor->controls[1] & 32) {
fWBTempAuto = _AddAutoParameter(subgroup, index + 10,
PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL);
}
}
}
}
if (descriptor->controlSize >= 2) {
if (descriptor->controls[1] & 1) {
// debug_printf("\tBACKLIGHT COMPENSATION\n");
int16 data;
wValue = PU_BACKLIGHT_COMPENSATION_CONTROL << 8;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_IN,
GET_MAX, wValue, fControlRequestIndex, sizeof(data), &data);
maxValue = (float)data;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_IN,
GET_MIN, wValue, fControlRequestIndex, sizeof(data), &data);
minValue = (float)data;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_IN,
GET_CUR, wValue, fControlRequestIndex, sizeof(data), &data);
fBacklightCompensation = (float)data;
subgroup = group->MakeGroup("Backlight Compensation");
if (maxValue - minValue == 1) { // Binary Switch
fBinaryBacklightCompensation = true;
subgroup->MakeDiscreteParameter(index + 11,
B_MEDIA_RAW_VIDEO, "Backlight Compensation",
B_ENABLE);
} else { // Range of values
fBinaryBacklightCompensation = false;
p = subgroup->MakeContinuousParameter(index + 11,
B_MEDIA_RAW_VIDEO, "Backlight Compensation",
B_GAIN, "", minValue, maxValue, 1.0 / (maxValue - minValue));
}
}
if (descriptor->controls[1] & 2) {
// debug_printf("\tGAIN\n");
fGain = _AddParameter(group, &subgroup, index + 12, PU_GAIN_CONTROL,
"Gain");
}
if (descriptor->controls[1] & 4) {
// debug_printf("\tPOWER LINE FREQUENCY\n");
wValue = PU_POWER_LINE_FREQUENCY_CONTROL << 8;
int8 data;
if (fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_IN,
GET_CUR, wValue, fControlRequestIndex, sizeof(data), &data) == sizeof(data)) {
fPowerlineFrequency = data;
}
subgroup = group->MakeGroup("Power Line Frequency");
p = subgroup->MakeContinuousParameter(index + 13,
B_MEDIA_RAW_VIDEO, "Frequency", B_GAIN, "", 0, 60.0, 1.0 / 60.0);
}
// TODO Determine whether controls apply to these
/*
if (descriptor->controls[1] & 64)
debug_printf("\tDigital Multiplier\n");
if (descriptor->controls[1] & 128)
debug_printf("\tDigital Multiplier Limit\n");
*/
}
// TODO Determine whether controls apply to these
/*
if (descriptor->controlSize >= 3) {
if (descriptor->controls[2] & 1)
debug_printf("\tAnalog Video Standard\n");
if (descriptor->controls[2] & 2)
debug_printf("\tAnalog Video Lock Status\n");
}
*/
}
UVCCamDeviceAddon::~UVCCamDeviceAddon()
{
}
const char *
UVCCamDeviceAddon::BrandName()
{
printf("UVCCamDeviceAddon::BrandName()\n");
return "USB Video Class";
}
UVCCamDevice *
UVCCamDeviceAddon::Instantiate(CamRoster& roster, BUSBDevice* from)
{
printf("UVCCamDeviceAddon::Instantiate()\n");
return new UVCCamDevice(*this, from);
}
float
UVCCamDevice::_AddParameter(BParameterGroup* group,
BParameterGroup** subgroup, int32 index, uint16 wValue, const char* name)
{
float minValue = 0.0;
float maxValue = 100.0;
float currValue = 0.0;
float minValue = 0.0;
float maxValue = 100.0;
float currValue = 0.0;
int16 data;
BContinuousParameter* p;
uint16 data;
wValue <<= 8;
wValue = wValue << 8;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_IN,
GET_MAX, wValue, fControlRequestIndex, 2, &data);
maxValue = (float)(*((uint16*)data));
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_IN,
GET_MIN, wValue, fControlRequestIndex, 2, &data);
minValue = (float)(*((uint16*)data));
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_IN,
GET_CUR, wValue, fControlRequestIndex, 2, &data);
if (fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_IN,
GET_MAX, wValue, fControlRequestIndex, sizeof(data), &data)
== sizeof(data)) {
maxValue = (float)data;
}
if (fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_IN,
GET_MIN, wValue, fControlRequestIndex, sizeof(data), &data)
== sizeof(data)) {
minValue = (float)data;
}
if (fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_IN,
GET_CUR, wValue, fControlRequestIndex, sizeof(data), &data)
== sizeof(data)) {
currValue = (float)data;
}
*subgroup = group->MakeGroup(name);
p = (*subgroup)->MakeContinuousParameter(index,
B_MEDIA_RAW_VIDEO, name,
B_GAIN, "", minValue, maxValue, 1.0 / (maxValue - minValue));
return currValue;
*subgroup = group->MakeGroup(name);
BContinuousParameter* p = (*subgroup)->MakeContinuousParameter(index,
B_MEDIA_RAW_VIDEO, name, B_GAIN, "", minValue, maxValue,
1.0 / (maxValue - minValue));
return currValue;
}
int UVCCamDevice::_AddAutoParameter(BParameterGroup* subgroup, int32 index,
uint8
UVCCamDevice::_AddAutoParameter(BParameterGroup* subgroup, int32 index,
uint16 wValue)
{
uint8 data;
@@ -837,161 +947,32 @@ UVCCamDevice::AddParameters(BParameterGroup* group, int32& index)
printf("UVCCamDevice::AddParameters()\n");
fFirstParameterID = index;
// debug_printf("fIndex = %d\n",fIndex);
BParameterGroup* subgroup;
BContinuousParameter* p;
CamDevice::AddParameters(group, index);
const BUSBConfiguration* config;
const BUSBInterface* interface;
usb_descriptor* generic;
uint8 buffer[1024];
void* data = (void*)(new uint16);
generic = (usb_descriptor*)buffer;
usb_descriptor* generic = (usb_descriptor*)buffer;
for (uint32 i = 0; i < fDevice->CountConfigurations(); i++) {
config = fDevice->ConfigurationAt(i);
fDevice->SetConfiguration(config);
for (uint32 j = 0; j < config->CountInterfaces(); j++) {
interface = config->InterfaceAt(j);
if (interface->Class() == CC_VIDEO && interface->Subclass()
== SC_VIDEOCONTROL) {
for (uint32 k = 0; interface->OtherDescriptorAt(k, generic,
sizeof(buffer)) == B_OK; k++) {
if (generic->generic.descriptor_type != (USB_REQTYPE_CLASS
| USB_DESCRIPTOR_INTERFACE))
continue;
if (interface->Class() != CC_VIDEO || interface->Subclass()
!= SC_VIDEOCONTROL)
continue;
for (uint32 k = 0; interface->OtherDescriptorAt(k, generic,
sizeof(buffer)) == B_OK; k++) {
if (generic->generic.descriptor_type != (USB_REQTYPE_CLASS
| USB_DESCRIPTOR_INTERFACE))
continue;
if (((const usbvc_class_descriptor*)generic)->descriptorSubtype
== VC_PROCESSING_UNIT) {
const usbvc_processing_unit_descriptor* descriptor
= (const usbvc_processing_unit_descriptor*)generic;
uint16 wValue = 0; // Control Selector
float minValue = 0.0;
float maxValue = 100.0;
if (descriptor->controlSize >= 1) {
if (descriptor->controls[0] & 1) {
// debug_printf("\tBRIGHTNESS\n");
fBrightness = _AddParameter(group, &subgroup, index,
PU_BRIGHTNESS_CONTROL, "Brightness");
}
if (descriptor->controls[0] & 2) {
// debug_printf("\tCONSTRAST\n");
fContrast = _AddParameter(group, &subgroup, index + 1,
PU_CONTRAST_CONTROL, "Contrast");
}
if (descriptor->controls[0] & 4) {
// debug_printf("\tHUE\n");
fHue = _AddParameter(group, &subgroup, index + 2,
PU_HUE_CONTROL, "Hue");
if (descriptor->controlSize >= 2) {
if (descriptor->controls[1] & 8) {
fHueAuto = _AddAutoParameter(subgroup, index + 3,
PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL);
}
}
}
if (descriptor->controls[0] & 8) {
// debug_printf("\tSATURATION\n");
fSaturation = _AddParameter(group, &subgroup, index + 4,
PU_SATURATION_CONTROL, "Saturation");
}
if (descriptor->controls[0] & 16) {
// debug_printf("\tSHARPNESS\n");
fSharpness = _AddParameter(group, &subgroup, index + 5,
PU_SHARPNESS_CONTROL, "Sharpness");
}
if (descriptor->controls[0] & 32) {
// debug_printf("\tGamma\n");
fGamma = _AddParameter(group, &subgroup, index + 6,
PU_GAMMA_CONTROL, "Gamma");
}
if (descriptor->controls[0] & 64) {
// debug_printf("\tWHITE BALANCE TEMPERATURE\n");
fWBTemp = _AddParameter(group, &subgroup, index + 7,
PU_WHITE_BALANCE_TEMPERATURE_CONTROL, "WB Temperature");
if (descriptor->controlSize >= 2) {
if (descriptor->controls[1] & 16) {
fWBTempAuto = _AddAutoParameter(subgroup, index + 8,
PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL);
}
}
}
if (descriptor->controls[0] & 128) {
// debug_printf("\tWhite Balance Component\n");
fWBComponent = _AddParameter(group, &subgroup, index + 9,
PU_WHITE_BALANCE_COMPONENT_CONTROL, "WB Component");
if (descriptor->controlSize >= 2) {
if (descriptor->controls[1] & 32) {
fWBTempAuto = _AddAutoParameter(subgroup, index + 10,
PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL);
}
}
}
}
if (descriptor->controlSize >= 2) {
if (descriptor->controls[1] & 1) {
// debug_printf("\tBACKLIGHT COMPENSATION\n");
wValue = PU_BACKLIGHT_COMPENSATION_CONTROL;
wValue = wValue << 8;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_IN,
GET_MAX, wValue, fControlRequestIndex, 2, data);
maxValue = (float)(*((uint16*)data));
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_IN,
GET_MIN, wValue, fControlRequestIndex, 2, data);
minValue = (float)(*((uint16*)data));
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_IN,
GET_CUR, wValue, fControlRequestIndex, 2, data);
fBacklightCompensation = (float)(*((uint16*)data));
subgroup = group->MakeGroup("Backlight Compensation");
if (maxValue - minValue == 1) { // Binary Switch
fBinaryBacklightCompensation = true;
subgroup->MakeDiscreteParameter(index + 11,
B_MEDIA_RAW_VIDEO, "Backlight Compensation",
B_ENABLE);
} else { // Range of values
fBinaryBacklightCompensation = false;
p = subgroup->MakeContinuousParameter(index + 11,
B_MEDIA_RAW_VIDEO, "Backlight Compensation",
B_GAIN, "", minValue, maxValue, 1.0/(maxValue - minValue));
}
}
if (descriptor->controls[1] & 2) {
// debug_printf("\tGAIN\n");
fGain = _AddParameter(group, &subgroup, index + 12, PU_GAIN_CONTROL,
"Gain");
}
if (descriptor->controls[1] & 4) {
// debug_printf("\tPOWER LINE FREQUENCY\n");
wValue = PU_POWER_LINE_FREQUENCY_CONTROL;
wValue = wValue << 8;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_IN,
GET_CUR, wValue, fControlRequestIndex, 1, data);
fPowerlineFrequency = (uint16)(*((uint8*)data));
subgroup = group->MakeGroup("Power Line Frequency");
p = subgroup->MakeContinuousParameter(index + 13,
B_MEDIA_RAW_VIDEO, "Frequency",
B_GAIN, "", 0, 60.0, 1.0 / 60.0);
}
// TODO Determine whether controls apply to these
/*
if (descriptor->controls[1] & 64)
debug_printf("\tDigital Multiplier\n");
if (descriptor->controls[1] & 128)
debug_printf("\tDigital Multiplier Limit\n");
*/
}
// TODO Determine whether controls apply to these
/*
if (descriptor->controlSize >= 3) {
if (descriptor->controls[2] & 1)
debug_printf("\tAnalog Video Standard\n");
if (descriptor->controls[2] & 2)
debug_printf("\tAnalog Video Lock Status\n");
}
*/
}
if (((const usbvc_class_descriptor*)generic)->descriptorSubtype
== VC_PROCESSING_UNIT) {
_AddProcessingParameter(group, index,
(const usbvc_processing_unit_descriptor*)generic);
}
}
}
@@ -1006,14 +987,14 @@ UVCCamDevice::GetParameterValue(int32 id, bigtime_t* last_change, void* value,
printf("UVCCAmDevice::GetParameterValue(%ld)\n", id - fFirstParameterID);
float* currValue;
int* currValueInt;
void* data;
int16 data;
uint16 wValue = 0;
switch (id - fFirstParameterID) {
case 0:
// debug_printf("\tBrightness:\n");
// debug_printf("\tValue = %f\n",fBrightness);
*size = sizeof(float);
currValue = ((float*)value);
currValue = (float*)value;
*currValue = fBrightness;
*last_change = fLastParameterChanges;
return B_OK;
@@ -1021,7 +1002,7 @@ UVCCamDevice::GetParameterValue(int32 id, bigtime_t* last_change, void* value,
// debug_printf("\tContrast:\n");
// debug_printf("\tValue = %f\n",fContrast);
*size = sizeof(float);
currValue = ((float*)value);
currValue = (float*)value;
*currValue = fContrast;
*last_change = fLastParameterChanges;
return B_OK;
@@ -1029,7 +1010,7 @@ UVCCamDevice::GetParameterValue(int32 id, bigtime_t* last_change, void* value,
// debug_printf("\tHue:\n");
// debug_printf("\tValue = %f\n",fHue);
*size = sizeof(float);
currValue = ((float*)value);
currValue = (float*)value;
*currValue = fHue;
*last_change = fLastParameterChanges;
return B_OK;
@@ -1037,7 +1018,7 @@ UVCCamDevice::GetParameterValue(int32 id, bigtime_t* last_change, void* value,
// debug_printf("\tSaturation:\n");
// debug_printf("\tValue = %f\n",fSaturation);
*size = sizeof(float);
currValue = ((float*)value);
currValue = (float*)value;
*currValue = fSaturation;
*last_change = fLastParameterChanges;
return B_OK;
@@ -1045,19 +1026,20 @@ UVCCamDevice::GetParameterValue(int32 id, bigtime_t* last_change, void* value,
// debug_printf("\tSharpness:\n");
// debug_printf("\tValue = %f\n",fSharpness);
*size = sizeof(float);
currValue = ((float*)value);
currValue = (float*)value;
*currValue = fSharpness;
*last_change = fLastParameterChanges;
return B_OK;
case 7:
// debug_printf("\tWB Temperature:\n");
*size = sizeof(float);
currValue = ((float*)value);
wValue = PU_WHITE_BALANCE_TEMPERATURE_CONTROL;
wValue = wValue << 8;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_IN,
GET_CUR, wValue, fControlRequestIndex, 2, data);
fWBTemp = (float)(*((uint16*)data));
currValue = (float*)value;
wValue = PU_WHITE_BALANCE_TEMPERATURE_CONTROL << 8;
if (fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_IN,
GET_CUR, wValue, fControlRequestIndex, sizeof(data), &data)
== sizeof(data)) {
fWBTemp = (float)data;
}
// debug_printf("\tValue = %f\n",fWBTemp);
*currValue = fWBTemp;
*last_change = fLastParameterChanges;
@@ -1075,13 +1057,13 @@ UVCCamDevice::GetParameterValue(int32 id, bigtime_t* last_change, void* value,
// debug_printf("\tBacklight Compensation:\n");
// debug_printf("\tValue = %f\n",fBacklightCompensation);
*size = sizeof(float);
currValue = ((float*)value);
currValue = (float*)value;
*currValue = fBacklightCompensation;
*last_change = fLastParameterChanges;
} else {
// debug_printf("\tBacklight Compensation:\n");
// debug_printf("\tValue = %d\n",fBacklightCompensationBinary);
currValueInt = ((int*)value);
currValueInt = (int*)value;
*currValueInt = fBacklightCompensationBinary;
*last_change = fLastParameterChanges;
}
@@ -1090,7 +1072,7 @@ UVCCamDevice::GetParameterValue(int32 id, bigtime_t* last_change, void* value,
// debug_printf("\tGain:\n");
// debug_printf("\tValue = %f\n",fGain);
*size = sizeof(float);
currValue = ((float*)value);
currValue = (float*)value;
*currValue = fGain;
*last_change = fLastParameterChanges;
return B_OK;
@@ -1098,7 +1080,7 @@ UVCCamDevice::GetParameterValue(int32 id, bigtime_t* last_change, void* value,
// debug_printf("\tPowerline Frequency:\n");
// debug_printf("\tValue = %d\n",fPowerlineFrequency);
*size = sizeof(float);
currValue = ((float*)value);
currValue = (float*)value;
switch (fPowerlineFrequency) {
case 0:
*currValue = 0.0;
@@ -1123,149 +1105,87 @@ UVCCamDevice::SetParameterValue(int32 id, bigtime_t when, const void* value,
size_t size)
{
printf("UVCCamDevice::SetParameterValue(%ld)\n", id - fFirstParameterID);
uint16 wValue = 0; //Control Selector
uint16 setValue = 0;
switch (id - fFirstParameterID) {
case 0:
// debug_printf("\tBrightness:\n");
// debug_printf("\tValue = %f\n",*((float*)value));
if (!value || (size != sizeof(float)))
return B_BAD_VALUE;
wValue = PU_BRIGHTNESS_CONTROL;
wValue = wValue << 8;
fBrightness = *((float*)value);
fLastParameterChanges = when;
setValue = (uint16)fBrightness;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_OUT,
SET_CUR, wValue, fControlRequestIndex, 2, &setValue);
return B_OK;
return _SetParameterValue(PU_BRIGHTNESS_CONTROL, (int16)fBrightness);
case 1:
// debug_printf("\tContrast:\n");
// debug_printf("\tValue = %f\n",*((float*)value));
if (!value || (size != sizeof(float)))
return B_BAD_VALUE;
wValue = PU_CONTRAST_CONTROL;
wValue = wValue << 8;
fContrast = *((float*)value);
fLastParameterChanges = when;
setValue = (uint16)fContrast;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_OUT,
SET_CUR, wValue, fControlRequestIndex, 2, &setValue);
return B_OK;
return _SetParameterValue(PU_CONTRAST_CONTROL, (int16)fContrast);
case 2:
// debug_printf("\tHue:\n");
// debug_printf("\tValue = %f\n",*((float*)value));
if (!value || (size != sizeof(float)))
return B_BAD_VALUE;
wValue = PU_HUE_CONTROL;
wValue = wValue << 8;
fHue = *((float*)value);
fLastParameterChanges = when;
setValue = (uint16)fHue;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_OUT,
SET_CUR, wValue, fControlRequestIndex, 2, &setValue);
return B_OK;
return _SetParameterValue(PU_HUE_CONTROL, (int16)fHue);
case 4:
// debug_printf("\tSaturation:\n");
// debug_printf("\tValue = %f\n",*((float*)value));
if (!value || (size != sizeof(float)))
return B_BAD_VALUE;
wValue = PU_SATURATION_CONTROL;
wValue = wValue << 8;
fSaturation = *((float*)value);
fLastParameterChanges = when;
setValue = (uint16)fSaturation;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_OUT,
SET_CUR, wValue, fControlRequestIndex, 2, &setValue);
return B_OK;
return _SetParameterValue(PU_SATURATION_CONTROL, (int16)fSaturation);
case 5:
// debug_printf("\tSharpness:\n");
// debug_printf("\tValue = %f\n",*((float*)value));
if (!value || (size != sizeof(float)))
return B_BAD_VALUE;
wValue = PU_SHARPNESS_CONTROL;
wValue = wValue << 8;
fSharpness = *((float*)value);
fLastParameterChanges = when;
setValue = (uint16)fSharpness;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_OUT,
SET_CUR, wValue, fControlRequestIndex, 2, &setValue);
return B_OK;
return _SetParameterValue(PU_SHARPNESS_CONTROL, (int16)fSharpness);
case 7:
if (!fWBTempAuto) {
// debug_printf("\tWB Temperature:\n");
// debug_printf("\tValue = %f\n",*((float*)value));
if (!value || (size != sizeof(float)))
return B_BAD_VALUE;
wValue = PU_WHITE_BALANCE_TEMPERATURE_CONTROL;
wValue = wValue << 8;
fWBTemp = *((float*)value);
fLastParameterChanges = when;
setValue = (uint16)fWBTemp;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_OUT,
SET_CUR, wValue, fControlRequestIndex, 2, &setValue);
}
return B_OK;
if (fWBTempAuto)
return B_OK;
// debug_printf("\tWB Temperature:\n");
if (!value || (size != sizeof(float)))
return B_BAD_VALUE;
fWBTemp = *((float*)value);
fLastParameterChanges = when;
return _SetParameterValue(PU_WHITE_BALANCE_TEMPERATURE_CONTROL,
(int16)fWBTemp);
case 8:
// debug_printf("\tWB Temperature Auto:\n");
if (!value || (size != sizeof(int)))
return B_BAD_VALUE;
// debug_printf("\tValue = %d\n",*((int*)value));
wValue = PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL;
wValue = wValue << 8;
fWBTempAuto = *((int*)value);
fLastParameterChanges = when;
setValue = fWBTempAuto;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_OUT,
SET_CUR, wValue, fControlRequestIndex, 1, &setValue);
return B_OK;
return _SetParameterValue(
PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL, (int8)fWBTempAuto);
case 11:
if (!fBinaryBacklightCompensation) {
// debug_printf("\tBacklight Compensation:\n");
if (!value || (size != sizeof(float)))
return B_BAD_VALUE;
// debug_printf("\tValue = %f\n",*((float*)value));
wValue = PU_BACKLIGHT_COMPENSATION_CONTROL;
wValue = wValue << 8;
fBacklightCompensation = *((float*)value);
fLastParameterChanges = when;
setValue = (uint16)fBacklightCompensation;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_OUT,
SET_CUR, wValue, fControlRequestIndex, 2, &setValue);
}else{
} else {
// debug_printf("\tBacklight Compensation:\n");
if (!value || (size != sizeof(int)))
return B_BAD_VALUE;
// debug_printf("\tValue = %d\n",*((int*)value));
wValue = PU_BACKLIGHT_COMPENSATION_CONTROL;
wValue = wValue << 8;
fBacklightCompensationBinary = *((int*)value);
fLastParameterChanges = when;
setValue = fBacklightCompensationBinary;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_OUT,
SET_CUR, wValue, fControlRequestIndex, 2, &setValue);
}
return B_OK;
fLastParameterChanges = when;
return _SetParameterValue(PU_BACKLIGHT_COMPENSATION_CONTROL,
(int16)fBacklightCompensationBinary);
case 12:
// debug_printf("\tGain:\n");
// debug_printf("\tValue = %f\n",*((float*)value));
if (!value || (size != sizeof(float)))
return B_BAD_VALUE;
wValue = PU_GAIN_CONTROL;
wValue = wValue << 8;
fGain = *((float*)value);
fLastParameterChanges = when;
setValue = (uint16)fGain;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_OUT,
SET_CUR, wValue, fControlRequestIndex, 2, &setValue);
return B_OK;
return _SetParameterValue(PU_GAIN_CONTROL, (int16)fGain);
case 13:
// debug_printf("\tPowerline Frequency:\n");
// debug_printf("\tValue = %f\n",*((float*)value));
if (!value || (size != sizeof(float)))
return B_BAD_VALUE;
wValue = PU_POWER_LINE_FREQUENCY_CONTROL;
wValue = wValue << 8;
float inValue = *((float*)value);
fPowerlineFrequency = 0;
if (inValue > 45.0 && inValue < 55.0) {
@@ -1275,16 +1195,32 @@ UVCCamDevice::SetParameterValue(int32 id, bigtime_t when, const void* value,
fPowerlineFrequency = 2;
}
fLastParameterChanges = when;
setValue = (uint8)fPowerlineFrequency;
fDevice->ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_INTERFACE_OUT,
SET_CUR, wValue, fControlRequestIndex, 1, &setValue);
return B_OK;
return _SetParameterValue(PU_POWER_LINE_FREQUENCY_CONTROL,
(int8)fPowerlineFrequency);
}
return B_BAD_VALUE;
}
status_t
UVCCamDevice::_SetParameterValue(uint16 wValue, int16 setValue)
{
return (fDevice->ControlTransfer(USB_REQTYPE_CLASS
| USB_REQTYPE_INTERFACE_OUT, SET_CUR, wValue << 8, fControlRequestIndex,
sizeof(setValue), &setValue)) == sizeof(setValue);
}
status_t
UVCCamDevice::_SetParameterValue(uint16 wValue, int8 setValue)
{
return (fDevice->ControlTransfer(USB_REQTYPE_CLASS
| USB_REQTYPE_INTERFACE_OUT, SET_CUR, wValue << 8, fControlRequestIndex,
sizeof(setValue), &setValue)) == sizeof(setValue);
}
status_t
UVCCamDevice::FillFrameBuffer(BBuffer* buffer, bigtime_t* stamp)
{
@@ -1392,6 +1328,37 @@ UVCCamDevice::_DecodeColor(unsigned char* dst, unsigned char* src,
}
UVCCamDeviceAddon::UVCCamDeviceAddon(WebCamMediaAddOn* webcam)
: CamDeviceAddon(webcam)
{
printf("UVCCamDeviceAddon::UVCCamDeviceAddon(WebCamMediaAddOn* webcam)\n");
SetSupportedDevices(kSupportedDevices);
}
UVCCamDeviceAddon::~UVCCamDeviceAddon()
{
}
const char *
UVCCamDeviceAddon::BrandName()
{
printf("UVCCamDeviceAddon::BrandName()\n");
return "USB Video Class";
}
UVCCamDevice *
UVCCamDeviceAddon::Instantiate(CamRoster& roster, BUSBDevice* from)
{
printf("UVCCamDeviceAddon::Instantiate()\n");
return new UVCCamDevice(*this, from);
}
extern "C" status_t
B_WEBCAM_MKINTFUNC(uvccam)
(WebCamMediaAddOn* webcam, CamDeviceAddon **addon)
@@ -49,11 +49,20 @@ private:
unsigned char *src, int32 width,
int32 height);
void _AddProcessingParameter(BParameterGroup* group,
int32 index,
const usbvc_processing_unit_descriptor*
descriptor);
float _AddParameter(BParameterGroup* group,
BParameterGroup** subgroup, int32 index,
uint16 wValue, const char* name);
int _AddAutoParameter(BParameterGroup* subgroup,
uint8 _AddAutoParameter(BParameterGroup* subgroup,
int32 index, uint16 wValue);
status_t _SetParameterValue(uint16 wValue,
int16 setValue);
status_t _SetParameterValue(uint16 wValue,
int8 setValue);
usbvc_interface_header_descriptor *fHeaderDescriptor;