49 unsigned total =
f->block_rows *
f->block_cols;
50 printf(
"%s frame %u: index %u offsets",
name, idx,
f->frame_index);
51 for (
unsigned i = 0;
i < total;
i++)
52 printf(
" %d", (
int)
f->block_offsets[
i]);
59 static const unsigned probe_indices[] = { 1, 2, 4, 5, 100 };
72 for (
unsigned i = 0;
i < 5;
i++) {
75 printf(
"valid frame_for_index %u: %u\n", probe_indices[
i],
f->frame_index);
77 printf(
"valid frame_for_index %u: none\n", probe_indices[
i]);
81 printf(
"valid segment_values 1:");
82 for (
unsigned i = 0;
i < n_vals;
i++)
103 static const unsigned probes[] = { 1, 2, 4, 5, 7, 8, 100 };
109 printf(
"clearing lookup %u: none\n", probes[
i]);
110 else if (!
f->block_offsets)
111 printf(
"clearing lookup %u: index %u clear\n",
112 probes[
i],
f->frame_index);
127 FILE *
fp = fopen(
path,
"wb");
130 if (fwrite(bytes, 1,
len,
fp) !=
len) {
146 printf(
"%s: cannot write fixture\n", tc->
name);
152 printf(
"%s: ok frames %u grid %ux%u\n", tc->
name,
160 if (remove(
path) != 0) {
161 printf(
"%s: cannot remove fixture\n", tc->
name);
177 for (
unsigned i = 0;
i < count;
i++)
185 static const int8_t p1[3] = { -12, 0, 12 };
189 p_all[
i] = (int8_t)(-12 +
i);
201 static const int seg[3] = { -12, 0, 12 };
206 printf(
" %u", (
unsigned)lut[
i]);
214 {
"valid",
" \t\n# comment\n2 I 26\n-12 12\n \t\n5 P 30\n3 -3\n",
215 sizeof(
" \t\n# comment\n2 I 26\n-12 12\n \t\n5 P 30\n3 -3\n") - 1,
check_valid },
216 {
"crlf",
"2 I 26\r\n-12 12\r\n5 P 30\r\n3 -3\r\n",
217 sizeof(
"2 I 26\r\n-12 12\r\n5 P 30\r\n3 -3\r\n") - 1,
NULL },
218 {
"clip",
"0 I 26\n-20 20\n",
220 {
"header-only",
"0 I 26\n3 P 26\n",
222 {
"clearing",
"2 I 26\n1 2\n5 P 26\n8 B 26\n-3 3\n",
223 sizeof(
"2 I 26\n1 2\n5 P 26\n8 B 26\n-3 3\n") - 1,
check_clearing },
224 {
"index-max",
"4294967295 I 26\n-1 1\n",
226 {
"index-over",
"4294967296 I 26\n",
227 sizeof(
"4294967296 I 26\n") - 1,
NULL },
228 {
"not-increasing",
"5 I 26\n5 P 26\n",
229 sizeof(
"5 I 26\n5 P 26\n") - 1,
NULL },
230 {
"no-record",
"# only a comment\n\n",
231 sizeof(
"# only a comment\n\n") - 1,
NULL },
232 {
"nul",
"0 I 26\n-12 12\0junk\n",
233 sizeof(
"0 I 26\n-12 12\0junk\n") - 1,
NULL },
234 {
"row-width",
"0 I 26\n1 2\n3\n",
235 sizeof(
"0 I 26\n1 2\n3\n") - 1,
NULL },
236 {
"frame-width",
"0 I 26\n1 2\n1 P 26\n3\n",
237 sizeof(
"0 I 26\n1 2\n1 P 26\n3\n") - 1,
NULL },
238 {
"frame-rows",
"0 I 26\n1 2\n1 P 26\n3 4\n5 6\n",
239 sizeof(
"0 I 26\n1 2\n1 P 26\n3 4\n5 6\n") - 1,
NULL },
245 snprintf(
path,
sizeof(
path),
"ff-qpfile-test-%08x.txt",
seed);
#define i(width, name, range_min, range_max)
__device__ int printf(const char *,...)
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
Utility Preprocessor macros.
unsigned ff_qpfile_palette(const int8_t *vals, size_t n, int *seg_values, unsigned max_segments)
Fill seg_values, ascending, with each distinct value of the n offsets in vals when there are at most ...
int ff_qpfile_load(void *log_ctx, const char *path, FFQpFile *out)
Load a per-frame QP-offset file into out, logging errors to log_ctx.
const FFQpFrame * ff_qpfile_frame_for_index(const FFQpFile *qf, unsigned frame_index)
Look up the QP frame record matching or preceding the given frame index.
unsigned ff_qpfile_segment_values(const FFQpFrame *qf, int *seg_values, unsigned max_segments)
Fill seg_values with the palette (see ff_qpfile_palette) of the frame's block offsets,...
void ff_qpfile_segment_lut(uint8_t *lut, const int *seg_values, unsigned n_seg)
Fill lut[QPFILE_LUT_SIZE] with the nearest segment index of each offset from QPFILE_DELTA_MIN to QPFI...
int ff_qpfile_check_grid(void *log_ctx, const char *encoder, const FFQpFile *qf, int width, int height)
Verify that the QP file grid matches the video macroblock dimensions.
void ff_qpfile_free(FFQpFile *qpf)
Free all memory allocated inside an FFQpFile structure.
Shared parser for the per-frame QP-offset file format.
#define FF_ARRAY_ELEMS(a)
void(* check)(const FFQpFile *qf)
static const TestCase cases[]
static void test_palette(const char *label, const int8_t *vals, size_t n, unsigned budget)
static void test_palettes(void)
static void print_frame(const char *name, unsigned idx, const FFQpFrame *f)
static void check_clearing(const FFQpFile *qf)
static void check_index_max(const FFQpFile *qf)
static int run_fixture_test(const char *path, const FixtureCase *tc)
static void check_header_only(const FFQpFile *qf)
static void test_lut(void)
static int write_fixture(const char *path, const char *bytes, size_t len)
static const char * err_name(int err)
static void check_clip(const FFQpFile *qf)
static void check_valid(const FFQpFile *qf)