From patchwork Tue May 28 03:29:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 13308 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 1094D448923 for ; Tue, 28 May 2019 06:30:41 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DC5B86805E4; Tue, 28 May 2019 06:30:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9CA68680407 for ; Tue, 28 May 2019 06:30:33 +0300 (EEST) Received: by mail-pl1-f193.google.com with SMTP id bb3so101981plb.13 for ; Mon, 27 May 2019 20:30:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/pbJiqeHK9tfKdEXv4i+zCtX/XHAAugvqET5mcBDG7c=; b=cvZ3yuExDUc5MSb0q1n19ak390xGtnaOdRzCaOrxUDBZr4kD6cJo9QUGbzujzh4IpK MstakiDfuJEdLhkj1nldPr6E7d39qiE1TL7iZIoaGoG2kaz3V2QhVOoUXfU6pBTTjdlj zuXT9i0vQip0rA4NQO1mpsX4ec2m/1n8pdoZojZHpIOlh8EucrA4JwncsBsVYx7FcFxs 4ghBn3SwcnXJyqZj2ZtwFbBcQiehrDO3MN+eErZNQaAyDm7RFDvDM8YoJwyYSdO/pXpM 88bVSukvcmzC5aAU0Bx8LRZfBApWOc8TgcTyoEXZKqD2Qqho4v6DbH45Fd5rtiwah/zJ dMoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/pbJiqeHK9tfKdEXv4i+zCtX/XHAAugvqET5mcBDG7c=; b=XXl7yUhpNYMysOrZo0vjsik79pVJlOKMOo9LcHJGX2LRQ9q+fJfjv9D6QEx+f7oXlf W4NN1cSptV4/LRD6rKWY8DGTltm+yJIZK0T9WkN12L/TeuGV43NCxibmYqSXfbKS4xQ2 Rvrj5yTmhgsuE9yaHeQww6/r+Jrsi7Wn1s6J2x0HtzMdpBlJVUDqL/ExQ1w5oQio0rhx 9xbM8vAPJbZPhbx1ZANC85BBHg4XqC/FrIiZjf7VidT39MCfo8BVUonOrsk8XH4uS1J3 3fNuIuMogw8yIHQH30GXkjWNJci0cM7AXD8gYVOt58SgkCIa/oS31q3nTGm3qA74OXDu sDZg== X-Gm-Message-State: APjAAAUVr8A073M3h97ULdoc4ZiML3shY3mhavB4hG3HIqv/8csBNEeM QMiS1+425JdvpGUj1El+Mhuav5GrCsk= X-Google-Smtp-Source: APXvYqzU2qCYfJH5n9Ut1/Iv41CqWrL5g9z3otwga5134sr2zaQfrz12mkXIHVdNmtHS1omJS6k68w== X-Received: by 2002:a17:902:42a5:: with SMTP id h34mr108665992pld.178.1559014231256; Mon, 27 May 2019 20:30:31 -0700 (PDT) Received: from localhost.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id v4sm14095774pff.45.2019.05.27.20.30.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 May 2019 20:30:30 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 May 2019 11:29:51 +0800 Message-Id: <20190528032953.3864-1-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190522065954.62328-2-lance.lmwang@gmail.com> References: <20190522065954.62328-2-lance.lmwang@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/3] avcodec/nvenc: add more sei data support X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Limin Wang , jamrial@gmail.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Signed-off-by: Limin Wang --- libavcodec/nvenc.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 3fe64bba8b..75dda6d689 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1705,7 +1705,8 @@ static int nvenc_upload_frame(AVCodecContext *avctx, const AVFrame *frame, static void nvenc_codec_specific_pic_params(AVCodecContext *avctx, NV_ENC_PIC_PARAMS *params, - NV_ENC_SEI_PAYLOAD *sei_data) + NV_ENC_SEI_PAYLOAD *sei_data, + int sei_count) { NvencContext *ctx = avctx->priv_data; @@ -1715,9 +1716,9 @@ static void nvenc_codec_specific_pic_params(AVCodecContext *avctx, ctx->encode_config.encodeCodecConfig.h264Config.sliceMode; params->codecPicParams.h264PicParams.sliceModeData = ctx->encode_config.encodeCodecConfig.h264Config.sliceModeData; - if (sei_data) { + if (sei_count > 0) { params->codecPicParams.h264PicParams.seiPayloadArray = sei_data; - params->codecPicParams.h264PicParams.seiPayloadArrayCnt = 1; + params->codecPicParams.h264PicParams.seiPayloadArrayCnt = sei_count; } break; @@ -1726,9 +1727,9 @@ static void nvenc_codec_specific_pic_params(AVCodecContext *avctx, ctx->encode_config.encodeCodecConfig.hevcConfig.sliceMode; params->codecPicParams.hevcPicParams.sliceModeData = ctx->encode_config.encodeCodecConfig.hevcConfig.sliceModeData; - if (sei_data) { + if (sei_count > 0) { params->codecPicParams.hevcPicParams.seiPayloadArray = sei_data; - params->codecPicParams.hevcPicParams.seiPayloadArrayCnt = 1; + params->codecPicParams.hevcPicParams.seiPayloadArrayCnt = sei_count; } break; @@ -2023,8 +2024,9 @@ int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) NVENCSTATUS nv_status; NvencSurface *tmp_out_surf, *in_surf; int res, res2; - NV_ENC_SEI_PAYLOAD *sei_data = NULL; - size_t sei_size; + NV_ENC_SEI_PAYLOAD sei_data[8]; + int sei_count = 0; + int i; NvencContext *ctx = avctx->priv_data; NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs; @@ -2093,18 +2095,22 @@ int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) pic_params.inputTimeStamp = frame->pts; if (ctx->a53_cc && av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC)) { - if (ff_alloc_a53_sei(frame, sizeof(NV_ENC_SEI_PAYLOAD), (void**)&sei_data, &sei_size) < 0) { + void *a53_data = NULL; + size_t a53_size = 0; + + if (ff_alloc_a53_sei(frame, 0, (void**)&a53_data, &a53_size) < 0) { av_log(ctx, AV_LOG_ERROR, "Not enough memory for closed captions, skipping\n"); } - if (sei_data) { - sei_data->payloadSize = (uint32_t)sei_size; - sei_data->payloadType = 4; - sei_data->payload = (uint8_t*)(sei_data + 1); + if (a53_data) { + sei_data[sei_count].payloadSize = (uint32_t)a53_size; + sei_data[sei_count].payloadType = 4; + sei_data[sei_count].payload = (uint8_t*)a53_data; + sei_count ++; } } - nvenc_codec_specific_pic_params(avctx, &pic_params, sei_data); + nvenc_codec_specific_pic_params(avctx, &pic_params, sei_data, sei_count); } else { pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS; ctx->encoder_flushing = 1; @@ -2115,7 +2121,9 @@ int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) return res; nv_status = p_nvenc->nvEncEncodePicture(ctx->nvencoder, &pic_params); - av_free(sei_data); + + for ( i = 0; i < sei_count; i++) + av_freep(&sei_data[i].payload); res = nvenc_pop_context(avctx); if (res < 0)