History

avcodec/libx265: Don't use AVBPrint unnecessarily

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.

Andreas Rheinhardt committed 2 years ago

Commit 244db711 parent c7716431 file · +6 −25Browse files

Unified · Split

libavcodec/libx265.c+6−25
@@ -28,17 +28,14 @@ · 27 unmodified lines
2828 #include <float.h>
2929
3030 #include "libavutil/avassert.h"
31−#include "libavutil/bprint.h"
3231 #include "libavutil/buffer.h"
3332 #include "libavutil/internal.h"
34−#include "libavutil/common.h"
3533 #include "libavutil/mastering_display_metadata.h"
3634 #include "libavutil/opt.h"
3735 #include "libavutil/pixdesc.h"
3836 #include "avcodec.h"
3937 #include "codec_internal.h"
4038 #include "encode.h"
41−#include "internal.h"
4239 #include "packet_internal.h"
4340 #include "atsc_a53.h"
4441 #include "sei.h"
@@ -182,13 +179,10 @@ static int handle_mdcv(const AVClass **avcl, const x265_api *api, · 137 unmodified lines
182179 x265_param *params,
183180 const AVMasteringDisplayMetadata *mdcv)
184181 {
185− int ret = AVERROR_BUG;
186− AVBPrint buf;
187− av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
182+ char buf[10 /* # of PRId64s */ * 20 /* max strlen for %PRId64 */ + sizeof("G(,)B(,)R(,)WP(,)L(,)")];
188183
189184 // G(%hu,%hu)B(%hu,%hu)R(%hu,%hu)WP(%hu,%hu)L(%u,%u)
190− av_bprintf(
191− &buf,
185+ snprintf(buf, sizeof(buf),
192186 "G(%"PRId64",%"PRId64")B(%"PRId64",%"PRId64")R(%"PRId64",%"PRId64")"
193187 "WP(%"PRId64",%"PRId64")L(%"PRId64",%"PRId64")",
194188 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, · 7 unmodified lines
202196 av_rescale_q(1, mdcv->max_luminance, (AVRational){ 1, 10000 }),
203197 av_rescale_q(1, mdcv->min_luminance, (AVRational){ 1, 10000 }));
204198
205− if (!av_bprint_is_complete(&buf)) {
206− av_log(avcl, AV_LOG_ERROR,
207− "MDCV string too long for its available space!\n");
208− ret = AVERROR(ENOMEM);
209− goto end;
210− }
211−
212− if (api->param_parse(params, "master-display", buf.str) ==
199+ if (api->param_parse(params, "master-display", buf) ==
213200 X265_PARAM_BAD_VALUE) {
214201 av_log(avcl, AV_LOG_ERROR,
215202 "Invalid value \"%s\" for param \"master-display\".\n",
216− buf.str);
217− ret = AVERROR(EINVAL);
218− goto end;
203+ buf);
204+ return AVERROR(EINVAL);
219205 }
220206
221− ret = 0;
222−
223−end:
224− av_bprint_finalize(&buf, NULL);
225−
226− return ret;
207+ return 0;
227208 }
228209
229210 static int handle_side_data(AVCodecContext *avctx, const x265_api *api,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t