音视频同步!RTCP协议解析及代码实现

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"RTCP是实时控制协议(Real-Time Control Protocol)的缩写。RTCP由RFC 3550定义(取代作废的RFC 1889)。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"实时传输协议(RTP)和实时控制协议(RTCP)结合使用,可以监视大型多播网络的数据传递。RTP承载媒体流,而RTCP用于","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"监视传输统计信息和服务质量","attrs":{}},{"type":"text","text":"。监视使接收器能够检测是否有任何丢包并补偿任何延迟抖动。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"两种协议都独立于基础传输层协议和网络层协议工作。RTP标头中的信息告诉接收器如何重建数据,并描述编解码器比特流的打包方式。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"下面我们重点讲解RTCP功能、RTCP信息包等。最后RTCP协议解析实现。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"RTCP有哪些功能","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1、RTCP主要功能是提供有关质量的反馈数据分发。这是RTP角色不可或缺的一部分,传输协议,与流量和拥塞有关其他传输协议的控制功能。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"2、RTCP带有RTP的持久性传输级别标识符源称为规范名称或CNAME。自从如果发现冲突或程序重新启动,接收方要求CNAME跟踪每个参与者。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"接收者也可能要求CNAME将来自给定参与者的多个数据流关联到集合中相关RTP会话的数量,例如同步音频和视频。媒体间同步还需要NTP和RTP数据发送方在RTCP数据包中包含的时间戳。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"3、前两个功能要求所有参与者发送RTCP数据包,因此必须控制速率以使RTP能够扩大到大量参与者。通过让每个参与者将其控制包发送给所有其他人,每个人都可以独立观察参与者的数量。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"4、这项功能对于参加者可以任意进入和离开的松散会话进程十分有用,参加者可以自由进入或离开,没有成员控制或参数协调。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"功能1-3应该在所有环境中使用,尤其是在IP多播环境。RTP应用程序设计师应避免只能在单播模式下工作且无法扩展到的机制更大的数字。RTCP的传输可以单独控制对于发送者和接收者,适用于例如单向链接,而接收者没有反馈可能的。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"RTCP协议的端口","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"RTSP通常使用RTP协议来传送实时流,RTP一般使用偶数端口,而RTCP使用相邻的奇数端口,即RTP端口号+1。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"RTP端口","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/7b/7b0f8c4c67099633dbf7eb64bea9ed31.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"RTCP端口","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/84/84e1b9719ac80843e115017c0a771b4d.png","alt":"在这里插入图片描述","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"RTCP信息包有哪些","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在RTCP通信控制中,RTCP协议的功能是通过不同类型的RTCP包来实现的。RTCP也是基于UDP包来传送的,主要有五种类型的封包:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"SR:发送端报告,由发送RTP数据报的应用程序或中端发出的。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"RR:接收端报告,由接受但不发送RTP数据报的应用程序或中端发出。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"SDES: 源描述,传递与会话成员有关的标识信息的载体,如用户名、邮件、电话等。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":4,"align":null,"origin":null},"content":[{"type":"text","text":"BYE: 通知离开,通知回话中的其他成员将退出会话。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":5,"align":null,"origin":null},"content":[{"type":"text","text":"APP: 由应用程序自己定义,作为RTCP协议的扩展。","attrs":{}}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"c"},"content":[{"type":"text","text":"#define RTCP_SR 200\n#define RTCP_RR 201\n#define RTCP_SDES 202\n#define RTCP_BYE 203\n#define RTCP_APP 204","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我们可以根据这五种类型包判断RTCP头部","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"cpp"},"content":[{"type":"text","text":"static bool dissect_rtcp_heur(u_char *rtcp_info,int PayloadLen)\n{\n unsigned int offset = 0;\n unsigned int first_byte = 0;\n unsigned int packet_type = 0;\n\n\n /* 查看第一个字节 */\n first_byte = rtcp_info[offset];\n\n /* 版本位是否设置为2*/\n\t//printf(\"version: %d\\n\",((first_byte & 0xC0) >> 6));\n if (((first_byte & 0xC0) >> 6) != 2)\n {\n return false;\n }\n\n /* 看包类型 */\n\toffset += 1;\n packet_type = rtcp_info[offset];\n\t//printf(\"packet_type: %d\\n\",packet_type);\n /* 复合数据包中的第一个数据包应该是发送方或接收者报告 */\n if (!((packet_type == RTCP_SR) || (packet_type == RTCP_RR) ||\n (packet_type == RTCP_BYE) || (packet_type == RTCP_APP) ||\n (packet_type == RTCP_PSFB)))\n {\n return false;\n }\n\n /*总长度必须是4个字节的倍数*/\n\t//printf(\"PayloadLen: %d\\n\",PayloadLen);\n if (PayloadLen % 4)\n {\n return false;\n }\n\n /* OK, dissect as RTCP */\n dissect_rtcp(rtcp_info,packet_type,offset,PayloadLen);\n return true;\n}","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"RTCP协议报文格式","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"SR:发送端报告","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/57/572aa27793a84d6b9a1cb534669562d3.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"版本(V)","attrs":{}},{"type":"text","text":":同RTP包头部","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"填充 ( P )","attrs":{}},{"type":"text","text":" :同RTP包头部。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"接收报告计数器(RC)","attrs":{}},{"type":"text","text":":5b 该SR包中接收的报告块的数目。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"包类型(PT)","attrs":{}},{"type":"text","text":": 8bit SR包类型为200","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"长度(length)","attrs":{}},{"type":"text","text":":SR包以32bit为1单位的长度减1","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"同步源(SSRC)","attrs":{}},{"type":"text","text":":SR包发送的同步源标识符。与对应RTP包中的SSRC一样。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"NTP时间戳(Network Time Protocol)","attrs":{}},{"type":"text","text":":SR包发送时的绝对时间。用于同步不同的流。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"RTP时间戳","attrs":{}},{"type":"text","text":":与NTP时间戳对应,与RTP包中的时间戳具有相同的初始值。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Send’s Packet count","attrs":{}},{"type":"text","text":":从开始发包到产生这个SR包的这段时间内发送者发送的有效数据的总字节数,不包括头部和填充,发送者改变SSRC时,该域要清零。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"同步源n的SSRC标识符","attrs":{}},{"type":"text","text":":该报告中包含的是从该源接收到的包的统计信息。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"丢失率","attrs":{}},{"type":"text","text":":表明从上一个SR或RR包发出依来从同步源n发送的RTP包的丢失率。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"累计丢失数据","attrs":{}},{"type":"text","text":":从开始接受SSRC_n的包到发送SR这个时间段内SSRC_n发送的RTP丢失的总数目。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"收到的扩展最大序列号","attrs":{}},{"type":"text","text":":从SSRC_n收到的从RTP数据包中的最大序列号。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"接收抖动(Interarrival jitter)","attrs":{}},{"type":"text","text":":RTP数据包接收时间的统计方差估计。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"上次SR时间戳(Last SR)","attrs":{}},{"type":"text","text":":取最近从SSRC_n收到的SR包中的NTP时间戳中的中间32bit。如果还未收到SR包,则为0。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"上次依赖SR延迟(Delay since Last SR)","attrs":{}},{"type":"text","text":":从上次SSRC_n收到SR包到发送本包的延迟","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Wireshark抓包:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/70/70a9ce4605a32b2ff12cf1dc1b4440fa.png","alt":"在这里插入图片描述","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"活动会话的参与者在发送和接收RTP分组时使用SR。SR有三个不同的部分:报头信息、发送方信息和许多接收方报告块。SR也可以有一个与大纲相关的扩展域。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/8d/8dbca109994317172b276cda17ba13e2.png","alt":"在这里插入图片描述","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Wireshark抓包:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/9d/9d6c4054cffdc73312dc91a0e4ba059a.png","alt":"在这里插入图片描述","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"SDES: 源描述","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"SDES提供了传递与会话成员有关的标识信息的载体,如用户名、邮件、电话等。每个RTCP混合分组中必须有SDES分组。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/02/02f134588c10594b7e4cd5e6ec038752.png","alt":"在这里插入图片描述","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"报头包含一个长度域、一个净荷类型域(PT=202)和一个源计数(RC)域。RC域5个bit,表示分组中信息块的数量。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"每个信息块包含一个SSRC或CSRC值,其后跟着一个或多个的标识符和一些可用于SSRC或CSRC的信息。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"CNAME 项的SDES包必须包含在每个组合RTCP包中。SDES包可能包括其他源描述项,这要根据特别的应用需要,并同时考虑带宽限制。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Wireshark抓包:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/78/78cfb47577b028adb71043d03f0c52b7.png","alt":"在这里插入图片描述","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"SDES源描述包提供了直观的文本信息来描述会话的参加者,包括CNAME、NAME、EMAIL、PHONE、LOC等源描述项。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"这些为接收方获取发送方的有关信息提供了方便。SDES 包由包头与数据块组成,数据块可以没有,也可有多个。包头由版本(V)、填充(P)、长度指示、包类型(PT)和源计数(SC)组成。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"PT占8位,用于识别RTCP的SDES包,SC占5位,指示包含在SDES包中的SSRC/CSRC块数量,零值有效,但没有意义。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"BYE: 通知离开","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"BYE分组用于表示一个或多个媒体源不再是处于激活状态。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/49/49fe19e19a6a1c01aed12468bf6386ce.png","alt":"在这里插入图片描述","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Wireshark抓包:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/fb/fb5a24478fa26dccdc3fc25d7d7f6e17.png","alt":"在这里插入图片描述","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"作为可选项,BYE包可包括一个8位八进制计数,后跟文本信息,表示离开原因。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"最后,组合包中每个RTCP包可独立处理,而不需要按照包组合的先后顺序处理。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在组合包中有以下几条强制约束。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"只要带宽允许,在SR包或RR包中的接收统计应该经常发送,因此每个周期发送的组合RTCP 包中应包含报告包。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"每个组合包中都应该包含SDES CNAME,因为新接收者需要通过接收CNAME来识别源,并与媒体联系进行同步。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"组合包前面是包类型数量,其增长应该受到限制。","attrs":{}}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"RTCP协议如何实现媒体流的同步","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通过抓包分析RTCP发送端报告,RTP的同步其实就靠这三个域:","attrs":{}}]},{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"sender SSRC :SR包发送的同步源标识符。与对应RTP包中的SSRC一样","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"NTP timestamp:SR包发送时的绝对时间。用于同步不同的流。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"RTP timestamp:与NTP时间戳对应,与RTP包中的时间戳具有相同的初始值。","attrs":{}}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/1b/1bc8a64fb2f82722461e8fbee7258593.png","alt":"在这里插入图片描述","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"那怎么计算NTP时间呢?在RTCP中NTP时间存放在8个字节中,分为:MSW和LSW,分别占用4个字节。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"cpp"},"content":[{"type":"text","text":"const char *tvb_ntp_fmt_ts_sec(u_char *rtcp_info, int offset)\n{\n\tuint32_t tempstmp = 0;\n\ttime_t temptime = 0;\n\tstruct tm *bd;\n\tchar *buff = NULL;\n\t\n\ttempstmp = ntohl(*(uint32_t*)(rtcp_info + offset));\n\tif (tempstmp == 0){\n\t\treturn \"NULL\";\n\t}\n\n\t/* We need a temporary variable here so the unsigned math\n\t* works correctly (for years > 2036 according to RFC 2030\n\t* chapter 3).\n\t*/\n\ttemptime = (time_t)(tempstmp - NTP_BASETIME);\n\tbd = gmtime(&temptime);\n\tif (!bd){\n\t\treturn \"Not representable\";\n\t}\n\n\tbuff = (char *)malloc(NTP_TS_SIZE);\n\tsnprintf(buff, NTP_TS_SIZE,\n\t\t\"%s %2d, %d %02d:%02d:%02d UTC\",\n\t\tmon_names[bd->tm_mon],\n\t\tbd->tm_mday,\n\t\tbd->tm_year + 1900,\n\t\tbd->tm_hour,\n\t\tbd->tm_min,\n\t\tbd->tm_sec);\n\treturn buff;\n}","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"NTP timestamp","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"c"},"content":[{"type":"text","text":"\n /* NTP timestamp */\n ts_msw = ntohl(*(uint32_t*)(rtcp_info + offset));\n\tprintf(\"ts_msw: 0x%x\\n\",ts_msw);\n ts_lsw = ntohl(*(uint32_t*)(rtcp_info + offset + 4));\n\tprintf(\"ts_lsw: 0x%x\\n\",ts_lsw);\n\tprintf(\"MSW: %s\\n\",tvb_ntp_fmt_ts_sec(rtcp_info,offset));\n offset += 8;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"RTCP协议实现","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"下面我给出对RTCP协议解析实现的代码,根据回放报文,解析字段信息。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"cpp"},"content":[{"type":"text","text":"/* 接收者/发送者计数是最后5位 */\n#define RTCP_COUNT(octet) ((octet) & 0x1F)\n\n\n#define RTCP_PT_MIN 192\n/* Supplemental H.261 specific RTCP packet types according to Section C.3.5 */\n#define RTCP_FIR 192\n#define RTCP_NACK 193\n#define RTCP_SMPTETC 194\n#define RTCP_IJ 195\n/* RTCP packet types according to Section A.11.1 */\n/* And https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml */\n#define RTCP_SR 200\n#define RTCP_RR 201\n#define RTCP_SDES 202\n#define RTCP_BYE 203\n#define RTCP_APP 204\n#define RTCP_RTPFB 205\n#define RTCP_PSFB 206\n#define RTCP_XR 207\n#define RTCP_AVB 208\n#define RTCP_RSI 209\n#define RTCP_TOKEN 210\n\n#define RTCP_PT_MAX 210\n\n\nstatic const char mon_names[12][4] = {\n\t\"Jan\",\n\t\"Feb\",\n\t\"Mar\",\n\t\"Apr\",\n\t\"May\",\n\t\"Jun\",\n\t\"Jul\",\n\t\"Aug\",\n\t\"Sep\",\n\t\"Oct\",\n\t\"Nov\",\n\t\"Dec\"\n};\n\n/** data structure to hold time values with nanosecond resolution*/\ntypedef struct {\n\ttime_t\tsecs;\n\tint\tnsecs;\n} nstime_t;\n\n\n/*\n * 1900-01-01 00:00:00 (proleptic?) UTC.\n * Used by a number of time formats.\n */\n#define EPOCH_DELTA_1900_01_01_00_00_00_UTC 2208988800U\n\n/*\n * NTP_BASETIME is in fact epoch - ntp_start_time; ntp_start_time\n * is January 1, 2036, 00:00:00 UTC.\n */\n#define NTP_BASETIME EPOCH_DELTA_1900_01_01_00_00_00_UTC\n#define NTP_FLOAT_DENOM 4294967296.0\n#define NTP_TS_SIZE 100\n\n\n/* 解剖长度字段。附加到此字段的文字表示转换为的实际字节数 (即 (原始值 + 1) * 4) */\nstatic int dissect_rtcp_length_field(u_char *rtcp_info, int offset)\n{\n\n uint16_t raw_length = ntohs(*(uint16_t*)(rtcp_info + offset));\n printf(\"(%u bytes)\\n\", (raw_length+1)*4);\n offset += 2;\n return offset;\n}\nstatic int dissect_rtcp_rr(u_char *rtcp_info, int offset,int count, int packet_length )\n{\n int counter = 0;\n uint8_t rr_flt = 0;\n int rr_offset = offset;\n\t\n counter = 1;\n while ( counter <= count ) {\n uint32_t lsr = 0, dlsr = 0;\n\n /* Create a new subtree for a length of 24 bytes */\n\n /* SSRC_n source identifier, 32 bits */\n\n offset += 4;\n\n /* Fraction lost, 8bits */\n rr_flt = rtcp_info[offset];\n\n offset++;\n\n /* Cumulative number of packets lost, 24 bits */\n offset += 3;\n\n\n /* Sequence number cycles */\n\n offset += 2;\n /* highest sequence number received */\n\n offset += 2;\n\n /* Interarrival jitter */\n\n offset += 4;\n\n /* Last SR timestamp */\n lsr = ntohl(*(uint32_t*)(rtcp_info + offset));\n\t\tprintf(\"Last SR timestamp: 0x%x\\n\",lsr);\n offset += 4;\n\n /* Delay since last SR timestamp */\n dlsr = ntohl(*(uint32_t*)(rtcp_info + offset));\n\n printf(\"(%d milliseconds)\\n\",(int)(((double)dlsr/(double)65536) * 1000.0));\n offset += 4;\n\n counter++;\n }\n\n return offset;\n}\n\nconst char *tvb_ntp_fmt_ts_sec(u_char *rtcp_info, int offset)\n{\n\tuint32_t tempstmp = 0;\n\ttime_t temptime = 0;\n\tstruct tm *bd;\n\tchar *buff = NULL;\n\t\n\ttempstmp = ntohl(*(uint32_t*)(rtcp_info + offset));\n\tif (tempstmp == 0){\n\t\treturn \"NULL\";\n\t}\n\n\t/* We need a temporary variable here so the unsigned math\n\t* works correctly (for years > 2036 according to RFC 2030\n\t* chapter 3).\n\t*/\n\ttemptime = (time_t)(tempstmp - NTP_BASETIME);\n\tbd = gmtime(&temptime);\n\tif (!bd){\n\t\treturn \"Not representable\";\n\t}\n\n\tbuff = (char *)malloc(NTP_TS_SIZE);\n\tsnprintf(buff, NTP_TS_SIZE,\n\t\t\"%s %2d, %d %02d:%02d:%02d UTC\",\n\t\tmon_names[bd->tm_mon],\n\t\tbd->tm_mday,\n\t\tbd->tm_year + 1900,\n\t\tbd->tm_hour,\n\t\tbd->tm_min,\n\t\tbd->tm_sec);\n\treturn buff;\n}\n\nstatic int dissect_rtcp_sr(u_char *rtcp_info, int offset,int count, int packet_length)\n{\n\n uint32_t ts_msw = 0, ts_lsw = 0;\n int sr_offset = offset;\n\n /* NTP timestamp */\n ts_msw = ntohl(*(uint32_t*)(rtcp_info + offset));\n\tprintf(\"ts_msw: 0x%x\\n\",ts_msw);\n ts_lsw = ntohl(*(uint32_t*)(rtcp_info + offset + 4));\n\tprintf(\"ts_lsw: 0x%x\\n\",ts_lsw);\n\n\t//printf(\"offset: 0x%x 0x%x 0x%x 0x%x\\n\",rtcp_info[offset],rtcp_info[offset + 1],rtcp_info[offset + 2],rtcp_info[offset + 3]);\n\tprintf(\"MSW: %s\\n\",tvb_ntp_fmt_ts_sec(rtcp_info,offset));\n offset += 8;\n\n /* RTP timestamp, 32 bits */\n\t\n offset += 4;\n /* Sender's packet count, 32 bits */\n\n offset += 4;\n /* Sender's octet count, 32 bits */\n\n offset += 4;\n\n\n /* The rest of the packet is equal to the RR packet */\n if ( count != 0 )\n offset = dissect_rtcp_rr(rtcp_info, offset, count, packet_length-(offset-sr_offset));\n else\n {\n /* If length remaining, assume profile-specific extension bytes */\n if ((offset-sr_offset) < packet_length)\n {\n\n offset = sr_offset + packet_length;\n }\n }\n\n return offset;\n}\n\nstatic int dissect_rtcp_sdes(u_char *rtcp_info, int offset, int count)\n{\n int chunk = 0;\n\n int start_offset = 0;\n int items_start_offset = 0;\n uint32_t ssrc = 0;\n unsigned int item_len = 0;\n unsigned int sdes_type = 0;\n unsigned int prefix_len = 0;\n\n chunk = 1;\n while ( chunk <= count ) \n\t{\n\t\t/* Create a subtree for this chunk; we don't yet know\n\t\t the length. */\n\t\tstart_offset = offset;\n\n\t\tssrc = ntohl(*(uint32_t*)(rtcp_info + offset));\n\t\tprintf(\"Chunk %u, SSRC/CSRC 0x%X\\n\", chunk, ssrc);\n\n\t\t/* SSRC_n source identifier, 32 bits */\n\t\toffset += 4;\n\n\t\t/* Create a subtree for the SDES items; we don't yet know\n\t\t the length */\n\n\n\t\t/*\n\t\t * Not every message is ended with \"null\" bytes, so check for\n\t\t * end of frame as well.\n\t\t */\n\t\t \n\t\t /* ID, 8 bits */\n\t\tsdes_type = rtcp_info[offset];\n\t\tprintf(\"Type: %d\\n\",sdes_type);\n\t\tif (sdes_type == 0)\n\t\t\tbreak;\n\t\toffset++;\n\t\t/* Item length, 8 bits */\n\t\titem_len = rtcp_info[offset];\n\t\tprintf(\"Length: %d\\n\",item_len);\n\t\toffset++;\n\t\t\n\t\tchar *pszText = (char*)malloc(item_len);\n\t\tif (pszText != 0)\n\t\t{\n\t\t\tmemcpy(pszText, rtcp_info + offset,item_len);\n\t\t\tpszText[item_len] = '\\0';\n\t\t\tprintf(\"Text = %s\\n\",pszText);\n\t\t}\t\n\n\t\tchunk++;\n }\n\n return offset;\n}\n\nstatic void dissect_rtcp(u_char *rtcp_info,int packet_type, int offset,int PayloadLen)\n{\n\tunsigned int temp_byte = 0;\n\tint elem_count = 0;\n\tint packet_length = 0;\n\tint total_packet_length = 0;\n\tint loop = 2;\n\tbool flag_rtcp = false;\n\n\t\t/*检查是否为有效类型*/\n\t\tif ( ( packet_type < RTCP_PT_MIN ) || ( packet_type > RTCP_PT_MAX ) )\n\t\t\texit(-1);\n\n\t\t/*\n\t\t * 获取完整的RTCP数据包的长度\n\t\t */\n\t\t \n\t\tpacket_length = (ntohs(*(uint16_t*)(rtcp_info + offset + 1)) + 1) * 4 ;\n\t\t//printf(\"packet_length: %d\\n\",packet_length);\n\n\t\t\n\t\ttemp_byte = rtcp_info[offset-1];\n\t\telem_count = RTCP_COUNT( temp_byte );/* Source count, 5 bits */\n\t\tprintf(\"Reception report count: %d\\n\",elem_count); \n\n\t\tswitch ( packet_type ) \n\t\t{\n\t\t\t\n\t\t\tcase RTCP_SR:\n\t\t\tcase RTCP_RR:\n\t\t\t\t/*\n\t\t\t\t\tReal-time Transport Control Protocol (Receiver Report)\n\t\t\t\t\t10.. .... = Version: RFC 1889 Version (2)\n\t\t\t\t\t..0. .... = Padding: False\n\t\t\t\t\t...0 0001 = Reception report count: 1\n\t\t\t\t\tPacket type: Receiver Report (201)\n\t\t\t\t\tLength: 7 (32 bytes)\n\t\t\t\t\tSender SSRC: 0xb584b03e (3045371966)\n\t\t\t\t\tSource 1\n\t\t\t\t*/\n\n\t\t\t\t/* Packet type, 8 bits */\n\t\t\t\toffset++;\n\t\t\t\t/* Packet length in 32 bit words MINUS one, 16 bits */\n\t\t\t\toffset = dissect_rtcp_length_field(rtcp_info, offset);\n\t\t\t\t/* Sender Synchronization source, 32 bits */\n\t\t\t\toffset += 4;\n\n\t\t\t\tif ( packet_type == RTCP_SR )\n\t\t\t\t{\n\t\t\t\t\toffset = dissect_rtcp_sr(rtcp_info, offset, elem_count, packet_length-8 );\n\t\t\t\t\tprintf(\"dissect_rtcp_sr\\n\");\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\t\n\t\t\t\t\toffset = dissect_rtcp_rr(rtcp_info, offset, elem_count, packet_length-8 );\t\t\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t//uint16_t second_packet_type = ntohs(*(uint16_t*)(rtcp_info + offset));\n\n\t\t\t\t//printf(\"111offset: 0x%x 0x%x 0x%x 0x%x\\n\",rtcp_info[offset],rtcp_info[offset + 1],rtcp_info[offset + 2],rtcp_info[offset + 3]);\n\t\t\t\t\n\t\t\t\tif (rtcp_info[offset + 1] == RTCP_SDES)\n\t\t\t\t{\n\t\t\t\t\t\n\t\t\t\t\t/* Source count, 5 bits */\n\t\t\t\t\toffset++;\n\t\t\t\t\t/* Packet type, 8 bits */\n\t\t\t\t\toffset++;\n\t\t\t\t\t/* Packet length in 32 bit words MINUS one, 16 bits */\n\t\t\t\t\toffset = dissect_rtcp_length_field(rtcp_info, offset);\n\t\t\t\t\toffset = dissect_rtcp_sdes(rtcp_info,offset,elem_count);\n\n\t\t\t\t}\n\n\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\t/*\n\t\t\t\t * To prevent endless loops in case of an unknown message type\n\t\t\t\t * increase offset. Some time the while will end :-)\n\t\t\t\t */\n\t\t\t\toffset++;\n\t\t\t\tbreak;\n\n\t\t}\n\t\t\n}\n\n\nstatic bool dissect_rtcp_heur(u_char *rtcp_info,int PayloadLen)\n{\n unsigned int offset = 0;\n unsigned int first_byte = 0;\n unsigned int packet_type = 0;\n\n\n /* 查看第一个字节 */\n first_byte = rtcp_info[offset];\n\n /* 版本位是否设置为2*/\n\t//printf(\"version: %d\\n\",((first_byte & 0xC0) >> 6));\n if (((first_byte & 0xC0) >> 6) != 2)\n {\n return false;\n }\n\n /* 看包类型 */\n\toffset += 1;\n packet_type = rtcp_info[offset];\n\t//printf(\"packet_type: %d\\n\",packet_type);\n /* 复合数据包中的第一个数据包应该是发送方或接收者报告 */\n if (!((packet_type == RTCP_SR) || (packet_type == RTCP_RR) ||\n (packet_type == RTCP_BYE) || (packet_type == RTCP_APP) ||\n (packet_type == RTCP_PSFB)))\n {\n return false;\n }\n\n /*总长度必须是4个字节的倍数*/\n\t//printf(\"PayloadLen: %d\\n\",PayloadLen);\n if (PayloadLen % 4)\n {\n return false;\n }\n\n /* OK, dissect as RTCP */\n dissect_rtcp(rtcp_info,packet_type,offset,PayloadLen);\n return true;\n}\n\n\nstatic void confirm_rtcp_packet(struct ip *pIp)\n{\n\tint iIpTotalLen = ntohs(pIp->ip_len);\n\tint offset = 0;\n\tint nFragSeq = 0;\n\tstruct udphdr* pUdpHdr = (struct udphdr*)((char*)pIp + (pIp->ip_hl<<2));\n\tif (pIp->ip_p == IPPROTO_UDP) \n\t{\n\t\tprintf(\"\\n\");\n\t\t\n\t\tint iPayloadLen = iIpTotalLen - (pIp->ip_hl<<2) - 8;\n\t\tprintf(\"UDP Payload Len %d\\n\", iPayloadLen);\n\t\t\n\t\tu_char *pDnsHdr = (u_char*)(pUdpHdr+1);\n\t\tdissect_rtcp_heur(pDnsHdr,iPayloadLen);\n\t\t\n\t}\t\n}","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"编译运行:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/88/8853ff58f287bc19b757a5977f9482bb.png","alt":"在这里插入图片描述","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"总结","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"RTCP协议是流媒体通信的基石。RTCP协议则负责可靠传输、流量控制和拥塞控制等服务质量保证。上面讲解了RTCP功能、RTCP数据包格式及代码实现。最后,学习一个新的协议,最好还是研究学习官方文档,因为这是最权威的资料。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章