📋 问题现象

错误特征

呼叫正常接通,但单侧无声音(一方能听到,另一方听不到)。

常见场景

  • ✅ 呼叫正常建立
  • ✅ 双方都能听到回铃音
  • ❌ 接通后一方无声音(单向静音)
  • ❌ RTP 流未正常传输

🔍 问题根源

可能原因

  1. RTP 媒体流未正常建立

    • RTP 端口未正确协商
    • 防火墙阻止 RTP 端口
  2. 编解码器不匹配

    • 双方编解码器不兼容
    • 转码失败
  3. NAT 问题

    • RTP 包无法到达对方
    • IP 地址不正确
  4. 媒体流方向问题

    • read 方向(收)或 write 方向(发)失败

✅ 解决步骤

步骤 1: 找到通话的 Channel UUID

使用 show channels 命令:

1
2
3
4
5
6
7
8
9
10
11
# 进入 fs_cli
fs_cli

# 查看当前所有通话通道
show channels

# 输出示例:
uuid name state cid_num
------------------------------------ ---------------- ------------- ----------
a1b2c3d4-e5f6-7890-abcd-ef1234567890 sofia/internal/... CS_EXECUTE 1001
b2c3d4e5-f6a7-8901-bcde-f12345678901 sofia/internal/... CS_EXECUTE 1002

输出说明:

字段 说明 示例
uuid 通话唯一标识符 a1b2c3d4-e5f6-7890-abcd-ef1234567890
name 通道名称 sofia/internal/1001@192.168.232.225
state 通道状态 CS_EXECUTE (执行中)
cid_num 主叫号码 1001

获取主被叫双方的 UUID:

1
2
3
4
5
6
7
8
9
# 方法 1: 从 show channels 输出中复制
# 主叫 UUID: a1b2c3d4-e5f6-7890-abcd-ef1234567890
# 被叫 UUID: b2c3d4e5-f6a7-8901-bcde-f12345678901

# 方法 2: 使用正则过滤特定号码
show channels | grep 1001

# 方法 3: 查看特定 UUID 的详细信息
uuid_dump a1b2c3d4-e5f6-7890-abcd-ef1234567890

步骤 2: 开启媒体流调试

使用 uuid_debug_media 命令:

1
2
3
4
5
6
7
# 基本语法
uuid_debug_media <uuid> <direction> <on|off>

# 参数说明:
# - uuid: 通话的 UUID(从步骤 1 获取)
# - direction: read(收), write(发), 或 both(双向)
# - on|off: 开启或关闭调试

示例 1: 调试主叫方的媒体流

1
2
3
4
5
# 调试主叫方的双向媒体流(收和发)
uuid_debug_media a1b2c3d4-e5f6-7890-abcd-ef1234567890 both on

# 预期输出:
# +OK Debug media enabled

示例 2: 调试被叫方的媒体流

1
2
# 调试被叫方的双向媒体流
uuid_debug_media b2c3d4e5-f6a7-8901-bcde-f12345678901 both on

示例 3: 只调试单向媒体流

1
2
3
4
5
# 只调试接收方向(read - 收)
uuid_debug_media a1b2c3d4-e5f6-7890-abcd-ef1234567890 read on

# 只调试发送方向(write - 发)
uuid_debug_media a1b2c3d4-e5f6-7890-abcd-ef1234567890 write on

步骤 3: 查看媒体流调试信息

开启调试后,让用户通话,观察日志:

1
2
3
4
5
# 实时查看日志
tail -f /usr/local/freeswitch/log/freeswitch.log

# 或在 fs_cli 中查看
console loglevel 7

正常日志示例(有声音):

1
2
3
4
[DEBUG] switch_rtp.c:1234 Read audio packet 160 bytes
[DEBUG] switch_rtp.c:2345 Write audio packet 160 bytes
[DEBUG] switch_rtp.c:3456 Read audio packet 160 bytes
[DEBUG] switch_rtp.c:4567 Write audio packet 160 bytes

异常日志示例(无声音 - 单向):

1
2
3
4
[DEBUG] switch_rtp.c:1234 Read audio packet 160 bytes
[WARNING] switch_rtp.c:2345 No audio packets to write
[DEBUG] switch_rtp.c:3456 Read audio packet 160 bytes
[WARNING] switch_rtp.c:4567 No audio packets to write

异常日志示例(无声音 - 双向):

1
2
3
4
[WARNING] switch_rtp.c:1234 No audio packets to read
[WARNING] switch_rtp.c:2345 No audio packets to write
[WARNING] switch_rtp.c:3456 RTP timeout
[ERR] switch_rtp.c:4567 RTP stream inactive

步骤 4: 分析问题原因

根据日志判断问题类型:

情况 1: read 方向无包(收不到)

日志特征:

1
[WARNING] switch_rtp.c:1234 No audio packets to read

