diff mbox

[FFmpeg-devel,v5,3/4] lavc/libxavs2: optimize using of spaces and indents

Message ID 1571059365-3263-3-git-send-email-hwrenx@126.com
State New
Headers show

Commit Message

hwren Oct. 14, 2019, 1:22 p.m. UTC
Signed-off-by: hwren <hwrenx@126.com>
---
 libavcodec/libxavs2.c | 51 +++++++++++++++++++++++----------------------------
 1 file changed, 23 insertions(+), 28 deletions(-)
diff mbox

Patch

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);
         }