FreeSWITCH rtp endpoint recvonly

查了下rtp.c的源码,远端端口为0就意味着recvonly,但其实不然,调用switch_rtp_new会马上返回失败

经过反复测试,增加下面几行代码之后终于变成了recvonly:

tech_pvt->mode = RTP_RECVONLY;
rtp_flags[SWITCH_RTP_FLAG_AUTOADJ]++;
switch_channel_set_variable(channel, "rtp_auto_adjust_threshold", "1");

有什么用?

用处大了,可以做录音呀监听呀什么的,接收别人的rtp流,下面是一个lua例子:

function debug(s)
    freeswitch.consoleLog("ERR", s or "")
end

local api = freeswitch.API()
local uuid = api:executeString("create_uuid")
debug("uuid = " .. uuid .. "\n")
local local_addr = api:executeString("global_getvar local_ip_v4")
local local_port = 2000
local remote_addr = local_addr -- 必须给远端地址和远端端口赋值,尽管实际不发送rtp流
local remote_port = 3000 -- 
local ptime = 20
local codec = "PCMA"
local pt = 8
local rate = 8000
 
local cmd = "bgapi originate "
cmd = cmd .. "[origination_uuid=" .. uuid .. "]"
cmd = cmd .. string.format("[local_addr=%s,local_port=%d,remote_addr=%s,remote_port=%d,ptime=%d,codec=%s,pt=%d,rate=%d]", local_addr, local_port, remote_addr, remote_port, ptime, codec, pt, rate)
cmd = cmd .. "rtp"
cmd = cmd .. " &lua(asr.lua)"
debug(cmd)
local reply = api:executeString(cmd)
debug("reply = " .. reply)
stream:write(reply)

呼叫成功后就执行lua asr.lua,至于asr.lua要怎么写,得您自己脑补了

你可能感兴趣的:(FreeSWITCH,FreeSWITCH,recvonly)