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

HLS: Fix on_hls and hls_dispose critical zone issue. v5.0.174 v6.0.69 #3781

Merged
merged 5 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .run/srs-stack.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="srs-stack" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="-c containers/conf/srs.release-local.conf" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" WORKING_DIR="file://$USER_HOME$/git/srs-stack/platform" PASS_PARENT_ENVS_2="true" PROJECT_NAME="srs" TARGET_NAME="srs" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="srs" RUN_TARGET_NAME="srs">
<envs>
<env name="SRS_RTC_SERVER_ENABLED" value="on" />
<env name="MallocNanoZone" value="0" />
</envs>
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
</component>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ developers listed below:
[![](https://opencollective.com/srs-server/backers.svg?width=800&button=false)](https://opencollective.com/srs-server)

We at SRS aim to establish a non-profit, open-source community that assists developers worldwide in creating
their own high-quality streaming and RTC platforms to support your businesses.
your own high-quality streaming and RTC platforms to support your businesses.

## AUTHORS

Expand Down
2 changes: 2 additions & 0 deletions trunk/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The changelog for SRS.
<a name="v6-changes"></a>

## SRS 6.0 Changelog
* v6.0, 2023-08-28, Merge [#3781](https://github.com/ossrs/srs/pull/3781): HLS: Fix on_hls and hls_dispose critical zone issue. v6.0.68 (#3781)
* v6.0, 2023-08-28, Merge [#3768](https://github.com/ossrs/srs/pull/3768): Support include empty config file. v6.0.68 (#3768)
* v6.0, 2023-08-25, Merge [#3782](https://github.com/ossrs/srs/pull/3782): HLS: Support reload HLS asynchronously. v6.0.67 (#3782)
* v6.0, 2023-08-22, Merge [#3775](https://github.com/ossrs/srs/pull/3775): Bugfix: Log format output type does not match. v6.0.66 (#3699)
Expand Down Expand Up @@ -80,6 +81,7 @@ The changelog for SRS.
<a name="v5-changes"></a>

## SRS 5.0 Changelog
* v5.0, 2023-08-28, Merge [#3781](https://github.com/ossrs/srs/pull/3781): HLS: Fix on_hls and hls_dispose critical zone issue. v5.0.173 (#3781)
* v5.0, 2023-08-28, Merge [#3768](https://github.com/ossrs/srs/pull/3768): Support include empty config file. v5.0.173 (#3768)
* v5.0, 2023-08-25, Merge [#3782](https://github.com/ossrs/srs/pull/3782): HLS: Support reload HLS asynchronously. v5.0.172 (#3782)
* v5.0, 2023-08-22, Merge [#3775](https://github.com/ossrs/srs/pull/3775): Bugfix: Log format output type does not match. v5.0.171 (#3699)
Expand Down
21 changes: 16 additions & 5 deletions trunk/src/app/srs_app_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,7 @@ SrsHls::SrsHls()

enabled = false;
disposable = false;
unpublishing_ = false;
async_reload_ = reloading_ = false;
last_update_time = 0;
hls_dts_directly = false;
Expand Down Expand Up @@ -1222,7 +1223,7 @@ void SrsHls::dispose()
srs_error_t SrsHls::cycle()
{
srs_error_t err = srs_success;

if (last_update_time <= 0) {
last_update_time = srs_get_system_time();
}
Expand All @@ -1231,6 +1232,9 @@ srs_error_t SrsHls::cycle()
return err;
}

// When unpublishing, we must wait for it done.
if (unpublishing_) return err;

// When reloading, we must wait for it done.
if (async_reload_) return err;

Expand All @@ -1243,12 +1247,12 @@ srs_error_t SrsHls::cycle()
return err;
}
last_update_time = srs_get_system_time();

if (!disposable) {
return err;
}
disposable = false;

srs_trace("hls cycle to dispose hls %s, timeout=%dms", req->get_stream_url().c_str(), hls_dispose);
dispose();

Expand Down Expand Up @@ -1295,6 +1299,8 @@ srs_error_t SrsHls::on_publish()

// if enabled, open the muxer.
enabled = true;
// Reset the unpublishing state.
unpublishing_ = false;

// ok, the hls can be dispose, or need to be dispose.
disposable = true;
Expand All @@ -1310,21 +1316,26 @@ void SrsHls::on_unpublish()
if (!enabled) {
return;
}

// During unpublishing, there maybe callback that switch to other coroutines.
if (unpublishing_) return;
unpublishing_ = true;

if ((err = controller->on_unpublish()) != srs_success) {
srs_warn("hls: ignore unpublish failed %s", srs_error_desc(err).c_str());
srs_freep(err);
}

enabled = false;
unpublishing_ = false;
}

srs_error_t SrsHls::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format)
{
srs_error_t err = srs_success;

// If not able to transmux to HLS, ignore.
if (!enabled) return err;
if (!enabled || unpublishing_) return err;
if (async_reload_) return reload();

// Ignore if no format->acodec, it means the codec is not parsed, or unknown codec.
Expand Down Expand Up @@ -1406,7 +1417,7 @@ srs_error_t SrsHls::on_video(SrsSharedPtrMessage* shared_video, SrsFormat* forma
srs_error_t err = srs_success;

// If not able to transmux to HLS, ignore.
if (!enabled) return err;
if (!enabled || unpublishing_) return err;
if (async_reload_) return reload();

// Ignore if no format->vcodec, it means the codec is not parsed, or unknown codec.
Expand Down
4 changes: 3 additions & 1 deletion trunk/src/app/srs_app_hls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,12 @@ class SrsHls
bool enabled;
// Whether the HLS stream is able to be disposed.
bool disposable;
// Whether the HLS stream is unpublishing.
bool unpublishing_;
// Whether requires HLS to do reload asynchronously.
bool async_reload_;
bool reloading_;
// To detect heartbeat and dipose it if configured.
// To detect heartbeat and dispose it if configured.
srs_utime_t last_update_time;
private:
// If the diff=dts-previous_audio_dts is about 23,
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

#define VERSION_MAJOR 5
#define VERSION_MINOR 0
#define VERSION_REVISION 173
#define VERSION_REVISION 174

#endif
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version6.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

#define VERSION_MAJOR 6
#define VERSION_MINOR 0
#define VERSION_REVISION 68
#define VERSION_REVISION 69

#endif