1 /*
2 * This file is part of libplacebo.
3 *
4 * libplacebo 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 * libplacebo 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
12 * GNU 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 libplacebo. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #pragma once
19
20 #include "common.h"
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <math.h>
26 #include <time.h>
27
pl_log_timestamp(void * stream,enum pl_log_level level,const char * msg)28 static void pl_log_timestamp(void *stream, enum pl_log_level level, const char *msg)
29 {
30 static char letter[] = {
31 [PL_LOG_FATAL] = 'f',
32 [PL_LOG_ERR] = 'e',
33 [PL_LOG_WARN] = 'w',
34 [PL_LOG_INFO] = 'i',
35 [PL_LOG_DEBUG] = 'd',
36 [PL_LOG_TRACE] = 't',
37 };
38
39 float secs = (float) clock() / CLOCKS_PER_SEC;
40 printf("[%2.3f][%c] %s\n", secs, letter[level], msg);
41
42 if (level <= PL_LOG_WARN) {
43 // duplicate warnings/errors to stderr
44 fprintf(stderr, "[%2.3f][%c] %s\n", secs, letter[level], msg);
45 fflush(stderr);
46 }
47 }
48
pl_test_logger()49 static inline pl_log pl_test_logger()
50 {
51 setbuf(stdout, NULL);
52 setbuf(stderr, NULL);
53
54 return pl_log_create(PL_API_VER, &(struct pl_log_params) {
55 .log_cb = isatty(fileno(stdout)) ? pl_log_color : pl_log_timestamp,
56 .log_level = PL_LOG_DEBUG,
57 });
58 }
59
require(bool b,const char * msg,const char * file,int line)60 static inline void require(bool b, const char *msg, const char *file, int line)
61 {
62 if (!b) {
63 fprintf(stderr, "=== FAILED: '%s' at %s:%d\n\n", msg, file, line);
64 exit(1);
65 }
66 }
67
feq(float a,float b,float epsilon)68 static inline bool feq(float a, float b, float epsilon)
69 {
70 return fabs(a - b) < epsilon * fmax(1.0, fabs(a));
71 }
72
73 #define REQUIRE(cond) require((cond), #cond, __FILE__, __LINE__)
74 #define RANDOM (rand() / (float) RAND_MAX)
75 #define SKIP 77
76
77 #define REQUIRE_HANDLE(shmem, type) \
78 switch (type) { \
79 case PL_HANDLE_FD: \
80 case PL_HANDLE_DMA_BUF: \
81 REQUIRE(shmem.handle.fd > -1); \
82 break; \
83 case PL_HANDLE_WIN32: \
84 case PL_HANDLE_WIN32_KMT: \
85 REQUIRE(shmem.handle.handle); \
86 /* INVALID_HANDLE_VALUE = (-1) */ \
87 REQUIRE(shmem.handle.handle != (void *)(intptr_t) (-1)); \
88 break; \
89 case PL_HANDLE_HOST_PTR: \
90 REQUIRE(shmem.handle.ptr); \
91 break; \
92 }
93
94 static const struct pl_av1_grain_data av1_grain_data = {
95 .grain_seed = 48476,
96
97 .num_points_y = 6,
98 .points_y = {{0, 4}, {27, 33}, {54, 55}, {67, 61}, {108, 71}, {255, 72}},
99 .chroma_scaling_from_luma = false,
100 .num_points_uv = {2, 2},
101 .points_uv = {{{0, 64}, {255, 64}}, {{0, 64}, {255, 64}}},
102 .scaling_shift = 11,
103 .ar_coeff_lag = 3,
104 .ar_coeffs_y = {4, 1, 3, 0, 1, -3, 8, -3, 7, -23, 1, -25,
105 0, -10, 6, -17, -4, 53, 36, 5, -5, -17, 8, 66},
106 .ar_coeffs_uv = {
107 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
108 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127},
109 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127},
111 },
112 .ar_coeff_shift = 7,
113 .grain_scale_shift = 0,
114 .uv_mult = {0, 0},
115 .uv_mult_luma = {64, 64},
116 .uv_offset = {0, 0},
117 };
118