diff options
author | Paul B Mahol <onemda@gmail.com> | 2023-09-04 14:13:45 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2023-09-04 14:16:57 +0200 |
commit | c4ab17a62dedba74a2fd8221a8346d4a403813a1 (patch) | |
tree | 97635c5baded3693bf439978cb9cb4a80c497f7a /libavcodec/osq.c | |
parent | 87b8c1081959e45ffdcbabb3d53ac9882ef2b5ce (diff) | |
download | ffmpeg-c4ab17a62dedba74a2fd8221a8346d4a403813a1.tar.gz |
avcodec/osq: improve 32bit sample format decoding
Diffstat (limited to 'libavcodec/osq.c')
-rw-r--r-- | libavcodec/osq.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/libavcodec/osq.c b/libavcodec/osq.c index ac091ebc3d..df9099f20f 100644 --- a/libavcodec/osq.c +++ b/libavcodec/osq.c @@ -50,6 +50,7 @@ typedef struct OSQContext { size_t max_framesize; size_t bitstream_size; + int factor; int decorrelate; int frame_samples; uint64_t nb_samples; @@ -97,16 +98,19 @@ static av_cold int osq_init(AVCodecContext *avctx) if (avctx->ch_layout.nb_channels > FF_ARRAY_ELEMS(s->decode_buffer)) return AVERROR_INVALIDDATA; + s->factor = 1; switch (avctx->extradata[2]) { case 8: avctx->sample_fmt = AV_SAMPLE_FMT_U8P; break; case 16: avctx->sample_fmt = AV_SAMPLE_FMT_S16P; break; case 20: case 24: case 28: - case 32: avctx->sample_fmt = AV_SAMPLE_FMT_S32P; break; + case 32: s->factor = 1 << (32 - avctx->extradata[2]); + avctx->sample_fmt = AV_SAMPLE_FMT_S32P; break; default: return AVERROR_INVALIDDATA; } + avctx->bits_per_raw_sample = avctx->extradata[2]; s->nb_samples = AV_RL64(avctx->extradata + 16); s->frame_samples = AV_RL16(avctx->extradata + 8); s->max_framesize = (s->frame_samples * 16 + 1024) * avctx->ch_layout.nb_channels; @@ -339,7 +343,9 @@ static int do_decode(AVCodecContext *avctx, AVFrame *frame, int decorrelate, int static int osq_decode_block(AVCodecContext *avctx, AVFrame *frame) { const int nb_channels = avctx->ch_layout.nb_channels; + const int nb_samples = frame->nb_samples; OSQContext *s = avctx->priv_data; + const int factor = s->factor; int ret, decorrelate, downsample; GetBitContext *gb = &s->gb; @@ -365,7 +371,7 @@ static int osq_decode_block(AVCodecContext *avctx, AVFrame *frame) uint8_t *dst = (uint8_t *)frame->extended_data[ch]; int32_t *src = s->decode_buffer[ch] + OFFSET; - for (int n = 0; n < frame->nb_samples; n++) + for (int n = 0; n < nb_samples; n++) dst[n] = av_clip_uint8(src[n] + 0x80); } break; @@ -374,7 +380,7 @@ static int osq_decode_block(AVCodecContext *avctx, AVFrame *frame) int16_t *dst = (int16_t *)frame->extended_data[ch]; int32_t *src = s->decode_buffer[ch] + OFFSET; - for (int n = 0; n < frame->nb_samples; n++) + for (int n = 0; n < nb_samples; n++) dst[n] = (int16_t)src[n]; } break; @@ -383,8 +389,8 @@ static int osq_decode_block(AVCodecContext *avctx, AVFrame *frame) int32_t *dst = (int32_t *)frame->extended_data[ch]; int32_t *src = s->decode_buffer[ch] + OFFSET; - for (int n = 0; n < frame->nb_samples; n++) - dst[n] = src[n]; + for (int n = 0; n < nb_samples; n++) + dst[n] = src[n] * factor; } break; default: |