From patchwork Mon Oct 14 06:52:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hwren X-Patchwork-Id: 15738 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 BF7DE44A374 for ; Mon, 14 Oct 2019 09:52:58 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AAFB5689F4D; Mon, 14 Oct 2019 09:52:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from m15-114.126.com (m15-114.126.com [220.181.15.114]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9D17C689A0D for ; Mon, 14 Oct 2019 09:52:50 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=o8jSe1LObhLTf66bPK KARLJ9rnFJ0hGWD0WFB503ZAk=; b=dw/QvyDpKvLNjV3qROVzhnt5KFK23ykbH4 Vmlo1tDW2WCRKA6BLg2kb/wKBjd/2j9YG4RpsCaSLMLkHFwFU5dY0kw8ydIk2viq 0f2bd9n+nEhe7L8pGeHHN/2YZV7FJRLKydAVuRYUTU27Avcj9IMny9pkB75+kdYr 8hFcu3kjY= Received: from localhost.localdomain (unknown [162.105.23.171]) by smtp7 (Coremail) with SMTP id DsmowAAnl7c9G6RdkHHNCA--.39299S5; Mon, 14 Oct 2019 14:52:46 +0800 (CST) From: hwrenx@126.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 14 Oct 2019 14:52:43 +0800 Message-Id: <1571035964-4947-3-git-send-email-hwrenx@126.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1571035964-4947-1-git-send-email-hwrenx@126.com> References: <1571035964-4947-1-git-send-email-hwrenx@126.com> X-CM-TRANSID: DsmowAAnl7c9G6RdkHHNCA--.39299S5 X-Coremail-Antispam: 1Uf129KBjvJXoWxJw48Aw1Uuw17GFW5ZryrWFg_yoW7Jw1kpF 13GF9Ig3ZrJF4rAay8Jr1Fvr15AF4jg3WUJ392yw1vvaySvr90gr42gFy8Ka92qaykZa1U Jr4Dtry5W39xKa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jwzVbUUUUU= X-Originating-IP: [162.105.23.171] X-CM-SenderInfo: pkzuv0b06rjloofrz/1tbiZh5O6VpD8RkbiwAAs+ Subject: [FFmpeg-devel] [PATCH v3 3/4] lavc/libxavs2: optimize using of spaces and indents 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: hwren MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: hwren Signed-off-by: hwren --- libavcodec/libxavs2.c | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c index b5c07ec..8077607 100644 --- a/libavcodec/libxavs2.c +++ b/libavcodec/libxavs2.c @@ -26,15 +26,16 @@ #include "mpeg12.h" #include "libavutil/avstring.h" -#define xavs2_opt_set2(name, format, ...) do{ \ - char opt_str[16] = {0}; \ - int err; \ - av_strlcatf(opt_str, sizeof(opt_str), format, __VA_ARGS__); \ - err = cae->api->opt_set2(cae->param, name, opt_str); \ - if (err < 0) {\ - av_log(avctx, AV_LOG_WARNING, "Invalid value for %s: %s\n", name, opt_str);\ - }\ -} while(0); +#define xavs2_opt_set2(name, format, ...) \ + do { \ + char opt_str[16] = {0}; \ + int err; \ + av_strlcatf(opt_str, sizeof(opt_str), format, __VA_ARGS__); \ + err = cae->api->opt_set2(cae->param, name, opt_str); \ + if (err < 0) { \ + av_log(avctx, AV_LOG_WARNING, "Invalid value for %s: %s\n", name, opt_str); \ + } \ + } while (0); typedef struct XAVS2EContext { AVClass *class; @@ -59,12 +60,12 @@ typedef struct XAVS2EContext { static av_cold int xavs2_init(AVCodecContext *avctx) { - XAVS2EContext *cae= avctx->priv_data; + XAVS2EContext *cae = avctx->priv_data; int bit_depth, code; bit_depth = avctx->pix_fmt == AV_PIX_FMT_YUV420P ? 8 : 10; - /* get API handler */ + // get API handler cae->api = xavs2_api_get(bit_depth); if (!cae->api) { av_log(avctx, AV_LOG_ERROR, "api get failed\n"); @@ -83,17 +84,15 @@ static av_cold int xavs2_init(AVCodecContext *avctx) xavs2_opt_set2("BitDepth", "%d", bit_depth); xavs2_opt_set2("Log", "%d", cae->log_level); xavs2_opt_set2("Preset", "%d", cae->preset_level); + xavs2_opt_set2("OpenGOP", "%d", !(avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)); xavs2_opt_set2("IntraPeriodMax", "%d", avctx->gop_size); xavs2_opt_set2("IntraPeriodMin", "%d", avctx->gop_size); - xavs2_opt_set2("ThreadFrames", "%d", avctx->thread_count); xavs2_opt_set2("ThreadRows", "%d", cae->lcu_row_threads); - xavs2_opt_set2("OpenGOP", "%d", !(avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)); - if (cae->xavs2_opts) { - AVDictionary *dict = NULL; + AVDictionary *dict = NULL; AVDictionaryEntry *en = NULL; if (!av_dict_parse_string(&dict, cae->xavs2_opts, "=", ":", 0)) { @@ -104,7 +103,7 @@ static av_cold int xavs2_init(AVCodecContext *avctx) } } - /* Rate control */ + // Rate control if (avctx->bit_rate > 0) { xavs2_opt_set2("RateControl", "%d", 1); xavs2_opt_set2("TargetBitRate", "%"PRId64"", avctx->bit_rate); @@ -115,15 +114,14 @@ static av_cold int xavs2_init(AVCodecContext *avctx) xavs2_opt_set2("InitialQP", "%d", cae->qp); } - ff_mpeg12_find_best_frame_rate(avctx->framerate, &code, NULL, NULL, 0); - xavs2_opt_set2("FrameRate", "%d", code); + xavs2_opt_set2("FrameRate", "%d", code); cae->encoder = cae->api->encoder_create(cae->param); if (!cae->encoder) { - av_log(avctx,AV_LOG_ERROR, "Can not create encoder. Null pointer returned\n"); + av_log(avctx, AV_LOG_ERROR, "Can not create encoder. Null pointer returned\n"); return AVERROR(EINVAL); } @@ -179,10 +177,10 @@ static int xavs2_encode_frame(AVCodecContext *avctx, AVPacket *pkt, xavs2_picture_t pic; int ret; - /* create the XAVS2 video encoder */ - /* read frame data and send to the XAVS2 video encoder */ + // create the XAVS2 video encoder + // read frame data and send to the XAVS2 video encoder if (cae->api->encoder_get_buffer(cae->encoder, &pic) < 0) { - av_log(avctx,AV_LOG_ERROR, "failed to get frame buffer\n"); + av_log(avctx, AV_LOG_ERROR, "failed to get frame buffer\n"); return AVERROR_EXTERNAL; } if (frame) { @@ -216,14 +214,12 @@ static int xavs2_encode_frame(AVCodecContext *avctx, AVPacket *pkt, av_log(avctx, AV_LOG_ERROR, "encode failed\n"); return AVERROR_EXTERNAL; } - } else { cae->api->encoder_encode(cae->encoder, NULL, &cae->packet); } - if ((cae->packet.len) && (cae->packet.state != XAVS2_STATE_FLUSH_END)){ - - if (av_new_packet(pkt, cae->packet.len) < 0){ + if ((cae->packet.len) && (cae->packet.state != XAVS2_STATE_FLUSH_END)) { + if (av_new_packet(pkt, cae->packet.len) < 0) { av_log(avctx, AV_LOG_ERROR, "packet alloc failed\n"); cae->api->encoder_packet_unref(cae->encoder, &cae->packet); return AVERROR(ENOMEM); @@ -248,10 +244,9 @@ static int xavs2_encode_frame(AVCodecContext *avctx, AVPacket *pkt, static av_cold int xavs2_close(AVCodecContext *avctx) { XAVS2EContext *cae = avctx->priv_data; - /* destroy the encoder */ + // destroy the encoder if (cae->api) { cae->api->encoder_destroy(cae->encoder); - if (cae->param) { cae->api->opt_destroy(cae->param); }