partial clean up

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36198 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2010-04-12 20:34:04 +00:00
parent 50e4dd9328
commit 02af02f93a
30 changed files with 326 additions and 299 deletions
@@ -48,19 +48,19 @@ WebCamMediaAddOn::~WebCamMediaAddOn()
} }
status_t status_t
WebCamMediaAddOn::InitCheck(const char **out_failure_text) WebCamMediaAddOn::InitCheck(const char **out_failure_text)
{ {
if (fInitStatus < B_OK) { if (fInitStatus < B_OK) {
*out_failure_text = "No cameras attached"; *out_failure_text = "No cameras attached";
return fInitStatus; return fInitStatus;
} }
return B_OK; return B_OK;
} }
int32 int32
WebCamMediaAddOn::CountFlavors() WebCamMediaAddOn::CountFlavors()
{ {
PRINT((CH "()" CT)); PRINT((CH "()" CT));
@@ -78,10 +78,10 @@ WebCamMediaAddOn::CountFlavors()
/* /*
* The pointer to the flavor received only needs to be valid between * The pointer to the flavor received only needs to be valid between
* successive calls to BMediaAddOn::GetFlavorAt(). * successive calls to BMediaAddOn::GetFlavorAt().
*/ */
status_t status_t
WebCamMediaAddOn::GetFlavorAt(int32 n, const flavor_info **out_info) WebCamMediaAddOn::GetFlavorAt(int32 n, const flavor_info **out_info)
{ {
PRINT((CH "(%d, ) roster %p is %lx" CT, n, fRoster, fInitStatus)); PRINT((CH "(%d, ) roster %p is %lx" CT, n, fRoster, fInitStatus));
@@ -191,7 +191,7 @@ WebCamMediaAddOn::FillDefaultFlavorInfo(flavor_info* info)
BMediaAddOn * BMediaAddOn *
make_media_addon(image_id imid) make_media_addon(image_id id)
{ {
return new WebCamMediaAddOn(imid); return new WebCamMediaAddOn(id);
} }
@@ -14,12 +14,11 @@ extern "C" _EXPORT BMediaAddOn *make_media_addon(image_id you);
class CamRoster; class CamRoster;
class CamDevice; class CamDevice;
class WebCamMediaAddOn : public BMediaAddOn class WebCamMediaAddOn : public BMediaAddOn {
{
public: public:
WebCamMediaAddOn(image_id imid); WebCamMediaAddOn(image_id imid);
virtual ~WebCamMediaAddOn(); virtual ~WebCamMediaAddOn();
virtual status_t InitCheck(const char **out_failure_text); virtual status_t InitCheck(const char **out_failure_text);
virtual int32 CountFlavors(); virtual int32 CountFlavors();
@@ -44,7 +43,7 @@ public:
status_t CameraAdded(CamDevice* device); status_t CameraAdded(CamDevice* device);
status_t CameraRemoved(CamDevice* device); status_t CameraRemoved(CamDevice* device);
void FillDefaultFlavorInfo(flavor_info* info); void FillDefaultFlavorInfo(flavor_info* info);
private: private:
uint32 fInternalIDCounter; uint32 fInternalIDCounter;
status_t fInitStatus; status_t fInitStatus;
@@ -9,8 +9,8 @@
CamBufferedFilterInterface::CamBufferedFilterInterface(CamDevice *device, bool allowWrite) CamBufferedFilterInterface::CamBufferedFilterInterface(CamDevice *device, bool allowWrite)
: CamFilterInterface(device), : CamFilterInterface(device),
fAllowWrite(allowWrite) fAllowWrite(allowWrite)
{ {
} }
@@ -10,8 +10,7 @@
#include <interface/Rect.h> #include <interface/Rect.h>
#include "CamFilterInterface.h" #include "CamFilterInterface.h"
class CamBufferedFilterInterface : public CamFilterInterface class CamBufferedFilterInterface : public CamFilterInterface {
{
public: public:
CamBufferedFilterInterface(CamDevice *device, bool allowWrite); CamBufferedFilterInterface(CamDevice *device, bool allowWrite);
virtual ~CamBufferedFilterInterface(); virtual ~CamBufferedFilterInterface();
@@ -3,7 +3,7 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
/* /*
* buffer based deframer * buffer based deframer
* buffers all packet until it finds a complete frame. * buffers all packet until it finds a complete frame.
* simpler than StreamingDeframer, but doesn't work any better * simpler than StreamingDeframer, but doesn't work any better
@@ -22,8 +22,8 @@
CamBufferingDeframer::CamBufferingDeframer(CamDevice *device) CamBufferingDeframer::CamBufferingDeframer(CamDevice *device)
: CamDeframer(device), : CamDeframer(device),
fInputBuffIndex(0) fInputBuffIndex(0)
{ {
} }
@@ -67,30 +67,30 @@ CamBufferingDeframer::Write(const void *buffer, size_t size)
break; break;
if (!fDevice->ValidateStartOfFrameTag(b + s, fSkipSOFTags)) if (!fDevice->ValidateStartOfFrameTag(b + s, fSkipSOFTags))
continue; continue;
PRINT((CH ": SOF[%d] at offset %d" CT, which, s)); PRINT((CH ": SOF[%d] at offset %d" CT, which, s));
PRINT((CH ": SOF: ... %02x %02x %02x %02x %02x %02x" CT, b[s+6], b[s+7], b[s+8], b[s+9], b[s+10], b[s+11])); PRINT((CH ": SOF: ... %02x %02x %02x %02x %02x %02x" CT, b[s+6], b[s+7], b[s+8], b[s+9], b[s+10], b[s+11]));
for (e = s + fSkipSOFTags + fMinFrameSize; for (e = s + fSkipSOFTags + fMinFrameSize;
((e <= (int)(s + fSkipSOFTags + fMaxFrameSize)) && ((e <= (int)(s + fSkipSOFTags + fMaxFrameSize)) &&
(e < l) && ((i = 0*FindEOF(b + e, l - e, &which)) > -1)); (e < l) && ((i = 0*FindEOF(b + e, l - e, &which)) > -1));
e++) { e++) {
e += i; e += i;
//PRINT((CH ": EOF[%d] at offset %d" CT, which, s)); //PRINT((CH ": EOF[%d] at offset %d" CT, which, s));
if (!fDevice->ValidateEndOfFrameTag(b + e, fSkipEOFTags, e - s - fSkipSOFTags)) if (!fDevice->ValidateEndOfFrameTag(b + e, fSkipEOFTags, e - s - fSkipSOFTags))
continue; continue;
PRINT((CH ": SOF= ... %02x %02x %02x %02x %02x %02x" CT, b[s+6], b[s+7], b[s+8], b[s+9], b[s+10], b[s+11])); PRINT((CH ": SOF= ... %02x %02x %02x %02x %02x %02x" CT, b[s+6], b[s+7], b[s+8], b[s+9], b[s+10], b[s+11]));
// we have one! // we have one!
s += fSkipSOFTags; s += fSkipSOFTags;
// fill it // fill it
fCurrentFrame->Write(b + s, e - s); fCurrentFrame->Write(b + s, e - s);
// queue it // queue it
BAutolock f(fLocker); BAutolock f(fLocker);
PRINT((CH ": Detaching a frame (%d bytes, %d to %d / %d)" CT, (size_t)fCurrentFrame->Position(), s, e, l)); PRINT((CH ": Detaching a frame (%d bytes, %d to %d / %d)" CT, (size_t)fCurrentFrame->Position(), s, e, l));
@@ -101,7 +101,7 @@ CamBufferingDeframer::Write(const void *buffer, size_t size)
fCurrentFrame = NULL; fCurrentFrame = NULL;
// discard the frame and everything before it. // discard the frame and everything before it.
DiscardFromInput(e + fSkipEOFTags); DiscardFromInput(e + fSkipEOFTags);
return size; return size;
} }
} }
@@ -126,4 +126,3 @@ CamBufferingDeframer::DiscardFromInput(size_t size)
fInputBuffIndex = next; fInputBuffIndex = next;
return size; return size;
} }
@@ -7,8 +7,7 @@
#include "CamDeframer.h" #include "CamDeframer.h"
class CamBufferingDeframer : public CamDeframer class CamBufferingDeframer : public CamDeframer {
{
public: public:
CamBufferingDeframer(CamDevice *device); CamBufferingDeframer(CamDevice *device);
virtual ~CamBufferingDeframer(); virtual ~CamBufferingDeframer();
@@ -27,22 +27,22 @@ CamColorSpaceTransform::CamColorSpaceTransform()
: fInitStatus(B_NO_INIT), : fInitStatus(B_NO_INIT),
fVideoFrame() fVideoFrame()
{ {
} }
CamColorSpaceTransform::~CamColorSpaceTransform() CamColorSpaceTransform::~CamColorSpaceTransform()
{ {
} }
status_t status_t
CamColorSpaceTransform::InitCheck() CamColorSpaceTransform::InitCheck()
{ {
return fInitStatus; return fInitStatus;
} }
const char * const char *
CamColorSpaceTransform::Name() CamColorSpaceTransform::Name()
@@ -68,12 +68,9 @@ CamColorSpaceTransform::SetVideoFrame(BRect rect)
CamColorSpaceTransform * CamColorSpaceTransform *
CamColorSpaceTransform::Create(const char *name) CamColorSpaceTransform::Create(const char *name)
{ {
int i; for (int i = 0; kTransformTable[i].name; i++) {
for (i = 0; kTransformTable[i].name; i++) {
if (!strcmp(kTransformTable[i].name, name)) if (!strcmp(kTransformTable[i].name, name))
return kTransformTable[i].instfunc(); return kTransformTable[i].instfunc();
} }
return NULL; return NULL;
} }
@@ -9,22 +9,21 @@
#include <Rect.h> #include <Rect.h>
// This class represents the camera's (cmos or whatever) sensor chip // This class represents the camera's (cmos or whatever) sensor chip
class CamColorSpaceTransform class CamColorSpaceTransform {
{ public:
public:
CamColorSpaceTransform(); CamColorSpaceTransform();
virtual ~CamColorSpaceTransform(); virtual ~CamColorSpaceTransform();
virtual status_t InitCheck(); virtual status_t InitCheck();
virtual const char* Name(); virtual const char* Name();
virtual color_space OutputSpace(); virtual color_space OutputSpace();
virtual status_t SetVideoFrame(BRect rect); virtual status_t SetVideoFrame(BRect rect);
virtual BRect VideoFrame() const { return fVideoFrame; }; virtual BRect VideoFrame() const { return fVideoFrame; };
static CamColorSpaceTransform *Create(const char *name); static CamColorSpaceTransform *Create(const char *name);
protected: protected:
status_t fInitStatus; status_t fInitStatus;
BRect fVideoFrame; BRect fVideoFrame;
@@ -13,19 +13,19 @@
CamDeframer::CamDeframer(CamDevice *device) CamDeframer::CamDeframer(CamDevice *device)
: CamFilterInterface(device), : CamFilterInterface(device),
fDevice(device), fDevice(device),
fState(ST_SYNC), fState(ST_SYNC),
fFrameSem(B_ERROR), fFrameSem(B_ERROR),
fLocker("CamDeframer Framelist lock", true), fLocker("CamDeframer Framelist lock", true),
fSOFTags(NULL), fSOFTags(NULL),
fEOFTags(NULL), fEOFTags(NULL),
fNumSOFTags(0), fNumSOFTags(0),
fNumEOFTags(0), fNumEOFTags(0),
fLenSOFTags(0), fLenSOFTags(0),
fLenEOFTags(0), fLenEOFTags(0),
fSkipSOFTags(0), fSkipSOFTags(0),
fSkipEOFTags(0) fSkipEOFTags(0)
{ {
fMinFrameSize = fDevice->MinRawFrameSize(); fMinFrameSize = fDevice->MinRawFrameSize();
fMaxFrameSize = fDevice->MaxRawFrameSize(); fMaxFrameSize = fDevice->MaxRawFrameSize();
@@ -217,4 +217,3 @@ CamDeframer::AllocFrame()
{ {
return new CamFrame(); return new CamFrame();
} }
@@ -22,8 +22,7 @@ ST_FRAME
/* should have a real Frame class someday */ /* should have a real Frame class someday */
class CamFrame : public BMallocIO class CamFrame : public BMallocIO {
{
public: public:
CamFrame() : BMallocIO() { fStamp = system_time(); }; CamFrame() : BMallocIO() { fStamp = system_time(); };
virtual ~CamFrame() {}; virtual ~CamFrame() {};
@@ -31,8 +30,7 @@ bigtime_t Stamp() const { return fStamp; };
bigtime_t fStamp; bigtime_t fStamp;
}; };
class CamDeframer : public CamFilterInterface class CamDeframer : public CamFilterInterface {
{
public: public:
CamDeframer(CamDevice *device); CamDeframer(CamDevice *device);
virtual ~CamDeframer(); virtual ~CamDeframer();
@@ -78,16 +78,16 @@ CamDevice::~CamDevice()
if (fDeframer) if (fDeframer)
delete fDeframer; delete fDeframer;
} }
status_t status_t
CamDevice::InitCheck() CamDevice::InitCheck()
{ {
return fInitStatus; return fInitStatus;
} }
bool
bool
CamDevice::Matches(BUSBDevice* _device) CamDevice::Matches(BUSBDevice* _device)
{ {
return (_device) == (fDevice); return (_device) == (fDevice);
@@ -182,12 +182,12 @@ CamDevice::StopTransfer()
if (err < B_OK) if (err < B_OK)
return err; return err;
fTransferEnabled = false; fTransferEnabled = false;
// the thread itself might Lock() // the thread itself might Lock()
fLocker.Unlock(); fLocker.Unlock();
wait_for_thread(fPumpThread, &err); wait_for_thread(fPumpThread, &err);
fLocker.Lock(); fLocker.Lock();
return B_OK; return B_OK;
} }
@@ -233,12 +233,14 @@ CamDevice::AddParameters(BParameterGroup *group, int32 &index)
fFirstParameterID = index; fFirstParameterID = 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)
{ {
@@ -246,7 +248,6 @@ CamDevice::SetParameterValue(int32 id, bigtime_t when, const void *value, size_t
} }
size_t size_t
CamDevice::MinRawFrameSize() CamDevice::MinRawFrameSize()
{ {
@@ -395,6 +396,7 @@ CamDevice::WriteIIC8(uint8 address, uint8 data)
return WriteIIC(address, &data, 1); return WriteIIC(address, &data, 1);
} }
ssize_t ssize_t
CamDevice::WriteIIC16(uint8 address, uint16 data) CamDevice::WriteIIC16(uint8 address, uint16 data)
{ {
@@ -406,8 +408,6 @@ CamDevice::WriteIIC16(uint8 address, uint16 data)
} }
ssize_t ssize_t
CamDevice::ReadIIC(uint8 address, uint8 *data) CamDevice::ReadIIC(uint8 address, uint8 *data)
{ {
@@ -467,7 +467,7 @@ CamDevice::ProbeSensor()
BString name; BString name;
sensors.CopyInto(name, i, sensors.FindFirst(',', i) - i); sensors.CopyInto(name, i, sensors.FindFirst(',', i) - i);
PRINT((CH ": probing sensor '%s'..." CT, name.String())); PRINT((CH ": probing sensor '%s'..." CT, name.String()));
fSensor = CreateSensor(name.String()); fSensor = CreateSensor(name.String());
if (fSensor) { if (fSensor) {
err = fSensor->Probe(); err = fSensor->Probe();
@@ -523,7 +523,7 @@ CamDevice::DataPumpThread()
#ifndef DEBUG_DISCARD_INPUT #ifndef DEBUG_DISCARD_INPUT
len = fBulkIn->BulkTransfer(fBuffer, fBufferLen); len = fBulkIn->BulkTransfer(fBuffer, fBufferLen);
#endif #endif
//PRINT((CH ": got %ld bytes" CT, len)); //PRINT((CH ": got %ld bytes" CT, len));
#ifdef DEBUG_WRITE_DUMP #ifdef DEBUG_WRITE_DUMP
write(fDumpFD, fBuffer, len); write(fDumpFD, fBuffer, len);
@@ -561,7 +561,7 @@ CamDevice::DataPumpThread()
#ifndef DEBUG_DISCARD_INPUT #ifndef DEBUG_DISCARD_INPUT
len = fIsoIn->IsochronousTransfer(fBuffer, fBufferLen, packetDescriptors, numPacketDescriptors); len = fIsoIn->IsochronousTransfer(fBuffer, fBufferLen, packetDescriptors, numPacketDescriptors);
#endif #endif
//PRINT((CH ": got %d bytes" CT, len)); //PRINT((CH ": got %d bytes" CT, len));
#ifdef DEBUG_WRITE_DUMP #ifdef DEBUG_WRITE_DUMP
write(fDumpFD, fBuffer, len); write(fDumpFD, fBuffer, len);
@@ -618,7 +618,7 @@ CamDevice::SendCommand(uint8 dir, uint8 request, uint16 value,
if (length > GetDevice()->MaxEndpoint0PacketSize()) if (length > GetDevice()->MaxEndpoint0PacketSize())
return EINVAL; return EINVAL;
ret = GetDevice()->ControlTransfer( ret = GetDevice()->ControlTransfer(
USB_REQTYPE_VENDOR | USB_REQTYPE_INTERFACE_OUT | dir, USB_REQTYPE_VENDOR | USB_REQTYPE_INTERFACE_OUT | dir,
request, value, index, length, data); request, value, index, length, data);
return ret; return ret;
} }
@@ -653,8 +653,7 @@ CamDeviceAddon::Sniff(BUSBDevice *device)
return EINVAL; return EINVAL;
bool supported = false; bool supported = false;
for (uint32 i = 0; !supported && fSupportedDevices[i].vendor; i++) for (uint32 i = 0; !supported && fSupportedDevices[i].vendor; i++) {
{
if ((fSupportedDevices[i].desc.vendor != 0 if ((fSupportedDevices[i].desc.vendor != 0
&& device->VendorID() != fSupportedDevices[i].desc.vendor) && device->VendorID() != fSupportedDevices[i].desc.vendor)
|| (fSupportedDevices[i].desc.product != 0 || (fSupportedDevices[i].desc.product != 0
@@ -711,4 +710,3 @@ CamDeviceAddon::SetSupportedDevices(const usb_webcam_support_descriptor *devs)
{ {
fSupportedDevices = devs; fSupportedDevices = devs;
} }
@@ -9,12 +9,12 @@
CamFilterInterface::CamFilterInterface(CamDevice *device) CamFilterInterface::CamFilterInterface(CamDevice *device)
: BPositionIO(), : BPositionIO(),
fDevice(device), fDevice(device),
fNextOfKin(NULL) fNextOfKin(NULL)
{ {
fVideoFrame = BRect(0,0,-1,-1); fVideoFrame = BRect(0,0,-1,-1);
} }
@@ -145,4 +145,3 @@ CamFilterInterface::SetVideoFrame(BRect frame)
fVideoFrame = frame; fVideoFrame = frame;
return B_OK; return B_OK;
} }
@@ -10,8 +10,7 @@
#include <interface/Rect.h> #include <interface/Rect.h>
class CamDevice; class CamDevice;
class CamFilterInterface : public BPositionIO class CamFilterInterface : public BPositionIO {
{
public: public:
CamFilterInterface(CamDevice *device); CamFilterInterface(CamDevice *device);
virtual ~CamFilterInterface(); virtual ~CamFilterInterface();
@@ -18,7 +18,6 @@ extern "C" status_t get_webcam_addon_##modname(WebCamMediaAddOn* webcam, CamDevi
#undef B_WEBCAM_MKINTFUNC #undef B_WEBCAM_MKINTFUNC
CamRoster::CamRoster(WebCamMediaAddOn* _addon) CamRoster::CamRoster(WebCamMediaAddOn* _addon)
: BUSBRoster(), : BUSBRoster(),
fLocker("WebcamRosterLock"), fLocker("WebcamRosterLock"),
@@ -40,8 +39,7 @@ CamRoster::DeviceAdded(BUSBDevice* _device)
{ {
PRINT((CH "()" CT)); PRINT((CH "()" CT));
status_t err; status_t err;
for( int16 i = fCamerasAddons.CountItems()-1; i >= 0; --i ) for (int16 i = fCamerasAddons.CountItems() - 1; i >= 0; --i ) {
{
CamDeviceAddon *ao = (CamDeviceAddon *)fCamerasAddons.ItemAt(i); CamDeviceAddon *ao = (CamDeviceAddon *)fCamerasAddons.ItemAt(i);
PRINT((CH ": checking %s for support..." CT, ao->BrandName())); PRINT((CH ": checking %s for support..." CT, ao->BrandName()));
err = ao->Sniff(_device); err = ao->Sniff(_device);
@@ -50,8 +48,7 @@ CamRoster::DeviceAdded(BUSBDevice* _device)
CamDevice *cam = ao->Instantiate(*this, _device); CamDevice *cam = ao->Instantiate(*this, _device);
PRINT((CH ": found camera %s:%s!" CT, cam->BrandName(), cam->ModelName())); PRINT((CH ": found camera %s:%s!" CT, cam->BrandName(), cam->ModelName()));
err = cam->InitCheck(); err = cam->InitCheck();
if (err >= B_OK) if (err >= B_OK) {
{
fCameras.AddItem(cam); fCameras.AddItem(cam);
fAddon->CameraAdded(cam); fAddon->CameraAdded(cam);
return B_OK; return B_OK;
@@ -66,11 +63,9 @@ void
CamRoster::DeviceRemoved(BUSBDevice* _device) CamRoster::DeviceRemoved(BUSBDevice* _device)
{ {
PRINT((CH "()" CT)); PRINT((CH "()" CT));
for(int32 i = 0; i < fCameras.CountItems(); ++i) for (int32 i = 0; i < fCameras.CountItems(); ++i) {
{
CamDevice* cam = (CamDevice *)fCameras.ItemAt(i); CamDevice* cam = (CamDevice *)fCameras.ItemAt(i);
if( cam->Matches(_device) ) if (cam->Matches(_device)) {
{
PRINT((CH ": camera %s:%s removed" CT, cam->BrandName(), cam->ModelName())); PRINT((CH ": camera %s:%s removed" CT, cam->BrandName(), cam->ModelName()));
fCameras.RemoveItem(i); fCameras.RemoveItem(i);
fAddon->CameraRemoved(cam); fAddon->CameraRemoved(cam);
@@ -78,9 +73,9 @@ CamRoster::DeviceRemoved(BUSBDevice* _device)
//delete cam; //delete cam;
cam->Unplugged(); cam->Unplugged();
return; return;
} }
} }
} }
uint32 uint32
@@ -154,9 +149,9 @@ CamRoster::LoadExternalAddons()
status_t err; status_t err;
CamDeviceAddon *addon; CamDeviceAddon *addon;
status_t (*get_webcam_addon_func)(WebCamMediaAddOn* webcam, CamDeviceAddon **addon); status_t (*get_webcam_addon_func)(WebCamMediaAddOn* webcam, CamDeviceAddon **addon);
for (index = 0; get_nth_image_symbol(fAddon->ImageID(), for (index = 0; get_nth_image_symbol(fAddon->ImageID(),
index, NULL, NULL, index, NULL, NULL,
&sclass, &sclass,
(void **)&get_webcam_addon_func) == B_OK; index++) { (void **)&get_webcam_addon_func) == B_OK; index++) {
PRINT((CH ": got sym" CT)); PRINT((CH ": got sym" CT));
// if (sclass != B_SYMBOL_TYPE_TEXT) // if (sclass != B_SYMBOL_TYPE_TEXT)
@@ -14,8 +14,7 @@
class WebCamMediaAddOn; class WebCamMediaAddOn;
class CamDeviceAddon; class CamDeviceAddon;
class CamRoster : public BUSBRoster class CamRoster : public BUSBRoster {
{
public: public:
CamRoster(WebCamMediaAddOn* _addon); CamRoster(WebCamMediaAddOn* _addon);
virtual ~CamRoster(); virtual ~CamRoster();
@@ -29,7 +28,7 @@ public:
CamDevice* CameraAt(int32 index); CamDevice* CameraAt(int32 index);
private: private:
status_t LoadInternalAddons(); status_t LoadInternalAddons();
status_t LoadExternalAddons(); status_t LoadExternalAddons();
@@ -15,15 +15,15 @@ CamSensor::CamSensor(CamDevice *_camera)
fLastParameterChanges(0), fLastParameterChanges(0),
fCamDevice(_camera) fCamDevice(_camera)
{ {
} }
CamSensor::~CamSensor() CamSensor::~CamSensor()
{ {
} }
status_t status_t
CamSensor::Probe() CamSensor::Probe()
@@ -31,21 +31,21 @@ CamSensor::Probe()
// default is to match by USB IDs // default is to match by USB IDs
return B_OK; return B_OK;
} }
status_t status_t
CamSensor::InitCheck() CamSensor::InitCheck()
{ {
return fInitStatus; return fInitStatus;
} }
status_t status_t
CamSensor::Setup() CamSensor::Setup()
{ {
return fInitStatus; return fInitStatus;
} }
const char * const char *
CamSensor::Name() CamSensor::Name()
@@ -130,9 +130,7 @@ status_t
CamSensor::ProbeByIICSignature(const uint8 *regList, const uint8 *matchList, CamSensor::ProbeByIICSignature(const uint8 *regList, const uint8 *matchList,
size_t count) size_t count)
{ {
int i; for (int i = 0; i < count; i++) {
for (i = 0; i < count; i++) {
uint8 value = 0; uint8 value = 0;
ssize_t len; ssize_t len;
len = Device()->ReadIIC8(regList[i], &value); len = Device()->ReadIIC8(regList[i], &value);
@@ -9,24 +9,23 @@
#include <Rect.h> #include <Rect.h>
// This class represents the camera's (cmos or whatever) sensor chip // This class represents the camera's (cmos or whatever) sensor chip
class CamSensor class CamSensor {
{ public:
public:
CamSensor(CamDevice *_camera); CamSensor(CamDevice *_camera);
virtual ~CamSensor(); virtual ~CamSensor();
virtual status_t Probe(); // returns B_OK if found. virtual status_t Probe(); // returns B_OK if found.
virtual status_t InitCheck(); virtual status_t InitCheck();
virtual status_t Setup(); virtual status_t Setup();
virtual const char* Name(); virtual const char* Name();
virtual status_t StartTransfer(); virtual status_t StartTransfer();
virtual status_t StopTransfer(); virtual status_t StopTransfer();
virtual bool TransferEnabled() const { return fTransferEnabled; }; virtual bool TransferEnabled() const { return fTransferEnabled; };
virtual bool IsBigEndian() const { return fIsBigEndian; }; virtual bool IsBigEndian() const { return fIsBigEndian; };
virtual bool Use400kHz() const { return false; }; virtual bool Use400kHz() const { return false; };
virtual bool UseRealIIC() const { return true; }; virtual bool UseRealIIC() const { return true; };
@@ -44,16 +43,16 @@ class CamSensor
virtual void AddParameters(BParameterGroup *group, int32 &index); virtual void AddParameters(BParameterGroup *group, int32 &index);
virtual status_t GetParameterValue(int32 id, bigtime_t *last_change, void *value, size_t *size); virtual status_t GetParameterValue(int32 id, bigtime_t *last_change, void *value, size_t *size);
virtual status_t SetParameterValue(int32 id, bigtime_t when, const void *value, size_t size); virtual status_t SetParameterValue(int32 id, bigtime_t when, const void *value, size_t size);
CamDevice *Device(); CamDevice *Device();
#if 0 #if 0
// generic register-like access // generic register-like access
virtual status_t WriteReg(uint16 address, uint8 *data, size_t count=1); virtual status_t WriteReg(uint16 address, uint8 *data, size_t count=1);
virtual status_t WriteReg8(uint16 address, uint8 data); virtual status_t WriteReg8(uint16 address, uint8 data);
virtual status_t WriteReg16(uint16 address, uint16 data); virtual status_t WriteReg16(uint16 address, uint16 data);
virtual status_t ReadReg(uint16 address, uint8 *data, size_t count=1, bool cached=false); virtual status_t ReadReg(uint16 address, uint8 *data, size_t count=1, bool cached=false);
// I2C-like access // I2C-like access
virtual status_t WriteIIC(uint8 address, uint8 *data, size_t count=1); virtual status_t WriteIIC(uint8 address, uint8 *data, size_t count=1);
virtual status_t ReadIIC(uint8 address, uint8 *data); virtual status_t ReadIIC(uint8 address, uint8 *data);
@@ -3,11 +3,11 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
/* /*
* stream based deframer * stream based deframer
* has a state machine and handles each packet separately. * has a state machine and handles each packet separately.
* much more complex than the buffering one, and I thought it didn't work, * much more complex than the buffering one, and I thought it didn't work,
* but since I fixed the rest it seems to be working even better without * but since I fixed the rest it seems to be working even better without
* taking the cpu over like the other one. * taking the cpu over like the other one.
*/ */
@@ -21,7 +21,7 @@
CamStreamingDeframer::CamStreamingDeframer(CamDevice *device) CamStreamingDeframer::CamStreamingDeframer(CamDevice *device)
: CamDeframer(device) : CamDeframer(device)
{ {
} }
@@ -56,7 +56,7 @@ CamStreamingDeframer::Write(const void *buffer, size_t size)
// update in case resolution changed // update in case resolution changed
fMinFrameSize = fDevice->MinRawFrameSize(); fMinFrameSize = fDevice->MinRawFrameSize();
fMaxFrameSize = fDevice->MaxRawFrameSize(); fMaxFrameSize = fDevice->MaxRawFrameSize();
if (fInputBuff.Position()) { if (fInputBuff.Position()) {
// residual data ? append to it // residual data ? append to it
fInputBuff.Write(buffer, size); fInputBuff.Write(buffer, size);
@@ -67,13 +67,13 @@ CamStreamingDeframer::Write(const void *buffer, size_t size)
} }
// whole buffer belongs to a frame, simple // whole buffer belongs to a frame, simple
if ((fState == ST_FRAME) && (fCurrentFrame->Position() + bufsize < fMinFrameSize)) { if ((fState == ST_FRAME) && (fCurrentFrame->Position() + bufsize < fMinFrameSize)) {
// no residual data, and // no residual data, and
fCurrentFrame->Write(buf, bufsize); fCurrentFrame->Write(buf, bufsize);
fInputBuff.Seek(0LL, SEEK_SET); fInputBuff.Seek(0LL, SEEK_SET);
fInputBuff.SetSize(0); fInputBuff.SetSize(0);
return size; return size;
} }
// waiting for a frame... // waiting for a frame...
if (fState == ST_SYNC) { if (fState == ST_SYNC) {
i = 0; i = 0;
@@ -94,7 +94,7 @@ CamStreamingDeframer::Write(const void *buffer, size_t size)
fState = ST_FRAME; fState = ST_FRAME;
} }
} }
// check for end of frame // check for end of frame
if (fState == ST_FRAME) { if (fState == ST_FRAME) {
#if 0 #if 0
@@ -122,7 +122,7 @@ CamStreamingDeframer::Write(const void *buffer, size_t size)
i = bufsize; i = bufsize;
} }
PRINT((CH ": checking for EOF; bufsize=%d i=%d" CT, bufsize, i)); PRINT((CH ": checking for EOF; bufsize=%d i=%d" CT, bufsize, i));
if (i + (int)fSkipEOFTags > bufsize) { // not enough room to check for EOF, leave it for next time if (i + (int)fSkipEOFTags > bufsize) { // not enough room to check for EOF, leave it for next time
end = i; end = i;
i = -1; // don't detach yet i = -1; // don't detach yet
@@ -178,9 +178,9 @@ CamStreamingDeframer::Write(const void *buffer, size_t size)
fState = ST_SYNC; fState = ST_SYNC;
} }
} }
// put the remainder in input buff, discarding old data // put the remainder in input buff, discarding old data
#if 0 #if 0
@@ -196,4 +196,3 @@ CamStreamingDeframer::Write(const void *buffer, size_t size)
fInputBuff.SetSize(bufsize - end); fInputBuff.SetSize(bufsize - end);
return size; return size;
} }
@@ -7,8 +7,7 @@
#include "CamDeframer.h" #include "CamDeframer.h"
class CamStreamingDeframer : public CamDeframer class CamStreamingDeframer : public CamDeframer {
{
public: public:
CamStreamingDeframer(CamDevice *device); CamStreamingDeframer(CamDevice *device);
virtual ~CamStreamingDeframer(); virtual ~CamStreamingDeframer();
@@ -49,11 +49,13 @@
//#define FIELD_RATE 29.97f //#define FIELD_RATE 29.97f
#define FIELD_RATE 5.f #define FIELD_RATE 5.f
int32 VideoProducer::fInstances = 0; int32 VideoProducer::fInstances = 0;
VideoProducer::VideoProducer( VideoProducer::VideoProducer(
BMediaAddOn *addon, CamDevice *dev, const char *name, int32 internal_id) BMediaAddOn *addon, CamDevice *dev, const char *name, int32 internal_id)
: BMediaNode(name), : BMediaNode(name),
BMediaEventLooper(), BMediaEventLooper(),
BBufferProducer(B_MEDIA_RAW_VIDEO), BBufferProducer(B_MEDIA_RAW_VIDEO),
BControllable() BControllable()
@@ -88,6 +90,7 @@ VideoProducer::VideoProducer(
return; return;
} }
VideoProducer::~VideoProducer() VideoProducer::~VideoProducer()
{ {
if (fInitStatus == B_OK) { if (fInitStatus == B_OK) {
@@ -102,14 +105,15 @@ VideoProducer::~VideoProducer()
atomic_add(&fInstances, -1); atomic_add(&fInstances, -1);
} }
/* BMediaNode */
/* BMediaNode */
port_id port_id
VideoProducer::ControlPort() const VideoProducer::ControlPort() const
{ {
return BMediaNode::ControlPort(); return BMediaNode::ControlPort();
} }
BMediaAddOn * BMediaAddOn *
VideoProducer::AddOn(int32 *internal_id) const VideoProducer::AddOn(int32 *internal_id) const
{ {
@@ -118,19 +122,22 @@ VideoProducer::AddOn(int32 *internal_id) const
return fAddOn; return fAddOn;
} }
status_t
status_t
VideoProducer::HandleMessage(int32 /*message*/, const void* /*data*/, size_t /*size*/) VideoProducer::HandleMessage(int32 /*message*/, const void* /*data*/, size_t /*size*/)
{ {
return B_ERROR; return B_ERROR;
} }
void
void
VideoProducer::Preroll() VideoProducer::Preroll()
{ {
/* This hook may be called before the node is started to give the hardware /* This hook may be called before the node is started to give the hardware
* a chance to start. */ * a chance to start. */
} }
void void
VideoProducer::SetTimeSource(BTimeSource* /*time_source*/) VideoProducer::SetTimeSource(BTimeSource* /*time_source*/)
{ {
@@ -138,15 +145,18 @@ VideoProducer::SetTimeSource(BTimeSource* /*time_source*/)
release_sem(fFrameSync); release_sem(fFrameSync);
} }
status_t status_t
VideoProducer::RequestCompleted(const media_request_info &info) VideoProducer::RequestCompleted(const media_request_info &info)
{ {
return BMediaNode::RequestCompleted(info); return BMediaNode::RequestCompleted(info);
} }
/* BMediaEventLooper */ /* BMediaEventLooper */
void
void
VideoProducer::NodeRegistered() VideoProducer::NodeRegistered()
{ {
if (fInitStatus != B_OK) { if (fInitStatus != B_OK) {
@@ -155,7 +165,7 @@ VideoProducer::NodeRegistered()
} }
/* Set up the parameter web */ /* Set up the parameter web */
//TODO: remove and put sensible stuff there //TODO: remove and put sensible stuff there
BParameterWeb *web = new BParameterWeb(); BParameterWeb *web = new BParameterWeb();
BParameterGroup *main = web->MakeGroup(Name()); BParameterGroup *main = web->MakeGroup(Name());
@@ -200,7 +210,7 @@ VideoProducer::NodeRegistered()
fOutput.source.port = ControlPort(); fOutput.source.port = ControlPort();
fOutput.source.id = 0; fOutput.source.id = 0;
fOutput.destination = media_destination::null; fOutput.destination = media_destination::null;
strcpy(fOutput.name, Name()); strcpy(fOutput.name, Name());
/* Tailor these for the output of your device */ /* Tailor these for the output of your device */
fOutput.format.type = B_MEDIA_RAW_VIDEO; fOutput.format.type = B_MEDIA_RAW_VIDEO;
@@ -213,50 +223,56 @@ VideoProducer::NodeRegistered()
Run(); Run();
} }
void void
VideoProducer::Start(bigtime_t performance_time) VideoProducer::Start(bigtime_t performance_time)
{ {
BMediaEventLooper::Start(performance_time); BMediaEventLooper::Start(performance_time);
} }
void void
VideoProducer::Stop(bigtime_t performance_time, bool immediate) VideoProducer::Stop(bigtime_t performance_time, bool immediate)
{ {
BMediaEventLooper::Stop(performance_time, immediate); BMediaEventLooper::Stop(performance_time, immediate);
} }
void void
VideoProducer::Seek(bigtime_t media_time, bigtime_t performance_time) VideoProducer::Seek(bigtime_t media_time, bigtime_t performance_time)
{ {
BMediaEventLooper::Seek(media_time, performance_time); BMediaEventLooper::Seek(media_time, performance_time);
} }
void void
VideoProducer::TimeWarp(bigtime_t at_real_time, bigtime_t to_performance_time) VideoProducer::TimeWarp(bigtime_t at_real_time, bigtime_t to_performance_time)
{ {
BMediaEventLooper::TimeWarp(at_real_time, to_performance_time); BMediaEventLooper::TimeWarp(at_real_time, to_performance_time);
} }
status_t status_t
VideoProducer::AddTimer(bigtime_t at_performance_time, int32 cookie) VideoProducer::AddTimer(bigtime_t at_performance_time, int32 cookie)
{ {
return BMediaEventLooper::AddTimer(at_performance_time, cookie); return BMediaEventLooper::AddTimer(at_performance_time, cookie);
} }
void void
VideoProducer::SetRunMode(run_mode mode) VideoProducer::SetRunMode(run_mode mode)
{ {
BMediaEventLooper::SetRunMode(mode); BMediaEventLooper::SetRunMode(mode);
} }
void
void
VideoProducer::HandleEvent(const media_timed_event *event, VideoProducer::HandleEvent(const media_timed_event *event,
bigtime_t lateness, bool realTimeEvent) bigtime_t lateness, bool realTimeEvent)
{ {
TOUCH(lateness); TOUCH(realTimeEvent); TOUCH(lateness); TOUCH(realTimeEvent);
switch(event->type) switch(event->type) {
{
case BTimedEventQueue::B_START: case BTimedEventQueue::B_START:
HandleStart(event->event_time); HandleStart(event->event_time);
break; break;
@@ -278,33 +294,39 @@ VideoProducer::HandleEvent(const media_timed_event *event,
} }
} }
void
void
VideoProducer::CleanUpEvent(const media_timed_event *event) VideoProducer::CleanUpEvent(const media_timed_event *event)
{ {
BMediaEventLooper::CleanUpEvent(event); BMediaEventLooper::CleanUpEvent(event);
} }
bigtime_t bigtime_t
VideoProducer::OfflineTime() VideoProducer::OfflineTime()
{ {
return BMediaEventLooper::OfflineTime(); return BMediaEventLooper::OfflineTime();
} }
void void
VideoProducer::ControlLoop() VideoProducer::ControlLoop()
{ {
BMediaEventLooper::ControlLoop(); BMediaEventLooper::ControlLoop();
} }
status_t status_t
VideoProducer::DeleteHook(BMediaNode * node) VideoProducer::DeleteHook(BMediaNode * node)
{ {
return BMediaEventLooper::DeleteHook(node); return BMediaEventLooper::DeleteHook(node);
} }
/* BBufferProducer */ /* BBufferProducer */
status_t
status_t
VideoProducer::FormatSuggestionRequested( VideoProducer::FormatSuggestionRequested(
media_type type, int32 quality, media_format *format) media_type type, int32 quality, media_format *format)
{ {
@@ -326,7 +348,8 @@ VideoProducer::FormatSuggestionRequested(
return B_OK; return B_OK;
} }
status_t
status_t
VideoProducer::FormatProposal(const media_source &output, media_format *format) VideoProducer::FormatProposal(const media_source &output, media_format *format)
{ {
status_t err; status_t err;
@@ -344,7 +367,7 @@ VideoProducer::FormatProposal(const media_source &output, media_format *format)
err = format_is_compatible(*format, fOutput.format) ? err = format_is_compatible(*format, fOutput.format) ?
B_OK : B_MEDIA_BAD_FORMAT; B_OK : B_MEDIA_BAD_FORMAT;
uint32 width = format->u.raw_video.display.line_width; uint32 width = format->u.raw_video.display.line_width;
uint32 height = format->u.raw_video.display.line_count; uint32 height = format->u.raw_video.display.line_count;
*format = fOutput.format; *format = fOutput.format;
@@ -362,10 +385,11 @@ VideoProducer::FormatProposal(const media_source &output, media_format *format)
format->u.raw_video.display.line_count)); format->u.raw_video.display.line_count));
return err; return err;
} }
status_t
status_t
VideoProducer::FormatChangeRequested(const media_source &source, VideoProducer::FormatChangeRequested(const media_source &source,
const media_destination &destination, media_format *io_format, const media_destination &destination, media_format *io_format,
int32 *_deprecated_) int32 *_deprecated_)
@@ -373,11 +397,12 @@ VideoProducer::FormatChangeRequested(const media_source &source,
TOUCH(destination); TOUCH(io_format); TOUCH(_deprecated_); TOUCH(destination); TOUCH(io_format); TOUCH(_deprecated_);
if (source != fOutput.source) if (source != fOutput.source)
return B_MEDIA_BAD_SOURCE; return B_MEDIA_BAD_SOURCE;
return B_ERROR; return B_ERROR;
} }
status_t
status_t
VideoProducer::GetNextOutput(int32 *cookie, media_output *out_output) VideoProducer::GetNextOutput(int32 *cookie, media_output *out_output)
{ {
if (!out_output) if (!out_output)
@@ -385,13 +410,14 @@ VideoProducer::GetNextOutput(int32 *cookie, media_output *out_output)
if ((*cookie) != 0) if ((*cookie) != 0)
return B_BAD_INDEX; return B_BAD_INDEX;
*out_output = fOutput; *out_output = fOutput;
(*cookie)++; (*cookie)++;
return B_OK; return B_OK;
} }
status_t
status_t
VideoProducer::DisposeOutputCookie(int32 cookie) VideoProducer::DisposeOutputCookie(int32 cookie)
{ {
TOUCH(cookie); TOUCH(cookie);
@@ -399,7 +425,8 @@ VideoProducer::DisposeOutputCookie(int32 cookie)
return B_OK; return B_OK;
} }
status_t
status_t
VideoProducer::SetBufferGroup(const media_source &for_source, VideoProducer::SetBufferGroup(const media_source &for_source,
BBufferGroup *group) BBufferGroup *group)
{ {
@@ -408,7 +435,8 @@ VideoProducer::SetBufferGroup(const media_source &for_source,
return B_ERROR; return B_ERROR;
} }
status_t
status_t
VideoProducer::VideoClippingChanged(const media_source &for_source, VideoProducer::VideoClippingChanged(const media_source &for_source,
int16 num_shorts, int16 *clip_data, int16 num_shorts, int16 *clip_data,
const media_video_display_info &display, int32 *_deprecated_) const media_video_display_info &display, int32 *_deprecated_)
@@ -419,14 +447,16 @@ VideoProducer::VideoClippingChanged(const media_source &for_source,
return B_ERROR; return B_ERROR;
} }
status_t
status_t
VideoProducer::GetLatency(bigtime_t *out_latency) VideoProducer::GetLatency(bigtime_t *out_latency)
{ {
*out_latency = EventLatency() + SchedulingLatency(); *out_latency = EventLatency() + SchedulingLatency();
return B_OK; return B_OK;
} }
status_t
status_t
VideoProducer::PrepareToConnect(const media_source &source, VideoProducer::PrepareToConnect(const media_source &source,
const media_destination &destination, media_format *format, const media_destination &destination, media_format *format,
media_source *out_source, char *out_name) media_source *out_source, char *out_name)
@@ -444,7 +474,7 @@ VideoProducer::PrepareToConnect(const media_source &source,
if (source != fOutput.source) if (source != fOutput.source)
return B_MEDIA_BAD_SOURCE; return B_MEDIA_BAD_SOURCE;
if (fOutput.destination != media_destination::null) if (fOutput.destination != media_destination::null)
return B_MEDIA_ALREADY_CONNECTED; return B_MEDIA_ALREADY_CONNECTED;
@@ -502,7 +532,8 @@ VideoProducer::PrepareToConnect(const media_source &source,
return B_OK; return B_OK;
} }
void
void
VideoProducer::Connect(status_t error, const media_source &source, VideoProducer::Connect(status_t error, const media_source &source,
const media_destination &destination, const media_format &format, const media_destination &destination, const media_format &format,
char *io_name) char *io_name)
@@ -522,8 +553,8 @@ VideoProducer::Connect(status_t error, const media_source &source,
return; return;
} }
if ( (source != fOutput.source) || (error < B_OK) || if (source != fOutput.source || error < B_OK
!const_cast<media_format *>(&format)->Matches(&fOutput.format)) { || !const_cast<media_format *>(&format)->Matches(&fOutput.format)) {
PRINTF(1, ("Connect: Connect error\n")); PRINTF(1, ("Connect: Connect error\n"));
return; return;
} }
@@ -538,7 +569,7 @@ VideoProducer::Connect(status_t error, const media_source &source,
(1000000 / fOutput.format.u.raw_video.field_rate)); (1000000 / fOutput.format.u.raw_video.field_rate));
fFrameBase = fFrame; fFrameBase = fFrame;
} }
fConnectedFormat = format.u.raw_video; fConnectedFormat = format.u.raw_video;
/* get the latency */ /* get the latency */
@@ -578,7 +609,7 @@ VideoProducer::Connect(status_t error, const media_source &source,
release_sem(fFrameSync); release_sem(fFrameSync);
} }
void void
VideoProducer::Disconnect(const media_source &source, VideoProducer::Disconnect(const media_source &source,
const media_destination &destination) const media_destination &destination)
{ {
@@ -599,7 +630,7 @@ VideoProducer::Disconnect(const media_source &source,
if (fRunning) if (fRunning)
HandleStop(); HandleStop();
#endif #endif
fEnabled = false; fEnabled = false;
fOutput.destination = media_destination::null; fOutput.destination = media_destination::null;
@@ -611,14 +642,16 @@ VideoProducer::Disconnect(const media_source &source,
fConnected = false; fConnected = false;
} }
void
void
VideoProducer::LateNoticeReceived(const media_source &source, VideoProducer::LateNoticeReceived(const media_source &source,
bigtime_t how_much, bigtime_t performance_time) bigtime_t how_much, bigtime_t performance_time)
{ {
TOUCH(source); TOUCH(how_much); TOUCH(performance_time); TOUCH(source); TOUCH(how_much); TOUCH(performance_time);
} }
void
void
VideoProducer::EnableOutput(const media_source &source, bool enabled, VideoProducer::EnableOutput(const media_source &source, bool enabled,
int32 *_deprecated_) int32 *_deprecated_)
{ {
@@ -630,7 +663,8 @@ VideoProducer::EnableOutput(const media_source &source, bool enabled,
fEnabled = enabled; fEnabled = enabled;
} }
status_t
status_t
VideoProducer::SetPlayRate(int32 numer, int32 denom) VideoProducer::SetPlayRate(int32 numer, int32 denom)
{ {
TOUCH(numer); TOUCH(denom); TOUCH(numer); TOUCH(denom);
@@ -638,7 +672,8 @@ VideoProducer::SetPlayRate(int32 numer, int32 denom)
return B_ERROR; return B_ERROR;
} }
void
void
VideoProducer::AdditionalBufferRequested(const media_source &source, VideoProducer::AdditionalBufferRequested(const media_source &source,
media_buffer_id prev_buffer, bigtime_t prev_time, media_buffer_id prev_buffer, bigtime_t prev_time,
const media_seek_tag *prev_tag) const media_seek_tag *prev_tag)
@@ -646,7 +681,8 @@ VideoProducer::AdditionalBufferRequested(const media_source &source,
TOUCH(source); TOUCH(prev_buffer); TOUCH(prev_time); TOUCH(prev_tag); TOUCH(source); TOUCH(prev_buffer); TOUCH(prev_time); TOUCH(prev_tag);
} }
void
void
VideoProducer::LatencyChanged(const media_source &source, VideoProducer::LatencyChanged(const media_source &source,
const media_destination &destination, bigtime_t new_latency, const media_destination &destination, bigtime_t new_latency,
uint32 flags) uint32 flags)
@@ -654,9 +690,11 @@ VideoProducer::LatencyChanged(const media_source &source,
TOUCH(source); TOUCH(destination); TOUCH(new_latency); TOUCH(flags); TOUCH(source); TOUCH(destination); TOUCH(new_latency); TOUCH(flags);
} }
/* BControllable */
status_t /* BControllable */
status_t
VideoProducer::GetParameterValue( VideoProducer::GetParameterValue(
int32 id, bigtime_t *last_change, void *value, size_t *size) int32 id, bigtime_t *last_change, void *value, size_t *size)
{ {
@@ -694,6 +732,7 @@ VideoProducer::GetParameterValue(
return B_BAD_VALUE; return B_BAD_VALUE;
} }
void void
VideoProducer::SetParameterValue( VideoProducer::SetParameterValue(
int32 id, bigtime_t when, const void *value, size_t size) int32 id, bigtime_t when, const void *value, size_t size)
@@ -729,14 +768,17 @@ VideoProducer::SetParameterValue(
BroadcastNewParameterValue(when, id, (void *)value, size); BroadcastNewParameterValue(when, id, (void *)value, size);
} }
status_t status_t
VideoProducer::StartControlPanel(BMessenger *out_messenger) VideoProducer::StartControlPanel(BMessenger *out_messenger)
{ {
return BControllable::StartControlPanel(out_messenger); return BControllable::StartControlPanel(out_messenger);
} }
/* VideoProducer */ /* VideoProducer */
void void
VideoProducer::HandleStart(bigtime_t performance_time) VideoProducer::HandleStart(bigtime_t performance_time)
{ {
@@ -778,6 +820,7 @@ err1:
return; return;
} }
void void
VideoProducer::HandleStop(void) VideoProducer::HandleStop(void)
{ {
@@ -797,6 +840,7 @@ VideoProducer::HandleStop(void)
fRunning = false; fRunning = false;
} }
void void
VideoProducer::HandleTimeWarp(bigtime_t performance_time) VideoProducer::HandleTimeWarp(bigtime_t performance_time)
{ {
@@ -807,6 +851,7 @@ VideoProducer::HandleTimeWarp(bigtime_t performance_time)
release_sem(fFrameSync); release_sem(fFrameSync);
} }
void void
VideoProducer::HandleSeek(bigtime_t performance_time) VideoProducer::HandleSeek(bigtime_t performance_time)
{ {
@@ -817,6 +862,7 @@ VideoProducer::HandleSeek(bigtime_t performance_time)
release_sem(fFrameSync); release_sem(fFrameSync);
} }
void void
VideoProducer::_UpdateStats() VideoProducer::_UpdateStats()
{ {
@@ -829,15 +875,14 @@ VideoProducer::_UpdateStats()
<< rfps << " real, missed: " << fStats[0].missed; << rfps << " real, missed: " << fStats[0].missed;
memcpy(&fStats[1], &fStats[0], sizeof(fStats[0])); memcpy(&fStats[1], &fStats[0], sizeof(fStats[0]));
fLastColorChange = system_time(); fLastColorChange = system_time();
BroadcastNewParameterValue(fLastColorChange, P_INFO, BroadcastNewParameterValue(fLastColorChange, P_INFO,
(void *)fInfoString.String(), fInfoString.Length()+1); (void *)fInfoString.String(), fInfoString.Length()+1);
} }
/* The following functions form the thread that generates frames. You should /* The following functions form the thread that generates frames. You should
* replace this with the code that interfaces to your hardware. */ * replace this with the code that interfaces to your hardware. */
int32 int32
VideoProducer::FrameGenerator() VideoProducer::FrameGenerator()
{ {
bigtime_t wait_until = system_time(); bigtime_t wait_until = system_time();
@@ -869,8 +914,8 @@ PRINT(("PS: %Ld\n", fProcessingLatency));
if (wait_until < system_time()) if (wait_until < system_time())
continue; continue;
PRINTF(1, ("FrameGenerator: wait until %Ld, %ctimed out, %crunning, %cenabled.\n", PRINTF(1, ("FrameGenerator: wait until %Ld, %ctimed out, %crunning, %cenabled.\n",
wait_until, wait_until,
(err == B_OK)?'!':' ', (err == B_OK)?'!':' ',
(fRunning)?' ':'!', (fRunning)?' ':'!',
(fEnabled)?' ':'!')); (fEnabled)?' ':'!'));
@@ -922,7 +967,7 @@ PRINT(("PS: %Ld\n", fProcessingLatency));
h->u.raw_video.line_count = fConnectedFormat.display.line_count; h->u.raw_video.line_count = fConnectedFormat.display.line_count;
// This is where we fill the video buffer. // This is where we fill the video buffer.
#if 0 #if 0
uint32 *p = (uint32 *)buffer->Data(); uint32 *p = (uint32 *)buffer->Data();
/* Fill in a pattern */ /* Fill in a pattern */
@@ -933,7 +978,7 @@ PRINT(("PS: %Ld\n", fProcessingLatency));
//NO! must be called without lock! //NO! must be called without lock!
//BAutolock lock(fCamDevice->Locker()); //BAutolock lock(fCamDevice->Locker());
bigtime_t now = system_time(); bigtime_t now = system_time();
bigtime_t stamp; bigtime_t stamp;
//#ifdef UseFillFrameBuffer //#ifdef UseFillFrameBuffer
@@ -982,6 +1027,7 @@ PRINT(("PS: %Ld\n", fProcessingLatency));
return B_OK; return B_OK;
} }
int32 int32
VideoProducer::_frame_generator_(void *data) VideoProducer::_frame_generator_(void *data)
{ {
@@ -21,8 +21,7 @@ class BTextParameter;
class VideoProducer : class VideoProducer :
public virtual BMediaEventLooper, public virtual BMediaEventLooper,
public virtual BBufferProducer, public virtual BBufferProducer,
public virtual BControllable public virtual BControllable {
{
public: public:
VideoProducer(BMediaAddOn *addon, CamDevice *dev, VideoProducer(BMediaAddOn *addon, CamDevice *dev,
const char *name, int32 internal_id); const char *name, int32 internal_id);
@@ -37,7 +36,7 @@ virtual port_id ControlPort() const;
virtual BMediaAddOn *AddOn(int32 * internal_id) const; virtual BMediaAddOn *AddOn(int32 * internal_id) const;
virtual status_t HandleMessage(int32 message, const void *data, virtual status_t HandleMessage(int32 message, const void *data,
size_t size); size_t size);
protected: protected:
virtual void Preroll(); virtual void Preroll();
virtual void SetTimeSource(BTimeSource * time_source); virtual void SetTimeSource(BTimeSource * time_source);
virtual status_t RequestCompleted(const media_request_info & info); virtual status_t RequestCompleted(const media_request_info & info);
@@ -59,7 +58,7 @@ virtual bigtime_t OfflineTime();
virtual void ControlLoop(); virtual void ControlLoop();
virtual status_t DeleteHook(BMediaNode * node); virtual status_t DeleteHook(BMediaNode * node);
/* BBufferProducer */ /* BBufferProducer */
protected: protected:
virtual status_t FormatSuggestionRequested(media_type type, int32 quality, virtual status_t FormatSuggestionRequested(media_type type, int32 quality,
media_format * format); media_format * format);
@@ -98,7 +97,7 @@ virtual void LatencyChanged(const media_source & source,
const media_destination & destination, const media_destination & destination,
bigtime_t new_latency, uint32 flags); bigtime_t new_latency, uint32 flags);
/* BControllable */ /* BControllable */
protected: protected:
virtual status_t GetParameterValue(int32 id, bigtime_t *last_change, virtual status_t GetParameterValue(int32 id, bigtime_t *last_change,
void *value, size_t *size); void *value, size_t *size);
@@ -26,9 +26,8 @@
// This class represents each webcam // This class represents each webcam
class NW80xCamDevice : public CamDevice class NW80xCamDevice : public CamDevice {
{ public:
public:
NW80xCamDevice(CamDeviceAddon &_addon, BUSBDevice* _device); NW80xCamDevice(CamDeviceAddon &_addon, BUSBDevice* _device);
~NW80xCamDevice(); ~NW80xCamDevice();
virtual bool SupportsBulk(); virtual bool SupportsBulk();
@@ -39,7 +38,7 @@ class NW80xCamDevice : public CamDevice
// generic register-like access // generic register-like access
virtual ssize_t WriteReg(uint16 address, uint8 *data, size_t count=1); virtual ssize_t WriteReg(uint16 address, uint8 *data, size_t count=1);
virtual ssize_t ReadReg(uint16 address, uint8 *data, size_t count=1, bool cached=false); virtual ssize_t ReadReg(uint16 address, uint8 *data, size_t count=1, bool cached=false);
// I2C-like access // I2C-like access
virtual status_t GetStatusIIC(); virtual status_t GetStatusIIC();
virtual status_t WaitReadyIIC(); virtual status_t WaitReadyIIC();
@@ -61,10 +60,10 @@ class NW80xCamDeviceAddon : public CamDeviceAddon
public: public:
NW80xCamDeviceAddon(WebCamMediaAddOn* webcam); NW80xCamDeviceAddon(WebCamMediaAddOn* webcam);
virtual ~NW80xCamDeviceAddon(); virtual ~NW80xCamDeviceAddon();
virtual const char *BrandName(); virtual const char *BrandName();
virtual NW80xCamDevice *Instantiate(CamRoster &roster, BUSBDevice *from); virtual NW80xCamDevice *Instantiate(CamRoster &roster, BUSBDevice *from);
}; };
#endif /* _NW80X_CAM_CAM_DEVICE_H */ #endif /* _NW80X_CAM_CAM_DEVICE_H */
@@ -26,9 +26,8 @@
// This class represents each webcam // This class represents each webcam
class QuickCamDevice : public CamDevice class QuickCamDevice : public CamDevice {
{ public:
public:
QuickCamDevice(CamDeviceAddon &_addon, BUSBDevice* _device); QuickCamDevice(CamDeviceAddon &_addon, BUSBDevice* _device);
~QuickCamDevice(); ~QuickCamDevice();
virtual bool SupportsBulk(); virtual bool SupportsBulk();
@@ -39,7 +38,7 @@ class QuickCamDevice : public CamDevice
// generic register-like access // generic register-like access
virtual ssize_t WriteReg(uint16 address, uint8 *data, size_t count=1); virtual ssize_t WriteReg(uint16 address, uint8 *data, size_t count=1);
virtual ssize_t ReadReg(uint16 address, uint8 *data, size_t count=1, bool cached=false); virtual ssize_t ReadReg(uint16 address, uint8 *data, size_t count=1, bool cached=false);
// I2C-like access // I2C-like access
virtual status_t GetStatusIIC(); virtual status_t GetStatusIIC();
virtual status_t WaitReadyIIC(); virtual status_t WaitReadyIIC();
@@ -56,15 +55,14 @@ class QuickCamDevice : public CamDevice
// the addon itself, that instanciate // the addon itself, that instanciate
class QuickCamDeviceAddon : public CamDeviceAddon class QuickCamDeviceAddon : public CamDeviceAddon {
{
public: public:
QuickCamDeviceAddon(WebCamMediaAddOn* webcam); QuickCamDeviceAddon(WebCamMediaAddOn* webcam);
virtual ~QuickCamDeviceAddon(); virtual ~QuickCamDeviceAddon();
virtual const char *BrandName(); virtual const char *BrandName();
virtual QuickCamDevice *Instantiate(CamRoster &roster, BUSBDevice *from); virtual QuickCamDevice *Instantiate(CamRoster &roster, BUSBDevice *from);
}; };
#endif /* _QUICK_CAM_CAM_DEVICE_H */ #endif /* _QUICK_CAM_CAM_DEVICE_H */
@@ -82,31 +82,31 @@ SonixCamDevice::SonixCamDevice(CamDeviceAddon &_addon, BUSBDevice* _device)
uchar data[8]; /* store bytes returned from sonix commands */ uchar data[8]; /* store bytes returned from sonix commands */
status_t err; status_t err;
fFrameTagState = 0; fFrameTagState = 0;
fRGain = fGGain = fBGain = 0; fRGain = fGGain = fBGain = 0;
// unknown // unknown
fBrightness = 0.5; fBrightness = 0.5;
memset(fCachedRegs, 0, SN9C102_REG_COUNT); memset(fCachedRegs, 0, SN9C102_REG_COUNT);
fChipVersion = 2; fChipVersion = 2;
if ((GetDevice()->ProductID() & ~0x3F) == 0x6080) { if ((GetDevice()->ProductID() & ~0x3F) == 0x6080) {
fChipVersion = 3; // says V4L2 fChipVersion = 3; // says V4L2
} }
err = ProbeSensor(); err = ProbeSensor();
// fDeframer = new CamBufferingDeframer(this); // fDeframer = new CamBufferingDeframer(this);
fDeframer = new CamStreamingDeframer(this); fDeframer = new CamStreamingDeframer(this);
fDeframer->RegisterSOFTags(sof_marks, 2, sizeof(sof_mark_1), 12); fDeframer->RegisterSOFTags(sof_marks, 2, sizeof(sof_mark_1), 12);
fDeframer->RegisterEOFTags(eof_marks, 4, sizeof(eof_mark_1), sizeof(eof_mark_1)); fDeframer->RegisterEOFTags(eof_marks, 4, sizeof(eof_mark_1), sizeof(eof_mark_1));
SetDataInput(fDeframer); SetDataInput(fDeframer);
/* init hw */ /* init hw */
const BUSBConfiguration *config = GetDevice()->ConfigurationAt(0); const BUSBConfiguration *config = GetDevice()->ConfigurationAt(0);
if (config) { if (config) {
const BUSBInterface *inter = config->InterfaceAt(0); const BUSBInterface *inter = config->InterfaceAt(0);
uint32 i; uint32 i;
GetDevice()->SetConfiguration(config); GetDevice()->SetConfiguration(config);
for (i = 0; inter && (i < inter->CountEndpoints()); i++) { for (i = 0; inter && (i < inter->CountEndpoints()); i++) {
@@ -119,14 +119,14 @@ SonixCamDevice::SonixCamDevice(CamDeviceAddon &_addon, BUSBDevice* _device)
} }
} }
/* sanity check */ /* sanity check */
err = ReadReg(SN9C102_ASIC_ID, data); err = ReadReg(SN9C102_ASIC_ID, data);
if (err < 0 || data[0] != 0x10) { if (err < 0 || data[0] != 0x10) {
PRINT((CH ": BAD ASIC signature! (%u != %u)" CT, data[0], 0x10)); PRINT((CH ": BAD ASIC signature! (%u != %u)" CT, data[0], 0x10));
return; return;
} }
//XXX: the XP driver sends this to the ICECAM... need to investigate. //XXX: the XP driver sends this to the ICECAM... need to investigate.
#if 1 #if 1
uint8 tmp_3[] = { uint8 tmp_3[] = {
@@ -149,7 +149,7 @@ SonixCamDevice::SonixCamDevice(CamDeviceAddon &_addon, BUSBDevice* _device)
uint8 tmp_2[] = {0x44, 0x44}; uint8 tmp_2[] = {0x44, 0x44};
WriteReg(SN9C102_CHIP_CTRL, tmp_2, 2); WriteReg(SN9C102_CHIP_CTRL, tmp_2, 2);
//URB_FUNCTION_VENDOR_INTERFACE: //URB_FUNCTION_VENDOR_INTERFACE:
//(USBD_TRANSFER_DIRECTION_OUT, ~USBD_SHORT_TRANSFER_OK) //(USBD_TRANSFER_DIRECTION_OUT, ~USBD_SHORT_TRANSFER_OK)
uint8 tmp_3[] = { uint8 tmp_3[] = {
0x44, 0x44, 0x00, 0x00, 0x00, 0x04, 0x00, 0xa0, 0x44, 0x44, 0x00, 0x00, 0x00, 0x04, 0x00, 0xa0,
@@ -197,7 +197,7 @@ SonixCamDevice::SonixCamDevice(CamDeviceAddon &_addon, BUSBDevice* _device)
//WriteReg8(SN9C102_PIX_CLK, 0x4b); //WriteReg8(SN9C102_PIX_CLK, 0x4b);
//############### //###############
if (Sensor()) { if (Sensor()) {
PRINT((CH ": CamSensor: %s" CT, Sensor()->Name())); PRINT((CH ": CamSensor: %s" CT, Sensor()->Name()));
fInitStatus = Sensor()->Setup(); fInitStatus = Sensor()->Setup();
@@ -237,11 +237,11 @@ SonixCamDevice::StartTransfer()
{ {
status_t err; status_t err;
uint8 r; uint8 r;
SetScale(1); SetScale(1);
if (Sensor()) if (Sensor())
SetVideoFrame(fVideoFrame); SetVideoFrame(fVideoFrame);
//SetVideoFrame(BRect(0, 0, 320-1, 240-1)); //SetVideoFrame(BRect(0, 0, 320-1, 240-1));
DumpRegs(); DumpRegs();
@@ -261,7 +261,7 @@ SonixCamDevice::StopTransfer()
{ {
status_t err; status_t err;
uint8 r; uint8 r;
DumpRegs(); DumpRegs();
err = CamDevice::StopTransfer(); err = CamDevice::StopTransfer();
// if (err < 0) // if (err < 0)
@@ -418,8 +418,8 @@ SonixCamDevice::ReadIIC(uint8 address, uint8 *data)
err = WaitReadyIIC(); err = WaitReadyIIC();
//dprintf(ID "sonix_i2c_write_multi: sonix_i2c_wait_ready error 0x%08lx\n", err); //dprintf(ID "sonix_i2c_write_multi: sonix_i2c_wait_ready error 0x%08lx\n", err);
//if (err) return err; //if (err) return err;
//dprintf(ID "sonix_i2c_write_multi(, %02x, %d, {%02x, %02x, %02x, %02x, %02x})\n", slave, count, d0, d1, d2, d3, d4); //dprintf(ID "sonix_i2c_write_multi(, %02x, %d, {%02x, %02x, %02x, %02x, %02x})\n", slave, count, d0, d1, d2, d3, d4);
buffer[0] = (1 << 4) | Sensor()->Use400kHz()?0x01:0 buffer[0] = (1 << 4) | Sensor()->Use400kHz()?0x01:0
| 0x02 | Sensor()->UseRealIIC()?0x80:0; /* read 1 byte */ | 0x02 | Sensor()->UseRealIIC()?0x80:0; /* read 1 byte */
@@ -431,7 +431,7 @@ SonixCamDevice::ReadIIC(uint8 address, uint8 *data)
err = WaitReadyIIC(); err = WaitReadyIIC();
//dprintf(ID "sonix_i2c_write_multi: sonix_i2c_wait_ready error 0x%08lx\n", err); //dprintf(ID "sonix_i2c_write_multi: sonix_i2c_wait_ready error 0x%08lx\n", err);
if (err < B_OK) return err; if (err < B_OK) return err;
err = ReadReg(SN9C102_I2C_DATA0, buffer, 5); err = ReadReg(SN9C102_I2C_DATA0, buffer, 5);
if (err < 5) return EIO; if (err < 5) return EIO;
@@ -477,7 +477,7 @@ SonixCamDevice::SetScale(float scale)
status_t err; status_t err;
uint8 r; uint8 r;
int iscale = (int)scale; int iscale = (int)scale;
PRINT((CH "(%u)" CT, iscale)); PRINT((CH "(%u)" CT, iscale));
err = ReadReg(SN9C102_SYNC_N_SCALE, &r, 1, true); err = ReadReg(SN9C102_SYNC_N_SCALE, &r, 1, true);
if (err < 0) if (err < 0)
@@ -509,25 +509,25 @@ SonixCamDevice::AddParameters(BParameterGroup *group, int32 &index)
BParameterGroup *g; BParameterGroup *g;
BContinuousParameter *p; BContinuousParameter *p;
CamDevice::AddParameters(group, index); CamDevice::AddParameters(group, index);
// R,G,B gains // R,G,B gains
g = group->MakeGroup("RGB gain"); g = group->MakeGroup("RGB gain");
p = g->MakeContinuousParameter(index++, p = g->MakeContinuousParameter(index++,
B_MEDIA_RAW_VIDEO, "RGB gain", B_MEDIA_RAW_VIDEO, "RGB gain",
B_GAIN, "", 1.0, 1.0+(float)(SN9C102_RGB_GAIN_MAX)/8, (float)1.0/8); B_GAIN, "", 1.0, 1.0+(float)(SN9C102_RGB_GAIN_MAX)/8, (float)1.0/8);
p->SetChannelCount(3); p->SetChannelCount(3);
#if 0 #if 0
// Contrast - NON FUNCTIONAL // Contrast - NON FUNCTIONAL
g = group->MakeGroup("Contrast"); g = group->MakeGroup("Contrast");
p = g->MakeContinuousParameter(index++, p = g->MakeContinuousParameter(index++,
B_MEDIA_RAW_VIDEO, "Contrast", B_MEDIA_RAW_VIDEO, "Contrast",
B_GAIN, "", 0.0, 1.0, 1.0/256); B_GAIN, "", 0.0, 1.0, 1.0/256);
// Brightness - NON FUNCTIONAL // Brightness - NON FUNCTIONAL
g = group->MakeGroup("Brightness"); g = group->MakeGroup("Brightness");
p = g->MakeContinuousParameter(index++, p = g->MakeContinuousParameter(index++,
B_MEDIA_RAW_VIDEO, "Brightness", B_MEDIA_RAW_VIDEO, "Brightness",
B_GAIN, "", 0.0, 1.0, 1.0/256); B_GAIN, "", 0.0, 1.0, 1.0/256);
#endif #endif
@@ -620,7 +620,7 @@ SonixCamDevice::SetParameterValue(int32 id, bigtime_t when, const void *value, s
fBrightness = gains[0]; fBrightness = gains[0];
// it actually ends up writing to SN9C102_V_SIZE... // it actually ends up writing to SN9C102_V_SIZE...
WriteReg8(SN9C10x_BRIGHTNESS, ((uint8)(fBrightness * 256))); WriteReg8(SN9C10x_BRIGHTNESS, ((uint8)(fBrightness * 256)));
return B_OK; return B_OK;
#endif #endif
} }
@@ -656,7 +656,7 @@ SonixCamDevice::ValidateStartOfFrameTag(const uint8 *tag, size_t taglen)
// supposedly corresponding with an equal byte in the end tag // supposedly corresponding with an equal byte in the end tag
fFrameTagState = tag[7] & 0xC0; fFrameTagState = tag[7] & 0xC0;
PRINT((CH "(, %d) state %x" CT, taglen, fFrameTagState)); PRINT((CH "(, %d) state %x" CT, taglen, fFrameTagState));
// which seems to be the same as of the EOF tag // which seems to be the same as of the EOF tag
return true; return true;
} }
@@ -692,14 +692,14 @@ SonixCamDevice::GetFrameBitmap(BBitmap **bm, bigtime_t *stamp /* = NULL */)
if (err < B_OK) if (err < B_OK)
return err; return err;
PRINT((CH ": VideoFrame = %fx%f,%fx%f" CT, VideoFrame().left, VideoFrame().top, VideoFrame().right, VideoFrame().bottom)); PRINT((CH ": VideoFrame = %fx%f,%fx%f" CT, VideoFrame().left, VideoFrame().top, VideoFrame().right, VideoFrame().bottom));
long int w = (long)(VideoFrame().right - VideoFrame().left + 1); long int w = (long)(VideoFrame().right - VideoFrame().left + 1);
long int h = (long)(VideoFrame().bottom - VideoFrame().top + 1); long int h = (long)(VideoFrame().bottom - VideoFrame().top + 1);
b = new BBitmap(VideoFrame().OffsetToSelf(0,0), 0, B_RGB32, w*4); b = new BBitmap(VideoFrame().OffsetToSelf(0,0), 0, B_RGB32, w*4);
PRINT((CH ": Frame: %dx%d" CT, w, h)); PRINT((CH ": Frame: %dx%d" CT, w, h));
bayer2rgb24((unsigned char *)b->Bits(), (unsigned char *)f->Buffer(), w, h); bayer2rgb24((unsigned char *)b->Bits(), (unsigned char *)f->Buffer(), w, h);
PRINT((CH ": got 1 frame (len %d)" CT, b->BitsLength())); PRINT((CH ": got 1 frame (len %d)" CT, b->BitsLength()));
*bm = b; *bm = b;
return B_OK; return B_OK;
@@ -727,12 +727,12 @@ SonixCamDevice::FillFrameBuffer(BBuffer *buffer, bigtime_t *stamp)
long int w = (long)(VideoFrame().right - VideoFrame().left + 1); long int w = (long)(VideoFrame().right - VideoFrame().left + 1);
long int h = (long)(VideoFrame().bottom - VideoFrame().top + 1); long int h = (long)(VideoFrame().bottom - VideoFrame().top + 1);
PRINT((CH ": VideoFrame = %fx%f,%fx%f Frame: %dx%d" CT, VideoFrame().left, VideoFrame().top, VideoFrame().right, VideoFrame().bottom, w, h)); PRINT((CH ": VideoFrame = %fx%f,%fx%f Frame: %dx%d" CT, VideoFrame().left, VideoFrame().top, VideoFrame().right, VideoFrame().bottom, w, h));
if (buffer->SizeAvailable() >= (size_t)w*h*4) if (buffer->SizeAvailable() >= (size_t)w*h*4)
bayer2rgb32le((unsigned char *)buffer->Data(), (unsigned char *)f->Buffer(), w, h); bayer2rgb32le((unsigned char *)buffer->Data(), (unsigned char *)f->Buffer(), w, h);
delete f; delete f;
PRINT((CH ": available %d, required %d" CT, buffer->SizeAvailable(), w*h*4)); PRINT((CH ": available %d, required %d" CT, buffer->SizeAvailable(), w*h*4));
if (buffer->SizeAvailable() < (size_t)w*h*4) if (buffer->SizeAvailable() < (size_t)w*h*4)
return E2BIG; return E2BIG;
@@ -747,18 +747,18 @@ SonixCamDevice::DumpRegs()
{ {
uint8 regs[SN9C102_REG_COUNT]; uint8 regs[SN9C102_REG_COUNT];
status_t err; status_t err;
//err = sonix_get_regs(dev, SN_ASIC_ID, regs, SN_REG_COUNT); //err = sonix_get_regs(dev, SN_ASIC_ID, regs, SN_REG_COUNT);
err = ReadReg(0, regs, SN9C102_REG_COUNT); err = ReadReg(0, regs, SN9C102_REG_COUNT);
if (err < 0) if (err < 0)
return; return;
printf("REG1: %02x %02x %02x %02x %02x %02x %02x %02x\n", printf("REG1: %02x %02x %02x %02x %02x %02x %02x %02x\n",
regs[0], regs[1], regs[2], regs[3], regs[4], regs[5], regs[6], regs[7]); regs[0], regs[1], regs[2], regs[3], regs[4], regs[5], regs[6], regs[7]);
printf(" 2: %02x %02x %02x %02x %02x %02x %02x %02x\n", printf(" 2: %02x %02x %02x %02x %02x %02x %02x %02x\n",
regs[8], regs[9], regs[10], regs[11], regs[12], regs[13], regs[14], regs[15]); regs[8], regs[9], regs[10], regs[11], regs[12], regs[13], regs[14], regs[15]);
printf(" 3: %02x %02x %02x %02x %02x %02x %02x %02x\n", printf(" 3: %02x %02x %02x %02x %02x %02x %02x %02x\n",
regs[16], regs[17], regs[18], regs[19], regs[20], regs[21], regs[22], regs[23]); regs[16], regs[17], regs[18], regs[19], regs[20], regs[21], regs[22], regs[23]);
printf(" 4: %02x %02x %02x %02x %02x %02x %02x %02x\n", printf(" 4: %02x %02x %02x %02x %02x %02x %02x %02x\n",
regs[24], regs[25], regs[26], regs[27], regs[28], regs[29], regs[30], regs[31]); regs[24], regs[25], regs[26], regs[27], regs[28], regs[29], regs[30], regs[31]);
} }
@@ -774,7 +774,7 @@ SonixCamDevice::SendCommand(uint8 dir, uint8 request, uint16 value,
if (length > GetDevice()->MaxEndpoint0PacketSize()) if (length > GetDevice()->MaxEndpoint0PacketSize())
return EINVAL; return EINVAL;
ret = GetDevice()->ControlTransfer( ret = GetDevice()->ControlTransfer(
USB_REQTYPE_VENDOR | USB_REQTYPE_INTERFACE_OUT | dir, USB_REQTYPE_VENDOR | USB_REQTYPE_INTERFACE_OUT | dir,
request, value, index, length, data); request, value, index, length, data);
return ret; return ret;
} }
@@ -996,5 +996,3 @@ void bayer2rgb32le(unsigned char *dst, unsigned char *src, long int WIDTH, long
} }
} }
@@ -16,7 +16,7 @@
#define SN9C102_R_GAIN 0x05 #define SN9C102_R_GAIN 0x05
#define SN9C102_B_GAIN 0x06 #define SN9C102_B_GAIN 0x06
#define SN9C102_I2C_SETUP 0x08 #define SN9C102_I2C_SETUP 0x08
#define SN9C102_I2C_SLAVE_ID 0x09 #define SN9C102_I2C_SLAVE_ID 0x09
#define SN9C102_I2C_DATA0 0x0a #define SN9C102_I2C_DATA0 0x0a
#define SN9C102_I2C_DATA1 0x0b #define SN9C102_I2C_DATA1 0x0b
#define SN9C102_I2C_DATA2 0x0c #define SN9C102_I2C_DATA2 0x0c
@@ -24,11 +24,11 @@
#define SN9C102_I2C_DATA4 0x0e #define SN9C102_I2C_DATA4 0x0e
#define SN9C102_CONTROL_STAT 0x0f /*I2C ??*/ #define SN9C102_CONTROL_STAT 0x0f /*I2C ??*/
#define SN9C102_R_B_GAIN 0x10 /* datasheet says so but it's WRONG */ #define SN9C102_R_B_GAIN 0x10 /* datasheet says so but it's WRONG */
#define SN9C102_G_GAIN 0x11 /* Green channel gain control. -> Gain = (1+G_GAIN/8) #define SN9C102_G_GAIN 0x11 /* Green channel gain control. -> Gain = (1+G_GAIN/8)
Note: It is sync with VSYNC */ Note: It is sync with VSYNC */
#define SN9C102_H_START 0x12 /* Start active pixel number after H­sync of sensor #define SN9C102_H_START 0x12 /* Start active pixel number after H­sync of sensor
Note: Note:
The 1st line sequence of image data is BGBGBG The 1st line sequence of image data is BGBGBG
The 2nd line sequence of image data is GRGRGR */ The 2nd line sequence of image data is GRGRGR */
#define SN9C102_V_START 0x13 /* Start active line number after V­sync of sensor */ #define SN9C102_V_START 0x13 /* Start active line number after V­sync of sensor */
#define SN9C102_OFFSET 0x14 /* Offset adjustment for sensor image data. */ #define SN9C102_OFFSET 0x14 /* Offset adjustment for sensor image data. */
@@ -54,9 +54,8 @@
#define SN9C102_RGB_GAIN_MAX 0x7f #define SN9C102_RGB_GAIN_MAX 0x7f
// This class represents each webcam // This class represents each webcam
class SonixCamDevice : public CamDevice class SonixCamDevice : public CamDevice {
{ public:
public:
SonixCamDevice(CamDeviceAddon &_addon, BUSBDevice* _device); SonixCamDevice(CamDeviceAddon &_addon, BUSBDevice* _device);
~SonixCamDevice(); ~SonixCamDevice();
virtual bool SupportsBulk(); virtual bool SupportsBulk();
@@ -70,13 +69,13 @@ class SonixCamDevice : public CamDevice
// generic register-like access // generic register-like access
virtual ssize_t WriteReg(uint16 address, uint8 *data, size_t count=1); virtual ssize_t WriteReg(uint16 address, uint8 *data, size_t count=1);
virtual ssize_t ReadReg(uint16 address, uint8 *data, size_t count=1, bool cached=false); virtual ssize_t ReadReg(uint16 address, uint8 *data, size_t count=1, bool cached=false);
// I2C-like access // I2C-like access
virtual status_t GetStatusIIC(); virtual status_t GetStatusIIC();
virtual status_t WaitReadyIIC(); virtual status_t WaitReadyIIC();
virtual ssize_t WriteIIC(uint8 address, uint8 *data, size_t count=1); virtual ssize_t WriteIIC(uint8 address, uint8 *data, size_t count=1);
virtual ssize_t ReadIIC(uint8 address, uint8 *data); virtual ssize_t ReadIIC(uint8 address, uint8 *data);
virtual status_t SetVideoFrame(BRect rect); virtual status_t SetVideoFrame(BRect rect);
virtual status_t SetScale(float scale); virtual status_t SetScale(float scale);
virtual status_t SetVideoParams(float brightness, float contrast, float hue, float red, float green, float blue); virtual status_t SetVideoParams(float brightness, float contrast, float hue, float red, float green, float blue);
@@ -94,7 +93,7 @@ class SonixCamDevice : public CamDevice
virtual status_t GetFrameBitmap(BBitmap **bm, bigtime_t *stamp=NULL); virtual status_t GetFrameBitmap(BBitmap **bm, bigtime_t *stamp=NULL);
virtual status_t FillFrameBuffer(BBuffer *buffer, bigtime_t *stamp=NULL); virtual status_t FillFrameBuffer(BBuffer *buffer, bigtime_t *stamp=NULL);
void DumpRegs(); void DumpRegs();
@@ -105,7 +104,7 @@ class SonixCamDevice : public CamDevice
int fChipVersion; int fChipVersion;
int fFrameTagState; int fFrameTagState;
uint8 fRGain; uint8 fRGain;
uint8 fGGain; uint8 fGGain;
uint8 fBGain; uint8 fBGain;
@@ -115,15 +114,14 @@ class SonixCamDevice : public CamDevice
// the addon itself, that instanciate // the addon itself, that instanciate
class SonixCamDeviceAddon : public CamDeviceAddon class SonixCamDeviceAddon : public CamDeviceAddon {
{
public: public:
SonixCamDeviceAddon(WebCamMediaAddOn* webcam); SonixCamDeviceAddon(WebCamMediaAddOn* webcam);
virtual ~SonixCamDeviceAddon(); virtual ~SonixCamDeviceAddon();
virtual const char *BrandName(); virtual const char *BrandName();
virtual SonixCamDevice *Instantiate(CamRoster &roster, BUSBDevice *from); virtual SonixCamDevice *Instantiate(CamRoster &roster, BUSBDevice *from);
}; };
@@ -7,7 +7,7 @@
#define _USB_VIDEO_H #define _USB_VIDEO_H
/* Class/Subclass/Protocol */ /* Class/Subclass/Protocol */
#define CC_VIDEO 0xE #define CC_VIDEO 0xE
#define SC_UNDEFINED 0x0 #define SC_UNDEFINED 0x0
#define SC_VIDEOCONTROL 0x1 #define SC_VIDEOCONTROL 0x1
#define SC_VIDEOSTREAMING 0x2 #define SC_VIDEOSTREAMING 0x2
@@ -15,15 +15,15 @@
#define PC_PROTOCOL_UNDEFINED 0x0 #define PC_PROTOCOL_UNDEFINED 0x0
#define CS_UNDEFINED 0x20 #define CS_UNDEFINED 0x20
#define CS_DEVICE 0x21 #define CS_DEVICE 0x21
#define CS_CONFIGURATION 0x22 #define CS_CONFIGURATION 0x22
#define CS_STRING 0x23 #define CS_STRING 0x23
#define CS_INTERFACE 0x24 #define CS_INTERFACE 0x24
#define CS_ENDPOINT 0x25 #define CS_ENDPOINT 0x25
/* Video Control Class Descriptors */ /* Video Control Class Descriptors */
#define VC_DESCRIPTOR_UNDEFINED 0x0 #define VC_DESCRIPTOR_UNDEFINED 0x0
#define VC_HEADER 0x1 #define VC_HEADER 0x1
#define VC_INPUT_TERMINAL 0x2 #define VC_INPUT_TERMINAL 0x2
#define VC_OUTPUT_TERMINAL 0x3 #define VC_OUTPUT_TERMINAL 0x3
#define VC_SELECTOR_UNIT 0x4 #define VC_SELECTOR_UNIT 0x4
@@ -34,32 +34,32 @@
#define VS_UNDEFINED 0x00 #define VS_UNDEFINED 0x00
#define VS_INPUT_HEADER 0x01 #define VS_INPUT_HEADER 0x01
#define VS_OUTPUT_HEADER 0x02 #define VS_OUTPUT_HEADER 0x02
#define VS_STILL_IMAGE_FRAME 0x03 #define VS_STILL_IMAGE_FRAME 0x03
#define VS_FORMAT_UNCOMPRESSED 0x04 #define VS_FORMAT_UNCOMPRESSED 0x04
#define VS_FRAME_UNCOMPRESSED 0x05 #define VS_FRAME_UNCOMPRESSED 0x05
#define VS_FORMAT_MJPEG 0x06 #define VS_FORMAT_MJPEG 0x06
#define VS_FRAME_MJPEG 0x07 #define VS_FRAME_MJPEG 0x07
#define VS_FORMAT_MPEG2TS 0x0a #define VS_FORMAT_MPEG2TS 0x0a
#define VS_FORMAT_DV 0x0c #define VS_FORMAT_DV 0x0c
#define VS_COLORFORMAT 0x0d #define VS_COLORFORMAT 0x0d
#define VS_FORMAT_FRAME_BASED 0x10 #define VS_FORMAT_FRAME_BASED 0x10
#define VS_FRAME_FRAME_BASED 0x11 #define VS_FRAME_FRAME_BASED 0x11
#define VS_FORMAT_STREAM_BASED 0x12 #define VS_FORMAT_STREAM_BASED 0x12
#define EP_UNDEFINED 0x0 #define EP_UNDEFINED 0x0
#define EP_GENERAL 0x1 #define EP_GENERAL 0x1
#define EP_ENDPOINT 0x2 #define EP_ENDPOINT 0x2
#define EP_INTERRUPT 0x3 #define EP_INTERRUPT 0x3
#define RC_UNDEFINED 0x00 #define RC_UNDEFINED 0x00
#define SET_CUR 0x01 #define SET_CUR 0x01
#define GET_CUR 0x81 #define GET_CUR 0x81
#define GET_MIN 0x82 #define GET_MIN 0x82
#define GET_MAX 0x83 #define GET_MAX 0x83
#define GET_RES 0x84 #define GET_RES 0x84
#define GET_LEN 0x85 #define GET_LEN 0x85
#define GET_INFO 0x86 #define GET_INFO 0x86
#define GET_DEF 0x87 #define GET_DEF 0x87
#define VC_CONTROL_UNDEFINED 0x0 #define VC_CONTROL_UNDEFINED 0x0
#define VC_VIDEO_POWER_MODE_CONTROL 0x1 #define VC_VIDEO_POWER_MODE_CONTROL 0x1
@@ -72,7 +72,7 @@
#define CT_CONTROL_UNDEFINED 0x0 #define CT_CONTROL_UNDEFINED 0x0
#define CT_SCANNING_MODE_CONTROL 0x1 #define CT_SCANNING_MODE_CONTROL 0x1
#define CT_AE_MODE_CONTROL 0x2 #define CT_AE_MODE_CONTROL 0x2
#define CT_AE_PRIORITY_CONTROL 0x3 #define CT_AE_PRIORITY_CONTROL 0x3
#define CT_EXPOSURE_TIME_ABSOLUTE_CONTROL 0x4 #define CT_EXPOSURE_TIME_ABSOLUTE_CONTROL 0x4
#define CT_EXPOSURE_TIME_RELATIVE_CONTROL 0x5 #define CT_EXPOSURE_TIME_RELATIVE_CONTROL 0x5
@@ -87,6 +87,6 @@
#define CT_PANTILT_RELATIVE_CONTROL 0xe #define CT_PANTILT_RELATIVE_CONTROL 0xe
#define CT_ROLL_ABSOLUTE_CONTROL 0xf #define CT_ROLL_ABSOLUTE_CONTROL 0xf
#define CT_ROLL_RELATIVE_CONTROL 0x10 #define CT_ROLL_RELATIVE_CONTROL 0x10
#define CT_PRIVACY_CONTROL 0x11 #define CT_PRIVACY_CONTROL 0x11
#endif /* _USB_VIDEO_H */ #endif /* _USB_VIDEO_H */
@@ -3,10 +3,13 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include "UVCCamDevice.h" #include "UVCCamDevice.h"
#include "USB_video.h" #include "USB_video.h"
#include <stdio.h> #include <stdio.h>
usb_webcam_support_descriptor kSupportedDevices[] = { usb_webcam_support_descriptor kSupportedDevices[] = {
// ofcourse we support a generic UVC device... // ofcourse we support a generic UVC device...
{{ CC_VIDEO, SC_VIDEOCONTROL, 0, 0, 0 }, "USB", "Video Class", "??" }, {{ CC_VIDEO, SC_VIDEOCONTROL, 0, 0, 0 }, "USB", "Video Class", "??" },
@@ -33,7 +36,9 @@ usb_webcam_support_descriptor kSupportedDevices[] = {
{{ 0, 0, 0, 0, 0}, NULL, NULL, NULL } {{ 0, 0, 0, 0, 0}, NULL, NULL, NULL }
}; };
static void print_guid(const uint8* buf)
static void
print_guid(const uint8* buf)
{ {
printf("%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", printf("%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7],
@@ -78,7 +83,9 @@ UVCCamDevice::UVCCamDevice(CamDeviceAddon &_addon, BUSBDevice* _device)
} }
} }
void UVCCamDevice::ParseVideoStreaming(const uint8* buffer, size_t len)
void
UVCCamDevice::ParseVideoStreaming(const uint8* buffer, size_t len)
{ {
int c, i, sz; int c, i, sz;
@@ -198,7 +205,9 @@ void UVCCamDevice::ParseVideoStreaming(const uint8* buffer, size_t len)
} }
} }
void UVCCamDevice::ParseVideoControl(const uint8* buffer, size_t len)
void
UVCCamDevice::ParseVideoControl(const uint8* buffer, size_t len)
{ {
int c, i; int c, i;
@@ -283,25 +292,33 @@ void UVCCamDevice::ParseVideoControl(const uint8* buffer, size_t len)
} }
} }
UVCCamDevice::~UVCCamDevice() UVCCamDevice::~UVCCamDevice()
{ {
} }
bool UVCCamDevice::SupportsIsochronous()
bool
UVCCamDevice::SupportsIsochronous()
{ {
return true; return true;
} }
status_t UVCCamDevice::StartTransfer()
status_t
UVCCamDevice::StartTransfer()
{ {
return CamDevice::StartTransfer(); return CamDevice::StartTransfer();
} }
status_t UVCCamDevice::StopTransfer()
status_t
UVCCamDevice::StopTransfer()
{ {
return CamDevice::StopTransfer(); return CamDevice::StopTransfer();
} }
UVCCamDeviceAddon::UVCCamDeviceAddon(WebCamMediaAddOn* webcam) UVCCamDeviceAddon::UVCCamDeviceAddon(WebCamMediaAddOn* webcam)
: CamDeviceAddon(webcam) : CamDeviceAddon(webcam)
{ {
@@ -8,8 +8,7 @@
#include "CamDevice.h" #include "CamDevice.h"
class UVCCamDevice : public CamDevice class UVCCamDevice : public CamDevice {
{
public: public:
UVCCamDevice(CamDeviceAddon &_addon, BUSBDevice* _device); UVCCamDevice(CamDeviceAddon &_addon, BUSBDevice* _device);
~UVCCamDevice(); ~UVCCamDevice();
@@ -22,12 +21,11 @@ private:
void ParseVideoStreaming(const uint8* buf, size_t len); void ParseVideoStreaming(const uint8* buf, size_t len);
}; };
class UVCCamDeviceAddon : public CamDeviceAddon class UVCCamDeviceAddon : public CamDeviceAddon {
{
public: public:
UVCCamDeviceAddon(WebCamMediaAddOn* webcam); UVCCamDeviceAddon(WebCamMediaAddOn* webcam);
virtual ~UVCCamDeviceAddon(); virtual ~UVCCamDeviceAddon();
virtual const char *BrandName(); virtual const char *BrandName();
virtual UVCCamDevice *Instantiate(CamRoster &roster, BUSBDevice *from); virtual UVCCamDevice *Instantiate(CamRoster &roster, BUSBDevice *from);
}; };
@@ -23,7 +23,7 @@ public:
HDCS1000Sensor::HDCS1000Sensor(CamDevice *_camera) HDCS1000Sensor::HDCS1000Sensor(CamDevice *_camera)
: CamSensor(_camera) : CamSensor(_camera)
{ {
} }
@@ -50,7 +50,7 @@ HDCS1000Sensor::Probe()
} }
return ENODEV; return ENODEV;
} }
B_WEBCAM_DECLARE_SENSOR(HDCS1000Sensor, hdcs1000) B_WEBCAM_DECLARE_SENSOR(HDCS1000Sensor, hdcs1000)
@@ -27,9 +27,9 @@ public:
HV7131E1Sensor::HV7131E1Sensor(CamDevice *_camera) HV7131E1Sensor::HV7131E1Sensor(CamDevice *_camera)
: CamSensor(_camera) : CamSensor(_camera)
{ {
} }
@@ -41,7 +41,7 @@ HV7131E1Sensor::~HV7131E1Sensor()
status_t status_t
HV7131E1Sensor::Probe() HV7131E1Sensor::Probe()
{ {
return ProbeByIICSignature(sProbeAddressList, sProbeMatchList, return ProbeByIICSignature(sProbeAddressList, sProbeMatchList,
sizeof(sProbeMatchList)); sizeof(sProbeMatchList));
} }