mirror of
https://github.com/tuxbox-neutrino/libstb-hal.git
synced 2025-08-26 15:02:58 +02:00
- formatting code using astyle
Conflicts: libarmbox/dmx.cpp libgeneric-pc/video_lib.h libspark/dmx.cpp Signed-off-by: Thilo Graf <dbt@novatux.de>
This commit is contained in:
@@ -50,15 +50,16 @@ extern cVideo *videoDecoder;
|
||||
#define hal_debug_z(args...) _hal_debug(HAL_DEBUG_DEMUX, thiz, args)
|
||||
|
||||
#define dmx_err(_errfmt, _errstr, _revents) do { \
|
||||
hal_info("%s " _errfmt " fd:%d, ev:0x%x %s pid:0x%04hx flt:0x%02hx\n", \
|
||||
__func__, _errstr, fd, _revents, DMX_T[dmx_type], pid, flt); \
|
||||
} while(0);
|
||||
hal_info("%s " _errfmt " fd:%d, ev:0x%x %s pid:0x%04hx flt:0x%02hx\n", \
|
||||
__func__, _errstr, fd, _revents, DMX_T[dmx_type], pid, flt); \
|
||||
} while(0);
|
||||
|
||||
cDemux *videoDemux = NULL;
|
||||
cDemux *audioDemux = NULL;
|
||||
//cDemux *pcrDemux = NULL;
|
||||
|
||||
static const char *DMX_T[] = {
|
||||
static const char *DMX_T[] =
|
||||
{
|
||||
"DMX_INVALID",
|
||||
"DMX_VIDEO",
|
||||
"DMX_AUDIO",
|
||||
@@ -91,6 +92,13 @@ static int dmx_source[NUM_DEMUX] = { 0, 0, 0, 0 };
|
||||
#endif
|
||||
#endif
|
||||
|
||||
char dmxdev[32];
|
||||
static char *devname(int adapter, int demux)
|
||||
{
|
||||
snprintf(dmxdev, sizeof(dmxdev), "/dev/dvb/adapter%d/demux%d", adapter, demux);
|
||||
return dmxdev;
|
||||
}
|
||||
|
||||
/* map the device numbers. */
|
||||
#if BOXMODEL_VUULTIMO4K
|
||||
#define NUM_DEMUXDEV 24
|
||||
@@ -101,36 +109,7 @@ static int dmx_source[NUM_DEMUX] = { 0, 0, 0, 0 };
|
||||
#define NUM_DEMUXDEV 8
|
||||
#endif
|
||||
#endif
|
||||
static const char *devname[NUM_DEMUXDEV] = {
|
||||
"/dev/dvb/adapter0/demux0",
|
||||
"/dev/dvb/adapter0/demux1",
|
||||
"/dev/dvb/adapter0/demux2",
|
||||
"/dev/dvb/adapter0/demux3",
|
||||
"/dev/dvb/adapter0/demux4",
|
||||
"/dev/dvb/adapter0/demux5",
|
||||
"/dev/dvb/adapter0/demux6",
|
||||
"/dev/dvb/adapter0/demux7"
|
||||
#if BOXMODEL_VUSOLO4K || BOXMODEL_VUDUO4K || BOXMODEL_VUULTIMO4K || BOXMODEL_VUUNO4KSE || BOXMODEL_VUUNO4K
|
||||
, "/dev/dvb/adapter0/demux8"
|
||||
, "/dev/dvb/adapter0/demux9"
|
||||
, "/dev/dvb/adapter0/demux10"
|
||||
, "/dev/dvb/adapter0/demux11"
|
||||
, "/dev/dvb/adapter0/demux12"
|
||||
, "/dev/dvb/adapter0/demux13"
|
||||
, "/dev/dvb/adapter0/demux14"
|
||||
, "/dev/dvb/adapter0/demux15"
|
||||
#if BOXMODEL_VUULTIMO4K
|
||||
, "/dev/dvb/adapter0/demux16"
|
||||
, "/dev/dvb/adapter0/demux17"
|
||||
, "/dev/dvb/adapter0/demux18"
|
||||
, "/dev/dvb/adapter0/demux19"
|
||||
, "/dev/dvb/adapter0/demux20"
|
||||
, "/dev/dvb/adapter0/demux21"
|
||||
, "/dev/dvb/adapter0/demux22"
|
||||
, "/dev/dvb/adapter0/demux23"
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
/* did we already DMX_SET_SOURCE on that demux device? */
|
||||
#if BOXMODEL_VUULTIMO4K
|
||||
static bool init[NUM_DEMUXDEV] = { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false };
|
||||
@@ -142,7 +121,8 @@ static bool init[NUM_DEMUXDEV] = { false, false, false, false, false, false, fal
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef struct dmx_pdata {
|
||||
typedef struct dmx_pdata
|
||||
{
|
||||
int last_source;
|
||||
OpenThreads::Mutex *mutex;
|
||||
} dmx_pdata;
|
||||
@@ -190,31 +170,33 @@ bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBuffe
|
||||
|
||||
static bool _open(cDemux *thiz, int num, int &fd, int &last_source, DMX_CHANNEL_TYPE dmx_type, int buffersize)
|
||||
{
|
||||
int flags = O_RDWR|O_CLOEXEC;
|
||||
int flags = O_RDWR | O_CLOEXEC;
|
||||
int devnum = dmx_source[num];
|
||||
if (last_source == devnum) {
|
||||
if (last_source == devnum)
|
||||
{
|
||||
hal_debug_z("%s #%d: source (%d) did not change\n", __func__, num, last_source);
|
||||
if (fd > -1)
|
||||
return true;
|
||||
}
|
||||
if (fd > -1) {
|
||||
if (fd > -1)
|
||||
{
|
||||
/* we changed source -> close and reopen the fd */
|
||||
hal_debug_z("%s #%d: FD ALREADY OPENED fd = %d lastsource %d devnum %d\n",
|
||||
__func__, num, fd, last_source, devnum);
|
||||
__func__, num, fd, last_source, devnum);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
if (dmx_type != DMX_PSI_CHANNEL)
|
||||
flags |= O_NONBLOCK;
|
||||
|
||||
fd = open(devname[devnum], flags);
|
||||
fd = open(devname(0, devnum), flags);
|
||||
if (fd < 0)
|
||||
{
|
||||
hal_info_z("%s %s: %m\n", __FUNCTION__, devname[devnum]);
|
||||
hal_info_z("%s %s: %m\n", __FUNCTION__, devname(0, devnum));
|
||||
return false;
|
||||
}
|
||||
hal_debug_z("%s #%d pes_type: %s(%d), uBufferSize: %d fd: %d\n", __func__,
|
||||
num, DMX_T[dmx_type], dmx_type, buffersize, fd);
|
||||
num, DMX_T[dmx_type], dmx_type, buffersize, fd);
|
||||
|
||||
/* this would actually need locking, but the worst that weill happen is, that
|
||||
* we'll DMX_SET_SOURCE twice per device, so don't bother... */
|
||||
@@ -222,7 +204,7 @@ static bool _open(cDemux *thiz, int num, int &fd, int &last_source, DMX_CHANNEL_
|
||||
{
|
||||
/* this should not change anything... */
|
||||
int n = DMX_SOURCE_FRONT0 + devnum;
|
||||
hal_info_z("%s: setting %s to source %d\n", __func__, devname[devnum], n);
|
||||
hal_info_z("%s: setting %s to source %d\n", __func__, devname(0, devnum), n);
|
||||
if (ioctl(fd, DMX_SET_SOURCE, &n) < 0)
|
||||
hal_info_z("%s DMX_SET_SOURCE failed!\n", __func__);
|
||||
else
|
||||
@@ -285,7 +267,7 @@ int cDemux::Read(unsigned char *buff, int len, int timeout)
|
||||
#if 0
|
||||
if (len != 4095 && timeout != 10)
|
||||
fprintf(stderr, "cDemux::%s #%d fd: %d type: %s len: %d timeout: %d\n",
|
||||
__FUNCTION__, num, fd, DMX_T[dmx_type], len, timeout);
|
||||
__FUNCTION__, num, fd, DMX_T[dmx_type], len, timeout);
|
||||
#endif
|
||||
if (fd < 0)
|
||||
{
|
||||
@@ -298,7 +280,7 @@ int cDemux::Read(unsigned char *buff, int len, int timeout)
|
||||
int to = timeout;
|
||||
struct pollfd ufds;
|
||||
ufds.fd = fd;
|
||||
ufds.events = POLLIN|POLLPRI|POLLERR;
|
||||
ufds.events = POLLIN | POLLPRI | POLLERR;
|
||||
ufds.revents = 0;
|
||||
|
||||
/* hack: if the frontend loses and regains lock, the demuxer often will not
|
||||
@@ -309,7 +291,7 @@ int cDemux::Read(unsigned char *buff, int len, int timeout)
|
||||
|
||||
if (to > 0)
|
||||
{
|
||||
retry:
|
||||
retry:
|
||||
rc = ::poll(&ufds, 1, to);
|
||||
if (ufds.fd != fd)
|
||||
{
|
||||
@@ -354,8 +336,9 @@ int cDemux::Read(unsigned char *buff, int len, int timeout)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (ufds.fd != fd) /* does this ever happen? and if, is it harmful? */
|
||||
{ /* read(-1,...) will just return EBADF anyway... */
|
||||
if (ufds.fd != fd) /* does this ever happen? and if, is it harmful? */
|
||||
{
|
||||
/* read(-1,...) will just return EBADF anyway... */
|
||||
hal_info("%s:2 ========== fd has changed, %d->%d ==========\n", __func__, ufds.fd, fd);
|
||||
return -1;
|
||||
}
|
||||
@@ -368,9 +351,9 @@ int cDemux::Read(unsigned char *buff, int len, int timeout)
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filter,
|
||||
const unsigned char * const mask, int len, int timeout,
|
||||
const unsigned char * const negmask)
|
||||
bool cDemux::sectionFilter(unsigned short _pid, const unsigned char *const filter,
|
||||
const unsigned char *const mask, int len, int timeout,
|
||||
const unsigned char *const negmask)
|
||||
{
|
||||
struct dmx_sct_filter_params s_flt;
|
||||
memset(&s_flt, 0, sizeof(s_flt));
|
||||
@@ -391,7 +374,7 @@ bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filt
|
||||
if (negmask != NULL)
|
||||
memcpy(s_flt.filter.mode, negmask, len);
|
||||
|
||||
s_flt.flags = DMX_IMMEDIATE_START|DMX_CHECK_CRC;
|
||||
s_flt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC;
|
||||
|
||||
int to = 0;
|
||||
switch (filter[0])
|
||||
@@ -476,15 +459,22 @@ bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filt
|
||||
s_flt.timeout = to;
|
||||
|
||||
hal_debug("%s #%d pid:0x%04hx fd:%d type:%s len:%d to:%d flags:%x flt[0]:%02x\n", __func__, num,
|
||||
pid, fd, DMX_T[dmx_type], len, s_flt.timeout, s_flt.flags, s_flt.filter.filter[0]);
|
||||
pid, fd, DMX_T[dmx_type], len, s_flt.timeout, s_flt.flags, s_flt.filter.filter[0]);
|
||||
|
||||
if (debuglevel == 2) {
|
||||
fprintf(stderr,"filt: "); for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.filter[i]); fprintf(stderr, "\n");
|
||||
fprintf(stderr,"mask: "); for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.mask [i]); fprintf(stderr, "\n");
|
||||
fprintf(stderr,"mode: "); for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.mode [i]); fprintf(stderr, "\n");
|
||||
if (debuglevel == 2)
|
||||
{
|
||||
fprintf(stderr, "filt: ");
|
||||
for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.filter[i]);
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "mask: ");
|
||||
for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.mask [i]);
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "mode: ");
|
||||
for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.mode [i]);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
ioctl (fd, DMX_STOP);
|
||||
ioctl(fd, DMX_STOP);
|
||||
if (ioctl(fd, DMX_SET_FILTER, &s_flt) < 0)
|
||||
return false;
|
||||
|
||||
@@ -500,7 +490,7 @@ bool cDemux::pesFilter(const unsigned short _pid)
|
||||
* this check originally is from tuxbox cvs but I'm not sure
|
||||
* what it is good for...
|
||||
if (pid <= 0x0001 && dmx_type != DMX_PCR_ONLY_CHANNEL)
|
||||
return false;
|
||||
return false;
|
||||
*/
|
||||
if ((pid >= 0x0002 && pid <= 0x000f) || pid >= 0x1fff)
|
||||
return false;
|
||||
@@ -592,7 +582,8 @@ void cDemux::removePid(unsigned short Pid)
|
||||
}
|
||||
for (std::vector<pes_pids>::iterator i = pesfds.begin(); i != pesfds.end(); ++i)
|
||||
{
|
||||
if ((*i).pid == Pid) {
|
||||
if ((*i).pid == Pid)
|
||||
{
|
||||
hal_debug("removePid: removing demux fd %d pid 0x%04x\n", fd, Pid);
|
||||
if (ioctl(fd, DMX_REMOVE_PID, Pid) < 0)
|
||||
hal_info("%s: (DMX_REMOVE_PID, 0x%04hx): %m\n", __func__, Pid);
|
||||
@@ -603,7 +594,7 @@ void cDemux::removePid(unsigned short Pid)
|
||||
hal_info("%s pid 0x%04x not found\n", __FUNCTION__, Pid);
|
||||
}
|
||||
|
||||
void cDemux::getSTC(int64_t * STC)
|
||||
void cDemux::getSTC(int64_t *STC)
|
||||
{
|
||||
/* apparently I can only get the PTS of the video decoder,
|
||||
* but that's good enough for dvbsub */
|
||||
@@ -625,7 +616,8 @@ int cDemux::getUnit(void)
|
||||
|
||||
bool cDemux::SetSource(int unit, int source)
|
||||
{
|
||||
if (unit >= NUM_DEMUX || unit < 0) {
|
||||
if (unit >= NUM_DEMUX || unit < 0)
|
||||
{
|
||||
hal_info_c("%s: unit (%d) out of range, NUM_DEMUX %d\n", __func__, unit, NUM_DEMUX);
|
||||
return false;
|
||||
}
|
||||
@@ -639,7 +631,8 @@ bool cDemux::SetSource(int unit, int source)
|
||||
|
||||
int cDemux::GetSource(int unit)
|
||||
{
|
||||
if (unit >= NUM_DEMUX || unit < 0) {
|
||||
if (unit >= NUM_DEMUX || unit < 0)
|
||||
{
|
||||
hal_info_c("%s: unit (%d) out of range, NUM_DEMUX %d\n", __func__, unit, NUM_DEMUX);
|
||||
return -1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user