vdr-plugin-streamdev/server/streamdev-server.c

149 lines
3.6 KiB
C
Raw Permalink Normal View History

2004-12-30 23:43:55 +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:57:17 +01:00
* $Id: streamdev-server.c,v 1.2 2010/07/19 13:49:32 schmirl Exp $
2004-12-30 23:43:55 +01:00
*/
#include <getopt.h>
#include <vdr/tools.h>
2004-12-30 23:43:55 +01:00
#include "streamdev-server.h"
#include "server/menu.h"
2004-12-30 23:43:55 +01:00
#include "server/setup.h"
#include "server/server.h"
#if !defined(APIVERSNUM) || APIVERSNUM < 10516
#error "VDR-1.5.16 API version or greater is required!"
#endif
const char *cPluginStreamdevServer::DESCRIPTION = trNOOP("VDR Streaming Server");
2004-12-30 23:43:55 +01:00
2005-05-09 22:22:29 +02:00
cPluginStreamdevServer::cPluginStreamdevServer(void)
{
2004-12-30 23:43:55 +01:00
}
2005-05-09 22:22:29 +02:00
cPluginStreamdevServer::~cPluginStreamdevServer()
{
free(opt_auth);
free(opt_remux);
2004-12-30 23:43:55 +01:00
}
2005-05-09 22:22:29 +02:00
const char *cPluginStreamdevServer::Description(void)
{
2004-12-30 23:43:55 +01:00
return tr(DESCRIPTION);
}
const char *cPluginStreamdevServer::CommandLineHelp(void)
{
// return a string that describes all known command line options.
return
" -a <LOGIN:PASSWORD>, --auth=<LOGIN:PASSWORD> Credentials for HTTP authentication.\n"
" -r <CMD>, --remux=<CMD> Define an external command for remuxing.\n"
;
}
bool cPluginStreamdevServer::ProcessArgs(int argc, char *argv[])
{
// implement command line argument processing here if applicable.
static const struct option long_options[] = {
{ "auth", required_argument, NULL, 'a' },
{ "remux", required_argument, NULL, 'r' },
{ NULL, 0, NULL, 0 }
};
int c;
while((c = getopt_long(argc, argv, "a:r:", long_options, NULL)) != -1) {
switch (c) {
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;
case 'r':
if (opt_remux)
free(opt_remux);
opt_remux = strdup(optarg);
break;
default:
return false;
}
}
return true;
}
2005-05-09 22:22:29 +02:00
bool cPluginStreamdevServer::Start(void)
{
I18nRegister(PLUGIN_NAME_I18N);
2005-05-09 22:22:29 +02:00
if (!StreamdevHosts.Load(STREAMDEVHOSTSPATH, true, true)) {
esyslog("streamdev-server: error while loading %s", STREAMDEVHOSTSPATH);
fprintf(stderr, "streamdev-server: error while loading %s\n", STREAMDEVHOSTSPATH);
2005-05-09 22:22:29 +02:00
if (access(STREAMDEVHOSTSPATH, F_OK) != 0) {
2004-12-30 23:43:55 +01:00
fprintf(stderr, " Please install streamdevhosts.conf into the path "
"printed above. Without it\n"
2005-05-09 22:22:29 +02:00
" no client will be able to access your streaming-"
"server. An example can be\n"
" found together with this plugin's sources.\n");
}
2004-12-30 23:43:55 +01:00
return false;
}
if (!opt_remux)
opt_remux = strdup(DEFAULT_EXTERNREMUX);
2004-12-30 23:43:55 +01:00
2005-05-09 22:22:29 +02:00
cStreamdevServer::Initialize();
2004-12-30 23:43:55 +01:00
2005-05-09 22:22:29 +02:00
return true;
2004-12-30 23:43:55 +01:00
}
2005-05-09 22:22:29 +02:00
void cPluginStreamdevServer::Stop(void)
{
cStreamdevServer::Destruct();
}
2006-07-05 22:36:58 +02:00
cString cPluginStreamdevServer::Active(void)
2005-05-09 22:22:29 +02:00
{
2006-07-05 22:36:58 +02:00
if (cStreamdevServer::Active())
{
static const char *Message = NULL;
if (!Message) Message = tr("Streaming active");
return Message;
2006-07-05 22:36:58 +02:00
}
return NULL;
2004-12-30 23:43:55 +01:00
}
2005-05-09 22:22:29 +02:00
const char *cPluginStreamdevServer::MainMenuEntry(void)
{
return tr("Streamdev Connections");
2004-12-30 23:43:55 +01:00
}
2005-05-09 22:22:29 +02:00
cOsdObject *cPluginStreamdevServer::MainMenuAction(void)
{
return new cStreamdevServerMenu();
2004-12-30 23:43:55 +01:00
}
void cPluginStreamdevServer::MainThreadHook(void)
{
cThreadLock lock;
const cList<cServerConnection>& clients = cStreamdevServer::Clients(lock);
for (cServerConnection *s = clients.First(); s; s = clients.Next(s))
s->MainThreadHook();
}
2005-05-09 22:22:29 +02:00
cMenuSetupPage *cPluginStreamdevServer::SetupMenu(void)
{
return new cStreamdevServerMenuSetupPage;
2004-12-30 23:43:55 +01:00
}
2005-05-09 22:22:29 +02:00
bool cPluginStreamdevServer::SetupParse(const char *Name, const char *Value)
{
return StreamdevServerSetup.SetupParse(Name, Value);
2004-12-30 23:43:55 +01:00
}
VDRPLUGINCREATOR(cPluginStreamdevServer); // Don't touch this!