rtsp

了解rtsp


更新記錄

item note
20170310 第一版

目錄


RTSP

  • RTP

    • RTP協定常用於流媒體系統(配合RTCP協定),視訊會議
    • RTP只傳送資料,因此需要用到RTCP來控制
    • RTP協定傳media stream(ex. audio,video)
    • RTCP協定傳控制訊息(ex.Qos, sync)
    • 傳送端就會將media封包在一個RTP packet裡面,然後再把packet封包在一個UDP的segment中,再傳到接收端
  • RTP Payload Format

type RFC
RTP Payload Format for H.264 Video RFC6184
RTP Payload Format for Transport of MPEG-4 Elementary Streams RFC3640
  • RTSP

    • 即時流協議(RTSP:Real Time Streaming Protocol)
    • RTSP provides an extensible framework to enable controlled, on-demand delivery of real-time data, such as audio and video
    • RTSP提供了一個可擴展框架,使即時資料,如音訊與視頻的受控、點播成為可能
    • 該協定目的在於控制多個資料發送連接,為選擇發送通道,如UDP、多播UDP與TCP提供途徑,並為選擇基於RTP上發送機制提供方法
    • In other words, RTSP acts as a “network remote control” for multimedia servers.
  • RTSP States

state note
SETUP Cause the server to allocate resources for a stream and start an RTSP session.
PLAY and RECORD Starts data transmission on a stream allocated via SETUP.
PAUSE temporaily hasts a stream without freeing server resources.
TREADOWN Fress resource assocate with the stream. The RTSP session casses to exit on the server.

RTSP Protocol directives

RTSP has state; an identifier is used when needed to track concurrent sessions

程序 內容
詢問伺服器支援哪些RTSP方法 OPTIONS
ex. DESCRIBE,SETUP,TEARDOWN, PLAY等
用戶端要求某個連結的描述(SDP) DESCRIBE
ex. vidoe/audio track
用戶端設定 RTSP 連線 SETUP
client提出對像rtsp://192.168.22.33:554/video0.sdp/track1
Server回應允許port並且缺少的部分(ex.unicast,session,timeout等)
用戶端要求伺服器V 開始傳送影片 PALY

OPTIONS

An OPTIONS request returns the request types the server will accept.
Client送出OPTIONS
Server回應目前可以接的指令(DESCRIBE,SETUP,TEARDOWN, PLAY等)
[wiki-options]
[實際內容]

DESCRIBE

A DESCRIBE request includes an RTSP URL (rtsp://…), and the type of reply data that can be handled.
This reply includes the presentation description, typically in Session Description Protocol (SDP) format.
the presentation description lists the media streams controlled with the aggregate URL.
在wiki範例中有video及audio
[wiki-describe]

在實際應用上
由m=video的屬性中(a=control:track1),取出video track為”track1”
[實際內容]

  • 在回應的資料中定義了3種頻寬(three types of Bandwidth)
    Understand Video Signaling with SDP Debugs

    • TIAS
      Transport Independent Application Specific (TIAS) in bps:
      Bandwidth does NOT include the lower layers (e.g. RTP bandwidth only)
    • AS
      Application Specific (AS) in kbps:
      Bandwidth includes the lower layers (e.g. TCP/UDP and IP)
    • CT
      Conference Total (CT):
      Max Bandwidth that a Conference Session will use
  • 低下的camera使用AS定義

    1
    b=AS:12000

SETUP

A SETUP request specifies how a single media stream must be transported.
This must be done before a PLAY request is sent.
This specifier typically includes a local port for receiving RTP data (audio or video)
[wiki-SETUP]

Client跟Server提出特定stream需求(video/audio track)
Server回應允許port並且缺少的部分(ex.unicast,session,timeout
[實際內容]

PLAY

A PLAY request will cause one or all media streams to be played.
可指定撥放的RANGE,若無指定則撥到結束
[wiki-play]

TEARDOWN

A TEARDOWN request is used to terminate the session. It stops all media streams and frees all session related data on the server.
[wiki-teardown]


RTSP Flow

  • RTSP Flow
    camera ip: 192.168.22.33
    nvr ip: 192.168.22.51
    在camera有大小碼流時
    就會有兩條RTSP的FLOW如下
    最後各自Play
    大碼流:PLAY rtps://192.168.22.33:554/video0.sdp RTSP/1.0
    小碼流:PLAY rtps://192.168.22.33:554/video1.sdp RTSP/1.0[RTSP Flow]

Session Description Protocol

Session Description Protocol
在RTSP中Server回應DESCRIBE是採用SDP格式如下
主要有3個section(Session description,Time description,Media description)
星號表示可有可無欄位(options)
[SDP]

  • 範例說明

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    v=0
    o=jdoe 2890844526 2890842807 IN IP4 10.47.16.5
    s=SDP Seminar
    i=A Seminar on the session description protocol
    u=http://www.example.com/seminars/sdp.pdf
    e=j.doe@example.com (Jane Doe)
    c=IN IP4 224.2.17.12/127
    t=2873397496 2873404696
    a=recvonly
    m=audio 49170 RTP/AVP 0
    m=video 51372 RTP/AVP 99
    a=rtpmap:99 h263-1998/90000
  • ex1
    This session is originated by the user ‘jdoe’, at IPv4 address 10.47.16.5.

    1
    o=jdoe 2890844526 2890842807 IN IP4 10.47.16.5
  • ex2
    Its name is “SDP Seminar”

    1
    s=SDP Seminar
  • ex3.
    Two media descriptions are provided, both using RTP Audio Video Profile.
    The first is an audio stream on port 49170 using RTP/AVP payload type 0
    second is a video stream on port 51372 using RTP/AVP payload type 99
    兩個m, 表示有兩組media stream,各別在port 48170及51372

    1
    2
    m=audio 49170 RTP/AVP 0
    m=video 51372 RTP/AVP 99
  • ex4.
    說明此padload的屬性h263
    an attribute is included which maps RTP/AVP payload type 99 to format h263-1998 with a 90kHz clock rate

    1
    a=rtpmap:99 h263-1998/90000

參考