2015年2月21日 星期六

Asterisk channel

Asterisk PBX 的通話通道用 struct ast_channel 表示,採用某種通道技術 (channel technology,struct ast_channel_tech)。

channel 模組呼叫 ast_channel_register() 註冊 ast_channel_tech 到 Asterisk,可能需要讀取設定檔,其中包括了解硬體 channel 的狀況。

channel 模組運作可分成撥入和撥出兩種情形。撥入時,建立一個 ast_channel,設定 ast_channel_tech ,並開始一個 pbx thread 執行 dialplan,此時 Asterisk 可能應答並收送 media,或者建立 outbound channel 撥出。如果是撥出,當受話端應答,Asterisk 將兩邊的 media stream 搭起來。

native bridge:如果兩邊的 ast_channel_tech 相同,media stream 可以不用經過 PBX,直接在 channel driver 內部,甚至在 channel driver 之前就可以互通。

 struct ast_channel_tech
  • 由 type 字串識別
  • ast_get_channel_tech() 取得指定 type 的 channel technology
  • ast_request() 在指定 channel technology 的 cap 相容的情況下,執行其 requester 來請求一個某個位址的 channel。可能是某個 channel 來請求的。

call in 是外部要 call 到 Asterisk,channel 模組通常會啟動一個 thread 來監控所有閒置的 channel。當偵測到「RING」或相當的事件時,配置一個新 channel 資料結構呼叫 ast_pbx_start() 建立一個 pbx_thread 呼叫__ast_pbx_run() 來執行 dialplan 直到結束,最後預設會執行掛斷的動作。

註:ast_pbx_run() 可以直接呼叫 __ast_pbx_run() 執行 dialplan
註:.indicate() 可告知對方 callee 狀態,例如響鈴中、忙線中、已連線等。.indicate() 也可告知 HOLD/UNHOLD 來開始/停止 MOH、要 hookflash 等,且不限於 call in。
註:.answer() 表示對方應答

call out 透過 channel technology 提供的 API 完成。首先 .requester() 請求一個 channel (seize),然後 .call() 讓 callee 振鈴及送 caller ID,callee 應答時送 AST_CONTROL_ANSWER。掛斷時 ast_queue_hangup()[待續]

struct ast_channel @ main/channel_internal_api.c

沒有留言:

張貼留言

SIP header Via

所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...