mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-09-02 10:21:04 +02:00
eitd/SIsections.cpp/hpp: remove unused code, test new event parsing
Origin commit data
------------------
Branch: ni/coolstream
Commit: 369671c36e
Author: [CST] Focus <focus.cst@gmail.com>
Date: 2012-02-08 (Wed, 08 Feb 2012)
------------------
No further description and justification available within origin commit message!
------------------
This commit was generated by Migit
This commit is contained in:
@@ -128,17 +128,17 @@ struct SI_section_header {
|
||||
} __attribute__ ((packed)) ; // 8 bytes
|
||||
|
||||
|
||||
class SIsection: public LongSection
|
||||
class SIsection //: public LongSection
|
||||
{
|
||||
public:
|
||||
//SIsection(void) { buffer = 0; bufferLength = 0;}
|
||||
|
||||
// Benutzt den uebergebenen Puffer (sollte mit new char[n] allokiert sein)
|
||||
SIsection(uint8_t *buf) : LongSection(buf)
|
||||
SIsection(uint8_t *buf) //: LongSection(buf)
|
||||
{
|
||||
buffer = NULL;
|
||||
bufferLength = 0;
|
||||
unsigned bufLength = 3 + getSectionLength();
|
||||
//unsigned bufLength = 3 + getSectionLength();
|
||||
unsigned bufLength = 3 + (((struct SI_section_header*) buf)->section_length_hi << 8 | ((struct SI_section_header*) buf)->section_length_lo);
|
||||
if ((buf) && (bufLength >= sizeof(struct SI_section_header))) {
|
||||
buffer = buf;
|
||||
bufferLength = bufLength;
|
||||
@@ -150,177 +150,16 @@ public:
|
||||
bufferLength = 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
unsigned char tableID(void) const {
|
||||
return buffer ? ((struct SI_section_header *)buffer)->table_id : (unsigned char) -1;
|
||||
}
|
||||
|
||||
unsigned short tableIDextension(void) const {
|
||||
return buffer ? ((((struct SI_section_header *)buffer)->table_id_extension_hi << 8) |
|
||||
((struct SI_section_header *)buffer)->table_id_extension_lo) : (unsigned short) -1;
|
||||
}
|
||||
|
||||
unsigned char sectionNumber(void) const {
|
||||
return buffer ? ((struct SI_section_header *)buffer)->section_number : (unsigned char) -1;
|
||||
}
|
||||
|
||||
unsigned char versionNumber(void) const {
|
||||
return buffer ? ((struct SI_section_header *)buffer)->version_number : (unsigned char) -1;
|
||||
}
|
||||
|
||||
unsigned char currentNextIndicator(void) const {
|
||||
return buffer ? ((struct SI_section_header *)buffer)->current_next_indicator : (unsigned char) -1;
|
||||
}
|
||||
|
||||
unsigned char lastSectionNumber(void) const {
|
||||
return buffer ? ((struct SI_section_header *)buffer)->last_section_number : (unsigned char) -1;
|
||||
}
|
||||
#endif
|
||||
struct SI_section_header const *header(void) const {
|
||||
return (struct SI_section_header *)buffer;
|
||||
}
|
||||
|
||||
static uint64_t key(const struct SI_section_header *header) {
|
||||
// Der eindeutige Key einer SIsection besteht aus 1 Byte Table-ID,
|
||||
// 2 Byte Table-ID-extension, 1 Byte Section number
|
||||
// 1 Byte Version number und 1 Byte current_next_indicator
|
||||
if (!header)
|
||||
return (uint64_t) -1;
|
||||
return (((uint64_t)header->table_id) << 40) +
|
||||
(((uint64_t)header->table_id_extension_hi) << 32) +
|
||||
(((uint64_t)header->table_id_extension_lo) << 24) +
|
||||
(((uint64_t)header->section_number) << 16) +
|
||||
(((uint64_t)header->version_number) << 8) +
|
||||
(((uint64_t)header->current_next_indicator));
|
||||
}
|
||||
|
||||
uint64_t key(void) const {
|
||||
return buffer ? key(header()) : (uint64_t) -1;
|
||||
}
|
||||
|
||||
// Der Operator zum sortieren
|
||||
bool operator < (const SIsection& s) const {
|
||||
return key() < s.key();
|
||||
}
|
||||
|
||||
static void dumpSmallSectionHeader(const struct SI_section_header *header) {
|
||||
if (!header)
|
||||
return;
|
||||
printf("\ntable_id: 0x%02x ", header->table_id);
|
||||
printf("table_id_extension: 0x%02x%02x", header->table_id_extension_hi, header->table_id_extension_lo);
|
||||
printf("section_number: 0x%02x\n", header->section_number);
|
||||
}
|
||||
|
||||
static void dumpSmallSectionHeader(const SIsection &s) {
|
||||
dumpSmallSectionHeader((struct SI_section_header *)s.buffer);
|
||||
}
|
||||
|
||||
void dumpSmallSectionHeader(void) const {
|
||||
dumpSmallSectionHeader((struct SI_section_header *)buffer);
|
||||
}
|
||||
|
||||
int saveBufferToFile(FILE *file) const {
|
||||
if (!file)
|
||||
return 1;
|
||||
return (fwrite(buffer, bufferLength, 1, file) != 1);
|
||||
}
|
||||
|
||||
int saveBufferToFile(const char *filename) const {
|
||||
if (!filename)
|
||||
return 2;
|
||||
|
||||
FILE *file = fopen(filename, "wb");
|
||||
|
||||
if (file) {
|
||||
int rc = saveBufferToFile(file);
|
||||
fclose(file);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
static void dump1(const struct SI_section_header *header) {
|
||||
if (!header)
|
||||
return;
|
||||
printf("\ntable_id: 0x%02x\n", header->table_id);
|
||||
printf("section_syntax_indicator: 0x%02x\n", header->section_syntax_indicator);
|
||||
printf("section_length: %hu\n", (header->section_length_hi << 8) | header->section_length_lo);
|
||||
}
|
||||
|
||||
static void dump2(const struct SI_section_header *header) {
|
||||
if (!header)
|
||||
return;
|
||||
printf("version_number: 0x%02x\n", header->version_number);
|
||||
printf("current_next_indicator: 0x%02x\n", header->current_next_indicator);
|
||||
printf("section_number: 0x%02x\n", header->section_number);
|
||||
printf("last_section_number: 0x%02x\n", header->last_section_number);
|
||||
}
|
||||
|
||||
static void dump(const struct SI_section_header *header) {
|
||||
if (!header)
|
||||
return;
|
||||
dump1(header);
|
||||
printf("table_id_extension: 0x%02x%02x\n", header->table_id_extension_hi, header->table_id_extension_lo);
|
||||
dump2(header);
|
||||
}
|
||||
|
||||
static void dump(const SIsection &s) {
|
||||
dump((struct SI_section_header *)s.buffer);
|
||||
}
|
||||
|
||||
void dump(void) const {
|
||||
dump((struct SI_section_header *)buffer);
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t *buffer;
|
||||
unsigned bufferLength;
|
||||
};
|
||||
|
||||
// Fuer for_each
|
||||
struct printSIsection : public std::unary_function<SIsection, void>
|
||||
{
|
||||
void operator() (const SIsection &s) { s.dump();}
|
||||
};
|
||||
|
||||
// Fuer for_each
|
||||
struct printSmallSIsectionHeader : public std::unary_function<SIsection, void>
|
||||
{
|
||||
void operator() (const SIsection &s) { s.dumpSmallSectionHeader();}
|
||||
};
|
||||
|
||||
class SIsections : public std::set <SIsection, std::less<SIsection> >
|
||||
class SIsectionEIT : public SIsection, public EventInformationSection
|
||||
{
|
||||
public:
|
||||
// Liefert 0 falls kein Fehler
|
||||
// Algo:
|
||||
// (1) Segment lesen (wird zum ersten Segment deklariert)
|
||||
// (2) Falls Segmentnummer = letze Segmentnummer = 0 dann fertig, sonst
|
||||
// (3) alle Segment lesen bis erstes wieder kommt
|
||||
// (4) fehlende Segmente (s. last_section_number) versuchen zu lesen
|
||||
// Der Timeout gilt fuer jeden der 3 Abschnitte, d.h. maximal dauert
|
||||
// es 3 x timeout.
|
||||
// Mit readNext=0 werden nur aktuelle Sections gelesen (current_next_indicator = 1)
|
||||
int readSections(unsigned short pid, unsigned char filter, unsigned char mask, int readNext=0, unsigned timeoutInSeconds=10);
|
||||
};
|
||||
|
||||
class SIsectionEIT : public SIsection
|
||||
{
|
||||
public:
|
||||
SIsectionEIT(const SIsection &s) : SIsection(s) {
|
||||
parsed = 0;
|
||||
parse();
|
||||
}
|
||||
|
||||
// Std-Copy
|
||||
SIsectionEIT(const SIsectionEIT &s) : SIsection(s) {
|
||||
evts = s.evts;
|
||||
parsed = s.parsed;
|
||||
}
|
||||
|
||||
// Benutzt den uebergebenen Puffer (sollte mit new char[n] allokiert sein)
|
||||
SIsectionEIT(uint8_t *buf) : SIsection(buf) {
|
||||
SIsectionEIT(uint8_t *buf) : SIsection(buf), EventInformationSection(buf)
|
||||
{
|
||||
parsed = 0;
|
||||
parse();
|
||||
}
|
||||
@@ -344,28 +183,6 @@ public:
|
||||
return (struct SI_section_EIT_header *)buffer;
|
||||
}
|
||||
|
||||
static void dump(const struct SI_section_EIT_header *header) {
|
||||
if (!header)
|
||||
return;
|
||||
SIsection::dump1((const struct SI_section_header *)header);
|
||||
printf("service_id: 0x%02x%02x\n", header->service_id_hi, header->service_id_lo);
|
||||
SIsection::dump2((const struct SI_section_header *)header);
|
||||
printf("transport_stream_id 0x%02x%02x\n", header->transport_stream_id_hi, header->transport_stream_id_lo);
|
||||
printf("original_network_id 0x%02x%02x\n", header->original_network_id_hi, header->original_network_id_lo);
|
||||
printf("segment_last_section_number: 0x%02x\n", header->segment_last_section_number);
|
||||
printf("last_table_id 0x%02x\n", header->last_table_id);
|
||||
}
|
||||
|
||||
static void dump(const SIsectionEIT &s) {
|
||||
dump((struct SI_section_EIT_header *)s.buffer);
|
||||
for_each(s.evts.begin(), s.evts.end(), printSIevent());
|
||||
}
|
||||
|
||||
void dump(void) const {
|
||||
dump((struct SI_section_EIT_header *)buffer);
|
||||
for_each(evts.begin(), evts.end(), printSIevent());
|
||||
}
|
||||
|
||||
const SIevents &events(void) const {
|
||||
//if(!parsed)
|
||||
// parse(); -> nicht const
|
||||
@@ -427,7 +244,7 @@ public:
|
||||
return buffer ? ((((struct SI_section_SDT_header *)buffer)->original_network_id_hi << 8) |
|
||||
((struct SI_section_SDT_header *)buffer)->original_network_id_lo) : 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void dump(const struct SI_section_SDT_header *header) {
|
||||
if (!header)
|
||||
return;
|
||||
@@ -446,7 +263,7 @@ public:
|
||||
dump((struct SI_section_SDT_header *)buffer);
|
||||
for_each(svs.begin(), svs.end(), printSIservice());
|
||||
}
|
||||
|
||||
#endif
|
||||
const SIservices &services(void) const {
|
||||
//if(!parsed)
|
||||
// parse(); -> nicht const
|
||||
|
Reference in New Issue
Block a user