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

📄 audrend.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 ***** */

// #define _AUDREND_FLOW_LOG

#define TIME_SYNC_GRANULARITY	100	// in milliseconds
#define MAX_AUDIO_WRITE_TIME	200	// in milliseconds

#define STREAM_MAJOR_VERSION  0
#define STREAM_MINOR_VERSION  0

#define CONTENT_MAJOR_VERSION 0
#define CONTENT_MINOR_VERSION 0

#define TIME_FUDGE 5

#define BASE_AUDIO_RENDERER_NAME    "Basic Audio"
#define MINIMAL_AUDIO_PUSHDOWN 120

#ifdef _AUDREND_FLOW_LOG
#define AUDREND_FLOW_FILE	    "C:\\audrend.txt"
#else	// _AUDREND_FLOW_LOG
#define AUDREND_FLOW_FILE	    NULL
#endif	// _AUDREND_FLOW_LOG


/****************************************************************************
 *  Includes
 */
#include "hlxclib/stdio.h"
#include "hlxclib/string.h"

#include "audrend.ver"

#include "hxtypes.h"
#include "hxcom.h"
#include "hxcomm.h"
#include "ihxpckts.h"
#include "hxcore.h"
#include "hxrendr.h"
#include "hxplugn.h"
#include "hxasm.h"
#include "hxver.h"
#include "hxupgrd.h"
#include "hxengin.h"
#include "hxprefs.h"
#include "hxerror.h"
#include "hxausvc.h"
#include "hxthread.h"
#include "hxstrutl.h"

#include "hxtick.h"
#include "hxassert.h"
#include "hxbuffer.h"
#include "addupcol.h"
#include "errdbg.h"
#include "adjtime.h"

#include "hxver.h"

#include "audrmlog.h"
#include "audrend.h"

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


/****************************************************************************
 *  Constants
 */
const char* const CAudioRenderer::zm_pDescription    = "RealNetworks Audio Renderer Plugin";
const char* const CAudioRenderer::zm_pCopyright      = HXVER_COPYRIGHT;
const char* const CAudioRenderer::zm_pMoreInfoURL    = HXVER_MOREINFO;
const char* const CAudioRenderer::zm_pStreamMimeTypes[] =
{
    "audio/NULL",
    NULL
};


/************************************************************************
 *  CAudioRenderer
 */
/************************************************************************
 *  Constructor/Destructor
 */
CAudioRenderer::CAudioRenderer()
	: m_pContext(NULL)
	, m_pStream(NULL)
	, m_pBackChannel(NULL)
	, m_pHeader(NULL)
        , m_pErrorMessages(NULL)
	, m_pCommonClassFactory(NULL)
	, m_pPreferences(NULL)
	, m_pRegistry(NULL)
	, m_ulRegistryID(0)
	, m_ulPreroll(0)
	, m_ulAudioWantedTime(NO_TIME_SET)
	, m_ulLastWriteTime(NO_TIME_SET)
	, m_pAudioPlayer(NULL)
	, m_bEndOfPackets(FALSE)
	, m_bDoneWritingPackets(FALSE)
	, m_bInSeekMode(FALSE)
	, m_ulDuration(0)
	, m_bFirstPacket(TRUE)
	, m_bDelayOffsetSet(FALSE)
	, m_ulDelay(0)
	, m_pMutex(NULL)
	, m_bProcessingPacket(FALSE)
	, m_pAudioFormat(NULL)
	, m_PlayState(stopped)
	, m_lRefCount(0)
        , m_ppAudioStream(NULL)
        , m_pAudioStats(NULL)
        , m_ulNumAudioStreams(0)
        , m_ulCurAudioStream(0)
        , m_bCanChangeAudioStream(FALSE)
    , m_lTimeOffset(0)
{ 
    // Allocate space for an initial number of pointers
    m_ppAudioStream = new IHXAudioStream* [AUDREND_INITIAL_NUMSTREAMPTRS];
    if (m_ppAudioStream)
    {
        memset((void*) m_ppAudioStream, 0, AUDREND_INITIAL_NUMSTREAMPTRS * sizeof(IHXAudioStream*));
        m_ulNumAudioStreams = AUDREND_INITIAL_NUMSTREAMPTRS;
    }
}

