/work/libde265/libde265/util.cc
Line | Count | Source |
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 | | // I see that there is a data-race when setting the current_poc (#535), |
44 | | // but this and log_poc_start are mainly there to reduce the log noise during |
45 | | // debugging. It's nothing that is used in production. |
46 | | // TODO: this may change if we add frame-parallel decoding. |
47 | | static int current_poc=0; |
48 | | static int log_poc_start=-9999; // frame-numbers can be negative |
49 | | static bool disable_log[NUMBER_OF_LogModules]; |
50 | 0 | void log_set_current_POC(int poc) { current_poc=poc; } |
51 | | #endif |
52 | | |
53 | | |
54 | | static int disable_logging_OLD=0; |
55 | | static int verbosity = 0; |
56 | | |
57 | | |
58 | | LIBDE265_API void de265_disable_logging() // DEPRECATED |
59 | 0 | { |
60 | 0 | disable_logging_OLD=1; |
61 | 0 | } |
62 | | |
63 | | |
64 | | LIBDE265_API void de265_set_verbosity(int level) |
65 | 0 | { |
66 | 0 | verbosity = level; |
67 | 0 | } |
68 | | |
69 | | #if defined(DE265_LOG_ERROR) || defined(DE265_LOG_INFO) || defined(DE265_LOG_DEBUG) || defined(DE265_LOG_INFO) |
70 | | void enable_logging(enum LogModule module) |
71 | 0 | { |
72 | 0 | disable_log[module]=false; |
73 | 0 | } |
74 | | void disable_logging(enum LogModule module) |
75 | 0 | { |
76 | 0 | disable_log[module]=true; |
77 | 0 | } |
78 | | #endif |
79 | | |
80 | | #ifdef DE265_LOG_TRACE |
81 | | static long logcnt[10]; |
82 | | #endif |
83 | | |
84 | | #ifdef DE265_LOG_ERROR |
85 | | void logerror(enum LogModule module, const char* string, ...) |
86 | 0 | { |
87 | 0 | if (current_poc < log_poc_start) { return; } |
88 | 0 | if (disable_log[module]) return; |
89 | | |
90 | 0 | va_list va; |
91 | |
|
92 | 0 | int noPrefix = (string[0]=='*'); |
93 | 0 | if (!noPrefix) fprintf(stdout, "ERR: "); |
94 | 0 | va_start(va, string); |
95 | 0 | vfprintf(stdout, string + (noPrefix ? 1 : 0), va); |
96 | 0 | va_end(va); |
97 | 0 | fflush(stdout); |
98 | 0 | } |
99 | | #endif |
100 | | |
101 | | #ifdef DE265_LOG_INFO |
102 | | void loginfo (enum LogModule module, const char* string, ...) |
103 | | { |
104 | | if (verbosity<1) return; |
105 | | if (current_poc < log_poc_start) { return; } |
106 | | if (disable_log[module]) return; |
107 | | |
108 | | va_list va; |
109 | | |
110 | | int noPrefix = (string[0]=='*'); |
111 | | if (!noPrefix) fprintf(stdout, "INFO: "); |
112 | | va_start(va, string); |
113 | | vfprintf(stdout, string + (noPrefix ? 1 : 0), va); |
114 | | va_end(va); |
115 | | fflush(stdout); |
116 | | } |
117 | | #endif |
118 | | |
119 | | #ifdef DE265_LOG_DEBUG |
120 | | void logdebug(enum LogModule module, const char* string, ...) |
121 | | { |
122 | | if (verbosity<2) return; |
123 | | if (current_poc < log_poc_start) { return; } |
124 | | if (disable_log[module]) return; |
125 | | |
126 | | va_list va; |
127 | | |
128 | | int noPrefix = (string[0]=='*'); |
129 | | if (!noPrefix) fprintf(stdout, "DEBUG: "); |
130 | | va_start(va, string); |
131 | | vfprintf(stdout, string + (noPrefix ? 1 : 0), va); |
132 | | va_end(va); |
133 | | fflush(stdout); |
134 | | } |
135 | | |
136 | | bool logdebug_enabled(enum LogModule module) |
137 | | { |
138 | | return verbosity>=2; |
139 | | } |
140 | | #endif |
141 | | |
142 | | #ifdef DE265_LOG_TRACE |
143 | | void logtrace(enum LogModule module, const char* string, ...) |
144 | | { |
145 | | if (verbosity<3) return; |
146 | | if (current_poc < log_poc_start) { return; } |
147 | | if (disable_log[module]) return; |
148 | | |
149 | | //if (module != LogSymbols /*&& module != LogCABAC*/) { return; } |
150 | | //if (logcnt<319500) return; |
151 | | |
152 | | //if (module != LogCABAC) return; |
153 | | |
154 | | va_list va; |
155 | | |
156 | | if (string[0]=='$') { |
157 | | int id = string[1]-'0'; |
158 | | logcnt[id]++; |
159 | | fprintf(stdout, "[%ld] ",logcnt[id]); |
160 | | |
161 | | string += 3; |
162 | | } |
163 | | |
164 | | int noPrefix = (string[0]=='*'); |
165 | | if (!noPrefix) { } // fprintf(stdout, "ERR: "); |
166 | | va_start(va, string); |
167 | | vfprintf(stdout, string + (noPrefix ? 1 : 0), va); |
168 | | va_end(va); |
169 | | fflush(stdout); |
170 | | } |
171 | | #endif |
172 | | |
173 | | void log2fh(FILE* fh, const char* string, ...) |
174 | 0 | { |
175 | 0 | va_list va; |
176 | |
|
177 | 0 | int noPrefix = (string[0]=='*'); |
178 | 0 | if (!noPrefix) fprintf(stdout, "INFO: "); |
179 | 0 | va_start(va, string); |
180 | 0 | vfprintf(fh, string + (noPrefix ? 1 : 0), va); |
181 | 0 | va_end(va); |
182 | 0 | fflush(stdout); |
183 | 0 | } |
184 | | |
185 | | |
186 | | |
187 | | void printBlk(const char* title, const int16_t* data, int blksize, int stride, |
188 | | const std::string& prefix) |
189 | 0 | { |
190 | 0 | if (title) printf("%s%s:\n",prefix.c_str(),title); |
191 | |
|
192 | 0 | for (int y=0;y<blksize;y++) { |
193 | | //logtrace(LogTransform," "); |
194 | 0 | printf("%s",prefix.c_str()); |
195 | 0 | for (int x=0;x<blksize;x++) { |
196 | | //logtrace(LogTransform,"*%3d ", data[x+y*stride]); |
197 | 0 | printf("%4d ", data[x+y*stride]); |
198 | 0 | } |
199 | | //logtrace(LogTransform,"*\n"); |
200 | 0 | printf("\n"); |
201 | 0 | } |
202 | 0 | } |
203 | | |
204 | | |
205 | | void printBlk(const char* title, const int32_t* data, int blksize, int stride, |
206 | | const std::string& prefix) |
207 | 0 | { |
208 | 0 | if (title) printf("%s%s:\n",prefix.c_str(),title); |
209 | |
|
210 | 0 | for (int y=0;y<blksize;y++) { |
211 | | //logtrace(LogTransform," "); |
212 | 0 | printf("%s",prefix.c_str()); |
213 | 0 | for (int x=0;x<blksize;x++) { |
214 | | //logtrace(LogTransform,"*%3d ", data[x+y*stride]); |
215 | 0 | printf("%4d ", data[x+y*stride]); |
216 | 0 | } |
217 | | //logtrace(LogTransform,"*\n"); |
218 | 0 | printf("\n"); |
219 | 0 | } |
220 | 0 | } |
221 | | |
222 | | |
223 | | void printBlk(const char* title, const uint8_t* data, int blksize, int stride, |
224 | | const std::string& prefix) |
225 | 0 | { |
226 | 0 | if (title) printf("%s%s:\n",prefix.c_str(),title); |
227 | |
|
228 | 0 | for (int y=0;y<blksize;y++) { |
229 | | //logtrace(LogTransform," "); |
230 | 0 | printf("%s",prefix.c_str()); |
231 | 0 | for (int x=0;x<blksize;x++) { |
232 | | //logtrace(LogTransform,"*%3d ", data[x+y*stride]); |
233 | 0 | printf("%02x ", data[x+y*stride]); |
234 | 0 | } |
235 | | //logtrace(LogTransform,"*\n"); |
236 | 0 | printf("\n"); |
237 | 0 | } |
238 | 0 | } |
239 | | |
240 | | |
241 | | static void (*debug_image_output_func)(const struct de265_image*, int slot) = nullptr; |
242 | | |
243 | | void debug_set_image_output(void (*func)(const struct de265_image*, int slot)) |
244 | 0 | { |
245 | 0 | debug_image_output_func = func; |
246 | 0 | } |
247 | | |
248 | | void debug_show_image(const struct de265_image* img, int slot) |
249 | 0 | { |
250 | 0 | if (debug_image_output_func) { |
251 | 0 | debug_image_output_func(img,slot); |
252 | 0 | } |
253 | 0 | } |