2007-09-12 19:28:59 +02:00
|
|
|
/*
|
|
|
|
* device.c: IPTV plugin for the Video Disk Recorder
|
|
|
|
*
|
|
|
|
* See the README file for copyright information and how to reach the author.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-09-15 17:38:38 +02:00
|
|
|
#include "config.h"
|
2010-03-04 16:34:21 +01:00
|
|
|
#include "source.h"
|
2007-09-12 19:28:59 +02:00
|
|
|
#include "device.h"
|
|
|
|
|
2009-02-24 12:40:16 +01:00
|
|
|
#define IPTV_MAX_DEVICES MAXDEVICES
|
2007-09-12 19:28:59 +02:00
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
static cIptvDevice * IptvDevicesS[IPTV_MAX_DEVICES] = { NULL };
|
2007-09-12 19:28:59 +02:00
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
cIptvDevice::cIptvDevice(unsigned int indexP)
|
|
|
|
: deviceIndexM(indexP),
|
|
|
|
dvrFdM(-1),
|
|
|
|
isPacketDeliveredM(false),
|
|
|
|
isOpenDvrM(false),
|
|
|
|
sidScanEnabledM(false),
|
|
|
|
pidScanEnabledM(false),
|
2014-01-10 22:59:26 +01:00
|
|
|
channelM()
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
2014-04-05 18:01:36 +02:00
|
|
|
unsigned int bufsize = (unsigned int)IPTV_BUFFER_SIZE;
|
2009-02-26 15:04:12 +01:00
|
|
|
bufsize -= (bufsize % TS_SIZE);
|
2015-03-08 13:33:18 +01:00
|
|
|
info("Creating IPTV device %d (CardIndex=%d)", deviceIndexM, CardIndex());
|
2013-02-23 14:31:11 +01:00
|
|
|
tsBufferM = new cRingBufferLinear(bufsize + 1, TS_SIZE, false,
|
2013-03-27 21:13:15 +01:00
|
|
|
*cString::sprintf("IPTV TS %d", deviceIndexM));
|
|
|
|
if (tsBufferM) {
|
|
|
|
tsBufferM->SetTimeouts(100, 100);
|
|
|
|
tsBufferM->SetIoThrottle();
|
|
|
|
pIptvStreamerM = new cIptvStreamer(*this, tsBufferM->Free());
|
|
|
|
}
|
2013-02-23 14:31:11 +01:00
|
|
|
pUdpProtocolM = new cIptvProtocolUdp();
|
|
|
|
pCurlProtocolM = new cIptvProtocolCurl();
|
|
|
|
pHttpProtocolM = new cIptvProtocolHttp();
|
|
|
|
pFileProtocolM = new cIptvProtocolFile();
|
|
|
|
pExtProtocolM = new cIptvProtocolExt();
|
|
|
|
pPidScannerM = new cPidScanner();
|
2007-10-01 20:14:57 +02:00
|
|
|
// Start section handler for iptv device
|
2013-03-27 21:13:15 +01:00
|
|
|
pIptvSectionM = new cIptvSectionFilterHandler(deviceIndexM, bufsize + 1);
|
2007-09-20 23:15:08 +02:00
|
|
|
StartSectionHandler();
|
2007-10-01 20:14:57 +02:00
|
|
|
// Sid scanner must be created after the section handler
|
2013-02-25 23:34:45 +01:00
|
|
|
AttachFilter(pSidScannerM = new cSidScanner());
|
2008-02-17 20:18:47 +01:00
|
|
|
// Check if dvr fifo exists
|
|
|
|
struct stat sb;
|
2013-02-23 14:31:11 +01:00
|
|
|
cString filename = cString::sprintf(IPTV_DVR_FILENAME, deviceIndexM);
|
2008-02-17 20:18:47 +01:00
|
|
|
stat(filename, &sb);
|
|
|
|
if (S_ISFIFO(sb.st_mode)) {
|
2013-02-23 14:31:11 +01:00
|
|
|
dvrFdM = open(filename, O_RDWR | O_NONBLOCK);
|
|
|
|
if (dvrFdM >= 0)
|
2015-03-08 13:33:18 +01:00
|
|
|
info("IPTV device %d redirecting input stream to '%s'", deviceIndexM, *filename);
|
2008-02-17 20:18:47 +01:00
|
|
|
}
|
2007-09-12 19:28:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cIptvDevice::~cIptvDevice()
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2013-02-25 23:34:45 +01:00
|
|
|
// Stop section handler of iptv device
|
|
|
|
StopSectionHandler();
|
2013-03-27 21:13:15 +01:00
|
|
|
DELETE_POINTER(pIptvSectionM);
|
2014-01-07 13:38:12 +01:00
|
|
|
DELETE_POINTER(pSidScannerM);
|
|
|
|
DELETE_POINTER(pPidScannerM);
|
|
|
|
DELETE_POINTER(pIptvStreamerM);
|
|
|
|
DELETE_POINTER(pExtProtocolM);
|
|
|
|
DELETE_POINTER(pFileProtocolM);
|
|
|
|
DELETE_POINTER(pHttpProtocolM);
|
|
|
|
DELETE_POINTER(pCurlProtocolM);
|
|
|
|
DELETE_POINTER(pUdpProtocolM);
|
|
|
|
DELETE_POINTER(tsBufferM);
|
2008-02-17 20:18:47 +01:00
|
|
|
// Close dvr fifo
|
2013-02-23 14:31:11 +01:00
|
|
|
if (dvrFdM >= 0) {
|
|
|
|
int fd = dvrFdM;
|
|
|
|
dvrFdM = -1;
|
2008-02-17 20:18:47 +01:00
|
|
|
close(fd);
|
|
|
|
}
|
2007-09-12 19:28:59 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
bool cIptvDevice::Initialize(unsigned int deviceCountP)
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s (%u)", __PRETTY_FUNCTION__, deviceCountP);
|
2010-03-04 16:34:21 +01:00
|
|
|
new cIptvSourceParam(IPTV_SOURCE_CHARACTER, "IPTV");
|
2013-02-23 14:31:11 +01:00
|
|
|
if (deviceCountP > IPTV_MAX_DEVICES)
|
|
|
|
deviceCountP = IPTV_MAX_DEVICES;
|
|
|
|
for (unsigned int i = 0; i < deviceCountP; ++i)
|
|
|
|
IptvDevicesS[i] = new cIptvDevice(i);
|
|
|
|
for (unsigned int i = deviceCountP; i < IPTV_MAX_DEVICES; ++i)
|
|
|
|
IptvDevicesS[i] = NULL;
|
2007-09-12 19:28:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-14 17:30:14 +01:00
|
|
|
void cIptvDevice::Shutdown(void)
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s", __PRETTY_FUNCTION__);
|
2014-01-14 17:30:14 +01:00
|
|
|
for (int i = 0; i < IPTV_MAX_DEVICES; ++i) {
|
|
|
|
if (IptvDevicesS[i])
|
|
|
|
IptvDevicesS[i]->CloseDvr();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-12 19:28:59 +02:00
|
|
|
unsigned int cIptvDevice::Count(void)
|
|
|
|
{
|
|
|
|
unsigned int count = 0;
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s", __PRETTY_FUNCTION__);
|
2007-09-12 19:28:59 +02:00
|
|
|
for (unsigned int i = 0; i < IPTV_MAX_DEVICES; ++i) {
|
2013-02-23 14:31:11 +01:00
|
|
|
if (IptvDevicesS[i] != NULL)
|
2007-09-12 19:28:59 +02:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
cIptvDevice *cIptvDevice::GetIptvDevice(int cardIndexP)
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s (%d)", __PRETTY_FUNCTION__, cardIndexP);
|
2007-10-06 22:57:53 +02:00
|
|
|
for (unsigned int i = 0; i < IPTV_MAX_DEVICES; ++i) {
|
2014-01-14 17:30:14 +01:00
|
|
|
if (IptvDevicesS[i] && (IptvDevicesS[i]->CardIndex() == cardIndexP)) {
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s (%d) Found", __PRETTY_FUNCTION__, cardIndexP);
|
2013-02-23 14:31:11 +01:00
|
|
|
return IptvDevicesS[i];
|
2007-10-06 22:57:53 +02:00
|
|
|
}
|
|
|
|
}
|
2007-09-12 19:28:59 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-10-09 01:51:58 +02:00
|
|
|
cString cIptvDevice::GetGeneralInformation(void)
|
2007-10-06 22:57:53 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2012-04-01 21:46:08 +02:00
|
|
|
return cString::sprintf("IPTV device: %d\nCardIndex: %d\nStream: %s\nStream bitrate: %s\n%sChannel: %s",
|
2013-02-23 14:31:11 +01:00
|
|
|
deviceIndexM, CardIndex(),
|
|
|
|
pIptvStreamerM ? *pIptvStreamerM->GetInformation() : "",
|
|
|
|
pIptvStreamerM ? *pIptvStreamerM->GetStreamerStatistic() : "",
|
2008-01-19 22:08:02 +01:00
|
|
|
*GetBufferStatistic(),
|
2007-10-12 01:06:49 +02:00
|
|
|
*Channels.GetByNumber(cDevice::CurrentChannel())->ToText());
|
2007-10-09 01:51:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cString cIptvDevice::GetPidsInformation(void)
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2008-01-19 22:08:02 +01:00
|
|
|
return GetPidStatistic();
|
2007-10-09 01:51:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cString cIptvDevice::GetFiltersInformation(void)
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2013-03-27 21:13:15 +01:00
|
|
|
return cString::sprintf("Active section filters:\n%s", pIptvSectionM ? *pIptvSectionM->GetInformation() : "");
|
2007-10-09 01:51:58 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
cString cIptvDevice::GetInformation(unsigned int pageP)
|
2007-10-09 01:51:58 +02:00
|
|
|
{
|
2007-10-08 00:54:09 +02:00
|
|
|
// generate information string
|
2013-02-23 01:03:27 +01:00
|
|
|
cString s;
|
2013-02-23 14:31:11 +01:00
|
|
|
switch (pageP) {
|
2007-10-09 01:51:58 +02:00
|
|
|
case IPTV_DEVICE_INFO_GENERAL:
|
2013-02-23 01:03:27 +01:00
|
|
|
s = GetGeneralInformation();
|
2007-10-09 01:51:58 +02:00
|
|
|
break;
|
|
|
|
case IPTV_DEVICE_INFO_PIDS:
|
2013-02-23 01:03:27 +01:00
|
|
|
s = GetPidsInformation();
|
2007-10-09 01:51:58 +02:00
|
|
|
break;
|
|
|
|
case IPTV_DEVICE_INFO_FILTERS:
|
2013-02-23 01:03:27 +01:00
|
|
|
s = GetFiltersInformation();
|
2007-10-09 01:51:58 +02:00
|
|
|
break;
|
2012-04-01 21:46:08 +02:00
|
|
|
case IPTV_DEVICE_INFO_PROTOCOL:
|
2013-02-23 14:31:11 +01:00
|
|
|
s = pIptvStreamerM ? *pIptvStreamerM->GetInformation() : "";
|
2012-04-01 21:46:08 +02:00
|
|
|
break;
|
|
|
|
case IPTV_DEVICE_INFO_BITRATE:
|
2013-02-23 14:31:11 +01:00
|
|
|
s = pIptvStreamerM ? *pIptvStreamerM->GetStreamerStatistic() : "";
|
2012-04-01 21:46:08 +02:00
|
|
|
break;
|
2007-10-09 01:51:58 +02:00
|
|
|
default:
|
2013-02-23 01:03:27 +01:00
|
|
|
s = cString::sprintf("%s%s%s",
|
|
|
|
*GetGeneralInformation(),
|
|
|
|
*GetPidsInformation(),
|
|
|
|
*GetFiltersInformation());
|
2007-10-09 01:51:58 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-02-23 01:03:27 +01:00
|
|
|
return s;
|
2007-10-06 22:57:53 +02:00
|
|
|
}
|
|
|
|
|
2012-04-02 18:15:53 +02:00
|
|
|
cString cIptvDevice::DeviceType(void) const
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2012-04-02 18:15:53 +02:00
|
|
|
return "IPTV";
|
|
|
|
}
|
|
|
|
|
2012-03-25 15:42:06 +02:00
|
|
|
cString cIptvDevice::DeviceName(void) const
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2013-02-23 14:31:11 +01:00
|
|
|
return cString::sprintf("IPTV %d", deviceIndexM);
|
2012-03-25 15:42:06 +02:00
|
|
|
}
|
|
|
|
|
2011-06-19 21:07:01 +02:00
|
|
|
int cIptvDevice::SignalStrength(void) const
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2011-06-19 21:07:01 +02:00
|
|
|
return (100);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cIptvDevice::SignalQuality(void) const
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2011-06-19 21:07:01 +02:00
|
|
|
return (100);
|
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
bool cIptvDevice::ProvidesSource(int sourceP) const
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2013-02-23 14:31:11 +01:00
|
|
|
return (cSource::IsType(sourceP, IPTV_SOURCE_CHARACTER));
|
2007-09-12 19:28:59 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
bool cIptvDevice::ProvidesTransponder(const cChannel *channelP) const
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2013-02-23 14:31:11 +01:00
|
|
|
return (ProvidesSource(channelP->Source()));
|
2007-09-12 19:28:59 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
bool cIptvDevice::ProvidesChannel(const cChannel *channelP, int priorityP, bool *needsDetachReceiversP) const
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
|
|
|
bool result = false;
|
2013-02-23 14:31:11 +01:00
|
|
|
bool hasPriority = (priorityP == IDLEPRIORITY) || (priorityP > this->Priority());
|
2012-06-02 14:37:05 +02:00
|
|
|
bool needsDetachReceivers = false;
|
2007-09-12 19:28:59 +02:00
|
|
|
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2012-06-02 14:37:05 +02:00
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
if (channelP && ProvidesTransponder(channelP)) {
|
2012-06-02 14:37:05 +02:00
|
|
|
result = hasPriority;
|
|
|
|
if (Receiving()) {
|
2014-01-10 22:59:26 +01:00
|
|
|
if (channelP->GetChannelID() == channelM.GetChannelID())
|
2012-06-02 14:37:05 +02:00
|
|
|
result = true;
|
|
|
|
else
|
|
|
|
needsDetachReceivers = Receiving();
|
|
|
|
}
|
|
|
|
}
|
2013-02-23 14:31:11 +01:00
|
|
|
if (needsDetachReceiversP)
|
|
|
|
*needsDetachReceiversP = needsDetachReceivers;
|
2007-09-12 19:28:59 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-09-04 16:58:18 +02:00
|
|
|
bool cIptvDevice::ProvidesEIT(void) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-01-28 22:36:32 +01:00
|
|
|
int cIptvDevice::NumProvidedSystems(void) const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-01-10 22:59:26 +01:00
|
|
|
const cChannel *cIptvDevice::GetCurrentlyTunedTransponder(void) const
|
|
|
|
{
|
|
|
|
return &channelM;
|
|
|
|
}
|
|
|
|
|
2014-01-07 12:16:13 +01:00
|
|
|
bool cIptvDevice::IsTunedToTransponder(const cChannel *channelP) const
|
|
|
|
{
|
2014-01-10 22:59:26 +01:00
|
|
|
return channelP ? (channelP->GetChannelID() == channelM.GetChannelID()) : false;
|
2014-01-07 12:16:13 +01:00
|
|
|
}
|
|
|
|
|
2014-01-14 17:40:54 +01:00
|
|
|
bool cIptvDevice::MaySwitchTransponder(const cChannel *channelP) const
|
|
|
|
{
|
|
|
|
return cDevice::MaySwitchTransponder(channelP);
|
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
bool cIptvDevice::SetChannelDevice(const cChannel *channelP, bool liveViewP)
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
2007-09-14 17:44:25 +02:00
|
|
|
cIptvProtocolIf *protocol;
|
2013-02-23 14:31:11 +01:00
|
|
|
cIptvTransponderParameters itp(channelP->Parameters());
|
2007-09-12 19:28:59 +02:00
|
|
|
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2011-06-15 16:49:15 +02:00
|
|
|
|
2010-03-04 16:34:21 +01:00
|
|
|
if (isempty(itp.Address())) {
|
2013-02-23 14:31:11 +01:00
|
|
|
error("Unrecognized IPTV address: %s", channelP->Parameters());
|
2007-09-14 23:36:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
2010-03-04 16:34:21 +01:00
|
|
|
switch (itp.Protocol()) {
|
|
|
|
case cIptvTransponderParameters::eProtocolUDP:
|
2013-02-23 14:31:11 +01:00
|
|
|
protocol = pUdpProtocolM;
|
2010-03-04 16:34:21 +01:00
|
|
|
break;
|
2013-02-23 01:03:27 +01:00
|
|
|
case cIptvTransponderParameters::eProtocolCURL:
|
2013-02-23 14:31:11 +01:00
|
|
|
protocol = pCurlProtocolM;
|
2013-02-23 01:03:27 +01:00
|
|
|
break;
|
2010-03-04 16:34:21 +01:00
|
|
|
case cIptvTransponderParameters::eProtocolHTTP:
|
2013-02-23 14:31:11 +01:00
|
|
|
protocol = pHttpProtocolM;
|
2010-03-04 16:34:21 +01:00
|
|
|
break;
|
|
|
|
case cIptvTransponderParameters::eProtocolFILE:
|
2013-02-23 14:31:11 +01:00
|
|
|
protocol = pFileProtocolM;
|
2010-03-04 16:34:21 +01:00
|
|
|
break;
|
|
|
|
case cIptvTransponderParameters::eProtocolEXT:
|
2013-02-23 14:31:11 +01:00
|
|
|
protocol = pExtProtocolM;
|
2010-03-04 16:34:21 +01:00
|
|
|
break;
|
|
|
|
default:
|
2013-02-23 14:31:11 +01:00
|
|
|
error("Unrecognized IPTV protocol: %s", channelP->Parameters());
|
2010-03-04 16:34:21 +01:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
2013-02-23 14:31:11 +01:00
|
|
|
sidScanEnabledM = itp.SidScan() ? true : false;
|
|
|
|
pidScanEnabledM = itp.PidScan() ? true : false;
|
2014-02-09 18:22:02 +01:00
|
|
|
if (pIptvStreamerM && pIptvStreamerM->SetSource(itp.Address(), itp.Parameter(), deviceIndexM, protocol)) {
|
2014-01-10 22:59:26 +01:00
|
|
|
channelM = *channelP;
|
2013-02-23 14:31:11 +01:00
|
|
|
if (sidScanEnabledM && pSidScannerM && IptvConfig.GetSectionFiltering())
|
2014-01-10 22:59:26 +01:00
|
|
|
pSidScannerM->SetChannel(channelM.GetChannelID());
|
2013-02-23 14:31:11 +01:00
|
|
|
if (pidScanEnabledM && pPidScannerM)
|
2014-01-10 22:59:26 +01:00
|
|
|
pPidScannerM->SetChannel(channelM.GetChannelID());
|
2008-04-02 22:22:48 +02:00
|
|
|
}
|
2007-09-12 19:28:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
bool cIptvDevice::SetPid(cPidHandle *handleP, int typeP, bool onP)
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s (%d, %d, %d) [device %d]", __PRETTY_FUNCTION__, handleP ? handleP->pid : -1, typeP, onP, deviceIndexM);
|
2014-02-09 18:22:02 +01:00
|
|
|
if (pIptvStreamerM && handleP)
|
|
|
|
return pIptvStreamerM->SetPid(handleP->pid, typeP, onP);
|
2007-09-12 19:28:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
int cIptvDevice::OpenFilter(u_short pidP, u_char tidP, u_char maskP)
|
2007-09-14 18:10:44 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s (%d, %d, %d) [device %d]", __PRETTY_FUNCTION__, pidP, tidP, maskP, deviceIndexM);
|
2014-02-09 18:22:02 +01:00
|
|
|
if (pIptvSectionM && IptvConfig.GetSectionFiltering()) {
|
|
|
|
if (pIptvStreamerM)
|
|
|
|
pIptvStreamerM->SetPid(pidP, ptOther, true);
|
2013-03-27 21:13:15 +01:00
|
|
|
return pIptvSectionM->Open(pidP, tidP, maskP);
|
2014-02-09 18:22:02 +01:00
|
|
|
}
|
2007-09-19 17:14:32 +02:00
|
|
|
return -1;
|
2007-09-14 18:10:44 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
void cIptvDevice::CloseFilter(int handleP)
|
2007-09-22 10:17:35 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s (%d) [device %d]", __PRETTY_FUNCTION__, handleP, deviceIndexM);
|
2014-02-09 18:22:02 +01:00
|
|
|
if (pIptvSectionM) {
|
|
|
|
if (pIptvStreamerM)
|
|
|
|
pIptvStreamerM->SetPid(pIptvSectionM->GetPid(handleP), ptOther, false);
|
2013-03-27 21:13:15 +01:00
|
|
|
pIptvSectionM->Close(handleP);
|
2014-02-09 18:22:02 +01:00
|
|
|
}
|
2007-09-22 10:17:35 +02:00
|
|
|
}
|
|
|
|
|
2007-09-12 19:28:59 +02:00
|
|
|
bool cIptvDevice::OpenDvr(void)
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2013-02-23 14:31:11 +01:00
|
|
|
isPacketDeliveredM = false;
|
|
|
|
tsBufferM->Clear();
|
|
|
|
if (pIptvStreamerM)
|
|
|
|
pIptvStreamerM->Open();
|
|
|
|
if (sidScanEnabledM && pSidScannerM && IptvConfig.GetSectionFiltering())
|
|
|
|
pSidScannerM->Open();
|
2014-01-14 17:30:14 +01:00
|
|
|
if (pidScanEnabledM && pPidScannerM)
|
|
|
|
pPidScannerM->Open();
|
2013-02-23 14:31:11 +01:00
|
|
|
isOpenDvrM = true;
|
2007-09-12 19:28:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cIptvDevice::CloseDvr(void)
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2014-01-14 17:30:14 +01:00
|
|
|
if (pidScanEnabledM && pPidScannerM)
|
|
|
|
pPidScannerM->Close();
|
2014-01-07 12:17:30 +01:00
|
|
|
if (sidScanEnabledM && pSidScannerM)
|
2013-02-23 14:31:11 +01:00
|
|
|
pSidScannerM->Close();
|
|
|
|
if (pIptvStreamerM)
|
|
|
|
pIptvStreamerM->Close();
|
|
|
|
isOpenDvrM = false;
|
2007-09-12 19:28:59 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
bool cIptvDevice::HasLock(int timeoutMsP) const
|
2007-09-21 00:01:42 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s (%d) [device %d]", __PRETTY_FUNCTION__, timeoutMsP, deviceIndexM);
|
2014-04-05 18:01:36 +02:00
|
|
|
return (pIptvStreamerM && pIptvStreamerM->Active());
|
2007-09-21 23:50:52 +02:00
|
|
|
}
|
|
|
|
|
2012-09-30 17:42:40 +02:00
|
|
|
bool cIptvDevice::HasInternalCam(void)
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2014-02-06 23:16:37 +01:00
|
|
|
return false;
|
2012-09-30 17:42:40 +02:00
|
|
|
}
|
|
|
|
|
2013-03-27 21:13:15 +01:00
|
|
|
void cIptvDevice::WriteData(uchar *bufferP, int lengthP)
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s (, %d) [device %d]", __PRETTY_FUNCTION__, lengthP, deviceIndexM);
|
2013-03-27 21:13:15 +01:00
|
|
|
int len;
|
|
|
|
// Send data to dvr fifo
|
|
|
|
if (dvrFdM >= 0)
|
|
|
|
len = write(dvrFdM, bufferP, lengthP);
|
|
|
|
// Fill up TS buffer
|
|
|
|
if (tsBufferM) {
|
|
|
|
len = tsBufferM->Put(bufferP, lengthP);
|
|
|
|
if (len != lengthP)
|
|
|
|
tsBufferM->ReportOverflow(lengthP - len);
|
|
|
|
}
|
|
|
|
// Filter the sections
|
|
|
|
if (pIptvSectionM && IptvConfig.GetSectionFiltering())
|
|
|
|
pIptvSectionM->Write(bufferP, lengthP);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int cIptvDevice::CheckData(void)
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2013-03-27 21:13:15 +01:00
|
|
|
if (tsBufferM)
|
|
|
|
return (unsigned int)tsBufferM->Free();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-28 16:10:11 +01:00
|
|
|
uchar *cIptvDevice::GetData(int *availableP)
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2014-04-05 18:01:36 +02:00
|
|
|
if (isOpenDvrM && tsBufferM) {
|
2014-01-28 16:10:11 +01:00
|
|
|
int count = 0;
|
|
|
|
if (isPacketDeliveredM)
|
|
|
|
SkipData(TS_SIZE);
|
|
|
|
uchar *p = tsBufferM->Get(count);
|
|
|
|
if (p && count >= TS_SIZE) {
|
2007-09-21 23:50:52 +02:00
|
|
|
if (*p != TS_SYNC_BYTE) {
|
2014-01-28 16:10:11 +01:00
|
|
|
for (int i = 1; i < count; i++) {
|
2007-09-21 23:50:52 +02:00
|
|
|
if (p[i] == TS_SYNC_BYTE) {
|
2014-01-28 16:10:11 +01:00
|
|
|
count = i;
|
2007-09-21 23:50:52 +02:00
|
|
|
break;
|
2007-09-19 20:02:38 +02:00
|
|
|
}
|
2007-09-21 23:50:52 +02:00
|
|
|
}
|
2014-01-28 16:10:11 +01:00
|
|
|
tsBufferM->Del(count);
|
2014-04-05 18:01:36 +02:00
|
|
|
info("Skipped %d bytes to sync on TS packet", count);
|
2014-01-28 16:10:11 +01:00
|
|
|
return NULL;
|
2007-09-21 23:50:52 +02:00
|
|
|
}
|
2013-02-23 14:31:11 +01:00
|
|
|
isPacketDeliveredM = true;
|
2014-01-28 16:10:11 +01:00
|
|
|
if (availableP)
|
|
|
|
*availableP = count;
|
2009-02-24 12:40:16 +01:00
|
|
|
// Update pid statistics
|
2008-01-30 23:41:58 +01:00
|
|
|
AddPidStatistic(ts_pid(p), payload(p));
|
2014-01-28 16:10:11 +01:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cIptvDevice::SkipData(int countP)
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s (%d) [device %d]]", __PRETTY_FUNCTION__, countP, deviceIndexM);
|
2014-01-28 16:10:11 +01:00
|
|
|
tsBufferM->Del(countP);
|
|
|
|
isPacketDeliveredM = false;
|
|
|
|
// Update buffer statistics
|
|
|
|
AddBufferStatistic(countP, tsBufferM->Available());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cIptvDevice::GetTSPacket(uchar *&dataP)
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, deviceIndexM);
|
2014-01-28 16:10:11 +01:00
|
|
|
if (tsBufferM) {
|
|
|
|
if (cCamSlot *cs = CamSlot()) {
|
|
|
|
if (cs->WantsTsData()) {
|
|
|
|
int available;
|
|
|
|
dataP = GetData(&available);
|
|
|
|
if (dataP) {
|
|
|
|
dataP = cs->Decrypt(dataP, available);
|
|
|
|
SkipData(available);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2007-09-21 23:50:52 +02:00
|
|
|
}
|
2014-01-28 16:10:11 +01:00
|
|
|
dataP = GetData();
|
|
|
|
return true;
|
2007-09-12 19:28:59 +02:00
|
|
|
}
|
2007-10-27 01:48:30 +02:00
|
|
|
// Reduce cpu load by preventing busylooping
|
2009-02-26 15:04:12 +01:00
|
|
|
cCondWait::SleepMs(10);
|
2014-01-28 16:10:11 +01:00
|
|
|
dataP = NULL;
|
2007-09-12 19:28:59 +02:00
|
|
|
return true;
|
|
|
|
}
|