| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2015 James Almer | ||
| 3 | * | ||
| 4 | * This file is part of FFmpeg. | ||
| 5 | * | ||
| 6 | * FFmpeg is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License along | ||
| 17 | * with FFmpeg; if not, write to the Free Software Foundation, Inc., | ||
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <string.h> | ||
| 22 | #include "checkasm.h" | ||
| 23 | #include "libavcodec/alacdsp.h" | ||
| 24 | #include "libavcodec/mathops.h" | ||
| 25 | #include "libavutil/common.h" | ||
| 26 | #include "libavutil/internal.h" | ||
| 27 | #include "libavutil/mem_internal.h" | ||
| 28 | |||
| 29 | #define BUF_SIZE 256 | ||
| 30 | #define MAX_CHANNELS 2 | ||
| 31 | |||
| 32 | #define randomize_buffers() \ | ||
| 33 | do { \ | ||
| 34 | int i; \ | ||
| 35 | for (i = 0; i < BUF_SIZE*MAX_CHANNELS; i++) { \ | ||
| 36 | int32_t r = sign_extend(rnd(), 24); \ | ||
| 37 | ref_buf[i] = r; \ | ||
| 38 | new_buf[i] = r; \ | ||
| 39 | } \ | ||
| 40 | } while (0) | ||
| 41 | |||
| 42 | 14 | static void check_decorrelate_stereo(void) | |
| 43 | { | ||
| 44 | 14 | LOCAL_ALIGNED_16(int32_t, ref_buf, [BUF_SIZE*MAX_CHANNELS]); | |
| 45 | 14 | LOCAL_ALIGNED_16(int32_t, new_buf, [BUF_SIZE*MAX_CHANNELS]); | |
| 46 | 14 | int32_t *ref[2] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1] }; | |
| 47 | 14 | int32_t *new[2] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1] }; | |
| 48 | ALACDSPContext c; | ||
| 49 | |||
| 50 | 14 | ff_alacdsp_init(&c); | |
| 51 |
2/2✓ Branch 3 taken 2 times.
✓ Branch 4 taken 12 times.
|
14 | if (check_func(c.decorrelate_stereo, "alac_decorrelate_stereo")) { |
| 52 | 2 | int len = (rnd() & 0xFF) + 1; | |
| 53 | 2 | int shift = rnd() & 0x1F; | |
| 54 | 2 | int weight = rnd() & 0xFF; | |
| 55 | 2 | declare_func(void, int32_t *buf[2], int len, int shift, int weight); | |
| 56 | |||
| 57 |
2/2✓ Branch 1 taken 1024 times.
✓ Branch 2 taken 2 times.
|
1026 | randomize_buffers(); |
| 58 | 2 | call_ref(ref, len, shift, weight); | |
| 59 | 2 | call_new(new, len, shift, weight); | |
| 60 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (memcmp(ref[0], new[0], len * sizeof(int32_t)) || |
| 61 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | memcmp(ref[1], new[1], len * sizeof(int32_t))) |
| 62 | ✗ | fail(); | |
| 63 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
|
2 | bench_new(new, BUF_SIZE, shift, weight); |
| 64 | } | ||
| 65 | |||
| 66 | 14 | report("decorrelate_stereo"); | |
| 67 | 14 | } | |
| 68 | |||
| 69 | #undef randomize_buffers | ||
| 70 | #define randomize_buffers() \ | ||
| 71 | do { \ | ||
| 72 | int i, j; \ | ||
| 73 | for (i = 0; i < BUF_SIZE; i++) { \ | ||
| 74 | for (j = 0; j < ch; j++) { \ | ||
| 75 | int32_t r = sign_extend(rnd(), 24); \ | ||
| 76 | ref[j][i] = r; \ | ||
| 77 | new[j][i] = r; \ | ||
| 78 | r = rnd() & 0xFF; \ | ||
| 79 | ref_ebb[j][i] = r; \ | ||
| 80 | new_ebb[j][i] = r; \ | ||
| 81 | } \ | ||
| 82 | } \ | ||
| 83 | } while (0) | ||
| 84 | |||
| 85 | 14 | static void check_append_extra_bits(void) | |
| 86 | { | ||
| 87 | 14 | LOCAL_ALIGNED_16(int32_t, ref_buf, [BUF_SIZE*MAX_CHANNELS*2]); | |
| 88 | 14 | LOCAL_ALIGNED_16(int32_t, new_buf, [BUF_SIZE*MAX_CHANNELS*2]); | |
| 89 | 14 | int32_t *ref[2] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1] }; | |
| 90 | 14 | int32_t *new[2] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1] }; | |
| 91 | 14 | int32_t *ref_ebb[2] = { &ref_buf[BUF_SIZE*2], &ref_buf[BUF_SIZE*3] }; | |
| 92 | 14 | int32_t *new_ebb[2] = { &new_buf[BUF_SIZE*2], &new_buf[BUF_SIZE*3] }; | |
| 93 | ALACDSPContext c; | ||
| 94 | static const char * const channels[2] = { "mono", "stereo" }; | ||
| 95 | int ch; | ||
| 96 | |||
| 97 | 14 | ff_alacdsp_init(&c); | |
| 98 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 14 times.
|
42 | for (ch = 1; ch <= 2; ch++) { |
| 99 |
2/2✓ Branch 3 taken 4 times.
✓ Branch 4 taken 24 times.
|
28 | if (check_func(c.append_extra_bits[ch-1], "alac_append_extra_bits_%s", channels[ch-1])) { |
| 100 | 4 | int len = (rnd() & 0xFF) + 1; | |
| 101 | 4 | declare_func(void, int32_t *buf[2], int32_t *ebb[2], int ebits, int ch, int len); | |
| 102 | |||
| 103 |
4/4✓ Branch 2 taken 1536 times.
✓ Branch 3 taken 1024 times.
✓ Branch 4 taken 1024 times.
✓ Branch 5 taken 4 times.
|
2564 | randomize_buffers(); |
| 104 | 4 | call_ref(ref, ref_ebb, 8, ch, len); | |
| 105 | 4 | call_new(new, new_ebb, 8, ch, len); | |
| 106 |
3/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
|
4 | if ( memcmp(ref[0], new[0], len * sizeof(int32_t)) || |
| 107 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | (ch == 2 && memcmp(ref[1], new[1], len * sizeof(int32_t)))) |
| 108 | ✗ | fail(); | |
| 109 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
|
4 | bench_new(new, new_ebb, 8, ch, BUF_SIZE); |
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | 14 | report("append_extra_bits"); | |
| 114 | 14 | } | |
| 115 | |||
| 116 | 14 | void checkasm_check_alacdsp(void) | |
| 117 | { | ||
| 118 | 14 | check_decorrelate_stereo(); | |
| 119 | 14 | check_append_extra_bits(); | |
| 120 | 14 | } | |
| 121 |