vdr 2.6.1
ringbuffer.h
Go to the documentation of this file.
1/*
2 * ringbuffer.h: A ring buffer
3 *
4 * See the main source file 'vdr.c' for copyright information and
5 * how to reach the author.
6 *
7 * $Id: ringbuffer.h 4.2 2017/03/19 13:11:39 kls Exp $
8 */
9
10#ifndef __RINGBUFFER_H
11#define __RINGBUFFER_H
12
13#include "thread.h"
14#include "tools.h"
15
17private:
21 int size;
26protected:
28 int maxFill;//XXX
30 bool statistics;//XXX
31 void UpdatePercentage(int Fill);
32 void WaitForPut(void);
33 void WaitForGet(void);
34 void EnablePut(void);
35 void EnableGet(void);
36 virtual void Clear(void) = 0;
37 virtual int Available(void) = 0;
38 virtual int Free(void) { return Size() - Available() - 1; }
39 int Size(void) { return size; }
40public:
41 cRingBuffer(int Size, bool Statistics = false);
42 virtual ~cRingBuffer();
43 void SetTimeouts(int PutTimeout, int GetTimeout);
44 void SetIoThrottle(void);
45 void ReportOverflow(int Bytes);
46 };
47
49//#define DEBUGRINGBUFFERS
50#ifdef DEBUGRINGBUFFERS
51private:
52 int lastHead, lastTail;
53 int lastPut, lastGet;
54 static cRingBufferLinear *RBLS[];
55 static void AddDebugRBL(cRingBufferLinear *RBL);
56 static void DelDebugRBL(cRingBufferLinear *RBL);
57public:
58 static void PrintDebugRBL(void);
59#endif
60private:
62 int gotten;
65protected:
66 virtual int DataReady(const uchar *Data, int Count);
72public:
73 cRingBufferLinear(int Size, int Margin = 0, bool Statistics = false, const char *Description = NULL);
78 virtual ~cRingBufferLinear();
79 virtual int Available(void);
80 virtual int Free(void) { return Size() - Available() - 1 - margin; }
81 virtual void Clear(void);
85 int Read(int FileHandle, int Max = 0);
91 int Read(cUnbufferedFile *File, int Max = 0);
93 int Put(const uchar *Data, int Count);
96 uchar *Get(int &Count);
101 void Del(int Count);
105 };
106
108
109class cFrame {
110 friend class cRingBufferFrame;
111private:
114 int count;
116 int index;
117 uint32_t pts;
119public:
120 cFrame(const uchar *Data, int Count, eFrameType = ftUnknown, int Index = -1, uint32_t Pts = 0, bool independent = false);
124 ~cFrame();
125 uchar *Data(void) const { return data; }
126 int Count(void) const { return count; }
127 eFrameType Type(void) const { return type; }
128 int Index(void) const { return index; }
129 uint32_t Pts(void) const { return pts; }
130 bool Independent(void) const { return independent; }
131 };
132
134private:
138 void Delete(cFrame *Frame);
139 void Lock(void) { mutex.Lock(); }
140 void Unlock(void) { mutex.Unlock(); }
141public:
142 cRingBufferFrame(int Size, bool Statistics = false);
143 virtual ~cRingBufferFrame();
144 virtual int Available(void);
145 virtual void Clear(void);
146 // Immediately clears the ring buffer.
147 bool Put(cFrame *Frame);
148 // Puts the Frame into the ring buffer.
149 // Returns true if this was possible.
150 cFrame *Get(void);
151 // Gets the next frame from the ring buffer.
152 // The actual data still remains in the buffer until Drop() is called.
153 void Drop(cFrame *Frame);
154 // Drops the Frame that has just been fetched with Get().
155 };
156
157#endif // __RINGBUFFER_H
uchar * Data(void) const
Definition: ringbuffer.h:125
eFrameType type
Definition: ringbuffer.h:115
uint32_t pts
Definition: ringbuffer.h:117
uint32_t Pts(void) const
Definition: ringbuffer.h:129
bool independent
Definition: ringbuffer.h:118
int Index(void) const
Definition: ringbuffer.h:128
eFrameType Type(void) const
Definition: ringbuffer.h:127
uchar * data
Definition: ringbuffer.h:113
int index
Definition: ringbuffer.h:116
cFrame * next
Definition: ringbuffer.h:112
bool Independent(void) const
Definition: ringbuffer.h:130
~cFrame()
Definition: ringbuffer.c:413
int count
Definition: ringbuffer.h:114
int Count(void) const
Definition: ringbuffer.h:126
Definition: thread.h:67
void Lock(void)
Definition: thread.c:222
void Unlock(void)
Definition: thread.c:228
virtual int Available(void)
Definition: ringbuffer.c:498
void Unlock(void)
Definition: ringbuffer.h:140
cFrame * Get(void)
Definition: ringbuffer.c:463
void Delete(cFrame *Frame)
Definition: ringbuffer.c:471
bool Put(cFrame *Frame)
Definition: ringbuffer.c:443
virtual void Clear(void)
Definition: ringbuffer.c:432
void Lock(void)
Definition: ringbuffer.h:139
void Drop(cFrame *Frame)
Definition: ringbuffer.c:477
virtual ~cRingBufferFrame()
Definition: ringbuffer.c:427
void Del(int Count)
Deletes at most Count bytes from the ring buffer.
Definition: ringbuffer.c:371
int Put(const uchar *Data, int Count)
Puts at most Count bytes of Data into the ring buffer.
Definition: ringbuffer.c:306
virtual int Available(void)
Definition: ringbuffer.c:211
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.
Definition: ringbuffer.c:206
virtual void Clear(void)
Immediately clears the ring buffer.
Definition: ringbuffer.c:217
uchar * Get(int &Count)
Gets data from the ring buffer.
Definition: ringbuffer.c:346
char * description
Definition: ringbuffer.h:64
virtual int Free(void)
Definition: ringbuffer.h:80
virtual ~cRingBufferLinear()
Definition: ringbuffer.c:197
int Read(int FileHandle, int Max=0)
Reads at most Max bytes from FileHandle and stores them in the ring buffer.
Definition: ringbuffer.c:230
int Size(void)
Definition: ringbuffer.h:39
void WaitForGet(void)
Definition: ringbuffer.c:71
int overflowCount
Definition: ringbuffer.h:23
void SetTimeouts(int PutTimeout, int GetTimeout)
Definition: ringbuffer.c:89
void SetIoThrottle(void)
Definition: ringbuffer.c:95
int lastPercent
Definition: ringbuffer.h:29
time_t lastOverflowReport
Definition: ringbuffer.h:22
void EnablePut(void)
Definition: ringbuffer.c:77
bool statistics
Definition: ringbuffer.h:30
void WaitForPut(void)
Definition: ringbuffer.c:65
int getTimeout
Definition: ringbuffer.h:20
virtual ~cRingBuffer()
Definition: ringbuffer.c:39
void EnableGet(void)
Definition: ringbuffer.c:83
void UpdatePercentage(int Fill)
Definition: ringbuffer.c:46
tThreadId getThreadTid
Definition: ringbuffer.h:27
void ReportOverflow(int Bytes)
Definition: ringbuffer.c:101
cIoThrottle * ioThrottle
Definition: ringbuffer.h:25
virtual int Free(void)
Definition: ringbuffer.h:38
int putTimeout
Definition: ringbuffer.h:19
int overflowBytes
Definition: ringbuffer.h:24
virtual void Clear(void)=0
cCondWait readyForGet
Definition: ringbuffer.h:18
virtual int Available(void)=0
cCondWait readyForPut
Definition: ringbuffer.h:18
cUnbufferedFile is used for large files that are mainly written or read in a streaming manner,...
Definition: tools.h:504
eFrameType
Definition: ringbuffer.h:107
@ ftUnknown
Definition: ringbuffer.h:107
@ ftAudio
Definition: ringbuffer.h:107
@ ftDolby
Definition: ringbuffer.h:107
@ ftVideo
Definition: ringbuffer.h:107
pid_t tThreadId
Definition: thread.h:17
unsigned char uchar
Definition: tools.h:31