shithub: openh264

Download patch

ref: d5affbaa3cd5c389a3283490ddb62c71acd489e8
parent: 5a8f5f9ad134a2946c4bb232b6b72559f0068ff6
parent: c174dcd6529fd982bcf78fbbd9ac51f2aa949f8a
author: Ethan Hugg <ethanhugg@gmail.com>
date: Mon Jan 27 03:54:20 EST 2014

Merge pull request #232 from mstorsjo/merge-fopen-wrappers

Remove the FOPEN macro, use WelsFopen instead

--- a/codec/common/crt_util_safe_x.h
+++ b/codec/common/crt_util_safe_x.h
@@ -427,7 +427,6 @@
 #define STRCAT		strcat_s
 #define STRNLEN		strnlen_s
 #define VSPRINTF	vsprintf_s
-#define FOPEN		fopen_s
 #else	// mainly for VC6
 #define SNPRINTF	_snprintf
 #define LOCALTIME	localtime
@@ -436,7 +435,6 @@
 #define STRCAT		wels_strcat_s	// override s.t.r.c.a.t here for safe
 #define STRNLEN		wels_strnlen_s	// override s.t.r.n.l.e.n here for safe
 #define VSPRINTF	vsprintf
-#define FOPEN		fopen
 #endif//_MSC_VER >= 1500
 
 #else//__GNUC__
@@ -447,7 +445,6 @@
 #define STRCAT		wels_strcat_s	// override s.t.r.c.a.t here for safe
 #define STRNLEN		wels_strnlen_s	// override s.t.r.n.l.e.n here for safe
 #define VSPRINTF	vsprintf
-#define FOPEN		fopen
 
 #endif//WIN32
 
--- a/codec/encoder/core/src/encoder.cpp
+++ b/codec/encoder/core/src/encoder.cpp
@@ -324,39 +324,29 @@
 
   if (bDependencyRecFlag[kiDid]) {
     if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0)	// confirmed_safe_unsafe_usage
-#if defined(__GNUC__) || (defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER<1500))
-      pDumpRecFile	= FOPEN (kpFileName, "ab");
-#elif defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500)	// vs2008
-      FOPEN (&pDumpRecFile, kpFileName, "ab");
-#endif//__GNUC__..
+      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
-      FOPEN (&pDumpRecFile, sDependencyRecFileName, "ab");
 #else
       SNPRINTF (sDependencyRecFileName, 16, "rec%d.yuv", kiDid);	// confirmed_safe_unsafe_usage
-      pDumpRecFile	= FOPEN (sDependencyRecFileName, "ab");
 #endif//WIN32..
+      pDumpRecFile	= WelsFopen (sDependencyRecFileName, "ab");
     }
     if (NULL != pDumpRecFile)
       fseek (pDumpRecFile, 0, SEEK_END);
   } else {
     if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) {	// confirmed_safe_unsafe_usage
-#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500)	// vs2008
-      FOPEN (&pDumpRecFile, kpFileName, "wb");
-#else
-      pDumpRecFile	= FOPEN (kpFileName, "wb");
-#endif//WIN32..
+      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
-      FOPEN (&pDumpRecFile, sDependencyRecFileName, "wb");
 #else
       SNPRINTF (sDependencyRecFileName, 16, "rec%d.yuv", kiDid);	// confirmed_safe_unsafe_usage
-      pDumpRecFile	= FOPEN (sDependencyRecFileName, "wb");
 #endif//WIN32..
+      pDumpRecFile	= WelsFopen (sDependencyRecFileName, "wb");
     }
     bDependencyRecFlag[kiDid]	= true;
   }
@@ -410,33 +400,17 @@
 
   if (bRecFlag) {
     if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) {	// confirmed_safe_unsafe_usage
-#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500)	// vs2008
-      FOPEN (&pDumpRecFile, kpFileName, "ab");
-#else
-      pDumpRecFile	= FOPEN (kpFileName, "ab");
-#endif//WIN32
+      pDumpRecFile	= WelsFopen (kpFileName, "ab");
     } else {
-#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500)	// vs2008
-      FOPEN (&pDumpRecFile, "rec.yuv", "ab");
-#else
-      pDumpRecFile	= FOPEN ("rec.yuv", "ab");
-#endif//WIN32
+      pDumpRecFile	= WelsFopen ("rec.yuv", "ab");
     }
     if (NULL != pDumpRecFile)
       fseek (pDumpRecFile, 0, SEEK_END);
   } else {
     if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) {	// confirmed_safe_unsafe_usage
-#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500)	// vs2008
-      FOPEN (&pDumpRecFile, kpFileName, "wb");
-#else
-      pDumpRecFile	= FOPEN (kpFileName, "wb");
-#endif//WIN32
+      pDumpRecFile	= WelsFopen (kpFileName, "wb");
     } else {
-#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500)	// vs2008
-      FOPEN (&pDumpRecFile, "rec.yuv", "wb");
-#else
-      pDumpRecFile	= FOPEN ("rec.yuv", "wb");
-#endif//WIN32..
+      pDumpRecFile	= WelsFopen ("rec.yuv", "wb");
     }
     bRecFlag	= true;
   }
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -2100,17 +2100,7 @@
 #endif//_MSC_VER
 
 
