Skip to content

Commit

Permalink
Fix #1506, support directly turn FLV timestamp to TS DTS. 3.0.68
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Dec 5, 2019
1 parent 31f341e commit b4870a6
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <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
* <strong>v3.0, 2019-11-30, [3.0 alpha2(3.0.66)][r3.0a2] released. 110831 lines.</strong>
Expand Down
9 changes: 9 additions & 0 deletions trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,8 @@ class SrsConfig
// 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.
Expand Down
12 changes: 12 additions & 0 deletions trunk/src/app/srs_app_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/app/srs_app_hls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ class SrsHls
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;
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <srs_auto_headers.hpp>
Expand Down

1 comment on commit b4870a6

@winlinvip
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For #1506

Please sign in to comment.