2010-12-02 08:53:01 +01:00
|
|
|
/*
|
2010-12-02 09:44:53 +01:00
|
|
|
* $Id: streamer.h,v 1.11 2009/06/19 06:32:45 schmirl Exp $
|
2010-12-02 08:53:01 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef VDR_STREAMDEV_STREAMER_H
|
|
|
|
#define VDR_STREAMDEV_STREAMER_H
|
|
|
|
|
|
|
|
#include <vdr/thread.h>
|
|
|
|
#include <vdr/ringbuffer.h>
|
|
|
|
#include <vdr/tools.h>
|
|
|
|
|
|
|
|
class cTBSocket;
|
|
|
|
class cStreamdevStreamer;
|
|
|
|
|
2010-12-02 09:43:13 +01:00
|
|
|
#ifndef TS_SIZE
|
|
|
|
#define TS_SIZE 188
|
|
|
|
#endif
|
|
|
|
|
2010-12-02 09:44:53 +01:00
|
|
|
#define STREAMERBUFSIZE (20000 * TS_SIZE)
|
|
|
|
#define WRITERBUFSIZE (5000 * TS_SIZE)
|
|
|
|
|
|
|
|
// --- cStreamdevBuffer -------------------------------------------------------
|
|
|
|
|
|
|
|
class cStreamdevBuffer: public cRingBufferLinear {
|
|
|
|
public:
|
|
|
|
// make public
|
|
|
|
void WaitForPut(void) { cRingBuffer::WaitForPut(); }
|
|
|
|
// Always write complete TS packets
|
|
|
|
// (assumes Count is a multiple of TS_SIZE)
|
|
|
|
int PutTS(const uchar *Data, int Count);
|
|
|
|
cStreamdevBuffer(int Size, int Margin = 0, bool Statistics = false, const char *Description = NULL);
|
|
|
|
};
|
|
|
|
|
|
|
|
inline int cStreamdevBuffer::PutTS(const uchar *Data, int Count)
|
|
|
|
{
|
|
|
|
int free = Free();
|
|
|
|
if (free < Count)
|
|
|
|
Count = free;
|
|
|
|
|
|
|
|
Count -= Count % TS_SIZE;
|
|
|
|
if (Count)
|
|
|
|
Count = Put(Data, Count);
|
|
|
|
else
|
|
|
|
WaitForPut();
|
|
|
|
return Count;
|
|
|
|
}
|
2010-12-02 08:53:01 +01:00
|
|
|
|
|
|
|
// --- cStreamdevWriter -------------------------------------------------------
|
|
|
|
|
|
|
|
class cStreamdevWriter: public cThread {
|
|
|
|
private:
|
|
|
|
cStreamdevStreamer *m_Streamer;
|
|
|
|
cTBSocket *m_Socket;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void Action(void);
|
|
|
|
|
|
|
|
public:
|
|
|
|
cStreamdevWriter(cTBSocket *Socket, cStreamdevStreamer *Streamer);
|
|
|
|
virtual ~cStreamdevWriter();
|
|
|
|
};
|
|
|
|
|
|
|
|
// --- cStreamdevStreamer -----------------------------------------------------
|
|
|
|
|
|
|
|
class cStreamdevStreamer: public cThread {
|
|
|
|
private:
|
|
|
|
cStreamdevWriter *m_Writer;
|
2010-12-02 09:44:53 +01:00
|
|
|
cStreamdevBuffer *m_RingBuffer;
|
|
|
|
cStreamdevBuffer *m_SendBuffer;
|
2010-12-02 08:53:01 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void Action(void);
|
|
|
|
|
2010-12-02 09:44:53 +01:00
|
|
|
bool IsRunning(void) const { return m_Writer; }
|
2010-12-02 08:53:01 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
cStreamdevStreamer(const char *Name);
|
|
|
|
virtual ~cStreamdevStreamer();
|
|
|
|
|
|
|
|
virtual void Start(cTBSocket *Socket);
|
|
|
|
virtual void Stop(void);
|
2010-12-02 09:43:13 +01:00
|
|
|
bool Abort(void);
|
2010-12-02 08:53:01 +01:00
|
|
|
|
|
|
|
void Activate(bool On);
|
2010-12-02 09:44:53 +01:00
|
|
|
int Receive(uchar *Data, int Length) { return m_RingBuffer->PutTS(Data, Length); }
|
2010-12-02 08:53:01 +01:00
|
|
|
void ReportOverflow(int Bytes) { m_RingBuffer->ReportOverflow(Bytes); }
|
|
|
|
|
2010-12-02 09:44:53 +01:00
|
|
|
virtual int Put(const uchar *Data, int Count) { return m_SendBuffer->PutTS(Data, Count); }
|
2010-12-02 08:53:01 +01:00
|
|
|
virtual uchar *Get(int &Count) { return m_SendBuffer->Get(Count); }
|
|
|
|
virtual void Del(int Count) { m_SendBuffer->Del(Count); }
|
|
|
|
|
|
|
|
virtual void Detach(void) {}
|
|
|
|
virtual void Attach(void) {}
|
|
|
|
};
|
|
|
|
|
2010-12-02 09:43:13 +01:00
|
|
|
inline bool cStreamdevStreamer::Abort(void)
|
2010-12-02 08:56:19 +01:00
|
|
|
{
|
2010-12-02 09:43:13 +01:00
|
|
|
return Active() && !m_Writer->Active();
|
2010-12-02 08:56:19 +01:00
|
|
|
}
|
|
|
|
|
2010-12-02 08:53:01 +01:00
|
|
|
#endif // VDR_STREAMDEV_STREAMER_H
|
|
|
|
|