extern "C" {
#endif
-void atsc_table_eit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length);
+ssize_t atsc_table_eit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct atsc_table_eit *eit, ssize_t *table_length);
void atsc_table_eit_free(struct atsc_table_eit *eit);
void atsc_table_eit_print(struct dvb_v5_fe_parms *parms, struct atsc_table_eit *eit);
void atsc_time(const uint32_t start_time, struct tm *tm);
extern "C" {
#endif
-void dvb_table_cat_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length);
+ssize_t dvb_table_cat_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_cat *cat, ssize_t *table_length);
void dvb_table_cat_free(struct dvb_table_cat *cat);
void dvb_table_cat_print(struct dvb_v5_fe_parms *parms, struct dvb_table_cat *t);
struct dvb_v5_fe_parms;
-typedef void (*dvb_table_init_func)(struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length);
+typedef void (*dvb_table_init_func)(struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, void *table, ssize_t *table_length);
struct dvb_table_init {
dvb_table_init_func init;
extern "C" {
#endif
-void dvb_table_eit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length);
+ssize_t dvb_table_eit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_eit *eit, ssize_t *table_length);
void dvb_table_eit_free(struct dvb_table_eit *eit);
void dvb_table_eit_print(struct dvb_v5_fe_parms *parms, struct dvb_table_eit *eit);
void dvb_time(const uint8_t data[5], struct tm *tm);
extern "C" {
#endif
-void atsc_table_mgt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length);
+ssize_t atsc_table_mgt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct atsc_table_mgt *mgt, ssize_t *table_length);
void atsc_table_mgt_free(struct atsc_table_mgt *mgt);
void atsc_table_mgt_print(struct dvb_v5_fe_parms *parms, struct atsc_table_mgt *mgt);
extern "C" {
#endif
-void dvb_table_nit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length);
+ssize_t dvb_table_nit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_nit *nit, ssize_t *table_length);
void dvb_table_nit_free(struct dvb_table_nit *nit);
void dvb_table_nit_print(struct dvb_v5_fe_parms *parms, struct dvb_table_nit *nit);
extern "C" {
#endif
-void dvb_table_pat_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length);
+ssize_t dvb_table_pat_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_pat *pat, ssize_t *table_length);
void dvb_table_pat_free(struct dvb_table_pat *pat);
void dvb_table_pat_print(struct dvb_v5_fe_parms *parms, struct dvb_table_pat *t);
extern "C" {
#endif
-void dvb_table_pmt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length);
+ssize_t dvb_table_pmt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_pmt *pmt, ssize_t *table_length);
void dvb_table_pmt_free(struct dvb_table_pmt *pmt);
void dvb_table_pmt_print(struct dvb_v5_fe_parms *parms, const struct dvb_table_pmt *pmt);
extern "C" {
#endif
-void dvb_table_sdt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length);
+ssize_t dvb_table_sdt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_sdt *sdt, ssize_t *table_lengh);
void dvb_table_sdt_free(struct dvb_table_sdt *sdt);
void dvb_table_sdt_print(struct dvb_v5_fe_parms *parms, struct dvb_table_sdt *sdt);
extern "C" {
#endif
-void atsc_table_vct_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length);
+ssize_t atsc_table_vct_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct atsc_table_vct *vct, ssize_t *table_length);
void atsc_table_vct_free(struct atsc_table_vct *vct);
void atsc_table_vct_print(struct dvb_v5_fe_parms *parms, struct atsc_table_vct *vct);
hexdump(parms, "| ", desc->data, desc->length);
}
+#define TABLE_INIT( _x ) { (dvb_table_init_func) _x##_init, sizeof(struct _x) }
+
const struct dvb_table_init dvb_table_initializers[] = {
- [DVB_TABLE_PAT] = { dvb_table_pat_init, sizeof(struct dvb_table_pat) },
- [DVB_TABLE_CAT] = { dvb_table_cat_init, sizeof(struct dvb_table_cat) },
- [DVB_TABLE_PMT] = { dvb_table_pmt_init, sizeof(struct dvb_table_pmt) },
- [DVB_TABLE_NIT] = { dvb_table_nit_init, sizeof(struct dvb_table_nit) },
- [DVB_TABLE_SDT] = { dvb_table_sdt_init, sizeof(struct dvb_table_sdt) },
- [DVB_TABLE_EIT] = { dvb_table_eit_init, sizeof(struct dvb_table_eit) },
- [DVB_TABLE_EIT_SCHEDULE] = { dvb_table_eit_init, sizeof(struct dvb_table_eit) },
- [ATSC_TABLE_MGT] = { atsc_table_mgt_init, sizeof(struct atsc_table_mgt) },
- [ATSC_TABLE_EIT] = { atsc_table_eit_init, sizeof(struct atsc_table_eit) },
- [ATSC_TABLE_TVCT] = { atsc_table_vct_init, sizeof(struct atsc_table_vct) },
- [ATSC_TABLE_CVCT] = { atsc_table_vct_init, sizeof(struct atsc_table_vct) },
+ [DVB_TABLE_PAT] = TABLE_INIT(dvb_table_pat),
+ [DVB_TABLE_CAT] = TABLE_INIT(dvb_table_cat),
+ [DVB_TABLE_PMT] = TABLE_INIT(dvb_table_pmt),
+ [DVB_TABLE_NIT] = TABLE_INIT(dvb_table_nit),
+ [DVB_TABLE_SDT] = TABLE_INIT(dvb_table_sdt),
+ [DVB_TABLE_EIT] = TABLE_INIT(dvb_table_eit),
+ [DVB_TABLE_EIT_SCHEDULE] = TABLE_INIT(dvb_table_eit),
+ [ATSC_TABLE_MGT] = TABLE_INIT(atsc_table_mgt),
+ [ATSC_TABLE_EIT] = TABLE_INIT(atsc_table_eit),
+ [ATSC_TABLE_TVCT] = TABLE_INIT(atsc_table_vct),
+ [ATSC_TABLE_CVCT] = TABLE_INIT(atsc_table_vct),
};
char *default_charset = "iso-8859-1";
#include <libdvbv5/atsc_eit.h>
#include <libdvbv5/dvb-fe.h>
-void atsc_table_eit_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length)
+ssize_t atsc_table_eit_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
+ ssize_t buflen, struct atsc_table_eit *eit, ssize_t *table_length)
{
const uint8_t *p = buf, *endbuf = buf + buflen - 4; /* minus CRC */;
- struct atsc_table_eit *eit = (struct atsc_table_eit *) table;
struct atsc_table_eit_event **head;
int i = 0;
struct atsc_table_eit_event *last = NULL;
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
size, endbuf - p);
- return;
+ return -1;
}
if (*table_length > 0) {
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
size, endbuf - p);
- return;
+ return -2;
}
event = (struct atsc_table_eit_event *) malloc(sizeof(struct atsc_table_eit_event));
memcpy(event, p, size);
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
size, endbuf - p);
- return;
+ return -3;
}
/* TODO: parse title */
p += size;
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
size, endbuf - p);
- return;
+ return -4;
}
memcpy(&dl, p, size);
p += size;
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
size, endbuf - p);
- return;
+ return -5;
}
dvb_parse_descriptors(parms, p, size, &event->descriptor);
p += size;
last = event;
}
+
+ *table_length = p - buf;
+ return p - buf;
}
void atsc_table_eit_free(struct atsc_table_eit *eit)
#include <libdvbv5/descriptors.h>
#include <libdvbv5/dvb-fe.h>
-void dvb_table_cat_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
- ssize_t buflen, uint8_t *table, ssize_t *table_length)
+ssize_t dvb_table_cat_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
+ ssize_t buflen, struct dvb_table_cat *cat, ssize_t *table_length)
{
- struct dvb_table_cat *cat = (void *)table;
struct dvb_desc **head_desc = &cat->descriptor;
const uint8_t *p = buf, *endbuf = buf + buflen - 4;
size_t size;
if (buf[0] != DVB_TABLE_CAT) {
dvb_logerr("%s: invalid marker 0x%02x, sould be 0x%02x", __func__, buf[0], DVB_TABLE_CAT);
*table_length = 0;
- return;
+ return -1;
}
if (*table_length > 0) {
if (p + size > endbuf) {
dvb_logerr("CAT table was truncated while filling dvb_table_cat. Need %zu bytes, but has only %zu.",
size, buflen);
- return;
+ return -2;
}
- memcpy(table, p, size);
+ memcpy(cat, p, size);
p += size;
*table_length = sizeof(struct dvb_table_cat);
size = endbuf - p;
dvb_parse_descriptors(parms, p, size, head_desc);
+
+ *table_length = p - buf;
+ return p - buf;
}
void dvb_table_cat_free(struct dvb_table_cat *cat)
#include <libdvbv5/eit.h>
#include <libdvbv5/dvb-fe.h>
-void dvb_table_eit_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length)
+ssize_t dvb_table_eit_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_eit *eit, ssize_t *table_length)
{
const uint8_t *p = buf;
- struct dvb_table_eit *eit = (struct dvb_table_eit *) table;
struct dvb_table_eit_event **head;
if (*table_length > 0) {
p += event->section_length;
last = event;
}
+ *table_length = p - buf;
+ return p - buf;
}
void dvb_table_eit_free(struct dvb_table_eit *eit)
#include <libdvbv5/mgt.h>
#include <libdvbv5/dvb-fe.h>
-void atsc_table_mgt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length)
+ssize_t atsc_table_mgt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
+ ssize_t buflen, struct atsc_table_mgt *mgt, ssize_t *table_length)
{
const uint8_t *p = buf, *endbuf = buf + buflen - 4; /* minus CRC */
- struct atsc_table_mgt *mgt = (struct atsc_table_mgt *) table;
struct dvb_desc **head_desc;
struct atsc_table_mgt_table **head;
int i = 0;
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
size, endbuf - p);
- return;
+ return -1;
}
if (*table_length > 0) {
/* FIXME: read current mgt->tables for loop below */
} else {
- memcpy(table, p, size);
+ memcpy(mgt, p, size);
*table_length = sizeof(struct atsc_table_mgt);
bswap16(mgt->tables);
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
size, endbuf - p);
- return;
+ return -2;
}
table = (struct atsc_table_mgt_table *) malloc(sizeof(struct atsc_table_mgt_table));
memcpy(table, p, size);
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
size, endbuf - p);
- return;
+ return -3;
}
dvb_parse_descriptors(parms, p, size, &table->descriptor);
p += size;
last = table;
}
+
/* TODO: parse MGT descriptors here into head_desc */
+
+ *table_length = p - buf;
+ return p - buf;
}
void atsc_table_mgt_free(struct atsc_table_mgt *mgt)
#include <libdvbv5/nit.h>
#include <libdvbv5/dvb-fe.h>
-void dvb_table_nit_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
- ssize_t buflen, uint8_t *table, ssize_t *table_length)
+ssize_t dvb_table_nit_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
+ ssize_t buflen, struct dvb_table_nit *nit, ssize_t *table_length)
{
const uint8_t *p = buf, *endbuf = buf + buflen - 4;
- struct dvb_table_nit *nit = (void *)table;
struct dvb_desc **head_desc = &nit->descriptor;
struct dvb_table_nit_transport **head = &nit->transport;
size_t size;
size = offsetof(struct dvb_table_nit, descriptor);
if (p + size > endbuf) {
dvb_logerr("NIT table (cont) was truncated");
- return;
+ return -1;
}
p += size;
t = (struct dvb_table_nit *)buf;
if (p + size > endbuf) {
dvb_logerr("NIT table was truncated while filling dvb_table_nit. Need %zu bytes, but has only %zu.",
size, buflen);
- return;
+ return -2;
}
- memcpy(table, p, size);
+ memcpy(nit, p, size);
p += size;
*table_length = sizeof(struct dvb_table_nit);
if (p + size > endbuf) {
dvb_logerr("NIT table was truncated while getting NIT descriptors. Need %zu bytes, but has only %zu.",
size, endbuf - p);
- return;
+ return -3;
}
dvb_parse_descriptors(parms, p, size, head_desc);
p += size;
if (p + size > endbuf) {
dvb_logerr("NIT table was truncated while getting NIT transports. Need %zu bytes, but has only %zu.",
size, endbuf - p);
- return;
+ return -4;
}
p += size;
transport = malloc(sizeof(struct dvb_table_nit_transport));
if (!transport) {
- dvb_perror("Out of memory");
- return;
+ dvb_perror(__func__);
+ return -5;
}
memcpy(transport, p, size);
p += size;
if (p + transport->section_length > endbuf) {
dvb_logerr("NIT table was truncated while getting NIT transport descriptors. Need %u bytes, but has only %zu.",
transport->section_length, endbuf - p);
- return;
+ return -6;
}
dvb_parse_descriptors(parms, p, transport->section_length, head_desc);
p += transport->section_length;
if (endbuf - p)
dvb_logerr("NIT table has %zu spurious bytes at the end.",
endbuf - p);
+ *table_length = p - buf;
+ return p - buf;
}
void dvb_table_nit_free(struct dvb_table_nit *nit)
#include <libdvbv5/descriptors.h>
#include <libdvbv5/dvb-fe.h>
-void dvb_table_pat_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
- ssize_t buflen, uint8_t *table, ssize_t *table_length)
+ssize_t dvb_table_pat_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
+ ssize_t buflen, struct dvb_table_pat *pat, ssize_t *table_length)
{
- struct dvb_table_pat *pat = (void *)table;
struct dvb_table_pat_program **head = &pat->program;
const uint8_t *p = buf, *endbuf = buf + buflen - 4;
size_t size;
if (p + size > endbuf) {
dvb_logerr("PAT table was truncated. Need %zu bytes, but has only %zu.",
size, buflen);
- return;
+ return -1;
}
- memcpy(table, buf, size);
+ memcpy(pat, buf, size);
p += size;
pat->programs = 0;
pat->program = NULL;
pgm = malloc(sizeof(struct dvb_table_pat_program));
if (!pgm) {
dvb_perror("Out of memory");
- return;
+ return -2;
}
memcpy(pgm, p, size);
if (endbuf - p)
dvb_logerr("PAT table has %zu spurious bytes at the end.",
endbuf - p);
+ *table_length = p - buf;
+ return p - buf;
}
void dvb_table_pat_free(struct dvb_table_pat *pat)
#include <string.h> /* memcpy */
-void dvb_table_pmt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
- ssize_t buflen, uint8_t *table, ssize_t *table_length)
+ssize_t dvb_table_pmt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
+ ssize_t buflen, struct dvb_table_pmt *pmt, ssize_t *table_length)
{
const uint8_t *p = buf, *endbuf = buf + buflen - 4;
- struct dvb_table_pmt *pmt = (void *)table;
struct dvb_table_pmt_stream **head = &pmt->stream;
size_t size;
if (buf[0] != DVB_TABLE_PMT) {
dvb_logerr("%s: invalid marker 0x%02x, sould be 0x%02x", __func__, buf[0], DVB_TABLE_PMT);
*table_length = 0;
- return;
+ return -1;
}
if (*table_length > 0) {
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
size, endbuf - p);
- return;
+ return -2;
}
memcpy(pmt, p, size);
p += size;
__func__, endbuf - p);
*table_length = p - buf;
+ return p - buf;
}
void dvb_table_pmt_free(struct dvb_table_pmt *pmt)
#include <libdvbv5/sdt.h>
#include <libdvbv5/dvb-fe.h>
-void dvb_table_sdt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
- ssize_t buflen, uint8_t *table, ssize_t *table_length)
+ssize_t dvb_table_sdt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
+ ssize_t buflen, struct dvb_table_sdt *sdt, ssize_t *table_length)
{
const uint8_t *p = buf, *endbuf = buf + buflen - 4;
- struct dvb_table_sdt *sdt = (void *)table;
struct dvb_table_sdt_service **head = &sdt->service;
size_t size = offsetof(struct dvb_table_sdt, service);
if (p + size > endbuf) {
dvb_logerr("SDT table was truncated. Need %zu bytes, but has only %zu.",
size, buflen);
- return;
+ return -1;
}
memcpy(sdt, p, size);
*table_length = sizeof(struct dvb_table_sdt);
if (endbuf - p)
dvb_logerr("SDT table has %zu spurious bytes at the end.",
endbuf - p);
+
+ *table_length = p - buf;
+ return p - buf;
}
void dvb_table_sdt_free(struct dvb_table_sdt *sdt)
#include <libdvbv5/dvb-fe.h>
#include <parse_string.h>
-void atsc_table_vct_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
- ssize_t buflen, uint8_t *table, ssize_t *table_length)
+ssize_t atsc_table_vct_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
+ ssize_t buflen, struct atsc_table_vct *vct, ssize_t *table_length)
{
const uint8_t *p = buf, *endbuf = buf + buflen - 4;
- struct atsc_table_vct *vct = (void *)table;
struct atsc_table_vct_channel **head = &vct->channel;
int i, n;
size_t size = offsetof(struct atsc_table_vct, channel);
if (p + size > endbuf) {
dvb_logerr("VCT table was truncated. Need %zu bytes, but has only %zu.",
size, buflen);
- return;
+ return -1;
}
if (*table_length > 0) {
if (endbuf - p < channel->descriptors_length) {
dvb_logerr("%s: short read %d/%zd bytes", __func__,
channel->descriptors_length, endbuf - p);
- return;
+ return -2;
}
/* get the descriptors for each program */
if (endbuf - p < d->descriptor_length) {
dvb_logerr("%s: short read %d/%zd bytes", __func__,
d->descriptor_length, endbuf - p);
- return;
+ return -3;
}
dvb_parse_descriptors(parms, p, d->descriptor_length,
&vct->descriptor);
if (endbuf - p)
dvb_logerr("VCT table has %zu spurious bytes at the end.",
endbuf - p);
+ *table_length = p - buf;
+ return p - buf;
}
void atsc_table_vct_free(struct atsc_table_vct *vct)