| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2015 Henrik Gramner | ||
| 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/codec_id.h" | ||
| 24 | #include "libavcodec/h264pred.h" | ||
| 25 | #include "libavutil/common.h" | ||
| 26 | #include "libavutil/internal.h" | ||
| 27 | #include "libavutil/intreadwrite.h" | ||
| 28 | #include "libavutil/mem_internal.h" | ||
| 29 | |||
| 30 | static const int codec_ids[4] = { AV_CODEC_ID_H264, AV_CODEC_ID_VP8, AV_CODEC_ID_RV40, AV_CODEC_ID_SVQ3 }; | ||
| 31 | |||
| 32 | static const char * const pred4x4_modes[4][15] = { | ||
| 33 | { /* H.264 */ | ||
| 34 | [VERT_PRED ] = "vertical", | ||
| 35 | [HOR_PRED ] = "horizontal", | ||
| 36 | [DC_PRED ] = "dc", | ||
| 37 | [DIAG_DOWN_LEFT_PRED ] = "down_left", | ||
| 38 | [DIAG_DOWN_RIGHT_PRED] = "down_right", | ||
| 39 | [VERT_RIGHT_PRED ] = "vertical_right", | ||
| 40 | [HOR_DOWN_PRED ] = "horizontal_right", | ||
| 41 | [VERT_LEFT_PRED ] = "vertical_left", | ||
| 42 | [HOR_UP_PRED ] = "horizontal_up", | ||
| 43 | [LEFT_DC_PRED ] = "left_dc", | ||
| 44 | [TOP_DC_PRED ] = "top_dc", | ||
| 45 | [DC_128_PRED ] = "dc_128", | ||
| 46 | }, | ||
| 47 | { /* VP8 */ | ||
| 48 | [VERT_PRED ] = "vertical_vp8", | ||
| 49 | [HOR_PRED ] = "horizontal_vp8", | ||
| 50 | [VERT_LEFT_PRED] = "vertical_left_vp8", | ||
| 51 | [TM_VP8_PRED ] = "tm_vp8", | ||
| 52 | [DC_127_PRED ] = "dc_127_vp8", | ||
| 53 | [DC_129_PRED ] = "dc_129_vp8", | ||
| 54 | }, | ||
| 55 | { /* RV40 */ | ||
| 56 | [DIAG_DOWN_LEFT_PRED ] = "down_left_rv40", | ||
| 57 | [VERT_LEFT_PRED ] = "vertical_left_rv40", | ||
| 58 | [HOR_UP_PRED ] = "horizontal_up_rv40", | ||
| 59 | [DIAG_DOWN_LEFT_PRED_RV40_NODOWN] = "down_left_nodown_rv40", | ||
| 60 | [HOR_UP_PRED_RV40_NODOWN ] = "horizontal_up_nodown_rv40", | ||
| 61 | [VERT_LEFT_PRED_RV40_NODOWN ] = "vertical_left_nodown_rv40", | ||
| 62 | }, | ||
| 63 | { /* SVQ3 */ | ||
| 64 | [DIAG_DOWN_LEFT_PRED] = "down_left_svq3", | ||
| 65 | }, | ||
| 66 | }; | ||
| 67 | |||
| 68 | static const char * const pred8x8_modes[4][11] = { | ||
| 69 | { /* H.264 */ | ||
| 70 | [DC_PRED8x8 ] = "dc", | ||
| 71 | [HOR_PRED8x8 ] = "horizontal", | ||
| 72 | [VERT_PRED8x8 ] = "vertical", | ||
| 73 | [PLANE_PRED8x8 ] = "plane", | ||
| 74 | [LEFT_DC_PRED8x8 ] = "left_dc", | ||
| 75 | [TOP_DC_PRED8x8 ] = "top_dc", | ||
| 76 | [DC_128_PRED8x8 ] = "dc_128", | ||
| 77 | [ALZHEIMER_DC_L0T_PRED8x8] = "mad_cow_dc_l0t", | ||
| 78 | [ALZHEIMER_DC_0LT_PRED8x8] = "mad_cow_dc_0lt", | ||
| 79 | [ALZHEIMER_DC_L00_PRED8x8] = "mad_cow_dc_l00", | ||
| 80 | [ALZHEIMER_DC_0L0_PRED8x8] = "mad_cow_dc_0l0", | ||
| 81 | }, | ||
| 82 | { /* VP8 */ | ||
| 83 | [PLANE_PRED8x8 ] = "tm_vp8", | ||
| 84 | [DC_127_PRED8x8] = "dc_127_vp8", | ||
| 85 | [DC_129_PRED8x8] = "dc_129_vp8", | ||
| 86 | }, | ||
| 87 | { /* RV40 */ | ||
| 88 | [DC_PRED8x8 ] = "dc_rv40", | ||
| 89 | [LEFT_DC_PRED8x8] = "left_dc_rv40", | ||
| 90 | [TOP_DC_PRED8x8 ] = "top_dc_rv40", | ||
| 91 | }, | ||
| 92 | /* nothing for SVQ3 */ | ||
| 93 | }; | ||
| 94 | |||
| 95 | static const char * const pred16x16_modes[4][9] = { | ||
| 96 | { /* H.264 */ | ||
| 97 | [DC_PRED8x8 ] = "dc", | ||
| 98 | [HOR_PRED8x8 ] = "horizontal", | ||
| 99 | [VERT_PRED8x8 ] = "vertical", | ||
| 100 | [PLANE_PRED8x8 ] = "plane", | ||
| 101 | [LEFT_DC_PRED8x8] = "left_dc", | ||
| 102 | [TOP_DC_PRED8x8 ] = "top_dc", | ||
| 103 | [DC_128_PRED8x8 ] = "dc_128", | ||
| 104 | }, | ||
| 105 | { /* VP8 */ | ||
| 106 | [PLANE_PRED8x8 ] = "tm_vp8", | ||
| 107 | [DC_127_PRED8x8] = "dc_127_vp8", | ||
| 108 | [DC_129_PRED8x8] = "dc_129_vp8", | ||
| 109 | }, | ||
| 110 | { /* RV40 */ | ||
| 111 | [PLANE_PRED8x8] = "plane_rv40", | ||
| 112 | }, | ||
| 113 | { /* SVQ3 */ | ||
| 114 | [PLANE_PRED8x8] = "plane_svq3", | ||
| 115 | }, | ||
| 116 | }; | ||
| 117 | |||
| 118 | static const uint32_t pixel_mask[3] = { 0xffffffff, 0x01ff01ff, 0x03ff03ff }; | ||
| 119 | |||
| 120 | #define SIZEOF_PIXEL ((bit_depth + 7) / 8) | ||
| 121 | #define BUF_SIZE (3 * 16 * 17) | ||
| 122 | |||
| 123 | #define check_pred_func(func, name, mode_name) \ | ||
| 124 | (mode_name && ((codec_ids[codec] == AV_CODEC_ID_H264) ? \ | ||
| 125 | check_func(func, "pred%s_%s_%d", name, mode_name, bit_depth) : \ | ||
| 126 | check_func(func, "pred%s_%s", name, mode_name))) | ||
| 127 | |||
| 128 | #define randomize_buffers() \ | ||
| 129 | do { \ | ||
| 130 | uint32_t mask = pixel_mask[bit_depth - 8]; \ | ||
| 131 | int i; \ | ||
| 132 | for (i = 0; i < BUF_SIZE; i += 4) { \ | ||
| 133 | uint32_t r = rnd() & mask; \ | ||
| 134 | AV_WN32A(buf0 + i, r); \ | ||
| 135 | AV_WN32A(buf1 + i, r); \ | ||
| 136 | } \ | ||
| 137 | } while (0) | ||
| 138 | |||
| 139 | #define src0 (buf0 + 4 * 16) /* Offset to allow room for top and left */ | ||
| 140 | #define src1 (buf1 + 4 * 16) | ||
| 141 | |||
| 142 | 117 | static void check_pred4x4(H264PredContext *h, uint8_t *buf0, uint8_t *buf1, | |
| 143 | int codec, int chroma_format, int bit_depth) | ||
| 144 | { | ||
| 145 |
2/2✓ Branch 0 taken 78 times.
✓ Branch 1 taken 39 times.
|
117 | if (chroma_format == 1) { |
| 146 | 78 | uint8_t *topright = buf0 + 2*16; | |
| 147 | int pred_mode; | ||
| 148 |
2/2✓ Branch 1 taken 72 times.
✓ Branch 2 taken 6 times.
|
78 | declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *src, const uint8_t *topright, ptrdiff_t stride); |
| 149 | |||
| 150 |
2/2✓ Branch 0 taken 1170 times.
✓ Branch 1 taken 78 times.
|
1248 | for (pred_mode = 0; pred_mode < 15; pred_mode++) { |
| 151 |
6/6✓ Branch 0 taken 637 times.
✓ Branch 1 taken 533 times.
✓ Branch 2 taken 468 times.
✓ Branch 3 taken 169 times.
✓ Branch 10 taken 74 times.
✓ Branch 11 taken 563 times.
|
1170 | if (check_pred_func(h->pred4x4[pred_mode], "4x4", pred4x4_modes[codec][pred_mode])) { |
| 152 |
2/2✓ Branch 1 taken 15096 times.
✓ Branch 2 taken 74 times.
|
15170 | randomize_buffers(); |
| 153 | 74 | call_ref(src0, topright, 12*SIZEOF_PIXEL); | |
| 154 | 74 | call_new(src1, topright, 12*SIZEOF_PIXEL); | |
| 155 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 74 times.
|
74 | if (memcmp(buf0, buf1, BUF_SIZE)) |
| 156 | ✗ | fail(); | |
| 157 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 74 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.
|
74 | bench_new(src1, topright, 12*SIZEOF_PIXEL); |
| 158 | } | ||
| 159 | } | ||
| 160 | } | ||
| 161 | 117 | } | |
| 162 | |||
| 163 | 117 | static void check_pred8x8(H264PredContext *h, uint8_t *buf0, uint8_t *buf1, | |
| 164 | int codec, int chroma_format, int bit_depth) | ||
| 165 | { | ||
| 166 | int pred_mode; | ||
| 167 |
2/2✓ Branch 1 taken 108 times.
✓ Branch 2 taken 9 times.
|
117 | declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *src, ptrdiff_t stride); |
| 168 | |||
| 169 |
2/2✓ Branch 0 taken 1287 times.
✓ Branch 1 taken 117 times.
|
1404 | for (pred_mode = 0; pred_mode < 11; pred_mode++) { |
| 170 |
9/10✓ Branch 0 taken 936 times.
✓ Branch 1 taken 351 times.
✓ Branch 2 taken 858 times.
✓ Branch 3 taken 78 times.
✓ Branch 6 taken 429 times.
✓ Branch 7 taken 429 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 78 times.
✓ Branch 14 taken 86 times.
✓ Branch 15 taken 850 times.
|
1287 | if (check_pred_func(h->pred8x8[pred_mode], (chroma_format == 2) ? "8x16" : "8x8", |
| 171 | pred8x8_modes[codec][pred_mode])) { | ||
| 172 |
2/2✓ Branch 1 taken 17544 times.
✓ Branch 2 taken 86 times.
|
17630 | randomize_buffers(); |
| 173 | 86 | call_ref(src0, 24*SIZEOF_PIXEL); | |
| 174 | 86 | call_new(src1, 24*SIZEOF_PIXEL); | |
| 175 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 86 times.
|
86 | if (memcmp(buf0, buf1, BUF_SIZE)) |
| 176 | ✗ | fail(); | |
| 177 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 86 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.
|
86 | bench_new(src1, 24*SIZEOF_PIXEL); |
| 178 | } | ||
| 179 | } | ||
| 180 | 117 | } | |
| 181 | |||
| 182 | 117 | static void check_pred16x16(H264PredContext *h, uint8_t *buf0, uint8_t *buf1, | |
| 183 | int codec, int chroma_format, int bit_depth) | ||
| 184 | { | ||
| 185 |
2/2✓ Branch 0 taken 78 times.
✓ Branch 1 taken 39 times.
|
117 | if (chroma_format == 1) { |
| 186 | int pred_mode; | ||
| 187 |
2/2✓ Branch 1 taken 72 times.
✓ Branch 2 taken 6 times.
|
78 | declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *src, ptrdiff_t stride); |
| 188 | |||
| 189 |
2/2✓ Branch 0 taken 702 times.
✓ Branch 1 taken 78 times.
|
780 | for (pred_mode = 0; pred_mode < 9; pred_mode++) { |
| 190 |
6/6✓ Branch 0 taken 338 times.
✓ Branch 1 taken 364 times.
✓ Branch 2 taken 273 times.
✓ Branch 3 taken 65 times.
✓ Branch 10 taken 45 times.
✓ Branch 11 taken 293 times.
|
702 | if (check_pred_func(h->pred16x16[pred_mode], "16x16", pred16x16_modes[codec][pred_mode])) { |
| 191 |
2/2✓ Branch 1 taken 9180 times.
✓ Branch 2 taken 45 times.
|
9225 | randomize_buffers(); |
| 192 | 45 | call_ref(src0, 48); | |
| 193 | 45 | call_new(src1, 48); | |
| 194 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
|
45 | if (memcmp(buf0, buf1, BUF_SIZE)) |
| 195 | ✗ | fail(); | |
| 196 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 45 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.
|
45 | bench_new(src1, 48); |
| 197 | } | ||
| 198 | } | ||
| 199 | } | ||
| 200 | 117 | } | |
| 201 | |||
| 202 | 117 | static void check_pred8x8l(H264PredContext *h, uint8_t *buf0, uint8_t *buf1, | |
| 203 | int codec, int chroma_format, int bit_depth) | ||
| 204 | { | ||
| 205 |
4/4✓ Branch 0 taken 78 times.
✓ Branch 1 taken 39 times.
✓ Branch 2 taken 39 times.
✓ Branch 3 taken 39 times.
|
117 | if (chroma_format == 1 && codec_ids[codec] == AV_CODEC_ID_H264) { |
| 206 | int pred_mode; | ||
| 207 |
2/2✓ Branch 1 taken 33 times.
✓ Branch 2 taken 6 times.
|
39 | declare_func_emms(AV_CPU_FLAG_MMXEXT, void, uint8_t *src, int topleft, int topright, ptrdiff_t stride); |
| 208 | |||
| 209 |
2/2✓ Branch 0 taken 468 times.
✓ Branch 1 taken 39 times.
|
507 | for (pred_mode = 0; pred_mode < 12; pred_mode++) { |
| 210 |
4/6✓ Branch 0 taken 468 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 468 times.
✗ Branch 3 not taken.
✓ Branch 10 taken 78 times.
✓ Branch 11 taken 390 times.
|
468 | if (check_pred_func(h->pred8x8l[pred_mode], "8x8l", pred4x4_modes[codec][pred_mode])) { |
| 211 | int neighbors; | ||
| 212 |
2/2✓ Branch 0 taken 312 times.
✓ Branch 1 taken 78 times.
|
390 | for (neighbors = 0; neighbors <= 0xc000; neighbors += 0x4000) { |
| 213 | 312 | int has_topleft = neighbors & 0x8000; | |
| 214 | 312 | int has_topright = neighbors & 0x4000; | |
| 215 | |||
| 216 |
6/6✓ Branch 0 taken 280 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 248 times.
✓ Branch 4 taken 32 times.
✓ Branch 5 taken 32 times.
|
312 | if ((pred_mode == DIAG_DOWN_RIGHT_PRED || pred_mode == VERT_RIGHT_PRED) && !has_topleft) |
| 217 | 32 | continue; /* Those aren't allowed according to the spec */ | |
| 218 | |||
| 219 |
2/2✓ Branch 1 taken 57120 times.
✓ Branch 2 taken 280 times.
|
57400 | randomize_buffers(); |
| 220 | 280 | call_ref(src0, has_topleft, has_topright, 24*SIZEOF_PIXEL); | |
| 221 | 280 | call_new(src1, has_topleft, has_topright, 24*SIZEOF_PIXEL); | |
| 222 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 280 times.
|
280 | if (memcmp(buf0, buf1, BUF_SIZE)) |
| 223 | ✗ | fail(); | |
| 224 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 280 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.
|
280 | bench_new(src1, has_topleft, has_topright, 24*SIZEOF_PIXEL); |
| 225 | } | ||
| 226 | } | ||
| 227 | } | ||
| 228 | } | ||
| 229 | 117 | } | |
| 230 | |||
| 231 | /* TODO: Add tests for H.264 lossless H/V prediction */ | ||
| 232 | |||
| 233 | 13 | void checkasm_check_h264pred(void) | |
| 234 | { | ||
| 235 | static const struct { | ||
| 236 | void (*func)(H264PredContext*, uint8_t*, uint8_t*, int, int, int); | ||
| 237 | const char *name; | ||
| 238 | } tests[] = { | ||
| 239 | { check_pred4x4, "pred4x4" }, | ||
| 240 | { check_pred8x8, "pred8x8" }, | ||
| 241 | { check_pred16x16, "pred16x16" }, | ||
| 242 | { check_pred8x8l, "pred8x8l" }, | ||
| 243 | }; | ||
| 244 | |||
| 245 | 13 | LOCAL_ALIGNED_16(uint8_t, buf0, [BUF_SIZE]); | |
| 246 | 13 | LOCAL_ALIGNED_16(uint8_t, buf1, [BUF_SIZE]); | |
| 247 | H264PredContext h; | ||
| 248 | int test, codec, chroma_format, bit_depth; | ||
| 249 | |||
| 250 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 13 times.
|
65 | for (test = 0; test < FF_ARRAY_ELEMS(tests); test++) { |
| 251 |
2/2✓ Branch 0 taken 208 times.
✓ Branch 1 taken 52 times.
|
260 | for (codec = 0; codec < 4; codec++) { |
| 252 | 208 | int codec_id = codec_ids[codec]; | |
| 253 |
4/4✓ Branch 0 taken 208 times.
✓ Branch 1 taken 312 times.
✓ Branch 2 taken 312 times.
✓ Branch 3 taken 208 times.
|
520 | for (bit_depth = 8; bit_depth <= (codec_id == AV_CODEC_ID_H264 ? 10 : 8); bit_depth++) |
| 254 |
4/4✓ Branch 0 taken 468 times.
✓ Branch 1 taken 312 times.
✓ Branch 2 taken 468 times.
✓ Branch 3 taken 312 times.
|
780 | for (chroma_format = 1; chroma_format <= (codec_id == AV_CODEC_ID_H264 ? 2 : 1); chroma_format++) { |
| 255 | 468 | ff_h264_pred_init(&h, codec_id, bit_depth, chroma_format); | |
| 256 | 468 | tests[test].func(&h, buf0, buf1, codec, chroma_format, bit_depth); | |
| 257 | } | ||
| 258 | } | ||
| 259 | 52 | report("%s", tests[test].name); | |
| 260 | } | ||
| 261 | 13 | } | |
| 262 |