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