1
0
mirror of https://github.com/rofafor/vdr-plugin-iptv.git synced 2023-10-10 11:37:03 +00:00

Compare commits

..

34 Commits

Author SHA1 Message Date
Rolf Ahrenberg
aaca7cba1a Fixed installation target bugs (Thanks to Alexander Grothe). 2014-03-09 16:04:54 +02:00
Rolf Ahrenberg
935f659e34 Added missing RTSP/UDP support. 2014-02-19 23:17:20 +02:00
Rolf Ahrenberg
9839b47229 Added SetPid() into cIptvProtocolIf(). 2014-02-09 19:22:02 +02:00
Rolf Ahrenberg
57e0af0ade Disabled missing internal cam. 2014-02-07 00:16:37 +02:00
Rolf Ahrenberg
0900e229cf Added initial CAM support. 2014-01-28 17:10:11 +02:00
Rolf Ahrenberg
3dcbff0a71 Updated translation files and version number. 2014-01-19 00:20:08 +02:00
Rolf Ahrenberg
5aefd40d65 Updated translation files and HISTORY. 2014-01-14 18:42:06 +02:00
Rolf Ahrenberg
6b0337d078 Added initial support for cDevice::MaySwitchTransponder(). 2014-01-14 18:40:54 +02:00
Rolf Ahrenberg
9e6d784aec Shutdown devices already in cPluginManager::Stop(). 2014-01-14 18:30:14 +02:00
Rolf Ahrenberg
3f3ba2ad1a Fixed a typo. 2014-01-11 00:35:12 +02:00
Rolf Ahrenberg
a4b9570ae6 Updated copyright headers. 2014-01-11 00:24:31 +02:00
Rolf Ahrenberg
767b1bdac7 Added support for cDevice::GetCurrentlyTunedTransponder(). 2014-01-10 23:59:26 +02:00
Rolf Ahrenberg
6f648401a4 Updated translation files and HISTORY. 2014-01-10 23:22:15 +02:00
Rolf Ahrenberg
b0995c9a9e Added support for cDevice::IsTunedToTransponder(). 2014-01-07 22:24:39 +02:00
Rolf Ahrenberg
412af81271 Fixed a mem leak and re-ordered pointer deletions. 2014-01-07 17:55:13 +02:00
Rolf Ahrenberg
43326bb4ea Whitespace cleanup. 2014-01-07 17:55:08 +02:00
Rolf Ahrenberg
555c08bd4d Updated Makefile. 2014-01-06 22:01:55 +02:00
Rolf Ahrenberg
5ad3103626 Fixed scan-build issues. 2014-01-02 21:47:43 +02:00
Rolf Ahrenberg
a4f0bdf737 Added missing CURL timeouts and improved section id scanner. 2014-01-02 21:35:38 +02:00
Rolf Ahrenberg
01b554a2de Updated README. 2013-04-01 23:11:38 +03:00
Rolf Ahrenberg
225b0cc297 Updated for vdr-2.0.0. 2013-04-01 22:36:41 +03:00
Rolf Ahrenberg
d940e616e3 Fixed and refactored the section filtering code, fixed a possible crash in the file protocol, and updated Makefile's install target. 2013-03-27 22:13:15 +02:00
Rolf Ahrenberg
f30817677e Fixed a nasty network byte order bug. 2013-03-17 01:18:58 +02:00
Rolf Ahrenberg
0c6257e4ca Added SetMenuCategory(mcSetupPlugins). 2013-03-13 23:33:37 +02:00
Rolf Ahrenberg
0caf746ef4 Enabled I/O throttling and tweaked buffer timeouts and tweaked max address string size to include a termination NULL byte. 2013-03-11 18:04:27 +02:00
Rolf Ahrenberg
41fe387018 Updated translation files. 2013-03-06 09:54:06 +02:00
Rolf Ahrenberg
2c287ef667 Updated HISTORY. 2013-03-06 09:50:43 +02:00
Rolf Ahrenberg
d7dfa0aad6 Fixed the channel editor and added extra locking into the CURL protocol. 2013-03-02 19:58:37 +02:00
Rolf Ahrenberg
72a9f21006 Changed a pointer to a reference in order to stabilize the CURL protocol and always remember to close the sid scanner. 2013-03-02 01:26:04 +02:00
Rolf Ahrenberg
d84fd79d14 Reverted the CURL locking changes and updated some word wrapping. 2013-03-01 12:22:41 +02:00
Rolf Ahrenberg
f632650547 Added case-insensitive comparisions and fixed data types of a few CURL options. 2013-02-28 22:07:14 +02:00
Rolf Ahrenberg
980aafb206 Modified the filter code. 2013-02-26 00:34:45 +02:00
Rolf Ahrenberg
45192e924a Fixed URL decoding and section filter protection. 2013-02-25 23:11:41 +02:00
Rolf Ahrenberg
e4657c1820 Fixed bugs found in the CURL implementation (Thanks to Jeremy Hall). 2013-02-25 21:08:08 +02:00
43 changed files with 1032 additions and 537 deletions

50
HISTORY
View File

@@ -193,3 +193,53 @@ VDR Plugin 'iptv' Revision History
- Updated for vdr-1.7.38.
- Added a new CURL protocol for HTTP/HTTPS.
2013-03-06: Version 1.2.1
- Fixed bugs found in the CURL implementation (Thanks
to Jeremy Hall).
- Fixed the channel editor.
==================================
VDR Plugin 'iptv' Revision History
==================================
2013-04-01: Version 2.0.0
- Updated for vdr-2.0.0.
- Enabled I/O throttling and tweaked buffer timeouts.
- Fixed a nasty network byte order bug.
- Fixed and refactored the section filtering code.
- Fixed a possible crash in the file protocol.
2014-01-10: Version 2.0.1
- Added missing CURL timeouts.
- Improved section id scanner.
- Added support for cDevice::IsTunedToTransponder() and
cDevice::GetCurrentlyTunedTransponder().
- Fixed a memory leak and some issues reported by scan-build.
2014-01-18: Version 2.0.2
- Made devices to shutdown already in cPluginManager::Stop()
to prevent possible crashes while VDR shutdown.
2014-03-09: Version 2.0.3
- Fixed installation target bugs (Thanks to Alexander Grothe).
==================================
VDR Plugin 'iptv' Revision History
==================================
2014-02-20: Version 2.1.0
- Added initial CAM support.
- Added missing RTSP/UDP support.
2014-03-09: Version 2.1.1
- Fixed installation target bugs (Thanks to Alexander Grothe).

View File

