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