⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 advgroup.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** 
 * Version: RCSL 1.0/RPSL 1.0 
 *  
 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
 *      
 * The contents of this file, and the files included with this file, are 
 * subject to the current version of the RealNetworks Public Source License 
 * Version 1.0 (the "RPSL") available at 
 * http://www.helixcommunity.org/content/rpsl unless you have licensed 
 * the file under the RealNetworks Community Source License Version 1.0 
 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
 * in which case the RCSL will apply. You may also obtain the license terms 
 * directly from RealNetworks.  You may not use this file except in 
 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
 * applicable to this file, the RCSL.  Please see the applicable RPSL or 
 * RCSL for the rights, obligations and limitations governing use of the 
 * contents of the file.  
 *  
 * This file is part of the Helix DNA Technology. RealNetworks is the 
 * developer of the Original Code and owns the copyrights in the portions 
 * it created. 
 *  
 * This file, and the files included with this file, is distributed and made 
 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
 * 
 * Technology Compatibility Kit Test Suite(s) Location: 
 *    http://www.helixcommunity.org/content/tck 
 * 
 * Contributor(s): 
 *  
 * ***** END LICENSE BLOCK ***** */ 

#include "hxcom.h"

#include "hxresult.h"
#include "hxausvc.h"
#include "ihxpckts.h"
#include "hxmap.h"
#include "smiltype.h"
#include "hxgroup.h"
#include "advgroup.h"
#include "hxwintyp.h"
#include "hxengin.h"
#include "hxcore.h"
#include "hxplay.h"
#include "hxbsrc.h"
#include "hxsrc.h"
#include "srcinfo.h"
#include "hxslist.h"
#include "hxtac.h"
#include "hxstrutl.h"

#include "hxheap.h"
#ifdef _DEBUG
#undef HX_THIS_FILE
static const char HX_THIS_FILE[] = __FILE__;
#endif

HXAdvancedTrack::HXAdvancedTrack(HXAdvancedGroup* pHXGroup)
                :HXBasicTrack(pHXGroup)
                ,m_pRepeatList(NULL)
                ,m_uSoundLevel(100)
                ,m_bInSoundLevelAnimation(FALSE)
                ,m_ulSoundLevelAnimationTime(0)
                ,m_ulGranularity(0)
{
}

HXAdvancedTrack::~HXAdvancedTrack(void)
{
    Close();
}

#if defined(HELIX_FEATURE_AUDIOHOOK)
/*
 *  IUnknown methods
 */
STDMETHODIMP HXAdvancedTrack::QueryInterface(REFIID riid, void** ppvObj)
{
    if (HXR_OK == HXBasicTrack::QueryInterface(riid, ppvObj))
    {
	return HXR_OK;
    }
    else if (IsEqualIID(riid, IID_IHXAudioHook))
    {
        AddRef();
        *ppvObj = (IHXAudioHook*)this;
        return HXR_OK;
    }

    *ppvObj = NULL;
    return HXR_NOINTERFACE;
}

STDMETHODIMP_(ULONG32) HXAdvancedTrack::AddRef()
{
    return InterlockedIncrement(&m_lRefCount);
}

STDMETHODIMP_(ULONG32) HXAdvancedTrack::Release()
{
    if (InterlockedDecrement(&m_lRefCount) > 0)
    {
        return m_lRefCount;
    }

    delete this;
    return 0;
}

/*
 *  IHXAudioHook methods
 */
/************************************************************************
 *  Method:
 *      IHXAudioHook::OnInit
 *  Purpose:
 *      Audio Services calls OnInit() with the audio data format of the
 *	    audio data that will be provided in the OnBuffer() method.
 */
STDMETHODIMP
HXAdvancedTrack::OnInit(HXAudioFormat* /*IN*/ pFormat)
{
    CHXAudioPlayer* pAudioPlayer = NULL;
    
    pAudioPlayer = m_pHXGroup->m_pPlayer->GetAudioPlayer();
    if (pAudioPlayer)
    {
	m_ulSoundLevelAnimationTime = pAudioPlayer->GetCurrentPlayBackTime();
	m_ulGranularity = pAudioPlayer->GetGranularity();
    }

    return HXR_OK;
}

