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