Commit 4fc878e7 authored by Jean-Paul Saman's avatar Jean-Paul Saman

src/psi.{c,h}: Cleanup

- Introduce bool for things that are used as bools
- Indentation
parent a0622578
/*****************************************************************************
* psi.c: common PSI functions
*----------------------------------------------------------------------------
* Copyright (C) 2001-2010 VideoLAN
* Copyright (C) 2001-2011 VideoLAN
* $Id$
*
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
......@@ -24,7 +24,6 @@
*
*****************************************************************************/
#include "config.h"
#include <stdio.h>
......@@ -41,60 +40,53 @@
#include "dvbpsi_private.h"
#include "psi.h"
/*****************************************************************************
* dvbpsi_NewPSISection
*****************************************************************************
* Creation of a new dvbpsi_psi_section_t structure.
*****************************************************************************/
dvbpsi_psi_section_t * dvbpsi_NewPSISection(int i_max_size)
dvbpsi_psi_section_t *dvbpsi_NewPSISection(int i_max_size)
{
/* Allocate the dvbpsi_psi_section_t structure */
dvbpsi_psi_section_t * p_section
= (dvbpsi_psi_section_t*)malloc(sizeof(dvbpsi_psi_section_t));
/* Allocate the dvbpsi_psi_section_t structure */
dvbpsi_psi_section_t * p_section
= (dvbpsi_psi_section_t*)malloc(sizeof(dvbpsi_psi_section_t));
if (p_section == NULL)
return NULL;
if(p_section != NULL)
{
/* Allocate the p_data memory area */
p_section->p_data = (uint8_t*)malloc(i_max_size * sizeof(uint8_t));
if(p_section->p_data != NULL)
{
p_section->p_payload_end = p_section->p_data;
}
if (p_section->p_data != NULL)
p_section->p_payload_end = p_section->p_data;
else
{
free(p_section);
return NULL;
free(p_section);
return NULL;
}
p_section->p_next = NULL;
}
return p_section;
return p_section;
}
/*****************************************************************************
* dvbpsi_DeletePSISections
*****************************************************************************
* Destruction of a dvbpsi_psi_section_t structure.
*****************************************************************************/
void dvbpsi_DeletePSISections(dvbpsi_psi_section_t * p_section)
void dvbpsi_DeletePSISections(dvbpsi_psi_section_t *p_section)
{
while(p_section != NULL)
{
dvbpsi_psi_section_t* p_next = p_section->p_next;
while(p_section != NULL)
{
dvbpsi_psi_section_t* p_next = p_section->p_next;
if(p_section->p_data != NULL)
free(p_section->p_data);
if (p_section->p_data != NULL)
free(p_section->p_data);
free(p_section);
p_section = p_next;
}
free(p_section);
p_section = p_next;
}
}
/*****************************************************************************
* dvbpsi_ValidPSISection
*****************************************************************************
......@@ -102,31 +94,30 @@ void dvbpsi_DeletePSISections(dvbpsi_psi_section_t * p_section)
*****************************************************************************/
bool dvbpsi_ValidPSISection(dvbpsi_psi_section_t* p_section)
{
if(p_section->b_syntax_indicator)
{
/* Check the CRC_32 if b_syntax_indicator is 0 */
uint32_t i_crc = 0xffffffff;
uint8_t* p_byte = p_section->p_data;
while(p_byte < p_section->p_payload_end + 4)
if (p_section->b_syntax_indicator)
{
i_crc = (i_crc << 8) ^ dvbpsi_crc32_table[(i_crc >> 24) ^ (*p_byte)];
p_byte++;
/* Check the CRC_32 if b_syntax_indicator is 0 */
uint32_t i_crc = 0xffffffff;
uint8_t* p_byte = p_section->p_data;
while(p_byte < p_section->p_payload_end + 4)
{
i_crc = (i_crc << 8) ^ dvbpsi_crc32_table[(i_crc >> 24) ^ (*p_byte)];
p_byte++;
}
if (i_crc == 0)
return true;
else
return false;
}
if(i_crc == 0)
return true;
else
return false;
}
else
{
/* No check to do if b_syntax_indicator is 0 */
return false;
}
{
/* No check to do if b_syntax_indicator is 0 */
return false;
}
}
/*****************************************************************************
* dvbpsi_BuildPSISection
*****************************************************************************
......@@ -148,7 +139,7 @@ void dvbpsi_BuildPSISection(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t* p_section)
p_section->p_data[2] = p_section->i_length & 0xff;
/* Optional part of a PSI section */
if(p_section->b_syntax_indicator)
if (p_section->b_syntax_indicator)
{
/* 8 MSB of table_id_extension */
p_section->p_data[3] = (p_section->i_extension >> 8) & 0xff;
......@@ -166,7 +157,7 @@ void dvbpsi_BuildPSISection(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t* p_section)
/* CRC_32 */
p_section->i_crc = 0xffffffff;
while(p_byte < p_section->p_payload_end)
while (p_byte < p_section->p_payload_end)
{
p_section->i_crc = (p_section->i_crc << 8)
^ dvbpsi_crc32_table[(p_section->i_crc >> 24) ^ (*p_byte)];
......@@ -178,7 +169,7 @@ void dvbpsi_BuildPSISection(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t* p_section)
p_section->p_payload_end[2] = (p_section->i_crc >> 8) & 0xff;
p_section->p_payload_end[3] = p_section->i_crc & 0xff;
if(!dvbpsi_ValidPSISection(p_section))
if (!dvbpsi_ValidPSISection(p_section))
{
dvbpsi_error(p_dvbpsi, "misc PSI", "********************************************");
dvbpsi_error(p_dvbpsi, "misc PSI", "* Generated PSI section has a bad CRC_32. *");
......@@ -188,4 +179,3 @@ void dvbpsi_BuildPSISection(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t* p_section)
}
}
}
/*****************************************************************************
* psi.h
* Copyright (C) 2001-2010 VideoLAN
* Copyright (C) 2001-2011 VideoLAN
* $Id: psi.h,v 1.6 2002/04/02 17:55:30 bozo Exp $
*
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
......@@ -36,7 +36,6 @@
extern "C" {
#endif
/*****************************************************************************
* dvbpsi_psi_section_t
*****************************************************************************/
......@@ -70,8 +69,8 @@ struct dvbpsi_psi_section_s
{
/* non-specific section data */
uint8_t i_table_id; /*!< table_id */
int b_syntax_indicator; /*!< section_syntax_indicator */
int b_private_indicator; /*!< private_indicator */
bool b_syntax_indicator; /*!< section_syntax_indicator */
bool b_private_indicator; /*!< private_indicator */
uint16_t i_length; /*!< section_length */
/* used if b_syntax_indicator is true */
......@@ -79,7 +78,7 @@ struct dvbpsi_psi_section_s
/*!< transport_stream_id for a
PAT section */
uint8_t i_version; /*!< version_number */
int b_current_next; /*!< current_next_indicator */
bool b_current_next; /*!< current_next_indicator */
uint8_t i_number; /*!< section_number */
uint8_t i_last_number; /*!< last_section_number */
......@@ -95,10 +94,8 @@ struct dvbpsi_psi_section_s
/* list handling */
struct dvbpsi_psi_section_s * p_next; /*!< next element of
the list */
};
/*****************************************************************************
* dvbpsi_NewPSISection
*****************************************************************************/
......@@ -110,7 +107,6 @@ struct dvbpsi_psi_section_s
*/
dvbpsi_psi_section_t * dvbpsi_NewPSISection(int i_max_size);
/*****************************************************************************
* dvbpsi_DeletePSISections
*****************************************************************************/
......@@ -122,7 +118,6 @@ dvbpsi_psi_section_t * dvbpsi_NewPSISection(int i_max_size);
*/
void dvbpsi_DeletePSISections(dvbpsi_psi_section_t * p_section);
/*****************************************************************************
* dvbpsi_ValidPSISection
*****************************************************************************/
......@@ -136,7 +131,6 @@ void dvbpsi_DeletePSISections(dvbpsi_psi_section_t * p_section);
*/
bool dvbpsi_ValidPSISection(dvbpsi_psi_section_t* p_section);
/*****************************************************************************
* dvbpsi_BuildPSISection
*****************************************************************************/
......@@ -149,7 +143,6 @@ bool dvbpsi_ValidPSISection(dvbpsi_psi_section_t* p_section);
*/
void dvbpsi_BuildPSISection(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t* p_section);
#ifdef __cplusplus
};
#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