RTP/RTCP

RTP是基于 UDP协议的, UDP不用建立连接,效率更高;但允许丢包, 这就要求在重新组装媒体的时候多做些工作

RTP只是包裹内容信息,而RTCP是交换控制信息的,Qos是通过RTCP实现的

RTP中一个重要的概念是 session, 对于一个 audio stream 可以是一个session 但可以有多个 contributor, 也可以有多个监听者, 比如网络电话


做实时视频流,先用采集设备,直接把视频做成 H.264 的 NALu,而后通过 RTP打包,传输给客户端

有一篇文就是介绍如何把 NALu 用RTP打包的

​http://www.rosoo.net/a/201108/14896.html​


了解实时媒体的播放(RTP/RTCP 和 RTSP)_javascript



RTSP

但还缺少一个环节, 应用程序对应的是 play, seek, pause, stop, 如何把应用指令和 RTP的传输结合起来.

RTSP正是为了解决这个问题产生的

RTSP是应用层的协议和 HTTP协议很相似,客户端和服务器通过传递文本,通知如何进行 RTP/RTCP信息的交互

了解实时媒体的播放(RTP/RTCP 和 RTSP)_ide_02

从图中,我们可以看到 RTSP也可以不用 RTP, 而用TCP来实现流媒体传递

RTSP的 client 连接 server 多通过 SDP(会话描述协议)传递信息

[html]​view plain​​​​copy​


  1. C -> S :
  2. DESCRIBE rtsp://server.example.com/fizzle/foo RTSP/1.0 312
  3. Accept: application/sdp, application/rtsl, application/mheg

  4. S -> C :
  5. RTSP/1.0 200 312 OK
  6. Date: 23 Jan 1997 15:35:06 GMT
  7. Content-Type: application/sdp
  8. Content-Length: 376

  9. v=0
  10. o=mhandley 2890844526 2890842807 IN IP4 126.16.64.4
  11. s=SDP Seminar
  12. i=A Seminar on the session description protocol
  13. u=http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps
  14. e=mjh@isi.edu (Mark Handley)
  15. c=IN IP4 224.2.17.12/127
  16. t=2873397496 28973404696
  17. a=recvonly
  18. m=audio 3456 RTP/AVP 0
  19. m=video 2232 RTP/AVP 31
  20. m=whiteboard 32416 UDP WB
  21. a=orient:portrait



   Session description

          v=   (protocol version)

          o=   (owner/creator and session identifier)

          s=   (session name)

          i=* (session information)

          u=* (URI of description)

          e=* (email address)

          p=* (phone number)

          c=* (connection information - not required if included in all media)

          b=* (zero or more bandwidth information lines)

          One or more time descriptions ("t=" and "r=" lines, see below)

          z=* (time zone adjustments)

          k=* (encryption key)

          a=* (zero or more session attribute lines)

          Zero or more media descriptions

通过这些信息,client 就可以连接正确的 RTP session

关于RTMP和RTSP的区别

RTMP: RTM(Messaging)P 是 Adobe公司自己的规范,为播放器和服务器之间音频、视频和数据传输开发的私有协议。

看下面评论

They are both protocols for Streaming Media and on a high level achieve the same thing - Specify a standard to stream media. Although RTMP was developed and owned by Adobe before being made public , whereas RTSP was a public standard from the beginning. Since RTMP is mostly used by Flash player。

对于 Android这个开源项目,其 media player 一定是使用 public 的 RTSP




一个奔跑的程序员