hxsm2.cpp

来自「symbian 下的helix player源代码」· C++ 代码 · 共 1,302 行 · 第 1/3 页

CPP
1,302
字号

	delete [] pCurrentSubInfo;
    }
}

inline
CHXSimpleList* ASMSourceInfo2::SubsChanges()
{
    return &m_subsChanges;
}

void ASMSourceInfo2::SubscribeToChanges()
{
    if (!m_subsChanges.IsEmpty() && m_pStreams && m_pStreams[0])
    {
	m_pStreams[0]->SubscribeToChanges(&m_subsChanges);

	while(!m_subsChanges.IsEmpty())
	{
	    RTSPSubscription* pSub = (RTSPSubscription*)m_subsChanges.RemoveHead();
	    delete pSub;
	}
    }
}

void ASMSourceInfo2::SetDeliveryBw(UINT32 ulMaxBw)
{
    if (m_pStreams)
    {
	UINT32 ulTotalBw = 0;
	
	// Calculate the total BW used by the streams
	for (UINT32 i = 0; i < m_ulStreamCount; i++)
	{
	    ulTotalBw += m_pStreams[i]->CurrentBw();
	}

	m_ulSubscribedBw = ulTotalBw;

	if (ulTotalBw)
	{
	    IHXThinnableSource* pThin = 0;
	    
	    if (HXR_OK == m_pSource->QueryInterface(IID_IHXThinnableSource, 
						    (void **)&pThin))
	    {
		/* Clamp bandwidth request */
		if (ulTotalBw > ulMaxBw)
		{
		    ulTotalBw = ulMaxBw;
		}
		
		pThin->SetDeliveryBandwidth(ulTotalBw, 0);
		
		HX_RELEASE(pThin);
	    }
	}
    }
}

inline
void ASMSourceInfo2::Done()
{
    HX_RELEASE(m_pSource);
}

HX_RESULT ASMSourceInfo2::GetSubInfo(UINT32 ulBandwidth,
				     BOOL* pCurrentSubInfo)
{
    HX_RESULT res = HXR_FAILED;

    if (m_pMasterRuleBook)
    {
	res = HXSMUpdateSubscriptionVars(m_pSubsVars, ulBandwidth, FALSE, 0);

	if (HXR_OK == res)
	{
	    res = m_pMasterRuleBook->GetSubscription(pCurrentSubInfo, 
						     m_pSubsVars);
	}
    }

    return res;
}

UINT32 ASMSourceInfo2::GetStreamBw(IHXValues* pProps, 
				   UINT32 ulStreamIndex) const
{
    UINT32 ulRet = 0;

    UINT8       pTemp[128];
    IHXBuffer* pBw = NULL;
    HX_RESULT   hxResult;
    
    // Don't assume that streamid == index in m_pStreams[j]
    sprintf((char *)pTemp, 
	    "Stream%ldBandwidth", 
	    m_pStreams[ulStreamIndex]->StreamID()); /* Flawfinder: ignore */
		    
    /*
     * if this tripps either there's a bug in here or
     * the content is messed up
     *
     */
    //If the Stream?Bandwidth property isn't found for
    //all streams don't worry about it. Not all streams
    //may have rule books.
    hxResult = pProps->GetPropertyCString((char *)pTemp, pBw);
    if(HXR_OK == hxResult && pBw)
    {
	ulRet = atoi((char*)pBw->GetBuffer());
	
	HX_RELEASE(pBw);
    }

    return ulRet;
}

