mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2026-03-13 09:00:40 +08:00
avcodec/liblc3{dec,enc}: Simplify sample_size, is_planar check
Sample size is always sizeof(float), is planar is a simple if given that these codecs only support float and planar float. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@@ -123,8 +123,6 @@ static int liblc3_decode(AVCodecContext *avctx, AVFrame *frame,
|
||||
int channels = avctx->ch_layout.nb_channels;
|
||||
uint8_t *in = avpkt->data;
|
||||
int block_bytes, ret;
|
||||
size_t sample_size;
|
||||
int is_planar;
|
||||
|
||||
frame->nb_samples = av_rescale(
|
||||
liblc3->frame_us, liblc3->srate_hz, 1000*1000);
|
||||
@@ -132,13 +130,12 @@ static int liblc3_decode(AVCodecContext *avctx, AVFrame *frame,
|
||||
return ret;
|
||||
|
||||
block_bytes = avpkt->size;
|
||||
is_planar = av_sample_fmt_is_planar(avctx->sample_fmt);
|
||||
sample_size = av_get_bytes_per_sample(avctx->sample_fmt);
|
||||
int is_planar = avctx->sample_fmt == AV_SAMPLE_FMT_FLTP;
|
||||
|
||||
for (int ch = 0; ch < channels; ch++) {
|
||||
int nbytes = block_bytes / channels + (ch < block_bytes % channels);
|
||||
void *pcm_data = is_planar ? frame->extended_data[ch] :
|
||||
frame->extended_data[0] + ch * sample_size;
|
||||
float *pcm_data = is_planar ? (float*)frame->extended_data[ch] :
|
||||
(float*)frame->extended_data[0] + ch;
|
||||
int stride = is_planar ? 1 : channels;
|
||||
|
||||
ret = lc3_decode(liblc3->decoder[ch], in, nbytes,
|
||||
|
||||
@@ -138,13 +138,8 @@ static int liblc3_encode(AVCodecContext *avctx, AVPacket *pkt,
|
||||
int block_bytes = liblc3->block_bytes;
|
||||
int channels = avctx->ch_layout.nb_channels;
|
||||
uint8_t *data_ptr;
|
||||
size_t sample_size;
|
||||
int is_planar;
|
||||
int ret;
|
||||
|
||||
is_planar = av_sample_fmt_is_planar(avctx->sample_fmt);
|
||||
sample_size = av_get_bytes_per_sample(avctx->sample_fmt);
|
||||
|
||||
if ((ret = ff_get_encode_buffer(avctx, pkt, block_bytes, 0)) < 0)
|
||||
return ret;
|
||||
|
||||
@@ -158,14 +153,16 @@ static int liblc3_encode(AVCodecContext *avctx, AVPacket *pkt,
|
||||
liblc3->remaining_samples = 0;
|
||||
}
|
||||
|
||||
int is_planar = avctx->sample_fmt == AV_SAMPLE_FMT_FLTP;
|
||||
|
||||
data_ptr = pkt->data;
|
||||
for (int ch = 0; ch < channels; ch++) {
|
||||
int nbytes = block_bytes / channels + (ch < block_bytes % channels);
|
||||
|
||||
const void *pcm = frame ?
|
||||
(is_planar ? frame->data[ch] :
|
||||
frame->data[0] + ch * sample_size) :
|
||||
(const void *)(const float[]){ 0 };
|
||||
const float *pcm = frame ?
|
||||
(is_planar ? (const float*)frame->data[ch] :
|
||||
(const float*)frame->data[0] + ch) :
|
||||
(const float[]){ 0 };
|
||||
|
||||
int stride = frame ? (is_planar ? 1 : channels) : 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user