From patchwork Fri Aug 25 05:30:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 43303 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:f07:b0:149:dfde:5c0a with SMTP id fl7csp208221pzb; Thu, 24 Aug 2023 22:30:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+F0HxvtKT3x32vDAK9jUGyAp/ClPr9xprRLtaHMYAmkKJkd+7Sn+HaI+LHOCjaCwxYLsN X-Received: by 2002:a05:6402:2051:b0:525:469a:fc49 with SMTP id bc17-20020a056402205100b00525469afc49mr13273845edb.17.1692941451002; Thu, 24 Aug 2023 22:30:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692941450; cv=none; d=google.com; s=arc-20160816; b=0Pjkks2pvOtCZr9wRGZVd1liTqAbDdVDKrvLO7WwG9MhMFOrx+89Jhs1hjhUlO0WF7 J1ccFZ/rFijSB1lm199ic78b2Z2TU266c52WJG4gpHkojZKHxbLJ49mDorl3Yst3HV5R hFi9yFDTyNEwdFLspee+YeWuOf65zer+GsSWKIvuBtwkQPl5sk5dAyzh7Dgf+Bvy52fZ lPjg7WqamAazw8FM6JvnXjNqNyDKbIW7ex2POYae4UAm9Hnuhs0wB9f6bLW6uON6jn5B /0HRo7bdUyux+FO2A2VVYJ0554os4vSYi8zlfRTQORKfFCel1tK3bq1QIp2kiKExlO0I 54KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:feedback-id:mime-version:references :in-reply-to:message-id:date:to:from:delivered-to; bh=3SArgekw/fK2DAZXvKjhUh0H3aI7XkndujoD4W6xP8w=; fh=w8JR1T/5WquwCqgnlKgniZcITMXOtCHDzF0NyyyGKZI=; b=nHtNucZHxNs2taE9gOVzphRtQ6Qooqg83w4oFZ2F8ay7pbKgT+15Sw1FuzdhUQFYeP dkNHkq8dhRttQGxbkd06xpo76czRKqqulfDT1+GZiJSdjcUZlfKyO4XI/c+re3GQHSXh BGFsw0qpFQuo8YAk/JLPGCcsuaEsqlD/HWGfIQjWfb5smJ9yeYo6QyDMZ3D53Ay+Doyo AsA30UHEuMWrilT9ZJR6ssCCyV1MwWPoUNuR2H1gmMfmY5p4J7+0zg9z51Emb7VV2cam QV78mYdGfKqUbcrBZVysoDHZn+sONE57hwoGJAoKW64l0NAAfM9st5Hixb08bb4D1fEA pvng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v22-20020aa7d9d6000000b00528497fa1dfsi634428eds.584.2023.08.24.22.30.49; Thu, 24 Aug 2023 22:30:50 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6EA7B68C69E; Fri, 25 Aug 2023 08:30:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F099768C534 for ; Fri, 25 Aug 2023 08:30:37 +0300 (EEST) X-QQ-mid: bizesmtp77t1692941430t5ekwfpm Received: from localhost ( [103.102.203.194]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 25 Aug 2023 13:30:29 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: tPoUdLrJrp9sty370jQ5TkdZKX50hAZvHUaJO7xXgqaOg9S7ITvsxemiWKQzO Rj9hTUdcbXUZZhyGD75/0HYJROSlLBO4xyrkYK21HFaNQO52m+5q3eta6WLD/zTBlhyfBaj S2CGMSgoB/dia3rUBw9uXFbE633PbVNA4zJViZPLQzUyK5kWfyOTfWC0/GwFd2GShQ6jl5D TYpYyjgcjF7WYNTvVOIg6nQ6mNAv704oqiaEY9bOR+92uMNYK71jxNoNKN9BCYO9Y++8qGO fsLYXDT1uzkgjBlYDjma4hUa3wcla9E/SDQljim7XVPalqjrZmex9o2x/dPj+9VFbZy7ShH kFMSWwu97t1ch7JqzHXHZva3hO9sw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 5562970876272392700 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Fri, 25 Aug 2023 13:30:26 +0800 Message-Id: <20230825053027.6610-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <776917a5-a1fc-457b-df47-c3d76ecb112b@passwd.hu> References: <776917a5-a1fc-457b-df47-c3d76ecb112b@passwd.hu> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybglogicsvrsz:qybglogicsvrsz3a-0 Subject: [FFmpeg-devel] [PATCH v2 1/2] avformat/rtmppkt: add ff_amf_write_array for write array strings X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Steven Liu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 87Kt7q+m7aRy Signed-off-by: Steven Liu --- libavformat/rtmppkt.c | 6 ++++++ libavformat/rtmppkt.h | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c index 4b97c0833f..a602bf6a96 100644 --- a/libavformat/rtmppkt.c +++ b/libavformat/rtmppkt.c @@ -40,6 +40,12 @@ void ff_amf_write_number(uint8_t **dst, double val) bytestream_put_be64(dst, av_double2int(val)); } +void ff_amf_write_array_start(uint8_t **dst, uint32_t length) +{ + bytestream_put_byte(dst, AMF_DATA_TYPE_ARRAY); + bytestream_put_be32(dst, length); +} + void ff_amf_write_string(uint8_t **dst, const char *str) { bytestream_put_byte(dst, AMF_DATA_TYPE_STRING); diff --git a/libavformat/rtmppkt.h b/libavformat/rtmppkt.h index a15d2a5773..7c580f2224 100644 --- a/libavformat/rtmppkt.h +++ b/libavformat/rtmppkt.h @@ -244,6 +244,14 @@ void ff_amf_write_null(uint8_t **dst); */ void ff_amf_write_object_start(uint8_t **dst); +/** + * Write marker and length for AMF array to buffer. + * + * @param dst pointer to the input buffer (will be modified) + * @param length value to write + */ +void ff_amf_write_array_start(uint8_t **dst, uint32_t length); + /** * Write string used as field name in AMF object to buffer. * From patchwork Fri Aug 25 05:30:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 43304 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:f07:b0:149:dfde:5c0a with SMTP id fl7csp208294pzb; Thu, 24 Aug 2023 22:31:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEveeZegmQbzUpWjGuVT6BGYQ2KyGL1GezstD5VUx+/jSMXEemo27Tr6cHpvFH28Xpskk2J X-Received: by 2002:a17:906:186:b0:9a1:fdfe:a6bf with SMTP id 6-20020a170906018600b009a1fdfea6bfmr3575568ejb.38.1692941460823; Thu, 24 Aug 2023 22:31:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692941460; cv=none; d=google.com; s=arc-20160816; b=kwytQS/gx/O1pACZVk3V5e94QzhGXxMRzRyNZhgKmRIAknH6QVs3/wgvDBfj1LLDWX clwyWr0N9eGe2RxV70ic7uRlSiSSibICimp4AglvwmRnWi6VTJL/niK9ANoshoDSlxZE IecJRNMc7Nv7WbSwha/aFPmj8yLXMpY9r2jCQ9rBxBEBvZbf8kw4sU6u1AvP0qvYruYK fYEwUQnioRPNheIBewaLuAGIaYueOs6VV/ujljNjtXi2yJZQG2tkBz+Cq5xn+HzpB3Cm NDH1s/flGD8wP5kMYgI0RF0naF8IbdIIjF7Zj1QA0F7HfqqLA/7pz897BpRBrsafBJnD D1Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:feedback-id:mime-version:references :in-reply-to:message-id:date:to:from:delivered-to; bh=06IaE1H/cyrw1Ht6TLyYKOsQrwu9VU/LbHd3LdlG93w=; fh=w8JR1T/5WquwCqgnlKgniZcITMXOtCHDzF0NyyyGKZI=; b=szKxTExkyoMI+9hqi+sMwDC6gvLaw+xWQelBK37euZHfk89mupGyy93kKdjfIJl9ox 7r2o4QDxAuxaB7pJbFlf6CIoCJ0DOMyL3NiXvw/+mVCZv0La68UONLxmmwvHOKrkzL7F ZXKc5NNR5dYVkxa1uLrc4ELVXj9nJk94Vzu53vipUnamM9JhxV7P3VtvPn/bW9j1tLsn tDmFtdf5F1nZMcJ2dwmCatb6rTxi3QK1UePH+I8J1Ev5NKdNKj9ti+bWPPapYWDp7/3F 0Jm1Negy+3EoNGUn5ypVGgj3ShDRdf4K8yaQathbXpcXTNugAxl0W5qIdzm+i2/Zrb3M N9CA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d17-20020a170906371100b0098cf3eaee47si521333ejc.689.2023.08.24.22.31.00; Thu, 24 Aug 2023 22:31:00 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 87BD368C6C0; Fri, 25 Aug 2023 08:30:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E9BB268C684 for ; Fri, 25 Aug 2023 08:30:39 +0300 (EEST) X-QQ-mid: bizesmtp81t1692941434tmypmhg8 Received: from localhost ( [103.102.203.194]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 25 Aug 2023 13:30:33 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: 4do7Yod3Qiu5QrNXuVIkPyiJK2zLmOm5eIT1sSP4hXEj2Td5lomdKRwXiwZYV lDCp4Q19AejRbD3nVaeh3PjpJf82VQ1rw30NRyPJI39pe1bGsssYPKBH78C71+iPuiwywNE E0I9b8WPwUgsbs140AOFFOdfbMHJ3j/ER3+SsD/SLOnuBMGQCsNrt7O578zgLaykn34j1pL Fc6LjSJVmYzXwGng9F9ggZILt9u/CeF1nlTmvpC95iZlI8dBUCISWPKJU54rnD54R7xFGOf nzoF1mh4W5vuAtI2slPK4YpjFCdr+XoOyLTTEyNwugGkEzEBFFd5UBCifrsR6u5ETrC2An3 Xn831yhzgitQoMXhB0EwvOA6zmiXkg9rp8PyCT5DX+0hLHzrJ4= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 3810956278091021564 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Fri, 25 Aug 2023 13:30:27 +0800 Message-Id: <20230825053027.6610-2-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230825053027.6610-1-lq@chinaffmpeg.org> References: <776917a5-a1fc-457b-df47-c3d76ecb112b@passwd.hu> <20230825053027.6610-1-lq@chinaffmpeg.org> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybglogicsvrsz:qybglogicsvrsz3a-0 Subject: [FFmpeg-devel] [PATCH v2 2/2] avformat/rtmpproto: support enhanced rtmp X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Steven Liu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: AAVQKIvRuD5a Add option named rtmp_enhanced_codec, it would support hvc1,av01,vp09 now, the fourcc is using Array of strings. Signed-off-by: Steven Liu --- doc/protocols.texi | 6 ++++++ libavformat/rtmpproto.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/doc/protocols.texi b/doc/protocols.texi index b3fad55591..bd2b25e502 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -896,6 +896,12 @@ be named, by prefixing the type with 'N' and specifying the name before the value (i.e. @code{NB:myFlag:1}). This option may be used multiple times to construct arbitrary AMF sequences. +@item rtmp_enhanced_codecs +Specify the list of codecs the client advertises to support in an +enhanced RTMP stream. This option should set a string like @code{hvc1,av01,vp09} +for multiple codecs, or @code{hvc1} for only one codec, +set codec fourcc into fourCcLive property into Connect Command Message, + @item rtmp_flashver Version of the Flash plugin used to run the SWF player. The default is LNX 9,0,124,2. (When publishing, the default is FMLE/3.0 (compatible; diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index f0ef223f05..ea25454362 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -127,6 +127,7 @@ typedef struct RTMPContext { int nb_streamid; ///< The next stream id to return on createStream calls double duration; ///< Duration of the stream in seconds as returned by the server (only valid if non-zero) int tcp_nodelay; ///< Use TCP_NODELAY to disable Nagle's algorithm if set to 1 + char *enhanced_codecs; ///< codec list in enhanced rtmp char username[50]; char password[50]; char auth_params[500]; @@ -336,6 +337,39 @@ static int gen_connect(URLContext *s, RTMPContext *rt) ff_amf_write_field_name(&p, "app"); ff_amf_write_string2(&p, rt->app, rt->auth_params); + if (rt->enhanced_codecs) { + uint32_t list_len = 0; + char *fourcc_data = rt->enhanced_codecs; + int fourcc_str_len = strlen(fourcc_data); + + // check the string, fourcc + ',' + ... + end fourcc correct length should be (4+1)*n+4 + if ((fourcc_str_len + 1) % 5 != 0) + return AVERROR(EINVAL); + + list_len = (fourcc_str_len + 1) / 5; + // write the fourCcList field name + ff_amf_write_field_name(&p, "fourCcList"); + + // write the fourcc array length + ff_amf_write_array_start(&p, list_len); + + while(fourcc_data - rt->enhanced_codecs < fourcc_str_len) { + unsigned char fourcc[5]; + switch (AV_RN32(fourcc_data)) { + case MKTAG('h', 'v', 'c', '1'): + case MKTAG('a', 'v', '0', '1'): + case MKTAG('v', 'p', '0', '9'): + av_strlcpy(fourcc, fourcc_data, sizeof(fourcc)); + ff_amf_write_string(&p, fourcc); + break; + default: + return AVERROR(EINVAL); + } + + fourcc_data += 5; + } + } + if (!rt->is_input) { ff_amf_write_field_name(&p, "type"); ff_amf_write_string(&p, "nonprivate"); @@ -3104,6 +3138,7 @@ static const AVOption rtmp_options[] = { {"rtmp_conn", "Append arbitrary AMF data to the Connect message", OFFSET(conn), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC}, {"rtmp_flashver", "Version of the Flash plugin used to run the SWF player.", OFFSET(flashver), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC}, {"rtmp_flush_interval", "Number of packets flushed in the same request (RTMPT only).", OFFSET(flush_interval), AV_OPT_TYPE_INT, {.i64 = 10}, 0, INT_MAX, ENC}, + {"rtmp_enhanced_codecs", "Specify the codec(s) to use in an enhanced rtmp live stream", OFFSET(enhanced_codecs), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, ENC}, {"rtmp_live", "Specify that the media is a live stream.", OFFSET(live), AV_OPT_TYPE_INT, {.i64 = -2}, INT_MIN, INT_MAX, DEC, "rtmp_live"}, {"any", "both", 0, AV_OPT_TYPE_CONST, {.i64 = -2}, 0, 0, DEC, "rtmp_live"}, {"live", "live stream", 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, DEC, "rtmp_live"},