Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/libx265: Don't use AVBPrint unnecessarily
Date: Fri, 22 Mar 2024 14:32:50 +0100
Message-ID: <GV1P250MB0737842CEA6E6DCA5F67FFB38F312@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw)

This code uses the AVBPrint API for exactly one av_bprintf()
in a scenario in which a good upper bound for the needed
size of the buffer is available (with said upper bound being
much smaller than sizeof(AVBPrint)). So one can simply use
snprintf() instead. This also avoids the (always-false due to
the current size of the internal AVBPrint buffer) check for
whether the AVBPrint is complete.

Furthermore, the old code used AV_BPRINT_SIZE_AUTOMATIC
which implies that the AVBPrint buffer will never be
(re)allocated and yet it used av_bprint_finalize().
This has of course also been removed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
This has actually been mentioned in my review of v3
of this patchset:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20230817214858.184010-13-jeebjp@gmail.com/

 libavcodec/libx265.c | 31 ++++++-------------------------
 1 file changed, 6 insertions(+), 25 deletions(-)

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 70ec6d3539..d7620878b8 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -28,17 +28,14 @@
 #include <float.h>
 
 #include "libavutil/avassert.h"
-#include "libavutil/bprint.h"
 #include "libavutil/buffer.h"
 #include "libavutil/internal.h"
-#include "libavutil/common.h"
 #include "libavutil/mastering_display_metadata.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "avcodec.h"
 #include "codec_internal.h"
 #include "encode.h"
-#include "internal.h"
 #include "packet_internal.h"
 #include "atsc_a53.h"
 #include "sei.h"
@@ -182,13 +179,10 @@ static int handle_mdcv(const AVClass **avcl, const x265_api *api,
                        x265_param *params,
                        const AVMasteringDisplayMetadata *mdcv)
 {
-    int ret = AVERROR_BUG;
-    AVBPrint buf;
-    av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
+    char buf[10 /* # of PRId64s */ * 20 /* max strlen for %PRId64 */ + sizeof("G(,)B(,)R(,)WP(,)L(,)")];
 
     // G(%hu,%hu)B(%hu,%hu)R(%hu,%hu)WP(%hu,%hu)L(%u,%u)
-    av_bprintf(
-        &buf,
+    snprintf(buf, sizeof(buf),
         "G(%"PRId64",%"PRId64")B(%"PRId64",%"PRId64")R(%"PRId64",%"PRId64")"
         "WP(%"PRId64",%"PRId64")L(%"PRId64",%"PRId64")",
         av_rescale_q(1, mdcv->display_primaries[1][0], (AVRational){ 1, 50000 }),
@@ -202,28 +196,15 @@ static int handle_mdcv(const AVClass **avcl, const x265_api *api,
         av_rescale_q(1, mdcv->max_luminance,  (AVRational){ 1, 10000 }),
         av_rescale_q(1, mdcv->min_luminance,  (AVRational){ 1, 10000 }));
 
-    if (!av_bprint_is_complete(&buf)) {
-        av_log(avcl, AV_LOG_ERROR,
-          "MDCV string too long for its available space!\n");
-        ret = AVERROR(ENOMEM);
-        goto end;
-    }
-
-    if (api->param_parse(params, "master-display", buf.str) ==
+    if (api->param_parse(params, "master-display", buf) ==
             X265_PARAM_BAD_VALUE) {
         av_log(avcl, AV_LOG_ERROR,
                "Invalid value \"%s\" for param \"master-display\".\n",
-               buf.str);
-        ret = AVERROR(EINVAL);
-        goto end;
+               buf);
+        return AVERROR(EINVAL);
     }
 
-    ret = 0;
-
-end:
-    av_bprint_finalize(&buf, NULL);
-
-    return ret;
+    return 0;
 }
 
 static int handle_side_data(AVCodecContext *avctx, const x265_api *api,
-- 
2.40.1

_______________________________________________
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".

             reply	other threads:[~2024-03-22 13:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22 13:32 Andreas Rheinhardt [this message]
2024-03-22 13:33 ` [FFmpeg-devel] [PATCH 2/2] avcodec/libx265: Pass logctx as void*, not AVClass** Andreas Rheinhardt
2024-03-22 13:57 ` [FFmpeg-devel] [PATCH 3/4] avutil/frame: Constify av_frame_side_data_get() Andreas Rheinhardt
2024-03-22 13:58 ` [FFmpeg-devel] [PATCH 4/4] avutil/frame: Rename av_frame_side_data_get and add wrapper for it Andreas Rheinhardt
2024-03-22 14:41 ` [FFmpeg-devel] [PATCH 5/5] avutil/frame: Use av_realloc_array(), improve overflow check Andreas Rheinhardt
2024-03-22 22:07   ` Jan Ekström

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=GV1P250MB0737842CEA6E6DCA5F67FFB38F312@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git