1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libopus/silk/debug.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,279 @@ 1.4 +/*********************************************************************** 1.5 +Copyright (c) 2006-2011, Skype Limited. All rights reserved. 1.6 +Redistribution and use in source and binary forms, with or without 1.7 +modification, are permitted provided that the following conditions 1.8 +are met: 1.9 +- Redistributions of source code must retain the above copyright notice, 1.10 +this list of conditions and the following disclaimer. 1.11 +- Redistributions in binary form must reproduce the above copyright 1.12 +notice, this list of conditions and the following disclaimer in the 1.13 +documentation and/or other materials provided with the distribution. 1.14 +- Neither the name of Internet Society, IETF or IETF Trust, nor the 1.15 +names of specific contributors, may be used to endorse or promote 1.16 +products derived from this software without specific prior written 1.17 +permission. 1.18 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1.19 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.20 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.21 +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 1.22 +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.23 +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.24 +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1.25 +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1.26 +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.27 +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1.28 +POSSIBILITY OF SUCH DAMAGE. 1.29 +***********************************************************************/ 1.30 + 1.31 +#ifndef SILK_DEBUG_H 1.32 +#define SILK_DEBUG_H 1.33 + 1.34 +#include "typedef.h" 1.35 +#include <stdio.h> /* file writing */ 1.36 +#include <string.h> /* strcpy, strcmp */ 1.37 + 1.38 +#ifdef __cplusplus 1.39 +extern "C" 1.40 +{ 1.41 +#endif 1.42 + 1.43 +unsigned long GetHighResolutionTime(void); /* O time in usec*/ 1.44 + 1.45 +/* make SILK_DEBUG dependent on compiler's _DEBUG */ 1.46 +#if defined _WIN32 1.47 + #ifdef _DEBUG 1.48 + #define SILK_DEBUG 1 1.49 + #else 1.50 + #define SILK_DEBUG 0 1.51 + #endif 1.52 + 1.53 + /* overrule the above */ 1.54 + #if 0 1.55 + /* #define NO_ASSERTS*/ 1.56 + #undef SILK_DEBUG 1.57 + #define SILK_DEBUG 1 1.58 + #endif 1.59 +#else 1.60 + #define SILK_DEBUG 0 1.61 +#endif 1.62 + 1.63 +/* Flag for using timers */ 1.64 +#define SILK_TIC_TOC 0 1.65 + 1.66 + 1.67 +#if SILK_TIC_TOC 1.68 + 1.69 +#if (defined(_WIN32) || defined(_WINCE)) 1.70 +#include <windows.h> /* timer */ 1.71 +#else /* Linux or Mac*/ 1.72 +#include <sys/time.h> 1.73 +#endif 1.74 + 1.75 +/*********************************/ 1.76 +/* timer functions for profiling */ 1.77 +/*********************************/ 1.78 +/* example: */ 1.79 +/* */ 1.80 +/* TIC(LPC) */ 1.81 +/* do_LPC(in_vec, order, acoef); // do LPC analysis */ 1.82 +/* TOC(LPC) */ 1.83 +/* */ 1.84 +/* and call the following just before exiting (from main) */ 1.85 +/* */ 1.86 +/* silk_TimerSave("silk_TimingData.txt"); */ 1.87 +/* */ 1.88 +/* results are now in silk_TimingData.txt */ 1.89 + 1.90 +void silk_TimerSave(char *file_name); 1.91 + 1.92 +/* max number of timers (in different locations) */ 1.93 +#define silk_NUM_TIMERS_MAX 50 1.94 +/* max length of name tags in TIC(..), TOC(..) */ 1.95 +#define silk_NUM_TIMERS_MAX_TAG_LEN 30 1.96 + 1.97 +extern int silk_Timer_nTimers; 1.98 +extern int silk_Timer_depth_ctr; 1.99 +extern char silk_Timer_tags[silk_NUM_TIMERS_MAX][silk_NUM_TIMERS_MAX_TAG_LEN]; 1.100 +#ifdef _WIN32 1.101 +extern LARGE_INTEGER silk_Timer_start[silk_NUM_TIMERS_MAX]; 1.102 +#else 1.103 +extern unsigned long silk_Timer_start[silk_NUM_TIMERS_MAX]; 1.104 +#endif 1.105 +extern unsigned int silk_Timer_cnt[silk_NUM_TIMERS_MAX]; 1.106 +extern opus_int64 silk_Timer_sum[silk_NUM_TIMERS_MAX]; 1.107 +extern opus_int64 silk_Timer_max[silk_NUM_TIMERS_MAX]; 1.108 +extern opus_int64 silk_Timer_min[silk_NUM_TIMERS_MAX]; 1.109 +extern opus_int64 silk_Timer_depth[silk_NUM_TIMERS_MAX]; 1.110 + 1.111 +/* WARNING: TIC()/TOC can measure only up to 0.1 seconds at a time */ 1.112 +#ifdef _WIN32 1.113 +#define TIC(TAG_NAME) { \ 1.114 + static int init = 0; \ 1.115 + static int ID = -1; \ 1.116 + if( init == 0 ) \ 1.117 + { \ 1.118 + int k; \ 1.119 + init = 1; \ 1.120 + for( k = 0; k < silk_Timer_nTimers; k++ ) { \ 1.121 + if( strcmp(silk_Timer_tags[k], #TAG_NAME) == 0 ) { \ 1.122 + ID = k; \ 1.123 + break; \ 1.124 + } \ 1.125 + } \ 1.126 + if (ID == -1) { \ 1.127 + ID = silk_Timer_nTimers; \ 1.128 + silk_Timer_nTimers++; \ 1.129 + silk_Timer_depth[ID] = silk_Timer_depth_ctr; \ 1.130 + strcpy(silk_Timer_tags[ID], #TAG_NAME); \ 1.131 + silk_Timer_cnt[ID] = 0; \ 1.132 + silk_Timer_sum[ID] = 0; \ 1.133 + silk_Timer_min[ID] = 0xFFFFFFFF; \ 1.134 + silk_Timer_max[ID] = 0; \ 1.135 + } \ 1.136 + } \ 1.137 + silk_Timer_depth_ctr++; \ 1.138 + QueryPerformanceCounter(&silk_Timer_start[ID]); \ 1.139 +} 1.140 +#else 1.141 +#define TIC(TAG_NAME) { \ 1.142 + static int init = 0; \ 1.143 + static int ID = -1; \ 1.144 + if( init == 0 ) \ 1.145 + { \ 1.146 + int k; \ 1.147 + init = 1; \ 1.148 + for( k = 0; k < silk_Timer_nTimers; k++ ) { \ 1.149 + if( strcmp(silk_Timer_tags[k], #TAG_NAME) == 0 ) { \ 1.150 + ID = k; \ 1.151 + break; \ 1.152 + } \ 1.153 + } \ 1.154 + if (ID == -1) { \ 1.155 + ID = silk_Timer_nTimers; \ 1.156 + silk_Timer_nTimers++; \ 1.157 + silk_Timer_depth[ID] = silk_Timer_depth_ctr; \ 1.158 + strcpy(silk_Timer_tags[ID], #TAG_NAME); \ 1.159 + silk_Timer_cnt[ID] = 0; \ 1.160 + silk_Timer_sum[ID] = 0; \ 1.161 + silk_Timer_min[ID] = 0xFFFFFFFF; \ 1.162 + silk_Timer_max[ID] = 0; \ 1.163 + } \ 1.164 + } \ 1.165 + silk_Timer_depth_ctr++; \ 1.166 + silk_Timer_start[ID] = GetHighResolutionTime(); \ 1.167 +} 1.168 +#endif 1.169 + 1.170 +#ifdef _WIN32 1.171 +#define TOC(TAG_NAME) { \ 1.172 + LARGE_INTEGER lpPerformanceCount; \ 1.173 + static int init = 0; \ 1.174 + static int ID = 0; \ 1.175 + if( init == 0 ) \ 1.176 + { \ 1.177 + int k; \ 1.178 + init = 1; \ 1.179 + for( k = 0; k < silk_Timer_nTimers; k++ ) { \ 1.180 + if( strcmp(silk_Timer_tags[k], #TAG_NAME) == 0 ) { \ 1.181 + ID = k; \ 1.182 + break; \ 1.183 + } \ 1.184 + } \ 1.185 + } \ 1.186 + QueryPerformanceCounter(&lpPerformanceCount); \ 1.187 + lpPerformanceCount.QuadPart -= silk_Timer_start[ID].QuadPart; \ 1.188 + if((lpPerformanceCount.QuadPart < 100000000) && \ 1.189 + (lpPerformanceCount.QuadPart >= 0)) { \ 1.190 + silk_Timer_cnt[ID]++; \ 1.191 + silk_Timer_sum[ID] += lpPerformanceCount.QuadPart; \ 1.192 + if( lpPerformanceCount.QuadPart > silk_Timer_max[ID] ) \ 1.193 + silk_Timer_max[ID] = lpPerformanceCount.QuadPart; \ 1.194 + if( lpPerformanceCount.QuadPart < silk_Timer_min[ID] ) \ 1.195 + silk_Timer_min[ID] = lpPerformanceCount.QuadPart; \ 1.196 + } \ 1.197 + silk_Timer_depth_ctr--; \ 1.198 +} 1.199 +#else 1.200 +#define TOC(TAG_NAME) { \ 1.201 + unsigned long endTime; \ 1.202 + static int init = 0; \ 1.203 + static int ID = 0; \ 1.204 + if( init == 0 ) \ 1.205 + { \ 1.206 + int k; \ 1.207 + init = 1; \ 1.208 + for( k = 0; k < silk_Timer_nTimers; k++ ) { \ 1.209 + if( strcmp(silk_Timer_tags[k], #TAG_NAME) == 0 ) { \ 1.210 + ID = k; \ 1.211 + break; \ 1.212 + } \ 1.213 + } \ 1.214 + } \ 1.215 + endTime = GetHighResolutionTime(); \ 1.216 + endTime -= silk_Timer_start[ID]; \ 1.217 + if((endTime < 100000000) && \ 1.218 + (endTime >= 0)) { \ 1.219 + silk_Timer_cnt[ID]++; \ 1.220 + silk_Timer_sum[ID] += endTime; \ 1.221 + if( endTime > silk_Timer_max[ID] ) \ 1.222 + silk_Timer_max[ID] = endTime; \ 1.223 + if( endTime < silk_Timer_min[ID] ) \ 1.224 + silk_Timer_min[ID] = endTime; \ 1.225 + } \ 1.226 + silk_Timer_depth_ctr--; \ 1.227 +} 1.228 +#endif 1.229 + 1.230 +#else /* SILK_TIC_TOC */ 1.231 + 1.232 +/* define macros as empty strings */ 1.233 +#define TIC(TAG_NAME) 1.234 +#define TOC(TAG_NAME) 1.235 +#define silk_TimerSave(FILE_NAME) 1.236 + 1.237 +#endif /* SILK_TIC_TOC */ 1.238 + 1.239 + 1.240 +#if SILK_DEBUG 1.241 +/************************************/ 1.242 +/* write data to file for debugging */ 1.243 +/************************************/ 1.244 +/* Example: DEBUG_STORE_DATA(testfile.pcm, &RIN[0], 160*sizeof(opus_int16)); */ 1.245 + 1.246 +#define silk_NUM_STORES_MAX 100 1.247 +extern FILE *silk_debug_store_fp[ silk_NUM_STORES_MAX ]; 1.248 +extern int silk_debug_store_count; 1.249 + 1.250 +/* Faster way of storing the data */ 1.251 +#define DEBUG_STORE_DATA( FILE_NAME, DATA_PTR, N_BYTES ) { \ 1.252 + static opus_int init = 0, cnt = 0; \ 1.253 + static FILE **fp; \ 1.254 + if (init == 0) { \ 1.255 + init = 1; \ 1.256 + cnt = silk_debug_store_count++; \ 1.257 + silk_debug_store_fp[ cnt ] = fopen(#FILE_NAME, "wb"); \ 1.258 + } \ 1.259 + fwrite((DATA_PTR), (N_BYTES), 1, silk_debug_store_fp[ cnt ]); \ 1.260 +} 1.261 + 1.262 +/* Call this at the end of main() */ 1.263 +#define SILK_DEBUG_STORE_CLOSE_FILES { \ 1.264 + opus_int i; \ 1.265 + for( i = 0; i < silk_debug_store_count; i++ ) { \ 1.266 + fclose( silk_debug_store_fp[ i ] ); \ 1.267 + } \ 1.268 +} 1.269 + 1.270 +#else /* SILK_DEBUG */ 1.271 + 1.272 +/* define macros as empty strings */ 1.273 +#define DEBUG_STORE_DATA(FILE_NAME, DATA_PTR, N_BYTES) 1.274 +#define SILK_DEBUG_STORE_CLOSE_FILES 1.275 + 1.276 +#endif /* SILK_DEBUG */ 1.277 + 1.278 +#ifdef __cplusplus 1.279 +} 1.280 +#endif 1.281 + 1.282 +#endif /* SILK_DEBUG_H */