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

📄 hxaudply.cpp

📁 symbian 下的helix player源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/* ***** BEGIN LICENSE BLOCK *****
 * Source last modified: $Id: hxaudply.cpp,v 1.25.2.3 2004/07/09 02:08:08 hubbe Exp $
 * 
 * Portions Copyright (c) 1995-2004 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 (the "RPSL") available at
 * http://www.helixcommunity.org/content/rpsl unless you have licensed
 * the file under the current version of the RealNetworks Community
 * Source License (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.
 * 
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU General Public License Version 2 or later (the
 * "GPL") in which case the provisions of the GPL are applicable
 * instead of those above. If you wish to allow use of your version of
 * this file only under the terms of the GPL, and not to allow others
 * to use your version of this file under the terms of either the RPSL
 * or RCSL, indicate your decision by deleting the provisions above
 * and replace them with the notice and other provisions required by
 * the GPL. If you do not delete the provisions above, a recipient may
 * use your version of this file under the terms of any one of the
 * RPSL, the RCSL or the GPL.
 * 
 * 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 "hlxclib/stdio.h"
#include "hlxclib/stdlib.h"
#include "hlxclib/string.h"

#ifndef WIN32_PLATFORM_PSPC
#include "hlxclib/signal.h"
#endif

#include "hxresult.h"
#include "hxtypes.h"
#include "hxslist.h"
#include "hxcom.h"

#include "ihxpckts.h"
#include "hxengin.h"
#include "hxprefs.h"
#include "hxausvc.h"
#include "hxrasyn.h"
#include "hxerror.h"
#include "hxcore.h"

#include "hxmap.h"

#include "hxaudply.h"
#include "hxaudstr.h"
#include "hxaudses.h"
#include "hxaudvol.h"

#include "hxaudtyp.h"

#include "timeval.h"
#include "hxtick.h"

#ifdef _MACINTOSH
#include "hxmm.h"

extern  ULONG32	gTIMELINE_MUTEX;
#endif

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

#if defined(HELIX_FEATURE_PREFERENCES)
#include "hxprefs.h"
#include "hxprefutil.h"
#endif /* HELIX_FEATURE_PREFERENCES */

#ifdef HELIX_CONFIG_MIN_PCM_PUSHDOWN_BYTES
// These values were arrived at via trial and error on a linux, xi586 (pentium)
#define MINIMUM_AUDIO_GRANULARITY	50
#define MAXIMUM_AUDIO_GRANULARITY	100
#else
#define MINIMUM_AUDIO_GRANULARITY	50
#define MAXIMUM_AUDIO_GRANULARITY	100
#endif

#define MAX_WAIT_AT_SAME_TIME		(MAXIMUM_AUDIO_GRANULARITY+50)

CHXAudioPlayer::CHXAudioPlayer( CHXAudioSession* owner )
:	m_lRefCount(0)
,       m_ulCallbackID(0)
,	m_pContext(0)
,	m_bInited(FALSE)
,	m_ulGranularity(0)
,	m_Owner(owner)
,	m_pStreamList(0)
,	m_pRealAudioStreamList(0)
,	m_bAdjustForRealAudio(FALSE)
,	m_pPlayerResponse(0)
,	m_pScheduler (0)
,	m_pPreferences(0)
,	m_bHasStreams(FALSE)
,	m_bIsLive(FALSE)
,	m_ulCurrentTime(0)
,	m_ulLastCurrentTimeReturned(0)
,	m_ulLastDeviceTimeAdjusted(0)
,	m_bTimeReturned(FALSE)
,	m_pPMixHookList(0)
,	m_ulBytesPerGran(0)
,	m_pStreamRespList(0)
,	m_ulASstartTime(0)
,	m_ulAPplaybackTime(0)
,	m_ulAPstartTime(0)
,	m_ulADresumeTime(0)
, 	m_eState(E_STOPPED)
,	m_bPrefUse11khz(FALSE)
,	m_uPrefBitsPerSample(16)
,	m_uPrefAudioQuality(4)
,	m_pFakeAudioCBTime(0)
,	m_ulLastFakeCallbackTime(0)
,	m_ulIncreasingTimer(0)
,	m_bDisableWrite(FALSE)
,	m_bIsResumed(FALSE)
,	m_ulTimeAdjustDoneAt(0)
,	m_bIsDonePlayback(TRUE)
,	m_bIsFirstResume(TRUE)
,	m_bCanBeRewound(FALSE)
,	m_uVolume(0)
,	m_bMute(FALSE)
,	m_bHasDataInAudioDevice(FALSE)
,	m_llLastWriteTime(0)
{
#ifdef HELIX_FEATURE_VOLUME
    m_pPlayerVolume = NULL;
#endif

    m_Owner->AddRef();
    m_pFakeAudioCBTime			= new Timeval;
    // NOTE: we should add some check on the success of this allocation.

    /* Default value of Player format */
    m_PlayerFmt.uChannels	= 2;
    m_PlayerFmt.uBitsPerSample	= 16;
    m_PlayerFmt.ulSamplesPerSec	= 16000;
    m_PlayerFmt.uMaxBlockSize	= 64000;
}

