📄 hxsrc.cpp
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: hxsrc.cpp,v 1.35.2.1 2004/07/09 02:05:58 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 "hxtypes.h"#include "hxcom.h"#ifdef _WINDOWS#include <windows.h>#endif#include "hlxclib/stdio.h"#include "hlxclib/stdlib.h"#include "prefdefs.h"#include "plprefk.h"#include "hxcomm.h"#include "ihxpckts.h"#include "hxfiles.h"#include "hxengin.h"#include "hxcore.h"#include "hxprefs.h"#include "hxpref.h"#include "hxausvc.h"#include "hxmon.h"#include "hxclreg.h"#include "hxgroup.h"#include "hxsmbw.h"#include "hxstrm.h"#include "hxwin.h"#include "hxcore.h"#include "hxhyper.h"#include "playhpnv.h"#include "hxplugn.h"#include "hxrendr.h"#include "chxeven.h"#include "chxelst.h"#include "hxmap.h"#include "hxrquest.h"#include "hxmangle.h"#include "hxtick.h"#include "dbcs.h"#include "hxstrutl.h"#include "strminfo.h"#include "timeval.h"#include "statsmgr.h"#include "hxbsrc.h"#include "hxsrc.h"#include "srcinfo.h"#include "corshare.h"#include "upgrdcol.h"#include "hxrasyn.h"#include "hxaudstr.h"#include "hxplugn.h"#include "hxrendr.h"#include "errdbg.h"// will be taken out once flags are defined in a separate file#include "rmfftype.h" #include "hxplay.h"#include "hxcleng.h"#include "hxsrc.h"#include "hxheap.h"#ifdef _DEBUG#undef HX_THIS_FILE static const char HX_THIS_FILE[] = __FILE__;#endif#if defined(HELIX_CONFIG_MIN_PCM_PUSHDOWN_BYTES)// TurboPlay should never be turned on in low heap mode, but just in case ...#define TURBO_AUDIO_PUSHDOWN 100#else#define TURBO_AUDIO_PUSHDOWN 2000#endifHXSource::HXSource() : m_pPlayer (0) , m_lRefCount(0) , m_ulStreamIndex(0) , m_bInitialized (FALSE) , m_bIsPreBufferingDone(FALSE) , m_bClipTimeAdjusted(FALSE) , mLastError (HXR_OK) , m_ulPerfectPlayTime (0) , m_ulBufferedPlayTime(0) , m_ulStreamHeadersExpected(0) , m_bPerfectPlayEntireClip(FALSE) , m_bCannotBufferEntireClip(FALSE) , m_uNumStreams (0) , mFlags (0) , m_bPerfectPlayAllowed (FALSE) , mSaveAsAllowed (FALSE) , mLiveStream (FALSE) , m_bRestrictedLiveStream (FALSE) , m_bSourceEnd (FALSE) , m_bForcedSourceEnd(FALSE) , m_ulPreRollInMs (0) , m_ulPreRoll (0) , m_ulAvgBandwidth (0) , m_ulDuration (0) , m_bReceivedData (FALSE) , m_bReceivedHeader(FALSE) , m_bNonSeekable(FALSE) , m_nSeeking (0) , m_bPaused (FALSE) , m_bFirstResume(TRUE) , m_bResumePending(FALSE) , m_bIsActive(FALSE) , m_uActiveStreams (0) , m_pszURL(NULL) , m_pURL(NULL) , m_bAltURL(TRUE) , m_ulStartTime (0) , m_ulEndTime (0) , m_ulDelay (0) , m_ulOriginalDelay (0) , m_ulPrefetchDelay (0) , m_llLastExpectedPacketTime(0) , m_ulRestrictedDuration(0) , m_bDelayed(FALSE) , m_ulSourceStartTime(0) , m_pPreferences (0) , m_pRegistry (0) , m_pScheduler (0)#if defined(HELIX_FEATURE_STATS) && defined(HELIX_FEATURE_REGISTRY) , m_pStats (0) , m_pStatsManager(NULL)#endif /* HELIX_FEATURE_STATS && HELIX_FEATURE_REGISTRY */ , m_bLocked (FALSE) , m_pEngine (0) , m_bRebufferingRequired(FALSE) , m_bInitialBuffering(TRUE) , m_bPartOfNextGroup(FALSE) , m_bPartOfPrefetchGroup(FALSE) , m_pBufferManager(NULL) , m_pFileHeader(0) , m_bPerfectPlay(FALSE) , m_bBufferedPlay(FALSE) , m_ulLossHack(0) , m_ulNumFakeLostPackets(0) , m_ulLastBufferingCalcTime(0) , m_pSourceInfo(NULL) , m_pRequest(NULL) , m_pASMSource(NULL) , m_pBackChannel(NULL) , m_bDefaultAltURL(FALSE) , m_bCustomEndTime(FALSE) , m_bCustomDuration(FALSE) , m_bIsPreBufferingStarted(FALSE) , m_ulOriginalDuration(0) , m_bReSetup(FALSE)#if defined(HELIX_FEATURE_AUTOUPGRADE) , m_pUpgradeCollection(NULL)#endif /* HELIX_FEATURE_AUTOUPGRADE */ , m_bRTSPRuleFlagWorkAround(FALSE) , m_bContinueWithHeaders(FALSE) , m_bPrefetch(FALSE) , m_prefetchType(PrefetchUnknown) , m_ulPrefetchValue(0) , m_ulFirstPacketTime(0) , m_bIsMeta(FALSE) , m_bFastStart(FALSE) , m_serverTurboPlay(TURBO_PLAY_UNKNOWN) , m_ulMaxBandwidth(4000) // 4000kbps , m_pAudioStreamList(NULL) , m_maxPossibleAccelRatio(4.0) // I donno what's a good value? , m_ulTurboPushDown(TURBO_AUDIO_PUSHDOWN) , m_bSureStreamClip(FALSE) , m_ulTurboStartActiveTime(0) , m_srcEndCode(END_UNKNOWN) , m_pRecordControl(NULL) , m_bPlayFromRecordControl(FALSE) , m_pRedirectURL(NULL) , m_bRedirectPending(FALSE){ mStreamInfoTable = new CHXMapLongToObj;}HXSource::~HXSource(){ // XXX moved this to the distuctor because we want to keep arround // the request until the renderers are close at which point we should // be released and deleted. HX_RELEASE(m_pRequest); HX_VECTOR_DELETE(m_pszURL); HX_DELETE(mStreamInfoTable);}voidHXSource::Stop(){ m_pSourceInfo = NULL; HX_DELETE (m_pURL); HX_DELETE (m_pBufferManager); if ( FAILED(mLastError) ) { HX_RELEASE(m_pRequest); }#if defined(HELIX_FEATURE_STATS) && defined(HELIX_FEATURE_REGISTRY) if (m_pStatsManager) { m_pStatsManager->DoCleanup(); HX_RELEASE(m_pStatsManager); } HX_DELETE(m_pStats); #endif /* HELIX_FEATURE_STATS && HELIX_FEATURE_REGISTRY */ DeleteAllEvents(); HX_RELEASE(m_pRegistry); HX_RELEASE(m_pPreferences); HX_RELEASE(m_pScheduler); HX_RELEASE(m_pEngine);} HX_RESULT HXSource::DoCleanup(EndCode endCode){ m_ulDuration = 0; m_ulPreRollInMs = 0; m_ulPreRoll = 0; m_ulAvgBandwidth = 0; m_ulLastBufferingCalcTime = 0; m_ulMaxBandwidth = 0; m_serverTurboPlay = TURBO_PLAY_UNKNOWN; m_bAltURL = FALSE; m_bPaused = FALSE; m_bFirstResume = TRUE; m_bIsActive = FALSE; m_bResumePending = FALSE; m_bIsPreBufferingStarted = FALSE; m_bIsPreBufferingDone = FALSE; m_bClipTimeAdjusted = FALSE; m_bInitialBuffering = TRUE; m_bRebufferingRequired = FALSE; m_bReceivedData = FALSE; m_bReceivedHeader = FALSE; ReleaseAudioStreams(m_pAudioStreamList); HX_DELETE(m_pAudioStreamList); DeleteStreamTable(); CHXSimpleList::Iterator lIter = m_HXStreamList.Begin(); for (; lIter != m_HXStreamList.End(); ++lIter) { HXStream* pStream = (HXStream*) (*lIter); pStream->Release(); } m_HXStreamList.RemoveAll(); HX_RELEASE(m_pFileHeader); HX_RELEASE(m_pASMSource); HX_RELEASE(m_pBackChannel);#if defined(HELIX_FEATURE_AUTOUPGRADE) HX_RELEASE(m_pUpgradeCollection);#endif /* HELIX_FEATURE_AUTOUPGRADE */ m_bForcedSourceEnd = FALSE; m_bSourceEnd = FALSE; HX_DELETE(m_pRedirectURL); m_bRedirectPending = FALSE;#if defined(HELIX_FEATURE_RECORDCONTROL) if(m_pRecordControl) { m_pRecordControl->Cleanup(); }#endif /* HELIX_FEATURE_RECORDCONTROL */ HX_RELEASE(m_pRecordControl); return HXR_OK;}/////////////////////////////////////////////////////////////////////////// Method:// IUnknown::QueryInterface// Purpose:// Implement this to export the interfaces supported by your // object.//STDMETHODIMP HXSource::QueryInterface(REFIID riid, void** ppvObj){ QInterfaceList qiList[] = { { GET_IIDHANDLE(IID_IHXStreamSource), (IHXStreamSource*)this }, { GET_IIDHANDLE(IID_IHXPendingStatus), (IHXPendingStatus*)this }, { GET_IIDHANDLE(IID_IHXInfoLogger), (IHXInfoLogger*)this }, { GET_IIDHANDLE(IID_IHXPrivateStreamSource), (IHXPrivateStreamSource*)this }, { GET_IIDHANDLE(IID_IHXSourceBufferingStats), (IHXSourceBufferingStats*)this }, { GET_IIDHANDLE(IID_IHXSourceBufferingStats2), (IHXSourceBufferingStats2*)this },#if defined(HELIX_FEATURE_HYPER_NAVIGATE) { GET_IIDHANDLE(IID_IHXHyperNavigate), (IHXHyperNavigate*)this }, { GET_IIDHANDLE(IID_IHXHyperNavigate2), (IHXHyperNavigate2*)this },#endif /* defined(HELIX_FEATURE_HYPER_NAVIGATE) */ { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXStreamSource*)this }, }; HX_RESULT res = ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj); // if successful, return immediately... if (SUCCEEDED(res)) { return res; } // ... otherwise proceed onward if (IsEqualIID(riid, IID_IHXBackChannel)) { if (m_pBackChannel) { AddRef(); *ppvObj = (IHXBackChannel*)this; return HXR_OK; } else { *ppvObj = NULL; return HXR_NOINTERFACE; } } else if (IsEqualIID(riid, IID_IHXASMSource)) { if (m_pASMSource) { AddRef(); *ppvObj = (IHXASMSource*)this; return HXR_OK; } else { *ppvObj = NULL; return HXR_NOINTERFACE; } }#if defined(HELIX_FEATURE_AUTOUPGRADE) else if (IsEqualIID(riid, IID_IHXUpgradeCollection)) { if (!m_pUpgradeCollection) { m_pUpgradeCollection = new HXUpgradeCollection; m_pUpgradeCollection->AddRef(); } return m_pUpgradeCollection->QueryInterface(riid, ppvObj); }#endif /* HELIX_FEATURE_AUTOUPGRADE */ else if (m_pRequest && m_pRequest->QueryInterface(riid, ppvObj) == HXR_OK) { return HXR_OK; } else if (m_pFileHeader && m_pFileHeader->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) HXSource::AddRef(){ return InterlockedIncrement(&m_lRefCount);}/////////////////////////////////////////////////////////////////////////// Method:// IUnknown::Release// Purpose:// Everyone usually implements this the same... feel free to use// this implementation.//STDMETHODIMP_(ULONG32) HXSource::Release(){ if (InterlockedDecrement(&m_lRefCount) > 0) { return m_lRefCount; } delete this; return 0;}// *** IHXStreamSource methods ***/************************************************************************ * Method: * IHXStreamSource::IsLive * Purpose: * Ask the source whether it is live * */STDMETHODIMP_ (BOOL) HXSource::IsLive(void){ return mLiveStream;}/************************************************************************ * Method: * IHXStreamSource::GetPlayer * Purpose: * Get the interface to the player object of which the source is * a part of. * */STDMETHODIMP HXSource::GetPlayer(IHXPlayer* &pPlayer){ pPlayer = m_pPlayer; if (pPlayer) { pPlayer->AddRef(); } return HXR_OK;}/************************************************************************ * Method: * IHXStreamSource::GetContext * Purpose: * Get the interface to the context object of which the source is * a part of. * */STDMETHODIMP HXSource::GetContext(IUnknown* &pContext){ pContext = ((IUnknown*)(IHXClientEngine*) m_pEngine); if (pContext) { pContext->AddRef(); } return HXR_OK;}/************************************************************************ * Method: * IHXStreamSource::GetURL * Purpose: * Get the URL for this source. NOTE: The returned string is * assumed to be valid for the life of the IHXStreamSource from which it * was returned. * */STDMETHODIMP_(const char*) HXSource::GetURL(void){ const char* pURL = NULL; /* * Make sure that the we have not been re-directed * to a new URL. */ if (m_pRequest && m_pRequest->GetURL(pURL) == HXR_OK && pURL) { if (!m_pszURL || ::strcasecmp(pURL, m_pszURL) != 0) { HX_VECTOR_DELETE(m_pszURL); m_pszURL = new char[strlen(pURL) + 1]; strcpy(m_pszURL, pURL); /* Flawfinder: ignore */ } } // append RAM mimeType as URL option to notify the // caller(i.e. ViewSource) if (m_bIsMeta)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -