Commit 8176eb84 authored by Christophe Massiot's avatar Christophe Massiot

* src/tables/eit*: EIT decoder (no generator yet)

  * 0x55 (dvb parental rating) descriptor decoder
  * fixed a segfault in the subtitles descriptor decoder
  * bumped up version number to 0.1.5
parent 84476959
...@@ -12,4 +12,24 @@ D: main structure ...@@ -12,4 +12,24 @@ D: main structure
D: PSI section gathering D: PSI section gathering
D: PAT decoder/generator D: PAT decoder/generator
D: PMT decoder/generator D: PMT decoder/generator
D: MPEG descriptors
N: Johan Bilien
E: jobi@via.ecp.fr
C: jobi
D: subtables decoder
D: SDT decoder
D: most DVB descriptors
N: Tristan Leteurtre
E: tristan.leteurtre@anevia.com
C: tooney
D: subtitles descriptor (0x59)
N: Christophe Massiot
E: massiot@via.ecp.fr
C: massiot
D: initial specs
D: EIT decoder
D: parental rating descriptor (0x55)
$Id: NEWS,v 1.5 2004/01/02 14:15:46 sam Exp $ $Id$
Changes between 0.1.4 and 0.1.5:
--------------------------------
* src/tables/eit*: EIT decoder (no generator yet)
* 0x55 (dvb parental rating) descriptor decoder
* fixed a segfault in the subtitles descriptor decoder
Changes between 0.1.3 and 0.1.4: Changes between 0.1.3 and 0.1.4:
-------------------------------- --------------------------------
......
...@@ -4,7 +4,7 @@ AC_PREREQ(2.50) ...@@ -4,7 +4,7 @@ AC_PREREQ(2.50)
AC_CONFIG_AUX_DIR(autotools) AC_CONFIG_AUX_DIR(autotools)
AC_CANONICAL_SYSTEM AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE(libdvbpsi3, 0.1.4) AM_INIT_AUTOMAKE(libdvbpsi3, 0.1.5)
AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(config.h)
#AC_CANONICAL_HOST #AC_CANONICAL_HOST
......
...@@ -14,7 +14,7 @@ libdvbpsi_la_SOURCES = dvbpsi.c dvbpsi_private.h \ ...@@ -14,7 +14,7 @@ libdvbpsi_la_SOURCES = dvbpsi.c dvbpsi_private.h \
libdvbpsi_la_LDFLAGS = -version-info 3:0:0 libdvbpsi_la_LDFLAGS = -version-info 3:0:0
pkginclude_HEADERS = dvbpsi.h psi.h descriptor.h demux.h \ pkginclude_HEADERS = dvbpsi.h psi.h descriptor.h demux.h \
tables/pat.h tables/pmt.h tables/sdt.h \ tables/pat.h tables/pmt.h tables/sdt.h tables/eit.h \
descriptors/dr_02.h \ descriptors/dr_02.h \
descriptors/dr_03.h \ descriptors/dr_03.h \
descriptors/dr_04.h \ descriptors/dr_04.h \
...@@ -32,6 +32,7 @@ pkginclude_HEADERS = dvbpsi.h psi.h descriptor.h demux.h \ ...@@ -32,6 +32,7 @@ pkginclude_HEADERS = dvbpsi.h psi.h descriptor.h demux.h \
descriptors/dr_42.h \ descriptors/dr_42.h \
descriptors/dr_47.h \ descriptors/dr_47.h \
descriptors/dr_48.h \ descriptors/dr_48.h \
descriptors/dr_55.h \
descriptors/dr_59.h \ descriptors/dr_59.h \
descriptors/dr.h descriptors/dr.h
...@@ -52,9 +53,11 @@ descriptors_src = descriptors/dr_02.c \ ...@@ -52,9 +53,11 @@ descriptors_src = descriptors/dr_02.c \
descriptors/dr_42.c \ descriptors/dr_42.c \
descriptors/dr_47.c \ descriptors/dr_47.c \
descriptors/dr_48.c \ descriptors/dr_48.c \
descriptors/dr_55.c \
descriptors/dr_59.c descriptors/dr_59.c
tables_src = tables/pat.c tables/pat_private.h \ tables_src = tables/pat.c tables/pat_private.h \
tables/pmt.c tables/pmt_private.h \ tables/pmt.c tables/pmt_private.h \
tables/sdt.c tables/sdt_private.h tables/sdt.c tables/sdt_private.h \
tables/eit.c tables/eit_private.h
/***************************************************************************** /*****************************************************************************
* dr.h * dr.h
* (c)2001-2002 VideoLAN * (c)2001-2002 VideoLAN
* $Id: dr.h,v 1.5 2003/11/06 16:20:30 nitrox Exp $ * $Id$
* *
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
* *
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include "dr_42.h" #include "dr_42.h"
#include "dr_47.h" #include "dr_47.h"
#include "dr_48.h" #include "dr_48.h"
#include "dr_55.h"
#include "dr_59.h" #include "dr_59.h"
#else #else
......
/*****************************************************************************
* dr_55.c
* (c)2004 VideoLAN
* $Id: dr_55.c 89 2004-06-28 19:17:23Z gbazin $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*****************************************************************************/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(HAVE_INTTYPES_H)
#include <inttypes.h>
#elif defined(HAVE_STDINT_H)
#include <stdint.h>
#endif
#include "../dvbpsi.h"
#include "../dvbpsi_private.h"
#include "../descriptor.h"
#include "dr_55.h"
/*****************************************************************************
* dvbpsi_DecodeParentalRatingDr
*****************************************************************************/
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(p_descriptor->i_tag != 0x55)
{
DVBPSI_ERROR_ARG("dr_55 decoder", "bad tag (0x%x)", p_descriptor->i_tag);
return NULL;
}
/* Don't decode twice */
if(p_descriptor->p_decoded)
return p_descriptor->p_decoded;
/* Allocate memory */
p_decoded =
(dvbpsi_parental_rating_dr_t*)malloc(sizeof(dvbpsi_parental_rating_dr_t));
if(!p_decoded)
{
DVBPSI_ERROR("dr_55 decoder", "out of memory");
return NULL;
}
/* Decode data and check the length */
if(p_descriptor->i_length % 4)
{
DVBPSI_ERROR_ARG("dr_55 decoder", "length not multiple of 4 (%d)",
p_descriptor->i_length);
free(p_decoded);
return NULL;
}
i_ratings_number = p_descriptor->i_length / 4;
p_decoded->i_ratings_number = i_ratings_number;
for (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)
| ((uint32_t)p_descriptor->p_data[4 * i + 1] << 8)
| p_descriptor->p_data[4 * i + 2];
p_decoded->p_parental_rating[i].i_rating = p_descriptor->p_data[4 * i + 3];
}
p_descriptor->p_decoded = (void*)p_decoded;
return p_decoded;
}
/*****************************************************************************
* dvbpsi_GenParentalRatingDr
*****************************************************************************/
dvbpsi_descriptor_t * dvbpsi_GenParentalRatingDr(
dvbpsi_parental_rating_dr_t * p_decoded,
int 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)
{
/* Encode data */
for (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;
p_descriptor->p_data[8 * i + 1] =
(p_decoded->p_parental_rating[i].i_country_code >> 8) & 0xff;
p_descriptor->p_data[8 * i + 2] =
p_decoded->p_parental_rating[i].i_country_code & 0xff;
p_descriptor->p_data[8 * i + 3] =
p_decoded->p_parental_rating[i].i_rating;
}
if(b_duplicate)
{
/* Duplicate decoded data */
dvbpsi_parental_rating_dr_t * p_dup_decoded =
(dvbpsi_parental_rating_dr_t*)malloc(sizeof(dvbpsi_parental_rating_dr_t));
if(p_dup_decoded)
memcpy(p_dup_decoded, p_decoded, sizeof(dvbpsi_parental_rating_dr_t));
p_descriptor->p_decoded = (void*)p_dup_decoded;
}
}
return p_descriptor;
}
/*****************************************************************************
* dr_55.h
* (c)2004 VideoLAN
* $Id: dr_55.h 88 2004-02-24 14:31:18Z sam $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*****************************************************************************/
/*!
* \file <dr_55.h>
* \author Christophe Massiot <massiot@via.ecp.fr>
* \brief Parental rating descriptor parsing.
*
* Parental rating descriptor parsing, according to ETSI EN 300 468
* section 6.2.26.
*/
#ifndef _DVBPSI_DR_55_H_
#define _DVBPSI_DR_55_H_
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************
* dvbpsi_parental_rating_t
*****************************************************************************/
/*!
* \struct dvbpsi_parental_rating_s
* \brief one subtitle structure.
*
* This structure is used since parental_rating_descriptor will contain several
* coutry/rating pairs.
*/
/*!
* \typedef struct dvbpsi_parental_rating_s dvbpsi_parental_rating_t
* \brief dvbpsi_parental_rating_t type definition.
*/
typedef struct dvbpsi_parental_rating_s
{
uint32_t i_country_code;
uint8_t i_rating;
} dvbpsi_parental_rating_t;
/*****************************************************************************
* dvbpsi_parental_rating_dr_t
*****************************************************************************/
/*!
* \struct dvbpsi_parental_rating_dr_s
* \brief "parental_rating" descriptor structure.
*
* This structure is used to store a decoded "parental_rating"
* descriptor. (ETSI EN 300 468 section 6.2.26).
*/
/*!
* \typedef struct dvbpsi_parental_rating_dr_s dvbpsi_parental_rating_dr_t
* \brief dvbpsi_parental_rating_dr_t type definition.
*/
typedef struct dvbpsi_parental_rating_dr_s
{
uint8_t i_ratings_number;
dvbpsi_parental_rating_t p_parental_rating[64];
} dvbpsi_parental_rating_dr_t;
/*****************************************************************************
* dvbpsi_DecodeParentalRatingDataDr
*****************************************************************************/
/*!
* \fn dvbpsi_parental_rating_dr_t * dvbpsi_DecodeParentalRatingDr(
dvbpsi_descriptor_t * p_descriptor)
* \brief "parental_rating" descriptor decoder.
* \param p_descriptor pointer to the descriptor structure
* \return a pointer to a new "parental_rating" descriptor structure
* which contains the decoded data.
*/
dvbpsi_parental_rating_dr_t* dvbpsi_DecodeParentalRatingDr(
dvbpsi_descriptor_t * p_descriptor);
/*****************************************************************************
* dvbpsi_GenParentalRatingDataDr
*****************************************************************************/
/*!
* \fn dvbpsi_descriptor_t * dvbpsi_GenParentalRatingDr(
dvbpsi_parental_rating_dr_t * p_decoded, int b_duplicate)
* \brief "parental_rating" descriptor generator.
* \param p_decoded pointer to a decoded "parental_rating" descriptor
* structure
* \param b_duplicate if non zero then duplicate the p_decoded structure into
* the descriptor
* \return a pointer to a new descriptor structure which contains encoded data.
*/
dvbpsi_descriptor_t * dvbpsi_GenParentalRatingDr(
dvbpsi_parental_rating_dr_t * p_decoded,
int b_duplicate);
#ifdef __cplusplus
};
#endif
#else
#error "Multiple inclusions of dr_55.h"
#endif
/***************************************************************************** /*****************************************************************************
* dr_48.c * dr_59.c
* (c)2001-2002 VideoLAN * (c)2001-2002 VideoLAN
* $Id$ * $Id$
* *
...@@ -77,6 +77,7 @@ dvbpsi_subtitling_dr_t * dvbpsi_DecodeSubtitlingDr( ...@@ -77,6 +77,7 @@ dvbpsi_subtitling_dr_t * dvbpsi_DecodeSubtitlingDr(
DVBPSI_ERROR_ARG("dr_59 decoder", "bad length (%d)", DVBPSI_ERROR_ARG("dr_59 decoder", "bad length (%d)",
p_descriptor->i_length); p_descriptor->i_length);
free(p_decoded); free(p_decoded);
return NULL;
} }
if(p_descriptor->i_length % 8) if(p_descriptor->i_length % 8)
...@@ -84,6 +85,7 @@ dvbpsi_subtitling_dr_t * dvbpsi_DecodeSubtitlingDr( ...@@ -84,6 +85,7 @@ dvbpsi_subtitling_dr_t * dvbpsi_DecodeSubtitlingDr(
DVBPSI_ERROR_ARG("dr_59 decoder", "length not multiple of 8 (%d)", DVBPSI_ERROR_ARG("dr_59 decoder", "length not multiple of 8 (%d)",
p_descriptor->i_length); p_descriptor->i_length);
free(p_decoded); free(p_decoded);
return NULL;
} }
i_subtitles_number = p_descriptor->i_length / 8; i_subtitles_number = p_descriptor->i_length / 8;
......
/***************************************************************************** /*****************************************************************************
* dr_59.h * dr_59.h
* (c)2001-2002 VideoLAN * (c)2001-2002 VideoLAN
* $Id: dr_59.h,v 1.1 2003/11/06 16:20:30 nitrox Exp $ * $Id$
* *
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
* Tristan Leteurtre <tristan.leteurtre@anevia.com> * Tristan Leteurtre <tristan.leteurtre@anevia.com>
...@@ -42,7 +42,7 @@ extern "C" { ...@@ -42,7 +42,7 @@ extern "C" {
* dvbpsi_subtitle_t * dvbpsi_subtitle_t
*****************************************************************************/ *****************************************************************************/
/*! /*!
* \struct dvbpsi_subtitle_dr_s * \struct dvbpsi_subtitle_s
* \brief one subtitle structure. * \brief one subtitle structure.
* *
* This structure is used since subtitling_descriptor will contain several * This structure is used since subtitling_descriptor will contain several
......
/*****************************************************************************
* eit.c: EIT decoder/generator
*----------------------------------------------------------------------------
* (c)2004 VideoLAN
* $Id: eit.c 88 2004-02-24 14:31:18Z sam $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Johan Bilien <jobi@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*----------------------------------------------------------------------------
*
*****************************************************************************/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(HAVE_INTTYPES_H)
#include <inttypes.h>
#elif defined(HAVE_STDINT_H)
#include <stdint.h>
#endif
#include "../dvbpsi.h"
#include "../dvbpsi_private.h"
#include "../psi.h"
#include "../descriptor.h"
#include "../demux.h"
#include "eit.h"
#include "eit_private.h"
/*****************************************************************************
* dvbpsi_AttachEIT
*****************************************************************************
* Initialize a EIT subtable decoder.
*****************************************************************************/
int dvbpsi_AttachEIT(dvbpsi_decoder_t * p_psi_decoder, uint8_t i_table_id,
uint16_t i_extension, dvbpsi_eit_callback pf_callback,
void* p_cb_data)
{
dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_psi_decoder->p_private_decoder;
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_eit_decoder_t* p_eit_decoder;
unsigned int i;
if(dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
{
DVBPSI_ERROR_ARG("EIT decoder",
"Already a decoder for (table_id == 0x%02x,"
"extension == 0x%02x)",
i_table_id, i_extension);
return 1;
}
p_subdec = (dvbpsi_demux_subdec_t*)malloc(sizeof(dvbpsi_demux_subdec_t));
if(p_subdec == NULL)
{
return 1;
}
p_eit_decoder = (dvbpsi_eit_decoder_t*)malloc(sizeof(dvbpsi_eit_decoder_t));
if(p_eit_decoder == NULL)
{
free(p_subdec);
return 1;
}
/* subtable decoder configuration */
p_subdec->pf_callback = &dvbpsi_GatherEITSections;
p_subdec->p_cb_data = p_eit_decoder;
p_subdec->i_id = (uint32_t)i_table_id << 16 | (uint32_t)i_extension;
/* Attach the subtable decoder to the demux */
p_subdec->p_next = p_demux->p_first_subdec;
p_demux->p_first_subdec = p_subdec;
/* EIT decoder information */
p_eit_decoder->pf_callback = pf_callback;
p_eit_decoder->p_cb_data = p_cb_data;
/* EIT decoder initial state */
p_eit_decoder->b_current_valid = 0;
p_eit_decoder->p_building_eit = NULL;
for(i = 0; i <= 255; i++)
p_eit_decoder->ap_sections[i] = NULL;
return 0;
}
/*****************************************************************************
* dvbpsi_DetachEIT
*****************************************************************************
* Close a EIT decoder.
*****************************************************************************/
void dvbpsi_DetachEIT(dvbpsi_demux_t * p_demux, uint8_t i_table_id,
uint16_t i_extension)
{
dvbpsi_demux_subdec_t* p_subdec;
dvbpsi_demux_subdec_t* p_next_subdec;
dvbpsi_eit_decoder_t* p_eit_decoder;
unsigned int i;
p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
if(p_demux == NULL)
{
DVBPSI_ERROR_ARG("EIT Decoder",
"No such EIT decoder (table_id == 0x%02x,"
"extension == 0x%02x)",
i_table_id, i_extension);
return;
}
p_next_subdec = p_subdec->p_next;
p_eit_decoder = (dvbpsi_eit_decoder_t*)p_subdec->p_cb_data;
free(p_eit_decoder->p_building_eit);
for(i = 0; i <= 255; i++)
{
if(p_eit_decoder->ap_sections[i])
free(p_eit_decoder->ap_sections[i]);
}
free(p_subdec->p_cb_data);
free(p_subdec);
p_subdec = p_next_subdec;
}
/*****************************************************************************
* dvbpsi_InitEIT
*****************************************************************************
* Initialize a pre-allocated dvbpsi_eit_t structure.
*****************************************************************************/
void dvbpsi_InitEIT(dvbpsi_eit_t* p_eit, uint16_t i_service_id, uint8_t i_version,
int b_current_next, uint16_t i_ts_id, uint16_t i_network_id,
uint8_t i_segment_last_section_number,
uint8_t i_last_table_id)
{
p_eit->i_service_id = i_service_id;
p_eit->i_version = i_version;
p_eit->b_current_next = b_current_next;
p_eit->i_ts_id = i_ts_id;
p_eit->i_network_id = i_network_id;
p_eit->i_segment_last_section_number = i_segment_last_section_number;
p_eit->i_last_table_id = i_last_table_id;
p_eit->p_first_event = NULL;
}
/*****************************************************************************
* dvbpsi_EmptyEIT
*****************************************************************************
* Clean a dvbpsi_eit_t structure.
*****************************************************************************/
void dvbpsi_EmptyEIT(dvbpsi_eit_t* p_eit)
{
dvbpsi_eit_event_t* p_event = p_eit->p_first_event;
while(p_event != NULL)
{
dvbpsi_eit_event_t* p_tmp = p_event->p_next;
dvbpsi_DeleteDescriptors(p_event->p_first_descriptor);
free(p_event);
p_event = p_tmp;
}
p_eit->p_first_event = NULL;
}
/*****************************************************************************
* dvbpsi_EITAddEvent
*****************************************************************************
* Add an event description at the end of the EIT.
*****************************************************************************/
dvbpsi_eit_event_t* dvbpsi_EITAddEvent(dvbpsi_eit_t* p_eit,
uint16_t i_event_id, uint64_t i_start_time, uint32_t i_duration,
uint8_t i_running_status,int b_free_ca)
{
dvbpsi_eit_event_t* p_event
= (dvbpsi_eit_event_t*)malloc(sizeof(dvbpsi_eit_event_t));
if(p_event)
{
p_event->i_event_id = i_event_id;
p_event->i_start_time = i_start_time;
p_event->i_duration = i_duration;
p_event->i_running_status = i_running_status;
p_event->b_free_ca = b_free_ca;
p_event->p_next = NULL;
p_event->p_first_descriptor = NULL;
if(p_eit->p_first_event == NULL)
{
p_eit->p_first_event = p_event;
}
else
{
dvbpsi_eit_event_t* p_last_event = p_eit->p_first_event;
while(p_last_event->p_next != NULL)
p_last_event = p_last_event->p_next;
p_last_event->p_next = p_event;
}
}
return p_event;
}
/*****************************************************************************
* dvbpsi_EITEventAddDescriptor
*****************************************************************************
* Add a descriptor in the EIT event description.
*****************************************************************************/
dvbpsi_descriptor_t* dvbpsi_EITEventAddDescriptor(
dvbpsi_eit_event_t* p_event,
uint8_t i_tag, uint8_t i_length,
uint8_t* p_data)
{
dvbpsi_descriptor_t* p_descriptor
= dvbpsi_NewDescriptor(i_tag, i_length, p_data);
if(p_descriptor)
{
if(p_event->p_first_descriptor == NULL)
{
p_event->p_first_descriptor = p_descriptor;
}
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;
}
/*****************************************************************************
* dvbpsi_GatherEITSections
*****************************************************************************
* Callback for the subtable demultiplexor.
*****************************************************************************/
void dvbpsi_GatherEITSections(dvbpsi_decoder_t * p_psi_decoder,
void * p_private_decoder,
dvbpsi_psi_section_t * p_section)
{
dvbpsi_eit_decoder_t* p_eit_decoder
= (dvbpsi_eit_decoder_t*)p_private_decoder;
int b_append = 1;
int b_reinit = 0;
unsigned int i;
DVBPSI_DEBUG_ARG("EIT decoder",
"Table version %2d, " "i_table_id %2d, " "i_extension %5d, "
"section %3d up to %3d, " "current %1d",
p_section->i_version, p_section->i_table_id,
p_section->i_extension,
p_section->i_number, p_section->i_last_number,
p_section->b_current_next);
if(!p_section->b_syntax_indicator)
{
/* Invalid section_syntax_indicator */
DVBPSI_ERROR("EIT decoder",
"invalid section (section_syntax_indicator == 0)");
b_append = 0;
}
/* Now if b_append is true then we have a valid EIT section */
if(b_append)
{
/* TS discontinuity check */
if(p_psi_decoder->b_discontinuity)
{
b_reinit = 1;
p_psi_decoder->b_discontinuity = 0;
}
else
{
/* Perform a few sanity checks */
if(p_eit_decoder->p_building_eit)
{
if(p_eit_decoder->p_building_eit->i_service_id != p_section->i_extension)
{
/* service_id */
DVBPSI_ERROR("EIT decoder",
"'service_id' differs"
" whereas no TS discontinuity has occurred");
b_reinit = 1;
}
else if(p_eit_decoder->p_building_eit->i_version
!= p_section->i_version)
{
/* version_number */
DVBPSI_ERROR("EIT decoder",
"'version_number' differs"
" whereas no discontinuity has occurred");
b_reinit = 1;
}
else if(p_eit_decoder->i_last_section_number !=
p_section->i_last_number)
{
/* last_section_number */
DVBPSI_ERROR("EIT decoder",
"'last_section_number' differs"
" whereas no discontinuity has occured");
b_reinit = 1;
}
}
else
{
if( (p_eit_decoder->b_current_valid)
&& (p_eit_decoder->current_eit.i_version == p_section->i_version))
{
/* Signal a new EIT if the previous one wasn't active */
if( (!p_eit_decoder->current_eit.b_current_next)
&& (p_section->b_current_next))
{
dvbpsi_eit_t* p_eit = (dvbpsi_eit_t*)malloc(sizeof(dvbpsi_eit_t));
p_eit_decoder->current_eit.b_current_next = 1;
*p_eit = p_eit_decoder->current_eit;
p_eit_decoder->pf_callback(p_eit_decoder->p_cb_data, p_eit);
}
/* Don't decode since this version is already decoded */
b_append = 0;
}
}
}
}
/* Reinit the decoder if wanted */
if(b_reinit)
{
/* Force redecoding */
p_eit_decoder->b_current_valid = 0;
/* Free structures */
if(p_eit_decoder->p_building_eit)
{
free(p_eit_decoder->p_building_eit);
p_eit_decoder->p_building_eit = NULL;
}
/* Clear the section array */
for(i = 0; i <= 255; i++)
{
if(p_eit_decoder->ap_sections[i] != NULL)
{
dvbpsi_DeletePSISections(p_eit_decoder->ap_sections[i]);
p_eit_decoder->ap_sections[i] = NULL;
}
}
}
/* Append the section to the list if wanted */
if(b_append)
{
int b_complete;
/* Initialize the structures if it's the first section received */
if(!p_eit_decoder->p_building_eit)
{
p_eit_decoder->p_building_eit =
(dvbpsi_eit_t*)malloc(sizeof(dvbpsi_eit_t));
dvbpsi_InitEIT(p_eit_decoder->p_building_eit,
p_section->i_extension,
p_section->i_version,
p_section->b_current_next,
((uint16_t)(p_section->p_payload_start[0]) << 8)
| p_section->p_payload_start[1],
((uint16_t)(p_section->p_payload_start[2]) << 8)
| p_section->p_payload_start[3],
p_section->p_payload_start[4],
p_section->p_payload_start[5]);
p_eit_decoder->i_last_section_number = p_section->i_last_number;
}
/* Fill the section array */
if(p_eit_decoder->ap_sections[p_section->i_number] != NULL)
{
DVBPSI_DEBUG_ARG("EIT decoder", "overwrite section number %d",
p_section->i_number);
dvbpsi_DeletePSISections(p_eit_decoder->ap_sections[p_section->i_number]);
}
p_eit_decoder->ap_sections[p_section->i_number] = p_section;
/* Check if we have all the sections */
b_complete = 0;
for(i = 0; i <= p_eit_decoder->i_last_section_number; i++)
{
if(!p_eit_decoder->ap_sections[i])
break;
if(i == p_eit_decoder->i_last_section_number)
b_complete = 1;
}
if(b_complete)
{
/* Save the current information */
p_eit_decoder->current_eit = *p_eit_decoder->p_building_eit;
p_eit_decoder->b_current_valid = 1;
/* Chain the sections */
if(p_eit_decoder->i_last_section_number)
{
for(i = 0; i <= p_eit_decoder->i_last_section_number - 1; i++)
p_eit_decoder->ap_sections[i]->p_next =
p_eit_decoder->ap_sections[i + 1];
}
/* Decode the sections */
dvbpsi_DecodeEITSections(p_eit_decoder->p_building_eit,
p_eit_decoder->ap_sections[0]);
/* Delete the sections */
dvbpsi_DeletePSISections(p_eit_decoder->ap_sections[0]);
/* signal the new EIT */
p_eit_decoder->pf_callback(p_eit_decoder->p_cb_data,
p_eit_decoder->p_building_eit);
/* Reinitialize the structures */
p_eit_decoder->p_building_eit = NULL;
for(i = 0; i <= p_eit_decoder->i_last_section_number; i++)
p_eit_decoder->ap_sections[i] = NULL;
}
}
else
{
dvbpsi_DeletePSISections(p_section);
}
}
/*****************************************************************************
* dvbpsi_DecodeEITSections
*****************************************************************************
* EIT decoder.
*****************************************************************************/
void dvbpsi_DecodeEITSections(dvbpsi_eit_t* p_eit,
dvbpsi_psi_section_t* p_section)
{
uint8_t* p_byte, * p_end;
while(p_section)
{
for(p_byte = p_section->p_payload_start + 3;
p_byte < p_section->p_payload_end;)
{
uint16_t i_event_id = ((uint16_t)(p_byte[0]) << 8) | p_byte[1];
uint64_t i_start_time = ((uint64_t)(p_byte[1]) << 32)
| ((uint64_t)(p_byte[2]) << 24)
| ((uint64_t)(p_byte[3]) << 16)
| ((uint64_t)(p_byte[4]) << 8) | p_byte[5];
uint32_t i_duration = ((uint32_t)(p_byte[5]) << 16)
| ((uint32_t)(p_byte[6]) << 8) | p_byte[7];
uint8_t i_running_status = (uint8_t)(p_byte[8]) >> 5;
int b_free_ca = (int)(p_byte[8]) & 0x10 >> 4;
uint16_t i_length = ((uint16_t)(p_byte[8] & 0xf) << 8) | p_byte[9];
dvbpsi_eit_event_t* p_event = dvbpsi_EITAddEvent(p_eit,
i_event_id, i_start_time, i_duration,
i_running_status, b_free_ca);
/* Event descriptors */
p_byte += 10;
p_end = p_byte + i_length;
while(p_byte + 2 < p_end)
{
uint8_t i_tag = p_byte[0];
uint8_t i_length = p_byte[1];
if(i_length + 2 <= p_end - p_byte)
dvbpsi_EITEventAddDescriptor(p_event, i_tag, i_length, p_byte + 2);
p_byte += 2 + i_length;
}
}
p_section = p_section->p_next;
}
}
/*****************************************************************************
* eit.h
* (c)2004 VideoLAN
* $Id: eit.h 88 2004-02-24 14:31:18Z sam $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*****************************************************************************/
/*!
* \file <eit.h>
* \author Christophe Massiot <massiot@via.ecp.fr>
* \brief Application interface for the EIT decoder and the EIT generator.
*
* Application interface for the EIT decoder and the EIT generator. New
* decoded EIT are sent by callback to the application. If a table
* wasn't active (b_current_next == 0) and the next is the same but active
* (b_current_next == 1) then the event information list is empty and should
* be caught from the previous structure.
*/
#ifndef _DVBPSI_EIT_H_
#define _DVBPSI_EIT_H_
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************
* dvbpsi_eit_event_t
*****************************************************************************/
/*!
* \struct dvbpsi_eit_event_s
* \brief EIT service description structure.
*
* This structure is used to store a decoded EIT event description.
* (ETSI EN 300 468 V1.5.1 section 5.2.4).
*/
/*!
* \typedef struct dvbpsi_eit_service_s dvbpsi_eit_event_t
* \brief dvbpsi_eit_event_t type definition.
*/
typedef struct dvbpsi_eit_event_s
{
uint16_t i_event_id; /*!< event_id */
uint64_t i_start_time; /*!< start_time */
uint32_t i_duration; /*!< duration */
uint8_t i_running_status; /*!< Running status */
int b_free_ca; /*!< Free CA mode flag */
uint16_t i_descriptors_length; /*!< Descriptors loop
length */
dvbpsi_descriptor_t * p_first_descriptor; /*!< First of the following
DVB descriptors */
struct dvbpsi_eit_event_s * p_next; /*!< next element of
the list */
} dvbpsi_eit_event_t;
/*****************************************************************************
* dvbpsi_eit_t
*****************************************************************************/
/*!
* \struct dvbpsi_eit_s
* \brief EIT structure.
*
* This structure is used to store a decoded EIT.
* (ETSI EN 300 468 V1.5.1 section 5.2.4).
*/
/*!
* \typedef struct dvbpsi_eit_s dvbpsi_eit_t
* \brief dvbpsi_eit_t type definition.
*/
typedef struct dvbpsi_eit_s
{
uint16_t i_service_id; /*!< service_id */
uint8_t i_version; /*!< version_number */
int b_current_next; /*!< current_next_indicator */
uint16_t i_ts_id; /*!< transport stream id */
uint16_t i_network_id; /*!< original network id */
uint8_t i_segment_last_section_number; /*!< segment last section number */
uint8_t i_last_table_id; /*!< last table id */
dvbpsi_eit_event_t * p_first_event; /*!< event information list */
} dvbpsi_eit_t;
/*****************************************************************************
* dvbpsi_eit_callback
*****************************************************************************/
/*!
* \typedef void (* dvbpsi_eit_callback)(void* p_cb_data,
dvbpsi_eit_t* p_new_eit)
* \brief Callback type definition.
*/
typedef void (* dvbpsi_eit_callback)(void* p_cb_data, dvbpsi_eit_t* p_new_eit);
/*****************************************************************************
* dvbpsi_AttachEIT
*****************************************************************************/
/*!
* \fn void dvbpsi_AttachEIT(dvbpsi_demux_t * p_demux, uint8_t i_table_id,
uint16_t i_extension, dvbpsi_eit_callback pf_callback,
void* p_cb_data)
* \brief Creation and initialization of a EIT decoder.
* \param p_demux Subtable demultiplexor to which the decoder is attached.
* \param i_table_id Table ID, 0x4E, 0x4F, or 0x50-0x6F.
* \param i_extension Table ID extension, here service ID.
* \param pf_callback function to call back on new EIT.
* \param p_cb_data private data given in argument to the callback.
* \return 0 if everything went ok.
*/
int dvbpsi_AttachEIT(dvbpsi_decoder_t * p_psi_decoder, uint8_t i_table_id,
uint16_t i_extension, dvbpsi_eit_callback pf_callback,
void* p_cb_data);
/*****************************************************************************
* dvbpsi_DetachEIT
*****************************************************************************/
/*!
* \fn void dvbpsi_DetachEIT(dvbpsi_demux_t * p_demux, uint8_t i_table_id,
uint16_t i_extension)
* \brief Destroy a EIT decoder.
* \param p_demux Subtable demultiplexor to which the decoder is attached.
* \param i_table_id Table ID, 0x4E, 0x4F, or 0x50-0x6F.
* \param i_extension Table ID extension, here service ID.
* \return nothing.
*/
void dvbpsi_DetachEIT(dvbpsi_demux_t * p_demux, uint8_t i_table_id,
uint16_t i_extension);
/*****************************************************************************
* dvbpsi_InitEIT/dvbpsi_NewEIT
*****************************************************************************/
/*!
* \fn void dvbpsi_InitEIT(dvbpsi_eit_t* p_eit, uint16_t i_service_id,
uint8_t i_version, int b_current_next, uint16_t i_ts_id,
uint16_t i_network_id, uint8_t i_segment_last_section_number,
uint8_t i_last_table_id)
* \brief Initialize a user-allocated dvbpsi_eit_t structure.
* \param p_eit pointer to the EIT structure
* \param i_service_id service ID
* \param i_version EIT version
* \param b_current_next current next indicator
* \param i_ts_id transport stream ID
* \param i_network_id original network id
* \param i_segment_last_section_number segment_last_section_number
* \param i_last_table_id i_last_table_id
* \return nothing.
*/
void dvbpsi_InitEIT(dvbpsi_eit_t* p_eit, uint16_t i_service_id, uint8_t i_version,
int b_current_next, uint16_t i_ts_id, uint16_t i_network_id,
uint8_t i_segment_last_section_number,
uint8_t i_last_table_id);
/*!
* \def dvbpsi_NewEIT(p_eit, i_ts_id, i_version, b_current_next, i_network_id)
* \brief Allocate and initialize a new dvbpsi_eit_t structure.
* \param p_eit pointer to the EIT structure
* \param i_ts_id transport stream ID
* \param i_version EIT version
* \param b_current_next current next indicator
* \param i_network_id original network id
* \return nothing.
*/
#define dvbpsi_NewEIT(p_eit, i_service_id, i_version, b_current_next, i_ts_id, i_network_id, i_segment_last_section_number, i_last_table_id) \
p_eit = (dvbpsi_eit_t*)malloc(sizeof(dvbpsi_eit_t)); \
if(p_eit != NULL) \
dvbpsi_InitEIT(p_eit, i_service_id, i_version, b_current_next, i_ts_id, i_network_id, i_segment_last_section_number, i_last_table_id);
/*****************************************************************************
* dvbpsi_EmptyEIT/dvbpsi_DeleteEIT
*****************************************************************************/
/*!
* \fn void dvbpsi_EmptyEIT(dvbpsi_eit_t* p_eit)
* \brief Clean a dvbpsi_eit_t structure.
* \param p_eit pointer to the EIT structure
* \return nothing.
*/
void dvbpsi_EmptyEIT(dvbpsi_eit_t* p_eit);
/*!
* \def dvbpsi_DeleteEIT(p_eit)
* \brief Clean and free a dvbpsi_eit_t structure.
* \param p_eit pointer to the EIT structure
* \return nothing.
*/
#define dvbpsi_DeleteEIT(p_eit) \
dvbpsi_EmptyEIT(p_eit); \
free(p_eit);
/*****************************************************************************
* dvbpsi_EITAddEvent
*****************************************************************************/
/*!
* \fn dvbpsi_eit_event_t* dvbpsi_EITAddEvent(dvbpsi_eit_t* p_eit,
uint16_t i_event_id,
uint64_t i_start_time,
uint32_t i_duration,
uint8_t i_running_status,
int b_free_ca)
* \brief Add a service description at the end of the EIT.
* \param p_eit pointer to the EIT structure
* \param i_event_id Event ID
* \param i_start_time Start Time
* \param i_duration Duration
* \param i_running_status Running status
* \param b_free_ca Free CA flag
* \return a pointer to the added service description.
*/
dvbpsi_eit_event_t* dvbpsi_EITAddEvent(dvbpsi_eit_t* p_eit,
uint16_t i_event_id, uint64_t i_start_time, uint32_t i_duration,
uint8_t i_running_status, int b_free_ca);
#ifdef __cplusplus
};
#endif
#else
#error "Multiple inclusions of eit.h"
#endif
/*****************************************************************************
* eit_private.h: private EIT structures
*----------------------------------------------------------------------------
* (c)2004 VideoLAN
* $Id: eit_private.h 88 2004-02-24 14:31:18Z sam $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*----------------------------------------------------------------------------
*
*****************************************************************************/
#ifndef _DVBPSI_EIT_PRIVATE_H_
#define _DVBPSI_EIT_PRIVATE_H_
/*****************************************************************************
* dvbpsi_eit_decoder_t
*****************************************************************************
* EIT decoder.
*****************************************************************************/
typedef struct dvbpsi_eit_decoder_s
{
dvbpsi_eit_callback pf_callback;
void * p_cb_data;
dvbpsi_eit_t current_eit;
dvbpsi_eit_t * p_building_eit;
int b_current_valid;
uint8_t i_last_section_number;
dvbpsi_psi_section_t * ap_sections [256];
} dvbpsi_eit_decoder_t;
/*****************************************************************************
* dvbpsi_GatherEITSections
*****************************************************************************
* Callback for the PSI decoder.
*****************************************************************************/
void dvbpsi_GatherEITSections(dvbpsi_decoder_t* p_psi_decoder,
void* p_private_decoder,
dvbpsi_psi_section_t* p_section);
/*****************************************************************************
* dvbpsi_DecodeEITSection
*****************************************************************************
* EIT decoder.
*****************************************************************************/
void dvbpsi_DecodeEITSections(dvbpsi_eit_t* p_eit,
dvbpsi_psi_section_t* p_section);
#else
#error "Multiple inclusions of eit_private.h"
#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