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

BAT: implement as chained decoder

parent 882a4a3a
...@@ -42,13 +42,13 @@ ...@@ -42,13 +42,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/bat.h" #include "../src/tables/bat.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/bat.h> #include <dvbpsi/bat.h>
#endif #endif
...@@ -194,7 +194,6 @@ static void DumpBAT(void* p_zero, dvbpsi_bat_t* p_bat) ...@@ -194,7 +194,6 @@ static void DumpBAT(void* p_zero, dvbpsi_bat_t* p_bat)
dvbpsi_bat_delete(p_bat); dvbpsi_bat_delete(p_bat);
} }
/***************************************************************************** /*****************************************************************************
* NewSubtable * NewSubtable
*****************************************************************************/ *****************************************************************************/
...@@ -208,6 +207,18 @@ static void NewSubtableBAT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex ...@@ -208,6 +207,18 @@ static void NewSubtableBAT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
} }
} }
/*****************************************************************************
* DelSubtable
*****************************************************************************/
static void DelSubtableBAT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension)
{
if(i_table_id == 0x4a)
{
dvbpsi_bat_detach(p_dvbpsi, i_table_id, i_extension);
}
}
static void message(dvbpsi_t *handle, const dvbpsi_msg_level_t level, const char* msg) static void message(dvbpsi_t *handle, const dvbpsi_msg_level_t level, const char* msg)
{ {
switch(level) switch(level)
...@@ -227,21 +238,22 @@ static void message(dvbpsi_t *handle, const dvbpsi_msg_level_t level, const char ...@@ -227,21 +238,22 @@ static void message(dvbpsi_t *handle, const dvbpsi_msg_level_t level, const char
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;
if(i_argc != 2) if(i_argc != 2)
return 1; return ret;
i_fd = open(pa_argv[1], 0); i_fd = open(pa_argv[1], 0);
if (i_fd < 0) if (i_fd < 0)
return 1; return ret;
p_dvbpsi = dvbpsi_new(&message, DVBPSI_MSG_DEBUG); p_dvbpsi = dvbpsi_new(&message, DVBPSI_MSG_DEBUG);
if (p_dvbpsi == NULL) if (p_dvbpsi == NULL)
goto out; goto out;
if (!dvbpsi_AttachDemux(p_dvbpsi, NewSubtableBAT, NULL)) if (!dvbpsi_decoder_chain_new(p_dvbpsi, NewSubtableBAT, DelSubtableBAT, NULL))
goto out; goto out;
b_ok = ReadPacket(i_fd, data); b_ok = ReadPacket(i_fd, data);
...@@ -254,12 +266,15 @@ int main(int i_argc, char* pa_argv[]) ...@@ -254,12 +266,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;
} }
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,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 "bat.h" #include "bat.h"
#include "bat_private.h" #include "bat_private.h"
...@@ -59,10 +59,9 @@ bool dvbpsi_bat_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, ...@@ -59,10 +59,9 @@ bool dvbpsi_bat_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
uint16_t i_extension, dvbpsi_bat_callback pf_callback, void* p_cb_data) uint16_t i_extension, dvbpsi_bat_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 (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension)) if (p_dec != NULL)
{ {
dvbpsi_error(p_dvbpsi, "BAT decoder", dvbpsi_error(p_dvbpsi, "BAT decoder",
"Already a decoder for (table_id == 0x%02x," "Already a decoder for (table_id == 0x%02x,"
...@@ -71,30 +70,26 @@ bool dvbpsi_bat_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, ...@@ -71,30 +70,26 @@ bool dvbpsi_bat_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
return false; return false;
} }
dvbpsi_bat_decoder_t* p_bat_decoder; dvbpsi_bat_decoder_t *p_bat_decoder;
p_bat_decoder = (dvbpsi_bat_decoder_t*) dvbpsi_decoder_new(NULL, p_bat_decoder = (dvbpsi_bat_decoder_t*) dvbpsi_decoder_new(dvbpsi_bat_sections_gather,
0, true, sizeof(dvbpsi_bat_decoder_t)); 4096, true, sizeof(dvbpsi_bat_decoder_t));
if (p_bat_decoder == NULL) if (p_bat_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_bat_detach,
dvbpsi_bat_sections_gather, DVBPSI_DECODER(p_bat_decoder));
if (p_subdec == NULL)
{
dvbpsi_decoder_delete(DVBPSI_DECODER(p_bat_decoder));
return false;
}
/* Attach the subtable decoder to the demux */
dvbpsi_AttachDemuxSubDecoder(p_demux, p_subdec);
/* BAT decoder information */ /* BAT decoder information */
p_bat_decoder->pf_bat_callback = pf_callback; p_bat_decoder->pf_bat_callback = pf_callback;
p_bat_decoder->p_cb_data = p_cb_data; p_bat_decoder->p_cb_data = p_cb_data;
p_bat_decoder->p_building_bat = NULL; p_bat_decoder->p_building_bat = NULL;
p_bat_decoder->i_table_id = i_table_id;
p_bat_decoder->i_extension = i_extension;
/* Add bat decoder to decoder chain */
if (!dvbpsi_decoder_chain_add(p_dvbpsi, DVBPSI_DECODER(p_bat_decoder)))
{
dvbpsi_decoder_delete(DVBPSI_DECODER(p_bat_decoder));
return false;
}
return true; return true;
} }
...@@ -106,13 +101,9 @@ bool dvbpsi_bat_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, ...@@ -106,13 +101,9 @@ bool dvbpsi_bat_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
void dvbpsi_bat_detach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension) void dvbpsi_bat_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, "BAT Decoder", dvbpsi_error(p_dvbpsi, "BAT Decoder",
"No such BAT decoder (table_id == 0x%02x," "No such BAT decoder (table_id == 0x%02x,"
...@@ -121,14 +112,22 @@ void dvbpsi_bat_detach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens ...@@ -121,14 +112,22 @@ void dvbpsi_bat_detach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens
return; return;
} }
dvbpsi_bat_decoder_t* p_bat_decoder; /* Remove table decoder from chain */
p_bat_decoder = (dvbpsi_bat_decoder_t*)p_subdec->p_decoder; if (!dvbpsi_decoder_chain_remove(p_dvbpsi, p_dec))
{
dvbpsi_error(p_dvbpsi, "BAT Decoder",
"Failed to remove"
"extension == 0x%02x)",
i_table_id, i_extension);
return;
}
dvbpsi_bat_decoder_t* p_bat_decoder = (dvbpsi_bat_decoder_t*)p_dec;
if (p_bat_decoder->p_building_bat) if (p_bat_decoder->p_building_bat)
dvbpsi_bat_delete(p_bat_decoder->p_building_bat); dvbpsi_bat_delete(p_bat_decoder->p_building_bat);
p_bat_decoder->p_building_bat = NULL; p_bat_decoder->p_building_bat = NULL;
dvbpsi_decoder_delete(p_dec);
dvbpsi_DetachDemuxSubDecoder(p_demux, p_subdec); p_dec = NULL;
dvbpsi_DeleteDemuxSubDecoder(p_subdec);
} }
/***************************************************************************** /*****************************************************************************
...@@ -362,14 +361,9 @@ static bool dvbpsi_AddSectionBAT(dvbpsi_t *p_dvbpsi, dvbpsi_bat_decoder_t *p_bat ...@@ -362,14 +361,9 @@ static bool dvbpsi_AddSectionBAT(dvbpsi_t *p_dvbpsi, dvbpsi_bat_decoder_t *p_bat
* Callback for the subtable demultiplexor. * Callback for the subtable demultiplexor.
*****************************************************************************/ *****************************************************************************/
void dvbpsi_bat_sections_gather(dvbpsi_t *p_dvbpsi, void dvbpsi_bat_sections_gather(dvbpsi_t *p_dvbpsi,
dvbpsi_decoder_t *p_decoder,
dvbpsi_psi_section_t * p_section) dvbpsi_psi_section_t * p_section)
{ {
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
dvbpsi_bat_decoder_t * p_bat_decoder = (dvbpsi_bat_decoder_t *) p_decoder;
assert(p_dvbpsi); assert(p_dvbpsi);
assert(p_dvbpsi->p_decoder);
if (!dvbpsi_CheckPSISection(p_dvbpsi, p_section, 0x4a, "BAT decoder")) if (!dvbpsi_CheckPSISection(p_dvbpsi, p_section, 0x4a, "BAT decoder"))
{ {
...@@ -378,11 +372,18 @@ void dvbpsi_bat_sections_gather(dvbpsi_t *p_dvbpsi, ...@@ -378,11 +372,18 @@ void dvbpsi_bat_sections_gather(dvbpsi_t *p_dvbpsi,
} }
/* We have a valid BAT section */ /* We have a valid BAT section */
if (p_demux->b_discontinuity) 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;
}
dvbpsi_bat_decoder_t *p_bat_decoder = (dvbpsi_bat_decoder_t*)p_dec;
if (p_bat_decoder->b_discontinuity)
{ {
dvbpsi_ReInitBAT(p_bat_decoder, true); dvbpsi_ReInitBAT(p_bat_decoder, true);
p_bat_decoder->b_discontinuity = false; p_bat_decoder->b_discontinuity = false;
p_demux->b_discontinuity = false;
} }
else else
{ {
......
...@@ -51,7 +51,7 @@ typedef struct dvbpsi_bat_decoder_s ...@@ -51,7 +51,7 @@ typedef struct dvbpsi_bat_decoder_s
***************************************************************************** *****************************************************************************
* Callback for the PSI decoder. * Callback for the PSI decoder.
*****************************************************************************/ *****************************************************************************/
void dvbpsi_bat_sections_gather(dvbpsi_t* p_dvbpsi, dvbpsi_decoder_t* p_decoder, void dvbpsi_bat_sections_gather(dvbpsi_t* p_dvbpsi,
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