[FFmpeg-cvslog] avcodec/mpegutils: Avoid allocations when using AVBPrint
Andreas Rheinhardt
git at videolan.org
Tue Mar 26 07:44:02 EET 2024
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sat Mar 23 13:01:11 2024 +0100| [5eda98f382103be8bc626fa36408b51a996b6518] | committer: Andreas Rheinhardt
avcodec/mpegutils: Avoid allocations when using AVBPrint
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5eda98f382103be8bc626fa36408b51a996b6518
---
libavcodec/mpegutils.c | 21 +++++----------------
1 file changed, 5 insertions(+), 16 deletions(-)
diff --git a/libavcodec/mpegutils.c b/libavcodec/mpegutils.c
index fc3e270631..7f499b3d0f 100644
--- a/libavcodec/mpegutils.c
+++ b/libavcodec/mpegutils.c
@@ -252,7 +252,6 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict,
if (avctx->debug & (FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)) {
int x,y;
AVBPrint buf;
- char *str = NULL;
int n;
int margin_left;
int x_step;
@@ -278,16 +277,11 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict,
x_step = (mb_width * 16 > 999) ? 8 : 4;
for (x = 0; x < mb_width; x += x_step)
av_bprintf(&buf, "%-*d", n * x_step, x << 4);
- n = av_bprint_finalize(&buf, &str);
- if (n < 0) {
- av_log(avctx, AV_LOG_ERROR, "%s failed, %s\n", __func__, av_err2str(n));
- return;
- }
- av_log(avctx, AV_LOG_DEBUG, "%s\n", str);
- av_freep(&str);
+
+ av_log(avctx, AV_LOG_DEBUG, "%s\n", buf.str);
for (y = 0; y < mb_height; y++) {
- av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
+ av_bprint_clear(&buf);
for (x = 0; x < mb_width; x++) {
if (x == 0)
av_bprintf(&buf, "%*d ", margin_left - 1, y << 4);
@@ -310,13 +304,8 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict,
}
}
- n = av_bprint_finalize(&buf, &str);
- if (n < 0) {
- av_log(avctx, AV_LOG_ERROR, "%s failed, %s\n", __func__, av_err2str(n));
- return;
- }
- av_log(avctx, AV_LOG_DEBUG, "%s\n", str);
- av_freep(&str);
+ av_log(avctx, AV_LOG_DEBUG, "%s\n", buf.str);
}
+ av_bprint_finalize(&buf, NULL);
}
}
More information about the ffmpeg-cvslog
mailing list