2004-12-30 23:43:55 +01:00
|
|
|
/*
|
2005-02-10 23:24:26 +01:00
|
|
|
* $Id: streamer.c,v 1.6 2005/02/10 22:24:26 lordjaxom Exp $
|
2004-12-30 23:43:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <vdr/ringbuffer.h>
|
|
|
|
#include <vdr/device.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "server/streamer.h"
|
|
|
|
#include "server/suspend.h"
|
|
|
|
#include "server/setup.h"
|
|
|
|
#include "tools/socket.h"
|
|
|
|
#include "common.h"
|
|
|
|
|
2005-02-10 23:24:26 +01:00
|
|
|
// --- cStreamdevWriter -------------------------------------------------------
|
|
|
|
|
2005-02-08 20:54:52 +01:00
|
|
|
cStreamdevWriter::cStreamdevWriter(cTBSocket *Socket, cStreamdevStreamer *Streamer):
|
|
|
|
cThread("streamdev-writer"),
|
|
|
|
m_Streamer(Streamer),
|
|
|
|
m_Socket(Socket),
|
|
|
|
m_Active(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
cStreamdevWriter::~cStreamdevWriter()
|
|
|
|
{
|
|
|
|
m_Active = false;
|
|
|
|
Cancel(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cStreamdevWriter::Action(void)
|
|
|
|
{
|
2005-02-10 23:24:26 +01:00
|
|
|
Dprintf("Writer start\n");
|
2005-02-08 20:54:52 +01:00
|
|
|
int max = 0;
|
|
|
|
m_Active = true;
|
|
|
|
while (m_Active) {
|
|
|
|
int count;
|
|
|
|
uchar *block = m_Streamer->Get(count);
|
|
|
|
|
2005-02-09 20:47:09 +01:00
|
|
|
if (block) {
|
|
|
|
if (!m_Socket->TimedWrite(block, count, 2000)) {
|
|
|
|
esyslog("ERROR: streamdev-server: couldn't send data: %m");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (count > max)
|
|
|
|
max = count;
|
|
|
|
m_Streamer->Del(count);
|
2005-02-08 20:54:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m_Active = false;
|
|
|
|
Dprintf("Max. Transmit Blocksize was: %d\n", max);
|
|
|
|
}
|
2004-12-30 23:43:55 +01:00
|
|
|
|
2005-02-10 23:24:26 +01:00
|
|
|
// --- cStreamdevStreamer -----------------------------------------------------
|
|
|
|
|
2005-02-08 18:22:35 +01:00
|
|
|
cStreamdevStreamer::cStreamdevStreamer(const char *Name):
|
2005-02-08 20:54:52 +01:00
|
|
|
cThread(Name),
|
|
|
|
m_Active(false),
|
|
|
|
m_Writer(NULL),
|
|
|
|
m_RingBuffer(new cRingBufferLinear(STREAMERBUFSIZE, TS_SIZE * 2, true,
|
|
|
|
"streamdev-streamer")),
|
2005-02-10 23:24:26 +01:00
|
|
|
m_SendBuffer(new cRingBufferLinear(WRITERBUFSIZE, TS_SIZE * 2))
|
2004-12-30 23:43:55 +01:00
|
|
|
{
|
2005-02-08 20:54:52 +01:00
|
|
|
m_RingBuffer->SetTimeouts(0, 100);
|
|
|
|
m_SendBuffer->SetTimeouts(0, 100);
|
2004-12-30 23:43:55 +01:00
|
|
|
}
|
|
|
|
|
2005-02-08 20:54:52 +01:00
|
|
|
cStreamdevStreamer::~cStreamdevStreamer()
|
|
|
|
{
|
2004-12-30 23:43:55 +01:00
|
|
|
Stop();
|
|
|
|
delete m_RingBuffer;
|
2005-02-08 20:54:52 +01:00
|
|
|
delete m_Writer;
|
|
|
|
delete m_SendBuffer;
|
2004-12-30 23:43:55 +01:00
|
|
|
}
|
|
|
|
|
2005-02-08 20:54:52 +01:00
|
|
|
void cStreamdevStreamer::Start(cTBSocket *Socket)
|
|
|
|
{
|
2005-02-10 23:24:26 +01:00
|
|
|
Dprintf("start streamer\n");
|
2005-02-08 20:54:52 +01:00
|
|
|
m_Writer = new cStreamdevWriter(Socket, this);
|
2004-12-30 23:43:55 +01:00
|
|
|
Attach();
|
2005-02-08 20:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cStreamdevStreamer::Activate(bool On)
|
|
|
|
{
|
2005-02-10 23:24:26 +01:00
|
|
|
Dprintf("activate streamer\n");
|
2005-02-08 20:54:52 +01:00
|
|
|
if (On && !m_Active) {
|
|
|
|
m_Writer->Start();
|
2004-12-30 23:43:55 +01:00
|
|
|
cThread::Start();
|
2005-02-08 20:54:52 +01:00
|
|
|
}
|
2004-12-30 23:43:55 +01:00
|
|
|
}
|
|
|
|
|
2005-02-08 20:54:52 +01:00
|
|
|
void cStreamdevStreamer::Stop(void)
|
|
|
|
{
|
2004-12-30 23:43:55 +01:00
|
|
|
if (m_Active) {
|
|
|
|
Dprintf("stopping live streamer\n");
|
|
|
|
m_Active = false;
|
|
|
|
Cancel(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-08 20:54:52 +01:00
|
|
|
void cStreamdevStreamer::Action(void)
|
|
|
|
{
|
|
|
|
int max = 0;
|
2004-12-30 23:43:55 +01:00
|
|
|
|
|
|
|
m_Active = true;
|
|
|
|
while (m_Active) {
|
2005-02-08 20:54:52 +01:00
|
|
|
int got;
|
|
|
|
uchar *block = m_RingBuffer->Get(got);
|
|
|
|
|
2005-02-09 20:47:09 +01:00
|
|
|
if (block) {
|
2005-02-08 20:54:52 +01:00
|
|
|
int count = Put(block, got);
|
|
|
|
if (count)
|
|
|
|
m_RingBuffer->Del(count);
|
|
|
|
}
|
2004-12-30 23:43:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|