CAudioRenderer::~CAudioRenderer()
{
    EndStream();

#if defined(HELIX_FEATURE_STATS)
    HX_DELETE(m_pAudioStats); 
#endif /* HELIX_FEATURE_STATS */
    HX_DELETE(m_pMutex);
    HX_RELEASE(m_pContext);
    HX_RELEASE(m_pHeader);
    HX_RELEASE(m_pErrorMessages);
    HX_RELEASE(m_pCommonClassFactory);
    HX_RELEASE(m_pPreferences);
    HX_RELEASE(m_pRegistry);
}


/************************************************************************
 *  IHXPlugin Methods
 */
/************************************************************************
 *  Method:
 *    IHXPlugin::InitPlugin
 *  Purpose:
 *    Initializes the plugin for use. This interface must always be
 *    called before any other method is called. This is primarily needed
 *    so that the plugin can have access to the context for creation of
 *    IHXBuffers and IMalloc.
 */
STDMETHODIMP CAudioRenderer::InitPlugin(IUnknown* /*IN*/ pContext)
{
    HX_RESULT retVal = HXR_OK;

    HX_ASSERT(pContext);

    m_pContext = pContext;
    m_pContext->AddRef();

    retVal = m_pContext->QueryInterface(IID_IHXCommonClassFactory,
					(void**) &m_pCommonClassFactory);

    m_pContext->QueryInterface(IID_IHXPreferences,
                               (void**) &m_pPreferences);

    m_pContext->QueryInterface(IID_IHXRegistry, (void**) &m_pRegistry);

    if (SUCCEEDED(retVal) && !m_pMutex)
    {
#ifdef THREADS_SUPPORTED
	retVal = HXMutex::MakeMutex(m_pMutex);
#else  // THREADS_SUPPORTED
	retVal = HXMutex::MakeStubMutex(m_pMutex);
#endif  // THREADS_SUPPORTED
    }

#if defined(HELIX_FEATURE_STATS)
    if (SUCCEEDED(retVal))
    {
	m_pAudioStats = new CAudioStatistics(m_pContext);

	retVal = HXR_OUTOFMEMORY;
	if (m_pAudioStats)
	{
	    retVal = HXR_OK;
	}
    }
#endif /* HELIX_FEATURE_STATS */

    // Get the IHXErrorMessages interface. Not an error
    // if it's not supported
    HX_RELEASE(m_pErrorMessages);
    m_pContext->QueryInterface(IID_IHXErrorMessages,
                               (void**) &m_pErrorMessages);

    if (FAILED(retVal))
    {
	HX_RELEASE(m_pCommonClassFactory);
	HX_RELEASE(m_pPreferences);
	HX_RELEASE(m_pRegistry);
    }

    return retVal;
}

/************************************************************************
 *  Method:
 *    IHXPlugin::GetPluginInfo
 *  Purpose:
 *    Returns the basic information about this plugin. Including:
 *
 *    bLoadMultiple	whether or not this plugin DLL can be loaded
 *			multiple times. All File Formats must set
 *			this value to TRUE.
 *    pDescription	which is used in about UIs (can be NULL)
 *    pCopyright	which is used in about UIs (can be NULL)
 *    pMoreInfoURL	which is used in about UIs (can be NULL)
 */
STDMETHODIMP CAudioRenderer::GetPluginInfo
(
   REF(BOOL)        /*OUT*/ bLoadMultiple,
   REF(const char*) /*OUT*/ pDescription,
   REF(const char*) /*OUT*/ pCopyright,
   REF(const char*) /*OUT*/ pMoreInfoURL,
   REF(ULONG32)     /*OUT*/ ulVersionNumber
)
{
    bLoadMultiple = TRUE;   // Must be true for file formats.

    pDescription    = zm_pDescription;
    pCopyright	    = zm_pCopyright;
    pMoreInfoURL    = zm_pMoreInfoURL;
    ulVersionNumber = TARVER_ULONG32_VERSION;

    return HXR_OK;
}

/************************************************************************
 *  Method:
 *    IHXPlugin::GetRendererInfo
 *  Purpose:
 *    If this object is a file format object this method returns
 *    information vital to the instantiation of file format plugins.
 *    If this object is not a file format object, it should return
 *    HXR_UNEXPECTED.
 */
STDMETHODIMP CAudioRenderer::GetRendererInfo
(
 REF(const char**) /*OUT*/ pStreamMimeTypes,
 REF(UINT32)      /*OUT*/ unInitialGranularity
)
{
    pStreamMimeTypes = (const char**)zm_pStreamMimeTypes;
    unInitialGranularity = TIME_SYNC_GRANULARITY;
    return HXR_OK;
}


// *** IUnknown methods ***
/****************************************************************************
*  IUnknown::QueryInterface                                    ref:  hxcom.h
*
*  This routine indicates which interfaces this object supports. If a given
*  interface is supported, the object's reference count is incremented, and
*  a reference to that interface is returned. Otherwise a NULL object and
*  error code are returned. This method is called by other objects to
*  discover the functionality of this object.
*/
STDMETHODIMP CAudioRenderer::QueryInterface(REFIID riid, void** ppvObj)
{
    QInterfaceList  qiList[] =
    {
	{ GET_IIDHANDLE(IID_IHXInterruptSafe), (IHXInterruptSafe*)this},
	{ GET_IIDHANDLE(IID_IHXDryNotification), (IHXDryNotification*)this},
	{ GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXPlugin*) this},
	{ GET_IIDHANDLE(IID_IHXPlugin), (IHXPlugin*)this},
	{ GET_IIDHANDLE(IID_IHXRenderer), (IHXRenderer*)this},
#if defined(HELIX_FEATURE_STATS)
	{ GET_IIDHANDLE(IID_IHXStatistics), (IHXStatistics*)this},
#endif	// HELIX_FEATURE_STATS
    };
    return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
}

/****************************************************************************
*  IUnknown::AddRef                                            ref:  hxcom.h
*
*  This routine increases the object reference count in a thread safe
*  manner. The reference count is used to manage the lifetime of an object.
*  This method must be explicitly called by the user whenever a new
*  reference to an object is used.
*/
STDMETHODIMP_(ULONG32) CAudioRenderer::AddRef()
{
    return InterlockedIncrement(&m_lRefCount);
}

/****************************************************************************
*  IUnknown::Release                                           ref:  hxcom.h
*
*  This routine decreases the object reference count in a thread safe
*  manner, and deletes the object if no more references to it exist. It must
*  be called explicitly by the user whenever an object is no longer needed.
*/
STDMETHODIMP_(ULONG32) CAudioRenderer::Release()
{
    if (InterlockedDecrement(&m_lRefCount) > 0)
    {
        return m_lRefCount;
    }

    delete this;
    return 0;
}


/************************************************************************
 *  IHXRenderer Methods
 */
/////////////////////////////////////////////////////////////////////////
//  Method:
//	IHXRenderer::StartStream
//  Purpose:
//	Called by client engine to inform the renderer of the stream it
//	will be rendering. The stream interface can provide access to
//	its source or player. This method also provides access to the
//	primary client controller interface.
//
STDMETHODIMP
CAudioRenderer::StartStream
(
    IHXStream*	    pStream,
    IHXPlayer*	    pPlayer
)
{
    HX_RESULT retVal = HXR_OK;

    m_pStream  = pStream;

    if (m_pStream)
    {
	m_pStream->AddRef();
	IHXStreamSource* pSource = 0;
	if (m_pStream->GetSource(pSource) == HXR_OK)
	{
	    /* It is OK if the source does not support backchannel. Reasons:
	     *
	     * 1. This stream may not be coming from h261 fileformat.
	     *	  It may instead be merged into a container fileformat which
	     *	  may be does not support BackChannel.
	     *
	     * 2. The protocol used to serve this stream may not support
	     *	  BackChannel.
	     */
	    pSource->QueryInterface(IID_IHXBackChannel, (void**) &m_pBackChannel);

	    pSource->Release();
	}
    }

    IHXAudioPushdown2 * pAudioPushdown2 = NULL;

    // get interface to audio player
    if (pPlayer)
    {
	retVal = pPlayer->QueryInterface(IID_IHXAudioPlayer,
					   (void**) &m_pAudioPlayer);
#ifdef HELIX_CONFIG_MIN_PCM_PUSHDOWN_BYTES
        if( m_pAudioPlayer )
        {
            m_pAudioPlayer->QueryInterface(IID_IHXAudioPushdown2, (void**) &pAudioPushdown2);
            if( pAudioPushdown2 )
            {
                pAudioPushdown2->SetAudioPushdown( MINIMAL_AUDIO_PUSHDOWN );
                pAudioPushdown2->Release();
            }
        }
#endif // HELIX_CONFIG_MIN_PCM_PUSHDOWN_BYTES
    }

    return retVal;
}