/************************************************************************
 *  Method:
 *		IHXAudioPlayer::~CHXAudioPlayer()
 *	Purpose:
 *		Destructor. Clean up and set free.
 */
CHXAudioPlayer::~CHXAudioPlayer()
{
    Close();
}

void CHXAudioPlayer::Close(void)
{
    ResetPlayer();

    HX_DELETE(m_pStreamList);
    HX_DELETE(m_pRealAudioStreamList);

    HX_RELEASE(m_pContext);
#if defined(HELIX_FEATURE_PREFERENCES)
    HX_RELEASE(m_pPreferences);
#endif /* HELIX_FEATURE_PREFERENCES */
    HX_RELEASE(m_pPlayerResponse);

    if ( m_pPMixHookList )
    {
	HXAudioHookInfo* pMixHookInfo  = 0;
	while(!m_pPMixHookList->IsEmpty())
	{
	    pMixHookInfo = (HXAudioHookInfo*) m_pPMixHookList->RemoveHead();
	    pMixHookInfo->pHook->Release();
	    delete pMixHookInfo;
	}

	delete m_pPMixHookList;
	m_pPMixHookList = 0;
    }

    // Delete all stream response items.
    if ( m_pStreamRespList )
    {
	IHXAudioStreamInfoResponse*   pAudioStreamInfoResponse = 0;
	while(!m_pStreamRespList->IsEmpty())
	{
	    pAudioStreamInfoResponse =
	     (IHXAudioStreamInfoResponse*) m_pStreamRespList->RemoveHead();

	    pAudioStreamInfoResponse->Release();
	}

	delete m_pStreamRespList;
	m_pStreamRespList = 0;
    }

#ifdef HELIX_FEATURE_VOLUME
    if( m_pPlayerVolume )
    {
        m_pPlayerVolume->RemoveAdviseSink((IHXVolumeAdviseSink*)this);
        m_pPlayerVolume->Release();
        m_pPlayerVolume = NULL;
    }
#endif

    // Delete IRMA volume object.
    HX_DELETE(m_pFakeAudioCBTime);
    HX_RELEASE(m_Owner);
    HX_RELEASE(m_pScheduler);
}

/////////////////////////////////////////////////////////////////////////
//  Method:
//      IUnknown::QueryInterface
//  Purpose:
//      Implement this to export the interfaces supported by your
//      object.
//
STDMETHODIMP CHXAudioPlayer::QueryInterface(REFIID riid, void** ppvObj)
{
    QInterfaceList qiList[] =
        {
            { GET_IIDHANDLE(IID_IHXAudioPlayer), (IHXAudioPlayer*)this },
#if defined(HELIX_FEATURE_CROSSFADE)
            { GET_IIDHANDLE(IID_IHXAudioCrossFade), (IHXAudioCrossFade*)this },
#endif /* HELIX_FEATURE_CROSSFADE */
#if defined(HELIX_FEATURE_VOLUME)
            { GET_IIDHANDLE(IID_IHXVolumeAdviseSink), (IHXVolumeAdviseSink*)this },
#endif /* HELIX_FEATURE_VOLUME */
            { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXAudioPlayer*)this },
        };

    HX_RESULT res = ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);

    // if succeeded, return immediately...
    if (SUCCEEDED(res))
    {
        return res;
    }
    // ...otherwise, proceed.

    if (m_Owner &&
	     m_Owner->QueryInterface(riid, ppvObj) == HXR_OK)
    {
	return HXR_OK;
    }

    *ppvObj = NULL;
    return HXR_NOINTERFACE;
}

