shithub: openh264

Download patch

ref: 00f28cc1857be58804bbf1e18aacbbe999941f8a
parent: 1888fba3360a7e2824b918e61960b81838edd47a
author: Martin Storsjö <[email protected]>
date: Thu Jun 26 11:04:30 EDT 2014

Avoid using static arrays for keeping track of frame dumping state

--- a/codec/encoder/core/inc/encoder.h
+++ b/codec/encoder/core/inc/encoder.h
@@ -91,12 +91,12 @@
  * \brief	Dump reconstruction for dependency layer
  */
 
-extern "C" void DumpDependencyRec (SPicture* pSrcPic, const char* kpFileName, const int8_t kiDid);
+extern "C" void DumpDependencyRec (SPicture* pSrcPic, const char* kpFileName, const int8_t kiDid, bool bAppend);
 
 /*!
  * \brief	Dump the reconstruction pictures
  */
-void DumpRecFrame (SPicture* pSrcPic, const char* kpFileName);
+void DumpRecFrame (SPicture* pSrcPic, const char* kpFileName, bool bAppend);
 
 
 /*!
--- a/codec/encoder/core/inc/encoder_context.h
+++ b/codec/encoder/core/inc/encoder_context.h
@@ -217,6 +217,11 @@
 int32_t iEncoderError;
 WELS_MUTEX					mutexEncoderError;
 int32_t iDropNumber;
+
+#ifdef ENABLE_FRAME_DUMP
+bool bDependencyRecFlag[MAX_DEPENDENCY_LAYER];
+bool bRecFlag;
+#endif
 } sWelsEncCtx/*, *PWelsEncCtx*/;
 }
 #endif//sWelsEncCtx_H__
--- a/codec/encoder/core/src/encoder.cpp
+++ b/codec/encoder/core/src/encoder.cpp
@@ -350,15 +350,14 @@
  * \brief	Dump reconstruction for dependency layer
  */
 
-extern "C" void DumpDependencyRec (SPicture* pCurPicture, const char* kpFileName, const int8_t kiDid) {
+extern "C" void DumpDependencyRec (SPicture* pCurPicture, const char* kpFileName, const int8_t kiDid, bool bAppend) {
   WelsFileHandle* pDumpRecFile = NULL;
-  static bool bDependencyRecFlag[MAX_DEPENDENCY_LAYER]	= {0};
   int32_t iWrittenSize											= 0;
 
   if (NULL == pCurPicture || NULL == kpFileName || kiDid >= MAX_DEPENDENCY_LAYER)
     return;
 
-  if (bDependencyRecFlag[kiDid]) {
+  if (bAppend) {
     if (strlen (kpFileName) > 0)	// confirmed_safe_unsafe_usage
       pDumpRecFile = WelsFopen (kpFileName, "ab");
     else {
@@ -376,7 +375,6 @@
       WelsSnprintf (sDependencyRecFileName, 16, "rec%d.yuv", kiDid);	// confirmed_safe_unsafe_usage
       pDumpRecFile	= WelsFopen (sDependencyRecFileName, "wb");
     }
-    bDependencyRecFlag[kiDid]	= true;
   }
 
   if (NULL != pDumpRecFile) {
@@ -418,15 +416,14 @@
  * \brief	Dump the reconstruction pictures
  */
 
-void DumpRecFrame (SPicture* pCurPicture, const char* kpFileName) {
+void DumpRecFrame (SPicture* pCurPicture, const char* kpFileName, bool bAppend) {
   WelsFileHandle* pDumpRecFile				= NULL;
-  static bool bRecFlag	= false;
   int32_t iWrittenSize			= 0;
 
   if (NULL == pCurPicture || NULL == kpFileName)
     return;
 
-  if (bRecFlag) {
+  if (bAppend) {
     if (strlen (kpFileName) > 0) {	// confirmed_safe_unsafe_usage
       pDumpRecFile	= WelsFopen (kpFileName, "ab");
     } else {
@@ -440,7 +437,6 @@
     } else {
       pDumpRecFile	= WelsFopen ("rec.yuv", "wb");
     }
-    bRecFlag	= true;
   }
 
   if (NULL != pDumpRecFile) {
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -3384,8 +3384,11 @@
 
 #ifdef ENABLE_FRAME_DUMP
     // Dump reconstruction picture for each sQualityStat layer
-    if (iCurDid + 1 < pSvcParam->iSpatialLayerNum)
-      DumpDependencyRec (fsnr, &pSvcParam->sDependencyLayers[pSvcParam->iSpatialLayerNum].sRecFileName[0], iCurDid);
+    if (iCurDid + 1 < pSvcParam->iSpatialLayerNum) {
+      DumpDependencyRec (fsnr, &pSvcParam->sDependencyLayers[pSvcParam->iSpatialLayerNum].sRecFileName[0], iCurDid,
+                         pCtx->bDependencyRecFlag[iCurDid]);
+      pCtx->bDependencyRecFlag[iCurDid] = true;
+    }
 #endif//ENABLE_FRAME_DUMP
 
 #if defined(ENABLE_PSNR_CALC)
@@ -3551,7 +3554,8 @@
 
 #ifdef ENABLE_FRAME_DUMP
   DumpRecFrame (fsnr, &pSvcParam->sDependencyLayers[pSvcParam->iSpatialLayerNum -
-                1].sRecFileName[0]);	// pDecPic: final reconstruction output
+                1].sRecFileName[0], pCtx->bRecFlag);	// pDecPic: final reconstruction output
+  pCtx->bRecFlag = true;
 #endif//ENABLE_FRAME_DUMP
 
   ++ pCtx->iCodingIndex;