?? hxaudstr.cpp
字號:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: hxaudstr.cpp,v 1.17.2.1 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/string.h"#include "hxresult.h"#include "hxtypes.h"#include "hxcom.h"#include "hxengin.h"#include "ihxpckts.h"#include "hxausvc.h"#include "hxrasyn.h"#include "hxprefs.h"#include "hxerror.h"#include "errdbg.h"#include "chxpckts.h"#include "hxaudply.h"#include "hxaudstr.h"#include "hxaudses.h"#include "hxmixer.h"#include "hxaudvol.h" #include "hxslist.h"#include "hxmap.h"#include "auderrs.h"#include "hxtick.h"//#include "rmarsmp.h"#ifdef _WINDOWS#include "hxrsmp2.h"#endif /* _WINDOWS *///#include "resample.h" //#include "interp.h" #include "crosfade.h"#include "hxheap.h"#ifdef _DEBUG#undef HX_THIS_FILE static const char HX_THIS_FILE[] = __FILE__;#endif#define CACHE_INCREMENT_SIZE 2//#define _TESTING 1#ifdef _TESTING#include <fcntl.h>#include <sys/types.h>#include <sys/stat.h>#if defined (_WINDOWS) || defined (_WIN32)#include <io.h>#endifint g_log = -1;#endif/************************************************************************ * Method: * IHXAudioStream::CHXAudioStream() * Purpose: * Constructor. */CHXAudioStream::CHXAudioStream(CHXAudioPlayer* owner, IUnknown* pContext): m_lRefCount(0), m_wLastError(HXR_OK), m_pResampler(NULL), m_pValues(0), m_bDisableWrite(FALSE), m_ulGranularity(0), m_ulInputBytesPerGran(0), m_ulOutputBytesPerGran(0), m_ulExcessInterpBufferSize(0), m_ulPreviousExcessInterpBufferSize(0), m_pDataList(0), m_pInstantaneousList(0), m_pRAByToTsInList(0), m_pRAByToTsAdjustedList(0), m_bFirstWrite(TRUE), m_bHooksInitialized(FALSE), m_bInited(FALSE), m_bSetupDone(FALSE), m_bAudioFormatKnown(FALSE), m_ulMaxBlockSize(0), m_pResampleBuf(0), m_pTmpResBuf(0), m_pCrossFader(0), m_pCrossFadeBuffer(0), m_pExcessInterpBuffer(NULL), m_pTempInterpBuffer(NULL), m_fVolume((float)1.0), m_bChannelConvert(FALSE), m_pStreamVolume(0), m_uVolume(HX_MAX_VOLUME), m_bMute(FALSE), m_bGotHooks(FALSE), m_llLastWriteTime(0), m_ulFudge(5), m_pInDataPtr(0), m_pOutDataPtr(0), m_pVolumeAdviseSink(0), m_bTobeTimed(TRUE), m_bIsFirstPacket(TRUE), m_bIsLive(FALSE), m_ulBaseTime(0), m_ulLiveDelay(0), m_bSetupToBeDone(FALSE), m_bCrossFadingToBeDone(FALSE), m_pCrossFadeStream(NULL), m_llCrossFadeStartTime(0), m_ulCrossFadeDuration(0), m_bFadeToThisStream(FALSE), m_bFadeAlreadyDone(FALSE), m_bRealAudioStream(FALSE), m_ulLastInputStartTime(0), m_ulLastInputEndTime(0), m_llLastStartTimePlayed(0), m_ulTSRollOver(0), m_bLastWriteTimeUpdated(FALSE), m_pCommonClassFactory(NULL), m_pAvailableBuffers(NULL), m_uCacheSize(CACHE_INCREMENT_SIZE), m_bCacheMayBeGrown(FALSE), m_bDeterminedInitialCacheSize(FALSE), m_bLastNMilliSecsToBeSaved(FALSE), m_ulLastNMilliSeconds(MINIMUM_INITIAL_PUSHDOWN), m_pLastNMilliSecsList(NULL), m_ulLastNHeadTime(0), m_ulLastNTailTime(0), m_eState(E_STOPPED), m_bCanBeRewound(FALSE), m_bAudioDeviceReflushHint(FALSE), m_bIsResumed(FALSE), m_bPlayerPause(FALSE), m_pPreferences(NULL), m_bMayNeedToRollbackTimestamp(FALSE){/* * Left around for future debugging static int fnum = 0; char fname[80]; sprintf(fname, "c:\\temp\\before.%d", fnum); fdbefore = fopen(fname, "ab+"); sprintf(fname, "c:\\temp\\before.%d.txt", fnum); fdbeforetxt = fopen(fname, "w+"); sprintf(fname, "c:\\temp\\after.%d", fnum); fdafter = fopen(fname, "ab+"); sprintf(fname, "c:\\temp\\after.%d.txt", fnum); fdaftertxt = fopen(fname, "w+"); sprintf(fname, "c:\\temp\\in.%d", fnum); fdin = fopen(fname, "ab+"); fnum++;*/ m_Owner = owner; if (m_Owner) { m_Owner->AddRef(); } if (pContext) { HX_VERIFY(HXR_OK == pContext->QueryInterface(IID_IHXCommonClassFactory, (void**) &m_pCommonClassFactory)); }#if defined(HELIX_FEATURE_PREFERENCES) if (pContext) { HX_VERIFY(HXR_OK == pContext->QueryInterface(IID_IHXPreferences, (void**) &m_pPreferences)); }#endif /* HELIX_FEATURE_PREFERENCES */ m_pInDataPtr = new HXAudioData; m_pOutDataPtr = new HXAudioData;};/************************************************************************ * Method: * IHXAudioStream::~CHXAudioStream() * Purpose: * Destructor. Clean up and set free. */CHXAudioStream::~CHXAudioStream(){ ResetStream();/* * Left around for future debugging if (fdbefore) { fclose(fdbefore); } if (fdbeforetxt) { fclose(fdbeforetxt); } if (fdafter) { fclose(fdafter); } if (fdaftertxt) { fclose(fdaftertxt); } if (fdin) { fclose(fdin); }*/}/////////////////////////////////////////////////////////////////////////// Method:// IUnknown::QueryInterface// Purpose:// Implement this to export the interfaces supported by your// object.//STDMETHODIMP CHXAudioStream::QueryInterface(REFIID riid, void** ppvObj){ QInterfaceList qiList[] = { { GET_IIDHANDLE(IID_IHXAudioStream), (IHXAudioStream*) this }, { GET_IIDHANDLE(IID_IHXRealAudioSync), (IHXRealAudioSync*) this }, { GET_IIDHANDLE(IID_IHXAudioStream2), (IHXAudioStream2*) this }, { GET_IIDHANDLE(IID_IHXCommonClassFactory), (IHXCommonClassFactory*) this }, { GET_IIDHANDLE(IID_IHXUpdateProperties), (IHXUpdateProperties*) 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) CHXAudioStream::AddRef(){ return InterlockedIncrement(&m_lRefCount);}/////////////////////////////////////////////////////////////////////////// Method:// IUnknown::Release// Purpose:// Everyone usually implements this the same... feel free to use// this implementation.//STDMETHODIMP_(ULONG32) CHXAudioStream::Release(){ if (InterlockedDecrement(&m_lRefCount) > 0) { return m_lRefCount; } delete this; return 0;}/* * IHXAudioStream methods *//************************************************************************ * Method: * IHXAudioStream::Init * Purpose: * Init the audio stream. */STDMETHODIMP CHXAudioStream::Init( const HXAudioFormat* pAudioFormat, IHXValues* pValues){ if (m_bAudioFormatKnown) { return HXR_OK; } HX_RESULT theErr = HXR_OK; m_pValues = pValues; if (m_pValues) { m_pValues->AddRef(); UINT32 ulVal = 0; m_pValues->GetPropertyULONG32("audioDeviceReflushHint", ulVal); if (ulVal == 1) { SetAudioDeviceReflushHint(TRUE); m_Owner->m_Owner->CheckIfLastNMilliSecsToBeStored(); } } memcpy( &m_AudioFmt, pAudioFormat, sizeof(HXAudioFormat) ); /* Flawfinder: ignore */ // Create the audio data list m_pDataList = new CHXSimpleList; if ( !m_pDataList ) theErr = HXR_OUTOFMEMORY; if(!theErr) // check if list constructor really succeeded { if(!m_pDataList->IsPtrListValid()) theErr = HXR_OUTOFMEMORY; } m_pInstantaneousList = new CHXSimpleList; if ( !m_pInstantaneousList || !m_pInstantaneousList->IsPtrListValid()) theErr = HXR_OUTOFMEMORY; // Reset this so that we init the hooks m_bFirstWrite = TRUE; m_bHooksInitialized = FALSE;#if defined(HELIX_FEATURE_VOLUME) // Create a volume object. if ( !theErr ) { m_pVolumeAdviseSink = new HXStreamVolumeAdviseSink; if (!m_pVolumeAdviseSink) { theErr = HXR_OUTOFMEMORY; } else { m_pVolumeAdviseSink->AddRef(); m_pVolumeAdviseSink->m_pCHXAudioStream = this; } m_pStreamVolume = (IHXVolume*) new CHXVolume; if ( !m_pStreamVolume ) theErr = HXR_OUTOFMEMORY; else { m_pStreamVolume->AddRef(); m_pStreamVolume->AddAdviseSink(m_pVolumeAdviseSink); m_pStreamVolume->SetVolume(HX_MAX_VOLUME); } }#endif /* HELIX_FEATURE_VOLUME */#ifdef _TESTING g_log = open("c:\\log\\stream.raw", O_WRONLY | O_CREAT | O_BINARY | _O_SEQUENTIAL);#endif m_bAudioFormatKnown = TRUE; if (m_bSetupToBeDone) { m_bSetupToBeDone = FALSE;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -