1. 程式人生 > >FreeSWITCH 限制音視訊會議數量(lua實現)

FreeSWITCH 限制音視訊會議數量(lua實現)

實現思路

寫兩個指令碼:
- 第一個指令碼為啟動時執行的常駐指令碼,監聽 CUSTOM 事件的 conference::maintenance 子事件,該子事件有兩個action:conference-create與conference-destroy,通過這兩個action記錄會議數量和會議名稱。
- 第二個指令碼為呼叫時執行指令碼,呼叫時判斷會議數量是否達到最大,如果達到最大,則判斷該呼叫的會議名稱是否為已存在的會議名稱,若不是,則該呼叫將超出會議最大數量,結束通話;若是,則應答。

實現細節

  • 因為要在兩個指令碼中共享資料,因此先新增幾個全域性變數,在 vars.xml 中新增以下全域性變數,分別記錄當前會議數量,允許的最多會議數量,以及會議名稱:
<X-PRE-PROCESS cmd="set" data="conference_count=0"/>
<X-PRE-PROCESS cmd="set" data="max_conference_count=1"/>
<X-PRE-PROCESS cmd="set" data="conference_names="/>
  • 在 /scripts 目錄新建 conference_listen.lua,用來監聽會議數量和會議名稱的變化:
con = freeswitch.EventConsumer("CUSTOM")
api = freeswitch.API()
for
e in (function() return con:pop(1) end) do event_name = e:getHeader("Event-Name") event_subclass = e:getHeader("Event-Subclass") action = e:getHeader("Action") -- freeswitch.consoleLog("info", "event\n" .. e:serialize("xml")) local conference_name = e:getHeader("Conference-Name") local
conference_names = api:executeString("global_getvar conference_names") if (event_name == "CUSTOM" and event_subclass == "conference::maintenance") then if (action == "conference-create") then local conference_count = tonumber(api:executeString("global_getvar conference_count")) conference_count = conference_count + 1 freeswitch.consoleLog("INFO", "New conference created, now there are " .. conference_count .. " conferences\n") api:executeString("global_setvar conference_count=" .. conference_count) local nFind = string.find(conference_names, conference_name, 1) if not nFind then conference_names = conference_names .. conference_name .. ";" api:executeString("global_setvar conference_names=" .. conference_names) end freeswitch.consoleLog("info", "Current conference names: " .. conference_names .. "\n") elseif (action == "conference-destroy") then local conference_count = tonumber(api:executeString("global_getvar conference_count")) conference_count = conference_count - 1 freeswitch.consoleLog("INFO", "Conference destroyed, now there are " .. conference_count .. " conferences\n") api:executeString("global_setvar conference_count=" .. conference_count) local nFind = string.find(conference_names, conference_name, 1) if nFind then local new_conference_names = "" if nFind ~= 1 then new_conference_names = new_conference_names .. string.sub(conference_names, 1, nFind - 1) end if nFind ~= string.len(conference_names) - string.len(conference_name) then new_conference_names = new_conference_names .. string.sub(conference_names, nFind + string.len(conference_name) + 1) end api:executeString("global_setvar conference_names=" .. new_conference_names) freeswitch.consoleLog("info", "Current conference names: " .. new_conference_names .. "\n") else freeswitch.consoleLog("error", "Can not find the conference named: " .. conference_name) end end end end
  • 由於需要啟動FreeSWITCH時啟動該指令碼,因此在 /conf/autoload_configs/lua.conf.xml 中新增一行:
    <param name="startup-script" value="conference_listen.lua"/>
  • 在 /scripts 目錄新建指令碼 conference.lua:
api = freeswitch.API()
local conference_count = tonumber(api:executeString("global_getvar conference_count"))
local max_conference_count = tonumber(api:executeString("global_getvar max_conference_count"))
freeswitch.consoleLog("info", "current count: " .. conference_count .. " and max count: " .. max_conference_count)
function answer_conference()
    session:answer()
    session:execute("set", "conference_member_flags=vmute")
    session:execute("conference", argv[1] .. "@video-mcu-stereo")
