Skip to content

Commit

Permalink
Fix #547, support HLS audio in TS. 3.0.22
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Apr 16, 2017
1 parent 6ee85ae commit a98c9e0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Please select your language:
- [x] [experiment] Support push POST FLV over HTTP, please read [wiki]([CN][v2_CN_Streamer2], [EN][v2_EN_Streamer2]).
- [x] [experiment] Support multiple processes by [dolphin][srs-dolphin] or [oryx][oryx].
- [x] [experiment] Support [mgmt console][console], please read [srs-ngb][srs-ngb].
- [ ] Enhanced HLS audio-only use aac instead of ts.
- [x] Enhanced HLS audio-only use ts, see [#547][bug #547].
- [ ] Enhanced forward with vhost and url variables.
- [ ] Support source or idle stream cleanup.
- [ ] Support origin cluster, please read [#464][bug #464], [RTMP 302][bug #92].
Expand All @@ -186,6 +186,7 @@ Please select your language:

### V3 changes

* v3.0, 2017-04-16, Fix [#547][bug #547], support HLS audio in TS. 3.0.22
* v3.0, 2017-03-26, Fix [#820][bug #820], extract service for modules. 3.0.21
* v3.0, 2017-03-02, Fix [#786][bug #786], simply don't reuse object. 3.0.20
* v3.0, 2017-03-01, For [#110][bug #110], refine thread object. 3.0.19
Expand Down Expand Up @@ -1400,6 +1401,7 @@ Winlin
[bug #738]: https://github.com/ossrs/srs/issues/738
[bug #786]: https://github.com/ossrs/srs/issues/786
[bug #820]: https://github.com/ossrs/srs/issues/820
[bug #547]: https://github.com/ossrs/srs/issues/547
[bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx

[exo #828]: https://github.com/google/ExoPlayer/pull/828
Expand Down
21 changes: 19 additions & 2 deletions trunk/src/app/srs_app_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions trunk/src/app/srs_app_hls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ class SrsHls
bool enabled;
bool disposable;
int64_t last_update_time;
private:
// If the diff=dts-previous_audio_dts is about 23,
// that's the AAC samples is 1024, and we use the samples to calc the dts.
int64_t previous_audio_dts;
// The total aac samples.
uint64_t aac_samples;
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 @@
// current release version
#define VERSION_MAJOR 3
#define VERSION_MINOR 0
#define VERSION_REVISION 21
#define VERSION_REVISION 22

// generated by configure, only macros.
#include <srs_auto_headers.hpp>
Expand Down
1 change: 1 addition & 0 deletions trunk/src/kernel/srs_kernel_codec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ enum SrsAudioAacFrameTrait
* 2 = 22 kHz = 22050 Hz
* 3 = 44 kHz = 44100 Hz
* However, we can extends this table.
* @remark Use srs_flv_srates to convert it.
*/
enum SrsAudioSampleRate
{
Expand Down

0 comments on commit a98c9e0

Please sign in to comment.