可能原因:

  • 对方未发送 RTP 包
  • 防火墙阻止入站 RTP
  • RTP 端口不正确
  • NAT 映射问题

解决方案:

1
2
3
4
5
6
7
8
9
10
11
12
# 1. 检查 RTP 端口范围
fs_cli -x "eval \${rtp_port_min}"
fs_cli -x "eval \${rtp_port_max}"

# 2. 检查防火墙
sudo iptables -L -n | grep 10000:20000

# 3. 允许 RTP 端口通过
sudo iptables -I INPUT -p udp --dport 10000:20000 -j ACCEPT

# 4. 检查 NAT 配置
fs_cli -x "nat_map status"

情况 2: write 方向无包(发不出)

日志特征:

1
[WARNING] switch_rtp.c:2345 No audio packets to write

可能原因:

  • 本地未生成 RTP 包
  • 编解码器问题
  • 媒体流未正常建立

解决方案:

1
2
3
4
5
6
7
8
9
10
# 1. 检查编解码器
fs_cli -x "uuid_getvar <uuid> read_codec"
fs_cli -x "uuid_getvar <uuid> write_codec"

# 2. 检查 RTP 统计
fs_cli -x "uuid_park <uuid>"
fs_cli -x "show rtp"

# 3. 查看详细媒体信息
fs_cli -x "uuid_dump <uuid>"

情况 3: 双向都有包,但听不到

日志特征:

1
2
[DEBUG] switch_rtp.c:1234 Read audio packet 160 bytes
[DEBUG] switch_rtp.c:2345 Write audio packet 160 bytes

可能原因:

  • 编解码器不兼容
  • 转码失败
  • 音频设备问题

解决方案:

1
2
3
4
5
6
7
8
# 1. 检查编解码器协商
fs_cli -x "uuid_getvar <uuid> codec_string"

# 2. 强制使用特定编解码器
fs_cli -x "uuid_setvar <uuid> absolute_codec_string=PCMU"

# 3. 检查客户端音频设备
# (需要在客户端软电话/硬终端检查)

步骤 5: 关闭媒体流调试

调试完成后,关闭调试:

1
2
3
4
5
6
7
8
9
# 关闭双向调试
uuid_debug_media a1b2c3d4-e5f6-7890-abcd-ef1234567890 both off

# 关闭单向调试
uuid_debug_media a1b2c3d4-e5f6-7890-abcd-ef1234567890 read off
uuid_debug_media a1b2c3d4-e5f6-7890-abcd-ef1234567890 write off

# 预期输出:
# +OK Debug media disabled

⚠️ 注意: 调试模式会产生大量日志,生产环境调试完成后务必关闭。


🚨 常见问题

问题 1: uuid_debug_media 命令不存在

现象:

1
[ERR] uuid_debug_media: Command not found

原因: FreeSWITCH 版本过旧或模块未加载

解决方案:

1
2
3
4
5
6
7
8
9
10
11
12
# 1. 检查 FreeSWITCH 版本
fs_cli -x "version"

# 2. 检查 console 模块
fs_cli -x "module_exists mod_console"

# 3. 如果模块未加载,加载模块
fs_cli -x "load mod_console"

# 4. 使用替代命令
fs_cli -x "uuid_park <uuid>"
fs_cli -x "uuid_dump <uuid>"

问题 2: 找不到 UUID

现象:

1
2
show channels
# 输出为空或找不到特定号码

排查步骤:

1
2
3
4
5
6
7
8
9
10
11
# 1. 确认通话正在进行
fs_cli -x "show channels"

# 2. 查看所有注册的分机
fs_cli -x "sofia status profile internal reg"

# 3. 查看呼叫详情
fs_cli -x "show calls"

# 4. 使用 grep 过滤
fs_cli -x "show channels" | grep 1001

问题 3: 调试后日志量过大

现象: 开启 both 调试后,日志暴增

解决方案:

1
2
3
4
5
6
7
8
9
10
11
12
# 1. 只调试特定方向
uuid_debug_media <uuid> read on # 只调试接收
uuid_debug_media <uuid> write on # 只调试发送

# 2. 降低日志级别
fs_cli -x "console loglevel 3"

# 3. 过滤日志
tail -f /usr/local/freeswitch/log/freeswitch.log | grep "Read audio\|Write audio"

# 4. 及时关闭调试
uuid_debug_media <uuid> both off

问题 4: RTP 端口被防火墙阻止

排查步骤:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 1. 检查 RTP 端口范围
fs_cli -x "eval \${rtp_port_min}" # 默认 16384
fs_cli -x "eval \${rtp_port_max}" # 默认 32768

# 2. 检查防火墙规则
sudo iptables -L -n -v | grep -E "16384:32768|10000:20000"

# 3. 添加防火墙规则
sudo iptables -I INPUT -p udp --dport 16384:32768 -j ACCEPT
sudo iptables -I OUTPUT -p udp --sport 16384:32768 -j ACCEPT

