This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit 5339fc6a514dc7800e50c26c4adb198929f7c06f Author: Ayoub Nabil Boubagrat <[email protected]> AuthorDate: Sat Sep 5 12:56:11 2026 +0200 Commit: michaelni <[email protected]> CommitDate: Wed Sep 9 18:06:23 2026 +0000 tests/ac3: cover bit allocation cover band boundaries, partial ranges and exponent limits before changing the bit allocation code. Signed-off-by: Ayoub Nabil Boubagrat <[email protected]> --- libavcodec/Makefile | 1 + libavcodec/tests/.gitignore | 1 + libavcodec/tests/ac3.c | 92 +++++++++++++++++++++++++++++++++++++++ tests/fate/libavcodec.mak | 4 ++ tests/ref/fate/ac3-bit-allocation | 4 ++ 5 files changed, 102 insertions(+) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 8535f460ab..4a8a06a796 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1382,6 +1382,7 @@ TESTPROGS = avcodec \ jpeg2000dwt \ mathops \ +TESTPROGS-$(CONFIG_AC3DSP) += ac3 TESTPROGS-$(CONFIG_APV_DECODER) += apv TESTPROGS-$(CONFIG_AV1_VAAPI_ENCODER) += av1_levels TESTPROGS-$(CONFIG_CABAC) += cabac diff --git a/libavcodec/tests/.gitignore b/libavcodec/tests/.gitignore index 04e1e2518b..4977c63e00 100644 --- a/libavcodec/tests/.gitignore +++ b/libavcodec/tests/.gitignore @@ -1,3 +1,4 @@ +/ac3 /apv /av1_levels /avcodec diff --git a/libavcodec/tests/ac3.c b/libavcodec/tests/ac3.c new file mode 100644 index 0000000000..c343e265f7 --- /dev/null +++ b/libavcodec/tests/ac3.c @@ -0,0 +1,92 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <inttypes.h> +#include <stdio.h> +#include <string.h> + +#include "libavutil/crc.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/lfg.h" +#include "libavutil/macros.h" +#include "libavcodec/ac3.h" +#include "libavcodec/ac3dsp.h" +#include "libavcodec/ac3tab.h" + +static uint32_t hash_int16(const AVCRC *crc, uint32_t hash, + const int16_t *data, int count) +{ + uint8_t bytes[2 * AC3_MAX_COEFS]; + + for (int i = 0; i < count; i++) + AV_WL16(bytes + 2 * i, data[i]); + return av_crc(crc, hash, bytes, 2 * count); +} + +int main(void) +{ + static const int ends[] = { 7, 27, 28, 29, 37, 73, 133, 229, 253 }; + static const int offsets[] = { -960, -959, 0, 1024, 3132 }; + const AVCRC *crc = av_crc_get_table(AV_CRC_32_IEEE); + int8_t exp[AC3_MAX_COEFS]; + int16_t psd[AC3_MAX_COEFS], band_psd[AC3_CRITICAL_BANDS]; + int16_t mask[AC3_CRITICAL_BANDS]; + uint8_t bap[AC3_MAX_COEFS]; + AC3DSPContext dsp; + AVLFG lfg; + + ff_ac3dsp_init(&dsp); + av_lfg_init(&lfg, 1); + for (int i = 0; i < AC3_CRITICAL_BANDS; i++) + mask[i] = av_lfg_get(&lfg) % 3073; + + for (int pattern = 0; pattern < 4; pattern++) { + uint32_t psd_hash = 0, bap_hash = 0; + + for (int i = 0; i < AC3_MAX_COEFS; i++) + exp[i] = pattern == 0 ? 0 : pattern == 1 ? 24 : + pattern == 2 ? (i & 1) * 24 : av_lfg_get(&lfg) % 25; + + for (int start = 0; start < 253; start++) { + for (int j = 0; j <= FF_ARRAY_ELEMS(ends); j++) { + int end = j ? ends[j - 1] : start + 1; + + if (start >= end) + continue; + memset(psd, 0x5a, sizeof(psd)); + memset(band_psd, 0x5a, sizeof(band_psd)); + ff_ac3_bit_alloc_calc_psd(exp, start, end, psd, band_psd); + psd_hash = hash_int16(crc, psd_hash, psd, AC3_MAX_COEFS); + psd_hash = hash_int16(crc, psd_hash, band_psd, AC3_CRITICAL_BANDS); + + for (int floor = 0; floor < 8; floor++) { + for (int k = 0; k < FF_ARRAY_ELEMS(offsets); k++) { + memset(bap, 0x5a, sizeof(bap)); + dsp.bit_alloc_calc_bap(mask, psd, start, end, + offsets[k], ff_ac3_floor_tab[floor], + ff_ac3_bap_tab, bap); + bap_hash = av_crc(crc, bap_hash, bap, sizeof(bap)); + } + } + } + } + printf("pattern %d: psd %08"PRIx32" bap %08"PRIx32"\n", + pattern, psd_hash, bap_hash); + } + return 0; +} diff --git a/tests/fate/libavcodec.mak b/tests/fate/libavcodec.mak index e2d616e307..f6858c4921 100644 --- a/tests/fate/libavcodec.mak +++ b/tests/fate/libavcodec.mak @@ -1,3 +1,7 @@ +FATE_LIBAVCODEC-$(CONFIG_AC3DSP) += fate-ac3-bit-allocation +fate-ac3-bit-allocation: libavcodec/tests/ac3$(EXESUF) +fate-ac3-bit-allocation: CMD = run libavcodec/tests/ac3$(EXESUF) + FATE_LIBAVCODEC-$(CONFIG_AV1_VAAPI_ENCODER) += fate-av1-levels fate-av1-levels: libavcodec/tests/av1_levels$(EXESUF) fate-av1-levels: CMD = run libavcodec/tests/av1_levels$(EXESUF) diff --git a/tests/ref/fate/ac3-bit-allocation b/tests/ref/fate/ac3-bit-allocation new file mode 100644 index 0000000000..faa4d1bb39 --- /dev/null +++ b/tests/ref/fate/ac3-bit-allocation @@ -0,0 +1,4 @@ +pattern 0: psd 849e1ac4 bap e81b62f5 +pattern 1: psd 8443966b bap 9175e8d9 +pattern 2: psd 6713433c bap 9aed758b +pattern 3: psd 129b9438 bap 0f3be9c7 -- To stop receiving notification emails like this one, please contact [email protected]. _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
