vidstats.cpp
Upload User: dangjiwu
Upload Date: 2013-07-19
Package Size: 42019k
Code Size: 9k
Category:

Symbian

Development Platform:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: vidstats.cpp,v 1.3.20.1 2004/07/09 01:55:01 hubbe Exp $
  3.  * 
  4.  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
  5.  * 
  6.  * The contents of this file, and the files included with this file,
  7.  * are subject to the current version of the RealNetworks Public
  8.  * Source License (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the current version of the RealNetworks Community
  11.  * Source License (the "RCSL") available at
  12.  * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
  13.  * will apply. You may also obtain the license terms directly from
  14.  * RealNetworks.  You may not use this file except in compliance with
  15.  * the RPSL or, if you have a valid RCSL with RealNetworks applicable
  16.  * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
  17.  * the rights, obligations and limitations governing use of the
  18.  * contents of the file.
  19.  * 
  20.  * Alternatively, the contents of this file may be used under the
  21.  * terms of the GNU General Public License Version 2 or later (the
  22.  * "GPL") in which case the provisions of the GPL are applicable
  23.  * instead of those above. If you wish to allow use of your version of
  24.  * this file only under the terms of the GPL, and not to allow others
  25.  * to use your version of this file under the terms of either the RPSL
  26.  * or RCSL, indicate your decision by deleting the provisions above
  27.  * and replace them with the notice and other provisions required by
  28.  * the GPL. If you do not delete the provisions above, a recipient may
  29.  * use your version of this file under the terms of any one of the
  30.  * RPSL, the RCSL or the GPL.
  31.  * 
  32.  * This file is part of the Helix DNA Technology. RealNetworks is the
  33.  * developer of the Original Code and owns the copyrights in the
  34.  * portions it created.
  35.  * 
  36.  * This file, and the files included with this file, is distributed
  37.  * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
  38.  * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
  39.  * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
  40.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
  41.  * ENJOYMENT OR NON-INFRINGEMENT.
  42.  * 
  43.  * Technology Compatibility Kit Test Suite(s) Location:
  44.  *    http://www.helixcommunity.org/content/tck
  45.  * 
  46.  * Contributor(s):
  47.  * 
  48.  * ***** END LICENSE BLOCK ***** */
  49. /****************************************************************************
  50.  *  Defines
  51.  */
  52. #define MAX_FLOAT_STRING_LENGTH     35
  53. /****************************************************************************
  54.  *  Includes
  55.  */
  56. #include <stdio.h>
  57. #include "rendstats.h"
  58. #include "vidstats.h"
  59. #include "hxstrutl.h"
  60. /****************************************************************************
  61.  *  CVideoStatistics
  62.  */
  63. /****************************************************************************
  64.  *  Costructor/Destructor
  65.  */
  66. CVideoStatistics::CVideoStatistics(IUnknown* pContext,
  67.    ULONG32 ulNumIntervals)
  68.     : m_pRegistry(NULL)
  69.     , m_pDisplay(NULL)
  70.     , m_ulLastSyncTime(0)
  71.     , m_ulNumIntervalPoints(ulNumIntervals + 1)
  72.     , m_pPast(NULL)
  73.     , m_ulStartIntervalIndex(0)
  74.     , m_ulEndIntervalIndex(0)
  75.     , m_bStatsComputed(FALSE)
  76.     , m_fPercentFramesDisplayed(0.0)
  77.     , m_fFrameRate(0.0)
  78. {
  79.     pContext->QueryInterface(IID_IHXRegistry, (void**)&m_pRegistry);
  80.     HX_ASSERT(m_ulNumIntervalPoints > 0);
  81.     if (m_ulNumIntervalPoints > 0)
  82.     {
  83. m_pPast = new VStatCounters [m_ulNumIntervalPoints];
  84. HX_ASSERT(m_pPast);
  85.     }
  86.     m_pDisplay = new CRendererStatisticsDisplay(m_pRegistry, 
  87. (UINT32) VS_NUM_ENTRIES);
  88.     HX_ASSERT(m_pDisplay);
  89.     PrimeEntries();
  90. }
  91. CVideoStatistics::~CVideoStatistics()
  92. {
  93.     HX_DELETE(m_pDisplay);
  94.     HX_VECTOR_DELETE(m_pPast);
  95.     HX_RELEASE(m_pRegistry);
  96. }
  97. /****************************************************************************
  98.  *  PrimeEntries
  99.  */
  100. HX_RESULT CVideoStatistics::PrimeEntries(void)
  101. {
  102.     HX_RESULT retVal = HXR_FAIL;
  103.     if (m_pDisplay)
  104.     {
  105. m_pDisplay->PrimeEntry((UINT32) VS_REND_NAME, "Name", REG_TYPE_STRING);
  106. m_pDisplay->PrimeEntry((UINT32) VS_CODEC_NAME, "CodecName", REG_TYPE_STRING);
  107. m_pDisplay->PrimeEntry((UINT32) VS_CODEC_4CC, "CodecFourCC", REG_TYPE_STRING);
  108. m_pDisplay->PrimeEntry((UINT32) VS_CODEC_VERSION, "CodecVersion", REG_TYPE_NUMBER);
  109. m_pDisplay->PrimeEntry((UINT32) VS_CODEC_FRAMERATE, "CodecFrameRate", REG_TYPE_NUMBER);
  110. m_pDisplay->PrimeEntry((UINT32) VS_CURRENT_FRAMERATE, "CurrentFrameRate", REG_TYPE_STRING);
  111. m_pDisplay->PrimeEntry((UINT32) VS_FRAMES_DISPLAYED, "FramesDisplayed", REG_TYPE_STRING);
  112. m_pDisplay->PrimeEntry((UINT32) VS_FRAMES_DROPPED, "FramesDropped", REG_TYPE_NUMBER);
  113. m_pDisplay->PrimeEntry((UINT32) VS_FRAMES_LOST, "FramesLost", REG_TYPE_NUMBER);
  114. m_pDisplay->PrimeEntry((UINT32) VS_SURESTREAM, "SureStream", REG_TYPE_STRING);
  115. m_pDisplay->PrimeEntry((UINT32) VS_POSTFILTER, "CodecPostFilter", REG_TYPE_NUMBER);
  116. m_pDisplay->PrimeEntry((UINT32) VS_CODECS, "CodecsSuite", REG_TYPE_STRING);
  117. m_pDisplay->PrimeEntry((UINT32) VS_CODECS_FRAMERATES, "CodecsFrameRates", REG_TYPE_STRING);
  118. m_pDisplay->PrimeEntry((UINT32) VS_IMAGE_WIDTH, "ImageWidth", REG_TYPE_NUMBER);
  119. m_pDisplay->PrimeEntry((UINT32) VS_IMAGE_HEIGHT, "ImageHeight", REG_TYPE_NUMBER);
  120. retVal = HXR_OK;
  121.     }
  122.     return retVal;
  123. }
  124. /****************************************************************************
  125.  *  UpdateStatistics
  126.  */
  127. HX_RESULT CVideoStatistics::DisplayStats(UINT32 ulRegistryID)
  128. {
  129.     HX_RESULT retVal = HXR_FAIL;
  130.     if (m_pDisplay && (ulRegistryID != 0))
  131.     {
  132. retVal = HXR_OK;
  133.     }
  134.     // Perform any outstanding updates
  135.     if (SUCCEEDED(retVal))
  136.     {
  137. if (m_bStatsComputed)
  138. {
  139.     char pValBuffer[MAX_FLOAT_STRING_LENGTH];
  140.     m_bStatsComputed = FALSE;
  141.     sprintf(pValBuffer, "%.1f", m_fFrameRate);
  142.     ReportStat(VS_CURRENT_FRAMERATE, pValBuffer);
  143.     SafeSprintf(pValBuffer, MAX_FLOAT_STRING_LENGTH, "%.1f", m_fPercentFramesDisplayed);
  144.     ReportStat(VS_FRAMES_DISPLAYED, pValBuffer);
  145. }
  146. ReportStat(VS_FRAMES_DROPPED, m_Master.m_ulDroppedFrameCount);
  147. ReportStat(VS_FRAMES_LOST, m_Master.m_ulLostFrameCount);
  148.     }
  149.     // Refresh Display
  150.     if (SUCCEEDED(retVal))
  151.     {
  152. m_pDisplay->RefreshEntries(ulRegistryID);
  153.     }
  154.     return HXR_OK;
  155. }
  156. /****************************************************************************
  157.  *  SyncStats
  158.  */
  159. HX_RESULT CVideoStatistics::SyncStats(ULONG32 ulTime)
  160. {
  161.     ULONG32 ulLostFrameCount = m_Master.m_ulLostFrameCount;
  162.     ULONG32 ulDroppedFrameCount = m_Master.m_ulDroppedFrameCount;
  163.     ULONG32 ulBlitedFrameCount = m_Master.m_ulBlitedFrameCount;
  164.     ULONG32 ulLastFrameTimeStamp = m_Master.m_ulLastFrameTimeStamp;
  165.     VStatCounters* pNewStats = &(m_pPast[m_ulEndIntervalIndex]);
  166.     pNewStats->m_ulLostFrameCount = ulLostFrameCount;
  167.     pNewStats->m_ulDroppedFrameCount = ulDroppedFrameCount;
  168.     pNewStats->m_ulBlitedFrameCount = ulBlitedFrameCount;
  169.     pNewStats->m_ulLastFrameTimeStamp = ulLastFrameTimeStamp;
  170.     m_ulLastSyncTime = ulTime;
  171.     ComputeStatistics();
  172.     AdvanceIndex();
  173.     return HXR_OK;
  174. }
  175. /****************************************************************************
  176.  *  UpdateStatistics
  177.  */
  178. void CVideoStatistics::ComputeStatistics(void)
  179. {
  180.     if (m_ulStartIntervalIndex != m_ulEndIntervalIndex)
  181.     {
  182. ULONG32 ulIntervalLostFrameCount = 
  183.     m_pPast[m_ulEndIntervalIndex].m_ulLostFrameCount -
  184.     m_pPast[m_ulStartIntervalIndex].m_ulLostFrameCount;
  185. ULONG32 ulIntervalDroppedFrameCount = 
  186.     m_pPast[m_ulEndIntervalIndex].m_ulDroppedFrameCount -
  187.     m_pPast[m_ulStartIntervalIndex].m_ulDroppedFrameCount;
  188. ULONG32 ulIntervalBlitedFrameCount = 
  189.     m_pPast[m_ulEndIntervalIndex].m_ulBlitedFrameCount -
  190.     m_pPast[m_ulStartIntervalIndex].m_ulBlitedFrameCount;
  191. ULONG32 ulIntervalTime = 
  192.     m_pPast[m_ulEndIntervalIndex].m_ulLastFrameTimeStamp -
  193.     m_pPast[m_ulStartIntervalIndex].m_ulLastFrameTimeStamp;
  194. ULONG32 ulIntervalTotalFrames = ulIntervalLostFrameCount +
  195. ulIntervalDroppedFrameCount +
  196. ulIntervalBlitedFrameCount;
  197. if (ulIntervalTime != 0)
  198. {
  199.     m_fFrameRate = ((double) ulIntervalBlitedFrameCount) *
  200.    1000.0 /
  201.    ((double) ulIntervalTime);
  202. }
  203. if (ulIntervalTotalFrames != 0)
  204. {
  205.     m_fPercentFramesDisplayed = ((double) ulIntervalBlitedFrameCount) *
  206. 100.0 /
  207. ((double) ulIntervalTotalFrames);
  208. }
  209. else
  210. {
  211.     m_fPercentFramesDisplayed = 100.0;
  212. }
  213. m_bStatsComputed = TRUE;
  214.     }
  215. }