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 2/3] avcodec/flacenc: Don't copy buffer if avoidable
Date: Tue, 27 Dec 2022 23:47:38 +0100
Message-ID: <GV1P250MB0737FCD3267CA4FC2CD6945E8FED9@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <GV1P250MB073744E0C70DD7FFE1268A208FED9@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM>

It is avoidable for 32-bit FLAC on little endian hardware.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/flacenc.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index bf5d12facb..adaaa77b79 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -1573,22 +1573,22 @@ static int write_frame(FlacEncodeContext *s, AVPacket *avpkt)
 
 static int update_md5_sum(FlacEncodeContext *s, const void *samples)
 {
-    const uint8_t *buf;
+    const uint8_t *buf = samples;
     int buf_size = s->frame.blocksize * s->channels *
                    ((s->avctx->bits_per_raw_sample + 7) / 8);
 
-    if (s->avctx->bits_per_raw_sample > 16 || HAVE_BIGENDIAN) {
+    if (HAVE_BIGENDIAN ||
+        s->avctx->bits_per_raw_sample > 16 && s->avctx->bits_per_raw_sample <= 24) {
         av_fast_malloc(&s->md5_buffer, &s->md5_buffer_size, buf_size);
         if (!s->md5_buffer)
             return AVERROR(ENOMEM);
+        buf = s->md5_buffer;
     }
 
     if (s->avctx->bits_per_raw_sample <= 16) {
-        buf = (const uint8_t *)samples;
 #if HAVE_BIGENDIAN
         s->bdsp.bswap16_buf((uint16_t *) s->md5_buffer,
                             samples, buf_size / 2);
-        buf = s->md5_buffer;
 #endif
     } else if (s->avctx->bits_per_raw_sample <= 24) {
         int i;
@@ -1599,16 +1599,12 @@ static int update_md5_sum(FlacEncodeContext *s, const void *samples)
             int32_t v = samples0[i] >> 8;
             AV_WL24(tmp + 3*i, v);
         }
-        buf = s->md5_buffer;
     } else {
         /* s->avctx->bits_per_raw_sample <= 32 */
-        int i;
-        const int32_t *samples0 = samples;
-        uint8_t *tmp            = s->md5_buffer;
-
-        for (i = 0; i < s->frame.blocksize * s->channels; i++)
-            AV_WL32(tmp + 4*i, samples0[i]);
-        buf = s->md5_buffer;
+#if HAVE_BIGENDIAN
+        s->bdsp.bswap_buf((uint32_t *) s->md5_buffer,
+                          samples, s->frame.blocksize * s->channels);
+#endif
     }
     av_md5_update(s->md5ctx, buf, buf_size);
 
-- 
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".

  reply	other threads:[~2022-12-27 22:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-27 22:41 [FFmpeg-devel] [PATCH 1/3] avcodec/bswapdsp: Don't presume src to be naturally aligned Andreas Rheinhardt
2022-12-27 22:47 ` Andreas Rheinhardt [this message]
2022-12-27 22:47 ` [FFmpeg-devel] [PATCH 3/3] avcodec/flacenc: Don't reload bits_per_raw_sample 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=GV1P250MB0737FCD3267CA4FC2CD6945E8FED9@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