TUT HEVC Encoder
Loading...
Searching...
No Matches
src
checkpoint.h
Go to the documentation of this file.
1
#ifndef CHECKPOINT_H_
2
#define CHECKPOINT_H_
3
/*****************************************************************************
4
* This file is part of Kvazaar HEVC encoder.
5
*
6
* Copyright (c) 2021, Tampere University, ITU/ISO/IEC, project contributors
7
* All rights reserved.
8
*
9
* Redistribution and use in source and binary forms, with or without modification,
10
* are permitted provided that the following conditions are met:
11
*
12
* * Redistributions of source code must retain the above copyright notice, this
13
* list of conditions and the following disclaimer.
14
*
15
* * Redistributions in binary form must reproduce the above copyright notice, this
16
* list of conditions and the following disclaimer in the documentation and/or
17
* other materials provided with the distribution.
18
*
19
* * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
20
* contributors may be used to endorse or promote products derived from
21
* this software without specific prior written permission.
22
*
23
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28
* INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
30
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
* INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
33
****************************************************************************/
34
40
#ifdef CHECKPOINTS
41
#ifdef NDEBUG
42
#error "CHECKPOINTS require assertions to be enabled!"
43
#endif
44
#include <string.h>
45
#include <stdio.h>
46
#include <stdlib.h>
47
48
#include "
global.h
"
// IWYU pragma: keep
49
50
51
extern
FILE* g_ckpt_file;
52
extern
int
g_ckpt_enabled;
//Do we check?
53
extern
int
g_ckpt_record;
//Do we record?
54
55
#define CHECKPOINTS_INIT() do { \
56
if (getenv("CHECKPOINTS")) {\
57
if (strcmp(getenv("CHECKPOINTS"),"record") == 0) { \
58
g_ckpt_file = fopen("__debug_ckpt.log", "w"); assert(g_ckpt_file); \
59
g_ckpt_record = 1; \
60
} else if (strcmp(getenv("CHECKPOINTS"),"check") == 0) { \
61
g_ckpt_file = fopen("__debug_ckpt.log", "r"); assert(g_ckpt_file); \
62
g_ckpt_record = 0; \
63
g_ckpt_enabled = 0; \
64
} else { \
65
g_ckpt_file = NULL; \
66
} \
67
} else {\
68
g_ckpt_file = NULL; \
69
} \
70
} while (0)
71
72
#define CHECKPOINTS_FINALIZE() do {if (g_ckpt_file) fclose(g_ckpt_file); g_ckpt_file = NULL;} while (0)
73
74
#define CHECKPOINT_MARK(str, ...) do { \
75
if (g_ckpt_file) { \
76
if (g_ckpt_record) { \
77
fprintf(g_ckpt_file, "MARK: " str "\n", __VA_ARGS__); \
78
} else { \
79
char buffer_ckpt[4096]; \
80
long pos; \
81
snprintf(buffer_ckpt, 4095, "MARK: " str "\n", __VA_ARGS__); \
82
pos = ftell(g_ckpt_file); \
83
g_ckpt_enabled = 0; \
84
while (!feof(g_ckpt_file)) { \
85
char buffer_file[4096]; \
86
assert(fgets(buffer_file, 4095, g_ckpt_file) != NULL); \
87
if (strncmp(buffer_file, buffer_ckpt, 4096)==0) { \
88
g_ckpt_enabled = 1; \
89
break; \
90
} \
91
} \
92
if (!g_ckpt_enabled) fseek(g_ckpt_file, pos, SEEK_SET); \
93
} \
94
} \
95
} while (0)
96
#define CHECKPOINT(str, ...) do { \
97
if (g_ckpt_file) { \
98
if (g_ckpt_record) { \
99
fprintf(g_ckpt_file, str "\n", __VA_ARGS__); \
100
} else if (g_ckpt_enabled) { \
101
char buffer_file[4096], buffer_ckpt[4096]; \
102
assert(fgets(buffer_file, 4095, g_ckpt_file) != NULL); \
103
snprintf(buffer_ckpt, 4095, str "\n", __VA_ARGS__); \
104
if (strncmp(buffer_file, buffer_ckpt, 4096)!=0) { \
105
fprintf(stderr, "Checkpoint failed (at %ld):\nFile: %sExec: %s", ftell(g_ckpt_file), buffer_file, buffer_ckpt); \
106
assert(0); \
107
} \
108
} \
109
} \
110
} while (0)
111
#endif
112
113
#if !defined(CHECKPOINTS)
114
#define CHECKPOINTS_INIT()
115
#define CHECKPOINTS_FINALIZE()
116
#define CHECKPOINT_MARK(str, ...)
117
#define CHECKPOINT(str, ...)
118
#endif
119
120
121
122
#endif
//CHECKPOINT_H_
global.h
Header that is included in every other header.
Generated on Tue Aug 20 2024 21:35:07 for TUT HEVC Encoder by
1.12.0