Commit 71cc59bb authored by Jean-Paul Saman's avatar Jean-Paul Saman

Use dvbpsi_NewDecoder() and dvbpsi_DeleteDecoder() to allocate decoders for...

Use dvbpsi_NewDecoder() and dvbpsi_DeleteDecoder() to allocate decoders for Demux, PAT, PMT and CAT.
parent 4adb388a
......@@ -56,19 +56,12 @@ bool dvbpsi_AttachDemux(dvbpsi_t * p_dvbpsi,
assert(p_dvbpsi);
assert(p_dvbpsi->p_private == NULL);
dvbpsi_demux_t *p_demux = (dvbpsi_demux_t*)malloc(sizeof(dvbpsi_demux_t));
dvbpsi_demux_t *p_demux;
p_demux = (dvbpsi_demux_t*) dvbpsi_NewDecoder(&dvbpsi_Demux, 4096, true,
sizeof(dvbpsi_demux_t));
if (p_demux == NULL)
return false;
/* PSI decoder configuration */
p_demux->pf_callback = &dvbpsi_Demux;
p_demux->i_section_max_size = 4096;
/* PSI decoder initial state */
p_demux->i_continuity_counter = 31;
p_demux->b_discontinuity = true;
p_demux->p_current_section = NULL;
/* Subtables demux configuration */
p_demux->p_first_subdec = NULL;
p_demux->pf_new_callback = pf_new_cb;
......@@ -161,9 +154,6 @@ void dvbpsi_DetachDemux(dvbpsi_t *p_dvbpsi)
else free(p_subdec_temp);
}
if (p_demux->p_current_section)
dvbpsi_DeletePSISections(p_demux->p_current_section);
dvbpsi_DeleteDecoder((dvbpsi_decoder_t *)p_dvbpsi->p_private);
p_dvbpsi->p_private = NULL;
free(p_demux);
}
......@@ -169,15 +169,21 @@ void dvbpsi_DeleteHandle(dvbpsi_t *handle)
/*****************************************************************************
* dvbpsi_NewDecoder
*****************************************************************************/
dvbpsi_decoder_t *dvbpsi_NewDecoder(dvbpsi_t *handle, dvbpsi_callback *callback)
#define DVBPSI_INVALID_CC (0xFF)
dvbpsi_decoder_t *dvbpsi_NewDecoder(dvbpsi_callback callback,
const int i_section_max_size, const bool b_discontinuity, const size_t psi_size)
{
dvbpsi_decoder_t *p_decoder = calloc(1, sizeof(dvbpsi_decoder_t));
dvbpsi_decoder_t *p_decoder = (dvbpsi_decoder_t *) calloc(1, psi_size);
if (p_decoder == NULL)
return NULL;
p_decoder->pf_callback = NULL;
p_decoder->pf_callback = callback;
p_decoder->p_current_section = NULL;
p_decoder->i_continuity_counter = 0xFF; /* invalid CC */
p_decoder->i_section_max_size = i_section_max_size;
p_decoder->b_discontinuity = b_discontinuity;
p_decoder->i_continuity_counter = DVBPSI_INVALID_CC;
p_decoder->p_current_section = NULL;
p_decoder->b_complete_header = false;
return p_decoder;
}
......@@ -185,15 +191,11 @@ dvbpsi_decoder_t *dvbpsi_NewDecoder(dvbpsi_t *handle, dvbpsi_callback *callback)
/*****************************************************************************
* dvbpsi_DeleteDecoder
*****************************************************************************/
void dvbpsi_DeleteDecoder(dvbpsi_t *handle)
void dvbpsi_DeleteDecoder(dvbpsi_decoder_t *p_decoder)
{
assert(handle);
assert(handle->p_private);
dvbpsi_decoder_t *p_decoder = (dvbpsi_decoder_t *) handle->p_private;
handle->p_private = NULL;
assert(p_decoder);
assert(p_decoder->p_current_section == NULL);
dvbpsi_DeletePSISections(p_decoder->p_current_section);
free(p_decoder);
}
......@@ -235,7 +237,7 @@ bool dvbpsi_PushPacket(dvbpsi_t *handle, uint8_t* p_data)
}
/* Continuity check */
bool b_first = (p_decoder->i_continuity_counter == 0xFF);
bool b_first = (p_decoder->i_continuity_counter == DVBPSI_INVALID_CC);
if (b_first)
p_decoder->i_continuity_counter = p_data[3] & 0xf;
else
......@@ -447,6 +449,7 @@ bool dvbpsi_PushPacket(dvbpsi_t *handle, uint8_t* p_data)
}
return true;
}
#undef DVBPSI_INVALID_CC
/*****************************************************************************
* Message error level:
......
......@@ -199,30 +199,34 @@ struct dvbpsi_decoder_s
* dvbpsi_NewDecoder
*****************************************************************************/
/*!
* \fn dvbpsi_decoder_t *dvbpsi_NewDecoder(dvbpsi_t *p_dvbpsi, dvbpsi_callback *callback)
* \fn dvbpsi_decoder_t *dvbpsi_NewDecoder(dvbpsi_t *p_dvbpsi, dvbpsi_callback *callback,
* const int i_section_max_size, const bool b_discontinuity, const size_t struct_size);
* \brief Create a new dvbpsi_decoder_t.
* \param p_dvbpsi handle to dvbpsi with attached decoder
* \param callback dvbpsi_callback handler
* \param i_section_max_size Max size of a section for this decoder
* \param b_discontinuity Discontinuity flag
* \param psi_size size of new PSI struct, eg: sizeof(dvbpsi_pat_t)
* \return pointer to dvbpsi_decoder_t&
*
* Creates a dvbpsi_decoder_t pointer to struct dvbpsi_decoder_s. It should be
* delete with dvbpsi_DeleteDecoder() function.
*/
dvbpsi_decoder_t *dvbpsi_NewDecoder(dvbpsi_t *p_dvbpsi, dvbpsi_callback *callback);
dvbpsi_decoder_t *dvbpsi_NewDecoder(dvbpsi_callback callback,
const int i_section_max_size, const bool b_discontinuity, const size_t psi_size);
/*****************************************************************************
* dvbpsi_DeleteDecoder
*****************************************************************************/
/*!
* \fn void dvbpsi_DeleteDecoder(dvbpsi_t *p_dvbpsi);
* \brief Deletes attached decoder struct from dvbpsi_t handle and frees its memory
* \param p_dvbpsi handle to dvbpsi with attached decoder
* \fn void dvbpsi_DeleteDecoder(dvbpsi_decoder_t *p_decoder);
* \brief Deletes decoder struct and frees its memory
* \param p_decoder pointer to dvbpsi_decoder_t with decoder
* \return nothing
*
* Delets a dvbpsi_t handle by calling free(handle). Make sure to detach any
* decoder of encoder before deleting the dvbpsi handle.
*/
void dvbpsi_DeleteDecoder(dvbpsi_t *p_dvbpsi);
void dvbpsi_DeleteDecoder(dvbpsi_decoder_t *p_decoder);
/*****************************************************************************
* dvbpsi_HasDecoder
......
/*****************************************************************************
* cat.c: CAT decoder/generator
*----------------------------------------------------------------------------
* Copyright (C) 2001-2010 VideoLAN
* Copyright (C) 2001-2011 VideoLAN
* $Id$
*
* Authors: Johann Hanne
......@@ -61,19 +61,11 @@ bool dvbpsi_AttachCAT(dvbpsi_t *p_dvbpsi, dvbpsi_cat_callback pf_callback,
assert(p_dvbpsi->p_private == NULL);
dvbpsi_cat_decoder_t* p_cat_decoder;
p_cat_decoder = (dvbpsi_cat_decoder_t*)calloc(1, sizeof(dvbpsi_cat_decoder_t));
p_cat_decoder = (dvbpsi_cat_decoder_t*) dvbpsi_NewDecoder(&dvbpsi_GatherCATSections,
1024, true, sizeof(dvbpsi_cat_decoder_t));
if (p_cat_decoder == NULL)
return false;
/* PSI decoder configuration */
p_cat_decoder->pf_callback = &dvbpsi_GatherCATSections;
p_dvbpsi->p_private = p_cat_decoder;
p_cat_decoder->i_section_max_size = 1024;
/* PSI decoder initial state */
p_cat_decoder->i_continuity_counter = 31;
p_cat_decoder->b_discontinuity = true;
p_cat_decoder->p_current_section = NULL;
/* CAT decoder configuration */
p_cat_decoder->pf_cat_callback = pf_callback;
p_cat_decoder->p_cb_data = p_cb_data;
......@@ -83,6 +75,7 @@ bool dvbpsi_AttachCAT(dvbpsi_t *p_dvbpsi, dvbpsi_cat_callback pf_callback,
for (unsigned int i = 0; i <= 255; i++)
p_cat_decoder->ap_sections[i] = NULL;
p_dvbpsi->p_private = p_cat_decoder;
return true;
}
......@@ -106,9 +99,7 @@ void dvbpsi_DetachCAT(dvbpsi_t *p_dvbpsi)
free(p_cat_decoder->ap_sections[i]);
}
if (p_cat_decoder->p_current_section)
dvbpsi_DeletePSISections(p_cat_decoder->p_current_section);
free(p_cat_decoder);
dvbpsi_DeleteDecoder((dvbpsi_decoder_t *)p_dvbpsi->p_private);
p_dvbpsi->p_private = NULL;
}
......
......@@ -56,19 +56,13 @@ bool dvbpsi_AttachPAT(dvbpsi_t *p_dvbpsi, dvbpsi_pat_callback pf_callback,
assert(p_dvbpsi);
assert(p_dvbpsi->p_private == NULL);
dvbpsi_pat_decoder_t* p_pat_decoder = (dvbpsi_pat_decoder_t*) calloc(1, sizeof(dvbpsi_pat_decoder_t));
/* PSI decoder configuration and initial state */
dvbpsi_pat_decoder_t *p_pat_decoder;
p_pat_decoder = (dvbpsi_pat_decoder_t*) dvbpsi_NewDecoder(&dvbpsi_GatherPATSections,
1024, true, sizeof(dvbpsi_pat_decoder_t));
if (p_pat_decoder == NULL)
return false;
/* PSI decoder configuration */
p_pat_decoder->pf_callback = &dvbpsi_GatherPATSections;
p_pat_decoder->i_section_max_size = 1024;
/* PSI decoder initial state */
p_pat_decoder->i_continuity_counter = 31;
p_pat_decoder->b_discontinuity = true;
p_pat_decoder->p_current_section = NULL;
/* PAT decoder information */
p_pat_decoder->pf_pat_callback = pf_callback;
p_pat_decoder->p_cb_data = p_cb_data;
......@@ -103,9 +97,7 @@ void dvbpsi_DetachPAT(dvbpsi_t *p_dvbpsi)
free(p_pat_decoder->ap_sections[i]);
}
if (p_pat_decoder->p_current_section)
dvbpsi_DeletePSISections(p_pat_decoder->p_current_section);
free(p_pat_decoder);
dvbpsi_DeleteDecoder((dvbpsi_decoder_t *)p_dvbpsi->p_private);
p_dvbpsi->p_private = NULL;
}
......
/*****************************************************************************
* pmt.c: PMT decoder/generator
*----------------------------------------------------------------------------
* Copyright (C) 2001-2010 VideoLAN
* Copyright (C) 2001-2011 VideoLAN
* $Id$
*
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
......@@ -59,21 +59,13 @@ bool dvbpsi_AttachPMT(dvbpsi_t *p_dvbpsi, uint16_t i_program_number,
assert(p_dvbpsi->p_private == NULL);
dvbpsi_pmt_decoder_t* p_pmt_decoder;
p_pmt_decoder = (dvbpsi_pmt_decoder_t*)malloc(sizeof(dvbpsi_pmt_decoder_t));
p_pmt_decoder = (dvbpsi_pmt_decoder_t*) dvbpsi_NewDecoder(&dvbpsi_GatherPMTSections,
1024, true, sizeof(dvbpsi_pmt_decoder_t));
if (p_pmt_decoder == NULL)
return false;
p_dvbpsi->p_private = (void *)p_pmt_decoder;
/* PSI decoder configuration */
p_pmt_decoder->pf_callback = &dvbpsi_GatherPMTSections;
p_pmt_decoder->i_section_max_size = 1024;
/* PSI decoder initial state */
p_pmt_decoder->i_continuity_counter = 31;
p_pmt_decoder->b_discontinuity = true;
p_pmt_decoder->p_current_section = NULL;
/* PMT decoder configuration */
p_pmt_decoder->i_program_number = i_program_number;
p_pmt_decoder->pf_pmt_callback = pf_callback;
......@@ -98,8 +90,8 @@ void dvbpsi_DetachPMT(dvbpsi_t *p_dvbpsi)
assert(p_dvbpsi);
assert(p_dvbpsi->p_private);
dvbpsi_pmt_decoder_t* p_pmt_decoder
= (dvbpsi_pmt_decoder_t*)p_dvbpsi->p_private;
dvbpsi_pmt_decoder_t* p_pmt_decoder;
p_pmt_decoder = (dvbpsi_pmt_decoder_t*)p_dvbpsi->p_private;
free(p_pmt_decoder->p_building_pmt);
for (unsigned int i = 0; i <= 255; i++)
......@@ -108,9 +100,7 @@ void dvbpsi_DetachPMT(dvbpsi_t *p_dvbpsi)
free(p_pmt_decoder->ap_sections[i]);
}
if (p_pmt_decoder->p_current_section)
dvbpsi_DeletePSISections(p_pmt_decoder->p_current_section);
free(p_pmt_decoder);
dvbpsi_DeleteDecoder((dvbpsi_decoder_t *)p_dvbpsi->p_private);
p_dvbpsi->p_private = NULL;
}
......
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