创建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;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值