mirror of
https://github.com/rofafor/vdr-plugin-iptv.git
synced 2023-10-10 13:37:03 +02:00
Reformatted debug messages.
This commit is contained in:
parent
e75080b1a8
commit
26a0adceb5
4
config.c
4
config.c
@ -18,7 +18,7 @@ cIptvConfig::cIptvConfig(void)
|
||||
{
|
||||
for (unsigned int i = 0; i < ARRAY_SIZE(disabledFiltersM); ++i)
|
||||
disabledFiltersM[i] = -1;
|
||||
memset(configDirectoryM, '\0', sizeof(configDirectoryM));
|
||||
memset(configDirectoryM, 0, sizeof(configDirectoryM));
|
||||
}
|
||||
|
||||
unsigned int cIptvConfig::GetDisabledFiltersCount(void) const
|
||||
@ -42,6 +42,6 @@ void cIptvConfig::SetDisabledFilters(unsigned int indexP, int numberP)
|
||||
|
||||
void cIptvConfig::SetConfigDirectory(const char *directoryP)
|
||||
{
|
||||
debug("cIptvConfig::SetConfigDirectory(%s)\n", directoryP);
|
||||
debug("cIptvConfig::%s(%s)", __FUNCTION__, directoryP);
|
||||
ERROR_IF(!realpath(directoryP, configDirectoryM), "Cannot canonicalize configuration directory");
|
||||
}
|
||||
|
60
device.c
60
device.c
@ -57,7 +57,7 @@ cIptvDevice::cIptvDevice(unsigned int indexP)
|
||||
|
||||
cIptvDevice::~cIptvDevice()
|
||||
{
|
||||
debug("cIptvDevice::~cIptvDevice(%d)\n", deviceIndexM);
|
||||
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
// Stop section handler of iptv device
|
||||
StopSectionHandler();
|
||||
DELETE_POINTER(pIptvStreamerM);
|
||||
@ -86,7 +86,7 @@ cIptvDevice::~cIptvDevice()
|
||||
|
||||
bool cIptvDevice::Initialize(unsigned int deviceCountP)
|
||||
{
|
||||
debug("cIptvDevice::Initialize(): DeviceCount=%d\n", deviceCountP);
|
||||
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceCountP);
|
||||
new cIptvSourceParam(IPTV_SOURCE_CHARACTER, "IPTV");
|
||||
if (deviceCountP > IPTV_MAX_DEVICES)
|
||||
deviceCountP = IPTV_MAX_DEVICES;
|
||||
@ -100,7 +100,7 @@ bool cIptvDevice::Initialize(unsigned int deviceCountP)
|
||||
unsigned int cIptvDevice::Count(void)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
debug("cIptvDevice::Count()\n");
|
||||
debug("cIptvDevice::%s()", __FUNCTION__);
|
||||
for (unsigned int i = 0; i < IPTV_MAX_DEVICES; ++i) {
|
||||
if (IptvDevicesS[i] != NULL)
|
||||
count++;
|
||||
@ -110,10 +110,10 @@ unsigned int cIptvDevice::Count(void)
|
||||
|
||||
cIptvDevice *cIptvDevice::GetIptvDevice(int cardIndexP)
|
||||
{
|
||||
//debug("cIptvDevice::GetIptvDevice(%d)\n", 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)) {
|
||||
//debug("cIptvDevice::GetIptvDevice(%d): FOUND!\n", cardIndexP);
|
||||
//debug("cIptvDevice::%s(%d): found!", __FUNCTION__, cardIndexP);
|
||||
return IptvDevicesS[i];
|
||||
}
|
||||
}
|
||||
@ -122,7 +122,7 @@ cIptvDevice *cIptvDevice::GetIptvDevice(int cardIndexP)
|
||||
|
||||
cString cIptvDevice::GetGeneralInformation(void)
|
||||
{
|
||||
//debug("cIptvDevice::GetGeneralInformation(%d)\n", deviceIndexM);
|
||||
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
return cString::sprintf("IPTV device: %d\nCardIndex: %d\nStream: %s\nStream bitrate: %s\n%sChannel: %s",
|
||||
deviceIndexM, CardIndex(),
|
||||
pIptvStreamerM ? *pIptvStreamerM->GetInformation() : "",
|
||||
@ -133,13 +133,13 @@ cString cIptvDevice::GetGeneralInformation(void)
|
||||
|
||||
cString cIptvDevice::GetPidsInformation(void)
|
||||
{
|
||||
//debug("cIptvDevice::GetPidsInformation(%d)\n", deviceIndexM);
|
||||
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
return GetPidStatistic();
|
||||
}
|
||||
|
||||
cString cIptvDevice::GetFiltersInformation(void)
|
||||
{
|
||||
//debug("cIptvDevice::GetFiltersInformation(%d)\n", deviceIndexM);
|
||||
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
unsigned int count = 0;
|
||||
cString s("Active section filters:\n");
|
||||
// loop through active section filters
|
||||
@ -187,37 +187,37 @@ cString cIptvDevice::GetInformation(unsigned int pageP)
|
||||
|
||||
cString cIptvDevice::DeviceType(void) const
|
||||
{
|
||||
debug("cIptvDevice::DeviceType(%d)\n", deviceIndexM);
|
||||
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
return "IPTV";
|
||||
}
|
||||
|
||||
cString cIptvDevice::DeviceName(void) const
|
||||
{
|
||||
debug("cIptvDevice::DeviceName(%d)\n", deviceIndexM);
|
||||
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
return cString::sprintf("IPTV %d", deviceIndexM);
|
||||
}
|
||||
|
||||
int cIptvDevice::SignalStrength(void) const
|
||||
{
|
||||
debug("cIptvDevice::SignalStrength(%d)\n", deviceIndexM);
|
||||
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
return (100);
|
||||
}
|
||||
|
||||
int cIptvDevice::SignalQuality(void) const
|
||||
{
|
||||
debug("cIptvDevice::SignalQuality(%d)\n", deviceIndexM);
|
||||
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
return (100);
|
||||
}
|
||||
|
||||
bool cIptvDevice::ProvidesSource(int sourceP) const
|
||||
{
|
||||
debug("cIptvDevice::ProvidesSource(%d)\n", deviceIndexM);
|
||||
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
return (cSource::IsType(sourceP, IPTV_SOURCE_CHARACTER));
|
||||
}
|
||||
|
||||
bool cIptvDevice::ProvidesTransponder(const cChannel *channelP) const
|
||||
{
|
||||
debug("cIptvDevice::ProvidesTransponder(%d)\n", deviceIndexM);
|
||||
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
return (ProvidesSource(channelP->Source()));
|
||||
}
|
||||
|
||||
@ -227,7 +227,7 @@ bool cIptvDevice::ProvidesChannel(const cChannel *channelP, int priorityP, bool
|
||||
bool hasPriority = (priorityP == IDLEPRIORITY) || (priorityP > this->Priority());
|
||||
bool needsDetachReceivers = false;
|
||||
|
||||
debug("cIptvDevice::ProvidesChannel(%d)\n", deviceIndexM);
|
||||
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
|
||||
if (channelP && ProvidesTransponder(channelP)) {
|
||||
result = hasPriority;
|
||||
@ -258,7 +258,7 @@ bool cIptvDevice::SetChannelDevice(const cChannel *channelP, bool liveViewP)
|
||||
cIptvProtocolIf *protocol;
|
||||
cIptvTransponderParameters itp(channelP->Parameters());
|
||||
|
||||
debug("cIptvDevice::SetChannelDevice(%d)\n", deviceIndexM);
|
||||
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
|
||||
if (isempty(itp.Address())) {
|
||||
error("Unrecognized IPTV address: %s", channelP->Parameters());
|
||||
@ -299,14 +299,14 @@ bool cIptvDevice::SetChannelDevice(const cChannel *channelP, bool liveViewP)
|
||||
|
||||
bool cIptvDevice::SetPid(cPidHandle *handleP, int typeP, bool onP)
|
||||
{
|
||||
debug("cIptvDevice::SetPid(%d) Pid=%d Type=%d On=%d\n", deviceIndexM, handleP->pid, typeP, onP);
|
||||
debug("cIptvDevice::%s(%d): pid=%d type=%d on=%d", __FUNCTION__, deviceIndexM, handleP->pid, typeP, onP);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cIptvDevice::DeleteFilter(unsigned int indexP)
|
||||
{
|
||||
if ((indexP < eMaxSecFilterCount) && secFiltersM[indexP]) {
|
||||
//debug("cIptvDevice::DeleteFilter(%d) Index=%d\n", deviceIndexM, indexP);
|
||||
//debug("cIptvDevice::%s(%d): index=%d", __FUNCTION__, deviceIndexM, indexP);
|
||||
cIptvSectionFilter *tmp = secFiltersM[indexP];
|
||||
secFiltersM[indexP] = NULL;
|
||||
delete tmp;
|
||||
@ -317,7 +317,7 @@ bool cIptvDevice::DeleteFilter(unsigned int indexP)
|
||||
|
||||
bool cIptvDevice::IsBlackListed(u_short pidP, u_char tidP, u_char maskP) const
|
||||
{
|
||||
//debug("cIptvDevice::IsBlackListed(%d) Pid=%d Tid=%02X Mask=%02X\n", deviceIndexM, pidP, tidP, maskP);
|
||||
//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);
|
||||
@ -325,7 +325,7 @@ bool cIptvDevice::IsBlackListed(u_short pidP, u_char tidP, u_char maskP) const
|
||||
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::IsBlackListed(%d) Found=%s\n", deviceIndexM, section_filter_table[index].description);
|
||||
//debug("cIptvDevice::%s(%d): found %s", __FUNCTION__, deviceIndexM, section_filter_table[index].description);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -345,7 +345,7 @@ int cIptvDevice::OpenFilter(u_short pidP, u_char tidP, u_char maskP)
|
||||
// Search the next free filter slot
|
||||
for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) {
|
||||
if (!secFiltersM[i]) {
|
||||
//debug("cIptvDevice::OpenFilter(%d): Pid=%d Tid=%02X Mask=%02X Index=%d\n", deviceIndexM, pidP, tidP, maskP, 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;
|
||||
@ -363,7 +363,7 @@ int cIptvDevice::ReadFilter(int handleP, void *bufferP, size_t lengthP)
|
||||
// ... and load
|
||||
if (secFiltersM[handleP]) {
|
||||
return secFiltersM[handleP]->Read(bufferP, lengthP);
|
||||
//debug("cIptvDevice::ReadFilter(%d): %d %d\n", deviceIndexM, handleP, lengthP);
|
||||
//debug("cIptvDevice::%s(%d): handle=%d length=%d", __FUNCTION__, deviceIndexM, handleP, lengthP);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -374,14 +374,14 @@ void cIptvDevice::CloseFilter(int handleP)
|
||||
cMutexLock MutexLock(&mutexM);
|
||||
// ... and load
|
||||
if (secFiltersM[handleP]) {
|
||||
//debug("cIptvDevice::CloseFilter(%d): %d\n", deviceIndexM, handleP);
|
||||
//debug("cIptvDevice::%s(%d): handle=%d", __FUNCTION__, deviceIndexM, handleP);
|
||||
DeleteFilter(handleP);
|
||||
}
|
||||
}
|
||||
|
||||
bool cIptvDevice::OpenDvr(void)
|
||||
{
|
||||
debug("cIptvDevice::OpenDvr(%d)\n", deviceIndexM);
|
||||
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
isPacketDeliveredM = false;
|
||||
tsBufferM->Clear();
|
||||
ResetBuffering();
|
||||
@ -395,7 +395,7 @@ bool cIptvDevice::OpenDvr(void)
|
||||
|
||||
void cIptvDevice::CloseDvr(void)
|
||||
{
|
||||
debug("cIptvDevice::CloseDvr(%d)\n", deviceIndexM);
|
||||
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
if (sidScanEnabledM && pSidScannerM && IptvConfig.GetSectionFiltering())
|
||||
pSidScannerM->Close();
|
||||
if (pIptvStreamerM)
|
||||
@ -405,19 +405,19 @@ void cIptvDevice::CloseDvr(void)
|
||||
|
||||
bool cIptvDevice::HasLock(int timeoutMsP) const
|
||||
{
|
||||
//debug("cIptvDevice::HasLock(%d): %d\n", deviceIndexM, timeoutMsP);
|
||||
//debug("cIptvDevice::%s(%d): timeoutMs=%d", __FUNCTION__, deviceIndexM, timeoutMsP);
|
||||
return (!IsBuffering());
|
||||
}
|
||||
|
||||
bool cIptvDevice::HasInternalCam(void)
|
||||
{
|
||||
//debug("cIptvDevice::HasInternalCam(%d)\n", deviceIndexM);
|
||||
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
return true;
|
||||
}
|
||||
|
||||
void cIptvDevice::ResetBuffering(void)
|
||||
{
|
||||
debug("cIptvDevice::ResetBuffering(%d)\n", deviceIndexM);
|
||||
debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
// pad prefill to multiple of TS_SIZE
|
||||
tsBufferPrefillM = (unsigned int)MEGABYTE(IptvConfig.GetTsBufferSize()) *
|
||||
IptvConfig.GetTsBufferPrefillRatio() / 100;
|
||||
@ -426,7 +426,7 @@ void cIptvDevice::ResetBuffering(void)
|
||||
|
||||
bool cIptvDevice::IsBuffering(void) const
|
||||
{
|
||||
//debug("cIptvDevice::IsBuffering(%d): %d\n", deviceIndexM);
|
||||
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
if (tsBufferPrefillM && tsBufferM && tsBufferM->Available() < tsBufferPrefillM)
|
||||
return true;
|
||||
else
|
||||
@ -436,7 +436,7 @@ bool cIptvDevice::IsBuffering(void) const
|
||||
|
||||
bool cIptvDevice::GetTSPacket(uchar *&Data)
|
||||
{
|
||||
//debug("cIptvDevice::GetTSPacket(%d)\n", deviceIndexM);
|
||||
//debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM);
|
||||
if (tsBufferM && !IsBuffering()) {
|
||||
if (isPacketDeliveredM) {
|
||||
tsBufferM->Del(TS_SIZE);
|
||||
|
38
iptv.c
38
iptv.c
@ -54,7 +54,7 @@ public:
|
||||
cPluginIptv::cPluginIptv(void)
|
||||
: deviceCountM(1)
|
||||
{
|
||||
//debug("cPluginIptv::cPluginIptv()\n");
|
||||
//debug("cPluginIptv::%s()", __FUNCTION__);
|
||||
// Initialize any member variables here.
|
||||
// DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
|
||||
// VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
|
||||
@ -62,20 +62,20 @@ cPluginIptv::cPluginIptv(void)
|
||||
|
||||
cPluginIptv::~cPluginIptv()
|
||||
{
|
||||
//debug("cPluginIptv::~cPluginIptv()\n");
|
||||
//debug("cPluginIptv::%s()", __FUNCTION__);
|
||||
// Clean up after yourself!
|
||||
}
|
||||
|
||||
const char *cPluginIptv::CommandLineHelp(void)
|
||||
{
|
||||
debug("cPluginIptv::CommandLineHelp()\n");
|
||||
debug("cPluginIptv::%s()", __FUNCTION__);
|
||||
// Return a string that describes all known command line options.
|
||||
return " -d <num>, --devices=<number> number of devices to be created\n";
|
||||
}
|
||||
|
||||
bool cPluginIptv::ProcessArgs(int argc, char *argv[])
|
||||
{
|
||||
debug("cPluginIptv::ProcessArgs()\n");
|
||||
debug("cPluginIptv::%s()", __FUNCTION__);
|
||||
// Implement command line argument processing here if applicable.
|
||||
static const struct option long_options[] = {
|
||||
{ "devices", required_argument, NULL, 'd' },
|
||||
@ -97,7 +97,7 @@ bool cPluginIptv::ProcessArgs(int argc, char *argv[])
|
||||
|
||||
bool cPluginIptv::Initialize(void)
|
||||
{
|
||||
debug("cPluginIptv::Initialize()\n");
|
||||
debug("cPluginIptv::%s()", __FUNCTION__);
|
||||
// Initialize any background activities the plugin shall perform.
|
||||
IptvConfig.SetConfigDirectory(cPlugin::ResourceDirectory(PLUGIN_NAME_I18N));
|
||||
return cIptvDevice::Initialize(deviceCountM);
|
||||
@ -105,7 +105,7 @@ bool cPluginIptv::Initialize(void)
|
||||
|
||||
bool cPluginIptv::Start(void)
|
||||
{
|
||||
debug("cPluginIptv::Start()\n");
|
||||
debug("cPluginIptv::%s()", __FUNCTION__);
|
||||
// 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);
|
||||
@ -116,61 +116,61 @@ bool cPluginIptv::Start(void)
|
||||
|
||||
void cPluginIptv::Stop(void)
|
||||
{
|
||||
debug("cPluginIptv::Stop()\n");
|
||||
debug("cPluginIptv::%s()", __FUNCTION__);
|
||||
// Stop any background activities the plugin is performing.
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
void cPluginIptv::Housekeeping(void)
|
||||
{
|
||||
//debug("cPluginIptv::Housekeeping()\n");
|
||||
//debug("cPluginIptv::%s()", __FUNCTION__);
|
||||
// Perform any cleanup or other regular tasks.
|
||||
}
|
||||
|
||||
void cPluginIptv::MainThreadHook(void)
|
||||
{
|
||||
//debug("cPluginIptv::MainThreadHook()\n");
|
||||
//debug("cPluginIptv::%s()", __FUNCTION__);
|
||||
// Perform actions in the context of the main program thread.
|
||||
// WARNING: Use with great care - see PLUGINS.html!
|
||||
}
|
||||
|
||||
cString cPluginIptv::Active(void)
|
||||
{
|
||||
//debug("cPluginIptv::Active()\n");
|
||||
//debug("cPluginIptv::%s()", __FUNCTION__);
|
||||
// Return a message string if shutdown should be postponed
|
||||
return NULL;
|
||||
}
|
||||
|
||||
time_t cPluginIptv::WakeupTime(void)
|
||||
{
|
||||
//debug("cPluginIptv::WakeupTime()\n");
|
||||
//debug("cPluginIptv::%s()", __FUNCTION__);
|
||||
// Return custom wakeup time for shutdown script
|
||||
return 0;
|
||||
}
|
||||
|
||||
cOsdObject *cPluginIptv::MainMenuAction(void)
|
||||
{
|
||||
//debug("cPluginIptv::MainMenuAction()\n");
|
||||
//debug("cPluginIptv::%s()", __FUNCTION__);
|
||||
// Perform the action when selected from the main VDR menu.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cMenuSetupPage *cPluginIptv::SetupMenu(void)
|
||||
{
|
||||
debug("cPluginIptv::SetupMenu()\n");
|
||||
debug("cPluginIptv::%s()", __FUNCTION__);
|
||||
// Return a setup menu in case the plugin supports one.
|
||||
return new cIptvPluginSetup();
|
||||
}
|
||||
|
||||
int cPluginIptv::ParseFilters(const char *valueP, int *filtersP)
|
||||
{
|
||||
debug("cPluginIptv::ParseFilters(%s)\n", valueP);
|
||||
debug("cPluginIptv::%s(%s)", __FUNCTION__, valueP);
|
||||
char buffer[256];
|
||||
int n = 0;
|
||||
while (valueP && *valueP && (n < SECTION_FILTER_TABLE_SIZE)) {
|
||||
strn0cpy(buffer, valueP, sizeof(buffer));
|
||||
int i = atoi(buffer);
|
||||
//debug("cPluginIptv::ParseFilters(): Filters[%d]=%d\n", n, i);
|
||||
//debug("cPluginIptv::%s(): filters[%d]=%d", __FUNCTION__, n, i);
|
||||
if (i >= 0)
|
||||
filtersP[n++] = i;
|
||||
if ((valueP = strchr(valueP, ' ')) != NULL)
|
||||
@ -181,7 +181,7 @@ int cPluginIptv::ParseFilters(const char *valueP, int *filtersP)
|
||||
|
||||
bool cPluginIptv::SetupParse(const char *nameP, const char *valueP)
|
||||
{
|
||||
debug("cPluginIptv::SetupParse()\n");
|
||||
debug("cPluginIptv::%s()", __FUNCTION__);
|
||||
// Parse your own setup parameters and store their values.
|
||||
if (!strcasecmp(nameP, "TsBufferSize"))
|
||||
IptvConfig.SetTsBufferSize(atoi(valueP));
|
||||
@ -206,7 +206,7 @@ bool cPluginIptv::SetupParse(const char *nameP, const char *valueP)
|
||||
|
||||
bool cPluginIptv::Service(const char *idP, void *dataP)
|
||||
{
|
||||
debug("cPluginIptv::Service()\n");
|
||||
debug("cPluginIptv::%s()", __FUNCTION__);
|
||||
if (strcmp(idP,"IptvService-v1.0") == 0) {
|
||||
if (dataP) {
|
||||
IptvService_v1_0 *data = reinterpret_cast<IptvService_v1_0*>(dataP);
|
||||
@ -223,7 +223,7 @@ bool cPluginIptv::Service(const char *idP, void *dataP)
|
||||
|
||||
const char **cPluginIptv::SVDRPHelpPages(void)
|
||||
{
|
||||
debug("cPluginIptv::SVDRPHelpPages()\n");
|
||||
debug("cPluginIptv::%s()", __FUNCTION__);
|
||||
static const char *HelpPages[] = {
|
||||
"INFO [ <page> ]\n"
|
||||
" Print IPTV device information and statistics.\n"
|
||||
@ -238,7 +238,7 @@ const char **cPluginIptv::SVDRPHelpPages(void)
|
||||
|
||||
cString cPluginIptv::SVDRPCommand(const char *commandP, const char *optionP, int &replyCodeP)
|
||||
{
|
||||
debug("cPluginIptv::SVDRPCommand('%s', %s')\n", commandP, optionP);
|
||||
debug("cPluginIptv::%s(%s, %s)", __FUNCTION__, commandP, optionP);
|
||||
if (strcasecmp(commandP, "INFO") == 0) {
|
||||
cIptvDevice *device = cIptvDevice::GetIptvDevice(cDevice::ActualDevice()->CardIndex());
|
||||
if (device) {
|
||||
|
20
pidscanner.c
20
pidscanner.c
@ -22,17 +22,17 @@ cPidScanner::cPidScanner(void)
|
||||
numVpidsM(0),
|
||||
numApidsM(0)
|
||||
{
|
||||
debug("cPidScanner::cPidScanner()\n");
|
||||
debug("cPidScanner::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
cPidScanner::~cPidScanner()
|
||||
{
|
||||
debug("cPidScanner::~cPidScanner()\n");
|
||||
debug("cPidScanner::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
void cPidScanner::SetChannel(const tChannelID &channelIdP)
|
||||
{
|
||||
debug("cPidScanner::SetChannel(): %s\n", *channelIdP.ToString());
|
||||
debug("cPidScanner::%s(%s)", __FUNCTION__, *channelIdP.ToString());
|
||||
channelIdM = channelIdP;
|
||||
vPidM = 0xFFFF;
|
||||
numVpidsM = 0;
|
||||
@ -44,13 +44,13 @@ void cPidScanner::SetChannel(const tChannelID &channelIdP)
|
||||
|
||||
void cPidScanner::Process(const uint8_t* bufP)
|
||||
{
|
||||
//debug("cPidScanner::Process()\n");
|
||||
//debug("cPidScanner::%s()", __FUNCTION__);
|
||||
if (!processM)
|
||||
return;
|
||||
|
||||
// Stop scanning after defined timeout
|
||||
if (timeoutM.TimedOut()) {
|
||||
debug("cPidScanner::Process: Timed out determining pids\n");
|
||||
debug("cPidScanner::%s(): timed out determining pids", __FUNCTION__);
|
||||
processM = false;
|
||||
}
|
||||
|
||||
@ -85,24 +85,24 @@ void cPidScanner::Process(const uint8_t* bufP)
|
||||
// Stream ID
|
||||
if ((sid >= 0xC0) && (sid <= 0xDF)) {
|
||||
if (pid < aPidM) {
|
||||
debug("cPidScanner::Process: Found lower Apid: 0x%X instead of 0x%X\n", pid, aPidM);
|
||||
debug("cPidScanner::%s(): found lower Apid: 0x%X instead of 0x%X", __FUNCTION__, pid, aPidM);
|
||||
aPidM = pid;
|
||||
numApidsM = 1;
|
||||
}
|
||||
else if (pid == aPidM) {
|
||||
++numApidsM;
|
||||
debug("cPidScanner::Process: Incrementing Apids, now at %d\n", numApidsM);
|
||||
debug("cPidScanner::%s(): incrementing Apids, now at %d", __FUNCTION__, numApidsM);
|
||||
}
|
||||
}
|
||||
else if ((sid >= 0xE0) && (sid <= 0xEF)) {
|
||||
if (pid < vPidM) {
|
||||
debug("cPidScanner::Process: Found lower Vpid: 0x%X instead of 0x%X\n", pid, vPidM);
|
||||
debug("cPidScanner::%s(): found lower Vpid: 0x%X instead of 0x%X", __FUNCTION__, pid, vPidM);
|
||||
vPidM = pid;
|
||||
numVpidsM = 1;
|
||||
}
|
||||
else if (pid == vPidM) {
|
||||
++numVpidsM;
|
||||
debug("cPidScanner::Process: Incrementing Vpids, now at %d\n", numVpidsM);
|
||||
debug("cPidScanner::%s(): incrementing Vpids, now at %d", __FUNCTION__, numVpidsM);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -147,7 +147,7 @@ void cPidScanner::Process(const uint8_t* bufP)
|
||||
}
|
||||
for (unsigned int i = 0; i < MAXSPIDS; ++i)
|
||||
Spids[i] = IptvChannel->Spid(i);
|
||||
debug("cPidScanner::Process(): Vpid=0x%04X, Apid=0x%04X\n", vPidM, aPidM);
|
||||
debug("cPidScanner::%s(): vpid=0x%04X, apid=0x%04X", __FUNCTION__, vPidM, aPidM);
|
||||
IptvChannel->SetPids(vPidM, Ppid, Vtype, Apids, Atypes, ALangs, Dpids, Dtypes, DLangs, Spids, SLangs, Tpid);
|
||||
}
|
||||
Channels.Unlock();
|
||||
|
@ -28,7 +28,7 @@ cIptvProtocolCurl::cIptvProtocolCurl()
|
||||
connectedM(false),
|
||||
pausedM(false)
|
||||
{
|
||||
debug("cIptvProtocolCurl::cIptvProtocolCurl()\n");
|
||||
debug("cIptvProtocolCurl::%s()", __FUNCTION__);
|
||||
if (ringBufferM)
|
||||
ringBufferM->SetTimeouts(100, 0);
|
||||
Connect();
|
||||
@ -36,7 +36,7 @@ cIptvProtocolCurl::cIptvProtocolCurl()
|
||||
|
||||
cIptvProtocolCurl::~cIptvProtocolCurl()
|
||||
{
|
||||
debug("cIptvProtocolCurl::~cIptvProtocolCurl()\n");
|
||||
debug("cIptvProtocolCurl::%s()", __FUNCTION__);
|
||||
Disconnect();
|
||||
// Free allocated memory
|
||||
DELETE_POINTER(ringBufferM);
|
||||
@ -46,7 +46,7 @@ size_t cIptvProtocolCurl::WriteCallback(void *ptrP, size_t sizeP, size_t nmembP,
|
||||
{
|
||||
cIptvProtocolCurl *obj = reinterpret_cast<cIptvProtocolCurl *>(dataP);
|
||||
size_t len = sizeP * nmembP;
|
||||
//debug("cIptvProtocolCurl::WriteCallback(%zu)\n", len);
|
||||
//debug("cIptvProtocolCurl::%s(%zu)", __FUNCTION__, len);
|
||||
|
||||
if (obj && !obj->PutData((unsigned char *)ptrP, (int)len))
|
||||
return CURL_WRITEFUNC_PAUSE;
|
||||
@ -59,7 +59,7 @@ size_t cIptvProtocolCurl::WriteRtspCallback(void *ptrP, size_t sizeP, size_t nme
|
||||
cIptvProtocolCurl *obj = reinterpret_cast<cIptvProtocolCurl *>(dataP);
|
||||
size_t len = sizeP * nmembP;
|
||||
unsigned char *p = (unsigned char *)ptrP;
|
||||
//debug("cIptvProtocolCurl::WriteRtspCallback(%zu)\n", len);
|
||||
//debug("cIptvProtocolCurl::%s(%zu)", __FUNCTION__, len);
|
||||
|
||||
// validate packet header ('$') and channel (0)
|
||||
if (obj && (p[0] == 0x24 ) && (p[1] == 0)) {
|
||||
@ -101,14 +101,14 @@ size_t cIptvProtocolCurl::DescribeCallback(void *ptrP, size_t sizeP, size_t nmem
|
||||
{
|
||||
cIptvProtocolCurl *obj = reinterpret_cast<cIptvProtocolCurl *>(dataP);
|
||||
size_t len = sizeP * nmembP;
|
||||
//debug("cIptvProtocolCurl::DescribeCallback(%zu)\n", len);
|
||||
//debug("cIptvProtocolCurl::%s(%zu)", __FUNCTION__, len);
|
||||
|
||||
cString control = "";
|
||||
char *p = (char *)ptrP;
|
||||
char *r = strtok(p, "\r\n");
|
||||
|
||||
while (r) {
|
||||
//debug("cIptvProtocolCurl::DescribeCallback(%zu): %s\n", len, r);
|
||||
//debug("cIptvProtocolCurl::%s(%zu): %s", __FUNCTION__, len, r);
|
||||
if (strstr(r, "a=control")) {
|
||||
char *s = NULL;
|
||||
if (sscanf(r, "a=control:%64ms", &s) == 1)
|
||||
@ -128,13 +128,13 @@ size_t cIptvProtocolCurl::HeaderCallback(void *ptrP, size_t sizeP, size_t nmembP
|
||||
{
|
||||
//cIptvProtocolCurl *obj = reinterpret_cast<cIptvProtocolCurl *>(dataP);
|
||||
size_t len = sizeP * nmembP;
|
||||
//debug("cIptvProtocolCurl::HeaderCallback(%zu)\n", len);
|
||||
//debug("cIptvProtocolCurl::%s(%zu)", __FUNCTION__, len);
|
||||
|
||||
char *p = (char *)ptrP;
|
||||
char *r = strtok(p, "\r\n");
|
||||
|
||||
while (r) {
|
||||
//debug("cIptvProtocolCurl::HeaderCallback(%zu): %s\n", len, r);
|
||||
//debug("cIptvProtocolCurl::%s(%zu): %s", __FUNCTION__, len, r);
|
||||
r = strtok(NULL, "\r\n");
|
||||
}
|
||||
|
||||
@ -144,20 +144,20 @@ size_t cIptvProtocolCurl::HeaderCallback(void *ptrP, size_t sizeP, size_t nmembP
|
||||
void cIptvProtocolCurl::SetRtspControl(const char *controlP)
|
||||
{
|
||||
cMutexLock MutexLock(&mutexM);
|
||||
debug("cIptvProtocolCurl::SetRtspControl('%s')\n", controlP);
|
||||
debug("cIptvProtocolCurl::%s(%s)", __FUNCTION__, controlP);
|
||||
rtspControlM = controlP;
|
||||
}
|
||||
|
||||
bool cIptvProtocolCurl::PutData(unsigned char *dataP, int lenP)
|
||||
{
|
||||
cMutexLock MutexLock(&mutexM);
|
||||
//debug("cIptvProtocolCurl::PutData(%d)\n", lenP);
|
||||
//debug("cIptvProtocolCurl::%s(%d)", __FUNCTION__, lenP);
|
||||
if (pausedM)
|
||||
return false;
|
||||
if (ringBufferM && (lenP >= 0)) {
|
||||
// should be pause the transfer?
|
||||
if (ringBufferM->Free() < (2 * CURL_MAX_WRITE_SIZE)) {
|
||||
debug("cIptvProtocolCurl::PutData(pause): free=%d available=%d len=%d", 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;
|
||||
}
|
||||
@ -172,14 +172,14 @@ bool cIptvProtocolCurl::PutData(unsigned char *dataP, int lenP)
|
||||
void cIptvProtocolCurl::DelData(int lenP)
|
||||
{
|
||||
cMutexLock MutexLock(&mutexM);
|
||||
//debug("cIptvProtocolCurl::DelData()\n");
|
||||
//debug("cIptvProtocolCurl::%s()", __FUNCTION__);
|
||||
if (ringBufferM && (lenP >= 0))
|
||||
ringBufferM->Del(lenP);
|
||||
}
|
||||
|
||||
void cIptvProtocolCurl::ClearData()
|
||||
{
|
||||
//debug("cIptvProtocolCurl::ClearData()\n");
|
||||
//debug("cIptvProtocolCurl::%s()", __FUNCTION__);
|
||||
if (ringBufferM)
|
||||
ringBufferM->Clear();
|
||||
}
|
||||
@ -187,7 +187,7 @@ void cIptvProtocolCurl::ClearData()
|
||||
unsigned char *cIptvProtocolCurl::GetData(unsigned int *lenP)
|
||||
{
|
||||
cMutexLock MutexLock(&mutexM);
|
||||
//debug("cIptvProtocolCurl::GetData()\n");
|
||||
//debug("cIptvProtocolCurl::%s()", __FUNCTION__);
|
||||
unsigned char *p = NULL;
|
||||
*lenP = 0;
|
||||
if (ringBufferM) {
|
||||
@ -219,7 +219,7 @@ unsigned char *cIptvProtocolCurl::GetData(unsigned int *lenP)
|
||||
bool cIptvProtocolCurl::Connect()
|
||||
{
|
||||
cMutexLock MutexLock(&mutexM);
|
||||
debug("cIptvProtocolCurl::Connect()\n");
|
||||
debug("cIptvProtocolCurl::%s()", __FUNCTION__);
|
||||
if (connectedM)
|
||||
return true;
|
||||
|
||||
@ -350,7 +350,7 @@ bool cIptvProtocolCurl::Connect()
|
||||
bool cIptvProtocolCurl::Disconnect()
|
||||
{
|
||||
cMutexLock MutexLock(&mutexM);
|
||||
debug("cIptvProtocolCurl::Disconnect()\n");
|
||||
debug("cIptvProtocolCurl::%s()", __FUNCTION__);
|
||||
if (handleM) {
|
||||
// mode specific tricks
|
||||
switch (modeM) {
|
||||
@ -393,20 +393,20 @@ bool cIptvProtocolCurl::Disconnect()
|
||||
|
||||
bool cIptvProtocolCurl::Open(void)
|
||||
{
|
||||
debug("cIptvProtocolCurl::Open()\n");
|
||||
debug("cIptvProtocolCurl::%s()", __FUNCTION__);
|
||||
return Connect();
|
||||
}
|
||||
|
||||
bool cIptvProtocolCurl::Close(void)
|
||||
{
|
||||
debug("cIptvProtocolCurl::Close()\n");
|
||||
debug("cIptvProtocolCurl::%s()", __FUNCTION__);
|
||||
Disconnect();
|
||||
return true;
|
||||
}
|
||||
|
||||
int cIptvProtocolCurl::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
|
||||
{
|
||||
//debug("cIptvProtocolCurl::Read()\n");
|
||||
//debug("cIptvProtocolCurl::%s()", __FUNCTION__);
|
||||
int len = 0;
|
||||
if (ringBufferM) {
|
||||
// fill up the buffer
|
||||
@ -437,7 +437,7 @@ int cIptvProtocolCurl::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
|
||||
// shall be continue filling up the buffer?
|
||||
mutexM.Lock();
|
||||
if (pausedM && (ringBufferM->Free() > ringBufferM->Available())) {
|
||||
debug("cIptvProtocolCurl::Read(continue): free=%d available=%d\n", 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);
|
||||
}
|
||||
@ -448,7 +448,7 @@ int cIptvProtocolCurl::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
|
||||
int msgcount;
|
||||
CURLMsg *msg = curl_multi_info_read(multiM, &msgcount);
|
||||
if (msg && (msg->msg == CURLMSG_DONE)) {
|
||||
debug("cIptvProtocolCurl::Read(done): %s (%d)\n", curl_easy_strerror(msg->data.result), msg->data.result);
|
||||
debug("cIptvProtocolCurl::%s(done): %s (%d)", __FUNCTION__, curl_easy_strerror(msg->data.result), msg->data.result);
|
||||
Disconnect();
|
||||
Connect();
|
||||
}
|
||||
@ -467,7 +467,7 @@ int cIptvProtocolCurl::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
|
||||
memcpy(bufferAddrP, p, bufferLenP);
|
||||
DelData(bufferLenP);
|
||||
len = bufferLenP;
|
||||
//debug("cIptvProtocolCurl::Read(): get %d bytes\n", len);
|
||||
//debug("cIptvProtocolCurl::%s(): get %d bytes", __FUNCTION__, len);
|
||||
}
|
||||
}
|
||||
|
||||
@ -476,7 +476,7 @@ int cIptvProtocolCurl::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
|
||||
|
||||
bool cIptvProtocolCurl::Set(const char* locationP, const int parameterP, const int indexP)
|
||||
{
|
||||
debug("cIptvProtocolCurl::Set('%s', %d, %d)\n", locationP, parameterP, indexP);
|
||||
debug("cIptvProtocolCurl::%s(%s, %d, %d)", __FUNCTION__, locationP, parameterP, indexP);
|
||||
if (!isempty(locationP)) {
|
||||
// Disconnect
|
||||
Disconnect();
|
||||
@ -498,7 +498,6 @@ bool cIptvProtocolCurl::Set(const char* locationP, const int parameterP, const i
|
||||
modeM = eModeUnknown;
|
||||
// Update stream parameter
|
||||
streamParamM = parameterP;
|
||||
//debug("%s [%d]\n", *streamUrlM, streamParamM);
|
||||
// Reconnect
|
||||
Connect();
|
||||
}
|
||||
@ -507,6 +506,6 @@ bool cIptvProtocolCurl::Set(const char* locationP, const int parameterP, const i
|
||||
|
||||
cString cIptvProtocolCurl::GetInformation(void)
|
||||
{
|
||||
//debug("cIptvProtocolCurl::GetInformation()");
|
||||
//debug("cIptvProtocolCurl::%s()", __FUNCTION__);
|
||||
return cString::sprintf("%s [%d]", *streamUrlM, streamParamM);
|
||||
}
|
||||
|
@ -29,21 +29,21 @@ cIptvProtocolExt::cIptvProtocolExt()
|
||||
scriptParameterM(0),
|
||||
streamPortM(0)
|
||||
{
|
||||
debug("cIptvProtocolExt::cIptvProtocolExt()\n");
|
||||
debug("cIptvProtocolExt::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
cIptvProtocolExt::~cIptvProtocolExt()
|
||||
{
|
||||
debug("cIptvProtocolExt::~cIptvProtocolExt()\n");
|
||||
debug("cIptvProtocolExt::%s()", __FUNCTION__);
|
||||
// Drop the socket connection
|
||||
cIptvProtocolExt::Close();
|
||||
}
|
||||
|
||||
void cIptvProtocolExt::ExecuteScript(void)
|
||||
{
|
||||
debug("cIptvProtocolExt::ExecuteScript()\n");
|
||||
debug("cIptvProtocolExt::%s()", __FUNCTION__);
|
||||
// Check if already executing
|
||||
if (isActive || isempty(scriptFileM))
|
||||
if (isActiveM || isempty(scriptFileM))
|
||||
return;
|
||||
if (pidM > 0) {
|
||||
error("Cannot execute script!");
|
||||
@ -59,7 +59,7 @@ void cIptvProtocolExt::ExecuteScript(void)
|
||||
close(i);
|
||||
// Execute the external script
|
||||
cString cmd = cString::sprintf("%s %d %d", *scriptFileM, scriptParameterM, streamPortM);
|
||||
debug("cIptvProtocolExt::ExecuteScript(child): %s\n", *cmd);
|
||||
debug("cIptvProtocolExt::%s(child): %s", __FUNCTION__, *cmd);
|
||||
// Create a new session for a process group
|
||||
ERROR_IF_RET(setsid() == -1, "setsid()", _exit(-1));
|
||||
if (execl(EXTSHELL, "sh", "-c", *cmd, (char *)NULL) == -1) {
|
||||
@ -69,14 +69,14 @@ void cIptvProtocolExt::ExecuteScript(void)
|
||||
_exit(0);
|
||||
}
|
||||
else {
|
||||
debug("cIptvProtocolExt::ExecuteScript(): pid=%d\n", pidM);
|
||||
debug("cIptvProtocolExt::%s(): pid=%d", __FUNCTION__, pidM);
|
||||
}
|
||||
}
|
||||
|
||||
void cIptvProtocolExt::TerminateScript(void)
|
||||
{
|
||||
debug("cIptvProtocolExt::TerminateScript(): pid=%d\n", pidM);
|
||||
if (!isActive || isempty(scriptFileM))
|
||||
debug("cIptvProtocolExt::%s(): pid=%d", __FUNCTION__, pidM);
|
||||
if (!isActiveM || isempty(scriptFileM))
|
||||
return;
|
||||
if (pidM > 0) {
|
||||
const unsigned int timeoutms = 100;
|
||||
@ -99,7 +99,7 @@ void cIptvProtocolExt::TerminateScript(void)
|
||||
retval = waitpid(pidM, &waitStatus, WNOHANG);
|
||||
#else // __FreeBSD__
|
||||
siginfo_t waitStatus;
|
||||
memset(&waitStatus, '\0', sizeof(waitStatus));
|
||||
memset(&waitStatus, 0, sizeof(waitStatus));
|
||||
retval = waitid(P_PID, pidM, &waitStatus, (WNOHANG | WEXITED));
|
||||
#endif // __FreeBSD__
|
||||
ERROR_IF_RET(retval < 0, "waitid()", waitOver = true);
|
||||
@ -111,7 +111,7 @@ void cIptvProtocolExt::TerminateScript(void)
|
||||
if (!retval && waitStatus.si_pid && (waitStatus.si_pid == pidM) &&
|
||||
((waitStatus.si_code == CLD_EXITED) || (waitStatus.si_code == CLD_KILLED))) {
|
||||
#endif // __FreeBSD__
|
||||
debug("Child (%d) exited as expected\n", pidM);
|
||||
debug("cIptvProtocolExt::%s(): child (%d) exited as expected", __FUNCTION__, pidM);
|
||||
waitOver = true;
|
||||
}
|
||||
// Unsuccessful wait, avoid busy looping
|
||||
@ -124,7 +124,7 @@ void cIptvProtocolExt::TerminateScript(void)
|
||||
|
||||
bool cIptvProtocolExt::Open(void)
|
||||
{
|
||||
debug("cIptvProtocolExt::Open()\n");
|
||||
debug("cIptvProtocolExt::%s()", __FUNCTION__);
|
||||
// Reject empty script files
|
||||
if (!strlen(*scriptFileM))
|
||||
return false;
|
||||
@ -132,16 +132,16 @@ bool cIptvProtocolExt::Open(void)
|
||||
OpenSocket(streamPortM);
|
||||
// Execute the external script
|
||||
ExecuteScript();
|
||||
isActive = true;
|
||||
isActiveM = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cIptvProtocolExt::Close(void)
|
||||
{
|
||||
debug("cIptvProtocolExt::Close()\n");
|
||||
debug("cIptvProtocolExt::%s()", __FUNCTION__);
|
||||
// Terminate the external script
|
||||
TerminateScript();
|
||||
isActive = false;
|
||||
isActiveM = false;
|
||||
// Close the socket
|
||||
CloseSocket();
|
||||
return true;
|
||||
@ -154,7 +154,7 @@ int cIptvProtocolExt::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
|
||||
|
||||
bool cIptvProtocolExt::Set(const char* locationP, const int parameterP, const int indexP)
|
||||
{
|
||||
debug("cIptvProtocolExt::Set('%s', %d, %d)\n", locationP, parameterP, indexP);
|
||||
debug("cIptvProtocolExt::%s(%s, %d, %d)", __FUNCTION__, locationP, parameterP, indexP);
|
||||
if (!isempty(locationP)) {
|
||||
struct stat stbuf;
|
||||
// Update script file and parameter
|
||||
@ -172,6 +172,6 @@ bool cIptvProtocolExt::Set(const char* locationP, const int parameterP, const in
|
||||
|
||||
cString cIptvProtocolExt::GetInformation(void)
|
||||
{
|
||||
//debug("cIptvProtocolExt::GetInformation()");
|
||||
//debug("cIptvProtocolExt::%s()", __FUNCTION__);
|
||||
return cString::sprintf("ext://%s:%d", *scriptFileM, scriptParameterM);
|
||||
}
|
||||
|
@ -20,12 +20,12 @@ cIptvProtocolFile::cIptvProtocolFile()
|
||||
fileStreamM(NULL),
|
||||
isActiveM(false)
|
||||
{
|
||||
debug("cIptvProtocolFile::cIptvProtocolFile()\n");
|
||||
debug("cIptvProtocolFile::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
cIptvProtocolFile::~cIptvProtocolFile()
|
||||
{
|
||||
debug("cIptvProtocolFile::~cIptvProtocolFile()\n");
|
||||
debug("cIptvProtocolFile::%s()", __FUNCTION__);
|
||||
// Drop open handles
|
||||
cIptvProtocolFile::Close();
|
||||
// Free allocated memory
|
||||
@ -34,7 +34,7 @@ cIptvProtocolFile::~cIptvProtocolFile()
|
||||
|
||||
bool cIptvProtocolFile::OpenFile(void)
|
||||
{
|
||||
debug("cIptvProtocolFile::OpenFile()\n");
|
||||
debug("cIptvProtocolFile::%s()", __FUNCTION__);
|
||||
// Check that stream address is valid
|
||||
if (!isActiveM && !isempty(fileLocationM)) {
|
||||
fileStreamM = fopen(fileLocationM, "rb");
|
||||
@ -47,7 +47,7 @@ bool cIptvProtocolFile::OpenFile(void)
|
||||
|
||||
void cIptvProtocolFile::CloseFile(void)
|
||||
{
|
||||
debug("cIptvProtocolFile::CloseFile()\n");
|
||||
debug("cIptvProtocolFile::%s()", __FUNCTION__);
|
||||
// Check that file stream is valid
|
||||
if (isActiveM && !isempty(fileLocationM)) {
|
||||
fclose(fileStreamM);
|
||||
@ -58,10 +58,10 @@ void cIptvProtocolFile::CloseFile(void)
|
||||
|
||||
int cIptvProtocolFile::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
|
||||
{
|
||||
//debug("cIptvProtocolFile::Read()\n");
|
||||
//debug("cIptvProtocolFile::%s()", __FUNCTION__);
|
||||
// Check errors
|
||||
if (ferror(fileStreamM)) {
|
||||
debug("Read error\n");
|
||||
debug("cIptvProtocolFile::%s(): stream error", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
// Rewind if EOF
|
||||
@ -81,7 +81,7 @@ int cIptvProtocolFile::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
|
||||
|
||||
bool cIptvProtocolFile::Open(void)
|
||||
{
|
||||
debug("cIptvProtocolFile::Open()\n");
|
||||
debug("cIptvProtocolFile::%s()", __FUNCTION__);
|
||||
// Open the file stream
|
||||
OpenFile();
|
||||
return true;
|
||||
@ -89,7 +89,7 @@ bool cIptvProtocolFile::Open(void)
|
||||
|
||||
bool cIptvProtocolFile::Close(void)
|
||||
{
|
||||
debug("cIptvProtocolFile::Close()\n");
|
||||
debug("cIptvProtocolFile::%s()", __FUNCTION__);
|
||||
// Close the file stream
|
||||
CloseFile();
|
||||
return true;
|
||||
@ -97,7 +97,7 @@ bool cIptvProtocolFile::Close(void)
|
||||
|
||||
bool cIptvProtocolFile::Set(const char* locationP, const int parameterP, const int indexP)
|
||||
{
|
||||
debug("cIptvProtocolFile::Set('%s', %d, %d)\n", locationP, parameterP, indexP);
|
||||
debug("cIptvProtocolFile::%s(%s, %d, %d)", __FUNCTION__, locationP, parameterP, indexP);
|
||||
if (!isempty(locationP)) {
|
||||
// Close the file stream
|
||||
CloseFile();
|
||||
@ -112,6 +112,6 @@ bool cIptvProtocolFile::Set(const char* locationP, const int parameterP, const i
|
||||
|
||||
cString cIptvProtocolFile::GetInformation(void)
|
||||
{
|
||||
//debug("cIptvProtocolFile::GetInformation()");
|
||||
//debug("cIptvProtocolFile::%s()", __FUNCTION__);
|
||||
return cString::sprintf("file://%s:%d", fileLocationM, fileDelayM);
|
||||
}
|
||||
|
@ -23,12 +23,12 @@ cIptvProtocolHttp::cIptvProtocolHttp()
|
||||
streamPathM(strdup("/")),
|
||||
streamPortM(0)
|
||||
{
|
||||
debug("cIptvProtocolHttp::cIptvProtocolHttp()\n");
|
||||
debug("cIptvProtocolHttp::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
cIptvProtocolHttp::~cIptvProtocolHttp()
|
||||
{
|
||||
debug("cIptvProtocolHttp::~cIptvProtocolHttp()\n");
|
||||
debug("cIptvProtocolHttp::%s()", __FUNCTION__);
|
||||
// Close the socket
|
||||
cIptvProtocolHttp::Close();
|
||||
// Free allocated memory
|
||||
@ -38,9 +38,9 @@ cIptvProtocolHttp::~cIptvProtocolHttp()
|
||||
|
||||
bool cIptvProtocolHttp::Connect(void)
|
||||
{
|
||||
debug("cIptvProtocolHttp::Connect()\n");
|
||||
debug("cIptvProtocolHttp::%s()", __FUNCTION__);
|
||||
// Check that stream address is valid
|
||||
if (!isActive && !isempty(streamAddrM) && !isempty(streamPathM)) {
|
||||
if (!isActiveM && !isempty(streamAddrM) && !isempty(streamPathM)) {
|
||||
// Ensure that socket is valid and connect
|
||||
OpenSocket(streamPortM, streamAddrM);
|
||||
if (!ConnectSocket()) {
|
||||
@ -55,7 +55,7 @@ bool cIptvProtocolHttp::Connect(void)
|
||||
"Connection: Close\r\n"
|
||||
"\r\n", streamPathM, streamAddrM,
|
||||
PLUGIN_NAME_I18N, VERSION);
|
||||
debug("Sending http request: %s\n", *buffer);
|
||||
debug("cIptvProtocolHttp::%s(): requesting: %s", __FUNCTION__, *buffer);
|
||||
if (!Write(*buffer, (unsigned int)strlen(*buffer))) {
|
||||
CloseSocket();
|
||||
return false;
|
||||
@ -66,19 +66,19 @@ bool cIptvProtocolHttp::Connect(void)
|
||||
return false;
|
||||
}
|
||||
// Update active flag
|
||||
isActive = true;
|
||||
isActiveM = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cIptvProtocolHttp::Disconnect(void)
|
||||
{
|
||||
debug("cIptvProtocolHttp::Disconnect()\n");
|
||||
if (isActive) {
|
||||
debug("cIptvProtocolHttp::%s()", __FUNCTION__);
|
||||
if (isActiveM) {
|
||||
// Close the socket
|
||||
CloseSocket();
|
||||
// Update active flag
|
||||
isActive = false;
|
||||
isActiveM = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -86,7 +86,7 @@ bool cIptvProtocolHttp::Disconnect(void)
|
||||
bool cIptvProtocolHttp::GetHeaderLine(char* destP, unsigned int destLenP,
|
||||
unsigned int &recvLenP)
|
||||
{
|
||||
debug("cIptvProtocolHttp::GetHeaderLine()\n");
|
||||
debug("cIptvProtocolHttp::%s()", __FUNCTION__);
|
||||
bool linefeed = false;
|
||||
bool newline = false;
|
||||
char *bufptr = destP;
|
||||
@ -127,7 +127,7 @@ bool cIptvProtocolHttp::GetHeaderLine(char* destP, unsigned int destLenP,
|
||||
|
||||
bool cIptvProtocolHttp::ProcessHeaders(void)
|
||||
{
|
||||
debug("cIptvProtocolHttp::ProcessHeaders()\n");
|
||||
debug("cIptvProtocolHttp::%s()", __FUNCTION__);
|
||||
unsigned int lineLength = 0;
|
||||
int version = 0, response = 0;
|
||||
bool responseFound = false;
|
||||
@ -138,7 +138,7 @@ bool cIptvProtocolHttp::ProcessHeaders(void)
|
||||
snprintf(fmt, sizeof(fmt), "HTTP/1.%%%zui %%%zui ", sizeof(version) - 1, sizeof(response) - 1);
|
||||
|
||||
while (!responseFound || lineLength != 0) {
|
||||
memset(buf, '\0', sizeof(buf));
|
||||
memset(buf, 0, sizeof(buf));
|
||||
if (!GetHeaderLine(buf, sizeof(buf), lineLength))
|
||||
return false;
|
||||
if (!responseFound && sscanf(buf, fmt, &version, &response) != 2) {
|
||||
@ -158,14 +158,14 @@ bool cIptvProtocolHttp::ProcessHeaders(void)
|
||||
|
||||
bool cIptvProtocolHttp::Open(void)
|
||||
{
|
||||
debug("cIptvProtocolHttp::Open()\n");
|
||||
debug("cIptvProtocolHttp::%s()", __FUNCTION__);
|
||||
// Connect the socket
|
||||
return Connect();
|
||||
}
|
||||
|
||||
bool cIptvProtocolHttp::Close(void)
|
||||
{
|
||||
debug("cIptvProtocolHttp::Close()\n");
|
||||
debug("cIptvProtocolHttp::%s()", __FUNCTION__);
|
||||
// Disconnect the current stream
|
||||
Disconnect();
|
||||
return true;
|
||||
@ -178,7 +178,7 @@ int cIptvProtocolHttp::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
|
||||
|
||||
bool cIptvProtocolHttp::Set(const char* locationP, const int parameterP, const int indexP)
|
||||
{
|
||||
debug("cIptvProtocolHttp::Set('%s', %d, %d)\n", locationP, parameterP, indexP);
|
||||
debug("cIptvProtocolHttp::%s(%s, %d, %d)", __FUNCTION__, locationP, parameterP, indexP);
|
||||
if (!isempty(locationP)) {
|
||||
// Disconnect the current socket
|
||||
Disconnect();
|
||||
@ -192,7 +192,6 @@ bool cIptvProtocolHttp::Set(const char* locationP, const int parameterP, const i
|
||||
else
|
||||
streamPathM = strcpyrealloc(streamPathM, "/");
|
||||
streamPortM = parameterP;
|
||||
//debug("http://%s:%d%s\n", streamAddrM, streamPortM, streamPathM);
|
||||
// Re-connect the socket
|
||||
Connect();
|
||||
}
|
||||
@ -201,6 +200,6 @@ bool cIptvProtocolHttp::Set(const char* locationP, const int parameterP, const i
|
||||
|
||||
cString cIptvProtocolHttp::GetInformation(void)
|
||||
{
|
||||
//debug("cIptvProtocolHttp::GetInformation()");
|
||||
//debug("cIptvProtocolHttp::%s()", __FUNCTION__);
|
||||
return cString::sprintf("http://%s:%d%s", streamAddrM, streamPortM, streamPathM);
|
||||
}
|
||||
|
@ -24,12 +24,12 @@ cIptvProtocolUdp::cIptvProtocolUdp()
|
||||
streamAddrM(strdup("")),
|
||||
streamPortM(0)
|
||||
{
|
||||
debug("cIptvProtocolUdp::cIptvProtocolUdp()\n");
|
||||
debug("cIptvProtocolUdp::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
cIptvProtocolUdp::~cIptvProtocolUdp()
|
||||
{
|
||||
debug("cIptvProtocolUdp::~cIptvProtocolUdp()\n");
|
||||
debug("cIptvProtocolUdp::%s()", __FUNCTION__);
|
||||
// Drop the multicast group and close the socket
|
||||
cIptvProtocolUdp::Close();
|
||||
// Free allocated memory
|
||||
@ -39,7 +39,7 @@ cIptvProtocolUdp::~cIptvProtocolUdp()
|
||||
|
||||
bool cIptvProtocolUdp::Open(void)
|
||||
{
|
||||
debug("cIptvProtocolUdp::Open(): '%s'\n", streamAddrM);
|
||||
debug("cIptvProtocolUdp::%s(%s)", __FUNCTION__, streamAddrM);
|
||||
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
|
||||
if (!isempty(streamAddrM)) {
|
||||
// Join a new multicast group
|
||||
@ -50,7 +50,7 @@ bool cIptvProtocolUdp::Open(void)
|
||||
|
||||
bool cIptvProtocolUdp::Close(void)
|
||||
{
|
||||
debug("cIptvProtocolUdp::Close(): '%s'\n", streamAddrM);
|
||||
debug("cIptvProtocolUdp::%s(%s)", __FUNCTION__, streamAddrM);
|
||||
if (!isempty(streamAddrM)) {
|
||||
// Drop the multicast group
|
||||
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
|
||||
@ -72,7 +72,7 @@ int cIptvProtocolUdp::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
|
||||
|
||||
bool cIptvProtocolUdp::Set(const char* locationP, const int parameterP, const int indexP)
|
||||
{
|
||||
debug("cIptvProtocolUdp::Set('%s', %d, %d)\n", locationP, parameterP, indexP);
|
||||
debug("cIptvProtocolUdp::%s(%s, %d, %d)", __FUNCTION__, locationP, parameterP, indexP);
|
||||
if (!isempty(locationP)) {
|
||||
// Drop the multicast group
|
||||
if (!isempty(streamAddrM)) {
|
||||
@ -105,7 +105,7 @@ bool cIptvProtocolUdp::Set(const char* locationP, const int parameterP, const in
|
||||
|
||||
cString cIptvProtocolUdp::GetInformation(void)
|
||||
{
|
||||
//debug("cIptvProtocolUdp::GetInformation()");
|
||||
//debug("cIptvProtocolUdp::%s()", __FUNCTION__);
|
||||
if (isIGMPv3M)
|
||||
return cString::sprintf("udp://%s@%s:%d", sourceAddrM, streamAddrM, streamPortM);
|
||||
return cString::sprintf("udp://%s:%d", streamAddrM, streamPortM);
|
||||
|
@ -19,7 +19,7 @@ cIptvSectionFilter::cIptvSectionFilter(int deviceIndexP, uint16_t pidP, uint8_t
|
||||
pidM(pidP),
|
||||
devIdM(deviceIndexP)
|
||||
{
|
||||
//debug("cIptvSectionFilter::cIptvSectionFilter(%d, %d)\n", devIdM, pidM);
|
||||
//debug("cIptvSectionFilter::%s(%d, %d)", __FUNCTION__, devIdM, pidM);
|
||||
int i;
|
||||
|
||||
memset(secBufBaseM, 0, sizeof(secBufBaseM));
|
||||
@ -56,7 +56,7 @@ cIptvSectionFilter::cIptvSectionFilter(int deviceIndexP, uint16_t pidP, uint8_t
|
||||
|
||||
cIptvSectionFilter::~cIptvSectionFilter()
|
||||
{
|
||||
//debug("cIptvSectionFilter::~cIptvSectionfilter(%d, %d)\n", devIdM, pidM);
|
||||
//debug("cIptvSectionFilter::%s(%d, %d)", __FUNCTION__, devIdM, pidM);
|
||||
DELETE_POINTER(ringbufferM);
|
||||
secBufM = NULL;
|
||||
}
|
||||
|
6
setup.c
6
setup.c
@ -112,7 +112,7 @@ eOSState cIptvMenuInfo::ProcessKey(eKeys keyP)
|
||||
|
||||
cIptvPluginSetup::cIptvPluginSetup()
|
||||
{
|
||||
debug("cIptvPluginSetup::cIptvPluginSetup()\n");
|
||||
debug("cIptvPluginSetup::%s()", __FUNCTION__);
|
||||
tsBufferSizeM = IptvConfig.GetTsBufferSize();
|
||||
tsBufferPrefillM = IptvConfig.GetTsBufferPrefillRatio();
|
||||
extProtocolBasePortM = IptvConfig.GetExtProtocolBasePort();
|
||||
@ -164,7 +164,7 @@ void cIptvPluginSetup::Setup(void)
|
||||
|
||||
eOSState cIptvPluginSetup::ShowInfo(void)
|
||||
{
|
||||
debug("cIptvPluginSetup::ShowInfo()\n");
|
||||
debug("cIptvPluginSetup::%s()", __FUNCTION__);
|
||||
if (HasSubMenu())
|
||||
return osContinue;
|
||||
return AddSubMenu(new cIptvMenuInfo());
|
||||
@ -209,7 +209,7 @@ void cIptvPluginSetup::StoreFilters(const char *nameP, int *valuesP)
|
||||
q += strlen(s);
|
||||
}
|
||||
*q = 0;
|
||||
debug("cIptvPluginSetup::StoreFilters(): %s=%s\n", nameP, buffer);
|
||||
debug("cIptvPluginSetup::%s(%s, %s)", __FUNCTION__, nameP, buffer);
|
||||
SetupStore(nameP, buffer);
|
||||
}
|
||||
|
||||
|
20
sidscanner.c
20
sidscanner.c
@ -16,25 +16,25 @@ cSidScanner::cSidScanner(void)
|
||||
nidFoundM(false),
|
||||
tidFoundM(false)
|
||||
{
|
||||
debug("cSidScanner::cSidScanner()\n");
|
||||
debug("cSidScanner::%s()", __FUNCTION__);
|
||||
Set(0x00, 0x00); // PAT
|
||||
Set(0x10, 0x40); // NIT
|
||||
}
|
||||
|
||||
cSidScanner::~cSidScanner()
|
||||
{
|
||||
debug("cSidScanner::~cSidScanner()\n");
|
||||
debug("cSidScanner::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
void cSidScanner::SetStatus(bool onP)
|
||||
{
|
||||
debug("cSidScanner::SetStatus(%d)\n", onP);
|
||||
debug("cSidScanner::%s(%d)", __FUNCTION__, onP);
|
||||
cFilter::SetStatus(onP);
|
||||
}
|
||||
|
||||
void cSidScanner::SetChannel(const tChannelID &channelIdP)
|
||||
{
|
||||
debug("cSidScanner::SetChannel('%s')\n", *channelIdP.ToString());
|
||||
debug("cSidScanner::%s(%s)", __FUNCTION__, *channelIdP.ToString());
|
||||
channelIdM = channelIdP;
|
||||
sidFoundM = false;
|
||||
nidFoundM = false;
|
||||
@ -45,10 +45,10 @@ void cSidScanner::Process(u_short pidP, u_char tidP, const u_char *dataP, int le
|
||||
{
|
||||
int newSid = -1, newNid = -1, newTid = -1;
|
||||
|
||||
//debug("cSidScanner::Process()\n");
|
||||
//debug("cSidScanner::%s()", __FUNCTION__);
|
||||
if (channelIdM.Valid()) {
|
||||
if ((pidP == 0x00) && (tidP == 0x00)) {
|
||||
debug("cSidScanner::Process(): Pid=%d Tid=%02X\n", pidP, tidP);
|
||||
debug("cSidScanner::%s(%d, %02X)", __FUNCTION__, pidP, tidP);
|
||||
SI::PAT pat(dataP, false);
|
||||
if (!pat.CheckCRCAndParse())
|
||||
return;
|
||||
@ -56,7 +56,7 @@ void cSidScanner::Process(u_short pidP, u_char tidP, const u_char *dataP, int le
|
||||
for (SI::Loop::Iterator it; pat.associationLoop.getNext(assoc, it); ) {
|
||||
if (!assoc.isNITPid()) {
|
||||
if (assoc.getServiceId() != channelIdM.Sid()) {
|
||||
debug("cSidScanner::Process(): Sid=%d\n", assoc.getServiceId());
|
||||
debug("cSidScanner::%s(): sid=%d", __FUNCTION__, assoc.getServiceId());
|
||||
newSid = assoc.getServiceId();
|
||||
}
|
||||
sidFoundM = true;
|
||||
@ -65,21 +65,21 @@ void cSidScanner::Process(u_short pidP, u_char tidP, const u_char *dataP, int le
|
||||
}
|
||||
}
|
||||
else if ((pidP == 0x10) && (tidP == 0x40)) {
|
||||
debug("cSidScanner::Process(): Pid=%d Tid=%02X\n", pidP, tidP);
|
||||
debug("cSidScanner::%s(%d, %02X)", __FUNCTION__, pidP, tidP);
|
||||
SI::NIT nit(dataP, false);
|
||||
if (!nit.CheckCRCAndParse())
|
||||
return;
|
||||
SI::NIT::TransportStream ts;
|
||||
for (SI::Loop::Iterator it; nit.transportStreamLoop.getNext(ts, it); ) {
|
||||
if (ts.getTransportStreamId() != channelIdM.Tid()) {
|
||||
debug("cSidScanner::Process(): TSid=%d\n", ts.getTransportStreamId());
|
||||
debug("cSidScanner::%s(): tsid=%d", __FUNCTION__, ts.getTransportStreamId());
|
||||
newTid = ts.getTransportStreamId();
|
||||
}
|
||||
tidFoundM = true;
|
||||
break; // default to the first one
|
||||
}
|
||||
if (nit.getNetworkId() != channelIdM.Nid()) {
|
||||
debug("cSidScanner::Process(): Nid=%d\n", ts.getTransportStreamId());
|
||||
debug("cSidScanner::%s(): nid=%d\n", __FUNCTION__, ts.getTransportStreamId());
|
||||
newNid = nit.getNetworkId();
|
||||
}
|
||||
nidFoundM = true;
|
||||
|
255
socket.c
255
socket.c
@ -19,93 +19,90 @@
|
||||
#include "socket.h"
|
||||
|
||||
cIptvSocket::cIptvSocket()
|
||||
: socketPort(0),
|
||||
socketDesc(-1),
|
||||
isActive(false)
|
||||
: socketPortM(0),
|
||||
socketDescM(-1),
|
||||
isActiveM(false)
|
||||
{
|
||||
debug("cIptvSocket::cIptvSocket()\n");
|
||||
memset(&sockAddr, '\0', sizeof(sockAddr));
|
||||
debug("cIptvSocket::%s()", __FUNCTION__);
|
||||
memset(&sockAddrM, 0, sizeof(sockAddrM));
|
||||
}
|
||||
|
||||
cIptvSocket::~cIptvSocket()
|
||||
{
|
||||
debug("cIptvSocket::~cIptvSocket()\n");
|
||||
debug("cIptvSocket::%s()", __FUNCTION__);
|
||||
// Close the socket
|
||||
CloseSocket();
|
||||
}
|
||||
|
||||
bool cIptvSocket::OpenSocket(const int Port, const bool isUdp)
|
||||
bool cIptvSocket::OpenSocket(const int portP, const bool isUdpP)
|
||||
{
|
||||
debug("cIptvSocket::OpenSocket()\n");
|
||||
debug("cIptvSocket::%s()", __FUNCTION__);
|
||||
// If socket is there already and it is bound to a different port, it must
|
||||
// be closed first
|
||||
if (Port != socketPort) {
|
||||
debug("cIptvSocket::OpenSocket(): Socket tear-down\n");
|
||||
if (portP != socketPortM) {
|
||||
debug("cIptvSocket::%s(): socket tear-down", __FUNCTION__);
|
||||
CloseSocket();
|
||||
}
|
||||
// Bind to the socket if it is not active already
|
||||
if (socketDesc < 0) {
|
||||
if (socketDescM < 0) {
|
||||
int yes = 1;
|
||||
// Create socket
|
||||
if (isUdp)
|
||||
socketDesc = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
if (isUdpP)
|
||||
socketDescM = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
else
|
||||
socketDesc = socket(PF_INET, SOCK_STREAM, 0);
|
||||
ERROR_IF_RET(socketDesc < 0, "socket()", return false);
|
||||
socketDescM = socket(PF_INET, SOCK_STREAM, 0);
|
||||
ERROR_IF_RET(socketDescM < 0, "socket()", return false);
|
||||
// Make it use non-blocking I/O to avoid stuck read calls
|
||||
ERROR_IF_FUNC(fcntl(socketDesc, F_SETFL, O_NONBLOCK), "fcntl(O_NONBLOCK)",
|
||||
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(socketDesc, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0, "setsockopt(SO_REUSEADDR)",
|
||||
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(socketDesc, SOL_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0, "setsockopt(IP_PKTINFO)",
|
||||
ERROR_IF_FUNC(setsockopt(socketDescM, SOL_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0, "setsockopt(IP_PKTINFO)",
|
||||
CloseSocket(), return false);
|
||||
#endif // __FreeBSD__
|
||||
// Bind socket
|
||||
memset(&sockAddr, 0, sizeof(sockAddr));
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons((uint16_t)(Port & 0xFFFF));
|
||||
sockAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
if (isUdp) {
|
||||
int err = bind(socketDesc, (struct sockaddr *)&sockAddr, sizeof(sockAddr));
|
||||
ERROR_IF_FUNC(err < 0, "bind()", CloseSocket(), return false);
|
||||
}
|
||||
memset(&sockAddrM, 0, sizeof(sockAddrM));
|
||||
sockAddrM.sin_family = AF_INET;
|
||||
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);
|
||||
// Update socket port
|
||||
socketPort = Port;
|
||||
socketPortM = portP;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void cIptvSocket::CloseSocket(void)
|
||||
{
|
||||
debug("cIptvSocket::CloseSocket()\n");
|
||||
debug("cIptvSocket::%s()", __FUNCTION__);
|
||||
// Check if socket exists
|
||||
if (socketDesc >= 0) {
|
||||
close(socketDesc);
|
||||
socketDesc = -1;
|
||||
socketPort = 0;
|
||||
memset(&sockAddr, 0, sizeof(sockAddr));
|
||||
if (socketDescM >= 0) {
|
||||
close(socketDescM);
|
||||
socketDescM = -1;
|
||||
socketPortM = 0;
|
||||
memset(&sockAddrM, 0, sizeof(sockAddrM));
|
||||
}
|
||||
}
|
||||
|
||||
bool cIptvSocket::CheckAddress(const char *Addr, in_addr_t *InAddr)
|
||||
bool cIptvSocket::CheckAddress(const char *addrP, in_addr_t *inAddrP)
|
||||
{
|
||||
if (InAddr) {
|
||||
if (inAddrP) {
|
||||
// First try only the IP address
|
||||
*InAddr = htonl(inet_addr(Addr));
|
||||
if (*InAddr == htonl(INADDR_NONE)) {
|
||||
debug("Cannot convert %s directly to internet address\n", Addr);
|
||||
*inAddrP = htonl(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;
|
||||
host = gethostbyname(Addr);
|
||||
struct hostent *host = gethostbyname(addrP);
|
||||
if (!host) {
|
||||
char tmp[64];
|
||||
error("gethostbyname() failed: %s is not valid address: %s", Addr, 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;
|
||||
}
|
||||
*InAddr = htonl(inet_addr(*host->h_addr_list));
|
||||
*inAddrP = htonl(inet_addr(*host->h_addr_list));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -114,52 +111,52 @@ bool cIptvSocket::CheckAddress(const char *Addr, in_addr_t *InAddr)
|
||||
|
||||
// UDP socket class
|
||||
cIptvUdpSocket::cIptvUdpSocket()
|
||||
: streamAddr(htonl(INADDR_ANY)),
|
||||
sourceAddr(htonl(INADDR_ANY)),
|
||||
useIGMPv3(false)
|
||||
: streamAddrM(htonl(INADDR_ANY)),
|
||||
sourceAddrM(htonl(INADDR_ANY)),
|
||||
useIGMPv3M(false)
|
||||
{
|
||||
debug("cIptvUdpSocket::cIptvUdpSocket()\n");
|
||||
debug("cIptvUdpSocket::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
cIptvUdpSocket::~cIptvUdpSocket()
|
||||
{
|
||||
debug("cIptvUdpSocket::~cIptvUdpSocket()\n");
|
||||
debug("cIptvUdpSocket::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
bool cIptvUdpSocket::OpenSocket(const int Port)
|
||||
bool cIptvUdpSocket::OpenSocket(const int portP)
|
||||
{
|
||||
debug("cIptvUdpSocket::OpenSocket()\n");
|
||||
streamAddr = htonl(INADDR_ANY);
|
||||
sourceAddr = htonl(INADDR_ANY);
|
||||
useIGMPv3 = false;
|
||||
return cIptvSocket::OpenSocket(Port, true);
|
||||
debug("cIptvUdpSocket::%s()", __FUNCTION__);
|
||||
streamAddrM = htonl(INADDR_ANY);
|
||||
sourceAddrM = htonl(INADDR_ANY);
|
||||
useIGMPv3M = false;
|
||||
return cIptvSocket::OpenSocket(portP, true);
|
||||
}
|
||||
|
||||
bool cIptvUdpSocket::OpenSocket(const int Port, const char *StreamAddr, const char *SourceAddr, bool UseIGMPv3)
|
||||
bool cIptvUdpSocket::OpenSocket(const int portP, const char *streamAddrP, const char *sourceAddrP, bool useIGMPv3P)
|
||||
{
|
||||
debug("cIptvUdpSocket::OpenSocket()\n");
|
||||
CheckAddress(StreamAddr, &streamAddr);
|
||||
CheckAddress(SourceAddr, &sourceAddr);
|
||||
useIGMPv3 = UseIGMPv3;
|
||||
return cIptvSocket::OpenSocket(Port, true);
|
||||
debug("cIptvUdpSocket::%s(%d, %s, %s, %d)", __FUNCTION__, portP, streamAddrP, sourceAddrP, useIGMPv3P);
|
||||
CheckAddress(streamAddrP, &streamAddrM);
|
||||
CheckAddress(sourceAddrP, &sourceAddrM);
|
||||
useIGMPv3M = useIGMPv3P;
|
||||
return cIptvSocket::OpenSocket(portP, true);
|
||||
}
|
||||
|
||||
void cIptvUdpSocket::CloseSocket(void)
|
||||
{
|
||||
debug("cIptvUdpSocket::CloseSocket()\n");
|
||||
streamAddr = htonl(INADDR_ANY);
|
||||
sourceAddr = htonl(INADDR_ANY);
|
||||
useIGMPv3 = false;
|
||||
debug("cIptvUdpSocket::%s()", __FUNCTION__);
|
||||
streamAddrM = htonl(INADDR_ANY);
|
||||
sourceAddrM = htonl(INADDR_ANY);
|
||||
useIGMPv3M = false;
|
||||
cIptvSocket::CloseSocket();
|
||||
}
|
||||
|
||||
bool cIptvUdpSocket::JoinMulticast(void)
|
||||
{
|
||||
debug("cIptvUdpSocket::JoinMulticast()\n");
|
||||
debug("cIptvUdpSocket::%s()", __FUNCTION__);
|
||||
// Check if socket exists
|
||||
if (!isActive && (socketDesc >= 0)) {
|
||||
if (!isActiveM && (socketDescM >= 0)) {
|
||||
// Join a new multicast group
|
||||
if (useIGMPv3) {
|
||||
if (useIGMPv3M) {
|
||||
// Source-specific multicast (SSM) is used
|
||||
struct group_source_req gsr;
|
||||
struct sockaddr_in *grp;
|
||||
@ -167,33 +164,33 @@ bool cIptvUdpSocket::JoinMulticast(void)
|
||||
gsr.gsr_interface = 0; // if_nametoindex("any") ?
|
||||
grp = (struct sockaddr_in*)&gsr.gsr_group;
|
||||
grp->sin_family = AF_INET;
|
||||
grp->sin_addr.s_addr = streamAddr;
|
||||
grp->sin_addr.s_addr = streamAddrM;
|
||||
grp->sin_port = 0;
|
||||
src = (struct sockaddr_in*)&gsr.gsr_source;
|
||||
src->sin_family = AF_INET;
|
||||
src->sin_addr.s_addr = sourceAddr;
|
||||
src->sin_addr.s_addr = sourceAddrM;
|
||||
src->sin_port = 0;
|
||||
ERROR_IF_RET(setsockopt(socketDesc, SOL_IP, MCAST_JOIN_SOURCE_GROUP, &gsr, sizeof(gsr)) < 0, "setsockopt(MCAST_JOIN_SOURCE_GROUP)", return false);
|
||||
ERROR_IF_RET(setsockopt(socketDescM, SOL_IP, MCAST_JOIN_SOURCE_GROUP, &gsr, sizeof(gsr)) < 0, "setsockopt(MCAST_JOIN_SOURCE_GROUP)", return false);
|
||||
}
|
||||
else {
|
||||
struct ip_mreq mreq;
|
||||
mreq.imr_multiaddr.s_addr = streamAddr;
|
||||
mreq.imr_multiaddr.s_addr = streamAddrM;
|
||||
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
|
||||
ERROR_IF_RET(setsockopt(socketDesc, SOL_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0, "setsockopt(IP_ADD_MEMBERSHIP)", return false);
|
||||
ERROR_IF_RET(setsockopt(socketDescM, SOL_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0, "setsockopt(IP_ADD_MEMBERSHIP)", return false);
|
||||
}
|
||||
// Update multicasting flag
|
||||
isActive = true;
|
||||
isActiveM = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cIptvUdpSocket::DropMulticast(void)
|
||||
{
|
||||
debug("cIptvUdpSocket::DropMulticast()\n");
|
||||
debug("cIptvUdpSocket::%s()", __FUNCTION__);
|
||||
// Check if socket exists
|
||||
if (isActive && (socketDesc >= 0)) {
|
||||
if (isActiveM && (socketDescM >= 0)) {
|
||||
// Drop the existing multicast group
|
||||
if (useIGMPv3) {
|
||||
if (useIGMPv3M) {
|
||||
// Source-specific multicast (SSM) is used
|
||||
struct group_source_req gsr;
|
||||
struct sockaddr_in *grp;
|
||||
@ -201,57 +198,57 @@ bool cIptvUdpSocket::DropMulticast(void)
|
||||
gsr.gsr_interface = 0; // if_nametoindex("any") ?
|
||||
grp = (struct sockaddr_in*)&gsr.gsr_group;
|
||||
grp->sin_family = AF_INET;
|
||||
grp->sin_addr.s_addr = streamAddr;
|
||||
grp->sin_addr.s_addr = streamAddrM;
|
||||
grp->sin_port = 0;
|
||||
src = (struct sockaddr_in*)&gsr.gsr_source;
|
||||
src->sin_family = AF_INET;
|
||||
src->sin_addr.s_addr = sourceAddr;
|
||||
src->sin_addr.s_addr = sourceAddrM;
|
||||
src->sin_port = 0;
|
||||
ERROR_IF_RET(setsockopt(socketDesc, SOL_IP, MCAST_LEAVE_SOURCE_GROUP, &gsr, sizeof(gsr)) < 0, "setsockopt(MCAST_LEAVE_SOURCE_GROUP)", return false);
|
||||
ERROR_IF_RET(setsockopt(socketDescM, SOL_IP, MCAST_LEAVE_SOURCE_GROUP, &gsr, sizeof(gsr)) < 0, "setsockopt(MCAST_LEAVE_SOURCE_GROUP)", return false);
|
||||
}
|
||||
else {
|
||||
struct ip_mreq mreq;
|
||||
mreq.imr_multiaddr.s_addr = streamAddr;
|
||||
mreq.imr_multiaddr.s_addr = streamAddrM;
|
||||
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
|
||||
ERROR_IF_RET(setsockopt(socketDesc, SOL_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)) < 0, "setsockopt(IP_DROP_MEMBERSHIP)", return false);
|
||||
ERROR_IF_RET(setsockopt(socketDescM, SOL_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)) < 0, "setsockopt(IP_DROP_MEMBERSHIP)", return false);
|
||||
}
|
||||
// Update multicasting flag
|
||||
isActive = false;
|
||||
isActiveM = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int cIptvUdpSocket::Read(unsigned char* BufferAddr, unsigned int BufferLen)
|
||||
int cIptvUdpSocket::Read(unsigned char *bufferAddrP, unsigned int bufferLenP)
|
||||
{
|
||||
//debug("cIptvUdpSocket::Read()\n");
|
||||
//debug("cIptvUdpSocket::%s()", __FUNCTION__);
|
||||
// Error out if socket not initialized
|
||||
if (socketDesc <= 0) {
|
||||
if (socketDescM <= 0) {
|
||||
error("Invalid socket in cIptvUdpSocket::%s()\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
int len = 0;
|
||||
// Read data from socket in a loop
|
||||
do {
|
||||
socklen_t addrlen = sizeof(sockAddr);
|
||||
socklen_t addrlen = sizeof(sockAddrM);
|
||||
struct msghdr msgh;
|
||||
struct iovec iov;
|
||||
char cbuf[256];
|
||||
len = 0;
|
||||
// Initialize iov and msgh structures
|
||||
memset(&msgh, 0, sizeof(struct msghdr));
|
||||
iov.iov_base = BufferAddr;
|
||||
iov.iov_len = BufferLen;
|
||||
iov.iov_base = bufferAddrP;
|
||||
iov.iov_len = bufferLenP;
|
||||
msgh.msg_control = cbuf;
|
||||
msgh.msg_controllen = sizeof(cbuf);
|
||||
msgh.msg_name = &sockAddr;
|
||||
msgh.msg_name = &sockAddrM;
|
||||
msgh.msg_namelen = addrlen;
|
||||
msgh.msg_iov = &iov;
|
||||
msgh.msg_iovlen = 1;
|
||||
msgh.msg_flags = 0;
|
||||
|
||||
if (isActive && socketDesc && BufferAddr && (BufferLen > 0))
|
||||
len = (int)recvmsg(socketDesc, &msgh, MSG_DONTWAIT);
|
||||
if (isActiveM && socketDescM && bufferAddrP && (bufferLenP > 0))
|
||||
len = (int)recvmsg(socketDescM, &msgh, MSG_DONTWAIT);
|
||||
else
|
||||
break;
|
||||
if (len > 0) {
|
||||
@ -260,36 +257,36 @@ int cIptvUdpSocket::Read(unsigned char* BufferAddr, unsigned int BufferLen)
|
||||
for (struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL; cmsg = CMSG_NXTHDR(&msgh, cmsg)) {
|
||||
if ((cmsg->cmsg_level == SOL_IP) && (cmsg->cmsg_type == IP_PKTINFO)) {
|
||||
struct in_pktinfo *i = (struct in_pktinfo *)CMSG_DATA(cmsg);
|
||||
if ((i->ipi_addr.s_addr == streamAddr) || (htonl(INADDR_ANY) == streamAddr)) {
|
||||
if ((i->ipi_addr.s_addr == streamAddrM) || (htonl(INADDR_ANY) == streamAddrM)) {
|
||||
#endif // __FreeBSD__
|
||||
if (BufferAddr[0] == TS_SYNC_BYTE)
|
||||
if (bufferAddrP[0] == TS_SYNC_BYTE)
|
||||
return len;
|
||||
else if (len > 3) {
|
||||
// http://tools.ietf.org/html/rfc3550
|
||||
// http://tools.ietf.org/html/rfc2250
|
||||
// version
|
||||
unsigned int v = (BufferAddr[0] >> 6) & 0x03;
|
||||
unsigned int v = (bufferAddrP[0] >> 6) & 0x03;
|
||||
// extension bit
|
||||
unsigned int x = (BufferAddr[0] >> 4) & 0x01;
|
||||
unsigned int x = (bufferAddrP[0] >> 4) & 0x01;
|
||||
// cscr count
|
||||
unsigned int cc = BufferAddr[0] & 0x0F;
|
||||
unsigned int cc = bufferAddrP[0] & 0x0F;
|
||||
// payload type: MPEG2 TS = 33
|
||||
//unsigned int pt = readBuffer[1] & 0x7F;
|
||||
//unsigned int pt = bufferAddrP[1] & 0x7F;
|
||||
// header lenght
|
||||
unsigned int headerlen = (3 + cc) * (unsigned int)sizeof(uint32_t);
|
||||
// check if extension
|
||||
if (x) {
|
||||
// extension header length
|
||||
unsigned int ehl = (((BufferAddr[headerlen + 2] & 0xFF) << 8) |
|
||||
(BufferAddr[headerlen + 3] & 0xFF));
|
||||
unsigned int ehl = (((bufferAddrP[headerlen + 2] & 0xFF) << 8) |
|
||||
(bufferAddrP[headerlen + 3] & 0xFF));
|
||||
// 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
|
||||
if ((v == 2) && (((len - headerlen) % TS_SIZE) == 0) &&
|
||||
(BufferAddr[headerlen] == TS_SYNC_BYTE)) {
|
||||
(bufferAddrP[headerlen] == TS_SYNC_BYTE)) {
|
||||
// Set argument point to payload in read buffer
|
||||
memmove(BufferAddr, &BufferAddr[headerlen], (len - headerlen));
|
||||
memmove(bufferAddrP, &bufferAddrP[headerlen], (len - headerlen));
|
||||
return (len - headerlen);
|
||||
}
|
||||
}
|
||||
@ -308,42 +305,42 @@ int cIptvUdpSocket::Read(unsigned char* BufferAddr, unsigned int BufferLen)
|
||||
// TCP socket class
|
||||
cIptvTcpSocket::cIptvTcpSocket()
|
||||
{
|
||||
debug("cIptvTcpSocket::cIptvTcpSocket()\n");
|
||||
debug("cIptvTcpSocket::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
cIptvTcpSocket::~cIptvTcpSocket()
|
||||
{
|
||||
debug("cIptvTcpSocket::~cIptvTcpSocket()\n");
|
||||
debug("cIptvTcpSocket::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
bool cIptvTcpSocket::OpenSocket(const int Port, const char *StreamAddr)
|
||||
bool cIptvTcpSocket::OpenSocket(const int portP, const char *streamAddrP)
|
||||
{
|
||||
debug("cIptvTcpSocket::OpenSocket()\n");
|
||||
debug("cIptvTcpSocket::%s(%s, %s)", __FUNCTION__, portP, streamAddrP);
|
||||
// Socket must be opened before setting the host address
|
||||
return (cIptvSocket::OpenSocket(Port, false) && CheckAddress(StreamAddr, &sockAddr.sin_addr.s_addr));
|
||||
return (cIptvSocket::OpenSocket(portP, false) && CheckAddress(streamAddrP, &sockAddrM.sin_addr.s_addr));
|
||||
}
|
||||
|
||||
void cIptvTcpSocket::CloseSocket(void)
|
||||
{
|
||||
debug("cIptvTcpSocket::CloseSocket()\n");
|
||||
debug("cIptvTcpSocket::%s()", __FUNCTION__);
|
||||
cIptvSocket::CloseSocket();
|
||||
}
|
||||
|
||||
bool cIptvTcpSocket::ConnectSocket(void)
|
||||
{
|
||||
debug("cIptvTcpSocket::ConnectSocket()\n");
|
||||
if (!isActive && (socketDesc >= 0)) {
|
||||
int retval = connect(socketDesc, (struct sockaddr *)&sockAddr, sizeof(sockAddr));
|
||||
debug("cIptvTcpSocket::%s()", __FUNCTION__);
|
||||
if (!isActiveM && (socketDescM >= 0)) {
|
||||
int retval = connect(socketDescM, (struct sockaddr *)&sockAddrM, sizeof(sockAddrM));
|
||||
// Non-blocking sockets always report in-progress error when connected
|
||||
ERROR_IF_RET(retval < 0 && errno != EINPROGRESS, "connect()", return false);
|
||||
// Select with 800ms timeout on the socket completion, check if it is writable
|
||||
retval = select_single_desc(socketDesc, 800000, true);
|
||||
retval = select_single_desc(socketDescM, 800000, true);
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
// Select has returned. Get socket errors if there are any
|
||||
retval = 0;
|
||||
socklen_t len = sizeof(retval);
|
||||
getsockopt(socketDesc, SOL_SOCKET, SO_ERROR, &retval, &len);
|
||||
getsockopt(socketDescM, SOL_SOCKET, SO_ERROR, &retval, &len);
|
||||
// If not any errors, then socket must be ready and connected
|
||||
if (retval != 0) {
|
||||
char tmp[64];
|
||||
@ -355,41 +352,41 @@ bool cIptvTcpSocket::ConnectSocket(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
int cIptvTcpSocket::Read(unsigned char* BufferAddr, unsigned int BufferLen)
|
||||
int cIptvTcpSocket::Read(unsigned char *bufferAddrP, unsigned int bufferLenP)
|
||||
{
|
||||
//debug("cIptvTcpSocket::Read()\n");
|
||||
//debug("cIptvTcpSocket::%s()", __FUNCTION__);
|
||||
// Error out if socket not initialized
|
||||
if (socketDesc <= 0) {
|
||||
if (socketDescM <= 0) {
|
||||
error("Invalid socket in cIptvTcpSocket::%s()\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
int len = 0;
|
||||
socklen_t addrlen = sizeof(sockAddr);
|
||||
socklen_t addrlen = sizeof(sockAddrM);
|
||||
// Read data from socket
|
||||
if (isActive && socketDesc && BufferAddr && (BufferLen > 0))
|
||||
len = (int)recvfrom(socketDesc, BufferAddr, BufferLen, MSG_DONTWAIT,
|
||||
(struct sockaddr *)&sockAddr, &addrlen);
|
||||
if (isActiveM && socketDescM && bufferAddrP && (bufferLenP > 0))
|
||||
len = (int)recvfrom(socketDescM, bufferAddrP, bufferLenP, MSG_DONTWAIT,
|
||||
(struct sockaddr *)&sockAddrM, &addrlen);
|
||||
return len;
|
||||
}
|
||||
|
||||
bool cIptvTcpSocket::ReadChar(char* BufferAddr, unsigned int TimeoutMs)
|
||||
bool cIptvTcpSocket::ReadChar(char *bufferAddrP, unsigned int timeoutMsP)
|
||||
{
|
||||
//debug("cIptvTcpSocket::ReadChar()\n");
|
||||
//debug("cIptvTcpSocket::%s()", __FUNCTION__);
|
||||
// Error out if socket not initialized
|
||||
if (socketDesc <= 0) {
|
||||
if (socketDescM <= 0) {
|
||||
error("Invalid socket in cIptvTcpSocket::%s()\n", __FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
socklen_t addrlen = sizeof(sockAddr);
|
||||
socklen_t addrlen = sizeof(sockAddrM);
|
||||
// Wait 500ms for data
|
||||
int retval = select_single_desc(socketDesc, 1000 * TimeoutMs, false);
|
||||
int retval = select_single_desc(socketDescM, 1000 * timeoutMsP, false);
|
||||
// Check if error
|
||||
if (retval < 0)
|
||||
return false;
|
||||
// Check if data available
|
||||
else if (retval) {
|
||||
retval = (int)recvfrom(socketDesc, BufferAddr, 1, MSG_DONTWAIT,
|
||||
(struct sockaddr *)&sockAddr, &addrlen);
|
||||
retval = (int)recvfrom(socketDescM, bufferAddrP, 1, MSG_DONTWAIT,
|
||||
(struct sockaddr *)&sockAddrM, &addrlen);
|
||||
if (retval <= 0)
|
||||
return false;
|
||||
}
|
||||
@ -397,15 +394,15 @@ bool cIptvTcpSocket::ReadChar(char* BufferAddr, unsigned int TimeoutMs)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cIptvTcpSocket::Write(const char* BufferAddr, unsigned int BufferLen)
|
||||
bool cIptvTcpSocket::Write(const char *bufferAddrP, unsigned int bufferLenP)
|
||||
{
|
||||
//debug("cIptvTcpSocket::Write()\n");
|
||||
//debug("cIptvTcpSocket::%s()", __FUNCTION__);
|
||||
// Error out if socket not initialized
|
||||
if (socketDesc <= 0) {
|
||||
if (socketDescM <= 0) {
|
||||
error("Invalid socket in cIptvTcpSocket::%s()\n", __FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
ERROR_IF_RET(send(socketDesc, BufferAddr, BufferLen, 0) < 0, "send()", return false);
|
||||
ERROR_IF_RET(send(socketDescM, bufferAddrP, bufferLenP, 0) < 0, "send()", return false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
30
socket.h
30
socket.h
@ -15,17 +15,17 @@
|
||||
|
||||
class cIptvSocket {
|
||||
private:
|
||||
int socketPort;
|
||||
int socketPortM;
|
||||
|
||||
protected:
|
||||
int socketDesc;
|
||||
struct sockaddr_in sockAddr;
|
||||
bool isActive;
|
||||
int socketDescM;
|
||||
struct sockaddr_in sockAddrM;
|
||||
bool isActiveM;
|
||||
|
||||
protected:
|
||||
bool OpenSocket(const int Port, const bool isUdp);
|
||||
bool OpenSocket(const int portP, const bool isUdpP);
|
||||
void CloseSocket(void);
|
||||
bool CheckAddress(const char *Addr, in_addr_t *InAddr);
|
||||
bool CheckAddress(const char *addrP, in_addr_t *inAddrP);
|
||||
|
||||
public:
|
||||
cIptvSocket();
|
||||
@ -34,16 +34,16 @@ public:
|
||||
|
||||
class cIptvUdpSocket : public cIptvSocket {
|
||||
private:
|
||||
in_addr_t streamAddr;
|
||||
in_addr_t sourceAddr;
|
||||
bool useIGMPv3;
|
||||
in_addr_t streamAddrM;
|
||||
in_addr_t sourceAddrM;
|
||||
bool useIGMPv3M;
|
||||
|
||||
public:
|
||||
cIptvUdpSocket();
|
||||
virtual ~cIptvUdpSocket();
|
||||
virtual int Read(unsigned char* BufferAddr, unsigned int BufferLen);
|
||||
virtual int Read(unsigned char* bufferAddrP, unsigned int bufferLenP);
|
||||
bool OpenSocket(const int Port);
|
||||
bool OpenSocket(const int Port, const char *StreamAddr, const char *SourceAddr, bool UseIGMPv3);
|
||||
bool OpenSocket(const int Port, const char *streamAddrP, const char *sourceAddrP, bool useIGMPv3P);
|
||||
void CloseSocket(void);
|
||||
bool JoinMulticast(void);
|
||||
bool DropMulticast(void);
|
||||
@ -53,12 +53,12 @@ class cIptvTcpSocket : public cIptvSocket {
|
||||
public:
|
||||
cIptvTcpSocket();
|
||||
virtual ~cIptvTcpSocket();
|
||||
virtual int Read(unsigned char* BufferAddr, unsigned int BufferLen);
|
||||
bool OpenSocket(const int Port, const char *StreamAddr);
|
||||
virtual int Read(unsigned char* bufferAddrP, unsigned int bufferLenP);
|
||||
bool OpenSocket(const int portP, const char *streamAddrP);
|
||||
void CloseSocket(void);
|
||||
bool ConnectSocket(void);
|
||||
bool ReadChar(char* BufferAddr, unsigned int TimeoutMs);
|
||||
bool Write(const char* BufferAddr, unsigned int BufferLen);
|
||||
bool ReadChar(char* bufferAddrP, unsigned int timeoutMsP);
|
||||
bool Write(const char* bufferAddrP, unsigned int bufferLenP);
|
||||
};
|
||||
|
||||
#endif // __IPTV_SOCKET_H
|
||||
|
14
source.c
14
source.c
@ -16,7 +16,7 @@ cIptvTransponderParameters::cIptvTransponderParameters(const char *parametersP)
|
||||
protocolM(eProtocolUDP),
|
||||
parameterM(0)
|
||||
{
|
||||
debug("cIptvTransponderParameters::cIptvTransponderParameters('%s')\n", parametersP);
|
||||
debug("cIptvTransponderParameters::%s(%s)", __FUNCTION__, parametersP);
|
||||
|
||||
memset(&addressM, 0, sizeof(addressM));
|
||||
Parse(parametersP);
|
||||
@ -24,7 +24,7 @@ cIptvTransponderParameters::cIptvTransponderParameters(const char *parametersP)
|
||||
|
||||
cString cIptvTransponderParameters::ToString(char typeP) const
|
||||
{
|
||||
debug("cIptvTransponderParameters::ToString(%c)\n", typeP);
|
||||
debug("cIptvTransponderParameters::%s(%c)", __FUNCTION__, typeP);
|
||||
|
||||
const char *protocolstr;
|
||||
|
||||
@ -51,7 +51,7 @@ cString cIptvTransponderParameters::ToString(char typeP) const
|
||||
|
||||
bool cIptvTransponderParameters::Parse(const char *strP)
|
||||
{
|
||||
debug("cIptvTransponderParameters::Parse('%s'\n", strP);
|
||||
debug("cIptvTransponderParameters::%s(%s)", __FUNCTION__, strP);
|
||||
bool result = false;
|
||||
|
||||
if (strP && *strP) {
|
||||
@ -138,7 +138,7 @@ cIptvSourceParam::cIptvSourceParam(char sourceP, const char *descriptionP)
|
||||
dataM(),
|
||||
itpM()
|
||||
{
|
||||
debug("cIptvSourceParam::cIptvSourceParam(%c, '%s')\n", sourceP, descriptionP);
|
||||
debug("cIptvSourceParam::%s(%c, %s)", __FUNCTION__, sourceP, descriptionP);
|
||||
|
||||
protocolsM[cIptvTransponderParameters::eProtocolUDP] = tr("UDP");
|
||||
protocolsM[cIptvTransponderParameters::eProtocolCURL] = tr("CURL");
|
||||
@ -149,7 +149,7 @@ cIptvSourceParam::cIptvSourceParam(char sourceP, const char *descriptionP)
|
||||
|
||||
void cIptvSourceParam::SetData(cChannel *channelP)
|
||||
{
|
||||
debug("cIptvSourceParam::SetData('%s')\n", channelP->Parameters());
|
||||
debug("cIptvSourceParam::%s(%s)", __FUNCTION__, channelP->Parameters());
|
||||
dataM = *channelP;
|
||||
nidM = dataM.Nid();
|
||||
tidM = dataM.Tid();
|
||||
@ -160,7 +160,7 @@ void cIptvSourceParam::SetData(cChannel *channelP)
|
||||
|
||||
void cIptvSourceParam::GetData(cChannel *channelP)
|
||||
{
|
||||
debug("cIptvSourceParam::GetData('%s')\n", channelP->Parameters());
|
||||
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;
|
||||
@ -168,7 +168,7 @@ void cIptvSourceParam::GetData(cChannel *channelP)
|
||||
|
||||
cOsdItem *cIptvSourceParam::GetOsdItem(void)
|
||||
{
|
||||
debug("cIptvSourceParam::GetOsdItem()\n");
|
||||
debug("cIptvSourceParam::%s()", __FUNCTION__);
|
||||
switch (paramM++) {
|
||||
case 0: return new cMenuEditIntItem( tr("Nid"), &nidM, 0);
|
||||
case 1: return new cMenuEditIntItem( tr("Tid"), &tidM, 0);
|
||||
|
46
statistics.c
46
statistics.c
@ -11,24 +11,24 @@
|
||||
#include "statistics.h"
|
||||
#include "config.h"
|
||||
|
||||
// Section statistic class
|
||||
// Section statistics class
|
||||
cIptvSectionStatistics::cIptvSectionStatistics()
|
||||
: filteredDataM(0),
|
||||
numberOfCallsM(0),
|
||||
timerM(),
|
||||
mutexM()
|
||||
{
|
||||
//debug("cIptvSectionStatistics::cIptvSectionStatistics()\n");
|
||||
//debug("cIptvSectionStatistics::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
cIptvSectionStatistics::~cIptvSectionStatistics()
|
||||
{
|
||||
//debug("cIptvSectionStatistics::~cIptvSectionStatistics()\n");
|
||||
//debug("cIptvSectionStatistics::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
cString cIptvSectionStatistics::GetSectionStatistic()
|
||||
{
|
||||
//debug("cIptvSectionStatistics::GetStatistic()\n");
|
||||
//debug("cIptvSectionStatistics::%s()", __FUNCTION__);
|
||||
cMutexLock MutexLock(&mutexM);
|
||||
uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
|
||||
timerM.Set();
|
||||
@ -44,7 +44,7 @@ cString cIptvSectionStatistics::GetSectionStatistic()
|
||||
|
||||
void cIptvSectionStatistics::AddSectionStatistic(long bytesP, long callsP)
|
||||
{
|
||||
//debug("cIptvSectionStatistics::AddStatistic(%ld, %ld)\n", bytesP, callsP);
|
||||
//debug("cIptvSectionStatistics::%s(%ld, %ld)", __FUNCTION__, bytesP, callsP);
|
||||
cMutexLock MutexLock(&mutexM);
|
||||
filteredDataM += bytesP;
|
||||
numberOfCallsM += callsP;
|
||||
@ -52,23 +52,23 @@ void cIptvSectionStatistics::AddSectionStatistic(long bytesP, long callsP)
|
||||
|
||||
// --- cIptvPidStatistics ----------------------------------------------------
|
||||
|
||||
// Device statistic class
|
||||
// Device statistics class
|
||||
cIptvPidStatistics::cIptvPidStatistics()
|
||||
: timerM(),
|
||||
mutexM()
|
||||
{
|
||||
debug("cIptvPidStatistics::cIptvPidStatistics()\n");
|
||||
memset(mostActivePidsM, '\0', sizeof(mostActivePidsM));
|
||||
debug("cIptvPidStatistics::%s()", __FUNCTION__);
|
||||
memset(mostActivePidsM, 0, sizeof(mostActivePidsM));
|
||||
}
|
||||
|
||||
cIptvPidStatistics::~cIptvPidStatistics()
|
||||
{
|
||||
debug("cIptvPidStatistics::~cIptvPidStatistics()\n");
|
||||
debug("cIptvPidStatistics::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
cString cIptvPidStatistics::GetPidStatistic()
|
||||
{
|
||||
//debug("cIptvPidStatistics::GetStatistic()\n");
|
||||
//debug("cIptvPidStatistics::%s()", __FUNCTION__);
|
||||
cMutexLock MutexLock(&mutexM);
|
||||
uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
|
||||
timerM.Set();
|
||||
@ -83,13 +83,13 @@ cString cIptvPidStatistics::GetPidStatistic()
|
||||
IptvConfig.GetUseBytes() ? "B" : "bit");
|
||||
}
|
||||
}
|
||||
memset(mostActivePidsM, '\0', sizeof(mostActivePidsM));
|
||||
memset(mostActivePidsM, 0, sizeof(mostActivePidsM));
|
||||
return s;
|
||||
}
|
||||
|
||||
int cIptvPidStatistics::SortPids(const void* data1P, const void* data2P)
|
||||
{
|
||||
//debug("cIptvPidStatistics::SortPids()\n");
|
||||
//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)
|
||||
@ -101,7 +101,7 @@ int cIptvPidStatistics::SortPids(const void* data1P, const void* data2P)
|
||||
|
||||
void cIptvPidStatistics::AddPidStatistic(u_short pidP, long payloadP)
|
||||
{
|
||||
//debug("cIptvPidStatistics::AddStatistic(%ld, %ld)\n", pidP, payloadP);
|
||||
//debug("cIptvPidStatistics::%s(%ld, %ld)", __FUNCTION__, pidP, payloadP);
|
||||
cMutexLock MutexLock(&mutexM);
|
||||
const int numberOfElements = sizeof(mostActivePidsM) / sizeof(pidStruct);
|
||||
// If our statistic already is in the array, update it and quit
|
||||
@ -125,23 +125,23 @@ void cIptvPidStatistics::AddPidStatistic(u_short pidP, long payloadP)
|
||||
|
||||
// --- cIptvStreamerStatistics -----------------------------------------------
|
||||
|
||||
// Streamer statistic class
|
||||
// Streamer statistics class
|
||||
cIptvStreamerStatistics::cIptvStreamerStatistics()
|
||||
: dataBytesM(0),
|
||||
timerM(),
|
||||
mutexM()
|
||||
{
|
||||
debug("cIptvStreamerStatistics::cIptvStreamerStatistics()\n");
|
||||
debug("cIptvStreamerStatistics::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
cIptvStreamerStatistics::~cIptvStreamerStatistics()
|
||||
{
|
||||
debug("cIptvStreamerStatistics::~cIptvStreamerStatistics()\n");
|
||||
debug("cIptvStreamerStatistics::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
cString cIptvStreamerStatistics::GetStreamerStatistic()
|
||||
{
|
||||
//debug("cIptvStreamerStatistics::GetStatistic()\n");
|
||||
//debug("cIptvStreamerStatistics::%s()", __FUNCTION__);
|
||||
cMutexLock MutexLock(&mutexM);
|
||||
uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
|
||||
timerM.Set();
|
||||
@ -155,13 +155,13 @@ cString cIptvStreamerStatistics::GetStreamerStatistic()
|
||||
|
||||
void cIptvStreamerStatistics::AddStreamerStatistic(long bytesP)
|
||||
{
|
||||
//debug("cIptvStreamerStatistics::AddStatistic(%ld)\n", bytesP);
|
||||
//debug("cIptvStreamerStatistics::%s(%ld)", __FUNCTION__, bytesP);
|
||||
cMutexLock MutexLock(&mutexM);
|
||||
dataBytesM += bytesP;
|
||||
}
|
||||
|
||||
|
||||
// Buffer statistic class
|
||||
// Buffer statistics class
|
||||
cIptvBufferStatistics::cIptvBufferStatistics()
|
||||
: dataBytesM(0),
|
||||
freeSpaceM(0),
|
||||
@ -169,17 +169,17 @@ cIptvBufferStatistics::cIptvBufferStatistics()
|
||||
timerM(),
|
||||
mutexM()
|
||||
{
|
||||
debug("cIptvBufferStatistics::cIptvBufferStatistics()\n");
|
||||
debug("cIptvBufferStatistics::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
cIptvBufferStatistics::~cIptvBufferStatistics()
|
||||
{
|
||||
debug("cIptvBufferStatistics::~cIptvBufferStatistics()\n");
|
||||
debug("cIptvBufferStatistics::%s()", __FUNCTION__);
|
||||
}
|
||||
|
||||
cString cIptvBufferStatistics::GetBufferStatistic()
|
||||
{
|
||||
//debug("cIptvBufferStatistics::GetStatistic()\n");
|
||||
//debug("cIptvBufferStatistics::%s()", __FUNCTION__);
|
||||
cMutexLock MutexLock(&mutexM);
|
||||
uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
|
||||
timerM.Set();
|
||||
@ -203,7 +203,7 @@ cString cIptvBufferStatistics::GetBufferStatistic()
|
||||
|
||||
void cIptvBufferStatistics::AddBufferStatistic(long bytesP, long usedP)
|
||||
{
|
||||
//debug("cIptvBufferStatistics::AddStatistic(%ld, %ld)\n", bytesP, usedP);
|
||||
//debug("cIptvBufferStatistics::%s(%ld, %ld)", __FUNCTION__, bytesP, usedP);
|
||||
cMutexLock MutexLock(&mutexM);
|
||||
dataBytesM += bytesP;
|
||||
if (usedP > usedSpaceM)
|
||||
|
16
streamer.c
16
streamer.c
@ -17,7 +17,7 @@ cIptvStreamer::cIptvStreamer(cRingBufferLinear* ringBufferP, unsigned int packet
|
||||
packetBufferLenM(packetLenP),
|
||||
protocolM(NULL)
|
||||
{
|
||||
debug("cIptvStreamer::cIptvStreamer(%d)\n", packetBufferLenM);
|
||||
debug("cIptvStreamer::%s(%d)", __FUNCTION__, packetBufferLenM);
|
||||
// Allocate packet buffer
|
||||
packetBufferM = MALLOC(unsigned char, packetBufferLenM);
|
||||
if (packetBufferM)
|
||||
@ -28,7 +28,7 @@ cIptvStreamer::cIptvStreamer(cRingBufferLinear* ringBufferP, unsigned int packet
|
||||
|
||||
cIptvStreamer::~cIptvStreamer()
|
||||
{
|
||||
debug("cIptvStreamer::~cIptvStreamer()\n");
|
||||
debug("cIptvStreamer::%s()", __FUNCTION__);
|
||||
// Close the protocol
|
||||
Close();
|
||||
protocolM = NULL;
|
||||
@ -39,7 +39,7 @@ cIptvStreamer::~cIptvStreamer()
|
||||
|
||||
void cIptvStreamer::Action(void)
|
||||
{
|
||||
debug("cIptvStreamer::Action(): Entering\n");
|
||||
debug("cIptvStreamer::%s(): entering", __FUNCTION__);
|
||||
// Increase priority
|
||||
//SetPriority(-1);
|
||||
// Do the thread loop
|
||||
@ -58,12 +58,12 @@ void cIptvStreamer::Action(void)
|
||||
else
|
||||
sleepM.Wait(10); // to avoid busy loop and reduce cpu load
|
||||
}
|
||||
debug("cIptvStreamer::Action(): Exiting\n");
|
||||
debug("cIptvStreamer::%s(): exiting", __FUNCTION__);
|
||||
}
|
||||
|
||||
bool cIptvStreamer::Open(void)
|
||||
{
|
||||
debug("cIptvStreamer::Open()\n");
|
||||
debug("cIptvStreamer::%s()", __FUNCTION__);
|
||||
// Open the protocol
|
||||
if (protocolM && !protocolM->Open())
|
||||
return false;
|
||||
@ -74,7 +74,7 @@ bool cIptvStreamer::Open(void)
|
||||
|
||||
bool cIptvStreamer::Close(void)
|
||||
{
|
||||
debug("cIptvStreamer::Close()\n");
|
||||
debug("cIptvStreamer::%s()", __FUNCTION__);
|
||||
// Stop thread
|
||||
sleepM.Signal();
|
||||
if (Running())
|
||||
@ -87,7 +87,7 @@ bool cIptvStreamer::Close(void)
|
||||
|
||||
bool cIptvStreamer::Set(const char* locationP, const int parameterP, const int indexP, cIptvProtocolIf* protocolP)
|
||||
{
|
||||
debug("cIptvStreamer::Set('%s', %d, %d)\n", locationP, parameterP, indexP);
|
||||
debug("cIptvStreamer::%s(%s, %d, %d)", __FUNCTION__, locationP, parameterP, indexP);
|
||||
if (!isempty(locationP)) {
|
||||
// Update protocol and set location and parameter; Close the existing one if changed
|
||||
if (protocolM != protocolP) {
|
||||
@ -107,7 +107,7 @@ bool cIptvStreamer::Set(const char* locationP, const int parameterP, const int i
|
||||
|
||||
cString cIptvStreamer::GetInformation(void)
|
||||
{
|
||||
//debug("cIptvStreamer::GetInformation()");
|
||||
//debug("cIptvStreamer::%s()", __FUNCTION__);
|
||||
cString s;
|
||||
if (protocolM)
|
||||
s = protocolM->GetInformation();
|
||||
|
Loading…
Reference in New Issue
Block a user