xref: /third_party/ffmpeg/tests/checkasm/v210enc.c (revision cabdff1a)
1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * Copyright (c) 2015 Henrik Gramner
3cabdff1aSopenharmony_ci *
4cabdff1aSopenharmony_ci * This file is part of FFmpeg.
5cabdff1aSopenharmony_ci *
6cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or modify
7cabdff1aSopenharmony_ci * it under the terms of the GNU General Public License as published by
8cabdff1aSopenharmony_ci * the Free Software Foundation; either version 2 of the License, or
9cabdff1aSopenharmony_ci * (at your option) any later version.
10cabdff1aSopenharmony_ci *
11cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
12cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
13cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14cabdff1aSopenharmony_ci * GNU General Public License for more details.
15cabdff1aSopenharmony_ci *
16cabdff1aSopenharmony_ci * You should have received a copy of the GNU General Public License along
17cabdff1aSopenharmony_ci * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18cabdff1aSopenharmony_ci * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19cabdff1aSopenharmony_ci */
20cabdff1aSopenharmony_ci
21cabdff1aSopenharmony_ci#include <string.h>
22cabdff1aSopenharmony_ci#include "checkasm.h"
23cabdff1aSopenharmony_ci#include "libavcodec/v210enc_init.h"
24cabdff1aSopenharmony_ci#include "libavutil/common.h"
25cabdff1aSopenharmony_ci#include "libavutil/internal.h"
26cabdff1aSopenharmony_ci#include "libavutil/intreadwrite.h"
27cabdff1aSopenharmony_ci#include "libavutil/mem_internal.h"
28cabdff1aSopenharmony_ci
29cabdff1aSopenharmony_ci#define BUF_SIZE 512
30cabdff1aSopenharmony_ci
31cabdff1aSopenharmony_ci#define randomize_buffers(mask)                        \
32cabdff1aSopenharmony_ci    do {                                               \
33cabdff1aSopenharmony_ci        int i, size = sizeof(*y0);                     \
34cabdff1aSopenharmony_ci        for (i = 0; i < BUF_SIZE; i += 4 / size) {     \
35cabdff1aSopenharmony_ci            uint32_t r = rnd() & mask;                 \
36cabdff1aSopenharmony_ci            AV_WN32A(y0 + i, r);                       \
37cabdff1aSopenharmony_ci            AV_WN32A(y1 + i, r);                       \
38cabdff1aSopenharmony_ci        }                                              \
39cabdff1aSopenharmony_ci        for (i = 0; i < BUF_SIZE / 2; i += 4 / size) { \
40cabdff1aSopenharmony_ci            uint32_t r = rnd() & mask;                 \
41cabdff1aSopenharmony_ci            AV_WN32A(u0 + i, r);                       \
42cabdff1aSopenharmony_ci            AV_WN32A(u1 + i, r);                       \
43cabdff1aSopenharmony_ci            r = rnd() & mask;                          \
44cabdff1aSopenharmony_ci            AV_WN32A(v0 + i, r);                       \
45cabdff1aSopenharmony_ci            AV_WN32A(v1 + i, r);                       \
46cabdff1aSopenharmony_ci        }                                              \
47cabdff1aSopenharmony_ci        for (i = 0; i < width * 8 / 3; i += 4) {       \
48cabdff1aSopenharmony_ci            uint32_t r = rnd();                        \
49cabdff1aSopenharmony_ci            AV_WN32A(dst0 + i, r);                     \
50cabdff1aSopenharmony_ci            AV_WN32A(dst1 + i, r);                     \
51cabdff1aSopenharmony_ci        }                                              \
52cabdff1aSopenharmony_ci    } while (0)
53cabdff1aSopenharmony_ci
54cabdff1aSopenharmony_ci#define check_pack_line(type, mask)                                                \
55cabdff1aSopenharmony_ci    do {                                                                           \
56cabdff1aSopenharmony_ci        LOCAL_ALIGNED_16(type, y0, [BUF_SIZE]);                                    \
57cabdff1aSopenharmony_ci        LOCAL_ALIGNED_16(type, y1, [BUF_SIZE]);                                    \
58cabdff1aSopenharmony_ci        LOCAL_ALIGNED_16(type, u0, [BUF_SIZE / 2]);                                \
59cabdff1aSopenharmony_ci        LOCAL_ALIGNED_16(type, u1, [BUF_SIZE / 2]);                                \
60cabdff1aSopenharmony_ci        LOCAL_ALIGNED_16(type, v0, [BUF_SIZE / 2]);                                \
61cabdff1aSopenharmony_ci        LOCAL_ALIGNED_16(type, v1, [BUF_SIZE / 2]);                                \
62cabdff1aSopenharmony_ci        LOCAL_ALIGNED_16(uint8_t, dst0, [BUF_SIZE * 8 / 3]);                       \
63cabdff1aSopenharmony_ci        LOCAL_ALIGNED_16(uint8_t, dst1, [BUF_SIZE * 8 / 3]);                       \
64cabdff1aSopenharmony_ci                                                                                   \
65cabdff1aSopenharmony_ci        declare_func(void, const type * y, const type * u, const type * v,         \
66cabdff1aSopenharmony_ci                     uint8_t * dst, ptrdiff_t width);                              \
67cabdff1aSopenharmony_ci        ptrdiff_t width, step = 12 / sizeof(type);                                 \
68cabdff1aSopenharmony_ci                                                                                   \
69cabdff1aSopenharmony_ci        for (width = step; width < BUF_SIZE - 15; width += step) {                 \
70cabdff1aSopenharmony_ci            int y_offset  = rnd() & 15;                                            \
71cabdff1aSopenharmony_ci            int uv_offset = y_offset / 2;                                          \
72cabdff1aSopenharmony_ci            randomize_buffers(mask);                                               \
73cabdff1aSopenharmony_ci            call_ref(y0 + y_offset, u0 + uv_offset, v0 + uv_offset, dst0, width);  \
74cabdff1aSopenharmony_ci            call_new(y1 + y_offset, u1 + uv_offset, v1 + uv_offset, dst1, width);  \
75cabdff1aSopenharmony_ci            if (memcmp(y0, y1, BUF_SIZE) || memcmp(u0, u1, BUF_SIZE / 2) ||        \
76cabdff1aSopenharmony_ci                memcmp(v0, v1, BUF_SIZE / 2) || memcmp(dst0, dst1, width * 8 / 3)) \
77cabdff1aSopenharmony_ci                fail();                                                            \
78cabdff1aSopenharmony_ci            bench_new(y1 + y_offset, u1 + uv_offset, v1 + uv_offset, dst1, width); \
79cabdff1aSopenharmony_ci        }                                                                          \
80cabdff1aSopenharmony_ci    } while (0)
81cabdff1aSopenharmony_ci
82cabdff1aSopenharmony_civoid checkasm_check_v210enc(void)
83cabdff1aSopenharmony_ci{
84cabdff1aSopenharmony_ci    V210EncContext h;
85cabdff1aSopenharmony_ci
86cabdff1aSopenharmony_ci    ff_v210enc_init(&h);
87cabdff1aSopenharmony_ci
88cabdff1aSopenharmony_ci    if (check_func(h.pack_line_8, "v210_planar_pack_8"))
89cabdff1aSopenharmony_ci        check_pack_line(uint8_t, 0xffffffff);
90cabdff1aSopenharmony_ci
91cabdff1aSopenharmony_ci    if (check_func(h.pack_line_10, "v210_planar_pack_10"))
92cabdff1aSopenharmony_ci        check_pack_line(uint16_t, 0x03ff03ff);
93cabdff1aSopenharmony_ci
94cabdff1aSopenharmony_ci    report("planar_pack");
95cabdff1aSopenharmony_ci}
96