From patchwork Mon Aug 28 02:00:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 43362 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7194:b0:149:dfde:5c0a with SMTP id s20csp1088405pzb; Sun, 27 Aug 2023 19:00:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFsdfWih+W3nWWQSrc+QeLlsg9XexuOka1phz3mfNYDVptJLj2Y5ZE9Z/kcWfmQpAZWsZ94 X-Received: by 2002:a50:ef08:0:b0:525:7d81:71ee with SMTP id m8-20020a50ef08000000b005257d8171eemr17653984eds.15.1693188057642; Sun, 27 Aug 2023 19:00:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693188057; cv=none; d=google.com; s=arc-20160816; b=FYJRjNi40SZyVKleihEpAualeIgeRFwzH0JHokWE2ZBjJY8pTOUrjmINZMupAPml53 tBZKIh3a6wTECzHe7/45aGX3pZXB1CavNcepqOzWs6W7jR/DZObL0kpsyQKk7IiSQ+9c qLwB2h0ydcilF5/MPnNE/j+WSv8fOiUSuhidD6NieVa5G/T8N06eJjRk26ACWU0F7aFY c3kpoML69hevPg1YNxVfSCezZjDuw3TlOrLMiFDCxd07wdzOMdJqUeVlPMxUWxnM9So8 3tZlGUUh0gUeZHxX43AEIwLUKIpXSvnoWLyadI/iovaXmDEt1IWyJcw37Hn880Zz+ejg 3C7A== 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=OLFNau+MmX5nre2CnLWF5Ypy9cMkFkqQQLgs9aBoHfbxuK68owr+CIqjR7hOOpfJ71 XlkVQl3xpIK5ODV+mXZHf/dJVoNMKy0nEcrmoweNmzAuU2o8WLAj0/sC7ZUPKWVBk6QW YP0+nJZWTneAm5HHTOtXgyfD3qWrpQvyT65T6dghqI2wnBkyFjLqmNsTlzbWmAYS26ky /NhIWGkn26aAvjkPHNZI0puzT4Cg3OJlgGVpEJHFPu/+bnlPGxM/+KpzPeD8Q8DU/Zdl KQKfv9m+B71BAyY4v1UtRawuKWw9xnonWRz/SFTpK48M/ae59AvyhWE9itYvsJxilFW4 Osag== 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 e17-20020aa7d7d1000000b0052a10f811a5si3921965eds.628.2023.08.27.19.00.56; Sun, 27 Aug 2023 19:00:57 -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 5286568C5F5; Mon, 28 Aug 2023 05:00:52 +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 D3DDA68068C for ; Mon, 28 Aug 2023 05:00:44 +0300 (EEST) X-QQ-mid: bizesmtp63t1693188037tylkjo00 Received: from localhost ( [103.102.203.200]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 28 Aug 2023 10:00:36 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: ZqTIE5dM3SpQEZJPOrUBei4Me0p2Mp3mF6peBS8tI341587LubWYDhBiO3k8k TJssT8pWUBnXnjZn5hyyG1660fYxT2lDWW0xEd49ghMNJO02Jmcbj3jjVM0EvDTrtvSZ/rJ od23fh9TvIhZC0uL3PD7dIZS/j4N0NrnjZa/v+Np1uGLnbmqs11EV2GtI+LWdAnIjZtHUFf aeYnhof+kF4n2Y8co+eRqk09qKqGSH4z5RyLTCjonZaHsoV77B1uovTSS+IugGZD/vSV7El zkqDRV927WkixRxCtmWKKr5z4bMT53sQiInmZPAtI6UP75FBckfTRlFQ3pgRb3EOpxbOhSL DsS91x4XWCqkICFdpI= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 10483548470103110867 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Mon, 28 Aug 2023 10:00:34 +0800 Message-Id: <20230828020035.83831-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybglogicsvrsz:qybglogicsvrsz3a-0 Subject: [FFmpeg-devel] [PATCH v4 1/2] avformat/rtmppkt: add ff_amf_write_array for write 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: 07cCLBGt1UGg 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 Mon Aug 28 02:00:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 43363 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7194:b0:149:dfde:5c0a with SMTP id s20csp1088441pzb; Sun, 27 Aug 2023 19:01:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMbVSzagB3GVuzm738gkSUdTfac2b+AweRlEaCoROGnWcpyhDOi5TnQCbEhI1UyrBJ0wPL X-Received: by 2002:a17:907:2c6a:b0:9a2:739:3aa1 with SMTP id ib10-20020a1709072c6a00b009a207393aa1mr8236942ejc.61.1693188067337; Sun, 27 Aug 2023 19:01:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693188067; cv=none; d=google.com; s=arc-20160816; b=rX5Qj/itBJgYOWBpJJyjhQr9RS0OwcZI0TZULhCW3uRT99EQJqvz75zBrU39w+ynyA +CFEVxevwtapN8AmkZbZoOO047Y/cR3EtV/wjCXghLpHWeeXoZHyYmPMAiBnFa5D/0SL ZPAR+PuzFVbpwRTGDGgercYCX4cn7WQ5oJ4PkXpXfqWnYI//qPjzw2A73VULPaLCzMYj EakvrfeW5C7zF7LA7MlKItFvhV+QVHdzGxe0oTKVwZLXkxkXaDRTDeEPpgEoCmPx2XRk kWuiAzmfAv35Vx5up8nX2bB4TDxD3YRtZ1UpLcmkNrrwfCWUFzNJauN+s3cB4EI0haHk 7U6A== 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=ZHdGNwvxu2J0bBRcRv3m9ERKD/6QF6REJMxWHu1wmbM=; fh=w8JR1T/5WquwCqgnlKgniZcITMXOtCHDzF0NyyyGKZI=; b=gSRgnEPVHn57hlCXGmJ2aRmQHQ4gxSsoYksucHxBLBuW4i2ecinYtoJBeODsDPqP/A 3E9600oGF9oza/R50o3TKD4h3pWxY4mtzKXKj1nbYLhnRI/4Jd6MJwQXhhvOSb/tkIls 8Nr1SKQcDqxFfyyzSWHxC4hvYhTe0cISKtCJ25M8FmkgCBHfj7JCQrxih08B66EwKODL 2C7PxW9Tg5eOSATjzCijt70UGXO//QljVSc4BNmm6OfKIncK4hehPn7EC+uiLZRx7fve jOLAvtPN2wC3sBWWlC4IfX5UmAK8tMxvuQdhvpW7H5hS83dJRa9iZCjHl7982ElML6IJ +nDA== 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 v9-20020a170906488900b009a19ed38f2fsi1960013ejq.398.2023.08.27.19.01.06; Sun, 27 Aug 2023 19:01:07 -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 724B768C613; Mon, 28 Aug 2023 05:00:54 +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 02A4D68BE34 for ; Mon, 28 Aug 2023 05:00:46 +0300 (EEST) X-QQ-mid: bizesmtp85t1693188042t920hdzj Received: from localhost ( [103.102.203.200]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 28 Aug 2023 10:00:40 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: dFVR8TEWHmt0+qWA3jwioH3rjTt9FTzj2IgCa25W+bobLuT819LIM63cifRqI bbSJz+GpPeKcDfRC4BvQxF8F64ouBHmjW5Q4TeQ2+z6bWVycR4ZQGl+LuX+AY54aeU+FC9C gh4oneZWBOeypL3lC8nb9Jlrw8s9nhLr4ZtnW7RITJfTta2ZbjrA4I9Crz+0+BhP31SpmnJ gMIN94Z+s2nXgRsmZiFjaQ0Z1YH9cnpIbG8zBwny7FVS4a4577JmmAYKekByU7MxIruHOVS Qb7aGTAfeD6OhOwgwvXgT+NYNclJHNUZXVEVpTFB+OuzSwmNm4dqJe9n7ZUSIKEvDye+eAw aLv7D92PIknxkwhdMvNc3DgbQabVvrWRneatQYG2Mx+QAGuD0k= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 9361067446484523045 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Mon, 28 Aug 2023 10:00:35 +0800 Message-Id: <20230828020035.83831-2-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230828020035.83831-1-lq@chinaffmpeg.org> References: <20230828020035.83831-1-lq@chinaffmpeg.org> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybglogicsvrsz:qybglogicsvrsz3a-0 Subject: [FFmpeg-devel] [PATCH v4 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: 5vleA7eyMYfk 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 | 11 +++++++++++ libavformat/rtmpproto.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/doc/protocols.texi b/doc/protocols.texi index b3fad55591..c7637c11c9 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -896,6 +896,17 @@ 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 be set to a comma separated +list of fourcc values, like @code{hvc1,av01,vp09} for multiple codecs +or @code{hvc1} for only one codec. The specified list will be presented +in the "fourCcLive" property of the Connect Command Message. + +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..98718bc6da 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,38 @@ 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) { + av_log(s, AV_LOG_ERROR, "Malformed rtmp_enhanched_codecs, " + "should be of the form hvc1[,av01][,vp09][,...]\n"); + return AVERROR(EINVAL); + } + + list_len = (fourcc_str_len + 1) / 5; + ff_amf_write_field_name(&p, "fourCcList"); + ff_amf_write_array_start(&p, list_len); + + while(fourcc_data - rt->enhanced_codecs < fourcc_str_len) { + unsigned char fourcc[5]; + if (!strncmp(fourcc_data, "hvc1", 4) || + !strncmp(fourcc_data, "av01", 4) || + !strncmp(fourcc_data, "vp09", 4)) { + av_strlcpy(fourcc, fourcc_data, sizeof(fourcc)); + ff_amf_write_string(&p, fourcc); + } else { + av_log(s, AV_LOG_ERROR, "Unsupported codec fourcc, %.*s\n", 4, fourcc_data); + return AVERROR_PATCHWELCOME; + } + + fourcc_data += 5; + } + } + if (!rt->is_input) { ff_amf_write_field_name(&p, "type"); ff_amf_write_string(&p, "nonprivate"); @@ -3104,6 +3137,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"},