winlin

refine code, use macro for hls resample audio

@@ -50,10 +50,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -50,10 +50,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
50 #define SRS_CONF_DEFAULT_DVR_PLAN SRS_CONF_DEFAULT_DVR_PLAN_SESSION 50 #define SRS_CONF_DEFAULT_DVR_PLAN SRS_CONF_DEFAULT_DVR_PLAN_SESSION
51 #define SRS_CONF_DEFAULT_DVR_DURATION 30 51 #define SRS_CONF_DEFAULT_DVR_DURATION 30
52 #define SRS_CONF_DEFAULT_TIME_JITTER "full" 52 #define SRS_CONF_DEFAULT_TIME_JITTER "full"
53 -// in ms, for HLS aac sync time.  
54 -#define SRS_CONF_DEFAULT_AAC_SYNC 100  
55 -// in ms, for HLS aac flush the audio  
56 -#define SRS_CONF_DEFAULT_AAC_DELAY 300  
57 // in seconds, the live queue length. 53 // in seconds, the live queue length.
58 #define SRS_CONF_DEFAULT_QUEUE_LENGTH 30 54 #define SRS_CONF_DEFAULT_QUEUE_LENGTH 30
59 // in seconds, the paused queue length. 55 // in seconds, the paused queue length.
@@ -66,6 +66,16 @@ using namespace std; @@ -66,6 +66,16 @@ using namespace std;
66 // ts avc stream id. 66 // ts avc stream id.
67 #define TS_VIDEO_AVC 0xe0 67 #define TS_VIDEO_AVC 0xe0
68 68
  69 +// @see: ngx_rtmp_hls_audio
  70 +/* We assume here AAC frame size is 1024
  71 + * Need to handle AAC frames with frame size of 960 */
  72 +#define _SRS_AAC_SAMPLE_SIZE 1024
  73 +
  74 +// in ms, for HLS aac sync time.
  75 +#define SRS_CONF_DEFAULT_AAC_SYNC 100
  76 +// in ms, for HLS aac flush the audio
  77 +#define SRS_CONF_DEFAULT_AAC_DELAY 300
  78 +
69 // @see: ngx_rtmp_mpegts_header 79 // @see: ngx_rtmp_mpegts_header
70 u_int8_t mpegts_header[] = { 80 u_int8_t mpegts_header[] = {
71 /* TS */ 81 /* TS */
@@ -391,9 +401,10 @@ int64_t SrsHlsAacJitter::on_buffer_start(int64_t flv_pts, int sample_rate, int a @@ -391,9 +401,10 @@ int64_t SrsHlsAacJitter::on_buffer_start(int64_t flv_pts, int sample_rate, int a
391 } 401 }
392 402
393 // @see: ngx_rtmp_hls_audio 403 // @see: ngx_rtmp_hls_audio
394 - /* TODO: We assume here AAC frame size is 1024  
395 - * Need to handle AAC frames with frame size of 960 */  
396 - int64_t est_pts = base_pts + nb_samples * 90000LL * 1024LL / flv_sample_rate; 404 + // resample for the tbn of ts is 90000, flv is 1000,
  405 + // we will lost timestamp if use audio packet timestamp,
  406 + // so we must resample. or audio will corupt in IOS.
  407 + int64_t est_pts = base_pts + nb_samples * 90000LL * _SRS_AAC_SAMPLE_SIZE / flv_sample_rate;
397 int64_t dpts = (int64_t) (est_pts - flv_pts); 408 int64_t dpts = (int64_t) (est_pts - flv_pts);
398 409
399 if (dpts <= (int64_t) sync_ms * 90 && dpts >= (int64_t) sync_ms * -90) { 410 if (dpts <= (int64_t) sync_ms * 90 && dpts >= (int64_t) sync_ms * -90) {