-#if defined(__GNUC__)
-    pCtx->pFileLog	= FOPEN (fname, "wt+");
-#else//WIN32
-#if defined(_WIN32) && defined(_MSC_VER)
-#if _MSC_VER >= 1500
-    FOPEN (&pCtx->pFileLog, fname, "wt+");
-#else
-    pCtx->pFileLog	= FOPEN (fname, "wt+");
-#endif//_MSC_VER>=1500
-#endif//WIN32 && _MSC_VER
-#endif//__GNUC__
+    pCtx->pFileLog	= WelsFopen (fname, "wt+");
     pCtx->uiSizeLog	= 0;
   }
 #endif//ENABLE_TRACE_FILE
--- a/codec/encoder/core/src/utils.cpp
+++ b/codec/encoder/core/src/utils.cpp
@@ -332,16 +332,11 @@
     STRNCPY (strTraceFile, MAX_FNAME_LEN, pCurPath, len);	// confirmed_safe_unsafe_usage
 #ifdef __GNUC__
     STRCAT (strTraceFile, MAX_FNAME_LEN - len, "/wels_encoder_trace.txt");	// confirmed_safe_unsafe_usage
-    pEncCtx->pFileLog	= FOPEN (strTraceFile, "wt+");	// confirmed_safe_unsafe_usage
 #elif _WIN32
     STRCAT (strTraceFile, MAX_FNAME_LEN - len, "\\wels_encoder_trace.txt"); // confirmed_safe_unsafe_usage
-#if _MSC_VER >= 1500
-    FOPEN (&pEncCtx->pFileLog, strTraceFile, "wt+");	// confirmed_safe_unsafe_usage
 #else
-    pEncCtx->pFileLog	= FOPEN (strTraceFile, "wt+");	// confirmed_safe_unsafe_usage
-#endif//_MSC_VER>=1500
-#else
 #endif//__GNUC__
+    pEncCtx->pFileLog	= WelsFopen (strTraceFile, "wt+");	// confirmed_safe_unsafe_usage
   }
 #endif//ENABLE_TRACE_FILE
 }
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -214,20 +214,8 @@
     }
   }
 
-#if defined(__GNUC__)
-  m_pFileBs       = FOPEN (strStreamFileName,      "wb");
-  m_pFileBsSize	= FOPEN (strLenFileName, "wb");
-#else
-#if defined(_MSC_VER)
-#if _MSC_VER>=1500
-  FOPEN (&m_pFileBs, strStreamFileName,      "wb");
-  FOPEN (&m_pFileBsSize, strLenFileName, "wb");
-#else
-  m_pFileBs       = FOPEN (strStreamFileName,      "wb");
-  m_pFileBsSize	= FOPEN (strLenFileName, "wb");
-#endif//_MSC_VER>=1500
-#endif//_MSC_VER
-#endif//__GNUC__
+  m_pFileBs     = WelsFopen (strStreamFileName, "wb");
+  m_pFileBsSize = WelsFopen (strLenFileName, "wb");
 
   m_bSwitch	= FALSE;
   m_iSwitchTimes	= 0;
@@ -697,10 +685,10 @@
 
       int32_t iLen = SNPRINTF (strStreamFileName, 128, "%sadj%d_w%d.264", m_pEncContext->sTracePath,  m_iSwitchTimes,
                                m_pEncContext->pSvcParam->iActualPicWidth);
-      m_pFileBs = FOPEN (strStreamFileName, "wb");
+      m_pFileBs = WelsFopen (strStreamFileName, "wb");
       SNPRINTF (strStreamFileName, 128, "%sadj%d_w%d_size.iLen", m_pEncContext->sTracePath, m_iSwitchTimes,
                 m_pEncContext->pSvcParam->iActualPicWidth);
-      m_pFileBsSize = FOPEN (strStreamFileName, "wb");
+      m_pFileBsSize = WelsFopen (strStreamFileName, "wb");
 
 #else//__GNUC__
 
@@ -708,16 +696,16 @@
 #if _MSC_VER>=1500
       int32_t iLen = SNPRINTF (strStreamFileName, 128, 128, "adj%d_w%d.264", m_iSwitchTimes,
                                m_pEncContext->pSvcParam->iActualPicWidth);
