From 921b7d239f29f23ed11c5853497543846945309a Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 5 Jul 2014 23:43:28 +0800 Subject: [PATCH] refine code, use macro for hls resample audio --- trunk/src/app/srs_app_config.hpp | 4 ---- trunk/src/app/srs_app_hls.cpp | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index d4c532459..54191b072 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -50,10 +50,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define SRS_CONF_DEFAULT_DVR_PLAN SRS_CONF_DEFAULT_DVR_PLAN_SESSION #define SRS_CONF_DEFAULT_DVR_DURATION 30 #define SRS_CONF_DEFAULT_TIME_JITTER "full" -// in ms, for HLS aac sync time. -#define SRS_CONF_DEFAULT_AAC_SYNC 100 -// in ms, for HLS aac flush the audio -#define SRS_CONF_DEFAULT_AAC_DELAY 300 // in seconds, the live queue length. #define SRS_CONF_DEFAULT_QUEUE_LENGTH 30 // in seconds, the paused queue length. diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index 5eae3e8e8..667999fa5 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -66,6 +66,16 @@ using namespace std; // ts avc stream id. #define TS_VIDEO_AVC 0xe0 +// @see: ngx_rtmp_hls_audio +/* We assume here AAC frame size is 1024 + * Need to handle AAC frames with frame size of 960 */ +#define _SRS_AAC_SAMPLE_SIZE 1024 + +// in ms, for HLS aac sync time. +#define SRS_CONF_DEFAULT_AAC_SYNC 100 +// in ms, for HLS aac flush the audio +#define SRS_CONF_DEFAULT_AAC_DELAY 300 + // @see: ngx_rtmp_mpegts_header u_int8_t mpegts_header[] = { /* TS */ @@ -391,9 +401,10 @@ int64_t SrsHlsAacJitter::on_buffer_start(int64_t flv_pts, int sample_rate, int a } // @see: ngx_rtmp_hls_audio - /* TODO: We assume here AAC frame size is 1024 - * Need to handle AAC frames with frame size of 960 */ - int64_t est_pts = base_pts + nb_samples * 90000LL * 1024LL / flv_sample_rate; + // resample for the tbn of ts is 90000, flv is 1000, + // we will lost timestamp if use audio packet timestamp, + // so we must resample. or audio will corupt in IOS. + int64_t est_pts = base_pts + nb_samples * 90000LL * _SRS_AAC_SAMPLE_SIZE / flv_sample_rate; int64_t dpts = (int64_t) (est_pts - flv_pts); if (dpts <= (int64_t) sync_ms * 90 && dpts >= (int64_t) sync_ms * -90) {