2 * Copyright 2004-2008, François Revol, <revol@free.fr>.
3 * Distributed under the terms of the MIT License.
7 #include "CamDeframer.h"
11 #define MAX_TAG_LEN CAMDEFRAMER_MAX_TAG_LEN
12 #define MAXFRAMEBUF CAMDEFRAMER_MAX_QUEUED_FRAMES
15 CamDeframer::CamDeframer(CamDevice
*device
)
16 : CamFilterInterface(device
),
20 fLocker("CamDeframer Framelist lock", true),
30 fMinFrameSize
= fDevice
->MinRawFrameSize();
31 fMaxFrameSize
= fDevice
->MaxRawFrameSize();
32 fFrameSem
= create_sem(0, "CamDeframer sem");
33 fCurrentFrame
= AllocFrame();
37 CamDeframer::~CamDeframer()
39 delete_sem(fFrameSem
);
46 CamDeframer::Read(void *buffer
, size_t size
)
49 CamFrame
*f
= (CamFrame
*)fFrames
.ItemAt(0);
52 return f
->Read(buffer
, size
);
57 CamDeframer::ReadAt(off_t pos
, void *buffer
, size_t size
)
60 CamFrame
*f
= (CamFrame
*)fFrames
.ItemAt(0);
63 return f
->ReadAt(pos
, buffer
, size
);
68 CamDeframer::Seek(off_t position
, uint32 seek_mode
)
71 CamFrame
*f
= (CamFrame
*)fFrames
.ItemAt(0);
74 return f
->Seek(position
, seek_mode
);
79 CamDeframer::Position() const
81 BAutolock
l((BLocker
&)fLocker
); // need to get rid of const here
82 CamFrame
*f
= (CamFrame
*)fFrames
.ItemAt(0);
90 CamDeframer::SetSize(off_t size
)
98 CamDeframer::Write(const void *buffer
, size_t size
)
107 CamDeframer::WriteAt(off_t pos
, const void *buffer
, size_t size
)
117 CamDeframer::WaitFrame(bigtime_t timeout
)
119 return acquire_sem_etc(fFrameSem
, 1, B_RELATIVE_TIMEOUT
, timeout
);
124 CamDeframer::GetFrame(CamFrame
**frame
, bigtime_t
*stamp
)
127 BAutolock
l(fLocker
);
128 CamFrame
*f
= (CamFrame
*)fFrames
.RemoveItem((int32
)0);
138 CamDeframer::DropFrame()
141 BAutolock
l(fLocker
);
142 CamFrame
*f
= (CamFrame
*)fFrames
.RemoveItem((int32
)0);
151 CamDeframer::RegisterSOFTags(const uint8
**tags
, int count
, size_t len
, size_t skip
)
155 if (len
> MAX_TAG_LEN
)
168 CamDeframer::RegisterEOFTags(const uint8
**tags
, int count
, size_t len
, size_t skip
)
172 if (len
> MAX_TAG_LEN
)
185 CamDeframer::FindTags(const uint8
*buf
, size_t buflen
, const uint8
**tags
, int tagcount
, size_t taglen
, size_t skiplen
, int *which
)
188 for (i
= 0; i
< (int)(buflen
- skiplen
+ 1); i
++) {
189 for (t
= 0; t
< tagcount
; t
++) {
190 if (!memcmp(buf
+i
, tags
[t
], taglen
)) {
202 CamDeframer::FindSOF(const uint8
*buf
, size_t buflen
, int *which
)
204 return FindTags(buf
, buflen
, fSOFTags
, fNumSOFTags
, fLenSOFTags
, fSkipSOFTags
, which
);
209 CamDeframer::FindEOF(const uint8
*buf
, size_t buflen
, int *which
)
211 return FindTags(buf
, buflen
, fEOFTags
, fNumEOFTags
, fLenEOFTags
, fSkipEOFTags
, which
);
216 CamDeframer::AllocFrame()
218 return new CamFrame();