summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorlordjaxom <lordjaxom>2005-02-11 16:44:14 +0000
committerlordjaxom <lordjaxom>2005-02-11 16:44:14 +0000
commitad70fe8c64d1acdec15db886f91676b86f5f7bd4 (patch)
tree64ffd3faac794d3a462cb642e5a7057bd29cd20c /server
parentab8f0c75f39b57cd1e28545259fb08bb7b4925b3 (diff)
downloadvdr-plugin-streamdev-ad70fe8c64d1acdec15db886f91676b86f5f7bd4.tar.gz
vdr-plugin-streamdev-ad70fe8c64d1acdec15db886f91676b86f5f7bd4.tar.bz2
- transfer
Diffstat (limited to 'server')
-rw-r--r--server/connectionHTTP.c193
-rw-r--r--server/connectionHTTP.h39
-rw-r--r--server/livestreamer.c75
-rw-r--r--server/livestreamer.h12
-rw-r--r--server/streamer.c8
-rw-r--r--server/streamer.h4
6 files changed, 219 insertions, 112 deletions
diff --git a/server/connectionHTTP.c b/server/connectionHTTP.c
index b8d1b36..c50f010 100644
--- a/server/connectionHTTP.c
+++ b/server/connectionHTTP.c
@@ -1,75 +1,80 @@
/*
- * $Id: connectionHTTP.c,v 1.6 2005/02/10 22:24:26 lordjaxom Exp $
+ * $Id: connectionHTTP.c,v 1.7 2005/02/11 16:44:15 lordjaxom Exp $
*/
#include "server/connectionHTTP.h"
-#include "server/livestreamer.h"
#include "server/setup.h"
-cConnectionHTTP::cConnectionHTTP(void): cServerConnection("HTTP") {
- m_Channel = NULL;
- m_Apid = 0;
- m_ListChannel = NULL;
- m_LiveStreamer = NULL;
- m_Status = hsRequest;
- m_StreamType = (eStreamType)StreamdevServerSetup.HTTPStreamType;
- m_Startup = false;
+cConnectionHTTP::cConnectionHTTP(void):
+ cServerConnection("HTTP"),
+ m_Status(hsRequest),
+ m_LiveStreamer(NULL),
+ m_Channel(NULL),
+ m_Apid(0),
+ m_StreamType((eStreamType)StreamdevServerSetup.HTTPStreamType),
+ m_ListChannel(NULL)
+{
+ Dprintf("constructor hsRequest\n");
}
-cConnectionHTTP::~cConnectionHTTP() {
- if (m_LiveStreamer != NULL) delete m_LiveStreamer;
+cConnectionHTTP::~cConnectionHTTP()
+{
+ delete m_LiveStreamer;
}
-void cConnectionHTTP::Detach(void) {
- if (m_LiveStreamer != NULL) m_LiveStreamer->Detach();
-}
-
-void cConnectionHTTP::Attach(void) {
- if (m_LiveStreamer != NULL) m_LiveStreamer->Attach();
-}
-
-bool cConnectionHTTP::Command(char *Cmd) {
+bool cConnectionHTTP::Command(char *Cmd)
+{
+ Dprintf("command %s\n", Cmd);
switch (m_Status) {
case hsRequest:
- if (strncmp(Cmd, "GET ", 4) == 0) return CmdGET(Cmd + 4);
- else {
- DeferClose();
- m_Status = hsTransfer; // Ignore following lines
- return Respond("HTTP/1.0 400 Bad Request");
- }
- break;
+ Dprintf("Request\n");
+ m_Request = Cmd;
+ m_Status = hsHeaders;
+ return true;
case hsHeaders:
if (*Cmd == '\0') {
- if (m_ListChannel != NULL) {
- m_Status = hsListing;
- return Respond("HTTP/1.0 200 OK")
- && Respond("Content-Type: text/html")
- && Respond("")
- && Respond("<html><head><title>VDR Channel Listing</title></head>")
- && Respond("<body><ul>");
- } else if (m_Channel == NULL) {
+ m_Status = hsBody;
+ return ProcessRequest();
+ }
+ Dprintf("header\n");
+ return true;
+ }
+ return false; // ??? shouldn't happen
+}
+
+bool cConnectionHTTP::ProcessRequest(void) {
+ Dprintf("process\n");
+ if (m_Request.substr(0, 4) == "GET " && CmdGET(m_Request.substr(4))) {
+ switch (m_Job) {
+ case hjListing:
+ return Respond("HTTP/1.0 200 OK")
+ && Respond("Content-Type: text/html")
+ && Respond("")
+ && Respond("<html><head><title>VDR Channel Listing</title></head>")
+ && Respond("<body><ul>");
+
+ case hjTransfer:
+ if (m_Channel == NULL) {
DeferClose();
return Respond("HTTP/1.0 404 not found");
}
- m_Status = hsTransfer;
+
m_LiveStreamer = new cStreamdevLiveStreamer(0);
cDevice *device = GetDevice(m_Channel, 0);
if (device != NULL) {
device->SwitchChannel(m_Channel, false);
if (m_LiveStreamer->SetChannel(m_Channel, m_StreamType, m_Apid)) {
m_LiveStreamer->SetDevice(device);
- m_Startup = true;
- if (m_StreamType == stES && (m_Channel->Vpid() == 0
- || m_Channel->Vpid() == 1 || m_Channel->Vpid() == 0x1FFF)) {
+ if (m_StreamType == stES && (m_Apid != 0 || ISRADIO(m_Channel))) {
return Respond("HTTP/1.0 200 OK")
- && Respond("Content-Type: audio/mpeg")
- && Respond((std::string)"icy-name: " + m_Channel->Name())
- && Respond("");
+ && Respond("Content-Type: audio/mpeg")
+ && Respond((std::string)"icy-name: " + m_Channel->Name())
+ && Respond("");
} else {
return Respond("HTTP/1.0 200 OK")
- && Respond("Content-Type: video/mpeg")
- && Respond("");
+ && Respond("Content-Type: video/mpeg")
+ && Respond("");
}
}
}
@@ -77,78 +82,110 @@ bool cConnectionHTTP::Command(char *Cmd) {
DeferClose();
return Respond("HTTP/1.0 409 Channel not available");
}
- break;
-
- default:
- break;
}
- return true;
+
+ DeferClose();
+ return Respond("HTTP/1.0 400 Bad Request");
}
void cConnectionHTTP::Flushed(void) {
- if (m_Status == hsListing) {
+ std::string line;
+
+ if (m_Status != hsBody)
+ return;
+
+ switch (m_Job) {
+ case hjListing:
if (m_ListChannel == NULL) {
Respond("</ul></body></html>");
DeferClose();
+ m_Status = hsFinished;
return;
}
- std::string line;
if (m_ListChannel->GroupSep())
line = (std::string)"<li>--- " + m_ListChannel->Name() + "---</li>";
- else
+ else {
+ int index = 1;
line = (std::string)"<li><a href=\"http://" + LocalIp() + ":"
+ (const char*)itoa(StreamdevServerSetup.HTTPServerPort) + "/"
+ + StreamTypes[m_StreamType] + "/"
+ (const char*)m_ListChannel->GetChannelID().ToString() + "\">"
- + m_ListChannel->Name() + "</a></li>";
+ + m_ListChannel->Name() + "</a> ";
+ for (int i = 0; m_ListChannel->Apid(i) != 0; ++i, ++index) {
+ line += "<a href=\"http://" + LocalIp() + ":"
+ + (const char*)itoa(StreamdevServerSetup.HTTPServerPort) + "/"
+ + StreamTypes[m_StreamType] + "/"
+ + (const char*)m_ListChannel->GetChannelID().ToString() + "+"
+ + (const char*)itoa(index) + "\">("
+ + m_ListChannel->Alang(i) + ")</a> ";
+ }
+ for (int i = 0; m_ListChannel->Dpid(i) != 0; ++i, ++index) {
+ line += "<a href=\"http://" + LocalIp() + ":"
+ + (const char*)itoa(StreamdevServerSetup.HTTPServerPort) + "/"
+ + StreamTypes[m_StreamType] + "/"
+ + (const char*)m_ListChannel->GetChannelID().ToString() + "+"
+ + (const char*)itoa(index) + "\">("
+ + m_ListChannel->Dlang(i) + ")</a> ";
+ }
+ line += "</li>";
+ }
if (!Respond(line))
DeferClose();
m_ListChannel = Channels.Next(m_ListChannel);
- } else if (m_Startup) {
+ break;
+
+ case hjTransfer:
Dprintf("streamer start\n");
m_LiveStreamer->Start(this);
- m_Startup = false;
+ m_Status = hsFinished;
+ break;
}
}
-bool cConnectionHTTP::CmdGET(char *Opts) {
+bool cConnectionHTTP::CmdGET(const std::string &Opts) {
+ const char *sp = Opts.c_str(), *ptr = sp, *ep;
const cChannel *chan;
- char *ep;
- int apid = 0;
+ int apid = 0, pos;
- Opts = skipspace(Opts);
- while (*Opts == '/')
- ++Opts;
+ ptr = skipspace(ptr);
+ while (*ptr == '/')
+ ++ptr;
- if (strncasecmp(Opts, "PS/", 3) == 0) {
+ if (strncasecmp(ptr, "PS/", 3) == 0) {
m_StreamType = stPS;
- Opts+=3;
- } else if (strncasecmp(Opts, "PES/", 4) == 0) {
+ ptr += 3;
+ } else if (strncasecmp(ptr, "PES/", 4) == 0) {
m_StreamType = stPES;
- Opts+=4;
- } else if (strncasecmp(Opts, "TS/", 3) == 0) {
+ ptr += 4;
+ } else if (strncasecmp(ptr, "TS/", 3) == 0) {
m_StreamType = stTS;
- Opts+=3;
- } else if (strncasecmp(Opts, "ES/", 3) == 0) {
+ ptr += 3;
+ } else if (strncasecmp(ptr, "ES/", 3) == 0) {
m_StreamType = stES;
- Opts+=3;
+ ptr += 3;
+ } else if (strncasecmp(ptr, "Extern/", 3) == 0) {
+ m_StreamType = stExtern;
+ ptr += 7;
}
- while (*Opts == '/')
- ++Opts;
- for (ep = Opts + strlen(Opts); ep >= Opts && !isspace(*ep); --ep)
+ while (*ptr == '/')
+ ++ptr;
+ for (ep = ptr + strlen(ptr); ep >= ptr && !isspace(*ep); --ep)
;
- *ep = '\0';
+
+ std::string filespec = Opts.substr(ptr - sp, ep - ptr);
+ Dprintf("substr: %s\n", filespec.c_str());
Dprintf("before channelfromstring\n");
- if (strncmp(Opts, "channels.htm", 12) == 0) {
+ if (filespec == "" || filespec.substr(0, 12) == "channels.htm") {
m_ListChannel = Channels.First();
- m_Status = hsHeaders;
- } else if ((chan = ChannelFromString(Opts, &apid)) != NULL) {
+ m_Job = hjListing;
+ } else if ((chan = ChannelFromString(filespec.c_str(), &apid)) != NULL) {
m_Channel = chan;
m_Apid = apid;
Dprintf("Apid is %d\n", apid);
- m_Status = hsHeaders;
+ m_Job = hjTransfer;
}
Dprintf("after channelfromstring\n");
return true;
diff --git a/server/connectionHTTP.h b/server/connectionHTTP.h
index 6e43d28..d12c418 100644
--- a/server/connectionHTTP.h
+++ b/server/connectionHTTP.h
@@ -1,11 +1,12 @@
/*
- * $Id: connectionHTTP.h,v 1.2 2005/02/10 22:24:26 lordjaxom Exp $
+ * $Id: connectionHTTP.h,v 1.3 2005/02/11 16:44:15 lordjaxom Exp $
*/
#ifndef VDR_STREAMDEV_SERVERS_CONNECTIONHTTP_H
#define VDR_STREAMDEV_SERVERS_CONNECTIONHTTP_H
#include "connection.h"
+#include "server/livestreamer.h"
#include <tools/select.h>
@@ -17,27 +18,39 @@ private:
enum eHTTPStatus {
hsRequest,
hsHeaders,
- hsTransfer,
- hsListing,
+ hsBody,
+ hsFinished,
};
- const cChannel *m_Channel;
- int m_Apid;
- const cChannel *m_ListChannel;
- cStreamdevLiveStreamer *m_LiveStreamer;
- eStreamType m_StreamType;
- eHTTPStatus m_Status;
- bool m_Startup;
+ enum eHTTPJob {
+ hjTransfer,
+ hjListing,
+ };
+
+ std::string m_Request;
+ //std::map<std::string,std::string> m_Headers; TODO: later?
+ eHTTPStatus m_Status;
+ eHTTPJob m_Job;
+ // job: transfer
+ cStreamdevLiveStreamer *m_LiveStreamer;
+ const cChannel *m_Channel;
+ int m_Apid;
+ eStreamType m_StreamType;
+ // job: listing
+ const cChannel *m_ListChannel;
+
+protected:
+ bool ProcessRequest(void);
public:
cConnectionHTTP(void);
virtual ~cConnectionHTTP();
- virtual void Detach(void);
- virtual void Attach(void);
+ virtual void Attach(void) { if (m_LiveStreamer != NULL) m_LiveStreamer->Attach(); }
+ virtual void Detach(void) { if (m_LiveStreamer != NULL) m_LiveStreamer->Detach(); }
virtual bool Command(char *Cmd);
- bool CmdGET(char *Opts);
+ bool CmdGET(const std::string &Opts);
virtual void Flushed(void);
};
diff --git a/server/livestreamer.c b/server/livestreamer.c
index b920ca4..aef55ef 100644
--- a/server/livestreamer.c
+++ b/server/livestreamer.c
@@ -3,6 +3,7 @@
#include "server/livestreamer.h"
#include "remux/ts2ps.h"
#include "remux/ts2es.h"
+#include "remux/extern.h"
#include "common.h"
// --- cStreamdevLiveReceiver -------------------------------------------------
@@ -37,15 +38,21 @@ cStreamdevLiveStreamer::cStreamdevLiveStreamer(int Priority):
m_Device(NULL),
m_Receiver(NULL),
m_PESRemux(NULL),
- m_Remux(NULL)
+ m_ESRemux(NULL),
+ m_PSRemux(NULL),
+ m_ExtRemux(NULL)
{
}
cStreamdevLiveStreamer::~cStreamdevLiveStreamer()
{
Dprintf("Desctructing Live streamer\n");
+ Stop();
delete m_Receiver;
- delete m_Remux;
+ delete m_PESRemux;
+ delete m_ESRemux;
+ delete m_PSRemux;
+ delete m_ExtRemux;
#if VDRVERSNUM >= 10300
//delete m_Filter; TODO
#endif
@@ -104,7 +111,7 @@ bool cStreamdevLiveStreamer::SetChannel(const cChannel *Channel, eStreamType Str
int pid = ISRADIO(m_Channel) ? m_Channel->Apid(0) : m_Channel->Vpid();
if (Apid != 0)
pid = Apid;
- m_Remux = new cTS2ESRemux(pid);
+ m_ESRemux = new cTS2ESRemux(pid);
return SetPid(pid, true);
}
@@ -121,9 +128,15 @@ bool cStreamdevLiveStreamer::SetChannel(const cChannel *Channel, eStreamType Str
&& SetPid(m_Channel->Dpid(0), true);
case stPS:
- m_Remux = new cTS2PSRemux(m_Channel->Vpid(), m_Channel->Apid(0), 0, 0, 0, true);
- return SetPid(m_Channel->Vpid(), true)
- && SetPid(m_Channel->Apid(0), true);
+ m_PSRemux = new cTS2PSRemux(m_Channel->Vpid(), m_Channel->Apids(), m_Channel->Dpids(),
+ m_Channel->Spids());
+ if (Apid != 0)
+ return SetPid(m_Channel->Vpid(), true)
+ && SetPid(Apid, true);
+ else
+ return SetPid(m_Channel->Vpid(), true)
+ && SetPid(m_Channel->Apid(0), true)
+ && SetPid(m_Channel->Dpid(0), true);
case stTS:
if (Apid != 0)
@@ -134,6 +147,17 @@ bool cStreamdevLiveStreamer::SetChannel(const cChannel *Channel, eStreamType Str
&& SetPid(m_Channel->Apid(0), true)
&& SetPid(m_Channel->Dpid(0), true);
+ case stExtern:
+ m_ExtRemux = new cExternRemux(m_Channel->Vpid(), m_Channel->Apids(), m_Channel->Dpids(),
+ m_Channel->Spids());
+ if (Apid != 0)
+ return SetPid(m_Channel->Vpid(), true)
+ && SetPid(Apid, true);
+ else
+ return SetPid(m_Channel->Vpid(), true)
+ && SetPid(m_Channel->Apid(0), true)
+ && SetPid(m_Channel->Dpid(0), true);
+
case stTSPIDS:
Dprintf("pid streaming mode\n");
return true;
@@ -170,8 +194,17 @@ int cStreamdevLiveStreamer::Put(const uchar *Data, int Count)
case stPES:
return m_PESRemux->Put(Data, Count);
- default:
- abort();
+ case stES:
+ return m_ESRemux->Put(Data, Count);
+
+ case stPS:
+ return m_PSRemux->Put(Data, Count);
+
+ case stExtern:
+ return m_ExtRemux->Put(Data, Count);
+
+ default: // shouldn't happen???
+ return 0;
}
}
@@ -184,9 +217,18 @@ uchar *cStreamdevLiveStreamer::Get(int &Count)
case stPES:
return m_PESRemux->Get(Count);
+
+ case stES:
+ return m_ESRemux->Get(Count);
+
+ case stPS:
+ return m_PSRemux->Get(Count);
- default:
- abort();
+ case stExtern:
+ return m_ExtRemux->Get(Count);
+
+ default: // shouldn't happen???
+ return 0;
}
}
@@ -201,9 +243,18 @@ void cStreamdevLiveStreamer::Del(int Count)
case stPES:
m_PESRemux->Del(Count);
break;
+
+ case stES:
+ m_ESRemux->Del(Count);
+ break;
- default:
- abort();
+ case stPS:
+ m_PSRemux->Del(Count);
+ break;
+
+ case stExtern:
+ m_ExtRemux->Del(Count);
+ break;
}
}
diff --git a/server/livestreamer.h b/server/livestreamer.h
index cd0cda6..e10d446 100644
--- a/server/livestreamer.h
+++ b/server/livestreamer.h
@@ -8,7 +8,9 @@
#include "server/livefilter.h"
#include "common.h"
-class cTSRemux;
+class cTS2PSRemux;
+class cTS2ESRemux;
+class cExternRemux;
class cRemux;
// --- cStreamdevLiveReceiver -------------------------------------------------
@@ -40,7 +42,9 @@ private:
cDevice *m_Device;
cStreamdevLiveReceiver *m_Receiver;
cRemux *m_PESRemux;
- cTSRemux *m_Remux;
+ cTS2ESRemux *m_ESRemux;
+ cTS2PSRemux *m_PSRemux;
+ cExternRemux *m_ExtRemux;
public:
cStreamdevLiveStreamer(int Priority);
@@ -55,7 +59,7 @@ public:
virtual uchar *Get(int &Count);
virtual void Del(int Count);
- virtual void Attach(void) { Dprintf("attach %p\n", m_Device);m_Device->AttachReceiver(m_Receiver); }
+ virtual void Attach(void) { m_Device->AttachReceiver(m_Receiver); }
virtual void Detach(void) { m_Device->Detach(m_Receiver); }
// Statistical purposes:
@@ -66,7 +70,7 @@ public:
inline void cStreamdevLiveReceiver::Activate(bool On)
{
- Dprintf("LiveReceiver->Activate()\n");
+ Dprintf("LiveReceiver->Activate(%d)\n", On);
m_Streamer->Activate(On);
}
diff --git a/server/streamer.c b/server/streamer.c
index 2205f74..acd4790 100644
--- a/server/streamer.c
+++ b/server/streamer.c
@@ -1,5 +1,5 @@
/*
- * $Id: streamer.c,v 1.6 2005/02/10 22:24:26 lordjaxom Exp $
+ * $Id: streamer.c,v 1.7 2005/02/11 16:44:15 lordjaxom Exp $
*/
#include <vdr/ringbuffer.h>
@@ -68,6 +68,7 @@ cStreamdevStreamer::cStreamdevStreamer(const char *Name):
cStreamdevStreamer::~cStreamdevStreamer()
{
+ Dprintf("Desctructing streamer\n");
Stop();
delete m_RingBuffer;
delete m_Writer;
@@ -83,8 +84,8 @@ void cStreamdevStreamer::Start(cTBSocket *Socket)
void cStreamdevStreamer::Activate(bool On)
{
- Dprintf("activate streamer\n");
if (On && !m_Active) {
+ Dprintf("activate streamer\n");
m_Writer->Start();
cThread::Start();
}
@@ -93,10 +94,11 @@ void cStreamdevStreamer::Activate(bool On)
void cStreamdevStreamer::Stop(void)
{
if (m_Active) {
- Dprintf("stopping live streamer\n");
+ Dprintf("stopping streamer\n");
m_Active = false;
Cancel(3);
}
+ DELETENULL(m_Writer);
}
void cStreamdevStreamer::Action(void)
diff --git a/server/streamer.h b/server/streamer.h
index 4db30a8..295b8ca 100644
--- a/server/streamer.h
+++ b/server/streamer.h
@@ -1,5 +1,5 @@
/*
- * $Id: streamer.h,v 1.4 2005/02/10 22:24:26 lordjaxom Exp $
+ * $Id: streamer.h,v 1.5 2005/02/11 16:44:15 lordjaxom Exp $
*/
#ifndef VDR_STREAMDEV_STREAMER_H
@@ -13,7 +13,7 @@ class cTBSocket;
class cStreamdevStreamer;
#define STREAMERBUFSIZE MEGABYTE(4)
-#define WRITERBUFSIZE KILOBYTE(192)
+#define WRITERBUFSIZE KILOBYTE(256)
// --- cStreamdevWriter -------------------------------------------------------