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

descriptors: implement some helper functions

- add dvbpsi_CanDecodeAsDescriptor() helper function
- add dvbpsi_IsDescriptorDecoded() helper function
- update descriptors
parent 2d8ba47b
......@@ -39,6 +39,41 @@
#include "dvbpsi.h"
#include "descriptor.h"
/*****************************************************************************
* dvbpsi_IsDescriptor
*****************************************************************************
* Is this descriptor of type i_tag?
*****************************************************************************/
static inline bool dvbpsi_IsDescriptor(dvbpsi_descriptor_t *p_descriptor, const uint8_t i_tag)
{
return (p_descriptor->i_tag == i_tag);
}
/*****************************************************************************
* IsDescriptorDecoded
*****************************************************************************
* Is this descriptor already decoded?
*****************************************************************************/
bool dvbpsi_IsDescriptorDecoded(dvbpsi_descriptor_t *p_descriptor)
{
return (p_descriptor->p_decoded != NULL);
}
/*****************************************************************************
* dvbpsi_CanDescodeAsDescriptor
*****************************************************************************
* Can Decode this descriptor as?
*****************************************************************************/
bool dvbpsi_CanDecodeAsDescriptor(dvbpsi_descriptor_t *p_descriptor, const uint8_t i_tag)
{
if (!p_descriptor)
return false;
if (!dvbpsi_IsDescriptor(p_descriptor, i_tag))
return false;
return true;
}
/*****************************************************************************
* dvbpsi_NewDescriptor
......
......@@ -68,7 +68,6 @@ typedef struct dvbpsi_descriptor_s
} dvbpsi_descriptor_t;
/*****************************************************************************
* dvbpsi_NewDescriptor
*****************************************************************************/
......@@ -97,6 +96,28 @@ dvbpsi_descriptor_t* dvbpsi_NewDescriptor(uint8_t i_tag, uint8_t i_length,
*/
void dvbpsi_DeleteDescriptors(dvbpsi_descriptor_t* p_descriptor);
/*****************************************************************************
* dvbpsi_CanDecodeAsDescriptor
*****************************************************************************/
/*!
* \fn bool dvbpsi_CanDecodeAsDescriptor(dvbpsi_descriptor_t *p_descriptor, const uint8_t i_tag);
* \brief Checks if descriptor tag matches.
* \param p_descriptor pointer to descriptor allocated with @see dvbpsi_NewDescriptor
* \param i_tag descriptor tag to evaluate against
* \return true if descriptor can be decoded, false if not.
*/
bool dvbpsi_CanDecodeAsDescriptor(dvbpsi_descriptor_t *p_descriptor, const uint8_t i_tag);
/*****************************************************************************
* dvbpsi_IsDescriptorDecoded
*****************************************************************************/
/*!
* \fn bool dvbpsi_IsDescriptorDecoded(dvbpsi_descriptor_t *p_descriptor);
* \brief Checks if descriptor was already decoded.
* \param p_descriptor pointer to descriptor allocated with @see dvbpsi_NewDescriptor
* \return true if descriptor can be decoded, false if already decoded.
*/
bool dvbpsi_IsDescriptorDecoded(dvbpsi_descriptor_t *p_descriptor);
#ifdef __cplusplus
};
......
......@@ -48,11 +48,11 @@ dvbpsi_vstream_dr_t * dvbpsi_DecodeVStreamDr(dvbpsi_descriptor_t * p_descriptor)
dvbpsi_vstream_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x02)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x02))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -49,11 +49,11 @@ dvbpsi_astream_dr_t * dvbpsi_DecodeAStreamDr(dvbpsi_descriptor_t * p_descriptor)
dvbpsi_astream_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x03)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x03))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......@@ -67,10 +67,10 @@ dvbpsi_astream_dr_t * dvbpsi_DecodeAStreamDr(dvbpsi_descriptor_t * p_descriptor)
return NULL;
}
p_decoded->b_free_format = (p_descriptor->p_data[0] & 0x80);
p_decoded->b_free_format = (p_descriptor->p_data[0] & 0x80) ? true : false;
p_decoded->i_id = (p_descriptor->p_data[0] & 0x40) >> 6;
p_decoded->i_layer = (p_descriptor->p_data[0] & 0x30) >> 4;
p_decoded->b_variable_rate_audio_indicator = (p_descriptor->p_data[0] & 0x08) >> 3;
p_decoded->b_variable_rate_audio_indicator = ((p_descriptor->p_data[0] & 0x08) >> 3) ? true : false;
p_descriptor->p_decoded = (void*)p_decoded;
......
......@@ -50,11 +50,11 @@ dvbpsi_hierarchy_dr_t * dvbpsi_DecodeHierarchyDr(
dvbpsi_hierarchy_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x04)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x04))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -50,11 +50,11 @@ dvbpsi_registration_dr_t * dvbpsi_DecodeRegistrationDr(
dvbpsi_registration_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x05)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x05))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -50,13 +50,9 @@ dvbpsi_ds_alignment_dr_t * dvbpsi_DecodeDSAlignmentDr(
dvbpsi_ds_alignment_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x06)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x06))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
return p_descriptor->p_decoded;
/* Allocate memory */
p_decoded = (dvbpsi_ds_alignment_dr_t*)
malloc(sizeof(dvbpsi_ds_alignment_dr_t));
......
......@@ -50,11 +50,11 @@ dvbpsi_target_bg_grid_dr_t * dvbpsi_DecodeTargetBgGridDr(
dvbpsi_target_bg_grid_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x07)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x07))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -49,11 +49,11 @@ dvbpsi_vwindow_dr_t * dvbpsi_DecodeVWindowDr(dvbpsi_descriptor_t * p_descriptor)
dvbpsi_vwindow_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x08)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x08))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -49,11 +49,11 @@ dvbpsi_ca_dr_t * dvbpsi_DecodeCADr(dvbpsi_descriptor_t * p_descriptor)
dvbpsi_ca_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x09)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x09))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -50,11 +50,11 @@ dvbpsi_iso639_dr_t * dvbpsi_DecodeISO639Dr(dvbpsi_descriptor_t * p_descriptor)
int i;
/* Check the tag */
if(p_descriptor->i_tag != 0x0a)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x0a))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -50,11 +50,11 @@ dvbpsi_system_clock_dr_t * dvbpsi_DecodeSystemClockDr(
dvbpsi_system_clock_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x0b)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x0b))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -50,11 +50,11 @@ dvbpsi_mx_buff_utilization_dr_t * dvbpsi_DecodeMxBuffUtilizationDr(
dvbpsi_mx_buff_utilization_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x0c)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x0c))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -50,11 +50,11 @@ dvbpsi_copyright_dr_t * dvbpsi_DecodeCopyrightDr(
dvbpsi_copyright_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x0d)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x0d))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -50,11 +50,11 @@ dvbpsi_max_bitrate_dr_t * dvbpsi_DecodeMaxBitrateDr(
dvbpsi_max_bitrate_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x0e)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x0e))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -50,11 +50,11 @@ dvbpsi_private_data_dr_t * dvbpsi_DecodePrivateDataDr(
dvbpsi_private_data_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x0f)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x0f))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -48,11 +48,11 @@ dvbpsi_network_name_dr_t* dvbpsi_DecodeNetworkNameDr(
dvbpsi_network_name_dr_t * p_decoded;
/* Check the tag */
if (p_descriptor->i_tag != 0x40)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x40))
return NULL;
/* Don't decode twice */
if (p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -51,11 +51,11 @@ dvbpsi_stuffing_dr_t * dvbpsi_DecodeStuffingDr(
dvbpsi_stuffing_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x42)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x42))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -50,11 +50,11 @@ dvbpsi_sat_deliv_sys_dr_t * dvbpsi_DecodeSatDelivSysDr(
dvbpsi_sat_deliv_sys_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x43)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x43))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -50,11 +50,11 @@ dvbpsi_cable_deliv_sys_dr_t * dvbpsi_DecodeCableDelivSysDr(
dvbpsi_cable_deliv_sys_dr_t * p_decoded;
/* Check the tag */
if (p_descriptor->i_tag != 0x44)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x44))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -50,11 +50,11 @@ dvbpsi_vbi_dr_t * dvbpsi_DecodeVBIDataDr(
dvbpsi_vbi_dr_t * p_decoded;
/* Check the tag */
if( p_descriptor->i_tag != 0x45 )
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x45))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Decode data and check the length */
......
......@@ -51,11 +51,11 @@ dvbpsi_bouquet_name_dr_t * dvbpsi_DecodeBouquetNameDr(
dvbpsi_bouquet_name_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x47)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x47))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -51,11 +51,11 @@ dvbpsi_service_dr_t * dvbpsi_DecodeServiceDr(
dvbpsi_service_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x48)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x48))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -50,10 +50,14 @@ dvbpsi_short_event_dr_t * dvbpsi_DecodeShortEventDr(dvbpsi_descriptor_t * p_desc
int i_len2;
/* Check the tag */
if(p_descriptor->i_tag != 0x4d ||
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x4d) ||
p_descriptor->i_length < 5 )
return NULL;
/* Don't decode twice */
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Check length */
i_len1 = p_descriptor->p_data[3];
i_len2 = p_descriptor->p_data[4+i_len1];
......
......@@ -51,12 +51,12 @@ dvbpsi_extended_event_dr_t * dvbpsi_DecodeExtendedEventDr(dvbpsi_descriptor_t *
uint8_t *p;
/* Check the tag */
if(p_descriptor->i_tag != 0x4e ||
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x4e) ||
p_descriptor->i_length < 6 )
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -49,11 +49,11 @@ dvbpsi_stream_identifier_dr_t * dvbpsi_DecodeStreamIdentifierDr(
dvbpsi_stream_identifier_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x52)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x52))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -51,11 +51,11 @@ dvbpsi_parental_rating_dr_t * dvbpsi_DecodeParentalRatingDr(
dvbpsi_parental_rating_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x55)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x55))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -50,11 +50,12 @@ dvbpsi_teletext_dr_t * dvbpsi_DecodeTeletextDr(
dvbpsi_teletext_dr_t * p_decoded;
/* Check the tag */
if( (p_descriptor->i_tag != 0x56) && (p_descriptor->i_tag != 0x46) )
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x56) &&
!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x46))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Decode data and check the length */
......
......@@ -52,11 +52,11 @@ dvbpsi_local_time_offset_dr_t * dvbpsi_DecodeLocalTimeOffsetDr(
dvbpsi_local_time_offset_t * p_current;
/* Check the tag */
if(p_descriptor->i_tag != 0x58)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x58))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -52,13 +52,17 @@ dvbpsi_subtitling_dr_t * dvbpsi_DecodeSubtitlingDr(
dvbpsi_subtitling_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x59)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x59))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Decode data and check the length */
if(p_descriptor->i_length < 3)
return NULL;
/* Allocate memory */
p_decoded =
(dvbpsi_subtitling_dr_t*)malloc(sizeof(dvbpsi_subtitling_dr_t));
......
......@@ -50,11 +50,11 @@ dvbpsi_terr_deliv_sys_dr_t * dvbpsi_DecodeTerrDelivSysDr(
dvbpsi_terr_deliv_sys_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x5a)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x5a))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
......@@ -49,14 +49,14 @@ dvbpsi_PDC_dr_t * dvbpsi_DecodePDCDr(dvbpsi_descriptor_t * p_descriptor)
dvbpsi_PDC_dr_t * p_decoded;
/* Check the tag */
if(p_descriptor->i_tag != 0x69)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x69))
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Decode data and check the length */
/* Check the length */
if( p_descriptor->i_length != 3)
return NULL;
......
......@@ -48,11 +48,11 @@ dvbpsi_cuei_dr_t * dvbpsi_DecodeCUEIDr(dvbpsi_descriptor_t * p_descriptor)
dvbpsi_cuei_dr_t *p_decoded;
/* Check the tag */
if (p_descriptor->i_tag != 0x8a)
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x8a))
return NULL;
/* Don't decode twice */
if (p_descriptor->p_decoded)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
......
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