Commit 882a4a3a authored by Jean-Paul Saman's avatar Jean-Paul Saman

SDT: implement as chained decoder

parent 925cbbc6
...@@ -43,13 +43,13 @@ ...@@ -43,13 +43,13 @@
#ifdef DVBPSI_DIST #ifdef DVBPSI_DIST
#include "../src/dvbpsi.h" #include "../src/dvbpsi.h"
#include "../src/psi.h" #include "../src/psi.h"
#include "../src/demux.h" #include "../src/chain.h"
#include "../src/descriptor.h" #include "../src/descriptor.h"
#include "../src/tables/sdt.h" #include "../src/tables/sdt.h"
#else #else
#include <dvbpsi/dvbpsi.h> #include <dvbpsi/dvbpsi.h>
#include <dvbpsi/psi.h> #include <dvbpsi/psi.h>
#include <dvbpsi/demux.h> #include <dvbpsi/chain.h>
#include <dvbpsi/descriptor.h> #include <dvbpsi/descriptor.h>
#include <dvbpsi/sdt.h> #include <dvbpsi/sdt.h>
#endif #endif
...@@ -151,12 +151,24 @@ static void NewSubtable(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_exten ...@@ -151,12 +151,24 @@ static void NewSubtable(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_exten
} }
} }
/*****************************************************************************
* DelSubtable
*****************************************************************************/
static void DelSubtable(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension)
{
if(i_table_id == 0x42)
{
dvbpsi_sdt_detach(p_dvbpsi, i_table_id, i_extension);
}
}
/***************************************************************************** /*****************************************************************************
* main * main
*****************************************************************************/ *****************************************************************************/
int main(int i_argc, char* pa_argv[]) int main(int i_argc, char* pa_argv[])
{ {
int i_fd; int i_fd;
int ret = 1;
uint8_t data[188]; uint8_t data[188];
dvbpsi_t *p_dvbpsi; dvbpsi_t *p_dvbpsi;
bool b_ok; bool b_ok;
...@@ -172,7 +184,7 @@ int main(int i_argc, char* pa_argv[]) ...@@ -172,7 +184,7 @@ int main(int i_argc, char* pa_argv[])
if (p_dvbpsi == NULL) if (p_dvbpsi == NULL)
goto out; goto out;
if (!dvbpsi_AttachDemux(p_dvbpsi, NewSubtable, NULL)) if (!dvbpsi_decoder_chain_new(p_dvbpsi, NewSubtable, DelSubtable, NULL))
goto out; goto out;
b_ok = ReadPacket(i_fd, data); b_ok = ReadPacket(i_fd, data);
...@@ -185,13 +197,15 @@ int main(int i_argc, char* pa_argv[]) ...@@ -185,13 +197,15 @@ int main(int i_argc, char* pa_argv[])
b_ok = ReadPacket(i_fd, data); b_ok = ReadPacket(i_fd, data);
} }
ret = 0;
out: out:
if (p_dvbpsi) if (p_dvbpsi)
{ {
dvbpsi_DetachDemux(p_dvbpsi); if (!dvbpsi_decoder_chain_delete(p_dvbpsi))
ret = 1;
dvbpsi_delete(p_dvbpsi); dvbpsi_delete(p_dvbpsi);
} }
close(i_fd); close(i_fd);
return 0; return ret;
} }
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
#include "../dvbpsi_private.h" #include "../dvbpsi_private.h"
#include "../psi.h" #include "../psi.h"
#include "../descriptor.h" #include "../descriptor.h"
#include "../demux.h" #include "../chain.h"
#include "sdt.h" #include "sdt.h"
#include "sdt_private.h" #include "sdt_private.h"
...@@ -57,11 +57,9 @@ bool dvbpsi_sdt_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens ...@@ -57,11 +57,9 @@ bool dvbpsi_sdt_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens
dvbpsi_sdt_callback pf_callback, void* p_cb_data) dvbpsi_sdt_callback pf_callback, void* p_cb_data)
{ {
assert(p_dvbpsi); assert(p_dvbpsi);
assert(p_dvbpsi->p_decoder);
dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder; dvbpsi_decoder_t *p_dec = dvbpsi_decoder_chain_get(p_dvbpsi, i_table_id, i_extension);
if (p_dec != NULL)
if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
{ {
dvbpsi_error(p_dvbpsi, "SDT decoder", dvbpsi_error(p_dvbpsi, "SDT decoder",
"Already a decoder for (table_id == 0x%02x," "Already a decoder for (table_id == 0x%02x,"
...@@ -71,29 +69,26 @@ bool dvbpsi_sdt_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens ...@@ -71,29 +69,26 @@ bool dvbpsi_sdt_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens
} }
dvbpsi_sdt_decoder_t* p_sdt_decoder; dvbpsi_sdt_decoder_t* p_sdt_decoder;
p_sdt_decoder = (dvbpsi_sdt_decoder_t*) dvbpsi_decoder_new(NULL, p_sdt_decoder = (dvbpsi_sdt_decoder_t*) dvbpsi_decoder_new(dvbpsi_sdt_sections_gather,
0, true, sizeof(dvbpsi_sdt_decoder_t)); 4096, true, sizeof(dvbpsi_sdt_decoder_t));
if (p_sdt_decoder == NULL) if (p_sdt_decoder == NULL)
return false; return false;
/* subtable decoder configuration */
dvbpsi_demux_subdec_t* p_subdec;
p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_sdt_detach,
dvbpsi_sdt_sections_gather, DVBPSI_DECODER(p_sdt_decoder));
if (p_subdec == NULL)
{
dvbpsi_decoder_delete(DVBPSI_DECODER(p_sdt_decoder));
return false;
}
/* Attach the subtable decoder to the demux */
dvbpsi_AttachDemuxSubDecoder(p_demux, p_subdec);
/* SDT decoder information */ /* SDT decoder information */
p_sdt_decoder->pf_sdt_callback = pf_callback; p_sdt_decoder->pf_sdt_callback = pf_callback;
p_sdt_decoder->p_cb_data = p_cb_data; p_sdt_decoder->p_cb_data = p_cb_data;
p_sdt_decoder->p_building_sdt = NULL; p_sdt_decoder->p_building_sdt = NULL;
p_sdt_decoder->i_table_id = i_table_id;
p_sdt_decoder->i_extension = i_extension;
/* add sdt decoder to decoder chain */
if (!dvbpsi_decoder_chain_add(p_dvbpsi, DVBPSI_DECODER(p_sdt_decoder)))
{
dvbpsi_decoder_delete(DVBPSI_DECODER(p_sdt_decoder));
return false;
}
return true; return true;
} }
...@@ -105,13 +100,9 @@ bool dvbpsi_sdt_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens ...@@ -105,13 +100,9 @@ bool dvbpsi_sdt_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens
void dvbpsi_sdt_detach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension) void dvbpsi_sdt_detach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension)
{ {
assert(p_dvbpsi); 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; dvbpsi_decoder_t *p_dec = dvbpsi_decoder_chain_get(p_dvbpsi, i_table_id, i_extension);
p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension); if (p_dec == NULL)
if (p_subdec == NULL)
{ {
dvbpsi_error(p_dvbpsi, "SDT Decoder", dvbpsi_error(p_dvbpsi, "SDT Decoder",
"No such SDT decoder (table_id == 0x%02x," "No such SDT decoder (table_id == 0x%02x,"
...@@ -120,17 +111,23 @@ void dvbpsi_sdt_detach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens ...@@ -120,17 +111,23 @@ void dvbpsi_sdt_detach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens
return; return;
} }
assert(p_subdec->p_decoder); /* Remove table decoder from decoder chain */
if (!dvbpsi_decoder_chain_remove(p_dvbpsi, p_dec))
{
dvbpsi_error(p_dvbpsi, "SDT Decoder",
"Failed to remove"
"extension == 0x%02x)",
i_table_id, i_extension);
return;
}
dvbpsi_sdt_decoder_t* p_sdt_decoder; /* Free associated memory */
p_sdt_decoder = (dvbpsi_sdt_decoder_t*)p_subdec->p_decoder; dvbpsi_sdt_decoder_t* p_sdt_decoder = (dvbpsi_sdt_decoder_t*)p_dec;
if (p_sdt_decoder->p_building_sdt) if (p_sdt_decoder->p_building_sdt)
dvbpsi_sdt_delete(p_sdt_decoder->p_building_sdt); dvbpsi_sdt_delete(p_sdt_decoder->p_building_sdt);
p_sdt_decoder->p_building_sdt = NULL; p_sdt_decoder->p_building_sdt = NULL;
dvbpsi_decoder_delete(p_dec);
/* Free sub table decoder */ p_dec = NULL;
dvbpsi_DetachDemuxSubDecoder(p_demux, p_subdec);
dvbpsi_DeleteDemuxSubDecoder(p_subdec);
} }
/***************************************************************************** /*****************************************************************************
...@@ -346,12 +343,9 @@ static bool dvbpsi_AddSectionSDT(dvbpsi_t *p_dvbpsi, dvbpsi_sdt_decoder_t *p_sdt ...@@ -346,12 +343,9 @@ static bool dvbpsi_AddSectionSDT(dvbpsi_t *p_dvbpsi, dvbpsi_sdt_decoder_t *p_sdt
***************************************************************************** *****************************************************************************
* Callback for the subtable demultiplexor. * Callback for the subtable demultiplexor.
*****************************************************************************/ *****************************************************************************/
void dvbpsi_sdt_sections_gather(dvbpsi_t *p_dvbpsi, void dvbpsi_sdt_sections_gather(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section)
dvbpsi_decoder_t *p_private_decoder,
dvbpsi_psi_section_t * p_section)
{ {
assert(p_dvbpsi); assert(p_dvbpsi);
assert(p_dvbpsi->p_decoder);
const uint8_t i_table_id = (p_section->i_table_id == 0x42 || const uint8_t i_table_id = (p_section->i_table_id == 0x42 ||
p_section->i_table_id == 0x46) ? p_section->i_table_id == 0x46) ?
...@@ -363,17 +357,21 @@ void dvbpsi_sdt_sections_gather(dvbpsi_t *p_dvbpsi, ...@@ -363,17 +357,21 @@ void dvbpsi_sdt_sections_gather(dvbpsi_t *p_dvbpsi,
return; return;
} }
dvbpsi_decoder_t *p_dec = dvbpsi_decoder_chain_get(p_dvbpsi, p_section->i_table_id, p_section->i_extension);
if (!p_dec)
{
dvbpsi_DeletePSISections(p_section);
return;
}
/* We have a valid SDT section */ /* We have a valid SDT section */
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *)p_dvbpsi->p_decoder; dvbpsi_sdt_decoder_t *p_sdt_decoder = (dvbpsi_sdt_decoder_t*)p_dec;
dvbpsi_sdt_decoder_t *p_sdt_decoder
= (dvbpsi_sdt_decoder_t*)p_private_decoder;
/* TS discontinuity check */ /* TS discontinuity check */
if (p_demux->b_discontinuity) if (p_sdt_decoder->b_discontinuity)
{ {
dvbpsi_ReInitSDT(p_sdt_decoder, true); dvbpsi_ReInitSDT(p_sdt_decoder, true);
p_sdt_decoder->b_discontinuity = false; p_sdt_decoder->b_discontinuity = false;
p_demux->b_discontinuity = false;
} }
else else
{ {
......
...@@ -51,7 +51,6 @@ typedef struct dvbpsi_sdt_decoder_s ...@@ -51,7 +51,6 @@ typedef struct dvbpsi_sdt_decoder_s
* Callback for the PSI decoder. * Callback for the PSI decoder.
*****************************************************************************/ *****************************************************************************/
void dvbpsi_sdt_sections_gather(dvbpsi_t *p_dvbpsi, void dvbpsi_sdt_sections_gather(dvbpsi_t *p_dvbpsi,
dvbpsi_decoder_t *p_private_decoder,
dvbpsi_psi_section_t *p_section); dvbpsi_psi_section_t *p_section);
/***************************************************************************** /*****************************************************************************
......
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