/src/libde265/libde265/util.cc
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * H.265 video codec. |
3 | | * Copyright (c) 2013-2014 struktur AG, Dirk Farin <farin@struktur.de> |
4 | | * |
5 | | * This file is part of libde265. |
6 | | * |
7 | | * libde265 is free software: you can redistribute it and/or modify |
8 | | * it under the terms of the GNU Lesser General Public License as |
9 | | * published by the Free Software Foundation, either version 3 of |
10 | | * the License, or (at your option) any later version. |
11 | | * |
12 | | * libde265 is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | * GNU Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General Public License |
18 | | * along with libde265. If not, see <http://www.gnu.org/licenses/>. |
19 | | */ |
20 | | |
21 | | #include "util.h" |
22 | | #include "de265.h" |
23 | | |
24 | | #include <stdarg.h> |
25 | | #include <stdio.h> |
26 | | #include <string.h> |
27 | | |
28 | | |
29 | | void copy_subimage(uint8_t* dst,int dststride, |
30 | | const uint8_t* src,int srcstride, |
31 | | int w, int h) |
32 | 0 | { |
33 | 0 | for (int y=0;y<h;y++) { |
34 | 0 | memcpy(dst, src, w); |
35 | 0 | dst += dststride; |
36 | 0 | src += srcstride; |
37 | 0 | } |
38 | 0 | } |
39 | | |
40 | | |
41 | | |
42 | | #ifdef DE265_LOGGING |
43 | | static int current_poc=0; |
44 | | static int log_poc_start=-9999; // frame-numbers can be negative |
45 | | static bool disable_log[NUMBER_OF_LogModules]; |
46 | 0 | void log_set_current_POC(int poc) { current_poc=poc; } |
47 | | #endif |
48 | | |
49 | | |
50 | | static int disable_logging_OLD=0; |
51 | | static int verbosity = 0; |
52 | | |
53 | | |
54 | | LIBDE265_API void de265_disable_logging() // DEPRECATED |
55 | 0 | { |
56 | 0 | disable_logging_OLD=1; |
57 | 0 | } |
58 | | |
59 | | |
60 | | LIBDE265_API void de265_set_verbosity(int level) |
61 | 0 | { |
62 | 0 | verbosity = level; |
63 | 0 | } |
64 | | |
65 | | #if defined(DE265_LOG_ERROR) || defined(DE265_LOG_INFO) || defined(DE265_LOG_DEBUG) || defined(DE265_LOG_INFO) |
66 | | void enable_logging(enum LogModule module) |
67 | 0 | { |
68 | 0 | disable_log[module]=false; |
69 | 0 | } |
70 | | void disable_logging(enum LogModule module) |
71 | 0 | { |
72 | 0 | disable_log[module]=true; |
73 | 0 | } |
74 | | #endif |
75 | | |
76 | | static long logcnt[10]; |
77 | | |
78 | | #ifdef DE265_LOG_ERROR |
79 | | void logerror(enum LogModule module, const char* string, ...) |
80 | 0 | { |
81 | 0 | if (current_poc < log_poc_start) { return; } |
82 | 0 | if (disable_log[module]) return; |
83 | | |
84 | 0 | va_list va; |
85 | |
|
86 | 0 | int noPrefix = (string[0]=='*'); |
87 | 0 | if (!noPrefix) fprintf(stdout, "ERR: "); |
88 | 0 | va_start(va, string); |
89 | 0 | vfprintf(stdout, string + (noPrefix ? 1 : 0), va); |
90 | 0 | va_end(va); |
91 | 0 | fflush(stdout); |
92 | 0 | } |
93 | | #endif |
94 | | |
95 | | #ifdef DE265_LOG_INFO |
96 | | void loginfo (enum LogModule module, const char* string, ...) |
97 | | { |
98 | | if (verbosity<1) return; |
99 | | if (current_poc < log_poc_start) { return; } |
100 | | if (disable_log[module]) return; |
101 | | |
102 | | va_list va; |
103 | | |
104 | | int noPrefix = (string[0]=='*'); |
105 | | if (!noPrefix) fprintf(stdout, "INFO: "); |
106 | | va_start(va, string); |
107 | | vfprintf(stdout, string + (noPrefix ? 1 : 0), va); |
108 | | va_end(va); |
109 | | fflush(stdout); |
110 | | } |
111 | | #endif |
112 | | |
113 | | #ifdef DE265_LOG_DEBUG |
114 | | void logdebug(enum LogModule module, const char* string, ...) |
115 | | { |
116 | | if (verbosity<2) return; |
117 | | if (current_poc < log_poc_start) { return; } |
118 | | if (disable_log[module]) return; |
119 | | |
120 | | va_list va; |
121 | | |
122 | | int noPrefix = (string[0]=='*'); |
123 | | if (!noPrefix) fprintf(stdout, "DEBUG: "); |
124 | | va_start(va, string); |
125 | | vfprintf(stdout, string + (noPrefix ? 1 : 0), va); |
126 | | va_end(va); |
127 | | fflush(stdout); |
128 | | } |
129 | | |
130 | | bool logdebug_enabled(enum LogModule module) |
131 | | { |
132 | | return verbosity>=2; |
133 | | } |
134 | | #endif |
135 | | |
136 | | #ifdef DE265_LOG_TRACE |
137 | | void logtrace(enum LogModule module, const char* string, ...) |
138 | | { |
139 | | if (verbosity<3) return; |
140 | | if (current_poc < log_poc_start) { return; } |
141 | | if (disable_log[module]) return; |
142 | | |
143 | | //if (module != LogSymbols /*&& module != LogCABAC*/) { return; } |
144 | | //if (logcnt<319500) return; |
145 | | |
146 | | //if (module != LogCABAC) return; |
147 | | |
148 | | va_list va; |
149 | | |
150 | | if (string[0]=='$') { |
151 | | int id = string[1]-'0'; |
152 | | logcnt[id]++; |
153 | | fprintf(stdout, "[%ld] ",logcnt[id]); |
154 | | |
155 | | string += 3; |
156 | | } |
157 | | |
158 | | int noPrefix = (string[0]=='*'); |
159 | | if (!noPrefix) { } // fprintf(stdout, "ERR: "); |
160 | | va_start(va, string); |
161 | | vfprintf(stdout, string + (noPrefix ? 1 : 0), va); |
162 | | va_end(va); |
163 | | fflush(stdout); |
164 | | } |
165 | | #endif |
166 | | |
167 | | void log2fh(FILE* fh, const char* string, ...) |
168 | 0 | { |
169 | 0 | va_list va; |
170 | |
|
171 | 0 | int noPrefix = (string[0]=='*'); |
172 | 0 | if (!noPrefix) fprintf(stdout, "INFO: "); |
173 | 0 | va_start(va, string); |
174 | 0 | vfprintf(fh, string + (noPrefix ? 1 : 0), va); |
175 | 0 | va_end(va); |
176 | 0 | fflush(stdout); |
177 | 0 | } |
178 | | |
179 | | |
180 | | |
181 | | void printBlk(const char* title, const int16_t* data, int blksize, int stride, |
182 | | const std::string& prefix) |
183 | 0 | { |
184 | 0 | if (title) printf("%s%s:\n",prefix.c_str(),title); |
185 | |
|
186 | 0 | for (int y=0;y<blksize;y++) { |
187 | | //logtrace(LogTransform," "); |
188 | 0 | printf("%s",prefix.c_str()); |
189 | 0 | for (int x=0;x<blksize;x++) { |
190 | | //logtrace(LogTransform,"*%3d ", data[x+y*stride]); |
191 | 0 | printf("%4d ", data[x+y*stride]); |
192 | 0 | } |
193 | | //logtrace(LogTransform,"*\n"); |
194 | 0 | printf("\n"); |
195 | 0 | } |
196 | 0 | } |
197 | | |
198 | | |
199 | | void printBlk(const char* title, const int32_t* data, int blksize, int stride, |
200 | | const std::string& prefix) |
201 | 0 | { |
202 | 0 | if (title) printf("%s%s:\n",prefix.c_str(),title); |
203 | |
|
204 | 0 | for (int y=0;y<blksize;y++) { |
205 | | //logtrace(LogTransform," "); |
206 | 0 | printf("%s",prefix.c_str()); |
207 | 0 | for (int x=0;x<blksize;x++) { |
208 | | //logtrace(LogTransform,"*%3d ", data[x+y*stride]); |
209 | 0 | printf("%4d ", data[x+y*stride]); |
210 | 0 | } |
211 | | //logtrace(LogTransform,"*\n"); |
212 | 0 | printf("\n"); |
213 | 0 | } |
214 | 0 | } |
215 | | |
216 | | |
217 | | void printBlk(const char* title, const uint8_t* data, int blksize, int stride, |
218 | | const std::string& prefix) |
219 | 0 | { |
220 | 0 | if (title) printf("%s%s:\n",prefix.c_str(),title); |
221 | |
|
222 | 0 | for (int y=0;y<blksize;y++) { |
223 | | //logtrace(LogTransform," "); |
224 | 0 | printf("%s",prefix.c_str()); |
225 | 0 | for (int x=0;x<blksize;x++) { |
226 | | //logtrace(LogTransform,"*%3d ", data[x+y*stride]); |
227 | 0 | printf("%02x ", data[x+y*stride]); |
228 | 0 | } |
229 | | //logtrace(LogTransform,"*\n"); |
230 | 0 | printf("\n"); |
231 | 0 | } |
232 | 0 | } |
233 | | |
234 | | |
235 | | static void (*debug_image_output_func)(const struct de265_image*, int slot) = NULL; |
236 | | |
237 | | void debug_set_image_output(void (*func)(const struct de265_image*, int slot)) |
238 | 0 | { |
239 | 0 | debug_image_output_func = func; |
240 | 0 | } |
241 | | |
242 | | void debug_show_image(const struct de265_image* img, int slot) |
243 | 0 | { |
244 | 0 | if (debug_image_output_func) { |
245 | 0 | debug_image_output_func(img,slot); |
246 | 0 | } |
247 | 0 | } |