Skip to content

Commit f23075c

Browse files
committed
added interleave directive
1 parent 9b4725a commit f23075c

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

ngx_rtmp_live_module.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ static ngx_command_t ngx_rtmp_live_commands[] = {
6767
offsetof(ngx_rtmp_live_app_conf_t, atc),
6868
NULL },
6969

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+
7077
ngx_null_command
7178
};
7279

@@ -115,6 +122,7 @@ ngx_rtmp_live_create_app_conf(ngx_conf_t *cf)
115122
lacf->buflen = NGX_CONF_UNSET;
116123
lacf->sync = NGX_CONF_UNSET;
117124
lacf->atc = NGX_CONF_UNSET;
125+
lacf->interleave = NGX_CONF_UNSET;
118126

119127
return lacf;
120128
}
@@ -132,6 +140,7 @@ ngx_rtmp_live_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
132140
ngx_conf_merge_msec_value(conf->buflen, prev->buflen, 0);
133141
ngx_conf_merge_msec_value(conf->sync, prev->sync, 0);
134142
ngx_conf_merge_value(conf->atc, prev->atc, 0);
143+
ngx_conf_merge_value(conf->interleave, prev->interleave, 0);
135144

136145
conf->pool = ngx_create_pool(4096, &cf->cycle->new_log);
137146
if (conf->pool == NULL) {
@@ -365,19 +374,25 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
365374
ch.msid = NGX_RTMP_LIVE_MSID;
366375
ch.type = h->type;
367376
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+
368388
if (h->type == NGX_RTMP_MSG_VIDEO) {
369389
prio = ngx_rtmp_get_video_frame_type(in);
370390
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);
374391
} else {
375392
prio = 0;
376393
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);
380394
}
395+
381396
lh.csid = ch.csid;
382397
diff_timestamp = ch.timestamp - lh.timestamp;
383398

@@ -431,7 +446,7 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
431446
}
432447

433448
/* send absolute frame */
434-
if ((pctx->msg_mask & (1 << h->type)) == 0) {
449+
if ((pctx->msg_mask & (1 << ch.csid)) == 0) {
435450

436451
/* packet from the past for the peer */
437452
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,
452467
header_out ? header_out : in);
453468
ngx_rtmp_prepare_message(s, &ch, NULL, peer_out);
454469
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);
456471
if (header_out) {
457472
*(ngx_uint_t *)((u_char *)pctx + header_offset)
458473
= header_version;

ngx_rtmp_live_module.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef struct {
5656
ngx_flag_t meta;
5757
ngx_msec_t sync;
5858
ngx_flag_t atc;
59+
ngx_flag_t interleave;
5960
ngx_msec_t buflen;
6061
ngx_pool_t *pool;
6162
ngx_rtmp_live_stream_t *free_streams;

0 commit comments

Comments
 (0)