1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Re-implemented the WaitForPut/WaitForGet stuff in cRingBuffer, since some plugins actually need this

This commit is contained in:
Klaus Schmidinger 2003-05-12 17:46:34 +02:00
parent 2a7472b00a
commit 1c1fdc5a3f
3 changed files with 64 additions and 3 deletions

View File

@ -2143,7 +2143,10 @@ Video Disk Recorder Revision History
- Changed C++ style comments in libdtv into C style to avoid warnings in gcc 3.x - Changed C++ style comments in libdtv into C style to avoid warnings in gcc 3.x
(thanks to Andreas Schultz). (thanks to Andreas Schultz).
2003-05-11: Version 1.1.32 2003-05-12: Version 1.1.32
- Removed a faulty parameter initialization in menu.c (thanks to Lauri Tischler for - Removed a faulty parameter initialization in menu.c (thanks to Lauri Tischler for
reporting this one). reporting this one).
- Re-implemented the WaitForPut/WaitForGet stuff in cRingBuffer, since some plugins
actually need this. By default the buffer does not wait; if a plugin needs the
waiting functionality it can call the new SetTimeouts() function.

View File

@ -7,7 +7,7 @@
* Parts of this file were inspired by the 'ringbuffy.c' from the * Parts of this file were inspired by the 'ringbuffy.c' from the
* LinuxDVB driver (see linuxtv.org). * LinuxDVB driver (see linuxtv.org).
* *
* $Id: ringbuffer.c 1.16 2003/05/11 09:47:56 kls Exp $ * $Id: ringbuffer.c 1.17 2003/05/12 17:38:11 kls Exp $
*/ */
#include "ringbuffer.h" #include "ringbuffer.h"
@ -23,6 +23,7 @@ cRingBuffer::cRingBuffer(int Size, bool Statistics)
statistics = Statistics; statistics = Statistics;
maxFill = 0; maxFill = 0;
lastPercent = 0; lastPercent = 0;
putTimeout = getTimeout = 0;
} }
cRingBuffer::~cRingBuffer() cRingBuffer::~cRingBuffer()
@ -31,6 +32,42 @@ cRingBuffer::~cRingBuffer()
dsyslog("buffer stats: %d (%d%%) used", maxFill, maxFill * 100 / (size - 1)); dsyslog("buffer stats: %d (%d%%) used", maxFill, maxFill * 100 / (size - 1));
} }
void cRingBuffer::WaitForPut(void)
{
if (putTimeout) {
putMutex.Lock();
readyForPut.TimedWait(putMutex, putTimeout);
putMutex.Unlock();
}
}
void cRingBuffer::WaitForGet(void)
{
if (getTimeout) {
getMutex.Lock();
readyForGet.TimedWait(getMutex, getTimeout);
getMutex.Unlock();
}
}
void cRingBuffer::EnablePut(void)
{
if (putTimeout)
readyForPut.Broadcast();
}
void cRingBuffer::EnableGet(void)
{
if (getTimeout)
readyForGet.Broadcast();
}
void cRingBuffer::SetTimeouts(int PutTimeout, int GetTimeout)
{
putTimeout = PutTimeout;
getTimeout = GetTimeout;
}
// --- cRingBufferLinear ----------------------------------------------------- // --- cRingBufferLinear -----------------------------------------------------
cRingBufferLinear::cRingBufferLinear(int Size, int Margin, bool Statistics) cRingBufferLinear::cRingBufferLinear(int Size, int Margin, bool Statistics)
@ -68,6 +105,8 @@ void cRingBufferLinear::Clear(void)
head = tail = margin; head = tail = margin;
lastGet = -1; lastGet = -1;
Unlock(); Unlock();
EnablePut();
EnableGet();
} }
int cRingBufferLinear::Put(const uchar *Data, int Count) int cRingBufferLinear::Put(const uchar *Data, int Count)
@ -109,6 +148,9 @@ int cRingBufferLinear::Put(const uchar *Data, int Count)
else else
Count = 0; Count = 0;
Unlock(); Unlock();
EnableGet();
if (Count == 0)
WaitForPut();
} }
return Count; return Count;
} }
@ -134,6 +176,8 @@ uchar *cRingBufferLinear::Get(int &Count)
Count = lastGet = cont; Count = lastGet = cont;
} }
Unlock(); Unlock();
if (!p)
WaitForGet();
return p; return p;
} }
@ -146,6 +190,7 @@ void cRingBufferLinear::Del(int Count)
if (tail >= Size()) if (tail >= Size())
tail = margin; tail = margin;
Unlock(); Unlock();
EnablePut();
} }
else else
esyslog("ERROR: invalid Count in cRingBufferLinear::Del: %d", Count); esyslog("ERROR: invalid Count in cRingBufferLinear::Del: %d", Count);
@ -196,6 +241,8 @@ void cRingBufferFrame::Clear(void)
while ((p = Get()) != NULL) while ((p = Get()) != NULL)
Drop(p); Drop(p);
Unlock(); Unlock();
EnablePut();
EnableGet();
} }
bool cRingBufferFrame::Put(cFrame *Frame) bool cRingBufferFrame::Put(cFrame *Frame)
@ -212,6 +259,7 @@ bool cRingBufferFrame::Put(cFrame *Frame)
} }
currentFill += Frame->Count(); currentFill += Frame->Count();
Unlock(); Unlock();
EnableGet();
return true; return true;
} }
return false; return false;
@ -249,6 +297,7 @@ void cRingBufferFrame::Drop(cFrame *Frame)
esyslog("ERROR: attempt to drop wrong frame from ring buffer!"); esyslog("ERROR: attempt to drop wrong frame from ring buffer!");
} }
Unlock(); Unlock();
EnablePut();
} }
int cRingBufferFrame::Available(void) int cRingBufferFrame::Available(void)

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: ringbuffer.h 1.11 2003/05/11 09:48:23 kls Exp $ * $Id: ringbuffer.h 1.12 2003/05/12 17:35:10 kls Exp $
*/ */
#ifndef __RINGBUFFER_H #ifndef __RINGBUFFER_H
@ -16,11 +16,19 @@
class cRingBuffer { class cRingBuffer {
private: private:
cMutex mutex; cMutex mutex;
cCondVar readyForPut, readyForGet;
cMutex putMutex, getMutex;
int putTimeout;
int getTimeout;
int size; int size;
protected: protected:
int maxFill;//XXX int maxFill;//XXX
int lastPercent; int lastPercent;
bool statistics;//XXX bool statistics;//XXX
void WaitForPut(void);
void WaitForGet(void);
void EnablePut(void);
void EnableGet(void);
virtual void Clear(void) = 0; virtual void Clear(void) = 0;
virtual int Available(void) = 0; virtual int Available(void) = 0;
int Free(void) { return size - Available() - 1; } int Free(void) { return size - Available() - 1; }
@ -30,6 +38,7 @@ protected:
public: public:
cRingBuffer(int Size, bool Statistics = false); cRingBuffer(int Size, bool Statistics = false);
virtual ~cRingBuffer(); virtual ~cRingBuffer();
void SetTimeouts(int PutTimeout, int GetTimeout);
}; };
class cRingBufferLinear : public cRingBuffer { class cRingBufferLinear : public cRingBuffer {