* style fixes.

* added SuggestVideoFrame() so that this can be overriden.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41195 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2011-04-07 20:59:30 +00:00
parent d7411ad2ec
commit c5a669052f
3 changed files with 39 additions and 21 deletions
@@ -3,6 +3,7 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include "CamDevice.h" #include "CamDevice.h"
#include "CamSensor.h" #include "CamSensor.h"
#include "CamDeframer.h" #include "CamDeframer.h"
@@ -49,8 +50,7 @@ CamDevice::CamDevice(CamDeviceAddon &_addon, BUSBDevice* _device)
memset(&fFlavorInfo, 0, sizeof(fFlavorInfo)); memset(&fFlavorInfo, 0, sizeof(fFlavorInfo));
_addon.WebCamAddOn()->FillDefaultFlavorInfo(&fFlavorInfo); _addon.WebCamAddOn()->FillDefaultFlavorInfo(&fFlavorInfo);
// if we use id matching, cache the index to the list // if we use id matching, cache the index to the list
if (fCamDeviceAddon.SupportedDevices()) if (fCamDeviceAddon.SupportedDevices()) {
{
fSupportedDeviceIndex = fCamDeviceAddon.Sniff(_device); fSupportedDeviceIndex = fCamDeviceAddon.Sniff(_device);
fFlavorInfoNameStr = ""; fFlavorInfoNameStr = "";
fFlavorInfoNameStr << fCamDeviceAddon.SupportedDevices()[fSupportedDeviceIndex].vendor << " USB Webcam"; fFlavorInfoNameStr << fCamDeviceAddon.SupportedDevices()[fSupportedDeviceIndex].vendor << " USB Webcam";
@@ -90,7 +90,7 @@ CamDevice::InitCheck()
bool bool
CamDevice::Matches(BUSBDevice* _device) CamDevice::Matches(BUSBDevice* _device)
{ {
return (_device) == (fDevice); return _device == fDevice;
} }
@@ -156,7 +156,8 @@ CamDevice::StartTransfer()
PRINT((CH "()" CT)); PRINT((CH "()" CT));
if (fTransferEnabled) if (fTransferEnabled)
return EALREADY; return EALREADY;
fPumpThread = spawn_thread(_DataPumpThread, "USB Webcam Data Pump", 50, this); fPumpThread = spawn_thread(_DataPumpThread, "USB Webcam Data Pump", 50,
this);
if (fPumpThread < B_OK) if (fPumpThread < B_OK)
return fPumpThread; return fPumpThread;
if (fSensor) if (fSensor)
@@ -192,6 +193,18 @@ CamDevice::StopTransfer()
} }
status_t
CamDevice::SuggestVideoFrame(uint32 &width, uint32 &height)
{
if (Sensor()) {
width = Sensor()->MaxWidth();
height = Sensor()->MaxHeight();
return B_OK;
}
return B_NO_INIT;
}
status_t status_t
CamDevice::AcceptVideoFrame(uint32 &width, uint32 &height) CamDevice::AcceptVideoFrame(uint32 &width, uint32 &height)
{ {
@@ -200,7 +213,7 @@ CamDevice::AcceptVideoFrame(uint32 &width, uint32 &height)
err = Sensor()->AcceptVideoFrame(width, height); err = Sensor()->AcceptVideoFrame(width, height);
if (err < B_OK) if (err < B_OK)
return err; return err;
fVideoFrame = BRect(0, 0, width - 1, height - 1); SetVideoFrame(BRect(0, 0, width - 1, height - 1));
return B_OK; return B_OK;
} }
@@ -221,7 +234,8 @@ CamDevice::SetScale(float scale)
status_t status_t
CamDevice::SetVideoParams(float brightness, float contrast, float hue, float red, float green, float blue) CamDevice::SetVideoParams(float brightness, float contrast, float hue,
float red, float green, float blue)
{ {
return B_OK; return B_OK;
} }
@@ -235,14 +249,16 @@ CamDevice::AddParameters(BParameterGroup *group, int32 &index)
status_t status_t
CamDevice::GetParameterValue(int32 id, bigtime_t *last_change, void *value, size_t *size) CamDevice::GetParameterValue(int32 id, bigtime_t *last_change, void *value,
size_t *size)
{ {
return B_BAD_VALUE; return B_BAD_VALUE;
} }
status_t status_t
CamDevice::SetParameterValue(int32 id, bigtime_t when, const void *value, size_t size) CamDevice::SetParameterValue(int32 id, bigtime_t when, const void *value,
size_t size)
{ {
return B_BAD_VALUE; return B_BAD_VALUE;
} }
@@ -270,7 +286,8 @@ CamDevice::ValidateStartOfFrameTag(const uint8 *tag, size_t taglen)
bool bool
CamDevice::ValidateEndOfFrameTag(const uint8 *tag, size_t taglen, size_t datalen) CamDevice::ValidateEndOfFrameTag(const uint8 *tag, size_t taglen,
size_t datalen)
{ {
return true; return true;
} }
@@ -449,8 +466,7 @@ CamDevice::ProbeSensor()
if (fCamDeviceAddon.SupportedDevices() == NULL) if (fCamDeviceAddon.SupportedDevices() == NULL)
return B_ERROR; return B_ERROR;
devs = fCamDeviceAddon.SupportedDevices(); devs = fCamDeviceAddon.SupportedDevices();
for (i = 0; devs[i].vendor; i++) for (i = 0; devs[i].vendor; i++) {
{
if (GetDevice()->VendorID() != devs[i].desc.vendor) if (GetDevice()->VendorID() != devs[i].desc.vendor)
continue; continue;
if (GetDevice()->ProductID() != devs[i].desc.product) if (GetDevice()->ProductID() != devs[i].desc.product)
@@ -474,7 +490,8 @@ CamDevice::ProbeSensor()
if (err >= B_OK) if (err >= B_OK)
return B_OK; return B_OK;
PRINT((CH ": sensor '%s' Probe: %s" CT, name.String(), strerror(err))); PRINT((CH ": sensor '%s' Probe: %s" CT, name.String(),
strerror(err)));
delete fSensor; delete fSensor;
fSensor = NULL; fSensor = NULL;
@@ -491,8 +508,7 @@ CamDevice::ProbeSensor()
CamSensor * CamSensor *
CamDevice::CreateSensor(const char *name) CamDevice::CreateSensor(const char *name)
{ {
int i; for (int32 i = 0; kSensorTable[i].name; i++) {
for (i = 0; kSensorTable[i].name; i++) {
if (!strcmp(kSensorTable[i].name, name)) if (!strcmp(kSensorTable[i].name, name))
return kSensorTable[i].instfunc(this); return kSensorTable[i].instfunc(this);
} }
@@ -612,7 +628,7 @@ status_t
CamDevice::SendCommand(uint8 dir, uint8 request, uint16 value, CamDevice::SendCommand(uint8 dir, uint8 request, uint16 value,
uint16 index, uint16 length, void* data) uint16 index, uint16 length, void* data)
{ {
size_t ret; ssize_t ret;
if (!GetDevice()) if (!GetDevice())
return ENODEV; return ENODEV;
if (length > GetDevice()->MaxEndpoint0PacketSize()) if (length > GetDevice()->MaxEndpoint0PacketSize())
@@ -61,6 +61,7 @@ class CamDevice {
virtual status_t StopTransfer(); virtual status_t StopTransfer();
virtual bool TransferEnabled() const { return fTransferEnabled; }; virtual bool TransferEnabled() const { return fTransferEnabled; };
virtual status_t SuggestVideoFrame(uint32 &width, uint32 &height);
virtual status_t AcceptVideoFrame(uint32 &width, uint32 &height); virtual status_t AcceptVideoFrame(uint32 &width, uint32 &height);
virtual status_t SetVideoFrame(BRect rect); virtual status_t SetVideoFrame(BRect rect);
virtual BRect VideoFrame() const { return fVideoFrame; }; virtual BRect VideoFrame() const { return fVideoFrame; };
@@ -340,9 +340,10 @@ VideoProducer::FormatSuggestionRequested(
format->u.raw_video.display.line_count)); format->u.raw_video.display.line_count));
*format = fOutput.format; *format = fOutput.format;
if (fCamDevice && fCamDevice->Sensor()) { uint32 width, height;
format->u.raw_video.display.line_width = fCamDevice->Sensor()->MaxWidth(); if (fCamDevice && fCamDevice->SuggestVideoFrame(width, height) == B_OK) {
format->u.raw_video.display.line_count = fCamDevice->Sensor()->MaxHeight(); format->u.raw_video.display.line_width = width;
format->u.raw_video.display.line_count = height;
} }
format->u.raw_video.field_rate = FIELD_RATE; format->u.raw_video.field_rate = FIELD_RATE;
return B_OK; return B_OK;