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

src/tables/cat.c: Cleanup

Remove b_append from dvbpsi_GatherCATSections()
parent 9e0d751e
...@@ -166,7 +166,6 @@ void dvbpsi_GatherCATSections(dvbpsi_t *p_dvbpsi, ...@@ -166,7 +166,6 @@ void dvbpsi_GatherCATSections(dvbpsi_t *p_dvbpsi,
dvbpsi_cat_decoder_t* p_cat_decoder dvbpsi_cat_decoder_t* p_cat_decoder
= (dvbpsi_cat_decoder_t*)p_dvbpsi->p_private; = (dvbpsi_cat_decoder_t*)p_dvbpsi->p_private;
bool b_append = true;
bool b_reinit = false; bool b_reinit = false;
if (p_section->i_table_id != 0x01) if (p_section->i_table_id != 0x01)
...@@ -179,7 +178,7 @@ void dvbpsi_GatherCATSections(dvbpsi_t *p_dvbpsi, ...@@ -179,7 +178,7 @@ void dvbpsi_GatherCATSections(dvbpsi_t *p_dvbpsi,
return; 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, "CAT decoder", dvbpsi_error(p_dvbpsi, "CAT decoder",
...@@ -195,49 +194,45 @@ void dvbpsi_GatherCATSections(dvbpsi_t *p_dvbpsi, ...@@ -195,49 +194,45 @@ void dvbpsi_GatherCATSections(dvbpsi_t *p_dvbpsi,
p_section->i_number, p_section->i_last_number, p_section->i_number, p_section->i_last_number,
p_section->b_current_next); p_section->b_current_next);
if (b_append) /* TS discontinuity check */
if (p_cat_decoder->b_discontinuity)
{ {
/* TS discontinuity check */ b_reinit = true;
if (p_cat_decoder->b_discontinuity) p_cat_decoder->b_discontinuity = false;
{ }
b_reinit = true; else
p_cat_decoder->b_discontinuity = false; {
} /* Perform some few sanity checks */
else if (p_cat_decoder->p_building_cat)
{ {
/* Perform some few sanity checks */ if (p_cat_decoder->p_building_cat->i_version != p_section->i_version)
if (p_cat_decoder->p_building_cat)
{ {
if (p_cat_decoder->p_building_cat->i_version != p_section->i_version) /* version_number */
{ dvbpsi_error(p_dvbpsi, "CAT decoder",
/* version_number */
dvbpsi_error(p_dvbpsi, "CAT decoder",
"'version_number' differs" "'version_number' differs"
" whereas no discontinuity has occured"); " whereas no discontinuity has occured");
b_reinit = true; b_reinit = true;
} }
else if (p_cat_decoder->i_last_section_number else if (p_cat_decoder->i_last_section_number != p_section->i_last_number)
!= p_section->i_last_number) {
{ /* last_section_number */
/* last_section_number */ dvbpsi_error(p_dvbpsi, "CAT decoder",
dvbpsi_error(p_dvbpsi, "CAT decoder",
"'last_section_number' differs" "'last_section_number' differs"
" whereas no discontinuity has occured"); " whereas no discontinuity has occured");
b_reinit = true; b_reinit = true;
}
} }
else }
{ else
if ( (p_cat_decoder->b_current_valid) {
&& (p_cat_decoder->current_cat.i_version == p_section->i_version) if ( (p_cat_decoder->b_current_valid)
&& (p_cat_decoder->current_cat.b_current_next == && (p_cat_decoder->current_cat.i_version == p_section->i_version)
&& (p_cat_decoder->current_cat.b_current_next ==
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 */
dvbpsi_DeletePSISections(p_section); dvbpsi_DeletePSISections(p_section);
return; return;
} }
}
} }
} }
...@@ -263,71 +258,63 @@ void dvbpsi_GatherCATSections(dvbpsi_t *p_dvbpsi, ...@@ -263,71 +258,63 @@ void dvbpsi_GatherCATSections(dvbpsi_t *p_dvbpsi,
} }
} }
/* Append the section to the list if wanted */ int b_complete = false;
if (b_append)
{
int b_complete = false;
/* Initialize the structures if it's the first section received */ /* Initialize the structures if it's the first section received */
if (!p_cat_decoder->p_building_cat) if (!p_cat_decoder->p_building_cat)
{ {
p_cat_decoder->p_building_cat = p_cat_decoder->p_building_cat =
(dvbpsi_cat_t*)malloc(sizeof(dvbpsi_cat_t)); (dvbpsi_cat_t*)malloc(sizeof(dvbpsi_cat_t));
if (p_cat_decoder->p_building_cat) if (p_cat_decoder->p_building_cat)
dvbpsi_InitCAT(p_cat_decoder->p_building_cat, dvbpsi_InitCAT(p_cat_decoder->p_building_cat,
p_section->i_version, p_section->b_current_next); p_section->i_version, p_section->b_current_next);
else else
dvbpsi_error(p_dvbpsi, "CAT decoder", "failed decoding section"); dvbpsi_error(p_dvbpsi, "CAT decoder", "failed decoding section");
p_cat_decoder->i_last_section_number = p_section->i_last_number; p_cat_decoder->i_last_section_number = p_section->i_last_number;
} }
/* Fill the section array */ /* Fill the section array */
if (p_cat_decoder->ap_sections[p_section->i_number] != NULL) if (p_cat_decoder->ap_sections[p_section->i_number] != NULL)
{ {
dvbpsi_debug(p_dvbpsi, "CAT decoder", "overwrite section number %d", dvbpsi_debug(p_dvbpsi, "CAT decoder", "overwrite section number %d",
p_section->i_number); p_section->i_number);
dvbpsi_DeletePSISections(p_cat_decoder->ap_sections[p_section->i_number]); dvbpsi_DeletePSISections(p_cat_decoder->ap_sections[p_section->i_number]);
} }
p_cat_decoder->ap_sections[p_section->i_number] = p_section; p_cat_decoder->ap_sections[p_section->i_number] = p_section;
/* Check if we have all the sections */ /* Check if we have all the sections */
for (unsigned int i = 0; i <= p_cat_decoder->i_last_section_number; i++) for (unsigned int i = 0; i <= p_cat_decoder->i_last_section_number; i++)
{ {
if (!p_cat_decoder->ap_sections[i]) if (!p_cat_decoder->ap_sections[i])
break; break;
if (i == p_cat_decoder->i_last_section_number) if (i == p_cat_decoder->i_last_section_number)
b_complete = true; b_complete = true;
} }
if (b_complete) if (b_complete)
{
/* Save the current information */
p_cat_decoder->current_cat = *p_cat_decoder->p_building_cat;
p_cat_decoder->b_current_valid = true;
/* Chain the sections */
if (p_cat_decoder->i_last_section_number)
{ {
/* Save the current information */ for (int i = 0; i <= p_cat_decoder->i_last_section_number - 1; i++)
p_cat_decoder->current_cat = *p_cat_decoder->p_building_cat; p_cat_decoder->ap_sections[i]->p_next = p_cat_decoder->ap_sections[i + 1];
p_cat_decoder->b_current_valid = 1;
/* Chain the sections */
if (p_cat_decoder->i_last_section_number)
{
for (int i = 0; i <= p_cat_decoder->i_last_section_number - 1; i++)
p_cat_decoder->ap_sections[i]->p_next = p_cat_decoder->ap_sections[i + 1];
}
/* Decode the sections */
dvbpsi_DecodeCATSections(p_cat_decoder->p_building_cat,
p_cat_decoder->ap_sections[0]);
/* Delete the sections */
dvbpsi_DeletePSISections(p_cat_decoder->ap_sections[0]);
/* signal the new CAT */
p_cat_decoder->pf_cat_callback(p_cat_decoder->p_cb_data,
p_cat_decoder->p_building_cat);
/* Reinitialize the structures */
p_cat_decoder->p_building_cat = NULL;
for (unsigned int i = 0; i <= p_cat_decoder->i_last_section_number; i++)
p_cat_decoder->ap_sections[i] = NULL;
} }
} /* Decode the sections */
else dvbpsi_DecodeCATSections(p_cat_decoder->p_building_cat,
{ p_cat_decoder->ap_sections[0]);
dvbpsi_DeletePSISections(p_section); /* Delete the sections */
dvbpsi_DeletePSISections(p_cat_decoder->ap_sections[0]);
/* signal the new CAT */
p_cat_decoder->pf_cat_callback(p_cat_decoder->p_cb_data,
p_cat_decoder->p_building_cat);
/* Reinitialize the structures */
p_cat_decoder->p_building_cat = NULL;
for (unsigned int i = 0; i <= p_cat_decoder->i_last_section_number; i++)
p_cat_decoder->ap_sections[i] = NULL;
} }
} }
......
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