Example #1
0
int32_t CWelsTraceFile::WriteString (int32_t iLevel, const str_t* pStr) {
  int  iRC = 0;
  const static str_t chEnter[16] = "\n";
  if (m_pTraceFile) {
    iRC += WelsFwrite (pStr, 1, WelsStrnlen (pStr, MAX_LOG_SIZE), m_pTraceFile);
    iRC += WelsFwrite (chEnter, 1, WelsStrnlen (chEnter,  16), m_pTraceFile);
    WelsFflush (m_pTraceFile);
  }
  return iRC;
}
Example #2
0
int32_t  CWelsTraceBase::Trace (const int kLevel, const str_t* kpFormat, va_list pVl) {
  if (kLevel & m_iLevel) {
    str_t chWStrFormat[MAX_LOG_SIZE] = {0};
    str_t chBuf[MAX_LOG_SIZE] = {0};
    str_t chResult[MAX_LOG_SIZE] = {0};
    const int32_t kLen	= WelsStrnlen ((const str_t*)"[DECODER]: ", MAX_LOG_SIZE);

    WelsStrncpy (chWStrFormat, MAX_LOG_SIZE, (const str_t*)kpFormat, WelsStrnlen ((const str_t*)kpFormat, MAX_LOG_SIZE));

    WelsStrncpy (chBuf, MAX_LOG_SIZE, (const str_t*)"[DECODER]: ", kLen);

    WelsVsprintf ((chBuf + kLen),  MAX_LOG_SIZE - kLen, (const str_t*)kpFormat, pVl);
    WelsStrncpy (chResult, MAX_LOG_SIZE, (const str_t*)chBuf, WelsStrnlen ((const str_t*)chBuf, MAX_LOG_SIZE));

    WriteString (kLevel, chResult);
  }

  return 0;
}
Example #3
0
int32_t  CWelsCodecTrace::LoadWelsTraceModule()
{
#ifdef NO_DYNAMIC_VP
        m_fpDebugTrace = welsStderrTrace<WELS_LOG_DEBUG>;
        m_fpInfoTrace = welsStderrTrace<WELS_LOG_INFO>;
        m_fpWarnTrace = welsStderrTrace<WELS_LOG_WARNING>;
        m_fpErrorTrace = welsStderrTrace<WELS_LOG_ERROR>;
#else
#if defined WIN32	
	HMODULE hHandle = ::LoadLibrary("welstrace.dll");
//	HMODULE handle = ::LoadLibrary("contrace.dll");  // for c7 trace
	if ( NULL == hHandle )
		return -1;

	CHAR chPath[ _MAX_PATH]= {0};
	GetModuleFileName( (HMODULE)hHandle, chPath, _MAX_PATH);

	m_hTraceHandle = ::LoadLibrary(chPath);
	
	OutputDebugStringA(chPath);
	if( m_hTraceHandle) {
		m_fpDebugTrace = ( CM_WELS_TRACE)::GetProcAddress( ( HMODULE)m_hTraceHandle, "WELSDEBUGA");
		m_fpInfoTrace = ( CM_WELS_TRACE)::GetProcAddress( ( HMODULE)m_hTraceHandle, "WELSINFOA");
		m_fpWarnTrace = ( CM_WELS_TRACE)::GetProcAddress( ( HMODULE)m_hTraceHandle, "WELSWARNA");
		m_fpErrorTrace = ( CM_WELS_TRACE)::GetProcAddress( ( HMODULE)m_hTraceHandle, "WELSERRORA");
	}

	// coverity scan uninitial
	if (hHandle != NULL)
	{
		::FreeLibrary(hHandle);
		hHandle = NULL;
	}
#elif defined MACOS
	m_hTraceHandle = LoadLibrary("welstrace.bundle");
	if(m_hTraceHandle) {
		m_fpDebugTrace = ( CM_WELS_TRACE)GetProcessAddress( (CFBundleRef)m_hTraceHandle, "WELSDEBUG2");
		m_fpInfoTrace = ( CM_WELS_TRACE)GetProcessAddress( (CFBundleRef)m_hTraceHandle, "WELSINFO2");
		m_fpWarnTrace = ( CM_WELS_TRACE)GetProcessAddress( (CFBundleRef)m_hTraceHandle, "WELSWARN2");
		m_fpErrorTrace = ( CM_WELS_TRACE)GetProcessAddress( (CFBundleRef)m_hTraceHandle, "WELSERROR2");
	}
#elif defined LINUX || defined SOLARIS || defined UNIX
//#else
//	CCmString	cmPath;
	str_t chPath[255]= {0};
	Dl_info		sDlInfo;
	static int	iMmTPAddress;
    dladdr( &iMmTPAddress, &sDlInfo);

	if (NULL == sDlInfo.dli_fname)
		return -1;
	WelsStrncpy(chPath, 255, (const str_t*)sDlInfo.dli_fname, WelsStrnlen((const str_t*)sDlInfo.dli_fname, 255));
	str_t* p = strrchr(chPath, '/');//confirmed_safe_unsafe_usage
	if ( NULL == p )
		return -1;
	const int iLenTraceName = WelsStrnlen((const str_t*)"/libwelstrace.so", 15);
	const int iCurPos = p - chPath;
	if ( iCurPos + iLenTraceName < 255 )
		WelsStrncpy(p, 254-iCurPos, (const str_t*)"/libwelstrace.so", iLenTraceName );
	else
		return -1;

	m_hTraceHandle = dlopen( chPath, RTLD_LAZY);
	if (m_hTraceHandle == NULL)
	{
		WelsFileHandle* fp = WelsFopen((const str_t*)"/tmp/trace.txt", (const str_t*)"a");
		if(fp)
		{
			fprintf(fp, "welsCodecTrace::welsCodecTrace ===> dlopen %s fail, %s\n", chPath, dlerror());
			WelsFclose(fp);
		}
		return -1;
	}
	if (m_hTraceHandle) {
		m_fpDebugTrace = ( CM_WELS_TRACE)dlsym( m_hTraceHandle, "WELSDEBUG2");
		m_fpInfoTrace = ( CM_WELS_TRACE)dlsym( m_hTraceHandle, "WELSINFO2");
		m_fpWarnTrace = ( CM_WELS_TRACE)dlsym( m_hTraceHandle, "WELSWARN2");
		m_fpErrorTrace = ( CM_WELS_TRACE)dlsym( m_hTraceHandle, "WELSERROR2");
		if(m_fpDebugTrace == NULL)
		{
			WelsFileHandle* fp = WelsFopen((const str_t*)"/tmp/trace.txt", (const str_t*)"a");
			if(fp)
			{
				printf("welsCodecTrace::welsCodecTrace ===> dlsym failed (WELSDEBUG2) , dlerror = %s\n", dlerror());
				WelsFclose(fp);
			}
			return -1;
		}
	}
#endif
#endif  // NO_DYNAMIC_VP
	return 0;
}
Example #4
0
int32_t CWelsTraceWinDgb::WriteString(int32_t iLevel, const str_t * pStr)
{
	OutputDebugStringA(pStr);

	return WelsStrnlen(pStr, MAX_LOG_SIZE);//strnlen(pStr, MAX_LOG_SIZE);
}