Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
formiano committed Dec 13, 2024
1 parent 4f6e76a commit e7ad9ac
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 9 deletions.
96 changes: 89 additions & 7 deletions lib/dvb/streamserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
#include <lib/base/init.h>
#include <lib/base/init_num.h>
#include <lib/base/wrappers.h>
#include <lib/base/nconfig.h>
#include <lib/base/esimpleconfig.h>
#include <lib/base/cfile.h>
#include <lib/base/e2avahi.h>

#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 @@ -84,7 +85,7 @@ void eStreamClient::notifier(int what)
{
size_t pos;
size_t posdur;
if (eConfigManager::getConfigBoolValue("config.streaming.authentication"))
if (eSimpleConfig::getBool("config.streaming.authentication", false))
{
bool authenticated = false;
if ((pos = request.find("Authorization: Basic ")) != std::string::npos)
Expand All @@ -100,21 +101,21 @@ void eStreamClient::notifier(int what)
char *buffer = (char*)malloc(4096);
if (buffer)
{
struct passwd pwd;
struct passwd pwd = {};
struct passwd *pwdresult = NULL;
std::string crypt;
username = authentication.substr(0, pos);
password = authentication.substr(pos + 1);
getpwnam_r(username.c_str(), &pwd, buffer, 4096, &pwdresult);
if (pwdresult)
{
struct crypt_data cryptdata;
struct crypt_data cryptdata = {};
char *cryptresult = NULL;
cryptdata.initialized = 0;
crypt = pwd.pw_passwd;
if (crypt == "*" || crypt == "x")
{
struct spwd spwd;
struct spwd spwd = {};
struct spwd *spwdresult = NULL;
getspnam_r(username.c_str(), &spwd, buffer, 4096, &spwdresult);
if (spwdresult)
Expand Down Expand Up @@ -378,6 +379,87 @@ 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 @@ -387,8 +469,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, PyString_FromString((char *)it->getRemoteHost().c_str()));
PyTuple_SET_ITEM(tuple, 1, PyString_FromString((char *)it->getServiceref().c_str()));
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, 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_ */
50 changes: 49 additions & 1 deletion lib/python/enigma_python.i
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ is usually caused by not marking PSignals as immutable.
#include <lib/python/python_helpers.h>
#include <lib/gdi/picload.h>
#include <lib/dvb/fcc.h>
#include <lib/gdi/accel.h>
#include <lib/base/esettings.h>
%}

%feature("ref") iObject "$this->AddRef(); /* eDebug(\"AddRef (%s:%d)!\", __FILE__, __LINE__); */ "
Expand Down Expand Up @@ -268,6 +270,9 @@ typedef long time_t;
%include <lib/dvb/streamserver.h>
%include <lib/dvb/rtspstreamserver.h>
%include <lib/dvb/metaparser.h>
%include <lib/gdi/accel.h>
%include <lib/base/esettings.h>
/************** eptr **************/
/************** signals **************/
Expand Down Expand Up @@ -459,11 +464,48 @@ PyObject *getFontFaces()
std::vector<std::string> v = fontRenderClass::getInstance()->getFontFaces();
ePyObject result = PyList_New(v.size());
for (size_t i = 0; i < v.size(); i++)
PyList_SET_ITEM(result, i, PyString_FromString(v[i].c_str()));
PyList_SET_ITEM(result, i, PyUnicode_FromString(v[i].c_str()));
return result;
}
%}
void setACCELDebug(int);
%{
void setACCELDebug(int enable)
{
gAccel::getInstance()->setAccelDebug(enable);
}
%}
PyObject *getDeviceDB();
%{
PyObject *getDeviceDB()
{
ePyObject result = PyDict_New();
for (const auto & [ key, value ] : HardwareDB) {
PutToDict(result, key.c_str(), value.c_str());
}
return result;
}
%}
void eProfileDone();
%{
void eProfileDone()
{
eProfile::getInstance().close();
}
%}
void eProfileWrite(const char*);
%{
void eProfileWrite(const char* checkPoint)
{
eProfile::getInstance().write(checkPoint);
}
%}
/************** temp *****************/
/* need a better place for this, i agree. */
Expand All @@ -488,6 +530,9 @@ extern void setAnimation_current_listbox(int a);
extern void pauseInit(void);
extern void resumeInit(void);
extern int checkInternetAccess(const char* host, int timeout = 3);
extern int getVFDSymbolsPoll();
extern int getE2Flags();
extern bool checkLogin(const char *user, const char *pwd);
%}
extern void addFont(const char *filename, const char *alias, int scale_factor, int is_replacement, int renderflags = 0);
Expand All @@ -510,6 +555,9 @@ extern void setAnimation_current_listbox(int a);
extern void pauseInit(void);
extern void resumeInit(void);
extern int checkInternetAccess(const char* host, int timeout = 3);
extern int getVFDSymbolsPoll();
extern int getE2Flags();
extern bool checkLogin(const char *user, const char *pwd);
%include <lib/python/python_console.i>
%include <lib/python/python_base.i>

0 comments on commit e7ad9ac

Please sign in to comment.