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:
112
libspark/dmx.cpp
112
libspark/dmx.cpp
@@ -26,19 +26,19 @@
|
||||
*
|
||||
* the sh4 pti driver, driving the /dev/dvb/adapter0/dmxN devices, can
|
||||
* apparently only map one input to on demux device at a time, so e.g.
|
||||
* DMX_SOURCE_FRONT1 -> demux0
|
||||
* DMX_SOURCE_FRONT2 -> demux0
|
||||
* DMX_SOURCE_FRONT1 -> demux1
|
||||
* DMX_SOURCE_FRONT1 -> demux0
|
||||
* DMX_SOURCE_FRONT2 -> demux0
|
||||
* DMX_SOURCE_FRONT1 -> demux1
|
||||
* does not work. The driver makes sure that a one-to-one mapping of
|
||||
* DMX_SOURCE_FRONTn to demuxM is maintained, and it does by e.g changing
|
||||
* the default of
|
||||
* FRONT0 -> demux0
|
||||
* FRONT1 -> demux1
|
||||
* FRONT2 -> demux2
|
||||
* FRONT0 -> demux0
|
||||
* FRONT1 -> demux1
|
||||
* FRONT2 -> demux2
|
||||
* to
|
||||
* FRONT1 -> demux0
|
||||
* FRONT0 -> demux1
|
||||
* FRONT2 -> demux2
|
||||
* FRONT1 -> demux0
|
||||
* FRONT0 -> demux1
|
||||
* FRONT2 -> demux2
|
||||
* if you do a DMX_SET_SOURCE(FRONT1) ioctl on demux0.
|
||||
* This means, it also changes demux1's source on the SET_SOURCE ioctl on
|
||||
* demux0, potentially disturbing any operation on demux1 (e.g. recording).
|
||||
@@ -84,15 +84,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",
|
||||
@@ -109,17 +110,21 @@ static const char *DMX_T[] = {
|
||||
/* the current source of each cDemux unit */
|
||||
static int dmx_source[NUM_DEMUX] = { 0, 0, 0, 0 };
|
||||
|
||||
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. */
|
||||
#define NUM_DEMUXDEV 3
|
||||
static const char *devname[NUM_DEMUXDEV] = {
|
||||
"/dev/dvb/adapter0/demux0",
|
||||
"/dev/dvb/adapter0/demux1",
|
||||
"/dev/dvb/adapter0/demux2"
|
||||
};
|
||||
|
||||
/* did we already DMX_SET_SOURCE on that demux device? */
|
||||
static bool init[NUM_DEMUXDEV] = { false, false, false };
|
||||
|
||||
typedef struct dmx_pdata {
|
||||
typedef struct dmx_pdata
|
||||
{
|
||||
int last_source;
|
||||
OpenThreads::Mutex *mutex;
|
||||
} dmx_pdata;
|
||||
@@ -167,31 +172,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... */
|
||||
@@ -199,7 +206,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
|
||||
@@ -262,7 +269,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)
|
||||
{
|
||||
@@ -275,7 +282,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
|
||||
@@ -286,7 +293,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)
|
||||
{
|
||||
@@ -331,8 +338,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;
|
||||
}
|
||||
@@ -345,9 +353,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));
|
||||
@@ -368,7 +376,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])
|
||||
@@ -453,15 +461,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;
|
||||
|
||||
@@ -477,7 +492,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;
|
||||
@@ -569,7 +584,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);
|
||||
@@ -580,7 +596,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 */
|
||||
@@ -602,7 +618,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;
|
||||
}
|
||||
@@ -616,7 +633,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