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

descriptors: refactor and cleanup

- dvbpsi_Decode*() first check length then allocate memory
- dvbpsi_Gen*() refactor
parent 4a7ee37e
......@@ -96,37 +96,36 @@ dvbpsi_descriptor_t * dvbpsi_GenVStreamDr(dvbpsi_vstream_dr_t * p_decoded,
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x02, p_decoded->b_mpeg2 ? 3 : 1, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] = 0;
if(p_decoded->b_multiple_frame_rate)
if (p_decoded->b_multiple_frame_rate)
p_descriptor->p_data[0] |= 0x80;
p_descriptor->p_data[0] |= (p_decoded->i_frame_rate_code & 0x0f) << 3;
if(p_decoded->b_constrained_parameter)
if (p_decoded->b_constrained_parameter)
p_descriptor->p_data[0] |= 0x02;
if(p_decoded->b_still_picture)
if (p_decoded->b_still_picture)
p_descriptor->p_data[0] |= 0x01;
if(p_decoded->b_mpeg2)
if (p_decoded->b_mpeg2)
{
p_descriptor->p_data[0] |= 0x04;
p_descriptor->p_data[1] = p_decoded->i_profile_level_indication;
p_descriptor->p_data[2] = 0x1f;
p_descriptor->p_data[2] |= (p_decoded->i_chroma_format & 0x03) << 6;
if(p_decoded->b_frame_rate_extension)
if (p_decoded->b_frame_rate_extension)
p_descriptor->p_data[2] |= 0x20;
}
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_vstream_dr_t));
}
}
return p_descriptor;
}
......@@ -81,31 +81,30 @@ dvbpsi_astream_dr_t * dvbpsi_DecodeAStreamDr(dvbpsi_descriptor_t * p_descriptor)
/*****************************************************************************
* dvbpsi_GenAStreamDr
*****************************************************************************/
dvbpsi_descriptor_t * dvbpsi_GenAStreamDr(dvbpsi_astream_dr_t * p_decoded,
dvbpsi_descriptor_t *dvbpsi_GenAStreamDr(dvbpsi_astream_dr_t * p_decoded,
bool b_duplicate)
{
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(0x03, 1, NULL);
dvbpsi_descriptor_t *p_descriptor = dvbpsi_NewDescriptor(0x03, 1, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
*p_descriptor->p_data = 0x0f;
if(p_decoded->b_free_format)
if (p_decoded->b_free_format)
*p_descriptor->p_data |= 0x80;
*p_descriptor->p_data |= (p_decoded->i_id & 0x01) << 6;
*p_descriptor->p_data |= (p_decoded->i_layer & 0x03) << 4;
if(p_decoded->b_variable_rate_audio_indicator)
if (p_decoded->b_variable_rate_audio_indicator)
*p_descriptor->p_data |= 0x08;
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_astream_dr_t));
}
}
return p_descriptor;
}
......
......@@ -87,23 +87,22 @@ dvbpsi_descriptor_t * dvbpsi_GenHierarchyDr(dvbpsi_hierarchy_dr_t * p_decoded,
{
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(0x04, 4, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] = 0xf0 | p_decoded->i_h_type;
p_descriptor->p_data[1] = 0xc0 | p_decoded->i_h_layer_index;
p_descriptor->p_data[2] = 0xc0 | p_decoded->i_h_embedded_layer;
p_descriptor->p_data[3] = 0xc0 | p_decoded->i_h_priority;
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_hierarchy_dr_t));
}
}
return p_descriptor;
}
......
......@@ -96,26 +96,26 @@ dvbpsi_descriptor_t * dvbpsi_GenRegistrationDr(
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x05, p_decoded->i_additional_length + 4, NULL);
if(p_descriptor)
{
if (!p_descriptor)
return NULL;
/* Encode data */
p_descriptor->p_data[0] = p_decoded->i_format_identifier >> 24;
p_descriptor->p_data[1] = p_decoded->i_format_identifier >> 16;
p_descriptor->p_data[2] = p_decoded->i_format_identifier >> 8;
p_descriptor->p_data[3] = p_decoded->i_format_identifier;
if(p_decoded->i_additional_length)
if (p_decoded->i_additional_length)
memcpy(p_descriptor->p_data + 4,
p_decoded->i_additional_info,
p_decoded->i_additional_length);
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_registration_dr_t));
}
}
return p_descriptor;
}
......
......@@ -53,17 +53,16 @@ dvbpsi_ds_alignment_dr_t * dvbpsi_DecodeDSAlignmentDr(
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x06))
return NULL;
/* Allocate memory */
p_decoded = (dvbpsi_ds_alignment_dr_t*)
malloc(sizeof(dvbpsi_ds_alignment_dr_t));
if(!p_decoded) return NULL;
/* Don't decode twice */
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Decode data and check the length */
if(p_descriptor->i_length != 1)
{
free(p_decoded);
if (p_descriptor->i_length != 1)
return NULL;
}
/* Allocate memory */
p_decoded = (dvbpsi_ds_alignment_dr_t*) malloc(sizeof(dvbpsi_ds_alignment_dr_t));
if(!p_decoded) return NULL;
p_decoded->i_alignment_type = p_descriptor->p_data[0];
......@@ -82,22 +81,18 @@ dvbpsi_descriptor_t * dvbpsi_GenDSAlignmentDr(
{
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(0x06, 1, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] = p_decoded->i_alignment_type;
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
dvbpsi_ds_alignment_dr_t * p_dup_decoded =
(dvbpsi_ds_alignment_dr_t*)malloc(sizeof(dvbpsi_ds_alignment_dr_t));
if(p_dup_decoded)
memcpy(p_dup_decoded, p_decoded, sizeof(dvbpsi_ds_alignment_dr_t));
p_descriptor->p_decoded = (void*)p_dup_decoded;
}
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_ds_alignment_dr_t));
}
return p_descriptor;
......
......@@ -57,17 +57,13 @@ dvbpsi_target_bg_grid_dr_t * dvbpsi_DecodeTargetBgGridDr(
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
p_decoded = (dvbpsi_target_bg_grid_dr_t*)
malloc(sizeof(dvbpsi_target_bg_grid_dr_t));
if(!p_decoded) return NULL;
if (p_descriptor->i_length != 4)
return NULL;
/* Decode data and check the length */
if(p_descriptor->i_length != 4)
{
free(p_decoded);
/* Allocate memory */
p_decoded = (dvbpsi_target_bg_grid_dr_t*) malloc(sizeof(dvbpsi_target_bg_grid_dr_t));
if (!p_decoded)
return NULL;
}
p_decoded->i_horizontal_size = ((uint16_t)(p_descriptor->p_data[0]) << 6)
| ((p_descriptor->p_data[1] & 0xfc) >> 2);
......@@ -92,9 +88,9 @@ dvbpsi_descriptor_t * dvbpsi_GenTargetBgGridDr(
{
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(0x07, 4, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] = p_decoded->i_horizontal_size >> 6;
p_descriptor->p_data[1] = (((uint8_t)p_decoded->i_horizontal_size) << 2)
......@@ -103,14 +99,13 @@ dvbpsi_descriptor_t * dvbpsi_GenTargetBgGridDr(
p_descriptor->p_data[3] = (((uint8_t)p_decoded->i_vertical_size) << 4)
| (p_decoded->i_pel_aspect_ratio & 0x0f);
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_target_bg_grid_dr_t));
}
}
return p_descriptor;
}
......
......@@ -56,16 +56,13 @@ dvbpsi_vwindow_dr_t * dvbpsi_DecodeVWindowDr(dvbpsi_descriptor_t * p_descriptor)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
if (p_descriptor->i_length != 4)
return NULL;
/* Allocate memory */
p_decoded = (dvbpsi_vwindow_dr_t*)malloc(sizeof(dvbpsi_vwindow_dr_t));
if(!p_decoded) return NULL;
/* Decode data and check the length */
if(p_descriptor->i_length != 4)
{
free(p_decoded);
if (!p_decoded)
return NULL;
}
p_decoded->i_horizontal_offset = ((uint16_t)(p_descriptor->p_data[0]) << 6)
| ((p_descriptor->p_data[1] & 0xfc) >> 2);
......@@ -90,8 +87,9 @@ dvbpsi_descriptor_t * dvbpsi_GenVWindowDr(dvbpsi_vwindow_dr_t * p_decoded,
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(0x08, 4, NULL);
if(p_descriptor)
{
if (!p_descriptor)
return NULL;
/* Encode data */
p_descriptor->p_data[0] = p_decoded->i_horizontal_offset >> 6;
p_descriptor->p_data[1] = (((uint8_t)p_decoded->i_horizontal_offset) << 2)
......@@ -100,14 +98,13 @@ dvbpsi_descriptor_t * dvbpsi_GenVWindowDr(dvbpsi_vwindow_dr_t * p_decoded,
p_descriptor->p_data[3] = (((uint8_t)p_decoded->i_vertical_offset) << 4)
| (p_decoded->i_window_priority & 0x0f);
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_vwindow_dr_t));
}
}
return p_descriptor;
}
......
......@@ -56,23 +56,20 @@ dvbpsi_ca_dr_t * dvbpsi_DecodeCADr(dvbpsi_descriptor_t * p_descriptor)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
if (p_descriptor->i_length < 4)
return NULL;
/* Allocate memory */
p_decoded = (dvbpsi_ca_dr_t*)malloc(sizeof(dvbpsi_ca_dr_t));
if(!p_decoded) return NULL;
/* Decode data and check the length */
if(p_descriptor->i_length < 4)
{
free(p_decoded);
if (!p_decoded)
return NULL;
}
p_decoded->i_ca_system_id = ((uint16_t)(p_descriptor->p_data[0]) << 8)
| p_descriptor->p_data[1];
p_decoded->i_ca_pid = ((uint16_t)(p_descriptor->p_data[2] & 0x1f) << 8)
| p_descriptor->p_data[3];
p_decoded->i_private_length = p_descriptor->i_length - 4;
if(p_decoded->i_private_length)
if (p_decoded->i_private_length)
memcpy(p_decoded->i_private_data,
p_descriptor->p_data + 4,
p_decoded->i_private_length);
......@@ -82,7 +79,6 @@ dvbpsi_ca_dr_t * dvbpsi_DecodeCADr(dvbpsi_descriptor_t * p_descriptor)
return p_decoded;
}
/*****************************************************************************
* dvbpsi_GenCADr
*****************************************************************************/
......@@ -92,28 +88,26 @@ dvbpsi_descriptor_t * dvbpsi_GenCADr(dvbpsi_ca_dr_t * p_decoded,
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x09, p_decoded->i_private_length + 4, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] = p_decoded->i_ca_system_id >> 8;
p_descriptor->p_data[1] = p_decoded->i_ca_system_id;
p_descriptor->p_data[2] = 0xe0 | ((p_decoded->i_ca_pid >> 8) & 0x1f);
p_descriptor->p_data[3] = p_decoded->i_ca_pid;
if(p_decoded->i_private_length)
if (p_decoded->i_private_length)
memcpy(p_descriptor->p_data + 4,
p_decoded->i_private_data,
p_decoded->i_private_length);
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_ca_dr_t));
}
}
return p_descriptor;
}
......@@ -47,7 +47,6 @@
dvbpsi_iso639_dr_t * dvbpsi_DecodeISO639Dr(dvbpsi_descriptor_t * p_descriptor)
{
dvbpsi_iso639_dr_t * p_decoded;
int i;
/* Check the tag */
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x0a))
......@@ -57,20 +56,20 @@ dvbpsi_iso639_dr_t * dvbpsi_DecodeISO639Dr(dvbpsi_descriptor_t * p_descriptor)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
if ((p_descriptor->i_length < 1) ||
(p_descriptor->i_length % 4 != 0))
return NULL;
/* Allocate memory */
p_decoded = (dvbpsi_iso639_dr_t*)malloc(sizeof(dvbpsi_iso639_dr_t));
if(!p_decoded) return NULL;
/* Decode data and check the length */
if((p_descriptor->i_length < 1) || (p_descriptor->i_length % 4 != 0))
{
free(p_decoded);
if (!p_decoded)
return NULL;
}
p_decoded->i_code_count = p_descriptor->i_length / 4;
i = 0;
while( i < p_decoded->i_code_count ) {
int i = 0;
while( i < p_decoded->i_code_count )
{
p_decoded->code[i].iso_639_code[0] = p_descriptor->p_data[i*4];
p_decoded->code[i].iso_639_code[1] = p_descriptor->p_data[i*4+1];
p_decoded->code[i].iso_639_code[2] = p_descriptor->p_data[i*4+2];
......@@ -92,26 +91,27 @@ dvbpsi_descriptor_t * dvbpsi_GenISO639Dr(dvbpsi_iso639_dr_t * p_decoded,
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x0a, p_decoded->i_code_count * 4, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
int i = 0;
while( i < p_decoded->i_code_count ) {
while( i < p_decoded->i_code_count )
{
p_descriptor->p_data[i*4] = p_decoded->code[i].iso_639_code[0];
p_descriptor->p_data[i*4+1] = p_decoded->code[i].iso_639_code[1];
p_descriptor->p_data[i*4+2] = p_decoded->code[i].iso_639_code[2];
p_descriptor->p_data[i*4+3] = p_decoded->code[i].i_audio_type;
i++;
}
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_iso639_dr_t));
}
}
return p_descriptor;
}
......
......@@ -57,17 +57,15 @@ dvbpsi_system_clock_dr_t * dvbpsi_DecodeSystemClockDr(
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Check the length */
if (p_descriptor->i_length != 2)
return NULL;
/* Allocate memory */
p_decoded =
(dvbpsi_system_clock_dr_t*)malloc(sizeof(dvbpsi_system_clock_dr_t));
if(!p_decoded) return NULL;
/* Decode data and check the length */
if(p_descriptor->i_length != 2)
{
free(p_decoded);
if (!p_decoded)
return NULL;
}
p_decoded->b_external_clock_ref = (p_descriptor->p_data[0] & 0x80) ? true : false;
p_decoded->i_clock_accuracy_integer = p_descriptor->p_data[0] & 0x3f;
......@@ -78,7 +76,6 @@ dvbpsi_system_clock_dr_t * dvbpsi_DecodeSystemClockDr(
return p_decoded;
}
/*****************************************************************************
* dvbpsi_GenSystemClockDr
*****************************************************************************/
......@@ -89,25 +86,23 @@ dvbpsi_descriptor_t * dvbpsi_GenSystemClockDr(
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x0b, 2, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] =
0x40 | (p_decoded->i_clock_accuracy_integer & 0x3f);
if(p_decoded->b_external_clock_ref)
if (p_decoded->b_external_clock_ref)
p_descriptor->p_data[0] |= 0x80;
p_descriptor->p_data[1] = 0x1f | p_decoded->i_clock_accuracy_exponent << 5;
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_system_clock_dr_t));
}
}
return p_descriptor;
}
......@@ -57,17 +57,14 @@ dvbpsi_mx_buff_utilization_dr_t * dvbpsi_DecodeMxBuffUtilizationDr(
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
if (p_descriptor->i_length != 3)
return NULL;
/* Allocate memory */
p_decoded = (dvbpsi_mx_buff_utilization_dr_t*)
malloc(sizeof(dvbpsi_mx_buff_utilization_dr_t));
if(!p_decoded) return NULL;
/* Decode data and check the length */
if(p_descriptor->i_length != 3)
{
free(p_decoded);
if (!p_decoded)
return NULL;
}
p_decoded->b_mdv_valid = (p_descriptor->p_data[0] & 0x80) ? true : false;
p_decoded->i_mx_delay_variation =
......@@ -89,11 +86,10 @@ dvbpsi_descriptor_t * dvbpsi_GenMxBuffUtilizationDr(
bool b_duplicate)
{
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x0c, 3, NULL);
dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(0x0c, 3, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] = (p_decoded->i_mx_delay_variation >> 8) & 0x7f;
if(p_decoded->b_mdv_valid)
......@@ -101,14 +97,13 @@ dvbpsi_descriptor_t * dvbpsi_GenMxBuffUtilizationDr(
p_descriptor->p_data[1] = p_decoded->i_mx_delay_variation;
p_descriptor->p_data[2] = 0x1f | p_decoded->i_mx_strategy << 5;
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_mx_buff_utilization_dr_t));
}
}
return p_descriptor;
}
......
......@@ -57,17 +57,14 @@ dvbpsi_copyright_dr_t * dvbpsi_DecodeCopyrightDr(
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
if (p_descriptor->i_length < 4)
return NULL;
/* Allocate memory */
p_decoded = (dvbpsi_copyright_dr_t*)
malloc(sizeof(dvbpsi_copyright_dr_t));
if(!p_decoded) return NULL;
/* Decode data and check the length */
if(p_descriptor->i_length < 4)
{
free(p_decoded);
if (!p_decoded)
return NULL;
}
p_decoded->i_copyright_identifier =
((uint32_t)(p_descriptor->p_data[0]) << 24)
......@@ -75,7 +72,7 @@ dvbpsi_copyright_dr_t * dvbpsi_DecodeCopyrightDr(
| ((uint32_t)(p_descriptor->p_data[2]) << 8)
| (uint32_t)(p_descriptor->p_data[3]);
p_decoded->i_additional_length = p_descriptor->i_length - 4;
if(p_decoded->i_additional_length)
if (p_decoded->i_additional_length)
memcpy(p_decoded->i_additional_info,
p_descriptor->p_data + 4,
p_decoded->i_additional_length);
......@@ -96,9 +93,9 @@ dvbpsi_descriptor_t * dvbpsi_GenCopyrightDr(
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x0d, p_decoded->i_additional_length + 4, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] = p_decoded->i_copyright_identifier >> 24;
p_descriptor->p_data[1] = p_decoded->i_copyright_identifier >> 16;
......@@ -109,14 +106,13 @@ dvbpsi_descriptor_t * dvbpsi_GenCopyrightDr(
p_decoded->i_additional_info,
p_decoded->i_additional_length);
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_copyright_dr_t));
}
}
return p_descriptor;
}
......
......@@ -57,16 +57,13 @@ dvbpsi_max_bitrate_dr_t * dvbpsi_DecodeMaxBitrateDr(
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
if (p_descriptor->i_length != 3)
return NULL;
/* Allocate memory */
p_decoded = (dvbpsi_max_bitrate_dr_t*)malloc(sizeof(dvbpsi_max_bitrate_dr_t));
if(!p_decoded) return NULL;
/* Decode data and check the length */
if(p_descriptor->i_length != 3)
{
free(p_decoded);
if (!p_decoded)
return NULL;
}
p_decoded->i_max_bitrate =
((uint32_t)(p_descriptor->p_data[0] & 0x3f) << 16)
......@@ -78,7 +75,6 @@ dvbpsi_max_bitrate_dr_t * dvbpsi_DecodeMaxBitrateDr(
return p_decoded;
}
/*****************************************************************************
* dvbpsi_GenMaxBitrateDr
*****************************************************************************/
......@@ -87,25 +83,22 @@ dvbpsi_descriptor_t * dvbpsi_GenMaxBitrateDr(
bool b_duplicate)
{
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x0e, 3, NULL);
dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(0x0e, 3, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] = 0xc0 | ((p_decoded->i_max_bitrate >> 16) & 0x3f);
p_descriptor->p_data[1] = p_decoded->i_max_bitrate >> 8;
p_descriptor->p_data[2] = p_decoded->i_max_bitrate;
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_max_bitrate_dr_t));
}
}
return p_descriptor;
}
......@@ -57,17 +57,13 @@ dvbpsi_private_data_dr_t * dvbpsi_DecodePrivateDataDr(
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
p_decoded =
(dvbpsi_private_data_dr_t*)malloc(sizeof(dvbpsi_private_data_dr_t));
if(!p_decoded) return NULL;
if (p_descriptor->i_length != 4)
return NULL;
/* Decode data and check the length */
if(p_descriptor->i_length != 4)
{
free(p_decoded);
/* Allocate memory */
p_decoded = (dvbpsi_private_data_dr_t*)malloc(sizeof(dvbpsi_private_data_dr_t));
if (!p_decoded)
return NULL;
}
p_decoded->i_private_data = ((uint32_t)(p_descriptor->p_data[0]) << 24)
| ((uint32_t)(p_descriptor->p_data[1]) << 16)
......@@ -88,25 +84,23 @@ dvbpsi_descriptor_t * dvbpsi_GenPrivateDataDr(
bool b_duplicate)
{
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x0f, 4, NULL);
dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(0x0f, 4, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] = p_decoded->i_private_data >> 24;
p_descriptor->p_data[1] = p_decoded->i_private_data >> 16;
p_descriptor->p_data[2] = p_decoded->i_private_data >> 8;
p_descriptor->p_data[3] = p_decoded->i_private_data;
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_private_data_dr_t));
}
}
return p_descriptor;
}
......
......@@ -84,7 +84,6 @@ dvbpsi_descriptor_t * dvbpsi_GenNetworkNameDr(
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x40, p_decoded->i_name_length, NULL);
if (!p_descriptor)
return NULL;
......
......@@ -59,13 +59,13 @@ dvbpsi_stuffing_dr_t * dvbpsi_DecodeStuffingDr(
return p_descriptor->p_decoded;
/* Allocate memory */
p_decoded =
(dvbpsi_stuffing_dr_t*)malloc(sizeof(dvbpsi_stuffing_dr_t));
if(!p_decoded) return NULL;
p_decoded = (dvbpsi_stuffing_dr_t*)malloc(sizeof(dvbpsi_stuffing_dr_t));
if (!p_decoded)
return NULL;
/* Decode data */
p_decoded->i_stuffing_length = p_descriptor->i_length;
if(p_decoded->i_stuffing_length)
if (p_decoded->i_stuffing_length)
memcpy(p_decoded->i_stuffing_byte,
p_descriptor->p_data,
p_decoded->i_stuffing_length);
......@@ -86,23 +86,22 @@ dvbpsi_descriptor_t * dvbpsi_GenStuffingDr(
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x42, p_decoded->i_stuffing_length, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
if(p_decoded->i_stuffing_length)
if (p_decoded->i_stuffing_length)
memcpy(p_descriptor->p_data,
p_decoded->i_stuffing_byte,
p_decoded->i_stuffing_length);
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_stuffing_dr_t));
}
}
return p_descriptor;
}
......
......@@ -58,9 +58,9 @@ dvbpsi_sat_deliv_sys_dr_t * dvbpsi_DecodeSatDelivSysDr(
return p_descriptor->p_decoded;
/* Allocate memory */
p_decoded =
(dvbpsi_sat_deliv_sys_dr_t*)malloc(sizeof(dvbpsi_sat_deliv_sys_dr_t));
if(!p_decoded) return NULL;
p_decoded = (dvbpsi_sat_deliv_sys_dr_t*)malloc(sizeof(dvbpsi_sat_deliv_sys_dr_t));
if (!p_decoded)
return NULL;
/* Decode data */
p_decoded->i_frequency = (uint32_t)(p_descriptor->p_data[0] << 24)
......@@ -94,11 +94,10 @@ dvbpsi_descriptor_t * dvbpsi_GenSatDelivSysDr(
bool b_duplicate)
{
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x43, 11, NULL);
dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(0x43, 11, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] = (p_decoded->i_frequency >> 24) & 0xff;
p_descriptor->p_data[1] = (p_decoded->i_frequency >> 16) & 0xff;
......@@ -117,14 +116,13 @@ dvbpsi_descriptor_t * dvbpsi_GenSatDelivSysDr(
p_descriptor->p_data[10] = ((p_decoded->i_symbol_rate << 4) & 0xf0)
| (p_decoded->i_fec_inner & 0x0f);
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_sat_deliv_sys_dr_t));
}
}
return p_descriptor;
}
......@@ -60,7 +60,7 @@ dvbpsi_cable_deliv_sys_dr_t * dvbpsi_DecodeCableDelivSysDr(
/* Allocate memory */
p_decoded =
(dvbpsi_cable_deliv_sys_dr_t*)malloc(sizeof(dvbpsi_cable_deliv_sys_dr_t));
if(!p_decoded)
if (!p_decoded)
return NULL;
/* Decode data */
......@@ -91,9 +91,9 @@ dvbpsi_descriptor_t * dvbpsi_GenCableDelivSysDr(
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x44, 11, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] = (p_decoded->i_frequency >> 24) & 0xff;
p_descriptor->p_data[1] = (p_decoded->i_frequency >> 16) & 0xff;
......@@ -114,7 +114,6 @@ dvbpsi_descriptor_t * dvbpsi_GenCableDelivSysDr(
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_cable_deliv_sys_dr_t));
}
}
return p_descriptor;
}
......@@ -46,9 +46,6 @@
dvbpsi_vbi_dr_t * dvbpsi_DecodeVBIDataDr(
dvbpsi_descriptor_t * p_descriptor)
{
int i_services_number, i;
dvbpsi_vbi_dr_t * p_decoded;
/* Check the tag */
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x45))
return NULL;
......@@ -57,32 +54,33 @@ dvbpsi_vbi_dr_t * dvbpsi_DecodeVBIDataDr(
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Decode data and check the length */
if(p_descriptor->i_length < 3)
/* Check the length */
if (p_descriptor->i_length < 3)
return NULL;
if(p_descriptor->i_length % 2)
if (p_descriptor->i_length % 2)
return NULL;
i_services_number = p_descriptor->i_length / 2;
/* */
dvbpsi_vbi_dr_t * p_decoded;
int i_services_number = p_descriptor->i_length / 2;
/* Allocate memory */
p_decoded =
(dvbpsi_vbi_dr_t*)malloc(sizeof(dvbpsi_vbi_dr_t));
if(!p_decoded) return NULL;
p_decoded = (dvbpsi_vbi_dr_t*)malloc(sizeof(dvbpsi_vbi_dr_t));
if (!p_decoded)
return NULL;
p_decoded->i_services_number = i_services_number;
for(i=0; i < i_services_number; i++)
for (int i = 0; i < i_services_number; i++)
{
int n, i_lines = 0, i_data_service_id;
int i_lines = 0, i_data_service_id;
i_data_service_id = ((uint8_t)(p_descriptor->p_data[3 * i + 2 + i_lines]));
p_decoded->p_services[i].i_data_service_id = i_data_service_id;
i_lines = ((uint8_t)(p_descriptor->p_data[3 * i + 3]));
p_decoded->p_services[i].i_lines = i_lines;
for(n=0; n < i_lines; n++ )
for (int n = 0; n < i_lines; n++ )
{
if( (i_data_service_id >= 0x01) && (i_data_service_id <= 0x07) )
{
......@@ -99,7 +97,6 @@ dvbpsi_vbi_dr_t * dvbpsi_DecodeVBIDataDr(
return p_decoded;
}
/*****************************************************************************
* dvbpsi_GenVBIDataDr
*****************************************************************************/
......@@ -107,23 +104,20 @@ dvbpsi_descriptor_t * dvbpsi_GenVBIDataDr(
dvbpsi_vbi_dr_t * p_decoded,
bool b_duplicate)
{
int i;
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x45, p_decoded->i_services_number * 5 , NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
for (i=0; i < p_decoded->i_services_number; i++ )
for (int i = 0; i < p_decoded->i_services_number; i++ )
{
int n;
p_descriptor->p_data[5 * i + 3] =
( (uint8_t) p_decoded->p_services[i].i_data_service_id );
p_descriptor->p_data[5 * i + 4] = p_decoded->p_services[i].i_lines;
for (n=0; n < p_decoded->p_services[i].i_lines; n++ )
for (int n=0; n < p_decoded->p_services[i].i_lines; n++ )
{
if( (p_decoded->p_services[i].i_data_service_id >= 0x01) &&
(p_decoded->p_services[i].i_data_service_id <= 0x07) )
......@@ -136,14 +130,13 @@ dvbpsi_descriptor_t * dvbpsi_GenVBIDataDr(
}
}
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_vbi_dr_t));
}
}
return p_descriptor;
}
......@@ -59,9 +59,9 @@ dvbpsi_bouquet_name_dr_t * dvbpsi_DecodeBouquetNameDr(
return p_descriptor->p_decoded;
/* Allocate memory */
p_decoded =
(dvbpsi_bouquet_name_dr_t*)malloc(sizeof(dvbpsi_bouquet_name_dr_t));
if(!p_decoded) return NULL;
p_decoded = (dvbpsi_bouquet_name_dr_t*)malloc(sizeof(dvbpsi_bouquet_name_dr_t));
if (!p_decoded)
return NULL;
/* Decode data */
p_decoded->i_name_length = p_descriptor->i_length;
......@@ -86,23 +86,22 @@ dvbpsi_descriptor_t * dvbpsi_GenBouquetNameDr(
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x47, p_decoded->i_name_length, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
if(p_decoded->i_name_length)
memcpy(p_descriptor->p_data,
p_decoded->i_char,
p_decoded->i_name_length);
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_bouquet_name_dr_t));
}
}
return p_descriptor;
}
......@@ -48,8 +48,6 @@
dvbpsi_service_dr_t * dvbpsi_DecodeServiceDr(
dvbpsi_descriptor_t * p_descriptor)
{
dvbpsi_service_dr_t * p_decoded;
/* Check the tag */
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x48))
return NULL;
......@@ -58,17 +56,14 @@ dvbpsi_service_dr_t * dvbpsi_DecodeServiceDr(
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
p_decoded =
(dvbpsi_service_dr_t*)malloc(sizeof(dvbpsi_service_dr_t));
if(!p_decoded) return NULL;
if (p_descriptor->i_length < 3)
return NULL;
/* Decode data and check the length */
if(p_descriptor->i_length < 3)
{
free(p_decoded);
/* Allocate memory */
dvbpsi_service_dr_t * p_decoded;
p_decoded = (dvbpsi_service_dr_t*)malloc(sizeof(dvbpsi_service_dr_t));
if (!p_decoded)
return NULL;
}
p_descriptor->p_decoded = (void*)p_decoded;
......@@ -78,25 +73,25 @@ dvbpsi_service_dr_t * dvbpsi_DecodeServiceDr(
p_decoded->i_service_provider_name[0] = 0;
p_decoded->i_service_name[0] = 0;
if(p_decoded->i_service_provider_name_length + 2 > p_descriptor->i_length)
if (p_decoded->i_service_provider_name_length + 2 > p_descriptor->i_length)
return p_decoded;
if(p_decoded->i_service_provider_name_length)
if (p_decoded->i_service_provider_name_length)
memcpy(p_decoded->i_service_provider_name,
p_descriptor->p_data + 2,
p_decoded->i_service_provider_name_length);
if(p_decoded->i_service_provider_name_length + 3 > p_descriptor->i_length)
if (p_decoded->i_service_provider_name_length + 3 > p_descriptor->i_length)
return p_decoded;
p_decoded->i_service_name_length =
p_descriptor->p_data[2+p_decoded->i_service_provider_name_length];
if(p_decoded->i_service_provider_name_length + 3 +
if (p_decoded->i_service_provider_name_length + 3 +
p_decoded->i_service_name_length > p_descriptor->i_length)
return p_decoded;
if(p_decoded->i_service_name_length)
if (p_decoded->i_service_name_length)
memcpy(p_decoded->i_service_name,
p_descriptor->p_data + 3 + p_decoded->i_service_provider_name_length,
p_decoded->i_service_name_length);
......@@ -104,7 +99,6 @@ dvbpsi_service_dr_t * dvbpsi_DecodeServiceDr(
return p_decoded;
}
/*****************************************************************************
* dvbpsi_GenServiceDr
*****************************************************************************/
......@@ -116,32 +110,30 @@ dvbpsi_descriptor_t * dvbpsi_GenServiceDr(
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x48, 3 + p_decoded->i_service_name_length +
p_decoded->i_service_provider_name_length , NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] = p_decoded->i_service_type;
p_descriptor->p_data[1] = p_decoded->i_service_provider_name_length;
if(p_decoded->i_service_provider_name_length)
if (p_decoded->i_service_provider_name_length)
memcpy(p_descriptor->p_data + 2,
p_decoded->i_service_provider_name,
p_decoded->i_service_provider_name_length);
p_descriptor->p_data[2+p_decoded->i_service_provider_name_length] =
p_decoded->i_service_name_length;
if(p_decoded->i_service_name_length)
if (p_decoded->i_service_name_length)
memcpy(p_descriptor->p_data + 3 + p_decoded->i_service_provider_name_length,
p_decoded->i_service_name,
p_decoded->i_service_name_length);
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_service_dr_t));
}
}
return p_descriptor;
}
......@@ -62,24 +62,25 @@ dvbpsi_short_event_dr_t * dvbpsi_DecodeShortEventDr(dvbpsi_descriptor_t * p_desc
i_len1 = p_descriptor->p_data[3];
i_len2 = p_descriptor->p_data[4+i_len1];
if( p_descriptor->i_length < 5 + i_len1 + i_len2 )
if (p_descriptor->i_length < 5 + i_len1 + i_len2)
return NULL;
/* Don't decode twice */
if(p_descriptor->p_decoded)
if (p_descriptor->p_decoded)
return p_descriptor->p_decoded;
/* Allocate memory */
p_decoded = malloc(sizeof(dvbpsi_short_event_dr_t));
if(!p_decoded) return NULL;
if (!p_decoded)
return NULL;
/* Decode data and check the length */
memcpy( p_decoded->i_iso_639_code, &p_descriptor->p_data[0], 3 );
p_decoded->i_event_name_length = i_len1;
if( i_len1 > 0 )
if (i_len1 > 0)
memcpy( p_decoded->i_event_name, &p_descriptor->p_data[3+1], i_len1 );
p_decoded->i_text_length = i_len2;
if( i_len2 > 0 )
if (i_len2 > 0)
memcpy( p_decoded->i_text, &p_descriptor->p_data[4+i_len1+1], i_len2 );
p_descriptor->p_decoded = (void*)p_decoded;
......@@ -87,7 +88,6 @@ dvbpsi_short_event_dr_t * dvbpsi_DecodeShortEventDr(dvbpsi_descriptor_t * p_desc
return p_decoded;
}
/*****************************************************************************
* dvbpsi_GenShortEventDr
*****************************************************************************/
......@@ -98,28 +98,27 @@ dvbpsi_descriptor_t * dvbpsi_GenShortEventDr(dvbpsi_short_event_dr_t * p_decoded
int i_len2 = p_decoded->i_text_length;
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x4d, 5 + i_len1 + i_len2, NULL );
dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(0x4d, 5 + i_len1 + i_len2, NULL );
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
memcpy( &p_descriptor->p_data[0], p_decoded->i_iso_639_code, 3 );
p_descriptor->p_data[3] = i_len1;
if( i_len1 )
if (i_len1)
memcpy( &p_descriptor->p_data[4], p_decoded->i_event_name, i_len1 );
p_descriptor->p_data[3+1+i_len1] = i_len2;
if( i_len2 )
if (i_len2)
memcpy( &p_descriptor->p_data[3+1+i_len1+1], p_decoded->i_text, i_len2 );
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_short_event_dr_t));
}
}
return p_descriptor;
}
......@@ -61,7 +61,8 @@ dvbpsi_extended_event_dr_t * dvbpsi_DecodeExtendedEventDr(dvbpsi_descriptor_t *
/* Allocate memory */
p_decoded = malloc(sizeof(dvbpsi_extended_event_dr_t));
if(!p_decoded) return NULL;
if (!p_decoded)
return NULL;
/* Decode */
p_decoded->i_descriptor_number = (p_descriptor->p_data[0] >> 4)&0xf;
......@@ -110,18 +111,17 @@ dvbpsi_descriptor_t * dvbpsi_GenExtendedEventDr(dvbpsi_extended_event_dr_t * p_d
int i_len;
int i_len2;
dvbpsi_descriptor_t * p_descriptor;
int i;
i_len2 = 0;
for( i = 0; i < p_decoded->i_entry_count; i++ )
for (int i = 0; i < p_decoded->i_entry_count; i++)
i_len2 += 2 + p_decoded->i_item_description_length[i] + p_decoded->i_item_length[i];
i_len = 1 + 3 + 1 + i_len2 + 1 + p_decoded->i_text_length;
/* Create the descriptor */
p_descriptor = dvbpsi_NewDescriptor(0x4e, i_len, NULL );
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
uint8_t *p = &p_descriptor->p_data[0];
/* Encode data */
......@@ -132,7 +132,7 @@ dvbpsi_descriptor_t * dvbpsi_GenExtendedEventDr(dvbpsi_extended_event_dr_t * p_d
p += 4;
for( i = 0; i < p_decoded->i_entry_count; i++ )
for (int i = 0; i < p_decoded->i_entry_count; i++)
{
p[0] = p_decoded->i_item_description_length[i];
memcpy( &p[1], p_decoded->i_item_description[i], p[0] );
......@@ -146,14 +146,13 @@ dvbpsi_descriptor_t * dvbpsi_GenExtendedEventDr(dvbpsi_extended_event_dr_t * p_d
p[0] = p_decoded->i_text_length;
memcpy( &p[1], p_decoded->i_text, p[0] );
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_extended_event_dr_t));
}
}
return p_descriptor;
}
......@@ -56,17 +56,13 @@ dvbpsi_stream_identifier_dr_t * dvbpsi_DecodeStreamIdentifierDr(
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
p_decoded =
(dvbpsi_stream_identifier_dr_t*)malloc(sizeof(dvbpsi_stream_identifier_dr_t));
if(!p_decoded) return NULL;
if (p_descriptor->i_length < 1)
return NULL;
/* Decode data and check the length */
if(p_descriptor->i_length < 1)
{
free(p_decoded);
/* Allocate memory */
p_decoded = (dvbpsi_stream_identifier_dr_t*)malloc(sizeof(dvbpsi_stream_identifier_dr_t));
if (!p_decoded)
return NULL;
}
p_decoded->i_component_tag = p_descriptor->p_data[0];
......@@ -84,22 +80,20 @@ dvbpsi_descriptor_t * dvbpsi_GenStreamIdentifierDr(
bool b_duplicate)
{
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x52, 1, NULL);
dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(0x52, 1, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] = p_decoded->i_component_tag;
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_stream_identifier_dr_t));
}
}
return p_descriptor;
}
......
......@@ -47,9 +47,6 @@
dvbpsi_parental_rating_dr_t * dvbpsi_DecodeParentalRatingDr(
dvbpsi_descriptor_t * p_descriptor)
{
int i_ratings_number, i;
dvbpsi_parental_rating_dr_t * p_decoded;
/* Check the tag */
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x55))
return NULL;
......@@ -58,23 +55,20 @@ dvbpsi_parental_rating_dr_t * dvbpsi_DecodeParentalRatingDr(
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
/* Allocate memory */
p_decoded =
(dvbpsi_parental_rating_dr_t*)malloc(sizeof(dvbpsi_parental_rating_dr_t));
if(!p_decoded) return NULL;
/* Decode data and check the length */
if(p_descriptor->i_length % 4)
{
free(p_decoded);
return NULL;
}
i_ratings_number = p_descriptor->i_length / 4;
/* Allocate memory */
dvbpsi_parental_rating_dr_t * p_decoded;
p_decoded = (dvbpsi_parental_rating_dr_t*)malloc(sizeof(dvbpsi_parental_rating_dr_t));
if (!p_decoded)
return NULL;
int i_ratings_number = p_descriptor->i_length / 4;
p_decoded->i_ratings_number = i_ratings_number;
for (i=0; i < i_ratings_number; i++)
for (int i = 0; i < i_ratings_number; i++)
{
p_decoded->p_parental_rating[i].i_country_code =
((uint32_t)p_descriptor->p_data[4 * i] << 16)
......@@ -97,16 +91,15 @@ dvbpsi_descriptor_t * dvbpsi_GenParentalRatingDr(
dvbpsi_parental_rating_dr_t * p_decoded,
bool b_duplicate)
{
int i;
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x55, p_decoded->i_ratings_number * 4 , NULL);
if(p_descriptor)
{
if (!p_descriptor)
return NULL;
/* Encode data */
for (i=0; i < p_decoded->i_ratings_number; i++ )
for (int i = 0; i < p_decoded->i_ratings_number; i++ )
{
p_descriptor->p_data[8 * i] =
p_decoded->p_parental_rating[i].i_country_code >> 16;
......@@ -119,14 +112,13 @@ dvbpsi_descriptor_t * dvbpsi_GenParentalRatingDr(
p_decoded->p_parental_rating[i].i_rating;
}
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_parental_rating_dr_t));
}
}
return p_descriptor;
}
......
......@@ -46,9 +46,6 @@
dvbpsi_teletext_dr_t * dvbpsi_DecodeTeletextDr(
dvbpsi_descriptor_t * p_descriptor)
{
int i_pages_number, i;
dvbpsi_teletext_dr_t * p_decoded;
/* Check the tag */
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x56) &&
!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x46))
......@@ -65,16 +62,18 @@ dvbpsi_teletext_dr_t * dvbpsi_DecodeTeletextDr(
if(p_descriptor->i_length % 5)
return NULL;
int i_pages_number;
i_pages_number = p_descriptor->i_length / 5;
/* Allocate memory */
p_decoded =
(dvbpsi_teletext_dr_t*)malloc(sizeof(dvbpsi_teletext_dr_t));
if(!p_decoded) return NULL;
dvbpsi_teletext_dr_t * p_decoded;
p_decoded = (dvbpsi_teletext_dr_t*)malloc(sizeof(dvbpsi_teletext_dr_t));
if (!p_decoded)
return NULL;
p_decoded->i_pages_number = i_pages_number;
for(i=0; i < i_pages_number; i++)
for (int i = 0; i < i_pages_number; i++)
{
memcpy(p_decoded->p_pages[i].i_iso6392_language_code,
p_descriptor->p_data + 5 * i, 3);
......@@ -101,16 +100,14 @@ dvbpsi_descriptor_t * dvbpsi_GenTeletextDr(
dvbpsi_teletext_dr_t * p_decoded,
bool b_duplicate)
{
int i;
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x56, p_decoded->i_pages_number * 8 , NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
for (i=0; i < p_decoded->i_pages_number; i++ )
for (int i = 0; i < p_decoded->i_pages_number; i++ )
{
memcpy( p_descriptor->p_data + 8 * i,
p_decoded->p_pages[i].i_iso6392_language_code,
......@@ -124,14 +121,13 @@ dvbpsi_descriptor_t * dvbpsi_GenTeletextDr(
p_decoded->p_pages[i].i_teletext_page_number;
}
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_teletext_dr_t));
}
}
return p_descriptor;
}
......@@ -60,16 +60,17 @@ dvbpsi_local_time_offset_dr_t * dvbpsi_DecodeLocalTimeOffsetDr(
return p_descriptor->p_decoded;
/* Allocate memory */
p_decoded =
(dvbpsi_local_time_offset_dr_t*)malloc(sizeof(dvbpsi_local_time_offset_dr_t));
if(!p_decoded) return NULL;
p_decoded = (dvbpsi_local_time_offset_dr_t*)malloc(sizeof(dvbpsi_local_time_offset_dr_t));
if (!p_decoded)
return NULL;
/* Decode data */
p_decoded->i_local_time_offsets_number = 0;
p_current = p_decoded->p_local_time_offset;
p_end = p_descriptor->p_data + p_descriptor->i_length;
p_data = p_descriptor->p_data;
while(p_data + 13 <= p_end) {
while(p_data + 13 <= p_end)
{
memcpy(p_current->i_country_code, p_data, 3);
p_current->i_country_region_id = (p_data[3] >> 2) & 0x3f;
p_current->i_local_time_offset_polarity = p_data[3] & 0x01;
......@@ -93,7 +94,6 @@ dvbpsi_local_time_offset_dr_t * dvbpsi_DecodeLocalTimeOffsetDr(
return p_decoded;
}
/*****************************************************************************
* dvbpsi_GenLocalTimeOffsetDr
*****************************************************************************/
......@@ -101,22 +101,21 @@ dvbpsi_descriptor_t * dvbpsi_GenLocalTimeOffsetDr(
dvbpsi_local_time_offset_dr_t * p_decoded,
bool b_duplicate)
{
uint8_t i_num;
dvbpsi_local_time_offset_t * p_current;
uint8_t * p_data;
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x58, p_decoded->i_local_time_offsets_number * 13, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
dvbpsi_local_time_offset_t * p_current;
uint8_t * p_data;
p_current = p_decoded->p_local_time_offset;
p_data = p_descriptor->p_data;
for(i_num = 0; i_num < p_decoded->i_local_time_offsets_number; i_num++) {
for (uint8_t i_num = 0; i_num < p_decoded->i_local_time_offsets_number; i_num++)
{
memcpy(p_data, p_current->i_country_code, 3);
p_data[3] = ((p_current->i_country_region_id & 0x3f) << 2)
| 0x02
......@@ -135,14 +134,13 @@ dvbpsi_descriptor_t * dvbpsi_GenLocalTimeOffsetDr(
p_current++;
}
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_local_time_offset_dr_t));
}
}
return p_descriptor;
}
......@@ -48,7 +48,7 @@
dvbpsi_subtitling_dr_t * dvbpsi_DecodeSubtitlingDr(
dvbpsi_descriptor_t * p_descriptor)
{
int i_subtitles_number, i;
int i_subtitles_number;
dvbpsi_subtitling_dr_t * p_decoded;
/* Check the tag */
......@@ -60,32 +60,22 @@ dvbpsi_subtitling_dr_t * dvbpsi_DecodeSubtitlingDr(
return p_descriptor->p_decoded;
/* Decode data and check the length */
if(p_descriptor->i_length < 3)
if (p_descriptor->i_length < 3)
return NULL;
/* Allocate memory */
p_decoded =
(dvbpsi_subtitling_dr_t*)malloc(sizeof(dvbpsi_subtitling_dr_t));
if(!p_decoded) return NULL;
/* Decode data and check the length */
if(p_descriptor->i_length < 3)
{
free(p_decoded);
if (p_descriptor->i_length % 8)
return NULL;
}
if(p_descriptor->i_length % 8)
{
free(p_decoded);
/* Allocate memory */
p_decoded = (dvbpsi_subtitling_dr_t*)malloc(sizeof(dvbpsi_subtitling_dr_t));
if (!p_decoded)
return NULL;
}
i_subtitles_number = p_descriptor->i_length / 8;
p_decoded->i_subtitles_number = i_subtitles_number;
for (i=0; i < i_subtitles_number; i++)
for (int i = 0; i < i_subtitles_number; i++)
{
memcpy(p_decoded->p_subtitle[i].i_iso6392_language_code,
p_descriptor->p_data + 8 * i, 3);
......@@ -115,16 +105,14 @@ dvbpsi_descriptor_t * dvbpsi_GenSubtitlingDr(
dvbpsi_subtitling_dr_t * p_decoded,
bool b_duplicate)
{
int i;
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x59, p_decoded->i_subtitles_number * 8 , NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
for (i=0; i < p_decoded->i_subtitles_number; i++ )
for (int i = 0; i < p_decoded->i_subtitles_number; i++ )
{
memcpy( p_descriptor->p_data + 8 * i,
p_decoded->p_subtitle[i].i_iso6392_language_code,
......@@ -144,14 +132,13 @@ dvbpsi_descriptor_t * dvbpsi_GenSubtitlingDr(
p_decoded->p_subtitle[i].i_ancillary_page_id % 0xFF;
}
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_subtitling_dr_t));
}
}
return p_descriptor;
}
......@@ -47,8 +47,6 @@
dvbpsi_terr_deliv_sys_dr_t * dvbpsi_DecodeTerrDelivSysDr(
dvbpsi_descriptor_t * p_descriptor)
{
dvbpsi_terr_deliv_sys_dr_t * p_decoded;
/* Check the tag */
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x5a))
return NULL;
......@@ -58,9 +56,10 @@ dvbpsi_terr_deliv_sys_dr_t * dvbpsi_DecodeTerrDelivSysDr(
return p_descriptor->p_decoded;
/* Allocate memory */
p_decoded =
(dvbpsi_terr_deliv_sys_dr_t*)malloc(sizeof(dvbpsi_terr_deliv_sys_dr_t));
if(!p_decoded) return NULL;
dvbpsi_terr_deliv_sys_dr_t * p_decoded;
p_decoded = (dvbpsi_terr_deliv_sys_dr_t*)malloc(sizeof(dvbpsi_terr_deliv_sys_dr_t));
if (!p_decoded)
return NULL;
/* Decode data */
p_decoded->i_centre_frequency = (uint32_t)(p_descriptor->p_data[0] << 24)
......@@ -84,7 +83,6 @@ dvbpsi_terr_deliv_sys_dr_t * dvbpsi_DecodeTerrDelivSysDr(
return p_decoded;
}
/*****************************************************************************
* dvbpsi_GenTerrDelivSysDr
*****************************************************************************/
......@@ -93,11 +91,10 @@ dvbpsi_descriptor_t * dvbpsi_GenTerrDelivSysDr(
bool b_duplicate)
{
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x5a, 11, NULL);
dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(0x5a, 11, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] = (p_decoded->i_centre_frequency >> 24) & 0xff;
p_descriptor->p_data[1] = (p_decoded->i_centre_frequency >> 16) & 0xff;
......@@ -120,14 +117,13 @@ dvbpsi_descriptor_t * dvbpsi_GenTerrDelivSysDr(
p_descriptor->p_data[9] = 0xff;
p_descriptor->p_data[10] = 0xff;
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_terr_deliv_sys_dr_t));
}
}
return p_descriptor;
}
......@@ -57,12 +57,13 @@ dvbpsi_PDC_dr_t * dvbpsi_DecodePDCDr(dvbpsi_descriptor_t * p_descriptor)
return p_descriptor->p_decoded;
/* Check the length */
if( p_descriptor->i_length != 3)
if (p_descriptor->i_length != 3)
return NULL;
/* Allocate memory */
p_decoded = (dvbpsi_PDC_dr_t*)malloc(sizeof(dvbpsi_PDC_dr_t));
if(!p_decoded) return NULL;
if (!p_decoded)
return NULL;
p_decoded->i_PDC[0] = ((p_descriptor->p_data[0] & 0x0f) << 1) |
(p_descriptor->p_data[1] >> 7);
......@@ -84,26 +85,25 @@ dvbpsi_descriptor_t * dvbpsi_GenPDCDr(dvbpsi_PDC_dr_t * p_decoded,
bool b_duplicate)
{
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x69, 3, NULL);
dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(0x69, 3, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] = 0xf0 | (p_decoded->i_PDC[0] >> 1);
p_descriptor->p_data[1] = (p_decoded->i_PDC[0] << 7) |
(p_decoded->i_PDC[1] << 3) | (p_decoded->i_PDC[2] >> 2);
(p_decoded->i_PDC[1] << 3) |
(p_decoded->i_PDC[2] >> 2);
p_descriptor->p_data[2] = (p_decoded->i_PDC[2] << 6 ) |
p_decoded->i_PDC[3];
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_PDC_dr_t));
}
}
return p_descriptor;
}
......
......@@ -45,8 +45,6 @@
*****************************************************************************/
dvbpsi_cuei_dr_t * dvbpsi_DecodeCUEIDr(dvbpsi_descriptor_t * p_descriptor)
{
dvbpsi_cuei_dr_t *p_decoded;
/* Check the tag */
if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x8a))
return NULL;
......@@ -55,16 +53,14 @@ dvbpsi_cuei_dr_t * dvbpsi_DecodeCUEIDr(dvbpsi_descriptor_t * p_descriptor)
if (dvbpsi_IsDescriptorDecoded(p_descriptor))
return p_descriptor->p_decoded;
if (p_descriptor->i_length == 0x01)
return NULL;
/* Allocate memory */
dvbpsi_cuei_dr_t *p_decoded;
p_decoded = (dvbpsi_cuei_dr_t*)malloc(sizeof(dvbpsi_cuei_dr_t));
if (!p_decoded) return NULL;
/* Decode data and check the length */
if (p_descriptor->i_length == 0x01)
{
free(p_decoded);
if (!p_decoded)
return NULL;
}
/* cue_stream_type according to: SCTE 35 2004 - p15 - table 6.3
* cue_stream_type PID usage
......@@ -89,22 +85,20 @@ dvbpsi_cuei_dr_t * dvbpsi_DecodeCUEIDr(dvbpsi_descriptor_t * p_descriptor)
dvbpsi_descriptor_t * dvbpsi_GenCUEIDr(dvbpsi_cuei_dr_t * p_decoded, bool b_duplicate)
{
/* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x8a, 0x01, NULL);
dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(0x8a, 0x01, NULL);
if (!p_descriptor)
return NULL;
if(p_descriptor)
{
/* Encode data */
p_descriptor->p_data[0] = p_decoded->i_cue_stream_type;
if(b_duplicate)
if (b_duplicate)
{
/* Duplicate decoded data */
p_descriptor->p_decoded =
dvbpsi_DuplicateDecodedDescriptor(p_descriptor->p_decoded,
sizeof(dvbpsi_cuei_dr_t));
}
}
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