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

📄 hxsm.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
     * from our available bandwidth.
     */
    for (j = m_pASMStreamInfo->Begin(); j != m_pASMStreamInfo->End(); ++j)
    {
        INT32 lBias;

	pASMStreamInfo = (ASMStreamInfo*)(*j);

	HX_VERIFY(HXR_OK == pASMStreamInfo->m_pBias->GetBiasFactor(lBias));
	fBiasMean += lBias;

	if (pASMStreamInfo->m_ulFixedBandwidth)
	{
	    lAggregateBandwidthUsage -= pASMStreamInfo->m_ulFixedBandwidth;
	    ulStreamCount--;
	}

	/* Init this for later */
	pASMStreamInfo->m_ulMasterRuleBookSetOffer = 0;
    }

    /* fBiasMean is not needed if everything has a fixed bandwidth */
    if (ulStreamCount != 0)
    {
	fBiasMean /= (float)ulStreamCount;
    }

    /*
     * Calculate the offer for each source that has a master rulebook
     * defining it's bandwidth division.
     */
    INT32 lNewAggregateBandwidthUsage = lAggregateBandwidthUsage;

    for (j = m_pASMStreamInfo->Begin(); j != m_pASMStreamInfo->End(); ++j)
    {
	INT32 lBias;

	pASMStreamInfo = (ASMStreamInfo*)(*j);

	HX_VERIFY(HXR_OK == pASMStreamInfo->m_pBias->GetBiasFactor(lBias));

	if (pASMStreamInfo->m_pASMSourceInfo->m_pMasterRuleBook)
	{
	    UINT32 ulOffer = 
		(UINT32)(lAggregateBandwidthUsage / (float)ulStreamCount);

	    ulOffer += 
		(UINT32)(((float)lBias - fBiasMean) *
		((float)lAggregateBandwidthUsage / 100.0) *
		(2.0 / (float)ulStreamCount));

	    pASMStreamInfo->m_pASMSourceInfo->m_ulMasterOffer += ulOffer;
	    lNewAggregateBandwidthUsage -= ulOffer;
	}
    }

    lAggregateBandwidthUsage = lNewAggregateBandwidthUsage;

    /*
     * For each source that has a master rule book, evaluate it to find
     * out how much to distribute to each stream.
     */
    for (i = m_pASMSourceInfo->Begin(); i != m_pASMSourceInfo->End(); ++i)
    {
	pASMSourceInfo = (ASMSourceInfo*)(*i);
	ASMRuleBook* pRuleBook = pASMSourceInfo->m_pMasterRuleBook;

	if (pRuleBook)
	{
	    UINT32 ulNumStreamsForThisSource = 
		pASMSourceInfo->m_pSource->GetStreamCount();

	    BOOL* pCurrentSubInfo = new BOOL[pRuleBook->GetNumRules()];

	    HXSMUpdateSubscriptionVars(m_pSubscriptionVariables, 
				       pASMSourceInfo->m_ulMasterOffer,
				       FALSE, 0);

	    HX_RESULT lResult =
		pRuleBook->GetSubscription(pCurrentSubInfo, m_pSubscriptionVariables);
	    HX_ASSERT(lResult == HXR_OK);

	    for (UINT16 idxRule = 0; idxRule < pRuleBook->GetNumRules();
		idxRule++)
	    {
		if (pCurrentSubInfo[idxRule])
		{
		    IHXValues* pProps = 0;
		    // Set Distribution
		    pRuleBook->GetProperties(idxRule, pProps);

		    for (UINT32 j = 0; j < ulNumStreamsForThisSource; j++)
		    {
			UINT8       pTemp[128];
			IHXBuffer* pBw = NULL;
			HX_RESULT   hxResult;
			
			// Don't assume that streamid == index in pASMSourceInfo->m_pStreams[j]
                        SafeSprintf((char *)pTemp, 128, "Stream%ldBandwidth", pASMSourceInfo->m_pStreams[j]->m_ulStreamNumber); /* 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)
			{
			    pASMSourceInfo->m_pStreams[j]->
				m_ulMasterRuleBookSetOffer =
				atoi((char*)pBw->GetBuffer());

			    pBw->Release();
			    pBw = NULL;
			}
			else
			{
			    pASMSourceInfo
				->m_pStreams[j]
				->m_ulMasterRuleBookSetOffer = 0;
			}//HXR_OK==hxResult && pBw
		    }

		    HX_RELEASE(pProps);
		    break;
		}
	    }

	    delete [] pCurrentSubInfo;
	}
    }

    /*
     *  Now go through each of the streams that are not at a
     *  fixed bitrate and try to distribute the rest of the bandwidth.
     */
    UINT32 ulTakenBandwidth = 0;

    for (j = m_pASMStreamInfo->Begin(); j != m_pASMStreamInfo->End(); ++j)
    {
	INT32 lBias;

	pASMStreamInfo = (ASMStreamInfo*)(*j);

	if (pASMStreamInfo->m_ulFixedBandwidth != 0)
	{
	    ulTakenBandwidth += pASMStreamInfo->m_ulFixedBandwidth;
	    pASMStreamInfo->m_ulResistanceToLower = 0xffffffff;
	    continue;
	}

	HX_VERIFY(HXR_OK == pASMStreamInfo->m_pBias->GetBiasFactor(lBias));

	HX_ASSERT(pASMStreamInfo->m_pThreshold != NULL);

	UINT32 ulOffer = 0;

	if (pASMStreamInfo->m_pASMSourceInfo->m_bPerfectPlay)
	{
	    UINT32 i = pASMStreamInfo->m_ulMaxEffectiveThreshold;
	    ulTakenBandwidth += (UINT32)pASMStreamInfo->m_pThreshold[i];
	    pASMStreamInfo->m_ulResistanceToLower = 0xffffffff;
	    pASMStreamInfo->m_ulOffer = (UINT32)pASMStreamInfo->m_pThreshold[i];
	    pASMStreamInfo->m_ulThresholdPosition = i;

	    /*
	     * If we are in perfect play mode, just select the highest bandwidth rule
	     * and don't negotiate any further.
	     */
	    continue;
	}

	if (pASMStreamInfo->m_ulMasterRuleBookSetOffer)
	{
	    ulOffer = pASMStreamInfo->m_ulMasterRuleBookSetOffer - 1;
	}
	else
	{
	    ulOffer =
		(UINT32)(lAggregateBandwidthUsage / (float)ulStreamCount);

	    ulOffer += 
		(UINT32)(((float)lBias - fBiasMean) *
		((float)lAggregateBandwidthUsage / 100.0) *
		(2.0 / (float)ulStreamCount));
	}

	HX_ASSERT(pASMStreamInfo->m_ulMaxEffectiveThreshold >= 0);
	if (pASMStreamInfo->m_ulMaxEffectiveThreshold == 0)
	{
	    HX_ASSERT(pASMStreamInfo->m_pThreshold[0] == 0);

	    ulTakenBandwidth += (UINT32)pASMStreamInfo->m_pThreshold[0];
	    pASMStreamInfo->m_ulResistanceToLower = 0xffffffff;
	}
	else
	{
	    for (UINT32 i = 1; i <= pASMStreamInfo->m_ulMaxEffectiveThreshold; i++)
	    {
		if ((ulOffer <= pASMStreamInfo->m_pThreshold[i]) ||
			(i == (pASMStreamInfo->m_ulMaxEffectiveThreshold)))
		{
		    ulTakenBandwidth += (UINT32)pASMStreamInfo->m_pThreshold[i];

		    if (i == 1)
		    {
			pASMStreamInfo->m_ulResistanceToLower = 0xffffffff;
		    }
		    else
		    {
			pASMStreamInfo->m_ulResistanceToLower = (ulOffer -
			    (UINT32)pASMStreamInfo->m_pThreshold[i - 1]) * ulOffer;
		    }

		    pASMStreamInfo->
			m_ulOffer = ulOffer;
		    pASMStreamInfo->m_ulThresholdPosition = i;

		    break;
		}
	    }
	}
    }

    lAggregateBandwidthUsage = lCorrectAggregateBandwidthUsage;

tryagain:

    if (lAggregateBandwidthUsage < (INT32)ulTakenBandwidth)
    {
	/* Resistance is Futile.  You will be Real(tm)lyAssimilated */
	UINT32 ulLowestResistance = 0xffffffff;
	ASMStreamInfo* pLowestResistanceStream  = 0;

	for (j = m_pASMStreamInfo->Begin(); j != m_pASMStreamInfo->End(); ++j)
	{
	    pASMStreamInfo = (ASMStreamInfo*)(*j);

	    if (pASMStreamInfo->m_ulResistanceToLower < ulLowestResistance)
	    {
		ulLowestResistance = pASMStreamInfo->m_ulResistanceToLower;
		pLowestResistanceStream = pASMStreamInfo;
	    }
	}

	if (ulLowestResistance == 0xffffffff)
	{
	}
	else
	{
	    ulTakenBandwidth -= (UINT32)
		pLowestResistanceStream->m_pThreshold[pLowestResistanceStream->m_ulThresholdPosition];

	    pLowestResistanceStream->m_ulThresholdPosition--;

	    ulTakenBandwidth += (UINT32)
		pLowestResistanceStream->m_pThreshold[pLowestResistanceStream->m_ulThresholdPosition];

	    if (pLowestResistanceStream->m_ulThresholdPosition == 1)
	    {
		pLowestResistanceStream->m_ulResistanceToLower = 0xffffffff;
	    }
	    else
	    {
		pLowestResistanceStream->m_ulResistanceToLower = (pLowestResistanceStream->m_ulOffer -
		    (UINT32)pLowestResistanceStream->m_pThreshold[
		    pLowestResistanceStream->m_ulThresholdPosition - 1]) *
		    pLowestResistanceStream->m_ulOffer;
	    }

	    goto tryagain;
	}
    }

    UINT32 ulLeftOverForDropByN = lAggregateBandwidthUsage - ulTakenBandwidth;
    BOOL bForce = FALSE;

    for (j = m_pASMStreamInfo->Begin(); j != m_pASMStreamInfo->End(); ++j)
    {
	pASMStreamInfo = (ASMStreamInfo*)(*j);

	UINT32 ulBw = 1;

	if (pASMStreamInfo->m_ulFixedBandwidth)
	{
	    ulBw = pASMStreamInfo->m_ulFixedBandwidth;
	}
	else
	{
	    ulBw = (UINT32)
		    pASMStreamInfo->m_pThreshold[pASMStreamInfo->m_ulThresholdPosition];
	}

	UINT32 ulBwOffered = ulBw;

	if (ulBw == 1)
	{
	    // Hack Alert for DropByN. XXXSMP
	    ulBwOffered = ulBw = ulLeftOverForDropByN;
	}

	if ((ulBw != pASMStreamInfo->m_ulLastBandwidth) &&
	    (!pASMStreamInfo->m_ulFixedBandwidth))
	{
	    bForce = TRUE;
	}
	pASMStreamInfo->m_pRuleGather->
	    RuleGather(&pASMStreamInfo->m_pASMSourceInfo->
	    m_SubscriptionChanges);

	pASMStreamInfo->SetLastBandwidth(ulBw);
	HX_ASSERT(ulBw == ulBwOffered);

	//update the HXASMStream with our new bandwidth
	pASMStreamInfo->NotifyNewBandwidth();

	//update the source's knowledge of tsd
	pASMStreamInfo->NotifyTimeStampDelivery();

	//if the stream is behind, tell the server to chill
	pASMStreamInfo->NotifyLimitBandwidth(ulBwOffered);

	pASMStreamInfo->m_pRuleGather->RuleGather(0);
    }

    for (i = m_pASMSourceInfo->Begin(); i != m_pASMSourceInfo->End(); ++i)
    {
	pASMSourceInfo = (ASMSourceInfo*)(*i);

	if (!pASMSourceInfo->m_SubscriptionChanges.IsEmpty())
	{
	    pASMSourceInfo->m_pStreams[0]->m_pRuleGather->
		RuleFlush(&pASMSourceInfo->m_SubscriptionChanges);

	    for (j = pASMSourceInfo->m_SubscriptionChanges.Begin();
		 j != pASMSourceInfo->m_SubscriptionChanges.End(); ++j)
	    {
		RTSPSubscription* pSub = (RTSPSubscription*)(*j);
		delete pSub;
	    }
	    pASMSourceInfo->m_SubscriptionChanges.RemoveAll();
	}
    }

    if (m_State == REDO_ACCEL)
    {
	RecalcAccel();
	return;
    }
    if (m_State == CONGESTION)
    {
	RecalcAccel();
	return;
    }
    if (m_State == INIT)
    {
	m_State = INIT_REDIST;
	RecalcAccel();
	return;
    }
    if (bForce)
    {
	m_State = REDO_ACCEL;
	RecalcAccel();
	return;
    }
}

void
HXSM::RecalcAccel()
{
    CHXSimpleList::Iterator     i, j;
    ASMSourceInfo*                 pASMSourceInfo;
    ASMStreamInfo*                 pASMStreamInfo;
    UINT32 ulAggregateUsed = 0;
    UINT32 ulTotalMaxSubscribedBw = 0;

    if (m_State == INIT)
    {
	m_ulOfferToRecalc = m_ulHighestBandwidthAvail;

	if (m_ulOfferToRecalc > m_ulMaxAccelBitRate)
	{
	    m_ulOfferToRecalc = m_ulMaxAccelBitRate;
	}
#ifdef MOREDEBUG
	DEBUG_OUT(m_pEM, DOL_TRANSPORT, (s,
			"INIT Offer to Recalc() %d", m_ulOfferToRecalc));
#endif

	Recalc();
	return;
    }

    for (i = m_pASMSourceInfo->Begin(); i != m_pASMSourceInfo->End(); ++i)
    {
	pASMSourceInfo = (ASMSourceInfo*)(*i);

	pASMSourceInfo->m_ulSubscribedBw = 0;
	pASMSourceInfo->m_ulMaxSubscribedBw = 0;
    }

    for (j = m_pASMStreamInfo->Begin(); j != m_pASMStreamInfo->End(); ++j)
    {
	pASMStreamInfo = (ASMStreamInfo*)(*j);

	if (pASMStreamInfo->m_ulFixedBandwidth)
	{
	    pASMStreamInfo->m_pASMSourceInfo->m_ulSubscribedBw += 
		pASMStreamInfo->m_ulFixedBandwidth;
	    pASMStreamInfo->m_pASMSourceInfo->m_ulMaxSubscribedBw += 
		pASMStreamInfo->m_ulFixedBandwidth;
	    ulTotalMaxSubscribedBw += pASMStreamInfo->m_ulFixedBandwidth;
	    ulAggregateUsed += pASMStreamInfo->m_ulFixedBandwidth;
	}
	else
	{
	    pASMStreamInfo->m_pASMSourceInfo->m_ulSubscribedBw += (UINT32)
		pASMStreamInfo->m_pThreshold[
		    pASMStreamInfo->m_ulThresholdPosition];
	    HX_ASSERT(pASMStreamInfo->m_pASMSourceInfo->m_ulSubscribedBw < 0x7fffffff);

	    pASMStreamInfo->m_pASMSourceInfo->m_ulMaxSubscribedBw += (UINT32)
		pASMStreamInfo->m_pThreshold[
		    pASMStreamInfo->m_ulMaxEffectiveThreshold];

	    ulTotalMaxSubscribedBw += (UINT32)pASMStreamInfo->m_pThreshold[
		    pASMStreamInfo->m_ulMaxEffectiveThreshold];

	    ulAggregateUsed += (UINT32)
		pASMStreamInfo->m_pThreshold[
		    pASMStreamInfo->m_ulThresholdPosition];
	}
    }

    UINT32 ulNumBehindSources		= 0;
    UINT32 ulNumSlightlyBehindSources	= 0;
    INT32  lAggregateBandwidthUsage	= 0;
    INT32  ulMaxNeededBW                = 0;
    BOOL   bAllZeroBw			= TRUE;
    BOOL   bFastStart                   = FALSE;

⌨️ 快捷键说明

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