/////////////////////////////////////////////////////////////////////////
//  Method:
//	IHXRenderer::EndStream
//  Purpose:
//	Called by client engine to inform the renderer that the stream
//	is was rendering is closed.
//
STDMETHODIMP CAudioRenderer::EndStream()
{
    if (m_pMutex)
    {
	m_pMutex->Lock();
    }

    m_bDoneWritingPackets = TRUE;
    m_PlayState = stopped;

    if (m_pMutex)
    {
	m_pMutex->Unlock();
    }

    if (m_pAudioFormat)
    {
        m_pAudioFormat->Release();
        m_pAudioFormat = NULL;
    }
    HX_RELEASE(m_pStream);
    HX_RELEASE(m_pBackChannel);
    HX_RELEASE(m_pAudioPlayer);
    for (UINT32 i = 0; i < m_ulNumAudioStreams; i++)
    {
        HX_RELEASE(m_ppAudioStream[i]);
    }
    HX_VECTOR_DELETE(m_ppAudioStream);
    m_ulNumAudioStreams = 0;

    return HXR_OK;
}

/////////////////////////////////////////////////////////////////////////
//  Method:
//	IHXRenderer::OnHeader
//  Purpose:
//	Called by client engine when a header for this renderer is
//	available. The header will arrive before any packets.
//
STDMETHODIMP
CAudioRenderer::OnHeader(IHXValues* pHeader)
{
    HX_RESULT retVal = HXR_OK;
    UINT32 ulTrackStartTime = NO_TIME_SET;
    UINT32 ulTrackEndTime = NO_TIME_SET;

#if defined(HELIX_FEATURE_AUTOUPGRADE)
    // check the stream versions
    pHeader->AddRef();
    retVal = CheckStreamVersions(pHeader);
    pHeader->Release();
#endif /* #if defined(HELIX_FEATURE_AUTOUPGRADE) */

    if (SUCCEEDED(retVal))
    {
	pHeader->GetPropertyULONG32("Preroll", m_ulPreroll);
	pHeader->GetPropertyULONG32("Duration", m_ulDuration);
	pHeader->GetPropertyULONG32("Delay", m_ulDelay);

	pHeader->GetPropertyULONG32("TrackStartTime", ulTrackStartTime);
	pHeader->GetPropertyULONG32("TrackEndTime", ulTrackEndTime);
    }

    if (SUCCEEDED(retVal))
    {
	m_pAudioFormat = CreateFormatObject(pHeader);

	retVal = HXR_OUTOFMEMORY;
	if (m_pAudioFormat)
	{
	    m_pAudioFormat->AddRef();
	    retVal = HXR_OK;
	}
    }

    if (SUCCEEDED(retVal))
    {
	retVal = m_pAudioFormat->Init(pHeader);
#if defined(HELIX_FEATURE_AUTOUPGRADE)
        if (FAILED(retVal) && retVal == HXR_REQUEST_UPGRADE)
        {
            AddToAutoUpgradeCollection(m_pAudioFormat->GetAutoUpgradeString(),
                                       m_pContext);
        }
#endif /* #if defined(HELIX_FEATURE_AUTOUPGRADE) */
    }

⌨️ 快捷键说明

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