ASMStreamInfo2::ASMStreamInfo2(IUnknown* pStream) :
    m_bFixedBwValid(FALSE),
    m_ulFixedBandwidth(0),
    m_ulNumThresholds(0),
    m_pThresholds(0),
    m_ulCurThresh(0),
    m_ulMaxEffectiveThreshold(0),
    m_pBias(0),
    m_pNegotiator(0),
    m_pRuleGather(0),
    m_ulStreamID(0),
    m_ulStreamOffer(0),
    m_ulOffer(0),
    m_ulResistanceToLower(0xffffffff)
{
    if (pStream)
    {
	if (HXR_OK == pStream->QueryInterface
	    (IID_IHXStreamBandwidthNegotiator,
	     (void **)&m_pNegotiator))
	{
	    m_pNegotiator->GetFixedBandwidth(m_ulFixedBandwidth);

	    if (m_ulFixedBandwidth)
	    {
		/* We need to check to see if the fixed bandwidth value
		 * matches the ASMProps Bandwidth value. If it doesn't then
		 * that means that we are dealing with a clip that doesn't
		 * advertise any bandwidth information. This is a corner
		 * case discover by streaming some unhinted .3gp files.
		 */
		IHXASMProps* pASMProps = NULL;
		UINT32 ulASMBw = 0;

		if ((HXR_OK == pStream->QueryInterface(IID_IHXASMProps,
						       (void**)&pASMProps))&&
		    (HXR_OK == pASMProps->GetBandwidth(ulASMBw)) &&
		    (m_ulFixedBandwidth == ulASMBw))
		{
		    m_bFixedBwValid = TRUE;
		}

		HX_RELEASE(pASMProps);
	    }
	    else
	    {
		m_ulNumThresholds = m_pNegotiator->GetNumThresholds();
		m_pThresholds = new float[m_ulNumThresholds];

		if (m_pThresholds)
		{
		    m_pNegotiator->GetThresholdInfo(m_pThresholds, 
						m_ulNumThresholds);

		    m_ulMaxEffectiveThreshold = m_ulNumThresholds - 1;
		}
	    }
	}
	
	pStream->QueryInterface(IID_IHXStreamBandwidthBias,
				(void **)&m_pBias);
	
	pStream->QueryInterface(IID_IHXAtomicRuleGather,
				(void **)&m_pRuleGather);

	// Get StreamID
	IHXStream* pHXStream = 0;

	pStream->QueryInterface(IID_IHXStream, (void**)&pHXStream);
	if (pHXStream)
        {
            m_ulStreamID = pHXStream->GetStreamNumber();
            pHXStream->Release();
        }
    }
}

ASMStreamInfo2::~ASMStreamInfo2()
{
    delete [] m_pThresholds;
    m_pThresholds = 0;

    HX_RELEASE(m_pBias);
    HX_RELEASE(m_pNegotiator);
    HX_RELEASE(m_pRuleGather);
}

HX_RESULT ASMStreamInfo2::GetBiasFactor(REF(INT32) lBiasFactor)
{
    HX_RESULT res = HXR_FAILED;
    
    if (m_pBias)
    {
	res = m_pBias->GetBiasFactor(lBiasFactor);
    }

    return res;
}

inline
BOOL ASMStreamInfo2::IsFixedBw() const
{
    return (m_ulFixedBandwidth != 0);
}

UINT32 ASMStreamInfo2::CurrentBw() const
{
    UINT32 ulRet = (m_bFixedBwValid) ? m_ulFixedBandwidth : 0;

    if (!ulRet && m_pThresholds)
    {
	ulRet = (UINT32)m_pThresholds[m_ulCurThresh];
    }

    return ulRet;
}

inline
UINT32 ASMStreamInfo2::StreamID() const
{
    return m_ulStreamID;
}

inline
void ASMStreamInfo2::SetStreamOffer(UINT32 ulOffer)
{
    m_ulStreamOffer = ulOffer;
}

void ASMStreamInfo2::SelectBw(BOOL bPerfectPlay,
			      UINT32 ulAltOffer)
{
    if (m_pThresholds)
    {
	if (bPerfectPlay)
	{
	    /*
	     * If we are in perfect play mode, just select the highest bandwidth rule
	     * and don't negotiate any further.
	     */
	    m_ulCurThresh = m_ulMaxEffectiveThreshold;
	    m_ulOffer = CurrentBw();
	}
	else
	{ 
	    UINT32 ulOffer = ulAltOffer;

	    if (m_ulStreamOffer)
	    {
		ulOffer = m_ulStreamOffer - 1;
	    }
	    
	    if (m_ulMaxEffectiveThreshold != 0)
	    {
		for (UINT32 i = 1; i <= m_ulMaxEffectiveThreshold; i++)
		{
		    if ((ulOffer <= m_pThresholds[i]) ||
			(i == m_ulMaxEffectiveThreshold))
		    {
			m_ulOffer = ulOffer;
			m_ulCurThresh = i;
			break;
		    }
		}
	    }
	}

	ComputeResistence(bPerfectPlay);
    }
}