/************************************************************************
 *  Method:
 *      IHXAudioHook::OnBuffer
 *  Purpose:
 *      Audio Services calls OnBuffer() with audio data packets. The
 *	    renderer should not modify the data in the IHXBuffer part of
 *	    pAudioInData.  If the renderer wants to write a modified
 *	    version of the data back to Audio Services, then it should 
 *	    create its own IHXBuffer, modify the data and then associate 
 *	    this buffer with the pAudioOutData->pData member.
 */
STDMETHODIMP
HXAdvancedTrack::OnBuffer(HXAudioData*	/*IN*/   pAudioInData,
		   HXAudioData*	/*OUT*/  pAudioOutData)
{
    HX_RESULT	rc = HXR_OK;

    if (!m_pHXGroup)
    {
	rc = HXR_UNEXPECTED;
	goto cleanup;
    }

    m_ulSoundLevelAnimationTime += m_ulGranularity;
    rc = ((HXAdvancedGroup*)m_pHXGroup)->OnSoundLevelAnimation(m_uTrackIndex, m_uSoundLevel, m_ulSoundLevelAnimationTime);

cleanup:

    return rc;
}
#endif /* HELIX_FEATURE_AUDIOHOOK */

/*
 *  IHXTrack methods
 */
/************************************************************************
*  Method:
*	    IHXTrack::Begin()
*  Purpose:
*	    start the track
*/
STDMETHODIMP
HXAdvancedTrack::Begin(void)
{
    HX_RESULT	rc = HXR_OK;

    if (!m_pHXGroup)
    {
	rc = HXR_UNEXPECTED;
	goto cleanup;
    }

    rc = ((HXAdvancedGroup*)m_pHXGroup)->BeginTrack(m_uTrackIndex, m_pValues);

cleanup:

    return rc;
}

/************************************************************************
*  Method:
*	    IHXTrack::Pause()
*  Purpose:
*	    pause the track
*/
STDMETHODIMP
HXAdvancedTrack::Pause(void)
{
    HX_RESULT	rc = HXR_OK;

    if (!m_pHXGroup)
    {
	rc = HXR_UNEXPECTED;
	goto cleanup;
    }

    rc = ((HXAdvancedGroup*)m_pHXGroup)->PauseTrack(m_uTrackIndex, m_pValues);

cleanup:

    return rc;
}

/************************************************************************
*  Method:
*	    IHXTrack::Seek()
*  Purpose:
*	    seek the track
*/
STDMETHODIMP
HXAdvancedTrack::Seek(UINT32 ulSeekTime)
{
    HX_RESULT	rc = HXR_OK;

    if (!m_pHXGroup)
    {
	rc = HXR_UNEXPECTED;
	goto cleanup;
    }

    rc = ((HXAdvancedGroup*)m_pHXGroup)->SeekTrack(m_uTrackIndex, m_pValues, ulSeekTime);

cleanup:

    return rc;
}

/************************************************************************
*  Method:
*	    IHXTrack::Stop()
*  Purpose:
*	    stop the track
*/
STDMETHODIMP
HXAdvancedTrack::Stop(void)
{
    HX_RESULT	rc = HXR_OK;

    if (!m_pHXGroup)
    {
	rc = HXR_UNEXPECTED;
	goto cleanup;
    }

    rc = ((HXAdvancedGroup*)m_pHXGroup)->StopTrack(m_uTrackIndex, m_pValues);

cleanup:

    return rc;
}

/************************************************************************
*  Method:
*	    IHXTrack::AddRepeat()
*  Purpose:
*	    add repeat tracks
*/
STDMETHODIMP
HXAdvancedTrack::AddRepeat(IHXValues* pTrack)
{
    if (!m_pRepeatList)
    {
	m_pRepeatList = new CHXSimpleList();
    }

    m_pRepeatList->AddTail(pTrack);
    pTrack->AddRef();

    ((HXAdvancedGroup*)m_pHXGroup)->RepeatTrackAdded(m_uTrackIndex, pTrack);

    return HXR_OK;
}

