| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU Lesser General Public | ||
| 6 | * License as published by the Free Software Foundation; either | ||
| 7 | * version 2.1 of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public | ||
| 15 | * License along with FFmpeg; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <inttypes.h> | ||
| 20 | #include <stdio.h> | ||
| 21 | #include <string.h> | ||
| 22 | |||
| 23 | #include "libavutil/crc.h" | ||
| 24 | #include "libavutil/intreadwrite.h" | ||
| 25 | #include "libavutil/lfg.h" | ||
| 26 | #include "libavutil/macros.h" | ||
| 27 | #include "libavcodec/ac3.h" | ||
| 28 | #include "libavcodec/ac3dsp.h" | ||
| 29 | #include "libavcodec/ac3tab.h" | ||
| 30 | |||
| 31 | 8552 | static uint32_t hash_int16(const AVCRC *crc, uint32_t hash, | |
| 32 | const int16_t *data, int count) | ||
| 33 | { | ||
| 34 | uint8_t bytes[2 * AC3_MAX_COEFS]; | ||
| 35 | |||
| 36 |
2/2✓ Branch 0 taken 1308456 times.
✓ Branch 1 taken 8552 times.
|
1317008 | for (int i = 0; i < count; i++) |
| 37 | 1308456 | AV_WL16(bytes + 2 * i, data[i]); | |
| 38 | 8552 | return av_crc(crc, hash, bytes, 2 * count); | |
| 39 | } | ||
| 40 | |||
| 41 | 1 | int main(void) | |
| 42 | { | ||
| 43 | static const int ends[] = { 7, 27, 28, 29, 37, 73, 133, 229, 253 }; | ||
| 44 | static const int offsets[] = { -960, -959, 0, 1024, 3132 }; | ||
| 45 | 1 | const AVCRC *crc = av_crc_get_table(AV_CRC_32_IEEE); | |
| 46 | int8_t exp[AC3_MAX_COEFS]; | ||
| 47 | int16_t psd[AC3_MAX_COEFS], band_psd[AC3_CRITICAL_BANDS]; | ||
| 48 | int16_t mask[AC3_CRITICAL_BANDS]; | ||
| 49 | uint8_t bap[AC3_MAX_COEFS]; | ||
| 50 | AC3DSPContext dsp; | ||
| 51 | AVLFG lfg; | ||
| 52 | |||
| 53 | 1 | ff_ac3dsp_init(&dsp); | |
| 54 | 1 | av_lfg_init(&lfg, 1); | |
| 55 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 1 times.
|
51 | for (int i = 0; i < AC3_CRITICAL_BANDS; i++) |
| 56 | 50 | mask[i] = av_lfg_get(&lfg) % 3073; | |
| 57 | |||
| 58 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (int pattern = 0; pattern < 4; pattern++) { |
| 59 | 4 | uint32_t psd_hash = 0, bap_hash = 0; | |
| 60 | |||
| 61 |
2/2✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 4 times.
|
1028 | for (int i = 0; i < AC3_MAX_COEFS; i++) |
| 62 |
6/6✓ Branch 0 taken 768 times.
✓ Branch 1 taken 256 times.
✓ Branch 2 taken 512 times.
✓ Branch 3 taken 256 times.
✓ Branch 4 taken 256 times.
✓ Branch 5 taken 256 times.
|
1280 | exp[i] = pattern == 0 ? 0 : pattern == 1 ? 24 : |
| 63 | 256 | pattern == 2 ? (i & 1) * 24 : av_lfg_get(&lfg) % 25; | |
| 64 | |||
| 65 |
2/2✓ Branch 0 taken 1012 times.
✓ Branch 1 taken 4 times.
|
1016 | for (int start = 0; start < 253; start++) { |
| 66 |
2/2✓ Branch 0 taken 10120 times.
✓ Branch 1 taken 1012 times.
|
11132 | for (int j = 0; j <= FF_ARRAY_ELEMS(ends); j++) { |
| 67 |
2/2✓ Branch 0 taken 9108 times.
✓ Branch 1 taken 1012 times.
|
10120 | int end = j ? ends[j - 1] : start + 1; |
| 68 | |||
| 69 |
2/2✓ Branch 0 taken 5844 times.
✓ Branch 1 taken 4276 times.
|
10120 | if (start >= end) |
| 70 | 5844 | continue; | |
| 71 | 4276 | memset(psd, 0x5a, sizeof(psd)); | |
| 72 | 4276 | memset(band_psd, 0x5a, sizeof(band_psd)); | |
| 73 | 4276 | ff_ac3_bit_alloc_calc_psd(exp, start, end, psd, band_psd); | |
| 74 | 4276 | psd_hash = hash_int16(crc, psd_hash, psd, AC3_MAX_COEFS); | |
| 75 | 4276 | psd_hash = hash_int16(crc, psd_hash, band_psd, AC3_CRITICAL_BANDS); | |
| 76 | |||
| 77 |
2/2✓ Branch 0 taken 34208 times.
✓ Branch 1 taken 4276 times.
|
38484 | for (int floor = 0; floor < 8; floor++) { |
| 78 |
2/2✓ Branch 0 taken 171040 times.
✓ Branch 1 taken 34208 times.
|
205248 | for (int k = 0; k < FF_ARRAY_ELEMS(offsets); k++) { |
| 79 | 171040 | memset(bap, 0x5a, sizeof(bap)); | |
| 80 | 171040 | dsp.bit_alloc_calc_bap(mask, psd, start, end, | |
| 81 | 171040 | offsets[k], ff_ac3_floor_tab[floor], | |
| 82 | ff_ac3_bap_tab, bap); | ||
| 83 | 171040 | bap_hash = av_crc(crc, bap_hash, bap, sizeof(bap)); | |
| 84 | } | ||
| 85 | } | ||
| 86 | } | ||
| 87 | } | ||
| 88 | 4 | printf("pattern %d: psd %08"PRIx32" bap %08"PRIx32"\n", | |
| 89 | pattern, psd_hash, bap_hash); | ||
| 90 | } | ||
| 91 | 1 | return 0; | |
| 92 | } | ||
| 93 |