-      FOPEN (&m_pFileBs, strStreamFileName, "wb");
+      m_pFileBs = WelsFopen (strStreamFileName, "wb");
       SNPRINTF (strStreamFileName, 128, 128, "adj%d_w%d_size.iLen", m_iSwitchTimes,
                 m_pEncContext->pSvcParam->iActualPicWidth);
-      FOPEN (&m_pFileBsSize, strStreamFileName, "wb");
+      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 = FOPEN (strStreamFileName, "wb");
+      m_pFileBs = WelsFopen (strStreamFileName, "wb");
       SNPRINTF (strStreamFileName, 128, "adj%d_w%d_size.iLen", m_iSwitchTimes, m_pEncContext->pSvcParam->iActualPicWidth);
-      m_pFileBsSize = FOPEN (strStreamFileName, "wb");
+      m_pFileBsSize = WelsFopen (strStreamFileName, "wb");
 #endif//_MSC_VER>=1500
 #endif//_MSC_VER
 
@@ -1145,17 +1133,7 @@
   case videoFormatI420:
   case videoFormatYV12:
     STRCAT (strFileName, 256, "yuv");	// confirmed_safe_unsafe_usage
-#if defined(__GNUC__)
-    pFile = FOPEN (strFileName, "ab+");
-#else
-#if defined(_MSC_VER)
-#if _MSC_VER>=1500
-    FOPEN (&pFile, strFileName, "ab+");
-#else
-    pFile = FOPEN (strFileName, "ab+");
-#endif//_MSC_VER>=1500
-#endif//_MSC_VER
-#endif//__GNUC__
+    pFile = WelsFopen (strFileName, "ab+");
     //				WelsLog( m_pEncContext, WELS_LOG_INFO, "WELS_CSP_I420, m_iCspInternal= 0x%x\n", m_iCspInternal);
     if (NULL != pFile) {
       fwrite (pSrc, sizeof (uint8_t), (iDataLength * 3) >> 1, pFile);
@@ -1165,17 +1143,7 @@
     break;
   case videoFormatRGB:
     STRCAT (strFileName, 256, "rgb");	// confirmed_safe_unsafe_usage
-#if defined(__GNUC__)
-    pFile = FOPEN (strFileName, "ab+");
-#else
-#if defined(_MSC_VER)
-#if _MSC_VER>=1500
-    FOPEN (&pFile, strFileName, "ab+");
-#else
-    pFile = FOPEN (strFileName, "ab+");
-#endif//_MSC_VER>=1500
-#endif//_MSC_VER
-#endif//__GNUC__
+    pFile = WelsFopen (strFileName, "ab+");
     if (NULL != pFile) {
       fwrite (pSrc, sizeof (uint8_t), iDataLength * 3, pFile);
       fflush (pFile);
@@ -1183,17 +1151,7 @@
     }
   case videoFormatBGR:
     STRCAT (strFileName, 256, "bgr");	// confirmed_safe_unsafe_usage
-#if defined(__GNUC__)
-    pFile = FOPEN (strFileName, "ab+");
-#else
-#if defined(_MSC_VER)
-#if _MSC_VER>=1500
-    FOPEN (&pFile, strFileName, "ab+");
-#else
-    pFile = FOPEN (strFileName, "ab+");
-#endif//_MSC_VER>=1500
-#endif//_MSC_VER
-#endif//__GNUC__
+    pFile = WelsFopen (strFileName, "ab+");
     //				WelsLog( m_pEncContext, WELS_LOG_INFO, "WELS_CSP_BGR, m_iCspInternal= 0x%x\n", m_iCspInternal);
     if (NULL != pFile) {
       fwrite (pSrc, sizeof (uint8_t), iDataLength * 3, pFile);
@@ -1203,17 +1161,7 @@
     break;
   case videoFormatYUY2:
     STRCAT (strFileName, 256, "yuy2");	// confirmed_safe_unsafe_usage
-#if defined(__GNUC__)
-    pFile = FOPEN (strFileName, "ab+");
-#else
-#if defined(_MSC_VER)
-#if _MSC_VER>=1500
-    FOPEN (&pFile, strFileName, "ab+");
-#else
-    pFile = FOPEN (strFileName, "ab+");
-#endif//_MSC_VER>=1500
-#endif//_MSC_VER
-#endif//__GNUC__
+    pFile = WelsFopen (strFileName, "ab+");
     if (NULL != pFile) {
       fwrite (pSrc, sizeof (uint8_t), (CALC_BI_STRIDE (m_iMaxPicWidth,  16)) * m_iMaxPicHeight, pFile);
       fflush (pFile);