标签:hello demo convert 长度 struct get packet ica lib
1、rtcp是个非常小的多媒体控制协议,一般和jitter buffer一起用于rtp延时,抖动,丢包等处理。
1) rtcp应用描述,值得一看
详细的文档描述https://wenku.baidu.com/view/e21ee8e9b8f67c1cfad6b8f2.html
2) rtcp数据结构,消息构建,感谢网友。
https://www.cnblogs.com/Jimmly/archive/2009/08/03/1537468.html
https://www.cnblogs.com/Jimmly/archive/2009/09/02/1535648.html
c++的demo我改成c了,在code::blocks里调试的
rtcp.c
#include <stdio.h> #include <stdlib.h> #include <stdint.h> typedef struct _RTP_HEAD { unsigned char Version : 2; unsigned char Padding : 1; unsigned char Extension : 1; unsigned char Ccount : 4; unsigned char Marker : 1; unsigned char Ptype : 7; unsigned char Snumber; //16bits unsigned int Timestamp; //32 unsigned int Ssrc; //32 unsigned int Csrc; //32 }RTP_HEAD,*pRTP_HEAD; //RTCP的头部信息: typedef struct _RTCP_HEAD { unsigned char Version : 2; unsigned char Padding : 1; unsigned char PCount : 5; unsigned char Ptype; //8bits unsigned char Length; //16bits }RTCP_HEAD,*pRTCP_HEAD; //RTP的bit图和代码实现: // 0 1 2 3 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // 0 |V=2|P|X| CC |M| PT | sequence number | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // 4 | timestamp | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // 8 | synchronization source (SSRC) identifier | // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // 12 | payload header | // | .... | // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // | payload | // | .... | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ void RTPCompose( char *buffer, int payloadType, int sequenceNum, int timestamp, int ssrc, const char* payloadHeader, int payloadHeaderLength, const char* payload, int payloadLength ) { //ASSERT( payload && payloadLength >= 0 ); //buffer.resize( 12 + payloadHeaderLength + payloadLength ); buffer = malloc(12 + payloadHeaderLength + payloadLength); buffer[0] = (char)(2<<6); // v=2, p=x=cc=0 buffer[1] = (char)(payloadType & 0x127); // 7-bits for payload type *((unsigned short*)&buffer[2]) = (unsigned short)sequenceNum; *((unsigned int*)&buffer[4]) = (unsigned int)timestamp; *((unsigned int*)&buffer[8]) = (unsigned int)ssrc; memcpy( &buffer[12], payloadHeader, payloadHeaderLength ); memcpy( &buffer[12+payloadHeaderLength], payload, payloadLength ); } //RTCP的bit图和代码实现: // 0 1 2 3 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ //byte=0 |V=2|P| RC | PT=SR=200 | length | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // 4 | SSRC of sender | // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // 8 | NTP timestamp, most significant word | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // 12 | NTP timestamp, least significant word | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // 16 | RTP timestamp | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // 20 | sender‘s packet count | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // 24 | sender‘s octet count | // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // 28 |V=2|P| SC | PT=SDES=202 | length | // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // 32 | SSRC/CSRC_1 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // 36 | CNAME=1 | length | user and domain name ... // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ void RTCPSRCompose( char *buffer, int receptionCount, int ssrc, int64_t ntpTimestamp, int rtpTimestamp, int sentPackets, int sentBytes, const char* cname ) { //const string& cnameUTF8 = ConvertToUTF8( cname ); //int length = 8 + 20 + 4 + 6 + cnameUTF8.size( ); // 注意此处可能存在bug。 //buffer.resize( length ); buffer = malloc(8 + 20 + 4 + 6 + strlen(cname)); buffer[0] = (char)(2<<6); // V=2, P=RC=0 buffer[1] = (char)200; // PT=SR=200 *(unsigned short*)&buffer[2] = 6; // length (7 32-bit words, minus one) *(unsigned int*)&buffer[4] = (unsigned int)ssrc; *(unsigned int*)&buffer[8] = (unsigned int)(ntpTimestamp >> 32); // High 32-bits *(unsigned int*)&buffer[12] = (unsigned int)(ntpTimestamp & 0xFFFFFFFF); // Low 32-bits *(unsigned int*)&buffer[16] = (unsigned int)rtpTimestamp; *(unsigned int*)&buffer[20] = (unsigned int)sentPackets; *(unsigned int*)&buffer[24] = (unsigned int)sentBytes; buffer[28] = (char)(2<<6 & 1); // V=2, P=0, SC=1 *(unsigned short*)&buffer[30] = 0xFFFF; // 注意这里应该填写长度,由于我们并没有数据因此无法填写。请程序员按自己的包长自己填写。 *(unsigned int*)&buffer[32] = (unsigned int)ssrc; buffer[36] = 1; // CNAME=1 buffer[37] = strlen(cname);//(char)cnameUTF8.size( ); memcpy( &buffer[38], cname, strlen(cname) ); // 同理此处请程序员自己填写 } int main() { printf("Hello world!\n"); return 0; }
标签:hello demo convert 长度 struct get packet ica lib
原文地址:https://www.cnblogs.com/dong1/p/10331513.html