Use WelsSnprintf instead of SNPRINTF

This commit is contained in:
Martin Storsjö 2014-01-26 14:43:30 +02:00
parent 6fea084a42
commit f6fe4ddeaa
6 changed files with 29 additions and 117 deletions

View File

@ -420,7 +420,6 @@ static __inline int wels_strnlen_s (const char* dest, int dmax) {
#if defined(WIN32) && defined(_MSC_VER)
#if _MSC_VER >= 1500 // VS2008
#define SNPRINTF _snprintf_s
#define LOCALTIME localtime_s
#define FTIME _ftime_s
#define STRNCPY strncpy_s
@ -428,7 +427,6 @@ static __inline int wels_strnlen_s (const char* dest, int dmax) {
#define STRNLEN strnlen_s
#define VSPRINTF vsprintf_s
#else // mainly for VC6
#define SNPRINTF _snprintf
#define LOCALTIME localtime
#define FTIME _ftime
#define STRNCPY wels_strncpy_s // override s.t.r.n.c.p.y here for safe
@ -439,7 +437,6 @@ static __inline int wels_strnlen_s (const char* dest, int dmax) {
#else//__GNUC__
#define SNPRINTF snprintf
#define LOCALTIME localtime
#define STRNCPY wels_strncpy_s // override s.t.r.n.c.p.y here for safe
#define STRCAT wels_strcat_s // override s.t.r.c.a.t here for safe

View File

@ -327,11 +327,7 @@ extern "C" void DumpDependencyRec (SPicture* pCurPicture, const str_t* kpFileNam
pDumpRecFile = WelsFopen (kpFileName, "ab");
else {
str_t sDependencyRecFileName[16] = {0};
#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008
SNPRINTF (sDependencyRecFileName, 16, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
#else
SNPRINTF (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
#endif//WIN32..
WelsSnprintf (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
pDumpRecFile = WelsFopen (sDependencyRecFileName, "ab");
}
if (NULL != pDumpRecFile)
@ -341,11 +337,7 @@ extern "C" void DumpDependencyRec (SPicture* pCurPicture, const str_t* kpFileNam
pDumpRecFile = WelsFopen (kpFileName, "wb");
} else {
str_t sDependencyRecFileName[16] = {0};
#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008
SNPRINTF (sDependencyRecFileName, 16, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
#else
SNPRINTF (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
#endif//WIN32..
WelsSnprintf (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
pDumpRecFile = WelsFopen (sDependencyRecFileName, "wb");
}
bDependencyRecFlag[kiDid] = true;

View File

@ -2085,19 +2085,8 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar
if (wlog == WelsLogDefault) {
str_t fname[MAX_FNAME_LEN] = {0};
#if defined (_MSC_VER)
#if _MSC_VER>=1500
SNPRINTF (fname, MAX_FNAME_LEN, MAX_FNAME_LEN, "%swels_svc_encoder_trace.txt",
pCodingParam->sTracePath); // confirmed_safe_unsafe_usage
#else
SNPRINTF (fname, MAX_FNAME_LEN, "%swels_svc_encoder_trace.txt",
pCodingParam->sTracePath); // confirmed_safe_unsafe_usage
#endif//_MSC_VER>=1500
#else
//GNUC/
SNPRINTF (fname, MAX_FNAME_LEN, "%swels_svc_encoder_trace.txt",
pCodingParam->sTracePath); // confirmed_safe_unsafe_usage
#endif//_MSC_VER
WelsSnprintf (fname, MAX_FNAME_LEN, "%swels_svc_encoder_trace.txt",
pCodingParam->sTracePath); // confirmed_safe_unsafe_usage
pCtx->pFileLog = WelsFopen (fname, "wt+");

View File

@ -456,12 +456,12 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara
WelsEventInit (&pSmt->pFinUpdateMbListEvent[iIdx]);
#else
// length of semaphore name should be system constrained at least on mac 10.7
SNPRINTF (name, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx));
WelsSnprintf (name, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx));
err = WelsEventOpen (&pSmt->pUpdateMbListEvent[iIdx], name);
#if defined(ENABLE_TRACE_MT)
WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
#endif
SNPRINTF (name, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx));
WelsSnprintf (name, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx));
err = WelsEventOpen (&pSmt->pFinUpdateMbListEvent[iIdx], name);
#if defined(ENABLE_TRACE_MT)
WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
@ -475,12 +475,12 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara
WelsEventInit (&pSmt->pFinSliceCodingEvent[iIdx]);
WelsEventInit (&pSmt->pExitEncodeEvent[iIdx]);
#else
SNPRINTF (name, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx));
WelsSnprintf (name, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx));
err = WelsEventOpen (&pSmt->pSliceCodedEvent[iIdx], name);
#if defined(ENABLE_TRACE_MT)
WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pSliceCodedEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
#endif
SNPRINTF (name, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx));
WelsSnprintf (name, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx));
err = WelsEventOpen (&pSmt->pReadySliceCodingEvent[iIdx], name);
#if defined(ENABLE_TRACE_MT)
WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pReadySliceCodingEvent%d = 0x%p named(%s) ret%d err%d\n", iIdx,
@ -574,14 +574,14 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) {
#else
str_t ename[SEM_NAME_MAX] = {0};
// length of semaphore name should be system constrained at least on mac 10.7
SNPRINTF (ename, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx));
WelsSnprintf (ename, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx));
WelsEventClose (pSmt->pSliceCodedEvent[iIdx], ename);
SNPRINTF (ename, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx));
WelsSnprintf (ename, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx));
WelsEventClose (pSmt->pReadySliceCodingEvent[iIdx], ename);
#if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE)
SNPRINTF (ename, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx));
WelsSnprintf (ename, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx));
WelsEventClose (pSmt->pUpdateMbListEvent[iIdx], ename);
SNPRINTF (ename, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx));
WelsSnprintf (ename, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx));
WelsEventClose (pSmt->pFinUpdateMbListEvent[iIdx], ename);
#endif//DYNAMIC_SLICE_ASSIGN && TRY_SLICING_BALANCE
#endif//_WIN32
@ -1224,7 +1224,7 @@ int32_t CreateSliceThreads (sWelsEncCtx* pCtx) {
dw = SetThreadAffinityMask (pCtx->pSliceThreading->pThreadHandles[iIdx], dwAffinityMask); //1 << iIdx
if (dw == 0) {
str_t str[64] = {0};
SNPRINTF (str, 64, "SetThreadAffinityMask iIdx:%d", iIdx);
WelsSnprintf (str, 64, "SetThreadAffinityMask iIdx:%d", iIdx);
}
}
}

