Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTC: fix play rtc judge for config rtc2rtmp on.(#2863) #2872

Merged

Conversation

chundonglinlin
Copy link
Member

@chundonglinlin chundonglinlin commented Jan 11, 2022

Configuration1

vhost __defaultVhost__ {
    rtc {
        enabled     on;
        rtmp_to_rtc off;
        rtc_to_rtmp off;
    }
}

Step1: Rtmp Publish: ffmpeg -re -i 264_aac.flv -c copy -f flv rtmp://127.0.0.1/live/livestream
Step2: Rtmp stream can play: ffplay rtmp://localhost/live/livestream
Step3: Rtc stream can't play(reject tips): ./objs/srs_bench -sr webrtc://localhost/live/livestream

Step1: RTC Publish: ./objs/srs_bench -pr webrtc://localhost/live/livestream -sa avatar.ogg -sv avatar.h264 -fps 25
Step2: Rtmp stream can't play: ffplay rtmp://localhost/live/livestream
Step3: Rtc stream can play: ./objs/srs_bench -sr webrtc://localhost/live/livestream

Configuration2

vhost __defaultVhost__ {
    rtc {
        enabled     on;
        rtmp_to_rtc off;
        rtc_to_rtmp on;
    }
}

Step1: Rtmp Publish: ffmpeg -re -i 264_aac.flv -c copy -f flv rtmp://127.0.0.1/live/livestream
Step2: Rtmp stream can play: ffplay rtmp://localhost/live/livestream
Step3: Rtc stream can't play(reject tips): ./objs/srs_bench -sr webrtc://localhost/live/livestream

Step1: RTC Publish: ./objs/srs_bench -pr webrtc://localhost/live/livestream -sa avatar.ogg -sv avatar.h264 -fps 25
Step2: Rtmp stream can play: ffplay rtmp://localhost/live/livestream
Step3: Rtc stream can play: ./objs/srs_bench -sr webrtc://localhost/live/livestream

Configuration3

vhost __defaultVhost__ {
    rtc {
        enabled     on;
        rtmp_to_rtc on;
        rtc_to_rtmp off;
    }
}

Step1: Rtmp Publish: ffmpeg -re -i 264_aac.flv -c copy -f flv rtmp://127.0.0.1/live/livestream
Step2: Rtmp stream can play: ffplay rtmp://localhost/live/livestream
Step3: Rtc stream can play: ./objs/srs_bench -sr webrtc://localhost/live/livestream

Step1: RTC Publish: ./objs/srs_bench -pr webrtc://localhost/live/livestream -sa avatar.ogg -sv avatar.h264 -fps 25
Step2: Rtmp stream can't play: ffplay rtmp://localhost/live/livestream
Step3: Rtc stream can play: ./objs/srs_bench -sr webrtc://localhost/live/livestream

Configuration4

vhost __defaultVhost__ {
    rtc {
        enabled     on;
        rtmp_to_rtc on;
        rtc_to_rtmp on;
    }
}

Step1: Rtmp Publish: ffmpeg -re -i 264_aac.flv -c copy -f flv rtmp://127.0.0.1/live/livestream
Step2: Rtmp stream can play: ffplay rtmp://localhost/live/livestream
Step3: Rtc stream can play: ./objs/srs_bench -sr webrtc://localhost/live/livestream

Step1: RTC Publish: ./objs/srs_bench -pr webrtc://localhost/live/livestream -sa avatar.ogg -sv avatar.h264 -fps 25
Step2: Rtmp stream can play: ffplay rtmp://localhost/live/livestream
Step3: Rtc stream can play: ./objs/srs_bench -sr webrtc://localhost/live/livestream

if (rtmp && !rtmp->inactive()) {
return srs_error_new(ERROR_RTC_DISABLED, "Disabled rtmp_to_rtc of %s, see #2728", ruc.req_->vhost.c_str());
// FIX ERR: when config is { rtmp_to_rtc off; rtc_to_rtmp on; }, playing rtc will be rejected if publishing rtc stream.
if (!_srs_config->get_rtc_to_rtmp(ruc.req_->vhost)) {
Copy link
Member

@winlinvip winlinvip Jan 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This place is not just about checking the configuration, this logic is incorrect. For example, there will still be issues in the following situation:

  1. Configure rtmp2rtc off; rtc2rtmp on;, which means not enabling RTMP to RTC conversion, but enabling RTC to RTMP conversion.
  2. Push RTMP stream, but do not push RTC stream.
  3. Play RTC stream, here it will display a black screen instead of prompting a configuration error.

The core issue here is how to detect this type of error.

  1. Configure as rtmp2rtc off, which means not enabling stream conversion.
  2. Push RTMP stream and play RTC stream. At this point, there won't be any RTC stream (no RTC stream pushed, no RTMP to RTC stream conversion). It must fail at this point, otherwise, further investigation is required to determine why there is a black screen.

The issue with the original logic is not caused by the configuration, but rather due to overlooking a special case: "If there is an RTC stream, there is no need to check the rtmp2rtc switch." Because if there is an RTC stream, it means there is already an RTC stream available, so there is no need to worry about any switches. The RTC stream should be playable in this case.

If there is an RTC stream, it doesn't mean that enabling rtc2rtmp implies the presence of an RTC stream. Instead, it should directly check whether there is an RTC stream being pushed and obtain the stream status from the RTC source.

It should be changed to this:

'It should be changed to this:

bool is_rtc_stream_active = xxx; // Check if RTC has a stream
if (!is_rtc_stream_active && !_srs_config->get_rtc_from_rtmp(ruc.req_->vhost)) {
// Check if there is an RTMP stream and rtmp2rtc is disabled, in this case an error should be reported, the current logic is correct.

TRANS_BY_GPT3

Copy link
Member Author

@chundonglinlin chundonglinlin Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added RtcStream acquisition, only if the stream does not exist will it check the rtmp2rtc switch and print tips.

TRANS_BY_GPT3

@winlinvip winlinvip self-assigned this Jan 12, 2022
@chundonglinlin chundonglinlin force-pushed the bugfix/play_rtc_judge_error branch 2 times, most recently from 67050f3 to 990a1a9 Compare January 12, 2022 09:52
@@ -187,7 +187,9 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe
}

// For RTMP to RTC, fail if disabled and RTMP is active, see https://github.com/ossrs/srs/issues/2728
if (!_srs_config->get_rtc_from_rtmp(ruc.req_->vhost)) {
SrsRtcSource* source = _srs_rtc_sources->fetch(ruc.req_);
bool is_rtc_stream_active = (source && !source->can_publish());
Copy link
Member

@winlinvip winlinvip Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This place exposes a source object, but in reality, it is only used to generate the value of is_rtc_stream_active. Therefore, the source variable should be hidden to prevent others from misusing it.

// Whether RTC stream is active.
bool is_rtc_stream_active = false;
if (true) {
  SrsRtcSource* source = _srs_rtc_sources->fetch(ruc.req_);
  is_rtc_stream_active = (source && !source->can_publish());
}

// For RTMP to RTC, fail if disabled and RTMP is active, see https://github.com/ossrs/srs/issues/2728
if (!is_rtc_stream_active && !_srs_config->get_rtc_from_rtmp(ruc.req_->vhost)) {

Although it increases the number of lines of code, it hides unused variables, so others don't need to understand the code inside because it simply generates this flag. It is very worthwhile.

PS: Pay attention to comments and paragraphs.

TRANS_BY_GPT3

Copy link
Member Author

@chundonglinlin chundonglinlin Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, it has been modified. Finally understood the if (true) {} syntax of srs.

TRANS_BY_GPT3

@codecov-commenter
Copy link

codecov-commenter commented Jan 13, 2022

Codecov Report

Merging #2872 (5fe69d0) into 4.0release (c6c2e97) will decrease coverage by 0.00%.
The diff coverage is 0.00%.

Impacted file tree graph

@@              Coverage Diff               @@
##           4.0release    #2872      +/-   ##
==============================================
- Coverage       60.22%   60.21%   -0.01%     
==============================================
  Files             121      121              
  Lines           51070    51073       +3     
==============================================
  Hits            30756    30756              
- Misses          20314    20317       +3     

| Impacted Files | Coverage Δ | |'

Translated to English while maintaining the markdown structure:

'| Impacted Files | Coverage Δ | |
|---|---|---|
| trunk/src/app/srs_app_rtc_api.cpp | 0.00% <0.00%> (ø) | |
| trunk/src/app/srs_app_rtc_source.hpp | 9.09% <ø> (ø) | |

'

Translated to English while maintaining the markdown structure:

'| trunk/src/app/srs_app_rtc_api.cpp | 0.00% <0.00%> (ø) | |
| trunk/src/app/srs_app_rtc_source.hpp | 9.09% <ø> (ø) | |


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data'

Translated to English while maintaining the markdown structure:

'> Δ = absolute <relative> (impact), ø = not affected, ? = missing data

Powered by Codecov. Last update c6c2e97...5fe69d0. Read the comment docs.

TRANS_BY_GPT3

@winlinvip winlinvip merged commit 5848897 into ossrs:4.0release Jan 13, 2022
@winlinvip winlinvip added the TransByAI Translated by AI/GPT. label Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TransByAI Translated by AI/GPT.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants