572 Commits

Author SHA1 Message Date
OSSRS-AI
e59b30301a AI: API: Change pagination default count to 10, minimum 1. v7.0.128 (#4584) 2025-11-18 12:12:16 -05:00
OSSRS-AI
a3a2fa5ceb AI: Fix race condition causing immediate deletion of new sources. v7.0.127 (#4449) (#4576)
**Problem**: Newly created sources (RTMP/SRT/RTC/RTSP) were being
immediately marked as "dead" and deleted by the cleanup timer before
publishers could connect, causing "new live source, dead=1" errors.

**Root Cause**: All source constructors initialized `stream_die_at_ =
0`, causing `stream_is_dead()` to return `true` immediately since
current time was always greater than `0 + 3 seconds`.

**Solution**: Changed all four source constructors to initialize
`stream_die_at_ = srs_time_now_cached()`, giving newly created sources a
proper 3-second grace period before cleanup.
2025-11-13 21:24:07 -05:00
OSSRS-AI
6e93dd73b5 AI: WebRTC: Support optional msid attribute per RFC 8830. v7.0.126 (#4570) (#4572)
Fix issue #4570 by supporting optional `msid` attribute in WebRTC SDP
negotiation, enabling compatibility with libdatachannel and other
clients that don't include msid information.

SRS failed to negotiate WebRTC connections from libdatachannel clients
because:
- libdatachannel SDP lacks `a=ssrc:XX msid:stream_id track_id`
attributes
- SRS required msid information to create track descriptions
- According to RFC 8830, the msid attribute and its appdata (track_id)
are **optional**

If diligently look at the SDP generated by libdatachannel:

```
a=ssrc:42 cname:video-send
a=ssrc:43 cname:audio-send
```

It's deliberately missing the `a=ssrc:XX msid:stream_id track_id` line,
comparing that with this one:

```
a=ssrc:42 cname:video-send
a=ssrc:42 msid:stream_id video_track_id
a=ssrc:43 cname:audio-send  
a=ssrc:43 msid:stream_id audio_track_id
```

In such a situation, to keep compatible with libdatachannel, if no msid
line in sdp, SRS comprehensively and consistently uses:

* app/stream as stream_id, such as live/livestream
* type=video|audio, cname, and ssrc as track_id, such as
track-video-video-send-43
2025-11-11 10:22:31 -05:00
OSSRS-AI
3f2539d8fb AI: SRT: Stop TS parsing in SrsSrtFormat after codec detection. v7.0.125 (#4569) (#4571)
Fix log flooding issue when processing SRT streams containing SCTE-35
PIDs or other unrecognized stream types.

The `SrsSrtFormat::on_srt_packet()` method continuously parses TS
packets throughout the entire stream lifetime. The TS parser logs
warnings for every unrecognized stream type (like SCTE-35) in the PMT,
causing log flooding.

However, `SrsFormat` is only used to detect audio/video codec
information. Once both codecs are detected, there's no need to continue
parsing TS packets.

Note: This fix mitigates the problem - there will still be some warning
logs during the initial codec detection phase (typically 5-10 seconds),
but the continuous log flooding after codec detection is completely
eliminated.
2025-11-11 00:24:01 -05:00
OSSRS-AI
bfb91f9b82 AI: WebRTC: Support G.711 (PCMU/PCMA) audio codec for WebRTC. v7.0.124 (#4075) (#4568)
This PR adds G.711 (PCMU/PCMA) audio codec support for WebRTC in SRS,
enabling relay-only streaming of G.711 audio between WebRTC clients via
WHIP/WHEP. G.711 is a widely-used, royalty-free audio codec with
excellent compatibility across VoIP systems, IP cameras, and legacy
telephony equipment.

Fixes #4075

Many IP cameras, VoIP systems, and IoT devices use G.711 (PCMU/PCMA) as
their default audio codec. Previously, SRS only supported Opus for
WebRTC audio, requiring transcoding or rejecting G.711 streams entirely.
This PR enables direct relay of G.711 audio streams in WebRTC, similar
to how VP9/AV1 video codecs are supported.

Enhanced WHIP/WHEP players with URL-based codec selection:
```
# Audio codec only
http://localhost:8080/players/whip.html?acodec=pcmu
http://localhost:8080/players/whip.html?acodec=pcma

# Video + audio codecs
http://localhost:8080/players/whip.html?vcodec=vp9&acodec=pcmu
http://localhost:8080/players/whep.html?vcodec=h264&acodec=pcma

# Backward compatible (codec = vcodec)
http://localhost:8080/players/whip.html?codec=vp9
```

Testing

```bash
# Build and run unit tests
cd trunk
make utest -j && ./objs/srs_utest

# Test with WHIP player
# 1. Start SRS server
./objs/srs -c conf/rtc.conf

# 2. Open WHIP publisher with PCMU audio
http://localhost:8080/players/whip.html?acodec=pcmu

# 3. Open WHEP player to receive stream
http://localhost:8080/players/whep.html
```

## Related Issues

- Fixes #4075 - WebRTC G.711A Audio Codec Support
- Related to #4548 - VP9 codec support (similar relay-only pattern)
2025-11-09 12:08:03 -05:00
OSSRS-AI
7fcd406a63 AI: WebRTC: Support VP9 codec for WebRTC-to-WebRTC streaming. v7.0.123 (#4548) (#4565)
VP9 is a similar codec to HEVC, but for WebRTC, VP9 works better than
AVC/HEVC in some special cases. However, SRS only support VP9 for
WebRTC, doesn't support converting it to RTMP, for RTMP only support
AVC/HEVC/AV1 and SRS cannot support transcoding.

Usage:
* Publish with VP9:
[http://localhost:1985/rtc/v1/whip/?app=live&stream=livestream&codec=vp9](http://localhost:8080/players/whip.html?codec=vp9)
* Play with VP9:
[http://localhost:1985/rtc/v1/whep/?app=live&stream=livestream&codec=vp9](http://localhost:8080/players/whep.html?codec=vp9)
2025-11-08 12:47:31 -05:00
OSSRS-AI
1a96abc880 AI: API: Add audio_frames and video_frames to HTTP API. v7.0.122 (#4559) (#4564)
This PR adds separate audio and video frame counting to the HTTP API
(`/api/v1/streams/`) for better stream observability. The API now
reports three frame fields:
- `frames` - Total frames (video + audio)
- `video_frames` - Video frames/packets only
- `audio_frames` - Audio frames/packets only

This enhancement provides better visibility into stream composition and
helps detect issues with CBR/VBR streams, audio/video sync problems, and
codec-specific behavior.

**Before:**
```json
{
  "streams": [
    {
      "frames": 0, // video frames.
    }
  ]
}
```

**After:**
```json
{
  "streams": [
    {
      "frames": 6912, // video frames.
      "audio_frames": 5678, // audio frames.
      "video_frames": 1234, // video frames.
    }
  ]
}
```

Frame Counting Strategy
- All protocols report frames every N frames to balance accuracy and
performance
- Frames are counted at the protocol-specific message/packet level:
  - RTMP: Counts RTMP messages (video/audio)
  - WebRTC: Counts RTP packets (video/audio)
  - SRT: Counts MPEG-TS messages (H.264/HEVC/AAC)
2025-11-07 22:32:26 -05:00
Winlin
f392f9a5a7 WHIP: Return detailed HTTP error responses with proper status codes. v7.0.121 (#4502) (#4562)
This commit addresses issue #4502 by implementing proper HTTP error
handling
for WHIP endpoints, allowing clients to receive detailed error
information
instead of empty responses.

Before this change:
- WHIP clients received "Empty reply from server" when publish failed
- No way to distinguish between different failure reasons

After this change:
- WHIP clients receive proper HTTP status codes (400/401/409/500)
- Error responses include error code and description
- Clients can distinguish between SDP errors, stream busy, auth
failures, etc.

If success:

```
< HTTP/1.1 201 Created
< Content-Type: application/sdp
< Location: /rtc/v1/whip/?action=delete&token=77h5570j1&app=live&stream=livestream&session=x209e499:TKxW
< Content-Length: 1376
< Server: SRS/7.0.120(Kai)
< 
v=0
......
```

If request without SDP:

```
curl 'http://localhost:1985/rtc/v1/whip/?app=live&stream=livestream' -v
< HTTP/1.1 400 Bad Request
< Content-Type: text/plain; charset=utf-8
< Content-Length: 13
< Server: SRS/7.0.120(Kai)
< 
5043: RtcInvalidSdp
```

If request with corrupt SDP:

```
curl 'http://localhost:1985/rtc/v1/whip/?app=live&stream=livestream' --data-raw $'invalidsdp' -v
< HTTP/1.1 400 Bad Request
< Content-Type: text/plain; charset=utf-8
< Content-Length: 18
< Server: SRS/7.0.120(Kai)
< 
5012: RtcSdpDecode
```

If request with insufficient SDP:

```
curl 'http://localhost:1985/rtc/v1/whip/?app=live&stream=livestream' --data-raw $'v=0' -v
< HTTP/1.1 400 Bad Request
< Content-Type: text/plain; charset=utf-8
< Content-Length: 21
< Server: SRS/7.0.120(Kai)
< 
5018: RtcSdpNegotiate
```

If publish to a exists stream:

```
< HTTP/1.1 409 Conflict
< Content-Type: text/plain; charset=utf-8
< Content-Length: 16
< Server: SRS/7.0.120(Kai)
< 
1028: StreamBusy
```

If HTTP hooks or security verify failed:

```
< HTTP/1.1 401 Unauthorized
< Content-Type: text/plain; charset=utf-8
< Content-Length: 16
< Server: SRS/7.0.120(Kai)
< 
1102: SystemAuth
```

Other errors, for exmaple, RTC disabled:

```
< HTTP/1.1 500 Internal Server Error
< Content-Type: text/plain; charset=utf-8
< Content-Length: 17
< Server: SRS/7.0.120(Kai)
< 
5021: RtcDisabled
```

---------

Co-authored-by: OSSRS-AI <winlinam@gmail.com>
2025-11-07 21:05:41 -05:00
OSSRS-AI
99970d6ba0 AI: HLS: Support query string in hls_key_url for JWT tokens. v7.0.120 (#4426) 2025-11-06 23:00:19 -05:00
OSSRS-AI
0c26a3c309 AI: RTC: Support keep_original_ssrc to preserve SSRC and timestamps. v7.0.119 (#3850) 2025-11-06 21:45:50 -05:00
OSSRS-AI
dc8b2a804d AI: WebRTC: Report video/audio codec info and frame stats in HTTP API. v7.0.118 (#4554) 2025-11-05 21:56:16 -05:00
OSSRS-AI
eb9fca888d AI: SRT: Report video/audio codec info and frame stats in HTTP API. v7.0.117 (#4554) 2025-11-04 10:41:11 -05:00
Laurentiu
1f4c05bdd5 Fill missing defs for H264/AVC video levels. v7.0.116 (#4556)
Fill missing H264/AVC video levels (4.2, 5.2, 6, 6.1, 6.2). 
Partial Fix #4555

---------

Co-authored-by: OSSRS-AI <winlinam@gmail.com>
2025-11-03 10:31:13 -05:00
vivisoymilkhappy
57c74d1cdb Add ignore configuration for cursor. v7.0.115 (#4547)
Cursor ignored.

---------

Co-authored-by: Haibo Chen <495810242@qq.com>
Co-authored-by: ZhangWei <zhangwei@jlsoft.com>
Co-authored-by: winlin <winlinvip@gmail.com>
2025-10-31 19:11:51 -04:00
winlin
abacd680ba WebRTC: Use realtime for TWCC timestamp accuracy. v7.0.114 2025-10-30 21:37:45 -04:00
OSSRS-AI
8acceb1b1b AI: HLS: Fix crash when segment is not open by adding NULL checks. v7.0.113 (#3431) 2025-10-30 21:37:37 -04:00
OSSRS-AI
91a051b45d AI: AAC: Fix mono audio reported as stereo in HTTP API. v7.0.112 (#3556) 2025-10-29 22:22:02 -04:00
winlin
550760f2d0 HLS/DASH: Fix dispose to skip unpublish when not enabled, and add forbidden directory protection to SrsPath::unlink. v7.0.111 2025-10-27 08:14:48 -04:00
OSSRS-AI
3dc7b405ca AI: HTTP-FLV: Enforce minimum 10ms sleep to prevent CPU busy-wait when mw_latency=0. v7.0.110 (#3963) 2025-10-26 20:17:46 -04:00
OSSRS-AI
547b0c0ed5 AI: Edge: Fix stream names with dots being incorrectly truncated in source URL generation. v7.0.109 (#4011) 2025-10-26 18:44:12 -04:00
OSSRS-AI
19b603a0d7 AI: HTTPS: Handle SSL_ERROR_ZERO_RETURN as graceful connection closure. v7.0.108 (#4036) 2025-10-26 17:45:06 -04:00
OSSRS-AI
5fc1f2d2e5 AI: API: Add clients field to on_play/on_stop webhooks and total field to HTTP API. v7.0.107 (#4147) 2025-10-26 16:28:22 -04:00
OSSRS-AI
51ab6403a3 AI: WebRTC: Fix camera/microphone not released after closing publisher. v7.0.106 (#4261) 2025-10-26 08:43:53 -04:00
OSSRS-AI
9eae868e91 AI: Build: Improve dependency checking to report all missing dependencies at once. v7.0.105 (#4293) 2025-10-25 22:21:09 -04:00
OSSRS-AI
6590871ca8 AI: HLS: Support hls_master_m3u8_path_relative for reverse proxy compatibility. v7.0.104 (#4338) 2025-10-25 21:10:21 -04:00
OSSRS-AI
b7828e1fba API: Remove minimum limit of 10 for count parameter in /api/v1/streams and /api/v1/clients. v7.0.103 (#4358) 2025-10-25 19:44:03 -04:00
OSSRS-AI
2810d32d60 AI: Only support AAC/MP3/Opus audio codec. v7.0.102 (#4516) 2025-10-22 22:08:25 -04:00
OSSRS-AI
0c9868b4a2 AI: Fix AAC audio sample rate reporting in API. v7.0.101 (#4518) 2025-10-22 21:28:45 -04:00
Winlin
845e0287c0 Forward: Reject RTMPS destinations with clear error message. v7.0.100 (#4537)
SRS forward feature only supports plain RTMP protocol, not RTMPS (RTMP over SSL/TLS). This is by design - SRS SSL is server-side only (accepting connections), not client-side (initiating connections). The forward feature uses SrsSimpleRtmpClient which has no SSL handshake or encryption capabilities for outgoing connections.

Changes:
1. Add RTMPS URL detection in SrsForwarder::initialize()
2. Return ERROR_NOT_SUPPORTED error when RTMPS destination is detected
3. Add unit test to verify RTMPS URLs are properly rejected
4. Add FAQ section to .augment-guidelines explaining the limitation

For users who need to forward to RTMPS destinations (e.g., AWS IVS), the recommended solution is to use FFmpeg with SRS HTTP Hooks:
- on_publish event: Automatically start FFmpeg to relay stream to RTMPS destination
- on_unpublish event: Automatically stop FFmpeg process when stream ends

This provides a fully automated, production-ready RTMPS relay solution without adding complexity to SRS core.

Related: #4536

---------

Co-authored-by: OSSRS-AI <winlinam@gmail.com>
2025-10-20 08:03:07 -04:00
Haibo Chen(陈海博)
0d43ed5dd6 HLS: Fix a iterator bug in hls_ctx cleanup function. v6.0.182 v7.0.99 (#4534)
Co-authored-by: OSSRS-AI <winlinam@gmail.com>
2025-10-17 07:16:42 -04:00
Haibo Chen(陈海博)
abaffdd4b9 fix crash issue caused by reload configuration file. v7.0.98 (#4530)
fix crash issue caused by reload configuration file, which occurs when a
vhost is added/removed in the new configuration.

Introduced by https://github.com/ossrs/srs/pull/4458

see https://github.com/ossrs/srs/issues/4529
2025-10-16 07:30:16 -04:00
Jack Lau
6f526284a3 RTC2RTMP: fix illegal memory access. v7.0.97 (#4520)
Regression since 20f6cd595c

The early code might meet bridge is empty when
there is no bridge(e.x. rtc to rtc). Then srs_freep will free the brige.

Remove this code that seems redundant.

---------

Co-authored-by: Jacob Su <suzp1984@gmail.com>
Signed-off-by: Jack Lau <jacklau1222@qq.com>
2025-10-15 10:16:03 -04:00
winlin
1bc18509a2 Disable sanitizer by default to fix memory leak. #4364 v7.0.96 2025-10-14 20:32:37 -04:00
OSSRS-AI
fc6a851d5f SRT: Support configurable default_streamid option. v6.0.180 v7.0.95 (#4515) 2025-10-01 22:05:15 -04:00
Winlin
c7821b4770 For Edge, only support RTMP or HTTP-FLV. v7.0.94 (#4513) 2025-09-27 19:35:34 -04:00
Haibo Chen(陈海博)
2dfa54e21b improve blackbox test for rtsp. v7.0.93 (#4505)
Co-authored-by: winlin <winlinvip@gmail.com>
2025-09-21 23:36:49 -04:00
winlin
10c0b66c0f Fix WHIP with transcoding bug. v7.0.92 (#4495) 2025-09-21 08:58:22 -04:00
Jacob Su
f4c54ab9a5 fix rtsp compiling warning. v7.0.91 (#4504)
## steps to produce:

1. ./configure --rtsp=off
2. make

---------

Co-authored-by: winlin <winlinvip@gmail.com>
2025-09-20 11:38:07 -04:00
Winlin
20f6cd595c AI: Refine RTMP/SRT/RTC bridge. v7.0.90 (#4503)
This PR refactors the stream bridge architecture in SRS to improve code
organization, type safety, and maintainability by replacing the generic
ISrsStreamBridge interface with protocol-specific bridge classes and
target interfaces.

1. New Target Interface Architecture:

- Introduces  ISrsFrameTarget for AV frame consumers (RTMP sources)
- Introduces  ISrsRtpTarget for RTP packet consumers (RTC sources)
- Introduces ISrsSrtTarget for SRT packet consumers (SRT sources)

2. Protocol-Specific Bridge Classes:

- SrsRtmpBridge: Converts RTMP frames to RTC/RTSP protocols
-  SrsSrtBridge: Converts SRT packets to RTMP/RTC protocols
-  SrsRtcBridge: Converts RTC packets to RTMP protocol

3. Simplified Bridge Management:

- Removes the generic SrsCompositeBridge chain pattern
- Each source type now uses its appropriate bridge type directly

With this improvement, you are able to implement very complex bridge and
protocol converting, for example, you can bridge RTMP to RTC with opus
audio when you support enhanced RTMP with opus.

Another plan is to support bridging RTC to RTSP, directly without
converting RTP to media frame packet, but directly deliver RTP packet
from RTC source to RTSP source.

---------

Co-authored-by: OSSRS-AI <winlinam@gmail.com>
2025-09-19 21:50:28 -04:00
Winlin
5b27c3fa7a RTC2RTMP: Fix sequence number wraparound assertion crashes. v6.0.177 v7.0.89 (#4491)
The issue occurred when srs_rtp_seq_distance(start, end) + 1 resulted in
values <= 0
due to sequence number wraparound (e.g., when end < start). This caused
assertion
failures and server crashes.

SrsRtcFrameBuilder::check_frame_complete(): Added validation to return
false
  for invalid sequence ranges instead of asserting.

However, it maybe cause converting RTC to RTMP stream failure, because
this issue
should be caused by the problem of sequence number of RTP, which means
there potentially
be stream problem in RTC stream. Even so, changing assert to warning
logs is better,
because SRS should not crash when stream is corrupt.

---------

Co-authored-by: OSSRS-AI <winlinam@gmail.com>
2025-09-15 11:02:30 -04:00
Winlin
4247bd1f90 Improve coverage for kernel. v7.0.88 (#4489)
Co-authored-by: OSSRS-AI <winlinam@gmail.com>
2025-09-14 21:57:12 -04:00
Winlin
fadc1215af AI: Add utests for kernel and protocol. v7.0.87 (#4488)
Co-authored-by: OSSRS-AI <winlinam@gmail.com>
2025-09-14 08:35:36 -04:00
Winlin
d4d1d5d8b5 AI: Move some app files to kernel. v7.0.86 (#4486)
Co-authored-by: OSSRS-AI <winlinam@gmail.com>
2025-09-13 10:26:47 -04:00
Winlin
2384f3fb06 AI: Fix naming problem for app module. v7.0.85 (#4485)
Co-authored-by: OSSRS-AI <winlinam@gmail.com>
2025-09-12 19:44:43 -04:00
Jacob Su
a6d14eb09a SRT2RTMP: fix srt bridge hevc to rtmp error. v7.0.84 (#4446)
try to fix #4428.

## Cause

rtmp do not support hevc, rtmp enhanced do.

## How to reproduce

1. start srs.
   `./objs/srs -c conf/srt.conf`
2. publish hevc (h.265) stream to srs by srt.
`ffmpeg -re -i ./doc/source.flv -c:v libx265 -crf 28 -preset medium -c:a
copy -pes_payload_size 0 -f mpegts
'srt://127.0.0.1:10080?streamid=#!::r=live/livestream,m=publish'`
3. probe the rtmp stream
   `ffprobe rtmp://localhost/live/livestream`

## About the Failed BlackBox test
The failed blackbox test: `TestSlow_SrtPublish_RtmpPlay_HEVC_Basic`
`TestSlow_SrtPublish_HttpFlvPlay_HEVC_Basic`

### Cause: 

The ffmpeg 5 is used to record a piece of video (DRV), the ffmpeg will
transcode the enhanced flv format to TS format, but ffmpeg 5 don't
support enhanced rtmp (or flv) in this case.

The solution is to replace the ffmpeg to version 7 in those 2 test
cases.

### why not upgrade ffmpeg to version 7?

The black tests dependency on ffmpeg 5 will fail, and there are a few of
them are not easy to resolve in ffmpeg 7.

---------

Co-authored-by: winlin <winlinvip@gmail.com>
2025-09-09 21:10:04 -04:00
Winlin
3a29e5c550 AI: Fix naming issue for protocol module. v7.0.83 (#4482)
Co-authored-by: OSSRS-AI <winlinam@gmail.com>
2025-09-09 21:06:45 -04:00
Winlin
8f87d4092b AI: Fix naming problem in kernel module. v7.0.82 (#4479)
Co-authored-by: OSSRS-AI <winlinam@gmail.com>
2025-09-07 21:09:08 -04:00
Winlin
7c1e87ef5c AI: Add more utests for kernel module. v7.0.81 (#4478)
This PR significantly enhances the kernel module by adding comprehensive
unit test coverage and improving interface design for core buffer and
load balancer components.

- **ISrsDecoder**: New interface for decoding/deserialization operations
- **ISrsLbRoundRobin**: Extracted interface from concrete
SrsLbRoundRobin class for better abstraction
- **Enhanced Documentation**: Added comprehensive inline documentation
for ISrsEncoder, ISrsCodec, SrsBuffer, and SrsBitBuffer classes

---------

Co-authored-by: OSSRS-AI <winlinam@gmail.com>
2025-09-06 12:39:46 -04:00
Winlin
8976ce4c8d AI: Support anonymous coroutine with code block. v7.0.80 (#4475)
This PR introduces anonymous coroutine macros for easier coroutine
creation and improves the State Threads (ST) mutex and condition
variable handling in SRS.

- **Added coroutine macros**: `SRS_COROUTINE_GO`, `SRS_COROUTINE_GO2`,
`SRS_COROUTINE_GO_CTX`, `SRS_COROUTINE_GO_CTX2`
- **Added `SrsCoroutineChan`**: Channel for sharing data between
coroutines with coroutine-safe operations
- **Simplified coroutine creation**: Go-like syntax for creating
anonymous coroutines with code blocks

---------

Co-authored-by: Jacob Su <suzp1984@gmail.com>
Co-authored-by: OSSRS-AI <winlinam@gmail.com>
2025-09-06 08:10:49 -04:00
Winlin
8f09c4186e WebRTC: Fix race condition in RTC nack timer callbacks. v7.0.79 (#4474)
See [WebRTC: Fix race condition in RTC publish timer
callbacks.](421ab6c3fb)
v7.0.76 (https://github.com/ossrs/srs/pull/4470)
2025-09-05 09:58:19 -04:00