From: mkver via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Cc: mkver <code@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH] avcodec/liblc3enc: Avoid allocating buffer to send a zero frame (PR #20633) Date: Tue, 30 Sep 2025 17:04:23 -0000 Message-ID: <175925186383.69.5409419678900483020@bf249f23a2c8> (raw) PR #20633 opened by mkver URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20633 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20633.patch liblc3 supports arbitrary strides, so one can simply use a stride of zero to make it read the same zero value again and again. >From 3bf38a3570673776249787228325a8c15bc020c6 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Tue, 30 Sep 2025 18:53:08 +0200 Subject: [PATCH] avcodec/liblc3enc: Avoid allocating buffer to send a zero frame liblc3 supports arbitrary strides, so one can simply use a stride of zero to make it read the same zero value again and again. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/liblc3enc.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/libavcodec/liblc3enc.c b/libavcodec/liblc3enc.c index 66007a90f3..72c117b993 100644 --- a/libavcodec/liblc3enc.c +++ b/libavcodec/liblc3enc.c @@ -137,7 +137,6 @@ static int liblc3_encode(AVCodecContext *avctx, AVPacket *pkt, LibLC3EncContext *liblc3 = avctx->priv_data; int block_bytes = liblc3->block_bytes; int channels = avctx->ch_layout.nb_channels; - void *zero_frame = NULL; uint8_t *data_ptr; int ret; @@ -152,25 +151,20 @@ static int liblc3_encode(AVCodecContext *avctx, AVPacket *pkt, return 0; liblc3->remaining_samples = 0; - zero_frame = av_mallocz(avctx->frame_size * sizeof(float)); - if (!zero_frame) - return AVERROR(ENOMEM); } data_ptr = pkt->data; for (int ch = 0; ch < channels; ch++) { - const float *pcm = zero_frame ? zero_frame : frame->data[ch]; + const float *pcm = frame ? (const float*)frame->data[ch] : (const float[]){ 0 }; + int stride = !!frame; // use a stride of zero to send a zero frame int nbytes = block_bytes / channels + (ch < block_bytes % channels); lc3_encode(liblc3->encoder[ch], - LC3_PCM_FORMAT_FLOAT, pcm, 1, nbytes, data_ptr); + LC3_PCM_FORMAT_FLOAT, pcm, stride, nbytes, data_ptr); data_ptr += nbytes; } - if (zero_frame) - av_free(zero_frame); - *got_packet_ptr = 1; return 0; -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2025-09-30 17:04 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=175925186383.69.5409419678900483020@bf249f23a2c8 \ --to=ffmpeg-devel@ffmpeg.org \ --cc=code@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 http://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/ http://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