Message ID | 1571022557-19605-3-git-send-email-hwrenx@126.com |
---|---|
State | Superseded |
Headers | show |
> 在 2019年10月14日,11:09,hwren <hwrenx@126.com> 写道: > > Signed-off-by: hwren <hwrenx@126.com> > --- > libavcodec/libxavs2.c | 98 ++++++++++++++++++++++++--------------------------- > 1 file changed, 46 insertions(+), 52 deletions(-) > > diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c > index 7a41ca2..e52f0c4 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; > @@ -51,7 +52,7 @@ typedef struct XAVS2EContext { > char *xavs2_opts; > > xavs2_outpacket_t packet; > - xavs2_param_t *param; > + xavs2_param_t * param; maybe ok before modify. > > const xavs2_api_t *api; > > @@ -59,12 +60,12 @@ typedef struct XAVS2EContext { > > static av_cold int xavs2_init(AVCodecContext *avctx) > { > - XAVS2EContext *cae= avctx->priv_data; > - int bit_depth, code; > + 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"); > @@ -77,24 +78,21 @@ static av_cold int xavs2_init(AVCodecContext *avctx) > return AVERROR(ENOMEM); > } > > - xavs2_opt_set2("Width", "%d", avctx->width); > - xavs2_opt_set2("Height", "%d", avctx->height); > - xavs2_opt_set2("BFrames", "%d", avctx->max_b_frames); > - 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("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)); > + xavs2_opt_set2("Width", "%d", avctx->width); > + xavs2_opt_set2("Height", "%d", avctx->height); > + xavs2_opt_set2("BFrames", "%d", avctx->max_b_frames); > + 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("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; > - AVDictionaryEntry *en = NULL; > + AVDictionary * dict = NULL; maybe ok before modify. > + AVDictionaryEntry *en = NULL; > > if (!av_dict_parse_string(&dict, cae->xavs2_opts, "=", ":", 0)) { > while ((en = av_dict_get(dict, "", en, AV_DICT_IGNORE_SUFFIX))) { > @@ -104,26 +102,23 @@ 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); > - xavs2_opt_set2("InitialQP", "%d", cae->initial_qp); > - xavs2_opt_set2("MaxQP", "%d", avctx->qmax >= 0 ? avctx->qmax : cae->max_qp); > - xavs2_opt_set2("MinQP", "%d", avctx->qmin >= 0 ? avctx->qmin : cae->min_qp); > + xavs2_opt_set2("RateControl", "%d", 1); > + xavs2_opt_set2("TargetBitRate", "%" PRId64 "", avctx->bit_rate); > + xavs2_opt_set2("InitialQP", "%d", cae->initial_qp); > + xavs2_opt_set2("MaxQP", "%d", avctx->qmax >= 0 ? avctx->qmax : cae->max_qp); > + xavs2_opt_set2("MinQP", "%d", avctx->qmin >= 0 ? avctx->qmin : cae->min_qp); > } else { > - xavs2_opt_set2("InitialQP", "%d", cae->qp); > + 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); > } > > @@ -168,17 +163,16 @@ static void xavs2_copy_frame(xavs2_picture_t *pic, const AVFrame *frame) > } > } > > -static int xavs2_encode_frame(AVCodecContext *avctx, AVPacket *pkt, > - const AVFrame *frame, int *got_packet) > +static int xavs2_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet) > { > - XAVS2EContext *cae = avctx->priv_data; > + XAVS2EContext * cae = avctx->priv_data; maybe ok before modify. > xavs2_picture_t pic; > - int ret; > + 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 /* */ comment two lines maybe ok? > 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) { > @@ -217,9 +211,8 @@ static int xavs2_encode_frame(AVCodecContext *avctx, AVPacket *pkt, > 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); > @@ -244,7 +237,7 @@ 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); > > @@ -258,6 +251,7 @@ static av_cold int xavs2_close(AVCodecContext *avctx) > #define OFFSET(x) offsetof(XAVS2EContext, x) > #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM > > + empty line? > static const AVOption options[] = { > { "lcu_row_threads" , "number of parallel threads for rows" , OFFSET(lcu_row_threads) , AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, VE }, > { "initial_qp" , "Quantization initial parameter" , OFFSET(initial_qp) , AV_OPT_TYPE_INT, {.i64 = 34 }, 1, 63, VE }, > -- > 2.7.4 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". Code style looks terrible Thanks Steven
diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c index 7a41ca2..e52f0c4 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; @@ -51,7 +52,7 @@ typedef struct XAVS2EContext { char *xavs2_opts; xavs2_outpacket_t packet; - xavs2_param_t *param; + xavs2_param_t * param; const xavs2_api_t *api; @@ -59,12 +60,12 @@ typedef struct XAVS2EContext { static av_cold int xavs2_init(AVCodecContext *avctx) { - XAVS2EContext *cae= avctx->priv_data; - int bit_depth, code; + 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"); @@ -77,24 +78,21 @@ static av_cold int xavs2_init(AVCodecContext *avctx) return AVERROR(ENOMEM); } - xavs2_opt_set2("Width", "%d", avctx->width); - xavs2_opt_set2("Height", "%d", avctx->height); - xavs2_opt_set2("BFrames", "%d", avctx->max_b_frames); - 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("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)); + xavs2_opt_set2("Width", "%d", avctx->width); + xavs2_opt_set2("Height", "%d", avctx->height); + xavs2_opt_set2("BFrames", "%d", avctx->max_b_frames); + 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("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; - AVDictionaryEntry *en = NULL; + AVDictionary * dict = NULL; + AVDictionaryEntry *en = NULL; if (!av_dict_parse_string(&dict, cae->xavs2_opts, "=", ":", 0)) { while ((en = av_dict_get(dict, "", en, AV_DICT_IGNORE_SUFFIX))) { @@ -104,26 +102,23 @@ 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); - xavs2_opt_set2("InitialQP", "%d", cae->initial_qp); - xavs2_opt_set2("MaxQP", "%d", avctx->qmax >= 0 ? avctx->qmax : cae->max_qp); - xavs2_opt_set2("MinQP", "%d", avctx->qmin >= 0 ? avctx->qmin : cae->min_qp); + xavs2_opt_set2("RateControl", "%d", 1); + xavs2_opt_set2("TargetBitRate", "%" PRId64 "", avctx->bit_rate); + xavs2_opt_set2("InitialQP", "%d", cae->initial_qp); + xavs2_opt_set2("MaxQP", "%d", avctx->qmax >= 0 ? avctx->qmax : cae->max_qp); + xavs2_opt_set2("MinQP", "%d", avctx->qmin >= 0 ? avctx->qmin : cae->min_qp); } else { - xavs2_opt_set2("InitialQP", "%d", cae->qp); + 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); } @@ -168,17 +163,16 @@ static void xavs2_copy_frame(xavs2_picture_t *pic, const AVFrame *frame) } } -static int xavs2_encode_frame(AVCodecContext *avctx, AVPacket *pkt, - const AVFrame *frame, int *got_packet) +static int xavs2_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet) { - XAVS2EContext *cae = avctx->priv_data; + XAVS2EContext * cae = avctx->priv_data; xavs2_picture_t pic; - int ret; + 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) { @@ -217,9 +211,8 @@ static int xavs2_encode_frame(AVCodecContext *avctx, AVPacket *pkt, 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); @@ -244,7 +237,7 @@ 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); @@ -258,6 +251,7 @@ static av_cold int xavs2_close(AVCodecContext *avctx) #define OFFSET(x) offsetof(XAVS2EContext, x) #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM + static const AVOption options[] = { { "lcu_row_threads" , "number of parallel threads for rows" , OFFSET(lcu_row_threads) , AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, VE }, { "initial_qp" , "Quantization initial parameter" , OFFSET(initial_qp) , AV_OPT_TYPE_INT, {.i64 = 34 }, 1, 63, VE },
Signed-off-by: hwren <hwrenx@126.com> --- libavcodec/libxavs2.c | 98 ++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 52 deletions(-)