Commit 7beb890c authored by Jean-Paul Saman's avatar Jean-Paul Saman

demux: refactor

Refactor common demux code structures into utility functions.
See the complete list below:
- rearrange arguments of dvbpsi_demux_new_cb_t callback
- define dvbpsi_demux_gather_cb_t callback type
- define dvbpsi_demux_detach_cb_t callback type
- new utility function dvbpsi_NewDemuxSubDecoder()
- new utility function dvbpsi_DeleteDemuxSubDecoder()
- new utility funciton dvbpsi_AttachDemuxSubDecoder()
- new utility function dvbpsi_DetachDemuxSubDecoder()
parent 5e65f7a5
...@@ -198,8 +198,8 @@ static void DumpBAT(void* p_zero, dvbpsi_bat_t* p_bat) ...@@ -198,8 +198,8 @@ static void DumpBAT(void* p_zero, dvbpsi_bat_t* p_bat)
/***************************************************************************** /*****************************************************************************
* NewSubtable * NewSubtable
*****************************************************************************/ *****************************************************************************/
static void NewSubtableBAT(void * p_zero, dvbpsi_t *p_dvbpsi, static void NewSubtableBAT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
uint8_t i_table_id, uint16_t i_extension) void * p_zero)
{ {
if(i_table_id == 0x4a) if(i_table_id == 0x4a)
{ {
......
...@@ -141,8 +141,8 @@ static void message(dvbpsi_t *handle, const dvbpsi_msg_level_t level, const char ...@@ -141,8 +141,8 @@ static void message(dvbpsi_t *handle, const dvbpsi_msg_level_t level, const char
/***************************************************************************** /*****************************************************************************
* NewSubtable * NewSubtable
*****************************************************************************/ *****************************************************************************/
static void NewSubtable(void * p_zero, dvbpsi_t *p_dvbpsi, static void NewSubtable(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
uint8_t i_table_id, uint16_t i_extension) void * p_zero)
{ {
if(i_table_id == 0x42) if(i_table_id == 0x42)
{ {
......
...@@ -525,8 +525,8 @@ static void summary_packet(FILE *fd, ts_stream_t *stream) ...@@ -525,8 +525,8 @@ static void summary_packet(FILE *fd, ts_stream_t *stream)
/***************************************************************************** /*****************************************************************************
* handle_subtable * handle_subtable
*****************************************************************************/ *****************************************************************************/
static void handle_subtable(void *p_data, dvbpsi_t *p_dvbpsi, static void handle_subtable(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
uint8_t i_table_id, uint16_t i_extension) void *p_data)
{ {
switch (i_table_id) switch (i_table_id)
{ {
......
...@@ -111,8 +111,8 @@ void dvbpsi_Demux(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section) ...@@ -111,8 +111,8 @@ void dvbpsi_Demux(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section)
{ {
/* Tell the application we found a new subtable, so that it may attach a /* Tell the application we found a new subtable, so that it may attach a
* subtable decoder */ * subtable decoder */
p_demux->pf_new_callback(p_demux->p_new_cb_data, p_dvbpsi, p_demux->pf_new_callback(p_dvbpsi, p_section->i_table_id, p_section->i_extension,
p_section->i_table_id, p_section->i_extension); p_demux->p_new_cb_data);
/* Check if a new subtable decoder is available */ /* Check if a new subtable decoder is available */
p_subdec = dvbpsi_demuxGetSubDec(p_demux, p_section->i_table_id, p_subdec = dvbpsi_demuxGetSubDec(p_demux, p_section->i_table_id,
...@@ -152,3 +152,85 @@ void dvbpsi_DetachDemux(dvbpsi_t *p_dvbpsi) ...@@ -152,3 +152,85 @@ void dvbpsi_DetachDemux(dvbpsi_t *p_dvbpsi)
dvbpsi_DeleteDecoder((dvbpsi_decoder_t *)p_dvbpsi->p_private); dvbpsi_DeleteDecoder((dvbpsi_decoder_t *)p_dvbpsi->p_private);
p_dvbpsi->p_private = NULL; p_dvbpsi->p_private = NULL;
} }
/*****************************************************************************
* dvbpsi_NewDemuxSubDecoder
*****************************************************************************
* Allocate a new demux sub table decoder
*****************************************************************************/
dvbpsi_demux_subdec_t *dvbpsi_NewDemuxSubDecoder(const uint8_t i_table_id,
const uint16_t i_extension,
dvbpsi_demux_detach_cb_t pf_detach,
dvbpsi_demux_gather_cb_t pf_gather,
void *cb_data)
{
assert(pf_gather);
assert(pf_detach);
dvbpsi_demux_subdec_t *p_subdec = calloc(1, sizeof(dvbpsi_demux_subdec_t));
if (p_subdec == NULL)
return NULL;
uint32_t i_id = (uint32_t)i_table_id << 16 | (uint32_t)i_extension;
/* subtable decoder configuration */
p_subdec->i_id = i_id;
p_subdec->p_cb_data = cb_data;
p_subdec->pf_gather = pf_gather;
p_subdec->pf_detach = pf_detach;
return p_subdec;
}
/*****************************************************************************
* dvbpsi_DeleteDemuxSubDecoder
*****************************************************************************
* Free a demux sub table decoder
*****************************************************************************/
void dvbpsi_DeleteDemuxSubDecoder(dvbpsi_demux_subdec_t *p_subdec)
{
assert(p_subdec);
if (!p_subdec)
return;
free(p_subdec->p_cb_data);
free(p_subdec);
p_subdec = NULL;
}
/*****************************************************************************
* dvbpsi_AttachDemuxSubDecoder
*****************************************************************************/
void dvbpsi_AttachDemuxSubDecoder(dvbpsi_demux_t *p_demux, dvbpsi_demux_subdec_t *p_subdec)
{
assert(p_demux);
assert(p_subdec);
if (!p_demux || !p_subdec)
abort();
p_subdec->p_next = p_demux->p_first_subdec;
p_demux->p_first_subdec = p_subdec;
}
/*****************************************************************************
* dvbpsi_DetachDemuxSubDecoder
*****************************************************************************/
void dvbpsi_DetachDemuxSubDecoder(dvbpsi_demux_t *p_demux, dvbpsi_demux_subdec_t *p_subdec)
{
assert(p_demux);
assert(p_demux->p_first_subdec);
assert(p_subdec);
if (!p_demux || !p_subdec)
abort();
dvbpsi_demux_subdec_t** pp_prev_subdec;
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;
}
...@@ -42,16 +42,36 @@ extern "C" { ...@@ -42,16 +42,36 @@ extern "C" {
* dvbpsi_demux_new_cb_t * dvbpsi_demux_new_cb_t
*****************************************************************************/ *****************************************************************************/
/*! /*!
* \typedef void(* dvbpsi_demux_new_cb_t) (void * p_cb_data, * \typedef void(* dvbpsi_demux_new_cb_t) (dvbpsi_t *p_dvbpsi,
dvbpsi_t *p_dvbpsi,
uint8_t i_table_id, uint8_t i_table_id,
uint16_t i_extension); uint16_t i_extension,
void * p_cb_data);
* \brief Callback used in case of a new subtable detected. * \brief Callback used in case of a new subtable detected.
*/ */
typedef void (*dvbpsi_demux_new_cb_t) (void * p_cb_data, typedef void (*dvbpsi_demux_new_cb_t) (dvbpsi_t *p_dvbpsi, /*!< pointer to dvbpsi handle */
dvbpsi_t *p_dvbpsi, uint8_t i_table_id, /*!< table id to detach */
uint16_t i_extension,/*!< table extention to detach */
void * p_cb_data); /*!< pointer to callback data */
/*!
* \typedef void(*dvbpsi_demux_gather_cb_t)(dvbpsi_t *p_dvbpsi,
void *p_cb_data,
dvbpsi_psi_section_t *p_section);
* \brief Callback used for gathering psi sections on behalf of subtable decoders.
*/
typedef void (*dvbpsi_demux_gather_cb_t) (dvbpsi_t *p_dvbpsi, /*!< pointer to dvbpsi handle */
void *p_cb_data, /*!< pointer to callback data */
dvbpsi_psi_section_t *p_section); /*!< pointer to psi section */
/*!
* \typedef void (*dvbpsi_demux_detach_cb_t) (dvbpsi_t *p_dvbpsi,
uint8_t i_table_id, uint8_t i_table_id,
uint16_t i_extension); uint16_t i_extension);
* \brief Callback used for detaching subtable decoder from demuxer
*/
typedef void (*dvbpsi_demux_detach_cb_t) (dvbpsi_t *p_dvbpsi, /*!< pointer to dvbpsi handle */
uint8_t i_table_id, /*!< table id to detach */
uint16_t i_extension); /*!< table extention to detach */
/***************************************************************************** /*****************************************************************************
* dvbpsi_demux_subdec_t * dvbpsi_demux_subdec_t
...@@ -67,19 +87,19 @@ typedef void (*dvbpsi_demux_new_cb_t) (void * p_cb_data, ...@@ -67,19 +87,19 @@ typedef void (*dvbpsi_demux_new_cb_t) (void * p_cb_data,
* \typedef struct dvbpsi_demux_subdec_s dvbpsi_demux_subdec_t * \typedef struct dvbpsi_demux_subdec_s dvbpsi_demux_subdec_t
* \brief dvbpsi_demux_subdec_t type definition. * \brief dvbpsi_demux_subdec_t type definition.
*/ */
struct dvbpsi_demux_s;
typedef struct dvbpsi_demux_subdec_s typedef struct dvbpsi_demux_subdec_s
{ {
uint32_t i_id; /*!< subtable id */ uint32_t i_id; /*!< subtable id */
void (*pf_gather)(dvbpsi_t *, void *, dvbpsi_psi_section_t *); /*!< gather subdec callback */ dvbpsi_demux_gather_cb_t pf_gather; /*!< gather subdec callback */
void * p_cb_data; /*!< subdec callback data */ void * p_cb_data; /*!< subdec callback data */
void (*pf_detach)(dvbpsi_t *, uint8_t, uint16_t); /*!< detach subdec callback */ dvbpsi_demux_detach_cb_t pf_detach; /*!< detach subdec callback */
struct dvbpsi_demux_subdec_s * p_next; /*!< next subdec */ struct dvbpsi_demux_subdec_s *p_next; /*!< next subdec */
} dvbpsi_demux_subdec_t; } dvbpsi_demux_subdec_t;
/***************************************************************************** /*****************************************************************************
* dvbpsi_demux_s * dvbpsi_demux_s
*****************************************************************************/ *****************************************************************************/
...@@ -149,6 +169,7 @@ void dvbpsi_DetachDemux(dvbpsi_t *p_dvbpsi); ...@@ -149,6 +169,7 @@ void dvbpsi_DetachDemux(dvbpsi_t *p_dvbpsi);
dvbpsi_demux_subdec_t * dvbpsi_demuxGetSubDec(dvbpsi_demux_t * p_demux, dvbpsi_demux_subdec_t * dvbpsi_demuxGetSubDec(dvbpsi_demux_t * p_demux,
uint8_t i_table_id, uint8_t i_table_id,
uint16_t i_extension); uint16_t i_extension);
/***************************************************************************** /*****************************************************************************
* dvbpsi_Demux * dvbpsi_Demux
*****************************************************************************/ *****************************************************************************/
...@@ -161,6 +182,66 @@ dvbpsi_demux_subdec_t * dvbpsi_demuxGetSubDec(dvbpsi_demux_t * p_demux, ...@@ -161,6 +182,66 @@ dvbpsi_demux_subdec_t * dvbpsi_demuxGetSubDec(dvbpsi_demux_t * p_demux,
*/ */
void dvbpsi_Demux(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section); void dvbpsi_Demux(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section);
/*****************************************************************************
* dvbpsi_NewDemuxSubDecoder
*****************************************************************************/
/*!
* \fn dvbpsi_demux_subdec_t *dvbpsi_NewDemuxSubDecoder(const uint8_t i_table_id,
const uint16_t i_extension,
dvbpsi_demux_detach_cb_t *pf_detach,
dvbpsi_demux_gather_cb_t *pf_gather,
void *cb_data)
* \brief Allocates a new demux sub table decoder and initializes it.
* \param i_table_id table id to create subtable decoder for
* \param i_extension table extension to create subtable decoder for
* \param pf_detach pointer to detach function for subtable decoder.
* \param pf_gather pointer to gather function for subtable decoder.
* \param p_cb_data pointer to private decoder.
* \return pointer to demux subtable decoder.
*/
dvbpsi_demux_subdec_t *dvbpsi_NewDemuxSubDecoder(const uint8_t i_table_id,
const uint16_t i_extension,
dvbpsi_demux_detach_cb_t pf_detach,
dvbpsi_demux_gather_cb_t pf_gather,
void *cb_data);
/*****************************************************************************
* dvbpsi_DeleteDemuxSubDecoder
*****************************************************************************/
/*!
* \fn void dvbpsi_DeleteDemuxSubDecoder(dvbpsi_demux_subdec_t *p_subdec)
* \brief Releases memory allocated with @see dvbpsi_NewDemuxSubDecoder. It will
* also release p_cb_data pointer.
* \param p_subdec pointer to demux subtable decoder.
* \param p_new_cb_data Data given to the previous callback.
* \return nothing.
*/
void dvbpsi_DeleteDemuxSubDecoder(dvbpsi_demux_subdec_t *p_subdec);
/*****************************************************************************
* dvbpsi_AttachDemuxSubDecoder
*****************************************************************************/
/*!
* \fn void dvbpsi_AttachDemuxSubDecoder(dvbpsi_demux_t *p_demux, dvbpsi_demux_subdec_t *p_subdec)
* \brief Attach a subtable decoder to the given demux handle.
* \param p_demux pointer to dvbpsi_demux_t
* \param p_subdec pointer to dvbpsi_demux_subdec_t
* \return nothing
*/
void dvbpsi_AttachDemuxSubDecoder(dvbpsi_demux_t *p_demux, dvbpsi_demux_subdec_t *p_subdec);
/*****************************************************************************
* dvbpsi_DetachDemuxSubDecoder
*****************************************************************************/
/*!
* \fn void dvbpsi_DetachDemuxSubDecoder(dvbpsi_demux_t *p_demux, dvbpsi_demux_subdec_t *p_subdec)
* \brief Detach a subtable decoder from the given demux pointer.
* \param p_demux pointer to dvbpsi_demux_t
* \param p_subdec pointer to dvbpsi_demux_subdec_t
* \return nothing
*/
void dvbpsi_DetachDemuxSubDecoder(dvbpsi_demux_t *p_demux, dvbpsi_demux_subdec_t *p_subdec);
#ifdef __cplusplus #ifdef __cplusplus
}; };
#endif #endif
......
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