2013年1月15日 星期二

ONVIF -- audio channel

許多 IPCAM 都支援了將聲音由 NVR 傳至IPCAM 的功能,ONVIF 組織針對此功能定義了一套標準作法,稱為 audio backchannel,首先會利用 AudioOutputConfiguration 內的 Send-Primacy 設定 audio in/out 方向,接著再使用 RTSP ,利用其擴充功能 "Require" 來傳送接收 audio stream。


根據 ONVIF 規範,我們將其分成兩部分來討論



一、聲音的設定,例如 audio codec 可以是 AAC, G.711 或 G.726,full duplex or half duplex
此部份可參考 ONVIF-Media-Service-Spec-v221.pdf Chapter 5.14 Audio channel modes,摘錄如下: 
1. full duplex operation, no special handling is required
2. half duplex, should assign an optional Send-Primacy Parameter in AudioOutputConfiguration
  • www.onvif.org/ver20/HalfDuplex/Server The server is allowed to send audio data to the client. The client shall not send audio data via the backchannel to the device in this mode.
  • www.onvif.org/ver20/HalfDuplex/Client The client is allowed to send audio data via the backchannel to the server. The device shall not send audio data to the client in this mode.
  • www.onvif.org/ver20/HalfDuplex/Auto It is up to the device how to deal with sending and receiving audio data.
      Acoustic echo cancellation is out of ONVIF scope.  


若要支援 audio backchannel,則應該實作下列對應的 ONVIF API
  • GetAudioOutputsRequest
  • GetAudioOutputConfigurationsRequest
  • GetAudioOutputConfigurationRequest
  • GetCompatibleAudioOutputConfigurationsRequest
  • GetAudioOutputConfigurationOptionsRequest
  • SetAudioOutputConfiguration-Request
  • GetAudioDecoderConfigurationsRequest
  • GetAudioDecoderConfigurationRequest
  • GetCompatibleAudioDecoderConfigurationsRequest
  • GetAudioDecoderConfigurationOptionsRequest
  • SetAudioDecoderConfigurationRequest
   
   
二、聲音的傳送
此部份可參考 ONVIF-Streaming-Spec-v221.pdf chapter 5.3 Back Channel Connection

其實作是使用 RTSP [RFC 2326]的一個擴充tag "Require",將其設定為 "www.onvif.org/ver20/backchannel"。 
當 NVR 發出 RTSP Request時,若帶有此tag,表示NVR想要使用 backchannel功能
  • 若IPCAM支援,則回應的SDP 內會描述對應的 audio 設定,例如:"a=sendonly"。 
  • 若IPCAM不支援,則應該回覆 "551 Option not supported"。
註1:NVR 應該先使用 ONVIF API 詢問 IPCAM 能力,確認IPCAM支援 backchannel之後,才能夠在 RTSP Request 中加入 "www.onvif.org/ver20/backchannel" tag。 
註2: ONVIF 還定義了另一個 Require tag "onvif-replay",用來做 replay功能。

以下摘錄 spec 中針對 backchannel 的 RTSP 範例

Example 1: Server without backchannel support:

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 Server – Client: RTSP/1.0 551 Option not supported CSeq: 1 Unsupported: www.onvif.org/ver20/backchannel
Example 2: Server with Onvif backchannel support:
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 Server – Client: 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 // setup the sessions 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 // PLAY request 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 // TEARDOWN request. 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