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

📄 pat.c

📁 libdvbpsi4-0.1.5版本
💻 C
📖 第 1 页 / 共 2 页
字号:
                       " whereas no TS discontinuity has occured");          b_reinit = 1;        }        else if(p_pat_decoder->p_building_pat->i_version                                                != p_section->i_version)        {          /* version_number */          DVBPSI_ERROR("PAT decoder",                       "'version_number' differs"                       " whereas no discontinuity has occured");          b_reinit = 1;        }        else if(p_pat_decoder->i_last_section_number !=                                                p_section->i_last_number)        {          /* last_section_number */          DVBPSI_ERROR("PAT decoder",                       "'last_section_number' differs"                       " whereas no discontinuity has occured");          b_reinit = 1;        }      }      else      {        if(    (p_pat_decoder->b_current_valid)            && (p_pat_decoder->current_pat.i_version == p_section->i_version))        {          /* Signal a new PAT if the previous one wasn't active */          if(    (!p_pat_decoder->current_pat.b_current_next)              && (p_section->b_current_next))          {            dvbpsi_pat_t* p_pat = (dvbpsi_pat_t*)malloc(sizeof(dvbpsi_pat_t));            p_pat_decoder->current_pat.b_current_next = 1;            *p_pat = p_pat_decoder->current_pat;            p_pat_decoder->pf_callback(p_pat_decoder->p_cb_data, p_pat);          }          /* Don't decode since this version is already decoded */          b_append = 0;        }      }    }  }  /* Reinit the decoder if wanted */  if(b_reinit)  {    /* Force redecoding */    p_pat_decoder->b_current_valid = 0;    /* Free structures */    if(p_pat_decoder->p_building_pat)    {      free(p_pat_decoder->p_building_pat);      p_pat_decoder->p_building_pat = NULL;    }    /* Clear the section array */    for(i = 0; i <= 255; i++)    {      if(p_pat_decoder->ap_sections[i] != NULL)      {        dvbpsi_DeletePSISections(p_pat_decoder->ap_sections[i]);        p_pat_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_pat_decoder->p_building_pat)    {      p_pat_decoder->p_building_pat =                                (dvbpsi_pat_t*)malloc(sizeof(dvbpsi_pat_t));      dvbpsi_InitPAT(p_pat_decoder->p_building_pat,                     p_section->i_extension,                     p_section->i_version,                     p_section->b_current_next);      p_pat_decoder->i_last_section_number = p_section->i_last_number;    }    /* Fill the section array */    if(p_pat_decoder->ap_sections[p_section->i_number] != NULL)    {      DVBPSI_DEBUG_ARG("PAT decoder", "overwrite section number %d",                       p_section->i_number);      dvbpsi_DeletePSISections(p_pat_decoder->ap_sections[p_section->i_number]);    }    p_pat_decoder->ap_sections[p_section->i_number] = p_section;    /* Check if we have all the sections */    b_complete = 0;    for(i = 0; i <= p_pat_decoder->i_last_section_number; i++)    {      if(!p_pat_decoder->ap_sections[i])        break;      if(i == p_pat_decoder->i_last_section_number)        b_complete = 1;    }    if(b_complete)    {      /* Save the current information */      p_pat_decoder->current_pat = *p_pat_decoder->p_building_pat;      p_pat_decoder->b_current_valid = 1;      /* Chain the sections */      if(p_pat_decoder->i_last_section_number)      {        for(i = 0; i <= p_pat_decoder->i_last_section_number - 1; i++)          p_pat_decoder->ap_sections[i]->p_next =                                        p_pat_decoder->ap_sections[i + 1];      }      /* Decode the sections */      dvbpsi_DecodePATSections(p_pat_decoder->p_building_pat,                               p_pat_decoder->ap_sections[0]);      /* Delete the sections */      dvbpsi_DeletePSISections(p_pat_decoder->ap_sections[0]);      /* signal the new PAT */      p_pat_decoder->pf_callback(p_pat_decoder->p_cb_data,                                 p_pat_decoder->p_building_pat);      /* Reinitialize the structures */      p_pat_decoder->p_building_pat = NULL;      for(i = 0; i <= p_pat_decoder->i_last_section_number; i++)        p_pat_decoder->ap_sections[i] = NULL;    }  }  else  {    dvbpsi_DeletePSISections(p_section);  }}/***************************************************************************** * dvbpsi_DecodePATSection ***************************************************************************** * PAT decoder. *****************************************************************************/void dvbpsi_DecodePATSections(dvbpsi_pat_t* p_pat,                               dvbpsi_psi_section_t* p_section){  uint8_t* p_byte;  while(p_section)  {    for(p_byte = p_section->p_payload_start;        p_byte < p_section->p_payload_end;        p_byte += 4)    {      uint16_t i_program_number = ((uint16_t)(p_byte[0]) << 8) | p_byte[1];      uint16_t i_pid = ((uint16_t)(p_byte[2] & 0x1f) << 8) | p_byte[3];      dvbpsi_PATAddProgram(p_pat, i_program_number, i_pid);    }    p_section = p_section->p_next;  }}/***************************************************************************** * dvbpsi_GenPATSections ***************************************************************************** * Generate PAT sections based on the dvbpsi_pat_t structure. The third * argument is used to limit the number of program in each section (max: 253). *****************************************************************************/dvbpsi_psi_section_t* dvbpsi_GenPATSections(dvbpsi_pat_t* p_pat,                                            int i_max_pps){  dvbpsi_psi_section_t* p_result = dvbpsi_NewPSISection(1024);  dvbpsi_psi_section_t* p_current = p_result;  dvbpsi_psi_section_t* p_prev;  dvbpsi_pat_program_t* p_program = p_pat->p_first_program;  int i_count = 0;  /* A PAT section can carry up to 253 programs */  if((i_max_pps <= 0) || (i_max_pps > 253))    i_max_pps = 253;  p_current->i_table_id = 0;  p_current->b_syntax_indicator = 1;  p_current->b_private_indicator = 0;  p_current->i_length = 9;                      /* header + CRC_32 */  p_current->i_extension = p_pat->i_ts_id;  p_current->i_version = p_pat->i_version;  p_current->b_current_next = p_pat->b_current_next;  p_current->i_number = 0;  p_current->p_payload_end += 8;                /* just after the header */  p_current->p_payload_start = p_current->p_payload_end;  /* PAT programs */  while(p_program != NULL)  {    /* New section if needed */    if(++i_count > i_max_pps)    {      p_prev = p_current;      p_current = dvbpsi_NewPSISection(1024);      p_prev->p_next = p_current;      i_count = 1;      p_current->i_table_id = 0;      p_current->b_syntax_indicator = 1;      p_current->b_private_indicator = 0;      p_current->i_length = 9;                  /* header + CRC_32 */      p_current->i_extension = p_pat->i_ts_id;      p_current->i_version = p_pat->i_version;      p_current->b_current_next = p_pat->b_current_next;      p_current->i_number = p_prev->i_number + 1;      p_current->p_payload_end += 8;            /* just after the header */      p_current->p_payload_start = p_current->p_payload_end;    }    /* p_payload_end is where the program begins */    p_current->p_payload_end[0] = p_program->i_number >> 8;    p_current->p_payload_end[1] = p_program->i_number;    p_current->p_payload_end[2] = (p_program->i_pid >> 8) | 0xe0;    p_current->p_payload_end[3] = p_program->i_pid;    /* Increase length by 4 */    p_current->p_payload_end += 4;    p_current->i_length += 4;    p_program = p_program->p_next;  }  /* Finalization */  p_prev = p_result;  while(p_prev != NULL)  {    p_prev->i_last_number = p_current->i_number;    dvbpsi_BuildPSISection(p_prev);    p_prev = p_prev->p_next;  }  return p_result;}

⌨️ 快捷键说明

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