FreeSWITCH rtp endpoint recvonly

2023-12-15 12:05:09

查了下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要怎么写,得您自己脑补了

文章来源:https://blog.csdn.net/qq_56167818/article/details/135008806
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。