/////////////////////////////////////////////////////////////////////////
//  Method:
//      IUnknown::AddRef
//  Purpose:
//      Everyone usually implements this the same... feel free to use
//      this implementation.
//
STDMETHODIMP_(ULONG32) CHXAudioPlayer::AddRef()
{
    return InterlockedIncrement(&m_lRefCount);
}

/////////////////////////////////////////////////////////////////////////
//  Method:
//      IUnknown::Release
//  Purpose:
//      Everyone usually implements this the same... feel free to use
//      this implementation.
//
STDMETHODIMP_(ULONG32) CHXAudioPlayer::Release()
{
    if (InterlockedDecrement(&m_lRefCount) > 0)
    {
        return m_lRefCount;
    }

    delete this;
    return 0;
}

/*
 *  IHXAudioPlayer methods
 */
/************************************************************************
 *  Method:
 *              IHXAudioPlay::AddPostMixHook
 *      Purpose:
 *       Call this to add a post mix hook of the audio data.
 */
STDMETHODIMP CHXAudioPlayer::AddPostMixHook
(
    IHXAudioHook*	pHook,
    const BOOL		bDisableWrite,
    const BOOL          bFinal
)
{
    /* We only allow adding Hooks before the playback has started */
    if (m_bInited)
    {
	return HXR_FAILED;
    }

    return ActualAddPostMixHook(pHook, bDisableWrite, bFinal);
}

/************************************************************************
 *  Method:
 *              IHXAudioPlay::RemovePostMixHook
 *      Purpose:
 *       Call this to remove a post mix hook.
 */
STDMETHODIMP CHXAudioPlayer::RemovePostMixHook
(
    IHXAudioHook*	pHook
)
{
    /* We only allow removing Hooks after the playback has stopped */
    if (m_bInited)
    {
	return HXR_FAILED;
    }

    return ActualRemovePostMixHook(pHook);
}

/************************************************************************
*  Method:
*      IHXAudioPlayer::GetAudioStreamCount
*  Purpose:
*		Get the number of audio streams currently active in the
*		audio player. Since streams can be added mid-presentation
*		this function may return different values on different calls.
*		If the user needs to know about all the streams as they get
*		get added to the player, IHXAudioStreamInfoResponse should
*		be implemented and passed in SetStreamInfoResponse.
*/
STDMETHODIMP_(UINT16) CHXAudioPlayer::GetAudioStreamCount()
{
    HX_ASSERT(m_pStreamList);
    if (m_pStreamList)
    {
	return (UINT16) m_pStreamList->GetCount();
    }
    else
    {
	return 0;
    }
}

/************************************************************************
 *  Method:
 *              IHXAudioPlayer::GetAudioStream
 *      Purpose:
 */
STDMETHODIMP_(IHXAudioStream*) CHXAudioPlayer::GetAudioStream
(
    UINT16 	uIndex
)
{
    LISTPOSITION lp = 0;
    lp = m_pStreamList->FindIndex( (int) uIndex );
    if ( lp )
    {
	CHXAudioStream* s = 0;
	s = (CHXAudioStream*) m_pStreamList->GetAt(lp);
	s->AddRef();
	return s;
    }
    else
        return 0;
}

/************************************************************************
 *  Method:
 *              IHXAudioPlayer::GetAudioVolume
 *      Purpose:
 *		Return this player's IRMA volume interface.
 */
STDMETHODIMP_(IHXVolume*) CHXAudioPlayer::GetAudioVolume()
{
    IHXVolume* pRet = NULL;
#ifdef HELIX_FEATURE_VOLUME
    if( m_pPlayerVolume )
    {
        m_pPlayerVolume->AddRef();
        pRet = m_pPlayerVolume;
    }
#endif
    return pRet;
}

/************************************************************************
 *  Method:
 *              IHXAudioPlayer::GetDeviceVolume
 *      Purpose:
 *		Return this audio device volume interface.
 */
STDMETHODIMP_(IHXVolume*) CHXAudioPlayer::GetDeviceVolume()
{
    return ( m_Owner->GetDeviceVolume() );
}

/*
 *  IHXAudioCrossFade methods
 */

