创建PCR包的代码分享
内有详细解释:
//功能:创建PCR包//参数:tsPacket是要填充的TS包;pcrValue已知的PCR值;pcrPid含PCR的TS包的PID;void CreatePcrPacket(LPBYTE tsPacket, INT64 pcrValue, USHORT pcrPid){//创建的PCR包只是对其前12个字节处理,后176个字节写入0xff;FillMemory(tsPacket, TS_PACKET_SIZE, 0xff);//用0xff填写ts包;tsPacket[0] = 0x47;tsPacket[1] = (pcrPid >> 8) & 0x1f;tsPacket[2] = (pcrPid & 0xff);tsPacket[3] = 0x20;tsPacket[4] = 0xB7; //自适应区长tsPacket[5] = 0x10; //PCR标志// 加入PCR值INT64 i_pcr_base = pcrValue/300;//计算出pcr的基值;INT i_pcr_ext = pcrValue%300;//计算出pcr的扩展值;//pcr的编码方法tsPacket[6] = (i_pcr_base >> 25) & 0xff;tsPacket[7] = (i_pcr_base >> 17) & 0xff;tsPacket[8] = (i_pcr_base >> 9) & 0xff;tsPacket[9] = (i_pcr_base >> 1) & 0xff;tsPacket[10] = ((i_pcr_base << 7) & 0x80) | ((i_pcr_ext >> 8) & 0x01);tsPacket[11] = i_pcr_ext & 0xff;}