tdt段分析

来源:百度文库 编辑:神马文学网 时间:2024/04/29 19:01:08

int32  BCD_Seconds(u_int32  _time){   u_int32 temp;   u_int32 hour, minute, second;      temp = bcdint_to_int(_time&0xffffff, 6, 6, 1);      hour = temp/10000;   minute = temp/100 - hour*100;   second = temp - hour*10000 - minute*100;      temp = hour*3600 + minute*60 + second;      return (temp);}/* si_parser_sdt_analyse */
/*************************************************************************************//*                                                                                   *//*                                                                                   *//*                                                                                   *//*                                                                                   *//*                                                                                   *//*                                                                                   *//*************************************************************************************/int32 MJD_year_month_day(u_int32  date){   u_int32  month, day;   u_int32  temp, year;   u_int32  temp1;      temp = (u_int32)date;      year = (temp*100 - 1507820)/36525;   temp1 = year*36525/100;   month = (temp*10 - 149561 - temp1*10)/306.001;   day = temp - 14956 - temp1 - (month*306001/10000);      if((month == 14) || (month == 15))   {      year++;      month = month -1 - 12;   }   else      month--;      year += 1900;   return ((year&0xffff)<<16 | (month&0xff)<<8 | (day&0xff));}
/* si_parser_eit_analyse */
/****************************************************************************//*  FUNCTION:    si_parser_tdt_analyse                                      *//*                                                                          *//*  DESCRIPTION:                                                            *//*                                                                          *//*  INPUTS:                                                                 *//*                                                                          *//*  OUTPUTS:                                                                *//*                                                                          *//*  RETURNS:                                                                *//*                                                                          *//*  NOTES:       NONE                                                       *//*                                                                          *//*  CONTEXT:     Must be called from a non-interrupt context.               *//*                                                                          *//****************************************************************************/static SI_STATUS si_parser_tdt_analyse (   SI_TDT_HANDLE        hTDT,   u_int32              uLen,   u_int8 *             pData){   PTR_TDT_TABLE     pTDT = (PTR_TDT_TABLE)(hTDT);   u_int8 *          pBuffer = pData;   TDT_INFO *        pInfo;   u_int8            tbl_id, sct_syntax_indicator;   u_int16           sct_length;   u_int32           date;   START_TIME        _time;   SI_PARSER_HANDLE  handle;      if ((NULL == pTDT) || (uLen < 8) || (NULL == pBuffer))   {      return (SI_ERROR);   }      /* analyse the header of the section: total 8 bytes */   tbl_id = *pBuffer++;   sct_syntax_indicator = (*pBuffer & 0x80);   sct_length = (*pBuffer++ & 0x0F) << 8;   sct_length |= *pBuffer++;   /* check the header information of the section. */   if ((tbl_id != TID_MPEG2_TDT) || (sct_syntax_indicator != 0x00) ||       (sct_length > 5) || ((sct_length + 3) != (u_int16)uLen))   {      return (SI_ERROR);   }       pInfo = &(pTDT->sTDTInfo);
   pInfo->UTC_date = (*pBuffer++ ) << 8;      pInfo->UTC_date |= *pBuffer++;   pInfo->UTC_time = (*pBuffer++ ) <<16;    pInfo->UTC_time |= (*pBuffer++ ) << 8;   pInfo->UTC_time |= *pBuffer;
   date = MJD_year_month_day(pInfo->UTC_date);
   _time.year = date>>16 & 0xffff;   _time.month = date>>8 & 0xff;   _time.day = date & 0xff;   _time.time.seconds = BCD_Seconds((u_int32)(pInfo->UTC_time)&0xffffff);      if (NULL != pTDT->pfCbSection)   {      pTDT->pfCbSection ();   }
   if (NULL != pTDT->pfCbSingleSection)   {       /* fixme, other method shoud be called to get si_parser handle */       handle = (SI_PARSER_HANDLE)(&siParser);       pTDT->pfCbSingleSection(handle, &_time);   }      return (SI_OK);}