Commit 58e54473 authored by Jean-Paul Saman's avatar Jean-Paul Saman

SDT: rework dvbpsi_GatherSDTSections

parent fa575f15
...@@ -271,42 +271,41 @@ dvbpsi_descriptor_t *dvbpsi_SDTServiceAddDescriptor( ...@@ -271,42 +271,41 @@ dvbpsi_descriptor_t *dvbpsi_SDTServiceAddDescriptor(
return p_descriptor; return p_descriptor;
} }
/***************************************************************************** /* */
* dvbpsi_GatherSDTSections static void dvbpsi_ReInitSDT(dvbpsi_sdt_decoder_t* p_decoder, const bool b_force)
*****************************************************************************
* Callback for the subtable demultiplexor.
*****************************************************************************/
void dvbpsi_GatherSDTSections(dvbpsi_t *p_dvbpsi,
dvbpsi_decoder_t *p_private_decoder,
dvbpsi_psi_section_t * p_section)
{ {
assert(p_dvbpsi); assert(p_decoder);
assert(p_dvbpsi->p_private);
if (!dvbpsi_CheckPSISection(p_dvbpsi, p_section, 0x42, "SDT decoder")) /* Force redecoding */
if (b_force)
{ {
dvbpsi_DeletePSISections(p_section); p_decoder->b_current_valid = false;
return;
/* Free structures */
if (p_decoder->p_building_sdt)
free(p_decoder->p_building_sdt);
} }
p_decoder->p_building_sdt = NULL;
/* */ /* Clear the section array */
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *)p_dvbpsi->p_private; for (unsigned int i = 0; i <= 255; i++)
dvbpsi_sdt_decoder_t *p_sdt_decoder {
= (dvbpsi_sdt_decoder_t*)p_private_decoder; if (p_decoder->ap_sections[i] != NULL)
{
dvbpsi_DeletePSISections(p_decoder->ap_sections[i]);
p_decoder->ap_sections[i] = NULL;
}
}
}
static bool dvbpsi_CheckSDT(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section)
{
bool b_reinit = false; bool b_reinit = false;
assert(p_dvbpsi->p_private);
dvbpsi_sdt_decoder_t* p_sdt_decoder;
p_sdt_decoder = (dvbpsi_sdt_decoder_t *)p_dvbpsi->p_private;
/* TS discontinuity check */
if (p_demux->b_discontinuity)
{
b_reinit = true;
p_demux->b_discontinuity = false;
}
else
{
/* Perform a few sanity checks */
if (p_sdt_decoder->p_building_sdt)
{
if (p_sdt_decoder->p_building_sdt->i_ts_id != p_section->i_extension) if (p_sdt_decoder->p_building_sdt->i_ts_id != p_section->i_extension)
{ {
/* transport_stream_id */ /* transport_stream_id */
...@@ -331,59 +330,44 @@ void dvbpsi_GatherSDTSections(dvbpsi_t *p_dvbpsi, ...@@ -331,59 +330,44 @@ void dvbpsi_GatherSDTSections(dvbpsi_t *p_dvbpsi,
" whereas no discontinuity has occured"); " whereas no discontinuity has occured");
b_reinit = true; b_reinit = true;
} }
}
else
{
if( (p_sdt_decoder->b_current_valid)
&& (p_sdt_decoder->current_sdt.i_version == p_section->i_version)
&& (p_sdt_decoder->current_sdt.b_current_next == p_section->b_current_next))
{
/* Don't decode since this version is already decoded */
dvbpsi_DeletePSISections(p_section);
return;
}
}
}
/* Reinit the decoder if wanted */ return b_reinit;
if (b_reinit) }
{
/* Force redecoding */ static bool dvbpsi_IsCompleteSDT(dvbpsi_sdt_decoder_t* p_sdt_decoder)
p_sdt_decoder->b_current_valid = false; {
/* Free structures */ assert(p_sdt_decoder);
if (p_sdt_decoder->p_building_sdt)
{ bool b_complete = false;
free(p_sdt_decoder->p_building_sdt);
p_sdt_decoder->p_building_sdt = NULL; for (unsigned int i = 0; i <= p_sdt_decoder->i_last_section_number; i++)
}
/* Clear the section array */
for (unsigned int i = 0; i <= 255; i++)
{
if (p_sdt_decoder->ap_sections[i] != NULL)
{ {
dvbpsi_DeletePSISections(p_sdt_decoder->ap_sections[i]); if (!p_sdt_decoder->ap_sections[i])
p_sdt_decoder->ap_sections[i] = NULL; break;
} if (i == p_sdt_decoder->i_last_section_number)
} b_complete = true;
} }
return b_complete;
}
static bool dvbpsi_AddSectionSDT(dvbpsi_t *p_dvbpsi, dvbpsi_sdt_decoder_t *p_sdt_decoder,
dvbpsi_psi_section_t* p_section)
{
assert(p_dvbpsi);
assert(p_sdt_decoder);
assert(p_section);
/* Initialize the structures if it's the first section received */ /* Initialize the structures if it's the first section received */
if (!p_sdt_decoder->p_building_sdt) if (!p_sdt_decoder->p_building_sdt)
{ {
p_sdt_decoder->p_building_sdt = (dvbpsi_sdt_t*)calloc(1, sizeof(dvbpsi_sdt_t)); p_sdt_decoder->p_building_sdt = dvbpsi_NewSDT(p_section->i_extension,
if (p_sdt_decoder->p_building_sdt) p_section->i_version, p_section->b_current_next,
{
dvbpsi_InitSDT(p_sdt_decoder->p_building_sdt,
p_section->i_extension,
p_section->i_version,
p_section->b_current_next,
((uint16_t)(p_section->p_payload_start[0]) << 8) ((uint16_t)(p_section->p_payload_start[0]) << 8)
| p_section->p_payload_start[1]); | p_section->p_payload_start[1]);
if (p_sdt_decoder->p_building_sdt == NULL)
return false;
p_sdt_decoder->i_last_section_number = p_section->i_last_number; p_sdt_decoder->i_last_section_number = p_section->i_last_number;
} }
else
dvbpsi_debug(p_dvbpsi, "SDT decoder", "failed decoding section");
}
/* Fill the section array */ /* Fill the section array */
if (p_sdt_decoder->ap_sections[p_section->i_number] != NULL) if (p_sdt_decoder->ap_sections[p_section->i_number] != NULL)
...@@ -394,19 +378,74 @@ void dvbpsi_GatherSDTSections(dvbpsi_t *p_dvbpsi, ...@@ -394,19 +378,74 @@ void dvbpsi_GatherSDTSections(dvbpsi_t *p_dvbpsi,
} }
p_sdt_decoder->ap_sections[p_section->i_number] = p_section; p_sdt_decoder->ap_sections[p_section->i_number] = p_section;
/* Check if we have all the sections */ return true;
bool b_complete = false; }
for (unsigned int i = 0; i <= p_sdt_decoder->i_last_section_number; i++)
/*****************************************************************************
* dvbpsi_GatherSDTSections
*****************************************************************************
* Callback for the subtable demultiplexor.
*****************************************************************************/
void dvbpsi_GatherSDTSections(dvbpsi_t *p_dvbpsi,
dvbpsi_decoder_t *p_private_decoder,
dvbpsi_psi_section_t * p_section)
{
assert(p_dvbpsi);
assert(p_dvbpsi->p_private);
if (!dvbpsi_CheckPSISection(p_dvbpsi, p_section, 0x42, "SDT decoder"))
{ {
if (!p_sdt_decoder->ap_sections[i]) dvbpsi_DeletePSISections(p_section);
break; return;
}
if (i == p_sdt_decoder->i_last_section_number) /* We have a valid SDT section */
b_complete = true; dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *)p_dvbpsi->p_private;
dvbpsi_sdt_decoder_t *p_sdt_decoder
= (dvbpsi_sdt_decoder_t*)p_private_decoder;
/* TS discontinuity check */
if (p_demux->b_discontinuity)
{
dvbpsi_ReInitSDT(p_sdt_decoder, true);
p_sdt_decoder->b_discontinuity = false;
p_demux->b_discontinuity = false;
}
else
{
/* Perform a few sanity checks */
if (p_sdt_decoder->p_building_sdt)
{
if (dvbpsi_CheckSDT(p_dvbpsi, p_section))
dvbpsi_ReInitSDT(p_sdt_decoder, true);
}
else
{
if( (p_sdt_decoder->b_current_valid)
&& (p_sdt_decoder->current_sdt.i_version == p_section->i_version)
&& (p_sdt_decoder->current_sdt.b_current_next == p_section->b_current_next))
{
/* Don't decode since this version is already decoded */
dvbpsi_DeletePSISections(p_section);
return;
}
}
} }
if (b_complete) /* Add section to SDT */
if (!dvbpsi_AddSectionSDT(p_dvbpsi, p_sdt_decoder, p_section))
{ {
dvbpsi_error(p_dvbpsi, "SDT decoder", "failed decoding section %d",
p_section->i_number);
dvbpsi_DeletePSISections(p_section);
return;
}
/* Check if we have all the sections */
if (dvbpsi_IsCompleteSDT(p_sdt_decoder))
{
assert(p_sdt_decoder->pf_sdt_callback);
/* Save the current information */ /* Save the current information */
p_sdt_decoder->current_sdt = *p_sdt_decoder->p_building_sdt; p_sdt_decoder->current_sdt = *p_sdt_decoder->p_building_sdt;
p_sdt_decoder->b_current_valid = true; p_sdt_decoder->b_current_valid = true;
...@@ -426,9 +465,7 @@ void dvbpsi_GatherSDTSections(dvbpsi_t *p_dvbpsi, ...@@ -426,9 +465,7 @@ void dvbpsi_GatherSDTSections(dvbpsi_t *p_dvbpsi,
p_sdt_decoder->pf_sdt_callback(p_sdt_decoder->p_cb_data, p_sdt_decoder->pf_sdt_callback(p_sdt_decoder->p_cb_data,
p_sdt_decoder->p_building_sdt); p_sdt_decoder->p_building_sdt);
/* Reinitialize the structures */ /* Reinitialize the structures */
p_sdt_decoder->p_building_sdt = NULL; dvbpsi_ReInitSDT(p_sdt_decoder, false);
for (unsigned int i = 0; i <= p_sdt_decoder->i_last_section_number; i++)
p_sdt_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