onvif 語音對講
前言
在視頻監控應用場景中,有很多場景需要採集查看監控的人的語音發送到監控攝像頭的音響上去以實現對被監控對象的語音控制。
ONVIF Core Specification Core_2.00文檔
中章節12.3 Back Channel Connection
對此進行了詳細的描述。
ONVIF
語音對講的實現完全基於RTSP
協議,流程中沒有用到ONVIF
協議。
RTSP Require-Tag
RTSP 標準[RFC 2326]可以通過添加額外的頭進行擴展,引入Require
tag 用於處理特殊的功能擴展(參考 [RFC
2326], 1.5 Extending Rtsp and 12.32 Require).
Require
頭用來判定是否支持某個特性,如果要求server
理解支持某個特性並正確處理請求,需要對server
的每個請求都攜帶這個Require
頭。
server
如果支持backchannel
這個特性,需要理解該特性所對應的tag:
www.onvif.org/ver20/backchannel
如果client想要建立一個包含backchannel
的RTSP
連接,在這一系列請求(SUBSCRIBE,SETUP,PLAY,PAUSE,TEARDWON)中需要包含這個Require www.onvif.org/ver20/backchannel
頭。
DESCRIBE
在Client - Server
發送DESCRIBE
協議的時候添加前文說過的Require-tag
,這時如果Server
不支持語音對講則會回覆551 Option not supported
,示例如下:
Client – Server: DESCRIBE rtsp://192.168.0.1 RTSP/1.0
CSeq: 1
User-Agent: ONVIF Rtsp client
Accept: application/sdp
Require: www.onvif.org/ver20/backchannel #!! Require-tag
Server – Client: RTSP/1.0 551 Option not supported
CSeq: 1
Unsupported: www.onvif.org/ver20/backchannel
如果支持語音對講的話,則會回覆200 OK
並攜帶sdp
信息:
RTSP/1.0 200 OK
CSeq: 1
Content-Type: application/sdp
Content-Length: xxx
v=0
o= 2890842807 IN IP4 192.168.0.1
s=RTSP Session with audiobackchannel
m=video 0 RTP/AVP 26
a=control:rtsp://192.168.0.1/video
a=recvonly
m=audio 0 RTP/AVP 0
a=control:rtsp://192.168.0.1/audio
a=recvonly
m=audio 0 RTP/AVP 0
a=control:rtsp://192.168.0.1/audioback
a=rtpmap:0 PCMU/8000
a=sendonly
上面的sdp
列出了三個流及其控制URL
: 視頻流:rtsp://192.168.0.1/video
,音頻流:rtsp://192.168.0.1/audio
,以及我們的主角對講流rtsp://192.168.0.1/audioback
,注意對講流的屬性a=sendonly與其他流的a=recvonly不同。
SETUP
接下來我們就可以SETUP
這些session
:
Client – Server: SETUP rtsp://192.168.0.1/video RTSP/1.0
CSeq: 2
Transport: RTP/AVP;unicast;client_port=4588-4589
Server – Client: RTSP/1.0 200 OK
CSeq: 2
Session: 123124;timeout=60
Transport:RTP/AVP;unicast;client_port=4588-4589;
server_port=6256-6257
Client – Server: SETUP rtsp://192.168.0.1/audio RTSP/1.0
CSeq: 3
Session: 123124
Transport: RTP/AVP;unicast;client_port=4578-4579
Server – Client: RTSP/1.0 200 OK
CSeq: 3
Session: 123124;timeout=60
Transport:RTP/AVP;unicast;client_port=4578-4579;
server_port=6276-6277
Client – Server: SETUP rtsp://192.168.0.1/audioback RTSP/1.0
CSeq: 4
Session: 123124
Transport: RTP/AVP;unicast;client_port=6296-6297
Require: www.onvif.org/ver20/backchannel
Server – Client: RTSP/1.0 200 OK
CSeq: 4
Session: 123124;timeout=60
Transport:RTP/AVP;unicast;client_port=6296-6297;
server_port=2346-2347
上面setup
了三次,分別建立了視頻流,音頻流以及位於最後的音頻對講流的連接。
PLAY
由於rtsp
有集合控制的功能,僅需要發送一條PLAY
或者PAUSE
就可以同時控制多個音頻流和視頻流。所以下面我們發送一條PLAY
請求即可:
Client – Server: PLAY rtsp://192.168.0.1 RTSP/1.0
CSeq: 5
Session: 123124
Require: www.onvif.org/ver20/backchannel
Server – Client: RTSP/1.0 200 OK
CSeq: 5
Session: 123124;timeout=60
在收到PLAY
請求的200 OK
的回覆之後,客戶端就可以向Server
發送音頻數據包了,Client
不應該在收到回覆之前就開始發送數據包。
上面例子中的Require: www.onvif.org/ver20/backchannel
頭指明瞭這個特殊的解釋對於PLAY
命令是必須的。PLAY
命令同時開始了Client
從NVT
獲取音頻流和視頻流以及從Client
發送到Server
的對講流。
TEARDOWN
通過發送TEARDOWN
請求來關閉這個包含三個流的session
:
Client – NVT: TEARDOWN rtsp://192.168.0.1 RTSP/1.0
CSeq: 6
Session: 123124
Require: www.onvif.org/ver20/backchannel
NVT – Client: RTSP/1.0 200 OK
CSeq: 6
Session: 123124
Multicast Streaming
如果客戶端要發送語音廣播給多個攝像頭,那麼它需要使用SETUP
請求中的transport
參數來告訴Server
多播地址和端口
Client – Server: SETUP rtsp://192.168.0.1/audioback RTSP/1.0
CSeq: 4
Session: 123124
Transport:RTP/AVP;multicast;destination=224.2.1.1;port=60
000-60001;ttl=128
Require: www.onvif.org/ver20/backchannel
Server – Client: RTSP/1.0 200 OK
CSeq: 4
Session: 123124;timeout=60
Transport:RTP/AVP;multicast;destination=224.2.1.1;port=60
000-60001;ttl=128;mode=”PLAY”