No code exists within the project for building such a trace library. This also fixes building on OS X with -Wno-deprecated-declarations removed, since this code contained calls to deprecated functions within #ifdef MACOS, which now are enabled when building on OS X.
Showing the changes to codec/decoder/plus/src/welsCodecTrace.cpp (1 of 6 files). Show all
Unified · Split
| @@ -45,91 +45,11 @@ · 44 unmodified lines | |||
| 45 | #include "welsCodecTrace.h" | 45 | #include "welsCodecTrace.h" |
| 46 | #include "utils.h" | 46 | #include "utils.h" |
| 47 | #include "logging.h" | 47 | #include "logging.h" |
| 48 | #if defined LINUX || defined SOLARIS || defined UNIX || defined MACOS //LINUX/SOLARIS/UNIX | ||
| 49 | #include <dlfcn.h> | ||
| 50 | #endif | ||
| 51 | |||
| 52 | #if defined(MACOS) | ||
| 53 | #include <carbon/carbon.h> | ||
| 54 | #include <CoreFoundation/CFBundle.h> | ||
| 55 | #endif//MACOS | ||
| 56 | 48 | ||
| 57 | //using namespace WelsDec; | 49 | //using namespace WelsDec; |
| 58 | 50 | ||
| 59 | namespace WelsDec { | 51 | namespace WelsDec { |
| 60 | 52 | ||
| 61 | #ifdef MACOS | ||
| 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 | |||
| 103 | // Boolean bReturn = FALSE; | ||
| 104 | if (NULL != bundleRef) { | ||
| 105 | // bReturn = CFBundleLoadExecutable(bundleRef); | ||
| 106 | } | ||
| 107 | |||
| 108 | return bundleRef; | ||
| 109 | } | ||
| 110 | |||
| 111 | static Boolean FreeLibrary (CFBundleRef bundle) { | ||
| 112 | if (NULL != bundle) { | ||
| 113 | // CFBundleUnloadExecutable(bundle); | ||
| 114 | CFRelease (bundle); | ||
| 115 | } | ||
| 116 | |||
| 117 | return TRUE; | ||
| 118 | } | ||
| 119 | |||
| 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; | ||
| 129 | } | ||
| 130 | #endif | ||
| 131 | |||
| 132 | |||
| 133 | 53 | ||
| 134 | int32_t CWelsTraceBase::SetTraceLevel (int iLevel) { | 54 | int32_t CWelsTraceBase::SetTraceLevel (int iLevel) { |
| 135 | m_iLevel = iLevel; | 55 | m_iLevel = iLevel; |
| @@ -191,7 +111,6 @@ int32_t CWelsTraceWinDgb::WriteString (int32_t iLevel, const str_t* pStr) { · 55 unmodified lines | |||
| 191 | #endif | 111 | #endif |
| 192 | 112 | ||
| 193 | CWelsCodecTrace::CWelsCodecTrace() { | 113 | CWelsCodecTrace::CWelsCodecTrace() { |
| 194 | m_hTraceHandle = NULL; | ||
| 195 | m_fpDebugTrace = NULL; | 114 | m_fpDebugTrace = NULL; |
| 196 | m_fpInfoTrace = NULL; | 115 | m_fpInfoTrace = NULL; |
| 197 | m_fpWarnTrace = NULL; | 116 | m_fpWarnTrace = NULL; |
| @@ -205,111 +124,14 @@ CWelsCodecTrace::~CWelsCodecTrace() { · 7 unmodified lines | |||
| 205 | } | 124 | } |
| 206 | 125 | ||
| 207 | int32_t CWelsCodecTrace::LoadWelsTraceModule() { | 126 | int32_t CWelsCodecTrace::LoadWelsTraceModule() { |
| 208 | #ifdef NO_DYNAMIC_VP | ||
| 209 | m_fpDebugTrace = welsStderrTrace<WELS_LOG_DEBUG>; | 127 | m_fpDebugTrace = welsStderrTrace<WELS_LOG_DEBUG>; |
| 210 | m_fpInfoTrace = welsStderrTrace<WELS_LOG_INFO>; | 128 | m_fpInfoTrace = welsStderrTrace<WELS_LOG_INFO>; |
| 211 | m_fpWarnTrace = welsStderrTrace<WELS_LOG_WARNING>; | 129 | m_fpWarnTrace = welsStderrTrace<WELS_LOG_WARNING>; |
| 212 | m_fpErrorTrace = welsStderrTrace<WELS_LOG_ERROR>; | 130 | m_fpErrorTrace = welsStderrTrace<WELS_LOG_ERROR>; |
| 213 | #else | ||
| 214 | #if defined _WIN32 | ||
| 215 | HMODULE hHandle = ::LoadLibrary ("welstrace.dll"); | ||
| 216 | // HMODULE handle = ::LoadLibrary("contrace.dll"); // for c7 trace | ||
| 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 | } | ||
| 238 | #elif defined MACOS | ||
| 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 | } | ||
| 246 | #elif defined LINUX || defined SOLARIS || defined UNIX | ||
| 247 | //#else | ||
| 248 | // CCmString cmPath; | ||
| 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 | } | ||
| 290 | #endif | ||
| 291 | #endif // NO_DYNAMIC_VP | ||
| 292 | return 0; | 131 | return 0; |
| 293 | } | 132 | } |
| 294 | 133 | ||
| 295 | int32_t CWelsCodecTrace::UnloadWelsTraceModule() { | 134 | int32_t CWelsCodecTrace::UnloadWelsTraceModule() { |
| 296 | #ifndef NO_DYNAMIC_VP | ||
| 297 | #if defined _WIN32 | ||
| 298 | if (m_hTraceHandle) { | ||
| 299 | ::FreeLibrary ((HMODULE)m_hTraceHandle); | ||
| 300 | } | ||
| 301 | #elif defined MACOS | ||
| 302 | if (m_hTraceHandle) { | ||
| 303 | FreeLibrary ((CFBundleRef)m_hTraceHandle); | ||
| 304 | } | ||
| 305 | #elif defined LINUX || defined SOLARIS || defined UNIX | ||
| 306 | if (m_hTraceHandle) { | ||
| 307 | ::dlclose (m_hTraceHandle); | ||
| 308 | } | ||
| 309 | #endif | ||
| 310 | #endif | ||
| 311 | |||
| 312 | m_hTraceHandle = NULL; | ||
| 313 | m_fpDebugTrace = NULL; | 135 | m_fpDebugTrace = NULL; |
| 314 | m_fpInfoTrace = NULL; | 136 | m_fpInfoTrace = NULL; |
| 315 | m_fpWarnTrace = NULL; | 137 | m_fpWarnTrace = NULL; |
| @@ -318,9 +140,6 @@ int32_t CWelsCodecTrace::UnloadWelsTraceModule() { · 2 unmodified lines | |||
| 318 | } | 140 | } |
| 319 | 141 | ||
| 320 | int32_t CWelsCodecTrace::WriteString (int32_t iLevel, const str_t* pStr) { | 142 | int32_t CWelsCodecTrace::WriteString (int32_t iLevel, const str_t* pStr) { |
| 321 | #ifndef NO_DYNAMIC_VP | ||
| 322 | if (m_hTraceHandle) | ||
| 323 | #endif | ||
| 324 | { | 143 | { |
| 325 | #ifdef _WIN32 | 144 | #ifdef _WIN32 |
| 326 | switch (iLevel) { | 145 | switch (iLevel) { |