Пример #1
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;
}
Пример #2
0
/*!
 * \brief   get library/module name
 * \param   pBuf    pBuffer to restore module name
 * \param   iSize   size of pBuffer overall
 * \return  actual size of pBuffer used; 0 returned in failure
 */
int32_t GetLibName (char* pBuf, int32_t iSize) {
  int32_t iLen = 0;

  if (NULL == pBuf)
    return 0;

  iLen = (int32_t)strlen (WELS_LIB_NAME); // confirmed_safe_unsafe_usage
  if (iSize <= iLen)
    return 0;

  WelsStrncpy (pBuf, iSize, WELS_LIB_NAME); // confirmed_safe_unsafe_usage

  return iLen;
}
Пример #3
0
/*!
 * \brief   get identify information
 * \param   pBuf    pBuffer to restore indentify information
 * \param   iSize   size of pBuffer overall
 * \return  actual size of pBuffer used; 0 returned in failure
 */
int32_t GetIdentInfo (char* pBuf, int32_t iSize) {
  int32_t iLen = 0;

  if (NULL == pBuf)
    return 0;

  iLen = (int32_t)strlen (WELS_IDENT); // confirmed_safe_unsafe_usage
  if (iSize <= iLen)
    return 0;

  WelsStrncpy (pBuf, iSize, WELS_IDENT); // confirmed_safe_unsafe_usage

  return iLen;
}
Пример #4
0
/*!
 * \brief   get version number
 * \param   pBuf    pBuffer to restore version number
 * \param   iSize   size of pBuffer overall
 * \return  actual size of pBuffer used; 0 returned in failure
 */
int32_t GetVerNum (char* pBuf, int32_t iSize) {
  int32_t iLen = 0;

  if (NULL == pBuf)
    return 0;

  iLen = (int32_t)strlen (WELS_VERSION_STR); // confirmed_safe_unsafe_usage
  if (iSize <= iLen)
    return 0;

  WelsStrncpy (pBuf, iSize, WELS_VERSION_STR); // confirmed_safe_unsafe_usage

  return iLen;
}
Пример #5
0
int32_t  CWelsTraceBase::Trace (const int kLevel, const char* kpFormat, va_list pVl) {
  if (kLevel & m_iLevel) {
    char chBuf[MAX_LOG_SIZE] = {0};
    const int32_t kLen	= strlen ("[DECODER]: ");

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

    WelsVsnprintf ((chBuf + kLen),  MAX_LOG_SIZE - kLen, (const char*)kpFormat, pVl);

    WriteString (kLevel, chBuf);
  }

  return 0;
}
Пример #6
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;
}
Пример #7
0
char* WelsStrcat (char* pDest, int32_t iSizeInBytes, const char* kpSrc) {
  int32_t iCurLen = (int32_t)strlen (pDest);
  return WelsStrncpy (pDest + iCurLen, iSizeInBytes - iCurLen, kpSrc);
}
Пример #8
0
char* WelsStrcat (char* pDest, uint32_t uiSizeInBytes, const char* kpSrc) {
    uint32_t uiCurLen = (uint32_t) strlen (pDest);
    if (uiSizeInBytes > uiCurLen)
        return WelsStrncpy (pDest + uiCurLen, uiSizeInBytes - uiCurLen, kpSrc);
    return pDest;
}