/src/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 | | 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 | 4.80k | 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 | | #ifdef DE265_LOG_TRACE |
77 | | static long logcnt[10]; |
78 | | #endif |
79 | | |
80 | | #ifdef DE265_LOG_ERROR |
81 | | void logerror(enum LogModule module, const char* string, ...) |
82 | 0 | { |
83 | 0 | if (current_poc < log_poc_start) { return; } |
84 | 0 | if (disable_log[module]) return; |
85 | | |
86 | 0 | va_list va; |
87 | |
|
88 | 0 | int noPrefix = (string[0]=='*'); |
89 | 0 | if (!noPrefix) fprintf(stdout, "ERR: "); |
90 | 0 | va_start(va, string); |
91 | 0 | vfprintf(stdout, string + (noPrefix ? 1 : 0), va); |
92 | 0 | va_end(va); |
93 | 0 | fflush(stdout); |
94 | 0 | } |
95 | | #endif |
96 | | |
97 | | #ifdef DE265_LOG_INFO |
98 | | void loginfo (enum LogModule module, const char* string, ...) |
99 | | { |
100 | | if (verbosity<1) return; |
101 | | if (current_poc < log_poc_start) { return; } |
102 | | if (disable_log[module]) return; |
103 | | |
104 | | va_list va; |
105 | | |
106 | | int noPrefix = (string[0]=='*'); |
107 | | if (!noPrefix) fprintf(stdout, "INFO: "); |
108 | | va_start(va, string); |
109 | | vfprintf(stdout, string + (noPrefix ? 1 : 0), va); |
110 | | va_end(va); |
111 | | fflush(stdout); |
112 | | } |
113 | | #endif |
114 | | |
115 | | #ifdef DE265_LOG_DEBUG |
116 | | void logdebug(enum LogModule module, const char* string, ...) |
117 | | { |
118 | | if (verbosity<2) return; |
119 | | if (current_poc < log_poc_start) { return; } |
120 | | if (disable_log[module]) return; |
121 | | |
122 | | va_list va; |
123 | | |
124 | | int noPrefix = (string[0]=='*'); |
125 | | if (!noPrefix) fprintf(stdout, "DEBUG: "); |
126 | | va_start(va, string); |
127 | | vfprintf(stdout, string + (noPrefix ? 1 : 0), va); |
128 | | va_end(va); |
129 | | fflush(stdout); |
130 | | } |
131 | | |
132 | | bool logdebug_enabled(enum LogModule module) |
133 | | { |
134 | | return verbosity>=2; |
135 | | } |
136 | | #endif |
137 | | |
138 | | #ifdef DE265_LOG_TRACE |
139 | | void logtrace(enum LogModule module, const char* string, ...) |
140 | | { |
141 | | if (verbosity<3) return; |
142 | | if (current_poc < log_poc_start) { return; } |
143 | | if (disable_log[module]) return; |
144 | | |
145 | | //if (module != LogSymbols /*&& module != LogCABAC*/) { return; } |
146 | | //if (logcnt<319500) return; |
147 | | |
148 | | //if (module != LogCABAC) return; |
149 | | |
150 | | va_list va; |
151 | | |
152 | | if (string[0]=='$') { |
153 | | int id = string[1]-'0'; |
154 | | logcnt[id]++; |
155 | | fprintf(stdout, "[%ld] ",logcnt[id]); |
156 | | |
157 | | string += 3; |
158 | | } |
159 | | |
160 | | int noPrefix = (string[0]=='*'); |
161 | | if (!noPrefix) { } // fprintf(stdout, "ERR: "); |
162 | | va_start(va, string); |
163 | | vfprintf(stdout, string + (noPrefix ? 1 : 0), va); |
164 | | va_end(va); |
165 | | fflush(stdout); |
166 | | } |
167 | | #endif |
168 | | |
169 | | void log2fh(FILE* fh, const char* string, ...) |
170 | 0 | { |
171 | 0 | va_list va; |
172 | |
|
173 | 0 | int noPrefix = (string[0]=='*'); |
174 | 0 | if (!noPrefix) fprintf(stdout, "INFO: "); |
175 | 0 | va_start(va, string); |
176 | 0 | vfprintf(fh, string + (noPrefix ? 1 : 0), va); |
177 | 0 | va_end(va); |
178 | 0 | fflush(stdout); |
179 | 0 | } |
180 | | |
181 | | |
182 | | |
183 | | void printBlk(const char* title, const int16_t* data, int blksize, int stride, |
184 | | const std::string& prefix) |
185 | 0 | { |
186 | 0 | if (title) printf("%s%s:\n",prefix.c_str(),title); |
187 | |
|
188 | 0 | for (int y=0;y<blksize;y++) { |
189 | | //logtrace(LogTransform," "); |
190 | 0 | printf("%s",prefix.c_str()); |
191 | 0 | for (int x=0;x<blksize;x++) { |
192 | | //logtrace(LogTransform,"*%3d ", data[x+y*stride]); |
193 | 0 | printf("%4d ", data[x+y*stride]); |
194 | 0 | } |
195 | | //logtrace(LogTransform,"*\n"); |
196 | 0 | printf("\n"); |
197 | 0 | } |
198 | 0 | } |
199 | | |
200 | | |
201 | | void printBlk(const char* title, const int32_t* data, int blksize, int stride, |
202 | | const std::string& prefix) |
203 | 0 | { |
204 | 0 | if (title) printf("%s%s:\n",prefix.c_str(),title); |
205 | |
|
206 | 0 | for (int y=0;y<blksize;y++) { |
207 | | //logtrace(LogTransform," "); |
208 | 0 | printf("%s",prefix.c_str()); |
209 | 0 | for (int x=0;x<blksize;x++) { |
210 | | //logtrace(LogTransform,"*%3d ", data[x+y*stride]); |
211 | 0 | printf("%4d ", data[x+y*stride]); |
212 | 0 | } |
213 | | //logtrace(LogTransform,"*\n"); |
214 | 0 | printf("\n"); |
215 | 0 | } |
216 | 0 | } |
217 | | |
218 | | |
219 | | void printBlk(const char* title, const uint8_t* data, int blksize, int stride, |
220 | | const std::string& prefix) |
221 | 0 | { |
222 | 0 | if (title) printf("%s%s:\n",prefix.c_str(),title); |
223 | |
|
224 | 0 | for (int y=0;y<blksize;y++) { |
225 | | //logtrace(LogTransform," "); |
226 | 0 | printf("%s",prefix.c_str()); |
227 | 0 | for (int x=0;x<blksize;x++) { |
228 | | //logtrace(LogTransform,"*%3d ", data[x+y*stride]); |
229 | 0 | printf("%02x ", data[x+y*stride]); |
230 | 0 | } |
231 | | //logtrace(LogTransform,"*\n"); |
232 | 0 | printf("\n"); |
233 | 0 | } |
234 | 0 | } |
235 | | |
236 | | |
237 | | static void (*debug_image_output_func)(const struct de265_image*, int slot) = nullptr; |
238 | | |
239 | | void debug_set_image_output(void (*func)(const struct de265_image*, int slot)) |
240 | 0 | { |
241 | 0 | debug_image_output_func = func; |
242 | 0 | } |
243 | | |
244 | | void debug_show_image(const struct de265_image* img, int slot) |
245 | 0 | { |
246 | 0 | if (debug_image_output_func) { |
247 | 0 | debug_image_output_func(img,slot); |
248 | 0 | } |
249 | 0 | } |