summaryrefslogtreecommitdiff
path: root/p2pvr/scanner
diff options
context:
space:
mode:
Diffstat (limited to 'p2pvr/scanner')
-rw-r--r--p2pvr/scanner/dvbSiReaderHelper.cpp14
-rw-r--r--p2pvr/scanner/dvbSiReaderHelper.h15
-rw-r--r--p2pvr/scanner/eitRows.cpp36
-rw-r--r--p2pvr/scanner/eitRows.h33
-rw-r--r--p2pvr/scanner/serviceRows.cpp26
-rw-r--r--p2pvr/scanner/serviceRows.h15
6 files changed, 67 insertions, 72 deletions
diff --git a/p2pvr/scanner/dvbSiReaderHelper.cpp b/p2pvr/scanner/dvbSiReaderHelper.cpp
index 1737921..7a14cd4 100644
--- a/p2pvr/scanner/dvbSiReaderHelper.cpp
+++ b/p2pvr/scanner/dvbSiReaderHelper.cpp
@@ -12,9 +12,9 @@ SimpleMessageException(ErrorReadingData);
SimpleMessageException(TimeoutReadingData);
SimpleMessageException(DemuxOpenFailure);
-const std::string DvbSiReaderHelper::ISO10646("ISO-10646");
-const std::string DvbSiReaderHelper::EitEncoding("ISO6937");
-const std::string DvbSiReaderHelper::UTF8("UTF8");
+const std::string DvbSiParserHelper::ISO10646("ISO-10646");
+const std::string DvbSiParserHelper::EitEncoding("ISO6937");
+const std::string DvbSiParserHelper::UTF8("UTF8");
DvbSiReaderHelper::DvbSiReaderHelper(const ScriptNodePtr p) :
demux(p, "demux", "/dev/dvb/adapter0/demux0"),
@@ -46,8 +46,8 @@ DvbSiReaderHelper::closeInput() const
}
}
-DvbSiReaderHelper::StrPtr
-DvbSiReaderHelper::convert(const char * txt, size_t len)
+DvbSiParserHelper::StrPtr
+DvbSiParserHelper::convert(const char * txt, size_t len)
{
if (len == 0) {
return boost::shared_ptr<Glib::ustring>(new Glib::ustring());
@@ -99,7 +99,7 @@ _dvb_crc32(void * buf, size_t len)
}
void
-DvbSiReaderHelper::readTables(const RowProcessor * rp) const
+DvbSiReaderHelper::readTables(const InfoTableParser & parseInfoTable) const
{
u_char buf[1<<12];
struct pollfd ufd;
@@ -117,7 +117,7 @@ DvbSiReaderHelper::readTables(const RowProcessor * rp) const
if (n < l)
throw ErrorReadingData("Smaller that section length");
if (_dvb_crc32(buf, l)) {
- if (parseInfoTable(buf, l, rp)) {
+ if (parseInfoTable(buf, l)) {
time(&lastuseful);
}
else {
diff --git a/p2pvr/scanner/dvbSiReaderHelper.h b/p2pvr/scanner/dvbSiReaderHelper.h
index bdcc3b6..66e1206 100644
--- a/p2pvr/scanner/dvbSiReaderHelper.h
+++ b/p2pvr/scanner/dvbSiReaderHelper.h
@@ -3,11 +3,14 @@
#include "scripts.h"
#include "variables.h"
+#include <boost/function.hpp>
class RowProcessor;
class DvbSiReaderHelper {
public:
+ typedef boost::function<bool (const u_char *, size_t)> InfoTableParser;
+
DvbSiReaderHelper(const ScriptNodePtr p);
~DvbSiReaderHelper();
@@ -17,18 +20,20 @@ class DvbSiReaderHelper {
protected:
void openInput() const;
virtual void filterInput(int fd) const = 0;
- void readTables(const RowProcessor *) const;
- virtual bool parseInfoTable(const u_char *data, size_t len, const RowProcessor *) const = 0;
+ void readTables(const InfoTableParser &) const;
void closeInput() const;
+ private:
+ mutable int fd_epg;
+};
+
+class DvbSiParserHelper {
+ protected:
typedef boost::shared_ptr<Glib::ustring> StrPtr;
static StrPtr convert(const char * txt, size_t len);
static const std::string ISO10646;
static const std::string EitEncoding;
static const std::string UTF8;
-
- private:
- mutable int fd_epg;
};
#endif
diff --git a/p2pvr/scanner/eitRows.cpp b/p2pvr/scanner/eitRows.cpp
index 6f1934a..cb69882 100644
--- a/p2pvr/scanner/eitRows.cpp
+++ b/p2pvr/scanner/eitRows.cpp
@@ -45,6 +45,7 @@
#include "rowProcessor.h"
#include "eitRows.h"
+#include <boost/tuple/tuple_comparison.hpp>
struct EitProgram {
VariableType serviceID;
@@ -151,7 +152,7 @@ static Glib::RefPtr<Glib::Regex> yearRegex = Glib::Regex::create("\\(([0-9]{4})[
static Glib::RefPtr<Glib::Regex> flagsRegex = Glib::Regex::create("[ []+([A-Z,]+)\\]");
void
-EitRows::parseEventDescription(const u_char * data, EitProgram * current) const {
+EitRowState::parseEventDescription(const u_char * data, EitProgram * current) const {
assert(GetDescriptorTag(data) == 0x4D);
const struct descr_short_event *evtdesc = reinterpret_cast<const struct descr_short_event *>(data);
@@ -232,7 +233,7 @@ EitRows::parseEventDescription(const u_char * data, EitProgram * current) const
/* Parse 0x4E Extended Event Descriptor. {{{ */
void
-EitRows::parseLongEventDescription(const u_char * data, EitProgram * current) const {
+EitRowState::parseLongEventDescription(const u_char * data, EitProgram * current) const {
assert(GetDescriptorTag(data) == 0x4E);
const struct descr_extended_event *levt = reinterpret_cast<const struct descr_extended_event *>(data);
bool non_empty = (levt->descriptor_number || levt->last_descriptor_number || levt->length_of_items || levt->data[0]);
@@ -274,7 +275,7 @@ EitRows::parseLongEventDescription(const u_char * data, EitProgram * current) co
only output the first one of each (XMLTV can't cope with more than
one) */
void
-EitRows::parseComponentDescription(const u_char * data, EitProgram * current) const {
+EitRowState::parseComponentDescription(const u_char * data, EitProgram * current) const {
assert(GetDescriptorTag(data) == 0x50);
const struct descr_component *dc = reinterpret_cast<const struct descr_component *>(data);
@@ -299,7 +300,7 @@ EitRows::parseComponentDescription(const u_char * data, EitProgram * current) co
} /*}}}*/
void
-EitRows::parseContentDescription(const u_char * data, EitProgram * current) const {
+EitRowState::parseContentDescription(const u_char * data, EitProgram * current) const {
assert(GetDescriptorTag(data) == 0x54);
const struct descr_content * dc = reinterpret_cast<const struct descr_content *>(data);
for (const u_char * p = reinterpret_cast<const u_char*>(&dc->data); p < data + DESCR_GEN_LEN + dc->descriptor_length; p += NIBBLE_CONTENT_LEN) {
@@ -311,7 +312,7 @@ EitRows::parseContentDescription(const u_char * data, EitProgram * current) cons
}
void
-EitRows::parseRatingDescription(const u_char * data, EitProgram * current) const {
+EitRowState::parseRatingDescription(const u_char * data, EitProgram * current) const {
assert(GetDescriptorTag(data) == 0x55);
const struct descr_parental_rating * pr = reinterpret_cast<const struct descr_parental_rating *>(data);
for (const u_char * p = reinterpret_cast<const u_char *>(&pr->data); p < data + DESCR_GEN_LEN + pr->descriptor_length; p += PARENTAL_RATING_ITEM_LEN) {
@@ -336,7 +337,7 @@ int parsePrivateDataSpecifier(const u_char *data) {
/* Parse 0x76 Content Identifier Descriptor. {{{ */
/* See ETSI TS 102 323, section 12 */
void
-EitRows::parseContentIdentifierDescription(const u_char * data, EitProgram * current) const {
+EitRowState::parseContentIdentifierDescription(const u_char * data, EitProgram * current) const {
assert(GetDescriptorTag(data) == 0x76);
const struct descr_content_identifier *ci = reinterpret_cast<const struct descr_content_identifier *>(data);
for (const u_char * p = reinterpret_cast<const u_char *>(&ci->data); p < data + DESCR_GEN_LEN + ci->descriptor_length; p += DESCR_GEN_LEN + ci->descriptor_length) {
@@ -378,7 +379,7 @@ EitRows::parseContentIdentifierDescription(const u_char * data, EitProgram * cur
'new', 'subtitles', 'rating', 'star-rating'
*/
void
-EitRows::parseDescription(const u_char * data, size_t len, EitProgram * current) const {
+EitRowState::parseDescription(const u_char * data, size_t len, EitProgram * current) const {
int pds = 0;
for (const u_char * p = data; p < data + len; p += DESCR_GEN_LEN + GetDescriptorLength(p)) {
const struct descr_gen *desc = reinterpret_cast<const struct descr_gen *>(p);
@@ -447,25 +448,13 @@ static bool validateDescription(const u_char *data, size_t len) {
return false;
} /*}}}*/
-EitRows::SeenProgram::SeenProgram(int s, int e) :
- sid(s),
- eid(e)
-{
-}
-bool
-EitRows::SeenProgram::operator<(const SeenProgram & o) const
-{
- return ((this->sid < o.sid) || ((this->sid == o.sid) && (this->eid < o.eid)));
-}
-
bool
-EitRows::parseInfoTable(const u_char *data, size_t len, const RowProcessor * rp) const {
+EitRowState::parseInfoTable(const u_char *data, size_t len, const RowProcessor * rp) {
const struct eit *e = reinterpret_cast<const struct eit *>(data);
len -= 4; //remove CRC
// For each event listing
- EitRowState state;
bool found = false;
for (const u_char *p = reinterpret_cast<const u_char *>(&e->data); p < data + len; p += EIT_EVENT_LEN + GetEITDescriptorsLoopLength(p)) {
const struct eit_event *evt = reinterpret_cast<const struct eit_event *>(p);
@@ -487,7 +476,7 @@ EitRows::parseInfoTable(const u_char *data, size_t len, const RowProcessor * rp)
BcdCharToInt(evt->start_time_m),
BcdCharToInt(evt->start_time_s));
EitProgram results;
- state.current = &results;
+ current = &results;
results.startTime = startTime;
results.stopTime = startTime + boost::posix_time::time_duration(
BcdCharToInt(evt->duration_h),
@@ -504,7 +493,7 @@ EitRows::parseInfoTable(const u_char *data, size_t len, const RowProcessor * rp)
results.eventID = HILO(evt->event_id);
parseDescription(reinterpret_cast<const u_char *>(&evt->data), GetEITDescriptorsLoopLength(evt), &results);
- state.process(rp);
+ process(rp);
found = true;
}
return found;
@@ -531,8 +520,9 @@ EitRows::filterInput(int fd) const
void
EitRows::execute(const Glib::ustring &, const RowProcessor * rp) const
{
+ EitRowState state;
openInput();
- readTables(rp);
+ readTables(boost::bind(&EitRowState::parseInfoTable, &state, _1, _2, rp));
closeInput();
}
diff --git a/p2pvr/scanner/eitRows.h b/p2pvr/scanner/eitRows.h
index 1d76c2d..2a3603f 100644
--- a/p2pvr/scanner/eitRows.h
+++ b/p2pvr/scanner/eitRows.h
@@ -5,6 +5,7 @@
#include "rowSet.h"
#include "variables.h"
#include "dvbSiReaderHelper.h"
+#include <boost/tuple/tuple.hpp>
class EitProgram;
@@ -17,18 +18,18 @@ class EitRows : public RowSet, DvbSiReaderHelper {
void loadComplete(const CommonObjects *);
private:
- class SeenProgram {
- public:
- SeenProgram(int sid, int eid);
- bool operator<(const SeenProgram &) const;
- const int sid;
- const int eid;
- };
- typedef std::set<SeenProgram> SeenPrograms;
- mutable SeenPrograms seenPrograms;
-
void filterInput(int fd) const;
- bool parseInfoTable(const u_char *data, size_t len, const RowProcessor *) const;
+};
+
+class EitRowState : public RowState, DvbSiParserHelper {
+ public:
+ EitRowState();
+ const Columns & getColumns() const;
+ RowAttribute resolveAttr(const Glib::ustring & attrName) const;
+
+ bool parseInfoTable(const u_char *data, size_t len, const RowProcessor *);
+
+ private:
void parseEventDescription(const u_char *data, EitProgram * current) const;
void parseLongEventDescription(const u_char *data, EitProgram * current) const;
void parseComponentDescription(const u_char *data, EitProgram * current) const;
@@ -36,15 +37,11 @@ class EitRows : public RowSet, DvbSiReaderHelper {
void parseRatingDescription(const u_char *data, EitProgram * current) const;
void parseContentIdentifierDescription(const u_char *data, EitProgram * current) const;
void parseDescription(const u_char * data, size_t len, EitProgram * current) const;
-};
-class EitRowState : public RowState {
- public:
- EitRowState();
- const Columns & getColumns() const;
- RowAttribute resolveAttr(const Glib::ustring & attrName) const;
+ typedef boost::tuple<int, int> SeenProgram;
+ typedef std::set<SeenProgram> SeenPrograms;
+ SeenPrograms seenPrograms;
- private:
Columns columns;
friend class EitRows;
mutable EitProgram * current;
diff --git a/p2pvr/scanner/serviceRows.cpp b/p2pvr/scanner/serviceRows.cpp
index 39a0cd7..38b1459 100644
--- a/p2pvr/scanner/serviceRows.cpp
+++ b/p2pvr/scanner/serviceRows.cpp
@@ -90,29 +90,29 @@ ServiceRows::filterInput(int fd) const
void
ServiceRows::execute(const Glib::ustring &, const RowProcessor * rp) const
{
+ ServiceRowState state;
openInput();
- readTables(rp);
+ readTables(boost::bind(&ServiceRowState::parseInfoTable, &state, _1, _2, rp));
closeInput();
}
bool
-ServiceRows::parseInfoTable(const u_char * data, size_t len, const RowProcessor * rp) const {
+ServiceRowState::parseInfoTable(const u_char * data, size_t len, const RowProcessor * rp) {
const struct sit *e = reinterpret_cast<const struct sit *>(data);
assert(e->tableid == 0x42 || e->tableid == 0x46);
len -= 4; //remove CRC
// For each event listing
bool found = false;
- ServiceRowState state;
for (const u_char * p = e->serviceData; p < data + len; ) {
const struct si * sid = reinterpret_cast<const struct si *>(p);
int sID = be16toh(sid->serviceid);
bool seen = (seenServices.find(sID) != seenServices.end());
- if (!seen) {
- size_t dll = HILO(sid->desc_loop_len);
- Service serv;
- state.current = &serv;
- for (p = sid->descData; p < sid->descData + dll; p += DESCR_GEN_LEN + GetDescriptorLength(p)) {
+ size_t dll = HILO(sid->desc_loop_len);
+ Service serv;
+ current = &serv;
+ for (p = sid->descData; p < sid->descData + dll; p += DESCR_GEN_LEN + GetDescriptorLength(p)) {
+ if (!seen) {
serv.serviceID = sID;
serv.transportID = be16toh(e->transport_stream_id);
const struct descr_gen *desc = reinterpret_cast<const struct descr_gen *>(p);
@@ -127,16 +127,18 @@ ServiceRows::parseInfoTable(const u_char * data, size_t len, const RowProcessor
break;
}
}
- seenServices.insert(sID);
- state.process(rp);
+ }
+ if (!seen) {
found = true;
+ seenServices.insert(sID);
+ process(rp);
}
}
return found;
}
void
-ServiceRows::parseServiceDescriptor(const u_char * p, size_t, Service * current) const
+ServiceRowState::parseServiceDescriptor(const u_char * p, size_t, Service * current) const
{
current->type = p[2];
if (p[3]) {
@@ -146,7 +148,7 @@ ServiceRows::parseServiceDescriptor(const u_char * p, size_t, Service * current)
}
void
-ServiceRows::parseServiceAuthDescriptor(const u_char * p, size_t len, Service * current) const
+ServiceRowState::parseServiceAuthDescriptor(const u_char * p, size_t len, Service * current) const
{
current->defaultAuthority = *convert((const char *)(p + 2), len);
}
diff --git a/p2pvr/scanner/serviceRows.h b/p2pvr/scanner/serviceRows.h
index 0fbd119..83eb623 100644
--- a/p2pvr/scanner/serviceRows.h
+++ b/p2pvr/scanner/serviceRows.h
@@ -17,22 +17,23 @@ class ServiceRows : public RowSet, DvbSiReaderHelper {
void loadComplete(const CommonObjects *);
private:
- typedef std::set<int> SeenServices;
- mutable SeenServices seenServices;
-
void filterInput(int fd) const;
- bool parseInfoTable(const u_char *data, size_t len, const RowProcessor *) const;
- void parseServiceDescriptor(const u_char *data, size_t len, Service * current) const;
- void parseServiceAuthDescriptor(const u_char *data, size_t len, Service * current) const;
};
-class ServiceRowState : public RowState {
+class ServiceRowState : public RowState, DvbSiParserHelper {
public:
ServiceRowState();
const Columns & getColumns() const;
RowAttribute resolveAttr(const Glib::ustring & attrName) const;
+ bool parseInfoTable(const u_char *data, size_t len, const RowProcessor *);
private:
+ void parseServiceDescriptor(const u_char *data, size_t len, Service * current) const;
+ void parseServiceAuthDescriptor(const u_char *data, size_t len, Service * current) const;
+
+ typedef std::set<int> SeenServices;
+ SeenServices seenServices;
+
Columns columns;
friend class ServiceRows;
mutable Service * current;