Skip to content

Commit

Permalink
[streamserver] just a try
Browse files Browse the repository at this point in the history
  • Loading branch information
koivo committed Apr 22, 2024
1 parent 674b402 commit ae0864c
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 11 deletions.
112 changes: 102 additions & 10 deletions lib/dvb/streamserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <lib/dvb/streamserver.h>
#include <lib/dvb/encoder.h>
#include <lib/python/python_helpers.h>

eStreamClient::eStreamClient(eStreamServer *handler, int socket, const std::string remotehost)
: parent(handler), encoderFd(-1), streamFd(socket), streamThread(NULL), m_remotehost(remotehost), m_timeout(eTimer::create(eApp))
Expand Down Expand Up @@ -52,13 +53,13 @@ void eStreamClient::start()
void eStreamClient::set_socket_option(int fd, int optid, int option)
{
if(::setsockopt(fd, SOL_SOCKET, optid, &option, sizeof(option)))
eDebug("Failed to set socket option: %m");
eDebug("[eStreamClient] Failed to set socket option: %m");
}

void eStreamClient::set_tcp_option(int fd, int optid, int option)
{
if(::setsockopt(fd, SOL_TCP, optid, &option, sizeof(option)))
eDebug("Failed to set TCP parameter: %m");
eDebug("[eStreamClient] Failed to set TCP parameter: %m");
}

void eStreamClient::notifier(int what)
Expand Down Expand Up @@ -160,8 +161,16 @@ void eStreamClient::notifier(int what)
set_tcp_option(streamFd, TCP_USER_TIMEOUT, 10 * 1000);

if (serviceref.substr(0, 10) == "file?file=") /* convert openwebif stream reqeust back to serviceref */
serviceref = std::string("1:0:1:0:0:0:0:0:0:0:") + serviceref.substr(10);

serviceref = "1:0:1:0:0:0:0:0:0:0:" + serviceref.substr(10);
/* Strip session ID from URL if it exists, PLi streaming can not handle it */
pos = serviceref.find("&sessionid=");
if (pos != std::string::npos) {
serviceref.erase(pos, std::string::npos);
}
pos = serviceref.find("?sessionid=");
if (pos != std::string::npos) {
serviceref.erase(pos, std::string::npos);
}
pos = serviceref.find('?');
if (pos == std::string::npos)
{
Expand Down Expand Up @@ -211,7 +220,8 @@ void eStreamClient::notifier(int what)
int interlaced = 0;
int aspectratio = 0;
int buffersize;
std::string vcodec, acodec;
std::string vcodec = "h264";
std::string acodec = "aac";

sscanf(request.substr(pos).c_str(), "&bitrate=%d", &bitrate);
pos = request.find("&width=");
Expand Down Expand Up @@ -249,14 +259,13 @@ void eStreamClient::notifier(int what)
acodec = acodec.substr(0, pos);
}
}

encoderFd = -1;

if(eEncoder::getInstance())
if (eEncoder::getInstance())
encoderFd = eEncoder::getInstance()->allocateEncoder(serviceref, buffersize, bitrate, width, height, framerate, !!interlaced, aspectratio,
vcodec, acodec);

if(encoderFd >= 0)
if (encoderFd >= 0)
{
m_serviceref = serviceref;
m_useencoder = true;
Expand Down Expand Up @@ -370,6 +379,89 @@ bool eStreamServer::stopStreamClient(const std::string remotehost, const std::st
return false;
}

PyObject *eStreamServer::getConnectedClientDetails(int index)
{
ePyObject ret;

eUsePtr<iDVBChannel> stream_channel;
eServiceReferenceDVB dvbservice;

int idx = 0;
for (eSmartPtrList<eStreamClient>::iterator it = clients.begin(); it != clients.end(); ++it)
{
if(idx == index)
{
dvbservice = it->getDVBService();
break;
}
}

if(dvbservice)
{
std::list<eDVBResourceManager::active_channel> list;
ePtr<eDVBResourceManager> res_mgr;
if ( !eDVBResourceManager::getInstance( res_mgr ) )
{
res_mgr->getActiveChannels(list);
}

if(list.size()) {

eDVBChannelID channel;
dvbservice.getChannelID(channel);

for (std::list<eDVBResourceManager::active_channel>::iterator i(list.begin()); i != list.end(); ++i)
{
std::string channelid = i->m_channel_id.toString();
if (channelid == channel.toString().c_str())
{
stream_channel = i->m_channel;
break;
}
}

}

}

ret = PyDict_New();

if(stream_channel)
{

ePtr<iDVBFrontend> fe;
if(!stream_channel->getFrontend(fe))
{

ePtr<iDVBFrontendData> fdata;
fe->getFrontendData(fdata);
if (fdata)
{
ePyObject fret = PyDict_New();;
frontendDataToDict(fret, fdata);
PutToDict(ret, "frontend", fret);
}


ePtr<iDVBTransponderData> tdata;
fe->getTransponderData(tdata, true);
if (tdata)
{
ePyObject tret = PyDict_New();;
transponderDataToDict(tret, tdata);
PutToDict(ret, "transponder", tret);
}

}

}

return ret;

}



PyObject *eStreamServer::getConnectedClients()
{
ePyObject ret;
Expand All @@ -379,8 +471,8 @@ PyObject *eStreamServer::getConnectedClients()
for (eSmartPtrList<eStreamClient>::iterator it = clients.begin(); it != clients.end(); ++it)
{
ePyObject tuple = PyTuple_New(3);
PyTuple_SET_ITEM(tuple, 0, PyUnicode_FromString((char *)it->getRemoteHost().c_str()));
PyTuple_SET_ITEM(tuple, 1, PyUnicode_FromString((char *)it->getServiceref().c_str()));
PyTuple_SET_ITEM(tuple, 0, PyString_FromString((char *)it->getRemoteHost().c_str()));
PyTuple_SET_ITEM(tuple, 1, PyString_FromString((char *)it->getServiceref().c_str()));
PyTuple_SET_ITEM(tuple, 2, PyLong_FromLong(it->isUsingEncoder()));
PyList_SET_ITEM(ret, idx++, tuple);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/dvb/streamserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class eStreamServer;

class eStreamClient: public eDVBServiceStream
{
private:
private:
static void set_socket_option(int fd, int optid, int option);
static void set_tcp_option(int fd, int optid, int option);

Expand Down Expand Up @@ -43,6 +43,7 @@ class eStreamClient: public eDVBServiceStream
void start();
std::string getRemoteHost();
std::string getServiceref();
eServiceReferenceDVB getDVBService() { return m_ref; }
bool isUsingEncoder();
};
#endif
Expand Down Expand Up @@ -72,6 +73,8 @@ class eStreamServer: public eServerSocket
void stopStream();
bool stopStreamClient(const std::string remotehost, const std::string serviceref);
PyObject *getConnectedClients();
PyObject *getConnectedClientDetails(int index);

};

#endif /* __DVB_STREAMSERVER_H_ */

0 comments on commit ae0864c

Please sign in to comment.