vdr/ringbuffer.h
Klaus Schmidinger 527748826c Version 1.1.6
- Re-visited the race condition fix in the cDvbPlayer (thanks again to Andreas
  Schultz).
- Changed the VFAT handling to allow users who normally use it but have forgotten
  to set it when compiling a new version of VDR to at least see their recordings
  made with VFAT enabled (thanks to Christian Rienecker).
- Added some missing teletext PIDs (thanks to Joerg Riechardt).
- Fixed PID handling for cReceiver.
- Added a missing #include to ringbuffer.c (thanks to Martin Hammerschmid).
- Now using CC, CFLAGS, CXX and CXXFLAGS in Makefile.
- Changed the cDevice class to allow plugins to implement their own devices (see
  PLUGINS.html for details).
2002-08-04 18:00:00 +02:00

101 lines
2.6 KiB
C++

/*
* ringbuffer.h: A ring buffer
*
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: ringbuffer.h 1.7 2002/08/04 10:27:30 kls Exp $
*/
#ifndef __RINGBUFFER_H
#define __RINGBUFFER_H
#include "thread.h"
#include "tools.h"
class cRingBuffer {
private:
cMutex mutex;
cCondVar readyForPut, readyForGet;
cMutex putMutex, getMutex;
int size;
protected:
int maxFill;//XXX
int lastPercent;
bool statistics;//XXX
void WaitForPut(void);
void WaitForGet(void);
void EnablePut(void);
void EnableGet(void);
virtual void Clear(void) = 0;
virtual int Available(void) = 0;
int Free(void) { return size - Available() - 1; }
void Lock(void) { mutex.Lock(); }
void Unlock(void) { mutex.Unlock(); }
int Size(void) { return size; }
public:
cRingBuffer(int Size, bool Statistics = false);
virtual ~cRingBuffer();
};
class cRingBufferLinear : public cRingBuffer {
private:
int head, tail;
uchar *buffer;
pid_t getThreadPid;
public:
cRingBufferLinear(int Size, bool Statistics = false);
virtual ~cRingBufferLinear();
virtual int Available(void);
virtual void Clear(void);
// Immediately clears the ring buffer.
int Put(const uchar *Data, int Count);
// Puts at most Count bytes of Data into the ring buffer.
// Returns the number of bytes actually stored.
int Get(uchar *Data, int Count);
// Gets at most Count bytes of Data from the ring buffer.
// Returns the number of bytes actually retrieved.
};
enum eFrameType { ftUnknown, ftVideo, ftAudio, ftDolby };
class cFrame {
friend class cRingBufferFrame;
private:
cFrame *next;
uchar *data;
int count;
eFrameType type;
int index;
public:
cFrame(const uchar *Data, int Count, eFrameType = ftUnknown, int Index = -1);
~cFrame();
const uchar *Data(void) const { return data; }
int Count(void) const { return count; }
eFrameType Type(void) const { return type; }
int Index(void) const { return index; }
};
class cRingBufferFrame : public cRingBuffer {
private:
cFrame *head;
int currentFill;
void Delete(const cFrame *Frame);
public:
cRingBufferFrame(int Size, bool Statistics = false);
virtual ~cRingBufferFrame();
virtual int Available(void);
virtual void Clear(void);
// Immediately clears the ring buffer.
bool Put(cFrame *Frame);
// Puts the Frame into the ring buffer.
// Returns true if this was possible.
const cFrame *Get(void);
// Gets the next frame from the ring buffer.
// The actual data still remains in the buffer until Drop() is called.
void Drop(const cFrame *Frame);
// Drops the Frame that has just been fetched with Get().
};
#endif // __RINGBUFFER_H