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
|
|
|
{
|
2010-03-04 16:34:21 +01:00
|
|
|
unsigned int bufsize = (unsigned int)MEGABYTE(IptvConfig.GetTsBufferSize());
|
2009-02-26 15:04:12 +01:00
|
|
|
bufsize -= (bufsize % TS_SIZE);
|
2013-02-23 14:31:11 +01:00
|
|
|
isyslog("creating IPTV device %d (CardIndex=%d)", deviceIndexM, CardIndex());
|
|
|
|
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());
|
|
|
|
}
|
2007-09-21 23:50:52 +02:00
|
|
|
ResetBuffering();
|
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)
|
|
|
|
dsyslog("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()
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cIptvDevice::%s(%d)", __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
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cIptvDevice::%s(%d)", __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)
|
|
|
|
{
|
|
|
|
debug("cIptvDevice::%s()", __FUNCTION__);
|
|
|
|
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;
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cIptvDevice::%s()", __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
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cIptvDevice::%s(%d)", __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)) {
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cIptvDevice::%s(%d): found!", __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
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cIptvDevice::%s(%d)", __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)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
2008-01-19 22:08:02 +01:00
|
|
|
return GetPidStatistic();
|
2007-10-09 01:51:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cString cIptvDevice::GetFiltersInformation(void)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cIptvDevice::%s(%d)", __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
|
|
|
|
{
|
2013-03-27 21:13:15 +01:00
|
|
|
//debug("cIptvDevice::%s(%d)", __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
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cIptvDevice::%s(%d)", __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
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
2011-06-19 21:07:01 +02:00
|
|
|
return (100);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cIptvDevice::SignalQuality(void) const
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cIptvDevice::%s(%d)", __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
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cIptvDevice::%s(%d)", __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
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cIptvDevice::%s(%d)", __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
|
|
|
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cIptvDevice::%s(%d)", __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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cIptvDevice::%s(%d)", __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;
|
|
|
|
if (pIptvStreamerM->Set(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
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cIptvDevice::%s(%d): pid=%d type=%d on=%d", __FUNCTION__, deviceIndexM, 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
|
|
|
{
|
2013-04-01 21:36:41 +02:00
|
|
|
//debug("cIptvDevice::%s(%d): pid=%d tid=%d mask=%d", __FUNCTION__, deviceIndexM, pidP, tidP, maskP);
|
2013-03-27 21:13:15 +01:00
|
|
|
if (pIptvSectionM && IptvConfig.GetSectionFiltering())
|
|
|
|
return pIptvSectionM->Open(pidP, tidP, maskP);
|
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
|
|
|
{
|
2013-04-01 21:36:41 +02:00
|
|
|
//debug("cIptvDevice::%s(%d): handle=%d", __FUNCTION__, deviceIndexM, handleP);
|
2013-03-27 21:13:15 +01:00
|
|
|
if (pIptvSectionM)
|
|
|
|
pIptvSectionM->Close(handleP);
|
2007-09-22 10:17:35 +02:00
|
|
|
}
|
|
|
|
|
2007-09-12 19:28:59 +02:00
|
|
|
bool cIptvDevice::OpenDvr(void)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
2013-02-23 14:31:11 +01:00
|
|
|
isPacketDeliveredM = false;
|
|
|
|
tsBufferM->Clear();
|
2007-09-21 23:50:52 +02:00
|
|
|
ResetBuffering();
|
2013-02-23 14:31:11 +01:00
|
|
|
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)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cIptvDevice::%s(%d)", __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
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cIptvDevice::%s(%d): timeoutMs=%d", __FUNCTION__, deviceIndexM, timeoutMsP);
|
2013-02-23 14:31:11 +01:00
|
|
|
return (!IsBuffering());
|
2007-09-21 23:50:52 +02:00
|
|
|
}
|
|
|
|
|
2012-09-30 17:42:40 +02:00
|
|
|
bool cIptvDevice::HasInternalCam(void)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
2012-09-30 17:42:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-09-21 23:50:52 +02:00
|
|
|
void cIptvDevice::ResetBuffering(void)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
2013-02-25 20:08:08 +01:00
|
|
|
// Pad prefill to multiple of TS_SIZE
|
2013-02-23 14:31:11 +01:00
|
|
|
tsBufferPrefillM = (unsigned int)MEGABYTE(IptvConfig.GetTsBufferSize()) *
|
2007-09-21 23:50:52 +02:00
|
|
|
IptvConfig.GetTsBufferPrefillRatio() / 100;
|
2013-02-23 14:31:11 +01:00
|
|
|
tsBufferPrefillM -= (tsBufferPrefillM % TS_SIZE);
|
2007-09-21 23:50:52 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
bool cIptvDevice::IsBuffering(void) const
|
2007-09-21 23:50:52 +02:00
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
2013-02-23 14:31:11 +01:00
|
|
|
if (tsBufferPrefillM && tsBufferM && tsBufferM->Available() < tsBufferPrefillM)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
tsBufferPrefillM = 0;
|
|
|
|
return false;
|
2007-09-21 00:01:42 +02:00
|
|
|
}
|
|
|
|
|
2013-03-27 21:13:15 +01:00
|
|
|
void cIptvDevice::WriteData(uchar *bufferP, int lengthP)
|
|
|
|
{
|
|
|
|
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
|
|
|
if (tsBufferM)
|
|
|
|
return (unsigned int)tsBufferM->Free();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-12 19:28:59 +02:00
|
|
|
bool cIptvDevice::GetTSPacket(uchar *&Data)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
2014-01-14 17:30:14 +01:00
|
|
|
if (isOpenDvrM && tsBufferM && !IsBuffering()) {
|
2013-02-23 14:31:11 +01:00
|
|
|
if (isPacketDeliveredM) {
|
|
|
|
tsBufferM->Del(TS_SIZE);
|
|
|
|
isPacketDeliveredM = false;
|
2007-10-10 00:12:17 +02:00
|
|
|
// Update buffer statistics
|
2013-02-23 14:31:11 +01:00
|
|
|
AddBufferStatistic(TS_SIZE, tsBufferM->Available());
|
2007-09-12 19:28:59 +02:00
|
|
|
}
|
2011-06-15 16:49:15 +02:00
|
|
|
int Count = 0;
|
2013-02-23 14:31:11 +01:00
|
|
|
uchar *p = tsBufferM->Get(Count);
|
2007-09-21 23:50:52 +02:00
|
|
|
if (p && Count >= TS_SIZE) {
|
|
|
|
if (*p != TS_SYNC_BYTE) {
|
|
|
|
for (int i = 1; i < Count; i++) {
|
|
|
|
if (p[i] == TS_SYNC_BYTE) {
|
|
|
|
Count = i;
|
|
|
|
break;
|
2007-09-19 20:02:38 +02:00
|
|
|
}
|
2007-09-21 23:50:52 +02:00
|
|
|
}
|
2013-02-23 14:31:11 +01:00
|
|
|
tsBufferM->Del(Count);
|
2013-03-27 21:13:15 +01:00
|
|
|
error("Skipped %d bytes to sync on TS packet", Count);
|
2007-09-21 23:50:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-02-23 14:31:11 +01:00
|
|
|
isPacketDeliveredM = true;
|
2007-09-21 23:50:52 +02:00
|
|
|
Data = p;
|
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));
|
2007-09-21 23:50:52 +02:00
|
|
|
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);
|
2007-09-12 19:28:59 +02:00
|
|
|
Data = NULL;
|
|
|
|
return true;
|
|
|
|
}
|