inline
UINT32 ASMStreamInfo2::ResistanceToLower() const
{
    return m_ulResistanceToLower;
}

void ASMStreamInfo2::SelectNextLowerBw()
{
    if (m_ulCurThresh > 0)
    {
	m_ulCurThresh--;

	ComputeResistence(FALSE);
    }
}

inline
UINT32 ASMStreamInfo2::GetLastBw() const
{
    return m_ulLastBw;
}

void ASMStreamInfo2::SubscribeToNewBw(UINT32 ulBw, CHXSimpleList* pSubChanges)
{
    BOOL bTimeStampDelivery = FALSE;
    
    if (m_pRuleGather && m_pNegotiator)
    {
	m_pRuleGather->RuleGather(pSubChanges);
	
	//update the HXASMStream with our new bandwidth
	m_pNegotiator->SetBandwidthUsage(ulBw, bTimeStampDelivery);
	
	m_pRuleGather->RuleGather(0);
    }

    m_ulLastBw = ulBw;
}

void ASMStreamInfo2::SubscribeToChanges(CHXSimpleList* pSubChanges)
{
    if (m_pRuleGather)
    {
	m_pRuleGather->RuleFlush(pSubChanges);
    }
}

void ASMStreamInfo2::ComputeResistence(BOOL bPerfectPlay)
{
    /* NOTE:
     * m_ulCurThresh and m_ulOffer must
     * be valid when this function is called
     */

    if (IsFixedBw() || 
	bPerfectPlay ||
	(m_ulMaxEffectiveThreshold == 0) ||
	(m_ulCurThresh == 1))
    {
	m_ulResistanceToLower = 0xffffffff;
    }
    else
    {
	m_ulResistanceToLower = 
	    (m_ulOffer - (UINT32)m_pThresholds[m_ulCurThresh - 1]) * m_ulOffer;
    }
}

HXSM2::HXSM2() :
    m_lRefCount(0),
    m_ulNumSources(0),
    m_pASMSourceInfo(0),
    m_ulNumStreams(0),
    m_ulOfferToRecalc(0),
    m_ulSelectionBitRate(0),
    m_ulMaxAccelBitRate(0),
    m_ulSustainableBitRate(0),
    m_pSubscriptionVariables(0),
    m_bCheckOnDemandBw(FALSE)
{
    m_pASMSourceInfo = new CHXSimpleList();
}

HXSM2::~HXSM2()
{
    if (m_pASMSourceInfo)
    {
	while(!m_pASMSourceInfo->IsEmpty())
	{
	    ASMSourceInfo2* pSrc = 
		(ASMSourceInfo2*)m_pASMSourceInfo->RemoveHead();

	    delete pSrc;
	}

	delete m_pASMSourceInfo;
    }
}

STDMETHODIMP HXSM2::QueryInterface(THIS_ REFIID ID, void** ppInterfaceObj)
{
	QInterfaceList qiList[] =
	{
		{ GET_IIDHANDLE(IID_IUnknown), this },
		{ GET_IIDHANDLE(IID_IHXBandwidthManager), (IHXBandwidthManager*) this },
	};	
    return QIFind(qiList, QILISTSIZE(qiList), ID, ppInterfaceObj);
}

STDMETHODIMP_(UINT32) HXSM2::AddRef(THIS)
{
    return InterlockedIncrement(&m_lRefCount);
}

STDMETHODIMP_(UINT32) HXSM2::Release(THIS)
{
    if (InterlockedDecrement(&m_lRefCount) > 0)
    {
	return m_lRefCount;
    }

    delete this;
    return 0;
}

/*
 *	IHXBandwidthManager methods
 */
STDMETHODIMP HXSM2::RegisterSource(THIS_
				   HXSource* pSource,
				   IUnknown* pUnknown)
{
    HX_RESULT res = HXR_OK;

    IHXSourceBandwidthInfo* pSBI;
    IHXPreferences* pPreferences = NULL;
    IHXBuffer* pBuffer = 0;
    ASMSourceInfo2* pASMSourceInfo = NULL;

    if (HXR_OK == pSource->QueryInterface(IID_IHXSourceBandwidthInfo, 
            (void **)&pSBI))
    {
        pASMSourceInfo = new ASMSourceInfo2(pSource);

        m_ulNumSources++;

⌨️ 快捷键说明

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