Make CamFrame a subclass of BMallocIO to add a timestamp field.

Set the field on allocation and pass it around.
Still disabled as CodyCam drops everything, I should probably drop old frames from the buffer... 
for now it uses system_time() to make CodyCam happy.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23307 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol
2008-01-09 14:10:37 +00:00
parent 7815f565dc
commit 6bb8b29f48
7 changed files with 28 additions and 16 deletions
@@ -108,7 +108,7 @@ CamDeframer::GetFrame(CamFrame **frame, bigtime_t *stamp)
if (!f) if (!f)
return ENOENT; return ENOENT;
*frame = f; *frame = f;
*stamp = 0LL; *stamp = f->Stamp();
return B_OK; return B_OK;
} }
@@ -18,7 +18,14 @@ ST_FRAME
/* should have a real Frame class someday */ /* should have a real Frame class someday */
#define CamFrame BMallocIO class CamFrame : public BMallocIO
{
public:
CamFrame() : BMallocIO() { fStamp = system_time(); };
virtual ~CamFrame() {};
bigtime_t Stamp() const { return fStamp; };
bigtime_t fStamp;
};
class CamDeframer : public CamFilterInterface class CamDeframer : public CamFilterInterface
{ {
@@ -242,14 +242,14 @@ CamDevice::WaitFrame(bigtime_t timeout)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
status_t status_t
CamDevice::GetFrameBitmap(BBitmap **bm) CamDevice::GetFrameBitmap(BBitmap **bm, bigtime_t *stamp)
{ {
return EINVAL; return EINVAL;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
status_t status_t
CamDevice::FillFrameBuffer(BBuffer *buffer) CamDevice::FillFrameBuffer(BBuffer *buffer, bigtime_t *stamp)
{ {
return EINVAL; return EINVAL;
} }
@@ -66,8 +66,8 @@ class CamDevice {
// several ways to get raw frames // several ways to get raw frames
virtual status_t WaitFrame(bigtime_t timeout); virtual status_t WaitFrame(bigtime_t timeout);
virtual status_t GetFrameBitmap(BBitmap **bm); virtual status_t GetFrameBitmap(BBitmap **bm, bigtime_t *stamp=NULL);
virtual status_t FillFrameBuffer(BBuffer *buffer); virtual status_t FillFrameBuffer(BBuffer *buffer, bigtime_t *stamp=NULL);
// locking // locking
bool Lock(); bool Lock();
@@ -744,10 +744,12 @@ VideoProducer::FrameGenerator()
/* For a buffer originating from a device, you might want to calculate /* For a buffer originating from a device, you might want to calculate
* this based on the PerformanceTimeFor the time your buffer arrived at * this based on the PerformanceTimeFor the time your buffer arrived at
* the hardware (plus any applicable adjustments). */ * the hardware (plus any applicable adjustments). */
/*
h->start_time = fPerformanceTimeBase + h->start_time = fPerformanceTimeBase +
(bigtime_t) (bigtime_t)
((fFrame - fFrameBase) * ((fFrame - fFrameBase) *
(1000000 / fConnectedFormat.field_rate)); (1000000 / fConnectedFormat.field_rate));
*/
h->file_pos = 0; h->file_pos = 0;
h->orig_size = 0; h->orig_size = 0;
h->data_offset = 0; h->data_offset = 0;
@@ -771,19 +773,24 @@ VideoProducer::FrameGenerator()
//NO! must be called without lock! //NO! must be called without lock!
//BAutolock lock(fCamDevice->Locker()); //BAutolock lock(fCamDevice->Locker());
bigtime_t stamp;
//#ifdef UseFillFrameBuffer //#ifdef UseFillFrameBuffer
err = fCamDevice->FillFrameBuffer(buffer); err = fCamDevice->FillFrameBuffer(buffer, &stamp);
if (err < B_OK) { if (err < B_OK) {
;//XXX handle error ;//XXX handle error
} }
//#endif //#endif
#ifdef UseGetFrameBitmap #ifdef UseGetFrameBitmap
BBitmap *bm; BBitmap *bm;
err = fCamDevice->GetFrameBitmap(&bm); err = fCamDevice->GetFrameBitmap(&bm, &stamp);
if (err >= B_OK) { if (err >= B_OK) {
;//XXX handle error ;//XXX handle error
} }
#endif #endif
//PRINTF(1, ("FrameGenerator: stamp %Ld vs %Ld\n", stamp, h->start_time));
//XXX: that's what we should be doing, but CodyCam drops all frames as they are late. (maybe add latency ??)
//h->start_time = TimeSource()->PerformanceTimeFor(stamp);
h->start_time = TimeSource()->PerformanceTimeFor(system_time());
PRINTF(1, ("FrameGenerator: SendBuffer...\n")); PRINTF(1, ("FrameGenerator: SendBuffer...\n"));
/* Send the buffer on down to the consumer */ /* Send the buffer on down to the consumer */
@@ -415,18 +415,17 @@ SonixCamDevice::ValidateEndOfFrameTag(const uint8 *tag, size_t taglen, size_t da
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
status_t status_t
SonixCamDevice::GetFrameBitmap(BBitmap **bm) SonixCamDevice::GetFrameBitmap(BBitmap **bm, bigtime_t *stamp=NULL)
{ {
BBitmap *b; BBitmap *b;
CamFrame *f; CamFrame *f;
bigtime_t stamp;
status_t err; status_t err;
PRINT((CH "()" CT)); PRINT((CH "()" CT));
err = fDeframer->WaitFrame(200000); err = fDeframer->WaitFrame(200000);
if (err < B_OK) { PRINT((CH ": WaitFrame: %s" CT, strerror(err))); } if (err < B_OK) { PRINT((CH ": WaitFrame: %s" CT, strerror(err))); }
if (err < B_OK) if (err < B_OK)
return err; return err;
err = fDeframer->GetFrame(&f, &stamp); err = fDeframer->GetFrame(&f, stamp);
if (err < B_OK) { PRINT((CH ": GetFrame: %s" CT, strerror(err))); } if (err < B_OK) { PRINT((CH ": GetFrame: %s" CT, strerror(err))); }
if (err < B_OK) if (err < B_OK)
return err; return err;
@@ -446,10 +445,9 @@ SonixCamDevice::GetFrameBitmap(BBitmap **bm)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
status_t status_t
SonixCamDevice::FillFrameBuffer(BBuffer *buffer) SonixCamDevice::FillFrameBuffer(BBuffer *buffer, bigtime_t *stamp)
{ {
CamFrame *f; CamFrame *f;
bigtime_t stamp;
status_t err; status_t err;
PRINT((CH "()" CT)); PRINT((CH "()" CT));
@@ -459,7 +457,7 @@ SonixCamDevice::FillFrameBuffer(BBuffer *buffer)
if (err < B_OK) if (err < B_OK)
return err; return err;
err = fDeframer->GetFrame(&f, &stamp); err = fDeframer->GetFrame(&f, stamp);
if (err < B_OK) { PRINT((CH ": GetFrame: %s" CT, strerror(err))); } if (err < B_OK) { PRINT((CH ": GetFrame: %s" CT, strerror(err))); }
if (err < B_OK) if (err < B_OK)
return err; return err;
@@ -68,8 +68,8 @@ class SonixCamDevice : public CamDevice
virtual bool ValidateStartOfFrameTag(const uint8 *tag, size_t taglen); virtual bool ValidateStartOfFrameTag(const uint8 *tag, size_t taglen);
virtual bool ValidateEndOfFrameTag(const uint8 *tag, size_t taglen, size_t datalen); virtual bool ValidateEndOfFrameTag(const uint8 *tag, size_t taglen, size_t datalen);
virtual status_t GetFrameBitmap(BBitmap **bm); virtual status_t GetFrameBitmap(BBitmap **bm, bigtime_t *stamp=NULL);
virtual status_t FillFrameBuffer(BBuffer *buffer); virtual status_t FillFrameBuffer(BBuffer *buffer, bigtime_t *stamp=NULL);
void DumpRegs(); void DumpRegs();