You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-10-06 05:47:18 +02:00
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>
This commit is contained in:
@@ -137,7 +137,6 @@ static int liblc3_encode(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
LibLC3EncContext *liblc3 = avctx->priv_data;
|
LibLC3EncContext *liblc3 = avctx->priv_data;
|
||||||
int block_bytes = liblc3->block_bytes;
|
int block_bytes = liblc3->block_bytes;
|
||||||
int channels = avctx->ch_layout.nb_channels;
|
int channels = avctx->ch_layout.nb_channels;
|
||||||
void *zero_frame = NULL;
|
|
||||||
uint8_t *data_ptr;
|
uint8_t *data_ptr;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@@ -152,25 +151,20 @@ static int liblc3_encode(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
liblc3->remaining_samples = 0;
|
liblc3->remaining_samples = 0;
|
||||||
zero_frame = av_mallocz(avctx->frame_size * sizeof(float));
|
|
||||||
if (!zero_frame)
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data_ptr = pkt->data;
|
data_ptr = pkt->data;
|
||||||
for (int ch = 0; ch < channels; ch++) {
|
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);
|
int nbytes = block_bytes / channels + (ch < block_bytes % channels);
|
||||||
|
|
||||||
lc3_encode(liblc3->encoder[ch],
|
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;
|
data_ptr += nbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zero_frame)
|
|
||||||
av_free(zero_frame);
|
|
||||||
|
|
||||||
*got_packet_ptr = 1;
|
*got_packet_ptr = 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user