289 Commits

Author SHA1 Message Date
lizezhong233
117ab934d4 兼容大华 RTMP 推流在 @setDataFrame 中使用的 @onMetaData (#4879 #4873)
大华摄像头收到 `NetStream.Publish.Start` 后,发送两个 AMF0 字符串
`@setDataFrame`、`@onMetaData`,再附上宽、高和帧率。服务端原本只接受第二项为 `onMetaData`,于是在后续
AVC序列头到达前关闭了推流连接。
2026-11-23 14:28:05 +08:00
Vermilion Pasvikin
d8980ac386 fix(api): 轨道查询接口捕获 getTracks 异常,避免异常穿透 C ABI (#4851 #4878) 2026-11-23 14:26:16 +08:00
Honghao Zhang
fb3265725f fix: 兼容 a=fmtp:<pt> 不带参数的 SDP,修复 WebRTC 播放返回 400 (#4870) 2026-11-02 15:07:11 +08:00
yand9807
095eb47f48 修复接收 RTX 包时遗漏 TWCC 到包记录 (#4859) 2026-10-25 21:52:56 +08:00
pannal
46220e6a86 Fix Enhanced RTMP AV1 metadata and VPx packet framing (#4840)
Co-authored-by: xiongziliang <771730766@qq.com>
2026-10-08 15:06:05 +08:00
YuLi
de04a56c2b fix(rtmp): bound leading AMF compatibility parsing (#4842)
### Motivation
- Prevent a memory-amplification DoS in RTMP DATA/CMD handling where the
compatibility helper decoded arbitrary leading AMF values (including
large strict arrays) while searching for the first string.
- Support the observed non-standard publisher case (two leading AMF0
numbers) while avoiding unbounded recursive decoding and
attacker-controlled allocations.

### Description
- Replace the unbounded `amfLoadLeadingString()` behavior that
repeatedly `load<AMFValue>()` with a bounded compatibility rule that
skips at most two AMF0 `Number` values and then requires a string
(`amfLoadLeadingString` in `src/Rtmp/amf.cpp` and declaration in
`src/Rtmp/amf.h`).
- Add `friend` linkage for the helper in `AMFDecoder` and update header
comments to document the tightened compatibility semantics.
- Extend `tests/test_amf.cpp` with regression checks covering:
zero/one/two leading numbers, rejection of complex leading values (e.g.
strict array), excessive leading numbers, and AMF3 string handling.
- No new source files added and existing file UTF-8 BOMs were preserved.

### Testing
- Ran configuration and unit build: `cmake -S . -B build
-DENABLE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug` then `cmake --build build
--target test_amf -j8` and the build completed successfully.
- Executed the test binary via CTest: `ctest --test-dir build -R
'^test_amf$' --output-on-failure` and `test_amf` passed (1/1 tests
passed).
- Ran `git diff --check` and ensured no trailing whitespace or check
errors after changes.

------
[Codex
Task](https://chatgpt.com/codex/cloud/tasks/task_e_6abb8adc6f5c8320a84e8b198e28f68b)
2026-10-07 11:57:48 +08:00
YuLi
57f206e726 Avoid HLS cookies retaining HTTP sockets while preserving Session info (#4841) 2026-09-30 20:37:51 +08:00
YuLi
10268396b8 feat(hls): m3u8增加EXT-X-PROGRAM-DATE-TIME标签 (#4831)
按RFC 8216第4.3.2.6节,在每个切片的EXTINF之前写入该切片首帧对应的服务器
系统时间(UTC的ISO 8601格式,含毫秒),供播放器对齐字幕流、标记事件点。
直播m3u8与点播vod.m3u8均已支持。

默认关闭,由hls.programDateTime配置项开启。

时间统一以UTC输出而不采用本地时区偏移,因为ZLToolKit的getGMTOff()不含夏令
时修正、且在夏令时切换后不会刷新,会使标注的偏移与实际时刻相差1小时。

索引文件会被反复重建(点播模式下切片不删除,每次重建都遍历全部切片),故取值
在切片入列时格式化一次并缓存,避免在makeIndexFile()中对全部切片重复格式化。

close #4769
2026-09-22 11:54:01 +08:00
taotaobujue
6676b8d8fc fix(webrtc): 修复异常 ICE 会话导致的端口资源泄漏 (#4782)
公网部署时,ICE 端口可能遭受恶意请求或扫描。异常会话长期不退出,
导致 UDP 会话、TURN relay 端口及关联资源无法及时释放,最终可能耗尽
可用端口。

- 增加 UDP ICE 会话空闲超时配置,自动关闭长期无数据的会话
- 完善 TURN Allocation 的创建、刷新、超时和主动释放流程
- 会话异常退出或销毁时清理 relay 端口、Permission 和 ChannelBind
- 为 relay 会话注册表增加并发保护,避免残留或竞态访问
- 使用弱引用解除会话对象之间的循环引用
- 修正 Allocation Mismatch 错误码为 437
- 补充 iceSessionTimeoutSec 配置及使用说明

Plan-Item: ICEBUGFIX

---------

Co-authored-by: xiongziliang <771730766@qq.com>
2026-09-20 21:49:18 +08:00
YuLi
12ba56f534 ci: 引入 ctest 门禁并接入全平台流水线 (#4833)
tests 目录下的程序此前仅被编译、从不执行,项目中也没有任何 add_test 注册,
测试因此会静默腐烂:master 上的 test_vp9_rtp 目前即为失败状态,却无人察觉。

改为以白名单注册可无人值守执行的用例,并在流水线构建之后执行 ctest,
失败即中断。该目录其余程序多为服务型或压测工具,运行后不会自行退出,全量
自动收录会使 ctest 挂起,故采用白名单。

首批收录
test_amf、test_sortor、test_ts_splitter、test_mp4_muxer_video_dimension
四个,均已本地实测通过,总耗时 0.05 秒;并为每个用例设置 120 秒超时,避免
个别用例卡住流水线。

test_vp9_rtp 当前为失败状态,本次不收录,留待单独修复后再并入白名单。

现在先搭好框架, 后续逐个添加单元测试/门禁
2026-09-20 10:20:21 +08:00
YuLi
b0427c3901 VP9 RTP parser: add robust bounds checks, fix pictureID and references, add unit tests (#4790)
### Motivation

- Harden VP9 RTP payload parsing against malformed/truncated packets to
avoid OOB reads and crashes.
- Fix incorrect assembly of extended `pictureID` and incorrect
consumption of reference indices in flexible mode.
- Add focused unit tests to cover descriptor variants and edge cases so
regressions are caught automatically.

### Description

- Change parser signature to `int parse(const unsigned char *data, int
dataLength)` and replace raw pointer arithmetic with
`readByte`/`skipBytes` helpers that track remaining bytes and enforce
bounds.
- Fix `largePictureID` assembly by concatenating bytes correctly instead
of using `ntohs` arithmetic, and ensure `additionalReferenceIdx` is set
from the parsed byte; also limit flexible-mode reference chain to at
most three references.
- Parse scalability-structure fields (`spatialLayers`, `hasResolution`,
`hasGof`) with bounds checks and correctly read resolution entries and
GOF reference indices; return `-1` on truncation.
- Add an extra safety check in `VP9RtpDecoder::decodeRtp` to verify the
parsed header offset is within payload bounds, and add
`tests/test_vp9_rtp.cpp` with many descriptor/edge-case cases exercising
parsing logic.

### Testing

- Added unit test `tests/test_vp9_rtp.cpp` covering L/F/P combinations,
picture ID variants, reference chains, resolution and GOF parsing, and
truncation cases, and executed it as an automated test.
- The new test binary completed all test cases successfully (all
expected pass/fail outcomes matched).

------
[Codex
Task](https://chatgpt.com/codex/cloud/tasks/task_e_6a63e97a4c2c8320aa66d51a746c2e4d)
2026-08-02 13:06:34 +08:00
YuLi
6b16281ab0 fix: limit AMF decoder nesting depth (#4787)
### Motivation
- Prevent unbounded recursive-descent parsing in the AMF decoder that
allowed deeply nested AMF objects/arrays to exhaust the process stack
and cause a pre-auth remote DoS.

### Description
- Add an RAII depth guard `AMFDecoder::DepthGuard` and a per-decoder
`depth` counter with `kMaxDepth = 64` to `AMFDecoder` in
`src/Rtmp/amf.h`/`src/Rtmp/amf.cpp`.
- Instrument `load_object()`, `load_ecma()`, and `load_arr()` to create
a `DepthGuard` at entry so nesting is incremented and reliably
decremented on return or exception, and throw
`std::runtime_error("Maximum AMF nesting depth exceeded")` when the
limit is exceeded.
- Add `tests/test_amf.cpp` to assert that a 64-level nested AMF
container is accepted and a 65-level nested container is rejected with
the expected error.
- Keep non-nested parsing behavior unchanged; the guard only enforces a
maximum container nesting depth.

### Testing
- Configured the project with tests enabled using `cmake -S . -B build
-DENABLE_TESTS=ON`, which generated the `test_amf` target successfully.
- Built the test target with `cmake --build build --target test_amf` and
performed smoke compiles of modified sources, with `src/Rtmp/amf.cpp`
compiling to object (`/tmp/amf.o`) successfully.
- Compiled the new test source with `c++ -std=gnu++11 -c
tests/test_amf.cpp` successfully and verified `git diff --cached
--check` passed.

------
[Codex
Task](https://chatgpt.com/codex/cloud/tasks/task_e_6a63c9326b9883209c857c0f4fa5d0cc)
2026-07-27 22:56:18 +08:00
Miau Lightouch
a9e0e1a81e fix(webrtc): fix GStreamer WHEP interop (#4720)
## Summary

This PR fixes GStreamer interoperability issues during WebRTC/WHEP
negotiation with ZLMediaServer.

GStreamer could fail to establish the connection for two separate
reasons:

1. ZLMediaServer generated a non-compliant ICE `ufrag`. The generated
value contained `_`, which is not a valid ICE character, so GStreamer
rejected the SDP.
2. ZLMediaServer did not correctly handle `bundle-only` offers and could
answer an accepted bundled m-line with `port=0`, which caused the later
WHEP negotiation to fail.

## Changes

- Generate ICE `ufrag` values using ICE-compliant characters only.
- Preserve and handle `a=bundle-only` correctly during SDP parsing and
answer generation.
- Return `port=9` instead of `port=0` for accepted bundled m-lines.
- Add regression coverage for `bundle-only` SDP handling.
- URL-encode `delete_webrtc` query parameters in the returned `Location`
header so ICE-safe identifiers remain round-trippable over HTTP.

## Validation

- Built with WebRTC and SCTP enabled.
- Added regression test: `test_webrtc_regression`
- Verified:
  - ICE-safe identifier round-trip through `delete_webrtc`
  - `bundle-only` SDP answer generation
2026-04-21 11:37:08 +08:00
xia-chu
a59809047c 修复编译警告 2026-01-08 21:18:00 +08:00
xia-chu
c82dd75054 支持webrtc推流 2025-09-22 21:06:17 +08:00
肖锋
fd34b5526b feature:添加http head请求的支持 (#4321)
添加http head请求的支持
2025-06-30 20:46:18 +08:00
PioLing
9863f9c160 Add logo and version information to exe on windows (#4093) 2025-01-03 11:33:35 +08:00
xia-chu
87b42ab492 优化代码
除1024改成右移10位
2024-11-29 23:51:34 +08:00
xia-chu
4f8127f6f1 消除过多cmake警告 2024-11-29 20:14:32 +08:00
a839419160
78b00d9dc0 修复关闭mp4相关功能时test编译报错 (#4043) 2024-11-27 15:22:09 +08:00
Xiaofeng Wang
06ff8461c7 减少依赖影响范围 (#4039)
See #4034
2024-11-25 11:22:29 +08:00
a839419160
326b475beb 增加pcap解析工具(#4033 #4034) 2024-11-22 17:43:15 +08:00
alex
4152dcd409 AI automatically translates all comments in the code into English (#3917) 2024-09-19 14:53:50 +08:00
xia-chu
9463d1291d 修复编译警告 2024-07-21 19:47:36 +08:00
mtdxc
d735aa1797 Media tuple refactor (#3715)
Co-authored-by: cqm <cqm@97kid.com>
2024-07-14 09:32:41 +08:00
zhang2349
c72e576420 rtp server新增支持自定义vhost和app名称 (#3693)
代码来自https://github.com/ZLMediaKit/ZLMediaKit/pull/3446 , 增加了vhost
2024-07-09 10:42:10 +08:00
xiongziliang
77d2df1695 移除RtpSelector相关逻辑,优化代码结构 2024-06-09 10:52:10 +08:00
Dw9
d6f166c1f4 Push benchmark supports input from mp4 file (#3588) 2024-06-01 18:15:35 +08:00
xia-chu
af3ef996b0 Avoid build warnings in the main code 2024-03-30 14:59:28 +08:00
xia-chu
390c374086 Optimize the code
1. change param_strs to params
2. move params from MediaInfo to MediaTuple
3. passing MediaTuple as a parameter for some functions
2024-03-30 14:41:20 +08:00
xiongziliang
77400832ac Update ZLToolKit 2024-01-06 17:47:43 +08:00
xiongziliang
a106f8dfc0 Avoid blocking the poller thread 2023-12-31 22:10:13 +08:00
夏楚
bbe8f4a018 release 8.0 2023-12-09 16:23:51 +08:00
xiongziliang
c12a6f0aed 适配ZLToolKit 2023-12-02 19:49:28 +08:00
Jovial Young
a13b8417e5 修复rtmps默认端口不对导致无法推/拉流问题 (#2996)
在使用rtmps推流或者拉流时,端口被默认设置成了1935,正确的端口应该是443.
2023-11-19 14:37:04 +08:00
xia-chu
5b394fcff7 重写加载mp4文件推流rtsp/rtmp范例程序 2023-11-11 21:34:25 +08:00
xia-chu
a871fc1882 websocket服务器支持在创建器中指定消息类型
通过该修改可以更灵活的指定同端口下不同websocket服务的消息类型
2023-10-23 20:59:37 +08:00
Deepslient
67bc0273b4 Modify the readme description (#2859) 2023-10-12 14:38:45 +08:00
Nick
07a1a929ad 修复HLS点播时下载切片过快的bug (#2635 #2628)
Co-authored-by: xia-chu <771730766@qq.com>
2023-07-08 10:18:09 +08:00
夏楚
7e117b1c7f 新增支持http-flv播放器 (#2562) 2023-06-17 10:29:27 +08:00
johzzy
03770ff409 Replace the tuple (vhost/app/stream) with MediaTuple. (#2560) 2023-06-17 10:28:01 +08:00
xia-chu
64b8079ac1 优化函数命名风格
FindField改名为findSubString
2023-06-10 14:55:40 +08:00
xia-chu
af0ebf4633 优化Parser代码命名 2023-06-10 14:55:40 +08:00
Johnny
0232caf068 add MediaTuple 2023-05-30 11:01:27 +08:00
xia-chu
cdf97e7605 更新zltoolkit,适配最新代码 2023-04-28 22:04:09 +08:00
xiongziliang
c8a20f85f6 直接打印SockException类 2023-04-23 00:10:18 +08:00
xiongguangjie
c090fc3ea0 test_rtp avoid crash when exit 2023-04-07 23:34:41 +08:00
xiongguangjie
749ef33965 use poller input data avoid throw poll check 2023-04-07 23:09:10 +08:00
xia-chu
4cc2982a2c 重写jitter buffer算法,修复seq回环时可能丢包的bug 2023-03-11 10:17:31 +08:00
xiongziliang
9fdb3de8b2 优化rtp排序抖动缓存算法,提高webrtc/rtsp抗丢包性能 2023-03-06 00:31:11 +08:00