/************************************************************************
 *	Method:
 *	    IHXTrack::GetSource
 *	Purpose:
 *	    Returns the Nth source instance supported by this player.
 */
STDMETHODIMP
HXAdvancedTrack::GetSource(REF(IHXStreamSource*) pStreamSource)
{
    HX_RESULT	rc = HXR_OK;

    if (!m_pHXGroup)
    {
	rc = HXR_UNEXPECTED;
	goto cleanup;
    }

    rc = ((HXAdvancedGroup*)m_pHXGroup)->GetSource(m_uTrackIndex, pStreamSource);

cleanup:

    return rc;
}

/************************************************************************
*  Method:
*	    IHXTrack::SetSoundLevel()
*  Purpose:
*	    Set Audio Level
*/
STDMETHODIMP
HXAdvancedTrack::SetSoundLevel(UINT16 uSoundLevel)
{
    HX_RESULT	rc = HXR_OK;

    if (!m_pHXGroup)
    {
	rc = HXR_UNEXPECTED;
	goto cleanup;
    }

    if (m_uSoundLevel != uSoundLevel)
    {
	m_uSoundLevel = uSoundLevel;
	rc = ((HXAdvancedGroup*)m_pHXGroup)->SetSoundLevel(m_uTrackIndex, m_uSoundLevel, !m_bInSoundLevelAnimation);
    }

cleanup:

    return rc;
}

/************************************************************************
*  Method:
*	    IHXTrack::GetSoundLevel()
*  Purpose:
*	    Get Audio Level
*/
STDMETHODIMP_(UINT16)
HXAdvancedTrack::GetSoundLevel()
{
    return m_uSoundLevel;
}

/************************************************************************
*  Method:
*	    IHXTrack::BeginSoundLevelAnimation()
*  Purpose:
*	    notify the start of soundlevel animation
*/
STDMETHODIMP
HXAdvancedTrack::BeginSoundLevelAnimation(UINT16 uSoundLevelBeginWith)
{
    HX_RESULT	rc = HXR_OK;

    if (!m_pHXGroup)
    {
	rc = HXR_UNEXPECTED;
	goto cleanup;
    }

    m_uSoundLevel = uSoundLevelBeginWith;
    m_bInSoundLevelAnimation = TRUE;

    rc = ((HXAdvancedGroup*)m_pHXGroup)->BeginSoundLevelAnimation(m_uTrackIndex, m_uSoundLevel);
    
cleanup:

    return rc;
}

/************************************************************************
*  Method:
*	    IHXTrack::EndSoundLevelAnimation()
*  Purpose:
*	    notify the stop of soundlevel animation
*/
STDMETHODIMP
HXAdvancedTrack::EndSoundLevelAnimation(UINT16 uSoundLevelEndWith)
{
    HX_RESULT	rc = HXR_OK;

    if (!m_pHXGroup)
    {
	rc = HXR_UNEXPECTED;
	goto cleanup;
    }

    m_uSoundLevel = uSoundLevelEndWith;

    rc = ((HXAdvancedGroup*)m_pHXGroup)->EndSoundLevelAnimation(m_uTrackIndex, m_uSoundLevel);
    m_bInSoundLevelAnimation = FALSE;

cleanup:

    return rc;
}

void
HXAdvancedTrack::Close(void)
{
    if (m_bInSoundLevelAnimation)
    {
	EndSoundLevelAnimation(0);
    }

    if (m_pRepeatList)
    {
	CHXSimpleList::Iterator i = m_pRepeatList->Begin();
	for (; i != m_pRepeatList->End(); ++i)
	{
	    IHXValues* pValues = (IHXValues*)*i;
	    HX_RELEASE(pValues);
	}
	HX_DELETE(m_pRepeatList);
    }

    HXBasicTrack::Close();
}

