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

Symbian

开发平台:

Visual C++

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