extern "C" {
#endif
-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);
+ssize_t atsc_table_eit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct atsc_table_eit **table);
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
-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);
+ssize_t dvb_table_cat_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_cat **table);
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, void *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);
-struct dvb_table_init {
- dvb_table_init_func init;
- ssize_t size;
-};
-
-extern const struct dvb_table_init dvb_table_initializers[];
+extern const dvb_table_init_func dvb_table_initializers[256];
extern char *default_charset;
extern char *output_charset;
extern const struct dvb_descriptor dvb_descriptors[];
-enum dvb_tables {
- PAT,
- PMT,
- NIT,
- SDT,
- TVCT,
- CVCT,
-};
-
enum descriptors {
/* ISO/IEC 13818-1 */
video_stream_descriptor = 0x02,
extern "C" {
#endif
-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);
+ssize_t dvb_table_eit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_eit **table);
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
-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);
+ssize_t atsc_table_mgt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct atsc_table_mgt **table);
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
-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);
+ssize_t dvb_table_nit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_nit **table);
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
-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);
+ssize_t dvb_table_pat_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_pat **table);
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
-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);
+ssize_t dvb_table_pmt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_pmt **table);
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
-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);
+ssize_t dvb_table_sdt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_sdt **table);
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
-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);
+ssize_t atsc_table_vct_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct atsc_table_vct **table);
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) }
+#define TABLE_INIT(_x) (dvb_table_init_func) _x##_init
-const struct dvb_table_init dvb_table_initializers[] = {
+const dvb_table_init_func dvb_table_initializers[256] = {
+ [0 ... 255] = NULL,
[DVB_TABLE_PAT] = TABLE_INIT(dvb_table_pat),
[DVB_TABLE_CAT] = TABLE_INIT(dvb_table_cat),
[DVB_TABLE_PMT] = TABLE_INIT(dvb_table_pmt),
unsigned long is_read_bits[BITS_TO_LONGS(256)];
/* section gaps and multiple ts_id handling */
- ssize_t table_length;
int first_ts_id;
int first_section;
int done;
struct dvb_table_filter_priv *priv;
if (!sect->table) {
- dvb_logerr("table memory pointer not filled");
+ dvb_logerr("%s: table memory pointer not filled",
+ __func__);
return -4;
}
*sect->table = NULL;
struct dvb_table_header *h;
struct dvb_table_filter_priv *priv;
- uint8_t *tbl = NULL;
unsigned char tid;
h = (struct dvb_table_header *)buf;
if (!sect->allow_section_gaps && sect->ts_id != -1)
set_bit(h->section_id, priv->is_read_bits);
- tbl = *sect->table;
- if (!tbl) {
- if (!dvb_table_initializers[tid].size) {
- dvb_logerr("%s: no table size for table %d",
- __func__, tid);
- return -1;
- }
-
- tbl = calloc(dvb_table_initializers[tid].size, 1);
- }
-
- if (dvb_table_initializers[tid].init)
- dvb_table_initializers[tid].init(parms, buf, buf_length,
- tbl, &priv->table_length);
+ if (dvb_table_initializers[tid])
+ dvb_table_initializers[tid](parms, buf, buf_length,
+ sect->table);
else
dvb_logerr("%s: no initializer for table %d",
__func__, tid);
- /* Store the table */
- *sect->table = tbl;
-
if (!sect->allow_section_gaps && sect->ts_id != -1 &&
is_all_bits_set(priv->last_section, priv->is_read_bits))
priv->done = 1;
uint8_t *buf = NULL;
uint8_t mask = 0xff;
- /* FIXME: verify if all requested tables are known */
-
ret = dvb_parse_section_alloc(parms, sect);
if (ret < 0)
return ret;
#include <libdvbv5/dvb-fe.h>
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)
+ ssize_t buflen, struct atsc_table_eit **table)
{
const uint8_t *p = buf, *endbuf = buf + buflen - 4; /* minus CRC */;
+ struct atsc_table_eit *eit;
struct atsc_table_eit_event **head;
size_t size;
int i = 0;
return -2;
}
- if (*table_length > 0) {
- memcpy(eit, p, size);
-
- /* find end of curent list */
- head = &eit->event;
- while (*head != NULL)
- head = &(*head)->next;
- } else {
- memcpy(eit, p, size);
-
- eit->event = NULL;
- head = &eit->event;
+ if (!*table) {
+ *table = calloc(sizeof(struct atsc_table_eit), 1);
+ if (!*table) {
+ dvb_logerr("%s: out of memory", __func__);
+ return -3;
+ }
}
+ eit = *table;
+ memcpy(eit, p, size);
p += size;
+ /* find end of curent list */
+ head = &eit->event;
+ while (*head != NULL)
+ head = &(*head)->next;
+
while (i++ < eit->events && p < endbuf) {
struct atsc_table_eit_event *event;
union atsc_table_eit_desc_length dl;
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
endbuf - p, size);
- return -2;
+ return -4;
}
event = (struct atsc_table_eit_event *) malloc(sizeof(struct atsc_table_eit_event));
if (!event) {
dvb_logerr("%s: out of memory", __func__);
- return -3;
+ return -5;
}
memcpy(event, p, size);
p += size;
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
endbuf - p, size);
- return -3;
+ return -6;
}
/* TODO: parse title */
p += size;
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
endbuf - p, size);
- return -4;
+ return -7;
}
memcpy(&dl, p, size);
p += size;
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
endbuf - p, size);
- return -5;
+ return -8;
+ }
+ if (dvb_desc_parse(parms, p, size,
+ &event->descriptor) != 0 ) {
+ return -9;
}
- dvb_desc_parse(parms, p, size, &event->descriptor);
p += size;
}
- *table_length = p - buf;
return p - buf;
}
#include <libdvbv5/dvb-fe.h>
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)
+ ssize_t buflen, struct dvb_table_cat **table)
{
const uint8_t *p = buf, *endbuf = buf + buflen - 4;
+ struct dvb_table_cat *cat;
struct dvb_desc **head_desc;
size_t size;
return -2;
}
- if (*table_length > 0) {
- /* find end of current lists */
- head_desc = &cat->descriptor;
- while (*head_desc != NULL)
- head_desc = &(*head_desc)->next;
- } else {
- head_desc = &cat->descriptor;
+ if (!*table) {
+ *table = calloc(sizeof(struct dvb_table_cat), 1);
+ if (!*table) {
+ dvb_logerr("%s: out of memory", __func__);
+ return -3;
+ }
}
-
+ cat = *table;
memcpy(cat, p, size);
p += size;
+ /* find end of current lists */
+ head_desc = &cat->descriptor;
+ while (*head_desc != NULL)
+ head_desc = &(*head_desc)->next;
+
size = cat->header.section_length + 3 - 4; /* plus header, minus CRC */
if (buf + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
endbuf - buf, size);
- return -3;
+ return -4;
}
endbuf = buf + size;
uint16_t desc_length = endbuf - p;
if (dvb_desc_parse(parms, p, desc_length,
head_desc) != 0) {
- return -4;
+ return -5;
}
p += desc_length;
}
dvb_logwarn("%s: %zu spurious bytes at the end",
__func__, endbuf - p);
- *table_length = p - buf;
return p - buf;
}
#include <libdvbv5/dvb-fe.h>
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)
+ ssize_t buflen, struct dvb_table_eit **table)
{
const uint8_t *p = buf, *endbuf = buf + buflen - 4; /* minus CRC */
+ struct dvb_table_eit *eit;
struct dvb_table_eit_event **head;
size_t size;
return -2;
}
- if (*table_length > 0) {
- memcpy(eit, p, sizeof(struct dvb_table_eit) - sizeof(eit->event));
-
- bswap16(eit->transport_id);
- bswap16(eit->network_id);
-
- /* find end of curent list */
- head = &eit->event;
- while (*head != NULL)
- head = &(*head)->next;
- } else {
- memcpy(eit, p, sizeof(struct dvb_table_eit) - sizeof(eit->event));
-
- bswap16(eit->transport_id);
- bswap16(eit->network_id);
-
- eit->event = NULL;
- head = &eit->event;
+ if (!*table) {
+ *table = calloc(sizeof(struct dvb_table_eit), 1);
+ if (!*table) {
+ dvb_logerr("%s: out of memory", __func__);
+ return -3;
+ }
}
+ eit = *table;
+ memcpy(eit, p, size);
p += size;
+ bswap16(eit->transport_id);
+ bswap16(eit->network_id);
+
+ /* find end of curent list */
+ head = &eit->event;
+ while (*head != NULL)
+ head = &(*head)->next;
+
/* get the event entries */
size = offsetof(struct dvb_table_eit_event, descriptor);
while (p + size <= endbuf) {
event = malloc(sizeof(struct dvb_table_eit_event));
if (!event) {
dvb_logerr("%s: out of memory", __func__);
- return -3;
+ return -4;
}
memcpy(event, p, size);
p += size;
}
if (dvb_desc_parse(parms, p, desc_length,
&event->descriptor) != 0) {
- return -4;
+ return -5;
}
p += desc_length;
}
if (p < endbuf)
dvb_logwarn("%s: %zu spurious bytes at the end",
__func__, endbuf - p);
- *table_length = p - buf;
return p - buf;
}
#include <libdvbv5/dvb-fe.h>
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)
+ ssize_t buflen, struct atsc_table_mgt **table)
{
const uint8_t *p = buf, *endbuf = buf + buflen - 4; /* minus CRC */
+ struct atsc_table_mgt *mgt;
struct atsc_table_mgt_table **head;
struct dvb_desc **head_desc;
size_t size;
return -2;
}
- if (*table_length > 0) {
- memcpy(mgt, p, size);
-
- bswap16(mgt->tables);
-
- /* find end of curent lists */
- head_desc = &mgt->descriptor;
- while (*head_desc != NULL)
- head_desc = &(*head_desc)->next;
- head = &mgt->table;
- while (*head != NULL)
- head = &(*head)->next;
- } else {
- memcpy(mgt, p, size);
-
- bswap16(mgt->tables);
-
- mgt->descriptor = NULL;
- mgt->table = NULL;
- head_desc = &mgt->descriptor;
- head = &mgt->table;
+ if (!*table) {
+ *table = calloc(sizeof(struct atsc_table_mgt), 1);
+ if (!*table) {
+ dvb_logerr("%s: out of memory", __func__);
+ return -3;
+ }
}
+ mgt = *table;
+ memcpy(mgt, p, size);
p += size;
+ bswap16(mgt->tables);
+
+ /* find end of curent lists */
+ head_desc = &mgt->descriptor;
+ while (*head_desc != NULL)
+ head_desc = &(*head_desc)->next;
+ head = &mgt->table;
+ while (*head != NULL)
+ head = &(*head)->next;
+
while (i++ < mgt->tables && p < endbuf) {
struct atsc_table_mgt_table *table;
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
endbuf - p, size);
- return -2;
+ return -4;
}
table = (struct atsc_table_mgt_table *) malloc(sizeof(struct atsc_table_mgt_table));
if (!table) {
dvb_logerr("%s: out of memory", __func__);
- return -3;
+ return -5;
}
memcpy(table, p, size);
p += size;
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
endbuf - p, size);
- return -3;
+ return -6;
+ }
+ if (dvb_desc_parse(parms, p, size,
+ &table->descriptor) != 0) {
+ return -7;
}
- dvb_desc_parse(parms, p, size, &table->descriptor);
p += size;
}
/* TODO: parse MGT descriptors here into head_desc */
- *table_length = p - buf;
return p - buf;
}
#include <libdvbv5/dvb-fe.h>
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)
+ ssize_t buflen, struct dvb_table_nit **table)
{
const uint8_t *p = buf, *endbuf = buf + buflen - 4;
+ struct dvb_table_nit *nit;
struct dvb_table_nit_transport **head;
struct dvb_desc **head_desc;
size_t size;
return -2;
}
- if (*table_length > 0) {
- struct dvb_table_nit *t;
-
- /* find end of current lists */
- head_desc = &nit->descriptor;
- while (*head_desc != NULL)
- head_desc = &(*head_desc)->next;
- head = &nit->transport;
- while (*head != NULL)
- head = &(*head)->next;
-
- p += size;
- t = (struct dvb_table_nit *)buf;
-
- bswap16(t->bitfield);
- size = t->desc_length;
- } else {
- memcpy(nit, p, size);
- p += size;
+ if (!*table) {
+ *table = calloc(sizeof(struct dvb_table_nit), 1);
+ if (!*table) {
+ dvb_logerr("%s: out of memory", __func__);
+ return -3;
+ }
+ }
+ nit = *table;
+ memcpy(nit, p, size);
+ p += size;
- head = &nit->transport;
+ bswap16(nit->bitfield);
- nit->descriptor = NULL;
- nit->transport = NULL;
+ /* find end of current lists */
+ head_desc = &nit->descriptor;
+ while (*head_desc != NULL)
+ head_desc = &(*head_desc)->next;
+ head = &nit->transport;
+ while (*head != NULL)
+ head = &(*head)->next;
- bswap16(nit->bitfield);
- size = nit->desc_length;
- head_desc = &nit->descriptor;
- }
+ size = nit->desc_length;
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
endbuf - p, size);
- return -3;
+ return -4;
+ }
+ if (dvb_desc_parse(parms, p, size, head_desc) != 0) {
+ return -5;
}
- dvb_desc_parse(parms, p, size, head_desc);
p += size;
size = sizeof(union dvb_table_nit_transport_header);
if (p + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
endbuf - p, size);
- return -4;
+ return -6;
}
p += size;
transport = malloc(sizeof(struct dvb_table_nit_transport));
if (!transport) {
dvb_logerr("%s: out of memory", __func__);
- return -5;
+ return -7;
}
memcpy(transport, p, size);
p += size;
}
if (dvb_desc_parse(parms, p, desc_length,
&transport->descriptor) != 0) {
- return -6;
+ return -8;
}
p += desc_length;
}
if (endbuf - p)
dvb_logwarn("%s: %zu spurious bytes at the end",
__func__, endbuf - p);
- *table_length = p - buf;
return p - buf;
}
#include <libdvbv5/dvb-fe.h>
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)
+ ssize_t buflen, struct dvb_table_pat **table)
{
const uint8_t *p = buf, *endbuf = buf + buflen - 4;
+ struct dvb_table_pat *pat;
struct dvb_table_pat_program **head;
size_t size;
return -2;
}
- if (*table_length > 0) {
- /* find end of current list */
- head = &pat->program;
- while (*head != NULL)
- head = &(*head)->next;
- } else {
- memcpy(pat, buf, size);
- p += size;
- pat->programs = 0;
- pat->program = NULL;
- head = &pat->program;
+ if (!*table) {
+ *table = calloc(sizeof(struct dvb_table_pat), 1);
+ if (!*table) {
+ dvb_logerr("%s: out of memory", __func__);
+ return -3;
+ }
}
+ pat = *table;
+ memcpy(pat, buf, size);
+ p += size;
+
+ /* find end of current list */
+ head = &pat->program;
+ while (*head != NULL)
+ head = &(*head)->next;
size = offsetof(struct dvb_table_pat_program, next);
while (p + size <= endbuf) {
prog = malloc(sizeof(struct dvb_table_pat_program));
if (!prog) {
dvb_logerr("%s: out of memory", __func__);
- return -3;
+ return -4;
}
memcpy(prog, p, size);
if (endbuf - p)
dvb_logwarn("%s: %zu spurious bytes at the end",
__func__, endbuf - p);
- *table_length = p - buf;
return p - buf;
}
#include <string.h> /* memcpy */
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)
+ ssize_t buflen, struct dvb_table_pmt **table)
{
const uint8_t *p = buf, *endbuf = buf + buflen - 4;
+ struct dvb_table_pmt *pmt;
struct dvb_table_pmt_stream **head;
struct dvb_desc **head_desc;
size_t size;
return -2;
}
- if (*table_length > 0) {
- memcpy(pmt, p, size);
- bswap16(pmt->bitfield);
- bswap16(pmt->bitfield2);
-
- /* find end of current list */
- head = &pmt->stream;
- while (*head != NULL)
- head = &(*head)->next;
- head_desc = &pmt->descriptor;
- while (*head_desc != NULL)
- head_desc = &(*head_desc)->next;
- } else {
- memcpy(pmt, p, size);
- bswap16(pmt->bitfield);
- bswap16(pmt->bitfield2);
-
- pmt->descriptor = NULL;
- pmt->stream = NULL;
-
- head = &pmt->stream;
- head_desc = &pmt->descriptor;
+ if (!*table) {
+ *table = calloc(sizeof(struct dvb_table_pmt), 1);
+ if (!*table) {
+ dvb_logerr("%s: out of memory", __func__);
+ return -3;
+ }
}
+ pmt = *table;
+ memcpy(pmt, p, size);
p += size;
+ bswap16(pmt->bitfield);
+ bswap16(pmt->bitfield2);
+
+ /* find end of current list */
+ head = &pmt->stream;
+ while (*head != NULL)
+ head = &(*head)->next;
+ head_desc = &pmt->descriptor;
+ while (*head_desc != NULL)
+ head_desc = &(*head_desc)->next;
size = pmt->header.section_length + 3 - 4; /* plus header, minus CRC */
if (buf + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
endbuf - buf, size);
- return -3;
+ return -4;
}
endbuf = buf + size;
}
if (dvb_desc_parse(parms, p, desc_length,
head_desc) != 0) {
- return -3;
+ return -4;
}
p += desc_length;
}
stream = malloc(sizeof(struct dvb_table_pmt_stream));
if (!stream) {
dvb_logerr("%s: out of memory", __func__);
- return -3;
+ return -5;
}
memcpy(stream, p, size);
p += size;
}
if (dvb_desc_parse(parms, p, desc_length,
&stream->descriptor) != 0) {
- return -4;
+ return -6;
}
p += desc_length;
}
dvb_logwarn("%s: %zu spurious bytes at the end",
__func__, endbuf - p);
- *table_length = p - buf;
return p - buf;
}
#include <libdvbv5/dvb-fe.h>
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)
+ ssize_t buflen, struct dvb_table_sdt **table)
{
const uint8_t *p = buf, *endbuf = buf + buflen - 4;
+ struct dvb_table_sdt *sdt;
struct dvb_table_sdt_service **head;
size_t size;
return -2;
}
- if (*table_length > 0) {
- memcpy(sdt, p, size);
- bswap16(sdt->network_id);
-
- /* find end of curent list */
- head = &sdt->service;
- while (*head != NULL)
- head = &(*head)->next;
- } else {
- memcpy(sdt, p, size);
- bswap16(sdt->network_id);
-
- sdt->service = NULL;
- head = &sdt->service;
+ if (!*table) {
+ *table = calloc(sizeof(struct dvb_table_sdt), 1);
+ if (!*table) {
+ dvb_logerr("%s: out of memory", __func__);
+ return -3;
+ }
}
+ sdt = *table;
+ memcpy(sdt, p, size);
p += size;
+ bswap16(sdt->network_id);
+
+ /* find end of curent list */
+ head = &sdt->service;
+ while (*head != NULL)
+ head = &(*head)->next;
size = sdt->header.section_length + 3 - 4; /* plus header, minus CRC */
if (buf + size > endbuf) {
dvb_logerr("%s: short read %zd/%zd bytes", __func__,
endbuf - buf, size);
- return -3;
+ return -4;
}
endbuf = buf + size;
}
if (dvb_desc_parse(parms, p, desc_length,
&service->descriptor) != 0) {
- return -4;
+ return -6;
}
p += desc_length;
}
dvb_logwarn("%s: %zu spurious bytes at the end",
__func__, endbuf - p);
- *table_length = p - buf;
return p - buf;
}
#include <parse_string.h>
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)
+ ssize_t buflen, struct atsc_table_vct **table)
{
const uint8_t *p = buf, *endbuf = buf + buflen - 4;
+ struct atsc_table_vct *vct;
struct atsc_table_vct_channel **head;
size_t size;
int i, n;
return -2;
}
- if (*table_length > 0) {
- /* find end of curent list */
- head = &vct->channel;
- while (*head != NULL)
- head = &(*head)->next;
- } else {
- memcpy(vct, p, size);
-
- vct->channel = NULL;
- vct->descriptor = NULL;
-
- head = &vct->channel;
+ if (!*table) {
+ *table = calloc(sizeof(struct atsc_table_vct), 1);
+ if (!*table) {
+ dvb_logerr("%s: out of memory", __func__);
+ return -3;
+ }
}
+ vct = *table;
+ memcpy(vct, p, size);
p += size;
+ /* find end of curent list */
+ head = &vct->channel;
+ while (*head != NULL)
+ head = &(*head)->next;
+
size = offsetof(struct atsc_table_vct_channel, descriptor);
for (n = 0; n < vct->num_channels_in_section; n++) {
struct atsc_table_vct_channel *channel;
channel = malloc(sizeof(struct atsc_table_vct_channel));
if (!channel) {
dvb_logerr("%s: out of memory", __func__);
- return -3;
+ return -4;
}
memcpy(channel, p, size);
if (endbuf - p < channel->descriptors_length) {
dvb_logerr("%s: short read %d/%zd bytes", __func__,
channel->descriptors_length, endbuf - p);
- return -2;
+ return -5;
}
/* get the descriptors for each program */
- dvb_desc_parse(parms, p, channel->descriptors_length,
- &channel->descriptor);
+ if (dvb_desc_parse(parms, p, channel->descriptors_length,
+ &channel->descriptor) != 0) {
+ return -6;
+ }
p += channel->descriptors_length;
}
if (endbuf - p < d->descriptor_length) {
dvb_logerr("%s: short read %d/%zd bytes", __func__,
d->descriptor_length, endbuf - p);
- return -3;
+ return -7;
+ }
+ if (dvb_desc_parse(parms, p, d->descriptor_length,
+ &vct->descriptor) != 0) {
+ return -8;
}
- dvb_desc_parse(parms, p, d->descriptor_length,
- &vct->descriptor);
}
if (endbuf - p)
dvb_logwarn("%s: %zu spurious bytes at the end",
__func__, endbuf - p);
- *table_length = p - buf;
return p - buf;
}