This commit is contained in:
hummypkg 2011-06-02 01:32:55 +00:00 committed by HummyPkg
parent 9ebe37681b
commit d91dccdd7b
4 changed files with 164 additions and 37 deletions

116
epg.c
View File

@ -9,6 +9,8 @@
#include "lint.h"
#define _swap16(v) ((((v) >> 8) & 0xff) | (((v) & 0xff) << 8))
struct section_header *
read_section_header(struct epg *epg)
{
@ -24,25 +26,77 @@ read_section_header(struct epg *epg)
return NULL;
}
h.total_length = _swap16(h.total_length);
h.service_id = _swap16(h.service_id);
h.transport_stream_id = _swap16(h.transport_stream_id);
h.original_network_id = _swap16(h.original_network_id);
h.u1.comp = _swap16(h.u1.comp);
epg->offset += sizeof(h);
return &h;
}
struct data *
read_data(struct epg *epg)
{
static struct data d;
if (epg->binsize - epg->offset < sizeof(d))
return NULL;
memcpy(&d, epg->bin + epg->offset, sizeof(d));
d.event_id = _swap16(d.event_id);
d.start_date = _swap16(d.start_date);
d.u1.comp = _swap16(d.u1.comp);
epg->offset += sizeof(d);
return &d;
}
struct descriptor_header *
read_descriptor_header(struct epg *epg)
{
static struct descriptor_header d;
if (epg->binsize - epg->offset < sizeof(d))
return NULL;
memcpy(&d, epg->bin + epg->offset, sizeof(d));
epg->offset += sizeof(d);
return &d;
}
#define DUMPINT(ss,xx) printf(" %30s: %d\n", #xx, ss->xx)
#define DUMPSTR(ss,xx) printf(" %30s: %s\n", #xx, ss->xx)
#define DUMPHEX(ss,xx) printf(" %30s: %s\n", #xx, \
hexstr(ss->xx, sizeof(ss->xx)))
char *
ctime_nl(time_t *tm)
{
static char buf[26];
strcpy(buf, ctime(tm));
*strchr(buf, '\n') = '\0';
return buf;
}
void
dump_section_header(struct section_header *h)
{
printf("Section header:\n");
DUMPINT(h, total_length);
DUMPINT(h, table_id);
DUMPINT(h, section_syntax_indicator);
DUMPINT(h, reserved);
DUMPINT(h, section_length);
DUMPINT(h, u1.u.syntax_indicator);
DUMPINT(h, u1.u.reserved);
DUMPINT(h, u1.u.length);
DUMPINT(h, service_id);
DUMPINT(h, reserved2);
DUMPINT(h, version_number);
@ -55,20 +109,6 @@ dump_section_header(struct section_header *h)
DUMPINT(h, last_table_id);
}
struct data *
read_data(struct epg *epg)
{
static struct data d;
if (epg->binsize - epg->offset < sizeof(d))
return NULL;
memcpy(&d, epg->bin + epg->offset, sizeof(d));
epg->offset += sizeof(d);
return &d;
}
void
dump_data(struct data *d)
{
@ -76,15 +116,45 @@ dump_data(struct data *d)
printf("Data:\n");
DUMPINT(d, event_id);
DUMPINT(d, start_date);
tm = MJD_TO_UNIX(d->start_date);
printf(" %30s: %#x (%s)\n", "start_date",
d->start_date, ctime_nl(&tm));
printf(" %s", ctime(&tm));
printf(" %30s: %d:%02d:%02d\n", "start_time",
d->start_hour, d->start_min, d->start_sec);
printf(" %30s: %d:%02d:%02d\n", "duration",
d->dur_hour, d->dur_min, d->dur_sec);
DUMPINT(d, start_time);
// DUMPINT(d, duration);
DUMPINT(d, free_CA_mode);
DUMPINT(d, descriptors_loop_length);
DUMPINT(d, u1.u.running_status);
DUMPINT(d, u1.u.free_CA_mode);
DUMPINT(d, u1.u.descriptors_loop_length);
}
char *
descriptor_name(struct descriptor_header *d)
{
switch (d->tag)
{
case 77: return "short event";
case 80: return "component";
case 137: return "user defined";
case 118: return "content identifier";
case 74: return "linkage";
case 84: return "content";
case 95: return "private data specifier";
case 126: return "FTA content management";
default: return "Unknown";
}
return "Unknown";
}
void
dump_descriptor_header(struct descriptor_header *d)
{
printf("Descriptor header:\n");
printf(" %30s: %#x [%d] (%s)\n", "descriptor", d->tag, d->tag,
descriptor_name(d));
DUMPINT(d, len);
}

38
epg.h
View File

@ -17,13 +17,18 @@ struct section_header {
unsigned int total_length:16;
unsigned int magic2:32;
unsigned int table_id:8;
unsigned int section_syntax_indicator:1;
unsigned int reserved:3;
unsigned int section_length:12;
union {
struct {
unsigned int length:12;
unsigned int reserved:3;
unsigned int syntax_indicator:1;
} u;
unsigned int comp:16;
} u1;
unsigned int service_id:16;
unsigned int reserved2:2;
unsigned int version_number:5;
unsigned int current_next_indicator:1;
unsigned int version_number:5;
unsigned int reserved2:2;
unsigned int section_number:8;
unsigned int last_section_number:8;
unsigned int transport_stream_id:16;
@ -35,9 +40,24 @@ struct section_header {
struct data {
unsigned int event_id:16;
unsigned int start_date:16;
unsigned int start_time:24;
char duration[3];
unsigned int free_CA_mode:1;
unsigned int descriptors_loop_length:12;
unsigned int start_hour:8;
unsigned int start_min:8;
unsigned int start_sec:8;
unsigned int dur_hour:8;
unsigned int dur_min:8;
unsigned int dur_sec:8;
union {
struct {
unsigned int descriptors_loop_length:12;
unsigned int free_CA_mode:1;
unsigned int running_status:3;
} u;
unsigned int comp:16;
} u1;
};
struct descriptor_header {
unsigned int tag:8;
unsigned int len:8;
};

3
lint.h
View File

@ -22,3 +22,6 @@ void dump_section_header(struct section_header *);
struct data *read_data(struct epg *);
void dump_data(struct data *);
struct descriptor_header *read_descriptor_header(struct epg *);
void dump_descriptor_header(struct descriptor_header *);

44
main.c
View File

@ -40,15 +40,49 @@ main(int argc, char **argv)
struct data *d;
struct epg *epg;
if (!(epg = open_file("epg.dat")))
if (!(epg = open_file("../epg.dat")))
return 0;
h = read_section_header(epg);
dump_section_header(h);
while (epg->offset < epg->binsize)
{
uint32_t end;
d = read_data(epg);
dump_data(d);
if (!(h = read_section_header(epg)))
break;
dump_section_header(h);
end = epg->offset - 11 + h->u1.u.length - 4;
while (epg->offset < end)
{
uint32_t dend;
if (!(d = read_data(epg)))
break;
dump_data(d);
dend = epg->offset + d->u1.u.descriptors_loop_length;
while (epg->offset < dend)
{
struct descriptor_header *dh;
dh = read_descriptor_header(epg);
dump_descriptor_header(dh);
epg->offset += dh->len;
}
//goto stop;
}
/* Section CRC */
epg->offset += 4;
/* Skip padding bytes... */
while (epg->bin[epg->offset] == 'U')
epg->offset++;
}
stop:
close_file(epg);
return 0;