hxplay.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:277k
源码类别:

Symbian

开发平台:

C/C++

  1.     if (uGroupIndex == m_nCurrentGroup &&
  2.         HXR_OK == GetSourceInfo(uGroupIndex, uTrackIndex, pSourceInfo))
  3.     {
  4.         hr = pSourceInfo->SetSoundLevel(uSoundLevel, bReflushAudioDevice);
  5.     }
  6.     else
  7.     {
  8.         hr = HXR_UNEXPECTED;
  9.     }
  10.     return hr;
  11. }
  12.     
  13. void
  14. HXPlayer::CheckSourceRegistration(void)
  15. {
  16.     BOOL bAtLeastOneRegister = FALSE;
  17.     CHXMapPtrToPtr::Iterator ndxSources = m_pSourceMap->Begin();
  18.     /* Check if we are done. This may be TRUE for empty files */
  19.     for (; ndxSources != m_pSourceMap->End(); ++ndxSources)
  20.     {
  21.         SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSources);
  22.         if (pSourceInfo->m_pSource && pSourceInfo->m_pSource->CanBeResumed())
  23.         {
  24.             pSourceInfo->Register();
  25.             bAtLeastOneRegister = TRUE;
  26.         }
  27.     }
  28.     if (bAtLeastOneRegister)
  29.     {
  30.         RegisterSourcesDone();
  31.     }
  32. }
  33. void
  34. HXPlayer::GetTimingFromURL(CHXURL* pURL, UINT32& ulStart, 
  35.                            UINT32& ulEnd, UINT32& ulDelay, UINT32& ulDuration)
  36. {
  37.     IHXValues* pURLOptions = NULL;
  38.     ulStart = 0;
  39.     ulEnd = HX_EOF_TIME;
  40.     ulDelay = 0;
  41.     ulDuration = 0;
  42.     if (pURL)
  43.     {
  44.         pURLOptions = pURL->GetOptions();
  45.         if (pURLOptions)
  46.         {
  47.             pURLOptions->GetPropertyULONG32("Start", ulStart);
  48.             pURLOptions->GetPropertyULONG32("End", ulEnd);
  49.             pURLOptions->GetPropertyULONG32("Delay", ulDelay);
  50.             pURLOptions->GetPropertyULONG32("Duration", ulDuration);
  51.         }
  52.         HX_RELEASE(pURLOptions);
  53.     }
  54. }
  55. /************************************************************************
  56.  *  Method:
  57.  *      IHXOverrideDefaultServices::OverrideServices
  58.  *  Purpose:
  59.  *      Override default services provided by the G2 system.
  60.  *
  61.  */
  62. STDMETHODIMP
  63. HXPlayer::OverrideServices(IUnknown* pContext)
  64. {
  65.     if (!pContext)
  66.     {
  67.         return HXR_UNEXPECTED;
  68.     }
  69. #if defined(HELIX_FEATURE_PREFERENCES)
  70.     /* override IHXPreferences */
  71.     IHXPreferences* pPreferences = NULL;
  72.     if (pContext->QueryInterface(IID_IHXPreferences, (void**) &pPreferences)
  73.             == HXR_OK)
  74.     {
  75.         HX_RELEASE(m_pPreferences);
  76.         m_pPreferences = pPreferences;
  77.     }
  78. #endif /* HELIX_FEATURE_PREFERENCES */
  79.     /* override IHXPlugin2Handler */
  80.     IHXPlugin2Handler* pPlugin2Handler = NULL;
  81.     if (pContext->QueryInterface(IID_IHXPlugin2Handler, (void**) &pPlugin2Handler)
  82.             == HXR_OK)
  83.     {
  84.         HX_RELEASE(m_pPlugin2Handler);
  85.         m_pPlugin2Handler = pPlugin2Handler;
  86.     }
  87.     return HXR_OK;
  88. }
  89. /*
  90.  * IHXPlayerNavigator methods
  91.  */
  92. /************************************************************************
  93.  *      Method:
  94.  *          IHXPlayerNavigator::AddChildPlayer
  95.  *      Purpose:
  96.  *          Add child player to the current player
  97.  */
  98. STDMETHODIMP
  99. HXPlayer::AddChildPlayer(IHXPlayer* pPlayer)
  100. {
  101. #if defined(HELIX_FEATURE_PLAYERNAVIGATOR)
  102.     if (!m_pChildPlayerList)
  103.     {
  104.         m_pChildPlayerList = new CHXSimpleList();
  105.     }
  106.     if (m_pChildPlayerList &&
  107.         !m_pChildPlayerList->Find(pPlayer))
  108.     {
  109.         pPlayer->AddRef();
  110.         m_pChildPlayerList->AddTail(pPlayer);
  111.     }
  112.     return HXR_OK;
  113. #else
  114.     return HXR_NOTIMPL;
  115. #endif /* HELIX_FEATURE_AUTHENTICATION */
  116. }
  117. /************************************************************************
  118.  *      Method:
  119.  *          IHXPlayerNavigator::RemoveChildPlayer
  120.  *      Purpose:
  121.  *          Remove child player from the current player
  122.  */
  123. STDMETHODIMP
  124. HXPlayer::RemoveChildPlayer(IHXPlayer* pPlayer)
  125. {
  126. #if defined(HELIX_FEATURE_PLAYERNAVIGATOR)
  127.     if (m_pChildPlayerList)
  128.     {
  129.         LISTPOSITION lPosition = m_pChildPlayerList->Find(pPlayer);
  130.         if (lPosition)
  131.         {
  132.             m_pChildPlayerList->RemoveAt(lPosition);
  133.             HX_RELEASE(pPlayer);
  134.         }
  135.     }
  136.     return HXR_OK;
  137. #else
  138.     return HXR_NOTIMPL;
  139. #endif /* HELIX_FEATURE_AUTHENTICATION */
  140. }
  141. /************************************************************************
  142.  *      Method:
  143.  *          IHXPlayerNavigator::GetNumChildPlayer
  144.  *      Purpose:
  145.  *          Get number of the child players
  146.  */
  147. STDMETHODIMP_(UINT16)
  148. HXPlayer::GetNumChildPlayer()
  149. {
  150. #if defined(HELIX_FEATURE_PLAYERNAVIGATOR)
  151.     return m_pChildPlayerList ? m_pChildPlayerList->GetCount() : 0;
  152. #else
  153.     return 0;
  154. #endif /* HELIX_FEATURE_AUTHENTICATION */
  155. }
  156. /************************************************************************
  157.  *      Method:
  158.  *          IHXPlayerNavigator::GetChildPlayer
  159.  *      Purpose:
  160.  *          Get Nth child player
  161.  */
  162. STDMETHODIMP
  163. HXPlayer::GetChildPlayer(UINT16 uPlayerIndex,
  164.                           REF(IHXPlayer*) pPlayer)
  165. {
  166. #if defined(HELIX_FEATURE_PLAYERNAVIGATOR)
  167.     HX_RESULT       rc = HXR_OK;
  168.     LISTPOSITION    lPosition;
  169.     pPlayer = NULL;
  170.     if (!m_pChildPlayerList)
  171.     {
  172.         rc = HXR_FAILED;
  173.         goto cleanup;
  174.     }
  175.     lPosition = m_pChildPlayerList->FindIndex(uPlayerIndex);
  176.     if (!lPosition)
  177.     {
  178.         rc = HXR_FAILED;
  179.         goto cleanup;
  180.     }
  181.     pPlayer = (IHXPlayer*)m_pChildPlayerList->GetAt(lPosition);
  182.     pPlayer->AddRef();
  183. cleanup:
  184.     return rc;
  185. #else
  186.     return HXR_NOTIMPL;
  187. #endif /* HELIX_FEATURE_AUTHENTICATION */
  188. }
  189. /************************************************************************
  190.  *      Method:
  191.  *          IHXPlayerNavigator::SetParentPlayer
  192.  *      Purpose:
  193.  *          Set the parent player
  194.  */
  195. STDMETHODIMP
  196. HXPlayer::SetParentPlayer(IHXPlayer* pPlayer)
  197. {
  198. #if defined(HELIX_FEATURE_PLAYERNAVIGATOR)
  199.     HX_ASSERT(!m_pParentPlayer);
  200.     HX_RELEASE(m_pParentPlayer);
  201.     m_pParentPlayer = pPlayer;
  202.     pPlayer->AddRef();
  203.     return HXR_OK;
  204. #else
  205.     return HXR_NOTIMPL;
  206. #endif /* HELIX_FEATURE_AUTHENTICATION */
  207. }
  208. /************************************************************************
  209.  *      Method:
  210.  *          IHXPlayerNavigator::RemoveParentPlayer
  211.  *      Purpose:
  212.  *          Remove the parent player
  213.  */
  214. STDMETHODIMP
  215. HXPlayer::RemoveParentPlayer(IHXPlayer* pPlayer)
  216. {
  217. #if defined(HELIX_FEATURE_PLAYERNAVIGATOR)
  218.     HX_ASSERT(pPlayer == m_pParentPlayer);
  219.     HX_RELEASE(m_pParentPlayer);
  220.     return HXR_OK;
  221. #else
  222.     return HXR_NOTIMPL;
  223. #endif /* HELIX_FEATURE_AUTHENTICATION */
  224. }
  225. /************************************************************************
  226.  *      Method:
  227.  *          IHXPlayerNavigator::GetParentPlayer
  228.  *      Purpose:
  229.  *          Get the parent player
  230.  */
  231. STDMETHODIMP
  232. HXPlayer::GetParentPlayer(REF(IHXPlayer*) pPlayer)
  233. {
  234. #if defined(HELIX_FEATURE_PLAYERNAVIGATOR)
  235.     pPlayer = NULL;
  236.     if (m_pParentPlayer)
  237.     {
  238.         pPlayer = m_pParentPlayer;
  239.         pPlayer->AddRef();
  240.         return HXR_OK;
  241.     }
  242.     else
  243.     {
  244.         return HXR_FAILED;
  245.     }
  246. #else
  247.     return HXR_NOTIMPL;
  248. #endif /* HELIX_FEATURE_AUTHENTICATION */
  249. }
  250. #if defined(HELIX_FEATURE_STATS) && defined(HELIX_FEATURE_REGISTRY)
  251. // UpdateStatsCallback
  252. UpdateStatsCallback::UpdateStatsCallback() :
  253.      m_lRefCount (0)
  254.     ,m_pPlayer (0)
  255.     ,m_PendingHandle (0)
  256.     ,m_bIsCallbackPending(FALSE)
  257. {
  258. }
  259. UpdateStatsCallback::~UpdateStatsCallback()
  260. {
  261. }
  262. /*
  263.  * IUnknown methods
  264.  */
  265. /////////////////////////////////////////////////////////////////////////
  266. //      Method:
  267. //              IUnknown::QueryInterface
  268. //      Purpose:
  269. //              Implement this to export the interfaces supported by your
  270. //              object.
  271. //
  272. STDMETHODIMP UpdateStatsCallback::QueryInterface(REFIID riid, void** ppvObj)
  273. {
  274.     QInterfaceList qiList[] =
  275.         {
  276.             { GET_IIDHANDLE(IID_IHXCallback), (IHXCallback*)this },
  277.             { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXCallback*)this },
  278.         };
  279.     
  280.     return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
  281. }
  282. /////////////////////////////////////////////////////////////////////////
  283. //      Method:
  284. //              IUnknown::AddRef
  285. //      Purpose:
  286. //              Everyone usually implements this the same... feel free to use
  287. //              this implementation.
  288. //
  289. STDMETHODIMP_(ULONG32) UpdateStatsCallback::AddRef()
  290. {
  291.     return InterlockedIncrement(&m_lRefCount);
  292. }
  293. /////////////////////////////////////////////////////////////////////////
  294. //      Method:
  295. //              IUnknown::Release
  296. //      Purpose:
  297. //              Everyone usually implements this the same... feel free to use
  298. //              this implementation.
  299. //
  300. STDMETHODIMP_(ULONG32) UpdateStatsCallback::Release()
  301. {
  302.     if (InterlockedDecrement(&m_lRefCount) > 0)
  303.     {
  304.         return m_lRefCount;
  305.     }
  306.     delete this;
  307.     return 0;
  308. }
  309. /*
  310.  *      IHXCallback methods
  311.  */
  312. STDMETHODIMP UpdateStatsCallback::Func(void)
  313. {
  314.     m_PendingHandle     = 0;
  315.     m_bIsCallbackPending        = FALSE;
  316.     if (m_pPlayer)
  317.     {
  318.         m_pPlayer->UpdateStatistics();
  319.     }
  320.     return HXR_OK;
  321. }
  322. #endif /* HELIX_FEATURE_STATS && HELIX_FEATURE_REGISTRY */
  323. // HXCallback
  324. #if defined (_WIN32) || defined (_MACINTOSH) || defined(THREADS_SUPPORTED)
  325. HXPlayerCallback::HXPlayerCallback(void* pParam, fGenericCBFunc pFunc)
  326.  :  CHXGenericCallback(pParam, pFunc)
  327.  ,  m_bInterrupSafe(FALSE) 
  328. {
  329. }
  330.     
  331. STDMETHODIMP HXPlayerCallback::QueryInterface(REFIID riid, void** ppvObj)
  332. {
  333.     if (IsEqualIID(riid, IID_IHXInterruptSafe))
  334.     {
  335.         AddRef();
  336.         *ppvObj = (IUnknown*)(IHXInterruptSafe*)this;
  337.         return HXR_OK;
  338.     }
  339.     else
  340.     {
  341.         return CHXGenericCallback::QueryInterface(riid, ppvObj);
  342.     }
  343. }
  344. STDMETHODIMP_(BOOL) HXPlayerCallback::IsInterruptSafe()
  345. {
  346.     HXPlayer* pPlayer = (HXPlayer*)m_pParam;
  347.     return  m_bInterrupSafe && 
  348.             pPlayer->m_bInitialized &&
  349.             !pPlayer->m_bIsDone;
  350. }
  351. #endif //(_WIN32) || defined (_MACINTOSH) || defined(THREADS_SUPPORTED)
  352. void HXPlayer::PlayerCallback(void* pParam)
  353. {
  354.     HXPlayer* pObj = (HXPlayer*)pParam;
  355.     if (pObj)
  356.     {
  357.         pObj->ProcessIdle();
  358.     }
  359. }
  360. void HXPlayer::SetupCallback(void* pParam)
  361. {
  362.     HXPlayer* pObj = (HXPlayer*)pParam;
  363.     if (pObj)
  364.     {
  365.         pObj->SetupAudioPlayer();
  366.     }
  367. }
  368. #if defined(HELIX_FEATURE_AUTHENTICATION)
  369. void HXPlayer::AuthenticationCallback(void* pParam)
  370. {
  371.     HXPlayer* pObj = (HXPlayer*)pParam;
  372.     if (pObj)
  373.     {
  374.         pObj->ProcessPendingAuthentication();
  375.     }
  376. }
  377. #endif //HELIX_FEATURE_AUTHENTICATION
  378. /************************************************************************
  379.  *  Method:
  380.  *      HXPlayer::SetupRendererSite
  381.  *
  382.  *  NOTE: Notice that the props passed in are associated with the stream
  383.  *  that the renderer is rendering, but we don't make renderers implement
  384.  *  their own support IHXValues. That would be mean.
  385.  */
  386. void
  387. HXPlayer::SetupRendererSite(IUnknown* pRenderer, IHXValues* pProps, BOOL bIsPersistent)
  388. {
  389. #if defined(HELIX_FEATURE_VIDEO)
  390.     HX_ASSERT(pProps);
  391.     HX_ASSERT(pRenderer);
  392.     IHXSiteUserSupplier*   pSUS = NULL;
  393.     IHXSiteUser*           pSU  = NULL;
  394.     UINT32                  uReqestID;
  395.     /*
  396.      * If the renderer doesn't support IHXSiteUserSupplier then
  397.      * it is not a display oriented renderer and we skip it to
  398.      * go to the next one!
  399.      */
  400.     if (HXR_OK == pRenderer->QueryInterface(IID_IHXSiteUserSupplier,
  401.                                             (void**)&pSUS))
  402.     {
  403.         /*
  404.          * Ask the site manager if any sites are available
  405.          * for the renderer by this playto/from info.
  406.          */
  407.         if (!m_pSiteManager->
  408.                         IsSiteAvailableByPlayToFrom(pProps, /*bIsPersistent*/ FALSE))
  409.         {
  410.             if (m_pSiteSupplier)
  411.             {
  412.                 /*
  413.                  * Let the site supplier know that we are changing the layout.
  414.                  */
  415.                 if (m_bBeginChangeLayoutTobeCalled)
  416.                 {
  417.                     m_bBeginChangeLayoutTobeCalled      = FALSE;
  418.                     m_pSiteSupplier->BeginChangeLayout();
  419.                 }
  420.                 // XXXRA Change to revert back to old focus behavior for
  421.                 // datatypes that rely on this behavior
  422.                 CheckIfRendererNeedFocus(pRenderer);
  423.                 /*
  424.                  * Inform the TLC/SS of the new sites we need.
  425.                  */
  426.                 uReqestID = (ULONG32)pSUS;
  427.                 m_pSiteSupplier->SitesNeeded(uReqestID,pProps);
  428.                 DisableScreenSaver();
  429.                 m_SiteRequestIDList.AddTail((void*)uReqestID);
  430.             }
  431.         }
  432.         /*  JEB: if the hookup failed, do not release the site user
  433.          *  Hookup will add it to a list and hook it up later
  434.          *  when the site has really been added
  435.          */
  436.         if (m_pSiteManager->HookupByPlayToFrom(pSUS,pProps,/*bIsPersistent*/ FALSE))
  437.         {
  438.             pSUS->Release();
  439.         }
  440.     }
  441.     // If the renderer doesn't support SiteUserSupplier, than see if
  442.     // it supports single instance as a SiteUser...
  443.     else if (HXR_OK == pRenderer->QueryInterface(IID_IHXSiteUser,
  444.                             (void**)&pSU))
  445.     {
  446.         /*
  447.          * Ask the site manager if any sites are available
  448.          * for the renderer by this playto/from info.
  449.          */
  450.         if (!m_pSiteManager->
  451.                         IsSiteAvailableByPlayToFrom(pProps, /*bIsPersistent*/ FALSE))
  452.         {
  453.             if (m_pSiteSupplier)
  454.             {
  455.                 /*
  456.                  * Let the site supplier know that we are changing the layout.
  457.                  */
  458.                 if (m_bBeginChangeLayoutTobeCalled)
  459.                 {
  460.                     m_bBeginChangeLayoutTobeCalled      = FALSE;
  461.                     m_pSiteSupplier->BeginChangeLayout();
  462.                 }
  463.                 // XXXRA Change to revert back to old focus behavior for
  464.                 // datatypes that rely on this behavior
  465.                 CheckIfRendererNeedFocus(pRenderer);
  466.                 /*
  467.                  * Inform the TLC/SS of the new sites we need.
  468.                  */
  469.                 uReqestID = (ULONG32)pSU;
  470.                 m_pSiteSupplier->SitesNeeded(uReqestID,pProps);
  471.                 DisableScreenSaver();
  472.                 m_SiteRequestIDList.AddTail((void*)uReqestID);
  473.             }
  474.         }
  475.         /*  JEB: if the hookup failed, do not release the site user
  476.          *  Hookup will add it to a list and hook it up later
  477.          *  when the site has really been added
  478.          */
  479.         if (m_pSiteManager->HookupSingleSiteByPlayToFrom(pSU,pProps, /*bIsPersistent*/ FALSE))
  480.         {
  481.             pSU->Release();
  482.         }
  483.     }
  484. #endif /* HELIX_FEATURE_VIDEO */
  485. }
  486. /************************************************************************
  487.  *  Method:
  488.  *      HXPlayer::SetupLayoutSiteGroup
  489.  */
  490. void
  491. HXPlayer::SetupLayoutSiteGroup(IUnknown* pLSG, BOOL bIsPersistent)
  492. {
  493. #if defined(HELIX_FEATURE_VIDEO)
  494.     HX_ASSERT(pLSG);
  495.     IHXSiteUserSupplier*   pSUS = NULL;
  496.     IHXSiteUser*           pSU = NULL;
  497.     if (HXR_OK == pLSG->QueryInterface(IID_IHXSiteUserSupplier,
  498.                             (void**)&pSUS))
  499.     {
  500.         IHXValues* pSUSProps = NULL;
  501.         BOOL releaseSUS = TRUE;
  502.         if (HXR_OK == pSUS->QueryInterface(IID_IHXValues,
  503.                                 (void**)&pSUSProps))
  504.         {
  505.             /*
  506.              * Ask the site manager if any sites are available
  507.              * for the LSG by this LSGName.
  508.              */
  509.             if (!m_pSiteManager->IsSiteAvailableByLSGName(pSUSProps,
  510.                 /*bIsPersistent*/ FALSE))
  511.             {
  512.                 if (m_pSiteSupplier)
  513.                 {
  514.                     /*
  515.                      * Let the site supplier know that we are changing the layout.
  516.                      */
  517.                     if (m_bBeginChangeLayoutTobeCalled)
  518.                     {
  519.                         m_bBeginChangeLayoutTobeCalled  = FALSE;
  520.                         m_pSiteSupplier->BeginChangeLayout();
  521.                     }
  522.                     /*
  523.                      * Inform the TLC/SS of the new sites we need.
  524.                      */
  525.                     ULONG32 uReqestID = (ULONG32)pSUS;
  526.                     m_pSiteSupplier->SitesNeeded(uReqestID,pSUSProps);
  527.                     DisableScreenSaver();
  528.                     m_SiteRequestIDList.AddTail((void*)uReqestID);
  529.                 }
  530.             }
  531.             /*
  532.              * We can now assume that the site supplier has added
  533.              * any sites for this set of properties to the site
  534.              * manager that it is willing to provide.
  535.              *
  536.              * Tell the site manager to hook up the site user to
  537.              * any sites with the same LSGName as the layoutSiteGroup.
  538.              *
  539.              * Hookup will also create child sites for the tuners,
  540.              * But these are added to the site manager with a flag
  541.              * which states how they can be used (for renderers only).
  542.              * Because we don't want to accidentally connect one of these
  543.              * tuner sites as a LSG.
  544.              */
  545.             /*  JEB: if the hookup failed, do not release the site user
  546.              *  Hookup will add it to a list and hook it up later
  547.              *  when the site has really been added
  548.              */
  549.             if (!m_pSiteManager->HookupByLSGName(pSUS,pSUSProps,/*bIsPersistent*/ FALSE))
  550.             {
  551.                 releaseSUS = FALSE;
  552.             }
  553.             pSUSProps->Release();
  554.         }
  555.         if (releaseSUS)
  556.         {
  557.             pSUS->Release();
  558.         }
  559.     }
  560.     // If the LSG doesn't support SiteUserSupplier, than see if it supports
  561.     // single instance as a SiteUser...
  562.     else if (HXR_OK == pLSG->QueryInterface(IID_IHXSiteUser,
  563.                             (void**)&pSU))
  564.     {
  565.         IHXValues* pSUProps = NULL;
  566.         BOOL releaseSU = TRUE;
  567.         if (HXR_OK == pSU->QueryInterface(IID_IHXValues,
  568.                                 (void**)&pSUProps))
  569.         {
  570.             /*
  571.              * Ask the site manager if any sites are available
  572.              * for the LSG by this LSGName.
  573.              */
  574.             if (!m_pSiteManager->IsSiteAvailableByLSGName(pSUProps,
  575.                 /*bIsPersistent*/ FALSE))
  576.             {
  577.                 if (m_pSiteSupplier)
  578.                 {
  579.                     /*
  580.                      * Let the site supplier know that we are changing the layout.
  581.                      */
  582.                     if (m_bBeginChangeLayoutTobeCalled)
  583.                     {
  584.                         m_bBeginChangeLayoutTobeCalled  = FALSE;
  585.                         m_pSiteSupplier->BeginChangeLayout();
  586.                     }
  587.                     /*
  588.                      * Inform the TLC/SS of the new sites we need.
  589.                      */
  590.                     ULONG32 uReqestID = (ULONG32)pSU;
  591.                     m_pSiteSupplier->SitesNeeded(uReqestID,pSUProps);
  592.                     DisableScreenSaver();
  593.                     m_SiteRequestIDList.AddTail((void*)uReqestID);
  594.                 }
  595.             }
  596.             /*
  597.              * We can now assume that the site supplier has added
  598.              * any sites for this set of properties to the site
  599.              * manager that it is willing to provide.
  600.              *
  601.              * Tell the site manager to hook up the site user to
  602.              * any sites with the same LSGName as the layoutSiteGroup.
  603.              *
  604.              * Hookup will also create child sites for the tuners,
  605.              * But these are added to the site manager with a flag
  606.              * which states how they can be used (for renderers only).
  607.              * Because we don't want to accidentally connect one of these
  608.              * tuner sites as a LSG.
  609.              */
  610.             /*  JEB: if the hookup failed, do not release the site user
  611.              *  Hookup will add it to a list and hook it up later
  612.              *  when the site has really been added
  613.              */
  614.             if (!m_pSiteManager->HookupSingleSiteByLSGName(pSU,pSUProps,/*bIsPersistent*/ FALSE))
  615.             {
  616.                 releaseSU = FALSE;
  617.             }
  618.             pSUProps->Release();
  619.         }
  620.         if (releaseSU)
  621.         {
  622.             pSU->Release();
  623.         }
  624.     }
  625. #endif /* HELIX_FEATURE_VIDEO */
  626. }
  627. /************************************************************************
  628.  *  Method:
  629.  *      HXPlayer::SetupLayout
  630.  *  Purpose:
  631.  *      shuts down old layout and sets up new layout. If bShowNewLayout
  632.  *      is FALSE then new layout is not set up.
  633.  */
  634. STDMETHODIMP
  635. HXPlayer::SetupLayout(BOOL bIsPersistent)
  636. {
  637.     CHXMapPtrToPtr::Iterator ndxSource = m_pSourceMap->Begin();
  638.     for (; ndxSource != m_pSourceMap->End(); ++ndxSource)
  639.     {
  640.         SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSource);
  641.         pSourceInfo->SetupRendererSites(bIsPersistent);
  642.     }
  643.     return HXR_OK;
  644. }
  645. /************************************************************************
  646.  *  Method:
  647.  *      HXPlayer::CleanupLayout
  648.  *  Purpose:
  649.  *      shuts down old layout
  650.  */
  651. STDMETHODIMP
  652. HXPlayer::CleanupLayout()
  653. {
  654.     /*
  655.      * For each Site/SiteUser combination unhook them because
  656.      * the layout is changing. You might think that this is
  657.      * only appropriate for associations by LSGName, but we do it
  658.      * for all because we want this implementation to work for
  659.      * empty-layouts as well.
  660.      *
  661.      * Note this also means to unhook any and all site/user
  662.      * combinations for child sites for each of these sites.
  663.      * This means that all layouts are released.
  664.      */
  665. #if defined(HELIX_FEATURE_VIDEO)
  666.     if (m_pSiteManager) m_pSiteManager->UnhookAll();
  667.     /*
  668.      * Run through all previous requested sites... Note:
  669.      * this is not the same as the list of layoutGroupSites
  670.      * since we don't request ones that were available when
  671.      * we set the layout.
  672.      */
  673.     CHXSimpleList::Iterator ndxRequest = m_SiteRequestIDList.Begin();
  674.     for (; ndxRequest != m_SiteRequestIDList.End(); ++ndxRequest)
  675.     {
  676.         ULONG32 requestID = (ULONG32)(*ndxRequest);
  677.         if (m_pSiteSupplier)
  678.         {
  679.             /*
  680.              * Let the site supplier know that we are changing the layout.
  681.              */
  682.             if (m_bBeginChangeLayoutTobeCalled)
  683.             {
  684.                 m_bBeginChangeLayoutTobeCalled  = FALSE;
  685.                 m_pSiteSupplier->BeginChangeLayout();
  686.             }
  687.             /*
  688.              * Inform the TLC/SS that we don't need old sites.
  689.              */
  690.             m_pSiteSupplier->SitesNotNeeded(requestID);
  691.         }
  692.     }
  693.     m_SiteRequestIDList.RemoveAll();
  694. #endif /* HELIX_FEATURE_VIDEO */
  695.     return HXR_OK;
  696. }
  697. void
  698. HXPlayer::InternalPause()
  699. {
  700.     if (!m_bIsFirstBegin && !m_bBeginPending && !m_bTimelineToBeResumed)
  701.     {
  702.         m_bIsPlaying = FALSE;
  703.         m_bTimelineToBeResumed = TRUE;
  704.         m_pAudioPlayer->Pause();
  705. //      DEBUG_OUT(this, (s,
  706. //          "Pause Timeline %p", this));
  707.     }
  708. }
  709. /*
  710.  *  IHXGroupSink methods
  711.  */
  712. /************************************************************************
  713. *  Method:
  714. *      IHXGroupSink::GroupAdded
  715. *  Purpose:
  716. *               Notification of a new group being added to the presentation.
  717. */
  718. STDMETHODIMP
  719. HXPlayer::GroupAdded(UINT16         /*IN*/ uGroupIndex,
  720.                       IHXGroup*    /*IN*/ pGroup)
  721. {
  722. #if defined(HELIX_FEATURE_BASICGROUPMGR)
  723.     m_nGroupCount++;
  724.     if (m_nCurrentGroup == m_pGroupManager->GetGroupCount() - 1)
  725.     {
  726.         m_bLastGroup = TRUE;
  727.     }
  728.     else
  729.     {
  730.         m_bLastGroup = FALSE;
  731.     }
  732. #endif /* HELIX_FEATURE_BASICGROUPMGR */
  733.     return HXR_OK;
  734. }
  735. /************************************************************************
  736. *  Method:
  737. *      IHXGroupSink::GroupRemoved
  738. *  Purpose:
  739. *               Notification of a group being removed from the presentation.
  740. */
  741. STDMETHODIMP
  742. HXPlayer::GroupRemoved(UINT16       /*IN*/ uGroupIndex,
  743.                         IHXGroup*  /*IN*/ pGroup)
  744. {
  745. #if defined(HELIX_FEATURE_BASICGROUPMGR)
  746.     if (m_nGroupCount > 0)
  747.         m_nGroupCount--;
  748.     UINT16 uNumGroups = m_pGroupManager->GetGroupCount();
  749.     if (uNumGroups == 0 ||
  750.         m_nCurrentGroup == uNumGroups - 1)
  751.     {
  752.         m_bLastGroup = TRUE;
  753.     }
  754.     else
  755.     {
  756.         m_bLastGroup = FALSE;
  757.     }
  758.     return HXR_OK;
  759. #else
  760.     return HXR_NOTIMPL;
  761. #endif /* HELIX_FEATURE_BASICGROUPMGR */
  762. }
  763. /************************************************************************
  764. *  Method:
  765. *      IHXGroupSink::AllGroupsRemoved
  766. *  Purpose:
  767. *               Notification that all groups have been removed from the
  768. *               current presentation.
  769. */
  770. STDMETHODIMP
  771. HXPlayer::AllGroupsRemoved(void)
  772. {
  773.     HX_RELEASE(m_pCurrentGroup);
  774.     return HXR_OK;
  775. }
  776. /************************************************************************
  777. *  Method:
  778. *      IHXGroupSink::TrackAdded
  779. *  Purpose:
  780. *               Notification of a new track being added to a group.
  781. */
  782. STDMETHODIMP
  783. HXPlayer::TrackAdded(UINT16         /*IN*/ uGroupIndex,
  784.                       UINT16        /*IN*/ uTrackIndex,
  785.                       IHXValues*   /*IN*/ pTrack)
  786. {
  787. #if defined(HELIX_FEATURE_BASICGROUPMGR)
  788.     HX_RESULT       theErr = HXR_OK;
  789.     UINT16          uPrefetchSourceIndex = 0;
  790.     char            szDelay[] = "Delay";
  791.     UINT32          ulDelay = 0;
  792.     SourceInfo*     pSourceInfo = NULL;
  793.     IHXGroup*       pThisGroup = NULL;
  794.     IHXPrefetch*   pPrefetch = NULL;
  795.     m_pGroupManager->GetGroup(uGroupIndex, pThisGroup);
  796.     /* Check if a track is added to the group currently played */
  797.     if (uGroupIndex == m_nCurrentGroup &&
  798.         m_pCurrentGroup == pThisGroup)
  799.     {
  800. #if defined(HELIX_FEATURE_PREFETCH)
  801.         // determine whether the track has been prefetched
  802.         if (m_pPrefetchManager &&
  803.             m_pPrefetchManager->Lookup(pTrack, pSourceInfo))
  804.         {
  805.             pSourceInfo->m_pSource->PartOfPrefetchGroup(FALSE);
  806.             if (HXR_OK == m_pCurrentGroup->QueryInterface(IID_IHXPrefetch,
  807.                                                           (void**)&pPrefetch))
  808.             {
  809.                 theErr = pPrefetch->RemovePrefetchTrack(pSourceInfo->m_uTrackID);
  810.             }
  811.             HX_RELEASE(pPrefetch);
  812.             pSourceInfo->m_uGroupID = uGroupIndex;
  813.             pSourceInfo->m_uTrackID = uTrackIndex;
  814.             PrepareSourceInfo(pTrack, pSourceInfo);
  815.             pSourceInfo->m_pSource->UpdatePlayTimes(pTrack);
  816.             m_pSourceMap->SetAt((void*)pSourceInfo->m_pSource,
  817.                               (void*)pSourceInfo);
  818.             m_bPlayerWithoutSources = FALSE;
  819.             m_bSourceMapUpdated = TRUE;
  820.             m_bForceStatsUpdate = TRUE;
  821.             m_uNumSourcesActive++;
  822.             m_uNumCurrentSourceNotDone++;
  823.             AdjustPresentationTime();
  824.             InternalPause();
  825.         }
  826.         /* If we are not yet initialized, add tracks to the current source
  827.          * map only if the track is within the fudge factor.
  828.          *
  829.          * This is to fix a bug in SMIL file with multiple sources in seq
  830.          * with outer par.
  831.          * The expected behavior is to start the first source
  832.          * in seq and then initialize the remaining sources. Since we were
  833.          * adding additional tracks to the source map, the player was not
  834.          * getting initialized until ALL the sources in the seq have been
  835.          * initialized. This resulted in massive startup delays.
  836.          */
  837.     else if (!m_bInitialized)
  838. #else
  839.         if (!m_bInitialized)
  840. #endif
  841.         {
  842.             if ((HXR_OK != pTrack->GetPropertyULONG32(szDelay,ulDelay)) ||
  843.                 (ulDelay <= m_ulCurrentPlayTime + MIN_DELAYBEFORE_START))
  844.             {
  845.                 theErr = OpenTrack(pTrack, uGroupIndex, uTrackIndex);
  846.             }
  847.             else
  848.             {
  849.                 if (!m_pPendingTrackList)
  850.                 {
  851.                     m_pPendingTrackList = new CHXSimpleList;
  852.                 }
  853.                 PendingTrackInfo* pPendingTrackInfo =
  854.                     new PendingTrackInfo(uGroupIndex, uTrackIndex, pTrack);
  855.                 m_pPendingTrackList->AddTail(pPendingTrackInfo);
  856.             }
  857.         }
  858.         else
  859.         {
  860.             theErr = OpenTrack(pTrack, uGroupIndex, uTrackIndex);
  861.         }
  862.         if (theErr)
  863.         {
  864.             ReportError(NULL, theErr, NULL);
  865.         }
  866.     }
  867.     /* Check if a track is added to the group that is being prefetch */
  868.     else
  869.     {
  870. #if defined(HELIX_FEATURE_NEXTGROUPMGR)
  871.         IHXGroup* pGroup        = NULL;
  872.         UINT16 uCurrentGroup    = 0;
  873.         if (m_bNextGroupStarted &&
  874.             (m_pNextGroupManager->GetCurrentGroup(uCurrentGroup, pGroup)
  875.                                                 == HXR_OK) &&
  876.             uCurrentGroup == uGroupIndex &&
  877.             pGroup == pThisGroup)
  878.         {
  879.             m_bPartOfNextGroup = TRUE;
  880.             theErr = OpenTrack(pTrack, uGroupIndex, uTrackIndex);
  881.             if (theErr)
  882.             {
  883.                 ReportError(NULL, theErr, NULL);
  884.             }
  885.             m_bPartOfNextGroup = FALSE;
  886.         }
  887.         HX_RELEASE(pGroup);
  888. #endif /* HELIX_FEATURE_NEXTGROUPMGR */
  889.     }
  890.     HX_RELEASE(pThisGroup);
  891.     return HXR_OK;
  892. #else
  893.     return HXR_NOTIMPL;
  894. #endif /* HELIX_FEATURE_BASICGROUPMGR */
  895. }
  896. HX_RESULT
  897. HXPlayer::RepeatTrackAdded(UINT16       /*IN*/ uGroupIndex,
  898.                             UINT16      /*IN*/ uTrackIndex,
  899.                             IHXValues*  /*IN*/ pTrack)
  900. {
  901. #if defined(HELIX_FEATURE_ADVANCEDGROUPMGR) && defined(HELIX_FEATURE_SMIL_REPEAT)
  902.     HX_RESULT           theErr = HXR_OK;
  903.     UINT16              uCurrentGroup   = 0;
  904.     SourceInfo*         pSourceInfo = NULL;
  905.     IHXGroup*           pGroup  = NULL;
  906.     IHXGroup*           pThisGroup = NULL;
  907.     m_pGroupManager->GetGroup(uGroupIndex, pThisGroup);
  908.     if (HXR_OK == GetSourceInfo(uGroupIndex, uTrackIndex, pSourceInfo))
  909.     {
  910.         theErr = pSourceInfo->AppendRepeatRequest(uTrackIndex, pTrack);
  911.         AdjustPresentationTime();
  912.     }
  913. #if defined(HELIX_FEATURE_NEXTGROUPMGR)
  914.     else if (m_bNextGroupStarted &&
  915.              (m_pNextGroupManager->GetCurrentGroup(uCurrentGroup, pGroup) == HXR_OK) &&
  916.              uCurrentGroup == uGroupIndex &&
  917.              pGroup == pThisGroup)
  918.     {
  919.         m_pNextGroupManager->AddRepeatTrack(uTrackIndex, pTrack);
  920.     }
  921. #endif /* HELIX_FEATURE_NEXTGROUPMGR */
  922.     else
  923.     {
  924.         // XXX HP something is wrong!!
  925.         HX_ASSERT(FALSE);
  926.     }
  927.     HX_RELEASE(pGroup);
  928.     HX_RELEASE(pThisGroup);
  929.     return theErr;
  930. #else
  931.     return HXR_NOTIMPL;
  932. #endif /* HELIX_FEATURE_ADVANCEDGROUPMGR && HELIX_FEATURE_SMIL_REPEAT */
  933. }
  934. /************************************************************************
  935. *  Method:
  936. *      IHXGroupSink::TrackRemoved
  937. *  Purpose:
  938. *               Notification of a track being removed from a group.
  939. */
  940. STDMETHODIMP
  941. HXPlayer::TrackRemoved(UINT16           /*IN*/ uGroupIndex,
  942.                         UINT16          /*IN*/ uTrackIndex,
  943.                         IHXValues*      /*IN*/ pTrack)
  944. {
  945.     return HXR_OK;
  946. }
  947. /************************************************************************
  948. *  Method:
  949. *      IHXGroupSink::TrackStarted
  950. *  Purpose:
  951. *               Notification of a track being started in a group.
  952. */
  953. STDMETHODIMP
  954. HXPlayer::TrackStarted(UINT16           /*IN*/ uGroupIndex,
  955.                         UINT16          /*IN*/ uTrackIndex,
  956.                         IHXValues*      /*IN*/ pTrack)
  957. {
  958.     return HXR_OK;
  959. }
  960. /************************************************************************
  961. *  Method:
  962. *      IHXGroupSink::TrackStopped
  963. *  Purpose:
  964. *               Notification of a track being stopped in a group.
  965. */
  966. STDMETHODIMP
  967. HXPlayer::TrackStopped(UINT16           /*IN*/ uGroupIndex,
  968.                         UINT16          /*IN*/ uTrackIndex,
  969.                         IHXValues*      /*IN*/ pTrack)
  970. {
  971.     return HXR_OK;
  972. }
  973. /************************************************************************
  974. *  Method:
  975. *      IHXGroupSink::CurrentGroupSet
  976. *  Purpose:
  977. *               This group is being currently played in the presentation.
  978. */
  979. STDMETHODIMP
  980. HXPlayer::CurrentGroupSet(UINT16        /*IN*/ uGroupIndex,
  981.                            IHXGroup*   /*IN*/ pGroup)
  982. {
  983. #if defined(HELIX_FEATURE_BASICGROUPMGR)
  984.     HX_RESULT theErr = HXR_OK;
  985.     m_bCoreLocked = TRUE;
  986.     m_pCoreMutex->Lock();
  987.     /* If we called SetCurrentGroup, ignore this callback */
  988.     m_bIsPresentationClosedToBeSent = FALSE;
  989.     StopAllStreams(END_STOP);
  990.     m_bIsPresentationClosedToBeSent = TRUE;
  991.     ResetGroup();
  992.     m_bInitialized      = FALSE;
  993.     m_bIsDone           = FALSE;
  994.     m_ulActiveSureStreamSource = 0;
  995.     m_bFastStartCheckDone = FALSE;
  996.     m_turboPlayOffReason = TP_OFF_BY_UNKNOWN;
  997.     // uGroupIndex is needed to determine whether destroy the root layout
  998.     // during group switching under nested meta support
  999.     // uGroupIndex is used by IHXPersistentComponentManager::CloseAllRenderers()
  1000.     // which is called in CloseAllRenderers()
  1001.     CloseAllRenderers(uGroupIndex);
  1002.     /* Open this group here */
  1003.     /* Ask the next group manager for this group */
  1004.     UINT16 uCurrentGroup = 0;
  1005.     IHXGroup* pCurGroup = NULL;
  1006. #if defined(HELIX_FEATURE_NEXTGROUPMGR)
  1007.     if (m_pNextGroupManager->GetCurrentGroup(uCurrentGroup, pCurGroup) == HXR_OK &&
  1008.         uCurrentGroup == uGroupIndex && pCurGroup == pGroup)
  1009.     {
  1010.         SourceInfo*     pSourceInfo = NULL;
  1011.         UINT16 uNumSources = m_pNextGroupManager->GetNumSources();
  1012.         for (UINT16 i = 0; i < uNumSources; i++)
  1013.         {
  1014.             m_pNextGroupManager->GetSource(i, pSourceInfo);
  1015.             if (pSourceInfo->m_pSource)
  1016.             {
  1017.                 m_pSourceMap->SetAt((void*) pSourceInfo->m_pSource,
  1018.                                   (void*) pSourceInfo);
  1019.                 m_bPlayerWithoutSources = FALSE;
  1020.                 m_bSourceMapUpdated = TRUE;
  1021.                 pSourceInfo->m_pSource->PartOfNextGroup(FALSE);
  1022.                 if (pSourceInfo->m_bTobeInitializedBeforeBegin)
  1023.                 {
  1024.                     m_uNumSourceToBeInitializedBeforeBegin++;
  1025.                 }
  1026.                 // update the registries (from NextGroup.* to Player.*)
  1027.                 UpdateSourceInfo(pSourceInfo,
  1028. #if defined(HELIX_FEATURE_STATS) && defined(HELIX_FEATURE_REGISTRY)
  1029.                                  m_pStats->m_ulRegistryID,
  1030. #else
  1031.                                  NULL,
  1032. #endif /* HELIX_FEATURE_STATS && HELIX_FEATURE_REGISTRY */
  1033.                                  pSourceInfo->m_uTrackID);
  1034.             }
  1035.         }
  1036.         m_pNextGroupManager->RemoveAllSources();
  1037.         const char* pErrorString = NULL;
  1038.         HXSource* pSource        = NULL;
  1039.         theErr = m_pNextGroupManager->GetLastError(pSource, pErrorString);
  1040.         if (theErr)
  1041.         {
  1042.             SetLastError(theErr);
  1043.         }
  1044.         if (m_LastError != HXR_OK)
  1045.         {
  1046.             m_bIsDone = TRUE;
  1047.             ReportError(pSource, m_LastError, pErrorString);
  1048.         }
  1049.         else
  1050.         {
  1051.             m_nCurrentGroup = uGroupIndex;
  1052.         }
  1053.         m_pNextGroupManager->Cleanup();
  1054.         /* Get the duration from group properties */
  1055.         UINT32 ulGroupDuration = 0;
  1056.         IHXValues* pGroupProps = pGroup->GetGroupProperties();
  1057.         if (pGroupProps &&
  1058.             pGroupProps->GetPropertyULONG32("Duration", ulGroupDuration)
  1059.                                                                 == HXR_OK)
  1060.         {
  1061.             m_ulPresentationDuration = ulGroupDuration;
  1062.         }
  1063.         HX_RELEASE(pGroupProps);
  1064.         m_bIsPresentationClosedToBeSent = FALSE;
  1065.     }
  1066.     else
  1067. #endif /* HELIX_FEATURE_NEXTGROUPMGR */
  1068.     {
  1069. #if defined(HELIX_FEATURE_NEXTGROUPMGR)
  1070.         /* Cleanup any next group that we may have started downloading */
  1071.         m_pNextGroupManager->Cleanup();
  1072. #endif /* HELIX_FEATURE_NEXTGROUPMGR */
  1073.         m_nCurrentGroup = uGroupIndex;
  1074.         theErr = DoOpenGroup(uGroupIndex);
  1075.     }
  1076.     if (uGroupIndex == (m_pGroupManager->GetGroupCount() - 1))
  1077.     {
  1078.         m_bLastGroup = TRUE;
  1079.     }
  1080.     else
  1081.     {
  1082.         m_bLastGroup = FALSE;
  1083.     }
  1084.     m_pCurrentGroup = pGroup;
  1085.     m_pCurrentGroup->AddRef();
  1086.     m_bNextGroupStarted = FALSE;
  1087.     HX_RELEASE(pCurGroup);
  1088.     if (!theErr && !m_LastError && m_bUserHasCalledBegin)
  1089.     {
  1090.         Begin();
  1091.     }
  1092.     SchedulePlayer();
  1093.     if (theErr)
  1094.     {
  1095.         ReportError(NULL, theErr, NULL);
  1096.     }
  1097.     m_pCoreMutex->Unlock();
  1098.     m_bCoreLocked = FALSE;
  1099.     return HXR_OK;
  1100. #else
  1101.     return HXR_NOTIMPL;
  1102. #endif /* HELIX_FEATURE_BASICGROUPMGR */
  1103. }
  1104. /************************************************************************
  1105. *  Method:
  1106. *      IHXGroupSink::CurrentGroupSet
  1107. *  Purpose:
  1108. *               This group is set to be played next in the presentation.
  1109. */
  1110. HX_RESULT
  1111. HXPlayer::NextGroupSet(UINT16   /*IN*/ uGroupIndex)
  1112. {
  1113. #if defined(HELIX_FEATURE_NEXTGROUPMGR)
  1114.     /* Ask the next group manager for this group */
  1115.     UINT16 uCurrentGroup = 0;
  1116.     IHXGroup* pCurGroup = NULL;
  1117.     if (m_pNextGroupManager && m_pNextGroupManager->GetCurrentGroup(uCurrentGroup,
  1118.         pCurGroup) == HXR_OK)
  1119.     {
  1120.         // the next group being set is already the next group, so don't do anything
  1121.         if (uCurrentGroup == uGroupIndex)
  1122.         {
  1123.             return HXR_OK;
  1124.         }
  1125.         /* Cleanup any next group that we may have started downloading */
  1126.         m_pNextGroupManager->Cleanup();
  1127.         m_bNextGroupStarted     = FALSE;
  1128.     }
  1129.     return HXR_OK;
  1130. #else
  1131.     return HXR_NOTIMPL;
  1132. #endif /* HELIX_FEATURE_NEXTGROUPMGR */
  1133. }
  1134. /************************************************************************
  1135. *   Method:
  1136. *       IHXRendererUpgrade::IsRendererAvailable
  1137. *   Purpose:
  1138. *       See if a renderer with this mime type has been loaded
  1139. */
  1140. STDMETHODIMP_(BOOL)
  1141. HXPlayer::IsRendererAvailable(const char* pMimeType)
  1142. {
  1143.     BOOL bAvailable = FALSE;
  1144. #if defined(HELIX_FEATURE_AUTOUPGRADE)
  1145.     // create an upgrade collection
  1146.     HXUpgradeCollection* pCheckComponent = new HXUpgradeCollection;
  1147.     if (pCheckComponent)
  1148.     {
  1149.         pCheckComponent->AddRef();
  1150.         CHXBuffer* pBuffer = new CHXBuffer;
  1151.         pBuffer->AddRef();
  1152.         pBuffer->Set((BYTE*)pMimeType, strlen(pMimeType)+1);
  1153.         // add the component to the list
  1154.         pCheckComponent->Add(eUT_Required, pBuffer, 0, 0);
  1155.         HX_RELEASE(pBuffer);
  1156.         // Request the upgrade handler
  1157.         IHXUpgradeHandler* pUpgradeHandler = NULL;
  1158.         if(m_pClient &&
  1159.             m_pClient->QueryInterface(IID_IHXUpgradeHandler, (void**)&pUpgradeHandler) == HXR_OK)
  1160.         {
  1161.             // now see if the upgrade handler already has this component
  1162.             if(pUpgradeHandler->HasComponents(pCheckComponent) == HXR_OK)
  1163.             {
  1164.                 bAvailable = TRUE;
  1165.             }
  1166.             HX_RELEASE(pUpgradeHandler);
  1167.         }
  1168.     }
  1169.     HX_RELEASE(pCheckComponent);
  1170. #endif /* HELIX_FEATURE_AUTOUPGRADE */
  1171.     // return component availability
  1172.     return(bAvailable);
  1173. }
  1174. /************************************************************************
  1175. *   Method:
  1176. *       IHXRendererUpgrade::ForceUpgrade
  1177. *   Purpose:
  1178. *       Use the force to upgrade all renderers
  1179. */
  1180. STDMETHODIMP
  1181. HXPlayer::ForceUpgrade()
  1182. {
  1183.     return HXR_UNEXPECTED;
  1184. }
  1185. /************************************************************************
  1186. *  Method:
  1187. *      IHXLayoutSiteGroupManager::AddLayoutSiteGroup
  1188. *  Purpose:
  1189. *               Add LSG to the presentation.
  1190. */
  1191. STDMETHODIMP
  1192. HXPlayer::AddLayoutSiteGroup(IUnknown*  /*IN*/ pLSG)
  1193. {
  1194. #if defined(HELIX_FEATURE_VIDEO)
  1195.     m_bAddLayoutSiteGroupCalled = TRUE;
  1196.     SetupLayoutSiteGroup(pLSG, TRUE);
  1197.     return HXR_OK;
  1198. #else
  1199.     return HXR_NOTIMPL;
  1200. #endif /* HELIX_FEATURE_VIDEO */
  1201. }
  1202. /************************************************************************
  1203. *  Method:
  1204. *      IHXLayoutSiteGroupManager::RemoveLayoutSiteGroup
  1205. *  Purpose:
  1206. *               Remove LSG from the presentation.
  1207. */
  1208. STDMETHODIMP
  1209. HXPlayer::RemoveLayoutSiteGroup(IUnknown* pLSG)
  1210. {
  1211. #if defined(HELIX_FEATURE_PLAYERNAVIGATOR)
  1212.     HX_ASSERT(pLSG);
  1213.     IHXSiteUserSupplier*   pSUS = NULL;
  1214.     IHXSiteUser*           pSU = NULL;
  1215.     BOOL                    bIsPersistent = TRUE;   // assume called by a persistent renderer
  1216.     if (HXR_OK == pLSG->QueryInterface(IID_IHXSiteUserSupplier,
  1217.                             (void**)&pSUS))
  1218.     {
  1219.         IHXValues* pSUSProps = NULL;
  1220.         BOOL releaseSUS = TRUE;
  1221.         if (HXR_OK == pSUS->QueryInterface(IID_IHXValues,
  1222.                                 (void**)&pSUSProps))
  1223.         {
  1224. #if defined(HELIX_FEATURE_VIDEO)
  1225.             m_pSiteManager->RemoveSitesByLSGName(pSUSProps, /*bIsPersistent*/ FALSE);
  1226.             //m_pSiteManager->UnhookByLSGName(pSUS, pSUSProps, bIsPersistent);
  1227. #endif //HELIX_FEATURE_VIDEO
  1228.             pSUSProps->Release();
  1229.         }
  1230.         pSUS->Release();
  1231.     }
  1232.     // If the LSG doesn't support SiteUserSupplier, than see if it supports
  1233.     // single instance as a SiteUser...
  1234.     else if (HXR_OK == pLSG->QueryInterface(IID_IHXSiteUser,
  1235.                             (void**)&pSU))
  1236.     {
  1237.         IHXValues* pSUProps = NULL;
  1238.         if (HXR_OK == pSU->QueryInterface(IID_IHXValues,
  1239.                                 (void**)&pSUProps))
  1240.         {
  1241. #if defined(HELIX_FEATURE_VIDEO)
  1242.             m_pSiteManager->RemoveSitesByLSGName(pSUProps, /*bIsPersistent*/ FALSE);
  1243.             // m_pSiteManager->UnhookByLSGName(pSU, pSUProps, bIsPersistent);
  1244. #endif //HELIX_FEATURE_VIDEO
  1245.             pSUProps->Release();
  1246.         }
  1247.         pSU->Release();
  1248.     }
  1249.     m_bAddLayoutSiteGroupCalled = FALSE;
  1250.     return HXR_OK;
  1251. #else
  1252.     return HXR_NOTIMPL;
  1253. #endif /* HELIX_FEATURE_VIDEO */
  1254. }
  1255. /*
  1256.  * IHXInternalReset method
  1257.  */
  1258. STDMETHODIMP
  1259. HXPlayer::InternalReset(void)
  1260. {
  1261.     m_bCoreLocked = TRUE;
  1262.     m_pCoreMutex->Lock();
  1263.     m_bInternalReset = TRUE;
  1264.     PausePlayer();
  1265.     BeginPlayer();
  1266.     m_bInternalReset = FALSE;
  1267.     m_pCoreMutex->Unlock();
  1268.     m_bCoreLocked = FALSE;
  1269.     return HXR_OK;
  1270. }
  1271. void
  1272. HXPlayer::CheckToStartNextGroup(void)
  1273. {
  1274.     if (m_bLastGroup)
  1275.     {
  1276.         return;
  1277.     }
  1278. #if defined(HELIX_FEATURE_BASICGROUPMGR)
  1279.     if (m_pGroupManager->GetGroupCount() <= 1)
  1280.     {
  1281.         m_bLastGroup = TRUE;
  1282.         return;
  1283.     }
  1284. #if defined(HELIX_FEATURE_NEXTGROUPMGR)
  1285.     /* If all sources have ended, start downloading the next group */
  1286.     if (m_uNumCurrentSourceNotDone == 0)
  1287.     {
  1288.         /* Resume prefetching if the next group already has sources */
  1289.         if (m_pNextGroupManager->GetNumSources() > 0)
  1290.         {
  1291.             UnRegisterCurrentSources();
  1292.             m_pNextGroupManager->ContinuePreFetch();
  1293.             m_bNextGroupStarted = TRUE;
  1294.             return;
  1295.         }
  1296.         if (m_nCurrentGroup < (m_pGroupManager->GetGroupCount() - 1))
  1297.         {
  1298.             IHXGroup* pGroup = NULL;
  1299.             UINT16 uNextGroup = 0;
  1300.             m_pGroupManager->GetNextGroup(uNextGroup);
  1301.             HX_RESULT theErr = m_pGroupManager->GetGroup(uNextGroup, pGroup);
  1302.             if (!theErr)
  1303.             {
  1304.                 m_pNextGroupManager->SetCurrentGroup(uNextGroup, pGroup);
  1305.                 HX_RELEASE(pGroup);
  1306.                 UnRegisterCurrentSources();
  1307.                 m_bPartOfNextGroup = TRUE;
  1308.                 theErr = DoOpenGroup(uNextGroup);
  1309.                 m_bPartOfNextGroup = FALSE;
  1310.                 m_bNextGroupStarted     = TRUE;
  1311.                 DEBUG_OUT(this, DOL_TRANSPORT, (s,"Next Group is prefetched: %lu", uNextGroup));
  1312.                 if (theErr)
  1313.                 {
  1314.                     m_pNextGroupManager->SetLastError(theErr);
  1315.                 }
  1316.             }
  1317.         }
  1318.     }
  1319. #endif /* HELIX_FEATURE_NEXTGROUPMGR */
  1320. #endif /* HELIX_FEATURE_BASICGROUPMGR */
  1321. }
  1322. void
  1323. HXPlayer::AdjustPresentationTime(void)
  1324. {
  1325.     UINT32 ulSourceDuration = 0;
  1326.     // reset presentation duration
  1327.     m_ulPresentationDuration = 0;
  1328.     CHXMapPtrToPtr::Iterator ndxSource = m_pSourceMap->Begin();
  1329.     for (; ndxSource != m_pSourceMap->End(); ++ndxSource)
  1330.     {
  1331.         SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSource);
  1332.         // get duration after the source has been initialized
  1333.         // to ensure HXSource::AdjustClipTime() was called
  1334.         if (pSourceInfo->m_pSource->IsInitialized())
  1335.         {
  1336.             ulSourceDuration = pSourceInfo->GetActiveDuration();
  1337.             m_ulPresentationDuration = max(m_ulPresentationDuration,
  1338.                                            ulSourceDuration);
  1339.         }
  1340.     }
  1341. #if defined(HELIX_FEATURE_BASICGROUPMGR)
  1342.     // presentation duration is also restrained by its group duration
  1343.     // if it exists
  1344.     IHXGroup*   pGroup = NULL;
  1345.     if (HXR_OK == m_pGroupManager->GetGroup((UINT16)m_nCurrentGroup, pGroup))
  1346.     {
  1347.         /* Get the duration from group properties */
  1348.         UINT32 ulGroupDuration = 0;
  1349.         IHXValues* pGroupProps = pGroup->GetGroupProperties();
  1350.         if (pGroupProps &&
  1351.             HXR_OK == pGroupProps->GetPropertyULONG32("Duration", ulGroupDuration))
  1352.         {
  1353.             m_ulPresentationDuration = ulGroupDuration;
  1354.         }
  1355.         HX_RELEASE(pGroupProps);
  1356.     }
  1357.     HX_RELEASE(pGroup);
  1358. #endif /* HELIX_FEATURE_BASICGROUPMGR */
  1359.     if (m_pAdviseSink)
  1360.     {
  1361.         m_pAdviseSink->OnPosLength(m_ulCurrentPlayTime, m_ulPresentationDuration);
  1362.     }
  1363.     return;
  1364. }
  1365. void
  1366. HXPlayer::SetPresentationTime(UINT32 ulPresentationTime)
  1367. {
  1368.     m_ulPresentationDuration = ulPresentationTime;
  1369.     if (m_pAdviseSink)
  1370.     {
  1371.         m_pAdviseSink->OnPosLength(m_ulCurrentPlayTime, m_ulPresentationDuration);
  1372.     }
  1373. }
  1374. void
  1375. HXPlayer::UpdateSourceActive(void)
  1376. {
  1377.     m_uNumSourcesActive = 0;
  1378.     CHXMapPtrToPtr::Iterator ndxSources = m_pSourceMap->Begin();
  1379.     for (; ndxSources != m_pSourceMap->End(); ++ndxSources)
  1380.     {
  1381.         SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSources);
  1382.         if (pSourceInfo->m_bActive)
  1383.         {
  1384.             m_uNumSourcesActive++;
  1385.         }
  1386.     }
  1387.     m_uNumCurrentSourceNotDone = m_uNumSourcesActive;
  1388. }
  1389. HX_RESULT
  1390. HXPlayer::UpdateSourceInfo(SourceInfo* pSourceInfo,
  1391.                             UINT32 ulParentRegId,
  1392.                             UINT16 ulTrackIndex)
  1393. {
  1394.     HX_RESULT   rc = HXR_OK;
  1395.     UINT32      ulRegId = 0;
  1396.     IHXBuffer*  pParentName = NULL;
  1397. #if defined(HELIX_FEATURE_STATS) && defined(HELIX_FEATURE_REGISTRY)
  1398.     // update sourc/stream stats' registry
  1399.     if (m_pRegistry && m_pStats &&
  1400.         HXR_OK == m_pRegistry->GetPropName(ulParentRegId, pParentName))
  1401.     {
  1402.         char        szRegName[MAX_DISPLAY_NAME] = {0}; /* Flawfinder: ignore */
  1403.         SafeSprintf(szRegName, MAX_DISPLAY_NAME, "%s.Source%ld", pParentName->GetBuffer(), ulTrackIndex);
  1404.         // delete this registry if it exists
  1405.         ulRegId = m_pRegistry->GetId(szRegName);
  1406.         if (ulRegId)
  1407.         {
  1408.             m_pRegistry->DeleteById(ulRegId);
  1409.         }
  1410.         // create/update registry
  1411.         ulRegId = m_pRegistry->AddComp(szRegName);
  1412.         pSourceInfo->m_pSource->UpdateRegistry(ulRegId);
  1413. #endif /* HELIX_FEATURE_STATS && HELIX_FEATURE_REGISTRY */
  1414.         pSourceInfo->m_uTrackID = ulTrackIndex;
  1415. #if defined(HELIX_FEATURE_STATS) && defined(HELIX_FEATURE_REGISTRY)
  1416.     }
  1417.     HX_RELEASE(pParentName);
  1418.     // update renderer stats registry
  1419.     pSourceInfo->ReInitializeStats();
  1420. #endif /* HELIX_FEATURE_STATS && HELIX_FEATURE_REGISTRY */
  1421.     return rc;
  1422. }
  1423. HX_RESULT
  1424. HXPlayer::UpdatePersistentSrcInfo(SourceInfo* pSourceInfo,
  1425.                                   UINT32 ulParentRegId,
  1426.                                   UINT16 ulTrackIndex)
  1427. {
  1428.     HX_RESULT   rc = HXR_OK;
  1429.     UINT32      ulRegId = 0;
  1430.     IHXBuffer*  pParentName = NULL;
  1431. #if defined(HELIX_FEATURE_REGISTRY)
  1432.     char        szRegName[MAX_DISPLAY_NAME] = {0}; /* Flawfinder: ignore */
  1433.     // update sourc/stream stats' registry
  1434.     if (m_pRegistry && m_pStats &&
  1435.         HXR_OK == m_pRegistry->GetPropName(ulParentRegId, pParentName))
  1436.     {
  1437.         SafeSprintf(szRegName, MAX_DISPLAY_NAME, "%s.Source%u",
  1438.                 pParentName->GetBuffer(), ulTrackIndex);
  1439.         // delete this registry if it exists
  1440.         ulRegId = m_pRegistry->GetId(szRegName);
  1441.         if (ulRegId)
  1442.         {
  1443.             m_pRegistry->DeleteById(ulRegId);
  1444.         }
  1445.         //Create a new one.
  1446.         SafeSprintf(szRegName, MAX_DISPLAY_NAME, "%s.Persistent%u", pParentName->GetBuffer(),
  1447.                 pSourceInfo->m_ulPersistentComponentSelfID);
  1448.         // create/update registry
  1449.         ulRegId = m_pRegistry->GetId(szRegName);
  1450.         if( !ulRegId )
  1451.         {
  1452.             ulRegId = m_pRegistry->AddComp(szRegName);
  1453.         }
  1454.         pSourceInfo->m_pSource->UpdateRegistry(ulRegId);
  1455.         pSourceInfo->m_uTrackID = ulTrackIndex;
  1456.     }
  1457. #endif
  1458.     HX_RELEASE(pParentName);
  1459.     // update renderer stats registry
  1460.     pSourceInfo->ReInitializeStats();
  1461.     return rc;
  1462. }
  1463. HX_RESULT
  1464. HXPlayer::SetupAllStreams(void)
  1465. {
  1466.     HX_RESULT theErr = HXR_OK;
  1467.     CHXMapPtrToPtr::Iterator ndxSources = m_pSourceMap->Begin();
  1468.     /* Check if we are done. This may be TRUE for empty files */
  1469.     for (; !theErr && ndxSources != m_pSourceMap->End(); ++ndxSources)
  1470.     {
  1471.         SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSources);
  1472.         theErr = pSourceInfo->SetupStreams();
  1473.     }
  1474.     return theErr;
  1475. }
  1476. void
  1477. HXPlayer::EnterToBeginList(RendererInfo* pRendInfo)
  1478. {
  1479.     if (m_ToBeginRendererList.IsEmpty())
  1480.     {
  1481.         m_ToBeginRendererList.AddHead(pRendInfo);
  1482.         return;
  1483.     }
  1484.     RendererInfo*   pTmpRendInfo        = NULL;
  1485.     BOOL            earlierPacketFound  = FALSE;
  1486.     UINT32 startPos = pRendInfo->m_pStreamInfo->m_ulDelay;
  1487.     LISTPOSITION    position = m_ToBeginRendererList.GetTailPosition();
  1488.     while (position != NULL && !earlierPacketFound)
  1489.     {
  1490.         pTmpRendInfo =
  1491.             (RendererInfo*) m_ToBeginRendererList.GetPrev(position);
  1492.         // If this event is less than or equal to the timestamp
  1493.         // then this things are looking ok...
  1494.         if (pTmpRendInfo->m_pStreamInfo->m_ulDelay <= startPos)
  1495.         {
  1496.             // Remember that we found an earlier packet...
  1497.             earlierPacketFound = TRUE;
  1498.             // If the position is null, then event was the first
  1499.             // item in the list, and we need to do some fancy footwork...
  1500.             if (!position)
  1501.             {
  1502.                 POSITION theHead = m_ToBeginRendererList.GetHeadPosition();
  1503.                 m_ToBeginRendererList.InsertAfter(theHead,pRendInfo);
  1504.             }
  1505.             // otherwise, roll ahead one...
  1506.             else
  1507.             {
  1508.                 m_ToBeginRendererList.GetNext(position);
  1509.                 // Now if the position is null, then event was the last
  1510.                 // item in the list, and we need to do some more fancy footwork...
  1511.                 if (!position)
  1512.                 {
  1513.                     m_ToBeginRendererList.AddTail(pRendInfo);
  1514.                 }
  1515.                 else
  1516.                 // otherwise, we have a normal case and we want to insert
  1517.                 // right after the position of event
  1518.                 {
  1519.                     m_ToBeginRendererList.InsertAfter(position,pRendInfo);
  1520.                 }
  1521.             }
  1522.             // We don't need to search any more...
  1523.             break; // while
  1524.         }
  1525.     } // end while...
  1526.     // If we didn't find an earlier packet, then we should insert at
  1527.     // the head of the event list...
  1528.     if (!earlierPacketFound)
  1529.     {
  1530.         m_ToBeginRendererList.AddHead(pRendInfo);
  1531.     }
  1532. }
  1533. HX_RESULT
  1534. HXPlayer::CheckBeginList(void)
  1535. {
  1536.     RendererInfo* pRendInfo = (RendererInfo*) m_ToBeginRendererList.GetHead();
  1537.     if ((m_ulCurrentPlayTime < pRendInfo->m_pStreamInfo->m_ulDelay &&
  1538.         pRendInfo->m_pStreamInfo->m_ulDelay - m_ulCurrentPlayTime <=
  1539.         BEGIN_SYNC_FUDGE_FACTOR) ||
  1540.         pRendInfo->m_pStreamInfo->m_ulDelay <= m_ulCurrentPlayTime)
  1541.     {
  1542.         /* Send Begins to all the scheduled renderers */
  1543.         LISTPOSITION lPos = m_ToBeginRendererList.GetHeadPosition();
  1544.         while (lPos)
  1545.         {
  1546.             pRendInfo = (RendererInfo*) m_ToBeginRendererList.GetAt(lPos);
  1547.             if ((pRendInfo->m_bInterruptSafe || !m_pEngine->AtInterruptTime()) &&
  1548.                 ((m_ulCurrentPlayTime < pRendInfo->m_pStreamInfo->m_ulDelay &&
  1549.                 pRendInfo->m_pStreamInfo->m_ulDelay - m_ulCurrentPlayTime <=
  1550.                 BEGIN_SYNC_FUDGE_FACTOR) ||
  1551.                 pRendInfo->m_pStreamInfo->m_ulDelay <= m_ulCurrentPlayTime))
  1552.             {
  1553.                 pRendInfo->m_bInitialBeginToBeSent  = FALSE;
  1554.                 pRendInfo->m_pRenderer->OnBegin(m_ulCurrentPlayTime);
  1555.                 lPos = m_ToBeginRendererList.RemoveAt(lPos);
  1556.             }
  1557.             else
  1558.             {
  1559.                 break;
  1560.             }
  1561.         }
  1562.     }
  1563.     return HXR_OK;
  1564. }
  1565. void
  1566. HXPlayer::RemoveFromPendingList(RendererInfo* pRendInfo)
  1567. {
  1568.     LISTPOSITION lPos = NULL;
  1569.     lPos = m_ToBeginRendererList.Find((void*) pRendInfo);
  1570.     if (lPos)
  1571.     {
  1572.         m_ToBeginRendererList.RemoveAt(lPos);
  1573.     }
  1574. }
  1575. void
  1576. HXPlayer::UnregisterNonActiveSources()
  1577. {
  1578.     CHXMapPtrToPtr::Iterator ndxSources = m_pSourceMap->Begin();
  1579.     /* Check if we are done. This may be TRUE for empty files */
  1580.     for (; !m_bIsDone && ndxSources != m_pSourceMap->End(); ++ndxSources)
  1581.     {
  1582.         SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSources);
  1583.         if (pSourceInfo->m_pSource &&
  1584.             (pSourceInfo->m_pSource->IsSourceDone() ||
  1585.             pSourceInfo->m_pSource->IsDelayed()))
  1586.         {
  1587.             pSourceInfo->UnRegister();
  1588.             pSourceInfo->m_pSource->AdjustClipBandwidthStats(FALSE);
  1589.         }
  1590.     }
  1591. }
  1592. /*
  1593.  *  Purpose: Shutdown all the renderers/fileformats
  1594.  */
  1595. void
  1596. HXPlayer::ShutDown(void)
  1597. {
  1598.     /* If we are not in a STOP state, do an internal stop */
  1599.     if (!m_bIsDone)
  1600.     {
  1601.         m_bIsPresentationClosedToBeSent = FALSE;
  1602.         StopPlayer(END_STOP);
  1603.     }
  1604.     CloseAllRenderers(m_nCurrentGroup);
  1605. }
  1606. BOOL
  1607. HXPlayer::AreAllSourcesSeekable(void)
  1608. {
  1609.     CHXMapPtrToPtr::Iterator ndxSource = m_pSourceMap->Begin();
  1610.     for (; ndxSource != m_pSourceMap->End(); ++ndxSource)
  1611.     {
  1612.         SourceInfo* pSourceInfo = (SourceInfo*)(*ndxSource);
  1613.         HXSource * pSource = pSourceInfo->m_pSource;
  1614.         if(!pSource)
  1615.         {
  1616.             continue;
  1617.         }
  1618.         /* If any one source is non-seekable, entire presentation
  1619.          * is non-seekable
  1620.          */
  1621.         if (!pSource->IsSeekable())
  1622.         {
  1623.             return FALSE;
  1624.         }
  1625.     }
  1626.     return TRUE;
  1627. }
  1628. void
  1629. HXPlayer::RegisterSourcesDone()
  1630. {
  1631. #if defined(HELIX_FEATURE_ASM)
  1632.     /* We are done Registering Sources with ASM Bandwidth Manager */
  1633.     HX_ASSERT(m_pBandwidthMgr);
  1634.     m_pBandwidthMgr->RegisterSourcesDone();
  1635.     if (m_pBandwidthMgr->NotEnoughBandwidth() == TRUE)
  1636.     {
  1637.         SetLastError(HXR_NOTENOUGH_BANDWIDTH);
  1638.     }
  1639. #endif /* HELIX_FEATURE_ASM */
  1640. }
  1641. BOOL
  1642. HXPlayer::CanBeStarted(HXSource* pSource, SourceInfo* pThisSourceInfo, BOOL m_bPartOfNextGroup)
  1643. {
  1644.     UINT32      ulDelay             = pSource->GetDelay();
  1645. #if defined(HELIX_FEATURE_NEXTGROUPMGR)
  1646.     if (m_bPartOfNextGroup && m_pNextGroupManager)
  1647.     {
  1648.         return m_pNextGroupManager->CanBeStarted(pSource, pThisSourceInfo);
  1649.     }
  1650. #endif /* HELIX_FEATURE_NEXTGROUPMGR */
  1651.     if ((ulDelay < m_ulCurrentPlayTime)                             ||
  1652.         (ulDelay - m_ulCurrentPlayTime <= MIN_DELAYBEFORE_START)    ||
  1653.         !pThisSourceInfo)
  1654.     {
  1655.         return TRUE;
  1656.     }
  1657.     // XXX HP only start when we are in playing mode
  1658.     // this fixed b#55865 - extreme long startup time on sequence of image
  1659.     // files
  1660.     if (!m_bIsPlaying)
  1661.     {
  1662.         return FALSE;
  1663.     }
  1664.     CHXMapPtrToPtr::Iterator ndxSources = m_pSourceMap->Begin();
  1665.     /* Check if we are done. This may be TRUE for empty files */
  1666.     for (; ndxSources != m_pSourceMap->End(); ++ndxSources)
  1667.     {
  1668.         SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSources);
  1669.         if (!pSourceInfo->m_pSource ||
  1670.             pSourceInfo->m_pSource->IsSourceDone() ||
  1671.             !pSourceInfo->m_pSource->IsInitialized())
  1672.         {
  1673.             continue;
  1674.         }
  1675. #ifdef SEQ_DEPENDENCY
  1676.         int iRetVal = 0;
  1677.         if (!pSourceInfo->m_pSource->IsLive() &&
  1678.             IsDependent(pThisSourceInfo, pSourceInfo) &&
  1679.             !pSourceInfo->m_pSource->IsSourceDone())
  1680.         {
  1681.             return FALSE;
  1682.         }
  1683. #else
  1684.         if (!pSourceInfo->m_pSource->IsLive() &&
  1685.              pSourceInfo->m_pSource->GetDuration() <= ulDelay &&
  1686.             !pSourceInfo->m_pSource->IsSourceDone())
  1687.         {
  1688.             return FALSE;
  1689.         }
  1690. #endif /*SEQ_DEPENDENCY*/
  1691.     }
  1692.     return TRUE;
  1693. }
  1694. #ifdef SEQ_DEPENDENCY
  1695. BOOL
  1696. HXPlayer::IsDependent(SourceInfo* pThisSourceInfo, SourceInfo* pSourceInfo)
  1697. {
  1698.     if (!pThisSourceInfo                            ||
  1699.         !pSourceInfo                                ||
  1700.         pThisSourceInfo->m_uNumDependencies == 0    ||
  1701.         pSourceInfo->m_uNumDependencies     == 0)
  1702.     {
  1703.         return FALSE;
  1704.     }
  1705.     UINT16 uDepdencyNum = 0;
  1706.     while (uDepdencyNum < pThisSourceInfo->m_uNumDependencies &&
  1707.            uDepdencyNum < pSourceInfo->m_uNumDependencies)
  1708.     {
  1709.         if (pThisSourceInfo->m_pDependNode[uDepdencyNum] ==
  1710.             pSourceInfo->m_pDependNode[uDepdencyNum])
  1711.         {
  1712.             uDepdencyNum++;
  1713.         }
  1714.         else
  1715.         {
  1716.         }
  1717.     }
  1718.     if (uDepdencyNum < pThisSourceInfo->m_uNumDependencies &&
  1719.         uDepdencyNum >= pSourceInfo->m_uNumDependencies
  1720.     {
  1721.         return FALSE;
  1722.     }
  1723.     return TRUE;
  1724. }
  1725. #endif /*SEQ_DEPENDENCY*/
  1726. void
  1727. HXPlayer::EndOfSource(HXSource* pSource)
  1728. {
  1729.     BOOL bAtLeastOneSourceToBeResumed = FALSE;
  1730.     CHXMapPtrToPtr::Iterator ndxSources = m_pSourceMap->Begin();
  1731.     /* Check if we are done. This may be TRUE for empty files */
  1732.     for (; ndxSources != m_pSourceMap->End(); ++ndxSources)
  1733.     {
  1734.         SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSources);
  1735.         if (!pSourceInfo->m_pSource)
  1736.         {
  1737.             continue;
  1738.         }
  1739.         if (pSourceInfo->m_pSource->TryResume())
  1740.         {
  1741.             bAtLeastOneSourceToBeResumed = TRUE;
  1742.         }
  1743.     }
  1744.     if (bAtLeastOneSourceToBeResumed)
  1745.     {
  1746.         RegisterSourcesDone();
  1747.         ndxSources = m_pSourceMap->Begin();
  1748.         /* Check if we are done. This may be TRUE for empty files */
  1749.         for (; ndxSources != m_pSourceMap->End(); ++ndxSources)
  1750.         {
  1751.             SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSources);
  1752.             if (!pSourceInfo->m_pSource)
  1753.             {
  1754.                 continue;
  1755.             }
  1756.             if (pSourceInfo->m_pSource->IsResumePending())
  1757.             {
  1758.                 pSourceInfo->m_pSource->DoResume();
  1759.             }
  1760.         }
  1761.     }
  1762. }
  1763. void
  1764. HXPlayer::SureStreamSourceRegistered(SourceInfo* pSourceInfo)
  1765. {
  1766.     if (m_nCurrentGroup == pSourceInfo->m_uGroupID)
  1767.     {
  1768.         m_ulActiveSureStreamSource++;
  1769.         if (m_ulActiveSureStreamSource > 1 && m_bFastStart)
  1770.         {
  1771.             DEBUG_OUT(this, DOL_TRANSPORT, (s,"SureStreams > 1 - TurboPlay Off"));
  1772.             m_bFastStart = FALSE;
  1773.             CHXMapPtrToPtr::Iterator ndxSources = m_pSourceMap->Begin();
  1774.             for (;ndxSources != m_pSourceMap->End(); ++ndxSources)
  1775.             {
  1776.                 SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSources);
  1777.                 if (pSourceInfo->m_bIsRegisterSourceDone &&
  1778.                     pSourceInfo->m_pSource)
  1779.                 {
  1780.                     pSourceInfo->m_pSource->LeaveFastStart(TP_OFF_BY_MULTISURESTREAMS);
  1781.                 }
  1782.             }
  1783.         }
  1784.     }
  1785.     return;
  1786. }
  1787. void
  1788. HXPlayer::SureStreamSourceUnRegistered(SourceInfo* pSourceInfo)
  1789. {
  1790.     if (m_nCurrentGroup == pSourceInfo->m_uGroupID)
  1791.     {
  1792.         m_ulActiveSureStreamSource--;
  1793.     }
  1794.     return;
  1795. }
  1796. BOOL
  1797. HXPlayer::CanBeFastStarted(SourceInfo* pSourceInfo)
  1798. {
  1799.     BOOL                bFastStart = TRUE;
  1800.     BOOL                bTurboPlay = FALSE;
  1801.     IHXBuffer*          pBuffer    = NULL;
  1802.     IHXUpgradeHandler*  pHandler   = NULL;
  1803.     UINT16              uNextGroup = 0;
  1804.     IHXGroup*           pNextGroup = NULL;
  1805. #if defined(__TCS__)
  1806.     m_turboPlayOffReason = TP_OFF_BY_PREFERENCE;
  1807.     m_bFastStart = FALSE;
  1808.     goto cleanup;
  1809. #endif /* __TCS__ */
  1810.     // check if the source is within the current group
  1811.     if (m_nCurrentGroup != pSourceInfo->m_uGroupID)
  1812.     {
  1813.         bFastStart = FALSE;
  1814. #if defined(HELIX_FEATURE_NEXTGROUPMGR)
  1815.         // we want faststart the next group if we are done with the current one
  1816.         if (m_bNextGroupStarted &&
  1817.             m_pNextGroupManager &&
  1818.             HXR_OK == m_pNextGroupManager->GetCurrentGroup(uNextGroup, pNextGroup))
  1819.         {
  1820.             if (uNextGroup == pSourceInfo->m_uGroupID)
  1821.             {
  1822.                 bFastStart = TRUE;
  1823.             }
  1824.         }
  1825.         HX_RELEASE(pNextGroup);
  1826. #endif /* HELIX_FEATURE_NEXTGROUPMGR */
  1827.         goto cleanup;
  1828.     }
  1829.     else if (!m_bFastStartCheckDone)
  1830.     {
  1831.         m_bFastStartCheckDone = TRUE;
  1832.         m_bFastStart = TRUE;
  1833.         // check the preference
  1834.         ReadPrefBOOL(m_pPreferences, "TurboPlay", bTurboPlay);
  1835.         if (!bTurboPlay)
  1836.         {
  1837.             DEBUG_OUT(this, DOL_TRANSPORT, (s,"Preference check - TurboPlay Off"));
  1838.             m_turboPlayOffReason = TP_OFF_BY_PREFERENCE;
  1839.             m_bFastStart = FALSE;
  1840.             goto cleanup;
  1841.         }
  1842.     }
  1843.     else if (m_ulActiveSureStreamSource > 1)
  1844.     {
  1845.         m_turboPlayOffReason = TP_OFF_BY_MULTISURESTREAMS;
  1846.         bFastStart = FALSE;
  1847.         goto cleanup;
  1848.     }
  1849.   cleanup:
  1850.     HX_RELEASE(pHandler);
  1851.     HX_RELEASE(pBuffer);
  1852.     return (m_bFastStart & bFastStart);
  1853. }
  1854. void
  1855. HXPlayer::UpdateCurrentPlayTime( ULONG32 ulCurrentPlayTime )
  1856. {
  1857.     m_ulCurrentPlayTime = ulCurrentPlayTime;
  1858. #if defined(_MACINTOSH) || defined(_MAC_UNIX)
  1859.     if ( IsMacInCooperativeThread() )
  1860.     {
  1861.         m_ulCurrentSystemPlayTime = ulCurrentPlayTime;
  1862.     }
  1863. #endif
  1864. }
  1865. void
  1866. HXPlayer::SendPostSeekIfNecessary(RendererInfo* pRendererInfo)
  1867. {
  1868.     if (pRendererInfo->m_BufferingReason == BUFFERING_SEEK ||
  1869.         pRendererInfo->m_BufferingReason == BUFFERING_LIVE_PAUSE)
  1870.     {
  1871.         pRendererInfo->m_BufferingReason = BUFFERING_CONGESTION;
  1872.         pRendererInfo->m_pRenderer->OnPostSeek(
  1873.                 pRendererInfo->m_pStreamInfo->m_ulTimeBeforeSeek,
  1874.                 pRendererInfo->m_pStreamInfo->m_ulTimeAfterSeek);
  1875.         pRendererInfo->m_pStreamInfo->m_pStream->m_bPostSeekToBeSent = FALSE;
  1876.     }
  1877. }
  1878. BOOL
  1879. HXPlayer::ScheduleOnTimeSync()
  1880. {
  1881.     BOOL            bResult = FALSE;
  1882.     BOOL            bDurationTimeSyncAllSent = FALSE;
  1883.     ULONG32         ulAudioTime = 0;
  1884.     SourceInfo*     pSourceInfo = NULL;
  1885.     CHXMapPtrToPtr::Iterator    ndxSource;
  1886.     if (m_pAudioPlayer)
  1887.     {
  1888.         ulAudioTime = m_pAudioPlayer->GetCurrentPlayBackTime();
  1889.     }
  1890. #if defined(HELIX_FEATURE_NESTEDMETA)
  1891.     m_pPersistentComponentManager->OnTimeSync(ulAudioTime);
  1892. #endif /* HELIX_FEATURE_NESTEDMETA */
  1893.     ndxSource = m_pSourceMap->Begin();
  1894.     for (;ndxSource != m_pSourceMap->End(); ++ndxSource)
  1895.     {
  1896.         pSourceInfo = (SourceInfo*)(*ndxSource);
  1897.         if (!DurationTimeSyncAllSent(pSourceInfo))
  1898.         {
  1899.             pSourceInfo->OnTimeSync( ulAudioTime );
  1900.             bDurationTimeSyncAllSent = DurationTimeSyncAllSent(pSourceInfo);
  1901.             if (!pSourceInfo->m_bDurationTimeSyncScheduled &&
  1902.                 !bDurationTimeSyncAllSent)
  1903.             {
  1904.                 pSourceInfo->m_bDurationTimeSyncScheduled = TRUE;
  1905.                 bResult = TRUE;
  1906.                 goto cleanup;
  1907.             }
  1908.         }
  1909.     }
  1910. cleanup:
  1911.     return bResult;
  1912. }
  1913. BOOL
  1914. HXPlayer::DurationTimeSyncAllSent(SourceInfo* pSourceInfo)
  1915. {
  1916.     BOOL    bResult = TRUE;
  1917.     RendererInfo* pRendInfo = NULL;
  1918.     CHXMapLongToObj::Iterator   ndxRend;
  1919.     ndxRend = pSourceInfo->m_pRendererMap->Begin();
  1920.     for (;ndxRend != pSourceInfo->m_pRendererMap->End();++ndxRend)
  1921.     {
  1922.         pRendInfo   = (RendererInfo*)(*ndxRend);
  1923.         if (!pRendInfo->m_bDurationTimeSyncSent)
  1924.         {
  1925.             bResult = FALSE;
  1926.             break;
  1927.         }
  1928.     }
  1929.     return bResult;
  1930. }
  1931. void
  1932. HXPlayer::DisableScreenSaver()
  1933. {
  1934.     return;
  1935. }
  1936. void HXPlayer::RemovePendingCallback(CHXGenericCallback* pCB)
  1937. {
  1938.     if (pCB && 
  1939.         pCB->GetPendingCallback() &&
  1940.         m_pScheduler)
  1941.     {
  1942.         m_pScheduler->Remove(pCB->GetPendingCallback());
  1943.         pCB->CallbackCanceled();
  1944.     }
  1945. }
  1946. #ifndef _WIN16
  1947. #if defined(HELIX_FEATURE_AUTHENTICATION)
  1948. _CListOfWrapped_IUnknown_Node::_CListOfWrapped_IUnknown_Node()
  1949.   : m_plocPrev(NULL)
  1950.   , m_plocNext(NULL)
  1951. {
  1952. }
  1953. _CListOfWrapped_IUnknown_Node::~_CListOfWrapped_IUnknown_Node()
  1954. {
  1955.     Remove();
  1956. }
  1957. void
  1958. _CListOfWrapped_IUnknown_Node::Remove()
  1959. {
  1960.     if(m_plocPrev)
  1961.     {
  1962.         m_plocPrev->next(m_plocNext);
  1963.     }
  1964.     if(m_plocNext)
  1965.     {
  1966.         m_plocNext->prev(m_plocPrev);
  1967.     }
  1968. }
  1969. void
  1970. _CListOfWrapped_IUnknown_Node::Insert(_CListOfWrapped_IUnknown_Node& rlocnNew)
  1971. {
  1972.     rlocnNew.next(this);
  1973.     rlocnNew.prev(m_plocPrev);
  1974.     if(m_plocPrev)
  1975.     {
  1976.         m_plocPrev->next(&rlocnNew);
  1977.     }
  1978.     m_plocPrev = &rlocnNew;
  1979. }
  1980. Wrapped_IUnknown&
  1981. _CListOfWrapped_IUnknown_Node::value()
  1982. {
  1983.     return m_clsValue;
  1984. }
  1985. const Wrapped_IUnknown&
  1986. _CListOfWrapped_IUnknown_Node::value() const
  1987. {
  1988.     return m_clsValue;
  1989. }
  1990. void
  1991. _CListOfWrapped_IUnknown_Node::value(const Wrapped_IUnknown& rclsNewValue)
  1992. {
  1993.     m_clsValue = rclsNewValue;
  1994. }
  1995. _CListOfWrapped_IUnknown_Node&
  1996. _CListOfWrapped_IUnknown_Node::operator=(const Wrapped_IUnknown& rclsNewValue)
  1997. {
  1998.     m_clsValue = rclsNewValue;
  1999.     return *this;
  2000. }
  2001. _CListOfWrapped_IUnknown_Node*
  2002. _CListOfWrapped_IUnknown_Node::next() const
  2003. {
  2004.     return m_plocNext;
  2005. }
  2006. void
  2007. _CListOfWrapped_IUnknown_Node::next(_CListOfWrapped_IUnknown_Node* plocnNew)
  2008. {
  2009.     m_plocNext = plocnNew;
  2010. }
  2011. _CListOfWrapped_IUnknown_Node*
  2012. _CListOfWrapped_IUnknown_Node::prev() const
  2013. {
  2014.     return m_plocPrev;
  2015. }
  2016. void
  2017. _CListOfWrapped_IUnknown_Node::prev(_CListOfWrapped_IUnknown_Node* plocnNew)
  2018. {
  2019.     m_plocPrev = plocnNew;
  2020. }
  2021. _CListOfWrapped_IUnknown_::_CListOfWrapped_IUnknown_()
  2022. {
  2023.     m_locnREnd.next(&m_locnEnd);
  2024.     m_locnEnd.prev(&m_locnREnd);
  2025. }
  2026. _CListOfWrapped_IUnknown_::_CListOfWrapped_IUnknown_(const _CListOfWrapped_IUnknown_& rlocOther)
  2027. {
  2028.     m_locnREnd.next(&m_locnEnd);
  2029.     m_locnEnd.prev(&m_locnREnd);
  2030.     _copy(rlocOther);
  2031. }
  2032. _CListOfWrapped_IUnknown_::~_CListOfWrapped_IUnknown_()
  2033. {
  2034.     empty();
  2035. }
  2036. _CListOfWrapped_IUnknown_&
  2037. _CListOfWrapped_IUnknown_::operator=(const _CListOfWrapped_IUnknown_& rlocOther)
  2038. {
  2039.     empty();
  2040.     _copy(rlocOther);
  2041.     return *this;
  2042. }
  2043. void
  2044. _CListOfWrapped_IUnknown_::_copy(const _CListOfWrapped_IUnknown_& rlocOther)
  2045. {
  2046.     iterator itOther;
  2047.     for
  2048.     (
  2049.         itOther = rlocOther.begin();
  2050.         itOther != rlocOther.end();
  2051.         ++itOther
  2052.     )
  2053.     {
  2054.         insert(end(), *itOther);
  2055.     }
  2056. }
  2057. _CListOfWrapped_IUnknown_::iterator
  2058. _CListOfWrapped_IUnknown_::begin()
  2059. {
  2060.     return iterator(*(m_locnREnd.next()));
  2061. }
  2062. const _CListOfWrapped_IUnknown_::iterator
  2063. _CListOfWrapped_IUnknown_::begin() const
  2064. {
  2065.     return iterator(*(m_locnREnd.next()));
  2066. }
  2067. _CListOfWrapped_IUnknown_::iterator
  2068. _CListOfWrapped_IUnknown_::end()
  2069. {
  2070.     return iterator(m_locnEnd);
  2071. }
  2072. const _CListOfWrapped_IUnknown_::iterator
  2073. _CListOfWrapped_IUnknown_::end() const
  2074. {
  2075.     return iterator(m_locnEnd);
  2076. }
  2077. _CListOfWrapped_IUnknown_::reverse_iterator
  2078. _CListOfWrapped_IUnknown_::rbegin()
  2079. {
  2080.     return reverse_iterator(*(m_locnEnd.prev()));
  2081. }
  2082. const _CListOfWrapped_IUnknown_::reverse_iterator
  2083. _CListOfWrapped_IUnknown_::rbegin() const
  2084. {
  2085.     return const_reverse_iterator(*(m_locnEnd.prev()));
  2086. }
  2087. _CListOfWrapped_IUnknown_::reverse_iterator
  2088. _CListOfWrapped_IUnknown_::rend()
  2089. {
  2090.     return reverse_iterator(m_locnREnd);
  2091. }
  2092. const _CListOfWrapped_IUnknown_::reverse_iterator
  2093. _CListOfWrapped_IUnknown_::rend() const
  2094. {
  2095.     return const_reverse_iterator(*((const _CListOfWrapped_IUnknown_Node *)&m_locnREnd));
  2096. }
  2097. _CListOfWrapped_IUnknown_::iterator
  2098. _CListOfWrapped_IUnknown_::insert(iterator itBefore, const Wrapped_IUnknown& rclsNew)
  2099. {
  2100.     _CListOfWrapped_IUnknown_Node* plocnNew = new _CListOfWrapped_IUnknown_Node;
  2101.     HX_ASSERT(plocnNew);
  2102.     *plocnNew = rclsNew;
  2103.     itBefore.m_plocCurrent->Insert(*plocnNew);
  2104.     return iterator(*plocnNew);
  2105. }
  2106. void
  2107. _CListOfWrapped_IUnknown_::insert
  2108. (
  2109.     iterator itBefore,
  2110.     const iterator itFirst,
  2111.     const iterator itLast
  2112. )
  2113. {
  2114.     iterator itOther;
  2115.     _CListOfWrapped_IUnknown_Node* plocnNew;
  2116.     for (itOther = itFirst; itOther != itLast; ++itOther)
  2117.     {
  2118.         plocnNew = new _CListOfWrapped_IUnknown_Node;
  2119.         HX_ASSERT(plocnNew);
  2120.         *plocnNew = *itOther;
  2121.         itBefore.m_plocCurrent->Insert(*plocnNew);
  2122.     }
  2123. }
  2124. void
  2125. _CListOfWrapped_IUnknown_::remove(iterator itThis)
  2126. {
  2127.     if
  2128.     (
  2129.         itThis.m_plocCurrent == &m_locnEnd ||
  2130.         itThis.m_plocCurrent == &m_locnREnd
  2131.     )
  2132.     {
  2133.         return;
  2134.     }
  2135.     _CListOfWrapped_IUnknown_Node* plocnOld;
  2136.     plocnOld = itThis.m_plocCurrent;
  2137.     ++itThis;
  2138.     plocnOld->Remove();
  2139.     delete plocnOld;
  2140. }
  2141. void
  2142. _CListOfWrapped_IUnknown_::remove(iterator itFirst, iterator itLast)
  2143. {
  2144.     if
  2145.     (
  2146.         itFirst.m_plocCurrent == &m_locnEnd ||
  2147.         itFirst.m_plocCurrent == &m_locnREnd
  2148.     )
  2149.     {
  2150.         return;
  2151.     }
  2152.     iterator itOther;
  2153.     _CListOfWrapped_IUnknown_Node* plocnOld;
  2154.     for (itOther = itFirst; itOther != itLast;)
  2155.     {
  2156.         plocnOld = itOther.m_plocCurrent;
  2157.         ++itOther;
  2158.         plocnOld->Remove();
  2159.         delete plocnOld;
  2160.     }
  2161. }
  2162. void
  2163. _CListOfWrapped_IUnknown_::empty()
  2164. {
  2165.     remove(begin(), end());
  2166. }
  2167. _CListIteratorWrapped_IUnknown_::_CListIteratorWrapped_IUnknown_()
  2168.   : m_plocCurrent(NULL)
  2169. {
  2170. }
  2171. _CListIteratorWrapped_IUnknown_::_CListIteratorWrapped_IUnknown_
  2172. (
  2173.     const _CListOfWrapped_IUnknown_Node& rlocnNewLocation
  2174. )
  2175.   : m_plocCurrent((_CListOfWrapped_IUnknown_Node*)&rlocnNewLocation)
  2176. {
  2177. }
  2178. _CListIteratorWrapped_IUnknown_::_CListIteratorWrapped_IUnknown_
  2179. (
  2180.     const _CListIteratorWrapped_IUnknown_& rliocOther
  2181. )
  2182.   : m_plocCurrent(rliocOther.m_plocCurrent)
  2183. {
  2184. }
  2185. _CListIteratorWrapped_IUnknown_::~_CListIteratorWrapped_IUnknown_()
  2186. {
  2187. }
  2188. _CListIteratorWrapped_IUnknown_&
  2189. _CListIteratorWrapped_IUnknown_::operator=
  2190. (
  2191.     const _CListIteratorWrapped_IUnknown_& rliocOther
  2192. )
  2193. {
  2194.     m_plocCurrent = rliocOther.m_plocCurrent;
  2195.     return *this;
  2196. }
  2197. Wrapped_IUnknown&
  2198. _CListIteratorWrapped_IUnknown_::operator*()
  2199. {
  2200.     HX_ASSERT(m_plocCurrent);
  2201.     return m_plocCurrent->value();
  2202. }
  2203. _CListIteratorWrapped_IUnknown_&
  2204. _CListIteratorWrapped_IUnknown_::operator=(const Wrapped_IUnknown& rclsNewValue)
  2205. {
  2206.     if(!m_plocCurrent)
  2207.         return *this;
  2208.     m_plocCurrent->value(rclsNewValue);
  2209.     return *this;
  2210. }
  2211. _CListIteratorWrapped_IUnknown_&
  2212. _CListIteratorWrapped_IUnknown_::operator++()
  2213. {
  2214.     if(!m_plocCurrent)
  2215.         return *this;
  2216.     m_plocCurrent = m_plocCurrent->next();
  2217.     return *this;
  2218. }
  2219. const _CListIteratorWrapped_IUnknown_
  2220. _CListIteratorWrapped_IUnknown_::operator++(int)
  2221. {
  2222.     _CListIteratorWrapped_IUnknown_ liocRet(*this);
  2223.     ++(*this);
  2224.     return liocRet;
  2225. }
  2226. _CListIteratorWrapped_IUnknown_&
  2227. _CListIteratorWrapped_IUnknown_::operator--()
  2228. {
  2229.     if(!m_plocCurrent)
  2230.         return *this;
  2231.     m_plocCurrent = m_plocCurrent->prev();
  2232.     return *this;
  2233. }
  2234. const _CListIteratorWrapped_IUnknown_
  2235. _CListIteratorWrapped_IUnknown_::operator--(int)
  2236. {
  2237.     _CListIteratorWrapped_IUnknown_ liocRet(*this);
  2238.     --(*this);
  2239.     return liocRet;
  2240. }
  2241. BOOL operator==
  2242. (
  2243.     const _CListIteratorWrapped_IUnknown_& rliocLeft,
  2244.     const _CListIteratorWrapped_IUnknown_& rliocRight
  2245. )
  2246. {
  2247.     return (rliocLeft.m_plocCurrent == rliocRight.m_plocCurrent);
  2248. }
  2249. BOOL operator!=
  2250. (
  2251.     const _CListIteratorWrapped_IUnknown_& rliocLeft,
  2252.     const _CListIteratorWrapped_IUnknown_& rliocRight
  2253. )
  2254. {
  2255.     return (rliocLeft.m_plocCurrent != rliocRight.m_plocCurrent);
  2256. }
  2257. _CListReverseIteratorWrapped_IUnknown_::_CListReverseIteratorWrapped_IUnknown_()
  2258.   : m_plocCurrent(NULL)
  2259. {
  2260. }
  2261. _CListReverseIteratorWrapped_IUnknown_::_CListReverseIteratorWrapped_IUnknown_
  2262. (
  2263.     const _CListOfWrapped_IUnknown_Node& rlocnNewLocation
  2264. )
  2265.   : m_plocCurrent((_CListOfWrapped_IUnknown_Node*)&rlocnNewLocation)
  2266. {
  2267. }
  2268. _CListReverseIteratorWrapped_IUnknown_::_CListReverseIteratorWrapped_IUnknown_
  2269. (
  2270.     const _CListReverseIteratorWrapped_IUnknown_& rlriocOther
  2271. )
  2272.   : m_plocCurrent(rlriocOther.m_plocCurrent)
  2273. {
  2274. }
  2275. _CListReverseIteratorWrapped_IUnknown_::~_CListReverseIteratorWrapped_IUnknown_()
  2276. {
  2277. }
  2278. _CListReverseIteratorWrapped_IUnknown_&
  2279. _CListReverseIteratorWrapped_IUnknown_::operator=
  2280. (
  2281.     const _CListReverseIteratorWrapped_IUnknown_& rlriocOther
  2282. )
  2283. {
  2284.     m_plocCurrent = rlriocOther.m_plocCurrent;
  2285.     return *this;
  2286. }
  2287. Wrapped_IUnknown&
  2288. _CListReverseIteratorWrapped_IUnknown_::operator*()
  2289. {
  2290.     HX_ASSERT(m_plocCurrent);
  2291.     return m_plocCurrent->value();
  2292. }
  2293. _CListReverseIteratorWrapped_IUnknown_&
  2294. _CListReverseIteratorWrapped_IUnknown_::operator=(const Wrapped_IUnknown& rclsNewValue)
  2295. {
  2296.     if(!m_plocCurrent)
  2297.         return *this;
  2298.     m_plocCurrent->value(rclsNewValue);
  2299.     return *this;
  2300. }
  2301. _CListReverseIteratorWrapped_IUnknown_&
  2302. _CListReverseIteratorWrapped_IUnknown_::operator++()
  2303. {
  2304.     if(!m_plocCurrent)
  2305.         return *this;
  2306.     m_plocCurrent = m_plocCurrent->prev();
  2307.     return *this;
  2308. }
  2309. const _CListReverseIteratorWrapped_IUnknown_
  2310. _CListReverseIteratorWrapped_IUnknown_::operator++(int)
  2311. {
  2312.     _CListReverseIteratorWrapped_IUnknown_ lriocRet(*this);
  2313.     ++(*this);
  2314.     return lriocRet;
  2315. }
  2316. _CListReverseIteratorWrapped_IUnknown_&
  2317. _CListReverseIteratorWrapped_IUnknown_::operator--()
  2318. {
  2319.     if(!m_plocCurrent)
  2320.         return *this;
  2321.     m_plocCurrent = m_plocCurrent->next();
  2322.     return *this;
  2323. }
  2324. const _CListReverseIteratorWrapped_IUnknown_
  2325. _CListReverseIteratorWrapped_IUnknown_::operator--(int)
  2326. {
  2327.     _CListReverseIteratorWrapped_IUnknown_ lriocRet(*this);
  2328.     --(*this);
  2329.     return lriocRet;
  2330. }
  2331. BOOL operator==
  2332. (
  2333.     const _CListReverseIteratorWrapped_IUnknown_& rlriocLeft,
  2334.     const _CListReverseIteratorWrapped_IUnknown_& rlriocRight
  2335. )
  2336. {
  2337.     return (rlriocLeft.m_plocCurrent == rlriocRight.m_plocCurrent);
  2338. }
  2339. BOOL operator!=
  2340. (
  2341.     const _CListReverseIteratorWrapped_IUnknown_& rlriocLeft,
  2342.     const _CListReverseIteratorWrapped_IUnknown_& rlriocRight
  2343. )
  2344. {
  2345.     return (rlriocLeft.m_plocCurrent != rlriocRight.m_plocCurrent);
  2346. }
  2347. #endif /* HELIX_FEATURE_AUTHENTICATION */
  2348. _CHXAuthenticationRequests::_CHXAuthenticationRequests()
  2349.     : m_pMutexProtectList(NULL)
  2350.     , m_bUIShowing(FALSE)
  2351. {
  2352. #ifdef HELIX_FEATURE_AUTHENTICATION
  2353. #ifdef THREADS_SUPPORTED
  2354.     HXMutex::MakeMutex(m_pMutexProtectList);
  2355. #else
  2356.     HXMutex::MakeStubMutex(m_pMutexProtectList);
  2357. #endif
  2358. #endif /* HELIX_FEATURE_AUTHENTICATION */
  2359. }
  2360. _CHXAuthenticationRequests::~_CHXAuthenticationRequests()
  2361. {
  2362. #ifdef HELIX_FEATURE_AUTHENTICATION
  2363.     HX_DELETE(m_pMutexProtectList);
  2364. #endif /* HELIX_FEATURE_AUTHENTICATION */
  2365. }
  2366. HX_RESULT
  2367. _CHXAuthenticationRequests::Add(HXPlayer* pPlayerRequester,
  2368.         IHXAuthenticationManagerResponse* pAuthenticationManagerResponseRequester,
  2369.         IHXValues* pAuthenticationHeaderValues)
  2370. {
  2371. #ifdef HELIX_FEATURE_AUTHENTICATION
  2372.     BOOL bShowUI = FALSE;
  2373.     IHXAuthenticationManager* pAuthenticationManagerClient = NULL;
  2374.     IHXAuthenticationManager2* pAuthenticationManagerClient2 = NULL;
  2375.     pPlayerRequester->m_pClient->QueryInterface(IID_IHXAuthenticationManager2, (void**)&pAuthenticationManagerClient2);
  2376.     if (pAuthenticationManagerClient2)
  2377.     {
  2378.         HX_ASSERT(pPlayerRequester);
  2379.         if (pAuthenticationManagerClient2 == (IHXAuthenticationManager2*)pPlayerRequester)
  2380.         {
  2381.             HX_RELEASE(pAuthenticationManagerClient2);
  2382.             pAuthenticationManagerClient2 = NULL;
  2383.         }
  2384.     }
  2385.     if (!pAuthenticationManagerClient2)
  2386.     {
  2387.         pPlayerRequester->m_pClient->QueryInterface
  2388.         (
  2389.             IID_IHXAuthenticationManager,
  2390.             (void**)&pAuthenticationManagerClient
  2391.         );
  2392.     }
  2393.     if (!pAuthenticationManagerClient && !pAuthenticationManagerClient2)
  2394.     {
  2395.         return pAuthenticationManagerResponseRequester->AuthenticationRequestDone
  2396.         (
  2397.             HXR_UNEXPECTED,
  2398.             NULL,
  2399.             NULL
  2400.         );
  2401.     }
  2402.     HX_ASSERT(pAuthenticationManagerClient || pAuthenticationManagerClient2); // we want one...
  2403.     HX_ASSERT(!(pAuthenticationManagerClient && pAuthenticationManagerClient2)); // .. but not both
  2404.     // Don't allow iterating while we are adding.
  2405.     m_pMutexProtectList->Lock();
  2406.     m_ListOfIUnknownRequesters.insert(m_ListOfIUnknownRequesters.end(), (IUnknown*)pAuthenticationManagerResponseRequester);
  2407.     if (!m_bUIShowing)
  2408.     {
  2409.         bShowUI = m_bUIShowing = TRUE;
  2410.     }
  2411.     m_pMutexProtectList->Unlock();
  2412.     if (bShowUI)
  2413.     {
  2414.         IHXInterruptSafe* pInterruptSafe = NULL;
  2415.         if (pAuthenticationManagerClient) pAuthenticationManagerClient->QueryInterface(IID_IHXInterruptSafe,
  2416.                                                      (void**) &pInterruptSafe);
  2417.         if (pAuthenticationManagerClient2) pAuthenticationManagerClient2->QueryInterface(IID_IHXInterruptSafe,
  2418.                                                         (void**) &pInterruptSafe);
  2419.         if (!pPlayerRequester->m_pEngine->AtInterruptTime() ||
  2420.                       (pInterruptSafe && pInterruptSafe->IsInterruptSafe()))
  2421.         {
  2422.             /* Remove any pending callback */
  2423.             pPlayerRequester->RemovePendingCallback(pPlayerRequester->m_pAuthenticationCallback);
  2424.             if (pAuthenticationManagerClient)
  2425.             {
  2426.                 pAuthenticationManagerClient->HandleAuthenticationRequest
  2427.                             (
  2428.                                 pPlayerRequester
  2429.                             );
  2430.             }
  2431.             if (pAuthenticationManagerClient2)
  2432.             {
  2433.                 pAuthenticationManagerClient2->HandleAuthenticationRequest2
  2434.                             (
  2435.                                 pPlayerRequester,
  2436.                                 pAuthenticationHeaderValues
  2437.                             );
  2438.             }
  2439.         }
  2440.         else
  2441.         {
  2442.             m_bUIShowing = FALSE;
  2443.             /*
  2444.              * Schedule a callback to request authentication at
  2445.              * non-interrupt time
  2446.              */
  2447.             if (pPlayerRequester->m_pAuthenticationCallback &&
  2448.                 !pPlayerRequester->m_pAuthenticationCallback->GetPendingCallback())
  2449.             {
  2450.                 pPlayerRequester->m_pAuthenticationCallback->CallbackScheduled(
  2451.                     pPlayerRequester->m_pScheduler->RelativeEnter(pPlayerRequester->m_pAuthenticationCallback, 0));
  2452.             }
  2453.         }
  2454.         HX_RELEASE(pInterruptSafe);
  2455.     }
  2456.     HX_RELEASE(pAuthenticationManagerClient);
  2457.     HX_RELEASE(pAuthenticationManagerClient2);
  2458.     return HXR_OK;
  2459. #else
  2460.     return HXR_NOTIMPL;
  2461. #endif /* HELIX_FEATURE_AUTHENTICATION */
  2462. }
  2463. HX_RESULT
  2464. _CHXAuthenticationRequests::SatisfyPending
  2465. (
  2466.     HX_RESULT ResultStatus,
  2467.     const char* pCharUser,
  2468.     const char* pCharPassword
  2469. )
  2470. {
  2471. #ifdef HELIX_FEATURE_AUTHENTICATION
  2472.     _CListOfWrapped_IUnknown_::iterator ListOfIUnknownIteratorCurrentRequester;
  2473.     IUnknown* pUnknownRequester = NULL;
  2474.     IHXAuthenticationManagerResponse* pAuthenticationManagerResponseRequester = NULL;
  2475.     // Don't allow add's while we are iterating.
  2476.     m_pMutexProtectList->Lock();
  2477.     m_bUIShowing = FALSE;
  2478.     for
  2479.     (
  2480.         ListOfIUnknownIteratorCurrentRequester = m_ListOfIUnknownRequesters.begin();
  2481.         ListOfIUnknownIteratorCurrentRequester != m_ListOfIUnknownRequesters.end();
  2482.         ++ListOfIUnknownIteratorCurrentRequester
  2483.     )
  2484.     {
  2485.         pUnknownRequester = (*ListOfIUnknownIteratorCurrentRequester).wrapped_ptr();
  2486.         if (pUnknownRequester)
  2487.         {
  2488.             pUnknownRequester->QueryInterface
  2489.             (
  2490.                 IID_IHXAuthenticationManagerResponse,
  2491.                 (void**)&pAuthenticationManagerResponseRequester
  2492.             );
  2493.             if (pAuthenticationManagerResponseRequester)
  2494.             {
  2495.                 pAuthenticationManagerResponseRequester->AuthenticationRequestDone
  2496.                 (
  2497.                     ResultStatus,
  2498.                     pCharUser,
  2499.                     pCharPassword
  2500.                 );
  2501.             }
  2502.         }
  2503.         HX_RELEASE(pAuthenticationManagerResponseRequester);
  2504.         pUnknownRequester = NULL;
  2505.     }
  2506.     m_ListOfIUnknownRequesters.empty();
  2507.     m_pMutexProtectList->Unlock();
  2508.     return HXR_OK;
  2509. #else
  2510.     return HXR_NOTIMPL;
  2511. #endif /* HELIX_FEATURE_AUTHENTICATION */
  2512. }
  2513. void
  2514. _CHXAuthenticationRequests::ClearPendingList()
  2515. {
  2516. #ifdef HELIX_FEATURE_AUTHENTICATION
  2517.     m_ListOfIUnknownRequesters.empty();
  2518. #endif /* HELIX_FEATURE_AUTHENTICATION */
  2519. }
  2520. #endif /* _WIN16 */
  2521. HX_RESULT
  2522. HXPlayer::AdjustSeekOnRepeatedSource(SourceInfo*   pSourceInfo,
  2523.                                       UINT32        ulSeekTime)
  2524. {
  2525. #if defined(HELIX_FEATURE_SMIL_REPEAT)
  2526.     HX_RESULT   theErr = HXR_OK;
  2527.     SourceInfo* pAdjustedSourceInfo = NULL;
  2528.     pAdjustedSourceInfo = pSourceInfo->DoAdjustSeek(ulSeekTime);
  2529.     if (pAdjustedSourceInfo == pSourceInfo)
  2530.     {
  2531.         theErr = pSourceInfo->m_pSource->DoSeek(ulSeekTime);
  2532.     }
  2533.     else
  2534.     {
  2535.         m_pSourceMap->RemoveKey(pSourceInfo->m_pSource);
  2536.         m_pSourceMap->SetAt((void*)pAdjustedSourceInfo->m_pSource,
  2537.                           (void*)pAdjustedSourceInfo);
  2538.         m_bSourceMapUpdated = TRUE;
  2539.         m_bForceStatsUpdate = TRUE;
  2540.         if (pAdjustedSourceInfo->m_bTobeInitializedBeforeBegin)
  2541.         {
  2542.             m_uNumSourceToBeInitializedBeforeBegin++;
  2543.         }
  2544.     }
  2545.     return theErr;
  2546. #else
  2547.     return HXR_NOTIMPL;
  2548. #endif /* HELIX_FEATURE_SMIL_REPEAT */
  2549. }
  2550. BOOL
  2551. HXPlayer::IsSitePresent
  2552. (
  2553.     IHXSite*                pSite
  2554. )
  2555. {
  2556. #if defined(HELIX_FEATURE_VIDEO)
  2557.     return m_pSiteManager->IsSitePresent(pSite);
  2558. #else
  2559.     return FALSE;
  2560. #endif /* HELIX_FEATURE_VIDEO */
  2561. }
  2562. void
  2563. HXPlayer::CheckIfRendererNeedFocus(IUnknown* pRenderer)
  2564. {
  2565. #if defined(HELIX_FEATURE_VIDEO)
  2566.     BOOL bNeedFocus = FALSE;
  2567.     ReadPrefBOOL(m_pPreferences, "GrabFocus", bNeedFocus);
  2568.     IHXRenderer* pRend = NULL;
  2569.     pRenderer->QueryInterface(IID_IHXRenderer, (void**) &pRend);
  2570.     if (pRend)
  2571.     {
  2572.         UINT32 ulGran = 0;
  2573.         const char**    ppszMimeTypes = NULL;
  2574.         pRend->GetRendererInfo(ppszMimeTypes, ulGran);
  2575.         while (ppszMimeTypes && *ppszMimeTypes)
  2576.         {
  2577.             // XXRA Hernry, please remove the GrabFocus preference code from above
  2578.             // when you add the right mimetypes
  2579.             if ((::strcasecmp(*ppszMimeTypes, "MIMETYPE1") == 0) ||
  2580.                 (::strcasecmp(*ppszMimeTypes, "MIMETYPE2") == 0))
  2581.             {
  2582.                 bNeedFocus = TRUE;
  2583.                 goto rendexit;
  2584.             }
  2585.             ppszMimeTypes++;
  2586.         }
  2587.     }
  2588. rendexit:
  2589.     HX_RELEASE(pRend);
  2590.     if (m_pSiteManager && bNeedFocus)
  2591.     {
  2592.         m_pSiteManager->NeedFocus(TRUE);
  2593.     }
  2594. #endif /* HELIX_FEATURE_VIDEO */
  2595. }
  2596. #if defined(HELIX_FEATURE_RECORDCONTROL)
  2597. BOOL HXPlayer::IsRecordServiceEnabled()
  2598. {
  2599.     BOOL bRes = FALSE;
  2600.     ReadPrefBOOL(m_pPreferences, "LiveSuperBuffer", bRes);
  2601.     return bRes;
  2602. }
  2603. #endif
  2604. STDMETHODIMP
  2605. HXPlayer::LoadRecordService(IHXRecordService* pRecordService)
  2606. {
  2607. #if defined(HELIX_FEATURE_RECORDCONTROL)
  2608.     HX_RELEASE(m_pRecordService);
  2609.     m_pRecordService = pRecordService;
  2610.     if(m_pRecordService)
  2611.         m_pRecordService->AddRef();
  2612.     return HXR_OK;
  2613. #else
  2614.     return HXR_NOTIMPL;
  2615. #endif /* HELIX_FEATURE_RECORDCONTROL */
  2616. }
  2617. STDMETHODIMP
  2618. HXPlayer::GetRecordService(REF(IHXRecordService*) pRecordService)
  2619. {
  2620. #if defined(HELIX_FEATURE_RECORDCONTROL)
  2621.     pRecordService = m_pRecordService;
  2622.     if(pRecordService)
  2623.     {
  2624.         pRecordService->AddRef();
  2625.         return HXR_OK;
  2626.     }
  2627.     return HXR_FAILED;
  2628. #else
  2629.     return HXR_NOTIMPL;
  2630. #endif /* HELIX_FEATURE_RECORDCONTROL */
  2631. }
  2632. STDMETHODIMP
  2633. HXPlayer::UnloadRecordService()
  2634. {
  2635. #if defined(HELIX_FEATURE_RECORDCONTROL)
  2636.     HX_RELEASE(m_pRecordService);
  2637.     return HXR_OK;
  2638. #else
  2639.     return HXR_NOTIMPL;
  2640. #endif /* HELIX_FEATURE_RECORDCONTROL */
  2641. }
  2642. // working set monitoring tools on Windows
  2643. #if 0
  2644. #ifdef WIN32
  2645. typedef struct _PSAPI_WS_WATCH_INFORMATION
  2646. {
  2647.     LPVOID FaultingPc;
  2648.     LPVOID FaultingVa;
  2649. } PSAPI_WS_WATCH_INFORMATION;
  2650. #define WORKING_SET_BUFFER_ENTRYS 4096
  2651. PSAPI_WS_WATCH_INFORMATION WorkingSetBuffer[WORKING_SET_BUFFER_ENTRYS];
  2652. typedef BOOL (WINAPI * InitializeProcessForWsWatchType) (
  2653.     HANDLE hProcess
  2654.     );
  2655. typedef BOOL (WINAPI * GetWsChangesType) (
  2656.     HANDLE hProcess,
  2657.     PSAPI_WS_WATCH_INFORMATION* lpWatchInfo,
  2658.     DWORD cb
  2659.     );
  2660. InitializeProcessForWsWatchType g_fpInitializeProcessForWsWatch = NULL;
  2661. GetWsChangesType                g_fpGetWsChanges = NULL;
  2662. HINSTANCE                       g_PSAPIHandle = NULL;
  2663. HANDLE                          g_hCurrentProcess = NULL;
  2664. BOOL                            g_bPrintChanges = FALSE;
  2665. BOOL                            g_bSetWsChangeHook = FALSE;
  2666. BOOL                            g_bLockLikeACrazyMan = TRUE;
  2667. CHXMapPtrToPtr                  g_mWorkingSetMap;
  2668. int                             g_LockedPages = 0;
  2669. int                             g_totalFaults = 0;
  2670. int                             g_AttemptedLockedPages = 0;
  2671. int                             g_FailedLockedPages = 0;
  2672. void GetChangesToWorkingSet()
  2673. {
  2674.     int   count = 0;
  2675.     if (!g_hCurrentProcess)
  2676.     {
  2677.         g_hCurrentProcess = GetCurrentProcess();
  2678.         // check to see if we want to print data
  2679.         HKEY    hKey;
  2680.         char    szKeyName[256]; /* Flawfinder: ignore */
  2681.         long    szValueSize = 1024;
  2682.         char    szValue[1024]; /* Flawfinder: ignore */
  2683.         g_bLockLikeACrazyMan = FALSE;
  2684.         SafeSprintf(szKeyName, 256, "Software\%s\Debug\LockLikeCrazy", HXVER_COMMUNITY);
  2685.         if( RegOpenKey(HKEY_CLASSES_ROOT, szKeyName, &hKey) == ERROR_SUCCESS )
  2686.         {
  2687.             RegQueryValue(hKey, "", szValue, (long *)&szValueSize);
  2688.             g_bLockLikeACrazyMan = !strcmp(szValue,"1");
  2689.             RegCloseKey(hKey);
  2690.         }
  2691.         else
  2692.         {
  2693.             RegCreateKey(HKEY_CLASSES_ROOT, szKeyName, &hKey);
  2694.             RegCloseKey(hKey);
  2695.         }
  2696.         g_bSetWsChangeHook = FALSE;
  2697.         SafeSprintf(szKeyName, 256, "Software\%s\Debug\SetWsHook", HXVER_COMMUNITY);
  2698.         if( RegOpenKey(HKEY_CLASSES_ROOT, szKeyName, &hKey) == ERROR_SUCCESS )
  2699.         {
  2700.             RegQueryValue(hKey, "", szValue, (long *)&szValueSize);
  2701.             g_bSetWsChangeHook = !strcmp(szValue,"1");
  2702.             RegCloseKey(hKey);
  2703.         }
  2704.         else
  2705.         {
  2706.             RegCreateKey(HKEY_CLASSES_ROOT, szKeyName, &hKey);
  2707.             RegCloseKey(hKey);
  2708.         }
  2709.         if (g_bSetWsChangeHook)
  2710.         {
  2711.             if (g_bLockLikeACrazyMan)
  2712.             {
  2713.                 BOOL setProcessWorkingSize = SetProcessWorkingSetSize(g_hCurrentProcess, (1<<23), (1<<24) );
  2714.             }
  2715.             g_PSAPIHandle = LoadLibrary("psapi.dll");
  2716.             if (g_PSAPIHandle)
  2717.             {
  2718.                 g_fpInitializeProcessForWsWatch = (InitializeProcessForWsWatchType) GetProcAddress(g_PSAPIHandle, "InitializeProcessForWsWatch");
  2719.                 g_fpGetWsChanges = (GetWsChangesType) GetProcAddress(g_PSAPIHandle, "GetWsChanges");
  2720.             }
  2721.             BOOL initRetVal = g_fpInitializeProcessForWsWatch(g_hCurrentProcess);
  2722.         }
  2723.         // check to see if we want to print data
  2724.         SafeSprintf(szKeyName, 256, "Software\%s\Debug\PrintFaults", HXVER_COMMUNITY);
  2725.         if( RegOpenKey(HKEY_CLASSES_ROOT, szKeyName, &hKey) == ERROR_SUCCESS )
  2726.         {
  2727.             RegQueryValue(hKey, "", szValue, (long *)&szValueSize);
  2728.             g_bPrintChanges = !strcmp(szValue,"1");
  2729.             RegCloseKey(hKey);
  2730.         }
  2731.         else
  2732.         {
  2733.             RegCreateKey(HKEY_CLASSES_ROOT, szKeyName, &hKey);
  2734.             RegCloseKey(hKey);
  2735.         }
  2736.     }
  2737.     BOOL b = FALSE;
  2738.     if (g_fpGetWsChanges)
  2739.     {
  2740.         b = g_fpGetWsChanges(g_hCurrentProcess,&WorkingSetBuffer[0],sizeof(WorkingSetBuffer));
  2741.     }
  2742.     if ( b )
  2743.     {
  2744.         int i = 0;
  2745.         while (WorkingSetBuffer[i].FaultingPc)
  2746.         {
  2747.             void* Pc = WorkingSetBuffer[i].FaultingPc;
  2748.             void* Va = WorkingSetBuffer[i].FaultingVa;
  2749.             void* VaPage = (void*) ((ULONG)Va & 0xfffff000);
  2750.             g_totalFaults++;
  2751.             Va = (LPVOID)( (ULONG)Va & 0xfffffffe);
  2752.             count = 0;
  2753.             g_mWorkingSetMap.Lookup(VaPage, (void*&)count);
  2754.             count++;
  2755.             g_mWorkingSetMap.SetAt(VaPage, (void*)count);
  2756.             if (count==50 && g_bLockLikeACrazyMan)
  2757.             {
  2758.                 g_AttemptedLockedPages++;
  2759. #if 0 /* do not attempt to lock - RA */
  2760.                 BOOL bRetVal = VirtualLock(VaPage, 4096);
  2761.                 if (!bRetVal)
  2762.                 {
  2763.                     DWORD lastError = GetLastError();
  2764.                     void* lpMsgBuf;
  2765.                     FormatMessage(  FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
  2766.                                     NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL );
  2767.                     LocalFree( lpMsgBuf );
  2768.                     g_FailedLockedPages++;
  2769.                 }
  2770.                 else
  2771.                 {
  2772.                     g_LockedPages++;
  2773.                 }
  2774. #endif
  2775.             }
  2776.             i++;
  2777.         }
  2778.     }
  2779. }
  2780. #endif
  2781. #endif