Commit b80d45d1 authored by Jean-Paul Saman's avatar Jean-Paul Saman

src/table/nit*: Cleanup

- Use bool for structure members that are used as bools
- Indentation
parent e950dbfb
/*****************************************************************************
* nit.c: NIT decoder/generator
*----------------------------------------------------------------------------
* Copyright (C) 2001-2010 VideoLAN
* Copyright (C) 2001-2011 VideoLAN
* $Id$
*
* Authors: Johann Hanne
......@@ -101,7 +101,7 @@ bool dvbpsi_AttachNIT(dvbpsi_t* p_dvbpsi, uint8_t i_table_id,
p_nit_decoder->pf_nit_callback = pf_callback;
p_nit_decoder->p_cb_data = p_cb_data;
/* NIT decoder initial state */
p_nit_decoder->b_current_valid = 0;
p_nit_decoder->b_current_valid = false;
p_nit_decoder->p_building_nit = NULL;
for (unsigned int i = 0; i <= 255; i++)
p_nit_decoder->ap_sections[i] = NULL;
......@@ -157,7 +157,7 @@ void dvbpsi_DetachNIT(dvbpsi_t * p_dvbpsi, uint8_t i_table_id,
* Initialize a pre-allocated dvbpsi_nit_t structure.
*****************************************************************************/
void dvbpsi_InitNIT(dvbpsi_nit_t* p_nit, uint16_t i_network_id,
uint8_t i_version, int b_current_next)
uint8_t i_version, bool b_current_next)
{
p_nit->i_network_id = i_network_id;
p_nit->i_version = i_version;
......@@ -281,8 +281,8 @@ void dvbpsi_GatherNITSections(dvbpsi_t *p_dvbpsi,
{
dvbpsi_nit_decoder_t* p_nit_decoder
= (dvbpsi_nit_decoder_t*)p_private_decoder;
int b_append = 1;
int b_reinit = 0;
assert(p_dvbpsi);
dvbpsi_debug(p_dvbpsi, "NIT decoder",
"Table version %2d, " "i_extension %5d, "
......@@ -297,66 +297,68 @@ void dvbpsi_GatherNITSections(dvbpsi_t *p_dvbpsi,
dvbpsi_error(p_dvbpsi, "NIT decoder",
"invalid section (table_id == 0x%02x)",
p_section->i_table_id);
b_append = 0;
dvbpsi_DeletePSISections(p_section);
return;
}
if (b_append && !p_section->b_syntax_indicator)
if (!p_section->b_syntax_indicator)
{
/* Invalid section_syntax_indicator */
dvbpsi_error(p_dvbpsi, "NIT decoder",
"invalid section (section_syntax_indicator == 0)");
b_append = 0;
"invalid section (section_syntax_indicator == false)");
dvbpsi_DeletePSISections(p_section);
return;
}
/* Now if b_append is true then we have a valid NIT section */
if (b_append && (p_nit_decoder->i_network_id != p_section->i_extension))
if (p_nit_decoder->i_network_id != p_section->i_extension)
{
/* Invalid program_number */
dvbpsi_error(p_dvbpsi, "NIT decoder", "'network_id' don't match");
b_append = 0;
dvbpsi_DeletePSISections(p_section);
return;
}
if (b_append)
bool b_reinit = false;
/* TS discontinuity check */
if (p_nit_decoder->b_discontinuity)
{
/* TS discontinuity check */
if (p_nit_decoder->b_discontinuity)
{
b_reinit = 1;
p_nit_decoder->b_discontinuity = false;
}
else
b_reinit = true;
p_nit_decoder->b_discontinuity = false;
}
else
{
/* Perform some few sanity checks */
if (p_nit_decoder->p_building_nit)
{
/* Perform some few sanity checks */
if (p_nit_decoder->p_building_nit)
if (p_nit_decoder->p_building_nit->i_version != p_section->i_version)
{
if (p_nit_decoder->p_building_nit->i_version != p_section->i_version)
{
/* version_number */
dvbpsi_error(p_dvbpsi, "NIT decoder",
/* version_number */
dvbpsi_error(p_dvbpsi, "NIT decoder",
"'version_number' differs"
" whereas no discontinuity has occured");
b_reinit = 1;
}
else if (p_nit_decoder->i_last_section_number
!= p_section->i_last_number)
{
/* last_section_number */
dvbpsi_error(p_dvbpsi, "NIT decoder",
b_reinit = true;
}
else if (p_nit_decoder->i_last_section_number
!= p_section->i_last_number)
{
/* last_section_number */
dvbpsi_error(p_dvbpsi, "NIT decoder",
"'last_section_number' differs"
" whereas no discontinuity has occured");
b_reinit = 1;
}
b_reinit = true;
}
else
}
else
{
if ( (p_nit_decoder->b_current_valid)
&& (p_nit_decoder->current_nit.i_version == p_section->i_version)
&& (p_nit_decoder->current_nit.b_current_next == p_section->b_current_next))
{
if ( (p_nit_decoder->b_current_valid)
&& (p_nit_decoder->current_nit.i_version == p_section->i_version)
&& (p_nit_decoder->current_nit.b_current_next ==
p_section->b_current_next))
{
/* Don't decode since this version is already decoded */
b_append = 0;
}
/* Don't decode since this version is already decoded */
dvbpsi_DeletePSISections(p_section);
return;;
}
}
}
......@@ -365,7 +367,7 @@ void dvbpsi_GatherNITSections(dvbpsi_t *p_dvbpsi,
if (b_reinit)
{
/* Force redecoding */
p_nit_decoder->b_current_valid = 0;
p_nit_decoder->b_current_valid = false;
/* Free structures */
if(p_nit_decoder->p_building_nit)
{
......@@ -383,73 +385,64 @@ void dvbpsi_GatherNITSections(dvbpsi_t *p_dvbpsi,
}
}
/* Append the section to the list if wanted */
if (b_append)
/* Initialize the structures if it's the first section received */
if (!p_nit_decoder->p_building_nit)
{
int b_complete;
p_nit_decoder->p_building_nit = (dvbpsi_nit_t*)malloc(sizeof(dvbpsi_nit_t));
if (p_nit_decoder->p_building_nit)
dvbpsi_InitNIT(p_nit_decoder->p_building_nit,
p_nit_decoder->i_network_id,
p_section->i_version,
p_section->b_current_next);
else
dvbpsi_debug(p_dvbpsi, "NIT decoder", "failed decoding section");
p_nit_decoder->i_last_section_number = p_section->i_last_number;
}
/* Initialize the structures if it's the first section received */
if (!p_nit_decoder->p_building_nit)
{
p_nit_decoder->p_building_nit = (dvbpsi_nit_t*)malloc(sizeof(dvbpsi_nit_t));
if (p_nit_decoder->p_building_nit)
dvbpsi_InitNIT(p_nit_decoder->p_building_nit,
p_nit_decoder->i_network_id,
p_section->i_version,
p_section->b_current_next);
else
dvbpsi_debug(p_dvbpsi, "NIT decoder", "failed decoding section");
p_nit_decoder->i_last_section_number = p_section->i_last_number;
}
/* Fill the section array */
if (p_nit_decoder->ap_sections[p_section->i_number] != NULL)
{
dvbpsi_debug(p_dvbpsi, "NIT decoder", "overwrite section number %d",
p_section->i_number);
dvbpsi_DeletePSISections(p_nit_decoder->ap_sections[p_section->i_number]);
}
p_nit_decoder->ap_sections[p_section->i_number] = p_section;
/* Fill the section array */
if (p_nit_decoder->ap_sections[p_section->i_number] != NULL)
{
dvbpsi_debug(p_dvbpsi, "NIT decoder", "overwrite section number %d",
p_section->i_number);
dvbpsi_DeletePSISections(p_nit_decoder->ap_sections[p_section->i_number]);
}
p_nit_decoder->ap_sections[p_section->i_number] = p_section;
/* Check if we have all the sections */
bool b_complete = false;
/* Check if we have all the sections */
b_complete = 0;
for (unsigned int i = 0; i <= p_nit_decoder->i_last_section_number; i++)
{
if (!p_nit_decoder->ap_sections[i])
break;
if (i == p_nit_decoder->i_last_section_number)
b_complete = 1;
}
for (unsigned int i = 0; i <= p_nit_decoder->i_last_section_number; i++)
{
if (!p_nit_decoder->ap_sections[i])
break;
if (i == p_nit_decoder->i_last_section_number)
b_complete = true;
}
if (b_complete)
if (b_complete)
{
/* Save the current information */
p_nit_decoder->current_nit = *p_nit_decoder->p_building_nit;
p_nit_decoder->b_current_valid = true;
/* Chain the sections */
if (p_nit_decoder->i_last_section_number)
{
/* Save the current information */
p_nit_decoder->current_nit = *p_nit_decoder->p_building_nit;
p_nit_decoder->b_current_valid = 1;
/* Chain the sections */
if (p_nit_decoder->i_last_section_number)
{
for (unsigned int i = 0; (int)i <= p_nit_decoder->i_last_section_number - 1; i++)
p_nit_decoder->ap_sections[i]->p_next =
p_nit_decoder->ap_sections[i + 1];
}
/* Decode the sections */
dvbpsi_DecodeNITSections(p_dvbpsi, p_nit_decoder->p_building_nit,
p_nit_decoder->ap_sections[0]);
/* Delete the sections */
dvbpsi_DeletePSISections(p_nit_decoder->ap_sections[0]);
/* signal the new NIT */
p_nit_decoder->pf_nit_callback(p_nit_decoder->p_cb_data,
p_nit_decoder->p_building_nit);
/* Reinitialize the structures */
p_nit_decoder->p_building_nit = NULL;
for (unsigned int i = 0; i <= p_nit_decoder->i_last_section_number; i++)
p_nit_decoder->ap_sections[i] = NULL;
for (unsigned int i = 0; (int)i <= p_nit_decoder->i_last_section_number - 1; i++)
p_nit_decoder->ap_sections[i]->p_next =
p_nit_decoder->ap_sections[i + 1];
}
}
else
{
dvbpsi_DeletePSISections(p_section);
/* Decode the sections */
dvbpsi_DecodeNITSections(p_dvbpsi, p_nit_decoder->p_building_nit,
p_nit_decoder->ap_sections[0]);
/* Delete the sections */
dvbpsi_DeletePSISections(p_nit_decoder->ap_sections[0]);
/* signal the new NIT */
p_nit_decoder->pf_nit_callback(p_nit_decoder->p_cb_data,
p_nit_decoder->p_building_nit);
/* Reinitialize the structures */
p_nit_decoder->p_building_nit = NULL;
for (unsigned int i = 0; i <= p_nit_decoder->i_last_section_number; i++)
p_nit_decoder->ap_sections[i] = NULL;
}
}
......@@ -531,8 +524,8 @@ dvbpsi_psi_section_t* dvbpsi_GenNITSections(dvbpsi_t *p_dvbpsi,
uint8_t * p_transport_stream_loop_length;
p_current->i_table_id = i_table_id;
p_current->b_syntax_indicator = 1;
p_current->b_private_indicator = 0;
p_current->b_syntax_indicator = true;
p_current->b_private_indicator = false;
p_current->i_length = 13; /* including CRC_32 */
p_current->i_extension = p_nit->i_network_id;
p_current->i_version = p_nit->i_version;
......@@ -564,8 +557,8 @@ dvbpsi_psi_section_t* dvbpsi_GenNITSections(dvbpsi_t *p_dvbpsi,
p_prev->p_next = p_current;
p_current->i_table_id = i_table_id;
p_current->b_syntax_indicator = 1;
p_current->b_private_indicator = 0;
p_current->b_syntax_indicator = true;
p_current->b_private_indicator = false;
p_current->i_length = 13; /* including CRC_32 */
p_current->i_extension = p_nit->i_network_id;
p_current->i_version = p_nit->i_version;
......@@ -635,8 +628,8 @@ dvbpsi_psi_section_t* dvbpsi_GenNITSections(dvbpsi_t *p_dvbpsi,
p_prev->p_next = p_current;
p_current->i_table_id = i_table_id;
p_current->b_syntax_indicator = 1;
p_current->b_private_indicator = 0;
p_current->b_syntax_indicator = true;
p_current->b_private_indicator = false;
p_current->i_length = 13; /* including CRC_32 */
p_current->i_extension = p_nit->i_network_id;
p_current->i_version = p_nit->i_version;
......
/*****************************************************************************
* nit.h
* Copyright (C) 2001-2010 VideoLAN
* Copyright (C) 2001-2011 VideoLAN
* $Id$
*
* Authors: Johann Hanne
......@@ -84,7 +84,7 @@ typedef struct dvbpsi_nit_s
{
uint16_t i_network_id; /*!< network_id */
uint8_t i_version; /*!< version_number */
int b_current_next; /*!< current_next_indicator */
bool b_current_next; /*!< current_next_indicator */
dvbpsi_descriptor_t * p_first_descriptor; /*!< descriptor list */
......@@ -141,7 +141,7 @@ void dvbpsi_DetachNIT(dvbpsi_t* p_dvbpsi, uint8_t i_table_id,
*****************************************************************************/
/*!
* \fn void dvbpsi_InitNIT(dvbpsi_nit_t* p_nit, uint16_t i_network_id,
uint8_t i_version, int b_current_next)
uint8_t i_version, bool b_current_next)
* \brief Initialize a user-allocated dvbpsi_nit_t structure.
* \param p_nit pointer to the NIT structure
* \param i_network_id network id
......@@ -150,7 +150,7 @@ void dvbpsi_DetachNIT(dvbpsi_t* p_dvbpsi, uint8_t i_table_id,
* \return nothing.
*/
void dvbpsi_InitNIT(dvbpsi_nit_t* p_nit, uint16_t i_network_id,
uint8_t i_version, int b_current_next);
uint8_t i_version, bool b_current_next);
/*!
* \def dvbpsi_NewNIT(p_nit, i_network_id,
......@@ -208,9 +208,9 @@ do { \
* \param p_data descriptor's data
* \return a pointer to the added descriptor.
*/
dvbpsi_descriptor_t* dvbpsi_NITAddDescriptor(dvbpsi_nit_t* p_nit,
dvbpsi_descriptor_t* dvbpsi_NITAddDescriptor(dvbpsi_nit_t *p_nit,
uint8_t i_tag, uint8_t i_length,
uint8_t* p_data);
uint8_t *p_data);
/*****************************************************************************
* dvbpsi_NITAddTS
......
/*****************************************************************************
* nit_private.h: private NIT structures
*----------------------------------------------------------------------------
* Copyright (C) 2001-2010 VideoLAN
* Copyright (C) 2001-2011 VideoLAN
* $Id$
*
* Authors: Johann Hanne
......@@ -47,7 +47,7 @@ typedef struct dvbpsi_nit_decoder_s
dvbpsi_nit_t current_nit;
dvbpsi_nit_t * p_building_nit;
int b_current_valid;
bool b_current_valid;
uint8_t i_last_section_number;
dvbpsi_psi_section_t * ap_sections [256];
......
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