PSI: add dvbpsi_CheckPSISection() utility function
[email protected] (Jean-Paul Saman)
| Newsgroups | gmane.comp.video.videolan.libdvbpsi.devel |
|---|---|
| Message-ID | <[email protected]> |
libdvbpsi | branch: master | Jean-Paul Saman <[email protected]> | Mon Jun 11 14:22:49 2012 +0200| [58617799bd71e106c6c8ec3f5a2118cd2bf236c3] | committer: Jean-Paul Saman PSI: add dvbpsi_CheckPSISection() utility function All PSI table check the same common things before accepting a section as being a valid section. Centralize these checks into a single function. > http://git.videolan.org/gitweb.cgi/libdvbpsi.git/?a=commit;h=58617799bd71e106c6c8ec3f5a2118cd2bf236c3 --- src/psi.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/psi.h | 17 +++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/src/psi.c b/src/psi.c index 821a209..e24492f 100644 --- a/src/psi.c +++ b/src/psi.c @@ -30,6 +30,8 @@ #include <stdlib.h> #include <stdbool.h> +#include <assert.h> + #if defined(HAVE_INTTYPES_H) #include <inttypes.h> #elif defined(HAVE_STDINT_H) @@ -84,6 +86,50 @@ void dvbpsi_DeletePSISections(dvbpsi_psi_section_t *p_section) free(p_section); p_section = p_next; } + p_section = NULL; +} + +/***************************************************************************** + * dvbpsi_CheckPSISection + ***************************************************************************** + * Check if PSI section has the expected table_id and it the syntax indicator + * is true. + *****************************************************************************/ +bool dvbpsi_CheckPSISection(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section, + const uint8_t table_id, const char *psz_table_name) +{ + assert(p_dvbpsi); + assert(p_section); + + if (p_section->i_table_id != table_id) + { + /* Invalid table_id value */ + dvbpsi_error(p_dvbpsi, psz_table_name, + "invalid section (table_id == 0x%02x)", + p_section->i_table_id); + goto error; + } + + if (!p_section->b_syntax_indicator) + { + /* Invalid section_syntax_indicator */ + dvbpsi_error(p_dvbpsi, psz_table_name, + "invalid section (section_syntax_indicator == 0)"); + goto error; + } + + /* FIXME: Do we need to check the CRC for ALL tables? */ + + dvbpsi_debug(p_dvbpsi, psz_table_name, + "Table version %2d, " "i_extension %5d, " + "section %3d up to %3d, " "current %1d", + p_section->i_version, p_section->i_extension, + p_section->i_number, p_section->i_last_number, + p_section->b_current_next); + return true; + +error: + return false; } /***************************************************************************** diff --git a/src/psi.h b/src/psi.h index 62c6ba2..9061030 100644 --- a/src/psi.h +++ b/src/psi.h @@ -119,6 +119,23 @@ dvbpsi_psi_section_t * dvbpsi_NewPSISection(int i_max_size); void dvbpsi_DeletePSISections(dvbpsi_psi_section_t * p_section); /***************************************************************************** + * dvbpsi_CheckPSISection + *****************************************************************************/ +/*! + * \fn bool dvbpsi_CheckPSISection(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section, + const uint8_t table_id, const char *psz_table_name) + * \brief Check if PSI section has the expected table_id and it the syntax indicator + * is true. + * \param p_dvbpsi pointer to dvbpsi library handle + * \param p_section pointer to the PSI section structure + * \param table_id expected table id + * \param psz_table_name table name to use when reporting errors. + * \return boolean value (false if the section did not pass the tests). + */ +bool dvbpsi_CheckPSISection(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section, + const uint8_t table_id, const char *psz_table_name); + +/***************************************************************************** * dvbpsi_ValidPSISection *****************************************************************************/ /*! _______________________________________________ libdvbpsi-devel mailing list [email protected] http://mailman.videolan.org/listinfo/libdvbpsi-devel