vdr-plugin-iptv/streamer.c

110 lines
2.8 KiB
C
Raw Normal View History

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 "common.h"
#include "streamer.h"
cIptvStreamer::cIptvStreamer(cIptvDeviceIf &deviceP, unsigned int packetLenP)
2007-09-12 19:28:59 +02:00
: cThread("IPTV streamer"),
sleepM(),
deviceM(&deviceP),
2013-02-23 14:31:11 +01:00
packetBufferLenM(packetLenP),
protocolM(NULL)
2007-09-12 19:28:59 +02:00
{
2013-02-23 16:12:46 +01:00
debug("cIptvStreamer::%s(%d)", __FUNCTION__, 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
error("MALLOC() failed for packet buffer");
2007-09-12 19:28:59 +02:00
}
cIptvStreamer::~cIptvStreamer()
{
2013-02-23 16:12:46 +01:00
debug("cIptvStreamer::%s()", __FUNCTION__);
2007-09-14 17:44:25 +02:00
// Close the protocol
Close();
2013-02-23 14:31:11 +01:00
protocolM = 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
{
2013-02-23 16:12:46 +01:00
debug("cIptvStreamer::%s(): entering", __FUNCTION__);
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;
unsigned int size = min(deviceM->CheckData(), packetBufferLenM);
if (protocolM && (size > 0))
length = protocolM->Read(packetBufferM, size);
2009-02-27 15:05:19 +01:00
if (length > 0) {
2009-02-26 15:04:12 +01:00
AddStreamerStatistic(length);
deviceM->WriteData(packetBufferM, length);
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
}
2013-02-23 16:12:46 +01:00
debug("cIptvStreamer::%s(): exiting", __FUNCTION__);
2007-09-12 19:28:59 +02:00
}
2007-09-14 17:44:25 +02:00
bool cIptvStreamer::Open(void)
{
2013-02-23 16:12:46 +01:00
debug("cIptvStreamer::%s()", __FUNCTION__);
2007-09-14 17:44:25 +02:00
// 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
{
2013-02-23 16:12:46 +01:00
debug("cIptvStreamer::%s()", __FUNCTION__);
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 16:12:46 +01:00
debug("cIptvStreamer::%s(%s, %d, %d)", __FUNCTION__, locationP, parameterP, indexP);
2013-02-23 14:31:11 +01:00
if (!isempty(locationP)) {
// 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();
}
}
2013-02-23 14:31:11 +01:00
else if (protocolM)
protocolM->Set(locationP, parameterP, indexP);
}
2007-09-12 19:28:59 +02:00
return true;
}
2007-10-08 00:54:09 +02:00
cString cIptvStreamer::GetInformation(void)
{
2013-02-23 16:12:46 +01:00
//debug("cIptvStreamer::%s()", __FUNCTION__);
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
}