HXAdvancedGroup::HXAdvancedGroup(HXAdvancedGroupManager* pManager)
                :HXBasicGroup(pManager)
                ,m_pGroupProperties(NULL)
                ,m_bPrefetchSinkAdded(FALSE)
                ,m_pPrefetchTrackMap(NULL)
                ,m_pPersistentComponentPropertyMap(NULL)
                ,m_uPrefetchTrackCount(0)
                ,m_pTrackSinkList(NULL)
                ,m_pPrefetchSinkList(NULL)
{
}

HXAdvancedGroup::~HXAdvancedGroup(void)
{
    Close();
}

/*
 *  IUnknown methods
 */
STDMETHODIMP HXAdvancedGroup::QueryInterface(REFIID riid, void** ppvObj)
{
    if (HXR_OK == HXBasicGroup::QueryInterface(riid, ppvObj))
    {
	return HXR_OK;
    }
    else if (IsEqualIID(riid, IID_IHXGroup2))
    {
        AddRef();
        *ppvObj = (IHXGroup2*)this;
        return HXR_OK;
    }
#if defined(HELIX_FEATURE_PREFETCH)
    else if (IsEqualIID(riid, IID_IHXPrefetch))
    {
        AddRef();
        *ppvObj = (IHXPrefetch*)this;
        return HXR_OK;
    }
    else if (IsEqualIID(riid, IID_IHXPrefetchSink))
    {
        AddRef();
        *ppvObj = (IHXPrefetchSink*)this;
        return HXR_OK;
    }
#endif /* HELIX_FEATURE_PREFETCH */

    *ppvObj = NULL;
    return HXR_NOINTERFACE;
}

STDMETHODIMP_(ULONG32) HXAdvancedGroup::AddRef()
{
    return InterlockedIncrement(&m_lRefCount);
}

STDMETHODIMP_(ULONG32) HXAdvancedGroup::Release()
{
    if (InterlockedDecrement(&m_lRefCount) > 0)
    {
        return m_lRefCount;
    }

    delete this;
    return 0;
}

/*
 *  IHXGroup methods
 */
/************************************************************************
*  Method:
*      IHXGroup::SetGroupProperties
*  Purpose:
*		Set any group specific information like Title Author 
*		Copyright etc. 
*/
STDMETHODIMP
HXAdvancedGroup::SetGroupProperties(IHXValues*  /*IN*/ pProperties)
{
    UINT32  ulDuration = 0;

    if (m_pGroupProperties || !pProperties)
    {
	return HXR_UNEXPECTED;
    }

    m_pGroupProperties = pProperties;
    m_pGroupProperties->AddRef();

    // support adjust current group's duration on the fly
    if (m_uGroupIndex == m_pGroupManager->m_uCurrentGroup)
    {	
	if (HXR_OK == m_pGroupProperties->GetPropertyULONG32("duration", ulDuration))
	{
	    m_pPlayer->SetPresentationTime(ulDuration);
	}
    }

    return HXR_OK;
}

/************************************************************************
*  Method:
*      IHXGroup::GetGroupProperties
*  Purpose:
*		Get any group specific information. May return NULL.
*/
STDMETHODIMP_(IHXValues*)
HXAdvancedGroup::GetGroupProperties(void)
{
    if (m_pGroupProperties)
    {
	m_pGroupProperties->AddRef();
    }

    return m_pGroupProperties;
}

/************************************************************************
*  Method:
*      IHXGroup2::SetPersistentComponentProperties
*  Purpose:
*		Set persistent component properties associated with this group
*		One group may contain multiple persistent components
*/
STDMETHODIMP
HXAdvancedGroup::SetPersistentComponentProperties(UINT32        /*IN*/ ulPersistentComponentID,
					          IHXValues*	/*IN*/ pProperties)
{
    HX_RESULT	rc = HXR_OK;
    IHXValues*	pValues = NULL;

    if (!pProperties)
    {
	rc = HXR_FAILED;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -