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_WriteBytes(0),
m_WriteIndex(0),
m_Streamer(NULL),
m_OccupiedDev(NULL),
m_SwitchTo(NULL)
{
@ -35,6 +36,7 @@ cServerConnection::cServerConnection(const char *Protocol, int Type):
cServerConnection::~cServerConnection()
{
delete(m_Streamer);
}
const cChannel* cServerConnection::ChannelFromString(const char *String, int *Apid, int *Dpid) {

View File

@ -7,6 +7,7 @@
#include "tools/socket.h"
#include "common.h"
#include "server/streamer.h"
#include <map>
#include <string>
@ -34,6 +35,8 @@ private:
uint m_WriteBytes;
uint m_WriteIndex;
cStreamdevStreamer *m_Streamer;
/* Set to occupied device when live TV was interrupted */
cDevice *m_OccupiedDev;
/* Set to this connection's current channel when live TV was interrupted */
@ -61,6 +64,12 @@ protected:
/* Add a request header */
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);
public:
@ -119,8 +128,8 @@ public:
virtual void Flushed(void) {}
virtual void Detach(void) = 0;
virtual void Attach(void) = 0;
virtual void Attach(void) { if (m_Streamer != NULL) m_Streamer->Attach(); }
virtual void Detach(void) { if (m_Streamer != NULL) m_Streamer->Detach(); }
/* This connections protocol name */
virtual const char* Protocol(void) const { return m_Protocol; }

View File

@ -21,7 +21,6 @@
cConnectionHTTP::cConnectionHTTP(void):
cServerConnection("HTTP"),
m_Status(hsRequest),
m_Streamer(NULL),
m_StreamType((eStreamType)StreamdevServerSetup.HTTPStreamType),
m_Channel(NULL),
m_RecPlayer(NULL),
@ -36,7 +35,6 @@ cConnectionHTTP::cConnectionHTTP(void):
cConnectionHTTP::~cConnectionHTTP()
{
delete m_Streamer;
delete m_RecPlayer;
delete m_MenuList;
}
@ -180,7 +178,7 @@ bool cConnectionHTTP::ProcessRequest(void)
device = SwitchDevice(m_Channel, StreamdevServerSetup.HTTPPriority);
if (device != NULL) {
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)) {
liveStreamer->SetDevice(device);
if (!SetDSCP())
@ -195,7 +193,7 @@ bool cConnectionHTTP::ProcessRequest(void)
return HttpResponse(200, false, "video/mpeg");
}
}
DELETENULL(m_Streamer);
SetStreamer(NULL);
}
return HttpResponse(503, true);
}
@ -213,7 +211,7 @@ bool cConnectionHTTP::ProcessRequest(void)
}
else
recStreamer = new cStreamdevRecStreamer(m_RecPlayer, this, m_ReplayPos);
m_Streamer = recStreamer;
SetStreamer(recStreamer);
uint64_t total = recStreamer->GetLength();
if (hasRange) {
int64_t length = recStreamer->SetRange(from, to);
@ -239,7 +237,7 @@ bool cConnectionHTTP::ProcessRequest(void)
if (m_StreamType == stEXT) {
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);
m_Streamer = liveStreamer;
SetStreamer(liveStreamer);
return Respond("HTTP/1.0 200 OK");
} 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());
@ -265,7 +263,7 @@ bool cConnectionHTTP::ProcessRequest(void)
}
else
recStreamer = new cStreamdevRecStreamer(m_RecPlayer, this, m_ReplayPos);
m_Streamer = recStreamer;
SetStreamer(recStreamer);
uint64_t total = recStreamer->GetLength();
if (hasRange) {
int64_t length = recStreamer->SetRange(from, to);
@ -399,9 +397,9 @@ void cConnectionHTTP::Flushed(void)
}
return;
}
else if (m_Streamer != NULL) {
else if (Streamer()) {
Dprintf("streamer start\n");
m_Streamer->Start(this);
Streamer()->Start(this);
m_Status = hsFinished;
}
else {
@ -617,5 +615,5 @@ bool cConnectionHTTP::ProcessURI(const std::string& PathInfo)
cString cConnectionHTTP::ToText() const
{
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;
eHTTPStatus m_Status;
tStrStrMap m_Params;
cStreamdevStreamer *m_Streamer;
eStreamType m_StreamType;
// job: transfer
const cChannel *m_Channel;
@ -60,9 +59,6 @@ public:
cConnectionHTTP(void);
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 bool CanAuthenticate(void);
@ -75,7 +71,7 @@ public:
inline bool cConnectionHTTP::Abort(void) const
{
return !IsOpen() || (m_Streamer && m_Streamer->Abort());
return !IsOpen() || (Streamer() && Streamer()->Abort());
}
#endif // VDR_STREAMDEV_SERVERS_CONNECTIONVTP_H

View File

@ -11,7 +11,6 @@
cConnectionIGMP::cConnectionIGMP(const char* Name, int ClientPort, eStreamType StreamType) :
cServerConnection(Name, SOCK_DGRAM),
m_LiveStreamer(NULL),
m_ClientPort(ClientPort),
m_StreamType(StreamType),
m_Channel(NULL)
@ -20,7 +19,6 @@ cConnectionIGMP::cConnectionIGMP(const char* Name, int ClientPort, eStreamType S
cConnectionIGMP::~cConnectionIGMP()
{
delete m_LiveStreamer;
}
bool cConnectionIGMP::SetChannel(cChannel *Channel, in_addr_t Dst)
@ -46,17 +44,18 @@ void cConnectionIGMP::Welcome()
if (ProvidesChannel(m_Channel, StreamdevServerSetup.IGMPPriority))
device = SwitchDevice(m_Channel, StreamdevServerSetup.IGMPPriority);
if (device != NULL) {
m_LiveStreamer = new cStreamdevLiveStreamer(StreamdevServerSetup.IGMPPriority, this);
if (m_LiveStreamer->SetChannel(m_Channel, m_StreamType)) {
m_LiveStreamer->SetDevice(device);
cStreamdevLiveStreamer * liveStreamer = new cStreamdevLiveStreamer(StreamdevServerSetup.IGMPPriority, this);
SetStreamer(liveStreamer);
if (liveStreamer->SetChannel(m_Channel, m_StreamType)) {
liveStreamer->SetDevice(device);
if (!SetDSCP())
LOG_ERROR_STR("unable to set DSCP sockopt");
Dprintf("streamer start\n");
m_LiveStreamer->Start(this);
liveStreamer->Start(this);
}
else {
esyslog("streamdev-server IGMP: SetChannel failed");
DELETENULL(m_LiveStreamer);
SetStreamer(NULL);
}
}
else
@ -65,13 +64,13 @@ void cConnectionIGMP::Welcome()
bool cConnectionIGMP::Close()
{
if (m_LiveStreamer)
m_LiveStreamer->Stop();
if (Streamer())
Streamer()->Stop();
return cServerConnection::Close();
}
cString cConnectionIGMP::ToText() const
{
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 {
private:
cStreamdevLiveStreamer *m_LiveStreamer;
int m_ClientPort;
eStreamType m_StreamType;
cChannel *m_Channel;
@ -33,8 +32,6 @@ public:
/* Not used here */
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 Abort(void) const;
@ -42,7 +39,7 @@ public:
inline bool cConnectionIGMP::Abort(void) const
{
return !IsOpen() || !m_LiveStreamer || m_LiveStreamer->Abort();
return !IsOpen() || !Streamer() || Streamer()->Abort();
}
#endif // VDR_STREAMDEV_SERVERS_CONNECTIONIGMP_H

View File

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

View File

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