Showing the changes to codec/decoder/plus/src/welsCodecTrace.cpp (1 of 225 files). Show all
Unified · Split
| @@ -59,371 +59,339 @@ · 58 unmodified lines | ||
| 59 | 59 | namespace WelsDec { |
| 60 | 60 | |
| 61 | 61 | #ifdef MACOS |
| 62 | −static CFBundleRef LoadLibrary(const char* lpszbundle) | |
| 63 | −{ | |
| 64 | − // 1.get bundle path | |
| 65 | − char cBundlePath[PATH_MAX]; | |
| 66 | − memset(cBundlePath, 0, PATH_MAX); | |
| 67 | − | |
| 68 | − Dl_info dlInfo; | |
| 69 | − static int sDummy; | |
| 70 | − dladdr((void_t*)&sDummy, &dlInfo); | |
| 71 | − | |
| 72 | − strlcpy(cBundlePath, dlInfo.dli_fname, PATH_MAX); | |
| 73 | − | |
| 74 | − char * pPath = NULL; | |
| 75 | − for(int i = 4; i > 0; i--) | |
| 76 | − { | |
| 77 | − pPath = strrchr(cBundlePath,'/');//confirmed_safe_unsafe_usage | |
| 78 | − if(pPath) | |
| 79 | − { | |
| 80 | − *pPath = 0; | |
| 81 | − } | |
| 82 | − else | |
| 83 | − { | |
| 84 | − break; | |
| 85 | − } | |
| 86 | − } | |
| 87 | − if(pPath) | |
| 88 | − { | |
| 89 | − strlcat(cBundlePath, "/", PATH_MAX); | |
| 90 | − } | |
| 91 | − else | |
| 92 | − { | |
| 93 | − return NULL; | |
| 94 | − } | |
| 95 | − | |
| 96 | − strlcat(cBundlePath, lpszbundle, PATH_MAX); | |
| 97 | − | |
| 98 | − FSRef bundlePath; | |
| 99 | − OSStatus iStatus = FSPathMakeRef((unsigned char*)cBundlePath, &bundlePath, NULL); | |
| 100 | − if(noErr != iStatus) | |
| 101 | − return NULL; | |
| 102 | − | |
| 103 | − CFURLRef bundleURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &bundlePath); | |
| 104 | − if(NULL == bundleURL) | |
| 105 | − return NULL; | |
| 106 | − | |
| 107 | − // 2.get bundle ref | |
| 108 | − CFBundleRef bundleRef = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL); | |
| 109 | − CFRelease(bundleURL); | |
| 110 | − | |
| 62 | +static CFBundleRef LoadLibrary (const char* lpszbundle) { | |
| 63 | + // 1.get bundle path | |
| 64 | + char cBundlePath[PATH_MAX]; | |
| 65 | + memset (cBundlePath, 0, PATH_MAX); | |
| 66 | + | |
| 67 | + Dl_info dlInfo; | |
| 68 | + static int sDummy; | |
| 69 | + dladdr ((void_t*)&sDummy, &dlInfo); | |
| 70 | + | |
| 71 | + strlcpy (cBundlePath, dlInfo.dli_fname, PATH_MAX); | |
| 72 | + | |
| 73 | + char* pPath = NULL; | |
| 74 | + for (int i = 4; i > 0; i--) { | |
| 75 | + pPath = strrchr (cBundlePath, '/'); //confirmed_safe_unsafe_usage | |
| 76 | + if (pPath) { | |
| 77 | + *pPath = 0; | |
| 78 | + } else { | |
| 79 | + break; | |
| 80 | + } | |
| 81 | + } | |
| 82 | + if (pPath) { | |
| 83 | + strlcat (cBundlePath, "/", PATH_MAX); | |
| 84 | + } else { | |
| 85 | + return NULL; | |
| 86 | + } | |
| 87 | + | |
| 88 | + strlcat (cBundlePath, lpszbundle, PATH_MAX); | |
| 89 | + | |
| 90 | + FSRef bundlePath; | |
| 91 | + OSStatus iStatus = FSPathMakeRef ((unsigned char*)cBundlePath, &bundlePath, NULL); | |
| 92 | + if (noErr != iStatus) | |
| 93 | + return NULL; | |
| 94 | + | |
| 95 | + CFURLRef bundleURL = CFURLCreateFromFSRef (kCFAllocatorSystemDefault, &bundlePath); | |
| 96 | + if (NULL == bundleURL) | |
| 97 | + return NULL; | |
| 98 | + | |
| 99 | + // 2.get bundle ref | |
| 100 | + CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorSystemDefault, bundleURL); | |
| 101 | + CFRelease (bundleURL); | |
| 102 | + | |
| 111 | 103 | // Boolean bReturn = FALSE; |
| 112 | − if(NULL != bundleRef) | |
| 113 | − { | |
| 114 | − // bReturn = CFBundleLoadExecutable(bundleRef); | |
| 115 | − } | |
| 116 | − | |
| 117 | − return bundleRef; | |
| 104 | + if (NULL != bundleRef) { | |
| 105 | + // bReturn = CFBundleLoadExecutable(bundleRef); | |
| 106 | + } | |
| 107 | + | |
| 108 | + return bundleRef; | |
| 118 | 109 | } |
| 119 | 110 | |
| 120 | −static Boolean FreeLibrary(CFBundleRef bundle) | |
| 121 | −{ | |
| 122 | − if(NULL != bundle) | |
| 123 | − { | |
| 124 | − // CFBundleUnloadExecutable(bundle); | |
| 125 | − CFRelease(bundle); | |
| 126 | − } | |
| 127 | − | |
| 128 | − return TRUE; | |
| 111 | +static Boolean FreeLibrary (CFBundleRef bundle) { | |
| 112 | + if (NULL != bundle) { | |
| 113 | + // CFBundleUnloadExecutable(bundle); | |
| 114 | + CFRelease (bundle); | |
| 115 | + } | |
| 116 | + | |
| 117 | + return TRUE; | |
| 129 | 118 | } |
| 130 | 119 | |
| 131 | −static void_t* GetProcessAddress(CFBundleRef bundle, const char* lpszprocname) | |
| 132 | −{ | |
| 133 | − if(NULL == bundle) | |
| 134 | − return NULL; | |
| 135 | − | |
| 136 | − CFStringRef cfprocname = CFStringCreateWithCString(NULL,lpszprocname,CFStringGetSystemEncoding()); | |
| 137 | − void_t *processAddress = CFBundleGetFunctionPointerForName(bundle,cfprocname); | |
| 138 | − CFRelease(cfprocname); | |
| 139 | − | |
| 140 | − return processAddress; | |
| 120 | +static void_t* GetProcessAddress (CFBundleRef bundle, const char* lpszprocname) { | |
| 121 | + if (NULL == bundle) | |
| 122 | + return NULL; | |
| 123 | + | |
| 124 | + CFStringRef cfprocname = CFStringCreateWithCString (NULL, lpszprocname, CFStringGetSystemEncoding()); | |
| 125 | + void_t* processAddress = CFBundleGetFunctionPointerForName (bundle, cfprocname); | |
| 126 | + CFRelease (cfprocname); | |
| 127 | + | |
| 128 | + return processAddress; | |
| 141 | 129 | } |
| 142 | 130 | #endif |
| 143 | 131 | |
| 144 | 132 | |
| 145 | 133 | |
| 146 | −int32_t CWelsTraceBase::SetTraceLevel(int iLevel) | |
| 147 | −{ | |
| 148 | − m_iLevel = iLevel; | |
| 134 | +int32_t CWelsTraceBase::SetTraceLevel (int iLevel) { | |
| 135 | + m_iLevel = iLevel; | |
| 149 | 136 | |
| 150 | − return 0; | |
| 137 | + return 0; | |
| 151 | 138 | } |
| 152 | 139 | |
| 153 | −int32_t CWelsTraceBase::Trace(const int kLevel, const str_t *kpFormat, va_list pVl) | |
| 154 | −{ | |
| 155 | − if( kLevel & m_iLevel ){ | |
| 156 | − str_t chWStrFormat[MAX_LOG_SIZE] = {0}; | |
| 157 | − str_t chBuf[MAX_LOG_SIZE] = {0}; | |
| 158 | − str_t chResult[MAX_LOG_SIZE] = {0}; | |
| 159 | − const int32_t kLen = WelsStrnlen((const str_t *)"[DECODER]: ", MAX_LOG_SIZE); | |
| 140 | +int32_t CWelsTraceBase::Trace (const int kLevel, const str_t* kpFormat, va_list pVl) { | |
| 141 | + if (kLevel & m_iLevel) { | |
| 142 | + str_t chWStrFormat[MAX_LOG_SIZE] = {0}; | |
| 143 | + str_t chBuf[MAX_LOG_SIZE] = {0}; | |
| 144 | + str_t chResult[MAX_LOG_SIZE] = {0}; | |
| 145 | + const int32_t kLen = WelsStrnlen ((const str_t*)"[DECODER]: ", MAX_LOG_SIZE); | |
| 160 | 146 | |
| 161 | − WelsStrncpy(chWStrFormat, MAX_LOG_SIZE, (const str_t *)kpFormat, WelsStrnlen((const str_t *)kpFormat, MAX_LOG_SIZE)); | |
| 147 | + WelsStrncpy (chWStrFormat, MAX_LOG_SIZE, (const str_t*)kpFormat, WelsStrnlen ((const str_t*)kpFormat, MAX_LOG_SIZE)); | |
| 162 | 148 | |
| 163 | − WelsStrncpy(chBuf, MAX_LOG_SIZE, (const str_t *)"[DECODER]: ", kLen); | |
| 149 | + WelsStrncpy (chBuf, MAX_LOG_SIZE, (const str_t*)"[DECODER]: ", kLen); | |
| 164 | 150 | |
| 165 | − WelsVsprintf((chBuf + kLen), MAX_LOG_SIZE - kLen, (const str_t *)kpFormat, pVl); | |
| 166 | − WelsStrncpy(chResult, MAX_LOG_SIZE, (const str_t *)chBuf, WelsStrnlen((const str_t *)chBuf, MAX_LOG_SIZE)); | |
| 151 | + WelsVsprintf ((chBuf + kLen), MAX_LOG_SIZE - kLen, (const str_t*)kpFormat, pVl); | |
| 152 | + WelsStrncpy (chResult, MAX_LOG_SIZE, (const str_t*)chBuf, WelsStrnlen ((const str_t*)chBuf, MAX_LOG_SIZE)); | |
| 167 | 153 | |
| 168 | − WriteString(kLevel, chResult); | |
| 169 | − } | |
| 154 | + WriteString (kLevel, chResult); | |
| 155 | + } | |
| 170 | 156 | |
| 171 | − return 0; | |
| 157 | + return 0; | |
| 172 | 158 | } |
| 173 | 159 | |
| 174 | −CWelsTraceFile::CWelsTraceFile(const str_t * pFileName) | |
| 175 | −{ | |
| 176 | − m_pTraceFile = WelsFopen(pFileName, (const str_t *)"wt"); | |
| 160 | +CWelsTraceFile::CWelsTraceFile (const str_t* pFileName) { | |
| 161 | + m_pTraceFile = WelsFopen (pFileName, (const str_t*)"wt"); | |
| 177 | 162 | } |
| 178 | 163 | |
| 179 | −CWelsTraceFile::~CWelsTraceFile() | |
| 180 | −{ | |
| 181 | − if( m_pTraceFile ){ | |
| 182 | − WelsFclose(m_pTraceFile); | |
| 183 | − m_pTraceFile = NULL; | |
| 184 | − } | |
| 164 | +CWelsTraceFile::~CWelsTraceFile() { | |
| 165 | + if (m_pTraceFile) { | |
| 166 | + WelsFclose (m_pTraceFile); | |
| 167 | + m_pTraceFile = NULL; | |
| 168 | + } | |
| 185 | 169 | } |
| 186 | 170 | |
| 187 | −int32_t CWelsTraceFile::WriteString(int32_t iLevel, const str_t * pStr) | |
| 188 | −{ | |
| 189 | − int iRC = 0; | |
| 190 | − const static str_t chEnter[16] = "\n"; | |
| 191 | − if( m_pTraceFile ){ | |
| 192 | − iRC += WelsFwrite(pStr, 1, WelsStrnlen(pStr, MAX_LOG_SIZE), m_pTraceFile); | |
| 193 | − iRC += WelsFwrite(chEnter, 1, WelsStrnlen(chEnter, 16), m_pTraceFile); | |
| 194 | − WelsFflush(m_pTraceFile); | |
| 195 | − } | |
| 196 | − return iRC; | |
| 171 | +int32_t CWelsTraceFile::WriteString (int32_t iLevel, const str_t* pStr) { | |
| 172 | + int iRC = 0; | |
| 173 | + const static str_t chEnter[16] = "\n"; | |
| 174 | + if (m_pTraceFile) { | |
| 175 | + iRC += WelsFwrite (pStr, 1, WelsStrnlen (pStr, MAX_LOG_SIZE), m_pTraceFile); | |
| 176 | + iRC += WelsFwrite (chEnter, 1, WelsStrnlen (chEnter, 16), m_pTraceFile); | |
| 177 | + WelsFflush (m_pTraceFile); | |
| 178 | + } | |
| 179 | + return iRC; | |
| 197 | 180 | } |
| 198 | 181 | |
| 199 | 182 | |
| 200 | 183 | #ifdef WIN32 |
| 201 | 184 | |
| 202 | −int32_t CWelsTraceWinDgb::WriteString(int32_t iLevel, const str_t * pStr) | |
| 203 | −{ | |
| 204 | − OutputDebugStringA(pStr); | |
| 185 | +int32_t CWelsTraceWinDgb::WriteString (int32_t iLevel, const str_t* pStr) { | |
| 186 | + OutputDebugStringA (pStr); | |
| 205 | 187 | |
| 206 | − return WelsStrnlen(pStr, MAX_LOG_SIZE);//strnlen(pStr, MAX_LOG_SIZE); | |
| 188 | + return WelsStrnlen (pStr, MAX_LOG_SIZE); //strnlen(pStr, MAX_LOG_SIZE); | |
| 207 | 189 | } |
| 208 | 190 | |
| 209 | 191 | #endif |
| 210 | 192 | |
| 211 | −CWelsCodecTrace::CWelsCodecTrace() | |
| 212 | −{ | |
| 213 | − m_hTraceHandle = NULL; | |
| 214 | − m_fpDebugTrace = NULL; | |
| 215 | − m_fpInfoTrace = NULL; | |
| 216 | − m_fpWarnTrace = NULL; | |
| 217 | − m_fpErrorTrace = NULL; | |
| 193 | +CWelsCodecTrace::CWelsCodecTrace() { | |
| 194 | + m_hTraceHandle = NULL; | |
| 195 | + m_fpDebugTrace = NULL; | |
| 196 | + m_fpInfoTrace = NULL; | |
| 197 | + m_fpWarnTrace = NULL; | |
| 198 | + m_fpErrorTrace = NULL; | |
| 218 | 199 | |
| 219 | − LoadWelsTraceModule(); | |
| 200 | + LoadWelsTraceModule(); | |
| 220 | 201 | } |
| 221 | 202 | |
| 222 | −CWelsCodecTrace::~CWelsCodecTrace() | |
| 223 | −{ | |
| 224 | − UnloadWelsTraceModule(); | |
| 203 | +CWelsCodecTrace::~CWelsCodecTrace() { | |
| 204 | + UnloadWelsTraceModule(); | |
| 225 | 205 | } |
| 226 | 206 | |
| 227 | −int32_t CWelsCodecTrace::LoadWelsTraceModule() | |
| 228 | −{ | |
| 207 | +int32_t CWelsCodecTrace::LoadWelsTraceModule() { | |
| 229 | 208 | #ifdef NO_DYNAMIC_VP |
| 230 | − m_fpDebugTrace = welsStderrTrace<WELS_LOG_DEBUG>; | |
| 231 | − m_fpInfoTrace = welsStderrTrace<WELS_LOG_INFO>; | |
| 232 | − m_fpWarnTrace = welsStderrTrace<WELS_LOG_WARNING>; | |
| 233 | − m_fpErrorTrace = welsStderrTrace<WELS_LOG_ERROR>; | |
| 209 | + m_fpDebugTrace = welsStderrTrace<WELS_LOG_DEBUG>; | |
| 210 | + m_fpInfoTrace = welsStderrTrace<WELS_LOG_INFO>; | |
| 211 | + m_fpWarnTrace = welsStderrTrace<WELS_LOG_WARNING>; | |
| 212 | + m_fpErrorTrace = welsStderrTrace<WELS_LOG_ERROR>; | |
| 234 | 213 | #else |
| 235 | −#if defined WIN32 | |
| 236 | − HMODULE hHandle = ::LoadLibrary("welstrace.dll"); | |
| 214 | +#if defined WIN32 | |
| 215 | + HMODULE hHandle = ::LoadLibrary ("welstrace.dll"); | |
| 237 | 216 | // HMODULE handle = ::LoadLibrary("contrace.dll"); // for c7 trace |
| 238 | − if ( NULL == hHandle ) | |
| 239 | − return -1; | |
| 240 | − | |
| 241 | − CHAR chPath[ _MAX_PATH]= {0}; | |
| 242 | − GetModuleFileName( (HMODULE)hHandle, chPath, _MAX_PATH); | |
| 243 | − | |
| 244 | − m_hTraceHandle = ::LoadLibrary(chPath); | |
| 245 | − | |
| 246 | − OutputDebugStringA(chPath); | |
| 247 | − if( m_hTraceHandle) { | |
| 248 | − m_fpDebugTrace = ( CM_WELS_TRACE)::GetProcAddress( ( HMODULE)m_hTraceHandle, "WELSDEBUGA"); | |
| 249 | − m_fpInfoTrace = ( CM_WELS_TRACE)::GetProcAddress( ( HMODULE)m_hTraceHandle, "WELSINFOA"); | |
| 250 | − m_fpWarnTrace = ( CM_WELS_TRACE)::GetProcAddress( ( HMODULE)m_hTraceHandle, "WELSWARNA"); | |
| 251 | − m_fpErrorTrace = ( CM_WELS_TRACE)::GetProcAddress( ( HMODULE)m_hTraceHandle, "WELSERRORA"); | |
| 252 | − } | |
| 253 | − | |
| 254 | − // coverity scan uninitial | |
| 255 | − if (hHandle != NULL) | |
| 256 | − { | |
| 257 | − ::FreeLibrary(hHandle); | |
| 258 | − hHandle = NULL; | |
| 259 | − } | |
| 217 | + if (NULL == hHandle) | |
| 218 | + return -1; | |
| 219 | + | |
| 220 | + CHAR chPath[ _MAX_PATH] = {0}; | |
| 221 | + GetModuleFileName ((HMODULE)hHandle, chPath, _MAX_PATH); | |
| 222 | + | |
| 223 | + m_hTraceHandle = ::LoadLibrary (chPath); | |
| 224 | + | |
| 225 | + OutputDebugStringA (chPath); | |
| 226 | + if (m_hTraceHandle) { | |
| 227 | + m_fpDebugTrace = (CM_WELS_TRACE)::GetProcAddress ((HMODULE)m_hTraceHandle, "WELSDEBUGA"); | |
| 228 | + m_fpInfoTrace = (CM_WELS_TRACE)::GetProcAddress ((HMODULE)m_hTraceHandle, "WELSINFOA"); | |
| 229 | + m_fpWarnTrace = (CM_WELS_TRACE)::GetProcAddress ((HMODULE)m_hTraceHandle, "WELSWARNA"); | |
| 230 | + m_fpErrorTrace = (CM_WELS_TRACE)::GetProcAddress ((HMODULE)m_hTraceHandle, "WELSERRORA"); | |
| 231 | + } | |
| 232 | + | |
| 233 | + // coverity scan uninitial | |
| 234 | + if (hHandle != NULL) { | |
| 235 | + ::FreeLibrary (hHandle); | |
| 236 | + hHandle = NULL; | |
| 237 | + } | |
| 260 | 238 | #elif defined MACOS |
| 261 | − m_hTraceHandle = LoadLibrary("welstrace.bundle"); | |
| 262 | − if(m_hTraceHandle) { | |
| 263 | − m_fpDebugTrace = ( CM_WELS_TRACE)GetProcessAddress( (CFBundleRef)m_hTraceHandle, "WELSDEBUG2"); | |
| 264 | − m_fpInfoTrace = ( CM_WELS_TRACE)GetProcessAddress( (CFBundleRef)m_hTraceHandle, "WELSINFO2"); | |
| 265 | − m_fpWarnTrace = ( CM_WELS_TRACE)GetProcessAddress( (CFBundleRef)m_hTraceHandle, "WELSWARN2"); | |
| 266 | − m_fpErrorTrace = ( CM_WELS_TRACE)GetProcessAddress( (CFBundleRef)m_hTraceHandle, "WELSERROR2"); | |
| 267 | − } | |
| 239 | + m_hTraceHandle = LoadLibrary ("welstrace.bundle"); | |
| 240 | + if (m_hTraceHandle) { | |
| 241 | + m_fpDebugTrace = (CM_WELS_TRACE)GetProcessAddress ((CFBundleRef)m_hTraceHandle, "WELSDEBUG2"); | |
| 242 | + m_fpInfoTrace = (CM_WELS_TRACE)GetProcessAddress ((CFBundleRef)m_hTraceHandle, "WELSINFO2"); | |
| 243 | + m_fpWarnTrace = (CM_WELS_TRACE)GetProcessAddress ((CFBundleRef)m_hTraceHandle, "WELSWARN2"); | |
| 244 | + m_fpErrorTrace = (CM_WELS_TRACE)GetProcessAddress ((CFBundleRef)m_hTraceHandle, "WELSERROR2"); | |
| 245 | + } | |
| 268 | 246 | #elif defined LINUX || defined SOLARIS || defined UNIX |
| 269 | 247 | //#else |
| 270 | 248 | // CCmString cmPath; |
| 271 | − str_t chPath[255]= {0}; | |
| 272 | − Dl_info sDlInfo; | |
| 273 | − static int iMmTPAddress; | |
| 274 | − dladdr( &iMmTPAddress, &sDlInfo); | |
| 275 | − | |
| 276 | − if (NULL == sDlInfo.dli_fname) | |
| 277 | − return -1; | |
| 278 | − WelsStrncpy(chPath, 255, (const str_t*)sDlInfo.dli_fname, WelsStrnlen((const str_t*)sDlInfo.dli_fname, 255)); | |
| 279 | − str_t* p = strrchr(chPath, '/');//confirmed_safe_unsafe_usage | |
| 280 | − if ( NULL == p ) | |
| 281 | − return -1; | |
| 282 | − const int iLenTraceName = WelsStrnlen((const str_t*)"/libwelstrace.so", 15); | |
| 283 | − const int iCurPos = p - chPath; | |
| 284 | − if ( iCurPos + iLenTraceName < 255 ) | |
| 285 | − WelsStrncpy(p, 254-iCurPos, (const str_t*)"/libwelstrace.so", iLenTraceName ); | |
| 286 | − else | |
| 287 | − return -1; | |
| 288 | − | |
| 289 | − m_hTraceHandle = dlopen( chPath, RTLD_LAZY); | |
| 290 | − if (m_hTraceHandle == NULL) | |
| 291 | − { | |
| 292 | − WelsFileHandle* fp = WelsFopen((const str_t*)"/tmp/trace.txt", (const str_t*)"a"); | |
| 293 | − if(fp) | |
| 294 | − { | |
| 295 | − fprintf(fp, "welsCodecTrace::welsCodecTrace ===> dlopen %s fail, %s\n", chPath, dlerror()); | |
| 296 | − WelsFclose(fp); | |
| 297 | − } | |
| 298 | − return -1; | |
| 299 | − } | |
| 300 | − if (m_hTraceHandle) { | |
| 301 | − m_fpDebugTrace = ( CM_WELS_TRACE)dlsym( m_hTraceHandle, "WELSDEBUG2"); | |
| 302 | − m_fpInfoTrace = ( CM_WELS_TRACE)dlsym( m_hTraceHandle, "WELSINFO2"); | |
| 303 | − m_fpWarnTrace = ( CM_WELS_TRACE)dlsym( m_hTraceHandle, "WELSWARN2"); | |
| 304 | − m_fpErrorTrace = ( CM_WELS_TRACE)dlsym( m_hTraceHandle, "WELSERROR2"); | |
| 305 | − if(m_fpDebugTrace == NULL) | |
| 306 | − { | |
| 307 | − WelsFileHandle* fp = WelsFopen((const str_t*)"/tmp/trace.txt", (const str_t*)"a"); | |
| 308 | − if(fp) | |
| 309 | − { | |
| 310 | − printf("welsCodecTrace::welsCodecTrace ===> dlsym failed (WELSDEBUG2) , dlerror = %s\n", dlerror()); | |
| 311 | − WelsFclose(fp); | |
| 312 | − } | |
| 313 | − return -1; | |
| 314 | − } | |
| 315 | − } | |
| 249 | + str_t chPath[255] = {0}; | |
| 250 | + Dl_info sDlInfo; | |
| 251 | + static int iMmTPAddress; | |
| 252 | + dladdr (&iMmTPAddress, &sDlInfo); | |
| 253 | + | |
| 254 | + if (NULL == sDlInfo.dli_fname) | |
| 255 | + return -1; | |
| 256 | + WelsStrncpy (chPath, 255, (const str_t*)sDlInfo.dli_fname, WelsStrnlen ((const str_t*)sDlInfo.dli_fname, 255)); | |
| 257 | + str_t* p = strrchr (chPath, '/'); //confirmed_safe_unsafe_usage | |
| 258 | + if (NULL == p) | |
| 259 | + return -1; | |
| 260 | + const int iLenTraceName = WelsStrnlen ((const str_t*)"/libwelstrace.so", 15); | |
| 261 | + const int iCurPos = p - chPath; | |
| 262 | + if (iCurPos + iLenTraceName < 255) | |
| 263 | + WelsStrncpy (p, 254 - iCurPos, (const str_t*)"/libwelstrace.so", iLenTraceName); | |
| 264 | + else | |
| 265 | + return -1; | |
| 266 | + | |
| 267 | + m_hTraceHandle = dlopen (chPath, RTLD_LAZY); | |
| 268 | + if (m_hTraceHandle == NULL) { | |
| 269 | + WelsFileHandle* fp = WelsFopen ((const str_t*)"/tmp/trace.txt", (const str_t*)"a"); | |
| 270 | + if (fp) { | |
| 271 | + fprintf (fp, "welsCodecTrace::welsCodecTrace ===> dlopen %s fail, %s\n", chPath, dlerror()); | |
| 272 | + WelsFclose (fp); | |
| 273 | + } | |
| 274 | + return -1; | |
| 275 | + } | |
| 276 | + if (m_hTraceHandle) { | |
| 277 | + m_fpDebugTrace = (CM_WELS_TRACE)dlsym (m_hTraceHandle, "WELSDEBUG2"); | |
| 278 | + m_fpInfoTrace = (CM_WELS_TRACE)dlsym (m_hTraceHandle, "WELSINFO2"); | |
| 279 | + m_fpWarnTrace = (CM_WELS_TRACE)dlsym (m_hTraceHandle, "WELSWARN2"); | |
| 280 | + m_fpErrorTrace = (CM_WELS_TRACE)dlsym (m_hTraceHandle, "WELSERROR2"); | |
| 281 | + if (m_fpDebugTrace == NULL) { | |
| 282 | + WelsFileHandle* fp = WelsFopen ((const str_t*)"/tmp/trace.txt", (const str_t*)"a"); | |
| 283 | + if (fp) { | |
| 284 | + printf ("welsCodecTrace::welsCodecTrace ===> dlsym failed (WELSDEBUG2) , dlerror = %s\n", dlerror()); | |
| 285 | + WelsFclose (fp); | |
| 286 | + } | |
| 287 | + return -1; | |
| 288 | + } | |
| 289 | + } | |
| 316 | 290 | #endif |
| 317 | 291 | #endif // NO_DYNAMIC_VP |
| 318 | − return 0; | |
| 292 | + return 0; | |
| 319 | 293 | } |
| 320 | 294 | |
| 321 | −int32_t CWelsCodecTrace::UnloadWelsTraceModule() | |
| 322 | −{ | |
| 295 | +int32_t CWelsCodecTrace::UnloadWelsTraceModule() { | |
| 323 | 296 | #if defined WIN32 |
| 324 | − if( m_hTraceHandle) { | |
| 325 | − ::FreeLibrary( ( HMODULE)m_hTraceHandle); | |
| 326 | − } | |
| 297 | + if (m_hTraceHandle) { | |
| 298 | + ::FreeLibrary ((HMODULE)m_hTraceHandle); | |
| 299 | + } | |
| 327 | 300 | #elif defined MACOS |
| 328 | − if (m_hTraceHandle) { | |
| 329 | − FreeLibrary( (CFBundleRef)m_hTraceHandle); | |
| 330 | − } | |
| 301 | + if (m_hTraceHandle) { | |
| 302 | + FreeLibrary ((CFBundleRef)m_hTraceHandle); | |
| 303 | + } | |
| 331 | 304 | #elif defined LINUX || defined SOLARIS || defined UNIX |
| 332 | − if (m_hTraceHandle) { | |
| 333 | − ::dlclose( m_hTraceHandle); | |
| 334 | − } | |
| 305 | + if (m_hTraceHandle) { | |
| 306 | + ::dlclose (m_hTraceHandle); | |
| 307 | + } | |
| 335 | 308 | #endif |
| 336 | 309 | |
| 337 | − m_hTraceHandle = NULL; | |
| 338 | − m_fpDebugTrace = NULL; | |
| 339 | − m_fpInfoTrace = NULL; | |
| 340 | − m_fpWarnTrace = NULL; | |
| 341 | − m_fpErrorTrace = NULL; | |
| 342 | − return 0; | |
| 310 | + m_hTraceHandle = NULL; | |
| 311 | + m_fpDebugTrace = NULL; | |
| 312 | + m_fpInfoTrace = NULL; | |
| 313 | + m_fpWarnTrace = NULL; | |
| 314 | + m_fpErrorTrace = NULL; | |
| 315 | + return 0; | |
| 343 | 316 | } |
| 344 | 317 | |
| 345 | −int32_t CWelsCodecTrace::WriteString(int32_t iLevel, const str_t * pStr) | |
| 346 | −{ | |
| 318 | +int32_t CWelsCodecTrace::WriteString (int32_t iLevel, const str_t* pStr) { | |
| 347 | 319 | #ifndef NO_DYNAMIC_VP |
| 348 | − if( m_hTraceHandle ) | |
| 320 | + if (m_hTraceHandle) | |
| 349 | 321 | #endif |
| 350 | − { | |
| 322 | + { | |
| 351 | 323 | #ifdef WIN32 |
| 352 | − switch(iLevel) | |
| 353 | − { | |
| 354 | − case WELS_LOG_ERROR: | |
| 355 | − if(m_fpErrorTrace) | |
| 356 | − m_fpErrorTrace("%s", pStr); | |
| 357 | − break; | |
| 358 | − case WELS_LOG_WARNING: | |
| 359 | − if(m_fpWarnTrace) | |
| 360 | − m_fpWarnTrace("%s", pStr); | |
| 361 | − break; | |
| 362 | − case WELS_LOG_INFO: | |
| 363 | − if(m_fpInfoTrace) | |
| 364 | − m_fpInfoTrace("%s", pStr); | |
| 365 | − break; | |
| 366 | − case WELS_LOG_DEBUG: | |
| 367 | − if(m_fpDebugTrace) | |
| 368 | − m_fpDebugTrace("%s", pStr); | |
| 369 | − break; | |
| 370 | − default: | |
| 371 | − if(m_fpDebugTrace) | |
| 372 | − m_fpInfoTrace("%s", pStr); | |
| 373 | − break; | |
| 374 | − } | |
| 324 | + switch (iLevel) { | |
| 325 | + case WELS_LOG_ERROR: | |
| 326 | + if (m_fpErrorTrace) | |
| 327 | + m_fpErrorTrace ("%s", pStr); | |
| 328 | + break; | |
| 329 | + case WELS_LOG_WARNING: | |
| 330 | + if (m_fpWarnTrace) | |
| 331 | + m_fpWarnTrace ("%s", pStr); | |
| 332 | + break; | |
| 333 | + case WELS_LOG_INFO: | |
| 334 | + if (m_fpInfoTrace) | |
| 335 | + m_fpInfoTrace ("%s", pStr); | |
| 336 | + break; | |
| 337 | + case WELS_LOG_DEBUG: | |
| 338 | + if (m_fpDebugTrace) | |
| 339 | + m_fpDebugTrace ("%s", pStr); | |
| 340 | + break; | |
| 341 | + default: | |
| 342 | + if (m_fpDebugTrace) | |
| 343 | + m_fpInfoTrace ("%s", pStr); | |
| 344 | + break; | |
| 345 | + } | |
| 375 | 346 | #else |
| 376 | − switch(iLevel) | |
| 377 | − { | |
| 378 | − case WELS_LOG_ERROR: | |
| 379 | − if(m_fpErrorTrace) | |
| 380 | − m_fpErrorTrace("CODEC", "%s", pStr); | |
| 381 | − break; | |
| 382 | − case WELS_LOG_WARNING: | |
| 383 | − if(m_fpWarnTrace) | |
| 384 | − m_fpWarnTrace("CODEC", "%s", pStr); | |
| 385 | − break; | |
| 386 | − case WELS_LOG_INFO: | |
| 387 | − if(m_fpInfoTrace) | |
| 388 | − m_fpInfoTrace("CODEC", "%s", pStr); | |
| 389 | − break; | |
| 390 | − case WELS_LOG_DEBUG: | |
| 391 | − if(m_fpInfoTrace) | |
| 392 | − m_fpInfoTrace("CODEC", "%s", pStr); | |
| 393 | − break; | |
| 394 | − default: | |
| 395 | − if(m_fpInfoTrace) | |
| 396 | − m_fpInfoTrace("CODEC", "%s", pStr); | |
| 397 | − break; | |
| 398 | − } | |
| 347 | + switch (iLevel) { | |
| 348 | + case WELS_LOG_ERROR: | |
| 349 | + if (m_fpErrorTrace) | |
| 350 | + m_fpErrorTrace ("CODEC", "%s", pStr); | |
| 351 | + break; | |
| 352 | + case WELS_LOG_WARNING: | |
| 353 | + if (m_fpWarnTrace) | |
| 354 | + m_fpWarnTrace ("CODEC", "%s", pStr); | |
| 355 | + break; | |
| 356 | + case WELS_LOG_INFO: | |
| 357 | + if (m_fpInfoTrace) | |
| 358 | + m_fpInfoTrace ("CODEC", "%s", pStr); | |
| 359 | + break; | |
| 360 | + case WELS_LOG_DEBUG: | |
| 361 | + if (m_fpInfoTrace) | |
| 362 | + m_fpInfoTrace ("CODEC", "%s", pStr); | |
| 363 | + break; | |
| 364 | + default: | |
| 365 | + if (m_fpInfoTrace) | |
| 366 | + m_fpInfoTrace ("CODEC", "%s", pStr); | |
| 367 | + break; | |
| 368 | + } | |
| 399 | 369 | #endif |
| 400 | − } | |
| 370 | + } | |
| 401 | 371 | |
| 402 | − return 0; | |
| 372 | + return 0; | |
| 403 | 373 | } |
| 404 | 374 | |
| 405 | 375 | |
| 406 | −IWelsTrace * CreateWelsTrace(EWelsTraceType eType, void_t * pParam) | |
| 407 | −{ | |
| 408 | − IWelsTrace * pTrace = NULL; | |
| 409 | − switch(eType) | |
| 410 | − { | |
| 411 | − case Wels_Trace_Type: | |
| 412 | − pTrace = new CWelsCodecTrace(); | |
| 413 | − break; | |
| 414 | − case Wels_Trace_Type_File: | |
| 415 | − pTrace = new CWelsTraceFile(); | |
| 416 | − break; | |
| 376 | +IWelsTrace* CreateWelsTrace (EWelsTraceType eType, void_t* pParam) { | |
| 377 | + IWelsTrace* pTrace = NULL; | |
| 378 | + switch (eType) { | |
| 379 | + case Wels_Trace_Type: | |
| 380 | + pTrace = new CWelsCodecTrace(); | |
| 381 | + break; | |
| 382 | + case Wels_Trace_Type_File: | |
| 383 | + pTrace = new CWelsTraceFile(); | |
| 384 | + break; | |
| 417 | 385 | #ifdef WIN32 |
| 418 | − case Wels_Trace_Type_WinDgb: | |
| 419 | − pTrace = new CWelsTraceWinDgb(); | |
| 420 | − break; | |
| 386 | + case Wels_Trace_Type_WinDgb: | |
| 387 | + pTrace = new CWelsTraceWinDgb(); | |
| 388 | + break; | |
| 421 | 389 | #endif |
| 422 | − default: | |
| 423 | − break; | |
| 424 | − } | |
| 390 | + default: | |
| 391 | + break; | |
| 392 | + } | |
| 425 | 393 | |
| 426 | − return pTrace; | |
| 394 | + return pTrace; | |
| 427 | 395 | } |
| 428 | 396 | |
| 429 | 397 | } // namespace WelsDec |