Commit 5f2425ad authored by Jean-Paul Saman's avatar Jean-Paul Saman

ATSC EIT: implement as chained decoder

parent f359d18b
......@@ -39,7 +39,7 @@ Decode PSIP Virtual Channel Table.
#include "../dvbpsi_private.h"
#include "../psi.h"
#include "../descriptor.h"
#include "../demux.h"
#include "../chain.h"
#include "atsc_eit.h"
......@@ -70,7 +70,7 @@ static dvbpsi_descriptor_t *dvbpsi_atsc_EITChannelAddDescriptor(
uint8_t *p_data);
static void dvbpsi_atsc_GatherEITSections(dvbpsi_t* p_dvbpsi,
dvbpsi_decoder_t* p_decoder, dvbpsi_psi_section_t* p_section);
dvbpsi_psi_section_t* p_section);
static void dvbpsi_atsc_DecodeEITSections(dvbpsi_atsc_eit_t* p_eit,
dvbpsi_psi_section_t* p_section);
......@@ -84,11 +84,9 @@ bool dvbpsi_atsc_AttachEIT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
dvbpsi_atsc_eit_callback pf_callback, void* p_cb_data)
{
assert(p_dvbpsi);
assert(p_dvbpsi->p_decoder);
dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
dvbpsi_decoder_t *p_dec = dvbpsi_decoder_chain_get(p_dvbpsi, i_table_id, i_extension);
if (p_dec != NULL)
{
dvbpsi_error(p_dvbpsi, "ATSC EIT decoder",
"Already a decoder for (table_id == 0x%02x extension == 0x%04x)",
......@@ -97,28 +95,25 @@ bool dvbpsi_atsc_AttachEIT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
}
dvbpsi_atsc_eit_decoder_t* p_eit_decoder;
p_eit_decoder = (dvbpsi_atsc_eit_decoder_t*) dvbpsi_decoder_new(NULL,
0, true, sizeof(dvbpsi_atsc_eit_decoder_t));
p_eit_decoder = (dvbpsi_atsc_eit_decoder_t*) dvbpsi_decoder_new(dvbpsi_atsc_GatherEITSections,
4096, true, 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, DVBPSI_DECODER(p_eit_decoder));
if (p_subdec == NULL)
{
dvbpsi_decoder_delete(DVBPSI_DECODER(p_eit_decoder));
return false;
}
/* Attach the subtable decoder to the demux */
dvbpsi_AttachDemuxSubDecoder(p_demux, p_subdec);
/* EIT decoder information */
p_eit_decoder->pf_eit_callback = pf_callback;
p_eit_decoder->p_cb_data = p_cb_data;
p_eit_decoder->p_building_eit = NULL;
p_eit_decoder->i_table_id = i_table_id;
p_eit_decoder->i_extension = i_extension;
/* add decoder to decoder chain */
if (!dvbpsi_decoder_chain_add(p_dvbpsi, DVBPSI_DECODER(p_eit_decoder)))
{
dvbpsi_decoder_delete(DVBPSI_DECODER(p_eit_decoder));
return false;
}
return true;
}
......@@ -130,12 +125,9 @@ bool dvbpsi_atsc_AttachEIT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
void dvbpsi_atsc_DetachEIT(dvbpsi_t * p_dvbpsi, uint8_t i_table_id, uint16_t i_extension)
{
assert(p_dvbpsi);
assert(p_dvbpsi->p_decoder);
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
if (p_subdec == NULL)
dvbpsi_decoder_t *p_dec = dvbpsi_decoder_chain_get(p_dvbpsi, i_table_id, i_extension);
if (p_dec == NULL)
{
dvbpsi_error(p_dvbpsi, "ATSC EIT Decoder",
"No such EIT decoder (table_id == 0x%02x,"
......@@ -144,17 +136,22 @@ void dvbpsi_atsc_DetachEIT(dvbpsi_t * p_dvbpsi, uint8_t i_table_id, uint16_t i_e
return;
}
dvbpsi_atsc_eit_decoder_t* p_eit_decoder;
p_eit_decoder = (dvbpsi_atsc_eit_decoder_t*)p_subdec->p_decoder;
if (!p_eit_decoder)
/* Remove table decoder from decoder chain */
if (!dvbpsi_decoder_chain_remove(p_dvbpsi, p_dec))
{
dvbpsi_error(p_dvbpsi, "ATSC EIT Decoder",
"Failed to remove"
"extension == 0x%02x)",
i_table_id, i_extension);
return;
}
dvbpsi_atsc_eit_decoder_t *p_eit_decoder = (dvbpsi_atsc_eit_decoder_t*)p_dec;
if (p_eit_decoder->p_building_eit)
dvbpsi_atsc_DeleteEIT(p_eit_decoder->p_building_eit);
p_eit_decoder->p_building_eit = NULL;
dvbpsi_DetachDemuxSubDecoder(p_demux, p_subdec);
dvbpsi_DeleteDemuxSubDecoder(p_subdec);
dvbpsi_decoder_delete(p_dec);
p_dec = NULL;
}
/*****************************************************************************
......@@ -379,12 +376,10 @@ static bool dvbpsi_AddSectionEIT(dvbpsi_t *p_dvbpsi, dvbpsi_atsc_eit_decoder_t *
*****************************************************************************
* Callback for the subtable demultiplexor.
*****************************************************************************/
static void dvbpsi_atsc_GatherEITSections(dvbpsi_t * p_dvbpsi,
dvbpsi_decoder_t *p_decoder,
dvbpsi_psi_section_t * p_section)
static void dvbpsi_atsc_GatherEITSections(dvbpsi_t *p_dvbpsi,
dvbpsi_psi_section_t *p_section)
{
assert(p_dvbpsi);
assert(p_dvbpsi->p_decoder);
if (!dvbpsi_CheckPSISection(p_dvbpsi, p_section, 0xCB, "ATSC EIT decoder"))
{
......@@ -393,21 +388,19 @@ static void dvbpsi_atsc_GatherEITSections(dvbpsi_t * p_dvbpsi,
}
/* We have a valid EIT section */
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
dvbpsi_atsc_eit_decoder_t *p_eit_decoder = (dvbpsi_atsc_eit_decoder_t*)p_decoder;
if (!p_eit_decoder)
dvbpsi_decoder_t *p_dec = dvbpsi_decoder_chain_get(p_dvbpsi, p_section->i_table_id, p_section->i_extension);
if (!p_dec)
{
dvbpsi_error(p_dvbpsi, "ATSC EIT decoder", "No decoder specified");
dvbpsi_DeletePSISections(p_section);
return;
}
/* TS discontinuity check */
if (p_demux->b_discontinuity)
dvbpsi_atsc_eit_decoder_t *p_eit_decoder = (dvbpsi_atsc_eit_decoder_t*)p_dec;
if (p_eit_decoder->b_discontinuity)
{
dvbpsi_ReInitEIT(p_eit_decoder, true);
p_eit_decoder->b_discontinuity = false;
p_demux->b_discontinuity = false;
}
else
{
......
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