1 #ifndef _CAM_DEFRAMER_H 2 #define _CAM_DEFRAMER_H 3 4 #include <OS.h> 5 #include <DataIO.h> 6 #include <Locker.h> 7 #include <List.h> 8 #include "CamFilterInterface.h" 9 class CamDevice; 10 11 #define CAMDEFRAMER_MAX_TAG_LEN 16 12 #define CAMDEFRAMER_MAX_QUEUED_FRAMES 50 13 14 enum { 15 ST_SYNC, /* waiting for start of frame */ 16 ST_FRAME 17 }; 18 19 20 /* should have a real Frame class someday */ 21 class CamFrame : public BMallocIO 22 { 23 public: 24 CamFrame() : BMallocIO() { fStamp = system_time(); }; 25 virtual ~CamFrame() {}; 26 bigtime_t Stamp() const { return fStamp; }; 27 bigtime_t fStamp; 28 }; 29 30 class CamDeframer : public CamFilterInterface 31 { 32 public: 33 CamDeframer(CamDevice *device); 34 virtual ~CamDeframer(); 35 // BPositionIO interface 36 // read from translators/cs transforms 37 virtual ssize_t Read(void *buffer, size_t size); 38 virtual ssize_t ReadAt(off_t pos, void *buffer, size_t size); 39 virtual off_t Seek(off_t position, uint32 seek_mode); 40 virtual off_t Position() const; 41 virtual status_t SetSize(off_t size); 42 // write from usb transfers 43 virtual ssize_t Write(const void *buffer, size_t size); 44 virtual ssize_t WriteAt(off_t pos, const void *buffer, size_t size); 45 46 virtual status_t WaitFrame(bigtime_t timeout); 47 virtual status_t GetFrame(CamFrame **frame, bigtime_t *stamp); // caller deletes 48 virtual status_t DropFrame(); 49 50 status_t RegisterSOFTags(const uint8 **tags, int count, size_t len, size_t skip); 51 status_t RegisterEOFTags(const uint8 **tags, int count, size_t len, size_t skip); 52 53 protected: 54 55 int FindTags(const uint8 *buf, size_t buflen, const uint8 **tags, int tagcount, size_t taglen, size_t skiplen, int *which=NULL); 56 int FindSOF(const uint8 *buf, size_t buflen, int *which=NULL); 57 int FindEOF(const uint8 *buf, size_t buflen, int *which=NULL); 58 59 CamFrame *AllocFrame(); 60 61 CamDevice *fDevice; 62 size_t fMinFrameSize; 63 size_t fMaxFrameSize; 64 int fState; 65 sem_id fFrameSem; 66 BList fFrames; 67 BLocker fLocker; 68 CamFrame *fCurrentFrame; /* the one we write to*/ 69 70 /* tags */ 71 const uint8 **fSOFTags; 72 const uint8 **fEOFTags; 73 int fNumSOFTags; 74 int fNumEOFTags; 75 size_t fLenSOFTags; 76 size_t fLenEOFTags; 77 size_t fSkipSOFTags; 78 size_t fSkipEOFTags; 79 80 81 82 }; 83 84 85 #endif /* _CAM_DEFRAMER_H */ 86