2007-09-12 19:28:59 +02:00
|
|
|
/*
|
|
|
|
* iptv.c: A plugin for the Video Disk Recorder
|
|
|
|
*
|
|
|
|
* See the README file for copyright information and how to reach the author.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <vdr/plugin.h>
|
|
|
|
#include "common.h"
|
2007-09-15 17:38:38 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "setup.h"
|
2007-09-12 19:28:59 +02:00
|
|
|
#include "device.h"
|
2012-04-01 21:46:08 +02:00
|
|
|
#include "iptvservice.h"
|
2007-09-12 19:28:59 +02:00
|
|
|
|
2013-04-01 21:36:41 +02:00
|
|
|
#if defined(APIVERSNUM) && APIVERSNUM < 20000
|
|
|
|
#error "VDR-2.0.0 API version or greater is required!"
|
2007-10-27 01:13:24 +02:00
|
|
|
#endif
|
|
|
|
|
2012-02-26 21:54:45 +01:00
|
|
|
#ifndef GITVERSION
|
|
|
|
#define GITVERSION ""
|
|
|
|
#endif
|
|
|
|
|
2014-01-02 20:35:38 +01:00
|
|
|
const char VERSION[] = "2.0.1" GITVERSION;
|
2007-10-28 17:22:44 +01:00
|
|
|
static const char DESCRIPTION[] = trNOOP("Experience the IPTV");
|
2007-09-12 19:28:59 +02:00
|
|
|
|
|
|
|
class cPluginIptv : public cPlugin {
|
|
|
|
private:
|
2013-02-23 14:31:11 +01:00
|
|
|
unsigned int deviceCountM;
|
|
|
|
int ParseFilters(const char *valueP, int *filtersP);
|
2007-09-12 19:28:59 +02:00
|
|
|
public:
|
|
|
|
cPluginIptv(void);
|
|
|
|
virtual ~cPluginIptv();
|
|
|
|
virtual const char *Version(void) { return VERSION; }
|
|
|
|
virtual const char *Description(void) { return tr(DESCRIPTION); }
|
|
|
|
virtual const char *CommandLineHelp(void);
|
|
|
|
virtual bool ProcessArgs(int argc, char *argv[]);
|
|
|
|
virtual bool Initialize(void);
|
|
|
|
virtual bool Start(void);
|
|
|
|
virtual void Stop(void);
|
|
|
|
virtual void Housekeeping(void);
|
|
|
|
virtual void MainThreadHook(void);
|
|
|
|
virtual cString Active(void);
|
|
|
|
virtual time_t WakeupTime(void);
|
|
|
|
virtual const char *MainMenuEntry(void) { return NULL; }
|
|
|
|
virtual cOsdObject *MainMenuAction(void);
|
|
|
|
virtual cMenuSetupPage *SetupMenu(void);
|
|
|
|
virtual bool SetupParse(const char *Name, const char *Value);
|
|
|
|
virtual bool Service(const char *Id, void *Data = NULL);
|
|
|
|
virtual const char **SVDRPHelpPages(void);
|
|
|
|
virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode);
|
|
|
|
};
|
|
|
|
|
|
|
|
cPluginIptv::cPluginIptv(void)
|
2013-02-23 14:31:11 +01:00
|
|
|
: deviceCountM(1)
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cPluginIptv::%s()", __FUNCTION__);
|
2007-09-12 19:28:59 +02:00
|
|
|
// 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!
|
|
|
|
}
|
|
|
|
|
|
|
|
cPluginIptv::~cPluginIptv()
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cPluginIptv::%s()", __FUNCTION__);
|
2007-09-12 19:28:59 +02:00
|
|
|
// Clean up after yourself!
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *cPluginIptv::CommandLineHelp(void)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cPluginIptv::%s()", __FUNCTION__);
|
2007-09-12 19:28:59 +02:00
|
|
|
// Return a string that describes all known command line options.
|
2007-10-20 19:26:46 +02:00
|
|
|
return " -d <num>, --devices=<number> number of devices to be created\n";
|
2007-09-12 19:28:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cPluginIptv::ProcessArgs(int argc, char *argv[])
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cPluginIptv::%s()", __FUNCTION__);
|
2007-09-12 19:28:59 +02:00
|
|
|
// Implement command line argument processing here if applicable.
|
|
|
|
static const struct option long_options[] = {
|
2008-01-30 22:57:33 +01:00
|
|
|
{ "devices", required_argument, NULL, 'd' },
|
2010-01-06 18:02:40 +01:00
|
|
|
{ NULL, no_argument, NULL, 0 }
|
2008-01-30 22:57:33 +01:00
|
|
|
};
|
2007-09-12 19:28:59 +02:00
|
|
|
|
|
|
|
int c;
|
2007-10-20 19:26:46 +02:00
|
|
|
while ((c = getopt_long(argc, argv, "d:", long_options, NULL)) != -1) {
|
2008-01-30 22:57:33 +01:00
|
|
|
switch (c) {
|
|
|
|
case 'd':
|
2013-02-23 14:31:11 +01:00
|
|
|
deviceCountM = atoi(optarg);
|
2008-01-30 22:57:33 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2007-09-12 19:28:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cPluginIptv::Initialize(void)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cPluginIptv::%s()", __FUNCTION__);
|
2007-09-12 19:28:59 +02:00
|
|
|
// Initialize any background activities the plugin shall perform.
|
2012-09-30 17:42:40 +02:00
|
|
|
IptvConfig.SetConfigDirectory(cPlugin::ResourceDirectory(PLUGIN_NAME_I18N));
|
2013-02-23 14:31:11 +01:00
|
|
|
return cIptvDevice::Initialize(deviceCountM);
|
2007-09-12 19:28:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cPluginIptv::Start(void)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cPluginIptv::%s()", __FUNCTION__);
|
2007-09-12 19:28:59 +02:00
|
|
|
// Start any background activities the plugin shall perform.
|
2013-02-23 01:03:27 +01:00
|
|
|
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);
|
|
|
|
}
|
2007-09-12 19:28:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cPluginIptv::Stop(void)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cPluginIptv::%s()", __FUNCTION__);
|
2007-09-12 19:28:59 +02:00
|
|
|
// Stop any background activities the plugin is performing.
|
2014-01-14 17:30:14 +01:00
|
|
|
cIptvDevice::Shutdown();
|
2013-02-23 01:03:27 +01:00
|
|
|
curl_global_cleanup();
|
2007-09-12 19:28:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cPluginIptv::Housekeeping(void)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cPluginIptv::%s()", __FUNCTION__);
|
2007-09-12 19:28:59 +02:00
|
|
|
// Perform any cleanup or other regular tasks.
|
|
|
|
}
|
|
|
|
|
|
|
|
void cPluginIptv::MainThreadHook(void)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cPluginIptv::%s()", __FUNCTION__);
|
2007-09-12 19:28:59 +02:00
|
|
|
// Perform actions in the context of the main program thread.
|
|
|
|
// WARNING: Use with great care - see PLUGINS.html!
|
|
|
|
}
|
|
|
|
|
|
|
|
cString cPluginIptv::Active(void)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cPluginIptv::%s()", __FUNCTION__);
|
2007-09-12 19:28:59 +02:00
|
|
|
// Return a message string if shutdown should be postponed
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
time_t cPluginIptv::WakeupTime(void)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cPluginIptv::%s()", __FUNCTION__);
|
2007-09-12 19:28:59 +02:00
|
|
|
// Return custom wakeup time for shutdown script
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cOsdObject *cPluginIptv::MainMenuAction(void)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cPluginIptv::%s()", __FUNCTION__);
|
2007-09-12 19:28:59 +02:00
|
|
|
// Perform the action when selected from the main VDR menu.
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cMenuSetupPage *cPluginIptv::SetupMenu(void)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cPluginIptv::%s()", __FUNCTION__);
|
2007-09-12 19:28:59 +02:00
|
|
|
// Return a setup menu in case the plugin supports one.
|
2007-09-15 17:38:38 +02:00
|
|
|
return new cIptvPluginSetup();
|
2007-09-12 19:28:59 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
int cPluginIptv::ParseFilters(const char *valueP, int *filtersP)
|
2007-10-06 02:02:50 +02:00
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cPluginIptv::%s(%s)", __FUNCTION__, valueP);
|
2007-10-06 02:02:50 +02:00
|
|
|
char buffer[256];
|
|
|
|
int n = 0;
|
2013-02-23 14:31:11 +01:00
|
|
|
while (valueP && *valueP && (n < SECTION_FILTER_TABLE_SIZE)) {
|
|
|
|
strn0cpy(buffer, valueP, sizeof(buffer));
|
2008-01-30 22:57:33 +01:00
|
|
|
int i = atoi(buffer);
|
2013-02-23 16:12:46 +01:00
|
|
|
//debug("cPluginIptv::%s(): filters[%d]=%d", __FUNCTION__, n, i);
|
2008-01-30 22:57:33 +01:00
|
|
|
if (i >= 0)
|
2013-02-23 14:31:11 +01:00
|
|
|
filtersP[n++] = i;
|
|
|
|
if ((valueP = strchr(valueP, ' ')) != NULL)
|
|
|
|
valueP++;
|
2008-01-30 22:57:33 +01:00
|
|
|
}
|
2007-10-06 02:02:50 +02:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
bool cPluginIptv::SetupParse(const char *nameP, const char *valueP)
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cPluginIptv::%s()", __FUNCTION__);
|
2007-09-12 19:28:59 +02:00
|
|
|
// Parse your own setup parameters and store their values.
|
2013-02-23 14:31:11 +01:00
|
|
|
if (!strcasecmp(nameP, "TsBufferSize"))
|
|
|
|
IptvConfig.SetTsBufferSize(atoi(valueP));
|
|
|
|
else if (!strcasecmp(nameP, "TsBufferPrefill"))
|
|
|
|
IptvConfig.SetTsBufferPrefillRatio(atoi(valueP));
|
|
|
|
else if (!strcasecmp(nameP, "ExtProtocolBasePort"))
|
|
|
|
IptvConfig.SetExtProtocolBasePort(atoi(valueP));
|
|
|
|
else if (!strcasecmp(nameP, "SectionFiltering"))
|
|
|
|
IptvConfig.SetSectionFiltering(atoi(valueP));
|
|
|
|
else if (!strcasecmp(nameP, "DisabledFilters")) {
|
2008-01-05 00:36:37 +01:00
|
|
|
int DisabledFilters[SECTION_FILTER_TABLE_SIZE];
|
2008-01-06 21:19:02 +01:00
|
|
|
for (unsigned int i = 0; i < ARRAY_SIZE(DisabledFilters); ++i)
|
2008-01-05 00:36:37 +01:00
|
|
|
DisabledFilters[i] = -1;
|
2013-02-23 14:31:11 +01:00
|
|
|
unsigned int DisabledFiltersCount = ParseFilters(valueP, DisabledFilters);
|
2008-01-06 21:19:02 +01:00
|
|
|
for (unsigned int i = 0; i < DisabledFiltersCount; ++i)
|
2007-10-06 02:02:50 +02:00
|
|
|
IptvConfig.SetDisabledFilters(i, DisabledFilters[i]);
|
|
|
|
}
|
2007-09-15 17:38:38 +02:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return true;
|
2007-09-12 19:28:59 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
bool cPluginIptv::Service(const char *idP, void *dataP)
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cPluginIptv::%s()", __FUNCTION__);
|
2013-02-23 14:31:11 +01:00
|
|
|
if (strcmp(idP,"IptvService-v1.0") == 0) {
|
|
|
|
if (dataP) {
|
|
|
|
IptvService_v1_0 *data = reinterpret_cast<IptvService_v1_0*>(dataP);
|
2012-04-01 21:46:08 +02:00
|
|
|
cIptvDevice *dev = cIptvDevice::GetIptvDevice(data->cardIndex);
|
|
|
|
if (!dev)
|
|
|
|
return false;
|
|
|
|
data->protocol = dev->GetInformation(IPTV_DEVICE_INFO_PROTOCOL);
|
|
|
|
data->bitrate = dev->GetInformation(IPTV_DEVICE_INFO_BITRATE);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2007-09-12 19:28:59 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char **cPluginIptv::SVDRPHelpPages(void)
|
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cPluginIptv::%s()", __FUNCTION__);
|
2007-10-09 18:37:16 +02:00
|
|
|
static const char *HelpPages[] = {
|
2007-10-10 00:12:17 +02:00
|
|
|
"INFO [ <page> ]\n"
|
2007-10-09 18:37:16 +02:00
|
|
|
" Print IPTV device information and statistics.\n"
|
2007-10-10 00:12:17 +02:00
|
|
|
" The output can be narrowed using optional \"page\""
|
|
|
|
" option: 1=general 2=pids 3=section filters.\n",
|
|
|
|
"MODE\n"
|
|
|
|
" Toggles between bit or byte information mode.\n",
|
2007-10-09 18:37:16 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
return HelpPages;
|
2007-09-12 19:28:59 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
cString cPluginIptv::SVDRPCommand(const char *commandP, const char *optionP, int &replyCodeP)
|
2007-09-12 19:28:59 +02:00
|
|
|
{
|
2013-02-23 16:12:46 +01:00
|
|
|
debug("cPluginIptv::%s(%s, %s)", __FUNCTION__, commandP, optionP);
|
2013-02-23 14:31:11 +01:00
|
|
|
if (strcasecmp(commandP, "INFO") == 0) {
|
2007-10-06 22:57:53 +02:00
|
|
|
cIptvDevice *device = cIptvDevice::GetIptvDevice(cDevice::ActualDevice()->CardIndex());
|
2007-10-10 00:12:17 +02:00
|
|
|
if (device) {
|
|
|
|
int page = IPTV_DEVICE_INFO_ALL;
|
2013-02-23 14:31:11 +01:00
|
|
|
if (optionP) {
|
|
|
|
page = atoi(optionP);
|
2007-10-10 00:12:17 +02:00
|
|
|
if ((page < IPTV_DEVICE_INFO_ALL) || (page > IPTV_DEVICE_INFO_FILTERS))
|
|
|
|
page = IPTV_DEVICE_INFO_ALL;
|
|
|
|
}
|
|
|
|
return device->GetInformation(page);
|
|
|
|
}
|
2007-10-06 22:57:53 +02:00
|
|
|
else {
|
2013-02-23 14:31:11 +01:00
|
|
|
replyCodeP = 550; // Requested action not taken
|
2007-10-06 22:57:53 +02:00
|
|
|
return cString("IPTV information not available!");
|
|
|
|
}
|
|
|
|
}
|
2013-02-23 14:31:11 +01:00
|
|
|
else if (strcasecmp(commandP, "MODE") == 0) {
|
2007-10-10 00:12:17 +02:00
|
|
|
unsigned int mode = !IptvConfig.GetUseBytes();
|
|
|
|
IptvConfig.SetUseBytes(mode);
|
|
|
|
return cString::sprintf("IPTV information mode is: %s\n", mode ? "bytes" : "bits");
|
|
|
|
}
|
2007-09-12 19:28:59 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
VDRPLUGINCREATOR(cPluginIptv); // Don't touch this!
|