vdr-plugin-streamdev/streamdev-server.c

145 lines
3.5 KiB
C
Raw Normal View History

2010-12-02 08:53:01 +01:00
/*
* streamdev.c: A plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
2010-12-02 09:43:13 +01:00
* $Id: streamdev-server.c,v 1.11 2008/10/14 11:05:47 schmirl Exp $
2010-12-02 08:53:01 +01:00
*/
#include <getopt.h>
2010-12-02 09:43:13 +01:00
#include <vdr/tools.h>
#include "remux/extern.h"
2010-12-02 08:53:01 +01:00
#include "streamdev-server.h"
#include "server/setup.h"
#include "server/server.h"
#include "server/suspend.h"
2010-12-02 09:43:13 +01:00
#if !defined(APIVERSNUM) || APIVERSNUM < 10509
#error "VDR-1.5.9 API version or greater is required!"
#endif
const char *cPluginStreamdevServer::DESCRIPTION = trNOOP("VDR Streaming Server");
2010-12-02 08:53:01 +01:00
cPluginStreamdevServer::cPluginStreamdevServer(void)
{
}
cPluginStreamdevServer::~cPluginStreamdevServer()
{
2010-12-02 09:43:13 +01:00
free(opt_auth);
free(opt_remux);
2010-12-02 08:53:01 +01:00
}
const char *cPluginStreamdevServer::Description(void)
{
return tr(DESCRIPTION);
}
const char *cPluginStreamdevServer::CommandLineHelp(void)
{
// return a string that describes all known command line options.
2010-12-02 09:43:13 +01:00
return
" -a <LOGIN:PASSWORD>, --auth=<LOGIN:PASSWORD> Credentials for HTTP authentication.\n"
" -r <CMD>, --remux=<CMD> Define an external command for remuxing.\n"
;
2010-12-02 08:53:01 +01:00
}
bool cPluginStreamdevServer::ProcessArgs(int argc, char *argv[])
{
// implement command line argument processing here if applicable.
static const struct option long_options[] = {
2010-12-02 09:43:13 +01:00
{ "auth", required_argument, NULL, 'a' },
2010-12-02 08:53:01 +01:00
{ "remux", required_argument, NULL, 'r' },
{ NULL, 0, NULL, 0 }
};
int c;
2010-12-02 09:43:13 +01:00
while((c = getopt_long(argc, argv, "a:r:", long_options, NULL)) != -1) {
2010-12-02 08:53:01 +01:00
switch (c) {
2010-12-02 09:43:13 +01:00
case 'a':
{
if (opt_auth)
free(opt_auth);
int l = strlen(optarg);
cBase64Encoder Base64((uchar*) optarg, l, l * 4 / 3 + 3);
const char *s = Base64.NextLine();
if (s)
opt_auth = strdup(s);
}
break;
2010-12-02 08:53:01 +01:00
case 'r':
2010-12-02 09:43:13 +01:00
if (opt_remux)
free(opt_remux);
opt_remux = strdup(optarg);
2010-12-02 08:53:01 +01:00
break;
default:
return false;
}
}
return true;
}
bool cPluginStreamdevServer::Start(void)
{
2010-12-02 09:43:13 +01:00
I18nRegister(PLUGIN_NAME_I18N);
2010-12-02 08:53:01 +01:00
if (!StreamdevHosts.Load(STREAMDEVHOSTSPATH, true, true)) {
esyslog("streamdev-server: error while loading %s", STREAMDEVHOSTSPATH);
2010-12-02 08:59:14 +01:00
fprintf(stderr, "streamdev-server: error while loading %s\n", STREAMDEVHOSTSPATH);
2010-12-02 08:53:01 +01:00
if (access(STREAMDEVHOSTSPATH, F_OK) != 0) {
fprintf(stderr, " Please install streamdevhosts.conf into the path "
"printed above. Without it\n"
" no client will be able to access your streaming-"
"server. An example can be\n"
" found together with this plugin's sources.\n");
}
return false;
}
2010-12-02 09:43:13 +01:00
if (!opt_remux)
opt_remux = strdup(DEFAULT_EXTERNREMUX);
2010-12-02 08:53:01 +01:00
cStreamdevServer::Initialize();
return true;
}
void cPluginStreamdevServer::Stop(void)
{
cStreamdevServer::Destruct();
}
cString cPluginStreamdevServer::Active(void)
{
if (cStreamdevServer::Active())
{
static const char *Message = NULL;
if (!Message) Message = tr("Streaming active");
return Message;
}
return NULL;
}
const char *cPluginStreamdevServer::MainMenuEntry(void)
{
if (StreamdevServerSetup.SuspendMode == smOffer && !cSuspendCtl::IsActive())
return tr("Suspend Live TV");
return NULL;
}
cOsdObject *cPluginStreamdevServer::MainMenuAction(void)
{
cControl::Launch(new cSuspendCtl);
return NULL;
}
cMenuSetupPage *cPluginStreamdevServer::SetupMenu(void)
{
return new cStreamdevServerMenuSetupPage;
}
bool cPluginStreamdevServer::SetupParse(const char *Name, const char *Value)
{
return StreamdevServerSetup.SetupParse(Name, Value);
}
VDRPLUGINCREATOR(cPluginStreamdevServer); // Don't touch this!