From b4870a6d6f94ad26c7cc9c7fb39a4246180b5864 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 5 Dec 2019 20:47:23 +0800 Subject: [PATCH] Fix #1506, support directly turn FLV timestamp to TS DTS. 3.0.68 --- README.md | 1 + trunk/conf/full.conf | 9 +++++++++ trunk/src/app/srs_app_config.cpp | 21 ++++++++++++++++++++- trunk/src/app/srs_app_config.hpp | 2 ++ trunk/src/app/srs_app_hls.cpp | 12 ++++++++++++ trunk/src/app/srs_app_hls.hpp | 2 ++ trunk/src/core/srs_core.hpp | 2 +- 7 files changed, 47 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ab986f06a..591b38f90 100755 --- a/README.md +++ b/README.md @@ -145,6 +145,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2019-12-05, Fix [#1506][bug #1501], support directly turn FLV timestamp to TS DTS. 3.0.68 * v3.0, 2019-11-30, [3.0 alpha2(3.0.67)][r3.0a3] released. 110864 lines. * v3.0, 2019-12-01, Fix [#1501][bug #1501], use request coworker for origin cluster. 3.0.67 * v3.0, 2019-11-30, [3.0 alpha2(3.0.66)][r3.0a2] released. 110831 lines. diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index cf3e0217e..57926726c 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -1123,6 +1123,15 @@ vhost hls.srs.com { # @remark It's optional. hls_key_url https://localhost:8080; + # Special control controls. + ########################################### + # Whether calculate the DTS of audio frame directly. + # If on, guess the specific DTS by AAC samples, please read https://github.com/ossrs/srs/issues/547#issuecomment-294350544 + # If off, directly turn the FLV timestamp to DTS, which might cause corrupt audio stream. + # @remark Recommend to set to off, unless your audio stream sample-rate and timestamp is not correct. + # Default: off + hls_dts_directly off; + # on_hls, never config in here, should config in http_hooks. # for the hls http callback, @see http_hooks.on_hls of vhost hooks.callback.srs.com # @read https://github.com/ossrs/srs/wiki/v2_CN_DeliveryHLS#http-callback diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index a0adb9d07..024e296e2 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -2589,6 +2589,8 @@ srs_error_t SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsJsonObject* obj hls->set("hls_dispose", sdir->dumps_arg0_to_number()); } else if (sdir->name == "hls_nb_notify") { hls->set("hls_nb_notify", sdir->dumps_arg0_to_integer()); + } else if (sdir->name == "hls_dts_directly") { + hls->set("hls_dts_directly", sdir->dumps_arg0_to_boolean()); } else if (sdir->name == "hls_wait_keyframe") { hls->set("hls_wait_keyframe", sdir->dumps_arg0_to_boolean()); } else if (sdir->name == "hls_keys") { @@ -3751,7 +3753,7 @@ srs_error_t SrsConfig::check_normal_config() && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec" && m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify" && m != "hls_wait_keyframe" && m != "hls_dispose" && m != "hls_keys" && m != "hls_fragments_per_key" && m != "hls_key_file" - && m != "hls_key_file_path" && m != "hls_key_url") { + && m != "hls_key_file_path" && m != "hls_key_url" && m != "hls_dts_directly") { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.hls.%s of %s", m.c_str(), vhost->arg0().c_str()); } @@ -6148,6 +6150,23 @@ int SrsConfig::get_vhost_hls_nb_notify(string vhost) return ::atoi(conf->arg0().c_str()); } +bool SrsConfig::get_vhost_hls_dts_directly(string vhost) +{ + static bool DEFAULT = false; + + SrsConfDirective* conf = get_hls(vhost); + if (!conf) { + return DEFAULT; + } + + conf = conf->get("hls_dts_directly"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + + return SRS_CONF_PERFER_FALSE(conf->arg0()); +} + bool SrsConfig::get_hls_cleanup(string vhost) { static bool DEFAULT = true; diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 6ff503bb9..426b727ad 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -825,6 +825,8 @@ public: // Get the size of bytes to read from cdn network, for the on_hls_notify callback, // that is, to read max bytes of the bytes from the callback, or timeout or error. virtual int get_vhost_hls_nb_notify(std::string vhost); + // Whether turn the FLV timestamp to TS DTS. + virtual bool get_vhost_hls_dts_directly(std::string vhost); // hds section private: // Get the hds directive of vhost. diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index beb68d18b..ad00dc320 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -1062,6 +1062,7 @@ SrsHls::SrsHls() enabled = false; disposable = false; last_update_time = 0; + hls_dts_directly = false; previous_audio_dts = 0; aac_samples = 0; @@ -1160,6 +1161,11 @@ srs_error_t SrsHls::on_publish() if ((err = controller->on_publish(req)) != srs_success) { return srs_error_wrap(err, "hls: on publish"); } + + // TODO: FIXME: Support reload. + // TODO: FIXME: Support RAW API. + // If enabled, directly turn FLV timestamp to TS DTS. + hls_dts_directly = _srs_config->get_vhost_hls_dts_directly(req->vhost); // if enabled, open the muxer. enabled = true; @@ -1255,6 +1261,12 @@ srs_error_t SrsHls::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* forma // Recalc the DTS by the samples of AAC. aac_samples += nb_samples_per_frame; int64_t dts = 90000 * aac_samples / srs_flv_srates[format->acodec->sound_rate]; + + // If directly turn FLV timestamp, overwrite the guessed DTS. + // @doc https://github.com/ossrs/srs/issues/1506#issuecomment-562063095 + if (hls_dts_directly) { + dts = audio->timestamp * 90; + } if ((err = controller->write_audio(format->audio, dts)) != srs_success) { return srs_error_wrap(err, "hls: write audio"); diff --git a/trunk/src/app/srs_app_hls.hpp b/trunk/src/app/srs_app_hls.hpp index 5d7535f1c..2e6adebe2 100644 --- a/trunk/src/app/srs_app_hls.hpp +++ b/trunk/src/app/srs_app_hls.hpp @@ -288,6 +288,8 @@ private: int64_t previous_audio_dts; // The total aac samples. uint64_t aac_samples; + // Whether directly turn FLV timestamp to TS DTS. + bool hls_dts_directly; private: SrsOriginHub* hub; SrsRtmpJitter* jitter; diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 385fca95c..16ea216a1 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -27,7 +27,7 @@ // The version config. #define VERSION_MAJOR 3 #define VERSION_MINOR 0 -#define VERSION_REVISION 67 +#define VERSION_REVISION 68 // The macros generated by configure script. #include