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

Symbian

开发平台:

C/C++

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