View File

@ -170,13 +170,7 @@ void WelsLogDefault (void* pCtx, const int32_t kiLevel, const str_t* kpFmtStr, v
t_now = (struct tm*)LOCALTIME (&l_time);
gettimeofday (&tv, NULL);
#endif//WIN32
#ifdef _MSC_VER
#if _MSC_VER >= 1500
iCurUsed = SNPRINTF (&pBuf[iBufUsed], iBufLeft, iBufLeft, "[0x%p @ ", pEncCtx); // confirmed_safe_unsafe_usage
#else
iCurUsed = SNPRINTF (&pBuf[iBufUsed], iBufLeft, "[0x%p @ ", pEncCtx); // confirmed_safe_unsafe_usage
#endif//_MSC_VER >= 1500
#endif//_MSC_VER
iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, "[0x%p @ ", pEncCtx); // confirmed_safe_unsafe_usage
if (iCurUsed >= 0) {
iBufUsed += iCurUsed;
iBufLeft -= iCurUsed;
@ -230,16 +224,10 @@ void WelsLogDefault (void* pCtx, const int32_t kiLevel, const str_t* kpFmtStr, v
if (iBufLeft > 0) {
#if defined (_WIN32)
#ifdef _MSC_VER
#if _MSC_VER >= 1500
iCurUsed = SNPRINTF (&pBuf[iBufUsed], iBufLeft, iBufLeft, ".%03.3u]: ", tb.millitm); // confirmed_safe_unsafe_usage
#else
iCurUsed = SNPRINTF (&pBuf[iBufUsed], iBufLeft, ".%3.3u]: ", tb.millitm); // confirmed_safe_unsafe_usage
#endif//_MSC_VER >= 1500
#endif//_MSC_VER
iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, ".%3.3u]: ", tb.millitm); // confirmed_safe_unsafe_usage
#elif defined (__GNUC__)
iCurUsed = SNPRINTF (&pBuf[iBufUsed], iBufLeft, ".%3.3u]: ",
static_cast<unsigned int> (tv.tv_usec / 1000)); // confirmed_safe_unsafe_usage
iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, ".%3.3u]: ",
static_cast<unsigned int> (tv.tv_usec / 1000)); // confirmed_safe_unsafe_usage
#endif//WIN32
if (iCurUsed >= 0) {
iBufUsed += iCurUsed;

View File

@ -117,20 +117,8 @@ CWelsH264SVCEncoder::CWelsH264SVCEncoder()
gettimeofday (&tTimev, NULL);
#endif//WIN32
#ifdef _WIN32
#if defined(_MSC_VER)
#if _MSC_VER>=1500
iCurUsed = SNPRINTF (strStreamFileName, iBufferLeft, iBufferLeft, "enc_bs_0x%p_", (void*)this);
iCurUsedSize = SNPRINTF (strLenFileName, iBufferLeftSize, iBufferLeftSize, "enc_size_0x%p_", (void*)this);
#else
iCurUsed = SNPRINTF (strStreamFileName, iBufferLeft, "enc_bs_0x%p_", (void*)this);
iCurUsedSize = SNPRINTF (strLenFileName, iBufferLeftSize, "enc_size_0x%p_", (void*)this);
#endif//_MSC_VER>=1500
#endif//_MSC_VER
#else
iCurUsed = SNPRINTF (strStreamFileName, iBufferLeft, "/tmp/enc_bs_0x%p_", (void*)this);
iCurUsedSize = SNPRINTF (strLenFileName, iBufferLeftSize, "/tmp/enc_size_0x%p", (void*)this);
#endif//WIN32
iCurUsed = WelsSnprintf (strStreamFileName, iBufferLeft, "enc_bs_0x%p_", (void*)this);
iCurUsedSize = WelsSnprintf (strLenFileName, iBufferLeftSize, "enc_size_0x%p_", (void*)this);
if (iCurUsed > 0) {
@ -179,15 +167,9 @@ CWelsH264SVCEncoder::CWelsH264SVCEncoder()
if (iBufferLeft > 0) {
#ifdef _WIN32
#if defined(_MSC_VER)
#if _MSC_VER>=1500
iCurUsed = SNPRINTF (&strStreamFileName[iBufferUsed], iBufferLeft, iBufferLeft, ".%03.3u.264", tTimeb.millitm);
iCurUsed = WelsSnprintf (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264", tTimeb.millitm);
#else
iCurUsed = SNPRINTF (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264", tTimeb.millitm);
#endif//_MSC_VER>=1500
#endif//_MSC_VER
#else
iCurUsed = SNPRINTF (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264", tTimev.tv_usec / 1000);
iCurUsed = WelsSnprintf (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264", tTimev.tv_usec / 1000);
#endif//WIN32
if (iCurUsed > 0) {
iBufferUsed += iCurUsed;
@ -197,16 +179,9 @@ CWelsH264SVCEncoder::CWelsH264SVCEncoder()
if (iBufferLeftSize > 0) {
#ifdef _WIN32
#if defined(_MSC_VER)
#if _MSC_VER>=1500
iCurUsedSize = SNPRINTF (&strLenFileName[iBufferUsedSize], iBufferLeftSize, iBufferLeftSize, ".%03.3u.len",
tTimeb.millitm);
iCurUsedSize = WelsSnprintf (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len", tTimeb.millitm);
#else
iCurUsedSize = SNPRINTF (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len", tTimeb.millitm);
#endif//_MSC_VER>=1500
#endif//_MSC_VER
#else
iCurUsedSize = SNPRINTF (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len", tTimev.tv_usec / 1000);
iCurUsedSize = WelsSnprintf (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len", tTimev.tv_usec / 1000);
#endif//WIN32
if (iCurUsedSize > 0) {
iBufferUsedSize += iCurUsedSize;
@ -492,17 +467,11 @@ int CWelsH264SVCEncoder::Initialize2 (void* argv, const INIT_TYPE iInitType) {
#if defined(OUTPUT_BIT_STREAM) || defined(ENABLE_TRACE_FILE)
str_t fpath[MAX_FNAME_LEN] = {0};
#if defined(__GNUC__)
SNPRINTF (fpath, MAX_FNAME_LEN, "/tmp/"); // confirmed_safe_unsafe_usage
WelsSnprintf (fpath, MAX_FNAME_LEN, "/tmp/"); // confirmed_safe_unsafe_usage
#else//__GNUC__
#if defined (_MSC_VER)
#if _MSC_VER>=1500
SNPRINTF (fpath, MAX_FNAME_LEN, MAX_FNAME_LEN, ".\\"); // confirmed_safe_unsafe_usage
#else
SNPRINTF (fpath, MAX_FNAME_LEN, ".\\"); // confirmed_safe_unsafe_usage
#endif//_MSC_VER>=1500
#endif//_MSC_VER
WelsSnprintf (fpath, MAX_FNAME_LEN, ".\\"); // confirmed_safe_unsafe_usage
#endif //__GNUC__
strcpy (pCfg->sTracePath, fpath); // confirmed_safe_unsafe_usage
@ -681,36 +650,13 @@ int CWelsH264SVCEncoder::EncodeFrame2 (const SSourcePicture** pSrcPicList, int
m_pFileBsSize = NULL;
}
str_t strStreamFileName[128] = {0};
#if defined(__GNUC__)
int32_t iLen = SNPRINTF (strStreamFileName, 128, "%sadj%d_w%d.264", m_pEncContext->sTracePath, m_iSwitchTimes,
m_pEncContext->pSvcParam->iActualPicWidth);
int32_t iLen = WelsSnprintf (strStreamFileName, 128, "adj%d_w%d.264", m_iSwitchTimes,
m_pEncContext->pSvcParam->iActualPicWidth);
m_pFileBs = WelsFopen (strStreamFileName, "wb");
SNPRINTF (strStreamFileName, 128, "%sadj%d_w%d_size.iLen", m_pEncContext->sTracePath, m_iSwitchTimes,
m_pEncContext->pSvcParam->iActualPicWidth);
WelsSnprintf (strStreamFileName, 128, "adj%d_w%d_size.iLen", m_iSwitchTimes,
m_pEncContext->pSvcParam->iActualPicWidth);
m_pFileBsSize = WelsFopen (strStreamFileName, "wb");
#else//__GNUC__
#if defined (_MSC_VER)
#if _MSC_VER>=1500
int32_t iLen = SNPRINTF (strStreamFileName, 128, 128, "adj%d_w%d.264", m_iSwitchTimes,
m_pEncContext->pSvcParam->iActualPicWidth);
m_pFileBs = WelsFopen (strStreamFileName, "wb");
SNPRINTF (strStreamFileName, 128, 128, "adj%d_w%d_size.iLen", m_iSwitchTimes,
m_pEncContext->pSvcParam->iActualPicWidth);
m_pFileBsSize = WelsFopen (strStreamFileName, "wb");
#else
int32_t iLen = SNPRINTF (strStreamFileName, 128, "adj%d_w%d.264", m_iSwitchTimes,
m_pEncContext->pSvcParam->iActualPicWidth);
m_pFileBs = WelsFopen (strStreamFileName, "wb");
SNPRINTF (strStreamFileName, 128, "adj%d_w%d_size.iLen", m_iSwitchTimes, m_pEncContext->pSvcParam->iActualPicWidth);
m_pFileBsSize = WelsFopen (strStreamFileName, "wb");
#endif//_MSC_VER>=1500
#endif//_MSC_VER
#endif//__GNUC__
m_bSwitch = FALSE;
}