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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <vdr/thread.h>
|
|
|
|
#include <vdr/ringbuffer.h>
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "streamer.h"
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
cIptvStreamer::cIptvStreamer(cRingBufferLinear* ringBufferP, unsigned int packetLenP)
|
2007-09-12 19:28:59 +02:00
|
|
|
: cThread("IPTV streamer"),
|
2013-02-23 14:31:11 +01:00
|
|
|
ringBufferM(ringBufferP),
|
|
|
|
packetBufferLenM(packetLenP),
|
|
|
|
protocolM(NULL)
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
2013-02-23 14:31:11 +01:00
|
|
|
debug("cIptvStreamer::cIptvStreamer(%d)\n", packetBufferLenM);
|
2009-02-26 15:04:12 +01:00
|
|
|
// Allocate packet buffer
|
2013-02-23 14:31:11 +01:00
|
|
|
packetBufferM = MALLOC(unsigned char, packetBufferLenM);
|
|
|
|
if (packetBufferM)
|
|
|
|
memset(packetBufferM, 0, packetBufferLenM);
|
2009-02-26 15:04:12 +01:00
|
|
|
else
|
2009-10-01 17:48:28 +02:00
|
|
|
error("MALLOC() failed for packet buffer");
|
2007-09-12 19:28:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cIptvStreamer::~cIptvStreamer()
|
|
|
|
{
|
|
|
|
debug("cIptvStreamer::~cIptvStreamer()\n");
|
2007-09-14 17:44:25 +02:00
|
|
|
// Close the protocol
|
|
|
|
Close();
|
2013-02-23 14:31:11 +01:00
|
|
|
protocolM = NULL;
|
|
|
|
ringBufferM = NULL;
|
2009-02-26 15:04:12 +01:00
|
|
|
// Free allocated memory
|
2013-02-23 14:31:11 +01:00
|
|
|
free(packetBufferM);
|
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");
|
2009-02-26 15:04:12 +01:00
|
|
|
// Increase priority
|
|
|
|
//SetPriority(-1);
|
2007-09-13 18:58:22 +02:00
|
|
|
// Do the thread loop
|
2013-02-23 14:31:11 +01:00
|
|
|
while (packetBufferM && Running()) {
|
2009-02-26 15:04:12 +01:00
|
|
|
int length = -1;
|
2013-02-23 14:31:11 +01:00
|
|
|
if (protocolM)
|
|
|
|
length = protocolM->Read(packetBufferM, min((unsigned int)ringBufferM->Free(), packetBufferLenM));
|
2009-02-27 15:05:19 +01:00
|
|
|
if (length > 0) {
|
2009-02-26 15:04:12 +01:00
|
|
|
AddStreamerStatistic(length);
|
2013-02-23 14:31:11 +01:00
|
|
|
if (ringBufferM) {
|
|
|
|
int p = ringBufferM->Put(packetBufferM, length);
|
2009-02-26 15:04:12 +01:00
|
|
|
if (p != length)
|
2013-02-23 14:31:11 +01:00
|
|
|
ringBufferM->ReportOverflow(length - p);
|
2009-02-26 15:04:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2013-02-23 14:31:11 +01:00
|
|
|
sleepM.Wait(10); // to avoid busy loop and reduce cpu load
|
2009-02-26 15:04:12 +01:00
|
|
|
}
|
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
|
2013-02-23 14:31:11 +01:00
|
|
|
if (protocolM && !protocolM->Open())
|
2008-01-30 22:57:33 +01:00
|
|
|
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
|
2013-02-23 14:31:11 +01:00
|
|
|
sleepM.Signal();
|
2007-09-13 18:58:22 +02:00
|
|
|
if (Running())
|
|
|
|
Cancel(3);
|
2009-02-26 15:04:12 +01:00
|
|
|
// Close the protocol
|
2013-02-23 14:31:11 +01:00
|
|
|
if (protocolM)
|
|
|
|
protocolM->Close();
|
2007-09-12 19:28:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
bool cIptvStreamer::Set(const char* locationP, const int parameterP, const int indexP, cIptvProtocolIf* protocolP)
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
2013-02-23 14:31:11 +01:00
|
|
|
debug("cIptvStreamer::Set('%s', %d, %d)\n", locationP, parameterP, indexP);
|
|
|
|
if (!isempty(locationP)) {
|
2009-05-22 09:50:20 +02:00
|
|
|
// Update protocol and set location and parameter; Close the existing one if changed
|
2013-02-23 14:31:11 +01:00
|
|
|
if (protocolM != protocolP) {
|
|
|
|
if (protocolM)
|
|
|
|
protocolM->Close();
|
|
|
|
protocolM = protocolP;
|
|
|
|
if (protocolM) {
|
|
|
|
protocolM->Set(locationP, parameterP, indexP);
|
|
|
|
protocolM->Open();
|
2009-05-22 09:50:20 +02:00
|
|
|
}
|
2007-09-15 22:33:15 +02:00
|
|
|
}
|
2013-02-23 14:31:11 +01:00
|
|
|
else if (protocolM)
|
|
|
|
protocolM->Set(locationP, parameterP, indexP);
|
2007-09-15 22:33:15 +02:00
|
|
|
}
|
2007-09-12 19:28:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-10-08 00:54:09 +02:00
|
|
|
cString cIptvStreamer::GetInformation(void)
|
|
|
|
{
|
|
|
|
//debug("cIptvStreamer::GetInformation()");
|
2013-02-23 14:31:11 +01:00
|
|
|
cString s;
|
|
|
|
if (protocolM)
|
|
|
|
s = protocolM->GetInformation();
|
|
|
|
return s;
|
2007-10-08 00:54:09 +02:00
|
|
|
}
|