Commit Graph

8878 Commits

Author SHA1 Message Date
winlin
d73ac3670a AI: Update the docs guideline for augment code. 2025-07-02 20:53:19 -04:00
winlin
89f343af15 AI: Update the pr diff guideline for augment code. 2025-07-02 08:16:52 -04:00
winlin
97e2b64939 AI: Update utest private access and smart pointers for augment code. 2025-07-01 10:39:32 -04:00
winlin
1173560b55 AI: Add run utest in guideline for augment code. 2025-06-30 08:10:21 -04:00
winlin
e84074094b AI: Update threading model for augment code. 2025-06-28 09:13:50 -04:00
Winlin
07163df9a4 Refactor code for #4349 for better review. (#4405)
Also for augment AI to review it.
2025-06-27 10:52:00 -04:00
Winlin
40df358e50 AI: Add guide for Augment. (#4404) 2025-06-27 07:23:45 -04:00
winlin
acb9b88566 Migrate proxy to ossrs/proxy-go repository. 2025-06-23 10:39:57 -04:00
winlin
8538575915 Remove AGENTS for AI. 2025-06-21 07:51:06 -04:00
winlin
dcde554907 Debugging: Drop the specified N original SRTP packet for testing NACK. 2025-06-15 10:01:08 -04:00
Haibo Chen(陈海博)
07e7984fdf Player: Get codec by webrtc api: pc.getStats. v7.0.42 (#4310)
1. It cannot retrieve codec information on `Firefox` by
`getSenders/getReceivers`
2. It can retrieve codec information on `Chrome` by `getReceivers`, but
incorrect, like this:

![image](https://github.com/user-attachments/assets/e0bb93b1-ccd0-46c0-ae21-074934f66a1e)

3. So, we retrieve codec information from `getStats`, and it works well.
4. The timer is used because sometimes the codec cannot be retrieved
when `iceGatheringState` is `complete`.
5. Testing has been completed on the browsers listed below.
   - [x] Chrome
   - [x] Edge
   - [x] Safari
   - [x] Firefox

---------

Co-authored-by: winlin <winlinvip@gmail.com>
2025-06-04 10:28:46 -04:00
Haibo Chen(陈海博)
133866a944 Transcode: Bugfix: Fix loop transcoding with host. #3516. v6.0.168 v7.0.41 (#4325)
#### What issue has been resolved?
for issue: https://github.com/ossrs/srs/issues/3516
https://github.com/ossrs/srs/issues/4055
https://github.com/ossrs/srs/pull/3618

#### What is the root cause of the problem?
The issue arises from a mismatch between the `input` and `output`
formats within the
[`SrsEncoder::initialize_ffmpeg`](https://github.com/ossrs/srs/pull/4325/files#diff-a3dd7c498fc26d36def2e8c2c3b7edfe1bf78f0620b1a838aefa70ba119cad03L241-L254)
function.

For example:
Input: `rtmp://127.0.0.1:1935/live?vhost=__defaultVhost__/livestream_ff`
Output:
`rtmp://127.0.0.1:1935/live/livestream_ff?vhost=__defaultVhost__`

This may result in the failure of the [code
segment](https://github.com/ossrs/srs/pull/4325/files#diff-a3dd7c498fc26d36def2e8c2c3b7edfe1bf78f0620b1a838aefa70ba119cad03L292-L298)
responsible for determining whether to loop.

#### What is the approach to solving this issue?
It simply involves modifying the order of `stream` and `vhost`.

#### How was the issue introduced?
The commit introducing this bug is:
7d47017a00
The order of [parameters in the configuration
file](7d47017a00 (diff-428de168925d659dae72bb49273c3b048ed2800906c6848560badae854250126L26-R26))
has been modified to address the `ingest` issue.

#### Outstanding issues
Please note that this PR does not entirely resolve the issue; for
example, modifying the `output` format in configuration still results in
exceptions. To comprehensively address this problem, extensive code
modifications would be required.

However, strictly adhering to the configuration file format can
effectively prevent this issue.

---------

Co-authored-by: Jacob Su <suzp1984@gmail.com>
Co-authored-by: john <hondaxiao@tencent.com>
Co-authored-by: winlin <winlinvip@gmail.com>
2025-06-04 10:11:58 -04:00
Hamed Mansouri
8b65fe2063 Update the release in the README for consistent. v7.0.40 (#4341)
---------
Co-authored-by: Haibo Chen <495810242@qq.com>
Co-authored-by: winlin <winlinvip@gmail.com>
2025-06-04 08:08:00 -04:00
Haibo Chen(陈海博)
2d4bb8e839 Update the codename for version 7.0 to "Kai". v7.0.39 (#4368)
Co-authored-by: winlin <winlinvip@gmail.com>
2025-06-04 08:04:27 -04:00
ChenGH
cc115afc1d Script: Use clang-format to unify the coding style. v7.0.38 (#4366)
1. add clang-format config file
2. add clang_format.sh file, use to format cpp code before pr merged.

---------

Co-authored-by: winlin <winlinvip@gmail.com>
2025-06-01 22:01:15 -04:00
pengzhixiang
9b942fafcc RTMP: Use extended timestamp as delta when chunk fmt=1/2. v6.0.167 v7.0.37 (#4356)
1. When the chunk message header employs type 1 and type 2, the extended
timestamp denotes the time delta.
2. When the DTS (Decoding Time Stamp) experiences a jump and exceeds
16777215, there can be errors in DTS calculation, and if the audio and
video delta differs, it may result in audio-video synchronization
issues.

---------

`TRANS_BY_GPT4`

---------

Co-authored-by: 彭治湘 <zuolengchan@douyu.tv>
Co-authored-by: Haibo Chen(陈海博) <495810242@qq.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: winlin <winlinvip@gmail.com>
2025-05-29 14:26:05 -04:00
Haibo Chen(陈海博)
33b0a0fe7d Fix error about TestRtcPublish_HttpFlvPlay. v7.0.36 (#4363)
In the scenario of converting WebRTC to RTMP, this conversion will not
proceed until an SenderReport is received; for reference, see:
https://github.com/ossrs/srs/pull/2470.
Thus, if HTTP-FLV streaming is attempted before the SR is received, the
FLV Header will contain only audio, devoid of video content.
This error can be resolved by disabling `guess_has_av` in the
configuration file, since we can guarantee that both audio and video are
present in the test cases.

However, in the original regression tests, the
`TestRtcPublish_HttpFlvPlay` test case contains a bug:

5a404c089b/trunk/3rdparty/srs-bench/srs/rtc_test.go (L2421-L2424)

The test would pass when `hasAudio` is true and `hasVideo` is false,
which is actually incorrect. Therefore, it has been revised so that the
test now only passes if both values are true.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: winlin <winlinvip@gmail.com>
2025-05-29 14:07:56 -04:00
Haibo Chen(陈海博)
9c559dcb48 VSCode: Support GDB on Linux and LLDB on macOS. v7.0.35 (#4362)
Co-authored-by: winlin <winlinvip@gmail.com>
2025-05-29 08:44:44 -04:00
winlin
5a404c089b VSCode: Support debug and run utest in VSC. 2025-05-28 18:38:56 -04:00
Haibo Chen(陈海博)
974826800f update pion/webrtc to v4. v7.0.34 (#4359)
To enable H.265 support for the WebRTC protocol, upgrade the pion/webrtc
library to version 4.

---------

Co-authored-by: john <hondaxiao@tencent.com>
Co-authored-by: winlin <winlinvip@gmail.com>
2025-05-26 17:48:53 +08:00
winlin
53a6af659f Codex: Fix potential issues with memory leak. 2025-05-21 11:27:10 -04:00
winlin
2b0de99b5e Add AGENTS.md for OpenAI codex agent. 2025-05-21 10:45:58 -04:00
Haibo Chen(陈海博)
0c88ddbcdf rtmp2rtc: Support RTMP-to-WebRTC conversion with HEVC. v7.0.33 (#4289)
```bash
C:\Program Files\Google\Chrome\Application>"C:\Program Files\Google\Chrome\Application\chrome.exe" --enable-features=WebRtcAllowH265Receive --force-fieldtrials=WebRTC-Video-H26xPacketBuffer/Enabled

open -a "Google Chrome" --args --enable-features=WebRtcAllowH265Receive --force-fieldtrials=WebRTC-Video-H26xPacketBuffer/Enabled
```

> Note: The latest Chrome browser (version 136) fully enables this by
default, so there's no need to launch it with any extra parameters.

```bash
./objs/srs -c conf/rtmp2rtc.conf
```

```bash
ffmpeg -stream_loop -1 -re -i input.mp4 -c:v libx265 -preset fast -b:v 2000k -maxrate 2000k -bufsize 4000k -bf 0 -c:a aac -b:a 128k -ar 44100 -ac 2 -f flv rtmp://localhost/live/livestream
```

```bash
http://localhost:1985/rtc/v1/whep/?app=live&stream=livestream
```

![image](https://github.com/user-attachments/assets/bdbf4c67-b7e2-4dc6-92a1-93e2c78e00fe)

sendrecv offer
```bash
--enable-features=WebRtcAllowH265Send,PlatformHEVCEncoderSupport,WebRtcAllowH265Receive --force-fieldtrials=WebRTC-Video-H26xPacketBuffer/Enabled
```

sendonly offer
```bash
--enable-features=WebRtcAllowH265Send,PlatformHEVCEncoderSupport
```

recvonly offer
```bash
--enable-features=WebRtcAllowH265Receive --force-fieldtrials=WebRTC-Video-H26xPacketBuffer/Enabled
```

* Browser Test for supporting H265

https://webrtc.github.io/samples/src/content/peerconnection/change-codecs/

![image](https://github.com/user-attachments/assets/174476df-a7aa-4951-9880-56328ec75065)

* How to test Safari: https://github.com/ossrs/srs/pull/3441
* Debug in Safari

![image](https://github.com/user-attachments/assets/6cf94fca-e3ed-46d2-a102-a472f1699b4e)

---------

Co-authored-by: chundonglinlin <chundonglinlin@163.com>
Co-authored-by: winlin <winlinvip@gmail.com>
Co-authored-by: john <hondaxiao@tencent.com>

---------

Co-authored-by: chundonglinlin <chundonglinlin@163.com>
Co-authored-by: john <hondaxiao@tencent.com>
2025-05-14 07:49:04 -04:00
winlin
d35d02f112 Release v6.0-a2, 6.0 alpha2, v6.0.165, 169712 lines. 2025-05-03 20:28:55 -04:00
Haibo Chen(陈海博)
e00937e387 Fix memory leaks from errors skipping resource release. v7.0.32 (#4308)
---------

Co-authored-by: winlin <winlinvip@gmail.com>
Co-authored-by: john <hondaxiao@tencent.com>

---------

Co-authored-by: john <hondaxiao@tencent.com>
2025-04-30 12:09:31 +08:00
winlin
3fbd609bc7 Update CHANGELOG for #4309. v7.0.31 2025-04-26 06:58:00 -04:00
winlin
308bb6ec54 Upgrade actions worlflow image to Ubuntu 22.04
See https://github.com/actions/runner-images/issues/11101 for details.
2025-04-26 00:14:19 -04:00
Winlin
4e55bc83b7 Support custom deleter for SrsUniquePtr. (#4309)
SrsUniquePtr does not support array or object created by malloc, because
we only use delete to dispose the resource. You can use a custom
function to free the memory allocated by malloc or other allocators.
```cpp
      char* p = (char*)malloc(1024);
      SrsUniquePtr<char> ptr(p, your_free_chars);
```

This is used to replace the SrsAutoFreeH. For example:
```cpp
      addrinfo* r = NULL;
      SrsAutoFreeH(addrinfo, r, freeaddrinfo);
      getaddrinfo("127.0.0.1", NULL, &hints, &r);
```

Now, this can be replaced by:
```cpp
      addrinfo* r = NULL;
      getaddrinfo("127.0.0.1", NULL, &hints, &r);
      SrsUniquePtr<addrinfo> r2(r, freeaddrinfo);
```

Please aware that there is a slight difference between SrsAutoFreeH and
SrsUniquePtr. SrsAutoFreeH will track the address of pointer, while
SrsUniquePtr will not.
```cpp
      addrinfo* r = NULL;
      SrsAutoFreeH(addrinfo, r, freeaddrinfo); // r will be freed even r is changed later.
      SrsUniquePtr<addrinfo> ptr(r, freeaddrinfo); // crash because r is an invalid pointer.
```

---------

Co-authored-by: Haibo Chen <495810242@qq.com>
Co-authored-by: john <hondaxiao@tencent.com>
2025-04-26 00:01:34 -04:00
Winlin or William
5881155095 Update feature_request.md 2025-04-16 19:08:54 -04:00
Lukas
5f134798b6 Typo: "forked" process in log output. v7.0.30 (#4292)
---------

Co-authored-by: Haibo Chen <495810242@qq.com>
Co-authored-by: winlin <winlinvip@gmail.com>

Co-authored-by: Haibo Chen <495810242@qq.com>
2025-03-21 19:18:11 +08:00
chundonglinlin
e2461cd16d Build: update build version to v7. v7.0.29 (#4294)
Update the prompt document address to the latest version v7.

---------

Co-authored-by: Haibo Chen <495810242@qq.com>
Co-authored-by: winlin <winlinvip@gmail.com>

---------

Co-authored-by: Haibo Chen(陈海博) <495810242@qq.com>
Co-authored-by: john <hondaxiao@tencent.com>
2025-03-21 19:15:05 +08:00
Arjen10
464a0134f3 replace values with enums. v6.0.166 v7.0.28 (#4303)
---------

Co-authored-by: Haibo Chen <495810242@qq.com>
Co-authored-by: john <hondaxiao@tencent.com>
Co-authored-by: winlin <winlinvip@gmail.com>

---------

Co-authored-by: Haibo Chen(陈海博) <495810242@qq.com>
Co-authored-by: john <hondaxiao@tencent.com>
2025-03-21 19:11:19 +08:00
Haibo Chen(陈海博)
909c9efa40 free sample to prevent memory leak. v5.0.222 v6.0.164 v7.0.26 (#4305)
修复`SrsRtpRawPayload::copy()`方法中sample_覆盖的问题。

---------

Co-authored-by: chundonglinlin <chundonglinlin@163.com>
Co-authored-by: winlin <winlinvip@gmail.com>

---------

Co-authored-by: john <hondaxiao@tencent.com>
2025-03-21 10:38:08 +08:00
Haibo Chen(陈海博)
feb2abbd73 update geekyeggo/delete-artifact to 5.0.0. v5.0.221 v6.0.163 v7.0.25 (#4302)
>
https://github.com/marketplace/actions/delete-artifact?version=v5.0.0#-compatibility

The current version of `actions/upload-artifact` is `v4`, and the
corresponding version for `delete-artifact` should be `v5`.



---------

`TRANS_BY_GPT4`

---------

Co-authored-by: chundonglinlin <chundonglinlin@163.com>
Co-authored-by: winlin <winlinvip@gmail.com>

---------

Co-authored-by: john <hondaxiao@tencent.com>
2025-03-18 08:25:48 +08:00
chundonglinlin
3d8ef92a23 Dvr: support h265 flv fragments. v6.0.162 v7.0.24 (#4296)
1. Issue
When segmenting H.265 encoded FLV files using a DVR, the system does not
create FLV segments at regular intervals as specified by the
`dvr_wait_keyframe` configuration.

2. Configure dvr.segment.conf
```config
# the config for srs to dvr in segment mode
# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/dvr
# @see full.conf for detail config.

listen              1935;
max_connections     1000;
daemon              off;
srs_log_tank        console;
vhost __defaultVhost__ {
    dvr {
        enabled      on;
        dvr_path     ./objs/nginx/html/[app]/[stream].[timestamp].flv;
        dvr_plan     segment;
        dvr_duration    30;
        dvr_wait_keyframe       on;
    }
}
```

3. Stream Push Testing
### FFmpeg Stream Push
Domestic FFmpeg version (codecId=12)
```sh
hevc-12-ffmpeg -stream_loop -1 -re -i 264_aac.flv -c:v libx265 -preset fast -b:v 2000k -maxrate 2000k -bufsize 4000k -bf 0 -c:a aac -b:a 128k -ar 44100 -ac 2 -f flv rtmp://localhost/live/livestream
```
FFmpeg version 6.0 or higher (supports `enhanced RTMP`)
```sh
ffmpeg -stream_loop -1 -re -i 264_aac.flv -c:v libx265 -preset fast -b:v 2000k -maxrate 2000k -bufsize 4000k -bf 0 -c:a aac -b:a 128k -ar 44100 -ac 2 -f flv rtmp://localhost/live/livestream
```

OBS streaming (version 30.0 or above supports `enhanced RTMP`)

![image](https://github.com/user-attachments/assets/fd2806c3-b0e3-44c4-a2d5-e04e6e5386ff)

![image](https://github.com/user-attachments/assets/15ef9c45-e15a-426e-b70c-d4bdd5dc8055)

## 4. Playback Testing
SRS player (supports both `enhanced RTMP` and `codec=12 FLV`)
```
http://127.0.0.1:8080/players/srs_player.html
```
Domestic ffplay (supports `codec=12 FLV`)
```
hevc-12-ffplay http://127.0.0.1:8080/live/livestream.1740311867638.flv
```
ffplay (versions above ffmpeg 6.0 support `enhanced RTMP`)
```
ffplay http://127.0.0.1:8080/live/livestream.1740311867638.flv
```

![image](https://github.com/user-attachments/assets/711a4182-418c-4134-934f-cba41a08e06f)



---------

`TRANS_BY_GPT4`

---------

Co-authored-by: Haibo Chen <495810242@qq.com>
Co-authored-by: john <hondaxiao@tencent.com>
Co-authored-by: winlin <winlinvip@gmail.com>

---------

Co-authored-by: john <hondaxiao@tencent.com>
2025-03-18 07:34:04 +08:00
Winlin or William
02f04456b0 Update FUNDING.yml
Please contribute to OpenCollective only, thanks!
2025-03-14 11:33:14 -04:00
johzzy
93cba246bc fix typo about heartbeat. v5.0.220 v6.0.161 v7.0.23 (#4253)
---------

Co-authored-by: Haibo Chen <495810242@qq.com>
Co-authored-by: john <hondaxiao@tencent.com>
Co-authored-by: winlin <winlinvip@gmail.com>

---------

Co-authored-by: john <hondaxiao@tencent.com>
2025-02-20 13:47:52 +08:00
Haibo Chen
6a612784d0 fix ci error. v5.0.219 v6.0.160 v7.0.22 (#4291)
Starting January 30th, 2025, GitHub Actions customers will no longer be
able to use v3 of
[actions/upload-artifact](https://github.com/actions/upload-artifact) or
[actions/download-artifact](https://github.com/actions/download-artifact).
Customers should update workflows to begin using [v4 of the artifact
actions](https://github.blog/2024-02-12-get-started-with-v4-of-github-actions-artifacts/).
Learn more:
https://github.blog/changelog/2024-04-16-deprecation-notice-v3-of-the-artifact-actions/

---------

Co-authored-by: john <hondaxiao@tencent.com>
Co-authored-by: winlin <winlinvip@gmail.com>

---------

Co-authored-by: john <hondaxiao@tencent.com>
2025-02-20 12:26:24 +08:00
ChenGH
13597d1b7f update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271)
update copyright to 2025

---------

Co-authored-by: john <hondaxiao@tencent.com>
Co-authored-by: winlin <winlinvip@gmail.com>
2025-01-14 17:35:18 +08:00
Jacob Su
7416134262 fix compile error in srs_protocol_rtmp_stack.cpp (#4247)
Fix a compiling error.

## How to reproduce?


7951bf3bd6/trunk/src/core/srs_core_performance.hpp (L146)

Delete this line to write `iovs` one by one (or 2 by 2).
Then `./configure && make`, the compiling error appears.
2024-12-05 16:53:22 +08:00
Jacob Su
7951bf3bd6 Test: Fix utest fail for StUtimeInMicroseconds. v7.0.20 (#4218)
```
../../../src/utest/srs_utest_st.cpp:27: Failure
Expected: (st_time_2 - st_time_1) <= (100), actual: 119 vs 100
[  FAILED  ] StTest.StUtimeInMicroseconds (0 ms)
```

Maybe github's vm, running the action jobs, is slower. I notice this
error happens frequently, so let the UT pass by increase the number.

---------

Co-authored-by: Haibo Chen <495810242@qq.com>
Co-authored-by: winlin <winlinvip@gmail.com>
2024-10-31 18:25:57 +08:00
Haibo Chen
58e775ce8d HLS: Fix error when stream has extension. #4215 v5.0.217 v6.0.158 v7.0.19 (#4216)
---------

Co-authored-by: Jacob Su <suzp1984@gmail.com>
Co-authored-by: winlin <winlinvip@gmail.com>
2024-10-31 17:50:56 +08:00
Jacob Su
101382afd0 RTC2RTMP: Fix screen sharing stutter caused by packet loss. v5.0.216 v6.0.157 v7.0.18 (#4160)
## How to reproduce?

1. Refer this commit, which contains the web demo to capture screen as
video stream through RTC.
2. Copy the `trunk/research/players/whip.html` and
`trunk/research/players/js/srs.sdk.js` to replace the `develop` branch
source code.
3. `./configure && make`
4. `./objs/srs -c conf/rtc2rtmp.conf`
5. open `http://localhost:8080/players/whip.html?schema=http`
6. check `Screen` radio option.
7. click `publish`, then check the screen to share.
8. play the rtmp live stream: `rtmp://localhost/live/livestream`
9. check the video stuttering.

## Cause
When capture screen by the chrome web browser, which send RTP packet
with empty payload frequently, then all the cached RTP packets are
dropped before next key frame arrive in this case.

The OBS screen stream and camera stream do not have such problem.

## Add screen stream to WHIP demo

><img width="581" alt="Screenshot 2024-08-28 at 2 49 46 PM"
src="https://github.com/user-attachments/assets/9557dbd2-c799-4dfd-b336-5bbf2e4f8fb8">

---------

Co-authored-by: winlin <winlinvip@gmail.com>
2024-10-15 19:00:07 +08:00
Jacob Su
e7d78462fe ST: Use clock_gettime to prevent time jumping backwards. v7.0.17 (#3979)
try to fix #3978 

**Background**
check #3978 

**Research**

I referred the Android platform's solution, because I have android
background, and there is a loop to handle message inside android.


ff007a03c0/core/java/android/os/Handler.java (L701-L706C6)

```
    public final boolean sendMessageDelayed(@NonNull Message msg, long delayMillis) {
        if (delayMillis < 0) {
            delayMillis = 0;
        }
        return sendMessageAtTime(msg, SystemClock.uptimeMillis() + delayMillis);
    }
```


59d9dc1f50/libutils/SystemClock.cpp (L37-L51)

```
/*
 * native public static long uptimeMillis();
 */
int64_t uptimeMillis()
{
    return nanoseconds_to_milliseconds(uptimeNanos());
}


/*
 * public static native long uptimeNanos();
 */
int64_t uptimeNanos()
{
    return systemTime(SYSTEM_TIME_MONOTONIC);
}
```


59d9dc1f50/libutils/Timers.cpp (L32-L55)
```
#if defined(__linux__)
nsecs_t systemTime(int clock) {
    checkClockId(clock);
    static constexpr clockid_t clocks[] = {CLOCK_REALTIME, CLOCK_MONOTONIC,
                                           CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID,
                                           CLOCK_BOOTTIME};
    static_assert(clock_id_max == arraysize(clocks));
    timespec t = {};
    clock_gettime(clocks[clock], &t);
    return nsecs_t(t.tv_sec)*1000000000LL + t.tv_nsec;
}
#else
nsecs_t systemTime(int clock) {
    // TODO: is this ever called with anything but REALTIME on mac/windows?
    checkClockId(clock);


    // Clock support varies widely across hosts. Mac OS doesn't support
    // CLOCK_BOOTTIME (and doesn't even have clock_gettime until 10.12).
    // Windows is windows.
    timeval t = {};
    gettimeofday(&t, nullptr);
    return nsecs_t(t.tv_sec)*1000000000LL + nsecs_t(t.tv_usec)*1000LL;
}
#endif
```
For Linux system, we can use `clock_gettime` api, but it's first
appeared in Mac OSX 10.12.

`man clock_gettime`

The requirement is to find an alternative way to get the timestamp in
microsecond unit, but the `clock_gettime` get nanoseconds, the math
formula is the nanoseconds / 1000 = microsecond. Then I check the
performance of this api + math division.

I used those code to check the `clock_gettime` performance.

```
#include <sys/time.h>
#include <time.h>
#include <stdio.h>
#include <unistd.h>

int main() {
	struct timeval tv;
	struct timespec ts;
	clock_t start;
	clock_t end;
	long t;

	while (1) {
		start = clock();
		gettimeofday(&tv, NULL);
		end = clock();
		printf("gettimeofday clock is %lu\n", end - start);
		printf("gettimeofday is %lld\n", (tv.tv_sec * 1000000LL + tv.tv_usec));

		start = clock();
		clock_gettime(CLOCK_MONOTONIC, &ts);
		t = ts.tv_sec * 1000000L + ts.tv_nsec / 1000L;
		end = clock();
		printf("clock_monotonic clock is %lu\n", end - start);
		printf("clock_monotonic: seconds is %ld, nanoseconds is %ld, sum is %ld\n", ts.tv_sec, ts.tv_nsec, t);

		start = clock();
		clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
		t = ts.tv_sec * 1000000L + ts.tv_nsec / 1000L;
		end = clock();
		printf("clock_monotonic_raw clock is %lu\n", end - start);
		printf("clock_monotonic_raw: nanoseconds is %ld, sum is %ld\n", ts.tv_nsec, t);

		sleep(3);
	}
	
	return 0;
}

```

Here is output:

env: Mac OS M2 chip.

```
gettimeofday clock is 11
gettimeofday is 1709775727153949
clock_monotonic clock is 2
clock_monotonic: seconds is 1525204, nanoseconds is 409453000, sum is 1525204409453
clock_monotonic_raw clock is 2
clock_monotonic_raw: nanoseconds is 770493000, sum is 1525222770493
```
We can see the `clock_gettime` is faster than `gettimeofday`, so there
are no performance risks.

**MacOS solution**

`clock_gettime` api only available until mac os 10.12, for the mac os
older than 10.12, just keep the `gettimeofday`.
check osx version in `auto/options.sh`, then add MACRO in
`auto/depends.sh`, the MACRO is `MD_OSX_HAS_NO_CLOCK_GETTIME`.


**CYGWIN**
According to google search, it seems the
`clock_gettime(CLOCK_MONOTONIC)` is not support well at least 10 years
ago, but I didn't own an windows machine, so can't verify it. so keep
win's solution.

---------

Co-authored-by: winlin <winlinvip@gmail.com>
2024-10-15 17:52:17 +08:00
Winlin
0de887d374 Update bug_report.md 2024-10-09 11:29:35 +08:00
Winlin
2068aa4659 Update FUNDING.yml 2024-09-28 10:41:35 +08:00
winlin
40e8ed4586 VSCode: Support IDE vscode to run and debug. 2024-09-10 17:46:54 +08:00
winlin
e674f8266a Proxy: Remove dependency of godotenv. #4158 2024-09-10 10:53:09 +08:00
Winlin
2e4014ae1c Proxy: Support proxy server for SRS. v7.0.16 (#4158)
Please note that the proxy server is a new architecture or the next
version of the Origin Cluster, which allows the publication of multiple
streams. The SRS origin cluster consists of a group of origin servers
designed to handle a large number of streams.

```text
                         +-----------------------+
                     +---+ SRS Proxy(Deployment) +------+---------------------+
+-----------------+  |   +-----------+-----------+      +                     +
| LB(K8s Service) +--+               +(Redis/MESH)      + SRS Origin Servers  +
+-----------------+  |   +-----------+-----------+      +    (Deployment)     +
                     +---+ SRS Proxy(Deployment) +------+---------------------+
                         +-----------------------+
```

The new origin cluster is designed as a collection of proxy servers. For
more information, see [Discussion
#3634](https://github.com/ossrs/srs/discussions/3634). If you prefer to
use the old origin cluster, please switch to a version before SRS 6.0.

A proxy server can be used for a set of origin servers, which are
isolated and dedicated origin servers. The main improvement in the new
architecture is to store the state for origin servers in the proxy
server, rather than using MESH to communicate between origin servers.
With a proxy server, you can deploy origin servers as stateless servers,
such as in a Kubernetes (K8s) deployment.

Now that the proxy server is a stateful server, it uses Redis to store
the states. For faster development, we use Go to develop the proxy
server, instead of C/C++. Therefore, the proxy server itself is also
stateless, with all states stored in the Redis server or cluster. This
makes the new origin cluster architecture very powerful and robust.

The proxy server is also an architecture designed to solve multiple
process bottlenecks. You can run hundreds of SRS origin servers with one
proxy server on the same machine. This solution can utilize multi-core
machines, such as servers with 128 CPUs. Thus, we can keep SRS
single-threaded and very simple. See
https://github.com/ossrs/srs/discussions/3665#discussioncomment-6474441
for details.

```text
                                       +--------------------+
                               +-------+ SRS Origin Server  +
                               +       +--------------------+
                               +
+-----------------------+      +       +--------------------+
+ SRS Proxy(Deployment) +------+-------+ SRS Origin Server  +
+-----------------------+      +       +--------------------+
                               +
                               +       +--------------------+
                               +-------+ SRS Origin Server  +
                                       +--------------------+
```

Keep in mind that the proxy server for the Origin Cluster is designed to
handle many streams. To address the issue of many viewers, we will
enhance the Edge Cluster to support more protocols.

```text
+------------------+                                               +--------------------+
+ SRS Edge Server  +--+                                    +-------+ SRS Origin Server  +
+------------------+  +                                    +       +--------------------+
                      +                                    +
+------------------+  +     +-----------------------+      +       +--------------------+
+ SRS Edge Server  +--+-----+ SRS Proxy(Deployment) +------+-------+ SRS Origin Server  +
+------------------+  +     +-----------------------+      +       +--------------------+
                      +                                    +
+------------------+  +                                    +       +--------------------+
+ SRS Edge Server  +--+                                    +-------+ SRS Origin Server  +
+------------------+                                               +--------------------+
```

With the new Origin Cluster and Edge Cluster, you have a media system
capable of supporting a large number of streams and viewers. For
example, you can publish 10,000 streams, each with 100,000 viewers.

---------

Co-authored-by: Jacob Su <suzp1984@gmail.com>
2024-09-09 12:06:02 +08:00
Winlin
b475d552aa Heartbeat: Report ports for proxy server. v5.0.215 v6.0.156 v7.0.15 (#4171)
The heartbeat of SRS is a timer that requests an HTTP URL. We can use
this heartbeat to report the necessary information for registering the
backend server with the proxy server.

```text
SRS(backend) --heartbeat---> Proxy server
```

A proxy server is a specialized load balancer for media servers. It
operates at the application level rather than the TCP level. For more
information about the proxy server, see issue #4158.

Note that we will merge this PR into SRS 5.0+, allowing the use of SRS
5.0+ as the backend server, not limited to SRS 7.0. However, the proxy
server is introduced in SRS 7.0.

It's also possible to implement a registration service, allowing you to
use other media servers as backend servers. For example, if you gather
information about an nginx-rtmp server and register it with the proxy
server, the proxy will forward RTMP streams to nginx-rtmp. The backend
server is not limited to SRS.

---------

Co-authored-by: Jacob Su <suzp1984@gmail.com>
2024-09-09 10:37:41 +08:00