1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Fix #1506, support directly turn FLV timestamp to TS DTS. 3.0.68

This commit is contained in:
winlin 2019-12-05 20:47:23 +08:00
parent 31f341e205
commit b4870a6d6f
7 changed files with 47 additions and 2 deletions

View file

@ -145,6 +145,7 @@ For previous versions, please read:
## V3 changes ## V3 changes
* v3.0, 2019-12-05, Fix [#1506][bug #1501], support directly turn FLV timestamp to TS DTS. 3.0.68
* <strong>v3.0, 2019-11-30, [3.0 alpha2(3.0.67)][r3.0a3] released. 110864 lines.</strong> * <strong>v3.0, 2019-11-30, [3.0 alpha2(3.0.67)][r3.0a3] released. 110864 lines.</strong>
* v3.0, 2019-12-01, Fix [#1501][bug #1501], use request coworker for origin cluster. 3.0.67 * v3.0, 2019-12-01, Fix [#1501][bug #1501], use request coworker for origin cluster. 3.0.67
* <strong>v3.0, 2019-11-30, [3.0 alpha2(3.0.66)][r3.0a2] released. 110831 lines.</strong> * <strong>v3.0, 2019-11-30, [3.0 alpha2(3.0.66)][r3.0a2] released. 110831 lines.</strong>

View file

@ -1123,6 +1123,15 @@ vhost hls.srs.com {
# @remark It's optional. # @remark It's optional.
hls_key_url https://localhost:8080; 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. # 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 # 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 # @read https://github.com/ossrs/srs/wiki/v2_CN_DeliveryHLS#http-callback

View file

@ -2589,6 +2589,8 @@ srs_error_t SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsJsonObject* obj
hls->set("hls_dispose", sdir->dumps_arg0_to_number()); hls->set("hls_dispose", sdir->dumps_arg0_to_number());
} else if (sdir->name == "hls_nb_notify") { } else if (sdir->name == "hls_nb_notify") {
hls->set("hls_nb_notify", sdir->dumps_arg0_to_integer()); 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") { } else if (sdir->name == "hls_wait_keyframe") {
hls->set("hls_wait_keyframe", sdir->dumps_arg0_to_boolean()); hls->set("hls_wait_keyframe", sdir->dumps_arg0_to_boolean());
} else if (sdir->name == "hls_keys") { } 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_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_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_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()); 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()); 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) bool SrsConfig::get_hls_cleanup(string vhost)
{ {
static bool DEFAULT = true; static bool DEFAULT = true;

View file

@ -825,6 +825,8 @@ public:
// Get the size of bytes to read from cdn network, for the on_hls_notify callback, // 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. // 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); 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 // hds section
private: private:
// Get the hds directive of vhost. // Get the hds directive of vhost.

View file

@ -1062,6 +1062,7 @@ SrsHls::SrsHls()
enabled = false; enabled = false;
disposable = false; disposable = false;
last_update_time = 0; last_update_time = 0;
hls_dts_directly = false;
previous_audio_dts = 0; previous_audio_dts = 0;
aac_samples = 0; aac_samples = 0;
@ -1161,6 +1162,11 @@ srs_error_t SrsHls::on_publish()
return srs_error_wrap(err, "hls: on publish"); 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. // if enabled, open the muxer.
enabled = true; enabled = true;
@ -1256,6 +1262,12 @@ srs_error_t SrsHls::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* forma
aac_samples += nb_samples_per_frame; aac_samples += nb_samples_per_frame;
int64_t dts = 90000 * aac_samples / srs_flv_srates[format->acodec->sound_rate]; 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) { if ((err = controller->write_audio(format->audio, dts)) != srs_success) {
return srs_error_wrap(err, "hls: write audio"); return srs_error_wrap(err, "hls: write audio");
} }

View file

@ -288,6 +288,8 @@ private:
int64_t previous_audio_dts; int64_t previous_audio_dts;
// The total aac samples. // The total aac samples.
uint64_t aac_samples; uint64_t aac_samples;
// Whether directly turn FLV timestamp to TS DTS.
bool hls_dts_directly;
private: private:
SrsOriginHub* hub; SrsOriginHub* hub;
SrsRtmpJitter* jitter; SrsRtmpJitter* jitter;

View file

@ -27,7 +27,7 @@
// The version config. // The version config.
#define VERSION_MAJOR 3 #define VERSION_MAJOR 3
#define VERSION_MINOR 0 #define VERSION_MINOR 0
#define VERSION_REVISION 67 #define VERSION_REVISION 68
// The macros generated by configure script. // The macros generated by configure script.
#include <srs_auto_headers.hpp> #include <srs_auto_headers.hpp>