perscmgr.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:33k
源码类别:

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: perscmgr.cpp,v 1.9.8.2 2004/07/13 21:14:15 ehodge Exp $
  3.  * 
  4.  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
  5.  * 
  6.  * The contents of this file, and the files included with this file,
  7.  * are subject to the current version of the RealNetworks Public
  8.  * Source License (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the current version of the RealNetworks Community
  11.  * Source License (the "RCSL") available at
  12.  * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
  13.  * will apply. You may also obtain the license terms directly from
  14.  * RealNetworks.  You may not use this file except in compliance with
  15.  * the RPSL or, if you have a valid RCSL with RealNetworks applicable
  16.  * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
  17.  * the rights, obligations and limitations governing use of the
  18.  * contents of the file.
  19.  * 
  20.  * Alternatively, the contents of this file may be used under the
  21.  * terms of the GNU General Public License Version 2 or later (the
  22.  * "GPL") in which case the provisions of the GPL are applicable
  23.  * instead of those above. If you wish to allow use of your version of
  24.  * this file only under the terms of the GPL, and not to allow others
  25.  * to use your version of this file under the terms of either the RPSL
  26.  * or RCSL, indicate your decision by deleting the provisions above
  27.  * and replace them with the notice and other provisions required by
  28.  * the GPL. If you do not delete the provisions above, a recipient may
  29.  * use your version of this file under the terms of any one of the
  30.  * RPSL, the RCSL or the GPL.
  31.  * 
  32.  * This file is part of the Helix DNA Technology. RealNetworks is the
  33.  * developer of the Original Code and owns the copyrights in the
  34.  * portions it created.
  35.  * 
  36.  * This file, and the files included with this file, is distributed
  37.  * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
  38.  * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
  39.  * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
  40.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
  41.  * ENJOYMENT OR NON-INFRINGEMENT.
  42.  * 
  43.  * Technology Compatibility Kit Test Suite(s) Location:
  44.  *    http://www.helixcommunity.org/content/tck
  45.  * 
  46.  * Contributor(s):
  47.  * 
  48.  * ***** END LICENSE BLOCK ***** */
  49. #include "hxcom.h"
  50. #include "hxresult.h"
  51. #include "hxstrutl.h"
  52. #include "hxstring.h"
  53. #include "hxmap.h"
  54. #include "smiltype.h"
  55. #include "hxausvc.h"
  56. #include "hxengin.h"
  57. #include "hxcore.h"
  58. #include "hxgroup.h"
  59. #include "basgroup.h"
  60. #include "advgroup.h"
  61. #include "hxplay.h"
  62. #include "hxbsrc.h"
  63. #include "hxsrc.h"
  64. #include "hxplugn.h"
  65. #include "hxrendr.h"
  66. #include "srcinfo.h"
  67. #include "sitemgr.h"
  68. #include "perscmgr.h"
  69. #include "hxheap.h"
  70. #ifdef _DEBUG
  71. #undef HX_THIS_FILE
  72. static const char HX_THIS_FILE[] = __FILE__;
  73. #endif
  74. HXPersistentComponent::HXPersistentComponent(HXPersistentComponentManager* pManager)
  75.     : m_lRefCount(0)
  76.     , m_bInitialized(FALSE)
  77.     , m_bToBeClosed(FALSE)
  78.     , m_bCleanupLayoutCalled(FALSE)
  79.     , m_uGroups(0)
  80.     , m_uTracks(0)
  81.     , m_ulComponentID(0)
  82.     , m_pSourceInfo(NULL)
  83.     , m_pPersistentRenderer(NULL)
  84.     , m_pRendererAdviseSink(NULL)
  85.     , m_pGroupSink(NULL)
  86.     , m_pComponentManager(NULL)
  87.     , m_pPersistentParent(NULL)
  88.     , m_pPersistentChildList(NULL)
  89.     , m_pProperties(NULL)
  90.     , m_ulPersistentType(0)
  91. {
  92.     m_pComponentManager = pManager;    
  93.     HX_ADDREF(m_pComponentManager);
  94. }
  95. HXPersistentComponent::~HXPersistentComponent(void)
  96. {
  97.     Remove();
  98.     HX_DELETE(m_pPersistentChildList);
  99.     HX_RELEASE(m_pPersistentParent);
  100.     HX_RELEASE(m_pComponentManager);
  101. }
  102. /*
  103.  *  IUnknown methods
  104.  */
  105. STDMETHODIMP HXPersistentComponent::QueryInterface(REFIID riid, void** ppvObj)
  106. {
  107.     QInterfaceList qiList[] =
  108.         {
  109.             { GET_IIDHANDLE(IID_IHXPersistentComponent), (IHXPersistentComponent*)this },
  110.             { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXPersistentComponent*)this },
  111.         };
  112.     
  113.     return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
  114. }
  115. STDMETHODIMP_(ULONG32) HXPersistentComponent::AddRef()
  116. {
  117.     return InterlockedIncrement(&m_lRefCount);
  118. }
  119. STDMETHODIMP_(ULONG32) HXPersistentComponent::Release()
  120. {
  121.     if (InterlockedDecrement(&m_lRefCount) > 0)
  122.     {
  123.         return m_lRefCount;
  124.     }
  125.     delete this;
  126.     return 0;
  127. }
  128. /************************************************************************
  129.  * Method:
  130.  *     IHXPersistentComponent::Init
  131.  * Purpose:
  132.  *     initialize persistent component
  133.  */
  134. STDMETHODIMP
  135. HXPersistentComponent::Init(IHXPersistentRenderer* pPersistentRenderer)
  136. {
  137.     m_bInitialized = TRUE;
  138.     m_pPersistentRenderer = pPersistentRenderer;
  139.     HX_ADDREF(m_pPersistentRenderer);
  140.     return HXR_OK;
  141. }
  142. /************************************************************************
  143.  * Method:
  144.  *     IHXPersistentComponent::AddRendererAdviseSink
  145.  * Purpose:
  146.  *     add renderer advise sink
  147.  */
  148. STDMETHODIMP
  149. HXPersistentComponent::AddRendererAdviseSink(IHXRendererAdviseSink* pSink)
  150. {
  151.     m_pRendererAdviseSink = pSink;
  152.     HX_ADDREF(m_pRendererAdviseSink);
  153.     return HXR_OK;
  154. }
  155. /************************************************************************
  156.  * Method:
  157.  *     IHXPersistentComponent::RemoveRendererAdviseSink
  158.  * Purpose:
  159.  *     remove renderer advise sink
  160.  */
  161. STDMETHODIMP
  162. HXPersistentComponent::RemoveRendererAdviseSink(IHXRendererAdviseSink* pSink)
  163. {    
  164.     HX_RELEASE(m_pRendererAdviseSink);
  165.     return HXR_OK;
  166. }
  167. /************************************************************************
  168.  * Method:
  169.  *     IHXPersistentComponent::AddGroupSink
  170.  * Purpose:
  171.  *     add renderer advise sink
  172.  */
  173. STDMETHODIMP
  174. HXPersistentComponent::AddGroupSink(IHXGroupSink* pSink)
  175. {
  176.     m_pGroupSink = pSink;
  177.     HX_ADDREF(m_pGroupSink);
  178.     return HXR_OK;
  179. }
  180. /************************************************************************
  181.  * Method:
  182.  *     IHXPersistentComponent::RemoveGroupSink
  183.  * Purpose:
  184.  *     remove renderer advise sink
  185.  */
  186. STDMETHODIMP
  187. HXPersistentComponent::RemoveGroupSink(IHXGroupSink* pSink)
  188. {
  189.     HX_RELEASE(m_pGroupSink);
  190.     return HXR_OK;
  191. }
  192. /************************************************************************
  193.  * Method:
  194.  *     IHXPersistentComponent::GetPersistentRenderer
  195.  * Purpose:
  196.  *     get persistent renderer
  197.  */
  198. STDMETHODIMP
  199. HXPersistentComponent::GetPersistentRenderer(REF(IHXPersistentRenderer*) pPersistentRenderer)
  200. {
  201.     HX_RESULT rc = HXR_OK;
  202.     pPersistentRenderer = m_pPersistentRenderer;
  203.     HX_ADDREF(pPersistentRenderer);
  204.     return rc;
  205. }
  206.     
  207. /************************************************************************
  208.  * Method:
  209.  *     IHXPersistentComponent::GetPersistentProperties
  210.  * Purpose:
  211.  *     get persistent component properties
  212.  */
  213. STDMETHODIMP
  214. HXPersistentComponent::GetPersistentProperties(REF(IHXValues*) pProperties)
  215. {
  216.     pProperties = m_pProperties;
  217.     if (pProperties)
  218.     {
  219. pProperties->AddRef();
  220. return HXR_OK;
  221.     }
  222.     return HXR_FAILED;
  223. }
  224. HX_RESULT
  225. HXPersistentComponent::GetPersistentComponent(UINT32 ulComponentID, 
  226.        REF(IHXPersistentComponent*) pComponent)
  227. {
  228.     HX_RESULT     rc = HXR_FAILED;
  229.     HXPersistentComponent* pHXPersistentComponent = NULL;
  230.     CHXSimpleList::Iterator i;
  231.     pComponent = NULL;
  232.     if (m_ulComponentID == ulComponentID)
  233.     {
  234. QueryInterface(IID_IHXPersistentComponent, (void**)&pComponent);
  235. rc = HXR_OK;
  236.     }
  237.     else if (m_pPersistentChildList)
  238.     {
  239. for(i = m_pPersistentChildList->Begin();i != m_pPersistentChildList->End();++i)
  240. {
  241.     pHXPersistentComponent = (HXPersistentComponent*)(*i);
  242.     rc = pHXPersistentComponent->GetPersistentComponent(ulComponentID, pComponent);
  243.     if (HXR_OK == rc && pComponent)
  244.     {
  245. break;
  246.     }
  247. }
  248.     }
  249.     return rc;
  250. }
  251. HX_RESULT
  252. HXPersistentComponent::CurrentGroupSet(UINT16 uGroupIndex, IHXGroup* pGroup)
  253. {
  254.     HX_RESULT     rc = HXR_OK;
  255.     HXPersistentComponent* pHXPersistentComponent = NULL;
  256.     CHXSimpleList::Iterator i;
  257.     if (m_pPersistentChildList)
  258.     {
  259. for(i = m_pPersistentChildList->Begin();i != m_pPersistentChildList->End();++i)
  260. {
  261.     pHXPersistentComponent = (HXPersistentComponent*)(*i);
  262.     rc = pHXPersistentComponent->CurrentGroupSet(uGroupIndex, pGroup);
  263. }
  264.     }
  265.     m_pSourceInfo->Reset();
  266.     if (m_pGroupSink)
  267.     {
  268. rc = m_pGroupSink->CurrentGroupSet(uGroupIndex, pGroup);
  269.     }
  270.     return rc;
  271. }
  272. HX_RESULT
  273. HXPersistentComponent::OnTimeSync(UINT32 ulCurrentTime)
  274. {
  275.     HX_RESULT     rc = HXR_OK;
  276.     HXPersistentComponent* pHXPersistentComponent = NULL;
  277.     CHXSimpleList::Iterator i;
  278.     if (m_pPersistentChildList)
  279.     {
  280. for(i = m_pPersistentChildList->Begin();i != m_pPersistentChildList->End();++i)
  281. {
  282.     pHXPersistentComponent = (HXPersistentComponent*)(*i);
  283.     rc = pHXPersistentComponent->OnTimeSync(ulCurrentTime);
  284. }
  285.     }
  286.     if (m_pSourceInfo)
  287.     {
  288. m_pSourceInfo->OnTimeSync(ulCurrentTime);
  289.     }
  290.    return rc;
  291. }
  292. UINT32
  293. HXPersistentComponent::GetPersistentComponentCount()
  294. {
  295.     UINT32 ulTotalCount = 0;
  296.     HXPersistentComponent* pHXPersistentComponent = NULL;
  297.     CHXSimpleList::Iterator i;
  298.     if (m_pPersistentChildList)
  299.     {
  300. for(i = m_pPersistentChildList->Begin();i != m_pPersistentChildList->End();++i)
  301. {
  302.     pHXPersistentComponent = (HXPersistentComponent*)(*i);
  303.     ulTotalCount += pHXPersistentComponent->GetPersistentComponentCount();
  304. }
  305.     }
  306.     return (ulTotalCount + 1);
  307. }
  308. void
  309. HXPersistentComponent::TrackUpdated(UINT16 uGroupIndex, 
  310.      UINT16 uTrackIndex, 
  311.      IHXValues* pValues)
  312. {
  313.     HX_RESULT     rc = HXR_OK;
  314.     HXPersistentComponent* pHXPersistentComponent = NULL;
  315.     CHXSimpleList::Iterator i;
  316.     if (m_pPersistentChildList)
  317.     {
  318. for(i = m_pPersistentChildList->Begin();i != m_pPersistentChildList->End();++i)
  319. {
  320.     pHXPersistentComponent = (HXPersistentComponent*)(*i);
  321.     pHXPersistentComponent->TrackUpdated(uGroupIndex, uTrackIndex, pValues);
  322. }
  323.     }
  324.     if (m_pRendererAdviseSink)
  325.     {
  326. m_pRendererAdviseSink->TrackUpdated(uGroupIndex, uTrackIndex, pValues);
  327.     }
  328.     return;
  329. }
  330. void
  331. HXPersistentComponent::AllRenderersClosed(void)
  332. {
  333.     HX_RESULT     rc = HXR_OK;
  334.     HXPersistentComponent* pHXPersistentComponent = NULL;
  335.     CHXSimpleList::Iterator i;
  336.     if (m_pPersistentChildList)
  337.     {
  338. for(i = m_pPersistentChildList->Begin();i != m_pPersistentChildList->End();++i)
  339. {
  340.     pHXPersistentComponent = (HXPersistentComponent*)(*i);
  341.     pHXPersistentComponent->AllRenderersClosed();
  342. }
  343.     }
  344.     if (m_pSourceInfo)
  345.     {
  346. m_pSourceInfo->Reset();
  347.     }
  348.     return;
  349. }
  350. void
  351. HXPersistentComponent::Reset(void)
  352. {
  353.     HXPersistentComponent* pHXPersistentComponent = NULL;
  354.     CHXSimpleList::Iterator i;
  355.     if (m_pPersistentChildList)
  356.     {
  357. for(i = m_pPersistentChildList->Begin();i != m_pPersistentChildList->End();++i)
  358. {
  359.     pHXPersistentComponent = (HXPersistentComponent*)(*i);
  360.     pHXPersistentComponent->Reset();
  361. }
  362.     }
  363.     m_pComponentManager->m_pPlayer->m_pSourceMap->RemoveKey(m_pSourceInfo->m_pSource);
  364.     m_pComponentManager->m_pPlayer->m_bSourceMapUpdated = TRUE;
  365.     m_pSourceInfo->m_bIsPersistentSource = FALSE;
  366.     m_pSourceInfo->Stop();
  367.     m_bToBeClosed = TRUE;
  368.     return;
  369. }
  370. void
  371. HXPersistentComponent::Remove()
  372. {
  373.     HXPersistentComponent* pHXPersistentComponent = NULL;
  374.     CHXSimpleList::Iterator i;
  375.     if (m_pPersistentChildList)
  376.     {
  377. for(i = m_pPersistentChildList->Begin();i != m_pPersistentChildList->End();++i)
  378. {
  379.     pHXPersistentComponent = (HXPersistentComponent*)(*i);
  380.     pHXPersistentComponent->Remove();
  381.     HX_RELEASE(pHXPersistentComponent);
  382. }
  383. m_pPersistentChildList->RemoveAll();
  384.     }
  385.     
  386.     if (m_pSourceInfo)
  387.     {
  388. HX_ASSERT(!m_pSourceInfo->m_bIsPersistentSource);
  389. m_pSourceInfo->CloseRenderers();
  390. HX_DELETE(m_pSourceInfo);
  391.     }
  392.     HX_RELEASE(m_pProperties);
  393.     HX_RELEASE(m_pRendererAdviseSink);
  394.     HX_RELEASE(m_pGroupSink);
  395.     HX_RELEASE(m_pPersistentRenderer);
  396.     return;
  397. }
  398. HXPersistentComponentManager::HXPersistentComponentManager(HXPlayer* pPlayer)
  399.     : m_lRefCount(0)
  400.     , m_ulComponentIndex(0)
  401.     , m_nCurrentGroup(0)
  402.     , m_pPlayer(pPlayer)
  403.     , m_pRootPersistentComponent(NULL)
  404. {
  405.     HX_ADDREF(m_pPlayer);
  406. }
  407. HXPersistentComponentManager::~HXPersistentComponentManager(void)
  408. {
  409.     Close();
  410.     HX_RELEASE(m_pPlayer);
  411. }
  412. /*
  413.  *  IUnknown methods
  414.  */
  415. STDMETHODIMP HXPersistentComponentManager::QueryInterface(REFIID riid, void** ppvObj)
  416. {
  417.     QInterfaceList qiList[] =
  418.         {
  419.             { GET_IIDHANDLE(IID_IHXPersistentComponentManager), (IHXPersistentComponentManager*)this },
  420.             { GET_IIDHANDLE(IID_IHXGroupSink), (IHXGroupSink*)this },
  421.             { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXPersistentComponentManager*)this },
  422.         };
  423.     
  424.     return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
  425. }
  426. STDMETHODIMP_(ULONG32) HXPersistentComponentManager::AddRef()
  427. {
  428.     return InterlockedIncrement(&m_lRefCount);
  429. }
  430. STDMETHODIMP_(ULONG32) HXPersistentComponentManager::Release()
  431. {
  432.     if (InterlockedDecrement(&m_lRefCount) > 0)
  433.     {
  434.         return m_lRefCount;
  435.     }
  436.     delete this;
  437.     return 0;
  438. }
  439. /************************************************************************
  440.  * Method:
  441.  *     IHXPersistentComponentManager::CreatePersistentComponent
  442.  * Purpose:
  443.  *     create persistent component
  444.  */
  445. STDMETHODIMP
  446. HXPersistentComponentManager::CreatePersistentComponent(REF(IHXPersistentComponent*)   pPersistentComponent)
  447. {
  448.     pPersistentComponent = new HXPersistentComponent(this);    
  449.     if (!pPersistentComponent)
  450.     {
  451. return HXR_OUTOFMEMORY;
  452.     }
  453.     
  454.     return HXR_OK;
  455. }
  456. /************************************************************************
  457.  * Method:
  458.  *     IHXPersistentComponentManager::AddPersistentComponent
  459.  * Purpose:
  460.  *     add persistent component
  461.  */
  462. STDMETHODIMP
  463. HXPersistentComponentManager::AddPersistentComponent(IHXPersistentComponent* pPersistentComponent)
  464. {
  465.     HX_RESULT rc = HXR_OK;
  466.     BOOL bFound = FALSE;
  467.     HXSource* pSource = NULL;
  468.     SourceInfo* pSourceInfo = NULL;
  469.     RendererInfo* pRendInfo = NULL;
  470.     HXPersistentComponent* pHXPersistentComponent = NULL;
  471.     HXPersistentComponent* pHXPersistentParentComponent = NULL;
  472.     IHXValues* pProperties = NULL;
  473.     IHXGroup* pGroup = NULL;
  474.     IHXPersistentComponent* pPersistentParentComponent = NULL;
  475.     IHXPersistentRenderer* pPersistentRenderer = NULL;
  476.     IHXRenderer* pRenderer = NULL;    
  477.     CHXMapPtrToPtr::Iterator ndxSource;
  478.     CHXMapLongToObj::Iterator ndxRend;
  479.     
  480.     pHXPersistentComponent = (HXPersistentComponent*)pPersistentComponent;
  481.     if (!pHXPersistentComponent || !pHXPersistentComponent->m_bInitialized)
  482.     {
  483. rc = HXR_FAILED;
  484. goto cleanup;
  485.     }
  486.     pPersistentRenderer = pHXPersistentComponent->m_pPersistentRenderer;
  487.     if (HXR_OK != pPersistentRenderer->QueryInterface(IID_IHXRenderer, (void**)&pRenderer))
  488.     {
  489. rc = HXR_INVALID_PARAMETER;
  490. goto cleanup;
  491.     }
  492.     // find component's source info - better way?
  493.     ndxSource = m_pPlayer->m_pSourceMap->Begin();
  494.     for (; ndxSource != m_pPlayer->m_pSourceMap->End() && !bFound; ++ndxSource)
  495.     {
  496. pSourceInfo = (SourceInfo*)(*ndxSource);
  497. pSource = pSourceInfo->m_pSource;
  498. ndxRend = pSourceInfo->m_pRendererMap->Begin();
  499. for (; ndxRend != pSourceInfo->m_pRendererMap->End(); ++ndxRend)
  500. {
  501.     pRendInfo = (RendererInfo*) (*ndxRend);
  502.     if (pRendInfo->m_pRenderer == pRenderer)
  503.     {
  504. bFound = TRUE;
  505. break;
  506.     }
  507. }
  508.     }
  509.     if (!bFound)
  510.     {
  511. rc = HXR_FAILED;
  512. goto cleanup;
  513.     }
  514.     if (!m_pRootPersistentComponent)
  515.     {
  516. m_ulComponentIndex = 0;
  517. m_pRootPersistentComponent = pHXPersistentComponent;
  518. m_pRootPersistentComponent->AddRef();
  519. // XXX HP TBD - when we support timing attributes on a SMIL URL
  520. // for now, we resets all timing attributes on the root persistent
  521. // component since there could be a case when the same timing values
  522. // are specified in a CGI URL sent to the player
  523. if (pSourceInfo && pSourceInfo->m_pSource)
  524. {     
  525.     IHXValues* pValues = new CHXHeader();
  526.     pValues->AddRef();
  527.     pValues->SetPropertyULONG32("Start", 0);
  528.     pValues->SetPropertyULONG32("End", 0);
  529.     pValues->SetPropertyULONG32("Delay", 0);
  530.     pValues->SetPropertyULONG32("Duration", 0);
  531.     pSourceInfo->m_pSource->UpdatePlayTimes(pValues);
  532.     HX_RELEASE(pValues);
  533. }     
  534.     }
  535.     else if (HXR_OK == GetPersistentComponent(pSourceInfo->m_ulPersistentComponentID, pPersistentParentComponent))
  536.     {
  537. pHXPersistentParentComponent = (HXPersistentComponent*)pPersistentParentComponent;
  538. // XXX HP 
  539. // to workaround the screwed-up layout handling within nested meta, we call
  540. // CleanupLayout() on the alternated persistent source if we haven't called 
  541. // CleanupLayout() yet. this is a no-worse-than-before temporary solution.
  542. // REMOVE THIS AFTER PROPERLY HANDLING LAYOUT WITHIN NESTED META
  543. if (pSourceInfo->m_bAltURL && !pHXPersistentParentComponent->m_bCleanupLayoutCalled)
  544. {
  545.     m_pPlayer->CleanupLayout();
  546.     pHXPersistentParentComponent->m_bCleanupLayoutCalled = TRUE;
  547. }
  548. if (!pHXPersistentParentComponent->m_pPersistentChildList)
  549. {
  550.     pHXPersistentParentComponent->m_pPersistentChildList = new CHXSimpleList();
  551. }
  552.     
  553. pHXPersistentParentComponent->m_pPersistentChildList->AddTail(pHXPersistentComponent);
  554. pHXPersistentComponent->AddRef();
  555. pHXPersistentComponent->m_pPersistentParent = pHXPersistentParentComponent;
  556. pHXPersistentParentComponent->AddRef();
  557.     }
  558.     pSourceInfo->m_bIsPersistentSource = TRUE;
  559.     if (HXR_OK == pHXPersistentComponent->m_pPersistentRenderer->GetPersistentProperties(pProperties))
  560.     {
  561. pProperties->GetPropertyULONG32("PersistentType", pHXPersistentComponent->m_ulPersistentType);
  562.     }
  563.     HX_RELEASE(pProperties);
  564.     pSourceInfo->m_ulPersistentComponentSelfID = m_ulComponentIndex;
  565.     // new persistent info
  566.     pHXPersistentComponent->m_pSourceInfo = pSourceInfo;
  567.     pHXPersistentComponent->m_ulComponentID = m_ulComponentIndex;
  568.     // get the persistent properties(track properties)
  569.     if (HXR_OK == m_pPlayer->m_pGroupManager->GetGroup(pSourceInfo->m_uGroupID, pGroup))
  570.     {
  571. pGroup->GetTrack(pSourceInfo->m_uTrackID, pHXPersistentComponent->m_pProperties);
  572.     }
  573.     HX_RELEASE(pGroup);
  574.     pPersistentRenderer->InitPersistent(m_ulComponentIndex, 
  575. pSourceInfo->m_uGroupID,
  576. pSourceInfo->m_uTrackID,
  577. pHXPersistentParentComponent?pHXPersistentParentComponent->m_pPersistentRenderer:((IHXPersistentRenderer*) NULL));
  578.     m_ulComponentIndex++;
  579.     m_pPlayer->m_pGroupManager->PersistentComponentAdded(pSourceInfo->m_uGroupID, pSourceInfo->m_uTrackID);
  580. cleanup:
  581.     HX_RELEASE(pPersistentParentComponent);
  582.     HX_RELEASE(pRenderer);
  583.     return rc;
  584. }
  585. /************************************************************************
  586.  * Method:
  587.  *     IHXPersistentComponentManager::RemovePersistentComponent
  588.  * Purpose:
  589.  *     remove persistent component
  590.  */
  591. STDMETHODIMP
  592. HXPersistentComponentManager::RemovePersistentComponent(UINT32 ulPersistentComponentID)
  593. {
  594.     HX_RESULT rc = HXR_OK;
  595.     LISTPOSITION lPosition = NULL;
  596.     HXPersistentComponent* pHXPersistentParentComponent = NULL;
  597.     HXPersistentComponent* pHXPersistentComponent = NULL;
  598.     IHXPersistentComponent* pPersistentComponent = NULL;
  599.     if (HXR_OK == GetPersistentComponent(ulPersistentComponentID, pPersistentComponent))
  600.     {
  601. pHXPersistentComponent = (HXPersistentComponent*)pPersistentComponent;
  602. pHXPersistentParentComponent = pHXPersistentComponent->m_pPersistentParent;
  603. if (pHXPersistentParentComponent)
  604. {
  605.     pHXPersistentComponent->Remove();
  606.     HX_ASSERT(pHXPersistentParentComponent->m_pPersistentChildList &&
  607.       pHXPersistentParentComponent->m_pPersistentChildList->GetCount());
  608.     lPosition = pHXPersistentParentComponent->m_pPersistentChildList->Find(pHXPersistentComponent);
  609.     HX_ASSERT(lPosition);
  610.     pHXPersistentParentComponent->m_pPersistentChildList->RemoveAt(lPosition);
  611.     HX_RELEASE(pHXPersistentComponent);
  612. }
  613.     }
  614.     HX_RELEASE(pPersistentComponent);
  615.     if (m_pRootPersistentComponent  &&
  616. m_pRootPersistentComponent->m_ulComponentID == ulPersistentComponentID)
  617.     {
  618. HX_RELEASE(m_pRootPersistentComponent);
  619.     }
  620.     return rc;
  621. }
  622. /************************************************************************
  623.  * Method:
  624.  *     IHXPersistentComponentManager::GetPersistentComponent
  625.  * Purpose:
  626.  *     get persistent component information
  627.  */
  628. STDMETHODIMP
  629. HXPersistentComponentManager::GetPersistentComponent(UINT32     ulPersistentComponentID,
  630.       REF(IHXPersistentComponent*) pPersistentComponent)
  631. {
  632.     HX_RESULT rc = HXR_FAILED;
  633.     pPersistentComponent = NULL;
  634.     if (m_pRootPersistentComponent)
  635.     {
  636. rc = m_pRootPersistentComponent->GetPersistentComponent(ulPersistentComponentID, pPersistentComponent);
  637.     }
  638.     return rc;
  639. }
  640. /************************************************************************
  641.  * Method:
  642.  *     IHXPersistentComponentManager::AttachPersistentComponentLayout
  643.  * Purpose:
  644.  *     get persistent component information
  645.  */
  646. STDMETHODIMP
  647. HXPersistentComponentManager::AttachPersistentComponentLayout(IUnknown*    pLSG,
  648.        IHXValues*  pProps)
  649. {
  650.     HX_RESULT     rc = HXR_OK;
  651.     IHXSiteUser*   pSiteUser = NULL;
  652.     if (m_pPlayer)
  653.     {
  654. #if defined(HELIX_FEATURE_VIDEO)
  655.         if (HXR_OK == pLSG->QueryInterface(IID_IHXSiteUser, (void**)&pSiteUser))
  656. {
  657.     rc = m_pPlayer->m_pSiteManager->HookupSingleSiteByPlayToFrom(pSiteUser, pProps, FALSE);
  658. }
  659. HX_RELEASE(pSiteUser);
  660. #endif //HELIX_FEATURE_VIDEO
  661.     }
  662.     return rc;
  663. }
  664. /************************************************************************
  665. *  Method:
  666. *      IHXGroupSink::GroupAdded
  667. *  Purpose:
  668. * Notification of a new group being added to the presentation.
  669. */
  670. STDMETHODIMP
  671. HXPersistentComponentManager::GroupAdded(UINT16 /*IN*/ uGroupIndex,
  672.   IHXGroup* /*IN*/ pGroup)
  673. {
  674.     HX_RESULT rc = HXR_OK;
  675.     UINT32 ulPersistentComponentID = 0;
  676.     IHXValues* pProperties = NULL;
  677.     IHXGroupSink* pGroupSink = NULL;
  678.     IHXPersistentComponent* pPersistentComponent = NULL;
  679.     pProperties = pGroup->GetGroupProperties();
  680.     if (pProperties)
  681.     {
  682. if (HXR_OK == pProperties->GetPropertyULONG32("PersistentComponentID", ulPersistentComponentID))
  683. {
  684.     if (HXR_OK == GetPersistentComponent(ulPersistentComponentID, pPersistentComponent))
  685.     {
  686. pGroupSink = ((HXPersistentComponent*)pPersistentComponent)->m_pGroupSink;
  687. if (pGroupSink)
  688. {
  689.     pGroupSink->GroupAdded(uGroupIndex, pGroup);
  690. }
  691.     }
  692.     HX_RELEASE(pPersistentComponent);
  693. }
  694.     }
  695.     HX_RELEASE(pProperties);
  696.     return rc;
  697. }
  698. /************************************************************************
  699. *  Method:
  700. *      IHXGroupSink::GroupRemoved
  701. *  Purpose:
  702. * Notification of a group being removed from the presentation.
  703. */
  704. STDMETHODIMP
  705. HXPersistentComponentManager::GroupRemoved(UINT16 /*IN*/ uGroupIndex,
  706.     IHXGroup*  /*IN*/ pGroup)
  707. {
  708.     HX_RESULT rc = HXR_OK;
  709.     UINT32 ulPersistentComponentID = 0;
  710.     IHXValues* pProperties = NULL;
  711.     IHXGroupSink* pGroupSink = NULL;
  712.     IHXPersistentComponent* pPersistentComponent = NULL;
  713.     pProperties = pGroup->GetGroupProperties();
  714.     if (pProperties)
  715.     {
  716. if (HXR_OK == pProperties->GetPropertyULONG32("PersistentComponentID", ulPersistentComponentID))
  717. {
  718.     if (HXR_OK == GetPersistentComponent(ulPersistentComponentID, pPersistentComponent))
  719.     {
  720. pGroupSink = ((HXPersistentComponent*)pPersistentComponent)->m_pGroupSink;
  721. if (pGroupSink)
  722. {
  723.     pGroupSink->GroupRemoved(uGroupIndex, pGroup);
  724. }
  725.     }
  726.     HX_RELEASE(pPersistentComponent);
  727. }
  728.     }
  729.     HX_RELEASE(pProperties);
  730.     return rc;
  731. }
  732. /************************************************************************
  733. *  Method:
  734. *      IHXGroupSink::AllGroupsRemoved
  735. *  Purpose:
  736. * Notification that all groups have been removed from the 
  737. * current presentation.
  738. */
  739. STDMETHODIMP
  740. HXPersistentComponentManager::AllGroupsRemoved(void)
  741. {
  742.     return HXR_OK;
  743. }
  744. /************************************************************************
  745. *  Method:
  746. *      IHXGroupSink::TrackAdded
  747. *  Purpose:
  748. * Notification of a new track being added to a group.
  749. */
  750. STDMETHODIMP
  751. HXPersistentComponentManager::TrackAdded(UINT16      /*IN*/ uGroupIndex,
  752.   UINT16      /*IN*/ uTrackIndex,
  753.   IHXValues*     /*IN*/ pTrack)
  754. {
  755.     HX_RESULT rc = HXR_OK;
  756.     UINT32 ulPersistentComponentID = 0;
  757.     IHXGroupSink* pGroupSink = NULL;
  758.     IHXPersistentComponent* pPersistentComponent = NULL;
  759.     UINT32                   bNotUsed = 0;
  760.     if (HXR_OK == pTrack->GetPropertyULONG32("PersistentComponentID", ulPersistentComponentID))
  761.     {
  762. if (HXR_OK == GetPersistentComponent(ulPersistentComponentID, pPersistentComponent))
  763. {
  764.     pGroupSink = ((HXPersistentComponent*)pPersistentComponent)->m_pGroupSink;
  765.     if (pGroupSink)
  766.     {
  767.             //If the persistant renderer isn't using groups don't call track added.
  768.             if (HXR_OK != pTrack->GetPropertyULONG32("NoGroupsPresent", bNotUsed))
  769.             {
  770.                 pGroupSink->TrackAdded(uGroupIndex, uTrackIndex, pTrack);
  771.             }
  772.             
  773.     }
  774. }
  775. HX_RELEASE(pPersistentComponent);
  776.     }
  777.     return rc;
  778. }
  779. /************************************************************************
  780. *  Method:
  781. *      IHXGroupSink::TrackRemoved
  782. *  Purpose:
  783. * Notification of a track being removed from a group.
  784. */
  785. STDMETHODIMP
  786. HXPersistentComponentManager::TrackRemoved(UINT16     /*IN*/ uGroupIndex,
  787.     UINT16      /*IN*/ uTrackIndex,
  788.     IHXValues*     /*IN*/ pTrack)
  789. {
  790.     HX_RESULT rc = HXR_OK;
  791.     UINT32 ulPersistentComponentID = 0;
  792.     IHXGroupSink* pGroupSink = NULL;
  793.     IHXPersistentComponent* pPersistentComponent = NULL;
  794.     if (HXR_OK == pTrack->GetPropertyULONG32("PersistentComponentID", ulPersistentComponentID))
  795.     {
  796. if (HXR_OK == GetPersistentComponent(ulPersistentComponentID, pPersistentComponent))
  797. {
  798.     pGroupSink = ((HXPersistentComponent*)pPersistentComponent)->m_pGroupSink;
  799.     if (pGroupSink)
  800.     {
  801. pGroupSink->TrackRemoved(uGroupIndex, uTrackIndex, pTrack);
  802.     }
  803. }
  804. HX_RELEASE(pPersistentComponent);
  805.     }
  806.     return rc;
  807. }
  808. /************************************************************************
  809. *  Method:
  810. *      IHXGroupSink::TrackStarted
  811. *  Purpose:
  812. * Notification of a track being started (to get duration, for
  813. * instance...)
  814. */
  815. STDMETHODIMP
  816. HXPersistentComponentManager::TrackStarted(UINT16     /*IN*/ uGroupIndex,
  817.     UINT16     /*IN*/ uTrackIndex,
  818.     IHXValues*     /*IN*/ pTrack)
  819. {
  820.     HX_RESULT rc = HXR_OK;
  821.     UINT32 ulPersistentComponentID = 0;
  822.     IHXGroupSink* pGroupSink = NULL;
  823.     IHXPersistentComponent* pPersistentComponent = NULL;
  824.     if (HXR_OK == pTrack->GetPropertyULONG32("PersistentComponentID", ulPersistentComponentID))
  825.     {
  826. if (HXR_OK == GetPersistentComponent(ulPersistentComponentID, pPersistentComponent))
  827. {
  828.     pGroupSink = ((HXPersistentComponent*)pPersistentComponent)->m_pGroupSink;
  829.     if (pGroupSink)
  830.     {
  831. pGroupSink->TrackStarted(uGroupIndex, uTrackIndex, pTrack);
  832.     }
  833. }
  834. HX_RELEASE(pPersistentComponent);
  835.     }
  836.     return rc;
  837. }
  838. /************************************************************************
  839. *  Method:
  840. *      IHXGroupSink::TrackStopped
  841. *  Purpose:
  842. * Notification of a track being stopped
  843. *
  844. */
  845. STDMETHODIMP
  846. HXPersistentComponentManager::TrackStopped(UINT16     /*IN*/ uGroupIndex,
  847.     UINT16     /*IN*/ uTrackIndex,
  848.     IHXValues*     /*IN*/ pTrack)
  849. {
  850.     HX_RESULT rc = HXR_OK;
  851.     UINT32 ulPersistentComponentID = 0;
  852.     IHXGroupSink* pGroupSink = NULL;
  853.     IHXPersistentComponent* pPersistentComponent = NULL;
  854.     if (HXR_OK == pTrack->GetPropertyULONG32("PersistentComponentID", ulPersistentComponentID))
  855.     {
  856. if (HXR_OK == GetPersistentComponent(ulPersistentComponentID, pPersistentComponent))
  857. {
  858.     pGroupSink = ((HXPersistentComponent*)pPersistentComponent)->m_pGroupSink;
  859.     if (pGroupSink)
  860.     {
  861. pGroupSink->TrackStopped(uGroupIndex, uTrackIndex, pTrack);
  862.     }
  863. }
  864. HX_RELEASE(pPersistentComponent);
  865.     }
  866.     return rc;
  867. }
  868. /************************************************************************
  869. *  Method:
  870. *      IHXGroupSink::CurrentGroupSet
  871. *  Purpose:
  872. * This group is being currently played in the presentation.
  873. */
  874. STDMETHODIMP
  875. HXPersistentComponentManager::CurrentGroupSet(UINT16     /*IN*/ uGroupIndex,
  876.        IHXGroup*   /*IN*/ pGroup)
  877. {
  878.     HX_RESULT rc = HXR_OK;
  879.     m_nCurrentGroup = uGroupIndex;
  880.     if (m_pRootPersistentComponent)
  881.     {
  882. rc = m_pRootPersistentComponent->CurrentGroupSet(uGroupIndex, pGroup);
  883.     }
  884.     return rc;
  885. }
  886. HX_RESULT
  887. HXPersistentComponentManager::OnTimeSync(ULONG32 ulCurrentTime)
  888. {
  889.     HX_RESULT rc = HXR_OK;
  890.     if (m_pRootPersistentComponent)
  891.     {
  892. rc = m_pRootPersistentComponent->OnTimeSync(ulCurrentTime);
  893.     }
  894.     return rc;
  895. }
  896. BOOL
  897. HXPersistentComponentManager::IsCleanupLayoutNeeded(INT32 nCurrentGroup, INT32 nGroupSwitchTo)
  898. {
  899.     BOOL bResult = FALSE;
  900.     UINT32 ulPersistentComponentIDSwitchTo = 0;
  901.     IHXValues* pGroupProperties = NULL;
  902.     IHXValues* pGroupSwitchToProperties = NULL;
  903.     IHXGroup* pGroup = NULL;
  904.     IHXGroup* pGroupSwitchTo = NULL;
  905.     IHXGroup2* pGroup2 = NULL;
  906.     IHXGroupManager* pGroupManager = NULL;
  907.     IHXPersistentComponent* pPersistentComponent = NULL;
  908.     // we will cleanup the layout if the from_group and to_group:
  909.     // * associated with different persistent component OR
  910.     // * associated with the same RAM
  911.     if (HXR_OK == m_pPlayer->QueryInterface(IID_IHXGroupManager, (void**)&pGroupManager))
  912.     {
  913. if (HXR_OK == pGroupManager->GetGroup(nGroupSwitchTo, pGroupSwitchTo))
  914. {
  915.     pGroupSwitchToProperties = pGroupSwitchTo->GetGroupProperties();
  916.     if (pGroupSwitchToProperties)
  917.     {
  918. if (HXR_OK == pGroupSwitchToProperties->GetPropertyULONG32("PersistentComponentID", 
  919.    ulPersistentComponentIDSwitchTo))
  920. {
  921.     if (HXR_OK == pGroupManager->GetGroup(nCurrentGroup, pGroup) &&
  922. HXR_OK == pGroup->QueryInterface(IID_IHXGroup2, (void**)&pGroup2))
  923.     {
  924. if (HXR_OK == pGroup2->GetPersistentComponentProperties(ulPersistentComponentIDSwitchTo,
  925. pGroupProperties))
  926. {
  927.     if (HXR_OK == GetPersistentComponent(ulPersistentComponentIDSwitchTo, pPersistentComponent))
  928.     {
  929. // switch group within RAM
  930. if (((HXPersistentComponent*)pPersistentComponent)->m_ulPersistentType == PersistentRAM)
  931. {
  932.     bResult = TRUE;
  933. }
  934. // switch group within SMIL without root layout
  935. // m_pPlayer->m_bAddLayoutSiteGroupCalled = TRUE when there is root layout
  936. // specified in SMIL
  937. // this needs to be revisited when fixing the nested meta layout
  938. else if (!m_pPlayer->m_bAddLayoutSiteGroupCalled)
  939. {
  940.     bResult = TRUE;
  941. }
  942.     }
  943.     else
  944.     {
  945. HX_ASSERT(FALSE);
  946.     }
  947.     HX_RELEASE(pPersistentComponent);
  948. }
  949. else
  950. {
  951.     bResult = TRUE;
  952. }
  953. HX_RELEASE(pGroupProperties);
  954.     }
  955.     HX_RELEASE(pGroup2);
  956.     HX_RELEASE(pGroup);
  957. }
  958.     }
  959.     HX_RELEASE(pGroupSwitchToProperties);
  960. }
  961. HX_RELEASE(pGroupSwitchTo);
  962.     }
  963.     HX_RELEASE(pGroupManager);
  964.     return bResult;
  965. }
  966. UINT32
  967. HXPersistentComponentManager::GetPersistentComponentCount(void)
  968. {
  969.     if (m_pRootPersistentComponent)
  970.     {
  971. return m_pRootPersistentComponent->GetPersistentComponentCount();
  972.     }
  973.     return 0;
  974. }
  975. void
  976. HXPersistentComponentManager::TrackUpdated(UINT16 uGroupIndex, 
  977.     UINT16 uTrackIndex, 
  978.     IHXValues* pValues)
  979. {
  980.     if (m_pRootPersistentComponent)
  981.     {
  982. m_pRootPersistentComponent->TrackUpdated(uGroupIndex, 
  983.              uTrackIndex,
  984.  pValues);
  985.     }
  986.     return;
  987. }
  988. void
  989. HXPersistentComponentManager::CloseAllRenderers(INT32 nGroupSwitchTo)
  990. {
  991.     // nested meta support
  992.     if (m_pRootPersistentComponent)
  993.     {
  994. if (m_pRootPersistentComponent->m_bToBeClosed)
  995. {
  996.             // /Call CleanupLayout before calling Remove; fixes PR 116482:
  997.     m_pPlayer->CleanupLayout();
  998.     m_pRootPersistentComponent->Remove();
  999.     HX_RELEASE(m_pRootPersistentComponent);
  1000.         }
  1001.      else
  1002. {
  1003.     m_pRootPersistentComponent->AllRenderersClosed();
  1004.     if (IsCleanupLayoutNeeded(m_nCurrentGroup, nGroupSwitchTo))
  1005.     {
  1006. m_pPlayer->CleanupLayout();
  1007.     }
  1008. }
  1009.     }
  1010.     else
  1011.     {
  1012. m_pPlayer->CleanupLayout();
  1013.     }
  1014.     return;
  1015. }
  1016. void
  1017. HXPersistentComponentManager::Reset()
  1018. {
  1019.     if (m_pRootPersistentComponent)
  1020.     {
  1021. m_pRootPersistentComponent->Reset();
  1022.     }
  1023.     m_ulComponentIndex = 0;
  1024.     return;
  1025. }
  1026. void 
  1027. HXPersistentComponentManager::Close()
  1028. {
  1029.     HX_ASSERT(!m_pRootPersistentComponent);
  1030.     return;
  1031. }