History

Remove the FOPEN macro, use WelsFopen instead

This avoids ifdefs at each place the macro is used.

Martin Storsjö committed 12 years ago

Commit c174dcd1 parent 33fe2b55 files · +22 −118Browse files

Unified · Split

5 files
  1. codec/common/crt_util_safe_x.h +0 −3
  2. codec/encoder/core/src/encoder.cpp +8 −34
  3. codec/encoder/core/src/encoder_ext.cpp +1 −11
  4. codec/encoder/core/src/utils.cpp +1 −6
  5. codec/encoder/plus/src/welsEncoderExt.cpp +12 −64
codec/common/crt_util_safe_x.h+0−3
@@ -427,7 +427,6 @@ static __inline int wels_strnlen_s (const char* dest, int dmax) { · 426 unmodified lines
427#define STRCAT strcat_s427#define STRCAT strcat_s
428#define STRNLEN strnlen_s428#define STRNLEN strnlen_s
429#define VSPRINTF vsprintf_s429#define VSPRINTF vsprintf_s
430#define FOPEN fopen_s
431#else // mainly for VC6430#else // mainly for VC6
432#define SNPRINTF _snprintf431#define SNPRINTF _snprintf
433#define LOCALTIME localtime432#define LOCALTIME localtime
@@ -436,7 +435,6 @@ static __inline int wels_strnlen_s (const char* dest, int dmax) { · 2 unmodified lines
436#define STRCAT wels_strcat_s // override s.t.r.c.a.t here for safe435#define STRCAT wels_strcat_s // override s.t.r.c.a.t here for safe
437#define STRNLEN wels_strnlen_s // override s.t.r.n.l.e.n here for safe436#define STRNLEN wels_strnlen_s // override s.t.r.n.l.e.n here for safe
438#define VSPRINTF vsprintf437#define VSPRINTF vsprintf
439#define FOPEN fopen
440#endif//_MSC_VER >= 1500438#endif//_MSC_VER >= 1500
441 439
442#else//__GNUC__440#else//__GNUC__
@@ -447,7 +445,6 @@ static __inline int wels_strnlen_s (const char* dest, int dmax) { · 4 unmodified lines
447#define STRCAT wels_strcat_s // override s.t.r.c.a.t here for safe445#define STRCAT wels_strcat_s // override s.t.r.c.a.t here for safe
448#define STRNLEN wels_strnlen_s // override s.t.r.n.l.e.n here for safe446#define STRNLEN wels_strnlen_s // override s.t.r.n.l.e.n here for safe
449#define VSPRINTF vsprintf447#define VSPRINTF vsprintf
450#define FOPEN fopen
451 448
452#endif//WIN32449#endif//WIN32
453 450
codec/encoder/core/src/encoder.cpp+8−34
@@ -324,39 +324,29 @@ extern "C" void DumpDependencyRec (SPicture* pCurPicture, const str_t* kpFileNam · 323 unmodified lines
324 324
325 if (bDependencyRecFlag[kiDid]) {325 if (bDependencyRecFlag[kiDid]) {
326 if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) // confirmed_safe_unsafe_usage326 if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) // confirmed_safe_unsafe_usage
327#if defined(__GNUC__) || (defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER<1500))327 pDumpRecFile = WelsFopen (kpFileName, "ab");
328 pDumpRecFile = FOPEN (kpFileName, "ab");
329#elif defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008
330 FOPEN (&pDumpRecFile, kpFileName, "ab");
331#endif//__GNUC__..
332 else {328 else {
333 str_t sDependencyRecFileName[16] = {0};329 str_t sDependencyRecFileName[16] = {0};
334#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008330#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008
335 SNPRINTF (sDependencyRecFileName, 16, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage331 SNPRINTF (sDependencyRecFileName, 16, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
336 FOPEN (&pDumpRecFile, sDependencyRecFileName, "ab");
337#else332#else
338 SNPRINTF (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage333 SNPRINTF (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
339 pDumpRecFile = FOPEN (sDependencyRecFileName, "ab");
340#endif//WIN32..334#endif//WIN32..
335 pDumpRecFile = WelsFopen (sDependencyRecFileName, "ab");
341 }336 }
342 if (NULL != pDumpRecFile)337 if (NULL != pDumpRecFile)
343 fseek (pDumpRecFile, 0, SEEK_END);338 fseek (pDumpRecFile, 0, SEEK_END);
344 } else {339 } else {
345 if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) { // confirmed_safe_unsafe_usage340 if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) { // confirmed_safe_unsafe_usage
346#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008341 pDumpRecFile = WelsFopen (kpFileName, "wb");
347 FOPEN (&pDumpRecFile, kpFileName, "wb");
348#else
349 pDumpRecFile = FOPEN (kpFileName, "wb");
350#endif//WIN32..
351 } else {342 } else {
352 str_t sDependencyRecFileName[16] = {0};343 str_t sDependencyRecFileName[16] = {0};
353#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008344#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008
354 SNPRINTF (sDependencyRecFileName, 16, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage345 SNPRINTF (sDependencyRecFileName, 16, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
355 FOPEN (&pDumpRecFile, sDependencyRecFileName, "wb");
356#else346#else
357 SNPRINTF (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage347 SNPRINTF (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
358 pDumpRecFile = FOPEN (sDependencyRecFileName, "wb");
359#endif//WIN32..348#endif//WIN32..
349 pDumpRecFile = WelsFopen (sDependencyRecFileName, "wb");
360 }350 }
361 bDependencyRecFlag[kiDid] = true;351 bDependencyRecFlag[kiDid] = true;
362 }352 }
@@ -410,33 +400,17 @@ void DumpRecFrame (SPicture* pCurPicture, const str_t* kpFileName) { · 47 unmodified lines
410 400
411 if (bRecFlag) {401 if (bRecFlag) {
412 if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) { // confirmed_safe_unsafe_usage402 if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) { // confirmed_safe_unsafe_usage
413#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008403 pDumpRecFile = WelsFopen (kpFileName, "ab");
414 FOPEN (&pDumpRecFile, kpFileName, "ab");
415#else
416 pDumpRecFile = FOPEN (kpFileName, "ab");
417#endif//WIN32
418 } else {404 } else {
419#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008405 pDumpRecFile = WelsFopen ("rec.yuv", "ab");
420 FOPEN (&pDumpRecFile, "rec.yuv", "ab");
421#else
422 pDumpRecFile = FOPEN ("rec.yuv", "ab");
423#endif//WIN32
424 }406 }
425 if (NULL != pDumpRecFile)407 if (NULL != pDumpRecFile)
426 fseek (pDumpRecFile, 0, SEEK_END);408 fseek (pDumpRecFile, 0, SEEK_END);
427 } else {409 } else {
428 if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) { // confirmed_safe_unsafe_usage410 if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) { // confirmed_safe_unsafe_usage
429#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008411 pDumpRecFile = WelsFopen (kpFileName, "wb");
430 FOPEN (&pDumpRecFile, kpFileName, "wb");
431#else
432 pDumpRecFile = FOPEN (kpFileName, "wb");
433#endif//WIN32
434 } else {412 } else {
435#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008413 pDumpRecFile = WelsFopen ("rec.yuv", "wb");
436 FOPEN (&pDumpRecFile, "rec.yuv", "wb");
437#else
438 pDumpRecFile = FOPEN ("rec.yuv", "wb");
439#endif//WIN32..
440 }414 }
441 bRecFlag = true;415 bRecFlag = true;
442 }416 }
codec/encoder/core/src/encoder_ext.cpp+1−11
@@ -2100,17 +2100,7 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 2099 unmodified lines
2100#endif//_MSC_VER2100#endif//_MSC_VER
2101 2101
2102 2102
2103#if defined(__GNUC__)2103 pCtx->pFileLog = WelsFopen (fname, "wt+");
2104 pCtx->pFileLog = FOPEN (fname, "wt+");
2105#else//WIN32
2106#if defined(_WIN32) && defined(_MSC_VER)
2107#if _MSC_VER >= 1500
2108 FOPEN (&pCtx->pFileLog, fname, "wt+");
2109#else
2110 pCtx->pFileLog = FOPEN (fname, "wt+");
2111#endif//_MSC_VER>=1500
2112#endif//WIN32 && _MSC_VER
2113#endif//__GNUC__
2114 pCtx->uiSizeLog = 0;2104 pCtx->uiSizeLog = 0;
2115 }2105 }
2116#endif//ENABLE_TRACE_FILE2106#endif//ENABLE_TRACE_FILE
codec/encoder/core/src/utils.cpp+1−6
@@ -332,16 +332,11 @@ void WelsReopenTraceFile (void* pCtx, str_t* pCurPath) { · 331 unmodified lines
332 STRNCPY (strTraceFile, MAX_FNAME_LEN, pCurPath, len); // confirmed_safe_unsafe_usage332 STRNCPY (strTraceFile, MAX_FNAME_LEN, pCurPath, len); // confirmed_safe_unsafe_usage
333#ifdef __GNUC__333#ifdef __GNUC__
334 STRCAT (strTraceFile, MAX_FNAME_LEN - len, "/wels_encoder_trace.txt"); // confirmed_safe_unsafe_usage334 STRCAT (strTraceFile, MAX_FNAME_LEN - len, "/wels_encoder_trace.txt"); // confirmed_safe_unsafe_usage
335 pEncCtx->pFileLog = FOPEN (strTraceFile, "wt+"); // confirmed_safe_unsafe_usage
336#elif _WIN32335#elif _WIN32
337 STRCAT (strTraceFile, MAX_FNAME_LEN - len, "\\wels_encoder_trace.txt"); // confirmed_safe_unsafe_usage336 STRCAT (strTraceFile, MAX_FNAME_LEN - len, "\\wels_encoder_trace.txt"); // confirmed_safe_unsafe_usage
338#if _MSC_VER >= 1500
339 FOPEN (&pEncCtx->pFileLog, strTraceFile, "wt+"); // confirmed_safe_unsafe_usage
340#else
341 pEncCtx->pFileLog = FOPEN (strTraceFile, "wt+"); // confirmed_safe_unsafe_usage
342#endif//_MSC_VER>=1500
343#else337#else
344#endif//__GNUC__338#endif//__GNUC__
339 pEncCtx->pFileLog = WelsFopen (strTraceFile, "wt+"); // confirmed_safe_unsafe_usage
345 }340 }
346#endif//ENABLE_TRACE_FILE341#endif//ENABLE_TRACE_FILE
347}342}
codec/encoder/plus/src/welsEncoderExt.cpp+12−64
@@ -214,20 +214,8 @@ CWelsH264SVCEncoder::CWelsH264SVCEncoder() · 213 unmodified lines
214 }214 }
215 }215 }
216 216
217#if defined(__GNUC__)217 m_pFileBs = WelsFopen (strStreamFileName, "wb");
218 m_pFileBs = FOPEN (strStreamFileName, "wb");218 m_pFileBsSize = WelsFopen (strLenFileName, "wb");
219 m_pFileBsSize = FOPEN (strLenFileName, "wb");
220#else
221#if defined(_MSC_VER)
222#if _MSC_VER>=1500
223 FOPEN (&m_pFileBs, strStreamFileName, "wb");
224 FOPEN (&m_pFileBsSize, strLenFileName, "wb");
225#else
226 m_pFileBs = FOPEN (strStreamFileName, "wb");
227 m_pFileBsSize = FOPEN (strLenFileName, "wb");
228#endif//_MSC_VER>=1500
229#endif//_MSC_VER
230#endif//__GNUC__
231 219
232 m_bSwitch = FALSE;220 m_bSwitch = FALSE;
233 m_iSwitchTimes = 0;221 m_iSwitchTimes = 0;
@@ -697,10 +685,10 @@ int CWelsH264SVCEncoder::EncodeFrame2 (const SSourcePicture** pSrcPicList, int · 463 unmodified lines
697 685
698 int32_t iLen = SNPRINTF (strStreamFileName, 128, "%sadj%d_w%d.264", m_pEncContext->sTracePath, m_iSwitchTimes,686 int32_t iLen = SNPRINTF (strStreamFileName, 128, "%sadj%d_w%d.264", m_pEncContext->sTracePath, m_iSwitchTimes,
699 m_pEncContext->pSvcParam->iActualPicWidth);687 m_pEncContext->pSvcParam->iActualPicWidth);
700 m_pFileBs = FOPEN (strStreamFileName, "wb");688 m_pFileBs = WelsFopen (strStreamFileName, "wb");
701 SNPRINTF (strStreamFileName, 128, "%sadj%d_w%d_size.iLen", m_pEncContext->sTracePath, m_iSwitchTimes,689 SNPRINTF (strStreamFileName, 128, "%sadj%d_w%d_size.iLen", m_pEncContext->sTracePath, m_iSwitchTimes,
702 m_pEncContext->pSvcParam->iActualPicWidth);690 m_pEncContext->pSvcParam->iActualPicWidth);
703 m_pFileBsSize = FOPEN (strStreamFileName, "wb");691 m_pFileBsSize = WelsFopen (strStreamFileName, "wb");
704 692
705#else//__GNUC__693#else//__GNUC__
706 694
@@ -708,16 +696,16 @@ int CWelsH264SVCEncoder::EncodeFrame2 (const SSourcePicture** pSrcPicList, int · 1 unmodified line
708#if _MSC_VER>=1500696#if _MSC_VER>=1500
709 int32_t iLen = SNPRINTF (strStreamFileName, 128, 128, "adj%d_w%d.264", m_iSwitchTimes,697 int32_t iLen = SNPRINTF (strStreamFileName, 128, 128, "adj%d_w%d.264", m_iSwitchTimes,
710 m_pEncContext->pSvcParam->iActualPicWidth);698 m_pEncContext->pSvcParam->iActualPicWidth);
711 FOPEN (&m_pFileBs, strStreamFileName, "wb");699 m_pFileBs = WelsFopen (strStreamFileName, "wb");
712 SNPRINTF (strStreamFileName, 128, 128, "adj%d_w%d_size.iLen", m_iSwitchTimes,700 SNPRINTF (strStreamFileName, 128, 128, "adj%d_w%d_size.iLen", m_iSwitchTimes,
713 m_pEncContext->pSvcParam->iActualPicWidth);701 m_pEncContext->pSvcParam->iActualPicWidth);
714 FOPEN (&m_pFileBsSize, strStreamFileName, "wb");702 m_pFileBsSize = WelsFopen (strStreamFileName, "wb");
715#else703#else
716 int32_t iLen = SNPRINTF (strStreamFileName, 128, "adj%d_w%d.264", m_iSwitchTimes,704 int32_t iLen = SNPRINTF (strStreamFileName, 128, "adj%d_w%d.264", m_iSwitchTimes,
717 m_pEncContext->pSvcParam->iActualPicWidth);705 m_pEncContext->pSvcParam->iActualPicWidth);
718 m_pFileBs = FOPEN (strStreamFileName, "wb");706 m_pFileBs = WelsFopen (strStreamFileName, "wb");
719 SNPRINTF (strStreamFileName, 128, "adj%d_w%d_size.iLen", m_iSwitchTimes, m_pEncContext->pSvcParam->iActualPicWidth);707 SNPRINTF (strStreamFileName, 128, "adj%d_w%d_size.iLen", m_iSwitchTimes, m_pEncContext->pSvcParam->iActualPicWidth);
720 m_pFileBsSize = FOPEN (strStreamFileName, "wb");708 m_pFileBsSize = WelsFopen (strStreamFileName, "wb");
721#endif//_MSC_VER>=1500709#endif//_MSC_VER>=1500
722#endif//_MSC_VER710#endif//_MSC_VER
723 711
@@ -1145,17 +1133,7 @@ void CWelsH264SVCEncoder::DumpSrcPicture (const uint8_t* pSrc) { · 421 unmodified lines
1145 case videoFormatI420:1133 case videoFormatI420:
1146 case videoFormatYV12:1134 case videoFormatYV12:
1147 STRCAT (strFileName, 256, "yuv"); // confirmed_safe_unsafe_usage1135 STRCAT (strFileName, 256, "yuv"); // confirmed_safe_unsafe_usage
1148#if defined(__GNUC__)1136 pFile = WelsFopen (strFileName, "ab+");
1149 pFile = FOPEN (strFileName, "ab+");
1150#else
1151#if defined(_MSC_VER)
1152#if _MSC_VER>=1500
1153 FOPEN (&pFile, strFileName, "ab+");
1154#else
1155 pFile = FOPEN (strFileName, "ab+");
1156#endif//_MSC_VER>=1500
1157#endif//_MSC_VER
1158#endif//__GNUC__
1159 // WelsLog( m_pEncContext, WELS_LOG_INFO, "WELS_CSP_I420, m_iCspInternal= 0x%x\n", m_iCspInternal);1137 // WelsLog( m_pEncContext, WELS_LOG_INFO, "WELS_CSP_I420, m_iCspInternal= 0x%x\n", m_iCspInternal);
1160 if (NULL != pFile) {1138 if (NULL != pFile) {
1161 fwrite (pSrc, sizeof (uint8_t), (iDataLength * 3) >> 1, pFile);1139 fwrite (pSrc, sizeof (uint8_t), (iDataLength * 3) >> 1, pFile);
@@ -1165,17 +1143,7 @@ void CWelsH264SVCEncoder::DumpSrcPicture (const uint8_t* pSrc) { · 3 unmodified lines
1165 break;1143 break;
1166 case videoFormatRGB:1144 case videoFormatRGB:
1167 STRCAT (strFileName, 256, "rgb"); // confirmed_safe_unsafe_usage1145 STRCAT (strFileName, 256, "rgb"); // confirmed_safe_unsafe_usage
1168#if defined(__GNUC__)1146 pFile = WelsFopen (strFileName, "ab+");
1169 pFile = FOPEN (strFileName, "ab+");
1170#else
1171#if defined(_MSC_VER)
1172#if _MSC_VER>=1500
1173 FOPEN (&pFile, strFileName, "ab+");
1174#else
1175 pFile = FOPEN (strFileName, "ab+");
1176#endif//_MSC_VER>=1500
1177#endif//_MSC_VER
1178#endif//__GNUC__
1179 if (NULL != pFile) {1147 if (NULL != pFile) {
1180 fwrite (pSrc, sizeof (uint8_t), iDataLength * 3, pFile);1148 fwrite (pSrc, sizeof (uint8_t), iDataLength * 3, pFile);
1181 fflush (pFile);1149 fflush (pFile);
@@ -1183,17 +1151,7 @@ void CWelsH264SVCEncoder::DumpSrcPicture (const uint8_t* pSrc) { · 1 unmodified line
1183 }1151 }
1184 case videoFormatBGR:1152 case videoFormatBGR:
1185 STRCAT (strFileName, 256, "bgr"); // confirmed_safe_unsafe_usage1153 STRCAT (strFileName, 256, "bgr"); // confirmed_safe_unsafe_usage
1186#if defined(__GNUC__)1154 pFile = WelsFopen (strFileName, "ab+");
1187 pFile = FOPEN (strFileName, "ab+");
1188#else
1189#if defined(_MSC_VER)
1190#if _MSC_VER>=1500
1191 FOPEN (&pFile, strFileName, "ab+");
1192#else
1193 pFile = FOPEN (strFileName, "ab+");
1194#endif//_MSC_VER>=1500
1195#endif//_MSC_VER
1196#endif//__GNUC__
1197 // WelsLog( m_pEncContext, WELS_LOG_INFO, "WELS_CSP_BGR, m_iCspInternal= 0x%x\n", m_iCspInternal);1155 // WelsLog( m_pEncContext, WELS_LOG_INFO, "WELS_CSP_BGR, m_iCspInternal= 0x%x\n", m_iCspInternal);
1198 if (NULL != pFile) {1156 if (NULL != pFile) {
1199 fwrite (pSrc, sizeof (uint8_t), iDataLength * 3, pFile);1157 fwrite (pSrc, sizeof (uint8_t), iDataLength * 3, pFile);
@@ -1203,17 +1161,7 @@ void CWelsH264SVCEncoder::DumpSrcPicture (const uint8_t* pSrc) { · 3 unmodified lines
1203 break;1161 break;
1204 case videoFormatYUY2:1162 case videoFormatYUY2:
1205 STRCAT (strFileName, 256, "yuy2"); // confirmed_safe_unsafe_usage1163 STRCAT (strFileName, 256, "yuy2"); // confirmed_safe_unsafe_usage
1206#if defined(__GNUC__)1164 pFile = WelsFopen (strFileName, "ab+");
1207 pFile = FOPEN (strFileName, "ab+");
1208#else
1209#if defined(_MSC_VER)
1210#if _MSC_VER>=1500
1211 FOPEN (&pFile, strFileName, "ab+");
1212#else
1213 pFile = FOPEN (strFileName, "ab+");
1214#endif//_MSC_VER>=1500
1215#endif//_MSC_VER
1216#endif//__GNUC__
1217 if (NULL != pFile) {1165 if (NULL != pFile) {
1218 fwrite (pSrc, sizeof (uint8_t), (CALC_BI_STRIDE (m_iMaxPicWidth, 16)) * m_iMaxPicHeight, pFile);1166 fwrite (pSrc, sizeof (uint8_t), (CALC_BI_STRIDE (m_iMaxPicWidth, 16)) * m_iMaxPicHeight, pFile);
1219 fflush (pFile);1167 fflush (pFile);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t