diff --git a/src/eitd/Makefile.am b/src/eitd/Makefile.am index 200019dbe..36b30d54a 100644 --- a/src/eitd/Makefile.am +++ b/src/eitd/Makefile.am @@ -14,7 +14,7 @@ if BOXTYPE_TRIPLE INCLUDES += -I$(top_srcdir)/lib/libtriple endif -AM_CPPFLAGS = -D DO_NOT_INCLUDE_STUFF_NOT_NEEDED_FOR_SECTIONSD +AM_CPPFLAGS = noinst_LIBRARIES = libsectionsd.a libsectionsd_a_SOURCES = sectionsd.cpp dmxapi.cpp debug.cpp dmx.cpp SIsections.cpp SIevents.cpp SIutils.cpp SIlanguage.cpp edvbstring.cpp diff --git a/src/eitd/SIevents.cpp b/src/eitd/SIevents.cpp index bc18c0ada..65cd6b850 100644 --- a/src/eitd/SIevents.cpp +++ b/src/eitd/SIevents.cpp @@ -358,236 +358,3 @@ void SIevent::dumpSmall(void) const for_each(ratings.begin(), ratings.end(), printSIparentalRating()); for_each(linkage_descs.begin(), linkage_descs.end(), printSIlinkage()); } -/* -// Liest n Bytes aus einem Socket per read -inline int readNbytes(int fd, char *buf, int n) -{ -int j; -for(j=0; jservice_id == serviceID) - for (SItimes::iterator t = k->times.begin(); t != k->times.end(); ++t) - if ((t->startzeit <= zeit) && (zeit <= (long)(t->startzeit+t->dauer))) { - close(fd); - return SIevent(*k); - } - } - - else { - delete[] buf; - } - - } while (time(NULL) < szeit + (long)timeoutInSeconds); - - close(fd); - return evt; -} - -void SIevents::removeOldEvents(long seconds) -{ - time_t current_time = time(NULL); - - for(SIevents::iterator it = begin(); it != end(); ) - { - // "it->times.erase(kt);": - // passing `const SItimes' as `this' argument of `void set,allocator >::erase(_Rb_tree_iterator)' discards qualifiers - - // hence we have to modify a copy - - SIevent copy_of_event(*it); - bool copy_has_changed = false; - - for (SItimes::iterator jt = copy_of_event.times.begin(); jt != copy_of_event.times.end(); ) - { - if ((jt->startzeit) + (int)(jt->dauer) < current_time - seconds) - { - copy_of_event.times.erase(jt++); - copy_has_changed = true; - } - else - ++jt; - } - if (copy_has_changed) - { - erase(it++); - - // Set has the important property that inserting a new element into a set does not - // invalidate iterators that point to existing elements. - if (copy_of_event.times.size() != 0) -#ifdef DEBUG - assert((++insert(it, copy_of_event)) == it); -#else - insert(it, copy_of_event); // it is the hint where to insert (I hope that doesn't invalidate it) -// insert(copy_of_event); // alternative method without hint -#endif - - } - else - ++it; - } -} - -// Entfernt anhand der Services alle time shifted events (ohne Text, -// mit service-id welcher im nvod steht) -// und sortiert deren Zeiten in die Events mit dem Text ein. -void SIevents::mergeAndRemoveTimeShiftedEvents(const SIservices &services) -{ - // Wir gehen alle services durch, suchen uns die services mit nvods raus - // und fuegen dann die Zeiten der Events mit der service-id eines nvods - // in das entsprechende Event mit der service-id das die nvods hat ein. - // die 'nvod-events' werden auch geloescht - -// SIevents eventsToDelete; // Hier rein kommen Events die geloescht werden sollen - for(SIservices::iterator k=services.begin(); k!=services.end(); ++k) - if(k->nvods.size()) { - // NVOD-Referenzen gefunden - // Zuerst mal das Event mit dem Text holen - iterator e; - for(e=begin(); e!=end(); ++e) - if(e->service_id == k->service_id) - break; - if(e!=end()) { - // *e == event mit dem Text - SIevent newEvent(*e); // Kopie des Events - // Jetzt die nvods druchgehen und deren Uhrzeiten in obiges Event einfuegen - for(SInvodReferences::iterator n=k->nvods.begin(); n!=k->nvods.end(); ++n) { - // Alle druchgehen und deren Events suchen - for(iterator en=begin(); en!=end(); en++) { - if(en->service_id==n->getServiceID()) { - newEvent.times.insert(en->times.begin(), en->times.end()); -// newEvent.times.insert(SItime(en->startzeit, en->dauer)); -// eventsToDelete.insert(SIevent(*en)); - } - } - } - erase(e); // Altes Event loeschen -> iterator (e) ungültig - insert(newEvent); // und das erweiterte Event wieder einfuegen - } - } - - // - // delete all events with serviceID that have a service type 0 - // - for (iterator it = begin(); it != end(); ) - { - SIservices::iterator s = services.find(SIservice(it->service_id, it->original_network_id, it->transport_stream_id)); - if ((s != services.end()) && (s->serviceTyp == 0)) - { - // Set is a Sorted Associative Container - // Erasing an element from a set also does not invalidate any iterators, - // except, of course, for iterators that actually point to the element - // that is being erased. - erase(it++); - } - else - ++it; - } -} -#endif diff --git a/src/eitd/SIevents.hpp b/src/eitd/SIevents.hpp index 679fe881f..97b2e0fbc 100644 --- a/src/eitd/SIevents.hpp +++ b/src/eitd/SIevents.hpp @@ -407,11 +407,6 @@ public: int saveXML(FILE *file, const char *serviceName) const; // saves the event void dump(void) const; // dumps the event to stdout void dumpSmall(void) const; // dumps the event to stdout (not all information) -#ifndef DO_NOT_INCLUDE_STUFF_NOT_NEEDED_FOR_SECTIONSD - // Liefert das aktuelle EPG des senders mit der uebergebenen serviceID, - // bei Fehler ist die serviceID des zurueckgelieferten Events 0 - static SIevent readActualEvent(t_service_id serviceID, unsigned timeoutInSeconds=2); -#endif char getFSK() const; protected: int saveXML0(FILE *f) const; diff --git a/src/eitd/SIsections.cpp b/src/eitd/SIsections.cpp index 3c9a5d722..cfc59dbb6 100644 --- a/src/eitd/SIsections.cpp +++ b/src/eitd/SIsections.cpp @@ -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 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 diff --git a/src/eitd/SIsections.hpp b/src/eitd/SIsections.hpp index d71d9ccd3..152d18409 100644 --- a/src/eitd/SIsections.hpp +++ b/src/eitd/SIsections.hpp @@ -651,78 +651,6 @@ protected: }; #endif -#ifndef DO_NOT_INCLUDE_STUFF_NOT_NEEDED_FOR_SECTIONSD -// Fuer for_each -struct printSIsectionEIT : public std::unary_function -{ - void operator() (const SIsectionEIT &s) { s.dump();} -}; - -#ifdef ENABLE_PPT -// Fuer for_each -struct printSIsectionPPT : public std::unary_function -{ - void operator() (const SIsectionPPT &s) { s.dump();} -}; -#endif - -/* -// Fuer for_each -struct parseSIsectionEIT : public std::unary_function -{ - void operator() (const SIsectionEIT &s) { s.parse();} -}; -*/ - -// Menge aller present/following EITs (actual TS) -class SIsectionsEIT : public std::set > -{ -public: - int readSections(void) { - SIsections sections; - int rc=sections.readSections(0x12, 0x4e, 0xff); - - for (SIsections::iterator k=sections.begin(); k!=sections.end(); k++) - insert(*k); - - return rc; - } -}; - -#ifdef ENABLE_PPT -// Menge aller present/following PPTs (actual TS) -class SIsectionsPPT : public std::set > -{ -public: - int readSections(int pid) { -// int readSections(void) { - SIsections sections; - int rc=sections.readSections(pid, 0xa1, 0xfe); - - for (SIsections::iterator k=sections.begin(); k!=sections.end(); k++) - insert(*k); - - return rc; - } -}; -#endif - -// Menge aller schedule EITs (actual TS) -class SIsectionsEITschedule : public std::set > -{ -public: - int readSections(void) { - SIsections sections; - int rc=sections.readSections(0x12, 0x50, 0xf0); - - for (SIsections::iterator k=sections.begin(); k!=sections.end(); k++) - insert(*k); - - return rc; - } -}; -#endif - class SIsectionSDT : public SIsection { public: @@ -916,69 +844,5 @@ protected: void copyDeliveryDescriptor(const char *buf, SInetwork &s); }; #endif -#ifndef DO_NOT_INCLUDE_STUFF_NOT_NEEDED_FOR_SECTIONSD -// Fuer for_each -struct printSIsectionSDT : public std::unary_function -{ - void operator() (const SIsectionSDT &s) { s.dump();} -}; - -// Menge aller SDTs (actual TS) -class SIsectionsSDT : public std::set > -{ -public: - int readSections(void) { - SIsections sections; - int rc=sections.readSections(0x11, 0x42, 0xff); - - for (SIsections::iterator k=sections.begin(); k!=sections.end(); k++) - insert(*k); - - return rc; - } -}; - -// Fuer for_each -struct printSIsectionBAT : public std::unary_function -{ - void operator() (const SIsectionBAT &s) { s.dump();} -}; - -// Menge aller BATs -class SIsectionsBAT : public std::set > -{ -public: - int readSections(void) { - SIsections sections; - int rc=sections.readSections(0x11, 0x4a, 0xff); - - for (SIsections::iterator k=sections.begin(); k!=sections.end(); k++) - insert(*k); - - return rc; - } -}; - -// Fuer for_each -struct printSIsectionNIT : public std::unary_function -{ - void operator() (const SIsectionNIT &s) { s.dump();} -}; - -// Menge aller NITs (actual network) -class SIsectionsNIT : public std::set > -{ -public: - int readSections(void) { - SIsections sections; - int rc=sections.readSections(0x10, 0x40, 0xff); - - for (SIsections::iterator k=sections.begin(); k!=sections.end(); k++) - insert(*k); - - return rc; - } -}; -#endif #endif // SISECTIONS_HPP diff --git a/src/eitd/dmxapi.cpp b/src/eitd/dmxapi.cpp index 953200509..c567b5818 100644 --- a/src/eitd/dmxapi.cpp +++ b/src/eitd/dmxapi.cpp @@ -41,28 +41,6 @@ #include "SIutils.hpp" #include "debug.h" -#ifndef DO_NOT_INCLUDE_STUFF_NOT_NEEDED_FOR_SECTIONSD -bool setfilter(const int fd, const uint16_t pid, const uint8_t filter, const uint8_t mask, const uint32_t flags) -{ - struct dmx_sct_filter_params flt; - - memset(&flt, 0, sizeof(struct dmx_sct_filter_params)); - - flt.pid = pid; - flt.filter.filter[0] = filter; - flt.filter.mask [0] = mask; - flt.timeout = 0; - flt.flags = flags; - - if (::ioctl(fd, DMX_SET_FILTER, &flt) == -1) - { - perror("[sectionsd] DMX: DMX_SET_FILTER"); - return false; - } - return true; -} -#endif - struct SI_section_TOT_header { unsigned char table_id : 8;