hxplay.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:277k
- if (uGroupIndex == m_nCurrentGroup &&
- HXR_OK == GetSourceInfo(uGroupIndex, uTrackIndex, pSourceInfo))
- {
- hr = pSourceInfo->SetSoundLevel(uSoundLevel, bReflushAudioDevice);
- }
- else
- {
- hr = HXR_UNEXPECTED;
- }
- return hr;
- }
-
- void
- HXPlayer::CheckSourceRegistration(void)
- {
- BOOL bAtLeastOneRegister = FALSE;
- CHXMapPtrToPtr::Iterator ndxSources = m_pSourceMap->Begin();
- /* Check if we are done. This may be TRUE for empty files */
- for (; ndxSources != m_pSourceMap->End(); ++ndxSources)
- {
- SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSources);
- if (pSourceInfo->m_pSource && pSourceInfo->m_pSource->CanBeResumed())
- {
- pSourceInfo->Register();
- bAtLeastOneRegister = TRUE;
- }
- }
- if (bAtLeastOneRegister)
- {
- RegisterSourcesDone();
- }
- }
- void
- HXPlayer::GetTimingFromURL(CHXURL* pURL, UINT32& ulStart,
- UINT32& ulEnd, UINT32& ulDelay, UINT32& ulDuration)
- {
- IHXValues* pURLOptions = NULL;
- ulStart = 0;
- ulEnd = HX_EOF_TIME;
- ulDelay = 0;
- ulDuration = 0;
- if (pURL)
- {
- pURLOptions = pURL->GetOptions();
- if (pURLOptions)
- {
- pURLOptions->GetPropertyULONG32("Start", ulStart);
- pURLOptions->GetPropertyULONG32("End", ulEnd);
- pURLOptions->GetPropertyULONG32("Delay", ulDelay);
- pURLOptions->GetPropertyULONG32("Duration", ulDuration);
- }
- HX_RELEASE(pURLOptions);
- }
- }
- /************************************************************************
- * Method:
- * IHXOverrideDefaultServices::OverrideServices
- * Purpose:
- * Override default services provided by the G2 system.
- *
- */
- STDMETHODIMP
- HXPlayer::OverrideServices(IUnknown* pContext)
- {
- if (!pContext)
- {
- return HXR_UNEXPECTED;
- }
- #if defined(HELIX_FEATURE_PREFERENCES)
- /* override IHXPreferences */
- IHXPreferences* pPreferences = NULL;
- if (pContext->QueryInterface(IID_IHXPreferences, (void**) &pPreferences)
- == HXR_OK)
- {
- HX_RELEASE(m_pPreferences);
- m_pPreferences = pPreferences;
- }
- #endif /* HELIX_FEATURE_PREFERENCES */
- /* override IHXPlugin2Handler */
- IHXPlugin2Handler* pPlugin2Handler = NULL;
- if (pContext->QueryInterface(IID_IHXPlugin2Handler, (void**) &pPlugin2Handler)
- == HXR_OK)
- {
- HX_RELEASE(m_pPlugin2Handler);
- m_pPlugin2Handler = pPlugin2Handler;
- }
- return HXR_OK;
- }
- /*
- * IHXPlayerNavigator methods
- */
- /************************************************************************
- * Method:
- * IHXPlayerNavigator::AddChildPlayer
- * Purpose:
- * Add child player to the current player
- */
- STDMETHODIMP
- HXPlayer::AddChildPlayer(IHXPlayer* pPlayer)
- {
- #if defined(HELIX_FEATURE_PLAYERNAVIGATOR)
- if (!m_pChildPlayerList)
- {
- m_pChildPlayerList = new CHXSimpleList();
- }
- if (m_pChildPlayerList &&
- !m_pChildPlayerList->Find(pPlayer))
- {
- pPlayer->AddRef();
- m_pChildPlayerList->AddTail(pPlayer);
- }
- return HXR_OK;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_AUTHENTICATION */
- }
- /************************************************************************
- * Method:
- * IHXPlayerNavigator::RemoveChildPlayer
- * Purpose:
- * Remove child player from the current player
- */
- STDMETHODIMP
- HXPlayer::RemoveChildPlayer(IHXPlayer* pPlayer)
- {
- #if defined(HELIX_FEATURE_PLAYERNAVIGATOR)
- if (m_pChildPlayerList)
- {
- LISTPOSITION lPosition = m_pChildPlayerList->Find(pPlayer);
- if (lPosition)
- {
- m_pChildPlayerList->RemoveAt(lPosition);
- HX_RELEASE(pPlayer);
- }
- }
- return HXR_OK;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_AUTHENTICATION */
- }
- /************************************************************************
- * Method:
- * IHXPlayerNavigator::GetNumChildPlayer
- * Purpose:
- * Get number of the child players
- */
- STDMETHODIMP_(UINT16)
- HXPlayer::GetNumChildPlayer()
- {
- #if defined(HELIX_FEATURE_PLAYERNAVIGATOR)
- return m_pChildPlayerList ? m_pChildPlayerList->GetCount() : 0;
- #else
- return 0;
- #endif /* HELIX_FEATURE_AUTHENTICATION */
- }
- /************************************************************************
- * Method:
- * IHXPlayerNavigator::GetChildPlayer
- * Purpose:
- * Get Nth child player
- */
- STDMETHODIMP
- HXPlayer::GetChildPlayer(UINT16 uPlayerIndex,
- REF(IHXPlayer*) pPlayer)
- {
- #if defined(HELIX_FEATURE_PLAYERNAVIGATOR)
- HX_RESULT rc = HXR_OK;
- LISTPOSITION lPosition;
- pPlayer = NULL;
- if (!m_pChildPlayerList)
- {
- rc = HXR_FAILED;
- goto cleanup;
- }
- lPosition = m_pChildPlayerList->FindIndex(uPlayerIndex);
- if (!lPosition)
- {
- rc = HXR_FAILED;
- goto cleanup;
- }
- pPlayer = (IHXPlayer*)m_pChildPlayerList->GetAt(lPosition);
- pPlayer->AddRef();
- cleanup:
- return rc;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_AUTHENTICATION */
- }
- /************************************************************************
- * Method:
- * IHXPlayerNavigator::SetParentPlayer
- * Purpose:
- * Set the parent player
- */
- STDMETHODIMP
- HXPlayer::SetParentPlayer(IHXPlayer* pPlayer)
- {
- #if defined(HELIX_FEATURE_PLAYERNAVIGATOR)
- HX_ASSERT(!m_pParentPlayer);
- HX_RELEASE(m_pParentPlayer);
- m_pParentPlayer = pPlayer;
- pPlayer->AddRef();
- return HXR_OK;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_AUTHENTICATION */
- }
- /************************************************************************
- * Method:
- * IHXPlayerNavigator::RemoveParentPlayer
- * Purpose:
- * Remove the parent player
- */
- STDMETHODIMP
- HXPlayer::RemoveParentPlayer(IHXPlayer* pPlayer)
- {
- #if defined(HELIX_FEATURE_PLAYERNAVIGATOR)
- HX_ASSERT(pPlayer == m_pParentPlayer);
- HX_RELEASE(m_pParentPlayer);
- return HXR_OK;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_AUTHENTICATION */
- }
- /************************************************************************
- * Method:
- * IHXPlayerNavigator::GetParentPlayer
- * Purpose:
- * Get the parent player
- */
- STDMETHODIMP
- HXPlayer::GetParentPlayer(REF(IHXPlayer*) pPlayer)
- {
- #if defined(HELIX_FEATURE_PLAYERNAVIGATOR)
- pPlayer = NULL;
- if (m_pParentPlayer)
- {
- pPlayer = m_pParentPlayer;
- pPlayer->AddRef();
- return HXR_OK;
- }
- else
- {
- return HXR_FAILED;
- }
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_AUTHENTICATION */
- }
- #if defined(HELIX_FEATURE_STATS) && defined(HELIX_FEATURE_REGISTRY)
- // UpdateStatsCallback
- UpdateStatsCallback::UpdateStatsCallback() :
- m_lRefCount (0)
- ,m_pPlayer (0)
- ,m_PendingHandle (0)
- ,m_bIsCallbackPending(FALSE)
- {
- }
- UpdateStatsCallback::~UpdateStatsCallback()
- {
- }
- /*
- * IUnknown methods
- */
- /////////////////////////////////////////////////////////////////////////
- // Method:
- // IUnknown::QueryInterface
- // Purpose:
- // Implement this to export the interfaces supported by your
- // object.
- //
- STDMETHODIMP UpdateStatsCallback::QueryInterface(REFIID riid, void** ppvObj)
- {
- QInterfaceList qiList[] =
- {
- { GET_IIDHANDLE(IID_IHXCallback), (IHXCallback*)this },
- { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXCallback*)this },
- };
-
- return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
- }
- /////////////////////////////////////////////////////////////////////////
- // Method:
- // IUnknown::AddRef
- // Purpose:
- // Everyone usually implements this the same... feel free to use
- // this implementation.
- //
- STDMETHODIMP_(ULONG32) UpdateStatsCallback::AddRef()
- {
- return InterlockedIncrement(&m_lRefCount);
- }
- /////////////////////////////////////////////////////////////////////////
- // Method:
- // IUnknown::Release
- // Purpose:
- // Everyone usually implements this the same... feel free to use
- // this implementation.
- //
- STDMETHODIMP_(ULONG32) UpdateStatsCallback::Release()
- {
- if (InterlockedDecrement(&m_lRefCount) > 0)
- {
- return m_lRefCount;
- }
- delete this;
- return 0;
- }
- /*
- * IHXCallback methods
- */
- STDMETHODIMP UpdateStatsCallback::Func(void)
- {
- m_PendingHandle = 0;
- m_bIsCallbackPending = FALSE;
- if (m_pPlayer)
- {
- m_pPlayer->UpdateStatistics();
- }
- return HXR_OK;
- }
- #endif /* HELIX_FEATURE_STATS && HELIX_FEATURE_REGISTRY */
- // HXCallback
- #if defined (_WIN32) || defined (_MACINTOSH) || defined(THREADS_SUPPORTED)
- HXPlayerCallback::HXPlayerCallback(void* pParam, fGenericCBFunc pFunc)
- : CHXGenericCallback(pParam, pFunc)
- , m_bInterrupSafe(FALSE)
- {
- }
-
- STDMETHODIMP HXPlayerCallback::QueryInterface(REFIID riid, void** ppvObj)
- {
- if (IsEqualIID(riid, IID_IHXInterruptSafe))
- {
- AddRef();
- *ppvObj = (IUnknown*)(IHXInterruptSafe*)this;
- return HXR_OK;
- }
- else
- {
- return CHXGenericCallback::QueryInterface(riid, ppvObj);
- }
- }
- STDMETHODIMP_(BOOL) HXPlayerCallback::IsInterruptSafe()
- {
- HXPlayer* pPlayer = (HXPlayer*)m_pParam;
- return m_bInterrupSafe &&
- pPlayer->m_bInitialized &&
- !pPlayer->m_bIsDone;
- }
- #endif //(_WIN32) || defined (_MACINTOSH) || defined(THREADS_SUPPORTED)
- void HXPlayer::PlayerCallback(void* pParam)
- {
- HXPlayer* pObj = (HXPlayer*)pParam;
- if (pObj)
- {
- pObj->ProcessIdle();
- }
- }
- void HXPlayer::SetupCallback(void* pParam)
- {
- HXPlayer* pObj = (HXPlayer*)pParam;
- if (pObj)
- {
- pObj->SetupAudioPlayer();
- }
- }
- #if defined(HELIX_FEATURE_AUTHENTICATION)
- void HXPlayer::AuthenticationCallback(void* pParam)
- {
- HXPlayer* pObj = (HXPlayer*)pParam;
- if (pObj)
- {
- pObj->ProcessPendingAuthentication();
- }
- }
- #endif //HELIX_FEATURE_AUTHENTICATION
- /************************************************************************
- * Method:
- * HXPlayer::SetupRendererSite
- *
- * NOTE: Notice that the props passed in are associated with the stream
- * that the renderer is rendering, but we don't make renderers implement
- * their own support IHXValues. That would be mean.
- */
- void
- HXPlayer::SetupRendererSite(IUnknown* pRenderer, IHXValues* pProps, BOOL bIsPersistent)
- {
- #if defined(HELIX_FEATURE_VIDEO)
- HX_ASSERT(pProps);
- HX_ASSERT(pRenderer);
- IHXSiteUserSupplier* pSUS = NULL;
- IHXSiteUser* pSU = NULL;
- UINT32 uReqestID;
- /*
- * If the renderer doesn't support IHXSiteUserSupplier then
- * it is not a display oriented renderer and we skip it to
- * go to the next one!
- */
- if (HXR_OK == pRenderer->QueryInterface(IID_IHXSiteUserSupplier,
- (void**)&pSUS))
- {
- /*
- * Ask the site manager if any sites are available
- * for the renderer by this playto/from info.
- */
- if (!m_pSiteManager->
- IsSiteAvailableByPlayToFrom(pProps, /*bIsPersistent*/ FALSE))
- {
- if (m_pSiteSupplier)
- {
- /*
- * Let the site supplier know that we are changing the layout.
- */
- if (m_bBeginChangeLayoutTobeCalled)
- {
- m_bBeginChangeLayoutTobeCalled = FALSE;
- m_pSiteSupplier->BeginChangeLayout();
- }
- // XXXRA Change to revert back to old focus behavior for
- // datatypes that rely on this behavior
- CheckIfRendererNeedFocus(pRenderer);
- /*
- * Inform the TLC/SS of the new sites we need.
- */
- uReqestID = (ULONG32)pSUS;
- m_pSiteSupplier->SitesNeeded(uReqestID,pProps);
- DisableScreenSaver();
- m_SiteRequestIDList.AddTail((void*)uReqestID);
- }
- }
- /* JEB: if the hookup failed, do not release the site user
- * Hookup will add it to a list and hook it up later
- * when the site has really been added
- */
- if (m_pSiteManager->HookupByPlayToFrom(pSUS,pProps,/*bIsPersistent*/ FALSE))
- {
- pSUS->Release();
- }
- }
- // If the renderer doesn't support SiteUserSupplier, than see if
- // it supports single instance as a SiteUser...
- else if (HXR_OK == pRenderer->QueryInterface(IID_IHXSiteUser,
- (void**)&pSU))
- {
- /*
- * Ask the site manager if any sites are available
- * for the renderer by this playto/from info.
- */
- if (!m_pSiteManager->
- IsSiteAvailableByPlayToFrom(pProps, /*bIsPersistent*/ FALSE))
- {
- if (m_pSiteSupplier)
- {
- /*
- * Let the site supplier know that we are changing the layout.
- */
- if (m_bBeginChangeLayoutTobeCalled)
- {
- m_bBeginChangeLayoutTobeCalled = FALSE;
- m_pSiteSupplier->BeginChangeLayout();
- }
- // XXXRA Change to revert back to old focus behavior for
- // datatypes that rely on this behavior
- CheckIfRendererNeedFocus(pRenderer);
- /*
- * Inform the TLC/SS of the new sites we need.
- */
- uReqestID = (ULONG32)pSU;
- m_pSiteSupplier->SitesNeeded(uReqestID,pProps);
- DisableScreenSaver();
- m_SiteRequestIDList.AddTail((void*)uReqestID);
- }
- }
- /* JEB: if the hookup failed, do not release the site user
- * Hookup will add it to a list and hook it up later
- * when the site has really been added
- */
- if (m_pSiteManager->HookupSingleSiteByPlayToFrom(pSU,pProps, /*bIsPersistent*/ FALSE))
- {
- pSU->Release();
- }
- }
- #endif /* HELIX_FEATURE_VIDEO */
- }
- /************************************************************************
- * Method:
- * HXPlayer::SetupLayoutSiteGroup
- */
- void
- HXPlayer::SetupLayoutSiteGroup(IUnknown* pLSG, BOOL bIsPersistent)
- {
- #if defined(HELIX_FEATURE_VIDEO)
- HX_ASSERT(pLSG);
- IHXSiteUserSupplier* pSUS = NULL;
- IHXSiteUser* pSU = NULL;
- if (HXR_OK == pLSG->QueryInterface(IID_IHXSiteUserSupplier,
- (void**)&pSUS))
- {
- IHXValues* pSUSProps = NULL;
- BOOL releaseSUS = TRUE;
- if (HXR_OK == pSUS->QueryInterface(IID_IHXValues,
- (void**)&pSUSProps))
- {
- /*
- * Ask the site manager if any sites are available
- * for the LSG by this LSGName.
- */
- if (!m_pSiteManager->IsSiteAvailableByLSGName(pSUSProps,
- /*bIsPersistent*/ FALSE))
- {
- if (m_pSiteSupplier)
- {
- /*
- * Let the site supplier know that we are changing the layout.
- */
- if (m_bBeginChangeLayoutTobeCalled)
- {
- m_bBeginChangeLayoutTobeCalled = FALSE;
- m_pSiteSupplier->BeginChangeLayout();
- }
- /*
- * Inform the TLC/SS of the new sites we need.
- */
- ULONG32 uReqestID = (ULONG32)pSUS;
- m_pSiteSupplier->SitesNeeded(uReqestID,pSUSProps);
- DisableScreenSaver();
- m_SiteRequestIDList.AddTail((void*)uReqestID);
- }
- }
- /*
- * We can now assume that the site supplier has added
- * any sites for this set of properties to the site
- * manager that it is willing to provide.
- *
- * Tell the site manager to hook up the site user to
- * any sites with the same LSGName as the layoutSiteGroup.
- *
- * Hookup will also create child sites for the tuners,
- * But these are added to the site manager with a flag
- * which states how they can be used (for renderers only).
- * Because we don't want to accidentally connect one of these
- * tuner sites as a LSG.
- */
- /* JEB: if the hookup failed, do not release the site user
- * Hookup will add it to a list and hook it up later
- * when the site has really been added
- */
- if (!m_pSiteManager->HookupByLSGName(pSUS,pSUSProps,/*bIsPersistent*/ FALSE))
- {
- releaseSUS = FALSE;
- }
- pSUSProps->Release();
- }
- if (releaseSUS)
- {
- pSUS->Release();
- }
- }
- // If the LSG doesn't support SiteUserSupplier, than see if it supports
- // single instance as a SiteUser...
- else if (HXR_OK == pLSG->QueryInterface(IID_IHXSiteUser,
- (void**)&pSU))
- {
- IHXValues* pSUProps = NULL;
- BOOL releaseSU = TRUE;
- if (HXR_OK == pSU->QueryInterface(IID_IHXValues,
- (void**)&pSUProps))
- {
- /*
- * Ask the site manager if any sites are available
- * for the LSG by this LSGName.
- */
- if (!m_pSiteManager->IsSiteAvailableByLSGName(pSUProps,
- /*bIsPersistent*/ FALSE))
- {
- if (m_pSiteSupplier)
- {
- /*
- * Let the site supplier know that we are changing the layout.
- */
- if (m_bBeginChangeLayoutTobeCalled)
- {
- m_bBeginChangeLayoutTobeCalled = FALSE;
- m_pSiteSupplier->BeginChangeLayout();
- }
- /*
- * Inform the TLC/SS of the new sites we need.
- */
- ULONG32 uReqestID = (ULONG32)pSU;
- m_pSiteSupplier->SitesNeeded(uReqestID,pSUProps);
- DisableScreenSaver();
- m_SiteRequestIDList.AddTail((void*)uReqestID);
- }
- }
- /*
- * We can now assume that the site supplier has added
- * any sites for this set of properties to the site
- * manager that it is willing to provide.
- *
- * Tell the site manager to hook up the site user to
- * any sites with the same LSGName as the layoutSiteGroup.
- *
- * Hookup will also create child sites for the tuners,
- * But these are added to the site manager with a flag
- * which states how they can be used (for renderers only).
- * Because we don't want to accidentally connect one of these
- * tuner sites as a LSG.
- */
- /* JEB: if the hookup failed, do not release the site user
- * Hookup will add it to a list and hook it up later
- * when the site has really been added
- */
- if (!m_pSiteManager->HookupSingleSiteByLSGName(pSU,pSUProps,/*bIsPersistent*/ FALSE))
- {
- releaseSU = FALSE;
- }
- pSUProps->Release();
- }
- if (releaseSU)
- {
- pSU->Release();
- }
- }
- #endif /* HELIX_FEATURE_VIDEO */
- }
- /************************************************************************
- * Method:
- * HXPlayer::SetupLayout
- * Purpose:
- * shuts down old layout and sets up new layout. If bShowNewLayout
- * is FALSE then new layout is not set up.
- */
- STDMETHODIMP
- HXPlayer::SetupLayout(BOOL bIsPersistent)
- {
- CHXMapPtrToPtr::Iterator ndxSource = m_pSourceMap->Begin();
- for (; ndxSource != m_pSourceMap->End(); ++ndxSource)
- {
- SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSource);
- pSourceInfo->SetupRendererSites(bIsPersistent);
- }
- return HXR_OK;
- }
- /************************************************************************
- * Method:
- * HXPlayer::CleanupLayout
- * Purpose:
- * shuts down old layout
- */
- STDMETHODIMP
- HXPlayer::CleanupLayout()
- {
- /*
- * For each Site/SiteUser combination unhook them because
- * the layout is changing. You might think that this is
- * only appropriate for associations by LSGName, but we do it
- * for all because we want this implementation to work for
- * empty-layouts as well.
- *
- * Note this also means to unhook any and all site/user
- * combinations for child sites for each of these sites.
- * This means that all layouts are released.
- */
- #if defined(HELIX_FEATURE_VIDEO)
- if (m_pSiteManager) m_pSiteManager->UnhookAll();
- /*
- * Run through all previous requested sites... Note:
- * this is not the same as the list of layoutGroupSites
- * since we don't request ones that were available when
- * we set the layout.
- */
- CHXSimpleList::Iterator ndxRequest = m_SiteRequestIDList.Begin();
- for (; ndxRequest != m_SiteRequestIDList.End(); ++ndxRequest)
- {
- ULONG32 requestID = (ULONG32)(*ndxRequest);
- if (m_pSiteSupplier)
- {
- /*
- * Let the site supplier know that we are changing the layout.
- */
- if (m_bBeginChangeLayoutTobeCalled)
- {
- m_bBeginChangeLayoutTobeCalled = FALSE;
- m_pSiteSupplier->BeginChangeLayout();
- }
- /*
- * Inform the TLC/SS that we don't need old sites.
- */
- m_pSiteSupplier->SitesNotNeeded(requestID);
- }
- }
- m_SiteRequestIDList.RemoveAll();
- #endif /* HELIX_FEATURE_VIDEO */
- return HXR_OK;
- }
- void
- HXPlayer::InternalPause()
- {
- if (!m_bIsFirstBegin && !m_bBeginPending && !m_bTimelineToBeResumed)
- {
- m_bIsPlaying = FALSE;
- m_bTimelineToBeResumed = TRUE;
- m_pAudioPlayer->Pause();
- // DEBUG_OUT(this, (s,
- // "Pause Timeline %p", this));
- }
- }
- /*
- * IHXGroupSink methods
- */
- /************************************************************************
- * Method:
- * IHXGroupSink::GroupAdded
- * Purpose:
- * Notification of a new group being added to the presentation.
- */
- STDMETHODIMP
- HXPlayer::GroupAdded(UINT16 /*IN*/ uGroupIndex,
- IHXGroup* /*IN*/ pGroup)
- {
- #if defined(HELIX_FEATURE_BASICGROUPMGR)
- m_nGroupCount++;
- if (m_nCurrentGroup == m_pGroupManager->GetGroupCount() - 1)
- {
- m_bLastGroup = TRUE;
- }
- else
- {
- m_bLastGroup = FALSE;
- }
- #endif /* HELIX_FEATURE_BASICGROUPMGR */
- return HXR_OK;
- }
- /************************************************************************
- * Method:
- * IHXGroupSink::GroupRemoved
- * Purpose:
- * Notification of a group being removed from the presentation.
- */
- STDMETHODIMP
- HXPlayer::GroupRemoved(UINT16 /*IN*/ uGroupIndex,
- IHXGroup* /*IN*/ pGroup)
- {
- #if defined(HELIX_FEATURE_BASICGROUPMGR)
- if (m_nGroupCount > 0)
- m_nGroupCount--;
- UINT16 uNumGroups = m_pGroupManager->GetGroupCount();
- if (uNumGroups == 0 ||
- m_nCurrentGroup == uNumGroups - 1)
- {
- m_bLastGroup = TRUE;
- }
- else
- {
- m_bLastGroup = FALSE;
- }
- return HXR_OK;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_BASICGROUPMGR */
- }
- /************************************************************************
- * Method:
- * IHXGroupSink::AllGroupsRemoved
- * Purpose:
- * Notification that all groups have been removed from the
- * current presentation.
- */
- STDMETHODIMP
- HXPlayer::AllGroupsRemoved(void)
- {
- HX_RELEASE(m_pCurrentGroup);
- return HXR_OK;
- }
- /************************************************************************
- * Method:
- * IHXGroupSink::TrackAdded
- * Purpose:
- * Notification of a new track being added to a group.
- */
- STDMETHODIMP
- HXPlayer::TrackAdded(UINT16 /*IN*/ uGroupIndex,
- UINT16 /*IN*/ uTrackIndex,
- IHXValues* /*IN*/ pTrack)
- {
- #if defined(HELIX_FEATURE_BASICGROUPMGR)
- HX_RESULT theErr = HXR_OK;
- UINT16 uPrefetchSourceIndex = 0;
- char szDelay[] = "Delay";
- UINT32 ulDelay = 0;
- SourceInfo* pSourceInfo = NULL;
- IHXGroup* pThisGroup = NULL;
- IHXPrefetch* pPrefetch = NULL;
- m_pGroupManager->GetGroup(uGroupIndex, pThisGroup);
- /* Check if a track is added to the group currently played */
- if (uGroupIndex == m_nCurrentGroup &&
- m_pCurrentGroup == pThisGroup)
- {
- #if defined(HELIX_FEATURE_PREFETCH)
- // determine whether the track has been prefetched
- if (m_pPrefetchManager &&
- m_pPrefetchManager->Lookup(pTrack, pSourceInfo))
- {
- pSourceInfo->m_pSource->PartOfPrefetchGroup(FALSE);
- if (HXR_OK == m_pCurrentGroup->QueryInterface(IID_IHXPrefetch,
- (void**)&pPrefetch))
- {
- theErr = pPrefetch->RemovePrefetchTrack(pSourceInfo->m_uTrackID);
- }
- HX_RELEASE(pPrefetch);
- pSourceInfo->m_uGroupID = uGroupIndex;
- pSourceInfo->m_uTrackID = uTrackIndex;
- PrepareSourceInfo(pTrack, pSourceInfo);
- pSourceInfo->m_pSource->UpdatePlayTimes(pTrack);
- m_pSourceMap->SetAt((void*)pSourceInfo->m_pSource,
- (void*)pSourceInfo);
- m_bPlayerWithoutSources = FALSE;
- m_bSourceMapUpdated = TRUE;
- m_bForceStatsUpdate = TRUE;
- m_uNumSourcesActive++;
- m_uNumCurrentSourceNotDone++;
- AdjustPresentationTime();
- InternalPause();
- }
- /* If we are not yet initialized, add tracks to the current source
- * map only if the track is within the fudge factor.
- *
- * This is to fix a bug in SMIL file with multiple sources in seq
- * with outer par.
- * The expected behavior is to start the first source
- * in seq and then initialize the remaining sources. Since we were
- * adding additional tracks to the source map, the player was not
- * getting initialized until ALL the sources in the seq have been
- * initialized. This resulted in massive startup delays.
- */
- else if (!m_bInitialized)
- #else
- if (!m_bInitialized)
- #endif
- {
- if ((HXR_OK != pTrack->GetPropertyULONG32(szDelay,ulDelay)) ||
- (ulDelay <= m_ulCurrentPlayTime + MIN_DELAYBEFORE_START))
- {
- theErr = OpenTrack(pTrack, uGroupIndex, uTrackIndex);
- }
- else
- {
- if (!m_pPendingTrackList)
- {
- m_pPendingTrackList = new CHXSimpleList;
- }
- PendingTrackInfo* pPendingTrackInfo =
- new PendingTrackInfo(uGroupIndex, uTrackIndex, pTrack);
- m_pPendingTrackList->AddTail(pPendingTrackInfo);
- }
- }
- else
- {
- theErr = OpenTrack(pTrack, uGroupIndex, uTrackIndex);
- }
- if (theErr)
- {
- ReportError(NULL, theErr, NULL);
- }
- }
- /* Check if a track is added to the group that is being prefetch */
- else
- {
- #if defined(HELIX_FEATURE_NEXTGROUPMGR)
- IHXGroup* pGroup = NULL;
- UINT16 uCurrentGroup = 0;
- if (m_bNextGroupStarted &&
- (m_pNextGroupManager->GetCurrentGroup(uCurrentGroup, pGroup)
- == HXR_OK) &&
- uCurrentGroup == uGroupIndex &&
- pGroup == pThisGroup)
- {
- m_bPartOfNextGroup = TRUE;
- theErr = OpenTrack(pTrack, uGroupIndex, uTrackIndex);
- if (theErr)
- {
- ReportError(NULL, theErr, NULL);
- }
- m_bPartOfNextGroup = FALSE;
- }
- HX_RELEASE(pGroup);
- #endif /* HELIX_FEATURE_NEXTGROUPMGR */
- }
- HX_RELEASE(pThisGroup);
- return HXR_OK;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_BASICGROUPMGR */
- }
- HX_RESULT
- HXPlayer::RepeatTrackAdded(UINT16 /*IN*/ uGroupIndex,
- UINT16 /*IN*/ uTrackIndex,
- IHXValues* /*IN*/ pTrack)
- {
- #if defined(HELIX_FEATURE_ADVANCEDGROUPMGR) && defined(HELIX_FEATURE_SMIL_REPEAT)
- HX_RESULT theErr = HXR_OK;
- UINT16 uCurrentGroup = 0;
- SourceInfo* pSourceInfo = NULL;
- IHXGroup* pGroup = NULL;
- IHXGroup* pThisGroup = NULL;
- m_pGroupManager->GetGroup(uGroupIndex, pThisGroup);
- if (HXR_OK == GetSourceInfo(uGroupIndex, uTrackIndex, pSourceInfo))
- {
- theErr = pSourceInfo->AppendRepeatRequest(uTrackIndex, pTrack);
- AdjustPresentationTime();
- }
- #if defined(HELIX_FEATURE_NEXTGROUPMGR)
- else if (m_bNextGroupStarted &&
- (m_pNextGroupManager->GetCurrentGroup(uCurrentGroup, pGroup) == HXR_OK) &&
- uCurrentGroup == uGroupIndex &&
- pGroup == pThisGroup)
- {
- m_pNextGroupManager->AddRepeatTrack(uTrackIndex, pTrack);
- }
- #endif /* HELIX_FEATURE_NEXTGROUPMGR */
- else
- {
- // XXX HP something is wrong!!
- HX_ASSERT(FALSE);
- }
- HX_RELEASE(pGroup);
- HX_RELEASE(pThisGroup);
- return theErr;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_ADVANCEDGROUPMGR && HELIX_FEATURE_SMIL_REPEAT */
- }
- /************************************************************************
- * Method:
- * IHXGroupSink::TrackRemoved
- * Purpose:
- * Notification of a track being removed from a group.
- */
- STDMETHODIMP
- HXPlayer::TrackRemoved(UINT16 /*IN*/ uGroupIndex,
- UINT16 /*IN*/ uTrackIndex,
- IHXValues* /*IN*/ pTrack)
- {
- return HXR_OK;
- }
- /************************************************************************
- * Method:
- * IHXGroupSink::TrackStarted
- * Purpose:
- * Notification of a track being started in a group.
- */
- STDMETHODIMP
- HXPlayer::TrackStarted(UINT16 /*IN*/ uGroupIndex,
- UINT16 /*IN*/ uTrackIndex,
- IHXValues* /*IN*/ pTrack)
- {
- return HXR_OK;
- }
- /************************************************************************
- * Method:
- * IHXGroupSink::TrackStopped
- * Purpose:
- * Notification of a track being stopped in a group.
- */
- STDMETHODIMP
- HXPlayer::TrackStopped(UINT16 /*IN*/ uGroupIndex,
- UINT16 /*IN*/ uTrackIndex,
- IHXValues* /*IN*/ pTrack)
- {
- return HXR_OK;
- }
- /************************************************************************
- * Method:
- * IHXGroupSink::CurrentGroupSet
- * Purpose:
- * This group is being currently played in the presentation.
- */
- STDMETHODIMP
- HXPlayer::CurrentGroupSet(UINT16 /*IN*/ uGroupIndex,
- IHXGroup* /*IN*/ pGroup)
- {
- #if defined(HELIX_FEATURE_BASICGROUPMGR)
- HX_RESULT theErr = HXR_OK;
- m_bCoreLocked = TRUE;
- m_pCoreMutex->Lock();
- /* If we called SetCurrentGroup, ignore this callback */
- m_bIsPresentationClosedToBeSent = FALSE;
- StopAllStreams(END_STOP);
- m_bIsPresentationClosedToBeSent = TRUE;
- ResetGroup();
- m_bInitialized = FALSE;
- m_bIsDone = FALSE;
- m_ulActiveSureStreamSource = 0;
- m_bFastStartCheckDone = FALSE;
- m_turboPlayOffReason = TP_OFF_BY_UNKNOWN;
- // uGroupIndex is needed to determine whether destroy the root layout
- // during group switching under nested meta support
- // uGroupIndex is used by IHXPersistentComponentManager::CloseAllRenderers()
- // which is called in CloseAllRenderers()
- CloseAllRenderers(uGroupIndex);
- /* Open this group here */
- /* Ask the next group manager for this group */
- UINT16 uCurrentGroup = 0;
- IHXGroup* pCurGroup = NULL;
- #if defined(HELIX_FEATURE_NEXTGROUPMGR)
- if (m_pNextGroupManager->GetCurrentGroup(uCurrentGroup, pCurGroup) == HXR_OK &&
- uCurrentGroup == uGroupIndex && pCurGroup == pGroup)
- {
- SourceInfo* pSourceInfo = NULL;
- UINT16 uNumSources = m_pNextGroupManager->GetNumSources();
- for (UINT16 i = 0; i < uNumSources; i++)
- {
- m_pNextGroupManager->GetSource(i, pSourceInfo);
- if (pSourceInfo->m_pSource)
- {
- m_pSourceMap->SetAt((void*) pSourceInfo->m_pSource,
- (void*) pSourceInfo);
- m_bPlayerWithoutSources = FALSE;
- m_bSourceMapUpdated = TRUE;
- pSourceInfo->m_pSource->PartOfNextGroup(FALSE);
- if (pSourceInfo->m_bTobeInitializedBeforeBegin)
- {
- m_uNumSourceToBeInitializedBeforeBegin++;
- }
- // update the registries (from NextGroup.* to Player.*)
- UpdateSourceInfo(pSourceInfo,
- #if defined(HELIX_FEATURE_STATS) && defined(HELIX_FEATURE_REGISTRY)
- m_pStats->m_ulRegistryID,
- #else
- NULL,
- #endif /* HELIX_FEATURE_STATS && HELIX_FEATURE_REGISTRY */
- pSourceInfo->m_uTrackID);
- }
- }
- m_pNextGroupManager->RemoveAllSources();
- const char* pErrorString = NULL;
- HXSource* pSource = NULL;
- theErr = m_pNextGroupManager->GetLastError(pSource, pErrorString);
- if (theErr)
- {
- SetLastError(theErr);
- }
- if (m_LastError != HXR_OK)
- {
- m_bIsDone = TRUE;
- ReportError(pSource, m_LastError, pErrorString);
- }
- else
- {
- m_nCurrentGroup = uGroupIndex;
- }
- m_pNextGroupManager->Cleanup();
- /* Get the duration from group properties */
- UINT32 ulGroupDuration = 0;
- IHXValues* pGroupProps = pGroup->GetGroupProperties();
- if (pGroupProps &&
- pGroupProps->GetPropertyULONG32("Duration", ulGroupDuration)
- == HXR_OK)
- {
- m_ulPresentationDuration = ulGroupDuration;
- }
- HX_RELEASE(pGroupProps);
- m_bIsPresentationClosedToBeSent = FALSE;
- }
- else
- #endif /* HELIX_FEATURE_NEXTGROUPMGR */
- {
- #if defined(HELIX_FEATURE_NEXTGROUPMGR)
- /* Cleanup any next group that we may have started downloading */
- m_pNextGroupManager->Cleanup();
- #endif /* HELIX_FEATURE_NEXTGROUPMGR */
- m_nCurrentGroup = uGroupIndex;
- theErr = DoOpenGroup(uGroupIndex);
- }
- if (uGroupIndex == (m_pGroupManager->GetGroupCount() - 1))
- {
- m_bLastGroup = TRUE;
- }
- else
- {
- m_bLastGroup = FALSE;
- }
- m_pCurrentGroup = pGroup;
- m_pCurrentGroup->AddRef();
- m_bNextGroupStarted = FALSE;
- HX_RELEASE(pCurGroup);
- if (!theErr && !m_LastError && m_bUserHasCalledBegin)
- {
- Begin();
- }
- SchedulePlayer();
- if (theErr)
- {
- ReportError(NULL, theErr, NULL);
- }
- m_pCoreMutex->Unlock();
- m_bCoreLocked = FALSE;
- return HXR_OK;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_BASICGROUPMGR */
- }
- /************************************************************************
- * Method:
- * IHXGroupSink::CurrentGroupSet
- * Purpose:
- * This group is set to be played next in the presentation.
- */
- HX_RESULT
- HXPlayer::NextGroupSet(UINT16 /*IN*/ uGroupIndex)
- {
- #if defined(HELIX_FEATURE_NEXTGROUPMGR)
- /* Ask the next group manager for this group */
- UINT16 uCurrentGroup = 0;
- IHXGroup* pCurGroup = NULL;
- if (m_pNextGroupManager && m_pNextGroupManager->GetCurrentGroup(uCurrentGroup,
- pCurGroup) == HXR_OK)
- {
- // the next group being set is already the next group, so don't do anything
- if (uCurrentGroup == uGroupIndex)
- {
- return HXR_OK;
- }
- /* Cleanup any next group that we may have started downloading */
- m_pNextGroupManager->Cleanup();
- m_bNextGroupStarted = FALSE;
- }
- return HXR_OK;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_NEXTGROUPMGR */
- }
- /************************************************************************
- * Method:
- * IHXRendererUpgrade::IsRendererAvailable
- * Purpose:
- * See if a renderer with this mime type has been loaded
- */
- STDMETHODIMP_(BOOL)
- HXPlayer::IsRendererAvailable(const char* pMimeType)
- {
- BOOL bAvailable = FALSE;
- #if defined(HELIX_FEATURE_AUTOUPGRADE)
- // create an upgrade collection
- HXUpgradeCollection* pCheckComponent = new HXUpgradeCollection;
- if (pCheckComponent)
- {
- pCheckComponent->AddRef();
- CHXBuffer* pBuffer = new CHXBuffer;
- pBuffer->AddRef();
- pBuffer->Set((BYTE*)pMimeType, strlen(pMimeType)+1);
- // add the component to the list
- pCheckComponent->Add(eUT_Required, pBuffer, 0, 0);
- HX_RELEASE(pBuffer);
- // Request the upgrade handler
- IHXUpgradeHandler* pUpgradeHandler = NULL;
- if(m_pClient &&
- m_pClient->QueryInterface(IID_IHXUpgradeHandler, (void**)&pUpgradeHandler) == HXR_OK)
- {
- // now see if the upgrade handler already has this component
- if(pUpgradeHandler->HasComponents(pCheckComponent) == HXR_OK)
- {
- bAvailable = TRUE;
- }
- HX_RELEASE(pUpgradeHandler);
- }
- }
- HX_RELEASE(pCheckComponent);
- #endif /* HELIX_FEATURE_AUTOUPGRADE */
- // return component availability
- return(bAvailable);
- }
- /************************************************************************
- * Method:
- * IHXRendererUpgrade::ForceUpgrade
- * Purpose:
- * Use the force to upgrade all renderers
- */
- STDMETHODIMP
- HXPlayer::ForceUpgrade()
- {
- return HXR_UNEXPECTED;
- }
- /************************************************************************
- * Method:
- * IHXLayoutSiteGroupManager::AddLayoutSiteGroup
- * Purpose:
- * Add LSG to the presentation.
- */
- STDMETHODIMP
- HXPlayer::AddLayoutSiteGroup(IUnknown* /*IN*/ pLSG)
- {
- #if defined(HELIX_FEATURE_VIDEO)
- m_bAddLayoutSiteGroupCalled = TRUE;
- SetupLayoutSiteGroup(pLSG, TRUE);
- return HXR_OK;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_VIDEO */
- }
- /************************************************************************
- * Method:
- * IHXLayoutSiteGroupManager::RemoveLayoutSiteGroup
- * Purpose:
- * Remove LSG from the presentation.
- */
- STDMETHODIMP
- HXPlayer::RemoveLayoutSiteGroup(IUnknown* pLSG)
- {
- #if defined(HELIX_FEATURE_PLAYERNAVIGATOR)
- HX_ASSERT(pLSG);
- IHXSiteUserSupplier* pSUS = NULL;
- IHXSiteUser* pSU = NULL;
- BOOL bIsPersistent = TRUE; // assume called by a persistent renderer
- if (HXR_OK == pLSG->QueryInterface(IID_IHXSiteUserSupplier,
- (void**)&pSUS))
- {
- IHXValues* pSUSProps = NULL;
- BOOL releaseSUS = TRUE;
- if (HXR_OK == pSUS->QueryInterface(IID_IHXValues,
- (void**)&pSUSProps))
- {
- #if defined(HELIX_FEATURE_VIDEO)
- m_pSiteManager->RemoveSitesByLSGName(pSUSProps, /*bIsPersistent*/ FALSE);
- //m_pSiteManager->UnhookByLSGName(pSUS, pSUSProps, bIsPersistent);
- #endif //HELIX_FEATURE_VIDEO
- pSUSProps->Release();
- }
- pSUS->Release();
- }
- // If the LSG doesn't support SiteUserSupplier, than see if it supports
- // single instance as a SiteUser...
- else if (HXR_OK == pLSG->QueryInterface(IID_IHXSiteUser,
- (void**)&pSU))
- {
- IHXValues* pSUProps = NULL;
- if (HXR_OK == pSU->QueryInterface(IID_IHXValues,
- (void**)&pSUProps))
- {
- #if defined(HELIX_FEATURE_VIDEO)
- m_pSiteManager->RemoveSitesByLSGName(pSUProps, /*bIsPersistent*/ FALSE);
- // m_pSiteManager->UnhookByLSGName(pSU, pSUProps, bIsPersistent);
- #endif //HELIX_FEATURE_VIDEO
- pSUProps->Release();
- }
- pSU->Release();
- }
- m_bAddLayoutSiteGroupCalled = FALSE;
- return HXR_OK;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_VIDEO */
- }
- /*
- * IHXInternalReset method
- */
- STDMETHODIMP
- HXPlayer::InternalReset(void)
- {
- m_bCoreLocked = TRUE;
- m_pCoreMutex->Lock();
- m_bInternalReset = TRUE;
- PausePlayer();
- BeginPlayer();
- m_bInternalReset = FALSE;
- m_pCoreMutex->Unlock();
- m_bCoreLocked = FALSE;
- return HXR_OK;
- }
- void
- HXPlayer::CheckToStartNextGroup(void)
- {
- if (m_bLastGroup)
- {
- return;
- }
- #if defined(HELIX_FEATURE_BASICGROUPMGR)
- if (m_pGroupManager->GetGroupCount() <= 1)
- {
- m_bLastGroup = TRUE;
- return;
- }
- #if defined(HELIX_FEATURE_NEXTGROUPMGR)
- /* If all sources have ended, start downloading the next group */
- if (m_uNumCurrentSourceNotDone == 0)
- {
- /* Resume prefetching if the next group already has sources */
- if (m_pNextGroupManager->GetNumSources() > 0)
- {
- UnRegisterCurrentSources();
- m_pNextGroupManager->ContinuePreFetch();
- m_bNextGroupStarted = TRUE;
- return;
- }
- if (m_nCurrentGroup < (m_pGroupManager->GetGroupCount() - 1))
- {
- IHXGroup* pGroup = NULL;
- UINT16 uNextGroup = 0;
- m_pGroupManager->GetNextGroup(uNextGroup);
- HX_RESULT theErr = m_pGroupManager->GetGroup(uNextGroup, pGroup);
- if (!theErr)
- {
- m_pNextGroupManager->SetCurrentGroup(uNextGroup, pGroup);
- HX_RELEASE(pGroup);
- UnRegisterCurrentSources();
- m_bPartOfNextGroup = TRUE;
- theErr = DoOpenGroup(uNextGroup);
- m_bPartOfNextGroup = FALSE;
- m_bNextGroupStarted = TRUE;
- DEBUG_OUT(this, DOL_TRANSPORT, (s,"Next Group is prefetched: %lu", uNextGroup));
- if (theErr)
- {
- m_pNextGroupManager->SetLastError(theErr);
- }
- }
- }
- }
- #endif /* HELIX_FEATURE_NEXTGROUPMGR */
- #endif /* HELIX_FEATURE_BASICGROUPMGR */
- }
- void
- HXPlayer::AdjustPresentationTime(void)
- {
- UINT32 ulSourceDuration = 0;
- // reset presentation duration
- m_ulPresentationDuration = 0;
- CHXMapPtrToPtr::Iterator ndxSource = m_pSourceMap->Begin();
- for (; ndxSource != m_pSourceMap->End(); ++ndxSource)
- {
- SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSource);
- // get duration after the source has been initialized
- // to ensure HXSource::AdjustClipTime() was called
- if (pSourceInfo->m_pSource->IsInitialized())
- {
- ulSourceDuration = pSourceInfo->GetActiveDuration();
- m_ulPresentationDuration = max(m_ulPresentationDuration,
- ulSourceDuration);
- }
- }
- #if defined(HELIX_FEATURE_BASICGROUPMGR)
- // presentation duration is also restrained by its group duration
- // if it exists
- IHXGroup* pGroup = NULL;
- if (HXR_OK == m_pGroupManager->GetGroup((UINT16)m_nCurrentGroup, pGroup))
- {
- /* Get the duration from group properties */
- UINT32 ulGroupDuration = 0;
- IHXValues* pGroupProps = pGroup->GetGroupProperties();
- if (pGroupProps &&
- HXR_OK == pGroupProps->GetPropertyULONG32("Duration", ulGroupDuration))
- {
- m_ulPresentationDuration = ulGroupDuration;
- }
- HX_RELEASE(pGroupProps);
- }
- HX_RELEASE(pGroup);
- #endif /* HELIX_FEATURE_BASICGROUPMGR */
- if (m_pAdviseSink)
- {
- m_pAdviseSink->OnPosLength(m_ulCurrentPlayTime, m_ulPresentationDuration);
- }
- return;
- }
- void
- HXPlayer::SetPresentationTime(UINT32 ulPresentationTime)
- {
- m_ulPresentationDuration = ulPresentationTime;
- if (m_pAdviseSink)
- {
- m_pAdviseSink->OnPosLength(m_ulCurrentPlayTime, m_ulPresentationDuration);
- }
- }
- void
- HXPlayer::UpdateSourceActive(void)
- {
- m_uNumSourcesActive = 0;
- CHXMapPtrToPtr::Iterator ndxSources = m_pSourceMap->Begin();
- for (; ndxSources != m_pSourceMap->End(); ++ndxSources)
- {
- SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSources);
- if (pSourceInfo->m_bActive)
- {
- m_uNumSourcesActive++;
- }
- }
- m_uNumCurrentSourceNotDone = m_uNumSourcesActive;
- }
- HX_RESULT
- HXPlayer::UpdateSourceInfo(SourceInfo* pSourceInfo,
- UINT32 ulParentRegId,
- UINT16 ulTrackIndex)
- {
- HX_RESULT rc = HXR_OK;
- UINT32 ulRegId = 0;
- IHXBuffer* pParentName = NULL;
- #if defined(HELIX_FEATURE_STATS) && defined(HELIX_FEATURE_REGISTRY)
- // update sourc/stream stats' registry
- if (m_pRegistry && m_pStats &&
- HXR_OK == m_pRegistry->GetPropName(ulParentRegId, pParentName))
- {
- char szRegName[MAX_DISPLAY_NAME] = {0}; /* Flawfinder: ignore */
- SafeSprintf(szRegName, MAX_DISPLAY_NAME, "%s.Source%ld", pParentName->GetBuffer(), ulTrackIndex);
- // delete this registry if it exists
- ulRegId = m_pRegistry->GetId(szRegName);
- if (ulRegId)
- {
- m_pRegistry->DeleteById(ulRegId);
- }
- // create/update registry
- ulRegId = m_pRegistry->AddComp(szRegName);
- pSourceInfo->m_pSource->UpdateRegistry(ulRegId);
- #endif /* HELIX_FEATURE_STATS && HELIX_FEATURE_REGISTRY */
- pSourceInfo->m_uTrackID = ulTrackIndex;
- #if defined(HELIX_FEATURE_STATS) && defined(HELIX_FEATURE_REGISTRY)
- }
- HX_RELEASE(pParentName);
- // update renderer stats registry
- pSourceInfo->ReInitializeStats();
- #endif /* HELIX_FEATURE_STATS && HELIX_FEATURE_REGISTRY */
- return rc;
- }
- HX_RESULT
- HXPlayer::UpdatePersistentSrcInfo(SourceInfo* pSourceInfo,
- UINT32 ulParentRegId,
- UINT16 ulTrackIndex)
- {
- HX_RESULT rc = HXR_OK;
- UINT32 ulRegId = 0;
- IHXBuffer* pParentName = NULL;
- #if defined(HELIX_FEATURE_REGISTRY)
- char szRegName[MAX_DISPLAY_NAME] = {0}; /* Flawfinder: ignore */
- // update sourc/stream stats' registry
- if (m_pRegistry && m_pStats &&
- HXR_OK == m_pRegistry->GetPropName(ulParentRegId, pParentName))
- {
- SafeSprintf(szRegName, MAX_DISPLAY_NAME, "%s.Source%u",
- pParentName->GetBuffer(), ulTrackIndex);
- // delete this registry if it exists
- ulRegId = m_pRegistry->GetId(szRegName);
- if (ulRegId)
- {
- m_pRegistry->DeleteById(ulRegId);
- }
- //Create a new one.
- SafeSprintf(szRegName, MAX_DISPLAY_NAME, "%s.Persistent%u", pParentName->GetBuffer(),
- pSourceInfo->m_ulPersistentComponentSelfID);
- // create/update registry
- ulRegId = m_pRegistry->GetId(szRegName);
- if( !ulRegId )
- {
- ulRegId = m_pRegistry->AddComp(szRegName);
- }
- pSourceInfo->m_pSource->UpdateRegistry(ulRegId);
- pSourceInfo->m_uTrackID = ulTrackIndex;
- }
- #endif
- HX_RELEASE(pParentName);
- // update renderer stats registry
- pSourceInfo->ReInitializeStats();
- return rc;
- }
- HX_RESULT
- HXPlayer::SetupAllStreams(void)
- {
- HX_RESULT theErr = HXR_OK;
- CHXMapPtrToPtr::Iterator ndxSources = m_pSourceMap->Begin();
- /* Check if we are done. This may be TRUE for empty files */
- for (; !theErr && ndxSources != m_pSourceMap->End(); ++ndxSources)
- {
- SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSources);
- theErr = pSourceInfo->SetupStreams();
- }
- return theErr;
- }
- void
- HXPlayer::EnterToBeginList(RendererInfo* pRendInfo)
- {
- if (m_ToBeginRendererList.IsEmpty())
- {
- m_ToBeginRendererList.AddHead(pRendInfo);
- return;
- }
- RendererInfo* pTmpRendInfo = NULL;
- BOOL earlierPacketFound = FALSE;
- UINT32 startPos = pRendInfo->m_pStreamInfo->m_ulDelay;
- LISTPOSITION position = m_ToBeginRendererList.GetTailPosition();
- while (position != NULL && !earlierPacketFound)
- {
- pTmpRendInfo =
- (RendererInfo*) m_ToBeginRendererList.GetPrev(position);
- // If this event is less than or equal to the timestamp
- // then this things are looking ok...
- if (pTmpRendInfo->m_pStreamInfo->m_ulDelay <= startPos)
- {
- // Remember that we found an earlier packet...
- earlierPacketFound = TRUE;
- // If the position is null, then event was the first
- // item in the list, and we need to do some fancy footwork...
- if (!position)
- {
- POSITION theHead = m_ToBeginRendererList.GetHeadPosition();
- m_ToBeginRendererList.InsertAfter(theHead,pRendInfo);
- }
- // otherwise, roll ahead one...
- else
- {
- m_ToBeginRendererList.GetNext(position);
- // Now if the position is null, then event was the last
- // item in the list, and we need to do some more fancy footwork...
- if (!position)
- {
- m_ToBeginRendererList.AddTail(pRendInfo);
- }
- else
- // otherwise, we have a normal case and we want to insert
- // right after the position of event
- {
- m_ToBeginRendererList.InsertAfter(position,pRendInfo);
- }
- }
- // We don't need to search any more...
- break; // while
- }
- } // end while...
- // If we didn't find an earlier packet, then we should insert at
- // the head of the event list...
- if (!earlierPacketFound)
- {
- m_ToBeginRendererList.AddHead(pRendInfo);
- }
- }
- HX_RESULT
- HXPlayer::CheckBeginList(void)
- {
- RendererInfo* pRendInfo = (RendererInfo*) m_ToBeginRendererList.GetHead();
- if ((m_ulCurrentPlayTime < pRendInfo->m_pStreamInfo->m_ulDelay &&
- pRendInfo->m_pStreamInfo->m_ulDelay - m_ulCurrentPlayTime <=
- BEGIN_SYNC_FUDGE_FACTOR) ||
- pRendInfo->m_pStreamInfo->m_ulDelay <= m_ulCurrentPlayTime)
- {
- /* Send Begins to all the scheduled renderers */
- LISTPOSITION lPos = m_ToBeginRendererList.GetHeadPosition();
- while (lPos)
- {
- pRendInfo = (RendererInfo*) m_ToBeginRendererList.GetAt(lPos);
- if ((pRendInfo->m_bInterruptSafe || !m_pEngine->AtInterruptTime()) &&
- ((m_ulCurrentPlayTime < pRendInfo->m_pStreamInfo->m_ulDelay &&
- pRendInfo->m_pStreamInfo->m_ulDelay - m_ulCurrentPlayTime <=
- BEGIN_SYNC_FUDGE_FACTOR) ||
- pRendInfo->m_pStreamInfo->m_ulDelay <= m_ulCurrentPlayTime))
- {
- pRendInfo->m_bInitialBeginToBeSent = FALSE;
- pRendInfo->m_pRenderer->OnBegin(m_ulCurrentPlayTime);
- lPos = m_ToBeginRendererList.RemoveAt(lPos);
- }
- else
- {
- break;
- }
- }
- }
- return HXR_OK;
- }
- void
- HXPlayer::RemoveFromPendingList(RendererInfo* pRendInfo)
- {
- LISTPOSITION lPos = NULL;
- lPos = m_ToBeginRendererList.Find((void*) pRendInfo);
- if (lPos)
- {
- m_ToBeginRendererList.RemoveAt(lPos);
- }
- }
- void
- HXPlayer::UnregisterNonActiveSources()
- {
- CHXMapPtrToPtr::Iterator ndxSources = m_pSourceMap->Begin();
- /* Check if we are done. This may be TRUE for empty files */
- for (; !m_bIsDone && ndxSources != m_pSourceMap->End(); ++ndxSources)
- {
- SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSources);
- if (pSourceInfo->m_pSource &&
- (pSourceInfo->m_pSource->IsSourceDone() ||
- pSourceInfo->m_pSource->IsDelayed()))
- {
- pSourceInfo->UnRegister();
- pSourceInfo->m_pSource->AdjustClipBandwidthStats(FALSE);
- }
- }
- }
- /*
- * Purpose: Shutdown all the renderers/fileformats
- */
- void
- HXPlayer::ShutDown(void)
- {
- /* If we are not in a STOP state, do an internal stop */
- if (!m_bIsDone)
- {
- m_bIsPresentationClosedToBeSent = FALSE;
- StopPlayer(END_STOP);
- }
- CloseAllRenderers(m_nCurrentGroup);
- }
- BOOL
- HXPlayer::AreAllSourcesSeekable(void)
- {
- CHXMapPtrToPtr::Iterator ndxSource = m_pSourceMap->Begin();
- for (; ndxSource != m_pSourceMap->End(); ++ndxSource)
- {
- SourceInfo* pSourceInfo = (SourceInfo*)(*ndxSource);
- HXSource * pSource = pSourceInfo->m_pSource;
- if(!pSource)
- {
- continue;
- }
- /* If any one source is non-seekable, entire presentation
- * is non-seekable
- */
- if (!pSource->IsSeekable())
- {
- return FALSE;
- }
- }
- return TRUE;
- }
- void
- HXPlayer::RegisterSourcesDone()
- {
- #if defined(HELIX_FEATURE_ASM)
- /* We are done Registering Sources with ASM Bandwidth Manager */
- HX_ASSERT(m_pBandwidthMgr);
- m_pBandwidthMgr->RegisterSourcesDone();
- if (m_pBandwidthMgr->NotEnoughBandwidth() == TRUE)
- {
- SetLastError(HXR_NOTENOUGH_BANDWIDTH);
- }
- #endif /* HELIX_FEATURE_ASM */
- }
- BOOL
- HXPlayer::CanBeStarted(HXSource* pSource, SourceInfo* pThisSourceInfo, BOOL m_bPartOfNextGroup)
- {
- UINT32 ulDelay = pSource->GetDelay();
- #if defined(HELIX_FEATURE_NEXTGROUPMGR)
- if (m_bPartOfNextGroup && m_pNextGroupManager)
- {
- return m_pNextGroupManager->CanBeStarted(pSource, pThisSourceInfo);
- }
- #endif /* HELIX_FEATURE_NEXTGROUPMGR */
- if ((ulDelay < m_ulCurrentPlayTime) ||
- (ulDelay - m_ulCurrentPlayTime <= MIN_DELAYBEFORE_START) ||
- !pThisSourceInfo)
- {
- return TRUE;
- }
- // XXX HP only start when we are in playing mode
- // this fixed b#55865 - extreme long startup time on sequence of image
- // files
- if (!m_bIsPlaying)
- {
- return FALSE;
- }
- CHXMapPtrToPtr::Iterator ndxSources = m_pSourceMap->Begin();
- /* Check if we are done. This may be TRUE for empty files */
- for (; ndxSources != m_pSourceMap->End(); ++ndxSources)
- {
- SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSources);
- if (!pSourceInfo->m_pSource ||
- pSourceInfo->m_pSource->IsSourceDone() ||
- !pSourceInfo->m_pSource->IsInitialized())
- {
- continue;
- }
- #ifdef SEQ_DEPENDENCY
- int iRetVal = 0;
- if (!pSourceInfo->m_pSource->IsLive() &&
- IsDependent(pThisSourceInfo, pSourceInfo) &&
- !pSourceInfo->m_pSource->IsSourceDone())
- {
- return FALSE;
- }
- #else
- if (!pSourceInfo->m_pSource->IsLive() &&
- pSourceInfo->m_pSource->GetDuration() <= ulDelay &&
- !pSourceInfo->m_pSource->IsSourceDone())
- {
- return FALSE;
- }
- #endif /*SEQ_DEPENDENCY*/
- }
- return TRUE;
- }
- #ifdef SEQ_DEPENDENCY
- BOOL
- HXPlayer::IsDependent(SourceInfo* pThisSourceInfo, SourceInfo* pSourceInfo)
- {
- if (!pThisSourceInfo ||
- !pSourceInfo ||
- pThisSourceInfo->m_uNumDependencies == 0 ||
- pSourceInfo->m_uNumDependencies == 0)
- {
- return FALSE;
- }
- UINT16 uDepdencyNum = 0;
- while (uDepdencyNum < pThisSourceInfo->m_uNumDependencies &&
- uDepdencyNum < pSourceInfo->m_uNumDependencies)
- {
- if (pThisSourceInfo->m_pDependNode[uDepdencyNum] ==
- pSourceInfo->m_pDependNode[uDepdencyNum])
- {
- uDepdencyNum++;
- }
- else
- {
- }
- }
- if (uDepdencyNum < pThisSourceInfo->m_uNumDependencies &&
- uDepdencyNum >= pSourceInfo->m_uNumDependencies
- {
- return FALSE;
- }
- return TRUE;
- }
- #endif /*SEQ_DEPENDENCY*/
- void
- HXPlayer::EndOfSource(HXSource* pSource)
- {
- BOOL bAtLeastOneSourceToBeResumed = FALSE;
- CHXMapPtrToPtr::Iterator ndxSources = m_pSourceMap->Begin();
- /* Check if we are done. This may be TRUE for empty files */
- for (; ndxSources != m_pSourceMap->End(); ++ndxSources)
- {
- SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSources);
- if (!pSourceInfo->m_pSource)
- {
- continue;
- }
- if (pSourceInfo->m_pSource->TryResume())
- {
- bAtLeastOneSourceToBeResumed = TRUE;
- }
- }
- if (bAtLeastOneSourceToBeResumed)
- {
- RegisterSourcesDone();
- ndxSources = m_pSourceMap->Begin();
- /* Check if we are done. This may be TRUE for empty files */
- for (; ndxSources != m_pSourceMap->End(); ++ndxSources)
- {
- SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSources);
- if (!pSourceInfo->m_pSource)
- {
- continue;
- }
- if (pSourceInfo->m_pSource->IsResumePending())
- {
- pSourceInfo->m_pSource->DoResume();
- }
- }
- }
- }
- void
- HXPlayer::SureStreamSourceRegistered(SourceInfo* pSourceInfo)
- {
- if (m_nCurrentGroup == pSourceInfo->m_uGroupID)
- {
- m_ulActiveSureStreamSource++;
- if (m_ulActiveSureStreamSource > 1 && m_bFastStart)
- {
- DEBUG_OUT(this, DOL_TRANSPORT, (s,"SureStreams > 1 - TurboPlay Off"));
- m_bFastStart = FALSE;
- CHXMapPtrToPtr::Iterator ndxSources = m_pSourceMap->Begin();
- for (;ndxSources != m_pSourceMap->End(); ++ndxSources)
- {
- SourceInfo* pSourceInfo = (SourceInfo*) (*ndxSources);
- if (pSourceInfo->m_bIsRegisterSourceDone &&
- pSourceInfo->m_pSource)
- {
- pSourceInfo->m_pSource->LeaveFastStart(TP_OFF_BY_MULTISURESTREAMS);
- }
- }
- }
- }
- return;
- }
- void
- HXPlayer::SureStreamSourceUnRegistered(SourceInfo* pSourceInfo)
- {
- if (m_nCurrentGroup == pSourceInfo->m_uGroupID)
- {
- m_ulActiveSureStreamSource--;
- }
- return;
- }
- BOOL
- HXPlayer::CanBeFastStarted(SourceInfo* pSourceInfo)
- {
- BOOL bFastStart = TRUE;
- BOOL bTurboPlay = FALSE;
- IHXBuffer* pBuffer = NULL;
- IHXUpgradeHandler* pHandler = NULL;
- UINT16 uNextGroup = 0;
- IHXGroup* pNextGroup = NULL;
- #if defined(__TCS__)
- m_turboPlayOffReason = TP_OFF_BY_PREFERENCE;
- m_bFastStart = FALSE;
- goto cleanup;
- #endif /* __TCS__ */
- // check if the source is within the current group
- if (m_nCurrentGroup != pSourceInfo->m_uGroupID)
- {
- bFastStart = FALSE;
- #if defined(HELIX_FEATURE_NEXTGROUPMGR)
- // we want faststart the next group if we are done with the current one
- if (m_bNextGroupStarted &&
- m_pNextGroupManager &&
- HXR_OK == m_pNextGroupManager->GetCurrentGroup(uNextGroup, pNextGroup))
- {
- if (uNextGroup == pSourceInfo->m_uGroupID)
- {
- bFastStart = TRUE;
- }
- }
- HX_RELEASE(pNextGroup);
- #endif /* HELIX_FEATURE_NEXTGROUPMGR */
- goto cleanup;
- }
- else if (!m_bFastStartCheckDone)
- {
- m_bFastStartCheckDone = TRUE;
- m_bFastStart = TRUE;
- // check the preference
- ReadPrefBOOL(m_pPreferences, "TurboPlay", bTurboPlay);
- if (!bTurboPlay)
- {
- DEBUG_OUT(this, DOL_TRANSPORT, (s,"Preference check - TurboPlay Off"));
- m_turboPlayOffReason = TP_OFF_BY_PREFERENCE;
- m_bFastStart = FALSE;
- goto cleanup;
- }
- }
- else if (m_ulActiveSureStreamSource > 1)
- {
- m_turboPlayOffReason = TP_OFF_BY_MULTISURESTREAMS;
- bFastStart = FALSE;
- goto cleanup;
- }
- cleanup:
- HX_RELEASE(pHandler);
- HX_RELEASE(pBuffer);
- return (m_bFastStart & bFastStart);
- }
- void
- HXPlayer::UpdateCurrentPlayTime( ULONG32 ulCurrentPlayTime )
- {
- m_ulCurrentPlayTime = ulCurrentPlayTime;
- #if defined(_MACINTOSH) || defined(_MAC_UNIX)
- if ( IsMacInCooperativeThread() )
- {
- m_ulCurrentSystemPlayTime = ulCurrentPlayTime;
- }
- #endif
- }
- void
- HXPlayer::SendPostSeekIfNecessary(RendererInfo* pRendererInfo)
- {
- if (pRendererInfo->m_BufferingReason == BUFFERING_SEEK ||
- pRendererInfo->m_BufferingReason == BUFFERING_LIVE_PAUSE)
- {
- pRendererInfo->m_BufferingReason = BUFFERING_CONGESTION;
- pRendererInfo->m_pRenderer->OnPostSeek(
- pRendererInfo->m_pStreamInfo->m_ulTimeBeforeSeek,
- pRendererInfo->m_pStreamInfo->m_ulTimeAfterSeek);
- pRendererInfo->m_pStreamInfo->m_pStream->m_bPostSeekToBeSent = FALSE;
- }
- }
- BOOL
- HXPlayer::ScheduleOnTimeSync()
- {
- BOOL bResult = FALSE;
- BOOL bDurationTimeSyncAllSent = FALSE;
- ULONG32 ulAudioTime = 0;
- SourceInfo* pSourceInfo = NULL;
- CHXMapPtrToPtr::Iterator ndxSource;
- if (m_pAudioPlayer)
- {
- ulAudioTime = m_pAudioPlayer->GetCurrentPlayBackTime();
- }
- #if defined(HELIX_FEATURE_NESTEDMETA)
- m_pPersistentComponentManager->OnTimeSync(ulAudioTime);
- #endif /* HELIX_FEATURE_NESTEDMETA */
- ndxSource = m_pSourceMap->Begin();
- for (;ndxSource != m_pSourceMap->End(); ++ndxSource)
- {
- pSourceInfo = (SourceInfo*)(*ndxSource);
- if (!DurationTimeSyncAllSent(pSourceInfo))
- {
- pSourceInfo->OnTimeSync( ulAudioTime );
- bDurationTimeSyncAllSent = DurationTimeSyncAllSent(pSourceInfo);
- if (!pSourceInfo->m_bDurationTimeSyncScheduled &&
- !bDurationTimeSyncAllSent)
- {
- pSourceInfo->m_bDurationTimeSyncScheduled = TRUE;
- bResult = TRUE;
- goto cleanup;
- }
- }
- }
- cleanup:
- return bResult;
- }
- BOOL
- HXPlayer::DurationTimeSyncAllSent(SourceInfo* pSourceInfo)
- {
- BOOL bResult = TRUE;
- RendererInfo* pRendInfo = NULL;
- CHXMapLongToObj::Iterator ndxRend;
- ndxRend = pSourceInfo->m_pRendererMap->Begin();
- for (;ndxRend != pSourceInfo->m_pRendererMap->End();++ndxRend)
- {
- pRendInfo = (RendererInfo*)(*ndxRend);
- if (!pRendInfo->m_bDurationTimeSyncSent)
- {
- bResult = FALSE;
- break;
- }
- }
- return bResult;
- }
- void
- HXPlayer::DisableScreenSaver()
- {
- return;
- }
- void HXPlayer::RemovePendingCallback(CHXGenericCallback* pCB)
- {
- if (pCB &&
- pCB->GetPendingCallback() &&
- m_pScheduler)
- {
- m_pScheduler->Remove(pCB->GetPendingCallback());
- pCB->CallbackCanceled();
- }
- }
- #ifndef _WIN16
- #if defined(HELIX_FEATURE_AUTHENTICATION)
- _CListOfWrapped_IUnknown_Node::_CListOfWrapped_IUnknown_Node()
- : m_plocPrev(NULL)
- , m_plocNext(NULL)
- {
- }
- _CListOfWrapped_IUnknown_Node::~_CListOfWrapped_IUnknown_Node()
- {
- Remove();
- }
- void
- _CListOfWrapped_IUnknown_Node::Remove()
- {
- if(m_plocPrev)
- {
- m_plocPrev->next(m_plocNext);
- }
- if(m_plocNext)
- {
- m_plocNext->prev(m_plocPrev);
- }
- }
- void
- _CListOfWrapped_IUnknown_Node::Insert(_CListOfWrapped_IUnknown_Node& rlocnNew)
- {
- rlocnNew.next(this);
- rlocnNew.prev(m_plocPrev);
- if(m_plocPrev)
- {
- m_plocPrev->next(&rlocnNew);
- }
- m_plocPrev = &rlocnNew;
- }
- Wrapped_IUnknown&
- _CListOfWrapped_IUnknown_Node::value()
- {
- return m_clsValue;
- }
- const Wrapped_IUnknown&
- _CListOfWrapped_IUnknown_Node::value() const
- {
- return m_clsValue;
- }
- void
- _CListOfWrapped_IUnknown_Node::value(const Wrapped_IUnknown& rclsNewValue)
- {
- m_clsValue = rclsNewValue;
- }
- _CListOfWrapped_IUnknown_Node&
- _CListOfWrapped_IUnknown_Node::operator=(const Wrapped_IUnknown& rclsNewValue)
- {
- m_clsValue = rclsNewValue;
- return *this;
- }
- _CListOfWrapped_IUnknown_Node*
- _CListOfWrapped_IUnknown_Node::next() const
- {
- return m_plocNext;
- }
- void
- _CListOfWrapped_IUnknown_Node::next(_CListOfWrapped_IUnknown_Node* plocnNew)
- {
- m_plocNext = plocnNew;
- }
- _CListOfWrapped_IUnknown_Node*
- _CListOfWrapped_IUnknown_Node::prev() const
- {
- return m_plocPrev;
- }
- void
- _CListOfWrapped_IUnknown_Node::prev(_CListOfWrapped_IUnknown_Node* plocnNew)
- {
- m_plocPrev = plocnNew;
- }
- _CListOfWrapped_IUnknown_::_CListOfWrapped_IUnknown_()
- {
- m_locnREnd.next(&m_locnEnd);
- m_locnEnd.prev(&m_locnREnd);
- }
- _CListOfWrapped_IUnknown_::_CListOfWrapped_IUnknown_(const _CListOfWrapped_IUnknown_& rlocOther)
- {
- m_locnREnd.next(&m_locnEnd);
- m_locnEnd.prev(&m_locnREnd);
- _copy(rlocOther);
- }
- _CListOfWrapped_IUnknown_::~_CListOfWrapped_IUnknown_()
- {
- empty();
- }
- _CListOfWrapped_IUnknown_&
- _CListOfWrapped_IUnknown_::operator=(const _CListOfWrapped_IUnknown_& rlocOther)
- {
- empty();
- _copy(rlocOther);
- return *this;
- }
- void
- _CListOfWrapped_IUnknown_::_copy(const _CListOfWrapped_IUnknown_& rlocOther)
- {
- iterator itOther;
- for
- (
- itOther = rlocOther.begin();
- itOther != rlocOther.end();
- ++itOther
- )
- {
- insert(end(), *itOther);
- }
- }
- _CListOfWrapped_IUnknown_::iterator
- _CListOfWrapped_IUnknown_::begin()
- {
- return iterator(*(m_locnREnd.next()));
- }
- const _CListOfWrapped_IUnknown_::iterator
- _CListOfWrapped_IUnknown_::begin() const
- {
- return iterator(*(m_locnREnd.next()));
- }
- _CListOfWrapped_IUnknown_::iterator
- _CListOfWrapped_IUnknown_::end()
- {
- return iterator(m_locnEnd);
- }
- const _CListOfWrapped_IUnknown_::iterator
- _CListOfWrapped_IUnknown_::end() const
- {
- return iterator(m_locnEnd);
- }
- _CListOfWrapped_IUnknown_::reverse_iterator
- _CListOfWrapped_IUnknown_::rbegin()
- {
- return reverse_iterator(*(m_locnEnd.prev()));
- }
- const _CListOfWrapped_IUnknown_::reverse_iterator
- _CListOfWrapped_IUnknown_::rbegin() const
- {
- return const_reverse_iterator(*(m_locnEnd.prev()));
- }
- _CListOfWrapped_IUnknown_::reverse_iterator
- _CListOfWrapped_IUnknown_::rend()
- {
- return reverse_iterator(m_locnREnd);
- }
- const _CListOfWrapped_IUnknown_::reverse_iterator
- _CListOfWrapped_IUnknown_::rend() const
- {
- return const_reverse_iterator(*((const _CListOfWrapped_IUnknown_Node *)&m_locnREnd));
- }
- _CListOfWrapped_IUnknown_::iterator
- _CListOfWrapped_IUnknown_::insert(iterator itBefore, const Wrapped_IUnknown& rclsNew)
- {
- _CListOfWrapped_IUnknown_Node* plocnNew = new _CListOfWrapped_IUnknown_Node;
- HX_ASSERT(plocnNew);
- *plocnNew = rclsNew;
- itBefore.m_plocCurrent->Insert(*plocnNew);
- return iterator(*plocnNew);
- }
- void
- _CListOfWrapped_IUnknown_::insert
- (
- iterator itBefore,
- const iterator itFirst,
- const iterator itLast
- )
- {
- iterator itOther;
- _CListOfWrapped_IUnknown_Node* plocnNew;
- for (itOther = itFirst; itOther != itLast; ++itOther)
- {
- plocnNew = new _CListOfWrapped_IUnknown_Node;
- HX_ASSERT(plocnNew);
- *plocnNew = *itOther;
- itBefore.m_plocCurrent->Insert(*plocnNew);
- }
- }
- void
- _CListOfWrapped_IUnknown_::remove(iterator itThis)
- {
- if
- (
- itThis.m_plocCurrent == &m_locnEnd ||
- itThis.m_plocCurrent == &m_locnREnd
- )
- {
- return;
- }
- _CListOfWrapped_IUnknown_Node* plocnOld;
- plocnOld = itThis.m_plocCurrent;
- ++itThis;
- plocnOld->Remove();
- delete plocnOld;
- }
- void
- _CListOfWrapped_IUnknown_::remove(iterator itFirst, iterator itLast)
- {
- if
- (
- itFirst.m_plocCurrent == &m_locnEnd ||
- itFirst.m_plocCurrent == &m_locnREnd
- )
- {
- return;
- }
- iterator itOther;
- _CListOfWrapped_IUnknown_Node* plocnOld;
- for (itOther = itFirst; itOther != itLast;)
- {
- plocnOld = itOther.m_plocCurrent;
- ++itOther;
- plocnOld->Remove();
- delete plocnOld;
- }
- }
- void
- _CListOfWrapped_IUnknown_::empty()
- {
- remove(begin(), end());
- }
- _CListIteratorWrapped_IUnknown_::_CListIteratorWrapped_IUnknown_()
- : m_plocCurrent(NULL)
- {
- }
- _CListIteratorWrapped_IUnknown_::_CListIteratorWrapped_IUnknown_
- (
- const _CListOfWrapped_IUnknown_Node& rlocnNewLocation
- )
- : m_plocCurrent((_CListOfWrapped_IUnknown_Node*)&rlocnNewLocation)
- {
- }
- _CListIteratorWrapped_IUnknown_::_CListIteratorWrapped_IUnknown_
- (
- const _CListIteratorWrapped_IUnknown_& rliocOther
- )
- : m_plocCurrent(rliocOther.m_plocCurrent)
- {
- }
- _CListIteratorWrapped_IUnknown_::~_CListIteratorWrapped_IUnknown_()
- {
- }
- _CListIteratorWrapped_IUnknown_&
- _CListIteratorWrapped_IUnknown_::operator=
- (
- const _CListIteratorWrapped_IUnknown_& rliocOther
- )
- {
- m_plocCurrent = rliocOther.m_plocCurrent;
- return *this;
- }
- Wrapped_IUnknown&
- _CListIteratorWrapped_IUnknown_::operator*()
- {
- HX_ASSERT(m_plocCurrent);
- return m_plocCurrent->value();
- }
- _CListIteratorWrapped_IUnknown_&
- _CListIteratorWrapped_IUnknown_::operator=(const Wrapped_IUnknown& rclsNewValue)
- {
- if(!m_plocCurrent)
- return *this;
- m_plocCurrent->value(rclsNewValue);
- return *this;
- }
- _CListIteratorWrapped_IUnknown_&
- _CListIteratorWrapped_IUnknown_::operator++()
- {
- if(!m_plocCurrent)
- return *this;
- m_plocCurrent = m_plocCurrent->next();
- return *this;
- }
- const _CListIteratorWrapped_IUnknown_
- _CListIteratorWrapped_IUnknown_::operator++(int)
- {
- _CListIteratorWrapped_IUnknown_ liocRet(*this);
- ++(*this);
- return liocRet;
- }
- _CListIteratorWrapped_IUnknown_&
- _CListIteratorWrapped_IUnknown_::operator--()
- {
- if(!m_plocCurrent)
- return *this;
- m_plocCurrent = m_plocCurrent->prev();
- return *this;
- }
- const _CListIteratorWrapped_IUnknown_
- _CListIteratorWrapped_IUnknown_::operator--(int)
- {
- _CListIteratorWrapped_IUnknown_ liocRet(*this);
- --(*this);
- return liocRet;
- }
- BOOL operator==
- (
- const _CListIteratorWrapped_IUnknown_& rliocLeft,
- const _CListIteratorWrapped_IUnknown_& rliocRight
- )
- {
- return (rliocLeft.m_plocCurrent == rliocRight.m_plocCurrent);
- }
- BOOL operator!=
- (
- const _CListIteratorWrapped_IUnknown_& rliocLeft,
- const _CListIteratorWrapped_IUnknown_& rliocRight
- )
- {
- return (rliocLeft.m_plocCurrent != rliocRight.m_plocCurrent);
- }
- _CListReverseIteratorWrapped_IUnknown_::_CListReverseIteratorWrapped_IUnknown_()
- : m_plocCurrent(NULL)
- {
- }
- _CListReverseIteratorWrapped_IUnknown_::_CListReverseIteratorWrapped_IUnknown_
- (
- const _CListOfWrapped_IUnknown_Node& rlocnNewLocation
- )
- : m_plocCurrent((_CListOfWrapped_IUnknown_Node*)&rlocnNewLocation)
- {
- }
- _CListReverseIteratorWrapped_IUnknown_::_CListReverseIteratorWrapped_IUnknown_
- (
- const _CListReverseIteratorWrapped_IUnknown_& rlriocOther
- )
- : m_plocCurrent(rlriocOther.m_plocCurrent)
- {
- }
- _CListReverseIteratorWrapped_IUnknown_::~_CListReverseIteratorWrapped_IUnknown_()
- {
- }
- _CListReverseIteratorWrapped_IUnknown_&
- _CListReverseIteratorWrapped_IUnknown_::operator=
- (
- const _CListReverseIteratorWrapped_IUnknown_& rlriocOther
- )
- {
- m_plocCurrent = rlriocOther.m_plocCurrent;
- return *this;
- }
- Wrapped_IUnknown&
- _CListReverseIteratorWrapped_IUnknown_::operator*()
- {
- HX_ASSERT(m_plocCurrent);
- return m_plocCurrent->value();
- }
- _CListReverseIteratorWrapped_IUnknown_&
- _CListReverseIteratorWrapped_IUnknown_::operator=(const Wrapped_IUnknown& rclsNewValue)
- {
- if(!m_plocCurrent)
- return *this;
- m_plocCurrent->value(rclsNewValue);
- return *this;
- }
- _CListReverseIteratorWrapped_IUnknown_&
- _CListReverseIteratorWrapped_IUnknown_::operator++()
- {
- if(!m_plocCurrent)
- return *this;
- m_plocCurrent = m_plocCurrent->prev();
- return *this;
- }
- const _CListReverseIteratorWrapped_IUnknown_
- _CListReverseIteratorWrapped_IUnknown_::operator++(int)
- {
- _CListReverseIteratorWrapped_IUnknown_ lriocRet(*this);
- ++(*this);
- return lriocRet;
- }
- _CListReverseIteratorWrapped_IUnknown_&
- _CListReverseIteratorWrapped_IUnknown_::operator--()
- {
- if(!m_plocCurrent)
- return *this;
- m_plocCurrent = m_plocCurrent->next();
- return *this;
- }
- const _CListReverseIteratorWrapped_IUnknown_
- _CListReverseIteratorWrapped_IUnknown_::operator--(int)
- {
- _CListReverseIteratorWrapped_IUnknown_ lriocRet(*this);
- --(*this);
- return lriocRet;
- }
- BOOL operator==
- (
- const _CListReverseIteratorWrapped_IUnknown_& rlriocLeft,
- const _CListReverseIteratorWrapped_IUnknown_& rlriocRight
- )
- {
- return (rlriocLeft.m_plocCurrent == rlriocRight.m_plocCurrent);
- }
- BOOL operator!=
- (
- const _CListReverseIteratorWrapped_IUnknown_& rlriocLeft,
- const _CListReverseIteratorWrapped_IUnknown_& rlriocRight
- )
- {
- return (rlriocLeft.m_plocCurrent != rlriocRight.m_plocCurrent);
- }
- #endif /* HELIX_FEATURE_AUTHENTICATION */
- _CHXAuthenticationRequests::_CHXAuthenticationRequests()
- : m_pMutexProtectList(NULL)
- , m_bUIShowing(FALSE)
- {
- #ifdef HELIX_FEATURE_AUTHENTICATION
- #ifdef THREADS_SUPPORTED
- HXMutex::MakeMutex(m_pMutexProtectList);
- #else
- HXMutex::MakeStubMutex(m_pMutexProtectList);
- #endif
- #endif /* HELIX_FEATURE_AUTHENTICATION */
- }
- _CHXAuthenticationRequests::~_CHXAuthenticationRequests()
- {
- #ifdef HELIX_FEATURE_AUTHENTICATION
- HX_DELETE(m_pMutexProtectList);
- #endif /* HELIX_FEATURE_AUTHENTICATION */
- }
- HX_RESULT
- _CHXAuthenticationRequests::Add(HXPlayer* pPlayerRequester,
- IHXAuthenticationManagerResponse* pAuthenticationManagerResponseRequester,
- IHXValues* pAuthenticationHeaderValues)
- {
- #ifdef HELIX_FEATURE_AUTHENTICATION
- BOOL bShowUI = FALSE;
- IHXAuthenticationManager* pAuthenticationManagerClient = NULL;
- IHXAuthenticationManager2* pAuthenticationManagerClient2 = NULL;
- pPlayerRequester->m_pClient->QueryInterface(IID_IHXAuthenticationManager2, (void**)&pAuthenticationManagerClient2);
- if (pAuthenticationManagerClient2)
- {
- HX_ASSERT(pPlayerRequester);
- if (pAuthenticationManagerClient2 == (IHXAuthenticationManager2*)pPlayerRequester)
- {
- HX_RELEASE(pAuthenticationManagerClient2);
- pAuthenticationManagerClient2 = NULL;
- }
- }
- if (!pAuthenticationManagerClient2)
- {
- pPlayerRequester->m_pClient->QueryInterface
- (
- IID_IHXAuthenticationManager,
- (void**)&pAuthenticationManagerClient
- );
- }
- if (!pAuthenticationManagerClient && !pAuthenticationManagerClient2)
- {
- return pAuthenticationManagerResponseRequester->AuthenticationRequestDone
- (
- HXR_UNEXPECTED,
- NULL,
- NULL
- );
- }
- HX_ASSERT(pAuthenticationManagerClient || pAuthenticationManagerClient2); // we want one...
- HX_ASSERT(!(pAuthenticationManagerClient && pAuthenticationManagerClient2)); // .. but not both
- // Don't allow iterating while we are adding.
- m_pMutexProtectList->Lock();
- m_ListOfIUnknownRequesters.insert(m_ListOfIUnknownRequesters.end(), (IUnknown*)pAuthenticationManagerResponseRequester);
- if (!m_bUIShowing)
- {
- bShowUI = m_bUIShowing = TRUE;
- }
- m_pMutexProtectList->Unlock();
- if (bShowUI)
- {
- IHXInterruptSafe* pInterruptSafe = NULL;
- if (pAuthenticationManagerClient) pAuthenticationManagerClient->QueryInterface(IID_IHXInterruptSafe,
- (void**) &pInterruptSafe);
- if (pAuthenticationManagerClient2) pAuthenticationManagerClient2->QueryInterface(IID_IHXInterruptSafe,
- (void**) &pInterruptSafe);
- if (!pPlayerRequester->m_pEngine->AtInterruptTime() ||
- (pInterruptSafe && pInterruptSafe->IsInterruptSafe()))
- {
- /* Remove any pending callback */
- pPlayerRequester->RemovePendingCallback(pPlayerRequester->m_pAuthenticationCallback);
- if (pAuthenticationManagerClient)
- {
- pAuthenticationManagerClient->HandleAuthenticationRequest
- (
- pPlayerRequester
- );
- }
- if (pAuthenticationManagerClient2)
- {
- pAuthenticationManagerClient2->HandleAuthenticationRequest2
- (
- pPlayerRequester,
- pAuthenticationHeaderValues
- );
- }
- }
- else
- {
- m_bUIShowing = FALSE;
- /*
- * Schedule a callback to request authentication at
- * non-interrupt time
- */
- if (pPlayerRequester->m_pAuthenticationCallback &&
- !pPlayerRequester->m_pAuthenticationCallback->GetPendingCallback())
- {
- pPlayerRequester->m_pAuthenticationCallback->CallbackScheduled(
- pPlayerRequester->m_pScheduler->RelativeEnter(pPlayerRequester->m_pAuthenticationCallback, 0));
- }
- }
- HX_RELEASE(pInterruptSafe);
- }
- HX_RELEASE(pAuthenticationManagerClient);
- HX_RELEASE(pAuthenticationManagerClient2);
- return HXR_OK;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_AUTHENTICATION */
- }
- HX_RESULT
- _CHXAuthenticationRequests::SatisfyPending
- (
- HX_RESULT ResultStatus,
- const char* pCharUser,
- const char* pCharPassword
- )
- {
- #ifdef HELIX_FEATURE_AUTHENTICATION
- _CListOfWrapped_IUnknown_::iterator ListOfIUnknownIteratorCurrentRequester;
- IUnknown* pUnknownRequester = NULL;
- IHXAuthenticationManagerResponse* pAuthenticationManagerResponseRequester = NULL;
- // Don't allow add's while we are iterating.
- m_pMutexProtectList->Lock();
- m_bUIShowing = FALSE;
- for
- (
- ListOfIUnknownIteratorCurrentRequester = m_ListOfIUnknownRequesters.begin();
- ListOfIUnknownIteratorCurrentRequester != m_ListOfIUnknownRequesters.end();
- ++ListOfIUnknownIteratorCurrentRequester
- )
- {
- pUnknownRequester = (*ListOfIUnknownIteratorCurrentRequester).wrapped_ptr();
- if (pUnknownRequester)
- {
- pUnknownRequester->QueryInterface
- (
- IID_IHXAuthenticationManagerResponse,
- (void**)&pAuthenticationManagerResponseRequester
- );
- if (pAuthenticationManagerResponseRequester)
- {
- pAuthenticationManagerResponseRequester->AuthenticationRequestDone
- (
- ResultStatus,
- pCharUser,
- pCharPassword
- );
- }
- }
- HX_RELEASE(pAuthenticationManagerResponseRequester);
- pUnknownRequester = NULL;
- }
- m_ListOfIUnknownRequesters.empty();
- m_pMutexProtectList->Unlock();
- return HXR_OK;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_AUTHENTICATION */
- }
- void
- _CHXAuthenticationRequests::ClearPendingList()
- {
- #ifdef HELIX_FEATURE_AUTHENTICATION
- m_ListOfIUnknownRequesters.empty();
- #endif /* HELIX_FEATURE_AUTHENTICATION */
- }
- #endif /* _WIN16 */
- HX_RESULT
- HXPlayer::AdjustSeekOnRepeatedSource(SourceInfo* pSourceInfo,
- UINT32 ulSeekTime)
- {
- #if defined(HELIX_FEATURE_SMIL_REPEAT)
- HX_RESULT theErr = HXR_OK;
- SourceInfo* pAdjustedSourceInfo = NULL;
- pAdjustedSourceInfo = pSourceInfo->DoAdjustSeek(ulSeekTime);
- if (pAdjustedSourceInfo == pSourceInfo)
- {
- theErr = pSourceInfo->m_pSource->DoSeek(ulSeekTime);
- }
- else
- {
- m_pSourceMap->RemoveKey(pSourceInfo->m_pSource);
- m_pSourceMap->SetAt((void*)pAdjustedSourceInfo->m_pSource,
- (void*)pAdjustedSourceInfo);
- m_bSourceMapUpdated = TRUE;
- m_bForceStatsUpdate = TRUE;
- if (pAdjustedSourceInfo->m_bTobeInitializedBeforeBegin)
- {
- m_uNumSourceToBeInitializedBeforeBegin++;
- }
- }
- return theErr;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_SMIL_REPEAT */
- }
- BOOL
- HXPlayer::IsSitePresent
- (
- IHXSite* pSite
- )
- {
- #if defined(HELIX_FEATURE_VIDEO)
- return m_pSiteManager->IsSitePresent(pSite);
- #else
- return FALSE;
- #endif /* HELIX_FEATURE_VIDEO */
- }
- void
- HXPlayer::CheckIfRendererNeedFocus(IUnknown* pRenderer)
- {
- #if defined(HELIX_FEATURE_VIDEO)
- BOOL bNeedFocus = FALSE;
- ReadPrefBOOL(m_pPreferences, "GrabFocus", bNeedFocus);
- IHXRenderer* pRend = NULL;
- pRenderer->QueryInterface(IID_IHXRenderer, (void**) &pRend);
- if (pRend)
- {
- UINT32 ulGran = 0;
- const char** ppszMimeTypes = NULL;
- pRend->GetRendererInfo(ppszMimeTypes, ulGran);
- while (ppszMimeTypes && *ppszMimeTypes)
- {
- // XXRA Hernry, please remove the GrabFocus preference code from above
- // when you add the right mimetypes
- if ((::strcasecmp(*ppszMimeTypes, "MIMETYPE1") == 0) ||
- (::strcasecmp(*ppszMimeTypes, "MIMETYPE2") == 0))
- {
- bNeedFocus = TRUE;
- goto rendexit;
- }
- ppszMimeTypes++;
- }
- }
- rendexit:
- HX_RELEASE(pRend);
- if (m_pSiteManager && bNeedFocus)
- {
- m_pSiteManager->NeedFocus(TRUE);
- }
- #endif /* HELIX_FEATURE_VIDEO */
- }
- #if defined(HELIX_FEATURE_RECORDCONTROL)
- BOOL HXPlayer::IsRecordServiceEnabled()
- {
- BOOL bRes = FALSE;
- ReadPrefBOOL(m_pPreferences, "LiveSuperBuffer", bRes);
- return bRes;
- }
- #endif
- STDMETHODIMP
- HXPlayer::LoadRecordService(IHXRecordService* pRecordService)
- {
- #if defined(HELIX_FEATURE_RECORDCONTROL)
- HX_RELEASE(m_pRecordService);
- m_pRecordService = pRecordService;
- if(m_pRecordService)
- m_pRecordService->AddRef();
- return HXR_OK;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_RECORDCONTROL */
- }
- STDMETHODIMP
- HXPlayer::GetRecordService(REF(IHXRecordService*) pRecordService)
- {
- #if defined(HELIX_FEATURE_RECORDCONTROL)
- pRecordService = m_pRecordService;
- if(pRecordService)
- {
- pRecordService->AddRef();
- return HXR_OK;
- }
- return HXR_FAILED;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_RECORDCONTROL */
- }
- STDMETHODIMP
- HXPlayer::UnloadRecordService()
- {
- #if defined(HELIX_FEATURE_RECORDCONTROL)
- HX_RELEASE(m_pRecordService);
- return HXR_OK;
- #else
- return HXR_NOTIMPL;
- #endif /* HELIX_FEATURE_RECORDCONTROL */
- }
- // working set monitoring tools on Windows
- #if 0
- #ifdef WIN32
- typedef struct _PSAPI_WS_WATCH_INFORMATION
- {
- LPVOID FaultingPc;
- LPVOID FaultingVa;
- } PSAPI_WS_WATCH_INFORMATION;
- #define WORKING_SET_BUFFER_ENTRYS 4096
- PSAPI_WS_WATCH_INFORMATION WorkingSetBuffer[WORKING_SET_BUFFER_ENTRYS];
- typedef BOOL (WINAPI * InitializeProcessForWsWatchType) (
- HANDLE hProcess
- );
- typedef BOOL (WINAPI * GetWsChangesType) (
- HANDLE hProcess,
- PSAPI_WS_WATCH_INFORMATION* lpWatchInfo,
- DWORD cb
- );
- InitializeProcessForWsWatchType g_fpInitializeProcessForWsWatch = NULL;
- GetWsChangesType g_fpGetWsChanges = NULL;
- HINSTANCE g_PSAPIHandle = NULL;
- HANDLE g_hCurrentProcess = NULL;
- BOOL g_bPrintChanges = FALSE;
- BOOL g_bSetWsChangeHook = FALSE;
- BOOL g_bLockLikeACrazyMan = TRUE;
- CHXMapPtrToPtr g_mWorkingSetMap;
- int g_LockedPages = 0;
- int g_totalFaults = 0;
- int g_AttemptedLockedPages = 0;
- int g_FailedLockedPages = 0;
- void GetChangesToWorkingSet()
- {
- int count = 0;
- if (!g_hCurrentProcess)
- {
- g_hCurrentProcess = GetCurrentProcess();
- // check to see if we want to print data
- HKEY hKey;
- char szKeyName[256]; /* Flawfinder: ignore */
- long szValueSize = 1024;
- char szValue[1024]; /* Flawfinder: ignore */
- g_bLockLikeACrazyMan = FALSE;
- SafeSprintf(szKeyName, 256, "Software\%s\Debug\LockLikeCrazy", HXVER_COMMUNITY);
- if( RegOpenKey(HKEY_CLASSES_ROOT, szKeyName, &hKey) == ERROR_SUCCESS )
- {
- RegQueryValue(hKey, "", szValue, (long *)&szValueSize);
- g_bLockLikeACrazyMan = !strcmp(szValue,"1");
- RegCloseKey(hKey);
- }
- else
- {
- RegCreateKey(HKEY_CLASSES_ROOT, szKeyName, &hKey);
- RegCloseKey(hKey);
- }
- g_bSetWsChangeHook = FALSE;
- SafeSprintf(szKeyName, 256, "Software\%s\Debug\SetWsHook", HXVER_COMMUNITY);
- if( RegOpenKey(HKEY_CLASSES_ROOT, szKeyName, &hKey) == ERROR_SUCCESS )
- {
- RegQueryValue(hKey, "", szValue, (long *)&szValueSize);
- g_bSetWsChangeHook = !strcmp(szValue,"1");
- RegCloseKey(hKey);
- }
- else
- {
- RegCreateKey(HKEY_CLASSES_ROOT, szKeyName, &hKey);
- RegCloseKey(hKey);
- }
- if (g_bSetWsChangeHook)
- {
- if (g_bLockLikeACrazyMan)
- {
- BOOL setProcessWorkingSize = SetProcessWorkingSetSize(g_hCurrentProcess, (1<<23), (1<<24) );
- }
- g_PSAPIHandle = LoadLibrary("psapi.dll");
- if (g_PSAPIHandle)
- {
- g_fpInitializeProcessForWsWatch = (InitializeProcessForWsWatchType) GetProcAddress(g_PSAPIHandle, "InitializeProcessForWsWatch");
- g_fpGetWsChanges = (GetWsChangesType) GetProcAddress(g_PSAPIHandle, "GetWsChanges");
- }
- BOOL initRetVal = g_fpInitializeProcessForWsWatch(g_hCurrentProcess);
- }
- // check to see if we want to print data
- SafeSprintf(szKeyName, 256, "Software\%s\Debug\PrintFaults", HXVER_COMMUNITY);
- if( RegOpenKey(HKEY_CLASSES_ROOT, szKeyName, &hKey) == ERROR_SUCCESS )
- {
- RegQueryValue(hKey, "", szValue, (long *)&szValueSize);
- g_bPrintChanges = !strcmp(szValue,"1");
- RegCloseKey(hKey);
- }
- else
- {
- RegCreateKey(HKEY_CLASSES_ROOT, szKeyName, &hKey);
- RegCloseKey(hKey);
- }
- }
- BOOL b = FALSE;
- if (g_fpGetWsChanges)
- {
- b = g_fpGetWsChanges(g_hCurrentProcess,&WorkingSetBuffer[0],sizeof(WorkingSetBuffer));
- }
- if ( b )
- {
- int i = 0;
- while (WorkingSetBuffer[i].FaultingPc)
- {
- void* Pc = WorkingSetBuffer[i].FaultingPc;
- void* Va = WorkingSetBuffer[i].FaultingVa;
- void* VaPage = (void*) ((ULONG)Va & 0xfffff000);
- g_totalFaults++;
- Va = (LPVOID)( (ULONG)Va & 0xfffffffe);
- count = 0;
- g_mWorkingSetMap.Lookup(VaPage, (void*&)count);
- count++;
- g_mWorkingSetMap.SetAt(VaPage, (void*)count);
- if (count==50 && g_bLockLikeACrazyMan)
- {
- g_AttemptedLockedPages++;
- #if 0 /* do not attempt to lock - RA */
- BOOL bRetVal = VirtualLock(VaPage, 4096);
- if (!bRetVal)
- {
- DWORD lastError = GetLastError();
- void* lpMsgBuf;
- FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL );
- LocalFree( lpMsgBuf );
- g_FailedLockedPages++;
- }
- else
- {
- g_LockedPages++;
- }
- #endif
- }
- i++;
- }
- }
- }
- #endif
- #endif