Commit 2d3fb64a authored by Jean-Paul Saman's avatar Jean-Paul Saman

demux: use new utility functions.

Use new utility functions to replace common code blocks. Moving
code to demux.c instead of repeating them in the subtable functions.
This reduces the amount of code in subtable files and reduces the risk
of introducing errors in future for this code.
parent 7beb890c
......@@ -92,8 +92,6 @@ bool dvbpsi_atsc_AttachEIT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
assert(p_dvbpsi->p_private);
dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_atsc_eit_decoder_t* p_eit_decoder;
if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
{
......@@ -103,26 +101,22 @@ bool dvbpsi_atsc_AttachEIT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
return false;
}
p_subdec = (dvbpsi_demux_subdec_t*)malloc(sizeof(dvbpsi_demux_subdec_t));
if (p_subdec == NULL)
return false;
dvbpsi_atsc_eit_decoder_t* p_eit_decoder;
p_eit_decoder = (dvbpsi_atsc_eit_decoder_t*)malloc(sizeof(dvbpsi_atsc_eit_decoder_t));
if (p_eit_decoder == NULL)
return false;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_atsc_DetachEIT,
dvbpsi_atsc_GatherEITSections, p_eit_decoder);
if (p_subdec == NULL)
{
free(p_subdec);
free(p_eit_decoder);
return false;
}
/* subtable decoder configuration */
p_subdec->pf_gather = &dvbpsi_atsc_GatherEITSections;
p_subdec->p_cb_data = p_eit_decoder;
p_subdec->i_id = ((uint32_t)i_table_id << 16) | i_extension;
p_subdec->pf_detach = dvbpsi_atsc_DetachEIT;
/* Attach the subtable decoder to the demux */
p_subdec->p_next = p_demux->p_first_subdec;
p_demux->p_first_subdec = p_subdec;
dvbpsi_AttachDemuxSubDecoder(p_demux, p_subdec);
/* EIT decoder information */
p_eit_decoder->pf_eit_callback = pf_callback;
......@@ -148,8 +142,6 @@ void dvbpsi_atsc_DetachEIT(dvbpsi_t * p_dvbpsi, uint8_t i_table_id, uint16_t i_e
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_demux_subdec_t** pp_prev_subdec;
p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
if (p_subdec == NULL)
{
......@@ -175,13 +167,10 @@ void dvbpsi_atsc_DetachEIT(dvbpsi_t * p_dvbpsi, uint8_t i_table_id, uint16_t i_e
}
free(p_subdec->p_cb_data);
p_subdec->p_cb_data = NULL;
pp_prev_subdec = &p_demux->p_first_subdec;
while(*pp_prev_subdec != p_subdec)
pp_prev_subdec = &(*pp_prev_subdec)->p_next;
*pp_prev_subdec = p_subdec->p_next;
free(p_subdec);
dvbpsi_DetachDemuxSubDecoder(p_demux, p_subdec);
dvbpsi_DeleteDemuxSubDecoder(p_subdec);
}
/*****************************************************************************
......
......@@ -99,8 +99,6 @@ bool dvbpsi_atsc_AttachETT(dvbpsi_t * p_dvbpsi, uint8_t i_table_id, uint16_t i_e
assert(p_dvbpsi->p_private);
dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_atsc_ett_decoder_t* p_ett_decoder;
if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
{
......@@ -110,26 +108,23 @@ bool dvbpsi_atsc_AttachETT(dvbpsi_t * p_dvbpsi, uint8_t i_table_id, uint16_t i_e
return false;
}
p_subdec = (dvbpsi_demux_subdec_t*)malloc(sizeof(dvbpsi_demux_subdec_t));
if(p_subdec == NULL)
dvbpsi_atsc_ett_decoder_t* p_ett_decoder;
p_ett_decoder = (dvbpsi_atsc_ett_decoder_t*)malloc(sizeof(dvbpsi_atsc_ett_decoder_t));
if (p_ett_decoder == NULL)
return false;
p_ett_decoder = (dvbpsi_atsc_ett_decoder_t*)malloc(sizeof(dvbpsi_atsc_ett_decoder_t));
if(p_ett_decoder == NULL)
/* PSI decoder configuration */
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_atsc_DetachETT,
dvbpsi_atsc_GatherETTSections, p_ett_decoder);
if (p_subdec == NULL)
{
free(p_subdec);
free(p_ett_decoder);
return false;
}
/* PSI decoder configuration */
p_subdec->pf_gather = &dvbpsi_atsc_GatherETTSections;
p_subdec->p_cb_data = p_ett_decoder;
p_subdec->i_id = ((uint32_t)i_table_id << 16) | i_extension;
p_subdec->pf_detach = dvbpsi_atsc_DetachETT;
/* Attach the subtable decoder to the demux */
p_subdec->p_next = p_demux->p_first_subdec;
p_demux->p_first_subdec = p_subdec;
dvbpsi_AttachDemuxSubDecoder(p_demux, p_subdec);
/* ETT decoder information */
p_ett_decoder->pf_ett_callback = pf_callback;
......@@ -150,9 +145,7 @@ void dvbpsi_atsc_DetachETT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
assert(p_dvbpsi->p_private);
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_demux_subdec_t** pp_prev_subdec;
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_private;
p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
if (p_subdec == NULL)
{
......@@ -176,13 +169,10 @@ void dvbpsi_atsc_DetachETT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
}
free(p_subdec->p_cb_data);
p_subdec->p_cb_data = NULL;
pp_prev_subdec = &p_demux->p_first_subdec;
while(*pp_prev_subdec != p_subdec)
pp_prev_subdec = &(*pp_prev_subdec)->p_next;
*pp_prev_subdec = p_subdec->p_next;
free(p_subdec);
dvbpsi_DetachDemuxSubDecoder(p_demux, p_subdec);
dvbpsi_DeleteDemuxSubDecoder(p_subdec);
}
/*****************************************************************************
......
......@@ -96,7 +96,6 @@ bool dvbpsi_atsc_AttachMGT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
assert(p_dvbpsi->p_private);
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_private;
dvbpsi_demux_subdec_t *p_subdec;
if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
{
......@@ -106,27 +105,22 @@ bool dvbpsi_atsc_AttachMGT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
return false;
}
p_subdec = (dvbpsi_demux_subdec_t*)malloc(sizeof(dvbpsi_demux_subdec_t));
if (p_subdec == NULL)
return false;
dvbpsi_atsc_mgt_decoder_t* p_mgt_decoder;
p_mgt_decoder = (dvbpsi_atsc_mgt_decoder_t*)malloc(sizeof(dvbpsi_atsc_mgt_decoder_t));
if(p_mgt_decoder == NULL)
return false;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_atsc_DetachMGT,
dvbpsi_atsc_GatherMGTSections, p_mgt_decoder);
if (p_subdec == NULL)
{
free(p_subdec);
free(p_mgt_decoder);
return false;
}
/* subtable decoder configuration */
p_subdec->pf_gather = &dvbpsi_atsc_GatherMGTSections;
p_subdec->p_cb_data = p_mgt_decoder;
p_subdec->i_id = ((uint32_t)i_table_id << 16) | i_extension;
p_subdec->pf_detach = dvbpsi_atsc_DetachMGT;
/* Attach the subtable decoder to the demux */
p_subdec->p_next = p_demux->p_first_subdec;
p_demux->p_first_subdec = p_subdec;
dvbpsi_AttachDemuxSubDecoder(p_demux, p_subdec);
/* MGT decoder information */
p_mgt_decoder->pf_mgt_callback = pf_callback;
......@@ -150,10 +144,9 @@ void dvbpsi_atsc_DetachMGT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
assert(p_dvbpsi);
assert(p_dvbpsi->p_private);
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_demux_subdec_t** pp_prev_subdec;
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
if (p_subdec == NULL)
{
......@@ -166,28 +159,23 @@ void dvbpsi_atsc_DetachMGT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
dvbpsi_atsc_mgt_decoder_t* p_mgt_decoder;
p_mgt_decoder = (dvbpsi_atsc_mgt_decoder_t*)p_subdec->p_cb_data;
if(!p_mgt_decoder)
if (!p_mgt_decoder)
return;
if (p_mgt_decoder->p_building_mgt)
{
free(p_mgt_decoder->p_building_mgt);
}
for (unsigned int i = 0; i < 256; i++)
{
if(p_mgt_decoder->ap_sections[i])
if (p_mgt_decoder->ap_sections[i])
dvbpsi_DeletePSISections(p_mgt_decoder->ap_sections[i]);
}
free(p_subdec->p_cb_data);
p_subdec->p_cb_data = NULL;
pp_prev_subdec = &p_demux->p_first_subdec;
while(*pp_prev_subdec != p_subdec)
pp_prev_subdec = &(*pp_prev_subdec)->p_next;
*pp_prev_subdec = p_subdec->p_next;
free(p_subdec);
dvbpsi_DetachDemuxSubDecoder(p_demux, p_subdec);
dvbpsi_DeleteDemuxSubDecoder(p_subdec);
}
/*****************************************************************************
......
......@@ -68,15 +68,13 @@ static void dvbpsi_atsc_DecodeSTTSections(dvbpsi_atsc_stt_t* p_stt,
*****************************************************************************
* Initialize a STT subtable decoder.
*****************************************************************************/
bool dvbpsi_atsc_AttachSTT(dvbpsi_t* p_dvbpsi, uint8_t i_table_id,
bool dvbpsi_atsc_AttachSTT(dvbpsi_t* p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
dvbpsi_atsc_stt_callback pf_stt_callback, void* p_cb_data)
{
assert(p_dvbpsi);
assert(p_dvbpsi->p_private);
dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_atsc_stt_decoder_t* p_stt_decoder;
if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, 0))
{
......@@ -86,26 +84,23 @@ bool dvbpsi_atsc_AttachSTT(dvbpsi_t* p_dvbpsi, uint8_t i_table_id,
return false;
}
p_subdec = (dvbpsi_demux_subdec_t*)malloc(sizeof(dvbpsi_demux_subdec_t));
if(p_subdec == NULL)
dvbpsi_atsc_stt_decoder_t* p_stt_decoder;
p_stt_decoder = (dvbpsi_atsc_stt_decoder_t*)malloc(sizeof(dvbpsi_atsc_stt_decoder_t));
if (p_stt_decoder == NULL)
return false;
p_stt_decoder = (dvbpsi_atsc_stt_decoder_t*)malloc(sizeof(dvbpsi_atsc_stt_decoder_t));
if(p_stt_decoder == NULL)
/* subtable decoder configuration */
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_atsc_DetachSTT,
dvbpsi_atsc_GatherSTTSections, p_stt_decoder);
if (p_subdec == NULL)
{
free(p_subdec);
free(p_stt_decoder);
return false;
}
/* subtable decoder configuration */
p_subdec->pf_gather = &dvbpsi_atsc_GatherSTTSections;
p_subdec->p_cb_data = p_stt_decoder;
p_subdec->i_id = (uint32_t)i_table_id << 16;
p_subdec->pf_detach = dvbpsi_atsc_DetachSTT;
/* Attach the subtable decoder to the demux */
p_subdec->p_next = p_demux->p_first_subdec;
p_demux->p_first_subdec = p_subdec;
dvbpsi_AttachDemuxSubDecoder(p_demux, p_subdec);
/* STT decoder information */
p_stt_decoder->pf_stt_callback = pf_stt_callback;
......@@ -125,10 +120,10 @@ void dvbpsi_atsc_DetachSTT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
assert(p_dvbpsi->p_private);
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_demux_subdec_t** pp_prev_subdec;
p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, 0);
i_extension = 0;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
if (p_subdec == NULL)
{
dvbpsi_error(p_dvbpsi, "STT Decoder",
......@@ -144,13 +139,10 @@ void dvbpsi_atsc_DetachSTT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
return;
free(p_subdec->p_cb_data);
p_subdec->p_cb_data = NULL;
pp_prev_subdec = &p_demux->p_first_subdec;
while(*pp_prev_subdec != p_subdec)
pp_prev_subdec = &(*pp_prev_subdec)->p_next;
*pp_prev_subdec = p_subdec->p_next;
free(p_subdec);
dvbpsi_DetachDemuxSubDecoder(p_demux, p_subdec);
dvbpsi_DeleteDemuxSubDecoder(p_subdec);
}
/*****************************************************************************
......
......@@ -71,11 +71,12 @@ typedef void (* dvbpsi_atsc_stt_callback)(void* p_cb_data, dvbpsi_atsc_stt_t* p_
* \brief Creation and initialization of a STT decoder.
* \param p_dvbpsi dvbpsi handle to Subtable demultiplexor to which the decoder is attached
* \param i_table_id Table ID, 0xCD.
* \param i_extension Table ID extension, here it should be 0.
* \param pf_stt_callback function to call back on new STT.
* \param p_cb_data private data given in argument to the callback.
* \return true if everything went ok else false
*/
bool dvbpsi_atsc_AttachSTT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
bool dvbpsi_atsc_AttachSTT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
dvbpsi_atsc_stt_callback pf_stt_callback, void* p_cb_data);
/*****************************************************************************
......
......@@ -104,8 +104,6 @@ bool dvbpsi_atsc_AttachVCT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
assert(p_dvbpsi->p_private);
dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_atsc_vct_decoder_t* p_vct_decoder;
if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
{
......@@ -116,26 +114,23 @@ bool dvbpsi_atsc_AttachVCT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
return false;
}
p_subdec = (dvbpsi_demux_subdec_t*)calloc(1, sizeof(dvbpsi_demux_subdec_t));
if (p_subdec == NULL)
return false;
dvbpsi_atsc_vct_decoder_t* p_vct_decoder;
p_vct_decoder = (dvbpsi_atsc_vct_decoder_t*)calloc(1, sizeof(dvbpsi_atsc_vct_decoder_t));
if (p_vct_decoder == NULL)
{
free(p_subdec);
return false;
}
/* subtable decoder configuration */
p_subdec->pf_gather = &dvbpsi_atsc_GatherVCTSections;
p_subdec->p_cb_data = p_vct_decoder;
p_subdec->i_id = ((uint32_t)i_table_id << 16) | i_extension;
p_subdec->pf_detach = dvbpsi_atsc_DetachVCT;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_atsc_DetachVCT,
dvbpsi_atsc_GatherVCTSections, p_vct_decoder);
if (p_subdec == NULL)
{
free(p_vct_decoder);
return false;
}
/* Attach the subtable decoder to the demux */
p_subdec->p_next = p_demux->p_first_subdec;
p_demux->p_first_subdec = p_subdec;
dvbpsi_AttachDemuxSubDecoder(p_demux, p_subdec);
/* VCT decoder information */
p_vct_decoder->pf_vct_callback = pf_vct_callback;
......@@ -161,10 +156,8 @@ void dvbpsi_atsc_DetachVCT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
assert(p_dvbpsi->p_private);
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_demux_subdec_t** pp_prev_subdec;
dvbpsi_atsc_vct_decoder_t* p_vct_decoder;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
if(p_subdec == NULL)
{
......@@ -175,25 +168,22 @@ void dvbpsi_atsc_DetachVCT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
return;
}
dvbpsi_atsc_vct_decoder_t* p_vct_decoder;
p_vct_decoder = (dvbpsi_atsc_vct_decoder_t*)p_subdec->p_cb_data;
if(!p_vct_decoder)
if (!p_vct_decoder)
return;
free(p_vct_decoder->p_building_vct);
for(unsigned int i = 0; i < 256; i++)
for (unsigned int i = 0; i < 256; i++)
{
if (p_vct_decoder->ap_sections[i])
dvbpsi_DeletePSISections(p_vct_decoder->ap_sections[i]);
}
free(p_subdec->p_cb_data);
p_subdec->p_cb_data = NULL;
pp_prev_subdec = &p_demux->p_first_subdec;
while(*pp_prev_subdec != p_subdec)
pp_prev_subdec = &(*pp_prev_subdec)->p_next;
*pp_prev_subdec = p_subdec->p_next;
free(p_subdec);
p_subdec = NULL;
dvbpsi_DetachDemuxSubDecoder(p_demux, p_subdec);
dvbpsi_DeleteDemuxSubDecoder(p_subdec);
}
/*****************************************************************************
......
......@@ -62,8 +62,6 @@ bool dvbpsi_AttachBAT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
assert(p_dvbpsi->p_private);
dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_bat_decoder_t* p_bat_decoder;
if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
{
......@@ -74,26 +72,23 @@ bool dvbpsi_AttachBAT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
return false;
}
p_subdec = (dvbpsi_demux_subdec_t*)calloc(1, sizeof(dvbpsi_demux_subdec_t));
if (p_subdec == NULL)
return false;
dvbpsi_bat_decoder_t* p_bat_decoder;
p_bat_decoder = (dvbpsi_bat_decoder_t*)calloc(1, sizeof(dvbpsi_bat_decoder_t));
if (p_bat_decoder == NULL)
{
free(p_subdec);
return false;
}
/* subtable decoder configuration */
p_subdec->pf_gather = &dvbpsi_GatherBATSections;
p_subdec->p_cb_data = p_bat_decoder;
p_subdec->i_id = (uint32_t)i_table_id << 16 | (uint32_t)i_extension;
p_subdec->pf_detach = dvbpsi_DetachBAT;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_DetachBAT,
dvbpsi_GatherBATSections, p_bat_decoder);
if (p_subdec == NULL)
{
free(p_bat_decoder);
return false;
}
/* Attach the subtable decoder to the demux */
p_subdec->p_next = p_demux->p_first_subdec;
p_demux->p_first_subdec = p_subdec;
dvbpsi_AttachDemuxSubDecoder(p_demux, p_subdec);
/* BAT decoder information */
p_bat_decoder->pf_bat_callback = pf_callback;
......@@ -119,10 +114,8 @@ void dvbpsi_DetachBAT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extensi
assert(p_dvbpsi->p_private);
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_demux_subdec_t** pp_prev_subdec;
dvbpsi_bat_decoder_t* p_bat_decoder;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
if (p_subdec == NULL)
{
......@@ -133,6 +126,7 @@ void dvbpsi_DetachBAT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extensi
return;
}
dvbpsi_bat_decoder_t* p_bat_decoder;
p_bat_decoder = (dvbpsi_bat_decoder_t*)p_subdec->p_cb_data;
free(p_bat_decoder->p_building_bat);
......@@ -142,14 +136,10 @@ void dvbpsi_DetachBAT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extensi
dvbpsi_DeletePSISections(p_bat_decoder->ap_sections[i]);
}
free(p_subdec->p_cb_data);
p_subdec->p_cb_data = NULL;
pp_prev_subdec = &p_demux->p_first_subdec;
while(*pp_prev_subdec != p_subdec)
pp_prev_subdec = &(*pp_prev_subdec)->p_next;
*pp_prev_subdec = p_subdec->p_next;
free(p_subdec);
p_subdec = NULL;
dvbpsi_DetachDemuxSubDecoder(p_demux, p_subdec);
dvbpsi_DeleteDemuxSubDecoder(p_subdec);
}
/*****************************************************************************
......
......@@ -61,8 +61,6 @@ bool dvbpsi_AttachEIT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extensi
assert(p_dvbpsi->p_private);
dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_eit_decoder_t* p_eit_decoder;
if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension) != NULL)
{
......@@ -73,26 +71,23 @@ bool dvbpsi_AttachEIT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extensi
return false;
}
p_subdec = (dvbpsi_demux_subdec_t*)calloc(1, sizeof(dvbpsi_demux_subdec_t));
if (p_subdec == NULL)
return false;
dvbpsi_eit_decoder_t* p_eit_decoder;
p_eit_decoder = (dvbpsi_eit_decoder_t*)calloc(1, sizeof(dvbpsi_eit_decoder_t));
if (p_eit_decoder == NULL)
{
free(p_subdec);
return false;
}
/* subtable decoder configuration */
p_subdec->pf_gather = &dvbpsi_GatherEITSections;
p_subdec->p_cb_data = p_eit_decoder;
p_subdec->i_id = (uint32_t)i_table_id << 16 | (uint32_t)i_extension;
p_subdec->pf_detach = dvbpsi_DetachEIT;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_DetachEIT,
dvbpsi_GatherEITSections, p_eit_decoder);
if (p_subdec == NULL)
{
free(p_eit_decoder);
return false;
}
/* Attach the subtable decoder to the demux */
p_subdec->p_next = p_demux->p_first_subdec;
p_demux->p_first_subdec = p_subdec;
dvbpsi_AttachDemuxSubDecoder(p_demux, p_subdec);
/* EIT decoder information */
p_eit_decoder->pf_eit_callback = pf_callback;
......@@ -118,10 +113,8 @@ void dvbpsi_DetachEIT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
assert(p_dvbpsi->p_private);
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_demux_subdec_t** pp_prev_subdec;
dvbpsi_eit_decoder_t* p_eit_decoder;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
if (p_subdec == NULL)
{
......@@ -132,6 +125,7 @@ void dvbpsi_DetachEIT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
return;
}
dvbpsi_eit_decoder_t* p_eit_decoder;
p_eit_decoder = (dvbpsi_eit_decoder_t*)p_subdec->p_cb_data;
free(p_eit_decoder->p_building_eit);
......@@ -141,14 +135,10 @@ void dvbpsi_DetachEIT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
dvbpsi_DeletePSISections(p_eit_decoder->ap_sections[i]);
}
free(p_subdec->p_cb_data);
p_subdec->p_cb_data = NULL;
pp_prev_subdec = &p_demux->p_first_subdec;
while(*pp_prev_subdec != p_subdec)
pp_prev_subdec = &(*pp_prev_subdec)->p_next;
*pp_prev_subdec = p_subdec->p_next;
free(p_subdec);
p_subdec = NULL;
dvbpsi_DetachDemuxSubDecoder(p_demux, p_subdec);
dvbpsi_DeleteDemuxSubDecoder(p_subdec);
}
/*****************************************************************************
......
......@@ -63,8 +63,6 @@ bool dvbpsi_AttachNIT(dvbpsi_t* p_dvbpsi, uint8_t i_table_id,
assert(p_dvbpsi->p_private);
dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_nit_decoder_t* p_nit_decoder;
if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
{
......@@ -75,26 +73,23 @@ bool dvbpsi_AttachNIT(dvbpsi_t* p_dvbpsi, uint8_t i_table_id,
return false;
}
p_subdec = (dvbpsi_demux_subdec_t*)calloc(1, sizeof(dvbpsi_demux_subdec_t));
if (p_subdec == NULL)
return false;
dvbpsi_nit_decoder_t* p_nit_decoder;
p_nit_decoder = (dvbpsi_nit_decoder_t*)calloc(1, sizeof(dvbpsi_nit_decoder_t));
if (p_nit_decoder == NULL)
{
free(p_subdec);
return false;
}
/* subtable decoder configuration */
p_subdec->pf_gather = &dvbpsi_GatherNITSections;
p_subdec->p_cb_data = p_nit_decoder;
p_subdec->i_id = (uint32_t)i_table_id << 16 | (uint32_t)i_extension;
p_subdec->pf_detach = dvbpsi_DetachNIT;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_DetachNIT,
dvbpsi_GatherNITSections, p_nit_decoder);
if (p_subdec == NULL)
{
free(p_nit_decoder);
return false;
}
/* Attach the subtable decoder to the demux */
p_subdec->p_next = p_demux->p_first_subdec;
p_demux->p_first_subdec = p_subdec;
dvbpsi_AttachDemuxSubDecoder(p_demux, p_subdec);
/* NIT decoder information */
p_nit_decoder->i_network_id = i_extension;
......@@ -118,10 +113,8 @@ void dvbpsi_DetachNIT(dvbpsi_t * p_dvbpsi, uint8_t i_table_id,
uint16_t i_extension)
{
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_demux_subdec_t** pp_prev_subdec;
dvbpsi_nit_decoder_t* p_nit_decoder;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
if(p_demux == NULL)
{
......@@ -132,6 +125,7 @@ void dvbpsi_DetachNIT(dvbpsi_t * p_dvbpsi, uint8_t i_table_id,
return;
}
dvbpsi_nit_decoder_t* p_nit_decoder;
p_nit_decoder = (dvbpsi_nit_decoder_t*)p_subdec->p_cb_data;
free(p_nit_decoder->p_building_nit);
......@@ -141,14 +135,11 @@ void dvbpsi_DetachNIT(dvbpsi_t * p_dvbpsi, uint8_t i_table_id,
dvbpsi_DeletePSISections(p_nit_decoder->ap_sections[i]);
}
free(p_subdec->p_cb_data);
p_subdec->p_cb_data = NULL;
pp_prev_subdec = &p_demux->p_first_subdec;
while(*pp_prev_subdec != p_subdec)
pp_prev_subdec = &(*pp_prev_subdec)->p_next;
*pp_prev_subdec = p_subdec->p_next;
free(p_subdec);
p_subdec = NULL;
/* Free demux sub table decoder */
dvbpsi_DetachDemuxSubDecoder(p_demux, p_subdec);
dvbpsi_DeleteDemuxSubDecoder(p_subdec);
}
/****************************************************************************
......
......@@ -60,8 +60,6 @@ bool dvbpsi_AttachSDT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extensi
assert(p_dvbpsi->p_private);
dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_sdt_decoder_t* p_sdt_decoder;
if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
{
......@@ -72,26 +70,23 @@ bool dvbpsi_AttachSDT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extensi
return false;
}
p_subdec = (dvbpsi_demux_subdec_t*)calloc(1, sizeof(dvbpsi_demux_subdec_t));
if(p_subdec == NULL)
return false;
dvbpsi_sdt_decoder_t* p_sdt_decoder;
p_sdt_decoder = (dvbpsi_sdt_decoder_t*)calloc(1, sizeof(dvbpsi_sdt_decoder_t));
if (p_sdt_decoder == NULL)
{
free(p_subdec);
return false;
}
/* subtable decoder configuration */
p_subdec->pf_gather = &dvbpsi_GatherSDTSections;
p_subdec->p_cb_data = p_sdt_decoder;
p_subdec->i_id = (uint32_t)i_table_id << 16 | (uint32_t)i_extension;
p_subdec->pf_detach = &dvbpsi_DetachSDT;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_DetachSDT,
dvbpsi_GatherSDTSections, p_sdt_decoder);
if (p_subdec == NULL)
{
free(p_sdt_decoder);
return false;
}
/* Attach the subtable decoder to the demux */
p_subdec->p_next = p_demux->p_first_subdec;
p_demux->p_first_subdec = p_subdec;
dvbpsi_AttachDemuxSubDecoder(p_demux, p_subdec);
/* SDT decoder information */
p_sdt_decoder->pf_sdt_callback = pf_callback;
......@@ -117,10 +112,8 @@ void dvbpsi_DetachSDT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extensi
assert(p_dvbpsi->p_private);
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_demux_subdec_t** pp_prev_subdec;
dvbpsi_sdt_decoder_t* p_sdt_decoder;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
if (p_subdec == NULL)
{
......@@ -131,6 +124,9 @@ void dvbpsi_DetachSDT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extensi
return;
}
assert(p_subdec->p_cb_data);
dvbpsi_sdt_decoder_t* p_sdt_decoder;
p_sdt_decoder = (dvbpsi_sdt_decoder_t*)p_subdec->p_cb_data;
free(p_sdt_decoder->p_building_sdt);
......@@ -142,15 +138,10 @@ void dvbpsi_DetachSDT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extensi
p_sdt_decoder->ap_sections[i] = NULL;
}
}
free(p_subdec->p_cb_data);
pp_prev_subdec = &p_demux->p_first_subdec;
while(*pp_prev_subdec != p_subdec)
pp_prev_subdec = &(*pp_prev_subdec)->p_next;
*pp_prev_subdec = p_subdec->p_next;
free(p_subdec);
p_subdec = NULL;
/* Free sub table decoder */
dvbpsi_DetachDemuxSubDecoder(p_demux, p_subdec);
dvbpsi_DeleteDemuxSubDecoder(p_subdec);
}
/*****************************************************************************
......@@ -228,7 +219,7 @@ dvbpsi_sdt_service_t *dvbpsi_SDTAddService(dvbpsi_sdt_t* p_sdt,
bool b_free_ca)
{
dvbpsi_sdt_service_t * p_service;
p_service = (dvbpsi_sdt_service_t*)malloc(sizeof(dvbpsi_sdt_service_t));
p_service = (dvbpsi_sdt_service_t*)calloc(1, sizeof(dvbpsi_sdt_service_t));
if (p_service == NULL)
return NULL;
......
......@@ -60,8 +60,6 @@ bool dvbpsi_AttachSIS(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extensi
assert(p_dvbpsi->p_private);
dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_sis_decoder_t* p_sis_decoder;
i_extension = 0;
......@@ -74,26 +72,23 @@ bool dvbpsi_AttachSIS(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extensi
return false;
}
p_subdec = (dvbpsi_demux_subdec_t*)malloc(sizeof(dvbpsi_demux_subdec_t));
if (p_subdec == NULL)
return false;
dvbpsi_sis_decoder_t* p_sis_decoder;
p_sis_decoder = (dvbpsi_sis_decoder_t*)malloc(sizeof(dvbpsi_sis_decoder_t));
if (p_sis_decoder == NULL)
{
free(p_subdec);
return false;
}
/* subtable decoder configuration */
p_subdec->pf_gather = &dvbpsi_GatherSISSections;
p_subdec->p_cb_data = p_sis_decoder;
p_subdec->i_id = (uint32_t)i_table_id << 16 | (uint32_t)i_extension;
p_subdec->pf_detach = dvbpsi_DetachSIS;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_DetachSIS,
dvbpsi_GatherSISSections, p_sis_decoder);
if (p_subdec == NULL)
{
free(p_sis_decoder);
return false;
}
/* Attach the subtable decoder to the demux */
p_subdec->p_next = p_demux->p_first_subdec;
p_demux->p_first_subdec = p_subdec;
dvbpsi_AttachDemuxSubDecoder(p_demux, p_subdec);
/* SIS decoder information */
p_sis_decoder->pf_sis_callback = pf_callback;
......@@ -114,11 +109,9 @@ void dvbpsi_DetachSIS(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
assert(p_dvbpsi->p_private);
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_demux_subdec_t** pp_prev_subdec;
i_extension = 0;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
if (p_demux == NULL)
{
......@@ -129,18 +122,8 @@ void dvbpsi_DetachSIS(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
return;
}
dvbpsi_sis_decoder_t* p_sis_decoder;
p_sis_decoder = (dvbpsi_sis_decoder_t*)p_subdec->p_cb_data;
free(p_sis_decoder);
p_subdec->p_cb_data = NULL;
pp_prev_subdec = &p_demux->p_first_subdec;
while(*pp_prev_subdec != p_subdec)
pp_prev_subdec = &(*pp_prev_subdec)->p_next;
*pp_prev_subdec = p_subdec->p_next;
free(p_subdec);
p_subdec = NULL;
dvbpsi_DetachDemuxSubDecoder(p_demux, p_subdec);
dvbpsi_DeleteDemuxSubDecoder(p_subdec);
}
/*****************************************************************************
......
......@@ -56,14 +56,12 @@
* Initialize a TDT/TOT subtable decoder.
*****************************************************************************/
bool dvbpsi_AttachTOT(dvbpsi_t* p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
dvbpsi_tot_callback pf_callback, void* p_cb_data)
dvbpsi_tot_callback pf_callback, void* p_cb_data)
{
assert(p_dvbpsi);
assert(p_dvbpsi->p_private);
dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_tot_decoder_t* p_tot_decoder;
i_extension = 0; /* NOTE: force to 0 when handling TDT/TOT */
if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
......@@ -75,26 +73,23 @@ bool dvbpsi_AttachTOT(dvbpsi_t* p_dvbpsi, uint8_t i_table_id, uint16_t i_extensi
return false;
}
p_subdec = (dvbpsi_demux_subdec_t*)calloc(1, sizeof(dvbpsi_demux_subdec_t));
if(p_subdec == NULL)
return false;
dvbpsi_tot_decoder_t* p_tot_decoder;
p_tot_decoder = (dvbpsi_tot_decoder_t*)calloc(1, sizeof(dvbpsi_tot_decoder_t));
if (p_tot_decoder == NULL)
{
free(p_subdec);
return false;
}
/* subtable decoder configuration */
p_subdec->pf_gather = &dvbpsi_GatherTOTSections;
p_subdec->p_cb_data = p_tot_decoder;
p_subdec->i_id = (uint32_t)i_table_id << 16 | (uint32_t)0;
p_subdec->pf_detach = dvbpsi_DetachTOT;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_DetachTOT,
dvbpsi_GatherTOTSections, p_tot_decoder);
if (p_subdec == NULL)
{
free(p_tot_decoder);
return false;
}
/* Attach the subtable decoder to the demux */
p_subdec->p_next = p_demux->p_first_subdec;
p_demux->p_first_subdec = p_subdec;
dvbpsi_AttachDemuxSubDecoder(p_demux, p_subdec);
/* TDT/TOT decoder information */
p_tot_decoder->pf_tot_callback = pf_callback;
......@@ -116,7 +111,6 @@ void dvbpsi_DetachTOT(dvbpsi_t* p_dvbpsi, uint8_t i_table_id,
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *)p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_demux_subdec_t** pp_prev_subdec;
i_extension = 0; /* NOTE: force to 0 when handling TDT/TOT */
p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
......@@ -129,15 +123,8 @@ void dvbpsi_DetachTOT(dvbpsi_t* p_dvbpsi, uint8_t i_table_id,
return;
}
free(p_subdec->p_cb_data);
pp_prev_subdec = &p_demux->p_first_subdec;
while(*pp_prev_subdec != p_subdec)
pp_prev_subdec = &(*pp_prev_subdec)->p_next;
*pp_prev_subdec = p_subdec->p_next;
free(p_subdec);
p_subdec = NULL;
dvbpsi_DetachDemuxSubDecoder(p_demux, p_subdec);
dvbpsi_DeleteDemuxSubDecoder(p_subdec);
}
/*****************************************************************************
......
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