Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

329 lines
10 KiB

  1. /* *************************************************************************
  2. ** INTEL Corporation Proprietary Information
  3. **
  4. ** This listing is supplied under the terms of a license
  5. ** agreement with INTEL Corporation and may not be copied
  6. ** nor disclosed except in accordance with the terms of
  7. ** that agreement.
  8. **
  9. ** Copyright (c) 1995 Intel Corporation.
  10. ** All Rights Reserved.
  11. **
  12. ** *************************************************************************
  13. */
  14. /*****************************************************************************
  15. *
  16. * e1stat.cpp
  17. *
  18. * DESCRIPTION:
  19. * Encoder statistics functions
  20. *
  21. * Routines: Prototypes in:
  22. * OutputEncodeTimingStatistics e1stat.h
  23. */
  24. // $Header: R:\h26x\h26x\src\enc\e1stat.cpv 1.2 20 Mar 1996 14:20:58 Sylvia_C_Day $
  25. // $Log: R:\h26x\h26x\src\enc\e1stat.cpv $
  26. //
  27. // Rev 1.2 20 Mar 1996 14:20:58 Sylvia_C_Day
  28. // Added lower level timing stats for SLF_UV
  29. //
  30. // Rev 1.1 29 Dec 1995 18:08:56 DBRUCKS
  31. // add average quant used and coded
  32. //
  33. // Rev 1.0 26 Dec 1995 17:46:16 DBRUCKS
  34. // Initial revision.
  35. #include "precomp.h"
  36. #ifdef ENCODE_STATS
  37. static void OutputEncTimingDetail(FILE * pFile, ENC_TIMING_INFO * pEncTimingInfo);
  38. /************************************************************************
  39. *
  40. * OutputEncodeBitStreamStatistics
  41. */
  42. extern void OutputEncodeBitStreamStatistics(
  43. char * szFileName,
  44. ENC_BITSTREAM_INFO * pBSInfo,
  45. int bCIF)
  46. {
  47. FILE * pFile;
  48. U32 uTotalMBs;
  49. U32 uProcessedMBs;
  50. U32 uCOEFFBlocks;
  51. U32 uSkippedMBs;
  52. U32 uTotalQuantUsed;
  53. U32 uTotalQuantCoded;
  54. int i;
  55. pFile = fopen(szFileName, "a");
  56. if (pFile == NULL)
  57. {
  58. DBOUT("Error opening encode stat file");
  59. goto done;
  60. }
  61. /* Update the statistics
  62. */
  63. if (bCIF)
  64. {
  65. uTotalMBs = (pBSInfo->uKeyFrameCount + pBSInfo->uDeltaFrameCount) * 33 * 12;
  66. }
  67. else
  68. {
  69. uTotalMBs = (pBSInfo->uKeyFrameCount + pBSInfo->uDeltaFrameCount) * 33 * 3;
  70. }
  71. if (uTotalMBs == 0)
  72. {
  73. fprintf(pFile,"No Macro Blocks processed - skipping frame statistics\n");
  74. goto done;
  75. }
  76. uProcessedMBs = 0;
  77. uCOEFFBlocks = 0;
  78. for (i = 0 ; i < 10 ; i++)
  79. {
  80. uProcessedMBs += pBSInfo->uMTypeCount[i];
  81. uCOEFFBlocks += pBSInfo->uBlockCount[i];
  82. }
  83. uSkippedMBs = uTotalMBs - uProcessedMBs;
  84. fprintf(pFile,"Total Key Frames=%ld Delta Frames=%ld\n",
  85. pBSInfo->uKeyFrameCount, pBSInfo->uDeltaFrameCount);
  86. fprintf(pFile,"Total Total MBs=%ld\n", uTotalMBs);
  87. fprintf(pFile,"Total Coded MBs=%ld (%ld%%)\n", uProcessedMBs, ((uProcessedMBs*100)+(uTotalMBs/2))/uTotalMBs);
  88. fprintf(pFile,"Total Coded Blocks=%ld (%ld%%)\n", uCOEFFBlocks, ((uCOEFFBlocks*100)+(uTotalMBs/2))/(uTotalMBs*6));
  89. for (i = 0; i < 10 ; i++)
  90. {
  91. if (pBSInfo->uMTypeCount[i])
  92. {
  93. fprintf(pFile,"Total Coded MBType[%d]=%ld (%ld%%) blocks=%ld (%ld%%)\n",
  94. i,
  95. pBSInfo->uMTypeCount[i],
  96. ((pBSInfo->uMTypeCount[i]*100)+(uProcessedMBs/2))/uProcessedMBs,
  97. pBSInfo->uBlockCount[i],
  98. ((pBSInfo->uBlockCount[i]*100)+(uCOEFFBlocks/2))/uCOEFFBlocks);
  99. }
  100. }
  101. if (pBSInfo->uKeyFrameCount)
  102. {
  103. fprintf(pFile,"Total Key Frame Bytes=%ld Average Per Key Frame=%ld\n",
  104. pBSInfo->uTotalKeyBytes,
  105. (pBSInfo->uTotalKeyBytes + (pBSInfo->uKeyFrameCount/2)) / pBSInfo->uKeyFrameCount);
  106. }
  107. if (pBSInfo->uDeltaFrameCount)
  108. {
  109. fprintf(pFile,"Total Delta Frame Bytes=%ld Average Per Delta Frame=%ld\n",
  110. pBSInfo->uTotalDeltaBytes,
  111. (pBSInfo->uTotalDeltaBytes + (pBSInfo->uDeltaFrameCount/2)) / pBSInfo->uDeltaFrameCount);
  112. }
  113. if (pBSInfo->uKeyFrameCount || pBSInfo->uDeltaFrameCount)
  114. {
  115. fprintf(pFile,"Total Bytes=%ld Average Per Frame=%ld\n",
  116. pBSInfo->uTotalKeyBytes + pBSInfo->uTotalDeltaBytes,
  117. ((pBSInfo->uTotalKeyBytes + pBSInfo->uTotalDeltaBytes) + ((pBSInfo->uKeyFrameCount + pBSInfo->uDeltaFrameCount) / 2)) /
  118. (pBSInfo->uKeyFrameCount + pBSInfo->uDeltaFrameCount));
  119. }
  120. /* Quantization Information
  121. */
  122. uTotalQuantUsed = 0;
  123. uTotalQuantCoded = 0;
  124. for (i = 0; i <= 31; i++)
  125. {
  126. if (pBSInfo->uQuantsUsedOnBlocks[i])
  127. {
  128. fprintf(pFile,"QuantValue %2ld",i);
  129. fprintf(pFile," Used %7ld (%2ld%%)", pBSInfo->uQuantsUsedOnBlocks[i],
  130. ((pBSInfo->uQuantsUsedOnBlocks[i] * 100) + ((uTotalMBs*6)/2))/(uTotalMBs*6));
  131. fprintf(pFile," Coded %7ld (%2ld%%)\n", pBSInfo->uQuantsTransmittedOnBlocks[i],
  132. ((pBSInfo->uQuantsTransmittedOnBlocks[i] * 100) + ((uTotalMBs*6)/2))/(uTotalMBs*6));
  133. uTotalQuantUsed += pBSInfo->uQuantsUsedOnBlocks[i] * i;
  134. uTotalQuantCoded += pBSInfo->uQuantsTransmittedOnBlocks[i] * i;
  135. }
  136. if (pBSInfo->uQuantsTransmittedOnBlocks[i])
  137. ASSERT(pBSInfo->uQuantsUsedOnBlocks[i]);
  138. }
  139. if ((uTotalMBs > 0) && (uCOEFFBlocks > 0))
  140. {
  141. fprintf(pFile,"Average Used %f Average Coded %f",
  142. (float) uTotalQuantUsed / (float)(uTotalMBs*6),
  143. (float) uTotalQuantCoded / (float) uCOEFFBlocks);
  144. }
  145. #ifdef _DEBUG
  146. {
  147. U32 uUsedTotal = 0;
  148. U32 uCodedTotal = 0;
  149. for (i = 0; i <= 31; i++)
  150. {
  151. uUsedTotal += pBSInfo->uQuantsUsedOnBlocks[i];
  152. uCodedTotal += pBSInfo->uQuantsTransmittedOnBlocks[i];
  153. }
  154. ASSERT(uUsedTotal == (uTotalMBs*6));
  155. ASSERT(uCodedTotal == uCOEFFBlocks);
  156. }
  157. #endif
  158. done:
  159. return;
  160. } /* end OutputEncodeBitStreamStatistics() */
  161. /************************************************************************
  162. *
  163. * OutputEncodeTimingStatistics
  164. */
  165. extern void OutputEncodeTimingStatistics(
  166. char * szFileName,
  167. ENC_TIMING_INFO * pEncTimingInfo)
  168. {
  169. FILE * pFile;
  170. ENC_TIMING_INFO * pTempEncTimingInfo;
  171. ENC_TIMING_INFO etiTemp;
  172. int i;
  173. int iCount;
  174. pFile = fopen(szFileName, "a");
  175. if (pFile == NULL)
  176. {
  177. DBOUT("Error opening encode stat file");
  178. goto done;
  179. }
  180. #ifdef DETAIL_ENCODE_STATS
  181. /* Output the detail information
  182. */
  183. fprintf(pFile,"\nDetail Timing Information\n");
  184. for ( i = 0, pTempEncTimingInfo = pEncTimingInfo ;
  185. i < ENC_TIMING_INFO_FRAME_COUNT ;
  186. i++, pTempEncTimingInfo++ )
  187. {
  188. if (pTempEncTimingInfo->uDecodeFrame != 0)
  189. {
  190. fprintf(pFile, "Frame %d Detail Timing Information\n", i);
  191. OutputEncTimingDetail(pFile, pTempEncTimingInfo);
  192. }
  193. }
  194. #endif
  195. /* Compute the total information
  196. */
  197. memset(&etiTemp, 0, sizeof(ENC_TIMING_INFO));
  198. iCount = 0;
  199. for ( i = 0, pTempEncTimingInfo = pEncTimingInfo ;
  200. i < ENC_TIMING_INFO_FRAME_COUNT ;
  201. i++, pTempEncTimingInfo++ )
  202. {
  203. if (pTempEncTimingInfo->uDecodeFrame != 0)
  204. {
  205. iCount++;
  206. etiTemp.uEncodeFrame += pTempEncTimingInfo->uEncodeFrame;
  207. etiTemp.uInputCC += pTempEncTimingInfo->uInputCC;
  208. etiTemp.uMotionEstimation += pTempEncTimingInfo->uMotionEstimation;
  209. etiTemp.uFDCT += pTempEncTimingInfo->uFDCT;
  210. etiTemp.uQRLE += pTempEncTimingInfo->uQRLE;
  211. etiTemp.uDecodeFrame += pTempEncTimingInfo->uDecodeFrame;
  212. etiTemp.uZeroingBuffer += pTempEncTimingInfo->uZeroingBuffer;
  213. etiTemp.uSLF_UV += pTempEncTimingInfo->uSLF_UV;
  214. }
  215. }
  216. if (iCount > 0)
  217. {
  218. #ifdef DETAIL_ENCODE_STATS
  219. /* Output the total information
  220. */
  221. fprintf(pFile,"Total for %d frames\n", iCount);
  222. OutputEncTimingDetail(pFile, &etiTemp);
  223. #endif
  224. /* Compute the average
  225. */
  226. etiTemp.uEncodeFrame = (etiTemp.uEncodeFrame + (iCount / 2)) / iCount;
  227. etiTemp.uInputCC = (etiTemp.uInputCC + (iCount / 2)) / iCount;
  228. etiTemp.uMotionEstimation = (etiTemp.uMotionEstimation + (iCount / 2)) / iCount;
  229. etiTemp.uFDCT = (etiTemp.uFDCT + (iCount / 2)) / iCount;
  230. etiTemp.uQRLE = (etiTemp.uQRLE + (iCount / 2)) / iCount;
  231. etiTemp.uDecodeFrame = (etiTemp.uDecodeFrame + (iCount / 2)) / iCount;
  232. etiTemp.uZeroingBuffer = (etiTemp.uZeroingBuffer + (iCount / 2)) / iCount;
  233. etiTemp.uSLF_UV = (etiTemp.uSLF_UV + (iCount / 2)) / iCount;
  234. /* Output the average information
  235. */
  236. fprintf(pFile,"Average over %d frames\n", iCount);
  237. OutputEncTimingDetail(pFile, &etiTemp);
  238. }
  239. fclose(pFile);
  240. done:
  241. return;
  242. } /* OutputEncodeTimingStatistics() */
  243. /************************************************************************
  244. *
  245. * OutputEncTimingDetail
  246. */
  247. static void OutputEncTimingDetail(
  248. FILE * pFile,
  249. ENC_TIMING_INFO * pEncTimingInfo)
  250. {
  251. U32 uOther;
  252. U32 uRoundUp;
  253. U32 uDivisor;
  254. fprintf(pFile, "\tEncode Frame = %10d (%d milliseconds at 90Mhz)\n", pEncTimingInfo->uEncodeFrame,
  255. (pEncTimingInfo->uEncodeFrame + 45000) / 90000);
  256. uOther = pEncTimingInfo->uEncodeFrame;
  257. /* This is needed because of the integer truncation.
  258. */
  259. uDivisor = pEncTimingInfo->uEncodeFrame / 100; // to yield a percent
  260. uRoundUp = uDivisor / 2;
  261. fprintf(pFile, "\tInputCC = %10d (%2d%%)\n", pEncTimingInfo->uInputCC,
  262. (pEncTimingInfo->uInputCC + uRoundUp) / uDivisor);
  263. uOther -= pEncTimingInfo->uInputCC;
  264. fprintf(pFile, "\tMotionEstimation = %10d (%2d%%)\n", pEncTimingInfo->uMotionEstimation,
  265. (pEncTimingInfo->uMotionEstimation + uRoundUp) / uDivisor);
  266. uOther -= pEncTimingInfo->uMotionEstimation;
  267. fprintf(pFile, "\tFDCT = %10d (%2d%%)\n", pEncTimingInfo->uFDCT,
  268. (pEncTimingInfo->uFDCT + uRoundUp) / uDivisor);
  269. uOther -= pEncTimingInfo->uFDCT;
  270. fprintf(pFile, "\tQRLE = %10d (%2d%%)\n", pEncTimingInfo->uQRLE,
  271. (pEncTimingInfo->uQRLE + uRoundUp) / uDivisor);
  272. uOther -= pEncTimingInfo->uQRLE;
  273. fprintf(pFile, "\tDecodeFrame = %10d (%2d%%)\n", pEncTimingInfo->uDecodeFrame,
  274. (pEncTimingInfo->uDecodeFrame + uRoundUp) / uDivisor);
  275. uOther -= pEncTimingInfo->uDecodeFrame;
  276. fprintf(pFile, "\tZeroingBuffer = %10d (%2d%%)\n", pEncTimingInfo->uZeroingBuffer,
  277. (pEncTimingInfo->uZeroingBuffer + uRoundUp) / uDivisor);
  278. uOther -= pEncTimingInfo->uZeroingBuffer;
  279. fprintf(pFile, "\tSLF_UV = %10d (%2d%%)\n", pEncTimingInfo->uSLF_UV,
  280. (pEncTimingInfo->uSLF_UV + uRoundUp) / uDivisor);
  281. uOther -= pEncTimingInfo->uSLF_UV;
  282. fprintf(pFile, "\tOther = %10d (%2d%%)\n", uOther,
  283. (uOther + uRoundUp) / uDivisor);
  284. } /* end OutputEncTimingDetail() */
  285. #endif /* ENCODE_STATS */