@@ -28,10 +28,12 @@ GITTAG = $(shell git describe --always 2>/dev/null)
### The directory environment:
# Use package data if installed...otherwise assume we're under the VDR source directory:
PKGCFG = $(if $(VDRDIR),$(shell pkg-config --variable=$(1) $(VDRDIR)/vdr.pc),$(shell pkg-config --variable=$(1) vdr || pkg-config --variable=$(1) ../../../vdr.pc))
PKGCFG = $(if $(VDRDIR),$(shell pkg-config --variable=$(1) $(VDRDIR)/vdr.pc),$(shell PKG_CONFIG_PATH="$$PKG_CONFIG_PATH:../../.." pkg-config --variable=$(1) vdr))
LIBDIR = $(call PKGCFG,libdir)
LOCDIR = $(call PKGCFG,locdir)
PLGCFG = $(call PKGCFG,plgcfg)
RESDIR = $(call PKGCFG,resdir)
CFGDIR = $(call PKGCFG,configdir)
#
TMPDIR ?= /tmp
@@ -144,7 +146,12 @@ endif
install-lib: $(SOFILE)
install -D $^ $(DESTDIR)$(LIBDIR)/$^.$(APIVERSION)
install: install-lib install-i18n
install-conf:
@mkdir -p $(DESTDIR)$(CFGDIR)/plugins/$(PLUGIN)
@mkdir -p $(DESTDIR)$(RESDIR)/plugins/$(PLUGIN)
@cp -pn $(PLUGIN)/* $(DESTDIR)$(RESDIR)/plugins/$(PLUGIN)/
install: install-lib install-i18n install-conf
dist: $(I18Npo) clean
@-rm -rf $(TMPDIR)/$(ARCHIVE)

50
README
View File

@@ -41,14 +41,8 @@ MP3 radio streams, mms video streams and so on.
Installation:
cd /put/your/path/here/VDR/PLUGINS/src
tar -xzf /put/your/path/here/vdr-iptv-X.Y.Z.tgz
ln -s iptv-X.Y.Z iptv
cd /put/your/path/here/VDR
cp -R PLUGINS/src/iptv/iptv /path/to/vdrresource/plugins/
make
make plugins
./vdr -P iptv
make -C iptv-X.Y.Z install
Setup menu:
@@ -59,10 +53,12 @@ Setup menu:
stream ringbuffer before data is
transferred to VDR.
Valid range: 0...40
- EXT protocol base port = 4321 Defines base port used in EXT protocol.
- Protocol base port = 4321 Defines base port used in CURL/EXT
protocol. Two ports are defined for
each device.
The port range is defined by the number
of IPTV devices (max. 8).
Valid range: 0...65527
of IPTV devices times two (max. 32).
Valid range: 0...65503
- Use section filtering = 1 Defines whether section filtering shall
be used.
Valid range: 0...1
@@ -89,11 +85,11 @@ Configuration:
- channels.conf
TV4;IPTV:40:S=1|P=0|F=EXT|U=iptvstream.sh|A=0:I:0:0:680:0:0:4:0:0:0
TV3;IPTV:30:S=0|P=1|F=FILE|U=/video/stream.ts|A=5:I:0:514:670:2321:0:3:0:0:0
TV2;IPTV:20:S=0|P=1|F=HTTP|U=127.0.0.1/TS/2|A=3000:I:0:513:660:2321:0:2:0:0:0
TV1;IPTV:10:S=1|P=0|F=CURL|U=http%3A//foo%3Abar@127.0.0.1%3A3000/TS/2|A=0:I:0:512:650:2321:0:1:0:0:0
TV1;IPTV:10:S=1|P=0|F=UDP|U=127.0.0.1@127.0.0.1|A=1234:I:0:512:650:2321:0:1:0:0:0
TV6;IPTV:60:S=1|P=0|F=EXT|U=iptvstream.sh|A=0:I:0:0:680:0:0:6:0:0:0
TV5;IPTV:50:S=0|P=1|F=FILE|U=/video/stream.ts|A=5:I:0:514:670:2321:0:5:0:0:0
TV4;IPTV:40:S=0|P=1|F=HTTP|U=127.0.0.1/TS/2|A=3000:I:0:513:660:2321:0:4:0:0:0
TV3;IPTV:30:S=1|P=0|F=CURL|U=http%3A//foo%3Abar@127.0.0.1%3A3000/TS/2|A=0:I:0:512:650:2321:0:3:0:0:0
TV2;IPTV:20:S=1|P=0|F=UDP|U=127.0.0.1@127.0.0.1|A=1234:I:0:512:650:2321:0:2:0:0:0
TV1;IPTV:10:S=1|P=0|F=UDP|U=127.0.0.1|A=1234:I:0:512:650:2321:0:1:0:0:0
^ ^ ^ ^ ^ ^ ^
| | | | | | Source type ("I")
@@ -133,11 +129,11 @@ External streaming:
script parameter is passed to the script and it can be used to select for
example between different URLs.
- When an EXT channel is opened the IPTV plugin opens an UDP listening port
on the localhost. The external script is responsible for supplying IPTV
plugin with MPEG2 TS data in UDP/RTP format to the listening port. The
data will be processed in VDR like a normal DVB broadcast. The listening
base port can be specified in the plugin configuration menu.
- When an EXT or CURL/RTSP channel is opened the IPTV plugin opens an UDP
listening port on the localhost. The external script is responsible for
supplying IPTV plugin with MPEG2 TS data in UDP/RTP format to the listening
port. The data will be processed in VDR like a normal DVB broadcast. The
listening base port can be specified in the plugin configuration menu.
- Each IPTV device has different listen port. The port number is specified
as a base port number plus IPTV device index minus one. Maximum of 8 IPTV
@@ -171,8 +167,7 @@ Notes:
"disable_ca_updates" patch to the VDR in order to get rid of "Channel not
available" messages.
- EIT scanning functionality can be disabled for all IPTV channels by applying
the "disable_eitscan" patch to the VDR.
- EIT scanning functionality is disabled by default.
- Section id and pid scanners should be disabled after the correct data is
found. This can be made via VDR's channel editor.
@@ -182,11 +177,16 @@ Notes:
IGMP v3 protocol:
"U=<source address>@<group address>"
- The CURL implementation supports only HTTP/HTTPS protocols and an optional
netrc configuration file for authentication:
- The CURL implementation supports only RTSP/HTTP/HTTPS protocols and an
optional netrc configuration file for authentication:
$(CONFDIR)/iptv/netrc
- CURL implementation
- You can quite easily figure out correct DVB triplet values by using the
multicat and dvbsnoop tools:
$ multicat -u -d 1620000000 @127.0.0.1:1234 /tmp/video.ts
$ dvbsnoop -s ts -if /tmp/video.ts -tssubdecode -hexdumpbuffer 0x12 | \
grep -m1 -A8 Service_ID | grep _ID
Acknowledgements:
- The IPTV section filtering code is derived from Linux kernel.

View File

@@ -5,44 +5,45 @@
*
*/
#include <ctype.h>
#include <vdr/tools.h>
#include "common.h"
uint16_t ts_pid(const uint8_t *buf)
uint16_t ts_pid(const uint8_t *bufP)
{
return (uint16_t)(((buf[1] & 0x1f) << 8) + buf[2]);
return (uint16_t)(((bufP[1] & 0x1f) << 8) + bufP[2]);
}
uint8_t payload(const uint8_t *tsp)
uint8_t payload(const uint8_t *bufP)
{
if (!(tsp[3] & 0x10)) // no payload?
if (!(bufP[3] & 0x10)) // no payload?
return 0;
if (tsp[3] & 0x20) { // adaptation field?
if (tsp[4] > 183) // corrupted data?
if (bufP[3] & 0x20) { // adaptation field?
if (bufP[4] > 183) // corrupted data?
return 0;
else
return (uint8_t)((184 - 1) - tsp[4]);
return (uint8_t)((184 - 1) - bufP[4]);
}
return 184;
}
const char *id_pid(const u_short Pid)
const char *id_pid(const u_short pidP)
{
for (int i = 0; i < SECTION_FILTER_TABLE_SIZE; ++i) {
if (Pid == section_filter_table[i].pid)
if (pidP == section_filter_table[i].pid)
return section_filter_table[i].tag;
}
return "---";
}
int select_single_desc(int descriptor, const int usecs, const bool selectWrite)
int select_single_desc(int descriptorP, const int usecsP, const bool selectWriteP)
{
// Wait for data
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = usecs;
tv.tv_usec = usecsP;
// Use select
fd_set infd;
fd_set outfd;
@@ -50,17 +51,28 @@ int select_single_desc(int descriptor, const int usecs, const bool selectWrite)
FD_ZERO(&infd);
FD_ZERO(&outfd);
FD_ZERO(&errfd);
FD_SET(descriptor, &errfd);
if (selectWrite)
FD_SET(descriptor, &outfd);
FD_SET(descriptorP, &errfd);
if (selectWriteP)
FD_SET(descriptorP, &outfd);
else
FD_SET(descriptor, &infd);
int retval = select(descriptor + 1, &infd, &outfd, &errfd, &tv);
FD_SET(descriptorP, &infd);
int retval = select(descriptorP + 1, &infd, &outfd, &errfd, &tv);
// Check if error
ERROR_IF_RET(retval < 0, "select()", return retval);
return retval;
}
cString ChangeCase(const cString &strP, bool upperP)
{
cString res(strP);
char *p = (char *)*res;
while (p && *p) {
*p = upperP ? toupper(*p) : tolower(*p);
++p;
}
return res;
}
const section_filter_table_type section_filter_table[SECTION_FILTER_TABLE_SIZE] =
{
/* description tag pid tid mask */
@@ -72,4 +84,3 @@ const section_filter_table_type section_filter_table[SECTION_FILTER_TABLE_SIZE]
{trNOOP("EIT (0x6X)"), "EIT", 0x12, 0x60, 0xF0},
{trNOOP("TDT (0x70)"), "TDT", 0x14, 0x70, 0xFF},
};

View File

@@ -44,7 +44,8 @@
do { \
if (exp) { \
char tmp[64]; \
error(errstr": %s", strerror_r(errno, tmp, sizeof(tmp))); \
error("[%s,%d]: "errstr": %s", __FILE__, __LINE__, \
strerror_r(errno, tmp, sizeof(tmp))); \
func; \
ret; \
} \
@@ -66,10 +67,11 @@
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
uint16_t ts_pid(const uint8_t *buf);
uint8_t payload(const uint8_t *tsp);
const char *id_pid(const u_short Pid);
int select_single_desc(int descriptor, const int usecs, const bool selectWrite);
uint16_t ts_pid(const uint8_t *bufP);
uint8_t payload(const uint8_t *bufP);
const char *id_pid(const u_short pidP);
int select_single_desc(int descriptorP, const int usecsP, const bool selectWriteP);
cString ChangeCase(const cString &strP, bool upperP);
struct section_filter_table_type {
const char *description;

View File

@@ -12,13 +12,14 @@ cIptvConfig IptvConfig;
cIptvConfig::cIptvConfig(void)
: tsBufferSizeM(2),
tsBufferPrefillRatioM(0),
extProtocolBasePortM(4321),
protocolBasePortM(4321),
useBytesM(1),
sectionFilteringM(1)
{
for (unsigned int i = 0; i < ARRAY_SIZE(disabledFiltersM); ++i)
disabledFiltersM[i] = -1;
memset(configDirectoryM, 0, sizeof(configDirectoryM));
memset(resourceDirectoryM, 0, sizeof(resourceDirectoryM));
}
unsigned int cIptvConfig::GetDisabledFiltersCount(void) const
@@ -45,3 +46,9 @@ void cIptvConfig::SetConfigDirectory(const char *directoryP)
debug("cIptvConfig::%s(%s)", __FUNCTION__, directoryP);
ERROR_IF(!realpath(directoryP, configDirectoryM), "Cannot canonicalize configuration directory");
}
void cIptvConfig::SetResourceDirectory(const char *directoryP)
{
debug("cIptvConfig::%s(%s)", __FUNCTION__, directoryP);
ERROR_IF(!realpath(directoryP, resourceDirectoryM), "Cannot canonicalize resource directory");
}

View File

@@ -16,29 +16,32 @@ class cIptvConfig
private:
unsigned int tsBufferSizeM;
unsigned int tsBufferPrefillRatioM;
unsigned int extProtocolBasePortM;
unsigned int protocolBasePortM;
unsigned int useBytesM;
unsigned int sectionFilteringM;
int disabledFiltersM[SECTION_FILTER_TABLE_SIZE];
char configDirectoryM[PATH_MAX];
char resourceDirectoryM[PATH_MAX];
public:
cIptvConfig();
unsigned int GetTsBufferSize(void) const { return tsBufferSizeM; }
unsigned int GetTsBufferPrefillRatio(void) const { return tsBufferPrefillRatioM; }
unsigned int GetExtProtocolBasePort(void) const { return extProtocolBasePortM; }
unsigned int GetProtocolBasePort(void) const { return protocolBasePortM; }
unsigned int GetUseBytes(void) const { return useBytesM; }
unsigned int GetSectionFiltering(void) const { return sectionFilteringM; }
const char *GetConfigDirectory(void) const { return configDirectoryM; }
const char *GetResourceDirectory(void) const { return resourceDirectoryM; }
unsigned int GetDisabledFiltersCount(void) const;
int GetDisabledFilters(unsigned int indexP) const;
void SetTsBufferSize(unsigned int sizeP) { tsBufferSizeM = sizeP; }
void SetTsBufferPrefillRatio(unsigned int ratioP) { tsBufferPrefillRatioM = ratioP; }
void SetExtProtocolBasePort(unsigned int portNumberP) { extProtocolBasePortM = portNumberP; }
void SetProtocolBasePort(unsigned int portNumberP) { protocolBasePortM = portNumberP; }
void SetUseBytes(unsigned int onOffP) { useBytesM = onOffP; }
void SetSectionFiltering(unsigned int onOffP) { sectionFilteringM = onOffP; }
void SetDisabledFilters(unsigned int indexP, int numberP);
void SetConfigDirectory(const char *directoryP);
void SetResourceDirectory(const char *directoryP);
};
extern cIptvConfig IptvConfig;

287
device.c
View File

@@ -20,30 +20,30 @@ cIptvDevice::cIptvDevice(unsigned int indexP)
isOpenDvrM(false),
sidScanEnabledM(false),
pidScanEnabledM(false),
channelIdM(tChannelID::InvalidID)
channelM()
{
unsigned int bufsize = (unsigned int)MEGABYTE(IptvConfig.GetTsBufferSize());
bufsize -= (bufsize % TS_SIZE);
isyslog("creating IPTV device %d (CardIndex=%d)", deviceIndexM, CardIndex());
tsBufferM = new cRingBufferLinear(bufsize + 1, TS_SIZE, false,
*cString::sprintf("IPTV %d", deviceIndexM));
tsBufferM->SetTimeouts(10, 10);
*cString::sprintf("IPTV TS %d", deviceIndexM));
if (tsBufferM) {
tsBufferM->SetTimeouts(100, 100);
tsBufferM->SetIoThrottle();
pIptvStreamerM = new cIptvStreamer(*this, tsBufferM->Free());
}
ResetBuffering();
pUdpProtocolM = new cIptvProtocolUdp();
pCurlProtocolM = new cIptvProtocolCurl();
pHttpProtocolM = new cIptvProtocolHttp();
pFileProtocolM = new cIptvProtocolFile();
pExtProtocolM = new cIptvProtocolExt();
pIptvStreamerM = new cIptvStreamer(tsBufferM, (100 * TS_SIZE));
pPidScannerM = new cPidScanner();
// Initialize filter pointers
memset(secFiltersM, 0, sizeof(secFiltersM));
// Start section handler for iptv device
pIptvSectionM = new cIptvSectionFilterHandler(deviceIndexM, bufsize + 1);
StartSectionHandler();
// Sid scanner must be created after the section handler
pSidScannerM = new cSidScanner();
if (pSidScannerM)
AttachFilter(pSidScannerM);
AttachFilter(pSidScannerM = new cSidScanner());
// Check if dvr fifo exists
struct stat sb;
cString filename = cString::sprintf(IPTV_DVR_FILENAME, deviceIndexM);
@@ -60,22 +60,16 @@ cIptvDevice::~cIptvDevice()
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
// Stop section handler of iptv device
StopSectionHandler();
DELETE_POINTER(pIptvStreamerM);
DELETE_POINTER(pUdpProtocolM);
DELETE_POINTER(pCurlProtocolM);
DELETE_POINTER(pHttpProtocolM);
DELETE_POINTER(pFileProtocolM);
DELETE_POINTER(pExtProtocolM);
DELETE_POINTER(tsBufferM);
DELETE_POINTER(pIptvSectionM);
DELETE_POINTER(pSidScannerM);
DELETE_POINTER(pPidScannerM);
// Detach and destroy sid filter
if (pSidScannerM) {
Detach(pSidScannerM);
DELETE_POINTER(pSidScannerM);
}
// Destroy all filters
for (int i = 0; i < eMaxSecFilterCount; ++i)
DeleteFilter(i);
DELETE_POINTER(pIptvStreamerM);
DELETE_POINTER(pExtProtocolM);
DELETE_POINTER(pFileProtocolM);
DELETE_POINTER(pHttpProtocolM);
DELETE_POINTER(pCurlProtocolM);
DELETE_POINTER(pUdpProtocolM);
DELETE_POINTER(tsBufferM);
// Close dvr fifo
if (dvrFdM >= 0) {
int fd = dvrFdM;
@@ -97,6 +91,15 @@ bool cIptvDevice::Initialize(unsigned int deviceCountP)
return true;
}
void cIptvDevice::Shutdown(void)
{
debug("cIptvDevice::%s()", __FUNCTION__);
for (int i = 0; i < IPTV_MAX_DEVICES; ++i) {
if (IptvDevicesS[i])
IptvDevicesS[i]->CloseDvr();
}
}
unsigned int cIptvDevice::Count(void)
{
unsigned int count = 0;
@@ -112,7 +115,7 @@ cIptvDevice *cIptvDevice::GetIptvDevice(int cardIndexP)
{
//debug("cIptvDevice::%s(%d)", __FUNCTION__, cardIndexP);
for (unsigned int i = 0; i < IPTV_MAX_DEVICES; ++i) {
if ((IptvDevicesS[i] != NULL) && (IptvDevicesS[i]->CardIndex() == cardIndexP)) {
if (IptvDevicesS[i] && (IptvDevicesS[i]->CardIndex() == cardIndexP)) {
//debug("cIptvDevice::%s(%d): found!", __FUNCTION__, cardIndexP);
return IptvDevicesS[i];
}
@@ -140,19 +143,7 @@ cString cIptvDevice::GetPidsInformation(void)
cString cIptvDevice::GetFiltersInformation(void)
{
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
unsigned int count = 0;
cString s("Active section filters:\n");
// loop through active section filters
for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) {
if (secFiltersM[i]) {
s = cString::sprintf("%sFilter %d: %s Pid=0x%02X (%s)\n", *s, i,
*secFiltersM[i]->GetSectionStatistic(), secFiltersM[i]->GetPid(),
id_pid(secFiltersM[i]->GetPid()));
if (++count > IPTV_STATS_ACTIVE_FILTERS_COUNT)
break;
}
}
return s;
return cString::sprintf("Active section filters:\n%s", pIptvSectionM ? *pIptvSectionM->GetInformation() : "");
}
cString cIptvDevice::GetInformation(unsigned int pageP)
@@ -187,7 +178,7 @@ cString cIptvDevice::GetInformation(unsigned int pageP)
cString cIptvDevice::DeviceType(void) const
{
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
return "IPTV";
}
@@ -232,7 +223,7 @@ bool cIptvDevice::ProvidesChannel(const cChannel *channelP, int priorityP, bool
if (channelP && ProvidesTransponder(channelP)) {
result = hasPriority;
if (Receiving()) {
if (channelP->GetChannelID() == channelIdM)
if (channelP->GetChannelID() == channelM.GetChannelID())
result = true;
else
needsDetachReceivers = Receiving();
@@ -253,6 +244,21 @@ int cIptvDevice::NumProvidedSystems(void) const
return 1;
}
const cChannel *cIptvDevice::GetCurrentlyTunedTransponder(void) const
{
return &channelM;
}
bool cIptvDevice::IsTunedToTransponder(const cChannel *channelP) const
{
return channelP ? (channelP->GetChannelID() == channelM.GetChannelID()) : false;
}
bool cIptvDevice::MaySwitchTransponder(const cChannel *channelP) const
{
return cDevice::MaySwitchTransponder(channelP);
}
bool cIptvDevice::SetChannelDevice(const cChannel *channelP, bool liveViewP)
{
cIptvProtocolIf *protocol;
@@ -287,12 +293,12 @@ bool cIptvDevice::SetChannelDevice(const cChannel *channelP, bool liveViewP)
}
sidScanEnabledM = itp.SidScan() ? true : false;
pidScanEnabledM = itp.PidScan() ? true : false;
if (pIptvStreamerM->Set(itp.Address(), itp.Parameter(), deviceIndexM, protocol)) {
channelIdM = channelP->GetChannelID();
if (pIptvStreamerM && pIptvStreamerM->SetSource(itp.Address(), itp.Parameter(), deviceIndexM, protocol)) {
channelM = *channelP;
if (sidScanEnabledM && pSidScannerM && IptvConfig.GetSectionFiltering())
pSidScannerM->SetChannel(channelIdM);
pSidScannerM->SetChannel(channelM.GetChannelID());
if (pidScanEnabledM && pPidScannerM)
pPidScannerM->SetChannel(channelIdM);
pPidScannerM->SetChannel(channelM.GetChannelID());
}
return true;
}
@@ -300,82 +306,29 @@ bool cIptvDevice::SetChannelDevice(const cChannel *channelP, bool liveViewP)
bool cIptvDevice::SetPid(cPidHandle *handleP, int typeP, bool onP)
{
debug("cIptvDevice::%s(%d): pid=%d type=%d on=%d", __FUNCTION__, deviceIndexM, handleP->pid, typeP, onP);
if (pIptvStreamerM && handleP)
return pIptvStreamerM->SetPid(handleP->pid, typeP, onP);
return true;
}
bool cIptvDevice::DeleteFilter(unsigned int indexP)
{
if ((indexP < eMaxSecFilterCount) && secFiltersM[indexP]) {
//debug("cIptvDevice::%s(%d): index=%d", __FUNCTION__, deviceIndexM, indexP);
cIptvSectionFilter *tmp = secFiltersM[indexP];
secFiltersM[indexP] = NULL;
delete tmp;
return true;
}
return false;
}
bool cIptvDevice::IsBlackListed(u_short pidP, u_char tidP, u_char maskP) const
{
//debug("cIptvDevice::%s(%d): pid=%d tid=%02X mask=%02X", __FUNCTION__, deviceIndexM, pidP, tidP, maskP);
// loop through section filter table
for (int i = 0; i < SECTION_FILTER_TABLE_SIZE; ++i) {
int index = IptvConfig.GetDisabledFilters(i);
// check if matches
if ((index >= 0) && (index < SECTION_FILTER_TABLE_SIZE) &&
(section_filter_table[index].pid == pidP) && (section_filter_table[index].tid == tidP) &&
(section_filter_table[index].mask == maskP)) {
//debug("cIptvDevice::%s(%d): found %s", __FUNCTION__, deviceIndexM, section_filter_table[index].description);
return true;
}
}
return false;
}
int cIptvDevice::OpenFilter(u_short pidP, u_char tidP, u_char maskP)
{
// Check if disabled by user
if (!IptvConfig.GetSectionFiltering())
return -1;
// Blacklist check, refuse certain filters
if (IsBlackListed(pidP, tidP, maskP))
return -1;
// Lock
cMutexLock MutexLock(&mutexM);
// Search the next free filter slot
for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) {
if (!secFiltersM[i]) {
//debug("cIptvDevice::%s(%d): pid=%d tid=%02X mask=%02X index=%d", __FUNCTION__, deviceIndexM, pidP, tidP, maskP, i);
secFiltersM[i] = new cIptvSectionFilter(deviceIndexM, pidP, tidP, maskP);
if (secFiltersM[i])
return i;
break;
}
}
// No free filter slot found
return -1;
}
int cIptvDevice::ReadFilter(int handleP, void *bufferP, size_t lengthP)
{
// Lock
cMutexLock MutexLock(&mutexM);
// ... and load
if (secFiltersM[handleP]) {
return secFiltersM[handleP]->Read(bufferP, lengthP);
//debug("cIptvDevice::%s(%d): handle=%d length=%d", __FUNCTION__, deviceIndexM, handleP, lengthP);
//debug("cIptvDevice::%s(%d): pid=%d tid=%d mask=%d", __FUNCTION__, deviceIndexM, pidP, tidP, maskP);
if (pIptvSectionM && IptvConfig.GetSectionFiltering()) {
if (pIptvStreamerM)
pIptvStreamerM->SetPid(pidP, ptOther, true);
return pIptvSectionM->Open(pidP, tidP, maskP);
}
return 0;
return -1;
}
void cIptvDevice::CloseFilter(int handleP)
{
// Lock
cMutexLock MutexLock(&mutexM);
// ... and load
if (secFiltersM[handleP]) {
//debug("cIptvDevice::%s(%d): handle=%d", __FUNCTION__, deviceIndexM, handleP);
DeleteFilter(handleP);
//debug("cIptvDevice::%s(%d): handle=%d", __FUNCTION__, deviceIndexM, handleP);
if (pIptvSectionM) {
if (pIptvStreamerM)
pIptvStreamerM->SetPid(pIptvSectionM->GetPid(handleP), ptOther, false);
pIptvSectionM->Close(handleP);
}
}
@@ -389,6 +342,8 @@ bool cIptvDevice::OpenDvr(void)
pIptvStreamerM->Open();
if (sidScanEnabledM && pSidScannerM && IptvConfig.GetSectionFiltering())
pSidScannerM->Open();
if (pidScanEnabledM && pPidScannerM)
pPidScannerM->Open();
isOpenDvrM = true;
return true;
}
@@ -396,7 +351,9 @@ bool cIptvDevice::OpenDvr(void)
void cIptvDevice::CloseDvr(void)
{
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
if (sidScanEnabledM && pSidScannerM && IptvConfig.GetSectionFiltering())
if (pidScanEnabledM && pPidScannerM)
pPidScannerM->Close();
if (sidScanEnabledM && pSidScannerM)
pSidScannerM->Close();
if (pIptvStreamerM)
pIptvStreamerM->Close();
@@ -412,13 +369,13 @@ bool cIptvDevice::HasLock(int timeoutMsP) const
bool cIptvDevice::HasInternalCam(void)
{
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
return true;
return false;
}
void cIptvDevice::ResetBuffering(void)
{
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
// pad prefill to multiple of TS_SIZE
// Pad prefill to multiple of TS_SIZE
tsBufferPrefillM = (unsigned int)MEGABYTE(IptvConfig.GetTsBufferSize()) *
IptvConfig.GetTsBufferPrefillRatio() / 100;
tsBufferPrefillM -= (tsBufferPrefillM % TS_SIZE);
@@ -434,52 +391,92 @@ bool cIptvDevice::IsBuffering(void) const
return false;
}
bool cIptvDevice::GetTSPacket(uchar *&Data)
void cIptvDevice::WriteData(uchar *bufferP, int lengthP)
{
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
if (tsBufferM && !IsBuffering()) {
if (isPacketDeliveredM) {
tsBufferM->Del(TS_SIZE);
isPacketDeliveredM = false;
// Update buffer statistics
AddBufferStatistic(TS_SIZE, tsBufferM->Available());
}
int Count = 0;
uchar *p = tsBufferM->Get(Count);
if (p && Count >= TS_SIZE) {
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;
}
uchar *cIptvDevice::GetData(int *availableP)
{
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
if (isOpenDvrM && tsBufferM && !IsBuffering()) {
int count = 0;
if (isPacketDeliveredM)
SkipData(TS_SIZE);
uchar *p = tsBufferM->Get(count);
if (p && count >= TS_SIZE) {
if (*p != TS_SYNC_BYTE) {
for (int i = 1; i < Count; i++) {
for (int i = 1; i < count; i++) {
if (p[i] == TS_SYNC_BYTE) {
Count = i;
count = i;
break;
}
}
tsBufferM->Del(Count);
error("Skipped %d bytes to sync on TS packet\n", Count);
return false;
tsBufferM->Del(count);
error("Skipped %d bytes to sync on TS packet", count);
return NULL;
}
isPacketDeliveredM = true;
Data = p;
if (availableP)
*availableP = count;
// Update pid statistics
AddPidStatistic(ts_pid(p), payload(p));
// Send data also to dvr fifo
if (dvrFdM >= 0)
Count = (int)write(dvrFdM, p, TS_SIZE);
// Analyze incomplete streams with built-in pid analyzer
if (pidScanEnabledM && pPidScannerM)
pPidScannerM->Process(p);
// Lock
cMutexLock MutexLock(&mutexM);
// Run the data through all filters
for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) {
if (secFiltersM[i])
secFiltersM[i]->Process(p);
}
return true;
return p;
}
}
return NULL;
}
void cIptvDevice::SkipData(int countP)
{
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
tsBufferM->Del(countP);
isPacketDeliveredM = false;
// Update buffer statistics
AddBufferStatistic(countP, tsBufferM->Available());
}
bool cIptvDevice::GetTSPacket(uchar *&dataP)
{
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
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;
}
}
dataP = GetData();
return true;
}
// Reduce cpu load by preventing busylooping
cCondWait::SleepMs(10);
Data = NULL;
dataP = NULL;
return true;
}

View File

@@ -10,6 +10,7 @@
#include <vdr/device.h>
#include "common.h"
#include "deviceif.h"
#include "protocoludp.h"
#include "protocolcurl.h"
#include "protocolhttp.h"
@@ -21,19 +22,17 @@
#include "sidscanner.h"
#include "statistics.h"
class cIptvDevice : public cDevice, public cIptvPidStatistics, public cIptvBufferStatistics {
class cIptvDevice : public cDevice, public cIptvPidStatistics, public cIptvBufferStatistics, public cIptvDeviceIf {
// static ones
public:
static unsigned int deviceCount;
static bool Initialize(unsigned int DeviceCount);
static void Shutdown(void);
static unsigned int Count(void);
static cIptvDevice *GetIptvDevice(int CardIndex);
// private parts
private:
enum {
eMaxSecFilterCount = 32
};
unsigned int deviceIndexM;
int dvrFdM;
bool isPacketDeliveredM;
@@ -42,17 +41,17 @@ private:
bool pidScanEnabledM;
cRingBufferLinear *tsBufferM;
mutable int tsBufferPrefillM;
tChannelID channelIdM;
cChannel channelM;
cIptvProtocolUdp *pUdpProtocolM;
cIptvProtocolCurl *pCurlProtocolM;
cIptvProtocolHttp *pHttpProtocolM;
cIptvProtocolFile *pFileProtocolM;
cIptvProtocolExt *pExtProtocolM;
cIptvStreamer *pIptvStreamerM;
cIptvSectionFilterHandler *pIptvSectionM;
cPidScanner *pPidScannerM;
cSidScanner *pSidScannerM;
cMutex mutexM;
cIptvSectionFilter *secFiltersM[eMaxSecFilterCount];
// constructor & destructor
public:
@@ -74,8 +73,6 @@ private:
private:
void ResetBuffering(void);
bool IsBuffering(void) const;
bool DeleteFilter(unsigned int indexP);
bool IsBlackListed(u_short pidP, u_char tidP, u_char maskP) const;
// for channel info
public:
@@ -91,10 +88,18 @@ public:
virtual bool ProvidesChannel(const cChannel *channelP, int priorityP = -1, bool *needsDetachReceiversP = NULL) const;
virtual bool ProvidesEIT(void) const;
virtual int NumProvidedSystems(void) const;
virtual const cChannel *GetCurrentlyTunedTransponder(void) const;
virtual bool IsTunedToTransponder(const cChannel *channelP) const;
virtual bool MaySwitchTransponder(const cChannel *channelP) const;
protected:
virtual bool SetChannelDevice(const cChannel *channelP, bool liveViewP);
// for recording
private:
uchar *GetData(int *availableP = NULL);
void SkipData(int countP);
protected:
virtual bool SetPid(cPidHandle *handleP, int typeP, bool onP);
virtual bool OpenDvr(void);
@@ -104,7 +109,6 @@ protected:
// for section filtering
public:
virtual int OpenFilter(u_short pidP, u_char tidP, u_char maskP);
virtual int ReadFilter(int handleP, void *bufferP, size_t lengthP);
virtual void CloseFilter(int handleP);
// for transponder lock
@@ -114,6 +118,11 @@ public:
// for common interface
public:
virtual bool HasInternalCam(void);
// for internal device interface
public:
virtual void WriteData(u_char *bufferP, int lengthP);
virtual unsigned int CheckData(void);
};
#endif // __IPTV_DEVICE_H

23
deviceif.h Normal file
View File

@@ -0,0 +1,23 @@
/*
* deviceif.h: IPTV plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#ifndef __IPTV_DEVICEIF_H
#define __IPTV_DEVICEIF_H
class cIptvDeviceIf {
public:
cIptvDeviceIf() {}
virtual ~cIptvDeviceIf() {}
virtual void WriteData(u_char *bufferP, int lengthP) = 0;
virtual unsigned int CheckData(void) = 0;
private:
cIptvDeviceIf(const cIptvDeviceIf&);
cIptvDeviceIf& operator=(const cIptvDeviceIf&);
};
#endif // __IPTV_DEVICEIF_H

21
iptv.c
View File

@@ -13,15 +13,15 @@
#include "device.h"
#include "iptvservice.h"
#if defined(APIVERSNUM) && APIVERSNUM < 10738
#error "VDR-1.7.38 API version or greater is required!"
#if defined(APIVERSNUM) && APIVERSNUM < 20104
#error "VDR-2.1.4 API version or greater is required!"
#endif
#ifndef GITVERSION
#define GITVERSION ""
#endif
const char VERSION[] = "1.2.0" GITVERSION;
const char VERSION[] = "2.1.1" GITVERSION;
static const char DESCRIPTION[] = trNOOP("Experience the IPTV");
class cPluginIptv : public cPlugin {
@@ -99,7 +99,8 @@ bool cPluginIptv::Initialize(void)
{
debug("cPluginIptv::%s()", __FUNCTION__);
// Initialize any background activities the plugin shall perform.
IptvConfig.SetConfigDirectory(cPlugin::ResourceDirectory(PLUGIN_NAME_I18N));
IptvConfig.SetConfigDirectory(cPlugin::ConfigDirectory(PLUGIN_NAME_I18N));
IptvConfig.SetResourceDirectory(cPlugin::ResourceDirectory(PLUGIN_NAME_I18N));
return cIptvDevice::Initialize(deviceCountM);
}
@@ -109,7 +110,14 @@ bool cPluginIptv::Start(void)
// Start any background activities the plugin shall perform.
if (curl_global_init(CURL_GLOBAL_ALL) == CURLE_OK) {
curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
info("Using CURL %s", data->version);
cString info = cString::sprintf("Using CURL %s", data->version);
for (int i = 0; data->protocols[i]; ++i) {
// Supported protocols: HTTP(S), RTSP, FILE
if (startswith(data->protocols[i], "http") || startswith(data->protocols[i], "rtsp") ||
startswith(data->protocols[i], "file"))
info = cString::sprintf("%s %s", *info, data->protocols[i]);
}
info("%s", *info);
}
return true;
}
@@ -118,6 +126,7 @@ void cPluginIptv::Stop(void)
{
debug("cPluginIptv::%s()", __FUNCTION__);
// Stop any background activities the plugin is performing.
cIptvDevice::Shutdown();
curl_global_cleanup();
}
@@ -188,7 +197,7 @@ bool cPluginIptv::SetupParse(const char *nameP, const char *valueP)
else if (!strcasecmp(nameP, "TsBufferPrefill"))
IptvConfig.SetTsBufferPrefillRatio(atoi(valueP));
else if (!strcasecmp(nameP, "ExtProtocolBasePort"))
IptvConfig.SetExtProtocolBasePort(atoi(valueP));
IptvConfig.SetProtocolBasePort(atoi(valueP));
else if (!strcasecmp(nameP, "SectionFiltering"))
IptvConfig.SetSectionFiltering(atoi(valueP));
else if (!strcasecmp(nameP, "DisabledFilters")) {

View File

@@ -39,7 +39,6 @@ void cPidScanner::SetChannel(const tChannelID &channelIdP)
aPidM = 0xFFFF;
numApidsM = 0;
processM = true;
timeoutM.Set(PIDSCANNER_TIMEOUT_IN_MS);
}
void cPidScanner::Process(const uint8_t* bufP)
@@ -56,7 +55,7 @@ void cPidScanner::Process(const uint8_t* bufP)
// Verify TS packet
if (bufP[0] != 0x47) {
error("Not TS packet: 0x%X\n", bufP[0]);
error("Not TS packet: 0x%02X", bufP[0]);
return;
}

View File

@@ -13,6 +13,12 @@
class cPidScanner {
private:
enum {
PIDSCANNER_APID_COUNT = 5, /* minimum count of audio pid samples for pid detection */
PIDSCANNER_VPID_COUNT = 5, /* minimum count of video pid samples for pid detection */
PIDSCANNER_PID_DELTA_COUNT = 100, /* minimum count of pid samples for audio/video only pid detection */
PIDSCANNER_TIMEOUT_IN_MS = 15000 /* 15s timeout for detection */
};
cTimeMs timeoutM;
tChannelID channelIdM;
bool processM;
@@ -26,6 +32,8 @@ public:
~cPidScanner();
void SetChannel(const tChannelID &channelIdP);
void Process(const uint8_t* bufP);
void Open() { debug("cPidScanner::%s()", __FUNCTION__); timeoutM.Set(PIDSCANNER_TIMEOUT_IN_MS); }
void Close() { debug("cPidScanner::%s()", __FUNCTION__); timeoutM.Set(0); }
};
#endif // __PIDSCANNER_H

View File

@@ -1,14 +1,14 @@
# VDR plugin language source file.
# Copyright (C) 2007 Rolf Ahrenberg & Antti Seppala
# Copyright (C) 2007-2014 Rolf Ahrenberg & Antti Seppala
# This file is distributed under the same license as the iptv package.
# Tobias <vdr@e-tobi.net>, 2007.
#
msgid ""
msgstr ""
"Project-Id-Version: vdr-iptv 1.2.0\n"
"Project-Id-Version: vdr-iptv 2.1.1\n"
"Report-Msgid-Bugs-To: <see README>\n"
"POT-Creation-Date: 2012-06-03 06:03+0300\n"
"PO-Revision-Date: 2012-06-03 06:03+0300\n"
"POT-Creation-Date: 2014-03-09 03:09+0200\n"
"PO-Revision-Date: 2014-03-09 03:09+0200\n"
"Last-Translator: Tobias Grimm <tg@e-tobi.net>\n"
"Language-Team: German <vdr@linuxtv.org>\n"
"Language: de\n"
@@ -77,13 +77,13 @@ msgid ""
"This is useful if streaming media over a slow or unreliable connection."
msgstr ""
msgid "EXT protocol base port"
msgstr "EXT Protokoll Basisport"
msgid "Protocol base port"
msgstr "Protokoll Basisport"
msgid ""
"Define a base port used by EXT protocol.\n"
"Define a base port used by CURL/EXT protocol.\n"
"\n"
"The port range is defined by the number of IPTV devices. This setting sets the port which is listened for connections from external applications when using the EXT protocol."
"The port range is defined by the number of IPTV devices. This setting sets the port which is listened for connections from external applications when using the CURL/EXT protocol."
msgstr ""
msgid "Use section filtering"

View File

@@ -1,14 +1,14 @@
# VDR plugin language source file.
# Copyright (C) 2007 Rolf Ahrenberg & Antti Seppala
# Copyright (C) 2007-2014 Rolf Ahrenberg & Antti Seppala
# This file is distributed under the same license as the iptv package.
# Rolf Ahrenberg
#
msgid ""
msgstr ""
"Project-Id-Version: vdr-iptv 1.2.0\n"
"Project-Id-Version: vdr-iptv 2.1.1\n"
"Report-Msgid-Bugs-To: <see README>\n"
"POT-Creation-Date: 2012-06-03 06:03+0300\n"
"PO-Revision-Date: 2012-06-03 06:03+0300\n"
"POT-Creation-Date: 2014-03-09 03:09+0200\n"
"PO-Revision-Date: 2014-03-09 03:09+0200\n"
"Last-Translator: Rolf Ahrenberg\n"
"Language-Team: Finnish <vdr@linuxtv.org>\n"
"Language: fi\n"
@@ -82,17 +82,17 @@ msgstr ""
"\n"
"Puskurin esitäyttö parantaa suoratoistoa hitailla ja epäluotettavilla yhteyksillä."
msgid "EXT protocol base port"
msgstr "EXT-protokollan perusportti"
msgid "Protocol base port"
msgstr "Protokollan perusportti"
msgid ""
"Define a base port used by EXT protocol.\n"
"Define a base port used by CURL/EXT protocol.\n"
"\n"
"The port range is defined by the number of IPTV devices. This setting sets the port which is listened for connections from external applications when using the EXT protocol."
"The port range is defined by the number of IPTV devices. This setting sets the port which is listened for connections from external applications when using the CURL/EXT protocol."
msgstr ""
"Määrittele EXT-protokollan käyttämä perusportti.\n"
"Määrittele protokollan käyttämä perusportti.\n"
"\n"
"Porttiavaruuden koko määräytyy käytettyjen IPTV-laitteiden mukaan. Laajennos lukee EXT-protokollan yhteydessä perusportista dataa, jota ulkoiset ohjelmistot tarjoavat."
"Porttiavaruuden koko määräytyy käytettyjen IPTV-laitteiden mukaan. Laajennos lukee CURL/EXT-protokollan yhteydessä perusportista dataa, jota ulkoiset ohjelmistot tarjoavat."
msgid "Use section filtering"
msgstr "Käytä sektioiden suodatusta"

View File

@@ -1,15 +1,15 @@
# French translations for iptv package.
# Copyright (C) 2007 Rolf Ahrenberg & Antti Seppala
# Copyright (C) 2007-2014 Rolf Ahrenberg & Antti Seppala
# This file is distributed under the same license as the iptv package.
# Bruno ROUSSEL <bruno.roussel@free.fr>, 2007.
# NIVAL Michaël <mnival@club-internet.fr>, 2008.
#
msgid ""
msgstr ""
"Project-Id-Version: vdr-iptv 1.2.0\n"
"Project-Id-Version: vdr-iptv 2.1.1\n"
"Report-Msgid-Bugs-To: <see README>\n"
"POT-Creation-Date: 2012-06-03 06:03+0300\n"
"PO-Revision-Date: 2012-06-03 06:03+0300\n"
"POT-Creation-Date: 2014-03-09 03:09+0200\n"
"PO-Revision-Date: 2014-03-09 03:09+0200\n"
"Last-Translator: NIVAL Michaël <mnival@club-internet.fr>\n"
"Language-Team: French <vdr@linuxtv.org>\n"
"Language: fr\n"
@@ -84,17 +84,17 @@ msgstr ""
"\n"
"Cette option est utile si le streaming est sur une connexion lente ou peu fiables."
msgid "EXT protocol base port"
msgstr "Port de base du protocole EXT"
msgid "Protocol base port"
msgstr "Port de base du protocole"
msgid ""
"Define a base port used by EXT protocol.\n"
"Define a base port used by CURL/EXT protocol.\n"
"\n"
"The port range is defined by the number of IPTV devices. This setting sets the port which is listened for connections from external applications when using the EXT protocol."
"The port range is defined by the number of IPTV devices. This setting sets the port which is listened for connections from external applications when using the CURL/EXT protocol."
msgstr ""
"Définit le port de base utilisé par le protocole EXT.\n"
"Définit le port de base utilisé par le protocole CURL/EXT.\n"
"\n"
"La plage de port est défini par le nombre de dispositif IPTV. Ce paramètre défini le port qui est écouté pour les connexions à partir d'applications externes en utilisant le protocole EXT."
"La plage de port est défini par le nombre de dispositif IPTV. Ce paramètre défini le port qui est écouté pour les connexions à partir d'applications externes en utilisant le protocole CURL/EXT."
msgid "Use section filtering"
msgstr "Utiliser le filtrage de section"

View File

@@ -1,14 +1,14 @@
# VDR plugin language source file.
# Copyright (C) 2007 Rolf Ahrenberg & Antti Seppala
# Copyright (C) 2007-2014 Rolf Ahrenberg & Antti Seppala
# This file is distributed under the same license as the iptv package.
# Diego Pierotto <vdr-italian@tiscali.it>, 2008.
#
msgid ""
msgstr ""
"Project-Id-Version: vdr-iptv 1.2.0\n"
"Project-Id-Version: vdr-iptv 2.1.1\n"
"Report-Msgid-Bugs-To: <see README>\n"
"POT-Creation-Date: 2012-06-03 06:03+0300\n"
"PO-Revision-Date: 2012-06-03 06:03+0300\n"
"POT-Creation-Date: 2014-03-09 03:09+0200\n"
"PO-Revision-Date: 2014-03-09 03:09+0200\n"
"Last-Translator: Diego Pierotto <vdr-italian@tiscali.it>\n"
"Language-Team: Italian <vdr@linuxtv.org>\n"
"Language: it\n"
@@ -83,17 +83,17 @@ msgstr ""
"\n"
"Questo è utile se si trasmette dati su una connessione lenta oppure inaffidabile."
msgid "EXT protocol base port"
msgstr "Porta base protocollo EXT"
msgid "Protocol base port"
msgstr "Porta base protocollo"
msgid ""
"Define a base port used by EXT protocol.\n"
"Define a base port used by CURL/EXT protocol.\n"
"\n"
"The port range is defined by the number of IPTV devices. This setting sets the port which is listened for connections from external applications when using the EXT protocol."
"The port range is defined by the number of IPTV devices. This setting sets the port which is listened for connections from external applications when using the CURL/EXT protocol."
msgstr ""
"Definisci una porta base usata dal protocollo EXT.\n"
"Definisci una porta base usata dal protocollo CURL/EXT.\n"
"\n"
"Il range della porta è definito dal numero di periferiche IPTV. Questo parametro imposta la porta che è in ascolto per connessioni da applicazioni esterne quando si usa il protocollo EXT."
"Il range della porta è definito dal numero di periferiche IPTV. Questo parametro imposta la porta che è in ascolto per connessioni da applicazioni esterne quando si usa il protocollo CURL/EXT."
msgid "Use section filtering"
msgstr "Utilizza sezione filtri"

View File

@@ -1,14 +1,14 @@
# VDR plugin language source file.
# Copyright (C) 2007 Rolf Ahrenberg & Antti Seppala
# Copyright (C) 2007-2014 Rolf Ahrenberg & Antti Seppala
# This file is distributed under the same license as the iptv package.
# Carel, 2010.
#
msgid ""
msgstr ""
"Project-Id-Version: vdr-iptv 1.2.0\n"
"Project-Id-Version: vdr-iptv 2.1.1\n"
"Report-Msgid-Bugs-To: <see README>\n"
"POT-Creation-Date: 2012-06-03 06:03+0300\n"
"PO-Revision-Date: 2012-06-03 06:03+0300\n"
"POT-Creation-Date: 2014-03-09 03:09+0200\n"
"PO-Revision-Date: 2014-03-09 03:09+0200\n"
"Last-Translator: Carel\n"
"Language-Team: Dutch <vdr@linuxtv.org>\n"
"Language: nl\n"
@@ -83,17 +83,17 @@ msgstr ""
"\n"
"Dit is aan te bevelen bij onbetrouwbare of langzame verbindingen."
msgid "EXT protocol base port"
msgstr "EXT protocol basispoort"
msgid "Protocol base port"
msgstr "Protocol basispoort"
msgid ""
"Define a base port used by EXT protocol.\n"
"Define a base port used by CURL/EXT protocol.\n"
"\n"
"The port range is defined by the number of IPTV devices. This setting sets the port which is listened for connections from external applications when using the EXT protocol."
"The port range is defined by the number of IPTV devices. This setting sets the port which is listened for connections from external applications when using the CURL/EXT protocol."
msgstr ""
"Bepaal de basispoort voor het EXT protocol.\n"
"Bepaal de basispoort voor het CURL/EXT protocol.\n"
"\n"
"De poortrange wordt bepaald door het aantal IPTV apparaten. Deze poort luistert naar inkomende verbindingen wanneer het EXT protocol wordt gebruikt."
"De poortrange wordt bepaald door het aantal IPTV apparaten. Deze poort luistert naar inkomende verbindingen wanneer het CURL/EXT protocol wordt gebruikt."
msgid "Use section filtering"
msgstr "Benutze Abschnittsfilterung"

View File

@@ -1,14 +1,14 @@
# VDR plugin language source file.
# Copyright (C) 2007 Rolf Ahrenberg & Antti Seppala
# Copyright (C) 2007-2014 Rolf Ahrenberg & Antti Seppala
# This file is distributed under the same license as the iptv package.
# Alexander Gross <Bikalexander@gmail.com>, 2008.
#
msgid ""
msgstr ""
"Project-Id-Version: vdr-iptv 1.2.0\n"
"Project-Id-Version: vdr-iptv 2.1.1\n"
"Report-Msgid-Bugs-To: <see README>\n"
"POT-Creation-Date: 2012-06-03 06:03+0300\n"
"PO-Revision-Date: 2012-06-03 06:03+0300\n"
"POT-Creation-Date: 2014-03-09 03:09+0200\n"
"PO-Revision-Date: 2014-03-09 03:09+0200\n"
"Last-Translator: Alexander Gross <Bikalexander@gmail.com>\n"
"Language-Team: Russian <vdr@linuxtv.org>\n"
"Language: ru\n"
@@ -78,13 +78,13 @@ msgid ""
"This is useful if streaming media over a slow or unreliable connection."
msgstr ""
msgid "EXT protocol base port"
msgstr "Базисный порт EXT протокола"
msgid "Protocol base port"
msgstr "Базисный порт протокола"
msgid ""
"Define a base port used by EXT protocol.\n"
"Define a base port used by CURL/EXT protocol.\n"
"\n"
"The port range is defined by the number of IPTV devices. This setting sets the port which is listened for connections from external applications when using the EXT protocol."
"The port range is defined by the number of IPTV devices. This setting sets the port which is listened for connections from external applications when using the CURL/EXT protocol."
msgstr ""
msgid "Use section filtering"

View File

@@ -9,28 +9,41 @@
#include "config.h"
#include "protocolcurl.h"
#ifdef CURLOPT_RTSPHEADER
#define USE_RTSP
#endif
#define iptv_curl_easy_setopt(X, Y, Z) \
if ((res = curl_easy_setopt((X), (Y), (Z))) != CURLE_OK) { error("curl_easy_setopt(%s, %s, %s) failed: %d\n", #X, #Y, #Z, res); }
if ((res = curl_easy_setopt((X), (Y), (Z))) != CURLE_OK) { \
error("curl_easy_setopt(%s, %s) failed: %s (%d)", #Y, #Z, curl_easy_strerror(res), res); \
}
#define iptv_curl_easy_perform(X) \
if ((res = curl_easy_perform((X))) != CURLE_OK) { error("curl_easy_perform(%s) failed: %d\n", #X, res); }
if ((res = curl_easy_perform((X))) != CURLE_OK) { \
error("curl_easy_perform() failed: %s (%d)", curl_easy_strerror(res), res); \
}
cIptvProtocolCurl::cIptvProtocolCurl()
: streamUrlM(""),
streamParamM(0),
streamPortM(0),
mutexM(),
handleM(NULL),
multiM(NULL),
headerListM(NULL),
ringBufferM(new cRingBufferLinear(MEGABYTE(IptvConfig.GetTsBufferSize()), 7 * TS_SIZE)),
rtspControlM(),
ringBufferM(new cRingBufferLinear(MEGABYTE(IptvConfig.GetTsBufferSize()),
7 * TS_SIZE, false, "IPTV CURL")),
rtspControlM(""),
modeM(eModeUnknown),
timeoutM(),
connectedM(false),
pausedM(false)
{
debug("cIptvProtocolCurl::%s()", __FUNCTION__);
if (ringBufferM)
if (ringBufferM) {
ringBufferM->SetTimeouts(100, 0);
ringBufferM->SetIoThrottle();
}
Connect();
}
@@ -60,30 +73,30 @@ size_t cIptvProtocolCurl::WriteRtspCallback(void *ptrP, size_t sizeP, size_t nme
size_t len = sizeP * nmembP;
unsigned char *p = (unsigned char *)ptrP;
//debug("cIptvProtocolCurl::%s(%zu)", __FUNCTION__, len);
// validate packet header ('$') and channel (0)
if (obj && (p[0] == 0x24 ) && (p[1] == 0)) {
// Validate packet header ('$') and channel (0)
if (obj && (p[0] == 0x24) && (p[1] == 0)) {
int length = (p[2] << 8) | p[3];
if (length > 3) {
// skip interleave header
// Skip interleave header
p += 4;
// http://tools.ietf.org/html/rfc3550
// http://tools.ietf.org/html/rfc2250
// version
// Version
unsigned int v = (p[0] >> 6) & 0x03;
// extension bit
// Extension bit
unsigned int x = (p[0] >> 4) & 0x01;
// cscr count
// CSCR count
unsigned int cc = p[0] & 0x0F;
// payload type: MPEG2 TS = 33
// Payload type: MPEG2 TS = 33
//unsigned int pt = p[1] & 0x7F;
// header lenght
// Header lenght
unsigned int headerlen = (3 + cc) * (unsigned int)sizeof(uint32_t);
// check if extension
// Check if extension
if (x) {
// extension header length
// Extension header length
unsigned int ehl = (((p[headerlen + 2] & 0xFF) << 8) |(p[headerlen + 3] & 0xFF));
// update header length
// Update header length
headerlen += (ehl + 1) * (unsigned int)sizeof(uint32_t);
}
// Check that rtp is version 2 and payload contains multiple of TS packet data
@@ -103,20 +116,27 @@ size_t cIptvProtocolCurl::DescribeCallback(void *ptrP, size_t sizeP, size_t nmem
size_t len = sizeP * nmembP;
//debug("cIptvProtocolCurl::%s(%zu)", __FUNCTION__, len);
bool found = false;
cString control = "";
char *p = (char *)ptrP;
char *r = strtok(p, "\r\n");
while (r) {
//debug("cIptvProtocolCurl::%s(%zu): %s", __FUNCTION__, len, r);
if (strstr(r, "a=control")) {
// Look for a media name: "video"
if (strstr(r, "m=video")) {
found = true;
}
// ... and find out its' attribute
if (found && strstr(r, "a=control")) {
char *s = NULL;
if (sscanf(r, "a=control:%64ms", &s) == 1)
if (sscanf(r, "a=control:%255ms", &s) == 1)
control = compactspace(s);
free(s);
break;
}
r = strtok(NULL, "\r\n");
}
}
if (!isempty(*control) && obj)
obj->SetRtspControl(*control);
@@ -144,8 +164,14 @@ size_t cIptvProtocolCurl::HeaderCallback(void *ptrP, size_t sizeP, size_t nmembP
void cIptvProtocolCurl::SetRtspControl(const char *controlP)
{
cMutexLock MutexLock(&mutexM);
debug("cIptvProtocolCurl::%s(%s)", __FUNCTION__, controlP);
rtspControlM = controlP;
//debug("cIptvProtocolCurl::%s(%s)", __FUNCTION__, controlP);
cString protocol = ChangeCase(controlP, false).Truncate(7);
if (startswith(*protocol, "rtsp://")) {
streamUrlM = controlP;
rtspControlM = "";
}
else
rtspControlM = controlP;
}
bool cIptvProtocolCurl::PutData(unsigned char *dataP, int lenP)
@@ -155,9 +181,10 @@ bool cIptvProtocolCurl::PutData(unsigned char *dataP, int lenP)
if (pausedM)
return false;
if (ringBufferM && (lenP >= 0)) {
// should be pause the transfer?
// Should we pause the transfer ?
if (ringBufferM->Free() < (2 * CURL_MAX_WRITE_SIZE)) {
debug("cIptvProtocolCurl::%s(pause): free=%d available=%d len=%d", __FUNCTION__, ringBufferM->Free(), ringBufferM->Available(), lenP);
debug("cIptvProtocolCurl::%s(pause): free=%d available=%d len=%d", __FUNCTION__,
ringBufferM->Free(), ringBufferM->Available(), lenP);
pausedM = true;
return false;
}
@@ -184,12 +211,12 @@ void cIptvProtocolCurl::ClearData()
ringBufferM->Clear();
}
unsigned char *cIptvProtocolCurl::GetData(unsigned int *lenP)
unsigned char *cIptvProtocolCurl::GetData(int &lenP)
{
cMutexLock MutexLock(&mutexM);
//debug("cIptvProtocolCurl::%s()", __FUNCTION__);
unsigned char *p = NULL;
*lenP = 0;
lenP = 0;
if (ringBufferM) {
int count = 0;
p = ringBufferM->Get(count);
@@ -202,15 +229,15 @@ unsigned char *cIptvProtocolCurl::GetData(unsigned int *lenP)
break;
}
}
error("IPTV skipped %d bytes to sync on TS packet\n", count);
error("IPTV skipped %d bytes to sync on TS packet", count);
ringBufferM->Del(count);
*lenP = 0;
lenP = 0;
return NULL;
}
}
#endif
count -= (count % TS_SIZE);
*lenP = count;
lenP = count;
}
return p;
@@ -223,123 +250,154 @@ bool cIptvProtocolCurl::Connect()
if (connectedM)
return true;
// initialize the curl session
// Initialize the curl session
if (!handleM)
handleM = curl_easy_init();
if (!multiM)
multiM = curl_multi_init();
if (handleM && multiM && !isempty(*streamUrlM)) {
if (handleM && !isempty(*streamUrlM)) {
CURLcode res = CURLE_OK;
cString netrc = cString::sprintf("%s/netrc", IptvConfig.GetConfigDirectory());
#ifdef DEBUG
// verbose output
// Verbose output
iptv_curl_easy_setopt(handleM, CURLOPT_VERBOSE, 1L);
#endif
// set callbacks
// Set callbacks
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEFUNCTION, cIptvProtocolCurl::WriteCallback);
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEDATA, this);
iptv_curl_easy_setopt(handleM, CURLOPT_HEADERFUNCTION, cIptvProtocolCurl::HeaderCallback);
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEHEADER, this);
// no progress meter and no signaling
// No progress meter and no signaling
iptv_curl_easy_setopt(handleM, CURLOPT_NOPROGRESS, 1L);
iptv_curl_easy_setopt(handleM, CURLOPT_NOSIGNAL, 1L);
// support netrc
// Support netrc
iptv_curl_easy_setopt(handleM, CURLOPT_NETRC, (long)CURL_NETRC_OPTIONAL);
iptv_curl_easy_setopt(handleM, CURLOPT_NETRC_FILE, *netrc);
// set timeout
// Set timeouts
iptv_curl_easy_setopt(handleM, CURLOPT_TIMEOUT, (long)eConnectTimeoutS);
iptv_curl_easy_setopt(handleM, CURLOPT_CONNECTTIMEOUT, (long)eConnectTimeoutS);
// set user-agent
// Set user-agent
iptv_curl_easy_setopt(handleM, CURLOPT_USERAGENT, *cString::sprintf("vdr-%s/%s", PLUGIN_NAME_I18N, VERSION));
// set url
//char *p = curl_easy_unescape(handleM, *streamUrlM, 0, NULL);
//streamUrlM = p;
//curl_free(p);
// Set URL
char *p = curl_easy_unescape(handleM, *streamUrlM, 0, NULL);
streamUrlM = p;
curl_free(p);
iptv_curl_easy_setopt(handleM, CURLOPT_URL, *streamUrlM);
// protocol specific initializations
// Protocol specific initializations
switch (modeM) {
#ifdef USE_RTSP
case eModeRtsp:
{
cString uri, control, transport, range;
// request server options
// Create the listening socket for UDP mode
if (!streamParamM)
OpenSocket(streamPortM);
// Request server options
uri = cString::sprintf("%s", *streamUrlM);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_STREAM_URI, *uri);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_OPTIONS);
iptv_curl_easy_perform(handleM);
// request session description - SDP is delivered in message body and not in the header!
// Request session description - SDP is delivered in message body and not in the header!
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEFUNCTION, cIptvProtocolCurl::DescribeCallback);
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEDATA, this);
uri = cString::sprintf("%s", *streamUrlM);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_STREAM_URI, *uri);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_DESCRIBE);
iptv_curl_easy_perform(handleM);
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEFUNCTION, NULL);
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEDATA, NULL);
// setup media stream
uri = cString::sprintf("%s/%s", *streamUrlM, *rtspControlM);
transport = "RTP/AVP/TCP;unicast;interleaved=0-1";
// Setup media stream
if (isempty(*rtspControlM))
uri = cString::sprintf("%s", *streamUrlM);
else
uri = cString::sprintf("%s/%s", *streamUrlM, *rtspControlM);
if (streamParamM)
transport = "RTP/AVP/TCP;unicast;interleaved=0-1";
else
transport = cString::sprintf("RTP/AVP;unicast;client_port=%d-%d", streamPortM, streamPortM + 1);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_STREAM_URI, *uri);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_TRANSPORT, *transport);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_SETUP);
iptv_curl_easy_perform(handleM);
// start playing
// Start playing
uri = cString::sprintf("%s/", *streamUrlM);
range = "0.000-";
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_STREAM_URI, *uri);
iptv_curl_easy_setopt(handleM, CURLOPT_RANGE, *range);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
//iptv_curl_easy_setopt(handleM, CURLOPT_RANGE, *range);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_PLAY);
iptv_curl_easy_perform(handleM);
// start receiving
iptv_curl_easy_setopt(handleM, CURLOPT_INTERLEAVEFUNCTION, cIptvProtocolCurl::WriteRtspCallback);
iptv_curl_easy_setopt(handleM, CURLOPT_INTERLEAVEDATA, this);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_RECEIVE);
iptv_curl_easy_perform(handleM);
// Start receiving
if (streamParamM) {
iptv_curl_easy_setopt(handleM, CURLOPT_INTERLEAVEFUNCTION, cIptvProtocolCurl::WriteRtspCallback);
iptv_curl_easy_setopt(handleM, CURLOPT_INTERLEAVEDATA, this);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_RECEIVE);
iptv_curl_easy_perform(handleM);
}
// Don't add handle into multi set
isActiveM = true;
}
break;
#endif
case eModeHttp:
case eModeHttps:
{
// limit download speed (bytes/s)
// Limit download speed (bytes/s)
iptv_curl_easy_setopt(handleM, CURLOPT_MAX_RECV_SPEED_LARGE, eMaxDownloadSpeedMBits * 131072L);
// follow location
// Follow location
iptv_curl_easy_setopt(handleM, CURLOPT_FOLLOWLOCATION, 1L);
// fail if HTTP return code is >= 400
// Fail if HTTP return code is >= 400
iptv_curl_easy_setopt(handleM, CURLOPT_FAILONERROR, 1L);
// set additional headers to prevent caching
// Set additional headers to prevent caching
headerListM = curl_slist_append(headerListM, "Cache-Control: no-store, no-cache, must-revalidate");
headerListM = curl_slist_append(headerListM, "Cache-Control: post-check=0, pre-check=0");
headerListM = curl_slist_append(headerListM, "Pragma: no-cache");
headerListM = curl_slist_append(headerListM, "Expires: Mon, 26 Jul 1997 05:00:00 GMT");
iptv_curl_easy_setopt(handleM, CURLOPT_HTTPHEADER, headerListM);
// Initialize multi set and add handle into it
if (!multiM)
multiM = curl_multi_init();
if (multiM)
curl_multi_add_handle(multiM, handleM);
}
break;
case eModeFile:
{
// Set timeout
iptv_curl_easy_setopt(handleM, CURLOPT_TIMEOUT_MS, 10L);
// Initialize multi set and add handle into it
if (!multiM)
multiM = curl_multi_init();
if (multiM)
curl_multi_add_handle(multiM, handleM);
}
break;
case eModeUnknown:
default:
break;
}
// add handle into multi set
curl_multi_add_handle(multiM, handleM);
timeoutM.Set(eKeepAliveIntervalMs);
connectedM = true;
return true;
}
@@ -351,21 +409,36 @@ bool cIptvProtocolCurl::Disconnect()
{
cMutexLock MutexLock(&mutexM);
debug("cIptvProtocolCurl::%s()", __FUNCTION__);
if (!connectedM)
return true;
// Terminate curl session
if (handleM) {
// mode specific tricks
// Remove handle from multi set
if (multiM) {
curl_multi_remove_handle(multiM, handleM);
curl_multi_cleanup(multiM);
multiM = NULL;
}
// Mode specific tricks
switch (modeM) {
#ifdef USE_RTSP
case eModeRtsp:
{
CURLcode res = CURLE_OK;
// teardown rtsp session
// Teardown rtsp session
cString uri = cString::sprintf("%s/", *streamUrlM);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_STREAM_URI, *uri);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_TEARDOWN);
iptv_curl_easy_perform(handleM);
rtspControlM = "";
isActiveM = false;
// Close the listening socket
CloseSocket();
}
break;
#endif
case eModeHttp:
case eModeHttps:
case eModeFile:
@@ -374,14 +447,11 @@ bool cIptvProtocolCurl::Disconnect()
break;
}
// cleanup curl stuff
// Cleanup curl stuff
if (headerListM) {
curl_slist_free_all(headerListM);
headerListM = NULL;
}
curl_multi_remove_handle(multiM, handleM);
curl_multi_cleanup(multiM);
multiM = NULL;
curl_easy_cleanup(handleM);
handleM = NULL;
}
@@ -409,64 +479,85 @@ int cIptvProtocolCurl::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
//debug("cIptvProtocolCurl::%s()", __FUNCTION__);
int len = 0;
if (ringBufferM) {
// fill up the buffer
if (handleM && multiM) {
// Fill up the buffer
if (handleM) {
switch (modeM) {
#ifdef USE_RTSP
case eModeRtsp:
{
//CURLcode res = CURLE_OK;
//iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_RECEIVE);
//iptv_curl_easy_perform(handleM);
// @todo - how to detect eof?
cMutexLock MutexLock(&mutexM);
CURLcode res = CURLE_OK;
// Remember the heart beat
if (timeoutM.TimedOut()) {
debug("cIptvProtocolCurl::%s(): KeepAlive", __FUNCTION__);
cString uri = cString::sprintf("%s", *streamUrlM);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_STREAM_URI, *uri);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_OPTIONS);
iptv_curl_easy_perform(handleM);
timeoutM.Set(eKeepAliveIntervalMs);
}
// Check whether UDP or TCP mode used
if (streamParamM) {
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_RECEIVE);
iptv_curl_easy_perform(handleM);
}
else
return cIptvUdpSocket::Read(bufferAddrP, bufferLenP);
}
break;
#endif
case eModeFile:
break;
case eModeHttp:
case eModeHttps:
{
CURLMcode res;
int running_handles;
if (multiM) {
CURLMcode res;
int running_handles;
do {
res = curl_multi_perform(multiM, &running_handles);
} while (res == CURLM_CALL_MULTI_PERFORM);
do {
cMutexLock MutexLock(&mutexM);
res = curl_multi_perform(multiM, &running_handles);
} while (res == CURLM_CALL_MULTI_PERFORM);
// shall be continue filling up the buffer?
mutexM.Lock();
if (pausedM && (ringBufferM->Free() > ringBufferM->Available())) {
debug("cIptvProtocolCurl::%s(continue): free=%d available=%d", __FUNCTION__, ringBufferM->Free(), ringBufferM->Available());
pausedM = false;
curl_easy_pause(handleM, CURLPAUSE_CONT);
}
mutexM.Unlock();
// Use 20% threshold before continuing to filling up the buffer.
mutexM.Lock();
if (pausedM && (ringBufferM->Available() < (MEGABYTE(IptvConfig.GetTsBufferSize()) / 5))) {
debug("cIptvProtocolCurl::%s(continue): free=%d available=%d", __FUNCTION__,
ringBufferM->Free(), ringBufferM->Available());
pausedM = false;
curl_easy_pause(handleM, CURLPAUSE_CONT);
}
mutexM.Unlock();
// check end of file
if (running_handles == 0) {
int msgcount;
CURLMsg *msg = curl_multi_info_read(multiM, &msgcount);
if (msg && (msg->msg == CURLMSG_DONE)) {
debug("cIptvProtocolCurl::%s(done): %s (%d)", __FUNCTION__, curl_easy_strerror(msg->data.result), msg->data.result);
Disconnect();
Connect();
// Check if end of file
if (running_handles == 0) {
int msgcount;
mutexM.Lock();
CURLMsg *msg = curl_multi_info_read(multiM, &msgcount);
mutexM.Unlock();
if (msg && (msg->msg == CURLMSG_DONE)) {
debug("cIptvProtocolCurl::%s(done): %s (%d)", __FUNCTION__,
curl_easy_strerror(msg->data.result), msg->data.result);
Disconnect();
Connect();
}
}
}
}
break;
case eModeUnknown:
default:
break;
}
}
// ... and try to empty it
unsigned char *p = GetData(&bufferLenP);
if (p && (bufferLenP > 0)) {
memcpy(bufferAddrP, p, bufferLenP);
DelData(bufferLenP);
len = bufferLenP;
unsigned char *p = GetData(len);
if (p && (len > 0)) {
len = min(len, (int)bufferLenP);
memcpy(bufferAddrP, p, len);
DelData(len);
//debug("cIptvProtocolCurl::%s(): get %d bytes", __FUNCTION__, len);
}
}
@@ -474,36 +565,42 @@ int cIptvProtocolCurl::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
return len;
}
bool cIptvProtocolCurl::Set(const char* locationP, const int parameterP, const int indexP)
bool cIptvProtocolCurl::SetSource(const char* locationP, const int parameterP, const int indexP)
{
debug("cIptvProtocolCurl::%s(%s, %d, %d)", __FUNCTION__, locationP, parameterP, indexP);
if (!isempty(locationP)) {
// Disconnect
Disconnect();
// Update stream URL: colons (%3A) and pipes (%7C) shall be decoded
char *s = strdup(locationP);
strreplace(s, "%3A", ":");
strreplace(s, "%7C", "|");
streamUrlM = s;
free(s);
if (startswith(*streamUrlM, "rtsp") || startswith(*streamUrlM, "RTSP"))
// Update stream URL
streamUrlM = locationP;
cString protocol = ChangeCase(streamUrlM, false).Truncate(5);
if (startswith(*protocol, "rtsp"))
modeM = eModeRtsp;
else if (startswith(*streamUrlM, "https") || startswith(*streamUrlM, "HTTPS"))
modeM = eModeHttp;
else if (startswith(*streamUrlM, "http") || startswith(*streamUrlM, "HTTP"))
else if (startswith(*protocol, "https"))
modeM = eModeHttps;
else if (startswith(*streamUrlM, "file") || startswith(*streamUrlM, "FILE"))
else if (startswith(*protocol, "http"))
modeM = eModeHttp;
else if (startswith(*protocol, "file"))
modeM = eModeFile;
else
modeM = eModeUnknown;
// Update stream parameter
streamParamM = parameterP;
debug("cIptvProtocolCurl::%s(): %s (%d)", __FUNCTION__, *protocol, modeM);
// Update stream parameter - force UDP mode for RTSP
streamParamM = (modeM == eModeRtsp) ? 0 : parameterP;
// Update listen port
streamPortM = IptvConfig.GetProtocolBasePort() + indexP * 2;
// Reconnect
Connect();
}
return true;
}
bool cIptvProtocolCurl::SetPid(int pidP, int typeP, bool onP)
{
//debug("cIptvProtocolCurl::%s(%d, %d, %d)", __FUNCTION__, pidP, typeP, onP);
return true;
}
cString cIptvProtocolCurl::GetInformation(void)
{
//debug("cIptvProtocolCurl::%s()", __FUNCTION__);

View File

@@ -16,8 +16,9 @@
#include <vdr/tools.h>
#include "protocolif.h"
#include "socket.h"
class cIptvProtocolCurl : public cIptvProtocolIf {
class cIptvProtocolCurl : public cIptvUdpSocket, public cIptvProtocolIf {
private:
enum eModeType {
eModeUnknown = 0,
@@ -28,9 +29,9 @@ private:
eModeCount
};
enum {
eConnectTimeoutS = 5, // in seconds
eSelectTimeoutMs = 10, // in milliseconds
eMaxDownloadSpeedMBits = 20 // in megabits per second
eConnectTimeoutS = 5, // in seconds
eMaxDownloadSpeedMBits = 20, // in megabits per second
eKeepAliveIntervalMs = 300000 // in milliseconds
};
static size_t WriteCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP);
@@ -40,6 +41,7 @@ private:
cString streamUrlM;
int streamParamM;
int streamPortM;
cMutex mutexM;
CURL *handleM;
CURLM *multiM;
@@ -47,6 +49,7 @@ private:
cRingBufferLinear *ringBufferM;
cString rtspControlM;
eModeType modeM;
cTimeMs timeoutM;
bool connectedM;
bool pausedM;
@@ -55,13 +58,14 @@ private:
bool PutData(unsigned char *dataP, int lenP);
void DelData(int lenP);
void ClearData(void);
unsigned char *GetData(unsigned int *lenP);
unsigned char *GetData(int &lenP);
public:
cIptvProtocolCurl();
virtual ~cIptvProtocolCurl();
int Read(unsigned char* bufferAddrP, unsigned int bufferLenP);
bool Set(const char* locationP, const int parameterP, const int indexP);
bool SetSource(const char* locationP, const int parameterP, const int indexP);
bool SetPid(int pidP, int typeP, bool onP);
bool Open(void);
bool Close(void);
cString GetInformation(void);

View File

@@ -152,24 +152,30 @@ int cIptvProtocolExt::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
return cIptvUdpSocket::Read(bufferAddrP, bufferLenP);
}
bool cIptvProtocolExt::Set(const char* locationP, const int parameterP, const int indexP)
bool cIptvProtocolExt::SetSource(const char* locationP, const int parameterP, const int indexP)
{
debug("cIptvProtocolExt::%s(%s, %d, %d)", __FUNCTION__, locationP, parameterP, indexP);
if (!isempty(locationP)) {
struct stat stbuf;
// Update script file and parameter
scriptFileM = cString::sprintf("%s/%s", IptvConfig.GetConfigDirectory(), locationP);
scriptFileM = cString::sprintf("%s/%s", IptvConfig.GetResourceDirectory(), locationP);
if ((stat(*scriptFileM, &stbuf) != 0) || (strstr(*scriptFileM, "..") != 0)) {
error("Non-existent or relative path script '%s'", *scriptFileM);
return false;
}
scriptParameterM = parameterP;
// Update listen port
streamPortM = IptvConfig.GetExtProtocolBasePort() + indexP;
streamPortM = IptvConfig.GetProtocolBasePort() + indexP * 2;
}
return true;
}
bool cIptvProtocolExt::SetPid(int pidP, int typeP, bool onP)
{
//debug("cIptvProtocolExt::%s(%d, %d, %d)", __FUNCTION__, pidP, typeP, onP);
return true;
}
cString cIptvProtocolExt::GetInformation(void)
{
//debug("cIptvProtocolExt::%s()", __FUNCTION__);

View File

@@ -27,7 +27,8 @@ public:
cIptvProtocolExt();
virtual ~cIptvProtocolExt();
int Read(unsigned char* bufferAddrP, unsigned int bufferLenP);
bool Set(const char* locationP, const int parameterP, const int indexP);
bool SetSource(const char* locationP, const int parameterP, const int indexP);
bool SetPid(int pidP, int typeP, bool onP);
bool Open(void);
bool Close(void);
cString GetInformation(void);

View File

@@ -60,7 +60,7 @@ int cIptvProtocolFile::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
{
//debug("cIptvProtocolFile::%s()", __FUNCTION__);
// Check errors
if (ferror(fileStreamM)) {
if (!fileStreamM || ferror(fileStreamM)) {
debug("cIptvProtocolFile::%s(): stream error", __FUNCTION__);
return -1;
}
@@ -95,7 +95,7 @@ bool cIptvProtocolFile::Close(void)
return true;
}
bool cIptvProtocolFile::Set(const char* locationP, const int parameterP, const int indexP)
bool cIptvProtocolFile::SetSource(const char* locationP, const int parameterP, const int indexP)
{
debug("cIptvProtocolFile::%s(%s, %d, %d)", __FUNCTION__, locationP, parameterP, indexP);
if (!isempty(locationP)) {
@@ -110,6 +110,12 @@ bool cIptvProtocolFile::Set(const char* locationP, const int parameterP, const i
return true;
}
bool cIptvProtocolFile::SetPid(int pidP, int typeP, bool onP)
{
//debug("cIptvProtocolFile::%s(%d, %d, %d)", __FUNCTION__, pidP, typeP, onP);
return true;
}
cString cIptvProtocolFile::GetInformation(void)
{
//debug("cIptvProtocolFile::%s()", __FUNCTION__);

View File

@@ -26,7 +26,8 @@ public:
cIptvProtocolFile();
virtual ~cIptvProtocolFile();
int Read(unsigned char* bufferAddrP, unsigned int bufferLenP);
bool Set(const char* locationP, const int parameterP, const int indexP);
bool SetSource(const char* locationP, const int parameterP, const int indexP);
bool SetPid(int pidP, int typeP, bool onP);
bool Open(void);
bool Close(void);
cString GetInformation(void);

View File

@@ -55,8 +55,9 @@ bool cIptvProtocolHttp::Connect(void)
"Connection: Close\r\n"
"\r\n", streamPathM, streamAddrM,
PLUGIN_NAME_I18N, VERSION);
debug("cIptvProtocolHttp::%s(): requesting: %s", __FUNCTION__, *buffer);
if (!Write(*buffer, (unsigned int)strlen(*buffer))) {
unsigned int len = strlen(*buffer);
debug("cIptvProtocolHttp::%s(): requesting %d: %s", __FUNCTION__, len, *buffer);
if (!Write(*buffer, len)) {
CloseSocket();
return false;
}
@@ -112,13 +113,13 @@ bool cIptvProtocolHttp::GetHeaderLine(char* destP, unsigned int destLenP,
++bufptr;
// Check that buffer won't be exceeded
if (recvLenP >= destLenP) {
error("Header wouldn't fit into buffer\n");
error("Header wouldn't fit into buffer");
recvLenP = 0;
return false;
}
}
else {
error("No HTTP response received in 500ms\n");
error("No HTTP response received in 500ms");
return false;
}
}
@@ -142,14 +143,14 @@ bool cIptvProtocolHttp::ProcessHeaders(void)
if (!GetHeaderLine(buf, sizeof(buf), lineLength))
return false;
if (!responseFound && sscanf(buf, fmt, &version, &response) != 2) {
error("Expected HTTP header not found\n");
error("Expected HTTP header not found");
continue;
}
else
responseFound = true;
// Allow only 'OK' and 'Partial Content'
if ((response != 200) && (response != 206)) {
error("Invalid HTTP response (%d): %s\n", response, buf);
error("Invalid HTTP response (%d): %s", response, buf);
return false;
}
}
@@ -176,7 +177,7 @@ int cIptvProtocolHttp::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
return cIptvTcpSocket::Read(bufferAddrP, bufferLenP);
}
bool cIptvProtocolHttp::Set(const char* locationP, const int parameterP, const int indexP)
bool cIptvProtocolHttp::SetSource(const char* locationP, const int parameterP, const int indexP)
{
debug("cIptvProtocolHttp::%s(%s, %d, %d)", __FUNCTION__, locationP, parameterP, indexP);
if (!isempty(locationP)) {
@@ -198,6 +199,12 @@ bool cIptvProtocolHttp::Set(const char* locationP, const int parameterP, const i
return true;
}
bool cIptvProtocolHttp::SetPid(int pidP, int typeP, bool onP)
{
//debug("cIptvProtocolHttp::%s(%d, %d, %d)", __FUNCTION__, pidP, typeP, onP);
return true;
}
cString cIptvProtocolHttp::GetInformation(void)
{
//debug("cIptvProtocolHttp::%s()", __FUNCTION__);

View File

@@ -28,7 +28,8 @@ public:
cIptvProtocolHttp();
virtual ~cIptvProtocolHttp();
int Read(unsigned char* bufferAddrP, unsigned int bufferLenP);
bool Set(const char* locationP, const int parameterP, const int indexP);
bool SetSource(const char* locationP, const int parameterP, const int indexP);
bool SetPid(int pidP, int typeP, bool onP);
bool Open(void);
bool Close(void);
cString GetInformation(void);

View File

@@ -13,7 +13,8 @@ public:
cIptvProtocolIf() {}
virtual ~cIptvProtocolIf() {}
virtual int Read(unsigned char* bufferAddrP, unsigned int bufferLenP) = 0;
virtual bool Set(const char* locationP, const int parameterP, const int indexP) = 0;
virtual bool SetSource(const char* locationP, const int parameterP, const int indexP) = 0;
virtual bool SetPid(int pidP, int typeP, bool onP) = 0;
virtual bool Open(void) = 0;
virtual bool Close(void) = 0;
virtual cString GetInformation(void) = 0;

View File

@@ -70,7 +70,7 @@ int cIptvProtocolUdp::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
return cIptvUdpSocket::Read(bufferAddrP, bufferLenP);
}
bool cIptvProtocolUdp::Set(const char* locationP, const int parameterP, const int indexP)
bool cIptvProtocolUdp::SetSource(const char* locationP, const int parameterP, const int indexP)
{
debug("cIptvProtocolUdp::%s(%s, %d, %d)", __FUNCTION__, locationP, parameterP, indexP);
if (!isempty(locationP)) {
@@ -103,6 +103,12 @@ bool cIptvProtocolUdp::Set(const char* locationP, const int parameterP, const in
return true;
}
bool cIptvProtocolUdp::SetPid(int pidP, int typeP, bool onP)
{
//debug("cIptvProtocolUdp::%s(%d, %d, %d)", __FUNCTION__, pidP, typeP, onP);
return true;
}
cString cIptvProtocolUdp::GetInformation(void)
{
//debug("cIptvProtocolUdp::%s()", __FUNCTION__);

View File

@@ -23,7 +23,8 @@ public:
cIptvProtocolUdp();
virtual ~cIptvProtocolUdp();
int Read(unsigned char* bufferAddrP, unsigned int bufferLenP);
bool Set(const char* locationP, const int parameterP, const int indexP);
bool SetSource(const char* locationP, const int parameterP, const int indexP);
bool SetPid(int pidP, int typeP, bool onP);
bool Open(void);
bool Close(void);
cString GetInformation(void);

View File

@@ -17,9 +17,9 @@ cIptvSectionFilter::cIptvSectionFilter(int deviceIndexP, uint16_t pidP, uint8_t
secLenM(0),
tsFeedpM(0),
pidM(pidP),
devIdM(deviceIndexP)
deviceIndexM(deviceIndexP)
{
//debug("cIptvSectionFilter::%s(%d, %d)", __FUNCTION__, devIdM, pidM);
//debug("cIptvSectionFilter::%s(%d, %d)", __FUNCTION__, deviceIndexM, pidM);
int i;
memset(secBufBaseM, 0, sizeof(secBufBaseM));
@@ -46,32 +46,32 @@ cIptvSectionFilter::cIptvSectionFilter(int deviceIndexP, uint16_t pidP, uint8_t
}
doneqM = doneq ? 1 : 0;
// Create filtering buffer
ringbufferM = new cRingBufferLinear(KILOBYTE(128), 0, false, *cString::sprintf("IPTV SECTION %d/%d", devIdM, pidM));
if (ringbufferM)
ringbufferM->SetTimeouts(10, 10);
else
error("Failed to allocate buffer for section filter (device=%d pid=%d): ", devIdM, pidM);
// Create sockets
socketM[0] = socketM[1] = -1;
if (socketpair(AF_UNIX, SOCK_DGRAM, 0, socketM) != 0) {
char tmp[64];
error("Opening section filter sockets failed (device=%d pid=%d): %s", deviceIndexM, pidM, strerror_r(errno, tmp, sizeof(tmp)));
}
else if ((fcntl(socketM[0], F_SETFL, O_NONBLOCK) != 0) || (fcntl(socketM[1], F_SETFL, O_NONBLOCK) != 0)) {
char tmp[64];
error("Setting section filter socket to non-blocking mode failed (device=%d pid=%d): %s", deviceIndexM, pidM, strerror_r(errno, tmp, sizeof(tmp)));
}
}
cIptvSectionFilter::~cIptvSectionFilter()
{
//debug("cIptvSectionFilter::%s(%d, %d)", __FUNCTION__, devIdM, pidM);
DELETE_POINTER(ringbufferM);
//debug("cIptvSectionFilter::%s(%d, %d)", __FUNCTION__, deviceIndexM, pidM);
int tmp = socketM[1];
socketM[1] = -1;
if (tmp >= 0)
close(tmp);
tmp = socketM[0];
socketM[0] = -1;
if (tmp >= 0)
close(tmp);
secBufM = NULL;
}
int cIptvSectionFilter::Read(void *Data, size_t Length)
{
int count = 0;
uchar *p = ringbufferM->Get(count);
if (p && count > 0) {
memcpy(Data, p, count);
ringbufferM->Del(count);
}
return count;
}
inline uint16_t cIptvSectionFilter::GetLength(const uint8_t *dataP)
{
return (uint16_t)(3 + ((dataP[1] & 0x0f) << 8) + dataP[2]);
@@ -99,10 +99,10 @@ int cIptvSectionFilter::Filter(void)
if (doneqM && !neq)
return 0;
if (ringbufferM) {
int len = ringbufferM->Put(secBufM, secLenM);
if (len != secLenM)
ringbufferM->ReportOverflow(secLenM - len);
// There is no data in the read socket, more can be written
if ((socketM[0] >= 0) && (socketM[1] >= 0) /*&& !select_single_desc(socketM[0], 0, false)*/) {
ssize_t len = write(socketM[1], secBufM, secLenM);
ERROR_IF(len < 0, "write()");
// Update statistics
AddSectionStatistic(len, 1);
}
@@ -210,3 +210,197 @@ void cIptvSectionFilter::Process(const uint8_t* dataP)
CopyDump(&dataP[p], count);
}
}
cIptvSectionFilterHandler::cIptvSectionFilterHandler(int deviceIndexP, unsigned int bufferLenP)
: cThread("IPTV section handler", true),
mutexM(),
deviceIndexM(deviceIndexP),
processedM(false),
ringBufferM(new cRingBufferLinear(bufferLenP, TS_SIZE, false, *cString::sprintf("IPTV SECTION HANDLER %d", deviceIndexP)))
{
debug("cIptvSectionFilterHandler::%s(%d)", __FUNCTION__, deviceIndexM);
// Initialize filter pointers
memset(filtersM, 0, sizeof(filtersM));
// Create input buffer
if (ringBufferM) {
ringBufferM->SetTimeouts(100, 100);
ringBufferM->SetIoThrottle();
}
else
error("Failed to allocate buffer for section filter handler (device=%d): ", deviceIndexM);
Start();
}
cIptvSectionFilterHandler::~cIptvSectionFilterHandler()
{
debug("cIptvSectionFilterHandler::%s(%d)", __FUNCTION__, deviceIndexM);
Stop();
DELETE_POINTER(ringBufferM);
// Destroy all filters
cMutexLock MutexLock(&mutexM);
for (int i = 0; i < eMaxSecFilterCount; ++i)
Delete(i);
}
bool cIptvSectionFilterHandler::Stop(void)
{
debug("cIptvSectionFilterHandler::%s(%d): entering", __FUNCTION__, deviceIndexM);
// Stop thread
if (Running())
Cancel(3);
return true;
}
void cIptvSectionFilterHandler::Action(void)
{
debug("cIptvSectionFilterHandler::%s(%d): entering", __FUNCTION__, deviceIndexM);
// Do the thread loop
while (Running()) {
// Read one TS packet
if (ringBufferM) {
int len = 0;
if (processedM) {
ringBufferM->Del(TS_SIZE);
processedM = false;
}
uchar *p = ringBufferM->Get(len);
if (p && (len >= TS_SIZE)) {
if (*p != TS_SYNC_BYTE) {
for (int i = 1; i < len; ++i) {
if (p[i] == TS_SYNC_BYTE) {
len = i;
break;
}
}
ringBufferM->Del(len);
debug("cIptvSectionFilterHandler::%s(%d): Skipped %d bytes to sync on TS packet", __FUNCTION__, deviceIndexM, len);
continue;
}
// Process TS packet through all filters
mutexM.Lock();
for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) {
if (filtersM[i])
filtersM[i]->Process(p);
}
mutexM.Unlock();
processedM = true;
continue;
}
}
cCondWait::SleepMs(10); // to avoid busy loop and reduce cpu load
}
debug("cIptvSectionFilterHandler::%s(%d): exiting", __FUNCTION__, deviceIndexM);
}
cString cIptvSectionFilterHandler::GetInformation(void)
{
//debug("cIptvSectionFilterHandler::%s(%d)", __FUNCTION__, deviceIndexM);
// loop through active section filters
cMutexLock MutexLock(&mutexM);
cString s = "";
unsigned int count = 0;
for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) {
if (filtersM[i]) {
s = cString::sprintf("%sFilter %d: %s Pid=0x%02X (%s)\n", *s, i,
*filtersM[i]->GetSectionStatistic(), filtersM[i]->GetPid(),
id_pid(filtersM[i]->GetPid()));
if (++count > IPTV_STATS_ACTIVE_FILTERS_COUNT)
break;
}
}
return s;
}
bool cIptvSectionFilterHandler::Delete(unsigned int indexP)
{
//debug("cIptvSectionFilterHandler::%s(%d): index=%d", __FUNCTION__, deviceIndexM, indexP);
if ((indexP < eMaxSecFilterCount) && filtersM[indexP]) {
//debug("cIptvSectionFilterHandler::%s(%d): found %d", __FUNCTION__, deviceIndexM, indexP);
cIptvSectionFilter *tmp = filtersM[indexP];
filtersM[indexP] = NULL;
delete tmp;
return true;
}
return false;
}
bool cIptvSectionFilterHandler::IsBlackListed(u_short pidP, u_char tidP, u_char maskP) const
{
//debug("cIptvSectionFilterHandler::%s(%d): pid=%d tid=%02X mask=%02X", __FUNCTION__, deviceIndexM, pidP, tidP, maskP);
// loop through section filter table
for (int i = 0; i < SECTION_FILTER_TABLE_SIZE; ++i) {
int index = IptvConfig.GetDisabledFilters(i);
// Check if matches
if ((index >= 0) && (index < SECTION_FILTER_TABLE_SIZE) &&
(section_filter_table[index].pid == pidP) && (section_filter_table[index].tid == tidP) &&
(section_filter_table[index].mask == maskP)) {
//debug("cIptvSectionFilterHandler::%s(%d): found %s", __FUNCTION__, deviceIndexM, section_filter_table[index].description);
return true;
}
}
return false;
}
int cIptvSectionFilterHandler::Open(u_short pidP, u_char tidP, u_char maskP)
{
// Lock
cMutexLock MutexLock(&mutexM);
// Blacklist check, refuse certain filters
if (IsBlackListed(pidP, tidP, maskP))
return -1;
// Search the next free filter slot
for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) {
if (!filtersM[i]) {
filtersM[i] = new cIptvSectionFilter(deviceIndexM, pidP, tidP, maskP);
debug("cIptvSectionFilterHandler::%s(%d): pid=%d tid=%02X mask=%02X handle=%d index=%d", __FUNCTION__, deviceIndexM, pidP, tidP, maskP, filtersM[i]->GetFd(), i);
return filtersM[i]->GetFd();
}
}
// No free filter slot found
return -1;
}
void cIptvSectionFilterHandler::Close(int handleP)
{
// Lock
cMutexLock MutexLock(&mutexM);
// Search the filter for deletion
for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) {
if (filtersM[i] && (handleP == filtersM[i]->GetFd())) {
debug("cIptvSectionFilterHandler::%s(%d): pid=%d handle=%d index=%d", __FUNCTION__, deviceIndexM, filtersM[i]->GetPid(), filtersM[i]->GetFd(), i);
Delete(i);
break;
}
}
}
int cIptvSectionFilterHandler::GetPid(int handleP)
{
// Lock
cMutexLock MutexLock(&mutexM);
// Search the filter for data
for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) {
if (filtersM[i] && (handleP == filtersM[i]->GetFd())) {
debug("cIptvSectionFilterHandler::%s(%d): pid=%d handle=%d index=%d", __FUNCTION__, deviceIndexM, filtersM[i]->GetPid(), filtersM[i]->GetFd(), i);
return filtersM[i]->GetPid();
}
}
return -1;
}
void cIptvSectionFilterHandler::Write(uchar *bufferP, int lengthP)
{
//debug("cIptvSectionFilterHandler::%s(%d): length=%d", __FUNCTION__, deviceIndexM, lengthP);
// Fill up the buffer
if (ringBufferM) {
int len = ringBufferM->Put(bufferP, lengthP);
if (len != lengthP)
ringBufferM->ReportOverflow(lengthP - len);
}
}

View File

@@ -35,7 +35,8 @@ private:
uint16_t tsFeedpM;
uint16_t pidM;
int devIdM;
int deviceIndexM;
int socketM[2];
uint8_t filterValueM[DMX_MAX_FILTER_SIZE];
uint8_t filterMaskM[DMX_MAX_FILTER_SIZE];
@@ -44,8 +45,6 @@ private:
uint8_t maskAndModeM[DMX_MAX_FILTER_SIZE];
uint8_t maskAndNotModeM[DMX_MAX_FILTER_SIZE];
cRingBufferLinear *ringbufferM;
inline uint16_t GetLength(const uint8_t *dataP);
void New(void);
int Filter(void);
@@ -57,8 +56,36 @@ public:
cIptvSectionFilter(int deviceIndexP, uint16_t pidP, uint8_t tidP, uint8_t maskP);
virtual ~cIptvSectionFilter();
void Process(const uint8_t* dataP);
int Read(void *bufferP, size_t lengthP);
int GetFd(void) { return socketM[0]; }
uint16_t GetPid(void) const { return pidM; }
};
class cIptvSectionFilterHandler : public cThread {
private:
enum {
eMaxSecFilterCount = 32
};
cMutex mutexM;
int deviceIndexM;
bool processedM;
cRingBufferLinear *ringBufferM;
cIptvSectionFilter *filtersM[eMaxSecFilterCount];
bool Delete(unsigned int indexP);
bool IsBlackListed(u_short pidP, u_char tidP, u_char maskP) const;
protected:
virtual void Action(void);
public:
cIptvSectionFilterHandler(int deviceIndexP, unsigned int bufferLenP);
virtual ~cIptvSectionFilterHandler();
bool Stop(void);
cString GetInformation(void);
int Open(u_short pidP, u_char tidP, u_char maskP);
void Close(int handleP);
int GetPid(int handleP);
void Write(u_char *bufferP, int lengthP);
};
#endif // __IPTV_SECTIONFILTER_H

17
setup.c
View File

@@ -115,7 +115,7 @@ cIptvPluginSetup::cIptvPluginSetup()
debug("cIptvPluginSetup::%s()", __FUNCTION__);
tsBufferSizeM = IptvConfig.GetTsBufferSize();
tsBufferPrefillM = IptvConfig.GetTsBufferPrefillRatio();
extProtocolBasePortM = IptvConfig.GetExtProtocolBasePort();
protocolBasePortM = IptvConfig.GetProtocolBasePort();
sectionFilteringM = IptvConfig.GetSectionFiltering();
numDisabledFiltersM = IptvConfig.GetDisabledFiltersCount();
if (numDisabledFiltersM > SECTION_FILTER_TABLE_SIZE)
@@ -124,6 +124,7 @@ cIptvPluginSetup::cIptvPluginSetup()
disabledFilterIndexesM[i] = IptvConfig.GetDisabledFilters(i);
disabledFilterNamesM[i] = tr(section_filter_table[i].description);
}
SetMenuCategory(mcSetupPlugins);
Setup();
SetHelp(NULL, NULL, NULL, trVDR("Button$Info"));
}
@@ -135,20 +136,20 @@ void cIptvPluginSetup::Setup(void)
Clear();
helpM.Clear();
Add(new cMenuEditIntItem( tr("TS buffer size [MB]"), &tsBufferSizeM, 1, 4));
Add(new cMenuEditIntItem(tr("TS buffer size [MB]"), &tsBufferSizeM, 1, 4));
helpM.Append(tr("Define a ringbuffer size for transport streams in megabytes.\n\nSmaller sizes help memory consumption, but are more prone to buffer overflows."));
Add(new cMenuEditIntItem( tr("TS buffer prefill ratio [%]"), &tsBufferPrefillM, 0, 40));
Add(new cMenuEditIntItem(tr("TS buffer prefill ratio [%]"), &tsBufferPrefillM, 0, 40));
helpM.Append(tr("Define a prefill ratio of the ringbuffer for transport streams before data is transferred to VDR.\n\nThis is useful if streaming media over a slow or unreliable connection."));
Add(new cMenuEditIntItem( tr("EXT protocol base port"), &extProtocolBasePortM, 0, 0xFFF7));
helpM.Append(tr("Define a base port used by EXT protocol.\n\nThe port range is defined by the number of IPTV devices. This setting sets the port which is listened for connections from external applications when using the EXT protocol."));
Add(new cMenuEditIntItem(tr("Protocol base port"), &protocolBasePortM, 0, 0xFFFF - MAXDEVICES * 2));
helpM.Append(tr("Define a base port used by CURL/EXT protocol.\n\nThe port range is defined by the number of IPTV devices. This setting sets the port which is listened for connections from external applications when using the CURL/EXT protocol."));
Add(new cMenuEditBoolItem(tr("Use section filtering"), &sectionFilteringM));
helpM.Append(tr("Define whether the section filtering shall be used.\n\nSection filtering means that IPTV plugin tries to parse and provide VDR with secondary data about the currently active stream. VDR can then use this data for providing various functionalities such as automatic pid change detection and EPG etc.\nEnabling this feature does not affect streams that do not contain section data."));
if (sectionFilteringM) {
Add(new cMenuEditIntItem( tr("Disable filters"), &numDisabledFiltersM, 0, SECTION_FILTER_TABLE_SIZE));
Add(new cMenuEditIntItem(tr("Disable filters"), &numDisabledFiltersM, 0, SECTION_FILTER_TABLE_SIZE));
helpM.Append(tr("Define number of section filters to be disabled.\n\nCertain section filters might cause some unwanted behaviour to VDR such as time being falsely synchronized. By black-listing the filters here useful section data can be left intact for VDR to process."));
for (int i = 0; i < numDisabledFiltersM; ++i) {
@@ -218,13 +219,13 @@ void cIptvPluginSetup::Store(void)
// Store values into setup.conf
SetupStore("TsBufferSize", tsBufferSizeM);
SetupStore("TsBufferPrefill", tsBufferPrefillM);
SetupStore("ExtProtocolBasePort", extProtocolBasePortM);
SetupStore("ExtProtocolBasePort", protocolBasePortM);
SetupStore("SectionFiltering", sectionFilteringM);
StoreFilters("DisabledFilters", disabledFilterIndexesM);
// Update global config
IptvConfig.SetTsBufferSize(tsBufferSizeM);
IptvConfig.SetTsBufferPrefillRatio(tsBufferPrefillM);
IptvConfig.SetExtProtocolBasePort(extProtocolBasePortM);
IptvConfig.SetProtocolBasePort(protocolBasePortM);
IptvConfig.SetSectionFiltering(sectionFilteringM);
for (int i = 0; i < SECTION_FILTER_TABLE_SIZE; ++i)
IptvConfig.SetDisabledFilters(i, disabledFilterIndexesM[i]);

View File

@@ -17,7 +17,7 @@ class cIptvPluginSetup : public cMenuSetupPage
private:
int tsBufferSizeM;
int tsBufferPrefillM;
int extProtocolBasePortM;
int protocolBasePortM;
int sectionFilteringM;
int numDisabledFiltersM;
int disabledFilterIndexesM[SECTION_FILTER_TABLE_SIZE];

View File

@@ -14,7 +14,8 @@ cSidScanner::cSidScanner(void)
: channelIdM(tChannelID::InvalidID),
sidFoundM(false),
nidFoundM(false),
tidFoundM(false)
tidFoundM(false),
isActiveM(false)
{
debug("cSidScanner::%s()", __FUNCTION__);
Set(0x00, 0x00); // PAT
@@ -26,12 +27,6 @@ cSidScanner::~cSidScanner()
debug("cSidScanner::%s()", __FUNCTION__);
}
void cSidScanner::SetStatus(bool onP)
{
debug("cSidScanner::%s(%d)", __FUNCTION__, onP);
cFilter::SetStatus(onP);
}
void cSidScanner::SetChannel(const tChannelID &channelIdP)
{
debug("cSidScanner::%s(%s)", __FUNCTION__, *channelIdP.ToString());
@@ -46,9 +41,11 @@ void cSidScanner::Process(u_short pidP, u_char tidP, const u_char *dataP, int le
int newSid = -1, newNid = -1, newTid = -1;
//debug("cSidScanner::%s()", __FUNCTION__);
if (!isActiveM)
return;
if (channelIdM.Valid()) {
if ((pidP == 0x00) && (tidP == 0x00)) {
debug("cSidScanner::%s(%d, %02X)", __FUNCTION__, pidP, tidP);
//debug("cSidScanner::%s(%d, %02X)", __FUNCTION__, pidP, tidP);
SI::PAT pat(dataP, false);
if (!pat.CheckCRCAndParse())
return;
@@ -74,15 +71,21 @@ void cSidScanner::Process(u_short pidP, u_char tidP, const u_char *dataP, int le
if (ts.getTransportStreamId() != channelIdM.Tid()) {
debug("cSidScanner::%s(): tsid=%d", __FUNCTION__, ts.getTransportStreamId());
newTid = ts.getTransportStreamId();
tidFoundM = true;
}
if (ts.getOriginalNetworkId() != channelIdM.Nid()) {
debug("cSidScanner::%s(): onid=%d", __FUNCTION__, ts.getOriginalNetworkId());
newNid = ts.getOriginalNetworkId();
nidFoundM = true;
}
tidFoundM = true;
break; // default to the first one
}
if (nit.getNetworkId() != channelIdM.Nid()) {
debug("cSidScanner::%s(): nid=%d\n", __FUNCTION__, ts.getTransportStreamId());
// fallback for network id if not found already
if (!nidFoundM && (nit.getNetworkId() != channelIdM.Nid())) {
debug("cSidScanner::%s(): nid=%d", __FUNCTION__, nit.getNetworkId());
newNid = nit.getNetworkId();
nidFoundM = true;
}
nidFoundM = true;
}
}
if ((newSid >= 0) || (newNid >= 0) || (newTid >= 0)) {

View File

@@ -17,17 +17,17 @@ private:
bool sidFoundM;
bool nidFoundM;
bool tidFoundM;
bool isActiveM;
protected:
virtual void Process(u_short pidP, u_char tidP, const u_char *dataP, int lengthP);
virtual void SetStatus(bool onP);
public:
cSidScanner(void);
~cSidScanner();
void SetChannel(const tChannelID &channelIdP);
void Open() { SetStatus(true); }
void Close() { SetStatus(false); }
void Open() { debug("cSidScanner::%s()", __FUNCTION__); isActiveM = true; }
void Close() { debug("cSidScanner::%s()", __FUNCTION__); isActiveM = false; }
};
#endif // __SIDSCANNER_H

View File

@@ -36,7 +36,7 @@ cIptvSocket::~cIptvSocket()
bool cIptvSocket::OpenSocket(const int portP, const bool isUdpP)
{
debug("cIptvSocket::%s()", __FUNCTION__);
debug("cIptvSocket::%s(%d, %d)", __FUNCTION__, portP, isUdpP);
// If socket is there already and it is bound to a different port, it must
// be closed first
if (portP != socketPortM) {
@@ -56,12 +56,12 @@ bool cIptvSocket::OpenSocket(const int portP, const bool isUdpP)
ERROR_IF_FUNC(fcntl(socketDescM, F_SETFL, O_NONBLOCK), "fcntl(O_NONBLOCK)",
CloseSocket(), return false);
// Allow multiple sockets to use the same PORT number
ERROR_IF_FUNC(setsockopt(socketDescM, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0, "setsockopt(SO_REUSEADDR)",
CloseSocket(), return false);
ERROR_IF_FUNC(setsockopt(socketDescM, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0,
"setsockopt(SO_REUSEADDR)", CloseSocket(), return false);
#ifndef __FreeBSD__
// Allow packet information to be fetched
ERROR_IF_FUNC(setsockopt(socketDescM, SOL_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0, "setsockopt(IP_PKTINFO)",
CloseSocket(), return false);
ERROR_IF_FUNC(setsockopt(socketDescM, SOL_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0,
"setsockopt(IP_PKTINFO)", CloseSocket(), return false);
#endif // __FreeBSD__
// Bind socket
memset(&sockAddrM, 0, sizeof(sockAddrM));
@@ -69,7 +69,8 @@ bool cIptvSocket::OpenSocket(const int portP, const bool isUdpP)
sockAddrM.sin_port = htons((uint16_t)(portP & 0xFFFF));
sockAddrM.sin_addr.s_addr = htonl(INADDR_ANY);
if (isUdpP)
ERROR_IF_FUNC(bind(socketDescM, (struct sockaddr *)&sockAddrM, sizeof(sockAddrM)) < 0, "bind()", CloseSocket(), return false);
ERROR_IF_FUNC(bind(socketDescM, (struct sockaddr *)&sockAddrM, sizeof(sockAddrM)) < 0,
"bind()", CloseSocket(), return false);
// Update socket port
socketPortM = portP;
}
@@ -92,17 +93,18 @@ bool cIptvSocket::CheckAddress(const char *addrP, in_addr_t *inAddrP)
{
if (inAddrP) {
// First try only the IP address
*inAddrP = htonl(inet_addr(addrP));
*inAddrP = inet_addr(addrP);
if (*inAddrP == htonl(INADDR_NONE)) {
debug("cIptvSocket::%s(%s): cannot convert to address", __FUNCTION__, addrP);
// It may be a host name, get the name
struct hostent *host = gethostbyname(addrP);
if (!host) {
char tmp[64];
error("gethostbyname() failed: %s is not valid address: %s", addrP, strerror_r(h_errno, tmp, sizeof(tmp)));
error("gethostbyname() failed: %s is not valid address: %s", addrP,
strerror_r(h_errno, tmp, sizeof(tmp)));
return false;
}
*inAddrP = htonl(inet_addr(*host->h_addr_list));
*inAddrP = inet_addr(*host->h_addr_list);
}
return true;
}
@@ -224,7 +226,7 @@ int cIptvUdpSocket::Read(unsigned char *bufferAddrP, unsigned int bufferLenP)
//debug("cIptvUdpSocket::%s()", __FUNCTION__);
// Error out if socket not initialized
if (socketDescM <= 0) {
error("Invalid socket in cIptvUdpSocket::%s()\n", __FUNCTION__);
error("Invalid socket in cIptvUdpSocket::%s()", __FUNCTION__);
return -1;
}
int len = 0;
@@ -264,22 +266,22 @@ int cIptvUdpSocket::Read(unsigned char *bufferAddrP, unsigned int bufferLenP)
else if (len > 3) {
// http://tools.ietf.org/html/rfc3550
// http://tools.ietf.org/html/rfc2250
// version
// Version
unsigned int v = (bufferAddrP[0] >> 6) & 0x03;
// extension bit
// Extension bit
unsigned int x = (bufferAddrP[0] >> 4) & 0x01;
// cscr count
// CSCR count
unsigned int cc = bufferAddrP[0] & 0x0F;
// payload type: MPEG2 TS = 33
// Payload type: MPEG2 TS = 33
//unsigned int pt = bufferAddrP[1] & 0x7F;
// header lenght
// Header lenght
unsigned int headerlen = (3 + cc) * (unsigned int)sizeof(uint32_t);
// check if extension
// Check if extension
if (x) {
// extension header length
// Extension header length
unsigned int ehl = (((bufferAddrP[headerlen + 2] & 0xFF) << 8) |
(bufferAddrP[headerlen + 3] & 0xFF));
// update header length
// Update header length
headerlen += (ehl + 1) * (unsigned int)sizeof(uint32_t);
}
// Check that rtp is version 2 and payload contains multiple of TS packet data
@@ -357,7 +359,7 @@ int cIptvTcpSocket::Read(unsigned char *bufferAddrP, unsigned int bufferLenP)
//debug("cIptvTcpSocket::%s()", __FUNCTION__);
// Error out if socket not initialized
if (socketDescM <= 0) {
error("Invalid socket in cIptvTcpSocket::%s()\n", __FUNCTION__);
error("Invalid socket in cIptvTcpSocket::%s()", __FUNCTION__);
return -1;
}
int len = 0;
@@ -374,7 +376,7 @@ bool cIptvTcpSocket::ReadChar(char *bufferAddrP, unsigned int timeoutMsP)
//debug("cIptvTcpSocket::%s()", __FUNCTION__);
// Error out if socket not initialized
if (socketDescM <= 0) {
error("Invalid socket in cIptvTcpSocket::%s()\n", __FUNCTION__);
error("Invalid socket in cIptvTcpSocket::%s()", __FUNCTION__);
return false;
}
socklen_t addrlen = sizeof(sockAddrM);
@@ -399,7 +401,7 @@ bool cIptvTcpSocket::Write(const char *bufferAddrP, unsigned int bufferLenP)
//debug("cIptvTcpSocket::%s()", __FUNCTION__);
// Error out if socket not initialized
if (socketDescM <= 0) {
error("Invalid socket in cIptvTcpSocket::%s()\n", __FUNCTION__);
error("Invalid socket in cIptvTcpSocket::%s()", __FUNCTION__);
return false;
}
ERROR_IF_RET(send(socketDescM, bufferAddrP, bufferLenP, 0) < 0, "send()", return false);

View File

@@ -5,6 +5,7 @@
*
*/
#include <ctype.h>
#include "common.h"
#include "source.h"
@@ -57,6 +58,7 @@ bool cIptvTransponderParameters::Parse(const char *strP)
if (strP && *strP) {
const char *delim = "|";
char *str = strdup(strP);
char *p = str;
char *saveptr = NULL;
char *token = NULL;
bool found_s = false;
@@ -70,7 +72,7 @@ bool cIptvTransponderParameters::Parse(const char *strP)
++data;
if (data && (*data == '=')) {
++data;
switch (*token) {
switch (toupper(*token)) {
case 'S':
sidScanM = (int)strtol(data, (char **)NULL, 10);
found_s = true;
@@ -119,9 +121,9 @@ bool cIptvTransponderParameters::Parse(const char *strP)
if (found_s && found_p && found_f && found_u && found_a)
result = true;
else
error("Invalid channel parameters: %s\n", str);
error("Invalid channel parameters: %s", p);
free(str);
free(p);
}
return (result);
@@ -163,9 +165,8 @@ void cIptvSourceParam::SetData(cChannel *channelP)
void cIptvSourceParam::GetData(cChannel *channelP)
{
debug("cIptvSourceParam::%s(%s)", __FUNCTION__, channelP->Parameters());
dataM.SetTransponderData(channelP->Source(), channelP->Frequency(), dataM.Srate(), itpM.ToString(Source()), true);
dataM.SetId(nidM, tidM, channelP->Sid(), ridM);
*channelP = dataM;
channelP->SetTransponderData(channelP->Source(), channelP->Frequency(), dataM.Srate(), itpM.ToString(Source()), true);
channelP->SetId(nidM, tidM, channelP->Sid(), ridM);
}
cOsdItem *cIptvSourceParam::GetOsdItem(void)

View File

@@ -20,7 +20,7 @@ private:
int sidScanM;
int pidScanM;
int protocolM;
char addressM[NAME_MAX];
char addressM[NAME_MAX + 1];
int parameterM;
public:

View File

@@ -44,7 +44,7 @@ cString cIptvSectionStatistics::GetSectionStatistic()
void cIptvSectionStatistics::AddSectionStatistic(long bytesP, long callsP)
{
//debug("cIptvSectionStatistics::%s(%ld, %ld)", __FUNCTION__, bytesP, callsP);
//debug("cIptvSectionStatistics::%s(%ld, %ld)", __FUNCTION__, bytesP, callsP);
cMutexLock MutexLock(&mutexM);
filteredDataM += bytesP;
numberOfCallsM += callsP;
@@ -58,7 +58,11 @@ cIptvPidStatistics::cIptvPidStatistics()
mutexM()
{
debug("cIptvPidStatistics::%s()", __FUNCTION__);
memset(mostActivePidsM, 0, sizeof(mostActivePidsM));
const int numberOfElements = sizeof(mostActivePidsM) / sizeof(pidStruct);
for (int i = 0; i < numberOfElements; ++i) {
mostActivePidsM[i].pid = -1;
mostActivePidsM[i].dataAmount = 0L;
}
}
cIptvPidStatistics::~cIptvPidStatistics()
@@ -70,12 +74,13 @@ cString cIptvPidStatistics::GetPidStatistic()
{
//debug("cIptvPidStatistics::%s()", __FUNCTION__);
cMutexLock MutexLock(&mutexM);
const int numberOfElements = sizeof(mostActivePidsM) / sizeof(pidStruct);
uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
timerM.Set();
cString s("Active pids:\n");
for (unsigned int i = 0; i < IPTV_STATS_ACTIVE_PIDS_COUNT; ++i) {
if (mostActivePidsM[i].pid) {
long bitrate = elapsed ? (long)(1000.0L * mostActivePidsM[i].DataAmount / KILOBYTE(1) / elapsed) : 0L;
for (int i = 0; i < numberOfElements; ++i) {
if (mostActivePidsM[i].pid >= 0) {
long bitrate = elapsed ? (long)(1000.0L * mostActivePidsM[i].dataAmount / KILOBYTE(1) / elapsed) : 0L;
if (!IptvConfig.GetUseBytes())
bitrate *= 8;
s = cString::sprintf("%sPid %d: %4d (%4ld k%s/s)\n", *s, i,
@@ -83,7 +88,10 @@ cString cIptvPidStatistics::GetPidStatistic()
IptvConfig.GetUseBytes() ? "B" : "bit");
}
}
memset(mostActivePidsM, 0, sizeof(mostActivePidsM));
for (int i = 0; i < numberOfElements; ++i) {
mostActivePidsM[i].pid = -1;
mostActivePidsM[i].dataAmount = 0L;
}
return s;
}
@@ -92,14 +100,14 @@ int cIptvPidStatistics::SortPids(const void* data1P, const void* data2P)
//debug("cIptvPidStatistics::%s()", __FUNCTION__);
const pidStruct *comp1 = reinterpret_cast<const pidStruct*>(data1P);
const pidStruct *comp2 = reinterpret_cast<const pidStruct*>(data2P);
if (comp1->DataAmount > comp2->DataAmount)
if (comp1->dataAmount > comp2->dataAmount)
return -1;
if (comp1->DataAmount < comp2->DataAmount)
if (comp1->dataAmount < comp2->dataAmount)
return 1;
return 0;
}
void cIptvPidStatistics::AddPidStatistic(u_short pidP, long payloadP)
void cIptvPidStatistics::AddPidStatistic(int pidP, long payloadP)
{
//debug("cIptvPidStatistics::%s(%ld, %ld)", __FUNCTION__, pidP, payloadP);
cMutexLock MutexLock(&mutexM);
@@ -107,7 +115,7 @@ void cIptvPidStatistics::AddPidStatistic(u_short pidP, long payloadP)
// If our statistic already is in the array, update it and quit
for (int i = 0; i < numberOfElements; ++i) {
if (mostActivePidsM[i].pid == pidP) {
mostActivePidsM[i].DataAmount += payloadP;
mostActivePidsM[i].dataAmount += payloadP;
// Now re-sort the array and quit
qsort(mostActivePidsM, numberOfElements, sizeof(pidStruct), SortPids);
return;
@@ -115,9 +123,9 @@ void cIptvPidStatistics::AddPidStatistic(u_short pidP, long payloadP)
}
// Apparently our pid isn't in the array. Replace the last element with this
// one if new payload is greater
if (mostActivePidsM[numberOfElements - 1].DataAmount < payloadP) {
if (mostActivePidsM[numberOfElements - 1].dataAmount < payloadP) {
mostActivePidsM[numberOfElements - 1].pid = pidP;
mostActivePidsM[numberOfElements - 1].DataAmount = payloadP;
mostActivePidsM[numberOfElements - 1].dataAmount = payloadP;
// Re-sort
qsort(mostActivePidsM, numberOfElements, sizeof(pidStruct), SortPids);
}

View File

@@ -35,12 +35,12 @@ public:
cString GetPidStatistic();
protected:
void AddPidStatistic(u_short pidP, long payloadP);
void AddPidStatistic(int pidP, long payloadP);
private:
struct pidStruct {
u_short pid;
long DataAmount;
int pid;
long dataAmount;
};
pidStruct mostActivePidsM[IPTV_STATS_ACTIVE_PIDS_COUNT];
cTimeMs timerM;

View File

@@ -5,15 +5,13 @@
*
*/
#include <vdr/thread.h>
#include <vdr/ringbuffer.h>
#include "common.h"
#include "streamer.h"
cIptvStreamer::cIptvStreamer(cRingBufferLinear* ringBufferP, unsigned int packetLenP)
cIptvStreamer::cIptvStreamer(cIptvDeviceIf &deviceP, unsigned int packetLenP)
: cThread("IPTV streamer"),
ringBufferM(ringBufferP),
sleepM(),
deviceM(&deviceP),
packetBufferLenM(packetLenP),
protocolM(NULL)
{
@@ -32,7 +30,6 @@ cIptvStreamer::~cIptvStreamer()
// Close the protocol
Close();
protocolM = NULL;
ringBufferM = NULL;
// Free allocated memory
free(packetBufferM);
}
@@ -45,15 +42,12 @@ void cIptvStreamer::Action(void)
// Do the thread loop
while (packetBufferM && Running()) {
int length = -1;
if (protocolM)
length = protocolM->Read(packetBufferM, min((unsigned int)ringBufferM->Free(), packetBufferLenM));
unsigned int size = min(deviceM->CheckData(), packetBufferLenM);
if (protocolM && (size > 0))
length = protocolM->Read(packetBufferM, size);
if (length > 0) {
AddStreamerStatistic(length);
if (ringBufferM) {
int p = ringBufferM->Put(packetBufferM, length);
if (p != length)
ringBufferM->ReportOverflow(length - p);
}
deviceM->WriteData(packetBufferM, length);
}
else
sleepM.Wait(10); // to avoid busy loop and reduce cpu load
@@ -85,7 +79,7 @@ bool cIptvStreamer::Close(void)
return true;
}
bool cIptvStreamer::Set(const char* locationP, const int parameterP, const int indexP, cIptvProtocolIf* protocolP)
bool cIptvStreamer::SetSource(const char* locationP, const int parameterP, const int indexP, cIptvProtocolIf* protocolP)
{
debug("cIptvStreamer::%s(%s, %d, %d)", __FUNCTION__, locationP, parameterP, indexP);
if (!isempty(locationP)) {
@@ -95,16 +89,24 @@ bool cIptvStreamer::Set(const char* locationP, const int parameterP, const int i
protocolM->Close();
protocolM = protocolP;
if (protocolM) {
protocolM->Set(locationP, parameterP, indexP);
protocolM->SetSource(locationP, parameterP, indexP);
protocolM->Open();
}
}
else if (protocolM)
protocolM->Set(locationP, parameterP, indexP);
protocolM->SetSource(locationP, parameterP, indexP);
}
return true;
}
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;
}
cString cIptvStreamer::GetInformation(void)
{
//debug("cIptvStreamer::%s()", __FUNCTION__);

View File

@@ -11,15 +11,15 @@
#include <arpa/inet.h>
#include <vdr/thread.h>
#include <vdr/ringbuffer.h>
#include "deviceif.h"
#include "protocolif.h"
#include "statistics.h"
class cIptvStreamer : public cThread, public cIptvStreamerStatistics {
private:
cRingBufferLinear* ringBufferM;
cCondWait sleepM;
cIptvDeviceIf* deviceM;
unsigned char* packetBufferM;
unsigned int packetBufferLenM;
cIptvProtocolIf* protocolM;
@@ -28,9 +28,10 @@ protected:
virtual void Action(void);
public:
cIptvStreamer(cRingBufferLinear* ringBufferP, unsigned int packetLenP);
cIptvStreamer(cIptvDeviceIf &deviceP, unsigned int packetLenP);
virtual ~cIptvStreamer();
bool Set(const char* locationP, const int parameterP, const int indexP, cIptvProtocolIf* protocolP);
bool SetSource(const char* locationP, const int parameterP, const int indexP, cIptvProtocolIf* protocolP);
bool SetPid(int pidP, int typeP, bool onP);
bool Open(void);
bool Close(void);
cString GetInformation(void);