Commit 2b2d1423 authored by Jean-Paul Saman's avatar Jean-Paul Saman

Add utility function dvbpsi_AddDescriptor().

Adding a descriptor to the end of the descriptor list has now been
moved to a utility function implemented in src/descriptor.c
parent 7a09ba19
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#include <stdint.h> #include <stdint.h>
#endif #endif
#include <assert.h>
#include "dvbpsi.h" #include "dvbpsi.h"
#include "descriptor.h" #include "descriptor.h"
...@@ -108,6 +110,28 @@ dvbpsi_descriptor_t* dvbpsi_NewDescriptor(uint8_t i_tag, uint8_t i_length, ...@@ -108,6 +110,28 @@ dvbpsi_descriptor_t* dvbpsi_NewDescriptor(uint8_t i_tag, uint8_t i_length,
return p_descriptor; return p_descriptor;
} }
/*****************************************************************************
* dvbpsi_AddDescriptor
*****************************************************************************
* Add 'p_descriptor' to the list of descriptors 'p_list'
*****************************************************************************/
dvbpsi_descriptor_t *dvbpsi_AddDescriptor(dvbpsi_descriptor_t *p_list,
dvbpsi_descriptor_t *p_descriptor)
{
assert(p_descriptor);
if (p_list == NULL)
p_list = p_descriptor;
else
{
dvbpsi_descriptor_t *p_last = p_list;
while (p_last->p_next != NULL)
p_last = p_last->p_next;
p_last->p_next = p_descriptor;
}
return p_list;
}
/***************************************************************************** /*****************************************************************************
* dvbpsi_DeleteDescriptors * dvbpsi_DeleteDescriptors
***************************************************************************** *****************************************************************************
......
...@@ -96,6 +96,20 @@ dvbpsi_descriptor_t* dvbpsi_NewDescriptor(uint8_t i_tag, uint8_t i_length, ...@@ -96,6 +96,20 @@ dvbpsi_descriptor_t* dvbpsi_NewDescriptor(uint8_t i_tag, uint8_t i_length,
*/ */
void dvbpsi_DeleteDescriptors(dvbpsi_descriptor_t* p_descriptor); void dvbpsi_DeleteDescriptors(dvbpsi_descriptor_t* p_descriptor);
/*****************************************************************************
* dvbpsi_AddDescriptor
*****************************************************************************/
/*!
* \fn dvbpsi_descriptor_t *dvbpsi_AddDescriptor(dvbpsi_descriptor_t *p_list,
dvbpsi_descriptor_t *p_descriptor);
* \brief Add a descriptor to the end of descriptor list.
* \param p_list the first descriptor in the descriptor list.
* \param p_descriptor the descriptor to add to the list
* \return a pointer to the first element in the descriptor list.
*/
dvbpsi_descriptor_t *dvbpsi_AddDescriptor(dvbpsi_descriptor_t *p_list,
dvbpsi_descriptor_t *p_descriptor);
/***************************************************************************** /*****************************************************************************
* dvbpsi_CanDecodeAsDescriptor * dvbpsi_CanDecodeAsDescriptor
*****************************************************************************/ *****************************************************************************/
......
...@@ -270,20 +270,14 @@ static dvbpsi_descriptor_t *dvbpsi_atsc_EITChannelAddDescriptor( ...@@ -270,20 +270,14 @@ static dvbpsi_descriptor_t *dvbpsi_atsc_EITChannelAddDescriptor(
{ {
dvbpsi_descriptor_t * p_descriptor dvbpsi_descriptor_t * p_descriptor
= dvbpsi_NewDescriptor(i_tag, i_length, p_data); = dvbpsi_NewDescriptor(i_tag, i_length, p_data);
if(p_descriptor) if (p_descriptor == NULL)
{ return NULL;
if(p_event->p_first_descriptor == NULL)
{ p_event->p_first_descriptor = dvbpsi_AddDescriptor(p_event->p_first_descriptor,
p_event->p_first_descriptor = p_descriptor; p_descriptor);
} assert(p_event->p_first_descriptor);
else if (p_event->p_first_descriptor == NULL)
{ return NULL;
dvbpsi_descriptor_t * p_last_descriptor = p_event->p_first_descriptor;
while(p_last_descriptor->p_next != NULL)
p_last_descriptor = p_last_descriptor->p_next;
p_last_descriptor->p_next = p_descriptor;
}
}
return p_descriptor; return p_descriptor;
} }
......
...@@ -231,20 +231,14 @@ static dvbpsi_descriptor_t *dvbpsi_atsc_MGTAddDescriptor( ...@@ -231,20 +231,14 @@ static dvbpsi_descriptor_t *dvbpsi_atsc_MGTAddDescriptor(
{ {
dvbpsi_descriptor_t * p_descriptor dvbpsi_descriptor_t * p_descriptor
= dvbpsi_NewDescriptor(i_tag, i_length, p_data); = dvbpsi_NewDescriptor(i_tag, i_length, p_data);
if(p_descriptor) if (p_descriptor == NULL)
{ return NULL;
if(p_mgt->p_first_descriptor == NULL)
{ p_mgt->p_first_descriptor = dvbpsi_AddDescriptor(p_mgt->p_first_descriptor,
p_mgt->p_first_descriptor = p_descriptor; p_descriptor);
} assert(p_mgt->p_first_descriptor);
else if (p_mgt->p_first_descriptor == NULL)
{ return NULL;
dvbpsi_descriptor_t * p_last_descriptor = p_mgt->p_first_descriptor;
while(p_last_descriptor->p_next != NULL)
p_last_descriptor = p_last_descriptor->p_next;
p_last_descriptor->p_next = p_descriptor;
}
}
return p_descriptor; return p_descriptor;
} }
......
...@@ -209,20 +209,14 @@ dvbpsi_descriptor_t *dvbpsi_atsc_STTAddDescriptor( dvbpsi_atsc_stt_t *p_stt, ...@@ -209,20 +209,14 @@ dvbpsi_descriptor_t *dvbpsi_atsc_STTAddDescriptor( dvbpsi_atsc_stt_t *p_stt,
uint8_t *p_data) uint8_t *p_data)
{ {
dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(i_tag, i_length, p_data); dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(i_tag, i_length, p_data);
if (p_descriptor) if (p_descriptor == NULL)
{ return NULL;
p_stt->p_first_descriptor = dvbpsi_AddDescriptor(p_stt->p_first_descriptor,
p_descriptor);
assert(p_stt->p_first_descriptor);
if (p_stt->p_first_descriptor == NULL) if (p_stt->p_first_descriptor == NULL)
{ return NULL;
p_stt->p_first_descriptor = p_descriptor;
}
else
{
dvbpsi_descriptor_t * p_last_descriptor = p_stt->p_first_descriptor;
while(p_last_descriptor->p_next != NULL)
p_last_descriptor = p_last_descriptor->p_next;
p_last_descriptor->p_next = p_descriptor;
}
}
return p_descriptor; return p_descriptor;
} }
......
...@@ -248,20 +248,14 @@ static dvbpsi_descriptor_t *dvbpsi_atsc_VCTAddDescriptor(dvbpsi_atsc_vct_t *p_vc ...@@ -248,20 +248,14 @@ static dvbpsi_descriptor_t *dvbpsi_atsc_VCTAddDescriptor(dvbpsi_atsc_vct_t *p_vc
{ {
dvbpsi_descriptor_t * p_descriptor dvbpsi_descriptor_t * p_descriptor
= dvbpsi_NewDescriptor(i_tag, i_length, p_data); = dvbpsi_NewDescriptor(i_tag, i_length, p_data);
if(p_descriptor) if (p_descriptor == NULL)
{ return NULL;
if(p_vct->p_first_descriptor == NULL)
{ p_vct->p_first_descriptor = dvbpsi_AddDescriptor(p_vct->p_first_descriptor,
p_vct->p_first_descriptor = p_descriptor; p_descriptor);
} assert(p_vct->p_first_descriptor);
else if (p_vct->p_first_descriptor == NULL)
{ return NULL;
dvbpsi_descriptor_t * p_last_descriptor = p_vct->p_first_descriptor;
while(p_last_descriptor->p_next != NULL)
p_last_descriptor = p_last_descriptor->p_next;
p_last_descriptor->p_next = p_descriptor;
}
}
return p_descriptor; return p_descriptor;
} }
......
...@@ -241,15 +241,12 @@ dvbpsi_descriptor_t *dvbpsi_BATBouquetAddDescriptor( ...@@ -241,15 +241,12 @@ dvbpsi_descriptor_t *dvbpsi_BATBouquetAddDescriptor(
if (p_descriptor == NULL) if (p_descriptor == NULL)
return NULL; return NULL;
p_bat->p_first_descriptor = dvbpsi_AddDescriptor(p_bat->p_first_descriptor,
p_descriptor);
assert(p_bat->p_first_descriptor);
if (p_bat->p_first_descriptor == NULL) if (p_bat->p_first_descriptor == NULL)
p_bat->p_first_descriptor = p_descriptor; return NULL;
else
{
dvbpsi_descriptor_t * p_last_descriptor = p_bat->p_first_descriptor;
while(p_last_descriptor->p_next != NULL)
p_last_descriptor = p_last_descriptor->p_next;
p_last_descriptor->p_next = p_descriptor;
}
return p_descriptor; return p_descriptor;
} }
......
...@@ -159,15 +159,12 @@ dvbpsi_descriptor_t* dvbpsi_CATAddDescriptor(dvbpsi_cat_t* p_cat, ...@@ -159,15 +159,12 @@ dvbpsi_descriptor_t* dvbpsi_CATAddDescriptor(dvbpsi_cat_t* p_cat,
if (p_descriptor == NULL) if (p_descriptor == NULL)
return NULL; return NULL;
p_cat->p_first_descriptor = dvbpsi_AddDescriptor(p_cat->p_first_descriptor,
p_descriptor);
assert(p_cat->p_first_descriptor);
if (p_cat->p_first_descriptor == NULL) if (p_cat->p_first_descriptor == NULL)
p_cat->p_first_descriptor = p_descriptor; return NULL;
else
{
dvbpsi_descriptor_t* p_last_descriptor = p_cat->p_first_descriptor;
while(p_last_descriptor->p_next != NULL)
p_last_descriptor = p_last_descriptor->p_next;
p_last_descriptor->p_next = p_descriptor;
}
return p_descriptor; return p_descriptor;
} }
......
...@@ -238,7 +238,7 @@ dvbpsi_eit_event_t* dvbpsi_EITAddEvent(dvbpsi_eit_t* p_eit, ...@@ -238,7 +238,7 @@ dvbpsi_eit_event_t* dvbpsi_EITAddEvent(dvbpsi_eit_t* p_eit,
***************************************************************************** *****************************************************************************
* Add a descriptor in the EIT event description. * Add a descriptor in the EIT event description.
*****************************************************************************/ *****************************************************************************/
dvbpsi_descriptor_t* dvbpsi_EITEventAddDescriptor( dvbpsi_eit_event_t* p_event, dvbpsi_descriptor_t* dvbpsi_EITEventAddDescriptor(dvbpsi_eit_event_t* p_event,
uint8_t i_tag, uint8_t i_length, uint8_t* p_data) uint8_t i_tag, uint8_t i_length, uint8_t* p_data)
{ {
dvbpsi_descriptor_t* p_descriptor; dvbpsi_descriptor_t* p_descriptor;
...@@ -246,15 +246,12 @@ dvbpsi_descriptor_t* dvbpsi_EITEventAddDescriptor( dvbpsi_eit_event_t* p_event, ...@@ -246,15 +246,12 @@ dvbpsi_descriptor_t* dvbpsi_EITEventAddDescriptor( dvbpsi_eit_event_t* p_event,
if (p_descriptor == NULL) if (p_descriptor == NULL)
return NULL; return NULL;
p_event->p_first_descriptor = dvbpsi_AddDescriptor(p_event->p_first_descriptor,
p_descriptor);
assert(p_event->p_first_descriptor);
if (p_event->p_first_descriptor == NULL) if (p_event->p_first_descriptor == NULL)
p_event->p_first_descriptor = p_descriptor; return NULL;
else
{
dvbpsi_descriptor_t* p_last_descriptor = p_event->p_first_descriptor;
while(p_last_descriptor->p_next != NULL)
p_last_descriptor = p_last_descriptor->p_next;
p_last_descriptor->p_next = p_descriptor;
}
return p_descriptor; return p_descriptor;
} }
......
...@@ -265,15 +265,12 @@ dvbpsi_descriptor_t* dvbpsi_NITTSAddDescriptor(dvbpsi_nit_ts_t* p_ts, ...@@ -265,15 +265,12 @@ dvbpsi_descriptor_t* dvbpsi_NITTSAddDescriptor(dvbpsi_nit_ts_t* p_ts,
if (p_descriptor == NULL) if (p_descriptor == NULL)
return NULL; return NULL;
p_ts->p_first_descriptor = dvbpsi_AddDescriptor(p_ts->p_first_descriptor,
p_descriptor);
assert(p_ts->p_first_descriptor);
if (p_ts->p_first_descriptor == NULL) if (p_ts->p_first_descriptor == NULL)
p_ts->p_first_descriptor = p_descriptor; return NULL;
else
{
dvbpsi_descriptor_t* p_last_descriptor = p_ts->p_first_descriptor;
while(p_last_descriptor->p_next != NULL)
p_last_descriptor = p_last_descriptor->p_next;
p_last_descriptor->p_next = p_descriptor;
}
return p_descriptor; return p_descriptor;
} }
......
...@@ -177,15 +177,12 @@ dvbpsi_descriptor_t* dvbpsi_PMTAddDescriptor(dvbpsi_pmt_t* p_pmt, ...@@ -177,15 +177,12 @@ dvbpsi_descriptor_t* dvbpsi_PMTAddDescriptor(dvbpsi_pmt_t* p_pmt,
if (p_descriptor == NULL) if (p_descriptor == NULL)
return NULL; return NULL;
p_pmt->p_first_descriptor = dvbpsi_AddDescriptor(p_pmt->p_first_descriptor,
p_descriptor);
assert(p_pmt->p_first_descriptor);
if (p_pmt->p_first_descriptor == NULL) if (p_pmt->p_first_descriptor == NULL)
p_pmt->p_first_descriptor = p_descriptor; return NULL;
else
{
dvbpsi_descriptor_t* p_last_descriptor = p_pmt->p_first_descriptor;
while(p_last_descriptor->p_next != NULL)
p_last_descriptor = p_last_descriptor->p_next;
p_last_descriptor->p_next = p_descriptor;
}
return p_descriptor; return p_descriptor;
} }
......
...@@ -247,15 +247,12 @@ dvbpsi_descriptor_t *dvbpsi_SDTServiceAddDescriptor( ...@@ -247,15 +247,12 @@ dvbpsi_descriptor_t *dvbpsi_SDTServiceAddDescriptor(
if (p_descriptor == NULL) if (p_descriptor == NULL)
return NULL; return NULL;
p_service->p_first_descriptor = dvbpsi_AddDescriptor(p_service->p_first_descriptor,
p_descriptor);
assert(p_service->p_first_descriptor);
if (p_service->p_first_descriptor == NULL) if (p_service->p_first_descriptor == NULL)
p_service->p_first_descriptor = p_descriptor; return NULL;
else
{
dvbpsi_descriptor_t * p_last_descriptor = p_service->p_first_descriptor;
while(p_last_descriptor->p_next != NULL)
p_last_descriptor = p_last_descriptor->p_next;
p_last_descriptor->p_next = p_descriptor;
}
return p_descriptor; return p_descriptor;
} }
......
...@@ -227,15 +227,12 @@ dvbpsi_descriptor_t *dvbpsi_SISAddDescriptor(dvbpsi_sis_t *p_sis, ...@@ -227,15 +227,12 @@ dvbpsi_descriptor_t *dvbpsi_SISAddDescriptor(dvbpsi_sis_t *p_sis,
if (p_descriptor == NULL) if (p_descriptor == NULL)
return NULL; return NULL;
p_sis->p_first_descriptor = dvbpsi_AddDescriptor(p_sis->p_first_descriptor,
p_descriptor);
assert(p_sis->p_first_descriptor);
if (p_sis->p_first_descriptor == NULL) if (p_sis->p_first_descriptor == NULL)
p_sis->p_first_descriptor = p_descriptor; return NULL;
else
{
dvbpsi_descriptor_t *p_last_descriptor = p_sis->p_first_descriptor;
while (p_last_descriptor->p_next != NULL)
p_last_descriptor = p_last_descriptor->p_next;
p_last_descriptor->p_next = p_descriptor;
}
return p_descriptor; return p_descriptor;
} }
......
...@@ -207,15 +207,12 @@ dvbpsi_descriptor_t* dvbpsi_TOTAddDescriptor(dvbpsi_tot_t* p_tot, ...@@ -207,15 +207,12 @@ dvbpsi_descriptor_t* dvbpsi_TOTAddDescriptor(dvbpsi_tot_t* p_tot,
if (p_descriptor == NULL) if (p_descriptor == NULL)
return NULL; return NULL;
p_tot->p_first_descriptor = dvbpsi_AddDescriptor(p_tot->p_first_descriptor,
p_descriptor);
assert(p_tot->p_first_descriptor);
if (p_tot->p_first_descriptor == NULL) if (p_tot->p_first_descriptor == NULL)
p_tot->p_first_descriptor = p_descriptor; return NULL;
else
{
dvbpsi_descriptor_t* p_last_descriptor = p_tot->p_first_descriptor;
while(p_last_descriptor->p_next != NULL)
p_last_descriptor = p_last_descriptor->p_next;
p_last_descriptor->p_next = p_descriptor;
}
return p_descriptor; return p_descriptor;
} }
......
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