@@ -67,6 +67,13 @@ static ngx_command_t ngx_rtmp_live_commands[] = {
67
67
offsetof(ngx_rtmp_live_app_conf_t , atc ),
68
68
NULL },
69
69
70
+ { ngx_string ("interleave" ),
71
+ NGX_RTMP_MAIN_CONF |NGX_RTMP_SRV_CONF |NGX_RTMP_APP_CONF |NGX_CONF_TAKE1 ,
72
+ ngx_conf_set_flag_slot ,
73
+ NGX_RTMP_APP_CONF_OFFSET ,
74
+ offsetof(ngx_rtmp_live_app_conf_t , interleave ),
75
+ NULL },
76
+
70
77
ngx_null_command
71
78
};
72
79
@@ -115,6 +122,7 @@ ngx_rtmp_live_create_app_conf(ngx_conf_t *cf)
115
122
lacf -> buflen = NGX_CONF_UNSET ;
116
123
lacf -> sync = NGX_CONF_UNSET ;
117
124
lacf -> atc = NGX_CONF_UNSET ;
125
+ lacf -> interleave = NGX_CONF_UNSET ;
118
126
119
127
return lacf ;
120
128
}
@@ -132,6 +140,7 @@ ngx_rtmp_live_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
132
140
ngx_conf_merge_msec_value (conf -> buflen , prev -> buflen , 0 );
133
141
ngx_conf_merge_msec_value (conf -> sync , prev -> sync , 0 );
134
142
ngx_conf_merge_value (conf -> atc , prev -> atc , 0 );
143
+ ngx_conf_merge_value (conf -> interleave , prev -> interleave , 0 );
135
144
136
145
conf -> pool = ngx_create_pool (4096 , & cf -> cycle -> new_log );
137
146
if (conf -> pool == NULL ) {
@@ -365,19 +374,25 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
365
374
ch .msid = NGX_RTMP_LIVE_MSID ;
366
375
ch .type = h -> type ;
367
376
lh .msid = ch .msid ;
377
+
378
+ if (lacf -> interleave || h -> type == NGX_RTMP_MSG_VIDEO ) {
379
+ last_offset = offsetof(ngx_rtmp_live_ctx_t , last_video );
380
+ } else {
381
+ last_offset = offsetof(ngx_rtmp_live_ctx_t , last_audio );
382
+ }
383
+
384
+ last = (uint32_t * )((u_char * )ctx + last_offset );
385
+ lh .timestamp = * last ;
386
+ * last = ch .timestamp ;
387
+
368
388
if (h -> type == NGX_RTMP_MSG_VIDEO ) {
369
389
prio = ngx_rtmp_get_video_frame_type (in );
370
390
ch .csid = NGX_RTMP_LIVE_CSID_VIDEO ;
371
- lh .timestamp = ctx -> last_video ;
372
- ctx -> last_video = ch .timestamp ;
373
- last_offset = offsetof(ngx_rtmp_live_ctx_t , last_video );
374
391
} else {
375
392
prio = 0 ;
376
393
ch .csid = NGX_RTMP_LIVE_CSID_AUDIO ;
377
- lh .timestamp = ctx -> last_audio ;
378
- ctx -> last_audio = ch .timestamp ;
379
- last_offset = offsetof(ngx_rtmp_live_ctx_t , last_audio );
380
394
}
395
+
381
396
lh .csid = ch .csid ;
382
397
diff_timestamp = ch .timestamp - lh .timestamp ;
383
398
@@ -431,7 +446,7 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
431
446
}
432
447
433
448
/* send absolute frame */
434
- if ((pctx -> msg_mask & (1 << h -> type )) == 0 ) {
449
+ if ((pctx -> msg_mask & (1 << ch . csid )) == 0 ) {
435
450
436
451
/* packet from the past for the peer */
437
452
if (lacf -> atc == 0 && timestamp < (uint32_t )ss -> epoch ) {
@@ -452,7 +467,7 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
452
467
header_out ? header_out : in );
453
468
ngx_rtmp_prepare_message (s , & ch , NULL , peer_out );
454
469
if (ngx_rtmp_send_message (ss , peer_out , prio ) == NGX_OK ) {
455
- pctx -> msg_mask |= (1 << h -> type );
470
+ pctx -> msg_mask |= (1 << ch . csid );
456
471
if (header_out ) {
457
472
* (ngx_uint_t * )((u_char * )pctx + header_offset )
458
473
= header_version ;
0 commit comments