欢迎来到天天文库
浏览记录
ID:11506202
大小:30.50 KB
页数:7页
时间:2018-07-12
《具体h264字节流拆包和rtp封包方法如下》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、可以通过生成SDP文件给播放器在指定端口接收数据播放,如果你不用动态调整编码器什么的就不用考虑另外发送RTCP.而且RTCP必须自己实现RTSP服务结合起来用,没有实现RTSP服务,就谈不上实现RTCP.具体H264字节流拆包和RTP封包方法如下:UINTMediaStreamH264::TransportData(PBYTEpData,UINTdataSize,intpts){PBYTEp_buffer=pData;inti_buffer=dataSize;UINTwriteSize=0;while(i_buffer>4&&(p_buffer[0]!=0
2、
3、p_buf
4、fer[1]!=0
5、
6、p_buffer[2]!=1)){i_buffer--;p_buffer++;}/*Splitnalunits*/while(i_buffer>4){inti_offset;inti_size=i_buffer;inti_skip=i_buffer;/*searchnalend*/for(i_offset=4;i_offset+27、herstartcode*/i_size=i_offset-(p_buffer[i_offset-1]==0?1:0);i_skip=i_offset;break;}}/*TODOaddSTAP-Atoremovealotofoverheadwithsmallslice/sei/...*/UINTiWrite=TransportH264Nal(p_buffer,i_size,pts,(i_size>=i_buffer));if(iWrite>0)writeSize+=iWrite;i_buffer-=i_skip;p_buffer+=i_skip;}returnwrit8、eSize;}UINTMediaStreamH264::TransportH264Nal(constPBYTEpNal,UINTnalSize,INT32pts,BOOLisLast){ATLockatlock(&m_tlockRun);if(m_bRun==FALSE)return0;if(nalSize<5)return0;UINTmtu=m_nMTU;constinti_max=mtu-RTP_HEADER_SIZE;/*payloadmaxinonepacket*/inti_nal_hdr;inti_nal_type;i_nal_hdr=pNal[3];i_na9、l_type=i_nal_hdr&0x1f;stringsps;stringpps;if(i_nal_type==710、11、i_nal_type==8){/*XXXWhydoyouwanttoremovethem?Itwillbreakstreamingwith*SPS/PPSchange(broadcast)?*/return0;}/*Skipstartcode*/PBYTEp_data=pNal;inti_data=nalSize;p_data+=3;i_data-=3;intwriteSize=0;if(i_data<=i_max){/*SingleNALunitpa12、cket*///writeSize=m_pRtpTransport->SetRtpData(p_data,i_data,pts,isLast);writeSize=m_pRtpTransport->Write(p_data,i_data,m_nRtpPayloadType,pts,0,isLast);if(writeSize<=0)return0;returnwriteSize;}else{/*FU-AFragmentationUnitwithoutinterleaving*/constinti_count=(i_data-1+i_max-2-1)/(i_max-2);13、inti;p_data++;i_data--;for(i=0;i14、(i_nal_hdr&0x60)15、28;/*FUheader*/m_Packet.m_pData[1]=(i==0?0x80:0x00)16、((
7、herstartcode*/i_size=i_offset-(p_buffer[i_offset-1]==0?1:0);i_skip=i_offset;break;}}/*TODOaddSTAP-Atoremovealotofoverheadwithsmallslice/sei/...*/UINTiWrite=TransportH264Nal(p_buffer,i_size,pts,(i_size>=i_buffer));if(iWrite>0)writeSize+=iWrite;i_buffer-=i_skip;p_buffer+=i_skip;}returnwrit
8、eSize;}UINTMediaStreamH264::TransportH264Nal(constPBYTEpNal,UINTnalSize,INT32pts,BOOLisLast){ATLockatlock(&m_tlockRun);if(m_bRun==FALSE)return0;if(nalSize<5)return0;UINTmtu=m_nMTU;constinti_max=mtu-RTP_HEADER_SIZE;/*payloadmaxinonepacket*/inti_nal_hdr;inti_nal_type;i_nal_hdr=pNal[3];i_na
9、l_type=i_nal_hdr&0x1f;stringsps;stringpps;if(i_nal_type==7
10、
11、i_nal_type==8){/*XXXWhydoyouwanttoremovethem?Itwillbreakstreamingwith*SPS/PPSchange(broadcast)?*/return0;}/*Skipstartcode*/PBYTEp_data=pNal;inti_data=nalSize;p_data+=3;i_data-=3;intwriteSize=0;if(i_data<=i_max){/*SingleNALunitpa
12、cket*///writeSize=m_pRtpTransport->SetRtpData(p_data,i_data,pts,isLast);writeSize=m_pRtpTransport->Write(p_data,i_data,m_nRtpPayloadType,pts,0,isLast);if(writeSize<=0)return0;returnwriteSize;}else{/*FU-AFragmentationUnitwithoutinterleaving*/constinti_count=(i_data-1+i_max-2-1)/(i_max-2);
13、inti;p_data++;i_data--;for(i=0;i14、(i_nal_hdr&0x60)15、28;/*FUheader*/m_Packet.m_pData[1]=(i==0?0x80:0x00)16、((
14、(i_nal_hdr&0x60)
15、28;/*FUheader*/m_Packet.m_pData[1]=(i==0?0x80:0x00)
16、((
此文档下载收益归作者所有