libdvbpsi  1.3.0
dvbpsi.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002  * dvbpsi.h
00003  * Copyright (C) 2001-2012 VideoLAN
00004  * $Id$
00005  *
00006  * Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
00007  *          Jean-Paul Saman <jpsaman@videolan.org>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022  *
00023  *****************************************************************************/
00024 
00035 #ifndef _DVBPSI_DVBPSI_H_
00036 #define _DVBPSI_DVBPSI_H_
00037 
00038 #define DVBPSI_VERSION      1.3.0              
00039 #define DVBPSI_VERSION_INT  ((1<<16)+(3<<8)+0) 
00041 #ifdef __cplusplus
00042 extern "C" {
00043 #endif
00044 
00045 /*****************************************************************************
00046  * Helper for GCC version checks borrowed from VLC.
00047  *****************************************************************************/
00052 #ifdef __GNUC__
00053 # define DVBPSI_GCC_VERSION(maj,min) \
00054     ((__GNUC__ > (maj)) || (__GNUC__ == (maj) && __GNUC_MINOR__ >= (min)))
00055 #else
00056 # define DVBPSI_GCC_VERSION(maj,min) (0)
00057 #endif
00058 
00059 /*****************************************************************************
00060  * dvbpsi_t
00061  *****************************************************************************/
00066 typedef struct dvbpsi_s dvbpsi_t;
00067 
00072 enum dvbpsi_msg_level
00073 {
00074     DVBPSI_MSG_NONE  = -1, 
00075     DVBPSI_MSG_ERROR =  0, 
00076     DVBPSI_MSG_WARN  =  1, 
00077     DVBPSI_MSG_DEBUG =  2, 
00078 };
00083 typedef enum dvbpsi_msg_level dvbpsi_msg_level_t;
00084 
00085 /*****************************************************************************
00086  * dvbpsi_message_cb
00087  *****************************************************************************/
00094 typedef void (* dvbpsi_message_cb)(dvbpsi_t *handle,
00095                                    const dvbpsi_msg_level_t level,
00096                                    const char* msg);
00097 
00098 /*****************************************************************************
00099  * dvbpsi_decoder_t
00100  *****************************************************************************/
00105 typedef struct dvbpsi_decoder_s dvbpsi_decoder_t;
00106 
00111 /* Clever cast borrowed from VLC */
00112 #if DVBPSI_GCC_VERSION(4,0)
00113 # ifndef __cplusplus
00114 #  define DVBPSI_DECODER( x ) \
00115     __builtin_choose_expr( \
00116         __builtin_offsetof(__typeof__(*(x)), i_magic), \
00117         (void)0, \
00118         (dvbpsi_decoder_t *)(x))
00119 # else
00120 #  define DVBPSI_DECODER( x ) \
00121     ((dvbpsi_decoder_t *)(x) \
00122       + 0 * __builtin_offsetof(__typeof__(*(x)), i_magic))
00123 # endif
00124 #else
00125 # define DVBPSI_DECODER(x) ((dvbpsi_decoder_t *)(x))
00126 #endif
00127 
00128 /*****************************************************************************
00129  * dvbpsi_t
00130  *****************************************************************************/
00142 struct dvbpsi_s
00143 {
00144     dvbpsi_decoder_t             *p_decoder;          
00146     /* Messages callback */
00147     dvbpsi_message_cb             pf_message;           
00148     enum dvbpsi_msg_level         i_msg_level;          
00150     /* private data pointer for use by caller, not by libdvbpsi itself ! */
00151     void                         *p_sys;                
00155 };
00156 
00157 /*****************************************************************************
00158  * dvbpsi_new
00159  *****************************************************************************/
00171 dvbpsi_t *dvbpsi_new(dvbpsi_message_cb callback, enum dvbpsi_msg_level level);
00172 
00173 /*****************************************************************************
00174  * dvbpsi_delete
00175  *****************************************************************************/
00185 void dvbpsi_delete(dvbpsi_t *p_dvbpsi);
00186 
00187 /*****************************************************************************
00188  * dvbpsi_packet_push
00189  *****************************************************************************/
00199 bool dvbpsi_packet_push(dvbpsi_t *p_dvbpsi, uint8_t* p_data);
00200 
00201 /*****************************************************************************
00202  * dvbpsi_psi_section_t
00203  *****************************************************************************/
00204 
00209 typedef struct dvbpsi_psi_section_s dvbpsi_psi_section_t;
00210 
00211 /*****************************************************************************
00212  * dvbpsi_callback_gather_t
00213  *****************************************************************************/
00219 typedef void (* dvbpsi_callback_gather_t)(dvbpsi_t *p_dvbpsi,  
00220                             dvbpsi_psi_section_t* p_section);  
00222 /*****************************************************************************
00223  * DVBPSI_DECODER_COMMON
00224  *****************************************************************************/
00231 #define DVBPSI_DECODER_COMMON                                                     \
00232                                                                                \
00236                                                                            \
00237     uint8_t  i_magic[3];                              \
00238     bool     b_complete_header;                 \
00239     bool     b_discontinuity;                           \
00240     bool     b_current_valid;                      \
00241     uint8_t  i_continuity_counter;                      \
00242     uint8_t  i_last_section_number;           \
00243     dvbpsi_psi_section_t *p_current_section;               \
00244     dvbpsi_psi_section_t *p_sections;        \
00245     dvbpsi_callback_gather_t  pf_gather;            \
00246     int      i_section_max_size;    \
00247     int      i_need;                                          \
00248 
00250 /*****************************************************************************
00251  * struct dvbpsi_decoder_s
00252  *****************************************************************************/
00253 
00260 struct dvbpsi_decoder_s
00261 {
00262     DVBPSI_DECODER_COMMON
00263 };
00264 
00265 /*****************************************************************************
00266  * dvbpsi_decoder_new
00267  *****************************************************************************/
00284 void *dvbpsi_decoder_new(dvbpsi_callback_gather_t pf_gather,
00285                          const int i_section_max_size,
00286                          const bool b_discontinuity,
00287                          const size_t psi_size);
00288 
00289 /*****************************************************************************
00290  * dvbpsi_decoder_delete
00291  *****************************************************************************/
00301 void dvbpsi_decoder_delete(dvbpsi_decoder_t *p_decoder);
00302 
00303 /*****************************************************************************
00304  * dvbpsi_decoder_reset
00305  *****************************************************************************/
00314 void dvbpsi_decoder_reset(dvbpsi_decoder_t* p_decoder, const bool b_force);
00315 
00316 /*****************************************************************************
00317  * dvbpsi_decoder_psi_sections_completed
00318  *****************************************************************************/
00325 bool dvbpsi_decoder_psi_sections_completed(dvbpsi_decoder_t* p_decoder);
00326 
00327 /*****************************************************************************
00328  * dvbpsi_decoder_psi_section_add
00329  *****************************************************************************/
00337 bool dvbpsi_decoder_psi_section_add(dvbpsi_decoder_t *p_decoder, dvbpsi_psi_section_t *p_section);
00338 
00339 /*****************************************************************************
00340  * dvbpsi_decoder_present
00341  *****************************************************************************/
00351 bool dvbpsi_decoder_present(dvbpsi_t *p_dvbpsi);
00352 
00353 #ifdef __cplusplus
00354 };
00355 #endif
00356 
00357 #else
00358 #error "Multiple inclusions of dvbpsi.h"
00359 #endif