-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
RTC: fix play rtc judge for config rtc2rtmp on.(#2863) #2872
Conversation
6fabe91
to
5c2bed1
Compare
trunk/src/app/srs_app_rtc_api.cpp
Outdated
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)) { |
There was a problem hiding this comment.
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:
- Configure
rtmp2rtc off; rtc2rtmp on;
, which means not enabling RTMP to RTC conversion, but enabling RTC to RTMP conversion. - Push RTMP stream, but do not push RTC stream.
- 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.
- Configure as
rtmp2rtc off
, which means not enabling stream conversion. - 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
There was a problem hiding this comment.
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
67050f3
to
990a1a9
Compare
trunk/src/app/srs_app_rtc_api.cpp
Outdated
@@ -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()); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
990a1a9
to
a7da5a3
Compare
a7da5a3
to
5fe69d0
Compare
Codecov Report
@@ 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 Δ | | ' Translated to English while maintaining the markdown structure: '| trunk/src/app/srs_app_rtc_api.cpp | Continue to review full report at Codecov.
Translated to English while maintaining the markdown structure: '>
|
Configuration1
Configuration2
Configuration3
Configuration4