拥塞控制算法举例.docx

上传人:b****8 文档编号:27655788 上传时间:2023-07-03 格式:DOCX 页数:26 大小:602.55KB
下载 相关 举报
拥塞控制算法举例.docx_第1页
第1页 / 共26页
拥塞控制算法举例.docx_第2页
第2页 / 共26页
拥塞控制算法举例.docx_第3页
第3页 / 共26页
拥塞控制算法举例.docx_第4页
第4页 / 共26页
拥塞控制算法举例.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

拥塞控制算法举例.docx

《拥塞控制算法举例.docx》由会员分享,可在线阅读,更多相关《拥塞控制算法举例.docx(26页珍藏版)》请在冰豆网上搜索。

拥塞控制算法举例.docx

拥塞控制算法举例

1.拥塞控制算法

NAATA(intsentByte,intRcvByte){

staticintinit=1;//initialstateflag

staticintinit_bit;//initialbit-rate(userrequestedbit-rate)

staticintmin_bit;//minimumbit-rate

staticintmax_bit;//maximumbit-rate

staticinttmp;//temporaltargetbit-rate

staticinttarget_tr_bit;//targetbit-rate

staticintcount;//timecount

staticintflag=0;//flagforcontinousproblem

staticintthreshold_time=10;//thresholdtimetorecovertargetbit-rate

intthreshold_fail=0;//thresholdtodetecttransmissionfailure

intdiff=sentByte-RcvByte;

if(diff>threshold_fail){//whentransmissionfailureoccurs

if(init){//whenfirsttransmissionfailureoccurs

target_tr_bit=init_bit/2;

min_bit=max_bit=target_tr_bit;

init=0;

}elseif(flag==1){//whencontinuoustransmissionfailureoccurs

target_tr_bit=max_bit/2;

min_bit=0;

threshold_time+=10;

}else{//whentheothertransmissionfailureoccurs

target_tr_bit=(max_bit+min_bit)/2;

min_bit=target_tr_bit;

threshold_time+=10;

}

flag=1;//transmissionfailureoccurred

count=0;

}else{//whennotransmissionfailureoccurs

flag=0;//notransmissionfailure

tmp=target_tr_bit+increasedbit-rate;//calculatetemporaltargetbit-rate

if(tmp

target_tr_bit=max_bit=tmp;

}elseif(tmp>=init_bit){//whentmpissameasinitialbit-rate

target_tr_bit=init_bit;

count++;

if(count>=threshold_time){//whencountisgreaterthanthreshold

min_bit=0;

threshold_time-=10;

count=0;

}

}elseif(tmp>=max_bit){//whentmpisgreaterthanbandwidth

target_tr_bit=max_bit;

count++;

if(count>=threshold_time){//whencountisgreaterthanthreshold

min_bit=max_bit;

max_bit=init_bit;

count=0;

threshold_time-=10;

}

}

}

returntarget_tr_bit;

}

Althoughthequalityofplaymediadropsduetothelowbit-rate,itisbetterthanthejitteringandceasingphenomenaofmediastreaming.Ifthestreamingbit-rateiskeptastheinitialbit-rateinthepoornetworkbandwidthenvironment,thejitteringandceasingphenomenacannotbeavoided.

2.轨道交换

//-------------------SetTrackQualityLevelenQTRTPFile.cpp-------------------//

voidQTRTPFile:

:

SetTrackQualityLevel(RTPTrackListEntry*inEntry,UInt32inNewQualityLevel,UInt32

inMaxQualityLevel)

{

if(inNewQualityLevel!

=inEntry->QualityLevel)

{

UInt32threshold=3*(inMaxQualityLevel/4);

if(inNewQualityLevel>threshold&&inEntry->QualityLevel

>QualityLevel!

=0)

{

inEntry->QualityLevel=inMaxQualityLevel*0.4;

this->SwapTracks(false);

return;

}

elseif(inNewQualityLevel==0&&inEntry->QualityLevel>inNewQualityLevel&&inEntry-

>QualityLevel!

=10)

{

inEntry->QualityLevel=0;

this->SwapTracks(true);

return;

}

inEntry->QualityLevel=inNewQualityLevel;

}

}

//-------------------UpdateTimeAndQualityenRTPStream3GPP.cpp-------------------//

voidRTPStream3GPP:

:

UpdateTimeAndQuality(SInt64curTime)

