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