@@ -60,6 +60,13 @@ static ngx_command_t ngx_rtmp_live_commands[] = {
6060 offsetof(ngx_rtmp_live_app_conf_t , sync ),
6161 NULL },
6262
63+ { ngx_string ("atc" ),
64+ NGX_RTMP_MAIN_CONF |NGX_RTMP_SRV_CONF |NGX_RTMP_APP_CONF |NGX_CONF_TAKE1 ,
65+ ngx_conf_set_flag_slot ,
66+ NGX_RTMP_APP_CONF_OFFSET ,
67+ offsetof(ngx_rtmp_live_app_conf_t , atc ),
68+ NULL },
69+
6370 ngx_null_command
6471};
6572
@@ -107,6 +114,7 @@ ngx_rtmp_live_create_app_conf(ngx_conf_t *cf)
107114 lacf -> nbuckets = NGX_CONF_UNSET ;
108115 lacf -> buflen = NGX_CONF_UNSET ;
109116 lacf -> sync = NGX_CONF_UNSET ;
117+ lacf -> atc = NGX_CONF_UNSET ;
110118
111119 return lacf ;
112120}
@@ -123,6 +131,7 @@ ngx_rtmp_live_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
123131 ngx_conf_merge_value (conf -> nbuckets , prev -> nbuckets , 1024 );
124132 ngx_conf_merge_msec_value (conf -> buflen , prev -> buflen , 0 );
125133 ngx_conf_merge_msec_value (conf -> sync , prev -> sync , 0 );
134+ ngx_conf_merge_value (conf -> atc , prev -> atc , 0 );
126135
127136 conf -> pool = ngx_create_pool (4096 , & cf -> cycle -> new_log );
128137 if (conf -> pool == NULL ) {
@@ -337,10 +346,10 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
337346 return NGX_OK ;
338347 }
339348
340- ngx_log_debug2 (NGX_LOG_DEBUG_RTMP , s -> connection -> log , 0 ,
341- "live: av: %s timestamp=%uD" ,
349+ ngx_log_debug3 (NGX_LOG_DEBUG_RTMP , s -> connection -> log , 0 ,
350+ "live: av: %s timestamp=%uD timeshift=%uD " ,
342351 h -> type == NGX_RTMP_MSG_VIDEO ? "video" : "audio" ,
343- h -> timestamp );
352+ h -> timestamp , h -> timeshift );
344353
345354 cscf = ngx_rtmp_get_module_srv_conf (s , ngx_rtmp_core_module );
346355
@@ -410,17 +419,21 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
410419 ++ peers ;
411420 ss = pctx -> session ;
412421 last = (uint32_t * )((u_char * )pctx + last_offset );
413- ch .timestamp = s -> epoch + h -> timestamp - ss -> epoch ;
422+
423+ ch .timestamp = lacf -> atc ? h -> timestamp :
424+ h -> timeshift + h -> timestamp - (uint32_t )ss -> epoch ;
414425
415426 /* send absolute frame */
416427 if ((pctx -> msg_mask & (1 << h -> type )) == 0 ) {
417428
418429 /* packet from the past for the peer */
419- if (s -> epoch + h -> timestamp < ss -> epoch ) {
430+ if (lacf -> atc == 0 &&
431+ h -> timeshift + h -> timestamp < (uint32_t )ss -> epoch )
432+ {
420433 ngx_log_debug3 (NGX_LOG_DEBUG_RTMP , ss -> connection -> log , 0 ,
421434 "live: av: %s packet from the past %uD < %uD" ,
422435 h -> type == NGX_RTMP_MSG_VIDEO ? "video" : "audio" ,
423- ( uint32_t )( s -> epoch + h -> timestamp ) , (uint32_t )ss -> epoch );
436+ h -> timeshift + h -> timestamp , (uint32_t )ss -> epoch );
424437 continue ;
425438 }
426439
0 commit comments