8909 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
Winlin
e509d079a2 Add codecs supprted in README 2025-11-09 12:17:31 -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
Chunbo
f90a96a03d Fix a typo in README.md (#4558) 2025-11-03 22:31:24 -05:00
OSSRS-AI
82d57e17ab AI: Refine bug caused flaky test failure. 2025-11-03 21:01:35 -05:00
winlin
7439a91daf Update README.md with v6.0-b3 release. 2025-11-03 21:01:28 -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
OSSRS-AI
8438c8a799 AI: Improve utest coverage. 2025-10-29 08:09:40 -04:00
OSSRS-AI
75d35b7817 AI: Ignore some code that is no need to cover. 2025-10-28 23:10:31 -04:00
OSSRS-AI
1faadd0c73 AI: Improve utest coverage for HLS. 2025-10-28 20:57:58 -04:00
winlin
758906353c Enable default configure test. 2025-10-28 10:04:53 -04:00
Haibo Chen(陈海博)
ef048b0d65 RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541)
for issue #4418, #4151, #4076 .DVR Missing First Few Seconds of
Audio/Video

### Root Cause
When recording WebRTC streams to FLV files using DVR, the first 4-6
seconds of audio/video are missing. This occurs because:

1. **Packets are discarded before A/V sync is available**: The
RTC-to-RTMP conversion pipeline actively discards all RTP packets when
avsync_time <= 0.
2. **Original algorithm requires 2 RTCP SR packets**: The previous
implementation needed to receive two RTCP Sender Report (SR) packets
before it could calculate the rate for audio/video synchronization
timestamp conversion.
3. **Delay causes packet loss**: Since RTCP SR packets typically arrive
every 2-3 seconds, waiting for 2 SRs means 4-6 seconds of packets are
discarded before A/V sync becomes available.
4. **Audio SR arrives slower than video SR**: As reported in the issue,
video RTCP SR packets arrive much faster than audio SR packets. This
asymmetry causes audio packets to be discarded for a longer period,
resulting in the audio loss observed in DVR recordings.

### Solution
1. **Initialize rate from SDP**: Use the sample rate from SDP (Session
Description Protocol) to calculate the initial rate immediately when the
track is created.
Audio (Opus): 48000 Hz → rate = 48 (RTP units per millisecond)
Video (H.264/H.265): 90000 Hz → rate = 90 (RTP units per millisecond)
2. **Enable immediate A/V sync:** With the SDP rate available,
cal_avsync_time() can calculate valid timestamps from the very first RTP
packet, eliminating packet loss.
3. **Smooth transition to precise rate**: After receiving the 2nd RTCP
SR, update to the precisely calculated rate based on actual RTP/NTP
timestamp mapping.

## Configuration

Added new configuration option `init_rate_from_sdp` in the RTC vhost
section:

```nginx
vhost rtc.vhost.srs.com {
    rtc {
        # Whether initialize RTP rate from SDP sample rate for immediate A/V sync.
        # When enabled, the RTP rate (units per millisecond) is initialized from the SDP
        # sample rate (e.g., 90 for video 90kHz, 48 for audio 48kHz) before receiving
        # 2 RTCP SR packets. This allows immediate audio/video synchronization.
        # The rate will be updated to a more precise value after receiving the 2nd SR.
        # Overwrite by env SRS_VHOST_RTC_INIT_RATE_FROM_SDP for all vhosts.
        # Default: off
        init_rate_from_sdp off;
    }
}
```

**⚠️ Important Note**: This config defaults to **off** because:
-  When **enabled**: Fixes the audio loss problem (no missing first 4-6
seconds)
-  When **enabled**: VLC on macOS cannot play the video properly
-  Other platforms work fine (Windows, Linux)
-  FFplay works fine on all platforms

Users experiencing audio loss in DVR recordings can enable this option
if they don't need VLC macOS compatibility. We're investigating the VLC
macOS issue to make this feature safe to enable by default in the
future.

---------

Co-authored-by: winlin <winlinvip@gmail.com>
Co-authored-by: OSSRS-AI <winlinam@gmail.com>
2025-10-28 09:33:40 -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
winlin
1d9105396d Update guideline for AI about sanitizer. 2025-10-26 16:28:02 -04:00
OSSRS-AI
4ae9871285 AI: Remove deprecated SrsRtcPublisherAsync and SrsRtcPlayerAsync use WHIP/WHEP. 2025-10-26 10:00:05 -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
d9ea25b441 AI: Update conf description for multiple ep for callback. #4421 2025-10-24 22:22:14 -04:00
Haibo Chen(陈海博)
8f1578e0e3 Refactor: Rename ide/ directory to cmake/ for better clarity (#4539)
This PR renames the trunk/ide/ directory to trunk/cmake/ to better
reflect its actual purpose. The directory contains CMake build
configuration files used by multiple IDEs (CLion, VSCode), not
IDE-specific files.

* Directory rename: trunk/ide/ → trunk/cmake/
* Build output location: trunk/ide/vscode-build/ → trunk/cmake/build/
* CMakeLists.txt: Moved from trunk/ide/srs_clion/CMakeLists.txt to
trunk/cmake/CMakeLists.txt
2025-10-23 20:38:48 -04:00
OSSRS-AI
2fb216e86d AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
winlin
2893f43327 Compress guideline for AI. 2025-10-23 07:30:53 -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
0e28422d12 Update guideline for AI. 2025-10-22 11:46:11 -04:00
OSSRS-AI
8fd92d1598 AI: Add utest to cover forwarding module. #4531 2025-10-21 23:33:29 -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
OSSRS-AI
4e35b6cacc AI: Add utest to cover signal manager 2025-10-19 22:46:06 -04:00
OSSRS-AI
341c0c000c AI: Add workflow utest for http stream. 2025-10-19 21:55:45 -04:00
OSSRS-AI
ce7ac11eae AI: Add workflow test for HTTP conn 2025-10-19 19:10:52 -04:00
OSSRS-AI
35d0e3d7c7 AI: Add workflow utest for SRT conn 2025-10-19 13:23:20 -04:00