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

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 "hxausvc.h"
  38. #include "ihxpckts.h"
  39. #include "hxmap.h"
  40. #include "smiltype.h"
  41. #include "hxgroup.h"
  42. #include "basgroup.h"
  43. #include "advgroup.h"
  44. #include "hxwintyp.h"
  45. #include "hxengin.h"
  46. #include "hxcore.h"
  47. #include "hxplay.h"
  48. #include "hxbsrc.h"
  49. #include "hxsrc.h"
  50. #include "srcinfo.h"
  51. #include "hxslist.h"
  52. #include "hxtac.h"
  53. #include "hxstrutl.h"
  54. #include "hxheap.h"
  55. #ifdef _DEBUG
  56. #undef HX_THIS_FILE
  57. static const char HX_THIS_FILE[] = __FILE__;
  58. #endif
  59. HXBasicTrack::HXBasicTrack(HXBasicGroup* pHXGroup)
  60.             : m_lRefCount(0)
  61.             , m_uTrackIndex(0)
  62.             , m_pHXGroup(NULL)
  63.             , m_pValues(NULL)
  64.             , m_bActive(TRUE)
  65. {
  66.     m_pHXGroup = pHXGroup;
  67. }
  68. HXBasicTrack::~HXBasicTrack(void)
  69. {
  70.     Close();
  71. }
  72. /*
  73.  *  IUnknown methods
  74.  */
  75. STDMETHODIMP HXBasicTrack::QueryInterface(REFIID riid, void** ppvObj)
  76. {
  77.     if (IsEqualIID(riid, IID_IHXTrack))
  78.     {
  79.         AddRef();
  80.         *ppvObj = (IHXGroup*)this;
  81.         return HXR_OK;
  82.     }
  83.     else if (IsEqualIID(riid, IID_IUnknown))
  84.     {
  85. AddRef();
  86. *ppvObj = this;
  87. return HXR_OK;
  88.     }
  89.     *ppvObj = NULL;
  90.     return HXR_NOINTERFACE;
  91. }
  92. STDMETHODIMP_(ULONG32) HXBasicTrack::AddRef()
  93. {
  94.     return InterlockedIncrement(&m_lRefCount);
  95. }
  96. STDMETHODIMP_(ULONG32) HXBasicTrack::Release()
  97. {
  98.     if (InterlockedDecrement(&m_lRefCount) > 0)
  99.     {
  100.         return m_lRefCount;
  101.     }
  102.     delete this;
  103.     return 0;
  104. }
  105. /*
  106.  *  IHXTrack methods
  107.  */
  108. /************************************************************************
  109. *  Method:
  110. *     IHXBasicTrack::Begin()
  111. *  Purpose:
  112. *     start the track
  113. */
  114. STDMETHODIMP
  115. HXBasicTrack::Begin(void)
  116. {
  117.     return HXR_NOTIMPL;
  118. }
  119. /************************************************************************
  120. *  Method:
  121. *     IHXBasicTrack::Pause()
  122. *  Purpose:
  123. *     pause the track
  124. */
  125. STDMETHODIMP
  126. HXBasicTrack::Pause(void)
  127. {
  128.     return HXR_NOTIMPL;
  129. }
  130. /************************************************************************
  131. *  Method:
  132. *     IHXBasicTrack::Seek()
  133. *  Purpose:
  134. *     seek the track
  135. */
  136. STDMETHODIMP
  137. HXBasicTrack::Seek(UINT32 ulSeekTime)
  138. {
  139.     return HXR_NOTIMPL;
  140. }
  141. /************************************************************************
  142. *  Method:
  143. *     IHXBasicTrack::Stop()
  144. *  Purpose:
  145. *     stop the track
  146. */
  147. STDMETHODIMP
  148. HXBasicTrack::Stop(void)
  149. {
  150.     return HXR_NOTIMPL;
  151. }
  152. /************************************************************************
  153. *  Method:
  154. *     IHXBasicTrack::AddRepeat()
  155. *  Purpose:
  156. *     add repeat tracks
  157. */
  158. STDMETHODIMP
  159. HXBasicTrack::AddRepeat(IHXValues* pTrack)
  160. {
  161.     return HXR_NOTIMPL;
  162. }
  163. /************************************************************************
  164. *  Method:
  165. *     IHXBasicTrack::GetTrackProperties()
  166. *  Purpose:
  167. *     get track properties
  168. */
  169. STDMETHODIMP
  170. HXBasicTrack::GetTrackProperties(REF(IHXValues*) pValues,
  171.      REF(IHXValues*) pValuesInRequest)
  172. {
  173.     pValues = m_pValues;
  174.     if (pValues)
  175.     {
  176. pValues->AddRef();
  177.     }
  178.     pValuesInRequest = m_pValuesInRequest;
  179.     if (pValuesInRequest)
  180.     {
  181. pValuesInRequest->AddRef();
  182.     }
  183.     return HXR_OK;
  184. }
  185. /************************************************************************
  186.  * Method:
  187.  *     IHXBasicTrack::GetSource
  188.  * Purpose:
  189.  *     Returns the Nth source instance supported by this player.
  190.  */
  191. STDMETHODIMP
  192. HXBasicTrack::GetSource(REF(IHXStreamSource*) pStreamSource)
  193. {
  194.     return HXR_NOTIMPL;
  195. }
  196. /************************************************************************
  197. *  Method:
  198. *     IHXBasicTrack::SetSoundLevel()
  199. *  Purpose:
  200. *     Set Audio Level
  201. */
  202. STDMETHODIMP
  203. HXBasicTrack::SetSoundLevel(UINT16 uSoundLevel)
  204. {
  205.     return HXR_NOTIMPL;
  206. }
  207. /************************************************************************
  208. *  Method:
  209. *     IHXBasicTrack::GetSoundLevel()
  210. *  Purpose:
  211. *     Get Audio Level
  212. */
  213. STDMETHODIMP_(UINT16)
  214. HXBasicTrack::GetSoundLevel()
  215. {
  216.     return 0;
  217. }
  218. /************************************************************************
  219. *  Method:
  220. *     IHXBasicTrack::BeginSoundLevelAnimation()
  221. *  Purpose:
  222. *     notify the start of soundlevel animation
  223. */
  224. STDMETHODIMP
  225. HXBasicTrack::BeginSoundLevelAnimation(UINT16 uSoundLevelBeginWith)
  226. {
  227.     return HXR_NOTIMPL;
  228. }
  229. /************************************************************************
  230. *  Method:
  231. *     IHXBasicTrack::EndSoundLevelAnimation()
  232. *  Purpose:
  233. *     notify the stop of soundlevel animation
  234. */
  235. STDMETHODIMP
  236. HXBasicTrack::EndSoundLevelAnimation(UINT16 uSoundLevelEndWith)
  237. {
  238.     return HXR_NOTIMPL;
  239. }
  240. HX_RESULT
  241. HXBasicTrack::SetTrackProperties(IHXValues* pValues,
  242.      IHXValues* pValuesInRequest)
  243. {    
  244.     m_pValues = pValues;    
  245.     if (m_pValues)
  246.     {
  247. m_pValues->AddRef();
  248.     }
  249.     m_pValuesInRequest = pValuesInRequest;
  250.     if (m_pValuesInRequest)
  251.     {
  252. m_pValuesInRequest->AddRef();
  253.     }
  254.     return HXR_OK;
  255. }
  256. void
  257. HXBasicTrack::Close(void)
  258. {
  259.     HX_RELEASE(m_pValues);
  260.     HX_RELEASE(m_pValuesInRequest);
  261. }
  262. HXBasicGroup::HXBasicGroup(HXBasicGroupManager* pManager)
  263.             : m_lRefCount(0)
  264.             , m_pGroupManager(NULL)
  265.             , m_pPlayer(NULL)
  266.             , m_bToNotifyTrack(FALSE)
  267.             , m_pTrackMap(NULL)
  268.             , m_uGroupIndex(0)
  269.             , m_uTrackCount(0)
  270. {
  271.     m_pTrackMap = new CHXMapLongToObj;
  272.     m_pGroupManager = pManager;
  273.     m_pGroupManager->AddRef();
  274.     m_pPlayer = m_pGroupManager->m_pPlayer;
  275. }
  276. HXBasicGroup::~HXBasicGroup(void)
  277. {
  278.     Close();
  279.     HX_RELEASE(m_pGroupManager);
  280. }
  281. /*
  282.  *  IUnknown methods
  283.  */
  284. STDMETHODIMP HXBasicGroup::QueryInterface(REFIID riid, void** ppvObj)
  285. {
  286.     if (IsEqualIID(riid, IID_IHXGroup))
  287.     {
  288.         AddRef();
  289.         *ppvObj = (IHXGroup*)this;
  290.         return HXR_OK;
  291.     }
  292.     else if (IsEqualIID(riid, IID_IUnknown))
  293.     {
  294. AddRef();
  295. *ppvObj = this;
  296. return HXR_OK;
  297.     }
  298.     *ppvObj = NULL;
  299.     return HXR_NOINTERFACE;
  300. }
  301. STDMETHODIMP_(ULONG32) HXBasicGroup::AddRef()
  302. {
  303.     return InterlockedIncrement(&m_lRefCount);
  304. }
  305. STDMETHODIMP_(ULONG32) HXBasicGroup::Release()
  306. {
  307.     if (InterlockedDecrement(&m_lRefCount) > 0)
  308.     {
  309.         return m_lRefCount;
  310.     }
  311.     delete this;
  312.     return 0;
  313. }
  314. /*
  315.  *  IHXGroup methods
  316.  */
  317. /************************************************************************
  318. *  Method:
  319. *      IHXBasicGroup::SetGroupProperties
  320. *  Purpose:
  321. * Set any group specific information like Title Author 
  322. * Copyright etc. 
  323. */
  324. STDMETHODIMP
  325. HXBasicGroup::SetGroupProperties(IHXValues*  /*IN*/ pProperties)
  326. {
  327.     return HXR_NOTIMPL;
  328. }
  329. /************************************************************************
  330. *  Method:
  331. *      IHXBasicGroup::GetGroupProperties
  332. *  Purpose:
  333. * Get any group specific information. May return NULL.
  334. */
  335. STDMETHODIMP_(IHXValues*)
  336. HXBasicGroup::GetGroupProperties(void)
  337. {
  338.     return NULL;
  339. }
  340. /************************************************************************
  341. *  Method:
  342. *      IHXBasicGroup::GetTrackCount
  343. *  Purpose:
  344. * Get the number of tracks within this group.
  345. */
  346. STDMETHODIMP_(UINT16)
  347. HXBasicGroup::GetTrackCount(void)
  348. {
  349.     return m_uTrackCount;
  350. }
  351. /************************************************************************
  352. *  Method:
  353. *      IHXBasicGroup::GetTrack
  354. *  Purpose:
  355. * Call this to hook audio data after all audio streams in this
  356. * have been mixed.
  357. */
  358. STDMETHODIMP
  359. HXBasicGroup::GetTrack(UINT16          /*IN*/  uTrackIndex,
  360.        REF(IHXValues*)  /*OUT*/ pTrack)
  361. {
  362.     HX_RESULT rc = HXR_OK;
  363.     IHXValues* pTrackPropInRequest = NULL;
  364.     rc = DoGetTrack(uTrackIndex, pTrack, pTrackPropInRequest);
  365.     HX_RELEASE(pTrackPropInRequest);
  366.     return rc;
  367. }
  368. HX_RESULT
  369. HXBasicGroup::DoGetTrack(UINT16  /*IN*/ uTrackIndex,
  370.          REF(IHXValues*) /*OUT*/ pTrack,
  371.          REF(IHXValues*) /*OUT*/ pTrackPropInRequest)
  372. {
  373.     HX_RESULT     rc = HXR_OK;
  374.     HXBasicTrack*   pHXTrack = NULL;
  375.     if (!m_pTrackMap->Lookup(uTrackIndex, (void*&)pHXTrack))
  376.     {
  377. rc = HXR_UNEXPECTED;
  378. goto cleanup;
  379.     }
  380.     if (!pHXTrack->m_bActive)
  381.     {
  382. rc = HXR_IGNORE;
  383. goto cleanup;
  384.     }
  385.     rc = pHXTrack->GetTrackProperties(pTrack, pTrackPropInRequest);
  386. cleanup:
  387.     
  388.     return rc;
  389. }
  390. /************************************************************************
  391. *  Method:
  392. *      IHXBasicGroup::AddTrack
  393. *  Purpose:
  394. * SMIL renderer (IHXGroupSupplier) may want to add tracks even 
  395. * after adding IHXGroup to the IHXGroupManager
  396. */
  397. STDMETHODIMP
  398. HXBasicGroup::AddTrack(IHXValues* /*IN*/ pTrack)
  399. {
  400.     HX_RESULT   rc = HXR_OK;
  401.     HXBasicTrack* pHXTrack = new HXBasicTrack(this);
  402.     pHXTrack->AddRef();
  403.     rc = DoAddTrack(pTrack, NULL, pHXTrack);
  404.     if (HXR_OK != rc)
  405.     {
  406.         HX_RELEASE(pHXTrack);
  407.     }
  408.     return rc;
  409. }
  410. HX_RESULT
  411. HXBasicGroup::DoAddTrack(IHXValues*     /*IN*/ pTrack,
  412.          IHXValues*     /*IN*/ pTrackPropInRequest,
  413.                          HXBasicTrack*  /*IN*/ pHXTrack)
  414. {
  415.     HX_RESULT     theErr = HXR_OK;
  416.     if (!pTrack || !pHXTrack)
  417.     {
  418. return HXR_UNEXPECTED;
  419.     }
  420.     pHXTrack->SetTrackProperties(pTrack, pTrackPropInRequest);
  421.     pHXTrack->m_uTrackIndex = m_uTrackCount;
  422.     (*m_pTrackMap)[m_uTrackCount] = pHXTrack;
  423.     m_uTrackCount++;
  424.     if (m_bToNotifyTrack)
  425.     {
  426. theErr = m_pGroupManager->TrackAdded(m_uGroupIndex, pHXTrack->m_uTrackIndex, pTrack);
  427. HX_ASSERT(theErr == HXR_OK);
  428.     }
  429.     return theErr;
  430. }
  431. /************************************************************************
  432. *  Method:
  433. *      IHXBasicGroup::RemoveTrack
  434. *  Purpose:
  435. * Remove an already added track
  436. */
  437. STDMETHODIMP
  438. HXBasicGroup::RemoveTrack(UINT16 /*IN*/ uTrackIndex)
  439. {
  440.     return HXR_NOTIMPL;
  441. }
  442. HX_RESULT
  443. HXBasicGroup::CurrentGroupSet(void)
  444. {
  445.     return HXR_OK;
  446. }
  447. void     
  448. HXBasicGroup::StartTrackNotification(void)
  449. {
  450.     m_bToNotifyTrack = TRUE;
  451. }
  452. void
  453. HXBasicGroup::Close(void)
  454. {
  455.     CHXMapLongToObj::Iterator i;
  456.  
  457.     m_uTrackCount = 0;
  458.     if (m_pTrackMap)
  459.     {
  460. i = m_pTrackMap->Begin();
  461. for(; i != m_pTrackMap->End(); ++i)
  462. {
  463.     HXBasicTrack* pHXTrack = (HXBasicTrack*)(*i);
  464.     pHXTrack->Close();
  465.     HX_RELEASE(pHXTrack);
  466. }
  467. HX_DELETE(m_pTrackMap);
  468.     }
  469. }
  470. /*HXGroupManager*/
  471. HXBasicGroupManager::HXBasicGroupManager(HXPlayer* pPlayer)
  472.                     : m_lRefCount(0)
  473.                     , m_pGroupMap(NULL)
  474.                     , m_pSinkList(NULL)
  475.                     , m_uGroupCount(0)
  476.                     , m_uCurrentGroup(0)
  477.                     , m_uNextGroup(0)
  478.                     , m_bDefaultNextGroup(TRUE)
  479.                     , m_pPlayer(pPlayer)
  480.                     , m_bCurrentGroupInitialized(FALSE)
  481.                     , m_pPresentationProperties(NULL)
  482. {
  483.     m_pGroupMap     = new CHXMapLongToObj;
  484.     m_pSinkList     = new CHXSimpleList;
  485.     if (m_pPlayer)
  486. m_pPlayer->AddRef();
  487. }
  488. HXBasicGroupManager::~HXBasicGroupManager(void)
  489. {
  490.     Close();
  491. }
  492. /*
  493.  *  IUnknown methods
  494.  */
  495. STDMETHODIMP HXBasicGroupManager::QueryInterface(REFIID riid, void** ppvObj)
  496. {
  497.     if (IsEqualIID(riid, IID_IHXGroupManager))
  498.     {
  499.         AddRef();
  500.         *ppvObj = (IHXGroupManager*)this;
  501.         return HXR_OK;
  502.     }
  503.     else if (IsEqualIID(riid, IID_IHXPreCacheGroupMgr))
  504.     {
  505.         AddRef();
  506.         *ppvObj = (IHXPreCacheGroupMgr*)this;
  507.         return HXR_OK;
  508.     }
  509.     else if (IsEqualIID(riid, IID_IUnknown))
  510.     {
  511. AddRef();
  512. *ppvObj = this;
  513. return HXR_OK;
  514.     }
  515.     *ppvObj = NULL;
  516.     return HXR_NOINTERFACE;
  517. }
  518. STDMETHODIMP_(ULONG32) HXBasicGroupManager::AddRef()
  519. {
  520.     return InterlockedIncrement(&m_lRefCount);
  521. }
  522. STDMETHODIMP_(ULONG32) HXBasicGroupManager::Release()
  523. {
  524.     if (InterlockedDecrement(&m_lRefCount) > 0)
  525.     {
  526.         return m_lRefCount;
  527.     }
  528.     delete this;
  529.     return 0;
  530. }
  531. /*
  532.  *  IHXGroupManager methods
  533.  */
  534. /************************************************************************
  535. *  Method:
  536. *      IHXBasicGroupManager::CreateGroup
  537. *  Purpose:
  538. * Create a group
  539. */
  540. STDMETHODIMP
  541. HXBasicGroupManager::CreateGroup(REF(IHXGroup*) pGroup)
  542. {
  543.     pGroup = new HXBasicGroup(this);
  544.     if (!pGroup)
  545.     {
  546. return HXR_OUTOFMEMORY;
  547.     }
  548.     
  549.     pGroup->AddRef();
  550.     return HXR_OK;
  551. }
  552. /************************************************************************
  553. *  Method:
  554. *      IHXBasicGroupManager::GetGroupCount
  555. *  Purpose:
  556. * Get the number of groups within the presentation.
  557. */
  558. STDMETHODIMP_(UINT16)
  559. HXBasicGroupManager::GetGroupCount(void)
  560. {
  561.     return m_uGroupCount;
  562. }
  563. /************************************************************************
  564. *  Method:
  565. *      IHXBasicGroupManager::GetGroup
  566. *  Purpose:
  567. * Get ith group in the presentation
  568. */
  569. STDMETHODIMP
  570. HXBasicGroupManager::GetGroup(UINT16      /*IN*/ uGroupIndex,
  571.   REF(IHXGroup*)  /*OUT*/ pGroup)
  572. {
  573.     HX_RESULT rc = HXR_OK;
  574.     pGroup = NULL;
  575.     if (!m_pGroupMap->Lookup(uGroupIndex, (void*&)pGroup))
  576.     {
  577. rc = HXR_UNEXPECTED;
  578. goto cleanup;
  579.     }
  580.     pGroup->AddRef();
  581. cleanup:
  582.     
  583.     return rc;
  584. }
  585. /************************************************************************
  586. *  Method:
  587. *      IHXBasicGroupManager::SetCurrentGroup
  588. *  Purpose:
  589. * Play this group in the presentation.
  590. */
  591. STDMETHODIMP
  592. HXBasicGroupManager::SetCurrentGroup(UINT16      /*IN*/ uGroupIndex)
  593. {
  594.     HX_RESULT rc = HXR_OK;
  595.     IHXGroup* pHXGroup = NULL;
  596.     CHXSimpleList::Iterator ndx;
  597.     if (m_bCurrentGroupInitialized)
  598.     {
  599. // XXX HP
  600. // we should not receive multiple SetCurrentGroup() calls
  601. // on the same group, it would screw-up the layout stuff!!
  602. HX_ASSERT(m_uCurrentGroup != uGroupIndex);
  603.     }
  604.     if (HXR_OK != GetGroup(uGroupIndex, pHXGroup))
  605.     {
  606. rc = HXR_UNEXPECTED;
  607. goto cleanup;
  608.     }
  609.     ndx = m_pSinkList->Begin();
  610.     for (; ndx != m_pSinkList->End(); ++ndx)
  611.     {
  612. IHXGroupSink* pGroupSink = (IHXGroupSink*) (*ndx);
  613. pGroupSink->CurrentGroupSet(uGroupIndex, pHXGroup);
  614.     }
  615.     // add repeated sources
  616. #if defined(HELIX_FEATURE_ADVANCEDGROUPMGR)
  617.     ((HXAdvancedGroup*)pHXGroup)->CurrentGroupSet();
  618. #else
  619.     ((HXBasicGroup*)pHXGroup)->CurrentGroupSet();
  620. #endif /* HELIX_FEATURE_ADVANCEDGROUPMGR */
  621.     m_uCurrentGroup = uGroupIndex;
  622.     m_bCurrentGroupInitialized = TRUE;
  623. cleanup:
  624.     HX_RELEASE(pHXGroup);
  625.     return rc;
  626. }
  627. /************************************************************************
  628. *  Method:
  629. *      IHXBasicGroupManager::GetCurrentGroup
  630. *  Purpose:
  631. * Get the current presentation group index
  632. */
  633. STDMETHODIMP
  634. HXBasicGroupManager::GetCurrentGroup(REF(UINT16) /*OUT*/ uGroupIndex)
  635. {
  636.     uGroupIndex = m_uCurrentGroup;
  637.     return HXR_OK;
  638. }
  639. /************************************************************************
  640. *  Method:
  641. *      IHXBasicGroupManager::AddGroup
  642. *  Purpose:
  643. * Add a group to the presentation.
  644. */
  645. STDMETHODIMP
  646. HXBasicGroupManager::AddGroup(IHXGroup* /*IN*/ pGroup)
  647. {
  648.     HX_RESULT     theErr = HXR_OK;
  649.     if (!pGroup)
  650.     {
  651. return HXR_UNEXPECTED;
  652.     }
  653.     
  654.     theErr = InsertGroupAt(m_uGroupCount, pGroup);
  655.     return theErr;
  656. }
  657. /************************************************************************
  658. *  Method:
  659. *      IHXBasicGroupManager::RemoveGroup
  660. *  Purpose:
  661. * Remove an already added group
  662. */
  663. STDMETHODIMP
  664. HXBasicGroupManager::RemoveGroup(UINT16  /*IN*/ uGroupIndex)
  665. {
  666.     return HXR_NOTIMPL;
  667. }    
  668. /************************************************************************
  669. *  Method:
  670. *      IHXBasicGroupManager::AddSink
  671. *  Purpose:
  672. * Add a sink to get notifications about any tracks or groups
  673. * being added to the presentation.
  674. */
  675. STDMETHODIMP
  676. HXBasicGroupManager::AddSink(IHXGroupSink* /*IN*/ pGroupSink)
  677. {
  678.     if (!pGroupSink)
  679.     {
  680. return HXR_UNEXPECTED;
  681.     }
  682.     pGroupSink->AddRef();
  683.     m_pSinkList->AddTail(pGroupSink);
  684.     return HXR_OK;
  685. }
  686. /************************************************************************
  687. *  Method:
  688. *      IHXBasicGroupManager::RemoveSink
  689. *  Purpose:
  690. * Remove Sink
  691. */
  692. STDMETHODIMP
  693. HXBasicGroupManager::RemoveSink(IHXGroupSink* /*IN*/ pGroupSink)
  694. {
  695.     LISTPOSITION lPosition = m_pSinkList->Find(pGroupSink);
  696.     if (!lPosition)
  697.     {
  698. return HXR_UNEXPECTED;
  699.     }
  700.     m_pSinkList->RemoveAt(lPosition);
  701.     pGroupSink->Release();
  702.     
  703.     return HXR_OK;
  704. }
  705. /************************************************************************
  706. *  Method:
  707. *      IHXGroupManager::SetNextGroup
  708. *  Purpose:
  709. * Set the next group to play
  710. */
  711. STDMETHODIMP
  712. HXBasicGroupManager::SetNextGroup(UINT16 /*IN*/ uGroupIndex)
  713. {
  714.     // setting group index to total number of groups is valid; it means we are done
  715.     // record the next group index
  716.     m_uNextGroup = uGroupIndex;
  717.     m_bDefaultNextGroup = FALSE;
  718.     // tell the player about the next group
  719.     if (m_pPlayer)
  720.     {
  721.         m_pPlayer->NextGroupSet(uGroupIndex);
  722.     }
  723.     return HXR_OK;
  724. }
  725. /************************************************************************
  726. *  Method:
  727. *      IHXGroupManager::GetNextGroup
  728. *  Purpose:
  729. * Get the next group to play
  730. */
  731. STDMETHODIMP
  732. HXBasicGroupManager::GetNextGroup(REF(UINT16) uGroupIndex)
  733. {
  734.     HX_RESULT theErr = HXR_OK;
  735.     IHXGroup* pNextGroup = NULL;
  736.     if (m_bDefaultNextGroup)
  737. uGroupIndex = m_uCurrentGroup + 1;
  738.     else
  739. uGroupIndex = m_uNextGroup;
  740.     // make sure the next group we returned has >= 1 track
  741.     while (m_pGroupMap->Lookup(uGroupIndex, (void*&)pNextGroup))
  742.     {
  743. if (pNextGroup->GetTrackCount() > 0)
  744. {
  745.     break;
  746. }
  747. uGroupIndex++;
  748.     }
  749.     return HXR_OK;
  750. }
  751. /************************************************************************
  752. *  Method:
  753. *      IHXGroupManager::DefaultNextGroup
  754. *  Purpose:
  755. * reset to default the next group to play
  756. */
  757. STDMETHODIMP
  758. HXBasicGroupManager::DefaultNextGroup(void)
  759. {
  760.     m_bDefaultNextGroup = TRUE;
  761.     return HXR_OK;
  762. }
  763. /************************************************************************
  764. *  Method:
  765. *      IHXBasicGroupManager::SetPresentationProperties
  766. *  Purpose:
  767. * Set any presentation information like Title Author 
  768. * Copyright etc. 
  769. */
  770. STDMETHODIMP
  771. HXBasicGroupManager::SetPresentationProperties(IHXValues*  /*IN*/ pProperties)
  772. {
  773.     if(!pProperties)
  774.     {
  775. return HXR_UNEXPECTED;
  776.     }
  777.     HX_RELEASE(m_pPresentationProperties);
  778.     m_pPresentationProperties = pProperties;
  779.     m_pPresentationProperties->AddRef();
  780.     return HXR_OK;
  781. }
  782. /************************************************************************
  783. *  Method:
  784. *      IHXBasicGroupManager::GetPresentationProperties
  785. *  Purpose:
  786. * Get any presentation information. May return NULL.
  787. */
  788. STDMETHODIMP_(IHXValues*)
  789. HXBasicGroupManager::GetPresentationProperties(void)
  790. {
  791.     if (m_pPresentationProperties)
  792.     {
  793. m_pPresentationProperties->AddRef();
  794.     }
  795.     return m_pPresentationProperties;
  796. }
  797. HX_RESULT     
  798. HXBasicGroupManager::TrackAdded(UINT16 uGroupIndex, UINT16 uTrackIndex, 
  799.     IHXValues* pTrack)
  800. {
  801.     HX_RESULT rc = HXR_OK;
  802.     CHXSimpleList::Iterator ndx = m_pSinkList->Begin();
  803.     for (; ndx != m_pSinkList->End(); ++ndx)
  804.     {
  805. IHXGroupSink* pGroupSink = (IHXGroupSink*) (*ndx);
  806. pGroupSink->TrackAdded(uGroupIndex, uTrackIndex, pTrack);
  807.     }
  808.     return rc;
  809. }
  810. HX_RESULT
  811. HXBasicGroupManager::TrackRemoved(UINT16 uGroupIndex, UINT16 uTrackIndex, 
  812.       IHXValues* pTrack)
  813. {
  814.     HX_RESULT rc = HXR_OK;
  815.     CHXSimpleList::Iterator ndx = m_pSinkList->Begin();
  816.     for (; ndx != m_pSinkList->End(); ++ndx)
  817.     {
  818. IHXGroupSink* pGroupSink = (IHXGroupSink*) (*ndx);
  819. pGroupSink->TrackRemoved(uGroupIndex, uTrackIndex, pTrack);
  820.     }
  821.     return rc;
  822. }
  823. void 
  824. HXBasicGroupManager::SetMasterTAC(HXMasterTAC* pMasterTAC)
  825. {
  826.     return;
  827. }
  828. HX_RESULT     
  829. HXBasicGroupManager::TrackStarted(UINT16 uGroupIndex, UINT16 uTrackIndex)
  830. {
  831.     HX_RESULT rc = HXR_OK;
  832.     IHXGroup* pHXGroup = NULL;
  833.     IHXValues* pValues = NULL;
  834.     CHXSimpleList::Iterator ndx;
  835.     if (!m_pGroupMap->Lookup(uGroupIndex, (void*&)pHXGroup))
  836.     {
  837. rc = HXR_UNEXPECTED;
  838. goto cleanup;
  839.     }
  840.     if (HXR_OK != pHXGroup->GetTrack(uTrackIndex, pValues))
  841.     {
  842. rc = HXR_UNEXPECTED;
  843. goto cleanup;
  844.     }
  845.     
  846.     ndx = m_pSinkList->Begin();
  847.     for (; ndx != m_pSinkList->End(); ++ndx)
  848.     {
  849. IHXGroupSink* pGroupSink = (IHXGroupSink*) (*ndx);
  850. pGroupSink->TrackStarted(uGroupIndex, uTrackIndex, pValues);
  851.     }
  852. cleanup:
  853.     HX_RELEASE(pValues);    
  854.     return rc;
  855. }
  856. HX_RESULT     
  857. HXBasicGroupManager::TrackStopped(UINT16 uGroupIndex, UINT16 uTrackIndex)
  858. {
  859.     HX_RESULT rc = HXR_OK;
  860.     IHXGroup* pHXGroup = NULL;
  861.     IHXValues* pValues = NULL;
  862.     CHXSimpleList::Iterator ndx;
  863.     if (!m_pGroupMap->Lookup(uGroupIndex, (void*&)pHXGroup))
  864.     {
  865. rc = HXR_UNEXPECTED;
  866. goto cleanup;
  867.     }
  868.     if (HXR_OK != pHXGroup->GetTrack(uTrackIndex, pValues))
  869.     {
  870. rc = HXR_UNEXPECTED;
  871. goto cleanup;
  872.     }
  873.     
  874.     ndx = m_pSinkList->Begin();
  875.     for (; ndx != m_pSinkList->End(); ++ndx)
  876.     {
  877. IHXGroupSink* pGroupSink = (IHXGroupSink*) (*ndx);
  878. pGroupSink->TrackStopped(uGroupIndex, uTrackIndex, pValues);
  879.     }
  880. cleanup:
  881.     HX_RELEASE(pValues);
  882.     return rc;
  883. }
  884. void
  885. HXBasicGroupManager::PersistentComponentAdded(UINT16 uGroupIndex, UINT16 uTrackIndex)
  886. {
  887.     return;
  888. }
  889. void 
  890. HXBasicGroupManager::PersistentComponentRemoved(UINT16 uGroupIndex, UINT16 uTrackIndex)
  891. {    
  892.     return;
  893. }
  894. HX_RESULT
  895. HXBasicGroupManager::InsertGroupAt(UINT16 uGroupIndex, IHXGroup* pGroup)
  896. {
  897.     HX_RESULT rc = HXR_OK;
  898.     int i = 0;
  899.     CHXMapLongToObj* pNewGroupMap = NULL;
  900.     IHXGroup* pHXGroup = NULL;
  901.     HX_ASSERT(uGroupIndex <= m_uGroupCount);
  902.     // make the spot for insertion
  903.     if (uGroupIndex < m_uGroupCount)
  904.     {
  905. // adjust group map index
  906. pNewGroupMap = new CHXMapLongToObj;
  907. for (i = 0; i < uGroupIndex; i++)
  908. {
  909.     m_pGroupMap->Lookup(i, (void*&)pHXGroup);
  910.     HX_ASSERT(pHXGroup);
  911.     (*pNewGroupMap)[i] = pHXGroup;
  912. }
  913. for (i = uGroupIndex; i < m_uGroupCount; i++)
  914. {
  915.     m_pGroupMap->Lookup(i, (void*&)pHXGroup);
  916.     HX_ASSERT(pHXGroup);
  917.     ((HXBasicGroup*)pHXGroup)->m_uGroupIndex = i + 1;
  918.     (*pNewGroupMap)[i + 1] = pHXGroup;
  919. }
  920. HX_DELETE(m_pGroupMap);
  921. m_pGroupMap = pNewGroupMap;
  922.     }
  923.     pGroup->AddRef();
  924.     ((HXBasicGroup*)pGroup)->m_uGroupIndex = uGroupIndex;
  925.     (*m_pGroupMap)[uGroupIndex] = pGroup;
  926.     m_uGroupCount++;
  927.     ((HXBasicGroup*)pGroup)->StartTrackNotification();
  928.     CHXSimpleList::Iterator ndx = m_pSinkList->Begin();
  929.     for (; ndx != m_pSinkList->End(); ++ndx)
  930.     {
  931. IHXGroupSink* pGroupSink = (IHXGroupSink*) (*ndx);
  932. // XXX HP replace this with the commented out line
  933. // after the TLC supports new IHXGroupSink2
  934. pGroupSink->GroupAdded(m_uGroupCount-1, pGroup);
  935. //pGroupSink->GroupInsertedAfter(uGroupIndex, pGroup);
  936.     }
  937.     return rc;
  938. }
  939. void 
  940. HXBasicGroupManager::RemoveAllGroup(void)
  941. {
  942.     HX_RELEASE(m_pPresentationProperties);
  943.     
  944.     m_uGroupCount = 0;
  945.     m_uCurrentGroup = 0;
  946.     m_uNextGroup = 0;
  947.     m_bCurrentGroupInitialized = FALSE;
  948.     m_bDefaultNextGroup = TRUE;
  949.     if (m_pGroupMap)
  950.     {
  951.         CHXMapLongToObj::Iterator i = m_pGroupMap->Begin();    
  952.         for (; i != m_pGroupMap->End(); ++i)
  953.         {
  954.     IHXGroup* pGroup = (IHXGroup*) (*i);
  955.     HX_RELEASE(pGroup);
  956.         }
  957.         m_pGroupMap->RemoveAll();
  958.     }
  959.     if (m_pSinkList)
  960.     {
  961.         CHXSimpleList::Iterator ndx = m_pSinkList->Begin();
  962.         for (; ndx != m_pSinkList->End(); ++ndx)
  963.         {
  964.     IHXGroupSink* pGroupSink = (IHXGroupSink*) (*ndx);
  965.     pGroupSink->AllGroupsRemoved();
  966.         }
  967.     }
  968. }
  969. void
  970. HXBasicGroupManager::Close(void)
  971. {
  972.     RemoveAllGroup();
  973.     HX_DELETE(m_pGroupMap);
  974.     
  975.     if (m_pSinkList)
  976.     {
  977.         CHXSimpleList::Iterator ndx = m_pSinkList->Begin();
  978.         for (; ndx != m_pSinkList->End(); ++ndx)
  979.         {
  980.     IHXGroupSink* pGroupSink = (IHXGroupSink*) (*ndx);
  981.     HX_RELEASE(pGroupSink);
  982.         }
  983.         HX_DELETE(m_pSinkList);
  984.     }
  985.     HX_RELEASE(m_pPlayer);
  986.     HX_RELEASE(m_pPresentationProperties);
  987. }