mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-30 08:51:10 +02:00
eitd: remove code under DO_NOT_INCLUDE_STUFF_NOT_NEEDED_FOR_SECTIONSD ifdef
This commit is contained in:
@@ -1316,321 +1316,3 @@ void SIsectionNIT::parse(void)
|
||||
parsed = 1;
|
||||
}
|
||||
#endif
|
||||
#ifndef DO_NOT_INCLUDE_STUFF_NOT_NEEDED_FOR_SECTIONSD
|
||||
// Liest n Bytes aus einem Socket per read
|
||||
// Liefert 0 bei timeout
|
||||
// und -1 bei Fehler
|
||||
// ansonsten die Anzahl gelesener Bytes
|
||||
inline int readNbytes(int fd, char *buf, int n, unsigned timeoutInSeconds)
|
||||
{
|
||||
int j;
|
||||
for(j=0; j<n;) {
|
||||
struct pollfd ufds;
|
||||
// memset(&ufds, 0, sizeof(ufds));
|
||||
ufds.fd=fd;
|
||||
ufds.events=POLLIN|POLLPRI;
|
||||
ufds.revents=0;
|
||||
int rc=poll(&ufds, 1, timeoutInSeconds*1000);
|
||||
if(!rc)
|
||||
return 0; // timeout
|
||||
else if(rc<0) {
|
||||
perror ("poll");
|
||||
return -1;
|
||||
}
|
||||
int r=read (fd, buf, n-j);
|
||||
if(r<=0) {
|
||||
perror ("read");
|
||||
return -1;
|
||||
}
|
||||
j+=r;
|
||||
buf+=r;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
//
|
||||
// Beachtung der Stuffing tables (ST) fehlt noch
|
||||
//
|
||||
int SIsections :: readSections(const unsigned short pid, const unsigned char filter, const unsigned char mask, int readNext, unsigned timeoutInSeconds)
|
||||
{
|
||||
int fd;
|
||||
struct SI_section_header header;
|
||||
uint64_t firstKey=(uint64_t)-1;
|
||||
SIsections missingSections;
|
||||
char *buf;
|
||||
unsigned short section_length;
|
||||
|
||||
if ((fd = open(DEMUX_DEVICE, O_RDWR)) == -1) {
|
||||
perror(DEMUX_DEVICE);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!setfilter(fd, pid, filter, mask, DMX_IMMEDIATE_START | DMX_CHECK_CRC)) {
|
||||
close(fd);
|
||||
return 2;
|
||||
}
|
||||
|
||||
time_t szeit = time(NULL);
|
||||
|
||||
// Erstes Segment lesen
|
||||
|
||||
do {
|
||||
if (time(NULL) > szeit + (long)timeoutInSeconds) {
|
||||
close(fd);
|
||||
return 0; // timeout -> kein EPG
|
||||
}
|
||||
|
||||
int rc = readNbytes(fd, (char *)&header, sizeof(header), timeoutInSeconds);
|
||||
|
||||
if(!rc) {
|
||||
close(fd);
|
||||
return 0; // timeout -> kein EPG
|
||||
}
|
||||
|
||||
else if(rc<0) {
|
||||
close(fd);
|
||||
//perror ("read header");
|
||||
return 3;
|
||||
}
|
||||
|
||||
section_length = (header.section_length_hi << 8) | header.section_length_lo;
|
||||
|
||||
buf = new char[sizeof(header) + section_length - 5];
|
||||
|
||||
if (!buf) {
|
||||
close(fd);
|
||||
fprintf(stderr, "Not enough memory!\n");
|
||||
return 4;
|
||||
}
|
||||
|
||||
// Den Header kopieren
|
||||
memmove(buf, &header, sizeof(header));
|
||||
|
||||
rc = readNbytes(fd, &buf[sizeof(header)], section_length - 5, timeoutInSeconds);
|
||||
|
||||
if (!rc) {
|
||||
close(fd);
|
||||
delete[] buf;
|
||||
return 0; // timeout -> kein EPG
|
||||
}
|
||||
|
||||
else if (rc<0) {
|
||||
close(fd);
|
||||
//perror ("read section");
|
||||
delete[] buf;
|
||||
return 5;
|
||||
}
|
||||
|
||||
if ((readNext) || (header.current_next_indicator)) {
|
||||
// Wir wollen nur aktuelle sections
|
||||
insert(SIsection(sizeof(header) + section_length - 5, buf));
|
||||
firstKey = SIsection::key(&header);
|
||||
|
||||
// Sonderfall: Nur eine Section
|
||||
// d.h. wir sind fertig
|
||||
if ((!header.section_number) && (!header.last_section_number)) {
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
} while (firstKey == (uint64_t) -1);
|
||||
|
||||
// Die restlichen Segmente lesen
|
||||
szeit = time(NULL);
|
||||
|
||||
for (;;) {
|
||||
if (time(NULL) > szeit + (long)timeoutInSeconds)
|
||||
break; // timeout
|
||||
|
||||
int rc = readNbytes(fd, (char *)&header, sizeof(header), timeoutInSeconds);
|
||||
|
||||
if(!rc)
|
||||
break; // timeout
|
||||
|
||||
else if(rc<0) {
|
||||
close(fd);
|
||||
//perror ("read header");
|
||||
return 6;
|
||||
}
|
||||
|
||||
if (firstKey==SIsection::key(&header))
|
||||
// Wir haben die 1. section wieder gefunden
|
||||
break;
|
||||
|
||||
section_length = (header.section_length_hi << 8) | header.section_length_lo;
|
||||
|
||||
buf = new char[sizeof(header) + section_length - 5];
|
||||
|
||||
if (!buf) {
|
||||
close(fd);
|
||||
fprintf(stderr, "Not enough memory!\n");
|
||||
return 7;
|
||||
}
|
||||
|
||||
// Den Header kopieren (evtl. malloc und realloc nehmen)
|
||||
memmove(buf, &header, sizeof(header));
|
||||
|
||||
// den Rest der Section einlesen
|
||||
rc = readNbytes(fd, &buf[sizeof(header)], section_length - 5, timeoutInSeconds);
|
||||
|
||||
if (!rc) {
|
||||
delete[] buf;
|
||||
break; // timeout
|
||||
}
|
||||
|
||||
else if (rc < 0) {
|
||||
close(fd);
|
||||
delete[] buf;
|
||||
//perror ("read section");
|
||||
return 8;
|
||||
}
|
||||
|
||||
if ((readNext) || (header.current_next_indicator))
|
||||
insert(SIsection(sizeof(header) + section_length - 5, buf));
|
||||
else
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
#ifdef DEBUG
|
||||
// Die Sections ausgeben
|
||||
printf("----------------Found sections-----------------------\n");
|
||||
// for_each(begin(), end(), printSIsection());
|
||||
for_each(begin(), end(), printSIsectionEIT());
|
||||
printf("-----------------------------------------------------\n");
|
||||
#endif // DEBUG
|
||||
|
||||
|
||||
// Jetzt erstellen wir eine Liste der fehlenden Sections
|
||||
unsigned short actualTableIDextension = (unsigned short) -1;
|
||||
unsigned char actualTableID = (unsigned char) -1;
|
||||
unsigned char maxNr = 0;
|
||||
unsigned char lastNr = 0;
|
||||
|
||||
for (SIsections::iterator k = begin(); k != end(); k++) {
|
||||
if ((k->tableIDextension() != actualTableIDextension) || (k->tableID() != actualTableID)) {
|
||||
// Neue Table-ID-Extension
|
||||
maxNr = k->lastSectionNumber();
|
||||
actualTableIDextension = k->tableIDextension();
|
||||
actualTableID = k->tableID();
|
||||
}
|
||||
|
||||
else if (k->sectionNumber() != (unsigned char)(lastNr + 1)) {
|
||||
// Es fehlen Sections
|
||||
for (unsigned l = lastNr + 1; l < k->sectionNumber(); l++) {
|
||||
//printf("Debug: t: 0x%02x s: %u nr: %u last: %u max: %u l: %u\n", actualTableID, actualTableIDextension, k->sectionNumber(), lastNr, maxNr, l);
|
||||
|
||||
struct SI_section_header h;
|
||||
memmove(&h, k->header(), sizeof(struct SI_section_header));
|
||||
h.section_number = l;
|
||||
missingSections.insert(SIsection(&h));
|
||||
}
|
||||
}
|
||||
|
||||
lastNr = k->sectionNumber();
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Sections read: %d\n\n", size());
|
||||
#endif // DEBUG
|
||||
|
||||
if (!missingSections.size())
|
||||
return 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("----------------Missing sections---------------------\n");
|
||||
for_each(missingSections.begin(), missingSections.end(), printSmallSIsectionHeader());
|
||||
printf("-----------------------------------------------------\n");
|
||||
printf("Sections read: %d\n\n", size());
|
||||
printf("Sections misssing: %d\n", missingSections.size());
|
||||
printf("Searching missing sections\n");
|
||||
#endif // DEBUG
|
||||
|
||||
szeit = time(NULL);
|
||||
|
||||
if ((fd = open(DEMUX_DEVICE, O_RDWR)) == -1) {
|
||||
perror(DEMUX_DEVICE);
|
||||
return 9;
|
||||
}
|
||||
|
||||
if (!setfilter(fd, pid, filter, mask, DMX_IMMEDIATE_START | DMX_CHECK_CRC)) {
|
||||
close(fd);
|
||||
return 10;
|
||||
}
|
||||
|
||||
// Jetzt lesen wir die fehlenden Sections ein
|
||||
for(;;) {
|
||||
if (time(NULL) > szeit + (long)timeoutInSeconds)
|
||||
break; // Timeout
|
||||
|
||||
int rc = readNbytes(fd, (char *)&header, sizeof(header), timeoutInSeconds);
|
||||
|
||||
if(!rc)
|
||||
break; // timeout
|
||||
|
||||
else if (rc < 0) {
|
||||
close(fd);
|
||||
//perror ("read header");
|
||||
return 11;
|
||||
|
||||
}
|
||||
|
||||
section_length = (header.section_length_hi << 8) | header.section_length_lo;
|
||||
|
||||
buf = new char[sizeof(header) + section_length - 5];
|
||||
|
||||
if (!buf) {
|
||||
close(fd);
|
||||
fprintf(stderr, "Not enough memory!\n");
|
||||
return 12;
|
||||
}
|
||||
|
||||
// Den Header kopieren (evtl. malloc und realloc nehmen)
|
||||
memmove(buf, &header, sizeof(header));
|
||||
// den Rest der Section einlesen
|
||||
rc = readNbytes(fd, &buf[sizeof(header)], section_length - 5, timeoutInSeconds);
|
||||
|
||||
if (!rc) {
|
||||
delete[] buf;
|
||||
break; // timeout
|
||||
}
|
||||
|
||||
else if (rc < 0) {
|
||||
close(fd);
|
||||
delete[] buf;
|
||||
//perror ("read section");
|
||||
return 13;
|
||||
}
|
||||
|
||||
if (missingSections.find(SIsection(&header)) != missingSections.end()) {
|
||||
#ifdef DEBUG
|
||||
printf("Find missing section:");
|
||||
SIsection::dumpSmallSectionHeader(&header);
|
||||
#endif // DEBUG
|
||||
// War bisher vermisst
|
||||
// In die Menge einfuegen
|
||||
insert(SIsection(sizeof(header) + section_length - 5, buf));
|
||||
|
||||
// Und aus der vermissten Menge entfernen
|
||||
missingSections.erase(SIsection(&header));
|
||||
#ifdef DEBUG
|
||||
printf("Sections misssing: %d\n", missingSections.size());
|
||||
#endif // DEBUG
|
||||
}
|
||||
|
||||
else {
|
||||
// Puffer wieder loeschen
|
||||
delete[] buf;
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user