cDemux: fix removePid / pesfds usage

This commit is contained in:
Stefan Seyfried
2013-02-24 14:11:09 +01:00
parent 707020d16b
commit e900236f7e
3 changed files with 17 additions and 114 deletions

View File

@@ -162,14 +162,6 @@ void cDemux::Close(void)
return; return;
} }
for (std::vector<pes_pids>::const_iterator i = pesfds.begin(); i != pesfds.end(); ++i)
{
lt_debug("%s stopping and closing demux fd %d pid 0x%04x\n", __FUNCTION__, (*i).fd, (*i).pid);
if (ioctl((*i).fd, DMX_STOP) < 0)
perror("DEMUX_STOP");
if (close((*i).fd) < 0)
perror("close");
}
pesfds.clear(); pesfds.clear();
ioctl(fd, DMX_STOP); ioctl(fd, DMX_STOP);
close(fd); close(fd);
@@ -195,13 +187,6 @@ bool cDemux::Start(bool)
lt_info("%s #%d: not open!\n", __FUNCTION__, num); lt_info("%s #%d: not open!\n", __FUNCTION__, num);
return false; return false;
} }
for (std::vector<pes_pids>::const_iterator i = pesfds.begin(); i != pesfds.end(); ++i)
{
lt_debug("%s starting demux fd %d pid 0x%04x\n", __FUNCTION__, (*i).fd, (*i).pid);
if (ioctl((*i).fd, DMX_START) < 0)
perror("DMX_START");
}
ioctl(fd, DMX_START); ioctl(fd, DMX_START);
return true; return true;
} }
@@ -214,12 +199,6 @@ bool cDemux::Stop(void)
lt_info("%s #%d: not open!\n", __FUNCTION__, num); lt_info("%s #%d: not open!\n", __FUNCTION__, num);
return false; return false;
} }
for (std::vector<pes_pids>::const_iterator i = pesfds.begin(); i != pesfds.end(); ++i)
{
lt_debug("%s stopping demux fd %d pid 0x%04x\n", __FUNCTION__, (*i).fd, (*i).pid);
if (ioctl((*i).fd, DMX_STOP) < 0)
perror("DMX_STOP");
}
ioctl(fd, DMX_STOP); ioctl(fd, DMX_STOP);
return true; return true;
} }
@@ -474,7 +453,6 @@ bool cDemux::addPid(unsigned short Pid)
lt_debug("%s: pid 0x%04hx\n", __func__, Pid); lt_debug("%s: pid 0x%04hx\n", __func__, Pid);
pes_pids pfd; pes_pids pfd;
int ret; int ret;
struct dmx_pes_filter_params p;
if (dmx_type != DMX_TP_CHANNEL) if (dmx_type != DMX_TP_CHANNEL)
{ {
lt_info("%s pes_type %s not implemented yet! pid=%hx\n", __FUNCTION__, DMX_T[dmx_type], Pid); lt_info("%s pes_type %s not implemented yet! pid=%hx\n", __FUNCTION__, DMX_T[dmx_type], Pid);
@@ -482,6 +460,9 @@ bool cDemux::addPid(unsigned short Pid)
} }
if (fd == -1) if (fd == -1)
lt_info("%s bucketfd not yet opened? pid=%hx\n", __FUNCTION__, Pid); lt_info("%s bucketfd not yet opened? pid=%hx\n", __FUNCTION__, Pid);
pfd.fd = fd; /* dummy */
pfd.pid = Pid;
pesfds.push_back(pfd);
ret = (ioctl(fd, DMX_ADD_PID, &Pid)); ret = (ioctl(fd, DMX_ADD_PID, &Pid));
if (ret < 0) if (ret < 0)
lt_info("%s: DMX_ADD_PID (%m)\n", __func__); lt_info("%s: DMX_ADD_PID (%m)\n", __func__);
@@ -498,11 +479,9 @@ void cDemux::removePid(unsigned short Pid)
for (std::vector<pes_pids>::iterator i = pesfds.begin(); i != pesfds.end(); ++i) for (std::vector<pes_pids>::iterator i = pesfds.begin(); i != pesfds.end(); ++i)
{ {
if ((*i).pid == Pid) { if ((*i).pid == Pid) {
lt_debug("removePid: removing demux fd %d pid 0x%04x\n", (*i).fd, Pid); lt_debug("removePid: removing demux fd %d pid 0x%04x\n", fd, Pid);
if (ioctl((*i).fd, DMX_STOP) < 0) if (ioctl(fd, DMX_REMOVE_PID, Pid) < 0)
perror("DMX_STOP"); lt_info("%s: (DMX_REMOVE_PID, 0x%04hx): %m\n", __func__, Pid);
if (close((*i).fd) < 0)
perror("close");
pesfds.erase(i); pesfds.erase(i);
return; /* TODO: what if the same PID is there multiple times */ return; /* TODO: what if the same PID is there multiple times */
} }

View File

@@ -146,15 +146,6 @@ void cDemux::Close(void)
lt_info("%s #%d: not open!\n", __FUNCTION__, num); lt_info("%s #%d: not open!\n", __FUNCTION__, num);
return; return;
} }
for (std::vector<pes_pids>::const_iterator i = pesfds.begin(); i != pesfds.end(); ++i)
{
lt_debug("%s stopping and closing demux fd %d pid 0x%04x\n", __FUNCTION__, (*i).fd, (*i).pid);
if (ioctl((*i).fd, DMX_STOP) < 0)
perror("DEMUX_STOP");
if (close((*i).fd) < 0)
perror("close");
}
pesfds.clear(); pesfds.clear();
ioctl(fd, DMX_STOP); ioctl(fd, DMX_STOP);
close(fd); close(fd);
@@ -180,13 +171,6 @@ bool cDemux::Start(bool)
lt_info("%s #%d: not open!\n", __FUNCTION__, num); lt_info("%s #%d: not open!\n", __FUNCTION__, num);
return false; return false;
} }
for (std::vector<pes_pids>::const_iterator i = pesfds.begin(); i != pesfds.end(); ++i)
{
lt_debug("%s starting demux fd %d pid 0x%04x\n", __FUNCTION__, (*i).fd, (*i).pid);
if (ioctl((*i).fd, DMX_START) < 0)
perror("DMX_START");
}
ioctl(fd, DMX_START); ioctl(fd, DMX_START);
return true; return true;
} }
@@ -199,12 +183,6 @@ bool cDemux::Stop(void)
lt_info("%s #%d: not open!\n", __FUNCTION__, num); lt_info("%s #%d: not open!\n", __FUNCTION__, num);
return false; return false;
} }
for (std::vector<pes_pids>::const_iterator i = pesfds.begin(); i != pesfds.end(); ++i)
{
lt_debug("%s stopping demux fd %d pid 0x%04x\n", __FUNCTION__, (*i).fd, (*i).pid);
if (ioctl((*i).fd, DMX_STOP) < 0)
perror("DMX_STOP");
}
ioctl(fd, DMX_STOP); ioctl(fd, DMX_STOP);
return true; return true;
} }
@@ -443,7 +421,6 @@ bool cDemux::addPid(unsigned short Pid)
lt_debug("%s: pid 0x%04hx\n", __func__, Pid); lt_debug("%s: pid 0x%04hx\n", __func__, Pid);
pes_pids pfd; pes_pids pfd;
int ret; int ret;
struct dmx_pes_filter_params p;
if (dmx_type != DMX_TP_CHANNEL) if (dmx_type != DMX_TP_CHANNEL)
{ {
lt_info("%s pes_type %s not implemented yet! pid=%hx\n", __FUNCTION__, DMX_T[dmx_type], Pid); lt_info("%s pes_type %s not implemented yet! pid=%hx\n", __FUNCTION__, DMX_T[dmx_type], Pid);
@@ -451,6 +428,9 @@ bool cDemux::addPid(unsigned short Pid)
} }
if (fd == -1) if (fd == -1)
lt_info("%s bucketfd not yet opened? pid=%hx\n", __FUNCTION__, Pid); lt_info("%s bucketfd not yet opened? pid=%hx\n", __FUNCTION__, Pid);
pfd.fd = fd; /* dummy */
pfd.pid = Pid;
pesfds.push_back(pfd);
ret = (ioctl(fd, DMX_ADD_PID, &Pid)); ret = (ioctl(fd, DMX_ADD_PID, &Pid));
if (ret < 0) if (ret < 0)
lt_info("%s: DMX_ADD_PID (%m)\n", __func__); lt_info("%s: DMX_ADD_PID (%m)\n", __func__);
@@ -467,11 +447,9 @@ void cDemux::removePid(unsigned short Pid)
for (std::vector<pes_pids>::iterator i = pesfds.begin(); i != pesfds.end(); ++i) for (std::vector<pes_pids>::iterator i = pesfds.begin(); i != pesfds.end(); ++i)
{ {
if ((*i).pid == Pid) { if ((*i).pid == Pid) {
lt_debug("removePid: removing demux fd %d pid 0x%04x\n", (*i).fd, Pid); lt_debug("removePid: removing demux fd %d pid 0x%04x\n", fd, Pid);
if (ioctl((*i).fd, DMX_STOP) < 0) if (ioctl(fd, DMX_REMOVE_PID, Pid) < 0)
perror("DMX_STOP"); lt_info("%s: (DMX_REMOVE_PID, 0x%04hx): %m\n", __func__, Pid);
if (close((*i).fd) < 0)
perror("close");
pesfds.erase(i); pesfds.erase(i);
return; /* TODO: what if the same PID is there multiple times */ return; /* TODO: what if the same PID is there multiple times */
} }

View File

@@ -226,14 +226,6 @@ void cDemux::Close(void)
return; return;
} }
for (std::vector<pes_pids>::const_iterator i = pesfds.begin(); i != pesfds.end(); ++i)
{
lt_debug("%s stopping and closing demux fd %d pid 0x%04x\n", __FUNCTION__, (*i).fd, (*i).pid);
if (ioctl((*i).fd, DMX_STOP) < 0)
perror("DEMUX_STOP");
if (close((*i).fd) < 0)
perror("close");
}
pesfds.clear(); pesfds.clear();
ioctl(fd, DMX_STOP); ioctl(fd, DMX_STOP);
close(fd); close(fd);
@@ -258,13 +250,6 @@ bool cDemux::Start(bool)
lt_info("%s #%d: not open!\n", __FUNCTION__, num); lt_info("%s #%d: not open!\n", __FUNCTION__, num);
return false; return false;
} }
for (std::vector<pes_pids>::const_iterator i = pesfds.begin(); i != pesfds.end(); ++i)
{
lt_debug("%s starting demux fd %d pid 0x%04x\n", __FUNCTION__, (*i).fd, (*i).pid);
if (ioctl((*i).fd, DMX_START) < 0)
perror("DMX_START");
}
ioctl(fd, DMX_START); ioctl(fd, DMX_START);
return true; return true;
} }
@@ -276,12 +261,6 @@ bool cDemux::Stop(void)
lt_info("%s #%d: not open!\n", __FUNCTION__, num); lt_info("%s #%d: not open!\n", __FUNCTION__, num);
return false; return false;
} }
for (std::vector<pes_pids>::const_iterator i = pesfds.begin(); i != pesfds.end(); ++i)
{
lt_debug("%s stopping demux fd %d pid 0x%04x\n", __FUNCTION__, (*i).fd, (*i).pid);
if (ioctl((*i).fd, DMX_STOP) < 0)
perror("DMX_STOP");
}
ioctl(fd, DMX_STOP); ioctl(fd, DMX_STOP);
return true; return true;
} }
@@ -546,7 +525,6 @@ bool cDemux::addPid(unsigned short Pid)
lt_debug("%s: pid 0x%04hx\n", __func__, Pid); lt_debug("%s: pid 0x%04hx\n", __func__, Pid);
pes_pids pfd; pes_pids pfd;
int ret; int ret;
struct dmx_pes_filter_params p;
if (dmx_type != DMX_TP_CHANNEL) if (dmx_type != DMX_TP_CHANNEL)
{ {
lt_info("%s pes_type %s not implemented yet! pid=%hx\n", __FUNCTION__, DMX_T[dmx_type], Pid); lt_info("%s pes_type %s not implemented yet! pid=%hx\n", __FUNCTION__, DMX_T[dmx_type], Pid);
@@ -555,39 +533,9 @@ bool cDemux::addPid(unsigned short Pid)
_open(); _open();
if (fd == -1) if (fd == -1)
lt_info("%s bucketfd not yet opened? pid=%hx\n", __FUNCTION__, Pid); lt_info("%s bucketfd not yet opened? pid=%hx\n", __FUNCTION__, Pid);
#if 0 pfd.fd = fd; /* dummy */
pfd.fd = open(devname[num], O_RDWR);
if (pfd.fd < 0)
{
lt_info("%s #%d Pid = %hx open failed (%m)\n", __FUNCTION__, num, Pid);
return false;
}
fcntl(pfd.fd, F_SETFD, FD_CLOEXEC);
lt_debug("%s #%d Pid = %hx pfd = %d\n", __FUNCTION__, num, Pid, pfd.fd);
p.pid = Pid;
p.input = DMX_IN_FRONTEND;
p.pes_type = DMX_PES_OTHER;
p.output = DMX_OUT_TS_TAP;
p.flags = 0;
ret = ioctl(pfd.fd, DMX_SET_BUFFER_SIZE, 0x10000); // 64k
if (ret == -1)
perror("DMX_SET_BUFFER_SIZE");
else
{
ret = ioctl(pfd.fd, DMX_SET_PES_FILTER, &p);
if (ret == -1)
perror("DEMUX_FILTER_PES_SET");
}
pfd.pid = Pid; pfd.pid = Pid;
if (ret != -1) pesfds.push_back(pfd);
/* success! */
pesfds.push_back(pfd);
else
/* error! */
close(pfd.fd);
#endif
ret = (ioctl(fd, DMX_ADD_PID, &Pid)); ret = (ioctl(fd, DMX_ADD_PID, &Pid));
if (ret < 0) if (ret < 0)
lt_info("%s: DMX_ADD_PID (%m)\n", __func__); lt_info("%s: DMX_ADD_PID (%m)\n", __func__);
@@ -604,11 +552,9 @@ void cDemux::removePid(unsigned short Pid)
for (std::vector<pes_pids>::iterator i = pesfds.begin(); i != pesfds.end(); ++i) for (std::vector<pes_pids>::iterator i = pesfds.begin(); i != pesfds.end(); ++i)
{ {
if ((*i).pid == Pid) { if ((*i).pid == Pid) {
lt_debug("removePid: removing demux fd %d pid 0x%04x\n", (*i).fd, Pid); lt_debug("removePid: removing demux fd %d pid 0x%04x\n", fd, Pid);
if (ioctl((*i).fd, DMX_STOP) < 0) if (ioctl(fd, DMX_REMOVE_PID, Pid) < 0)
perror("DMX_STOP"); lt_info("%s: (DMX_REMOVE_PID, 0x%04hx): %m\n", __func__, Pid);
if (close((*i).fd) < 0)
perror("close");
pesfds.erase(i); pesfds.erase(i);
return; /* TODO: what if the same PID is there multiple times */ return; /* TODO: what if the same PID is there multiple times */
} }