Commit 19a31474 authored by Jean-Paul Saman's avatar Jean-Paul Saman

src/tables/*: Privatize dvbpsi_decoder_t in dvbpsi_t

All dvbpsi decoders now use dvbpsi_t as handle instead of
dvbpsi_decoder_t *. The pointer to dvbpsi_decoder_t is privatized
and accessible through (dvbpsi_t *)->p_private member. The user
must make sure to cast it to the correct dvbpsi_*_decoder_t type
before accessing structure members.

Dvbpsi decoder developers should use the define DVBPSI_DECODER_COMMON
at the start of a new dvbpsi_*_decoder_t.

WARNING: THIS COMMIT BREAKS THE EXISTING API IN A MAJOR WAY !!!

- most public APIs requires a pointer to existing dvbpsi_t
- new functions to obtain and delete a pointer to dvbpsi_t structure:
  dvbpsi_NewHandle() and dvbpsi_DeleteHandle()
- subtable descriptors fixes
- indentations
parent f6de3f79
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* $Id$ * $Id$
* *
* Authors: Johan Bilien <jobi@via.ecp.fr> * Authors: Johan Bilien <jobi@via.ecp.fr>
* Jean-Paul Saman <jpsaman@videolan.org>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -24,7 +25,6 @@ ...@@ -24,7 +25,6 @@
* *
*****************************************************************************/ *****************************************************************************/
#include "config.h" #include "config.h"
#include <stdio.h> #include <stdio.h>
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#include <stdint.h> #include <stdint.h>
#endif #endif
#include <assert.h>
#include "dvbpsi.h" #include "dvbpsi.h"
#include "dvbpsi_private.h" #include "dvbpsi_private.h"
#include "psi.h" #include "psi.h"
...@@ -46,39 +48,33 @@ ...@@ -46,39 +48,33 @@
***************************************************************************** *****************************************************************************
* Creation of the demux structure * Creation of the demux structure
*****************************************************************************/ *****************************************************************************/
dvbpsi_handle dvbpsi_AttachDemux(dvbpsi_demux_new_cb_t pf_new_cb, dvbpsi_t *dvbpsi_AttachDemux(dvbpsi_t * p_dvbpsi,
void * p_new_cb_data) dvbpsi_demux_new_cb_t pf_new_cb,
void * p_new_cb_data)
{ {
dvbpsi_handle h_dvbpsi = (dvbpsi_decoder_t*)malloc(sizeof(dvbpsi_decoder_t)); assert(p_dvbpsi);
dvbpsi_demux_t * p_demux; assert(p_dvbpsi->p_private);
if(h_dvbpsi == NULL) dvbpsi_demux_t *p_demux = (dvbpsi_demux_t*)malloc(sizeof(dvbpsi_demux_t));
return NULL; if (p_demux == NULL)
return NULL;
p_demux = (dvbpsi_demux_t*)malloc(sizeof(dvbpsi_demux_t));
/* PSI decoder configuration */
if(p_demux == NULL) p_demux->pf_callback = &dvbpsi_Demux;
{ p_demux->i_section_max_size = 4096;
free(h_dvbpsi);
return NULL; /* PSI decoder initial state */
} p_demux->i_continuity_counter = 31;
p_demux->b_discontinuity = 1;
/* PSI decoder configuration */ p_demux->p_current_section = NULL;
h_dvbpsi->pf_callback = &dvbpsi_Demux;
h_dvbpsi->p_private_decoder = p_demux; /* Subtables demux configuration */
h_dvbpsi->i_section_max_size = 4096; p_demux->p_first_subdec = NULL;
/* PSI decoder initial state */ p_demux->pf_new_callback = pf_new_cb;
h_dvbpsi->i_continuity_counter = 31; p_demux->p_new_cb_data = p_new_cb_data;
h_dvbpsi->b_discontinuity = 1;
h_dvbpsi->p_current_section = NULL; p_dvbpsi->p_private = (void *)p_demux;
return p_dvbpsi;
/* Sutables demux configuration */
p_demux->p_decoder = h_dvbpsi;
p_demux->p_first_subdec = NULL;
p_demux->pf_new_callback = pf_new_cb;
p_demux->p_new_cb_data = p_new_cb_data;
return h_dvbpsi;
} }
/***************************************************************************** /*****************************************************************************
...@@ -90,18 +86,18 @@ dvbpsi_demux_subdec_t * dvbpsi_demuxGetSubDec(dvbpsi_demux_t * p_demux, ...@@ -90,18 +86,18 @@ dvbpsi_demux_subdec_t * dvbpsi_demuxGetSubDec(dvbpsi_demux_t * p_demux,
uint8_t i_table_id, uint8_t i_table_id,
uint16_t i_extension) uint16_t i_extension)
{ {
uint32_t i_id = (uint32_t)i_table_id << 16 |(uint32_t)i_extension; uint32_t i_id = (uint32_t)i_table_id << 16 |(uint32_t)i_extension;
dvbpsi_demux_subdec_t * p_subdec = p_demux->p_first_subdec; dvbpsi_demux_subdec_t * p_subdec = p_demux->p_first_subdec;
while(p_subdec) while (p_subdec)
{ {
if(p_subdec->i_id == i_id) if (p_subdec->i_id == i_id)
break; break;
p_subdec = p_subdec->p_next; p_subdec = p_subdec->p_next;
} }
return p_subdec; return p_subdec;
} }
/***************************************************************************** /*****************************************************************************
...@@ -109,37 +105,35 @@ dvbpsi_demux_subdec_t * dvbpsi_demuxGetSubDec(dvbpsi_demux_t * p_demux, ...@@ -109,37 +105,35 @@ dvbpsi_demux_subdec_t * dvbpsi_demuxGetSubDec(dvbpsi_demux_t * p_demux,
***************************************************************************** *****************************************************************************
* Sends a PSI section to the right subtable decoder * Sends a PSI section to the right subtable decoder
*****************************************************************************/ *****************************************************************************/
void dvbpsi_Demux(dvbpsi_handle p_decoder, dvbpsi_psi_section_t * p_section) void dvbpsi_Demux(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section)
{ {
dvbpsi_demux_t * p_demux; assert(p_dvbpsi);
dvbpsi_demux_subdec_t * p_subdec; assert(p_dvbpsi->p_private);
p_demux = (dvbpsi_demux_t *)p_decoder->p_private_decoder; dvbpsi_demux_t * p_demux = (dvbpsi_demux_t *)p_dvbpsi->p_private;
dvbpsi_demux_subdec_t * p_subdec = dvbpsi_demuxGetSubDec(p_demux, p_section->i_table_id,
p_section->i_extension);
p_subdec = dvbpsi_demuxGetSubDec(p_demux, p_section->i_table_id,
p_section->i_extension); if (p_subdec == NULL)
{
if(p_subdec == NULL) /* Tell the application we found a new subtable, so that it may attach a
{ * subtable decoder */
/* Tell the application we found a new subtable, so that it may attach a p_demux->pf_new_callback(p_demux->p_new_cb_data, (dvbpsi_decoder_t *)p_demux,
* subtable decoder */ p_section->i_table_id, p_section->i_extension);
p_demux->pf_new_callback(p_demux->p_new_cb_data, p_decoder,
p_section->i_table_id, /* Check if a new subtable decoder is available */
p_section->i_extension); p_subdec = dvbpsi_demuxGetSubDec(p_demux, p_section->i_table_id,
/* Check if a new subtable decoder is available */ p_section->i_extension);
p_subdec = dvbpsi_demuxGetSubDec(p_demux, p_section->i_table_id, }
p_section->i_extension);
} if (p_subdec)
{
if(p_subdec) p_subdec->pf_callback(p_dvbpsi, p_subdec->p_cb_data, p_section);
{ }
p_subdec->pf_callback(p_demux->p_decoder, p_subdec->p_cb_data, p_section); else
} {
else dvbpsi_DeletePSISections(p_section);
{ }
dvbpsi_DeletePSISections(p_section);
}
} }
/***************************************************************************** /*****************************************************************************
...@@ -147,26 +141,28 @@ void dvbpsi_Demux(dvbpsi_handle p_decoder, dvbpsi_psi_section_t * p_section) ...@@ -147,26 +141,28 @@ void dvbpsi_Demux(dvbpsi_handle p_decoder, dvbpsi_psi_section_t * p_section)
***************************************************************************** *****************************************************************************
* Destroys a demux structure * Destroys a demux structure
*****************************************************************************/ *****************************************************************************/
void dvbpsi_DetachDemux(dvbpsi_handle h_dvbpsi) void dvbpsi_DetachDemux(dvbpsi_t *p_dvbpsi)
{ {
dvbpsi_demux_t* p_demux assert(p_dvbpsi);
= (dvbpsi_demux_t*)h_dvbpsi->p_private_decoder; assert(p_dvbpsi->p_private);
dvbpsi_demux_subdec_t* p_subdec
= p_demux->p_first_subdec; dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *)p_dvbpsi->p_private;
dvbpsi_demux_subdec_t* p_subdec_temp; dvbpsi_demux_subdec_t* p_subdec = p_demux->p_first_subdec;
while(p_subdec) while (p_subdec)
{ {
p_subdec_temp = p_subdec; dvbpsi_demux_subdec_t* p_subdec_temp = p_subdec;
p_subdec = p_subdec->p_next; p_subdec = p_subdec->p_next;
if(p_subdec_temp->pf_detach)
p_subdec_temp->pf_detach(p_demux, (p_subdec_temp->i_id >> 16) & 0xFFFF, if (p_subdec_temp->pf_detach)
p_subdec_temp->i_id & 0xFFFF); p_subdec_temp->pf_detach(p_dvbpsi, (p_subdec_temp->i_id >> 16) & 0xFFFF,
else free(p_subdec_temp); p_subdec_temp->i_id & 0xFFFF);
} else free(p_subdec_temp);
}
free(p_demux);
if(h_dvbpsi->p_current_section) if (p_demux->p_current_section)
dvbpsi_DeletePSISections(h_dvbpsi->p_current_section); dvbpsi_DeletePSISections(p_demux->p_current_section);
free(h_dvbpsi);
p_dvbpsi->p_private = NULL;
free(p_demux);
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* $Id$ * $Id$
* *
* Authors: Johan Bilien <jobi@via.ecp.fr> * Authors: Johan Bilien <jobi@via.ecp.fr>
* Jean-Paul Saman <jpsaman@videolan.org>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -37,19 +38,18 @@ ...@@ -37,19 +38,18 @@
extern "C" { extern "C" {
#endif #endif
/***************************************************************************** /*****************************************************************************
* dvbpsi_demux_new_cb_t * dvbpsi_demux_new_cb_t
*****************************************************************************/ *****************************************************************************/
/*! /*!
* \typedef void(* dvbpsi_demux_new_cb_t) (void * p_cb_data, * \typedef void(* dvbpsi_demux_new_cb_t) (void * p_cb_data,
dvbpsi_handle h_dvbpsi, dvbpsi_decoder_t *p_decoder,
uint8_t i_table_id, uint8_t i_table_id,
uint16_t i_extension); uint16_t i_extension);
* \brief Callback used in case of a new subtable detected. * \brief Callback used in case of a new subtable detected.
*/ */
typedef void (*dvbpsi_demux_new_cb_t) (void * p_cb_data, typedef void (*dvbpsi_demux_new_cb_t) (void * p_cb_data,
dvbpsi_handle h_dvbpsi, dvbpsi_decoder_t *p_decoder,
uint8_t i_table_id, uint8_t i_table_id,
uint16_t i_extension); uint16_t i_extension);
...@@ -58,15 +58,15 @@ typedef void (*dvbpsi_demux_new_cb_t) (void * p_cb_data, ...@@ -58,15 +58,15 @@ typedef void (*dvbpsi_demux_new_cb_t) (void * p_cb_data,
*****************************************************************************/ *****************************************************************************/
/*! /*!
* \typedef void (*dvbpsi_demux_subdec_cb_t) * \typedef void (*dvbpsi_demux_subdec_cb_t)
(dvbpsi_decoder_t* p_psi_decoder, (dvbpsi_t *p_dvbpsi,
void* p_private_decoder, void *p_private_decoder,
dvbpsi_psi_section_t* p_section); dvbpsi_psi_section_t *p_section);
* \brief Subtable specific decoder. * \brief Subtable specific decoder.
*/ */
typedef void (*dvbpsi_demux_subdec_cb_t) typedef void (*dvbpsi_demux_subdec_cb_t)
(dvbpsi_decoder_t* p_psi_decoder, (dvbpsi_t *p_dvbpsi,
void* p_private_decoder, void *p_private_decoder,
dvbpsi_psi_section_t* p_section); dvbpsi_psi_section_t *p_section);
/***************************************************************************** /*****************************************************************************
* dvbpsi_demux_subdec_t * dvbpsi_demux_subdec_t
...@@ -90,12 +90,12 @@ typedef struct dvbpsi_demux_subdec_s ...@@ -90,12 +90,12 @@ typedef struct dvbpsi_demux_subdec_s
void * p_cb_data; void * p_cb_data;
struct dvbpsi_demux_subdec_s * p_next; struct dvbpsi_demux_subdec_s * p_next;
void (*pf_detach)(struct dvbpsi_demux_s *, uint8_t, uint16_t); void (*pf_detach)(dvbpsi_t *, uint8_t, uint16_t);
} dvbpsi_demux_subdec_t; } dvbpsi_demux_subdec_t;
/***************************************************************************** /*****************************************************************************
* dvbpsi_demux_t * dvbpsi_demux_s
*****************************************************************************/ *****************************************************************************/
/*! /*!
* \struct dvbpsi_demux_s * \struct dvbpsi_demux_s
...@@ -108,41 +108,44 @@ typedef struct dvbpsi_demux_subdec_s ...@@ -108,41 +108,44 @@ typedef struct dvbpsi_demux_subdec_s
* \typedef struct dvbpsi_demux_s dvbpsi_demux_t * \typedef struct dvbpsi_demux_s dvbpsi_demux_t
* \brief dvbpsi_demux_t type definition. * \brief dvbpsi_demux_t type definition.
*/ */
typedef struct dvbpsi_demux_s typedef struct dvbpsi_demux_s dvbpsi_demux_t;
struct dvbpsi_demux_s
{ {
dvbpsi_handle p_decoder; /*!< Parent PSI Decoder */ DVBPSI_DECODER_COMMON
dvbpsi_demux_subdec_t * p_first_subdec; /*!< First subtable decoder */
/* New subtable callback */
dvbpsi_demux_new_cb_t pf_new_callback; /*!< New subtable callback */
void * p_new_cb_data; /*!< Data provided to the
previous callback */
} dvbpsi_demux_t; dvbpsi_demux_subdec_t * p_first_subdec; /*!< First subtable decoder */
/* New subtable callback */
dvbpsi_demux_new_cb_t pf_new_callback; /*!< New subtable callback */
void * p_new_cb_data; /*!< Data provided to the
previous callback */
};
/***************************************************************************** /*****************************************************************************
* dvbpsi_AttachDemux * dvbpsi_AttachDemux
*****************************************************************************/ *****************************************************************************/
/*! /*!
* \fn dvbpsi_handle_t dvbpsi_NewPSISection(dvbpsi_demux_new_cb_t pf_new_cb, void * p_new_cb_data) * \fn dvbpsi_t *dvbpsi_NewPSISection(dvbpsi_t *p_dvbpsi, dvbpsi_demux_new_cb_t pf_new_cb, void * p_new_cb_data)
* \brief Creates a new demux structure. * \brief Creates a new demux structure.
* \param p_dvbpsi pointer to dvbpsi_t handle
* \param pf_new_cb A callcack called when a new type of subtable is found. * \param pf_new_cb A callcack called when a new type of subtable is found.
* \param p_new_cb_data Data given to the previous callback. * \param p_new_cb_data Data given to the previous callback.
* \return a handle to the new demux structure. * \return a handle to the new attached demux structure.
*/ */
dvbpsi_handle dvbpsi_AttachDemux(dvbpsi_demux_new_cb_t pf_new_cb, dvbpsi_t *dvbpsi_AttachDemux(dvbpsi_t * p_dvbpsi,
void * p_new_cb_data); dvbpsi_demux_new_cb_t pf_new_cb,
void * p_new_cb_data);
/***************************************************************************** /*****************************************************************************
* dvbpsi_DetachDemux * dvbpsi_DetachDemux
*****************************************************************************/ *****************************************************************************/
/*! /*!
* \fn void dvbpsi_DetachDemux(dvbpsi_handle h_dvbpsi) * \fn void dvbpsi_DetachDemux(dvbpsi_decoder_t *p_decoder)
* \brief Destroys a demux structure. * \brief Destroys a demux structure.
* \param h_dvbpsi The handle of the demux to be destroyed. * \param h_dvbpsi The handle of the demux to be destroyed.
*/ */
void dvbpsi_DetachDemux(dvbpsi_t *p_dvbpsi);
void dvbpsi_DetachDemux(dvbpsi_handle h_dvbpsi);
/***************************************************************************** /*****************************************************************************
* dvbpsi_demuxGetSubDec * dvbpsi_demuxGetSubDec
...@@ -163,14 +166,13 @@ dvbpsi_demux_subdec_t * dvbpsi_demuxGetSubDec(dvbpsi_demux_t * p_demux, ...@@ -163,14 +166,13 @@ dvbpsi_demux_subdec_t * dvbpsi_demuxGetSubDec(dvbpsi_demux_t * p_demux,
* dvbpsi_Demux * dvbpsi_Demux
*****************************************************************************/ *****************************************************************************/
/*! /*!
* \fn void dvbpsi_Demux(dvbpsi_handle h_dvbpsi, * \fn void dvbpsi_Demux(dvbpsi_t *p_dvbpsi,
dvbpsi_psi_section_t * p_section) dvbpsi_psi_section_t * p_section)
* \brief Sends the PSI sections to the right subtable decoder according to their table ID and extension. * \brief Sends the PSI sections to the right subtable decoder according to their table ID and extension.
* \param h_dvbpsi PSI decoder handle. * \param p_dvbpsi PSI decoder handle.
* \param p_section PSI section. * \param p_section PSI section.
*/ */
void dvbpsi_Demux(dvbpsi_handle h_dvbpsi, void dvbpsi_Demux(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section);
dvbpsi_psi_section_t * p_section);
#ifdef __cplusplus #ifdef __cplusplus
}; };
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* $Id$ * $Id$
* *
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
* Jean-Paul Saman <jpsaman@videolan.org>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -30,6 +31,7 @@ ...@@ -30,6 +31,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#if defined(HAVE_INTTYPES_H) #if defined(HAVE_INTTYPES_H)
#include <inttypes.h> #include <inttypes.h>
...@@ -37,6 +39,8 @@ ...@@ -37,6 +39,8 @@
#include <stdint.h> #include <stdint.h>
#endif #endif
#include <assert.h>
#include "dvbpsi.h" #include "dvbpsi.h"
#include "dvbpsi_private.h" #include "dvbpsi_private.h"
#include "psi.h" #include "psi.h"
...@@ -137,13 +141,66 @@ uint32_t dvbpsi_crc32_table[256] = ...@@ -137,13 +141,66 @@ uint32_t dvbpsi_crc32_table[256] =
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
}; };
/*****************************************************************************
* dvbpsi_NewHandle
*****************************************************************************/
dvbpsi_t *dvbpsi_NewHandle(dvbpsi_message_cb callback, int level)
{
dvbpsi_t *handle = calloc(1, sizeof(dvbpsi_t));
if (handle != NULL)
{
handle->p_private = NULL;
handle->pf_message = callback;
handle->i_msg_level = level;
}
return handle;
}
/*****************************************************************************
* dvbpsi_DeleteHandle
*****************************************************************************/
void dvbpsi_DeleteHandle(dvbpsi_t *handle)
{
assert(handle->p_private != NULL);
handle->pf_message = NULL;
free(handle);
}
/*****************************************************************************
* dvbpsi_NewDecoder
*****************************************************************************/
dvbpsi_decoder_t *dvbpsi_NewDecoder(dvbpsi_t *handle, dvbpsi_callback *callback)
{
dvbpsi_decoder_t *p_decoder = calloc(1, sizeof(dvbpsi_decoder_t));
if (p_decoder == NULL)
return NULL;
p_decoder->pf_callback = NULL;
p_decoder->p_current_section = NULL;
return p_decoder;
}
/*****************************************************************************
* dvbpsi_DeletDecoder
*****************************************************************************/
void dvbpsi_DeleteDecoder(dvbpsi_t *handle)
{
assert(handle);
assert(handle->p_private);
dvbpsi_decoder_t *p_decoder = (dvbpsi_decoder_t *) handle->p_private;
handle->p_private = NULL;
free(p_decoder);
}
/***************************************************************************** /*****************************************************************************
* dvbpsi_PushPacket * dvbpsi_PushPacket
***************************************************************************** *****************************************************************************
* Injection of a TS packet into a PSI decoder. * Injection of a TS packet into a PSI decoder.
*****************************************************************************/ *****************************************************************************/
void dvbpsi_PushPacket(dvbpsi_handle h_dvbpsi, uint8_t* p_data) void dvbpsi_PushPacket(dvbpsi_t *handle, uint8_t* p_data)
{ {
uint8_t i_expected_counter; /* Expected continuity counter */ uint8_t i_expected_counter; /* Expected continuity counter */
dvbpsi_psi_section_t* p_section; /* Current section */ dvbpsi_psi_section_t* p_section; /* Current section */
...@@ -154,38 +211,41 @@ void dvbpsi_PushPacket(dvbpsi_handle h_dvbpsi, uint8_t* p_data) ...@@ -154,38 +211,41 @@ void dvbpsi_PushPacket(dvbpsi_handle h_dvbpsi, uint8_t* p_data)
int i_available; /* Byte count available in the int i_available; /* Byte count available in the
packet */ packet */
dvbpsi_decoder_t *p_decoder = (dvbpsi_decoder_t *)handle->p_private;
assert(p_decoder);
/* TS start code */ /* TS start code */
if(p_data[0] != 0x47) if(p_data[0] != 0x47)
{ {
dvbpsi_error(h_dvbpsi, "PSI decoder", "not a TS packet"); dvbpsi_error(handle, "PSI decoder", "not a TS packet");
return; return;
} }
/* Continuity check */ /* Continuity check */
i_expected_counter = (h_dvbpsi->i_continuity_counter + 1) & 0xf; i_expected_counter = (p_decoder->i_continuity_counter + 1) & 0xf;
h_dvbpsi->i_continuity_counter = p_data[3] & 0xf; p_decoder->i_continuity_counter = p_data[3] & 0xf;
if(i_expected_counter == ((h_dvbpsi->i_continuity_counter + 1) & 0xf) if(i_expected_counter == ((p_decoder->i_continuity_counter + 1) & 0xf)
&& !h_dvbpsi->b_discontinuity) && !p_decoder->b_discontinuity)
{ {
dvbpsi_error(h_dvbpsi, "PSI decoder", dvbpsi_error(handle, "PSI decoder",
"TS duplicate (received %d, expected %d) for PID %d", "TS duplicate (received %d, expected %d) for PID %d",
h_dvbpsi->i_continuity_counter, i_expected_counter, p_decoder->i_continuity_counter, i_expected_counter,
((uint16_t)(p_data[1] & 0x1f) << 8) | p_data[2]); ((uint16_t)(p_data[1] & 0x1f) << 8) | p_data[2]);
return; return;
} }
if(i_expected_counter != h_dvbpsi->i_continuity_counter) if(i_expected_counter != p_decoder->i_continuity_counter)
{ {
dvbpsi_error(h_dvbpsi, "PSI decoder", dvbpsi_error(handle, "PSI decoder",
"TS discontinuity (received %d, expected %d) for PID %d", "TS discontinuity (received %d, expected %d) for PID %d",
h_dvbpsi->i_continuity_counter, i_expected_counter, p_decoder->i_continuity_counter, i_expected_counter,
((uint16_t)(p_data[1] & 0x1f) << 8) | p_data[2]); ((uint16_t)(p_data[1] & 0x1f) << 8) | p_data[2]);
h_dvbpsi->b_discontinuity = 1; p_decoder->b_discontinuity = 1;
if(h_dvbpsi->p_current_section) if(p_decoder->p_current_section)
{ {
dvbpsi_DeletePSISections(h_dvbpsi->p_current_section); dvbpsi_DeletePSISections(p_decoder->p_current_section);
h_dvbpsi->p_current_section = NULL; p_decoder->p_current_section = NULL;
} }
} }
...@@ -208,7 +268,7 @@ void dvbpsi_PushPacket(dvbpsi_handle h_dvbpsi, uint8_t* p_data) ...@@ -208,7 +268,7 @@ void dvbpsi_PushPacket(dvbpsi_handle h_dvbpsi, uint8_t* p_data)
p_payload_pos += 1; p_payload_pos += 1;
} }
p_section = h_dvbpsi->p_current_section; p_section = p_decoder->p_current_section;
/* If the psi decoder needs a begginning of section and a new section /* If the psi decoder needs a begginning of section and a new section
begins in the packet then initialize the dvbpsi_psi_section_t structure */ begins in the packet then initialize the dvbpsi_psi_section_t structure */
...@@ -217,16 +277,16 @@ void dvbpsi_PushPacket(dvbpsi_handle h_dvbpsi, uint8_t* p_data) ...@@ -217,16 +277,16 @@ void dvbpsi_PushPacket(dvbpsi_handle h_dvbpsi, uint8_t* p_data)
if(p_new_pos) if(p_new_pos)
{ {
/* Allocation of the structure */ /* Allocation of the structure */
h_dvbpsi->p_current_section p_decoder->p_current_section
= p_section = p_section
= dvbpsi_NewPSISection(h_dvbpsi->i_section_max_size); = dvbpsi_NewPSISection(p_decoder->i_section_max_size);
/* Update the position in the packet */ /* Update the position in the packet */
p_payload_pos = p_new_pos; p_payload_pos = p_new_pos;
/* New section is being handled */ /* New section is being handled */
p_new_pos = NULL; p_new_pos = NULL;
/* Just need the header to know how long is the section */ /* Just need the header to know how long is the section */
h_dvbpsi->i_need = 3; p_decoder->i_need = 3;
h_dvbpsi->b_complete_header = 0; p_decoder->b_complete_header = 0;
} }
else else
{ {
...@@ -240,40 +300,40 @@ void dvbpsi_PushPacket(dvbpsi_handle h_dvbpsi, uint8_t* p_data) ...@@ -240,40 +300,40 @@ void dvbpsi_PushPacket(dvbpsi_handle h_dvbpsi, uint8_t* p_data)
while(i_available > 0) while(i_available > 0)
{ {
if(i_available >= h_dvbpsi->i_need) if(i_available >= p_decoder->i_need)
{ {
/* There are enough bytes in this packet to complete the /* There are enough bytes in this packet to complete the
header/section */ header/section */
memcpy(p_section->p_payload_end, p_payload_pos, h_dvbpsi->i_need); memcpy(p_section->p_payload_end, p_payload_pos, p_decoder->i_need);
p_payload_pos += h_dvbpsi->i_need; p_payload_pos += p_decoder->i_need;
p_section->p_payload_end += h_dvbpsi->i_need; p_section->p_payload_end += p_decoder->i_need;
i_available -= h_dvbpsi->i_need; i_available -= p_decoder->i_need;
if(!h_dvbpsi->b_complete_header) if(!p_decoder->b_complete_header)
{ {
/* Header is complete */ /* Header is complete */
h_dvbpsi->b_complete_header = 1; p_decoder->b_complete_header = 1;
/* Compute p_section->i_length and update h_dvbpsi->i_need */ /* Compute p_section->i_length and update p_decoder->i_need */
h_dvbpsi->i_need = p_section->i_length p_decoder->i_need = p_section->i_length
= ((uint16_t)(p_section->p_data[1] & 0xf)) << 8 = ((uint16_t)(p_section->p_data[1] & 0xf)) << 8
| p_section->p_data[2]; | p_section->p_data[2];
/* Check that the section isn't too long */ /* Check that the section isn't too long */
if(h_dvbpsi->i_need > h_dvbpsi->i_section_max_size - 3) if(p_decoder->i_need > p_decoder->i_section_max_size - 3)
{ {
dvbpsi_error(h_dvbpsi, "PSI decoder", "PSI section too long"); dvbpsi_error(handle, "PSI decoder", "PSI section too long");
dvbpsi_DeletePSISections(p_section); dvbpsi_DeletePSISections(p_section);
h_dvbpsi->p_current_section = NULL; p_decoder->p_current_section = NULL;
/* If there is a new section not being handled then go forward /* If there is a new section not being handled then go forward
in the packet */ in the packet */
if(p_new_pos) if(p_new_pos)
{ {
h_dvbpsi->p_current_section p_decoder->p_current_section
= p_section = p_section
= dvbpsi_NewPSISection(h_dvbpsi->i_section_max_size);