Home

Dokumentation

Impressum

Dokumentation VDR
 

Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

ringbuffer.h

Go to the documentation of this file.
00001 /*
00002  * ringbuffer.h: A ring buffer
00003  *
00004  * See the main source file 'vdr.c' for copyright information and
00005  * how to reach the author.
00006  *
00007  * $Id: ringbuffer.h 1.7 2002/08/04 10:27:30 kls Exp $
00008  */
00009 
00010 #ifndef __RINGBUFFER_H
00011 #define __RINGBUFFER_H
00012 
00013 #include "thread.h"
00014 #include "tools.h"
00015 
00017 class cRingBuffer {
00018 private:
00019   cMutex mutex;
00020   cCondVar readyForPut, readyForGet;
00021   cMutex putMutex, getMutex;
00022   int size;
00023 protected:
00024   int maxFill;//XXX
00025   int lastPercent;
00026   bool statistics;//XXX
00027   void WaitForPut(void);
00028   void WaitForGet(void);
00029   void EnablePut(void);
00030   void EnableGet(void);
00031   virtual void Clear(void) = 0;
00032   virtual int Available(void) = 0;
00033   int Free(void) { return size - Available() - 1; }
00034   void Lock(void) { mutex.Lock(); }
00035   void Unlock(void) { mutex.Unlock(); }
00036   int Size(void) { return size; }
00037 public:
00038   cRingBuffer(int Size, bool Statistics = false);
00039   virtual ~cRingBuffer();
00040   };
00041 
00043 class cRingBufferLinear : public cRingBuffer {
00044 private:
00045   int head, tail;
00046   uchar *buffer;
00047   pid_t getThreadPid;
00048 public:
00049   cRingBufferLinear(int Size, bool Statistics = false);
00050   virtual ~cRingBufferLinear();
00051   virtual int Available(void);
00052   virtual void Clear(void);
00053     // Immediately clears the ring buffer.
00054   int Put(const uchar *Data, int Count);
00055     // Puts at most Count bytes of Data into the ring buffer.
00056     // Returns the number of bytes actually stored.
00057   int Get(uchar *Data, int Count);
00058     // Gets at most Count bytes of Data from the ring buffer.
00059     // Returns the number of bytes actually retrieved.
00060   };
00061 
00062 enum eFrameType { ftUnknown, ftVideo, ftAudio, ftDolby };
00063 
00065 class cFrame {
00066   friend class cRingBufferFrame;
00067 private:
00068   cFrame *next;
00069   uchar *data;
00070   int count;
00071   eFrameType type;
00072   int index;
00073 public:
00074   cFrame(const uchar *Data, int Count, eFrameType = ftUnknown, int Index = -1);
00075   ~cFrame();
00076   const uchar *Data(void) const { return data; }
00077   int Count(void) const { return count; }
00078   eFrameType Type(void) const { return type; }
00079   int Index(void) const { return index; }
00080   };
00081 
00083 class cRingBufferFrame : public cRingBuffer {
00084 private:
00085   cFrame *head;
00086   int currentFill;
00087   void Delete(const cFrame *Frame);
00088 public:
00089   cRingBufferFrame(int Size, bool Statistics = false);
00090   virtual ~cRingBufferFrame();
00091   virtual int Available(void);
00092 
00096   virtual void Clear(void);
00097 
00102   bool Put(cFrame *Frame);
00103 
00108   const cFrame *Get(void);
00109 
00113   void Drop(const cFrame *Frame);
00114 
00115   };
00116 
00117 #endif // __RINGBUFFER_H
00118 

Generated on Wed Feb 5 23:30:11 2003 for VDR by doxygen1.3-rc2