xref: /haiku/src/add-ons/media/media-add-ons/usb_webcam/CamDeframer.h (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
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 #define CamFrame BMallocIO
22 
23 class CamDeframer : public CamFilterInterface
24 {
25 public:
26 			CamDeframer(CamDevice *device);
27 virtual 	~CamDeframer();
28 					// BPositionIO interface
29 					// read from translators/cs transforms
30 virtual ssize_t		Read(void *buffer, size_t size);
31 virtual ssize_t		ReadAt(off_t pos, void *buffer, size_t size);
32 virtual off_t		Seek(off_t position, uint32 seek_mode);
33 virtual off_t		Position() const;
34 virtual status_t	SetSize(off_t size);
35 					// write from usb transfers
36 virtual ssize_t		Write(const void *buffer, size_t size);
37 virtual ssize_t		WriteAt(off_t pos, const void *buffer, size_t size);
38 
39 virtual status_t	WaitFrame(bigtime_t timeout);
40 virtual status_t	GetFrame(CamFrame **frame, bigtime_t *stamp); // caller deletes
41 virtual status_t	DropFrame();
42 
43 status_t	RegisterSOFTags(const uint8 **tags, int count, size_t len, size_t skip);
44 status_t	RegisterEOFTags(const uint8 **tags, int count, size_t len, size_t skip);
45 
46 protected:
47 
48 int		FindTags(const uint8 *buf, size_t buflen, const uint8 **tags, int tagcount, size_t taglen, size_t skiplen, int *which=NULL);
49 int		FindSOF(const uint8 *buf, size_t buflen, int *which=NULL);
50 int		FindEOF(const uint8 *buf, size_t buflen, int *which=NULL);
51 
52 CamFrame	*AllocFrame();
53 
54 CamDevice	*fDevice;
55 size_t	fMinFrameSize;
56 size_t	fMaxFrameSize;
57 int	fState;
58 sem_id	fFrameSem;
59 BList	fFrames;
60 BLocker	fLocker;
61 CamFrame	*fCurrentFrame; /* the one we write to*/
62 
63 /* tags */
64 const uint8 **fSOFTags;
65 const uint8 **fEOFTags;
66 int			fNumSOFTags;
67 int			fNumEOFTags;
68 size_t		fLenSOFTags;
69 size_t		fLenEOFTags;
70 size_t		fSkipSOFTags;
71 size_t		fSkipEOFTags;
72 
73 
74 
75 };
76 
77 
78 #endif /* _CAM_DEFRAMER_H */
79