diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-08-03 00:34:53 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-08-03 00:34:53 +0100 |
commit | 9601afa4595961b441dc4cd7d3275b9255e9c443 (patch) | |
tree | 1f6a37dd73543ed49c11a029ebd9f7d8618c11fc | |
parent | Provide more comprehensive video stats, not just size (diff) | |
download | p2pvr-9601afa4595961b441dc4cd7d3275b9255e9c443.tar.bz2 p2pvr-9601afa4595961b441dc4cd7d3275b9255e9c443.tar.xz p2pvr-9601afa4595961b441dc4cd7d3275b9255e9c443.zip |
Internalise the core of SI table parsers into the DVB lib
-rw-r--r-- | p2pvr/dvb/siParsers/event.cpp | 2 | ||||
-rw-r--r-- | p2pvr/dvb/siParsers/network.cpp | 2 | ||||
-rw-r--r-- | p2pvr/dvb/siParsers/programAssociation.cpp | 2 | ||||
-rw-r--r-- | p2pvr/dvb/siParsers/programMap.cpp | 2 | ||||
-rw-r--r-- | p2pvr/dvb/siParsers/service.cpp | 2 | ||||
-rw-r--r-- | p2pvr/dvb/siParsers/table.cpp | 6 | ||||
-rw-r--r-- | p2pvr/dvb/siParsers/table.h | 112 | ||||
-rw-r--r-- | p2pvr/dvb/siParsers/table.impl.h | 121 |
8 files changed, 148 insertions, 101 deletions
diff --git a/p2pvr/dvb/siParsers/event.cpp b/p2pvr/dvb/siParsers/event.cpp index 6e290c0..435fee1 100644 --- a/p2pvr/dvb/siParsers/event.cpp +++ b/p2pvr/dvb/siParsers/event.cpp @@ -1,4 +1,5 @@ #include <time.h> +#include "table.impl.h" #include <glibmm/regex.h> #include <boost/regex.hpp> #include <boost/date_time/posix_time/posix_time_types.hpp> @@ -263,6 +264,7 @@ SiEpgParser::ParseSiTable(const EventInformation * eit, ::DVBSI::EitInformationP HandleTable(e); }); } +template bool DLL_PUBLIC SiTableParser<EventInformation, ::DVBSI::EitInformationPtr, int>::ParseInfoTable(const u_char * data, size_t len); } } diff --git a/p2pvr/dvb/siParsers/network.cpp b/p2pvr/dvb/siParsers/network.cpp index cca7e9f..56b4396 100644 --- a/p2pvr/dvb/siParsers/network.cpp +++ b/p2pvr/dvb/siParsers/network.cpp @@ -1,4 +1,5 @@ #include "network.h" +#include "table.impl.h" #include <boost/bind.hpp> #include <linux/dvb/frontend.h> #include <safeMapFind.h> @@ -297,6 +298,7 @@ SiNetworkInformationParser::parseDescriptor_ServiceList(::DVBSI::NetworkTranspor data += sizeof(ServiceListDescriptor); } } +template bool DLL_PUBLIC SiTableParser<NetworkInformation, ::DVBSI::NetworkPtr, u_char>::ParseInfoTable(const u_char * data, size_t len); } } diff --git a/p2pvr/dvb/siParsers/programAssociation.cpp b/p2pvr/dvb/siParsers/programAssociation.cpp index c3faf3a..709dba6 100644 --- a/p2pvr/dvb/siParsers/programAssociation.cpp +++ b/p2pvr/dvb/siParsers/programAssociation.cpp @@ -1,4 +1,5 @@ #include "programAssociation.h" +#include "table.impl.h" namespace P2PVR { namespace DVBSI { @@ -27,6 +28,7 @@ SiProgramAssociationParser::ParseSiTable(const ProgramAssociationSection * pas, (*pam)[ntohs(sd->program_number)] = HILO(sd->pid); }); } +template bool DLL_PUBLIC SiTableParser<ProgramAssociationSection, ProgramAssociationMapPtr, int>::ParseInfoTable(const u_char * data, size_t len); } } diff --git a/p2pvr/dvb/siParsers/programMap.cpp b/p2pvr/dvb/siParsers/programMap.cpp index 90bb8cf..c2f9482 100644 --- a/p2pvr/dvb/siParsers/programMap.cpp +++ b/p2pvr/dvb/siParsers/programMap.cpp @@ -1,4 +1,5 @@ #include "programMap.h" +#include "table.impl.h" #include <boost/bind.hpp> namespace P2PVR { @@ -46,6 +47,7 @@ SiProgramMapParser::ParseSiTable(const struct ProgramMap * pm, ::DVBSI::ProgramM pms = ParseDescriptors<ProgramMapStream>(pms->data, HILO(pms->ES_info_length)); } } +template bool DLL_PUBLIC SiTableParser<ProgramMap, ::DVBSI::ProgramMapPtr, u_char>::ParseInfoTable(const u_char * data, size_t len); } } diff --git a/p2pvr/dvb/siParsers/service.cpp b/p2pvr/dvb/siParsers/service.cpp index 6f4e27b..4334b1c 100644 --- a/p2pvr/dvb/siParsers/service.cpp +++ b/p2pvr/dvb/siParsers/service.cpp @@ -1,4 +1,5 @@ #include "service.h" +#include "table.impl.h" #include <boost/bind.hpp> namespace P2PVR { @@ -68,6 +69,7 @@ SiServicesParser::parseDescriptor_DefaultAuthority(::DVBSI::ServicePtr s, const { s->DefaultAuthority = *convert((const char *)p, len); } +template bool DLL_PUBLIC SiTableParser<TransportStreamDescriptor, ::DVBSI::TransportStreamPtr, int>::ParseInfoTable(const u_char * data, size_t len); } } diff --git a/p2pvr/dvb/siParsers/table.cpp b/p2pvr/dvb/siParsers/table.cpp index 40af5fb..4baa7a5 100644 --- a/p2pvr/dvb/siParsers/table.cpp +++ b/p2pvr/dvb/siParsers/table.cpp @@ -32,6 +32,12 @@ SiTableParserBase::CurrentRawData() const return *currentRawData; } +bool +SiTableParserBase::IsFinished() const +{ + return ((incomplete == 0) && (startTime < (time(NULL) - 10))); +} + SiTableParserBase::StrPtr SiTableParserBase::convert(const char * txt, size_t len) { diff --git a/p2pvr/dvb/siParsers/table.h b/p2pvr/dvb/siParsers/table.h index 821bf93..bbf84f6 100644 --- a/p2pvr/dvb/siParsers/table.h +++ b/p2pvr/dvb/siParsers/table.h @@ -34,6 +34,8 @@ class DLL_PUBLIC SiTableParserBase : public P2PVR::RawDataClient { bool NewData(const P2PVR::Data & bytes, const Ice::Current&); + virtual bool IsFinished() const; + static StrPtr convert(const char * txt, size_t len); static const std::string ISO10646; @@ -97,113 +99,21 @@ class SiTableParser : public SiTableParserBase { virtual uint8_t LastTableId(const TableType * t) { return t->header.tableid; } virtual uint8_t FirstTableId(const TableType * t) { return t->header.tableid; } - bool ParseInfoTable(const u_char * data, size_t len) - { - const u_char * dataEnd = data + len; - while (data < dataEnd) { - auto siTable = reinterpret_cast<const TableType *>(data); - if (siTable->header.current_next_indicator == 1 // current only, please. - && CheckTableId(siTable->header.tableid)) { // only tables we're interested in, please. - std::lock_guard<std::mutex> g(lock); - uint16_t contentId = ntohs(siTable->header.content_id); - ContentType & content = contents[contentId]; - uint8_t sectionNumber = siTable->header.section_number >> SectionNumberShift(); - TableTargetSections & targetTableSections = boost::get<1>(content); - TargetSections & targetSections = targetTableSections[siTable->header.tableid]; - boost::get<0>(targetSections) = siTable->header.last_section_number >> SectionNumberShift(); - Sections & seen = boost::get<1>(targetSections); - if (seen.find(sectionNumber) == seen.end()) { - auto & obj = boost::get<0>(content); - if (!obj) { - obj = TargetType(new typename TargetType::element_type()); - incomplete += 1; - } - ParseSiTable(siTable, obj); - seen.insert(sectionNumber); - bool complete = true; - for (int tid = FirstTableId(siTable); tid <= LastTableId(siTable); tid += 1) { - TableTargetSections::const_iterator tts = targetTableSections.find(tid); - if (tts == targetTableSections.end()) { - complete = false; - break; - } - if (boost::get<1>(tts->second).size() <= boost::get<0>(tts->second)) { - complete = false; - break; - } - } - if (complete) { - if (HandleTable(obj)) { - targetTableSections.clear(); - } - else { - obj = TargetType(); - } - incomplete -= 1; - } - } - } - data += HILO(siTable->header.section_length) + 4; - } - return IsFinished(); - } - - virtual bool IsFinished() const - { - return ((incomplete == 0) && (startTime < (time(NULL) - 10))); - } - - static void ParseDescriptor(const SiDescriptorHeader * descriptor) - { - (void)descriptor; - // Logger()->messagef(LOG_DEBUG, "Dropped descriptor with tag 0x%02x", descriptor->tag); - return; - } - - template <typename ... OtherParers> - static void ParseDescriptor(const SiDescriptorHeader * descriptor, u_char tag, boost::function<void(const u_char *, size_t)> parser, OtherParers ... otherParers) - { - if (tag == descriptor->tag) { - parser(descriptor->data, descriptor->length); - } - else { - ParseDescriptor(descriptor, otherParers...); - } - } + bool ParseInfoTable(const u_char * data, size_t len); + + static void ParseDescriptor(const SiDescriptorHeader * descriptor); + + template <typename ... OtherParsers> + static void ParseDescriptor(const SiDescriptorHeader * descriptor, u_char tag, const boost::function<void(const u_char *, size_t)> & parser, const OtherParsers & ... otherParsers); template <typename NextData = void, typename ... Parsers> - static const NextData * ParseDescriptors(const u_char * data, size_t len, Parsers ... parsers) - { - auto end = data + len; - while (data < end) { - auto descriptor = reinterpret_cast<const SiDescriptorHeader *>(data); - ParseDescriptor(descriptor, parsers...); - data += descriptor->length + 2; - } - return reinterpret_cast<const NextData *>(end); - } + static const NextData * ParseDescriptors(const u_char * data, size_t len, const Parsers & ... parsers); template<typename LoopContent> - static void LoopOver(const u_char * data, size_t len, boost::function<void(const LoopContent *)> parser) - { - auto end = data + len; - while (data < end) { - auto loopData = reinterpret_cast<const LoopContent *>(data); - parser(loopData); - data += HILO(loopData->descriptors_length) + (loopData->data - data); - } - } + static void LoopOver(const u_char * data, size_t len, const boost::function<void(const LoopContent *)> & parser); template<typename LoopContent> - static void LoopOverSection(const u_char * data, size_t len, boost::function<void(const LoopContent *)> parser) - { - auto end = data + len; - while (data < end) { - auto loopData = reinterpret_cast<const LoopContent *>(data); - parser(loopData); - data += sizeof(LoopContent); - } - } + static void LoopOverSection(const u_char * data, size_t len, const boost::function<void(const LoopContent *)> & parser); virtual bool CheckTableId(u_char tableId) const = 0; virtual void ParseSiTable(const TableType *, TargetType) = 0; diff --git a/p2pvr/dvb/siParsers/table.impl.h b/p2pvr/dvb/siParsers/table.impl.h new file mode 100644 index 0000000..c5fed98 --- /dev/null +++ b/p2pvr/dvb/siParsers/table.impl.h @@ -0,0 +1,121 @@ +#include "table.h" + +namespace P2PVR { + namespace DVBSI { + template <class TableType, class TargetType, class Key> + bool + SiTableParser<TableType, TargetType, Key>::ParseInfoTable(const u_char * data, size_t len) + { + const u_char * dataEnd = data + len; + while (data < dataEnd) { + auto siTable = reinterpret_cast<const TableType *>(data); + if (siTable->header.current_next_indicator == 1 // current only, please. + && CheckTableId(siTable->header.tableid)) { // only tables we're interested in, please. + std::lock_guard<std::mutex> g(lock); + uint16_t contentId = ntohs(siTable->header.content_id); + ContentType & content = contents[contentId]; + uint8_t sectionNumber = siTable->header.section_number >> SectionNumberShift(); + TableTargetSections & targetTableSections = boost::get<1>(content); + TargetSections & targetSections = targetTableSections[siTable->header.tableid]; + boost::get<0>(targetSections) = siTable->header.last_section_number >> SectionNumberShift(); + Sections & seen = boost::get<1>(targetSections); + if (seen.find(sectionNumber) == seen.end()) { + auto & obj = boost::get<0>(content); + if (!obj) { + obj = TargetType(new typename TargetType::element_type()); + incomplete += 1; + } + ParseSiTable(siTable, obj); + seen.insert(sectionNumber); + bool complete = true; + for (int tid = FirstTableId(siTable); tid <= LastTableId(siTable); tid += 1) { + TableTargetSections::const_iterator tts = targetTableSections.find(tid); + if (tts == targetTableSections.end()) { + complete = false; + break; + } + if (boost::get<1>(tts->second).size() <= boost::get<0>(tts->second)) { + complete = false; + break; + } + } + if (complete) { + if (HandleTable(obj)) { + targetTableSections.clear(); + } + else { + obj = TargetType(); + } + incomplete -= 1; + } + } + } + data += HILO(siTable->header.section_length) + 4; + } + return IsFinished(); + } + + template <class TableType, class TargetType, class Key> + void + SiTableParser<TableType, TargetType, Key>::ParseDescriptor(const SiDescriptorHeader * descriptor) + { + (void)descriptor; + // Logger()->messagef(LOG_DEBUG, "Dropped descriptor with tag 0x%02x", descriptor->tag); + return; + } + + template <class TableType, class TargetType, class Key> + template <typename ... OtherParsers> + void + SiTableParser<TableType, TargetType, Key>::ParseDescriptor(const SiDescriptorHeader * descriptor, u_char tag, const boost::function<void(const u_char *, size_t)> & parser, const OtherParsers & ... otherParsers) + { + if (tag == descriptor->tag) { + parser(descriptor->data, descriptor->length); + } + else { + ParseDescriptor(descriptor, otherParsers...); + } + } + + template <class TableType, class TargetType, class Key> + template <typename NextData, typename ... Parsers> + const NextData * + SiTableParser<TableType, TargetType, Key>::ParseDescriptors(const u_char * data, size_t len, const Parsers & ... parsers) + { + auto end = data + len; + while (data < end) { + auto descriptor = reinterpret_cast<const SiDescriptorHeader *>(data); + ParseDescriptor(descriptor, parsers...); + data += descriptor->length + 2; + } + return reinterpret_cast<const NextData *>(end); + } + + template <class TableType, class TargetType, class Key> + template<typename LoopContent> + void + SiTableParser<TableType, TargetType, Key>::LoopOver(const u_char * data, size_t len, const boost::function<void(const LoopContent *)> & parser) + { + auto end = data + len; + while (data < end) { + auto loopData = reinterpret_cast<const LoopContent *>(data); + parser(loopData); + data += HILO(loopData->descriptors_length) + (loopData->data - data); + } + } + + template <class TableType, class TargetType, class Key> + template<typename LoopContent> + void + SiTableParser<TableType, TargetType, Key>::LoopOverSection(const u_char * data, size_t len, const boost::function<void(const LoopContent *)> & parser) + { + auto end = data + len; + while (data < end) { + auto loopData = reinterpret_cast<const LoopContent *>(data); + parser(loopData); + data += sizeof(LoopContent); + } + } + } +} + |