⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdt.c

📁 Dvbstreamer 用在解析MPTS的部分内容
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * sdt.c: SDT decoder/generator *---------------------------------------------------------------------------- * (c)2001-2002 VideoLAN * $Id: sdt.c 110 2005-06-04 12:52:02Z gbazin $ * * Authors: 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 "sdt.h"#include "sdt_private.h"#include "objects.h"/***************************************************************************** * dvbpsi_AttachSDT ***************************************************************************** * Initialize a SDT subtable decoder. *****************************************************************************/int dvbpsi_AttachSDT(dvbpsi_decoder_t * p_psi_decoder, uint8_t i_table_id,          uint16_t i_extension, dvbpsi_sdt_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_sdt_decoder_t*  p_sdt_decoder;  unsigned int i;  if(dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))  {    DVBPSI_ERROR_ARG("SDT 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_sdt_decoder = (dvbpsi_sdt_decoder_t*)malloc(sizeof(dvbpsi_sdt_decoder_t));  if(p_sdt_decoder == NULL)  {    free(p_subdec);    return 1;  }  /* subtable decoder configuration */  p_subdec->pf_callback = &dvbpsi_GatherSDTSections;  p_subdec->p_cb_data = p_sdt_decoder;  p_subdec->i_id = (uint32_t)i_table_id << 16 | (uint32_t)i_extension;  p_subdec->pf_detach = dvbpsi_DetachSDT;  /* Attach the subtable decoder to the demux */  p_subdec->p_next = p_demux->p_first_subdec;  p_demux->p_first_subdec = p_subdec;  /* SDT decoder information */  p_sdt_decoder->pf_callback = pf_callback;  p_sdt_decoder->p_cb_data = p_cb_data;  /* SDT decoder initial state */  p_sdt_decoder->b_current_valid = 0;  p_sdt_decoder->p_building_sdt = NULL;  for(i = 0; i <= 255; i++)    p_sdt_decoder->ap_sections[i] = NULL;  return 0;}/***************************************************************************** * dvbpsi_DetachSDT ***************************************************************************** * Close a SDT decoder. *****************************************************************************/void dvbpsi_DetachSDT(dvbpsi_demux_t * p_demux, uint8_t i_table_id,          uint16_t i_extension){  dvbpsi_demux_subdec_t* p_subdec;  dvbpsi_demux_subdec_t** pp_prev_subdec;  dvbpsi_sdt_decoder_t* p_sdt_decoder;  unsigned int i;  p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);  if(p_demux == NULL)  {    DVBPSI_ERROR_ARG("SDT Decoder",                     "No such SDT decoder (table_id == 0x%02x,"                     "extension == 0x%02x)",                     i_table_id, i_extension);    return;  }  p_sdt_decoder = (dvbpsi_sdt_decoder_t*)p_subdec->p_cb_data;  if (p_sdt_decoder->p_building_sdt)  {    ObjectRefDec(p_sdt_decoder->p_building_sdt);  }  for(i = 0; i <= 255; i++)  {    if(p_sdt_decoder->ap_sections[i])      dvbpsi_DeletePSISections(p_sdt_decoder->ap_sections[i]);  }  free(p_subdec->p_cb_data);  pp_prev_subdec = &p_demux->p_first_subdec;  while(*pp_prev_subdec != p_subdec)    pp_prev_subdec = &(*pp_prev_subdec)->p_next;  *pp_prev_subdec = p_subdec->p_next;  free(p_subdec);}/***************************************************************************** * dvbpsi_InitSDT ***************************************************************************** * Initialize a pre-allocated dvbpsi_sdt_t structure. *****************************************************************************/void dvbpsi_InitSDT(dvbpsi_sdt_t* p_sdt, uint16_t i_ts_id, uint8_t i_version,                    int b_current_next, uint16_t i_network_id){  p_sdt->i_ts_id = i_ts_id;  p_sdt->i_version = i_version;  p_sdt->b_current_next = b_current_next;  p_sdt->i_network_id = i_network_id;  p_sdt->p_first_service = NULL;}/***************************************************************************** * dvbpsi_EmptySDT ***************************************************************************** * Clean a dvbpsi_sdt_t structure. *****************************************************************************/void dvbpsi_EmptySDT(dvbpsi_sdt_t* p_sdt){  dvbpsi_sdt_service_t* p_service = p_sdt->p_first_service;  while(p_service != NULL)  {    dvbpsi_sdt_service_t* p_tmp = p_service->p_next;    dvbpsi_DeleteDescriptors(p_service->p_first_descriptor);    free(p_service);    p_service = p_tmp;  }  p_sdt->p_first_service = NULL;}/***************************************************************************** * dvbpsi_SDTAddService ***************************************************************************** * Add a service description at the end of the SDT. *****************************************************************************/dvbpsi_sdt_service_t *dvbpsi_SDTAddService(dvbpsi_sdt_t* p_sdt,                                           uint16_t i_service_id,                                           int b_eit_schedule,                                           int b_eit_present,                                           uint8_t i_running_status,                                           int b_free_ca){  dvbpsi_sdt_service_t * p_service                = (dvbpsi_sdt_service_t*)malloc(sizeof(dvbpsi_sdt_service_t));  if(p_service)  {    p_service->i_service_id = i_service_id;    p_service->b_eit_schedule = b_eit_schedule;    p_service->b_eit_present = b_eit_present;    p_service->i_running_status = i_running_status;    p_service->b_free_ca = b_free_ca;    p_service->p_next = NULL;    p_service->p_first_descriptor = NULL;    if(p_sdt->p_first_service == NULL)    {      p_sdt->p_first_service = p_service;    }    else    {      dvbpsi_sdt_service_t * p_last_service = p_sdt->p_first_service;      while(p_last_service->p_next != NULL)        p_last_service = p_last_service->p_next;      p_last_service->p_next = p_service;    }  }  return p_service;}/***************************************************************************** * dvbpsi_SDTServiceAddDescriptor ***************************************************************************** * Add a descriptor in the SDT service description. *****************************************************************************/dvbpsi_descriptor_t *dvbpsi_SDTServiceAddDescriptor(                                               dvbpsi_sdt_service_t *p_service,                                               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_service->p_first_descriptor == NULL)    {      p_service->p_first_descriptor = p_descriptor;    }    else    {      dvbpsi_descriptor_t * p_last_descriptor = p_service->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_GatherSDTSections ***************************************************************************** * Callback for the subtable demultiplexor. *****************************************************************************/void dvbpsi_GatherSDTSections(dvbpsi_decoder_t * p_psi_decoder,                              void * p_private_decoder,                              dvbpsi_psi_section_t * p_section){  dvbpsi_sdt_decoder_t * p_sdt_decoder                        = (dvbpsi_sdt_decoder_t*)p_private_decoder;  int b_append = 1;  int b_reinit = 0;  unsigned int i;  DVBPSI_DEBUG_ARG("SDT 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("SDT decoder",                 "invalid section (section_syntax_indicator == 0)");    b_append = 0;  }  /* Now if b_append is true then we have a valid SDT section */  if(b_append)  {    /* TS discontinuity check */    if(p_psi_decoder->b_discontinuity)    {      b_reinit = 1;      p_psi_decoder->b_discontinuity = 0;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -