epg/epg.c

91 lines
1.9 KiB
C
Raw Normal View History

2011-06-01 23:34:35 +00:00
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <time.h>
#include <strings.h>
#include "lint.h"
struct section_header *
read_section_header(struct epg *epg)
{
static struct section_header h;
if (epg->binsize - epg->offset < sizeof(h))
return NULL;
memcpy(&h, epg->bin + epg->offset, sizeof(h));
if (memcmp(h.magic, SECTION_HEADER_MAGIC, sizeof(h.magic)))
{
printf("Section header magic mismatch.\n");
return NULL;
}
epg->offset += sizeof(h);
return &h;
}
#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)))
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, service_id);
DUMPINT(h, reserved2);
DUMPINT(h, version_number);
DUMPINT(h, current_next_indicator);
DUMPINT(h, section_number);
DUMPINT(h, last_section_number);
DUMPINT(h, transport_stream_id);
DUMPINT(h, original_network_id);
DUMPINT(h, segment_last_section_number);
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)
{
time_t tm;
printf("Data:\n");
DUMPINT(d, event_id);
DUMPINT(d, start_date);
tm = MJD_TO_UNIX(d->start_date);
printf(" %s", ctime(&tm));
DUMPINT(d, start_time);
// DUMPINT(d, duration);
DUMPINT(d, free_CA_mode);
DUMPINT(d, descriptors_loop_length);
}