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

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: advgroup.cpp,v 1.3.8.2 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 "advgroup.h"
  57. #include "hxwintyp.h"
  58. #include "hxengin.h"
  59. #include "hxcore.h"
  60. #include "hxplay.h"
  61. #include "hxbsrc.h"
  62. #include "hxsrc.h"
  63. #include "srcinfo.h"
  64. #include "hxslist.h"
  65. #include "hxtac.h"
  66. #include "hxstrutl.h"
  67. #include "hxheap.h"
  68. #ifdef _DEBUG
  69. #undef HX_THIS_FILE
  70. static const char HX_THIS_FILE[] = __FILE__;
  71. #endif
  72. HXAdvancedTrack::HXAdvancedTrack(HXAdvancedGroup* pHXGroup)
  73.                 :HXBasicTrack(pHXGroup)
  74.                 ,m_pRepeatList(NULL)
  75.                 ,m_uSoundLevel(100)
  76.                 ,m_bInSoundLevelAnimation(FALSE)
  77.                 ,m_ulSoundLevelAnimationTime(0)
  78.                 ,m_ulGranularity(0)
  79. {
  80. }
  81. HXAdvancedTrack::~HXAdvancedTrack(void)
  82. {
  83.     Close();
  84. }
  85. #if defined(HELIX_FEATURE_AUDIOHOOK)
  86. /*
  87.  *  IUnknown methods
  88.  */
  89. STDMETHODIMP HXAdvancedTrack::QueryInterface(REFIID riid, void** ppvObj)
  90. {
  91.     if (HXR_OK == HXBasicTrack::QueryInterface(riid, ppvObj))
  92.     {
  93. return HXR_OK;
  94.     }
  95.     else if (IsEqualIID(riid, IID_IHXAudioHook))
  96.     {
  97.         AddRef();
  98.         *ppvObj = (IHXAudioHook*)this;
  99.         return HXR_OK;
  100.     }
  101.     *ppvObj = NULL;
  102.     return HXR_NOINTERFACE;
  103. }
  104. STDMETHODIMP_(ULONG32) HXAdvancedTrack::AddRef()
  105. {
  106.     return InterlockedIncrement(&m_lRefCount);
  107. }
  108. STDMETHODIMP_(ULONG32) HXAdvancedTrack::Release()
  109. {
  110.     if (InterlockedDecrement(&m_lRefCount) > 0)
  111.     {
  112.         return m_lRefCount;
  113.     }
  114.     delete this;
  115.     return 0;
  116. }
  117. /*
  118.  *  IHXAudioHook methods
  119.  */
  120. /************************************************************************
  121.  *  Method:
  122.  *      IHXAudioHook::OnInit
  123.  *  Purpose:
  124.  *      Audio Services calls OnInit() with the audio data format of the
  125.  *     audio data that will be provided in the OnBuffer() method.
  126.  */
  127. STDMETHODIMP
  128. HXAdvancedTrack::OnInit(HXAudioFormat* /*IN*/ pFormat)
  129. {
  130.     CHXAudioPlayer* pAudioPlayer = NULL;
  131.     
  132.     pAudioPlayer = m_pHXGroup->m_pPlayer->GetAudioPlayer();
  133.     if (pAudioPlayer)
  134.     {
  135. m_ulSoundLevelAnimationTime = pAudioPlayer->GetCurrentPlayBackTime();
  136. m_ulGranularity = pAudioPlayer->GetGranularity();
  137.     }
  138.     return HXR_OK;
  139. }
  140. /************************************************************************
  141.  *  Method:
  142.  *      IHXAudioHook::OnBuffer
  143.  *  Purpose:
  144.  *      Audio Services calls OnBuffer() with audio data packets. The
  145.  *     renderer should not modify the data in the IHXBuffer part of
  146.  *     pAudioInData.  If the renderer wants to write a modified
  147.  *     version of the data back to Audio Services, then it should 
  148.  *     create its own IHXBuffer, modify the data and then associate 
  149.  *     this buffer with the pAudioOutData->pData member.
  150.  */
  151. STDMETHODIMP
  152. HXAdvancedTrack::OnBuffer(HXAudioData* /*IN*/   pAudioInData,
  153.    HXAudioData* /*OUT*/  pAudioOutData)
  154. {
  155.     HX_RESULT rc = HXR_OK;
  156.     if (!m_pHXGroup)
  157.     {
  158. rc = HXR_UNEXPECTED;
  159. goto cleanup;
  160.     }
  161.     m_ulSoundLevelAnimationTime += m_ulGranularity;
  162.     rc = ((HXAdvancedGroup*)m_pHXGroup)->OnSoundLevelAnimation(m_uTrackIndex, m_uSoundLevel, m_ulSoundLevelAnimationTime);
  163. cleanup:
  164.     return rc;
  165. }
  166. #endif /* HELIX_FEATURE_AUDIOHOOK */
  167. /*
  168.  *  IHXTrack methods
  169.  */
  170. /************************************************************************
  171. *  Method:
  172. *     IHXTrack::Begin()
  173. *  Purpose:
  174. *     start the track
  175. */
  176. STDMETHODIMP
  177. HXAdvancedTrack::Begin(void)
  178. {
  179.     HX_RESULT rc = HXR_OK;
  180.     if (!m_pHXGroup)
  181.     {
  182. rc = HXR_UNEXPECTED;
  183. goto cleanup;
  184.     }
  185.     rc = ((HXAdvancedGroup*)m_pHXGroup)->BeginTrack(m_uTrackIndex, m_pValues);
  186. cleanup:
  187.     return rc;
  188. }
  189. /************************************************************************
  190. *  Method:
  191. *     IHXTrack::Pause()
  192. *  Purpose:
  193. *     pause the track
  194. */
  195. STDMETHODIMP
  196. HXAdvancedTrack::Pause(void)
  197. {
  198.     HX_RESULT rc = HXR_OK;
  199.     if (!m_pHXGroup)
  200.     {
  201. rc = HXR_UNEXPECTED;
  202. goto cleanup;
  203.     }
  204.     rc = ((HXAdvancedGroup*)m_pHXGroup)->PauseTrack(m_uTrackIndex, m_pValues);
  205. cleanup:
  206.     return rc;
  207. }
  208. /************************************************************************
  209. *  Method:
  210. *     IHXTrack::Seek()
  211. *  Purpose:
  212. *     seek the track
  213. */
  214. STDMETHODIMP
  215. HXAdvancedTrack::Seek(UINT32 ulSeekTime)
  216. {
  217.     HX_RESULT rc = HXR_OK;
  218.     if (!m_pHXGroup)
  219.     {
  220. rc = HXR_UNEXPECTED;
  221. goto cleanup;
  222.     }
  223.     rc = ((HXAdvancedGroup*)m_pHXGroup)->SeekTrack(m_uTrackIndex, m_pValues, ulSeekTime);
  224. cleanup:
  225.     return rc;
  226. }
  227. /************************************************************************
  228. *  Method:
  229. *     IHXTrack::Stop()
  230. *  Purpose:
  231. *     stop the track
  232. */
  233. STDMETHODIMP
  234. HXAdvancedTrack::Stop(void)
  235. {
  236.     HX_RESULT rc = HXR_OK;
  237.     if (!m_pHXGroup)
  238.     {
  239. rc = HXR_UNEXPECTED;
  240. goto cleanup;
  241.     }
  242.     rc = ((HXAdvancedGroup*)m_pHXGroup)->StopTrack(m_uTrackIndex, m_pValues);
  243. cleanup:
  244.     return rc;
  245. }
  246. /************************************************************************
  247. *  Method:
  248. *     IHXTrack::AddRepeat()
  249. *  Purpose:
  250. *     add repeat tracks
  251. */
  252. STDMETHODIMP
  253. HXAdvancedTrack::AddRepeat(IHXValues* pTrack)
  254. {
  255.     if (!m_pRepeatList)
  256.     {
  257. m_pRepeatList = new CHXSimpleList();
  258.     }
  259.     m_pRepeatList->AddTail(pTrack);
  260.     pTrack->AddRef();
  261.     ((HXAdvancedGroup*)m_pHXGroup)->RepeatTrackAdded(m_uTrackIndex, pTrack);
  262.     return HXR_OK;
  263. }
  264. /************************************************************************
  265.  * Method:
  266.  *     IHXTrack::GetSource
  267.  * Purpose:
  268.  *     Returns the Nth source instance supported by this player.
  269.  */
  270. STDMETHODIMP
  271. HXAdvancedTrack::GetSource(REF(IHXStreamSource*) pStreamSource)
  272. {
  273.     HX_RESULT rc = HXR_OK;
  274.     if (!m_pHXGroup)
  275.     {
  276. rc = HXR_UNEXPECTED;
  277. goto cleanup;
  278.     }
  279.     rc = ((HXAdvancedGroup*)m_pHXGroup)->GetSource(m_uTrackIndex, pStreamSource);
  280. cleanup:
  281.     return rc;
  282. }
  283. /************************************************************************
  284. *  Method:
  285. *     IHXTrack::SetSoundLevel()
  286. *  Purpose:
  287. *     Set Audio Level
  288. */
  289. STDMETHODIMP
  290. HXAdvancedTrack::SetSoundLevel(UINT16 uSoundLevel)
  291. {
  292.     HX_RESULT rc = HXR_OK;
  293.     if (!m_pHXGroup)
  294.     {
  295. rc = HXR_UNEXPECTED;
  296. goto cleanup;
  297.     }
  298.     if (m_uSoundLevel != uSoundLevel)
  299.     {
  300. m_uSoundLevel = uSoundLevel;
  301. rc = ((HXAdvancedGroup*)m_pHXGroup)->SetSoundLevel(m_uTrackIndex, m_uSoundLevel, !m_bInSoundLevelAnimation);
  302.     }
  303. cleanup:
  304.     return rc;
  305. }
  306. /************************************************************************
  307. *  Method:
  308. *     IHXTrack::GetSoundLevel()
  309. *  Purpose:
  310. *     Get Audio Level
  311. */
  312. STDMETHODIMP_(UINT16)
  313. HXAdvancedTrack::GetSoundLevel()
  314. {
  315.     return m_uSoundLevel;
  316. }
  317. /************************************************************************
  318. *  Method:
  319. *     IHXTrack::BeginSoundLevelAnimation()
  320. *  Purpose:
  321. *     notify the start of soundlevel animation
  322. */
  323. STDMETHODIMP
  324. HXAdvancedTrack::BeginSoundLevelAnimation(UINT16 uSoundLevelBeginWith)
  325. {
  326.     HX_RESULT rc = HXR_OK;
  327.     if (!m_pHXGroup)
  328.     {
  329. rc = HXR_UNEXPECTED;
  330. goto cleanup;
  331.     }
  332.     m_uSoundLevel = uSoundLevelBeginWith;
  333.     m_bInSoundLevelAnimation = TRUE;
  334.     rc = ((HXAdvancedGroup*)m_pHXGroup)->BeginSoundLevelAnimation(m_uTrackIndex, m_uSoundLevel);
  335.     
  336. cleanup:
  337.     return rc;
  338. }
  339. /************************************************************************
  340. *  Method:
  341. *     IHXTrack::EndSoundLevelAnimation()
  342. *  Purpose:
  343. *     notify the stop of soundlevel animation
  344. */
  345. STDMETHODIMP
  346. HXAdvancedTrack::EndSoundLevelAnimation(UINT16 uSoundLevelEndWith)
  347. {
  348.     HX_RESULT rc = HXR_OK;
  349.     if (!m_pHXGroup)
  350.     {
  351. rc = HXR_UNEXPECTED;
  352. goto cleanup;
  353.     }
  354.     m_uSoundLevel = uSoundLevelEndWith;
  355.     rc = ((HXAdvancedGroup*)m_pHXGroup)->EndSoundLevelAnimation(m_uTrackIndex, m_uSoundLevel);
  356.     m_bInSoundLevelAnimation = FALSE;
  357. cleanup:
  358.     return rc;
  359. }
  360. void
  361. HXAdvancedTrack::Close(void)
  362. {
  363.     if (m_bInSoundLevelAnimation)
  364.     {
  365. EndSoundLevelAnimation(0);
  366.     }
  367.     if (m_pRepeatList)
  368.     {
  369. CHXSimpleList::Iterator i = m_pRepeatList->Begin();
  370. for (; i != m_pRepeatList->End(); ++i)
  371. {
  372.     IHXValues* pValues = (IHXValues*)*i;
  373.     HX_RELEASE(pValues);
  374. }
  375. HX_DELETE(m_pRepeatList);
  376.     }
  377.     HXBasicTrack::Close();
  378. }
  379. HXAdvancedGroup::HXAdvancedGroup(HXAdvancedGroupManager* pManager)
  380.                 :HXBasicGroup(pManager)
  381.                 ,m_pGroupProperties(NULL)
  382.                 ,m_bPrefetchSinkAdded(FALSE)
  383.                 ,m_pPrefetchTrackMap(NULL)
  384.                 ,m_pPersistentComponentPropertyMap(NULL)
  385.                 ,m_uPrefetchTrackCount(0)
  386.                 ,m_pTrackSinkList(NULL)
  387.                 ,m_pPrefetchSinkList(NULL)
  388. {
  389. }
  390. HXAdvancedGroup::~HXAdvancedGroup(void)
  391. {
  392.     Close();
  393. }
  394. /*
  395.  *  IUnknown methods
  396.  */
  397. STDMETHODIMP HXAdvancedGroup::QueryInterface(REFIID riid, void** ppvObj)
  398. {
  399.     if (HXR_OK == HXBasicGroup::QueryInterface(riid, ppvObj))
  400.     {
  401. return HXR_OK;
  402.     }
  403.     else if (IsEqualIID(riid, IID_IHXGroup2))
  404.     {
  405.         AddRef();
  406.         *ppvObj = (IHXGroup2*)this;
  407.         return HXR_OK;
  408.     }
  409. #if defined(HELIX_FEATURE_PREFETCH)
  410.     else if (IsEqualIID(riid, IID_IHXPrefetch))
  411.     {
  412.         AddRef();
  413.         *ppvObj = (IHXPrefetch*)this;
  414.         return HXR_OK;
  415.     }
  416.     else if (IsEqualIID(riid, IID_IHXPrefetchSink))
  417.     {
  418.         AddRef();
  419.         *ppvObj = (IHXPrefetchSink*)this;
  420.         return HXR_OK;
  421.     }
  422. #endif /* HELIX_FEATURE_PREFETCH */
  423.     *ppvObj = NULL;
  424.     return HXR_NOINTERFACE;
  425. }
  426. STDMETHODIMP_(ULONG32) HXAdvancedGroup::AddRef()
  427. {
  428.     return InterlockedIncrement(&m_lRefCount);
  429. }
  430. STDMETHODIMP_(ULONG32) HXAdvancedGroup::Release()
  431. {
  432.     if (InterlockedDecrement(&m_lRefCount) > 0)
  433.     {
  434.         return m_lRefCount;
  435.     }
  436.     delete this;
  437.     return 0;
  438. }
  439. /*
  440.  *  IHXGroup methods
  441.  */
  442. /************************************************************************
  443. *  Method:
  444. *      IHXGroup::SetGroupProperties
  445. *  Purpose:
  446. * Set any group specific information like Title Author 
  447. * Copyright etc. 
  448. */
  449. STDMETHODIMP
  450. HXAdvancedGroup::SetGroupProperties(IHXValues*  /*IN*/ pProperties)
  451. {
  452.     UINT32  ulDuration = 0;
  453.     if (m_pGroupProperties || !pProperties)
  454.     {
  455. return HXR_UNEXPECTED;
  456.     }
  457.     m_pGroupProperties = pProperties;
  458.     m_pGroupProperties->AddRef();
  459.     // support adjust current group's duration on the fly
  460.     if (m_uGroupIndex == m_pGroupManager->m_uCurrentGroup)
  461.     {
  462. if (HXR_OK == m_pGroupProperties->GetPropertyULONG32("duration", ulDuration))
  463. {
  464.     m_pPlayer->SetPresentationTime(ulDuration);
  465. }
  466.     }
  467.     return HXR_OK;
  468. }
  469. /************************************************************************
  470. *  Method:
  471. *      IHXGroup::GetGroupProperties
  472. *  Purpose:
  473. * Get any group specific information. May return NULL.
  474. */
  475. STDMETHODIMP_(IHXValues*)
  476. HXAdvancedGroup::GetGroupProperties(void)
  477. {
  478.     if (m_pGroupProperties)
  479.     {
  480. m_pGroupProperties->AddRef();
  481.     }
  482.     return m_pGroupProperties;
  483. }
  484. /************************************************************************
  485. *  Method:
  486. *      IHXGroup2::SetPersistentComponentProperties
  487. *  Purpose:
  488. * Set persistent component properties associated with this group
  489. * One group may contain multiple persistent components
  490. */
  491. STDMETHODIMP
  492. HXAdvancedGroup::SetPersistentComponentProperties(UINT32        /*IN*/ ulPersistentComponentID,
  493.           IHXValues* /*IN*/ pProperties)
  494. {
  495.     HX_RESULT rc = HXR_OK;
  496.     IHXValues* pValues = NULL;
  497.     if (!pProperties)
  498.     {
  499. rc = HXR_FAILED;
  500. goto cleanup;
  501.     }
  502.     if (!m_pPersistentComponentPropertyMap)
  503.     {
  504. m_pPersistentComponentPropertyMap = new CHXMapLongToObj;
  505.     }
  506.     if (!m_pPersistentComponentPropertyMap->Lookup(ulPersistentComponentID, 
  507.    (void*&)pValues))
  508.     {
  509. (*m_pPersistentComponentPropertyMap)[ulPersistentComponentID] = pProperties;
  510. pProperties->AddRef();
  511.     }
  512. cleanup:
  513.     return rc;
  514. }
  515. /************************************************************************
  516. *  Method:
  517. *      IHXGroup2::GetPersistentComponentProperties
  518. *  Purpose:
  519. * Get any persistent component specific information associated with 
  520. * the group.
  521. * One group may contain multiple persistent components
  522. */
  523. STDMETHODIMP
  524. HXAdvancedGroup::GetPersistentComponentProperties(UINT32          /*IN*/  ulPersistentComponentID,
  525.           REF(IHXValues*) /*OUT*/ pProperties)
  526. {
  527.     HX_RESULT rc = HXR_OK;
  528.     
  529.     pProperties = NULL;
  530.     if (m_pPersistentComponentPropertyMap &&
  531. m_pPersistentComponentPropertyMap->Lookup(ulPersistentComponentID, (void*&)pProperties))
  532.     {
  533. pProperties->AddRef();
  534.     }
  535.     else
  536.     {
  537. rc = HXR_FAILED;
  538.     }
  539.     return rc;
  540. }
  541. /************************************************************************
  542. *  Method:
  543. *      IHXGroup2::GetTrack2
  544. *  Purpose:
  545. * Get ith track in this group
  546. */
  547. STDMETHODIMP
  548. HXAdvancedGroup::GetTrack2(UINT16 /*IN*/ uTrackIndex,
  549.            REF(IHXValues*) /*OUT*/ pTrack,
  550.            REF(IHXValues*) /*OUT*/ pTrackPropInRequest)
  551. {
  552.     return DoGetTrack(uTrackIndex, pTrack, pTrackPropInRequest);
  553. }
  554. STDMETHODIMP
  555. HXAdvancedGroup::AddTrack(IHXValues* /*IN*/ pTrack)
  556. {
  557.     HX_RESULT   rc = HXR_OK;
  558.     HXAdvancedTrack* pHXTrack = new HXAdvancedTrack(this);
  559.     pHXTrack->AddRef();
  560.     rc = DoAddTrack(pTrack, NULL, pHXTrack);
  561.     if (HXR_OK != rc)
  562.     {
  563.         HX_RELEASE(pHXTrack);
  564.     }
  565.     return rc;
  566. }
  567. /************************************************************************
  568. *  Method:
  569. *      IHXGroup2::AddTrack2
  570. *  Purpose:
  571. * Add Tracks to the group, including the props set in RequestHeader
  572. */
  573. STDMETHODIMP
  574. HXAdvancedGroup::AddTrack2(IHXValues*   /*IN*/ pTrack,
  575.            IHXValues*   /*IN*/ pTrackPropInRequest)
  576. {
  577.     HX_RESULT   rc = HXR_OK;
  578.     HXAdvancedTrack* pHXTrack = new HXAdvancedTrack(this);
  579.     pHXTrack->AddRef();
  580.    
  581.     rc = DoAddTrack(pTrack, pTrackPropInRequest, pHXTrack);
  582.     if (HXR_OK != rc)
  583.     {
  584.         HX_RELEASE(pHXTrack);
  585.     }
  586.     return rc;
  587. }
  588. /************************************************************************
  589. *  Method:
  590. *      IHXGroup::RemoveTrack
  591. *  Purpose:
  592. * Remove an already added track
  593. */
  594. STDMETHODIMP
  595. HXAdvancedGroup::RemoveTrack(UINT16 /*IN*/ uTrackIndex)
  596. {
  597.     HX_RESULT theErr = HXR_OK;
  598.     int i = 0;
  599.     IHXValues* pValues = NULL;
  600.     IHXValues* pValuesInRequest = NULL;
  601.     IHXValues* pUpdateValues = NULL;
  602.     CHXMapLongToObj* pNewTrackMap = NULL;
  603.     HXAdvancedTrack* pHXTrackRemoved = NULL;
  604.     HXAdvancedTrack* pHXTrack = NULL;
  605.     if (!m_pTrackMap->Lookup(uTrackIndex, (void*&)pHXTrackRemoved))
  606.     {
  607. theErr = HXR_UNEXPECTED;
  608. goto cleanup;
  609.     }
  610.     m_pTrackMap->RemoveKey(uTrackIndex);
  611.     pHXTrackRemoved->GetTrackProperties(pValues, pValuesInRequest);
  612.     HX_ASSERT(pValues);
  613.     HX_ASSERT(m_pPlayer);
  614.     if (HXR_OK != m_pPlayer->RemoveTrack(m_uGroupIndex, uTrackIndex, pValues))
  615.     {
  616. theErr = HXR_UNEXPECTED;
  617. goto cleanup;
  618.     }
  619.     if (m_bToNotifyTrack)
  620.     {
  621. theErr = m_pGroupManager->TrackRemoved(m_uGroupIndex, uTrackIndex, pValues);
  622.     }
  623.     // adjust track map index
  624.     pNewTrackMap = new CHXMapLongToObj;
  625.     for (i = 0; i < uTrackIndex; i++)
  626.     {
  627. m_pTrackMap->Lookup(i, (void*&)pHXTrack);
  628. HX_ASSERT(pHXTrack);
  629. (*pNewTrackMap)[i] = pHXTrack;
  630.     }
  631.     for (i = uTrackIndex + 1; i < m_uTrackCount; i++)
  632.     {
  633. m_pTrackMap->Lookup(i, (void*&)pHXTrack);
  634. HX_ASSERT(pHXTrack);
  635. pHXTrack->m_uTrackIndex = i - 1;
  636. (*pNewTrackMap)[i - 1] = pHXTrack;
  637. pUpdateValues = new CHXHeader;
  638. pUpdateValues->AddRef();
  639. pUpdateValues->SetPropertyULONG32("TrackIndex", i - 1);
  640. m_pPlayer->UpdateTrack(m_uGroupIndex, i, pUpdateValues);
  641. HX_RELEASE(pUpdateValues);
  642.     }
  643.     HX_DELETE(m_pTrackMap);
  644.     m_pTrackMap = pNewTrackMap;
  645.     m_uTrackCount--;
  646.     
  647. cleanup:
  648.     HX_RELEASE(pValues);
  649.     HX_RELEASE(pValuesInRequest);
  650.     HX_RELEASE(pHXTrackRemoved);
  651.     return theErr;
  652. }
  653. HX_RESULT
  654. HXAdvancedGroup::BeginTrack(UINT16      /*IN*/ uTrackIndex,
  655.             IHXValues*  /*IN*/ pTrack)
  656. {
  657.     HX_RESULT theErr = HXR_OK;
  658.     HX_ASSERT(m_pPlayer);
  659.     theErr = m_pPlayer->BeginTrack(m_uGroupIndex, uTrackIndex, pTrack);
  660.     if (m_pTrackSinkList)
  661.     {
  662. CHXSimpleList::Iterator ndx = m_pTrackSinkList->Begin();
  663. for (; ndx != m_pTrackSinkList->End(); ++ndx)
  664. {
  665.     IHXTrackSink* pTrackSink = (IHXTrackSink*) (*ndx);
  666.     pTrackSink->BeginDone(m_uGroupIndex, uTrackIndex);
  667. }
  668.     }
  669.     return theErr;
  670. }
  671. HX_RESULT
  672. HXAdvancedGroup::PauseTrack(UINT16      /*IN*/ uTrackIndex,
  673.             IHXValues*  /*IN*/ pTrack)
  674. {
  675.     HX_RESULT theErr = HXR_OK;
  676.     HX_ASSERT(m_pPlayer);
  677.     theErr = m_pPlayer->PauseTrack(m_uGroupIndex, uTrackIndex, pTrack);
  678.     if (m_pTrackSinkList)
  679.     {
  680. CHXSimpleList::Iterator ndx = m_pTrackSinkList->Begin();
  681. for (; ndx != m_pTrackSinkList->End(); ++ndx)
  682. {
  683.     IHXTrackSink* pTrackSink = (IHXTrackSink*) (*ndx);
  684.     pTrackSink->PauseDone(m_uGroupIndex, uTrackIndex);
  685. }
  686.     }
  687.     return theErr;
  688. }
  689. HX_RESULT
  690. HXAdvancedGroup::SeekTrack(UINT16     /*IN*/ uTrackIndex,
  691.            IHXValues*     /*IN*/ pTrack,
  692.            UINT32     /*IN*/ ulSeekTime)
  693. {
  694.     HX_RESULT theErr = HXR_OK;
  695.     HX_ASSERT(m_pPlayer);
  696.     theErr = m_pPlayer->SeekTrack(m_uGroupIndex, uTrackIndex, pTrack, ulSeekTime);
  697.     if (m_pTrackSinkList)
  698.     {
  699. CHXSimpleList::Iterator ndx = m_pTrackSinkList->Begin();
  700. for (; ndx != m_pTrackSinkList->End(); ++ndx)
  701. {
  702.     IHXTrackSink* pTrackSink = (IHXTrackSink*) (*ndx);
  703.     pTrackSink->SeekDone(m_uGroupIndex, uTrackIndex, ulSeekTime);
  704. }
  705.     }
  706.     return theErr;
  707. }
  708. HX_RESULT
  709. HXAdvancedGroup::StopTrack(UINT16 /*IN*/ uTrackIndex,
  710.            IHXValues* /*IN*/ pTrack)
  711. {
  712.     HX_RESULT theErr = HXR_OK;
  713.     HX_ASSERT(m_pPlayer);    
  714.     theErr = m_pPlayer->StopTrack(m_uGroupIndex, uTrackIndex, pTrack);
  715.     if (m_pTrackSinkList)
  716.     {
  717. CHXSimpleList::Iterator ndx = m_pTrackSinkList->Begin();
  718. for (; ndx != m_pTrackSinkList->End(); ++ndx)
  719. {
  720.     IHXTrackSink* pTrackSink = (IHXTrackSink*) (*ndx);
  721.     pTrackSink->StopDone(m_uGroupIndex, uTrackIndex);
  722. }
  723.     }
  724.     return theErr;
  725. }
  726. HX_RESULT
  727. HXAdvancedGroup::GetSource(UINT16 uTrackIndex, 
  728.            IHXStreamSource*& pStreamSource)
  729. {
  730.     SourceInfo* pSourceInfo = NULL;
  731.     pStreamSource = NULL;
  732.     HX_ASSERT(m_pPlayer);
  733.     if (HXR_OK == m_pPlayer->GetSourceInfo(m_uGroupIndex, uTrackIndex, pSourceInfo) && 
  734. pSourceInfo)
  735.     {
  736. return pSourceInfo->m_pSource->QueryInterface(IID_IHXStreamSource, (void**)&pStreamSource);
  737.     }
  738.     return HXR_FAILED;
  739. }
  740. HX_RESULT
  741. HXAdvancedGroup::SetSoundLevel(UINT16 /*IN*/ uTrackIndex,
  742.        UINT16 /*IN*/ uSoundLevel,
  743.        BOOL /*IN*/ bReflushAudioDevice)
  744. {
  745.     HX_RESULT theErr = HXR_OK;
  746.     HX_ASSERT(m_pPlayer);
  747.     theErr = m_pPlayer->SetSoundLevel(m_uGroupIndex, 
  748.       uTrackIndex, 
  749.       uSoundLevel,
  750.       bReflushAudioDevice);
  751.     return theErr;
  752. }
  753. HX_RESULT
  754. HXAdvancedGroup::BeginSoundLevelAnimation(UINT16 uTrackIndex, 
  755.           UINT16 uSoundLevelBeginWith)
  756. {    
  757.     HX_RESULT         rc = HXR_OK;
  758.     CHXAudioPlayer*     pAudioPlayer = NULL;
  759.     HXAdvancedTrack* pHXTrack = NULL;
  760.     HX_ASSERT(m_pPlayer);
  761.     if ((pAudioPlayer = m_pPlayer->GetAudioPlayer()) &&
  762. m_pTrackMap->Lookup(uTrackIndex, (void*&)pHXTrack))
  763.     {     
  764. pAudioPlayer->ActualAddPostMixHook((IHXAudioHook*)pHXTrack, 0, 1);
  765. m_pPlayer->SetSoundLevel(m_uGroupIndex, 
  766.  uTrackIndex, 
  767.  uSoundLevelBeginWith, 
  768.  TRUE);
  769.     }
  770.     return rc;
  771. }
  772. HX_RESULT
  773. HXAdvancedGroup::EndSoundLevelAnimation(UINT16 uTrackIndex, 
  774.         UINT16 uSoundLevelEndWith)
  775. {
  776.     HX_RESULT         theErr = HXR_OK;
  777.     CHXAudioPlayer*     pAudioPlayer = NULL;
  778.     HXAdvancedTrack* pHXTrack = NULL;
  779.     HX_ASSERT(m_pPlayer);
  780.     if ((pAudioPlayer = m_pPlayer->GetAudioPlayer()) &&
  781. m_pTrackMap->Lookup(uTrackIndex, (void*&)pHXTrack))
  782.     {
  783. pAudioPlayer->ActualRemovePostMixHook((IHXAudioHook*)pHXTrack);
  784.     
  785. m_pPlayer->SetSoundLevel(m_uGroupIndex, 
  786.  uTrackIndex, 
  787.  uSoundLevelEndWith, 
  788.  FALSE);
  789.     }
  790.     return theErr;
  791. }
  792. HX_RESULT
  793. HXAdvancedGroup::OnSoundLevelAnimation(UINT16 uTrackIndex, 
  794.                                        UINT16 uSoundLevel, 
  795.                                        UINT32 ulSoundLevelAnimationTime)
  796. {
  797.     HX_RESULT theErr = HXR_OK;
  798.     if (m_pTrackSinkList)
  799.     {
  800. CHXSimpleList::Iterator ndx = m_pTrackSinkList->Begin();
  801. for (; ndx != m_pTrackSinkList->End(); ++ndx)
  802. {
  803.     IHXTrackSink* pTrackSink = (IHXTrackSink*) (*ndx);
  804.     pTrackSink->OnSoundLevelAnimation(m_uGroupIndex, uTrackIndex, ulSoundLevelAnimationTime);
  805. }
  806.     }
  807.     return theErr;
  808. }
  809. void
  810. HXAdvancedGroup::PersistentComponentAdded(UINT16 uTrackIndex)
  811. {
  812.     HXAdvancedTrack*    pPersistentHXTrack = NULL;
  813.     // XXX HP we don't actually remove the track in order
  814.     // to preserve the group/track ID of subsequent sources
  815.     // Need more work on RemoveTrack() so that all the group/
  816.     // track ID get updated across the board(esp. in persistent
  817.     // renderers)!!
  818.     if (m_pTrackMap->Lookup(uTrackIndex, (void*&)pPersistentHXTrack))
  819.     {
  820. pPersistentHXTrack->m_bActive = FALSE;
  821.     }
  822.     return;
  823. }
  824. void
  825. HXAdvancedGroup::PersistentComponentRemoved(UINT16 uTrackIndex)
  826. {
  827.     return;
  828. }
  829. HX_RESULT
  830. HXAdvancedGroup::CurrentGroupSet(void)
  831. {
  832.     HX_RESULT rc = HXR_OK;
  833.     CHXMapLongToObj::Iterator i = m_pTrackMap->Begin();
  834.     for(; i != m_pTrackMap->End(); ++i)
  835.     {
  836. HXAdvancedTrack*    pHXTrack = (HXAdvancedTrack*)(*i);
  837. CHXSimpleList*     pRepeatList = pHXTrack->m_pRepeatList;
  838. if (pRepeatList)
  839. {
  840.     CHXSimpleList::Iterator ndx = pRepeatList->Begin();
  841.     for (; ndx != pRepeatList->End(); ++ndx)
  842.     {
  843. IHXValues* pRepeatTrack = (IHXValues*) (*ndx);
  844. ((HXAdvancedGroupManager*)m_pGroupManager)->RepeatTrackAdded(m_uGroupIndex, 
  845.                                                                              pHXTrack->m_uTrackIndex, 
  846.                                                                              pRepeatTrack);
  847.     }
  848. }
  849.     }
  850.     return rc;
  851. }
  852. HX_RESULT
  853. HXAdvancedGroup::RepeatTrackAdded(UINT16 uTrackIndex, IHXValues* pValues)
  854. {
  855.     HX_RESULT rc = HXR_OK;
  856.     if (m_bToNotifyTrack)
  857.     {
  858. rc = ((HXAdvancedGroupManager*)m_pGroupManager)->RepeatTrackAdded(m_uGroupIndex, 
  859.                                                                           uTrackIndex, 
  860.                                                                           pValues);
  861. HX_ASSERT(rc == HXR_OK);
  862.     }
  863.     return rc;
  864. }
  865. /************************************************************************
  866. *  Method:
  867. *      IHXGroup2::GetIHXTrack
  868. *  Purpose:
  869. * get the IHXTrack object
  870. */
  871. STDMETHODIMP
  872. HXAdvancedGroup::GetIHXTrack(UINT16         /*IN*/  uTrackIndex,
  873.              REF(IHXTrack*) /*OUT*/ pTrack)
  874. {
  875.     HX_RESULT rc = HXR_OK;
  876.     pTrack = NULL;
  877.     if (!m_pTrackMap->Lookup(uTrackIndex, (void*&)pTrack))
  878.     {
  879. rc = HXR_FAILED;
  880. goto cleanup;
  881.     }
  882.     pTrack->AddRef();
  883. cleanup:
  884.     return HXR_OK;
  885. }
  886. /************************************************************************
  887. *  Method:
  888. *      IHXGroup2::AddTrackSink
  889. *  Purpose:
  890. * add advise sink on track
  891. */
  892. STDMETHODIMP
  893. HXAdvancedGroup::AddTrackSink(IHXTrackSink*   /*IN*/  pSink)
  894. {
  895.     if (!pSink)
  896.     {
  897. return HXR_UNEXPECTED;
  898.     }
  899.     if (!m_pTrackSinkList)
  900.     {
  901. m_pTrackSinkList = new CHXSimpleList;
  902.     }
  903.     pSink->AddRef();
  904.     m_pTrackSinkList->AddTail(pSink);
  905.     return HXR_OK;    
  906. }
  907. /************************************************************************
  908. *  Method:
  909. *      IHXGroup2::RemoveTrackSink
  910. *  Purpose:
  911. * remove advise sink on track
  912. */
  913. STDMETHODIMP
  914. HXAdvancedGroup::RemoveTrackSink(IHXTrackSink*   /*IN*/  pSink)
  915. {
  916.     if (!m_pTrackSinkList)
  917.     {
  918. return HXR_UNEXPECTED;
  919.     }
  920.     LISTPOSITION lPosition = m_pTrackSinkList->Find(pSink);
  921.     if (!lPosition)
  922.     {
  923. return HXR_UNEXPECTED;
  924.     }
  925.     m_pTrackSinkList->RemoveAt(lPosition);
  926.     HX_RELEASE(pSink);
  927.     
  928.     return HXR_OK;
  929. }
  930. #if defined(HELIX_FEATURE_PREFETCH)
  931. /************************************************************************
  932. *  Method:
  933. *      IHXPrefetch::AddPrefetchTrack
  934. *  Purpose:
  935. *      adds prefetch track by specifying "PrefetchType" and "PrefetchValue"
  936. *      in pTrack's IHXValues
  937. */
  938. STDMETHODIMP
  939. HXAdvancedGroup::AddPrefetchTrack(IHXValues* /*IN*/  pTrack)
  940. {
  941.     HX_RESULT     rc = HXR_OK;
  942.     UINT16     uPrefetchIndex = 0;
  943.     IHXPrefetch*   pPrefetch = NULL;
  944.     if (!pTrack)
  945.     {
  946. rc = HXR_UNEXPECTED;
  947. goto cleanup;
  948.     }
  949.     uPrefetchIndex = m_uPrefetchTrackCount;
  950.     pTrack->SetPropertyULONG32("GroupIndex", m_uGroupIndex);
  951.     pTrack->SetPropertyULONG32("TrackIndex", uPrefetchIndex);
  952.     // give TLC a first bite on prefetch track
  953.     if (HXR_OK == m_pPlayer->QueryInterface(IID_IHXPrefetch, (void**)&pPrefetch))
  954.     {
  955. rc = pPrefetch->AddPrefetchTrack(pTrack);
  956. if (HXR_OK == rc && !m_bPrefetchSinkAdded)
  957. {
  958.     m_bPrefetchSinkAdded = TRUE;
  959.     pPrefetch->AddPrefetchSink(this);
  960. }
  961. else if (HXR_NOT_SUPPORTED == rc)
  962. {
  963.     rc = m_pPlayer->AddPrefetchTrack(m_uGroupIndex, uPrefetchIndex, pTrack);
  964. }
  965.     }
  966.     else
  967.     {
  968. rc = m_pPlayer->AddPrefetchTrack(m_uGroupIndex, uPrefetchIndex, pTrack);
  969.     }
  970.     if (HXR_OK != rc)
  971.     {
  972. goto cleanup;
  973.     }
  974.     if (!m_pPrefetchTrackMap)
  975.     {
  976. m_pPrefetchTrackMap = new CHXMapLongToObj;
  977.     }
  978.     (*m_pPrefetchTrackMap)[uPrefetchIndex] = pTrack;
  979.     pTrack->AddRef();
  980.     m_uPrefetchTrackCount++;
  981.     if (m_pPrefetchSinkList)
  982.     {
  983. CHXSimpleList::Iterator ndx = m_pPrefetchSinkList->Begin();
  984. for (; ndx != m_pPrefetchSinkList->End(); ++ndx)
  985. {
  986.     IHXPrefetchSink* pPrefetchSink = (IHXPrefetchSink*) (*ndx);
  987.     pPrefetchSink->PrefetchTrackAdded(m_uGroupIndex, uPrefetchIndex, pTrack);
  988. }
  989.     }
  990. cleanup:
  991.     HX_RELEASE(pPrefetch);
  992.     return rc;
  993. }
  994. /************************************************************************
  995. *  Method:
  996. *      IHXPrefetch::RemovePrefetchTrack
  997. *  Purpose:
  998. *      removes prefetched track
  999. */
  1000. STDMETHODIMP
  1001. HXAdvancedGroup::RemovePrefetchTrack(UINT16 /*IN*/ uTrackIndex)
  1002. {
  1003.     HX_RESULT rc = HXR_OK;
  1004.     int i = 0;
  1005.     IHXValues* pTrack = NULL;
  1006.     IHXValues* pUpdateValues = NULL;
  1007.     CHXMapLongToObj* pNewPrefetchTrackMap = NULL;
  1008.     if (!m_pPrefetchTrackMap)
  1009.     {
  1010. rc = HXR_FAILED;
  1011. goto cleanup;
  1012.     }
  1013.     if (!m_pPrefetchTrackMap->Lookup(uTrackIndex, (void*&)pTrack))
  1014.     {
  1015. rc = HXR_FAILED;
  1016. goto cleanup;
  1017.     }
  1018.     m_pPrefetchTrackMap->RemoveKey(uTrackIndex);
  1019.     if (HXR_OK != m_pPlayer->RemovePrefetchTrack(m_uGroupIndex, uTrackIndex, pTrack))
  1020.     {
  1021. rc = HXR_FAILED;
  1022. goto cleanup;
  1023.     }
  1024.     if (m_pPrefetchSinkList)
  1025.     {
  1026. CHXSimpleList::Iterator ndx = m_pPrefetchSinkList->Begin();
  1027. for (; ndx != m_pPrefetchSinkList->End(); ++ndx)
  1028. {
  1029.     IHXPrefetchSink* pPrefetchSink = (IHXPrefetchSink*) (*ndx);
  1030.     pPrefetchSink->PrefetchTrackRemoved(m_uGroupIndex, uTrackIndex, pTrack);
  1031. }
  1032.     }
  1033.     HX_RELEASE(pTrack);
  1034.     // adjust track map index
  1035.     pNewPrefetchTrackMap = new CHXMapLongToObj;
  1036.     for (i = 0; i < uTrackIndex; i++)
  1037.     {
  1038. pTrack = (IHXValues*)(*m_pPrefetchTrackMap)[i];
  1039. HX_ASSERT(pTrack);
  1040. (*pNewPrefetchTrackMap)[i] = pTrack;
  1041.     }
  1042.     for (i = uTrackIndex + 1; i < m_uPrefetchTrackCount; i++)
  1043.     {
  1044. pTrack = (IHXValues*)(*m_pPrefetchTrackMap)[i];
  1045. HX_ASSERT(pTrack);
  1046. (*pNewPrefetchTrackMap)[i - 1] = pTrack;
  1047. pUpdateValues = new CHXHeader;
  1048. pUpdateValues->AddRef();
  1049. pUpdateValues->SetPropertyULONG32("TrackIndex", i - 1);
  1050. m_pPlayer->UpdatePrefetchTrack(m_uGroupIndex, i, pUpdateValues);
  1051. HX_RELEASE(pUpdateValues);
  1052.     }
  1053.     HX_DELETE(m_pPrefetchTrackMap);
  1054.     m_pPrefetchTrackMap = pNewPrefetchTrackMap;
  1055.     m_uPrefetchTrackCount--;
  1056. cleanup:
  1057.     return rc;
  1058. }
  1059. /************************************************************************
  1060. *  Method:
  1061. *      IHXPrefetch::GetPrefetchTrackCount
  1062. *  Purpose:
  1063. *      get number of prefetch tracks added
  1064. */
  1065. STDMETHODIMP_(UINT16)
  1066. HXAdvancedGroup::GetPrefetchTrackCount()
  1067. {
  1068.     return m_uPrefetchTrackCount;
  1069. }
  1070. /************************************************************************
  1071. *  Method:
  1072. *      IHXPrefetch::GetPrefetchTrack
  1073. *  Purpose:
  1074. *      get prefetch track based on the index
  1075. */
  1076. STDMETHODIMP
  1077. HXAdvancedGroup::GetPrefetchTrack(UINT16            /*IN*/  uTrackIndex,
  1078.           REF(IHXValues*)   /*OUT*/ pTrack)
  1079. {
  1080.     HX_RESULT rc = HXR_OK;
  1081.     pTrack = NULL;
  1082.     if (!m_pPrefetchTrackMap)
  1083.     {
  1084. rc = HXR_FAILED;
  1085. goto cleanup;
  1086.     }
  1087.     if (!m_pPrefetchTrackMap->Lookup(uTrackIndex, (void*&)pTrack))
  1088.     {
  1089. rc = HXR_FAILED;
  1090. goto cleanup;
  1091.     }
  1092. cleanup:
  1093.     return rc;
  1094. }
  1095. /************************************************************************
  1096. *  Method:
  1097. *      IHXPrefetch::AddPrefetchSink
  1098. *  Purpose:
  1099. *      add prefetch sink
  1100. */
  1101. STDMETHODIMP
  1102. HXAdvancedGroup::AddPrefetchSink(IHXPrefetchSink* /*IN*/ pSink)
  1103. {
  1104.     HX_RESULT rc = HXR_OK;
  1105.     if (!pSink)
  1106.     {
  1107. rc = HXR_FAILED;
  1108. goto cleanup;
  1109.     }
  1110.     if (!m_pPrefetchSinkList)
  1111.     {
  1112. m_pPrefetchSinkList = new CHXSimpleList;
  1113.     }
  1114.     m_pPrefetchSinkList->AddTail(pSink);
  1115.     pSink->AddRef();
  1116. cleanup:
  1117.     return rc;
  1118. }
  1119. /************************************************************************
  1120. *  Method:
  1121. *      IHXPrefetch::RemovePrefetchSink
  1122. *  Purpose:
  1123. *      remove prefetch sink
  1124. */
  1125. STDMETHODIMP
  1126. HXAdvancedGroup::RemovePrefetchSink(IHXPrefetchSink* /*IN*/ pSink)
  1127. {
  1128.     HX_RESULT     rc = HXR_OK;
  1129.     LISTPOSITION    lPosition = 0;
  1130.     if (!m_pPrefetchSinkList || !pSink)
  1131.     {
  1132. rc = HXR_FAILED;
  1133. goto cleanup;
  1134.     }
  1135.     lPosition = m_pPrefetchSinkList->Find(pSink);
  1136.     if (!lPosition)
  1137.     {
  1138. rc = HXR_FAILED;
  1139. goto cleanup;
  1140.     }
  1141.     m_pPrefetchSinkList->RemoveAt(lPosition);
  1142.     HX_RELEASE(pSink);
  1143.     
  1144. cleanup:
  1145.     return rc;
  1146. }
  1147. /************************************************************************
  1148. *  Method:
  1149. *     IHXPrefetchSink::PrefetchTrackAdded()
  1150. *  Purpose:
  1151. *     prefetch track is added
  1152. */
  1153. STDMETHODIMP
  1154. HXAdvancedGroup::PrefetchTrackAdded(UINT16      uGroupIndex,
  1155.             UINT16      uTrackIndex,
  1156.             IHXValues*  pTrack)
  1157. {
  1158.     return HXR_OK;
  1159. }
  1160. /************************************************************************
  1161. *  Method:
  1162. *     IHXPrefetchSink::PrefetchTrackRemoved()
  1163. *  Purpose:
  1164. *     prefetch track is removed
  1165. */
  1166. STDMETHODIMP
  1167. HXAdvancedGroup::PrefetchTrackRemoved(UINT16     uGroupIndex,
  1168.               UINT16        uTrackIndex,
  1169.               IHXValues*    pTrack)
  1170. {
  1171.     return HXR_OK;
  1172. }
  1173. /************************************************************************
  1174. *  Method:
  1175. *     IHXPrefetchSink::PrefetchTrackDone()
  1176. *  Purpose:
  1177. *     prefetch track is done
  1178. */
  1179. STDMETHODIMP
  1180. HXAdvancedGroup::PrefetchTrackDone(UINT16 uGroupIndex,
  1181.            UINT16 uTrackIndex,     
  1182.            HX_RESULT status)
  1183. {
  1184.     HX_RESULT rc = HXR_OK;
  1185.     if (m_pPrefetchSinkList)
  1186.     {
  1187. CHXSimpleList::Iterator ndx = m_pPrefetchSinkList->Begin();
  1188. for (; ndx != m_pPrefetchSinkList->End(); ++ndx)
  1189. {
  1190.     IHXPrefetchSink* pPrefetchSink = (IHXPrefetchSink*) (*ndx);
  1191.     pPrefetchSink->PrefetchTrackDone(uGroupIndex, uTrackIndex, status);
  1192. }
  1193.     }
  1194.     return rc;
  1195. }
  1196. #endif /* HELIX_FEATURE_PREFETCH */
  1197. void
  1198. HXAdvancedGroup::Close(void)
  1199. {
  1200.     HXBasicGroup::Close();
  1201.     HX_RELEASE(m_pGroupProperties);
  1202.     IHXPrefetch*   pPrefetch = NULL;
  1203.     CHXMapLongToObj::Iterator i;
  1204.     CHXSimpleList::Iterator j;
  1205.     m_uPrefetchTrackCount = 0;
  1206.     if (m_pTrackSinkList)
  1207.     {
  1208. CHXSimpleList::Iterator ndx = m_pTrackSinkList->Begin();
  1209. for (; ndx != m_pTrackSinkList->End(); ++ndx)
  1210. {
  1211.     IHXTrackSink* pTrackSink = (IHXTrackSink*) (*ndx);
  1212.     HX_RELEASE(pTrackSink);
  1213. }
  1214. HX_DELETE(m_pTrackSinkList);
  1215.     }
  1216. #if defined(HELIX_FEATURE_PREFETCH)
  1217.     if (m_pPrefetchTrackMap)
  1218.     {
  1219. i = m_pPrefetchTrackMap->Begin();
  1220. for(; i != m_pPrefetchTrackMap->End(); ++i)
  1221. {
  1222.     IHXValues* pTrack = (IHXValues*)(*i);
  1223.     HX_RELEASE(pTrack);
  1224. }
  1225. HX_DELETE(m_pPrefetchTrackMap);
  1226.     }
  1227.     if (m_pPrefetchSinkList)
  1228.     {
  1229. j = m_pPrefetchSinkList->Begin();
  1230. for (; j != m_pPrefetchSinkList->End(); ++j)
  1231. {
  1232.     IHXPrefetchSink* pPrefetchSink = (IHXPrefetchSink*) (*j);
  1233.     HX_RELEASE(pPrefetchSink);
  1234. }
  1235. HX_DELETE(m_pPrefetchSinkList);
  1236.     }
  1237.     if (m_bPrefetchSinkAdded)
  1238.     {
  1239. if (HXR_OK == m_pPlayer->QueryInterface(IID_IHXPrefetch, (void**)&pPrefetch))
  1240. {
  1241.     pPrefetch->RemovePrefetchSink(this);
  1242.     m_bPrefetchSinkAdded = FALSE;
  1243. }
  1244. HX_RELEASE(pPrefetch);
  1245.     }
  1246. #endif /* HELIX_FEATURE_PREFETCH */
  1247.     if (m_pPersistentComponentPropertyMap)
  1248.     {
  1249. i = m_pPersistentComponentPropertyMap->Begin();
  1250. for(; i != m_pPersistentComponentPropertyMap->End(); ++i)
  1251. {
  1252.     IHXValues* pValues = (IHXValues*)(*i);
  1253.     HX_RELEASE(pValues);
  1254. }
  1255. HX_DELETE(m_pPersistentComponentPropertyMap);
  1256.     }
  1257. }
  1258. /*HXAdvancedGroupManager*/
  1259. HXAdvancedGroupManager::HXAdvancedGroupManager(HXPlayer* pPlayer)
  1260.                        :HXBasicGroupManager(pPlayer)
  1261.                        ,m_pMasterTAC(NULL)
  1262. {
  1263. }
  1264. HXAdvancedGroupManager::~HXAdvancedGroupManager(void)
  1265. {
  1266.     Close();
  1267. }
  1268. void HXAdvancedGroupManager::SetMasterTAC(HXMasterTAC* pMasterTAC)
  1269. {
  1270.     m_pMasterTAC = pMasterTAC;
  1271.     m_pMasterTAC->AddRef();
  1272. }
  1273. void
  1274. HXAdvancedGroupManager::PersistentComponentAdded(UINT16 uGroupIndex, UINT16 uTrackIndex)
  1275. {
  1276.     HXAdvancedGroup* pGroup = NULL;
  1277.     CHXSimpleList::Iterator ndx;
  1278.     if (HXR_OK == GetGroup(uGroupIndex, (IHXGroup*&)pGroup))
  1279.     {
  1280. pGroup->PersistentComponentAdded(uTrackIndex);
  1281.     }
  1282.     HX_RELEASE(pGroup);
  1283.     return;
  1284. }
  1285. void 
  1286. HXAdvancedGroupManager::PersistentComponentRemoved(UINT16 uGroupIndex, UINT16 uTrackIndex)
  1287. {    
  1288.     HXAdvancedGroup* pGroup = NULL;
  1289.     CHXSimpleList::Iterator ndx;
  1290.     if (HXR_OK == GetGroup(uGroupIndex, (IHXGroup*&)pGroup))
  1291.     {
  1292. pGroup->PersistentComponentRemoved(uTrackIndex);
  1293.     }
  1294.     return;
  1295. }
  1296. /*
  1297.  *  IHXGroupManager methods
  1298.  */
  1299. /************************************************************************
  1300. *  Method:
  1301. *      IHXGroupManager::CreateGroup
  1302. *  Purpose:
  1303. * Create a group
  1304. */
  1305. STDMETHODIMP
  1306. HXAdvancedGroupManager::CreateGroup(REF(IHXGroup*) pGroup)
  1307. {
  1308.     pGroup = new HXAdvancedGroup(this);
  1309.     if (!pGroup)
  1310.     {
  1311. return HXR_OUTOFMEMORY;
  1312.     }
  1313.     
  1314.     pGroup->AddRef();
  1315.     return HXR_OK;
  1316. }
  1317. /************************************************************************
  1318. *  Method:
  1319. *      IHXGroupManager::AddGroup
  1320. *  Purpose:
  1321. * Add a group to the presentation.
  1322. */
  1323. STDMETHODIMP
  1324. HXAdvancedGroupManager::AddGroup(IHXGroup* /*IN*/ pGroup)
  1325. {
  1326.     HX_RESULT         theErr = HXR_OK;
  1327.     UINT16         uInsertGroupAt = 0;
  1328.     UINT32         ulLastGroupInRAM20 = 0;
  1329.     UINT32         ulPersistentComponentID = 0;
  1330.     IHXValues*         pGroupProperties = NULL;
  1331.     HXAdvancedTrack*    pHXTrack = NULL;
  1332.     IHXPersistentComponent* pPersistentComponent = NULL;
  1333.     HXPersistentComponentManager* pPersistentComponentManager = NULL;
  1334.     if (!pGroup)
  1335.     {
  1336. return HXR_UNEXPECTED;
  1337.     }
  1338.     
  1339.     pGroupProperties = ((HXAdvancedGroup*)pGroup)->m_pGroupProperties;
  1340. #if defined(HELIX_FEATURE_NESTEDMETA)
  1341.     if (pGroupProperties)
  1342.     {
  1343. if (HXR_OK != pGroupProperties->GetPropertyULONG32("LastGroupInRAM20", ulLastGroupInRAM20) &&
  1344.     HXR_OK == pGroupProperties->GetPropertyULONG32("PersistentComponentID", ulPersistentComponentID))
  1345. {
  1346.     pPersistentComponentManager = m_pPlayer->m_pPersistentComponentManager;
  1347.     if (HXR_OK == pPersistentComponentManager->GetPersistentComponent(ulPersistentComponentID,
  1348.       pPersistentComponent))
  1349.     {
  1350. ((HXPersistentComponent*)pPersistentComponent)->m_uGroups++;
  1351. uInsertGroupAt = ((HXPersistentComponent*)pPersistentComponent)->m_pSourceInfo->m_uGroupID +
  1352.  ((HXPersistentComponent*)pPersistentComponent)->m_uGroups;
  1353. theErr = InsertGroupAt(uInsertGroupAt, pGroup);
  1354.     }
  1355.     else
  1356.     {
  1357. HX_ASSERT(FALSE);
  1358.     }
  1359. }
  1360. else
  1361. {
  1362.     HX_ASSERT(ulLastGroupInRAM20);
  1363.     InsertGroupAt(m_uGroupCount, pGroup);
  1364. }
  1365.     }
  1366.     else
  1367. #endif /* HELIX_FEATURE_NESTEDMETA */
  1368.     {
  1369. InsertGroupAt(m_uGroupCount, pGroup);
  1370.     }
  1371.     
  1372.     HX_RELEASE(pPersistentComponent);
  1373.     return theErr;
  1374. }
  1375. /************************************************************************
  1376. *  Method:
  1377. *      IHXGroupManager::RemoveGroup
  1378. *  Purpose:
  1379. * Remove an already added group
  1380. */
  1381. STDMETHODIMP
  1382. HXAdvancedGroupManager::RemoveGroup(UINT16  /*IN*/ uGroupIndex)
  1383. {
  1384.     HX_RESULT theErr = HXR_OK;
  1385.     int i = 0;
  1386.     CHXMapLongToObj* pNewGroupMap = NULL;
  1387.     IHXGroup* pHXGroupRemoved = NULL;
  1388.     IHXGroup* pHXGroup = NULL;
  1389.     CHXSimpleList::Iterator ndx;
  1390.     if (!m_pGroupMap->Lookup(uGroupIndex, (void*&)pHXGroupRemoved))
  1391.     {
  1392. theErr = HXR_UNEXPECTED;
  1393. goto cleanup;
  1394.     }
  1395.     m_pGroupMap->RemoveKey(uGroupIndex);
  1396.     // adjust track map index
  1397.     pNewGroupMap = new CHXMapLongToObj;
  1398.     for (i = 0; i < uGroupIndex; i++)
  1399.     {
  1400. m_pGroupMap->Lookup(i, (void*&)pHXGroup);
  1401. HX_ASSERT(pHXGroup);
  1402. (*pNewGroupMap)[i] = pHXGroup;
  1403.     }
  1404.     for (i = uGroupIndex + 1; i < m_uGroupCount; i++)
  1405.     {
  1406. m_pGroupMap->Lookup(i, (void*&)pHXGroup);
  1407. HX_ASSERT(pHXGroup);
  1408. ((HXAdvancedGroup*)pHXGroup)->m_uGroupIndex = i - 1;
  1409. (*pNewGroupMap)[i - 1] = pHXGroup;
  1410.     }
  1411.     HX_DELETE(m_pGroupMap);
  1412.     m_pGroupMap = pNewGroupMap;
  1413.     m_uGroupCount--;
  1414.     
  1415.     ndx = m_pSinkList->Begin();
  1416.     for (; ndx != m_pSinkList->End(); ++ndx)
  1417.     {
  1418. IHXGroupSink* pGroupSink = (IHXGroupSink*) (*ndx);
  1419. pGroupSink->GroupRemoved(uGroupIndex, pHXGroupRemoved);
  1420.     }
  1421. cleanup:
  1422.     HX_RELEASE(pHXGroupRemoved);
  1423.     return theErr;
  1424. }    
  1425. STDMETHODIMP
  1426. HXAdvancedGroupManager::SetCurrentGroup(UINT16 uGroupIndex)
  1427. {
  1428.     HX_RESULT res = HXBasicGroupManager::SetCurrentGroup(uGroupIndex);
  1429. #if defined(HELIX_FEATURE_MASTERTAC)
  1430.     if (SUCCEEDED(res) && m_pMasterTAC)
  1431.     {
  1432.        // check for TAC info from new group
  1433.        m_pMasterTAC->ResetTAC(TRUE, TRUE); // reset status & clear master props
  1434.        m_pMasterTAC->CheckGroupForTACInfo(uGroupIndex);
  1435.     }
  1436. #endif // defined(HELIX_FEATURE_MASTERTAC)
  1437.     return res;
  1438. }
  1439. HX_RESULT     
  1440. HXAdvancedGroupManager::RepeatTrackAdded(UINT16 uGroupIndex, UINT16 uTrackIndex, IHXValues* pTrack)
  1441. {
  1442.     return m_pPlayer->RepeatTrackAdded(uGroupIndex, uTrackIndex, pTrack);
  1443. }
  1444. void
  1445. HXAdvancedGroupManager::Close(void)
  1446. {
  1447.     HX_RELEASE(m_pMasterTAC);
  1448.     HXBasicGroupManager::Close();
  1449. }