Skip to content

Commit

Permalink
fd0lock - HiSilicon receivers in python3 close FD0 and when allocated…
Browse files Browse the repository at this point in the history
… to demux unable to handle ioctl commands - this prevents allocation of fd0 - also needs servicehisilicon update
  • Loading branch information
tony whalley authored and Huevos committed Apr 12, 2021
1 parent 018fdc2 commit e9d754e
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 9 deletions.
62 changes: 62 additions & 0 deletions lib/dvb/decoder.cpp
Expand Up @@ -7,6 +7,7 @@
#include <linux/dvb/audio.h>
#include <linux/dvb/video.h>
#include <linux/dvb/dmx.h>
#include <lib/dvb/dvb.h>

#include <unistd.h>
#include <fcntl.h>
Expand Down Expand Up @@ -35,6 +36,20 @@ eDVBAudio::eDVBAudio(eDVBDemux *demux, int dev)
{
char filename[128];
sprintf(filename, "/dev/dvb/adapter%d/audio%d", demux ? demux->adapter : 0, dev);
int tmp_fd = -1;
tmp_fd = ::open("/dev/null", O_RDONLY | O_CLOEXEC);
/* eDebug("[decoder][eDVBAudio] Opened tmp_fd: %d", tmp_fd); */
if (tmp_fd == 0)
{
::close(tmp_fd);
tmp_fd = -1;
fd0lock = ::open("/dev/null", O_RDONLY | O_CLOEXEC);
/* eDebug("[decoder][eDVBAudio] opening null fd returned: %d", fd0lock); */
}
if (tmp_fd != -1)
{
::close(tmp_fd);
}
m_fd = ::open(filename, O_RDWR | O_CLOEXEC);
if (m_fd < 0)
eWarning("[eDVBAudio] %s: %m", filename);
Expand All @@ -61,6 +76,7 @@ int eDVBAudio::startPid(int pid, int type)
if (m_fd_demux >= 0)
{
dmx_pes_filter_params pes;
memset(&pes, 0, sizeof(pes));

pes.pid = pid;
pes.input = DMX_IN_FRONTEND;
Expand Down Expand Up @@ -253,6 +269,20 @@ eDVBVideo::eDVBVideo(eDVBDemux *demux, int dev)
{
char filename[128];
sprintf(filename, "/dev/dvb/adapter%d/video%d", demux ? demux->adapter : 0, dev);
int tmp_fd = -1;
tmp_fd = ::open("/dev/null", O_RDONLY | O_CLOEXEC);
/* eDebug("[decoder][eDVBVideo] Opened tmp_fd: %d", tmp_fd); */
if (tmp_fd == 0)
{
::close(tmp_fd);
tmp_fd = -1;
fd0lock = ::open("/dev/null", O_RDONLY | O_CLOEXEC);
/* eDebug("[decoder][eDVBVideo] opening null fd returned: %d", fd0lock); */
}
if (tmp_fd != -1)
{
::close(tmp_fd);
}
m_fd = ::open(filename, O_RDWR | O_CLOEXEC);
if (m_fd < 0)
eWarning("[eDVBVideo] %s: %m", filename);
Expand Down Expand Up @@ -355,6 +385,8 @@ int eDVBVideo::startPid(int pid, int type)
if (m_fd_demux >= 0)
{
dmx_pes_filter_params pes;
memset(&pes, 0, sizeof(pes));

pes.pid = pid;
pes.input = DMX_IN_FRONTEND;
pes.output = DMX_OUT_DECODER;
Expand Down Expand Up @@ -681,6 +713,20 @@ eDVBPCR::eDVBPCR(eDVBDemux *demux, int dev): m_demux(demux), m_dev(dev)
{
char filename[128];
sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
int tmp_fd = -1;
tmp_fd = ::open("/dev/null", O_RDONLY | O_CLOEXEC);
/* eDebug("[decoder][eDVBPCR] Opened tmp_fd: %d", tmp_fd); */
if (tmp_fd == 0)
{
::close(tmp_fd);
tmp_fd = -1;
fd0lock = ::open("/dev/null", O_RDONLY | O_CLOEXEC);
/* eDebug("[decoder][eDVBPCR] opening null fd returned: %d", fd0lock); */
}
if (tmp_fd != -1)
{
::close(tmp_fd);
}
m_fd_demux = ::open(filename, O_RDWR | O_CLOEXEC);
if (m_fd_demux < 0)
eWarning("[eDVBPCR] %s: %m", filename);
Expand All @@ -691,6 +737,7 @@ int eDVBPCR::startPid(int pid)
if (m_fd_demux < 0)
return -1;
dmx_pes_filter_params pes;
memset(&pes, 0, sizeof(pes));

pes.pid = pid;
pes.input = DMX_IN_FRONTEND;
Expand Down Expand Up @@ -751,6 +798,20 @@ eDVBTText::eDVBTText(eDVBDemux *demux, int dev)
{
char filename[128];
sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
int tmp_fd = -1;
tmp_fd = ::open("/dev/null", O_RDONLY | O_CLOEXEC);
/* eDebug("[decoder][eDVBText] Opened tmp_fd: %d", tmp_fd); */
if (tmp_fd == 0)
{
::close(tmp_fd);
tmp_fd = -1;
fd0lock = ::open("/dev/null", O_RDONLY | O_CLOEXEC);
/* eDebug("[decoder][eDVBText] opening null fd returned: %d", fd0lock); */
}
if (tmp_fd != -1)
{
::close(tmp_fd);
}
m_fd_demux = ::open(filename, O_RDWR | O_CLOEXEC);
if (m_fd_demux < 0)
eWarning("[eDVBText] %s: %m", filename);
Expand All @@ -761,6 +822,7 @@ int eDVBTText::startPid(int pid)
if (m_fd_demux < 0)
return -1;
dmx_pes_filter_params pes;
memset(&pes, 0, sizeof(pes));

pes.pid = pid;
pes.input = DMX_IN_FRONTEND;
Expand Down
52 changes: 50 additions & 2 deletions lib/dvb/demux.cpp
Expand Up @@ -11,6 +11,7 @@

#include <lib/base/eerror.h>
#include <lib/base/cfile.h>
#include <lib/dvb/dvb.h>
#include <lib/dvb/idvb.h>
#include <lib/dvb/demux.h>
#include <lib/dvb/esection.h>
Expand All @@ -28,7 +29,7 @@ enum dmx_source {
DMX_SOURCE_FRONT1,
DMX_SOURCE_FRONT2,
DMX_SOURCE_FRONT3,
DMX_SOURCE_DVR0 = 16,
DMX_SOURCE_DVR0 = 16,
DMX_SOURCE_DVR1,
DMX_SOURCE_DVR2,
DMX_SOURCE_DVR3
Expand Down Expand Up @@ -81,6 +82,20 @@ int eDVBDemux::openDemux(void)
char filename[32];
snprintf(filename, sizeof(filename), "/dev/dvb/adapter%d/demux%d", adapter, demux);
eDebug("[eDVBDemux] open demux %s", filename);
int tmp_fd = -1;
tmp_fd = ::open("/dev/null", O_RDONLY | O_CLOEXEC);
/* eDebug("[eDVBDemux] Twol00 Opened tmp_fd: %d", tmp_fd); */
if (tmp_fd == 0)
{
::close(tmp_fd);
tmp_fd = -1;
fd0lock = ::open("/dev/null", O_RDONLY | O_CLOEXEC);
/* eDebug("[eDVBDemux] opening null fd returned: %d", fd0lock); */
}
if (tmp_fd != -1)
{
::close(tmp_fd);
}
return ::open(filename, O_RDWR | O_CLOEXEC);
}

Expand All @@ -92,6 +107,20 @@ int eDVBDemux::openDVR(int flags)
char filename[32];
snprintf(filename, sizeof(filename), "/dev/dvb/adapter%d/dvr%d", adapter, demux);
eDebug("[eDVBDemux] open dvr %s", filename);
int tmp_fd = -1;
tmp_fd = ::open("/dev/null", O_RDONLY | O_CLOEXEC);
/* eDebug("[eDVBDemux] Twol00 Opened tmp_fd: %d", tmp_fd); */
if (tmp_fd == 0)
{
::close(tmp_fd);
tmp_fd = -1;
fd0lock = ::open("/dev/null", O_RDONLY | O_CLOEXEC);
/* eDebug("[eDVBDemux] opening null fd returned: %d", fd0lock); */
}
if (tmp_fd != -1)
{
::close(tmp_fd);
}
return ::open(filename, flags);
#endif
}
Expand Down Expand Up @@ -266,6 +295,7 @@ RESULT eDVBSectionReader::start(const eDVBSectionFilterMask &mask)
notifier->start();

dmx_sct_filter_params sct;
memset(&sct, 0, sizeof(sct));
sct.pid = mask.pid;
sct.timeout = 0;
sct.flags = DMX_IMMEDIATE_START;
Expand Down Expand Up @@ -378,6 +408,8 @@ RESULT eDVBPESReader::start(int pid)
m_notifier->start();

dmx_pes_filter_params flt;
memset(&flt, 0, sizeof(flt));

flt.pes_type = DMX_PES_OTHER;
flt.pid = pid;
flt.input = DMX_IN_FRONTEND;
Expand Down Expand Up @@ -531,7 +563,7 @@ int eDVBRecordFileThread::AsyncIO::poll()

int eDVBRecordFileThread::AsyncIO::start(int fd, off_t offset, size_t nbytes, void* buffer)
{
memset(&aio, 0, sizeof(aiocb)); // Documentation says "zero it before call".
memset(&aio, 0, sizeof(struct aiocb)); // Documentation says "zero it before call".
aio.aio_fildes = fd;
aio.aio_nbytes = nbytes;
aio.aio_offset = offset; // Offset can be omitted with O_APPEND
Expand Down Expand Up @@ -799,6 +831,20 @@ RESULT eDVBTSRecorder::start()

char filename[128];
snprintf(filename, 128, "/dev/dvb/adapter%d/demux%d", m_demux->adapter, m_demux->demux);
int tmp_fd = -1;
tmp_fd = ::open("/dev/null", O_RDONLY | O_CLOEXEC);
/* eDebug("[eDVBTSRecorder] Opened tmp_fd: %d", tmp_fd); */
if (tmp_fd == 0)
{
::close(tmp_fd);
tmp_fd = -1;
fd0lock = ::open("/dev/null", O_RDONLY | O_CLOEXEC);
/* eDebug("[eDVBTSRecorder] opening null fd returned: %d", fd0lock); */
}
if (tmp_fd != -1)
{
::close(tmp_fd);
}

#if HAVE_HISILICON
m_source_fd = ::open(filename, O_RDONLY | O_CLOEXEC | O_NONBLOCK);
Expand All @@ -815,6 +861,8 @@ RESULT eDVBTSRecorder::start()
setBufferSize(1024*1024);

dmx_pes_filter_params flt;
memset(&flt, 0, sizeof(flt));

flt.pes_type = DMX_PES_OTHER;
flt.output = DMX_OUT_TSDEMUX_TAP;
flt.pid = i->first;
Expand Down
2 changes: 2 additions & 0 deletions lib/dvb/dvb.cpp
Expand Up @@ -28,6 +28,8 @@ DEFINE_REF(eDVBRegisteredDemux);

DEFINE_REF(eDVBAllocatedFrontend);

int fd0lock = -1;

void eDVBRegisteredFrontend::closeFrontend()
{
if (!m_inuse && m_frontend->closeFrontend()) // frontend busy
Expand Down
2 changes: 2 additions & 0 deletions lib/dvb/dvb.h
Expand Up @@ -16,6 +16,8 @@

#include <dvbsi++/service_description_section.h>

extern int fd0lock;

class eDVBChannel;

/* we do NOT handle resource conflicts here. instead, the allocateChannel
Expand Down
1 change: 1 addition & 0 deletions lib/dvb/dvbtime.cpp
Expand Up @@ -178,6 +178,7 @@ int TDT::createTable(unsigned int nr, const uint8_t *data, unsigned int max)
void TDT::start()
{
eDVBTableSpec spec;
memset(&spec, 0, sizeof(spec));
spec.pid = TimeAndDateSection::PID;
spec.tid = TimeAndDateSection::TID;
spec.tid_mask = 0xFC;
Expand Down

0 comments on commit e9d754e

Please sign in to comment.