end
if conference_count < max_conference_count then
    answer_conference()
else
    local conference_names = api:executeString("global_getvar conference_names")
    freeswitch.consoleLog("info", "Current conference names: " .. conference_names .. "\n")
    freeswitch.consoleLog("info", "Conference to find : " .. argv[1])
    local nFind = string.find(conference_names, argv[1], 1)
    if not nFind then
        freeswitch.consoleLog("info", "Too many conferences, hangup!\n")
        local event = freeswitch.Event("CUSTOM", "conference::maintenance")
        event:addHeader("Hangup-Reason", "Too many conferences")
        event:addHeader("Calling-Number", argv[1])
        event:fire()
        session:hangup()
    else
        answer_conference()
    end
end 
  • 最後修改撥號計劃,conf/dialplan/default.xml,使指令碼得以執行。
<extension name="cdquality_conferences">
    <condition field="destination_number" expression="^(35\d{2})$">
        <action application="lua" data="conference.lua $1"/>
    </condition>
</extension>

相關推薦

FreeSWITCH 限制視訊會議數量lua實現

實現思路 寫兩個指令碼: - 第一個指令碼為啟動時執行的常駐指令碼,監聽 CUSTOM 事件的 conference::maintenance 子事件,該子事件有兩個action:conference-create與conference-destroy,通過

freeSWITCH + WebRTC 視訊會議

