From 24235d8b6a9c7a6403464c726f7d18ddc4186fea Mon Sep 17 00:00:00 2001 From: john Date: Thu, 16 Nov 2023 18:17:04 +0800 Subject: [PATCH] Fix the test fail when enable ffmpeg-opus. v6.0.100 (#3868) 1. After enabling FFmpeg opus, the transcoding time for each opus packet is around 4ms. 2. To speed up case execution, our test publisher sends 400 opus packets at intervals of 1ms. 3. After the publisher starts, wait for 30ms, then the player starts. 4. Due to the lengthy processing time for each opus packet, SRS continuously receives packets from the publisher, so it doesn't switch coroutines and can't accept the player's connection. 5. Only after all opus packets are processed will it accept the player connection. Therefore, the player doesn't receive any data, leading to the failure of the case. --------- Co-authored-by: winlin --- .github/workflows/test.yml | 2 +- trunk/3rdparty/srs-bench/srs/rtmp_test.go | 7 +++++-- trunk/Dockerfile.test | 3 ++- trunk/auto/options.sh | 1 + trunk/doc/CHANGELOG.md | 1 + trunk/ide/srs_clion/CMakeLists.txt | 4 ++-- trunk/src/app/srs_app_rtc_codec.cpp | 4 ++++ trunk/src/core/srs_core_version6.hpp | 2 +- 8 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6ea5e3c1f..53a114a6c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -198,7 +198,7 @@ jobs: - name: Run SRS regression-test run: | docker run --rm srs:test bash -c './objs/srs -c conf/regression-test.conf && \ - cd 3rdparty/srs-bench && (./objs/srs_test -test.v || (cat ../../objs/srs.log && exit 1)) && \ + cd 3rdparty/srs-bench && (./objs/srs_test -test.v || (cat ../../objs/srs.log && exit 1)) && cat ../../objs/srs.log && \ ./objs/srs_gb28181_test -test.v' runs-on: ubuntu-20.04 diff --git a/trunk/3rdparty/srs-bench/srs/rtmp_test.go b/trunk/3rdparty/srs-bench/srs/rtmp_test.go index 7dd39597f..798db65da 100644 --- a/trunk/3rdparty/srs-bench/srs/rtmp_test.go +++ b/trunk/3rdparty/srs-bench/srs/rtmp_test.go @@ -24,7 +24,6 @@ import ( "bytes" "context" "fmt" - "github.com/pkg/errors" "math/rand" "os" "sync" @@ -36,6 +35,7 @@ import ( "github.com/ossrs/go-oryx-lib/logger" "github.com/ossrs/go-oryx-lib/rtmp" "github.com/pion/interceptor" + "github.com/pkg/errors" ) func TestRtmpPublishPlay(t *testing.T) { @@ -623,7 +623,10 @@ func TestRtmpPublish_HttpFlvPlayNoVideo(t *testing.T) { go func() { defer wg.Done() publisher.onSendPacket = func(m *rtmp.Message) error { - time.Sleep(1 * time.Millisecond) + // Note that must greater than the cost of ffmpeg-opus, which is about 4ms, otherwise, + // the publisher will always get audio frames to transcode and won't accept new players + // connection and finally failed the case. + time.Sleep(5 * time.Millisecond) return nil } if r0 = publisher.Ingest(ctx, *srsPublishAvatar); r0 != nil { diff --git a/trunk/Dockerfile.test b/trunk/Dockerfile.test index 8b0bde656..30222976b 100644 --- a/trunk/Dockerfile.test +++ b/trunk/Dockerfile.test @@ -16,7 +16,8 @@ COPY . /srs WORKDIR /srs/trunk # Note that we must enable the gcc7 or link failed. -RUN ./configure --srt=on --gb28181=on --srt=on --gb28181=on --apm=on --h265=on --utest=on +# Note that we must disable the build-cache, or it will failed, but donot know why. +RUN ./configure --srt=on --gb28181=on --srt=on --apm=on --h265=on --utest=on --ffmpeg-opus=off --build-cache=on RUN make utest ${MAKEARGS} # Build benchmark tool. diff --git a/trunk/auto/options.sh b/trunk/auto/options.sh index 108747bfe..ef879547e 100755 --- a/trunk/auto/options.sh +++ b/trunk/auto/options.sh @@ -37,6 +37,7 @@ SRS_FFMPEG_TOOL=NO # FFmpeg fit is the source code for RTC, to transcode audio or video in SRS. SRS_FFMPEG_FIT=RESERVED # Whether use FFmpeg native opus codec for RTC. If not, use libopus instead. +# Should disable it by default, because the cost of it is very high, see https://github.com/ossrs/srs/pull/3868 SRS_FFMPEG_OPUS=NO # arguments SRS_PREFIX=/usr/local/srs diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index 17a260ac5..39f05fc6d 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -7,6 +7,7 @@ The changelog for SRS. ## SRS 6.0 Changelog +* v6.0, 2023-11-16, Merge [#3868](https://github.com/ossrs/srs/pull/3868): Fix the test fail when enable ffmpeg-opus. v6.0.100 (#3868) * v6.0, 2023-11-15, Merge [#3879](https://github.com/ossrs/srs/pull/3879): Add --extra-ldflags. v6.0.99 (#3879) * v6.0, 2023-11-06, Merge [#3851](https://github.com/ossrs/srs/pull/3851): donot compile libopus when enable sys-ffmpeg. v6.0.98 (#3851) * v6.0, 2023-11-04, Merge [#3852](https://github.com/ossrs/srs/pull/3852): RTC: Refine FFmpeg opus audio noisy issue. v6.0.97 (#3852) diff --git a/trunk/ide/srs_clion/CMakeLists.txt b/trunk/ide/srs_clion/CMakeLists.txt index deb36a5df..3c496eeaa 100755 --- a/trunk/ide/srs_clion/CMakeLists.txt +++ b/trunk/ide/srs_clion/CMakeLists.txt @@ -27,11 +27,11 @@ ProcessorCount(JOBS) # We should always configure SRS for switching between branches. IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") EXECUTE_PROCESS( - COMMAND ./configure --osx --srt=on --gb28181=on --apm=on --h265=on --utest=on --jobs=${JOBS} + COMMAND ./configure --osx --srt=on --gb28181=on --apm=on --h265=on --utest=on --ffmpeg-opus=off --jobs=${JOBS} WORKING_DIRECTORY ${SRS_DIR} RESULT_VARIABLE ret) ELSE () EXECUTE_PROCESS( - COMMAND ./configure --srt=on --gb28181=on --apm=on --h265=on --utest=on --jobs=${JOBS} + COMMAND ./configure --srt=on --gb28181=on --apm=on --h265=on --utest=on --ffmpeg-opus=off --jobs=${JOBS} WORKING_DIRECTORY ${SRS_DIR} RESULT_VARIABLE ret) ENDIF () if(NOT ret EQUAL 0) diff --git a/trunk/src/app/srs_app_rtc_codec.cpp b/trunk/src/app/srs_app_rtc_codec.cpp index bdf1b5312..a73b6f2bc 100644 --- a/trunk/src/app/srs_app_rtc_codec.cpp +++ b/trunk/src/app/srs_app_rtc_codec.cpp @@ -247,6 +247,10 @@ srs_error_t SrsAudioTranscoder::init_enc(SrsAudioCodecId dst_codec, int dst_chan //TODO: for more level setting enc_->compression_level = 1; enc_->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL; + +#ifdef SRS_FFMPEG_OPUS + av_opt_set(enc_->priv_data, "opus_delay", "2.5", 0); +#endif } else if (dst_codec == SrsAudioCodecIdAAC) { enc_->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL; } diff --git a/trunk/src/core/srs_core_version6.hpp b/trunk/src/core/srs_core_version6.hpp index 892842229..9fa9829b3 100644 --- a/trunk/src/core/srs_core_version6.hpp +++ b/trunk/src/core/srs_core_version6.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 6 #define VERSION_MINOR 0 -#define VERSION_REVISION 99 +#define VERSION_REVISION 100 #endif