2004-12-30 23:43:55 +01:00
|
|
|
/*
|
2010-12-02 09:57:17 +01:00
|
|
|
* $Id: streamer.h,v 1.12 2010/07/19 13:49:32 schmirl Exp $
|
2004-12-30 23:43:55 +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;
|
2005-02-08 20:54:52 +01:00
|
|
|
class cStreamdevStreamer;
|
2010-12-02 09:57:17 +01:00
|
|
|
class cServerConnection;
|
2005-02-08 20:54:52 +01:00
|
|
|
|
2009-02-13 11:39:20 +01:00
|
|
|
#ifndef TS_SIZE
|
|
|
|
#define TS_SIZE 188
|
|
|
|
#endif
|
|
|
|
|
2009-06-19 08:32:38 +02:00
|
|
|
#define STREAMERBUFSIZE (20000 * TS_SIZE)
|
2011-09-02 13:18:01 +02:00
|
|
|
#define WRITERBUFSIZE (20000 * TS_SIZE)
|
2009-06-19 08:32:38 +02:00
|
|
|
|
|
|
|
// --- 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;
|
|
|
|
}
|
2005-02-08 20:54:52 +01:00
|
|
|
|
2005-02-10 23:24:26 +01:00
|
|
|
// --- cStreamdevWriter -------------------------------------------------------
|
|
|
|
|
2005-02-08 20:54:52 +01:00
|
|
|
class cStreamdevWriter: public cThread {
|
|
|
|
private:
|
|
|
|
cStreamdevStreamer *m_Streamer;
|
|
|
|
cTBSocket *m_Socket;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void Action(void);
|
|
|
|
|
|
|
|
public:
|
|
|
|
cStreamdevWriter(cTBSocket *Socket, cStreamdevStreamer *Streamer);
|
|
|
|
virtual ~cStreamdevWriter();
|
|
|
|
};
|
2004-12-30 23:43:55 +01:00
|
|
|
|
2005-02-10 23:24:26 +01:00
|
|
|
// --- cStreamdevStreamer -----------------------------------------------------
|
|
|
|
|
2004-12-30 23:43:55 +01:00
|
|
|
class cStreamdevStreamer: public cThread {
|
|
|
|
private:
|
2010-12-02 09:57:17 +01:00
|
|
|
const cServerConnection *m_Connection;
|
2005-02-08 20:54:52 +01:00
|
|
|
cStreamdevWriter *m_Writer;
|
2009-06-19 08:32:38 +02:00
|
|
|
cStreamdevBuffer *m_RingBuffer;
|
|
|
|
cStreamdevBuffer *m_SendBuffer;
|
2004-12-30 23:43:55 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void Action(void);
|
|
|
|
|
2009-06-19 08:32:38 +02:00
|
|
|
bool IsRunning(void) const { return m_Writer; }
|
2005-02-11 18:02:22 +01:00
|
|
|
|
2004-12-30 23:43:55 +01:00
|
|
|
public:
|
2010-12-02 09:57:17 +01:00
|
|
|
cStreamdevStreamer(const char *Name, const cServerConnection *Connection = NULL);
|
2004-12-30 23:43:55 +01:00
|
|
|
virtual ~cStreamdevStreamer();
|
|
|
|
|
2010-12-02 09:57:17 +01:00
|
|
|
const cServerConnection* Connection(void) const { return m_Connection; }
|
|
|
|
|
2004-12-30 23:43:55 +01:00
|
|
|
virtual void Start(cTBSocket *Socket);
|
|
|
|
virtual void Stop(void);
|
2008-10-22 13:59:31 +02:00
|
|
|
bool Abort(void);
|
2004-12-30 23:43:55 +01:00
|
|
|
|
2005-02-08 20:54:52 +01:00
|
|
|
void Activate(bool On);
|
2009-06-19 08:32:38 +02:00
|
|
|
int Receive(uchar *Data, int Length) { return m_RingBuffer->PutTS(Data, Length); }
|
2005-02-08 14:59:16 +01:00
|
|
|
void ReportOverflow(int Bytes) { m_RingBuffer->ReportOverflow(Bytes); }
|
2005-02-08 20:54:52 +01:00
|
|
|
|
2009-06-19 08:32:38 +02:00
|
|
|
virtual int Put(const uchar *Data, int Count) { return m_SendBuffer->PutTS(Data, Count); }
|
2005-02-10 23:24:26 +01:00
|
|
|
virtual uchar *Get(int &Count) { return m_SendBuffer->Get(Count); }
|
|
|
|
virtual void Del(int Count) { m_SendBuffer->Del(Count); }
|
2004-12-30 23:43:55 +01:00
|
|
|
|
2005-03-12 13:54:19 +01:00
|
|
|
virtual void Detach(void) {}
|
|
|
|
virtual void Attach(void) {}
|
2004-12-30 23:43:55 +01:00
|
|
|
};
|
|
|
|
|
2008-10-22 13:59:31 +02:00
|
|
|
inline bool cStreamdevStreamer::Abort(void)
|
2007-04-02 12:32:34 +02:00
|
|
|
{
|
2008-10-22 13:59:31 +02:00
|
|
|
return Active() && !m_Writer->Active();
|
2007-04-02 12:32:34 +02:00
|
|
|
}
|
|
|
|
|
2004-12-30 23:43:55 +01:00
|
|
|
#endif // VDR_STREAMDEV_STREAMER_H
|
|
|
|
|