mirror of
https://github.com/zotanmew/nginx-rtmp-module.git
synced 2024-05-11 14:51:08 +02:00
implemented video sync mode
This commit is contained in:
parent
c1d21a76a9
commit
3f9dea711d
|
@ -722,11 +722,11 @@ ngx_rtmp_recv(ngx_event_t *rev)
|
|||
h->timestamp = timestamp;
|
||||
}
|
||||
|
||||
ngx_log_debug6(NGX_LOG_DEBUG_RTMP, c->log, 0,
|
||||
"RTMP mheader %s (%d) "
|
||||
"timestamp=%uD mlen=%D len=%D msid=%D",
|
||||
ngx_rtmp_message_type(h->type), (int)h->type,
|
||||
h->timestamp, h->mlen, st->len, h->msid);
|
||||
ngx_log_debug8(NGX_LOG_DEBUG_RTMP, c->log, 0,
|
||||
"RTMP mheader fmt=%d %s (%d) "
|
||||
"time=%uD/%uD mlen=%D len=%D msid=%D",
|
||||
(int)fmt, ngx_rtmp_message_type(h->type), (int)h->type,
|
||||
timestamp, h->timestamp, h->mlen, st->len, h->msid);
|
||||
|
||||
/* header done */
|
||||
b->pos = p;
|
||||
|
|
|
@ -57,8 +57,9 @@ typedef struct {
|
|||
ngx_int_t nbuckets;
|
||||
ngx_rtmp_live_stream_t **streams;
|
||||
ngx_flag_t live;
|
||||
ngx_uint_t time_flags;
|
||||
ngx_flag_t abstime;
|
||||
ngx_msec_t buflen;
|
||||
ngx_flag_t video_sync;
|
||||
ngx_pool_t *pool;
|
||||
ngx_rtmp_live_stream_t *free_streams;
|
||||
} ngx_rtmp_live_app_conf_t;
|
||||
|
@ -68,13 +69,6 @@ typedef struct {
|
|||
#define NGX_RTMP_LIVE_TIME_RELATIVE 0x02
|
||||
|
||||
|
||||
static ngx_conf_bitmask_t ngx_rtmp_live_time_mask[] = {
|
||||
{ ngx_string("absolute"), NGX_RTMP_LIVE_TIME_ABSOLUTE },
|
||||
{ ngx_string("relative"), NGX_RTMP_LIVE_TIME_RELATIVE },
|
||||
{ ngx_null_string, 0 }
|
||||
};
|
||||
|
||||
|
||||
static ngx_command_t ngx_rtmp_live_commands[] = {
|
||||
|
||||
{ ngx_string("live"),
|
||||
|
@ -98,12 +92,19 @@ static ngx_command_t ngx_rtmp_live_commands[] = {
|
|||
offsetof(ngx_rtmp_live_app_conf_t, buflen),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("time"),
|
||||
{ ngx_string("video_sync"),
|
||||
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_bitmask_slot,
|
||||
ngx_conf_set_flag_slot,
|
||||
NGX_RTMP_APP_CONF_OFFSET,
|
||||
offsetof(ngx_rtmp_live_app_conf_t, time_flags),
|
||||
ngx_rtmp_live_time_mask },
|
||||
offsetof(ngx_rtmp_live_app_conf_t, video_sync),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("abstime"),
|
||||
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_flag_slot,
|
||||
NGX_RTMP_APP_CONF_OFFSET,
|
||||
offsetof(ngx_rtmp_live_app_conf_t, abstime),
|
||||
NULL },
|
||||
|
||||
ngx_null_command
|
||||
};
|
||||
|
@ -149,7 +150,9 @@ ngx_rtmp_live_create_app_conf(ngx_conf_t *cf)
|
|||
|
||||
lacf->live = NGX_CONF_UNSET;
|
||||
lacf->nbuckets = NGX_CONF_UNSET;
|
||||
lacf->abstime = NGX_CONF_UNSET;
|
||||
lacf->buflen = NGX_CONF_UNSET;
|
||||
lacf->video_sync = NGX_CONF_UNSET;
|
||||
|
||||
return lacf;
|
||||
}
|
||||
|
@ -163,9 +166,9 @@ ngx_rtmp_live_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||
|
||||
ngx_conf_merge_value(conf->live, prev->live, 0);
|
||||
ngx_conf_merge_value(conf->nbuckets, prev->nbuckets, 1024);
|
||||
ngx_conf_merge_bitmask_value(conf->time_flags, prev->time_flags,
|
||||
NGX_RTMP_LIVE_TIME_RELATIVE);
|
||||
ngx_conf_merge_value(conf->abstime, prev->abstime, 0);
|
||||
ngx_conf_merge_msec_value(conf->buflen, prev->buflen, 0);
|
||||
ngx_conf_merge_value(conf->video_sync, prev->video_sync, 0);
|
||||
|
||||
conf->pool = ngx_create_pool(4096, &cf->cycle->new_log);
|
||||
if (conf->pool == NULL) {
|
||||
|
@ -333,7 +336,6 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
|||
ngx_rtmp_session_t *ss;
|
||||
ngx_rtmp_header_t ch, lh;
|
||||
ngx_uint_t prio, peer_prio;
|
||||
ngx_int_t relative;
|
||||
|
||||
c = s->connection;
|
||||
lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_live_module);
|
||||
|
@ -359,9 +361,12 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
|||
return NGX_OK;
|
||||
}
|
||||
|
||||
ngx_log_debug4(NGX_LOG_DEBUG_RTMP, c->log, 0,
|
||||
"live: av: peer_epoch=%uD; my_epoch=%uD timestamp=%uD; r=%uD",
|
||||
s->peer_epoch, s->epoch, h->timestamp, h->timestamp);
|
||||
ngx_log_debug3(NGX_LOG_DEBUG_RTMP, c->log, 0,
|
||||
"live: av: %s timestamp=%uD(%uD)",
|
||||
h->type == NGX_RTMP_MSG_VIDEO ? "video" : "audio",
|
||||
h->timestamp,
|
||||
h->type == NGX_RTMP_MSG_VIDEO ?
|
||||
ctx->last_video : ctx->last_audio);
|
||||
|
||||
cscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_core_module);
|
||||
|
||||
|
@ -375,24 +380,24 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
|||
if (h->type == NGX_RTMP_MSG_VIDEO) {
|
||||
prio = ngx_rtmp_get_video_frame_type(in);
|
||||
ch.csid = NGX_RTMP_LIVE_CSID_VIDEO;
|
||||
if (lacf->video_sync) {
|
||||
ch.timestamp = ctx->last_audio;
|
||||
}
|
||||
lh.timestamp = ctx->last_video;
|
||||
ctx->last_video = h->timestamp;
|
||||
ctx->last_video = ch.timestamp;
|
||||
} else {
|
||||
/* audio priority is the same as video key frame's */
|
||||
prio = NGX_RTMP_VIDEO_KEY_FRAME;
|
||||
ch.csid = NGX_RTMP_LIVE_CSID_AUDIO;
|
||||
lh.timestamp = ctx->last_audio;
|
||||
ctx->last_audio = h->timestamp;
|
||||
ctx->last_audio = ch.timestamp;
|
||||
}
|
||||
lh.csid = ch.csid;
|
||||
|
||||
out = ngx_rtmp_append_shared_bufs(cscf, NULL, in);
|
||||
ngx_rtmp_prepare_message(s, &ch,
|
||||
lacf->time_flags & NGX_RTMP_LIVE_TIME_ABSOLUTE ? NULL : &lh,
|
||||
out);
|
||||
ngx_rtmp_prepare_message(s, &ch, lacf->abstime ? NULL : &lh, out);
|
||||
out_abs = NULL;
|
||||
ch.timestamp = 0;
|
||||
relative = lacf->time_flags & NGX_RTMP_LIVE_TIME_RELATIVE;
|
||||
|
||||
/* broadcast to all subscribers */
|
||||
for (pctx = ctx->stream->ctx; pctx; pctx = pctx->next) {
|
||||
|
@ -402,7 +407,7 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
|||
ss = pctx->session;
|
||||
|
||||
/* send absolute frame */
|
||||
if (relative && (pctx->msg_mask & (1 << h->type)) == 0) {
|
||||
if (!lacf->abstime && (pctx->msg_mask & (1 << h->type)) == 0) {
|
||||
if (out_abs == NULL) {
|
||||
out_abs = ngx_rtmp_append_shared_bufs(cscf, NULL, in);
|
||||
ngx_rtmp_prepare_message(s, &ch, NULL, out_abs);
|
||||
|
|
Loading…
Reference in a new issue