20 #define OVERFLOWREPORTDELTA 5 // seconds between reports 21 #define PERCENTAGEDELTA 10 22 #define PERCENTAGETHRESHOLD 70 23 #define IOTHROTTLELOW 20 24 #define IOTHROTTLEHIGH 50 114 #ifdef DEBUGRINGBUFFERS 116 #define DEBUGRBLWIDTH 45 122 for (
int i = 0; i < MAXRBLS; i++) {
132 for (
int i = 0; i < MAXRBLS; i++) {
133 if (RBLS[i] == RBL) {
140 void cRingBufferLinear::PrintDebugRBL(
void)
142 bool printed =
false;
143 for (
int i = 0; i < MAXRBLS; i++) {
147 int lh = p->lastHead;
148 int lt = p->lastTail;
149 int h = lh * DEBUGRBLWIDTH / p->
Size();
150 int t = lt * DEBUGRBLWIDTH / p->
Size();
151 char buf[DEBUGRBLWIDTH + 10];
152 memset(buf,
'-', DEBUGRBLWIDTH);
154 memset(buf + t,
'*',
max(h - t, 1));
157 memset(buf + t,
'*', DEBUGRBLWIDTH - t);
161 buf[DEBUGRBLWIDTH] = 0;
162 printf(
"%2d %s %8d %8d %s\n", i, buf, p->lastPut, p->lastGet, p->
description);
173 description = Description ? strdup(Description) : NULL;
178 if (Margin <= Size / 2) {
181 esyslog(
"ERROR: can't allocate ring buffer (size=%d)", Size);
185 esyslog(
"ERROR: invalid margin for ring buffer (%d > %d)", Margin, Size / 2);
188 esyslog(
"ERROR: invalid size for ring buffer (%d)", Size);
189 #ifdef DEBUGRINGBUFFERS 192 lastPut = lastGet = -1;
199 #ifdef DEBUGRINGBUFFERS 208 return Count >=
margin ? Count : 0;
214 return (diff >= 0) ? diff :
Size() + diff -
margin;
220 #ifdef DEBUGRINGBUFFERS 223 lastPut = lastGet = -1;
232 int diff = Tail -
head;
233 int free = (diff > 0) ? diff - 1 :
Size() -
head;
239 if (0 < Max && Max < free)
243 int Head = head + Count;
248 int fill = head - Tail;
250 fill =
Size() + fill;
251 else if (fill >=
Size())
257 #ifdef DEBUGRINGBUFFERS 270 int diff = Tail -
head;
271 int free = (diff > 0) ? diff - 1 :
Size() -
head;
277 if (0 < Max && Max < free)
281 int Head = head + Count;
286 int fill = head - Tail;
288 fill =
Size() + fill;
289 else if (fill >=
Size())
295 #ifdef DEBUGRINGBUFFERS 310 int diff = Tail -
head;
311 int free = ((Tail < margin) ? rest : (diff > 0) ? diff :
Size() + diff -
margin) - 1;
313 int fill =
Size() - free - 1 + Count;
322 memcpy(
buffer + head, Data, rest);
325 head =
margin + Count - rest;
328 memcpy(
buffer + head, Data, Count);
334 #ifdef DEBUGRINGBUFFERS 357 int diff = Head -
tail;
358 int cont = (diff >= 0) ? diff :
Size() + diff -
margin;
373 esyslog(
"ERROR: invalid Count in cRingBufferLinear::Del: %d (limited to %d)", Count,
gotten);
385 #ifdef DEBUGRINGBUFFERS 400 data = (
uchar *)Data;
404 memcpy(data, Data, count);
406 esyslog(
"ERROR: can't allocate frame buffer (count=%d)", count);
434 while ((p =
Get()) != NULL)
490 esyslog(
"ERROR: attempt to drop wrong frame from ring buffer!");
virtual int DataReady(const uchar *Data, int Count)
By default a ring buffer has data ready as soon as there are at least 'margin' bytes available...
virtual void Clear(void)
Immediately clears the ring buffer.
virtual int Available(void)
ssize_t Read(void *Data, size_t Size)
void Signal(void)
Signals a caller of Wait() that the condition it is waiting for is met.
cRingBufferFrame(int Size, bool Statistics=false)
cRingBufferLinear(int Size, int Margin=0, bool Statistics=false, const char *Description=NULL)
Creates a linear ring buffer.
int Put(const uchar *Data, int Count)
Puts at most Count bytes of Data into the ring buffer.
void UpdatePercentage(int Fill)
cUnbufferedFile is used for large files that are mainly written or read in a streaming manner...
int Read(int FileHandle, int Max=0)
Reads at most Max bytes from FileHandle and stores them in the ring buffer.
virtual int Available(void)=0
bool Wait(int TimeoutMs=0)
Waits at most TimeoutMs milliseconds for a call to Signal(), or forever if TimeoutMs is 0...
static tThreadId ThreadId(void)
void Activate(void)
Activates the global I/O throttling mechanism.
void Del(int Count)
Deletes at most Count bytes from the ring buffer.
cFrame(const uchar *Data, int Count, eFrameType=ftUnknown, int Index=-1, uint32_t Pts=0)
Creates a new cFrame object.
virtual ~cRingBufferLinear()
uchar * Get(int &Count)
Gets data from the ring buffer.
void Delete(cFrame *Frame)
cRingBuffer(int Size, bool Statistics=false)
virtual ~cRingBufferFrame()
#define PERCENTAGETHRESHOLD
void SetTimeouts(int PutTimeout, int GetTimeout)
#define OVERFLOWREPORTDELTA
void Release(void)
Releases the global I/O throttling mechanism.
void ReportOverflow(int Bytes)
time_t lastOverflowReport
virtual int Available(void)