mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Fix #547, support HLS audio in TS. 3.0.22
This commit is contained in:
parent
6ee85aea83
commit
a98c9e04e3
5 changed files with 30 additions and 4 deletions
|
@ -969,6 +969,9 @@ SrsHls::SrsHls()
|
|||
disposable = false;
|
||||
last_update_time = 0;
|
||||
|
||||
previous_audio_dts = 0;
|
||||
aac_samples = 0;
|
||||
|
||||
jitter = new SrsRtmpJitter();
|
||||
controller = new SrsHlsController();
|
||||
|
||||
|
@ -1115,8 +1118,22 @@ int SrsHls::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format)
|
|||
return ret;
|
||||
}
|
||||
|
||||
// the dts calc from rtmp/flv header.
|
||||
int64_t dts = audio->timestamp * 90;
|
||||
// Reset the aac samples counter when DTS jitter.
|
||||
if (previous_audio_dts > audio->timestamp) {
|
||||
previous_audio_dts = audio->timestamp;
|
||||
aac_samples = 0;
|
||||
}
|
||||
|
||||
// Use the diff to guess whether the samples is 1024 or 960.
|
||||
int nb_samples_per_frame = 1024;
|
||||
int diff = ::abs((int)(audio->timestamp - previous_audio_dts)) * srs_flv_srates[format->acodec->sound_rate];
|
||||
if (diff > 100 && diff < 950) {
|
||||
nb_samples_per_frame = 960;
|
||||
}
|
||||
|
||||
// Recalc the DTS by the samples of AAC.
|
||||
int64_t dts = 90000 * aac_samples / srs_flv_srates[format->acodec->sound_rate];
|
||||
aac_samples += nb_samples_per_frame;
|
||||
|
||||
if ((ret = controller->write_audio(format->audio, dts)) != ERROR_SUCCESS) {
|
||||
srs_error("hls cache write audio failed. ret=%d", ret);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue