From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 4/7] avcodec/mpegvideo: Allocate map and score_map buffers jointly Date: Wed, 26 Oct 2022 04:01:45 +0200 Message-ID: <AS8P250MB074433A9F7DBC7363E9D8E798F309@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw) In-Reply-To: <AS8P250MB0744149DC87FAB32814CAF938F2E9@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> Reduces the amounts of allocs, frees and allocation checks. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/mpegvideo.c | 7 ++++--- libavcodec/snow.c | 1 - libavcodec/snowenc.c | 6 +++--- libavcodec/svq1enc.c | 8 +++----- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 0cd7c86ff6..a04d519ccc 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -373,9 +373,10 @@ static int init_duplicate_context(MpegEncContext *s) yc_size += 2*s->b8_stride + 2*s->mb_stride; if (s->encoding) { - if (!FF_ALLOCZ_TYPED_ARRAY(s->me.map, ME_MAP_SIZE) || - !FF_ALLOCZ_TYPED_ARRAY(s->me.score_map, ME_MAP_SIZE)) + s->me.map = av_mallocz(2 * ME_MAP_SIZE * sizeof(*s->me.map)); + if (!s->me.map) return AVERROR(ENOMEM); + s->me.score_map = s->me.map + ME_MAP_SIZE; if (s->noise_reduction) { if (!FF_ALLOCZ_TYPED_ARRAY(s->dct_error_sum, 2)) @@ -445,7 +446,7 @@ static void free_duplicate_context(MpegEncContext *s) av_freep(&s->dct_error_sum); av_freep(&s->me.map); - av_freep(&s->me.score_map); + s->me.score_map = NULL; av_freep(&s->blocks); av_freep(&s->ac_val_base); s->block = NULL; diff --git a/libavcodec/snow.c b/libavcodec/snow.c index cde09902c3..b6c8d5e256 100644 --- a/libavcodec/snow.c +++ b/libavcodec/snow.c @@ -635,7 +635,6 @@ av_cold void ff_snow_common_end(SnowContext *s) s->m.me.temp= NULL; av_freep(&s->m.me.scratchpad); av_freep(&s->m.me.map); - av_freep(&s->m.me.score_map); av_freep(&s->m.sc.obmc_scratchpad); av_freep(&s->block); diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c index ada24f7895..7fad95b69a 100644 --- a/libavcodec/snowenc.c +++ b/libavcodec/snowenc.c @@ -82,11 +82,11 @@ static av_cold int encode_init(AVCodecContext *avctx) s->m.me.temp = s->m.me.scratchpad = av_calloc(avctx->width + 64, 2*16*2*sizeof(uint8_t)); - s->m.me.map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); - s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); s->m.sc.obmc_scratchpad= av_mallocz(MB_SIZE*MB_SIZE*12*sizeof(uint32_t)); - if (!s->m.me.scratchpad || !s->m.me.map || !s->m.me.score_map || !s->m.sc.obmc_scratchpad) + s->m.me.map = av_mallocz(2 * ME_MAP_SIZE * sizeof(*s->m.me.map)); + if (!s->m.me.scratchpad || !s->m.me.map || !s->m.sc.obmc_scratchpad) return AVERROR(ENOMEM); + s->m.me.score_map = s->m.me.map + ME_MAP_SIZE; ff_h263_encode_init(&s->m); //mv_penalty diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c index 7c9430a137..92f91aeebd 100644 --- a/libavcodec/svq1enc.c +++ b/libavcodec/svq1enc.c @@ -552,7 +552,6 @@ static av_cold int svq1_encode_end(AVCodecContext *avctx) av_freep(&s->m.me.scratchpad); av_freep(&s->m.me.map); - av_freep(&s->m.me.score_map); av_freep(&s->mb_type); av_freep(&s->dummy); av_freep(&s->scratchbuf); @@ -608,18 +607,17 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx) s->m.me.temp = s->m.me.scratchpad = av_mallocz((avctx->width + 64) * 2 * 16 * 2 * sizeof(uint8_t)); - s->m.me.map = av_mallocz(ME_MAP_SIZE * sizeof(uint32_t)); - s->m.me.score_map = av_mallocz(ME_MAP_SIZE * sizeof(uint32_t)); s->mb_type = av_mallocz((s->y_block_width + 1) * s->y_block_height * sizeof(int16_t)); s->dummy = av_mallocz((s->y_block_width + 1) * s->y_block_height * sizeof(int32_t)); + s->m.me.map = av_mallocz(2 * ME_MAP_SIZE * sizeof(*s->m.me.map)); s->svq1encdsp.ssd_int8_vs_int16 = ssd_int8_vs_int16_c; if (!s->m.me.temp || !s->m.me.scratchpad || !s->m.me.map || - !s->m.me.score_map || !s->mb_type || !s->dummy) { + !s->mb_type || !s->dummy) return AVERROR(ENOMEM); - } + s->m.me.score_map = s->m.me.map + ME_MAP_SIZE; #if ARCH_PPC ff_svq1enc_init_ppc(&s->svq1encdsp); -- 2.34.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".
next prev parent reply other threads:[~2022-10-26 2:02 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-10-24 2:21 [FFmpeg-devel] [PATCH 1/2] avcodec/mpegvideo: Don't initialize H264Chroma ctx unnecessarily Andreas Rheinhardt 2022-10-24 2:22 ` [FFmpeg-devel] [PATCH 2/2] configure: Remove unnecessary mpeg[12]video_enc->h263dsp dependencies Andreas Rheinhardt 2022-10-26 2:01 ` [FFmpeg-devel] [PATCH 3/7] avcodec/mpegvideo: Don't overallocate buffer Andreas Rheinhardt 2022-10-28 13:53 ` Andreas Rheinhardt 2022-10-26 2:01 ` Andreas Rheinhardt [this message] 2022-10-26 2:01 ` [FFmpeg-devel] [PATCH 5/7] avcodec/msmpeg4dec: Move setting decode_mb for WMV2 to wmv2dec.c Andreas Rheinhardt 2022-10-26 2:01 ` [FFmpeg-devel] [PATCH 6/7] avcodec/mpegvideo: Remove always-false check Andreas Rheinhardt 2022-10-26 2:01 ` [FFmpeg-devel] [PATCH 7/7] avcodec/mpegvideo: Remove incorrect comment Andreas Rheinhardt 2022-10-26 23:33 ` [FFmpeg-devel] [PATCH 1/2] avcodec/mpegvideo: Don't initialize H264Chroma ctx unnecessarily Andreas Rheinhardt
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=AS8P250MB074433A9F7DBC7363E9D8E798F309@AS8P250MB0744.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