Moved streamer from each individual connection class to cServerConnection

This commit is contained in:
Frank Schmirler 2014-05-18 18:16:51 +02:00
parent 2cdf160648
commit 7be0c81a81
8 changed files with 57 additions and 58 deletions

View File

@ -28,6 +28,7 @@ cServerConnection::cServerConnection(const char *Protocol, int Type):
m_ReadBytes(0), m_ReadBytes(0),
m_WriteBytes(0), m_WriteBytes(0),
m_WriteIndex(0), m_WriteIndex(0),
m_Streamer(NULL),
m_OccupiedDev(NULL), m_OccupiedDev(NULL),
m_SwitchTo(NULL) m_SwitchTo(NULL)
{ {
@ -35,6 +36,7 @@ cServerConnection::cServerConnection(const char *Protocol, int Type):
cServerConnection::~cServerConnection() cServerConnection::~cServerConnection()
{ {
delete(m_Streamer);
} }
const cChannel* cServerConnection::ChannelFromString(const char *String, int *Apid, int *Dpid) { const cChannel* cServerConnection::ChannelFromString(const char *String, int *Apid, int *Dpid) {

View File

@ -7,6 +7,7 @@
#include "tools/socket.h" #include "tools/socket.h"
#include "common.h" #include "common.h"
#include "server/streamer.h"
#include <map> #include <map>
#include <string> #include <string>
@ -34,6 +35,8 @@ private:
uint m_WriteBytes; uint m_WriteBytes;
uint m_WriteIndex; uint m_WriteIndex;
cStreamdevStreamer *m_Streamer;
/* Set to occupied device when live TV was interrupted */ /* Set to occupied device when live TV was interrupted */
cDevice *m_OccupiedDev; cDevice *m_OccupiedDev;
/* Set to this connection's current channel when live TV was interrupted */ /* Set to this connection's current channel when live TV was interrupted */
@ -61,6 +64,12 @@ protected:
/* Add a request header */ /* Add a request header */
void SetHeader(const char *Name, const char *Value, const char *Prefix = "") { m_Headers.insert(tStrStr(std::string(Prefix) + Name, Value)); } void SetHeader(const char *Name, const char *Value, const char *Prefix = "") { m_Headers.insert(tStrStr(std::string(Prefix) + Name, Value)); }
/* Set the streamer */
void SetStreamer(cStreamdevStreamer* Streamer) { delete m_Streamer; m_Streamer = Streamer; }
/* Return the streamer */
cStreamdevStreamer *Streamer() const { return m_Streamer; }
static const cChannel *ChannelFromString(const char *String, int *Apid = NULL, int *Dpid = NULL); static const cChannel *ChannelFromString(const char *String, int *Apid = NULL, int *Dpid = NULL);
public: public:
@ -119,8 +128,8 @@ public:
virtual void Flushed(void) {} virtual void Flushed(void) {}
virtual void Detach(void) = 0; virtual void Attach(void) { if (m_Streamer != NULL) m_Streamer->Attach(); }
virtual void Attach(void) = 0; virtual void Detach(void) { if (m_Streamer != NULL) m_Streamer->Detach(); }
/* This connections protocol name */ /* This connections protocol name */
virtual const char* Protocol(void) const { return m_Protocol; } virtual const char* Protocol(void) const { return m_Protocol; }

View File

@ -21,7 +21,6 @@
cConnectionHTTP::cConnectionHTTP(void): cConnectionHTTP::cConnectionHTTP(void):
cServerConnection("HTTP"), cServerConnection("HTTP"),
m_Status(hsRequest), m_Status(hsRequest),
m_Streamer(NULL),
m_StreamType((eStreamType)StreamdevServerSetup.HTTPStreamType), m_StreamType((eStreamType)StreamdevServerSetup.HTTPStreamType),
m_Channel(NULL), m_Channel(NULL),
m_RecPlayer(NULL), m_RecPlayer(NULL),
@ -36,7 +35,6 @@ cConnectionHTTP::cConnectionHTTP(void):
cConnectionHTTP::~cConnectionHTTP() cConnectionHTTP::~cConnectionHTTP()
{ {
delete m_Streamer;
delete m_RecPlayer; delete m_RecPlayer;
delete m_MenuList; delete m_MenuList;
} }
@ -180,7 +178,7 @@ bool cConnectionHTTP::ProcessRequest(void)
device = SwitchDevice(m_Channel, StreamdevServerSetup.HTTPPriority); device = SwitchDevice(m_Channel, StreamdevServerSetup.HTTPPriority);
if (device != NULL) { if (device != NULL) {
cStreamdevLiveStreamer* liveStreamer = new cStreamdevLiveStreamer(StreamdevServerSetup.HTTPPriority, this); cStreamdevLiveStreamer* liveStreamer = new cStreamdevLiveStreamer(StreamdevServerSetup.HTTPPriority, this);
m_Streamer = liveStreamer; SetStreamer(liveStreamer);
if (liveStreamer->SetChannel(m_Channel, m_StreamType, m_Apid[0] ? m_Apid : NULL, m_Dpid[0] ? m_Dpid : NULL)) { if (liveStreamer->SetChannel(m_Channel, m_StreamType, m_Apid[0] ? m_Apid : NULL, m_Dpid[0] ? m_Dpid : NULL)) {
liveStreamer->SetDevice(device); liveStreamer->SetDevice(device);
if (!SetDSCP()) if (!SetDSCP())
@ -195,7 +193,7 @@ bool cConnectionHTTP::ProcessRequest(void)
return HttpResponse(200, false, "video/mpeg"); return HttpResponse(200, false, "video/mpeg");
} }
} }
DELETENULL(m_Streamer); SetStreamer(NULL);
} }
return HttpResponse(503, true); return HttpResponse(503, true);
} }
@ -213,7 +211,7 @@ bool cConnectionHTTP::ProcessRequest(void)
} }
else else
recStreamer = new cStreamdevRecStreamer(m_RecPlayer, this, m_ReplayPos); recStreamer = new cStreamdevRecStreamer(m_RecPlayer, this, m_ReplayPos);
m_Streamer = recStreamer; SetStreamer(recStreamer);
uint64_t total = recStreamer->GetLength(); uint64_t total = recStreamer->GetLength();
if (hasRange) { if (hasRange) {
int64_t length = recStreamer->SetRange(from, to); int64_t length = recStreamer->SetRange(from, to);
@ -239,7 +237,7 @@ bool cConnectionHTTP::ProcessRequest(void)
if (m_StreamType == stEXT) { if (m_StreamType == stEXT) {
cStreamdevLiveStreamer *liveStreamer = new cStreamdevLiveStreamer(StreamdevServerSetup.HTTPPriority, this); cStreamdevLiveStreamer *liveStreamer = new cStreamdevLiveStreamer(StreamdevServerSetup.HTTPPriority, this);
liveStreamer->SetChannel(m_Channel, m_StreamType, m_Apid[0] ? m_Apid : NULL, m_Dpid[0] ? m_Dpid : NULL); liveStreamer->SetChannel(m_Channel, m_StreamType, m_Apid[0] ? m_Apid : NULL, m_Dpid[0] ? m_Dpid : NULL);
m_Streamer = liveStreamer; SetStreamer(liveStreamer);
return Respond("HTTP/1.0 200 OK"); return Respond("HTTP/1.0 200 OK");
} else if (m_StreamType == stES && (m_Apid[0] || m_Dpid[0] || ISRADIO(m_Channel))) { } else if (m_StreamType == stES && (m_Apid[0] || m_Dpid[0] || ISRADIO(m_Channel))) {
return HttpResponse(200, true, "audio/mpeg", "icy-name: %s", m_Channel->Name()); return HttpResponse(200, true, "audio/mpeg", "icy-name: %s", m_Channel->Name());
@ -265,7 +263,7 @@ bool cConnectionHTTP::ProcessRequest(void)
} }
else else
recStreamer = new cStreamdevRecStreamer(m_RecPlayer, this, m_ReplayPos); recStreamer = new cStreamdevRecStreamer(m_RecPlayer, this, m_ReplayPos);
m_Streamer = recStreamer; SetStreamer(recStreamer);
uint64_t total = recStreamer->GetLength(); uint64_t total = recStreamer->GetLength();
if (hasRange) { if (hasRange) {
int64_t length = recStreamer->SetRange(from, to); int64_t length = recStreamer->SetRange(from, to);
@ -399,9 +397,9 @@ void cConnectionHTTP::Flushed(void)
} }
return; return;
} }
else if (m_Streamer != NULL) { else if (Streamer()) {
Dprintf("streamer start\n"); Dprintf("streamer start\n");
m_Streamer->Start(this); Streamer()->Start(this);
m_Status = hsFinished; m_Status = hsFinished;
} }
else { else {
@ -617,5 +615,5 @@ bool cConnectionHTTP::ProcessURI(const std::string& PathInfo)
cString cConnectionHTTP::ToText() const cString cConnectionHTTP::ToText() const
{ {
cString str = cServerConnection::ToText(); cString str = cServerConnection::ToText();
return m_Streamer ? cString::sprintf("%s\t%s", *str, *m_Streamer->ToText()) : str; return Streamer() ? cString::sprintf("%s\t%s", *str, *Streamer()->ToText()) : str;
} }

View File

@ -27,7 +27,6 @@ private:
std::string m_Authorization; std::string m_Authorization;
eHTTPStatus m_Status; eHTTPStatus m_Status;
tStrStrMap m_Params; tStrStrMap m_Params;
cStreamdevStreamer *m_Streamer;
eStreamType m_StreamType; eStreamType m_StreamType;
// job: transfer // job: transfer
const cChannel *m_Channel; const cChannel *m_Channel;
@ -60,9 +59,6 @@ public:
cConnectionHTTP(void); cConnectionHTTP(void);
virtual ~cConnectionHTTP(); virtual ~cConnectionHTTP();
virtual void Attach(void) { if (m_Streamer != NULL) m_Streamer->Attach(); }
virtual void Detach(void) { if (m_Streamer != NULL) m_Streamer->Detach(); }
virtual cString ToText() const; virtual cString ToText() const;
virtual bool CanAuthenticate(void); virtual bool CanAuthenticate(void);
@ -75,7 +71,7 @@ public:
inline bool cConnectionHTTP::Abort(void) const inline bool cConnectionHTTP::Abort(void) const
{ {
return !IsOpen() || (m_Streamer && m_Streamer->Abort()); return !IsOpen() || (Streamer() && Streamer()->Abort());
} }
#endif // VDR_STREAMDEV_SERVERS_CONNECTIONVTP_H #endif // VDR_STREAMDEV_SERVERS_CONNECTIONVTP_H

View File

@ -11,7 +11,6 @@
cConnectionIGMP::cConnectionIGMP(const char* Name, int ClientPort, eStreamType StreamType) : cConnectionIGMP::cConnectionIGMP(const char* Name, int ClientPort, eStreamType StreamType) :
cServerConnection(Name, SOCK_DGRAM), cServerConnection(Name, SOCK_DGRAM),
m_LiveStreamer(NULL),
m_ClientPort(ClientPort), m_ClientPort(ClientPort),
m_StreamType(StreamType), m_StreamType(StreamType),
m_Channel(NULL) m_Channel(NULL)
@ -20,7 +19,6 @@ cConnectionIGMP::cConnectionIGMP(const char* Name, int ClientPort, eStreamType S
cConnectionIGMP::~cConnectionIGMP() cConnectionIGMP::~cConnectionIGMP()
{ {
delete m_LiveStreamer;
} }
bool cConnectionIGMP::SetChannel(cChannel *Channel, in_addr_t Dst) bool cConnectionIGMP::SetChannel(cChannel *Channel, in_addr_t Dst)
@ -46,17 +44,18 @@ void cConnectionIGMP::Welcome()
if (ProvidesChannel(m_Channel, StreamdevServerSetup.IGMPPriority)) if (ProvidesChannel(m_Channel, StreamdevServerSetup.IGMPPriority))
device = SwitchDevice(m_Channel, StreamdevServerSetup.IGMPPriority); device = SwitchDevice(m_Channel, StreamdevServerSetup.IGMPPriority);
if (device != NULL) { if (device != NULL) {
m_LiveStreamer = new cStreamdevLiveStreamer(StreamdevServerSetup.IGMPPriority, this); cStreamdevLiveStreamer * liveStreamer = new cStreamdevLiveStreamer(StreamdevServerSetup.IGMPPriority, this);
if (m_LiveStreamer->SetChannel(m_Channel, m_StreamType)) { SetStreamer(liveStreamer);
m_LiveStreamer->SetDevice(device); if (liveStreamer->SetChannel(m_Channel, m_StreamType)) {
liveStreamer->SetDevice(device);
if (!SetDSCP()) if (!SetDSCP())
LOG_ERROR_STR("unable to set DSCP sockopt"); LOG_ERROR_STR("unable to set DSCP sockopt");
Dprintf("streamer start\n"); Dprintf("streamer start\n");
m_LiveStreamer->Start(this); liveStreamer->Start(this);
} }
else { else {
esyslog("streamdev-server IGMP: SetChannel failed"); esyslog("streamdev-server IGMP: SetChannel failed");
DELETENULL(m_LiveStreamer); SetStreamer(NULL);
} }
} }
else else
@ -65,13 +64,13 @@ void cConnectionIGMP::Welcome()
bool cConnectionIGMP::Close() bool cConnectionIGMP::Close()
{ {
if (m_LiveStreamer) if (Streamer())
m_LiveStreamer->Stop(); Streamer()->Stop();
return cServerConnection::Close(); return cServerConnection::Close();
} }
cString cConnectionIGMP::ToText() const cString cConnectionIGMP::ToText() const
{ {
cString str = cServerConnection::ToText(); cString str = cServerConnection::ToText();
return m_LiveStreamer ? cString::sprintf("%s\t%s", *str, *m_LiveStreamer->ToText()) : str; return Streamer() ? cString::sprintf("%s\t%s", *str, *Streamer()->ToText()) : str;
} }

View File

@ -17,7 +17,6 @@ class cStreamdevLiveStreamer;
class cConnectionIGMP: public cServerConnection { class cConnectionIGMP: public cServerConnection {
private: private:
cStreamdevLiveStreamer *m_LiveStreamer;
int m_ClientPort; int m_ClientPort;
eStreamType m_StreamType; eStreamType m_StreamType;
cChannel *m_Channel; cChannel *m_Channel;
@ -33,8 +32,6 @@ public:
/* Not used here */ /* Not used here */
virtual bool Command(char *Cmd) { return false; } virtual bool Command(char *Cmd) { return false; }
virtual void Attach(void) { if (m_LiveStreamer != NULL) m_LiveStreamer->Attach(); }
virtual void Detach(void) { if (m_LiveStreamer != NULL) m_LiveStreamer->Detach(); }
virtual bool Close(void); virtual bool Close(void);
virtual bool Abort(void) const; virtual bool Abort(void) const;
@ -42,7 +39,7 @@ public:
inline bool cConnectionIGMP::Abort(void) const inline bool cConnectionIGMP::Abort(void) const
{ {
return !IsOpen() || !m_LiveStreamer || m_LiveStreamer->Abort(); return !IsOpen() || !Streamer() || Streamer()->Abort();
} }
#endif // VDR_STREAMDEV_SERVERS_CONNECTIONIGMP_H #endif // VDR_STREAMDEV_SERVERS_CONNECTIONIGMP_H

View File

@ -727,7 +727,6 @@ public:
cConnectionVTP::cConnectionVTP(void): cConnectionVTP::cConnectionVTP(void):
cServerConnection("VTP"), cServerConnection("VTP"),
m_LiveSocket(NULL), m_LiveSocket(NULL),
m_LiveStreamer(NULL),
m_FilterSocket(NULL), m_FilterSocket(NULL),
m_FilterStreamer(NULL), m_FilterStreamer(NULL),
m_RecSocket(NULL), m_RecSocket(NULL),
@ -754,7 +753,8 @@ cConnectionVTP::~cConnectionVTP()
{ {
if (m_LastCommand != NULL) if (m_LastCommand != NULL)
free(m_LastCommand); free(m_LastCommand);
delete m_LiveStreamer; if (Streamer())
Streamer()->Stop();
delete m_LiveSocket; delete m_LiveSocket;
delete m_RecSocket; delete m_RecSocket;
delete m_FilterStreamer; delete m_FilterStreamer;
@ -769,8 +769,8 @@ cConnectionVTP::~cConnectionVTP()
bool cConnectionVTP::Abort(void) const bool cConnectionVTP::Abort(void) const
{ {
return !IsOpen() || (m_LiveStreamer && m_LiveStreamer->Abort()) || return !IsOpen() || (Streamer() && Streamer()->Abort()) ||
(!m_LiveStreamer && m_FilterStreamer && m_FilterStreamer->Abort()); (!Streamer() && m_FilterStreamer && m_FilterStreamer->Abort());
} }
void cConnectionVTP::Welcome(void) void cConnectionVTP::Welcome(void)
@ -786,13 +786,13 @@ void cConnectionVTP::Reject(void)
void cConnectionVTP::Detach(void) void cConnectionVTP::Detach(void)
{ {
if (m_LiveStreamer) m_LiveStreamer->Detach();
if (m_FilterStreamer) m_FilterStreamer->Detach(); if (m_FilterStreamer) m_FilterStreamer->Detach();
cServerConnection::Detach();
} }
void cConnectionVTP::Attach(void) void cConnectionVTP::Attach(void)
{ {
if (m_LiveStreamer) m_LiveStreamer->Attach(); cServerConnection::Attach();
if (m_FilterStreamer) m_FilterStreamer->Attach(); if (m_FilterStreamer) m_FilterStreamer->Attach();
} }
@ -1019,8 +1019,8 @@ bool cConnectionVTP::CmdPORT(char *Opts)
break; break;
case siLive: case siLive:
if(m_LiveSocket && m_LiveStreamer) if(m_LiveSocket && Streamer())
m_LiveStreamer->Stop(); Streamer()->Stop();
delete m_LiveSocket; delete m_LiveSocket;
m_LiveSocket = new cTBSocket(SOCK_STREAM); m_LiveSocket = new cTBSocket(SOCK_STREAM);
@ -1033,8 +1033,8 @@ bool cConnectionVTP::CmdPORT(char *Opts)
if (!m_LiveSocket->SetDSCP()) if (!m_LiveSocket->SetDSCP())
LOG_ERROR_STR("unable to set DSCP sockopt"); LOG_ERROR_STR("unable to set DSCP sockopt");
if (m_LiveStreamer) if (Streamer())
m_LiveStreamer->Start(m_LiveSocket); Streamer()->Start(m_LiveSocket);
return Respond(220, "Port command ok, data connection opened"); return Respond(220, "Port command ok, data connection opened");
break; break;
@ -1123,12 +1123,12 @@ bool cConnectionVTP::CmdTUNE(char *Opts)
if ((dev = SwitchDevice(chan, prio)) == NULL) if ((dev = SwitchDevice(chan, prio)) == NULL)
return Respond(560, "Channel not available (SwitchDevice)"); return Respond(560, "Channel not available (SwitchDevice)");
delete m_LiveStreamer; cStreamdevLiveStreamer* liveStreamer = new cStreamdevLiveStreamer(prio, this);
m_LiveStreamer = new cStreamdevLiveStreamer(prio, this); SetStreamer(liveStreamer);
m_LiveStreamer->SetChannel(chan, m_StreamType); liveStreamer->SetChannel(chan, m_StreamType);
m_LiveStreamer->SetDevice(dev); liveStreamer->SetDevice(dev);
if(m_LiveSocket) if(m_LiveSocket)
m_LiveStreamer->Start(m_LiveSocket); liveStreamer->Start(m_LiveSocket);
if(m_FiltersSupport) { if(m_FiltersSupport) {
if(!m_FilterStreamer) if(!m_FilterStreamer)
@ -1174,8 +1174,8 @@ bool cConnectionVTP::CmdPRIO(char *Opts)
if (end == Opts || (*end != '\0' && *end != ' ')) if (end == Opts || (*end != '\0' && *end != ' '))
return Respond(500, "Use: PRIO Priority"); return Respond(500, "Use: PRIO Priority");
if (m_LiveStreamer) { if (Streamer()) {
m_LiveStreamer->SetPriority(prio); ((cStreamdevLiveStreamer*) Streamer())->SetPriority(prio);
return Respond(220, "Priority changed to %d", prio); return Respond(220, "Priority changed to %d", prio);
} }
return Respond(550, "Priority not applicable"); return Respond(550, "Priority not applicable");
@ -1183,11 +1183,11 @@ bool cConnectionVTP::CmdPRIO(char *Opts)
bool cConnectionVTP::CmdSGNL(char *Opts) bool cConnectionVTP::CmdSGNL(char *Opts)
{ {
if (m_LiveStreamer) { if (Streamer()) {
int devnum = -1; int devnum = -1;
int signal = -1; int signal = -1;
int quality = -1; int quality = -1;
m_LiveStreamer->GetSignal(&devnum, &signal, &quality); ((cStreamdevLiveStreamer*) Streamer())->GetSignal(&devnum, &signal, &quality);
return Respond(220, "%d %d:%d", devnum, signal, quality); return Respond(220, "%d %d:%d", devnum, signal, quality);
} }
return Respond(550, "Signal not applicable"); return Respond(550, "Signal not applicable");
@ -1202,7 +1202,7 @@ bool cConnectionVTP::CmdADDP(char *Opts)
if (end == Opts || (*end != '\0' && *end != ' ')) if (end == Opts || (*end != '\0' && *end != ' '))
return Respond(500, "Use: ADDP Pid"); return Respond(500, "Use: ADDP Pid");
return m_LiveStreamer && m_LiveStreamer->SetPid(pid, true) return Streamer() && ((cStreamdevLiveStreamer*) Streamer())->SetPid(pid, true)
? Respond(220, "Pid %d available", pid) ? Respond(220, "Pid %d available", pid)
: Respond(560, "Pid %d not available", pid); : Respond(560, "Pid %d not available", pid);
} }
@ -1216,7 +1216,7 @@ bool cConnectionVTP::CmdDELP(char *Opts)
if (end == Opts || (*end != '\0' && *end != ' ')) if (end == Opts || (*end != '\0' && *end != ' '))
return Respond(500, "Use: DELP Pid"); return Respond(500, "Use: DELP Pid");
return m_LiveStreamer && m_LiveStreamer->SetPid(pid, false) return Streamer() && ((cStreamdevLiveStreamer*) Streamer())->SetPid(pid, false)
? Respond(220, "Pid %d stopped", pid) ? Respond(220, "Pid %d stopped", pid)
: Respond(560, "Pid %d not transferring", pid); : Respond(560, "Pid %d not transferring", pid);
} }
@ -1281,8 +1281,8 @@ bool cConnectionVTP::CmdABRT(char *Opts)
switch (id) { switch (id) {
case siLive: case siLive:
if (m_LiveStreamer) if (Streamer())
m_LiveStreamer->Stop(); Streamer()->Stop();
DELETENULL(m_LiveSocket); DELETENULL(m_LiveSocket);
break; break;
case siLiveFilter: case siLiveFilter:
@ -1838,8 +1838,8 @@ bool cConnectionVTP::Respond(int Code, const char *Message, ...)
cString cConnectionVTP::ToText() const cString cConnectionVTP::ToText() const
{ {
cString str = cServerConnection::ToText(); cString str = cServerConnection::ToText();
if (m_LiveStreamer) if (Streamer())
return cString::sprintf("%s\t%s", *str, *m_LiveStreamer->ToText()); return cString::sprintf("%s\t%s", *str, *Streamer()->ToText());
else if (m_RecPlayer) else if (m_RecPlayer)
return cString::sprintf("%s\t%s", *str, m_RecPlayer->getCurrentRecording()->Name()); return cString::sprintf("%s\t%s", *str, m_RecPlayer->getCurrentRecording()->Name());
else else

View File

@ -5,7 +5,6 @@
#include "server/recplayer.h" #include "server/recplayer.h"
class cTBSocket; class cTBSocket;
class cStreamdevLiveStreamer;
class cStreamdevFilterStreamer; class cStreamdevFilterStreamer;
class cLSTEHandler; class cLSTEHandler;
class cLSTCHandler; class cLSTCHandler;
@ -20,7 +19,6 @@ class cConnectionVTP: public cServerConnection {
private: private:
cTBSocket *m_LiveSocket; cTBSocket *m_LiveSocket;
cStreamdevLiveStreamer *m_LiveStreamer;
cTBSocket *m_FilterSocket; cTBSocket *m_FilterSocket;
cStreamdevFilterStreamer *m_FilterStreamer; cStreamdevFilterStreamer *m_FilterStreamer;
cTBSocket *m_RecSocket; cTBSocket *m_RecSocket;