From 2c558979016081fce256b415e755d838e5e2302c Mon Sep 17 00:00:00 2001 From: Executor Date: Thu, 2 Nov 2023 16:49:05 +0800 Subject: [PATCH] sync base repo (#2) * [fix] fixed a crash bug resulted from 'reload' * [fix] fixed 'proxy protocol not working' bug. * [fix] fixed a typo. * [fix] fixed an endian bug in mp4 vod. * [fix] worked around the buggy option `-map` in FFmpeg. * [fix] refactored (#245) and fixed a compilation error on Mac. --- ngx_rtmp_handler.c | 1 + ngx_rtmp_receive.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/ngx_rtmp_handler.c b/ngx_rtmp_handler.c index 0ab3b3f..fd65e4b 100644 --- a/ngx_rtmp_handler.c +++ b/ngx_rtmp_handler.c @@ -654,6 +654,7 @@ ngx_rtmp_prepare_message(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, hsize = hdrsize[fmt]; + (void) nbufs; ngx_log_debug8(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, "RTMP prep %s (%d) fmt=%d csid=%uD timestamp=%uD " "mlen=%uD msid=%uD nbufs=%d", diff --git a/ngx_rtmp_receive.c b/ngx_rtmp_receive.c index 24cb4f8..1e146f0 100644 --- a/ngx_rtmp_receive.c +++ b/ngx_rtmp_receive.c @@ -360,6 +360,8 @@ ngx_rtmp_amf_message_handler(ngx_rtmp_session_t *s, ngx_rtmp_core_main_conf_t *cmcf; ngx_array_t *ch; ngx_rtmp_handler_pt *ph; + ngx_chain_t *cl; + ngx_int_t amf_len; size_t len, n; static u_char func[128]; @@ -393,6 +395,32 @@ ngx_rtmp_amf_message_handler(ngx_rtmp_session_t *s, cmcf = ngx_rtmp_get_module_main_conf(s, ngx_rtmp_core_module); + /* + * work around the buggy option `-map` in FFmpeg, see: + * https://trac.ffmpeg.org/ticket/10565 + */ + if (in->buf->pos[0] == NGX_RTMP_AMF_NUMBER) { + cl = in; + amf_len = 0; + + while (cl) { + amf_len += cl->buf->last - cl->buf->pos; + /* type: 1B, number payload: 8B */ + if (amf_len >= 9) { + break; + } + + cl = cl->next; + } + + if (amf_len < 9) { + ngx_log_error(NGX_LOG_WARN, s->connection->log, 0, + "AMF malformed: type=%d, length=%D, ignored", + NGX_RTMP_AMF_NUMBER, amf_len); + return NGX_OK; + } + } + /* read AMF func name & transaction id */ ngx_memzero(&act, sizeof(act)); act.link = in;