Go to the documentation of this file.
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;
221 #ifdef DEBUGRINGBUFFERS
224 lastPut = lastGet = -1;
233 int diff = Tail -
head;
234 int free = (diff > 0) ? diff - 1 :
Size() -
head;
240 if (0 < Max && Max < free)
244 int Head =
head + Count;
249 int fill =
head - Tail;
251 fill =
Size() + fill;
252 else if (fill >=
Size())
258 #ifdef DEBUGRINGBUFFERS
271 int diff = Tail -
head;
272 int free = (diff > 0) ? diff - 1 :
Size() -
head;
278 if (0 < Max && Max < free)
282 int Head =
head + Count;
287 int fill =
head - Tail;
289 fill =
Size() + fill;
290 else if (fill >=
Size())
296 #ifdef DEBUGRINGBUFFERS
311 int diff = Tail -
head;
312 int free = ((Tail <
margin) ? rest : (diff > 0) ? diff :
Size() + diff -
margin) - 1;
314 int fill =
Size() - free - 1 + Count;
335 #ifdef DEBUGRINGBUFFERS
358 int diff = Head -
tail;
359 int cont = (diff >= 0) ? diff :
Size() + diff -
margin;
374 esyslog(
"ERROR: invalid Count in cRingBufferLinear::Del: %d (limited to %d)", Count,
gotten);
386 #ifdef DEBUGRINGBUFFERS
408 esyslog(
"ERROR: can't allocate frame buffer (count=%d)",
count);
436 while ((p =
Get()) != NULL)
492 esyslog(
"ERROR: attempt to drop wrong frame from ring buffer!");
bool Independent(void) const
virtual void Clear(void)
Immediately clears the ring buffer.
void SetTimeouts(int PutTimeout, int GetTimeout)
void Signal(void)
Signals a caller of Wait() that the condition it is waiting for is met.
int Put(const uchar *Data, int Count)
Puts at most Count bytes of Data into the ring buffer.
void UpdatePercentage(int Fill)
#define PERCENTAGETHRESHOLD
virtual int Available(void)
ssize_t Read(void *Data, size_t Size)
int Read(int FileHandle, int Max=0)
Reads at most Max bytes from FileHandle and stores them in the ring buffer.
cRingBufferFrame(int Size, bool Statistics=false)
cFrame(const uchar *Data, int Count, eFrameType=ftUnknown, int Index=-1, uint32_t Pts=0, bool independent=false)
Creates a new cFrame object.
cUnbufferedFile is used for large files that are mainly written or read in a streaming manner,...
static tThreadId ThreadId(void)
cRingBufferLinear(int Size, int Margin=0, bool Statistics=false, const char *Description=NULL)
Creates a linear ring buffer.
bool Wait(int TimeoutMs=0)
Waits at most TimeoutMs milliseconds for a call to Signal(), or forever if TimeoutMs is 0.
virtual int Available(void)=0
#define OVERFLOWREPORTDELTA
void Del(int Count)
Deletes at most Count bytes from the ring buffer.
uchar * Get(int &Count)
Gets data from the ring buffer.
void Delete(cFrame *Frame)
void Release(void)
Releases the global I/O throttling mechanism.
virtual ~cRingBufferFrame()
virtual ~cRingBufferLinear()
time_t lastOverflowReport
virtual int Available(void)
void Activate(void)
Activates the global I/O throttling mechanism.
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.
cRingBuffer(int Size, bool Statistics=false)
eFrameType Type(void) const
void ReportOverflow(int Bytes)