想把 freeSWITCH 和 WebRTC 組合起來做音視訊會議,網站找到的資料都比較老了,自己試驗了下,把過程記錄下來,有需要的人可以參考。 基本的設想是: JsSIP 用於網頁端(Chrom

視訊開發系列

  人類的五官能夠直接感受聲音和影象,但計算機只能認識二進位制。在音視訊的開發過程中,我們必須將聲音和影象編碼為二進資料流,才能讓計算機識別,進而加工處理、傳輸和儲存;計算機上為人類服務的,儲存的音視訊資料被使用者獲取後,需要重新解碼為人類能夠直接感受的聲音、影象。   大連哪個醫院看婦

從零開始學習視訊程式設計技術 FFMPEG的使用

零開始學習音視訊程式設計技術(四) FFMPEG的使用  音視訊開發中最常做的就是編解碼的操作了,以H.264為例:如果想要自己實現編碼h.264,需要對H.264非常的瞭解,首先需要檢視H.264的文件,這個文件好像說是三百多頁(本人並沒有看過)。 想到這

從零開始學習視訊程式設計技術 視訊格式講解學習筆記

/*  該型別部落格為學習時載錄筆記,加上自己對一些不理解部分自己的理解。會涉及其他博主的博文的摘錄,會標註出處  */ ==========================================================================

從零開始學習視訊程式設計技術 音訊格式講解

1. 音訊簡介     前面我們說過視訊有一個每秒鐘採集多少張的概念,這就叫做視訊的幀率。     和視訊的幀率一樣的道理,聲音也有一個頻率,叫做取樣率。   人對頻率的識別範圍是 20HZ - 20000HZ, 如果每秒鐘能對聲音做 20000 個取樣, 回放

快速實現ios手機端多人視訊會議直播免費

Rechatsdk為所有基於網際網路的實時通訊需求使用者提供了完整的解決方案,包括實時音訊/視訊互動、原生sdk低延遲廣播,相容第三方rtmp和hls直播方案 解壓後把reechat.framework匯入目標ios工程。   註冊sdk統一回調函式 ReeCha

Android端實現多人視訊聊天應用

本文轉載於資深Android開發者“東風玖哥”的部落格。 本系列文章分享了基於Agora SDK 2.1實現多人視訊通話的實踐經驗。 轉載已經過原作者許可。原文地址 自從2016年,鼓吹“網際網路寒冬”的論調甚囂塵上,2017年亦有愈演愈烈之勢。但連麥直播、線上抓娃

百度雲視訊直播服務LSS的使用流程

音視訊直播LSS(Live Streaming Service)是一個直播PaaS服務平臺,旨在幫助企業及個人開發者快速搭建自己的直播平臺及應用,關於LSS的相關介紹請採參考百度雲官網指導文件:https://cloud.baidu.com/doc/LSS/ProductDe

Android WebRTC 視訊開發總結

1 public void setTrace(boolean enable, VideoEngine.TraceLevel traceLevel) { 2 if (enable) { 3 vie.setTraceFile("/sdcard/trace.txt", f

Android 使用Rtmp視訊推流002

前言 本文介紹的是使用Android攝像頭、麥克風採集的音、視訊進行編碼。然後通過librtmp推送到流媒體伺服器上的功能。  我所使用的環境:Android Studio 2.2.3 、NDK13。 流程 使用到的Api 音視訊採集用到的api有:Camera、AudioRecord編

基於webrtc多人視訊的研究

基於webrtc多人音視訊的研究 眾所周知,WebRTC非常適合點對點(即一對一)的音視訊會話。然而,當我們的客戶要求超越一對一,即一對多、多對一設定多對多的解決方案或者服務,那麼問題就來了:“我們應該採用什麼樣的架構?” 。簡單的呢有人會考慮copy多個p2p就完

從零開始學習視訊程式設計技術 FFMPEG Qt視訊播放器之SDL的使用

前面介紹了使用FFMPEG+Qt解碼視訊並顯示。 現在我們就著手給它加上聲音播放。 播放聲音有很多種方式: 以windows系統為例,可以使用如下方法播放音訊: 1.直接呼叫系統API的wavein、waveout等函式 2.使用directsound播放

從零開始學習視訊程式設計技術 視訊格式講解

所謂視訊,其實就是將一張一張的圖片連續的放出來,就像放幻燈片一樣,由於人眼的惰性,因此只要圖片的數量足夠多,就會覺得是連續的動作。 所以,只需要將一張一張的圖片儲存下來,這樣就可以構成一個視訊了。      但是,由於目前網路和儲存空間的限制,直接儲存圖片顯然不可行。

快速實現android手機端多人視訊會議直播免費

reechatsdk為所有基於網際網路的實時通訊需求使用者提供了完整的解決方案,包括實時音訊/視訊互動、原生sdk低延遲廣播,相容第三方rtmp和hls直播方案 解壓壓縮包,並把reechat.jar和其他*.so匯入目標android工程(Add as Library

從零開始學習視訊程式設計技術35 windows下編譯並除錯ffmpeg

前面介紹了Linux下編譯ffmpeg的方法,考慮到大部分時候測試ffmpeg功能都是使用的windows系統(至少我是這樣的),因此將戰場重新轉移到windows上。    前面寫了那麼多的程式碼,但都只是簡單的呼叫了ffmpeg的API,並不知道他內部是如何實現的。如果可

深入理解Android視訊同步機制MediaSync的使用與原理

MedaiSync是android M新加入的API,可以幫助應用視音訊的同步播放,如同官網介紹的 From Andriod M: MediaSync: class which helps applications to synchronously r

【轉】從零開始學習視訊程式設計技術 音訊格式講解

轉自:http://blog.yundiantech.com/?log=blog&id=5 1. 音訊簡介     前面我們說過視訊有一個每秒鐘採集多少張的概念,這就叫做視訊的幀率。     和視訊的幀率一樣的道理,聲音也有一個頻率,叫做取樣率。   

GB28181協議實現系列之----IPC視訊PS封裝5

 RTP封裝PS    RTP報文頭格式(見RFC3550 Page12):     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 12 3 4 5 6 7 8 9 0 1   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+

視訊資料處理6--- PCM音訊取樣資料處理程式碼實現

音訊取樣資料在視訊播放器的解碼流程中的位置如下圖所示。 本文分別介紹如下幾個PCM音訊取樣資料處理函式: 分離PCM16LE雙聲道音訊取樣資料的左聲道和右聲道 將PCM16LE雙聲道音訊取樣資料中左聲道的音量降一半 將PCM16LE雙聲道音訊取樣資