Commit 8154e00f authored by Christophe Massiot's avatar Christophe Massiot

* ALL: New *_print() set of functions. * ALL (tables): Check CRC only when...

* ALL: New *_print() set of functions. * ALL (tables): Check CRC only when needed; also check tables coherence. * ALL (descriptors): Add a lot of missing _get_ functions. * ALL (descriptors): Fix off-by-one overflow of structure array. * mpeg/psi.h: Fix off-by-one overflow of PAT program array.
parent 968b0ea0
/*****************************************************************************
* common.h: (Rare) common declarations for all submodules
*****************************************************************************
* Copyright (C) 2010 VideoLAN
* $Id: psi.h 1 2010-08-10 19:42:50Z massiot $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*****************************************************************************/
#ifndef __BITSTREAM_COMMON_H__
#define __BITSTREAM_COMMON_H__
#ifdef __cplusplus
extern "C"
{
#endif
typedef void (*f_print)(void *, const char *, ...);
#ifdef __cplusplus
}
#endif
#endif
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#ifndef __BITSTREAM_DVB_SI_H__ #ifndef __BITSTREAM_DVB_SI_H__
#define __BITSTREAM_DVB_SI_H__ #define __BITSTREAM_DVB_SI_H__
#include <bitstream/common.h>
#include <bitstream/mpeg/psi.h> #include <bitstream/mpeg/psi.h>
#ifdef __cplusplus #ifdef __cplusplus
...@@ -55,6 +56,14 @@ static inline void desc40_get_networkname(const uint8_t *p_desc, ...@@ -55,6 +56,14 @@ static inline void desc40_get_networkname(const uint8_t *p_desc,
psz_network_name[i_length] = '\0'; psz_network_name[i_length] = '\0';
} }
static inline void desc40_print(const uint8_t *p_desc, f_print pf_print,
void *opaque)
{
DESC_DECLARE_STRING1(psz_network_name);
desc40_get_networkname(p_desc, psz_network_name);
pf_print(opaque, " - desc 40 networkname=%s", psz_network_name);
}
/***************************************************************************** /*****************************************************************************
* Descriptor 0x48: Service descriptor * Descriptor 0x48: Service descriptor
*****************************************************************************/ *****************************************************************************/
...@@ -81,6 +90,17 @@ static inline void desc48_get_service(const uint8_t *p_desc, ...@@ -81,6 +90,17 @@ static inline void desc48_get_service(const uint8_t *p_desc,
psz_service[*p] = '\0'; psz_service[*p] = '\0';
} }
static inline void desc48_print(const uint8_t *p_desc, f_print pf_print,
void *opaque)
{
DESC_DECLARE_STRING1(psz_provider);
DESC_DECLARE_STRING1(psz_service);
desc48_get_provider(p_desc, psz_provider);
desc48_get_service(p_desc, psz_service);
pf_print(opaque, " - desc 48 provider=%s service=%s", psz_provider,
psz_service);
}
/***************************************************************************** /*****************************************************************************
* Descriptor 0x56: Teletext descriptor * Descriptor 0x56: Teletext descriptor
*****************************************************************************/ *****************************************************************************/
...@@ -95,12 +115,14 @@ static inline void desc56_init(uint8_t *p_desc) ...@@ -95,12 +115,14 @@ static inline void desc56_init(uint8_t *p_desc)
static inline uint8_t *desc56_get_language(uint8_t *p_desc, uint8_t n) static inline uint8_t *desc56_get_language(uint8_t *p_desc, uint8_t n)
{ {
uint8_t *p_desc_n = p_desc + DESC56_HEADER_SIZE + n * DESC56_LANGUAGE_SIZE; uint8_t *p_desc_n = p_desc + DESC56_HEADER_SIZE + n * DESC56_LANGUAGE_SIZE;
if (p_desc_n - p_desc > desc_get_length(p_desc) + DESC56_HEADER_SIZE) if (p_desc_n + DESC56_LANGUAGE_SIZE - p_desc
> desc_get_length(p_desc) + DESC56_HEADER_SIZE)
return NULL; return NULL;
return p_desc_n; return p_desc_n;
} }
#define desc56n_set_code desc0an_set_code #define desc56n_set_code desc0an_set_code
#define desc56n_get_code desc0an_get_code
static inline void desc56n_set_teletexttype(uint8_t *p_desc_n, uint8_t i_type) static inline void desc56n_set_teletexttype(uint8_t *p_desc_n, uint8_t i_type)
{ {
...@@ -108,6 +130,11 @@ static inline void desc56n_set_teletexttype(uint8_t *p_desc_n, uint8_t i_type) ...@@ -108,6 +130,11 @@ static inline void desc56n_set_teletexttype(uint8_t *p_desc_n, uint8_t i_type)
p_desc_n[3] |= (i_type << 3) & 0xfc; p_desc_n[3] |= (i_type << 3) & 0xfc;
} }
static inline uint8_t desc56n_get_teletexttype(const uint8_t *p_desc_n)
{
return p_desc_n[3] >> 3;
}
static inline void desc56n_set_teletextmagazine(uint8_t *p_desc_n, static inline void desc56n_set_teletextmagazine(uint8_t *p_desc_n,
uint8_t i_magazine) uint8_t i_magazine)
{ {
...@@ -115,11 +142,38 @@ static inline void desc56n_set_teletextmagazine(uint8_t *p_desc_n, ...@@ -115,11 +142,38 @@ static inline void desc56n_set_teletextmagazine(uint8_t *p_desc_n,
p_desc_n[3] |= (i_magazine & 0x3); p_desc_n[3] |= (i_magazine & 0x3);
} }
static inline uint8_t desc56n_get_teletextmagazine(const uint8_t *p_desc_n)
{
return p_desc_n[3] & 0x3;
}
static inline void desc56n_set_teletextpage(uint8_t *p_desc_n, uint8_t i_page) static inline void desc56n_set_teletextpage(uint8_t *p_desc_n, uint8_t i_page)
{ {
p_desc_n[4] = i_page; p_desc_n[4] = i_page;
} }
static inline uint8_t desc56n_get_teletextpage(const uint8_t *p_desc_n)
{
return p_desc_n[4];
}
static inline void desc56_print(uint8_t *p_desc, f_print pf_print,
void *opaque)
{
uint8_t j = 0;
uint8_t *p_desc_n;
while ((p_desc_n = desc56_get_language(p_desc, j)) != NULL) {
j++;
pf_print(opaque,
" - desc 56 telx language=%3.3s type=%hhu mag=%hhu page=%hhu",
(const char *)desc56n_get_code(p_desc_n),
desc56n_get_teletexttype(p_desc_n),
desc56n_get_teletextmagazine(p_desc_n),
desc56n_get_teletextpage(p_desc_n));
}
}
/***************************************************************************** /*****************************************************************************
* Descriptor 0x59: Subtitling descriptor * Descriptor 0x59: Subtitling descriptor
*****************************************************************************/ *****************************************************************************/
...@@ -134,18 +188,25 @@ static inline void desc59_init(uint8_t *p_desc) ...@@ -134,18 +188,25 @@ static inline void desc59_init(uint8_t *p_desc)
static inline uint8_t *desc59_get_language(uint8_t *p_desc, uint8_t n) static inline uint8_t *desc59_get_language(uint8_t *p_desc, uint8_t n)
{ {
uint8_t *p_desc_n = p_desc + DESC59_HEADER_SIZE + n * DESC59_LANGUAGE_SIZE; uint8_t *p_desc_n = p_desc + DESC59_HEADER_SIZE + n * DESC59_LANGUAGE_SIZE;
if (p_desc_n - p_desc > desc_get_length(p_desc) + DESC59_HEADER_SIZE) if (p_desc_n + DESC59_LANGUAGE_SIZE - p_desc
> desc_get_length(p_desc) + DESC59_HEADER_SIZE)
return NULL; return NULL;
return p_desc_n; return p_desc_n;
} }
#define desc59n_set_code desc0an_set_code #define desc59n_set_code desc0an_set_code
#define desc59n_get_code desc0an_get_code
static inline void desc59n_set_subtitlingtype(uint8_t *p_desc_n, uint8_t i_type) static inline void desc59n_set_subtitlingtype(uint8_t *p_desc_n, uint8_t i_type)
{ {
p_desc_n[3] = i_type; p_desc_n[3] = i_type;
} }
static inline uint8_t desc59n_get_subtitlingtype(const uint8_t *p_desc_n)
{
return p_desc_n[3];
}
static inline void desc59n_set_compositionpage(uint8_t *p_desc_n, static inline void desc59n_set_compositionpage(uint8_t *p_desc_n,
uint16_t i_page) uint16_t i_page)
{ {
...@@ -153,12 +214,39 @@ static inline void desc59n_set_compositionpage(uint8_t *p_desc_n, ...@@ -153,12 +214,39 @@ static inline void desc59n_set_compositionpage(uint8_t *p_desc_n,
p_desc_n[5] = i_page & 0xff; p_desc_n[5] = i_page & 0xff;
} }
static inline uint16_t desc59n_get_compositionpage(const uint8_t *p_desc_n)
{
return (p_desc_n[4] << 8) | p_desc_n[5];
}
static inline void desc59n_set_ancillarypage(uint8_t *p_desc_n, uint16_t i_page) static inline void desc59n_set_ancillarypage(uint8_t *p_desc_n, uint16_t i_page)
{ {
p_desc_n[6] = i_page >> 8; p_desc_n[6] = i_page >> 8;
p_desc_n[7] = i_page & 0xff; p_desc_n[7] = i_page & 0xff;
} }
static inline uint16_t desc59n_get_ancillarypage(const uint8_t *p_desc_n)
{
return (p_desc_n[6] << 8) | p_desc_n[7];
}
static inline void desc59_print(uint8_t *p_desc, f_print pf_print,
void *opaque)
{
uint8_t j = 0;
uint8_t *p_desc_n;
while ((p_desc_n = desc59_get_language(p_desc, j)) != NULL) {
j++;
pf_print(opaque,
" - desc 59 dvbs language=%3.3s type=%hhu composition=%hu ancillary=%hu",
(const char *)desc59n_get_code(p_desc_n),
desc59n_get_subtitlingtype(p_desc_n),
desc59n_get_compositionpage(p_desc_n),
desc59n_get_ancillarypage(p_desc_n));
}
}
/***************************************************************************** /*****************************************************************************
* Descriptor 0x6a: AC-3 descriptor * Descriptor 0x6a: AC-3 descriptor
*****************************************************************************/ *****************************************************************************/
...@@ -174,6 +262,12 @@ static inline void desc6a_clear_flags(uint8_t *p_desc) ...@@ -174,6 +262,12 @@ static inline void desc6a_clear_flags(uint8_t *p_desc)
p_desc[2] = 0; p_desc[2] = 0;
} }
static inline void desc6a_print(const uint8_t *p_desc, f_print pf_print,
void *opaque)
{
pf_print(opaque, " - desc 6a ac3");
}
/***************************************************************************** /*****************************************************************************
* Network Information Table * Network Information Table
*****************************************************************************/ *****************************************************************************/
...@@ -337,6 +431,53 @@ static inline bool nit_validate(const uint8_t *p_nit) ...@@ -337,6 +431,53 @@ static inline bool nit_validate(const uint8_t *p_nit)
return (p_nit_n - p_nit == i_section_size); return (p_nit_n - p_nit == i_section_size);
} }
static inline uint8_t *nit_table_find_ts(uint8_t **pp_sections,
uint16_t i_tsid, uint16_t i_onid)
{
uint8_t i_last_section = psi_table_get_lastsection(pp_sections);
uint8_t i;
for (i = 0; i <= i_last_section; i++) {
uint8_t *p_section = psi_table_get_section(pp_sections, i);
uint8_t *p_ts;
int j = 0;
while ((p_ts = nit_get_ts(p_section, j)) != NULL) {
j++;
if (nitn_get_tsid(p_ts) == i_tsid && nitn_get_onid(p_ts) == i_onid)
return p_ts;
}
}
return NULL;
}
static inline bool nit_table_validate(uint8_t **pp_sections)
{
uint8_t i_last_section = psi_table_get_lastsection(pp_sections);
uint8_t i;
for (i = 0; i <= i_last_section; i++) {
uint8_t *p_section = psi_table_get_section(pp_sections, i);
uint8_t *p_ts;
int j = 0;
if (!psi_check_crc(p_section))
return false;
while ((p_ts = nit_get_ts(p_section, j)) != NULL) {
j++;
/* check that the program number if not already in the table */
if (nit_table_find_ts(pp_sections, nitn_get_tsid(p_ts),
nitn_get_onid(p_ts)) != p_ts)
return false;
}
}
return true;
}
/***************************************************************************** /*****************************************************************************
* Service Description Table * Service Description Table
*****************************************************************************/ *****************************************************************************/
...@@ -508,6 +649,23 @@ static inline uint8_t *sdt_table_find_service(uint8_t **pp_sections, ...@@ -508,6 +649,23 @@ static inline uint8_t *sdt_table_find_service(uint8_t **pp_sections,
return NULL; return NULL;
} }
static inline bool sdt_table_validate(uint8_t **pp_sections)
{
uint8_t i_last_section = psi_table_get_lastsection(pp_sections);
uint8_t i;
for (i = 0; i <= i_last_section; i++) {
uint8_t *p_section = psi_table_get_section(pp_sections, i);
uint8_t *p_ts;
int j = 0;
if (!psi_check_crc(p_section))
return false;
}
return true;
}
/***************************************************************************** /*****************************************************************************
* Event Information Table * Event Information Table
*****************************************************************************/ *****************************************************************************/
...@@ -569,6 +727,9 @@ static inline bool eit_validate(const uint8_t *p_eit) ...@@ -569,6 +727,9 @@ static inline bool eit_validate(const uint8_t *p_eit)
&& i_tid <= EIT_TABLE_ID_SCHED_OTHER_LAST))) && i_tid <= EIT_TABLE_ID_SCHED_OTHER_LAST)))
return false; return false;
if (!psi_check_crc(p_eit))
return false;
p_eit_n = p_eit + EIT_HEADER_SIZE; p_eit_n = p_eit + EIT_HEADER_SIZE;
while (p_eit_n + EIT_EVENT_SIZE - p_eit <= i_section_size while (p_eit_n + EIT_EVENT_SIZE - p_eit <= i_section_size
......
This diff is collapsed.
/*****************************************************************************
* psi_print.h: ISO/IEC 13818-1 Program Stream Information (printing)
*****************************************************************************
* Copyright (C) 2010 VideoLAN
* $Id: psi_print.h -1 $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*****************************************************************************/
/*
* Placed here for dependancy reasons
*/
#ifndef __BITSTREAM_MPEG_PSI_PRINT_H__
#define __BITSTREAM_MPEG_PSI_PRINT_H__
#include <bitstream/common.h>
#include <bitstream/mpeg/psi.h>
#include <bitstream/dvb/si.h>
#ifdef __cplusplus
extern "C"
{
#endif
/*****************************************************************************
* Descriptors list
*****************************************************************************/
static inline void descs_print(uint8_t *p_descs, f_print pf_print, void *opaque)
{
uint16_t j = 0;
uint8_t *p_desc;
while ((p_desc = descs_get_desc(p_descs, j)) != NULL) {
j++;
/* I am not proud of this */
switch (desc_get_tag(p_desc)) {
case 0x05:
desc05_print(p_desc, pf_print, opaque);
break;
case 0x09:
desc09_print(p_desc, pf_print, opaque);
break;
case 0x0a:
desc0a_print(p_desc, pf_print, opaque);
break;
case 0x40:
desc40_print(p_desc, pf_print, opaque);
break;
case 0x48:
desc48_print(p_desc, pf_print, opaque);
break;
case 0x56:
desc56_print(p_desc, pf_print, opaque);
break;
case 0x59:
desc59_print(p_desc, pf_print, opaque);
break;
case 0x6a:
desc6a_print(p_desc, pf_print, opaque);
break;
default:
desc_print(p_desc, pf_print, opaque);
break;
}
}
}
/*****************************************************************************
* Program Map Table
*****************************************************************************/
static inline void pmt_print(uint8_t *p_pmt, f_print pf_print, void *opaque)
{
uint8_t *p_es;
uint8_t j = 0;
pf_print(opaque, "new PMT program=%hu version=%hhu pcrpid=%hu",
pmt_get_program(p_pmt), psi_get_version(p_pmt),
pmt_get_pcrpid(p_pmt));
descs_print(pmt_get_descs(p_pmt), pf_print, opaque);
while ((p_es = pmt_get_es(p_pmt, j)) != NULL) {
j++;
pf_print(opaque, " * ES pid=%hu streamtype=0x%hx", pmtn_get_pid(p_es),
pmtn_get_streamtype(p_es));
descs_print(pmtn_get_descs(p_es), pf_print, opaque);
}
pf_print(opaque, "end PMT");
}
/*****************************************************************************
* Network Information Table
*****************************************************************************/
static inline void nit_table_print(uint8_t **pp_sections, f_print pf_print,
void *opaque)
{
uint8_t i_last_section = psi_table_get_lastsection(pp_sections);
uint8_t i;
pf_print(opaque, "new NIT %s networkid=%hu version=%hhu",
psi_table_get_tableid(pp_sections) == NIT_TABLE_ID_ACTUAL ?
"actual" : "other",
psi_table_get_tableidext(pp_sections),
psi_table_get_version(pp_sections));
descs_print(nit_get_descs(psi_table_get_section(pp_sections, 0)),
pf_print, opaque);
for (i = 0; i <= i_last_section; i++) {
uint8_t *p_section = psi_table_get_section(pp_sections, i);
const uint8_t *p_ts;
int j = 0;
while ((p_ts = nit_get_ts(p_section, j)) != NULL) {
j++;
pf_print(opaque, " * ts tsid=%hu onid=%hu",
nitn_get_tsid(p_ts), nitn_get_onid(p_ts));
descs_print(nitn_get_descs(p_ts), pf_print, opaque);
}
}
pf_print(opaque, "end NIT");
}
/*****************************************************************************
* Service Description Table
*****************************************************************************/
static inline void sdt_table_print(uint8_t **pp_sections, f_print pf_print,
void *opaque)
{
uint8_t i_last_section = psi_table_get_lastsection(pp_sections);
uint8_t i;
pf_print(opaque, "new SDT %s tsid=%hu version=%hhu onid=%hu",
psi_table_get_tableid(pp_sections) == SDT_TABLE_ID_ACTUAL ?
"actual" : "other",
psi_table_get_tableidext(pp_sections),
psi_table_get_version(pp_sections),
sdt_get_onid(psi_table_get_section(pp_sections, 0)));
for (i = 0; i <= i_last_section; i++) {
uint8_t *p_section = psi_table_get_section(pp_sections, i);
const uint8_t *p_service;
int j = 0;
while ((p_service = sdt_get_service(p_section, j)) != NULL) {
j++;
pf_print(opaque, " * service sid=%hu eit%s%s running=%hhu%s",
sdtn_get_sid(p_service),
sdtn_get_eitschedule(p_service) ? " schedule" : "",
sdtn_get_eitpresent(p_service) ? " present" : "",
sdtn_get_running(p_service),
sdtn_get_ca(p_service) ? " scrambled" : "");
descs_print(sdtn_get_descs(p_service), pf_print, opaque);
}
}
pf_print(opaque, "end SDT");
}
#ifdef __cplusplus
}
#endif
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment