shithub: openh264

Download patch

ref: 880e0fff06a407a72549de655b6163890735e2b2
parent: c7b50517386d21e3d4906c36e020602f3c253e53
author: dong zhang <dongzha@cisco.com>
date: Mon Nov 3 05:55:42 EST 2014

modify macro STICK_STREAM_SIZE	// For Demo interfaces test with track file of integrated frames
add macro NO_DELAY_DECODING	// For Demo interfaces test with no delay decoding

--- a/codec/console/dec/src/h264dec.cpp
+++ b/codec/console/dec/src/h264dec.cpp
@@ -63,6 +63,7 @@
 //using namespace WelsDec;
 
 //#define STICK_STREAM_SIZE	// For Demo interfaces test with track file of integrated frames
+//#define NO_DELAY_DECODING	// For Demo interfaces test with no delay decoding
 
 void H264DecodeInstance (ISVCDecoder* pDecoder, const char* kpH264FileName, const char* kpOuputFileName,
                          int32_t& iWidth, int32_t& iHeight, const char* pOptionFileName) {
@@ -69,6 +70,11 @@
   FILE* pH264File	  = NULL;
   FILE* pYuvFile	  = NULL;
   FILE* pOptionFile = NULL;
+#if defined ( STICK_STREAM_SIZE )
+  FILE* fpTrack = fopen ("3.len", "rb");
+  unsigned long pInfo[4];
+#endif// STICK_STREAM_SIZE
+
   int64_t iStart = 0, iEnd = 0, iTotal = 0;
   int32_t iSliceSize;
   int32_t iSliceIndex = 0;
@@ -153,12 +159,6 @@
     goto label_exit;
   }
 
-#if defined ( STICK_STREAM_SIZE )
-  FILE* fpTrack = fopen ("3.len", "rb");
-
-#endif// STICK_STREAM_SIZE
-
-
   while (true) {
 
     if (iBufPos >= iFileSize) {
@@ -169,8 +169,10 @@
     }
 
 #if defined ( STICK_STREAM_SIZE )
-    if (fpTrack)
-      fread (&iSliceSize, 1, sizeof (int32_t), fpTrack);
+    if (fpTrack) {
+      fread (pInfo, 4, sizeof (unsigned long), fpTrack);
+      iSliceSize = static_cast<int32_t>(pInfo[2]);
+    }
 #else
     for (i = 0; i < iFileSize; i++) {
       if ((pBuf[iBufPos + i] == 0 && pBuf[iBufPos + i + 1] == 0 && pBuf[iBufPos + i + 2] == 0 && pBuf[iBufPos + i + 3] == 1
@@ -234,6 +236,37 @@
       ++ iFrameCount;
     }
 
+#ifdef NO_DELAY_DECODING
+    iStart = WelsTime();
+    pData[0] = NULL;
+    pData[1] = NULL;
+    pData[2] = NULL;
+    memset (&sDstBufInfo, 0, sizeof (SBufferInfo));
+    pDecoder->DecodeFrame2 (NULL, 0, pData, &sDstBufInfo);
+    if (sDstBufInfo.iBufferStatus == 1) {
+      pDst[0] = pData[0];
+      pDst[1] = pData[1];
+      pDst[2] = pData[2];
+    }
+    iEnd	= WelsTime();
+    iTotal	+= iEnd - iStart;
+    if (sDstBufInfo.iBufferStatus == 1) {
+      cOutputModule.Process ((void**)pDst, &sDstBufInfo, pYuvFile);
+      iWidth  = sDstBufInfo.UsrData.sSystemBuffer.iWidth;
+      iHeight = sDstBufInfo.UsrData.sSystemBuffer.iHeight;
+
+      if (pOptionFile != NULL) {
+        if (iWidth != iLastWidth && iHeight != iLastHeight) {
+          fwrite (&iFrameCount, sizeof (iFrameCount), 1, pOptionFile);
+          fwrite (&iWidth , sizeof (iWidth) , 1, pOptionFile);
+          fwrite (&iHeight, sizeof (iHeight), 1, pOptionFile);
+          iLastWidth  = iWidth;
+          iLastHeight = iHeight;
+        }
+      }
+      ++ iFrameCount;
+    }
+#endif
     iBufPos += iSliceSize;
     ++ iSliceIndex;
   }