/************************************************************************
 *  Method:
 *      IHXAudioCrossFade::CrossFade
 *  Purpose:
 *	Cross-fade two audio streams.
 *	pStreamFrom		- Stream to be cross faded from
 *	pStreamTo		- Stream to be cross faded to
 *	ulFromCrossFadeStartTime- "From" Stream time when cross fade is
 *				  to be started
 *	ulToCrossFadeStartTime	- "To" Stream time when cross fade is to
 *				  be started
 *	ulCrossFadeDuration	- Duration over which cross-fade needs
 *				      to be done
 *
 */
STDMETHODIMP
CHXAudioPlayer::CrossFade(IHXAudioStream*  pStreamFrom,
			  IHXAudioStream*  pStreamTo,
			  UINT32	    ulFromCrossFadeStartTime,
			  UINT32	    ulToCrossFadeStartTime,
			  UINT32	    ulCrossFadeDuration)
{
#if defined(HELIX_FEATURE_CROSSFADE)
    HX_RESULT theErr = HXR_OK;

    /* Make sure these two streams are available */
    LISTPOSITION streamPos1 = m_pStreamList->Find(pStreamFrom);
    LISTPOSITION streamPos2 = m_pStreamList->Find(pStreamTo);
    if (!streamPos2 || !streamPos1)
    {
	return HXR_INVALID_PARAMETER;
    }

    CHXAudioStream* pFromStream =
	(CHXAudioStream*) m_pStreamList->GetAt(streamPos1);
    CHXAudioStream* pToStream	=
	(CHXAudioStream*) m_pStreamList->GetAt(streamPos2);

    theErr = pFromStream->StartCrossFade(pToStream, ulFromCrossFadeStartTime,
					ulCrossFadeDuration, FALSE);
    if (!theErr)
    {
	theErr = pToStream->StartCrossFade(pFromStream, ulToCrossFadeStartTime,
					ulCrossFadeDuration, TRUE);
    }

    /* Adjust the streams in list so that the "ToStream" List appears before
     * the "FromStream"
     * A lame but quick-and-dirty way to do it: Remove these two stream from
     * the listand them in order at the tail!
     */
    if (!theErr)
    {
	LISTPOSITION lPos = m_pStreamList->GetHeadPosition();
	while (lPos)
	{
	    CHXAudioStream* pStream =
		(CHXAudioStream* ) m_pStreamList->GetAt(lPos);
	    if (pStream == pFromStream ||
		pStream == pToStream)
	    {
		/* RemoveAt returns the next position in the list.
		 * DO NOT use GetNext if you remove a node.
		 */
		lPos = m_pStreamList->RemoveAt(lPos);
	    }
	    else
	    {
		m_pStreamList->GetNext(lPos);
	    }
	}

	m_pStreamList->AddTail((void*) pToStream);
	m_pStreamList->AddTail((void*) pFromStream);
    }
#endif /* HELIX_FEATURE_CROSSFADE */

    return HXR_OK;
}

/************************************************************************
 *  Method:
 *		CHXAudioPlayer::Init
 *	Purpose:
 *		Initialize the Audio Player object called by rmaplayer.
 */
HX_RESULT CHXAudioPlayer::Init
(
    IUnknown*	pContext
)
{
    if (!pContext)
	return HXR_INVALID_PARAMETER;

    m_pContext = pContext;
    m_pContext->AddRef();

    if (HXR_OK != pContext->QueryInterface(IID_IHXScheduler,
				(void **) &m_pScheduler))
    {
	return HXR_INVALID_PARAMETER;
    }

    if (HXR_OK != pContext->QueryInterface(IID_IHXAudioPlayerResponse,
				(void **) &m_pPlayerResponse))
    {
	return HXR_INVALID_PARAMETER;
    }
#if defined( HELIX_FEATURE_PREFERENCES )
    m_pContext->QueryInterface(IID_IHXPreferences, (void**) &m_pPreferences);
#endif
    return HXR_OK;
}


/************************************************************************
 *  Method:
 *		CHXAudioPlayer::_Init
 *	Purpose:
 *		Create internal lists, etc. Called by Audio Session
 *		CreateAudioPlayer() method.
 */
HX_RESULT CHXAudioPlayer::InitializeStructures()
{
    HX_RESULT theErr = HXR_OK;

    // Create the Stream list.
    // Create the Post process hook list.

⌨️ 快捷键说明

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