{

fAdjustTime=kNoChange;

fAdjustSize=kNoChange;

if(!

RateAdaptationEnabled())

return;

Bool16limitTargetDelay=true;

UInt32maxTargetDelayMilli=10000;//5000;

UInt32adjustedFreeBuffer=fLastReportedFreeBufferSpace;

UInt32adjustTargetDelay=fTargetBufferingDelay;

if(limitTargetDelay)

{

if(adjustTargetDelay>maxTargetDelayMilli)//makethisconstantapref

adjustTargetDelay=maxTargetDelayMilli;

}

if(fBufferSize>RTCPNaduPacket:

:

kMaximumReportableFreeBufferSpace)

fBufferSize=RTCPNaduPacket:

:

kMaximumReportableFreeBufferSpace;

UInt32maxUsableBufferSizeBytes=fBufferSize;

UInt32extraBufferMultipleInSeconds=2;//useupto3timestherequestedtargetdelayin

bytes

UInt32maxUsableDelaySecs=extraBufferMultipleInSeconds*(adjustTargetDelay/1000);

UInt32movieByteRate=fMovieBitRate>>3;//bitstobytes

UInt32bufferUsage=fBufferSize-fLastReportedFreeBufferSpace;

UInt32bufferDelay=fLastReportedBufferingDelay;

if(bufferUsage>fBufferSize)//thereismorereportedfreebufferthanthemaximum--not

goodforourratiosbutagoodsituationattheclienti.e.nobufferoverrunhere.

{

bufferUsage=fBufferSize/2;//Havetopicksomethingsouse50%.

}

DEBUG_PRINTF(("reportedbuffersize=%"_U32BITARG_"reportedFreeBuffer=%"_U32BITARG_"

currentcalculatedbufferUsage=%"_U32BITARG_"\n",fBufferSize,

fLastReportedFreeBufferSpace,bufferUsage));

DEBUG_PRINTF(("AvgMovieBitRate=%luoriginaltargetdelay=%luadjustedTargetDelay=%ld

\n",fMovieBitRate,fTargetBufferingDelay,adjustTargetDelay));

if(qtssVideoPayloadType==fRTPStream.GetPayLoadType()&&fMovieBitRate>0&&

adjustTargetDelay>0)//limithowmuchweuse

{

maxUsableBufferSizeBytes=maxUsableDelaySecs*movieByteRate;//buffertime*bitratefor

movieisbiggerthananysinglestreambuffer

if(maxUsableBufferSizeBytes>fBufferSize)//reportedsizeissmallerthanourbuffer

target

{maxUsableBufferSizeBytes=fBufferSize;

if(maxUsableBufferSizeBytes

maxUsableBufferSizeBytes=movieByteRate;

UInt32newTargetDelay=(maxUsableBufferSizeBytes/movieByteRate)*1000;

if(newTargetDelay

adjustTargetDelay=newTargetDelay;

}

if(adjustedFreeBuffer>maxUsableBufferSizeBytes)

adjustedFreeBuffer=maxUsableBufferSizeBytes;

UInt32freeBytes=fBufferSize-bufferUsage;

if(freeBytes>fBufferSize)

bufferUsage=maxUsableBufferSizeBytes/2;

DEBUG_PRINTF(("ADJUSTINGbufferusageandtargetdelay:

maxUsableBufferSizeBytes=%lu

adjustedFreeBuffer=%lubufferUsage=%luadjustedTargetDelay=%lu\n",maxUsableBufferSizeBytes,

adjustedFreeBuffer,bufferUsage,adjustTargetDelay));

}

DEBUG_PRINTF(("CalculatedmaxUsableBufferSize=%"_U32BITARG_"reported

fBufferSize=%"_U32BITARG_"reportedbufferdelay=%"_U32BITARG_"currentcalculatedbufferUsage=

%"_U32BITARG_"\n",maxUsableBufferSizeBytes,fBufferSize,bufferDelay,bufferUsage));

//bufferDelayshouldreallybethenetworkdelaybecauseifbufferdelaywerereallylargethat

wouldbeok

//itissupposedtobe-1ifnotsupportedorarealvalue.Someclientssend0incorrectly.

//ifbufferdelayissmallthatshouldmeanthebufferisemptyandaunder-runfailure

occurred.

if(bufferDelay==0)

bufferDelay=kUInt32_Max;

doublebufferUsageRatio=static_cast(bufferUsage)/maxUsableBufferSizeBytes;

doublebufferDelayRatio=static_cast(bufferDelay)/adjustTargetDelay;

DEBUG_PRINTF(("bufferUsageRatio=%fbufferDelayRatio=%f\n",bufferUsageRatio,

bufferDelayRatio));

if(!

fStartDoingAdaptation)

{

//ThisisusedtopreventQTSSfromthinninginthebeginningofthestream,whenthebuffering

delayandusageareexpectedtobelowRateadaptationwillstartwhenEITHERofthetwolow

watermarksforthinninghavepassed,ORthemediahasbeenplayingforthetargetbufferingdelay.

Theidealsituationforthecurrentcodeis2xormorebuffersizetotargettime.Sotargettime

convertedtobytesshouldbe50%orlessthebuffersizetoavoidoverrunthisoneisagressiveand

workswellwithNokiawhenallisgoodandthereisextrabandwidthsoitmakesagoodnetworklook

good.

if(bufferUsageRatio>=0.7)//startactiverateadaptwhenclientis70%full

{fStartDoingAdaptation=true;/*qtss_printf("bufferusage\n");*/}

elseif(curTime-fRTPStream.GetSession().GetFirstPlayTime()>=15000)//butdon'twait

longerthan15seconds

{fStartDoingAdaptation=true;}

else//neithercriteriawasmet.//speedupwhilewaitingforthebuffertofill.

{fAdjustTime=kAdjustUpUp;

}

if(fStartDoingAdaptation)

{fNumLargeRTT=0;

fNumSmallRTT=-3;//Delaythefirstrateincrease

}

}

if(fStartDoingAdaptation)

{

SInt32currentQualityLevel=fRTPStream.GetQualityLevel();

if(currentQualityLevel>(fRTPStream.GetNumQualityLevels()*0.75)||currentQualityLevel<1)

{

fRTPStream.SetQualityLevel(20);

}

//newcodeworksgoodforNokiaN93onwifiandokforslowlinks(needssomemorecomparison

testingagainstnonrateadaptcodeandagainstbuild520orearlier)

if(bufferDelay!

=kUInt32_Max)//notsupported

{

DEBUG_PRINTF(("rateadaptisusingdelayratioandbuffersize\n\n"));

//Thebufferingdelayinformationisavailable.

//shouldIspeeduporslowdown?

ADelayRatioof100%isatargetnotaminimumandnotamaximum.

if(bufferDelayRatio<2.0)//allowupto200%

fAdjustTime=kAdjustUpUp;

else

fAdjustTime=kAdjustDown;

if(bufferUsageRatio>=0.7)//ifyouareindangerofbuffer-overflowingbecausethe

buffersizeistoosmallforthemovie,alsoslow

fAdjustTime=kAdjustDown;

elseif(bufferUsageRatio<0.5&&bufferDelayRatio>2.5)//stoppushing.

fAdjustTime=kAdjustDownDown;

elseif(bufferUsageRatio<0.5&&bufferDelayRatio>2.0)//stoppushing.

fAdjustTime=kAdjustDown;

elseif(bufferUsageRatio<0.5&&bufferDelayRatio>0.5)//trytopushuphard.

{fAdjustTime=kAdjustUpUp;

fAdjustSize=kAdjustUp;

}

//shouldIthinorthicken?

if(bufferUsageRatio<0.2&&bufferDelayRatio>2.5)//avoidunderflowsincethe

bandwidthislow.

{fAdjustSize=kAdjustDown;

fAdjustTime=kAdjustUpUp;

}

elseif(bufferUsageRatio<=0.1)//trythickening

{fAdjustSize=kAdjustUpUp;

fAdjustTime=kAdjustUpUp;

}

elseif(bufferUsageRatio<=0.3&&bufferDelayRatio<1.0)//stillindangerofunderflow

fAdjustSize=kNoChange;

elseif(bufferUsageRatio<0.7)//nolongerindangerofunderflow;oktothick

fAdjustSize=kAdjustUp;

else

fAdjustSize=kNoChange;

}

else

{

DEBUG_PRINTF(("rateadaptisusingonlybuffersize\n"));

//Thebufferingdelayisnotavailable;wemakethin/slowdecisionsbasedonjustthe

bufferusagealone

if(bufferUsageRatio>0.9)//needtoslowandthintoavoidoverflow

{

fAdj

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 政史地

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1