From 1e52080dbae576383ac7fd4209e3ff0d8b3874ef Mon Sep 17 00:00:00 2001 From: vacingFang Date: Sun, 7 Jan 2024 23:02:51 +0800 Subject: [PATCH] [fix] fix sequence header cache bug --- ngx_rtmp_gop_cache_module.c | 38 +++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/ngx_rtmp_gop_cache_module.c b/ngx_rtmp_gop_cache_module.c index f65587c..059fc7a 100644 --- a/ngx_rtmp_gop_cache_module.c +++ b/ngx_rtmp_gop_cache_module.c @@ -292,22 +292,6 @@ ngx_rtmp_gop_cache_alloc_cache(ngx_rtmp_session_t *s) } } - // save video seq header. - if (codec_ctx->avc_header && ctx->video_seq_header == NULL) { - ctx->video_seq_header = codec_ctx->avc_header; - } - - // save audio seq header. - if (codec_ctx->aac_header && ctx->audio_seq_header == NULL) { - ctx->audio_seq_header = codec_ctx->aac_header; - } - - // save metadata. - if (codec_ctx->meta && ctx->meta == NULL) { - ctx->meta_version = codec_ctx->meta_version; - ctx->meta = codec_ctx->meta; - } - if (ctx->cache_head == NULL) { ctx->cache_tail = ctx->cache_head = cache; } else { @@ -476,6 +460,28 @@ ngx_rtmp_gop_cache_frame(ngx_rtmp_session_t *s, ngx_uint_t prio, } } + // save video seq header. + if (ctx->video_seq_header == NULL && codec_ctx->avc_header) { + ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, + "video header comming"); + ctx->video_seq_header = codec_ctx->avc_header; + } + + // save audio seq header. + if (ctx->audio_seq_header == NULL && codec_ctx->aac_header) { + ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, + "audio header comming"); + ctx->audio_seq_header = codec_ctx->aac_header; + } + + // save metadata. + if (ctx->meta == NULL && codec_ctx->meta) { + ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, + "meta comming"); + ctx->meta_version = codec_ctx->meta_version; + ctx->meta = codec_ctx->meta; + } + gf = ngx_rtmp_gop_cache_alloc_frame(s); if (gf == NULL) { return;