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

src/table/pat*: Cleanup

- Use bool for structure members that are used as bools
- Indentation
parent 4fc878e7
/***************************************************************************** /*****************************************************************************
* pat.c: PAT decoder/generator * pat.c: PAT decoder/generator
*---------------------------------------------------------------------------- *----------------------------------------------------------------------------
* Copyright (C) 2001-2010 VideoLAN * Copyright (C) 2001-2011 VideoLAN
* $Id$ * $Id$
* *
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
...@@ -66,7 +66,7 @@ bool dvbpsi_AttachPAT(dvbpsi_t *p_dvbpsi, dvbpsi_pat_callback pf_callback, ...@@ -66,7 +66,7 @@ bool dvbpsi_AttachPAT(dvbpsi_t *p_dvbpsi, dvbpsi_pat_callback pf_callback,
/* PSI decoder initial state */ /* PSI decoder initial state */
p_pat_decoder->i_continuity_counter = 31; p_pat_decoder->i_continuity_counter = 31;
p_pat_decoder->b_discontinuity = 1; p_pat_decoder->b_discontinuity = true;
p_pat_decoder->p_current_section = NULL; p_pat_decoder->p_current_section = NULL;
/* PAT decoder information */ /* PAT decoder information */
...@@ -74,7 +74,7 @@ bool dvbpsi_AttachPAT(dvbpsi_t *p_dvbpsi, dvbpsi_pat_callback pf_callback, ...@@ -74,7 +74,7 @@ bool dvbpsi_AttachPAT(dvbpsi_t *p_dvbpsi, dvbpsi_pat_callback pf_callback,
p_pat_decoder->p_cb_data = p_cb_data; p_pat_decoder->p_cb_data = p_cb_data;
/* PAT decoder initial state */ /* PAT decoder initial state */
p_pat_decoder->b_current_valid = 0; p_pat_decoder->b_current_valid = false;
p_pat_decoder->p_building_pat = NULL; p_pat_decoder->p_building_pat = NULL;
for(unsigned int i = 0; i <= 255; i++) for(unsigned int i = 0; i <= 255; i++)
...@@ -110,7 +110,6 @@ void dvbpsi_DetachPAT(dvbpsi_t *p_dvbpsi) ...@@ -110,7 +110,6 @@ void dvbpsi_DetachPAT(dvbpsi_t *p_dvbpsi)
p_dvbpsi->p_private = NULL; p_dvbpsi->p_private = NULL;
} }
/***************************************************************************** /*****************************************************************************
* dvbpsi_InitPAT * dvbpsi_InitPAT
***************************************************************************** *****************************************************************************
...@@ -125,7 +124,6 @@ void dvbpsi_InitPAT(dvbpsi_pat_t* p_pat, uint16_t i_ts_id, uint8_t i_version, ...@@ -125,7 +124,6 @@ void dvbpsi_InitPAT(dvbpsi_pat_t* p_pat, uint16_t i_ts_id, uint8_t i_version,
p_pat->p_first_program = NULL; p_pat->p_first_program = NULL;
} }
/***************************************************************************** /*****************************************************************************
* dvbpsi_EmptyPAT * dvbpsi_EmptyPAT
***************************************************************************** *****************************************************************************
...@@ -144,7 +142,6 @@ void dvbpsi_EmptyPAT(dvbpsi_pat_t* p_pat) ...@@ -144,7 +142,6 @@ void dvbpsi_EmptyPAT(dvbpsi_pat_t* p_pat)
p_pat->p_first_program = NULL; p_pat->p_first_program = NULL;
} }
/***************************************************************************** /*****************************************************************************
* dvbpsi_PATAddProgram * dvbpsi_PATAddProgram
***************************************************************************** *****************************************************************************
...@@ -176,7 +173,6 @@ dvbpsi_pat_program_t* dvbpsi_PATAddProgram(dvbpsi_pat_t* p_pat, ...@@ -176,7 +173,6 @@ dvbpsi_pat_program_t* dvbpsi_PATAddProgram(dvbpsi_pat_t* p_pat,
return p_program; return p_program;
} }
/***************************************************************************** /*****************************************************************************
* dvbpsi_GatherPATSections * dvbpsi_GatherPATSections
***************************************************************************** *****************************************************************************
...@@ -185,59 +181,58 @@ dvbpsi_pat_program_t* dvbpsi_PATAddProgram(dvbpsi_pat_t* p_pat, ...@@ -185,59 +181,58 @@ dvbpsi_pat_program_t* dvbpsi_PATAddProgram(dvbpsi_pat_t* p_pat,
void dvbpsi_GatherPATSections(dvbpsi_t* p_dvbpsi, dvbpsi_psi_section_t* p_section) void dvbpsi_GatherPATSections(dvbpsi_t* p_dvbpsi, dvbpsi_psi_section_t* p_section)
{ {
dvbpsi_pat_decoder_t* p_pat_decoder; dvbpsi_pat_decoder_t* p_pat_decoder;
int b_append = 1; bool b_reinit = false;
int b_reinit = 0;
assert(p_dvbpsi); assert(p_dvbpsi);
assert(p_dvbpsi->p_private); assert(p_dvbpsi->p_private);
dvbpsi_debug(p_dvbpsi, "PAT decoder", if (p_section->i_table_id != 0x00)
"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);
p_pat_decoder = (dvbpsi_pat_decoder_t *)p_dvbpsi->p_private;
if(p_section->i_table_id != 0x00)
{ {
/* Invalid table_id value */ /* Invalid table_id value */
dvbpsi_error(p_dvbpsi, "PAT decoder", dvbpsi_error(p_dvbpsi, "PAT decoder",
"invalid section (table_id == 0x%02x)", "invalid section (table_id == 0x%02x)",
p_section->i_table_id); 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 */ /* Invalid section_syntax_indicator */
dvbpsi_error(p_dvbpsi, "PAT decoder", dvbpsi_error(p_dvbpsi, "PAT decoder",
"invalid section (section_syntax_indicator == 0)"); "invalid section (section_syntax_indicator == 0)");
b_append = 0; dvbpsi_DeletePSISections(p_section);
return;
} }
/* Now if b_append is true then we have a valid PAT section */ /* Now we have a valid PAT section */
if(b_append) dvbpsi_debug(p_dvbpsi, "PAT decoder",
{ "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);
p_pat_decoder = (dvbpsi_pat_decoder_t *)p_dvbpsi->p_private;
/* TS discontinuity check */ /* TS discontinuity check */
if(p_pat_decoder->b_discontinuity) if (p_pat_decoder->b_discontinuity)
{ {
b_reinit = 1; b_reinit = true;
p_pat_decoder->b_discontinuity = 0; p_pat_decoder->b_discontinuity = false;
} }
else else
{ {
/* Perform a few sanity checks */ /* Perform a few sanity checks */
if(p_pat_decoder->p_building_pat) if (p_pat_decoder->p_building_pat)
{ {
if(p_pat_decoder->p_building_pat->i_ts_id != p_section->i_extension) if (p_pat_decoder->p_building_pat->i_ts_id != p_section->i_extension)
{ {
/* transport_stream_id */ /* transport_stream_id */
dvbpsi_error(p_dvbpsi, "PAT decoder", dvbpsi_error(p_dvbpsi, "PAT decoder",
"'transport_stream_id' differs" "'transport_stream_id' differs"
" whereas no TS discontinuity has occured"); " whereas no TS discontinuity has occured");
b_reinit = 1; b_reinit = true;
} }
else if(p_pat_decoder->p_building_pat->i_version else if(p_pat_decoder->p_building_pat->i_version
!= p_section->i_version) != p_section->i_version)
...@@ -246,7 +241,7 @@ void dvbpsi_GatherPATSections(dvbpsi_t* p_dvbpsi, dvbpsi_psi_section_t* p_sectio ...@@ -246,7 +241,7 @@ void dvbpsi_GatherPATSections(dvbpsi_t* p_dvbpsi, dvbpsi_psi_section_t* p_sectio
dvbpsi_error(p_dvbpsi, "PAT decoder", dvbpsi_error(p_dvbpsi, "PAT decoder",
"'version_number' differs" "'version_number' differs"
" whereas no discontinuity has occured"); " whereas no discontinuity has occured");
b_reinit = 1; b_reinit = true;
} }
else if(p_pat_decoder->i_last_section_number != else if(p_pat_decoder->i_last_section_number !=
p_section->i_last_number) p_section->i_last_number)
...@@ -255,7 +250,7 @@ void dvbpsi_GatherPATSections(dvbpsi_t* p_dvbpsi, dvbpsi_psi_section_t* p_sectio ...@@ -255,7 +250,7 @@ void dvbpsi_GatherPATSections(dvbpsi_t* p_dvbpsi, dvbpsi_psi_section_t* p_sectio
dvbpsi_error(p_dvbpsi, "PAT decoder", dvbpsi_error(p_dvbpsi, "PAT decoder",
"'last_section_number' differs" "'last_section_number' differs"
" whereas no discontinuity has occured"); " whereas no discontinuity has occured");
b_reinit = 1; b_reinit = true;
} }
} }
else else
...@@ -266,27 +261,30 @@ void dvbpsi_GatherPATSections(dvbpsi_t* p_dvbpsi, dvbpsi_psi_section_t* p_sectio ...@@ -266,27 +261,30 @@ void dvbpsi_GatherPATSections(dvbpsi_t* p_dvbpsi, dvbpsi_psi_section_t* p_sectio
p_section->b_current_next)) p_section->b_current_next))
{ {
/* Don't decode since this version is already decoded */ /* Don't decode since this version is already decoded */
b_append = 0; dvbpsi_debug(p_dvbpsi, "PAT decoder",
} "ignoring already decoded section %d",
p_section->i_number);
dvbpsi_DeletePSISections(p_section);
return;
} }
} }
} }
/* Reinit the decoder if wanted */ /* Reinit the decoder if wanted */
if(b_reinit) if (b_reinit)
{ {
/* Force redecoding */ /* Force redecoding */
p_pat_decoder->b_current_valid = 0; p_pat_decoder->b_current_valid = false;
/* Free structures */ /* Free structures */
if(p_pat_decoder->p_building_pat) if (p_pat_decoder->p_building_pat)
{ {
free(p_pat_decoder->p_building_pat); free(p_pat_decoder->p_building_pat);
p_pat_decoder->p_building_pat = NULL; p_pat_decoder->p_building_pat = NULL;
} }
/* Clear the section array */ /* Clear the section array */
for(unsigned int i = 0; i <= 255; i++) for (unsigned int i = 0; i <= 255; i++)
{ {
if(p_pat_decoder->ap_sections[i] != NULL) if (p_pat_decoder->ap_sections[i] != NULL)
{ {
dvbpsi_DeletePSISections(p_pat_decoder->ap_sections[i]); dvbpsi_DeletePSISections(p_pat_decoder->ap_sections[i]);
p_pat_decoder->ap_sections[i] = NULL; p_pat_decoder->ap_sections[i] = NULL;
...@@ -294,29 +292,29 @@ void dvbpsi_GatherPATSections(dvbpsi_t* p_dvbpsi, dvbpsi_psi_section_t* p_sectio ...@@ -294,29 +292,29 @@ void dvbpsi_GatherPATSections(dvbpsi_t* p_dvbpsi, dvbpsi_psi_section_t* p_sectio
} }
} }
/* Append the section to the list if wanted */ /* Append the section to the list */
if(b_append) bool b_complete = false;
{
int b_complete;
/* Initialize the structures if it's the first section received */ /* Initialize the structures if it's the first section received */
if(!p_pat_decoder->p_building_pat) if (!p_pat_decoder->p_building_pat)
{ {
p_pat_decoder->p_building_pat = p_pat_decoder->p_building_pat =
(dvbpsi_pat_t*)malloc(sizeof(dvbpsi_pat_t)); (dvbpsi_pat_t*)malloc(sizeof(dvbpsi_pat_t));
if (p_pat_decoder->p_building_pat) if (p_pat_decoder->p_building_pat == NULL)
dvbpsi_InitPAT(p_pat_decoder->p_building_pat, {
p_section->i_extension, dvbpsi_error(p_dvbpsi, "PAT decoder", "failed decoding section %d",
p_section->i_version, p_section->i_number);
p_section->b_current_next); dvbpsi_DeletePSISections(p_section);
else return;
dvbpsi_error(p_dvbpsi, "PAT decoder", "failed decoding section" ); }
dvbpsi_InitPAT(p_pat_decoder->p_building_pat, p_section->i_extension,
p_section->i_version, p_section->b_current_next);
p_pat_decoder->i_last_section_number = p_section->i_last_number; p_pat_decoder->i_last_section_number = p_section->i_last_number;
} }
/* Fill the section array */ /* Fill the section array */
if(p_pat_decoder->ap_sections[p_section->i_number] != NULL) if (p_pat_decoder->ap_sections[p_section->i_number] != NULL)
{ {
dvbpsi_debug(p_dvbpsi, "PAT decoder", "overwrite section number %d", dvbpsi_debug(p_dvbpsi, "PAT decoder", "overwrite section number %d",
p_section->i_number); p_section->i_number);
...@@ -325,25 +323,23 @@ void dvbpsi_GatherPATSections(dvbpsi_t* p_dvbpsi, dvbpsi_psi_section_t* p_sectio ...@@ -325,25 +323,23 @@ void dvbpsi_GatherPATSections(dvbpsi_t* p_dvbpsi, dvbpsi_psi_section_t* p_sectio
p_pat_decoder->ap_sections[p_section->i_number] = p_section; p_pat_decoder->ap_sections[p_section->i_number] = p_section;
/* Check if we have all the sections */ /* Check if we have all the sections */
b_complete = 0; for (unsigned int i = 0; i <= p_pat_decoder->i_last_section_number; i++)
for(unsigned int i = 0; i <= p_pat_decoder->i_last_section_number; i++)
{ {
if(!p_pat_decoder->ap_sections[i]) if (!p_pat_decoder->ap_sections[i])
break; break;
if (i == p_pat_decoder->i_last_section_number)
if(i == p_pat_decoder->i_last_section_number) b_complete = true;
b_complete = 1;
} }
if(b_complete) if (b_complete)
{ {
/* Save the current information */ /* Save the current information */
p_pat_decoder->current_pat = *p_pat_decoder->p_building_pat; p_pat_decoder->current_pat = *p_pat_decoder->p_building_pat;
p_pat_decoder->b_current_valid = 1; p_pat_decoder->b_current_valid = true;
/* Chain the sections */ /* Chain the sections */
if(p_pat_decoder->i_last_section_number) if (p_pat_decoder->i_last_section_number)
{ {
for(unsigned int i = 0; (int)i <= p_pat_decoder->i_last_section_number - 1; i++) for (unsigned int i = 0; (int)i <= p_pat_decoder->i_last_section_number - 1; i++)
p_pat_decoder->ap_sections[i]->p_next = p_pat_decoder->ap_sections[i]->p_next =
p_pat_decoder->ap_sections[i + 1]; p_pat_decoder->ap_sections[i + 1];
} }
...@@ -357,17 +353,11 @@ void dvbpsi_GatherPATSections(dvbpsi_t* p_dvbpsi, dvbpsi_psi_section_t* p_sectio ...@@ -357,17 +353,11 @@ void dvbpsi_GatherPATSections(dvbpsi_t* p_dvbpsi, dvbpsi_psi_section_t* p_sectio
p_pat_decoder->p_building_pat); p_pat_decoder->p_building_pat);
/* Reinitialize the structures */ /* Reinitialize the structures */
p_pat_decoder->p_building_pat = NULL; p_pat_decoder->p_building_pat = NULL;
for(unsigned int i = 0; i <= p_pat_decoder->i_last_section_number; i++) for (unsigned int i = 0; i <= p_pat_decoder->i_last_section_number; i++)
p_pat_decoder->ap_sections[i] = NULL; p_pat_decoder->ap_sections[i] = NULL;
} }
}
else
{
dvbpsi_DeletePSISections(p_section);
}
} }
/***************************************************************************** /*****************************************************************************
* dvbpsi_DecodePATSection * dvbpsi_DecodePATSection
***************************************************************************** *****************************************************************************
......
...@@ -81,7 +81,7 @@ typedef struct dvbpsi_pat_s ...@@ -81,7 +81,7 @@ typedef struct dvbpsi_pat_s
{ {
uint16_t i_ts_id; /*!< transport_stream_id */ uint16_t i_ts_id; /*!< transport_stream_id */
uint8_t i_version; /*!< version_number */ uint8_t i_version; /*!< version_number */
int b_current_next; /*!< current_next_indicator */ bool b_current_next; /*!< current_next_indicator */
dvbpsi_pat_program_t * p_first_program; /*!< program list */ dvbpsi_pat_program_t * p_first_program; /*!< program list */
......
...@@ -43,7 +43,7 @@ typedef struct dvbpsi_pat_decoder_s ...@@ -43,7 +43,7 @@ typedef struct dvbpsi_pat_decoder_s
dvbpsi_pat_t current_pat; dvbpsi_pat_t current_pat;
dvbpsi_pat_t * p_building_pat; dvbpsi_pat_t * p_building_pat;
int b_current_valid; bool b_current_valid;
uint8_t i_last_section_number; uint8_t i_last_section_number;
dvbpsi_psi_section_t * ap_sections [256]; 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