2007-09-12 19:28:59 +02:00
|
|
|
/*
|
|
|
|
* streamer.c: IPTV plugin for the Video Disk Recorder
|
|
|
|
*
|
|
|
|
* See the README file for copyright information and how to reach the author.
|
|
|
|
*
|
2007-09-29 18:21:04 +02:00
|
|
|
* $Id: streamer.c,v 1.16 2007/09/29 16:21:05 rahrenbe Exp $
|
2007-09-12 19:28:59 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <vdr/thread.h>
|
|
|
|
#include <vdr/ringbuffer.h>
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "streamer.h"
|
|
|
|
|
2007-09-14 17:44:25 +02:00
|
|
|
cIptvStreamer::cIptvStreamer(cRingBufferLinear* RingBuffer, cMutex* Mutex)
|
2007-09-12 19:28:59 +02:00
|
|
|
: cThread("IPTV streamer"),
|
2007-09-14 17:44:25 +02:00
|
|
|
ringBuffer(RingBuffer),
|
2007-09-12 19:28:59 +02:00
|
|
|
mutex(Mutex),
|
2007-09-14 17:44:25 +02:00
|
|
|
protocol(NULL)
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
|
|
|
debug("cIptvStreamer::cIptvStreamer()\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
cIptvStreamer::~cIptvStreamer()
|
|
|
|
{
|
|
|
|
debug("cIptvStreamer::~cIptvStreamer()\n");
|
2007-09-14 17:44:25 +02:00
|
|
|
// Close the protocol
|
|
|
|
Close();
|
2007-09-12 19:28:59 +02:00
|
|
|
}
|
|
|
|
|
2007-09-13 18:58:22 +02:00
|
|
|
void cIptvStreamer::Action(void)
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
|
|
|
debug("cIptvStreamer::Action(): Entering\n");
|
2007-09-13 18:58:22 +02:00
|
|
|
// Do the thread loop
|
2007-09-12 19:28:59 +02:00
|
|
|
while (Running()) {
|
2007-09-21 23:50:52 +02:00
|
|
|
if (ringBuffer && mutex && protocol && ringBuffer->Free()) {
|
2007-09-15 22:33:15 +02:00
|
|
|
unsigned char *buffer = NULL;
|
2007-09-15 23:27:00 +02:00
|
|
|
int length = protocol->Read(&buffer);
|
2007-09-14 17:44:25 +02:00
|
|
|
if (length >= 0) {
|
2007-09-13 18:58:22 +02:00
|
|
|
mutex->Lock();
|
2007-09-15 22:33:15 +02:00
|
|
|
int p = ringBuffer->Put(buffer, length);
|
2007-09-13 18:58:22 +02:00
|
|
|
if (p != length && Running())
|
2007-09-14 17:44:25 +02:00
|
|
|
ringBuffer->ReportOverflow(length - p);
|
2007-09-13 18:58:22 +02:00
|
|
|
mutex->Unlock();
|
2007-09-14 17:44:25 +02:00
|
|
|
}
|
|
|
|
else
|
2007-09-15 22:33:15 +02:00
|
|
|
cCondWait::SleepMs(100); // to reduce cpu load
|
2007-09-13 18:58:22 +02:00
|
|
|
}
|
|
|
|
else
|
2007-09-15 22:33:15 +02:00
|
|
|
cCondWait::SleepMs(100); // and avoid busy loop
|
2007-09-12 19:28:59 +02:00
|
|
|
}
|
|
|
|
debug("cIptvStreamer::Action(): Exiting\n");
|
|
|
|
}
|
|
|
|
|
2007-09-14 17:44:25 +02:00
|
|
|
bool cIptvStreamer::Open(void)
|
2007-09-12 20:33:56 +02:00
|
|
|
{
|
2007-09-14 17:44:25 +02:00
|
|
|
debug("cIptvStreamer::Open()\n");
|
|
|
|
// Open the protocol
|
|
|
|
if (protocol)
|
2007-09-29 13:17:57 +02:00
|
|
|
if(!protocol->Open())
|
|
|
|
return false;
|
2007-09-13 18:58:22 +02:00
|
|
|
// Start thread
|
|
|
|
Start();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-09-14 17:44:25 +02:00
|
|
|
bool cIptvStreamer::Close(void)
|
2007-09-13 18:58:22 +02:00
|
|
|
{
|
2007-09-14 17:44:25 +02:00
|
|
|
debug("cIptvStreamer::Close()\n");
|
2007-09-13 18:58:22 +02:00
|
|
|
// Stop thread
|
|
|
|
if (Running())
|
|
|
|
Cancel(3);
|
2007-09-14 17:44:25 +02:00
|
|
|
// Close the protocol
|
|
|
|
if (protocol)
|
|
|
|
protocol->Close();
|
2007-09-12 19:28:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-09-14 17:44:25 +02:00
|
|
|
bool cIptvStreamer::Set(const char* Address, const int Port, cIptvProtocolIf* Protocol)
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
2007-09-14 17:44:25 +02:00
|
|
|
debug("cIptvStreamer::Set(): %s:%d\n", Address, Port);
|
|
|
|
if (!isempty(Address)) {
|
2007-09-15 22:33:15 +02:00
|
|
|
// Update protocol; Close the existing one if changed
|
|
|
|
if (protocol != Protocol) {
|
|
|
|
if (protocol)
|
|
|
|
protocol->Close();
|
|
|
|
protocol = Protocol;
|
|
|
|
if (protocol)
|
|
|
|
protocol->Open();
|
|
|
|
}
|
|
|
|
// Set protocol address and port
|
|
|
|
if (protocol)
|
2007-09-14 17:44:25 +02:00
|
|
|
protocol->Set(Address, Port);
|
2007-09-15 22:33:15 +02:00
|
|
|
}
|
2007-09-12 19:28:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|