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"
|
|
|
|
|
2013-03-27 21:13:15 +01:00
|
|
|
cIptvStreamer::cIptvStreamer(cIptvDeviceIf &deviceP, unsigned int packetLenP)
|
2007-09-12 19:28:59 +02:00
|
|
|
: cThread("IPTV streamer"),
|
2013-02-25 20:08:08 +01:00
|
|
|
sleepM(),
|
2013-03-27 21:13:15 +01:00
|
|
|
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
|
2009-10-01 17:48:28 +02:00
|
|
|
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;
|
2013-03-27 21:13:15 +01:00
|
|
|
unsigned int size = min(deviceM->CheckData(), packetBufferLenM);
|
2013-03-02 00:26:04 +01:00
|
|
|
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);
|
2013-03-27 21:13:15 +01:00
|
|
|
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)
|
2007-09-12 20:33:56 +02:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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)) {
|
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) {
|
2014-02-09 18:22:02 +01:00
|
|
|
protocolM->SetSource(locationP, parameterP, indexP);
|
2013-02-23 14:31:11 +01:00
|
|
|
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)
|
2014-02-09 18:22:02 +01:00
|
|
|
protocolM->SetSource(locationP, parameterP, indexP);
|
2007-09-15 22:33:15 +02:00
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
debug("cIptvStreamer::%s(%d, %d, %d)", __FUNCTION__, pidP, typeP, onP);
|
|
|
|
if (protocolM)
|
|
|
|
return protocolM->SetPid(pidP, typeP, onP);
|
|
|
|
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
|
|
|
}
|