vdr-plugin-iptv/streamer.c

119 lines
2.9 KiB
C
Raw Permalink 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"
2015-03-08 13:33:18 +01:00
#include "log.h"
2007-09-12 19:28:59 +02:00
#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
{
2015-03-08 13:33:18 +01:00
debug1("%s (, %d)", __PRETTY_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()
{
2015-03-08 13:33:18 +01:00
debug1("%s", __PRETTY_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
{
2015-03-08 13:33:18 +01:00
debug1("%s() Entering", __PRETTY_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
}
2015-03-08 13:33:18 +01:00
debug1("%s Exiting", __PRETTY_FUNCTION__);
2007-09-12 19:28:59 +02:00
}
2007-09-14 17:44:25 +02:00
bool cIptvStreamer::Open(void)
{
2015-03-08 13:33:18 +01:00
debug1("%s", __PRETTY_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
{
2015-03-08 13:33:18 +01:00
debug1("%s", __PRETTY_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;
}
2014-02-09 18:22:02 +01:00
bool cIptvStreamer::SetSource(const char* locationP, const int parameterP, const int indexP, cIptvProtocolIf* protocolP)
2007-09-12 19:28:59 +02:00
{
2015-03-08 13:33:18 +01:00
debug1("%s (%s, %d, %d, )", __PRETTY_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) {
2014-02-09 18:22:02 +01:00
protocolM->SetSource(locationP, parameterP, indexP);
2013-02-23 14:31:11 +01:00
protocolM->Open();
}
}
2013-02-23 14:31:11 +01:00
else if (protocolM)
2014-02-09 18:22:02 +01:00
protocolM->SetSource(locationP, parameterP, indexP);
}
2007-09-12 19:28:59 +02:00
return true;
}
2014-02-09 18:22:02 +01:00
bool cIptvStreamer::SetPid(int pidP, int typeP, bool onP)
{
2015-03-08 13:33:18 +01:00
debug1("%s (%d, %d, %d)", __PRETTY_FUNCTION__, pidP, typeP, onP);
2014-02-09 18:22:02 +01:00
if (protocolM)
return protocolM->SetPid(pidP, typeP, onP);
return true;
}
2007-10-08 00:54:09 +02:00
cString cIptvStreamer::GetInformation(void)
{
2015-03-08 13:33:18 +01:00
debug16("%s", __PRETTY_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
}