# 4. 保存规则
sudo service iptables save

# 5. 或使用 firewalld
sudo firewall-cmd --permanent --add-port=16384-32768/udp
sudo firewall-cmd --reload

🔧 高级调试技巧

抓包分析 RTP 流

1
2
3
4
5
6
7
8
9
10
11
12
13
# 1. 找到 RTP 流的 IP 地址和端口
fs_cli -x "uuid_dump <uuid>" | grep -E "rtp_ip|audio_port"

# 2. 使用 tcpdump 抓包
tcpdump -i eth0 -n host <remote_ip> and udp port <rtp_port> -s 0 -w /tmp/rtp.pcap

# 3. 使用 Wireshark 分析
# - 过滤器: rtp
# - 查看 RTP 流统计
# - 检查丢包率、抖动等

# 4. 使用 tshark 命令行分析
tshark -r /tmp/rtp.pcap -q -z rtp-stream

检查 RTP 统计信息

1
2
3
4
5
6
7
8
9
10
11
12
13
# 1. 查看 RTP 统计
fs_cli -x "show rtp"

# 输出示例:
# <uuid> <remote_ip>:<port> <codec> <pkt_in> <pkt_out> <lost> <jitter>
# abc123... 192.168.236.163:50001 PCMU 1234 0 0 0.5ms

# 2. 查看特定 UUID 的 RTP 详情
fs_cli -x "uuid_getvar <uuid> rtp_audio_in_packet_count"
fs_cli -x "uuid_getvar <uuid> rtp_audio_out_packet_count"

# 3. 实时监控 RTP 统计
watch -n 1 'fs_cli -x "show rtp" | grep <uuid>'

测试编解码器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 1. 查看支持的编解码器
fs_cli -x "show codecs"

# 2. 查看当前使用的编解码器
fs_cli -x "uuid_getvar <uuid> read_codec"
fs_cli -x "uuid_getvar <uuid> write_codec"

# 3. 强制使用特定编解码器
fs_cli -x "uuid_setvar <uuid> absolute_codec_string=PCMU"
fs_cli -x "uuid_setvar <uuid> absolute_codec_string=PCMA"
fs_cli -x "uuid_setvar <uuid> absolute_codec_string=OPUS"

# 4. 重置编解码器
fs_cli -x "uuid_setvar <uuid> codec_string="

📋 快速诊断流程图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
呼叫单侧无声音
|
├─ 步骤 1: 找到通话 UUID
| └─ show channels
|
├─ 步骤 2: 开启媒体调试
| └─ uuid_debug_media <uuid> both on
|
├─ 步骤 3: 观察日志
| |
| ├─ read 无包?
| | ├─ 是 → 检查入站防火墙、NAT、对方发送
| | └─ 否 → 继续
| |
| ├─ write 无包?
| | ├─ 是 → 检查编解码器、媒体流建立
| | └─ 否 → 继续
| |
| └─ 双向都有包?
| └─ 检查编解码器兼容性、客户端设备
|
├─ 步骤 4: 修复问题
|
├─ 步骤 5: 关闭调试
| └─ uuid_debug_media <uuid> both off
|
└─ 验证修复
└─ 重新测试呼叫

📚 相关文档


💡 最佳实践

  1. 快速定位问题: 使用 show channels 快速找到 UUID
  2. 双向调试: 优先使用 both 查看完整媒体流
  3. 及时关闭调试: 避免日志量过大
  4. 防火墙检查: 确保 RTP 端口范围开放
  5. 编解码器协商: 优先使用标准编解码器(PCMU/PCMA/OPUS)
  6. 抓包分析: 复杂问题使用 Wireshark 深入分析

🎯 常用命令速查

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# === 查找 UUID ===
show channels # 查看所有通话
show channels | grep 1001 # 过滤特定号码
uuid_dump <uuid> # 查看 UUID 详情

# === 媒体流调试 ===
uuid_debug_media <uuid> both on # 开启双向调试
uuid_debug_media <uuid> read on # 开启接收调试
uuid_debug_media <uuid> write on # 开启发送调试
uuid_debug_media <uuid> both off # 关闭调试

# === 查看日志 ===
tail -f /usr/local/freeswitch/log/freeswitch.log
console loglevel 7 # 提高日志级别

# === 检查 RTP ===
show rtp # 查看 RTP 统计
uuid_getvar <uuid> read_codec # 查看读编解码器
uuid_getvar <uuid> write_codec # 查看写编解码器

# === 检查端口 ===
eval ${rtp_port_min} # RTP 最小端口
eval ${rtp_port_max} # RTP 最大端口

文档版本: v1.0 最后更新: 2026-01-29 维护者: FreeSWITCH 运维团队


© 2018–2026 小周周 · 使用 Stellar 构建

站内搜索

没有找到内容!