Skip to content

Commit

Permalink
Merge develop.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Aug 28, 2023
2 parents a302a86 + cf46dae commit 5871bfc
Show file tree
Hide file tree
Showing 13 changed files with 231 additions and 77 deletions.
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[![](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fossrs%2Fsrs.svg?type=small)](https://app.fossa.com/projects/git%2Bgithub.com%2Fossrs%2Fsrs?ref=badge_small)
[![](https://ossrs.net/wiki/images/srs-faq.svg)](https://ossrs.net/lts/zh-cn/faq)
[![](https://badgen.net/badge/srs/stackoverflow/orange?icon=terminal)](https://stackoverflow.com/questions/tagged/simple-realtime-server)
[![](https://opencollective.com/srs-server/tiers/badge.svg)](https://opencollective.com/srs-server/contribute)
[![](https://opencollective.com/srs-server/tiers/badge.svg)](https://opencollective.com/srs-server)
[![](https://img.shields.io/docker/pulls/ossrs/srs)](https://hub.docker.com/r/ossrs/srs/tags)
[![](https://ossrs.net/wiki/images/do-btn-srs-125x20.svg)](https://cloud.digitalocean.com/droplets/new?appId=133468816&size=s-1vcpu-512mb-10gb&region=sgp1&image=ossrs-srs&type=applications)
[![](https://api.securityscorecards.dev/projects/github.com/ossrs/srs/badge)](https://api.securityscorecards.dev/projects/github.com/ossrs/srs)
Expand Down Expand Up @@ -104,15 +104,24 @@ Here are some other important wikis:
* Usage: What are the strategies for improving edge performance on multiple CPUs? ([CN](https://ossrs.net/lts/zh-cn/docs/v5/doc/reuse-port), [EN](https://ossrs.io/lts/en-us/docs/v5/doc/reuse-port))
* Usage: How can bugs be reported or contact be made with us? ([CN](https://ossrs.net/lts/zh-cn/contact), [EN](https://ossrs.io/lts/en-us/contact))

## AUTHORS
## Sponsor

Would you like additional assistance from us? By becoming a sponsor or backer of SRS, we can provide you
with the support you need:

* Backer: $5 per month, online text chat support through Discord.
* Sponsor: $100 per month, online meeting support, 1 meeting per month in 1 hour.

We highly appreciate all our contributors for their significant contributions that have made a remarkable difference.
Thank you! 🙏
Please visit [OpenCollective](https://opencollective.com/srs-server) to become a backer or sponsor, and send
us a direct message on [Discord](https://discord.gg/yZ4BnPmHAd). We are currently providing support to the
developers listed below:

If you wish to support this project financially, you can donate [through Open Collective](https://opencollective.com/srs-server).
We appreciate your contribution!
[![](https://opencollective.com/srs-server/backers.svg?width=800&button=false)](https://opencollective.com/srs-server)

[![](https://opencollective.com/srs-server/backers.svg?width=800&button=true)](https://opencollective.com/srs-server/contribute/backer-34941/checkout?interval=month&amount=5)
We at SRS aim to establish a non-profit, open-source community that assists developers worldwide in creating
your own high-quality streaming and RTC platforms to support your businesses.

## AUTHORS

The [TOC(Technical Oversight Committee)](trunk/AUTHORS.md#toc) and [contributors](trunk/AUTHORS.md#contributors):

Expand Down
2 changes: 1 addition & 1 deletion trunk/configure
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ fi
if [[ $SRS_UTEST == YES ]]; then
MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_kernel" "srs_utest_core"
"srs_utest_config" "srs_utest_rtmp" "srs_utest_http" "srs_utest_avc" "srs_utest_reload"
"srs_utest_mp4" "srs_utest_service" "srs_utest_app" "srs_utest_rtc"
"srs_utest_mp4" "srs_utest_service" "srs_utest_app" "srs_utest_rtc" "srs_utest_config2"
"srs_utest_protocol" "srs_utest_protocol2" "srs_utest_kernel2")
if [[ $SRS_SRT == YES ]]; then
MODULE_FILES+=("srs_utest_srt")
Expand Down
4 changes: 4 additions & 0 deletions trunk/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ The changelog for SRS.
<a name="v6-changes"></a>

## SRS 6.0 Changelog
* 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)
* v6.0, 2023-08-02, Merge [#3750](https://github.com/ossrs/srs/pull/3750): HLS: Ignore empty NALU to avoid error. v6.0.64 (#3750)
* v6.0, 2023-07-27, Merge [#3611](https://github.com/ossrs/srs/pull/3611): Design and implement helm capabilities to streamline the deployment process of an SRS cluster.. v6.0.63 (#3611)
Expand Down Expand Up @@ -78,6 +80,8 @@ The changelog for SRS.
<a name="v5-changes"></a>

## SRS 5.0 Changelog
* 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)
* v5.0, 2023-08-02, HLS: Ignore empty NALU to avoid error. v5.0.170
* v5.0, 2023-07-26, Merge [#3699](https://github.com/ossrs/srs/pull/3699): Bugfix: Eliminate the redundant declaration of the _srs_rtc_manager variable. v5.0.168 (#3699)
Expand Down
11 changes: 8 additions & 3 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ namespace srs_internal

// read all.
int filesize = (int)reader.filesize();
// Ignore if empty file.
if (filesize <= 0) return err;

// create buffer
srs_freepa(start);
Expand Down Expand Up @@ -1068,6 +1070,9 @@ SrsJsonAny* SrsConfDirective::dumps_arg0_to_boolean()
srs_error_t SrsConfDirective::parse_conf(SrsConfigBuffer* buffer, SrsDirectiveContext ctx, SrsConfig* conf)
{
srs_error_t err = srs_success;

// Ignore empty config file.
if (ctx == SrsDirectiveContextFile && buffer->empty()) return err;

while (true) {
std::vector<string> args;
Expand Down Expand Up @@ -1127,7 +1132,7 @@ srs_error_t SrsConfDirective::parse_conf(SrsConfigBuffer* buffer, SrsDirectiveCo
}

if ((err = parse_conf(include_file_buffer, SrsDirectiveContextFile, conf)) != srs_success) {
return srs_error_wrap(err, "parse include buffer");
return srs_error_wrap(err, "parse include buffer %s", file.c_str());
}
}
}
Expand Down Expand Up @@ -2197,11 +2202,11 @@ srs_error_t SrsConfig::parse_file(const char* filename)
SrsConfigBuffer* buffer = NULL;
SrsAutoFree(SrsConfigBuffer, buffer);
if ((err = build_buffer(config_file, &buffer)) != srs_success) {
return srs_error_wrap(err, "buffer fullfill %s", config_file.c_str());
return srs_error_wrap(err, "buffer fullfill %s", filename);
}

if ((err = parse_buffer(buffer)) != srs_success) {
return srs_error_wrap(err, "parse buffer");
return srs_error_wrap(err, "parse buffer %s", filename);
}

return err;
Expand Down
68 changes: 60 additions & 8 deletions trunk/src/app/srs_app_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,7 @@ SrsHls::SrsHls()
enabled = false;
disposable = false;
unpublishing_ = false;
async_reload_ = reloading_ = false;
last_update_time = 0;
hls_dts_directly = false;

Expand All @@ -1156,6 +1157,53 @@ SrsHls::~SrsHls()
srs_freep(pprint);
}

void SrsHls::async_reload()
{
async_reload_ = true;
}

srs_error_t SrsHls::reload()
{
srs_error_t err = srs_success;

// Ignore if not active.
if (!enabled) return err;

int reloading = 0, reloaded = 0, refreshed = 0;
err = do_reload(&reloading, &reloaded, &refreshed);
srs_trace("async reload hls %s, reloading=%d, reloaded=%d, refreshed=%d",
req->get_stream_url().c_str(), reloading, reloaded, refreshed);

return err;
}

srs_error_t SrsHls::do_reload(int *reloading, int *reloaded, int *refreshed)
{
srs_error_t err = srs_success;

if (!async_reload_ || reloading_) return err;
reloading_ = true;
*reloading = 1;

on_unpublish();
if ((err = on_publish()) != srs_success) {
return srs_error_wrap(err, "hls publish failed");
}
*reloaded = 1;

// Before feed the sequence header, must reset the reloading.
reloading_ = false;
async_reload_ = false;

// After reloading, we must request the sequence header again.
if ((err = hub->on_hls_request_sh()) != srs_success) {
return srs_error_wrap(err, "hls request sh");
}
*refreshed = 1;

return err;
}

void SrsHls::dispose()
{
if (enabled) {
Expand Down Expand Up @@ -1187,6 +1235,10 @@ srs_error_t SrsHls::cycle()
// 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;

// If not unpublishing and not reloading, try to dispose HLS stream.
srs_utime_t hls_dispose = _srs_config->get_hls_dispose(req->vhost);
if (hls_dispose <= 0) {
return err;
Expand Down Expand Up @@ -1281,10 +1333,10 @@ void SrsHls::on_unpublish()
srs_error_t SrsHls::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format)
{
srs_error_t err = srs_success;
if (!enabled) {
return err;
}

// If not able to transmux to HLS, ignore.
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.
// @issue https://github.com/ossrs/srs/issues/1506#issuecomment-562079474
Expand Down Expand Up @@ -1363,10 +1415,10 @@ srs_error_t SrsHls::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* forma
srs_error_t SrsHls::on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format)
{
srs_error_t err = srs_success;
if (!enabled) {
return err;
}

// If not able to transmux to HLS, ignore.
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.
// @issue https://github.com/ossrs/srs/issues/1506#issuecomment-562079474
Expand Down
12 changes: 12 additions & 0 deletions trunk/src/app/srs_app_hls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,16 @@ class SrsHls
SrsHlsController* controller;
private:
SrsRequest* req;
// Whether the HLS is enabled.
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 dispose it if configured.
srs_utime_t last_update_time;
private:
// If the diff=dts-previous_audio_dts is about 23,
Expand All @@ -294,6 +301,11 @@ class SrsHls
public:
SrsHls();
virtual ~SrsHls();
public:
virtual void async_reload();
private:
srs_error_t reload();
srs_error_t do_reload(int *reloading, int *reloaded, int *refreshed);
public:
virtual void dispose();
virtual srs_error_t cycle();
Expand Down
84 changes: 34 additions & 50 deletions trunk/src/app/srs_app_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,27 @@ srs_error_t SrsOriginHub::on_dvr_request_sh()
return err;
}

srs_error_t SrsOriginHub::on_hls_request_sh()
{
srs_error_t err = srs_success;

SrsSharedPtrMessage* cache_sh_video = source->meta->vsh();
if (cache_sh_video) {
if ((err = hls->on_video(cache_sh_video, source->meta->vsh_format())) != srs_success) {
return srs_error_wrap(err, "hls video");
}
}

SrsSharedPtrMessage* cache_sh_audio = source->meta->ash();
if (cache_sh_audio) {
if ((err = hls->on_audio(cache_sh_audio, source->meta->ash_format())) != srs_success) {
return srs_error_wrap(err, "hls audio");
}
}

return err;
}

srs_error_t SrsOriginHub::on_reload_vhost_forward(string vhost)
{
srs_error_t err = srs_success;
Expand All @@ -1236,7 +1257,7 @@ srs_error_t SrsOriginHub::on_reload_vhost_forward(string vhost)
return err;
}

// TODO: FIXME: maybe should ignore when publish already stopped?
// TODO: FIXME: Must do async reload, see SrsHls::async_reload.

// forwarders
destroy_forwarders();
Expand All @@ -1262,7 +1283,9 @@ srs_error_t SrsOriginHub::on_reload_vhost_dash(string vhost)
if (req_->vhost != vhost) {
return err;
}


// TODO: FIXME: Must do async reload, see SrsHls::async_reload.

dash->on_unpublish();

// Don't start DASH when source is not active.
Expand Down Expand Up @@ -1306,47 +1329,8 @@ srs_error_t SrsOriginHub::on_reload_vhost_hls(string vhost)
if (req_->vhost != vhost) {
return err;
}

// TODO: FIXME: maybe should ignore when publish already stopped?

hls->on_unpublish();

// Don't start HLS when source is not active.
if (!is_active) {
return err;
}

if ((err = hls->on_publish()) != srs_success) {
return srs_error_wrap(err, "hls publish failed");
}
srs_trace("vhost %s hls reload success", vhost.c_str());

SrsRtmpFormat* format = source->format_;

// when publish, don't need to fetch sequence header, which is old and maybe corrupt.
// when reload, we must fetch the sequence header from source cache.
// notice the source to get the cached sequence header.
// when reload to start hls, hls will never get the sequence header in stream,
// use the SrsLiveSource.on_hls_start to push the sequence header to HLS.
SrsSharedPtrMessage* cache_sh_video = source->meta->vsh();
if (cache_sh_video) {
if ((err = format->on_video(cache_sh_video)) != srs_success) {
return srs_error_wrap(err, "format on_video");
}
if ((err = hls->on_video(cache_sh_video, format)) != srs_success) {
return srs_error_wrap(err, "hls on_video");
}
}

SrsSharedPtrMessage* cache_sh_audio = source->meta->ash();
if (cache_sh_audio) {
if ((err = format->on_audio(cache_sh_audio)) != srs_success) {
return srs_error_wrap(err, "format on_audio");
}
if ((err = hls->on_audio(cache_sh_audio, format)) != srs_success) {
return srs_error_wrap(err, "hls on_audio");
}
}
hls->async_reload();

return err;
}
Expand All @@ -1358,8 +1342,8 @@ srs_error_t SrsOriginHub::on_reload_vhost_hds(string vhost)
if (req_->vhost != vhost) {
return err;
}
// TODO: FIXME: maybe should ignore when publish already stopped?

// TODO: FIXME: Must do async reload, see SrsHls::async_reload.

#ifdef SRS_HDS
hds->on_unpublish();
Expand All @@ -1385,8 +1369,8 @@ srs_error_t SrsOriginHub::on_reload_vhost_dvr(string vhost)
if (req_->vhost != vhost) {
return err;
}
// TODO: FIXME: maybe should ignore when publish already stopped?

// TODO: FIXME: Must do async reload, see SrsHls::async_reload.

// cleanup dvr
dvr->on_unpublish();
Expand Down Expand Up @@ -1422,8 +1406,8 @@ srs_error_t SrsOriginHub::on_reload_vhost_transcode(string vhost)
if (req_->vhost != vhost) {
return err;
}
// TODO: FIXME: maybe should ignore when publish already stopped?

// TODO: FIXME: Must do async reload, see SrsHls::async_reload.

encoder->on_unpublish();

Expand All @@ -1447,8 +1431,8 @@ srs_error_t SrsOriginHub::on_reload_vhost_exec(string vhost)
if (req_->vhost != vhost) {
return err;
}
// TODO: FIXME: maybe should ignore when publish already stopped?

// TODO: FIXME: Must do async reload, see SrsHls::async_reload.

ng_exec->on_unpublish();

Expand Down
2 changes: 2 additions & 0 deletions trunk/src/app/srs_app_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ class SrsOriginHub : public ISrsReloadHandler
virtual srs_error_t on_forwarder_start(SrsForwarder* forwarder);
// For the SrsDvr to callback to request the sequence headers.
virtual srs_error_t on_dvr_request_sh();
// For the SrsHls to callback to request the sequence headers.
virtual srs_error_t on_hls_request_sh();
// Interface ISrsReloadHandler
public:
virtual srs_error_t on_reload_vhost_forward(std::string vhost);
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 171
#define VERSION_REVISION 173

#endif
Loading

0 comments on commit 5871bfc

Please sign in to comment.