You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TPCUtils.spec.js 136KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080
  1. /* eslint-disable max-len */
  2. import { CodecMimeType } from '../../service/RTC/CodecMimeType';
  3. import { SIM_LAYERS } from '../../service/RTC/StandardVideoSettings';
  4. import { VideoEncoderScalabilityMode } from '../../service/RTC/VideoEncoderScalabilityMode';
  5. import { MockJitsiLocalTrack, MockPeerConnection } from './MockClasses';
  6. import { TPCUtils } from './TPCUtils';
  7. describe('TPCUtils', () => {
  8. describe('ensureCorrectOrderOfSsrcs()', () => {
  9. const commonSdpLines = [
  10. 'v=0',
  11. 'o=- 814997227879783433 5 IN IP4 127.0.0.1',
  12. 's=-',
  13. 't=0 0',
  14. 'a=msid-semantic: WMS 0836cc8e-a7bb-47e9-affb-0599414bc56d',
  15. 'a=group:BUNDLE video',
  16. 'm=video 9 RTP/SAVPF 100 96',
  17. 'c=IN IP4 0.0.0.0',
  18. 'a=rtpmap:100 VP8/90000',
  19. 'a=fmtp:96 apt=100',
  20. 'a=rtcp:9 IN IP4 0.0.0.0',
  21. 'a=rtcp-fb:100 ccm fir',
  22. 'a=rtcp-fb:100 nack',
  23. 'a=rtcp-fb:100 nack pli',
  24. 'a=rtcp-fb:100 goog-remb',
  25. 'a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time',
  26. 'a=setup:passive',
  27. 'a=mid:video',
  28. 'a=sendrecv',
  29. 'a=ice-ufrag:adPg',
  30. 'a=ice-pwd:Xsr05Mq8S7CR44DAnusZE26F',
  31. 'a=fingerprint:sha-256 6A:39:DE:11:24:AD:2E:4E:63:D6:69:D3:85:05:53:C7:3C:38:A4:B7:91:74:C0:91:44:FC:94:63:7F:01:AB:A9'
  32. ];
  33. it('sort ssrcs associated with all FID ssrc-groups', () => {
  34. const pc = new MockPeerConnection();
  35. const tpcUtils = new TPCUtils(pc);
  36. const source = new RTCSessionDescription({
  37. type: 'offer',
  38. sdp: getSourceSdp()
  39. });
  40. const result = tpcUtils.ensureCorrectOrderOfSsrcs(source);
  41. expect(result.sdp).toBe(getExpectedSdp());
  42. /**
  43. * Test SDP with multiple FID groups
  44. */
  45. function getSourceSdp() {
  46. return `${[
  47. ...commonSdpLines,
  48. 'a=ssrc:1757014965 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  49. 'a=ssrc:1757014965 cname:peDGrDD6WsxUOki/',
  50. 'a=ssrc:1479742055 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  51. 'a=ssrc:1479742055 cname:peDGrDD6WsxUOki/',
  52. 'a=ssrc:1089111804 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  53. 'a=ssrc:1089111804 cname:peDGrDD6WsxUOki/',
  54. 'a=ssrc:855213044 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  55. 'a=ssrc:855213044 cname:peDGrDD6WsxUOki/',
  56. 'a=ssrc:984899560 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  57. 'a=ssrc:984899560 cname:peDGrDD6WsxUOki/',
  58. 'a=ssrc:2963867077 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  59. 'a=ssrc:2963867077 cname:peDGrDD6WsxUOki/',
  60. 'a=ssrc-group:FID 1757014965 984899560',
  61. 'a=ssrc-group:FID 1479742055 855213044',
  62. 'a=ssrc-group:FID 1089111804 2963867077',
  63. 'a=ssrc-group:SIM 1757014965 1479742055 1089111804',
  64. 'a=rtcp-mux'
  65. ].join('\r\n')}\r\n`;
  66. }
  67. /**
  68. * Expected SDP: all ssrc must be present and ordered
  69. */
  70. function getExpectedSdp() {
  71. return `${[
  72. ...commonSdpLines,
  73. 'a=ssrc:1757014965 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  74. 'a=ssrc:1757014965 cname:peDGrDD6WsxUOki/',
  75. 'a=ssrc:984899560 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  76. 'a=ssrc:984899560 cname:peDGrDD6WsxUOki/',
  77. 'a=ssrc:1479742055 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  78. 'a=ssrc:1479742055 cname:peDGrDD6WsxUOki/',
  79. 'a=ssrc:855213044 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  80. 'a=ssrc:855213044 cname:peDGrDD6WsxUOki/',
  81. 'a=ssrc:1089111804 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  82. 'a=ssrc:1089111804 cname:peDGrDD6WsxUOki/',
  83. 'a=ssrc:2963867077 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  84. 'a=ssrc:2963867077 cname:peDGrDD6WsxUOki/',
  85. 'a=ssrc-group:FID 1757014965 984899560',
  86. 'a=ssrc-group:FID 1479742055 855213044',
  87. 'a=ssrc-group:FID 1089111804 2963867077',
  88. 'a=ssrc-group:SIM 1757014965 1479742055 1089111804',
  89. 'a=rtcp-mux'
  90. ].join('\r\n')}\r\n`;
  91. }
  92. });
  93. it('sort ssrcs in case the first ssrc in the SIM group is not present at the top', () => {
  94. const pc = new MockPeerConnection();
  95. const tpcUtils = new TPCUtils(pc);
  96. const source = new RTCSessionDescription({
  97. type: 'offer',
  98. sdp: getSourceSdp()
  99. });
  100. const result = tpcUtils.ensureCorrectOrderOfSsrcs(source);
  101. expect(result.sdp).toBe(getExpectedSdp());
  102. /**
  103. * Test SDP with multiple FID groups where the first ssrc in the SIM group is not present at the top
  104. */
  105. function getSourceSdp() {
  106. return `${[
  107. ...commonSdpLines,
  108. 'a=ssrc:1479742055 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  109. 'a=ssrc:1479742055 cname:peDGrDD6WsxUOki/',
  110. 'a=ssrc:1757014965 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  111. 'a=ssrc:1757014965 cname:peDGrDD6WsxUOki/',
  112. 'a=ssrc:1089111804 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  113. 'a=ssrc:1089111804 cname:peDGrDD6WsxUOki/',
  114. 'a=ssrc:855213044 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  115. 'a=ssrc:855213044 cname:peDGrDD6WsxUOki/',
  116. 'a=ssrc:984899560 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  117. 'a=ssrc:984899560 cname:peDGrDD6WsxUOki/',
  118. 'a=ssrc:2963867077 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  119. 'a=ssrc:2963867077 cname:peDGrDD6WsxUOki/',
  120. 'a=ssrc-group:FID 1757014965 984899560',
  121. 'a=ssrc-group:FID 1479742055 855213044',
  122. 'a=ssrc-group:FID 1089111804 2963867077',
  123. 'a=ssrc-group:SIM 1757014965 1479742055 1089111804',
  124. 'a=rtcp-mux'
  125. ].join('\r\n')}\r\n`;
  126. }
  127. /**
  128. * Expected SDP: all ssrc must be present and ordered
  129. */
  130. function getExpectedSdp() {
  131. return `${[
  132. ...commonSdpLines,
  133. 'a=ssrc:1757014965 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  134. 'a=ssrc:1757014965 cname:peDGrDD6WsxUOki/',
  135. 'a=ssrc:984899560 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  136. 'a=ssrc:984899560 cname:peDGrDD6WsxUOki/',
  137. 'a=ssrc:1479742055 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  138. 'a=ssrc:1479742055 cname:peDGrDD6WsxUOki/',
  139. 'a=ssrc:855213044 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  140. 'a=ssrc:855213044 cname:peDGrDD6WsxUOki/',
  141. 'a=ssrc:1089111804 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  142. 'a=ssrc:1089111804 cname:peDGrDD6WsxUOki/',
  143. 'a=ssrc:2963867077 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  144. 'a=ssrc:2963867077 cname:peDGrDD6WsxUOki/',
  145. 'a=ssrc-group:FID 1757014965 984899560',
  146. 'a=ssrc-group:FID 1479742055 855213044',
  147. 'a=ssrc-group:FID 1089111804 2963867077',
  148. 'a=ssrc-group:SIM 1757014965 1479742055 1089111804',
  149. 'a=rtcp-mux'
  150. ].join('\r\n')}\r\n`;
  151. }
  152. });
  153. it('sort ssrcs in case there is a single FID group', () => {
  154. const pc = new MockPeerConnection();
  155. const tpcUtils = new TPCUtils(pc);
  156. const source = new RTCSessionDescription({
  157. type: 'offer',
  158. sdp: getSourceSdp()
  159. });
  160. const result = tpcUtils.ensureCorrectOrderOfSsrcs(source);
  161. expect(result.sdp).toBe(getExpectedSdp());
  162. /**
  163. * Test SDP with the single FID group
  164. */
  165. function getSourceSdp() {
  166. return `${[
  167. ...commonSdpLines,
  168. 'a=ssrc:984899560 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  169. 'a=ssrc:984899560 cname:peDGrDD6WsxUOki/',
  170. 'a=ssrc:1757014965 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  171. 'a=ssrc:1757014965 cname:peDGrDD6WsxUOki/',
  172. 'a=ssrc-group:FID 1757014965 984899560',
  173. 'a=rtcp-mux'
  174. ].join('\r\n')}\r\n`;
  175. }
  176. /**
  177. * Expected SDP: all ssrc must be present and ordered
  178. */
  179. function getExpectedSdp() {
  180. return `${[
  181. ...commonSdpLines,
  182. 'a=ssrc:1757014965 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  183. 'a=ssrc:1757014965 cname:peDGrDD6WsxUOki/',
  184. 'a=ssrc:984899560 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  185. 'a=ssrc:984899560 cname:peDGrDD6WsxUOki/',
  186. 'a=ssrc-group:FID 1757014965 984899560',
  187. 'a=rtcp-mux'
  188. ].join('\r\n')}\r\n`;
  189. }
  190. });
  191. });
  192. describe('Test encodings when default settings are used for', () => {
  193. let pc, tpcUtils;
  194. let activeState, height, maxBitrates, scalabilityModes, scaleFactor;
  195. afterEach(() => {
  196. activeState = null;
  197. height = null;
  198. maxBitrates = null;
  199. scalabilityModes = null;
  200. scaleFactor = null;
  201. });
  202. const videoQuality = {};
  203. describe('AV1 camera tracks', () => {
  204. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  205. const codec = CodecMimeType.AV1;
  206. beforeEach(() => {
  207. pc = new MockPeerConnection('1', true, true /* simulcast */);
  208. pc.options = { videoQuality };
  209. pc.videoTransferActive = true;
  210. tpcUtils = new TPCUtils(pc);
  211. });
  212. afterEach(() => {
  213. pc = null;
  214. tpcUtils = null;
  215. });
  216. it('and requested resolution is 720', () => {
  217. height = 720;
  218. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  219. expect(activeState[0]).toBe(true);
  220. expect(activeState[1]).toBe(false);
  221. expect(activeState[2]).toBe(false);
  222. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  223. expect(maxBitrates[0]).toBe(1000000);
  224. expect(maxBitrates[1]).toBe(0);
  225. expect(maxBitrates[2]).toBe(0);
  226. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  227. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L3T3_KEY);
  228. expect(scalabilityModes[1]).toBe(undefined);
  229. expect(scalabilityModes[2]).toBe(undefined);
  230. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  231. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  232. });
  233. it('and requested resolution is 360', () => {
  234. height = 360;
  235. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  236. expect(activeState[0]).toBe(true);
  237. expect(activeState[1]).toBe(false);
  238. expect(activeState[2]).toBe(false);
  239. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  240. expect(maxBitrates[0]).toBe(300000);
  241. expect(maxBitrates[1]).toBe(0);
  242. expect(maxBitrates[2]).toBe(0);
  243. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  244. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L2T3_KEY);
  245. expect(scalabilityModes[1]).toBe(undefined);
  246. expect(scalabilityModes[2]).toBe(undefined);
  247. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  248. expect(scaleFactor[0]).toBe(SIM_LAYERS[1].scaleFactor);
  249. });
  250. it('and requested resolution is 180', () => {
  251. height = 180;
  252. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  253. expect(activeState[0]).toBe(true);
  254. expect(activeState[1]).toBe(false);
  255. expect(activeState[2]).toBe(false);
  256. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  257. expect(maxBitrates[0]).toBe(100000);
  258. expect(maxBitrates[1]).toBe(0);
  259. expect(maxBitrates[2]).toBe(0);
  260. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  261. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  262. expect(scalabilityModes[1]).toBe(undefined);
  263. expect(scalabilityModes[2]).toBe(undefined);
  264. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  265. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  266. });
  267. it('and requested resolution is 0', () => {
  268. height = 0;
  269. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  270. expect(activeState[0]).toBe(false);
  271. expect(activeState[1]).toBe(false);
  272. expect(activeState[2]).toBe(false);
  273. });
  274. });
  275. describe('AV1 high resolution camera tracks', () => {
  276. const track = new MockJitsiLocalTrack(2160, 'video', 'camera');
  277. const codec = CodecMimeType.AV1;
  278. beforeEach(() => {
  279. pc = new MockPeerConnection('1', true, true /* simulcast */);
  280. pc.options = { videoQuality };
  281. pc.videoTransferActive = true;
  282. tpcUtils = new TPCUtils(pc);
  283. });
  284. afterEach(() => {
  285. pc = null;
  286. tpcUtils = null;
  287. });
  288. it('and requested resolution is 2160', () => {
  289. height = 2160;
  290. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  291. expect(activeState[0]).toBe(true);
  292. expect(activeState[1]).toBe(false);
  293. expect(activeState[2]).toBe(false);
  294. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  295. expect(maxBitrates[0]).toBe(4000000);
  296. expect(maxBitrates[1]).toBe(0);
  297. expect(maxBitrates[2]).toBe(0);
  298. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  299. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L3T3_KEY);
  300. expect(scalabilityModes[1]).toBe(undefined);
  301. expect(scalabilityModes[2]).toBe(undefined);
  302. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  303. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  304. });
  305. it('and requested resolution is 1080', () => {
  306. height = 1080;
  307. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  308. expect(activeState[0]).toBe(true);
  309. expect(activeState[1]).toBe(false);
  310. expect(activeState[2]).toBe(false);
  311. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  312. expect(maxBitrates[0]).toBe(2000000);
  313. expect(maxBitrates[1]).toBe(0);
  314. expect(maxBitrates[2]).toBe(0);
  315. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  316. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L3T3_KEY);
  317. expect(scalabilityModes[1]).toBe(undefined);
  318. expect(scalabilityModes[2]).toBe(undefined);
  319. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  320. expect(scaleFactor[0]).toBe(2);
  321. });
  322. it('and requested resolution is 720', () => {
  323. height = 720;
  324. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  325. expect(activeState[0]).toBe(true);
  326. expect(activeState[1]).toBe(false);
  327. expect(activeState[2]).toBe(false);
  328. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  329. expect(maxBitrates[0]).toBe(1000000);
  330. expect(maxBitrates[1]).toBe(0);
  331. expect(maxBitrates[2]).toBe(0);
  332. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  333. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L3T3_KEY);
  334. expect(scalabilityModes[1]).toBe(undefined);
  335. expect(scalabilityModes[2]).toBe(undefined);
  336. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  337. expect(scaleFactor[0]).toBe(3);
  338. });
  339. it('and requested resolution is 360', () => {
  340. height = 360;
  341. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  342. expect(activeState[0]).toBe(true);
  343. expect(activeState[1]).toBe(false);
  344. expect(activeState[2]).toBe(false);
  345. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  346. expect(maxBitrates[0]).toBe(300000);
  347. expect(maxBitrates[1]).toBe(0);
  348. expect(maxBitrates[2]).toBe(0);
  349. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  350. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L2T3_KEY);
  351. expect(scalabilityModes[1]).toBe(undefined);
  352. expect(scalabilityModes[2]).toBe(undefined);
  353. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  354. expect(scaleFactor[0]).toBe(6);
  355. });
  356. it('and requested resolution is 180', () => {
  357. height = 180;
  358. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  359. expect(activeState[0]).toBe(true);
  360. expect(activeState[1]).toBe(false);
  361. expect(activeState[2]).toBe(false);
  362. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  363. expect(maxBitrates[0]).toBe(100000);
  364. expect(maxBitrates[1]).toBe(0);
  365. expect(maxBitrates[2]).toBe(0);
  366. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  367. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  368. expect(scalabilityModes[1]).toBe(undefined);
  369. expect(scalabilityModes[2]).toBe(undefined);
  370. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  371. expect(scaleFactor[0]).toBe(12);
  372. });
  373. it('and requested resolution is 0', () => {
  374. height = 0;
  375. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  376. expect(activeState[0]).toBe(false);
  377. expect(activeState[1]).toBe(false);
  378. expect(activeState[2]).toBe(false);
  379. });
  380. });
  381. describe('AV1 low fps desktop tracks', () => {
  382. const codec = CodecMimeType.AV1;
  383. const track = new MockJitsiLocalTrack(1440, 'video', 'desktop');
  384. beforeEach(() => {
  385. pc = new MockPeerConnection('1', true, true /* simulcast */);
  386. pc._capScreenshareBitrate = true;
  387. pc.options = { videoQuality };
  388. pc.videoTransferActive = true;
  389. tpcUtils = new TPCUtils(pc);
  390. });
  391. afterEach(() => {
  392. pc = null;
  393. tpcUtils = null;
  394. });
  395. it('and requested resolution is 2160', () => {
  396. height = 2160;
  397. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  398. expect(activeState[0]).toBe(true);
  399. expect(activeState[1]).toBe(false);
  400. expect(activeState[2]).toBe(false);
  401. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  402. expect(maxBitrates[0]).toBe(2500000);
  403. expect(maxBitrates[1]).toBe(0);
  404. expect(maxBitrates[2]).toBe(0);
  405. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  406. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  407. expect(scalabilityModes[1]).toBe(undefined);
  408. expect(scalabilityModes[2]).toBe(undefined);
  409. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  410. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  411. });
  412. it('and requested resolution is 0', () => {
  413. height = 0;
  414. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  415. expect(activeState[0]).toBe(false);
  416. expect(activeState[1]).toBe(false);
  417. expect(activeState[2]).toBe(false);
  418. });
  419. });
  420. describe('AV1 desktop tracks for p2p', () => {
  421. const codec = CodecMimeType.AV1;
  422. const track = new MockJitsiLocalTrack(1440, 'video', 'desktop');
  423. beforeEach(() => {
  424. pc = new MockPeerConnection('1', true, false /* simulcast */);
  425. pc._capScreenshareBitrate = true;
  426. pc.options = { videoQuality };
  427. pc.videoTransferActive = true;
  428. tpcUtils = new TPCUtils(pc);
  429. });
  430. afterEach(() => {
  431. pc = null;
  432. tpcUtils = null;
  433. });
  434. it('and requested resolution is 2160', () => {
  435. height = 2160;
  436. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  437. expect(activeState[0]).toBe(true);
  438. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  439. expect(maxBitrates[0]).toBe(2500000);
  440. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  441. expect(scalabilityModes).toBe(undefined);
  442. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  443. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  444. });
  445. it('and requested resolution is 0', () => {
  446. height = 0;
  447. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  448. expect(activeState[0]).toBe(false);
  449. expect(activeState[1]).toBe(false);
  450. expect(activeState[2]).toBe(false);
  451. });
  452. });
  453. describe('AV1 high fps desktop tracks', () => {
  454. const codec = CodecMimeType.AV1;
  455. const track = new MockJitsiLocalTrack(1440, 'video', 'desktop');
  456. beforeEach(() => {
  457. pc = new MockPeerConnection('1', true, true /* simulcast */);
  458. pc._capScreenshareBitrate = false;
  459. pc.options = { videoQuality };
  460. pc.videoTransferActive = true;
  461. tpcUtils = new TPCUtils(pc);
  462. });
  463. afterEach(() => {
  464. pc = null;
  465. tpcUtils = null;
  466. });
  467. it('and requested resolution is 2160', () => {
  468. height = 2160;
  469. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  470. expect(activeState[0]).toBe(true);
  471. expect(activeState[1]).toBe(false);
  472. expect(activeState[2]).toBe(false);
  473. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  474. expect(maxBitrates[0]).toBe(2500000);
  475. expect(maxBitrates[1]).toBe(0);
  476. expect(maxBitrates[2]).toBe(0);
  477. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  478. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L3T3_KEY);
  479. expect(scalabilityModes[1]).toBe(undefined);
  480. expect(scalabilityModes[2]).toBe(undefined);
  481. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  482. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  483. });
  484. it('and requested resolution is 0', () => {
  485. height = 0;
  486. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  487. expect(activeState[0]).toBe(false);
  488. expect(activeState[1]).toBe(false);
  489. expect(activeState[2]).toBe(false);
  490. });
  491. });
  492. describe('AV1 camera tracks for p2p', () => {
  493. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  494. const codec = CodecMimeType.AV1;
  495. beforeEach(() => {
  496. pc = new MockPeerConnection('1', true, false /* simulcast */);
  497. pc.options = { videoQuality };
  498. pc.videoTransferActive = true;
  499. tpcUtils = new TPCUtils(pc);
  500. });
  501. afterEach(() => {
  502. pc = null;
  503. tpcUtils = null;
  504. });
  505. it('and requested resolution is 720', () => {
  506. height = 720;
  507. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  508. expect(activeState[0]).toBe(true);
  509. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  510. expect(maxBitrates[0]).toBe(1000000);
  511. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  512. expect(scalabilityModes).toBe(undefined);
  513. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  514. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  515. });
  516. it('and requested resolution is 360', () => {
  517. height = 360;
  518. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  519. expect(activeState[0]).toBe(true);
  520. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  521. expect(maxBitrates[0]).toBe(300000);
  522. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  523. expect(scalabilityModes).toBe(undefined);
  524. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  525. expect(scaleFactor[0]).toBe(SIM_LAYERS[1].scaleFactor);
  526. });
  527. it('and requested resolution is 720 again', () => {
  528. height = 720;
  529. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  530. expect(activeState[0]).toBe(true);
  531. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  532. expect(maxBitrates[0]).toBe(1000000);
  533. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  534. expect(scalabilityModes).toBe(undefined);
  535. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  536. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  537. });
  538. it('and requested resolution is 180', () => {
  539. height = 180;
  540. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  541. expect(activeState[0]).toBe(true);
  542. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  543. expect(maxBitrates[0]).toBe(100000);
  544. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  545. expect(scalabilityModes).toBe(undefined);
  546. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  547. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  548. });
  549. it('and requested resolution is 0', () => {
  550. height = 0;
  551. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  552. expect(activeState[0]).toBe(false);
  553. });
  554. });
  555. describe('AV1 desktop tracks for p2p', () => {
  556. const track = new MockJitsiLocalTrack(720, 'video', 'desktop');
  557. const codec = CodecMimeType.AV1;
  558. beforeEach(() => {
  559. pc = new MockPeerConnection('1', true, false /* simulcast */);
  560. pc.options = { videoQuality };
  561. pc.videoTransferActive = true;
  562. tpcUtils = new TPCUtils(pc);
  563. });
  564. afterEach(() => {
  565. pc = null;
  566. tpcUtils = null;
  567. });
  568. it('and requested resolution is 2160', () => {
  569. height = 2160;
  570. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  571. expect(activeState[0]).toBe(true);
  572. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  573. expect(maxBitrates[0]).toBe(2500000);
  574. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  575. expect(scalabilityModes).toBe(undefined);
  576. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  577. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  578. });
  579. it('and requested resolution is 0', () => {
  580. height = 0;
  581. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  582. expect(activeState[0]).toBe(false);
  583. });
  584. });
  585. describe('VP9 camera tracks', () => {
  586. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  587. const codec = CodecMimeType.VP9;
  588. beforeEach(() => {
  589. pc = new MockPeerConnection('1', true, true /* simulcast */);
  590. pc.options = { videoQuality };
  591. pc.videoTransferActive = true;
  592. tpcUtils = new TPCUtils(pc);
  593. });
  594. afterEach(() => {
  595. pc = null;
  596. tpcUtils = null;
  597. });
  598. it('and requested resolution is 720', () => {
  599. height = 720;
  600. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  601. expect(activeState[0]).toBe(true);
  602. expect(activeState[1]).toBe(false);
  603. expect(activeState[2]).toBe(false);
  604. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  605. expect(maxBitrates[0]).toBe(1200000);
  606. expect(maxBitrates[1]).toBe(0);
  607. expect(maxBitrates[2]).toBe(0);
  608. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  609. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L3T3_KEY);
  610. expect(scalabilityModes[1]).toBe(undefined);
  611. expect(scalabilityModes[2]).toBe(undefined);
  612. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  613. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  614. });
  615. it('and requested resolution is 360', () => {
  616. height = 360;
  617. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  618. expect(activeState[0]).toBe(true);
  619. expect(activeState[1]).toBe(false);
  620. expect(activeState[2]).toBe(false);
  621. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  622. expect(maxBitrates[0]).toBe(300000);
  623. expect(maxBitrates[1]).toBe(0);
  624. expect(maxBitrates[2]).toBe(0);
  625. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  626. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L2T3_KEY);
  627. expect(scalabilityModes[1]).toBe(undefined);
  628. expect(scalabilityModes[2]).toBe(undefined);
  629. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  630. expect(scaleFactor[0]).toBe(SIM_LAYERS[1].scaleFactor);
  631. });
  632. it('and requested resolution is 180', () => {
  633. height = 180;
  634. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  635. expect(activeState[0]).toBe(true);
  636. expect(activeState[1]).toBe(false);
  637. expect(activeState[2]).toBe(false);
  638. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  639. expect(maxBitrates[0]).toBe(100000);
  640. expect(maxBitrates[1]).toBe(0);
  641. expect(maxBitrates[2]).toBe(0);
  642. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  643. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  644. expect(scalabilityModes[1]).toBe(undefined);
  645. expect(scalabilityModes[2]).toBe(undefined);
  646. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  647. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  648. });
  649. it('and requested resolution is 0', () => {
  650. height = 0;
  651. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  652. expect(activeState[0]).toBe(false);
  653. expect(activeState[1]).toBe(false);
  654. expect(activeState[2]).toBe(false);
  655. });
  656. });
  657. describe('VP9 low fps desktop tracks', () => {
  658. const codec = CodecMimeType.VP9;
  659. const track = new MockJitsiLocalTrack(1440, 'video', 'desktop');
  660. beforeEach(() => {
  661. pc = new MockPeerConnection('1', true, true /* simulcast */);
  662. pc._capScreenshareBitrate = true;
  663. pc.options = { videoQuality };
  664. pc.videoTransferActive = true;
  665. tpcUtils = new TPCUtils(pc);
  666. });
  667. afterEach(() => {
  668. pc = null;
  669. tpcUtils = null;
  670. });
  671. it('and requested resolution is 2160', () => {
  672. height = 2160;
  673. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  674. expect(activeState[0]).toBe(true);
  675. expect(activeState[1]).toBe(false);
  676. expect(activeState[2]).toBe(false);
  677. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  678. expect(maxBitrates[0]).toBe(2500000);
  679. expect(maxBitrates[1]).toBe(0);
  680. expect(maxBitrates[2]).toBe(0);
  681. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  682. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  683. expect(scalabilityModes[1]).toBe(undefined);
  684. expect(scalabilityModes[2]).toBe(undefined);
  685. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  686. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  687. });
  688. it('and requested resolution is 0', () => {
  689. height = 0;
  690. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  691. expect(activeState[0]).toBe(false);
  692. expect(activeState[1]).toBe(false);
  693. expect(activeState[2]).toBe(false);
  694. });
  695. });
  696. describe('VP9 high fps desktop tracks', () => {
  697. const codec = CodecMimeType.VP9;
  698. const track = new MockJitsiLocalTrack(1440, 'video', 'desktop');
  699. beforeEach(() => {
  700. pc = new MockPeerConnection('1', true, true /* simulcast */);
  701. pc._capScreenshareBitrate = false;
  702. pc.options = { videoQuality };
  703. pc.videoTransferActive = true;
  704. tpcUtils = new TPCUtils(pc);
  705. });
  706. afterEach(() => {
  707. pc = null;
  708. tpcUtils = null;
  709. });
  710. it('and requested resolution is 2160', () => {
  711. height = 2160;
  712. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  713. expect(activeState[0]).toBe(true);
  714. expect(activeState[1]).toBe(false);
  715. expect(activeState[2]).toBe(false);
  716. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  717. expect(maxBitrates[0]).toBe(2500000);
  718. expect(maxBitrates[1]).toBe(0);
  719. expect(maxBitrates[2]).toBe(0);
  720. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  721. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L3T3_KEY);
  722. expect(scalabilityModes[1]).toBe(undefined);
  723. expect(scalabilityModes[2]).toBe(undefined);
  724. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  725. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  726. });
  727. it('and requested resolution is 0', () => {
  728. height = 0;
  729. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  730. expect(activeState[0]).toBe(false);
  731. expect(activeState[1]).toBe(false);
  732. expect(activeState[2]).toBe(false);
  733. });
  734. });
  735. describe('VP9 camera tracks with 1080p resolutions', () => {
  736. const codec = CodecMimeType.VP9;
  737. const track = new MockJitsiLocalTrack(1080, 'video', 'camera');
  738. beforeEach(() => {
  739. pc = new MockPeerConnection('1', true, true /* simulcast */);
  740. pc.options = { videoQuality };
  741. pc.videoTransferActive = true;
  742. tpcUtils = new TPCUtils(pc);
  743. });
  744. afterEach(() => {
  745. pc = null;
  746. tpcUtils = null;
  747. });
  748. it('and requested resolution is 2160', () => {
  749. height = 2160;
  750. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  751. expect(activeState[0]).toBe(true);
  752. expect(activeState[1]).toBe(false);
  753. expect(activeState[2]).toBe(false);
  754. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  755. expect(maxBitrates[0]).toBe(2500000);
  756. expect(maxBitrates[1]).toBe(0);
  757. expect(maxBitrates[2]).toBe(0);
  758. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  759. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L3T3_KEY);
  760. expect(scalabilityModes[1]).toBe(undefined);
  761. expect(scalabilityModes[2]).toBe(undefined);
  762. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  763. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  764. });
  765. it('and requested resolution is 720', () => {
  766. height = 720;
  767. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  768. expect(activeState[0]).toBe(true);
  769. expect(activeState[1]).toBe(false);
  770. expect(activeState[2]).toBe(false);
  771. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  772. expect(maxBitrates[0]).toBe(1200000);
  773. expect(maxBitrates[1]).toBe(0);
  774. expect(maxBitrates[2]).toBe(0);
  775. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  776. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L3T3_KEY);
  777. expect(scalabilityModes[1]).toBe(undefined);
  778. expect(scalabilityModes[2]).toBe(undefined);
  779. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  780. expect(scaleFactor[0]).toBe(1.5);
  781. });
  782. it('and requested resolution is 360', () => {
  783. height = 360;
  784. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  785. expect(activeState[0]).toBe(true);
  786. expect(activeState[1]).toBe(false);
  787. expect(activeState[2]).toBe(false);
  788. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  789. expect(maxBitrates[0]).toBe(300000);
  790. expect(maxBitrates[1]).toBe(0);
  791. expect(maxBitrates[2]).toBe(0);
  792. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  793. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L2T3_KEY);
  794. expect(scalabilityModes[1]).toBe(undefined);
  795. expect(scalabilityModes[2]).toBe(undefined);
  796. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  797. expect(scaleFactor[0]).toBe(3);
  798. });
  799. it('and requested resolution is 180', () => {
  800. height = 180;
  801. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  802. expect(activeState[0]).toBe(true);
  803. expect(activeState[1]).toBe(false);
  804. expect(activeState[2]).toBe(false);
  805. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  806. expect(maxBitrates[0]).toBe(100000);
  807. expect(maxBitrates[1]).toBe(0);
  808. expect(maxBitrates[2]).toBe(0);
  809. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  810. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  811. expect(scalabilityModes[1]).toBe(undefined);
  812. expect(scalabilityModes[2]).toBe(undefined);
  813. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  814. expect(scaleFactor[0]).toBe(6);
  815. });
  816. it('and requested resolution is 0', () => {
  817. height = 0;
  818. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  819. expect(activeState[0]).toBe(false);
  820. expect(activeState[1]).toBe(false);
  821. expect(activeState[2]).toBe(false);
  822. });
  823. });
  824. describe('VP9 camera tracks with odd resolutions ', () => {
  825. const codec = CodecMimeType.VP9;
  826. const track = new MockJitsiLocalTrack(550, 'video', 'camera');
  827. beforeEach(() => {
  828. pc = new MockPeerConnection('1', true, true /* simulcast */);
  829. pc.options = { videoQuality };
  830. pc.videoTransferActive = true;
  831. tpcUtils = new TPCUtils(pc);
  832. });
  833. afterEach(() => {
  834. pc = null;
  835. tpcUtils = null;
  836. });
  837. it('and requested resolution is 2160', () => {
  838. height = 2160;
  839. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  840. expect(activeState[0]).toBe(true);
  841. expect(activeState[1]).toBe(false);
  842. expect(activeState[2]).toBe(false);
  843. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  844. expect(maxBitrates[0]).toBe(300000);
  845. expect(maxBitrates[1]).toBe(0);
  846. expect(maxBitrates[2]).toBe(0);
  847. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  848. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L2T3_KEY);
  849. expect(scalabilityModes[1]).toBe(undefined);
  850. expect(scalabilityModes[2]).toBe(undefined);
  851. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  852. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  853. });
  854. it('and requested resolution is 720', () => {
  855. height = 720;
  856. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  857. expect(activeState[0]).toBe(true);
  858. expect(activeState[1]).toBe(false);
  859. expect(activeState[2]).toBe(false);
  860. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  861. expect(maxBitrates[0]).toBe(300000);
  862. expect(maxBitrates[1]).toBe(0);
  863. expect(maxBitrates[2]).toBe(0);
  864. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  865. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L2T3_KEY);
  866. expect(scalabilityModes[1]).toBe(undefined);
  867. expect(scalabilityModes[2]).toBe(undefined);
  868. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  869. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  870. });
  871. it('and requested resolution is 360', () => {
  872. height = 360;
  873. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  874. expect(activeState[0]).toBe(true);
  875. expect(activeState[1]).toBe(false);
  876. expect(activeState[2]).toBe(false);
  877. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  878. expect(maxBitrates[0]).toBe(300000);
  879. expect(maxBitrates[1]).toBe(0);
  880. expect(maxBitrates[2]).toBe(0);
  881. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  882. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L2T3_KEY);
  883. expect(scalabilityModes[1]).toBe(undefined);
  884. expect(scalabilityModes[2]).toBe(undefined);
  885. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  886. expect(scaleFactor[0]).toBe(550 / 360);
  887. });
  888. it('and requested resolution is 180', () => {
  889. height = 180;
  890. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  891. expect(activeState[0]).toBe(true);
  892. expect(activeState[1]).toBe(false);
  893. expect(activeState[2]).toBe(false);
  894. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  895. expect(maxBitrates[0]).toBe(100000);
  896. expect(maxBitrates[1]).toBe(0);
  897. expect(maxBitrates[2]).toBe(0);
  898. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  899. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  900. expect(scalabilityModes[1]).toBe(undefined);
  901. expect(scalabilityModes[2]).toBe(undefined);
  902. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  903. expect(scaleFactor[0]).toBe(550 / 180);
  904. });
  905. it('and requested resolution is 0', () => {
  906. height = 0;
  907. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  908. expect(activeState[0]).toBe(false);
  909. expect(activeState[1]).toBe(false);
  910. expect(activeState[2]).toBe(false);
  911. });
  912. });
  913. describe('VP9 camera tracks for p2p', () => {
  914. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  915. const codec = CodecMimeType.VP9;
  916. beforeEach(() => {
  917. pc = new MockPeerConnection('1', true, false /* simulcast */);
  918. pc.options = { videoQuality };
  919. pc.videoTransferActive = true;
  920. tpcUtils = new TPCUtils(pc);
  921. });
  922. afterEach(() => {
  923. pc = null;
  924. tpcUtils = null;
  925. });
  926. it('and requested resolution is 720', () => {
  927. height = 720;
  928. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  929. expect(activeState[0]).toBe(true);
  930. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  931. expect(maxBitrates[0]).toBe(1200000);
  932. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  933. expect(scalabilityModes).toBe(undefined);
  934. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  935. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  936. });
  937. it('and requested resolution is 360', () => {
  938. height = 360;
  939. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  940. expect(activeState[0]).toBe(true);
  941. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  942. expect(maxBitrates[0]).toBe(300000);
  943. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  944. expect(scalabilityModes).toBe(undefined);
  945. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  946. expect(scaleFactor[0]).toBe(SIM_LAYERS[1].scaleFactor);
  947. });
  948. it('and requested resolution is 180', () => {
  949. height = 180;
  950. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  951. expect(activeState[0]).toBe(true);
  952. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  953. expect(maxBitrates[0]).toBe(100000);
  954. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  955. expect(scalabilityModes).toBe(undefined);
  956. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  957. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  958. });
  959. it('and requested resolution is 0', () => {
  960. height = 0;
  961. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  962. expect(activeState[0]).toBe(false);
  963. });
  964. });
  965. describe('VP9 desktop tracks for p2p', () => {
  966. const track = new MockJitsiLocalTrack(720, 'video', 'desktop');
  967. const codec = CodecMimeType.VP9;
  968. beforeEach(() => {
  969. pc = new MockPeerConnection('1', true, false /* simulcast */);
  970. pc.options = { videoQuality };
  971. pc.videoTransferActive = true;
  972. tpcUtils = new TPCUtils(pc);
  973. });
  974. afterEach(() => {
  975. pc = null;
  976. tpcUtils = null;
  977. });
  978. it('and requested resolution is 2160', () => {
  979. height = 2160;
  980. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  981. expect(activeState[0]).toBe(true);
  982. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  983. expect(maxBitrates[0]).toBe(2500000);
  984. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  985. expect(scalabilityModes).toBe(undefined);
  986. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  987. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  988. });
  989. it('and requested resolution is 0', () => {
  990. height = 0;
  991. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  992. expect(activeState[0]).toBe(false);
  993. });
  994. });
  995. describe('H.264 camera tracks', () => {
  996. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  997. const codec = CodecMimeType.H264;
  998. beforeEach(() => {
  999. pc = new MockPeerConnection('1', true, true /* simulcast */);
  1000. pc.options = { videoQuality };
  1001. pc.videoTransferActive = true;
  1002. tpcUtils = new TPCUtils(pc);
  1003. });
  1004. afterEach(() => {
  1005. pc = null;
  1006. tpcUtils = null;
  1007. });
  1008. it('and requested resolution is 720', () => {
  1009. height = 720;
  1010. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1011. expect(activeState[0]).toBe(true);
  1012. expect(activeState[1]).toBe(true);
  1013. expect(activeState[2]).toBe(true);
  1014. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1015. expect(maxBitrates[0]).toBe(400000);
  1016. expect(maxBitrates[1]).toBe(800000);
  1017. expect(maxBitrates[2]).toBe(2000000);
  1018. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1019. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  1020. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  1021. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  1022. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1023. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1024. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1025. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1026. });
  1027. it('and requested resolution is 360', () => {
  1028. height = 360;
  1029. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1030. expect(activeState[0]).toBe(true);
  1031. expect(activeState[1]).toBe(true);
  1032. expect(activeState[2]).toBe(false);
  1033. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1034. expect(maxBitrates[0]).toBe(400000);
  1035. expect(maxBitrates[1]).toBe(800000);
  1036. expect(maxBitrates[2]).toBe(2000000);
  1037. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1038. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  1039. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  1040. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  1041. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1042. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1043. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1044. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1045. });
  1046. it('and requested resolution is 180', () => {
  1047. height = 180;
  1048. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1049. expect(activeState[0]).toBe(true);
  1050. expect(activeState[1]).toBe(false);
  1051. expect(activeState[2]).toBe(false);
  1052. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1053. expect(maxBitrates[0]).toBe(400000);
  1054. expect(maxBitrates[1]).toBe(800000);
  1055. expect(maxBitrates[2]).toBe(2000000);
  1056. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1057. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  1058. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  1059. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  1060. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1061. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1062. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1063. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1064. });
  1065. it('and requested resolution is 0', () => {
  1066. height = 0;
  1067. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1068. expect(activeState[0]).toBe(false);
  1069. expect(activeState[1]).toBe(false);
  1070. expect(activeState[2]).toBe(false);
  1071. });
  1072. });
  1073. describe('H.264 low fps desktop tracks', () => {
  1074. const codec = CodecMimeType.H264;
  1075. const track = new MockJitsiLocalTrack(1440, 'video', 'desktop');
  1076. beforeEach(() => {
  1077. pc = new MockPeerConnection('1', true, true /* simulcast */);
  1078. pc._capScreenshareBitrate = true;
  1079. pc.options = { videoQuality };
  1080. pc.videoTransferActive = true;
  1081. tpcUtils = new TPCUtils(pc);
  1082. });
  1083. afterEach(() => {
  1084. pc = null;
  1085. tpcUtils = null;
  1086. });
  1087. it('and requested resolution is 2160', () => {
  1088. height = 2160;
  1089. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1090. expect(activeState[0]).toBe(false);
  1091. expect(activeState[1]).toBe(false);
  1092. expect(activeState[2]).toBe(true);
  1093. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1094. expect(maxBitrates[0]).toBe(2500000);
  1095. expect(maxBitrates[1]).toBe(2500000);
  1096. expect(maxBitrates[2]).toBe(2500000);
  1097. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1098. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  1099. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  1100. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  1101. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1102. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1103. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1104. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1105. });
  1106. it('and requested resolution is 0', () => {
  1107. height = 0;
  1108. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1109. expect(activeState[0]).toBe(false);
  1110. expect(activeState[1]).toBe(false);
  1111. expect(activeState[2]).toBe(false);
  1112. });
  1113. });
  1114. describe('H.264 high fps desktop tracks', () => {
  1115. const codec = CodecMimeType.H264;
  1116. const track = new MockJitsiLocalTrack(1440, 'video', 'desktop');
  1117. beforeEach(() => {
  1118. pc = new MockPeerConnection('1', true, true /* simulcast */);
  1119. pc._capScreenshareBitrate = false;
  1120. pc.options = { videoQuality };
  1121. pc.videoTransferActive = true;
  1122. tpcUtils = new TPCUtils(pc);
  1123. });
  1124. afterEach(() => {
  1125. pc = null;
  1126. tpcUtils = null;
  1127. });
  1128. it('and requested resolution is 2160', () => {
  1129. height = 2160;
  1130. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1131. expect(activeState[0]).toBe(true);
  1132. expect(activeState[1]).toBe(true);
  1133. expect(activeState[2]).toBe(true);
  1134. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1135. expect(maxBitrates[0]).toBe(400000);
  1136. expect(maxBitrates[1]).toBe(800000);
  1137. expect(maxBitrates[2]).toBe(2500000);
  1138. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1139. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  1140. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  1141. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  1142. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1143. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1144. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1145. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1146. });
  1147. it('and requested resolution is 0', () => {
  1148. height = 0;
  1149. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1150. expect(activeState[0]).toBe(false);
  1151. expect(activeState[1]).toBe(false);
  1152. expect(activeState[2]).toBe(false);
  1153. });
  1154. });
  1155. describe('H.264 camera tracks for p2p', () => {
  1156. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  1157. const codec = CodecMimeType.H264;
  1158. beforeEach(() => {
  1159. pc = new MockPeerConnection('1', true, false /* simulcast */);
  1160. pc.options = { videoQuality };
  1161. pc.videoTransferActive = true;
  1162. tpcUtils = new TPCUtils(pc);
  1163. });
  1164. afterEach(() => {
  1165. pc = null;
  1166. tpcUtils = null;
  1167. });
  1168. it('and requested resolution is 720', () => {
  1169. height = 720;
  1170. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1171. expect(activeState[0]).toBe(true);
  1172. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1173. expect(maxBitrates[0]).toBe(2000000);
  1174. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1175. expect(scalabilityModes).toBe(undefined);
  1176. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1177. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  1178. });
  1179. it('and requested resolution is 360', () => {
  1180. height = 360;
  1181. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1182. expect(activeState[0]).toBe(true);
  1183. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1184. expect(maxBitrates[0]).toBe(800000);
  1185. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1186. expect(scalabilityModes).toBe(undefined);
  1187. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1188. expect(scaleFactor[0]).toBe(SIM_LAYERS[1].scaleFactor);
  1189. });
  1190. it('and requested resolution is 180', () => {
  1191. height = 180;
  1192. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1193. expect(activeState[0]).toBe(true);
  1194. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1195. expect(maxBitrates[0]).toBe(400000);
  1196. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1197. expect(scalabilityModes).toBe(undefined);
  1198. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1199. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1200. });
  1201. it('and requested resolution is 0', () => {
  1202. height = 0;
  1203. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1204. expect(activeState[0]).toBe(false);
  1205. });
  1206. });
  1207. describe('H.264 desktop tracks for p2p', () => {
  1208. const track = new MockJitsiLocalTrack(720, 'video', 'desktop');
  1209. const codec = CodecMimeType.H264;
  1210. beforeEach(() => {
  1211. pc = new MockPeerConnection('1', true, false /* simulcast */);
  1212. pc.options = { videoQuality };
  1213. pc.videoTransferActive = true;
  1214. tpcUtils = new TPCUtils(pc);
  1215. });
  1216. afterEach(() => {
  1217. pc = null;
  1218. tpcUtils = null;
  1219. });
  1220. it('and requested resolution is 2160', () => {
  1221. height = 2160;
  1222. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1223. expect(activeState[0]).toBe(true);
  1224. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1225. expect(maxBitrates[0]).toBe(2500000);
  1226. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1227. expect(scalabilityModes).toBe(undefined);
  1228. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1229. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  1230. });
  1231. it('and requested resolution is 0', () => {
  1232. height = 0;
  1233. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1234. expect(activeState[0]).toBe(false);
  1235. });
  1236. });
  1237. describe('VP8 camera tracks', () => {
  1238. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  1239. const codec = CodecMimeType.VP8;
  1240. beforeEach(() => {
  1241. pc = new MockPeerConnection('1', true, true /* simulcast */);
  1242. pc.options = { videoQuality };
  1243. pc.videoTransferActive = true;
  1244. tpcUtils = new TPCUtils(pc);
  1245. });
  1246. afterEach(() => {
  1247. pc = null;
  1248. tpcUtils = null;
  1249. });
  1250. it('and requested resolution is 720', () => {
  1251. height = 720;
  1252. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1253. expect(activeState[0]).toBe(true);
  1254. expect(activeState[1]).toBe(true);
  1255. expect(activeState[2]).toBe(true);
  1256. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1257. expect(maxBitrates[0]).toBe(200000);
  1258. expect(maxBitrates[1]).toBe(500000);
  1259. expect(maxBitrates[2]).toBe(1500000);
  1260. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1261. expect(scalabilityModes).toBe(undefined);
  1262. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1263. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1264. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1265. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1266. });
  1267. it('and requested resolution is 360', () => {
  1268. height = 360;
  1269. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1270. expect(activeState[0]).toBe(true);
  1271. expect(activeState[1]).toBe(true);
  1272. expect(activeState[2]).toBe(false);
  1273. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1274. expect(maxBitrates[0]).toBe(200000);
  1275. expect(maxBitrates[1]).toBe(500000);
  1276. expect(maxBitrates[2]).toBe(1500000);
  1277. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1278. expect(scalabilityModes).toBe(undefined);
  1279. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1280. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1281. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1282. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1283. });
  1284. it('and requested resolution is 180', () => {
  1285. height = 180;
  1286. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1287. expect(activeState[0]).toBe(true);
  1288. expect(activeState[1]).toBe(false);
  1289. expect(activeState[2]).toBe(false);
  1290. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1291. expect(maxBitrates[0]).toBe(200000);
  1292. expect(maxBitrates[1]).toBe(500000);
  1293. expect(maxBitrates[2]).toBe(1500000);
  1294. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1295. expect(scalabilityModes).toBe(undefined);
  1296. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1297. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1298. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1299. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1300. });
  1301. it('and requested resolution is 0', () => {
  1302. height = 0;
  1303. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1304. expect(activeState[0]).toBe(false);
  1305. expect(activeState[1]).toBe(false);
  1306. expect(activeState[2]).toBe(false);
  1307. });
  1308. it('and capture resolution is 4k', () => {
  1309. height = 180;
  1310. const highResolutiontrack = new MockJitsiLocalTrack(2160, 'video', 'camera');
  1311. activeState = tpcUtils.calculateEncodingsActiveState(highResolutiontrack, codec, height);
  1312. expect(activeState[0]).toBe(true);
  1313. expect(activeState[1]).toBe(false);
  1314. expect(activeState[2]).toBe(false);
  1315. maxBitrates = tpcUtils.calculateEncodingsBitrates(highResolutiontrack, codec, height);
  1316. expect(maxBitrates[0]).toBe(200000);
  1317. expect(maxBitrates[1]).toBe(500000);
  1318. expect(maxBitrates[2]).toBe(6000000);
  1319. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(highResolutiontrack, codec, height);
  1320. expect(scalabilityModes).toBe(undefined);
  1321. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(highResolutiontrack, codec, height);
  1322. expect(scaleFactor[0]).toBe(12);
  1323. expect(scaleFactor[1]).toBe(6);
  1324. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1325. });
  1326. });
  1327. describe('VP8 low fps desktop tracks', () => {
  1328. const codec = CodecMimeType.VP8;
  1329. const track = new MockJitsiLocalTrack(1440, 'video', 'desktop');
  1330. beforeEach(() => {
  1331. pc = new MockPeerConnection('1', true, true /* simulcast */);
  1332. pc._capScreenshareBitrate = true;
  1333. pc.options = { videoQuality };
  1334. pc.videoTransferActive = true;
  1335. tpcUtils = new TPCUtils(pc);
  1336. });
  1337. afterEach(() => {
  1338. pc = null;
  1339. tpcUtils = null;
  1340. });
  1341. it('and requested resolution is 2160', () => {
  1342. height = 2160;
  1343. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1344. expect(activeState[0]).toBe(false);
  1345. expect(activeState[1]).toBe(false);
  1346. expect(activeState[2]).toBe(true);
  1347. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1348. expect(maxBitrates[0]).toBe(2500000);
  1349. expect(maxBitrates[1]).toBe(2500000);
  1350. expect(maxBitrates[2]).toBe(2500000);
  1351. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1352. expect(scalabilityModes).toBe(undefined);
  1353. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1354. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1355. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1356. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1357. });
  1358. it('and requested resolution is 0', () => {
  1359. height = 0;
  1360. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1361. expect(activeState[0]).toBe(false);
  1362. expect(activeState[1]).toBe(false);
  1363. expect(activeState[2]).toBe(false);
  1364. });
  1365. });
  1366. describe('VP8 high fps desktop tracks', () => {
  1367. const codec = CodecMimeType.VP8;
  1368. const track = new MockJitsiLocalTrack(1440, 'video', 'desktop');
  1369. beforeEach(() => {
  1370. pc = new MockPeerConnection('1', true, true /* simulcast */);
  1371. pc._capScreenshareBitrate = false;
  1372. pc.options = { videoQuality };
  1373. pc.videoTransferActive = true;
  1374. tpcUtils = new TPCUtils(pc);
  1375. });
  1376. afterEach(() => {
  1377. pc = null;
  1378. tpcUtils = null;
  1379. });
  1380. it('and requested resolution is 2160', () => {
  1381. height = 2160;
  1382. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1383. expect(activeState[0]).toBe(true);
  1384. expect(activeState[1]).toBe(true);
  1385. expect(activeState[2]).toBe(true);
  1386. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1387. expect(maxBitrates[0]).toBe(200000);
  1388. expect(maxBitrates[1]).toBe(500000);
  1389. expect(maxBitrates[2]).toBe(2500000);
  1390. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1391. expect(scalabilityModes).toBe(undefined);
  1392. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1393. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1394. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1395. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1396. });
  1397. it('and requested resolution is 0', () => {
  1398. height = 0;
  1399. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1400. expect(activeState[0]).toBe(false);
  1401. expect(activeState[1]).toBe(false);
  1402. expect(activeState[2]).toBe(false);
  1403. });
  1404. });
  1405. describe('VP8 camera tracks for p2p', () => {
  1406. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  1407. const codec = CodecMimeType.VP8;
  1408. beforeEach(() => {
  1409. pc = new MockPeerConnection('1', true, false /* simulcast */);
  1410. pc.options = { videoQuality };
  1411. pc.videoTransferActive = true;
  1412. tpcUtils = new TPCUtils(pc);
  1413. });
  1414. afterEach(() => {
  1415. pc = null;
  1416. tpcUtils = null;
  1417. });
  1418. it('and requested resolution is 720', () => {
  1419. height = 720;
  1420. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1421. expect(activeState[0]).toBe(true);
  1422. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1423. expect(maxBitrates[0]).toBe(1500000);
  1424. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1425. expect(scalabilityModes).toBe(undefined);
  1426. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1427. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  1428. });
  1429. it('and requested resolution is 360', () => {
  1430. height = 360;
  1431. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1432. expect(activeState[0]).toBe(true);
  1433. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1434. expect(maxBitrates[0]).toBe(500000);
  1435. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1436. expect(scalabilityModes).toBe(undefined);
  1437. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1438. expect(scaleFactor[0]).toBe(SIM_LAYERS[1].scaleFactor);
  1439. });
  1440. it('and requested resolution is 180', () => {
  1441. height = 180;
  1442. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1443. expect(activeState[0]).toBe(true);
  1444. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1445. expect(maxBitrates[0]).toBe(200000);
  1446. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1447. expect(scalabilityModes).toBe(undefined);
  1448. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1449. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1450. });
  1451. it('and requested resolution is 0', () => {
  1452. height = 0;
  1453. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1454. expect(activeState[0]).toBe(false);
  1455. });
  1456. });
  1457. describe('VP8 desktop tracks for p2p', () => {
  1458. const track = new MockJitsiLocalTrack(720, 'video', 'desktop');
  1459. const codec = CodecMimeType.VP8;
  1460. beforeEach(() => {
  1461. pc = new MockPeerConnection('1', true, false /* simulcast */);
  1462. pc.options = { videoQuality };
  1463. pc.videoTransferActive = true;
  1464. tpcUtils = new TPCUtils(pc);
  1465. });
  1466. afterEach(() => {
  1467. pc = null;
  1468. tpcUtils = null;
  1469. });
  1470. it('and requested resolution is 2160', () => {
  1471. height = 2160;
  1472. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1473. expect(activeState[0]).toBe(true);
  1474. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1475. expect(maxBitrates[0]).toBe(2500000);
  1476. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1477. expect(scalabilityModes).toBe(undefined);
  1478. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1479. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  1480. });
  1481. it('and requested resolution is 180', () => {
  1482. height = 2160;
  1483. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1484. expect(activeState[0]).toBe(true);
  1485. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1486. expect(maxBitrates[0]).toBe(2500000);
  1487. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1488. expect(scalabilityModes).toBe(undefined);
  1489. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1490. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  1491. });
  1492. it('and requested resolution is 2160 again', () => {
  1493. height = 2160;
  1494. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1495. expect(activeState[0]).toBe(true);
  1496. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1497. expect(maxBitrates[0]).toBe(2500000);
  1498. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1499. expect(scalabilityModes).toBe(undefined);
  1500. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1501. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  1502. });
  1503. it('and requested resolution is 0', () => {
  1504. height = 0;
  1505. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1506. expect(activeState[0]).toBe(false);
  1507. });
  1508. });
  1509. describe('VP8 high fps desktop tracks for p2p', () => {
  1510. const track = new MockJitsiLocalTrack(720, 'video', 'desktop');
  1511. const codec = CodecMimeType.VP8;
  1512. beforeEach(() => {
  1513. pc = new MockPeerConnection('1', true, false /* simulcast */);
  1514. pc.options = { videoQuality };
  1515. pc._capScreenshareBitrate = false;
  1516. pc.videoTransferActive = true;
  1517. tpcUtils = new TPCUtils(pc);
  1518. });
  1519. afterEach(() => {
  1520. pc = null;
  1521. tpcUtils = null;
  1522. });
  1523. it('and requested resolution is 2160', () => {
  1524. height = 2160;
  1525. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1526. expect(activeState[0]).toBe(true);
  1527. maxBitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1528. expect(maxBitrates[0]).toBe(2500000);
  1529. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1530. expect(scalabilityModes).toBe(undefined);
  1531. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1532. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  1533. });
  1534. it('and requested resolution is 0', () => {
  1535. height = 0;
  1536. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1537. expect(activeState[0]).toBe(false);
  1538. });
  1539. });
  1540. });
  1541. describe('Test encodings when settings are overwritten', () => {
  1542. let pc, tpcUtils;
  1543. let activeState, bitrates, height, scalabilityModes, scaleFactor;
  1544. afterEach(() => {
  1545. activeState = null;
  1546. height = null;
  1547. bitrates = null;
  1548. scalabilityModes = null;
  1549. scaleFactor = null;
  1550. });
  1551. describe('for AV1 camera tracks when simulcast is configured', () => {
  1552. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  1553. const codec = CodecMimeType.AV1;
  1554. // Configure AV1 to run in simulcast mode.
  1555. const videoQuality = {
  1556. av1: {
  1557. maxBitratesVideo: {
  1558. low: 300000,
  1559. standard: 600000,
  1560. high: 2000000,
  1561. ssHigh: 2500000
  1562. },
  1563. useSimulcast: true
  1564. }
  1565. };
  1566. beforeEach(() => {
  1567. pc = new MockPeerConnection('1', true, true /* simulcast */);
  1568. pc.options = { videoQuality };
  1569. pc.videoTransferActive = true;
  1570. tpcUtils = new TPCUtils(pc);
  1571. });
  1572. afterEach(() => {
  1573. pc = null;
  1574. tpcUtils = null;
  1575. });
  1576. it('and requested resolution is 720', () => {
  1577. height = 720;
  1578. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1579. expect(activeState[0]).toBe(true);
  1580. expect(activeState[1]).toBe(true);
  1581. expect(activeState[2]).toBe(true);
  1582. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1583. expect(bitrates[0]).toBe(300000);
  1584. expect(bitrates[1]).toBe(600000);
  1585. expect(bitrates[2]).toBe(2000000);
  1586. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1587. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  1588. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  1589. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  1590. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1591. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1592. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1593. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1594. });
  1595. it('and requested resolution is 360', () => {
  1596. height = 360;
  1597. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1598. expect(activeState[0]).toBe(true);
  1599. expect(activeState[1]).toBe(true);
  1600. expect(activeState[2]).toBe(false);
  1601. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1602. expect(bitrates[0]).toBe(300000);
  1603. expect(bitrates[1]).toBe(600000);
  1604. expect(bitrates[2]).toBe(2000000);
  1605. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1606. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  1607. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  1608. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  1609. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1610. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1611. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1612. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1613. });
  1614. it('and requested resolution is 180', () => {
  1615. height = 180;
  1616. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1617. expect(activeState[0]).toBe(true);
  1618. expect(activeState[1]).toBe(false);
  1619. expect(activeState[2]).toBe(false);
  1620. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1621. expect(bitrates[0]).toBe(300000);
  1622. expect(bitrates[1]).toBe(600000);
  1623. expect(bitrates[2]).toBe(2000000);
  1624. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1625. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  1626. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  1627. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  1628. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1629. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1630. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1631. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1632. });
  1633. it('and requested resolution is 0', () => {
  1634. height = 0;
  1635. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1636. expect(activeState[0]).toBe(false);
  1637. expect(activeState[1]).toBe(false);
  1638. expect(activeState[2]).toBe(false);
  1639. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1640. expect(bitrates[0]).toBe(300000);
  1641. expect(bitrates[1]).toBe(600000);
  1642. expect(bitrates[2]).toBe(2000000);
  1643. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1644. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  1645. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  1646. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  1647. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1648. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1649. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1650. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1651. });
  1652. });
  1653. describe('for VP9 camera tracks when simulcast is configured', () => {
  1654. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  1655. const codec = CodecMimeType.VP9;
  1656. // Configure VP9 to run in simulcast mode.
  1657. const videoQuality = {
  1658. vp9: {
  1659. maxBitratesVideo: {
  1660. low: 300000,
  1661. standard: 600000,
  1662. high: 2000000,
  1663. ssHigh: 2500000
  1664. },
  1665. useSimulcast: true
  1666. }
  1667. };
  1668. beforeEach(() => {
  1669. pc = new MockPeerConnection('1', true, true /* simulcast */);
  1670. pc.options = { videoQuality };
  1671. pc.videoTransferActive = true;
  1672. tpcUtils = new TPCUtils(pc);
  1673. });
  1674. afterEach(() => {
  1675. pc = null;
  1676. tpcUtils = null;
  1677. });
  1678. it('and requested resolution is 720', () => {
  1679. height = 720;
  1680. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1681. expect(activeState[0]).toBe(true);
  1682. expect(activeState[1]).toBe(true);
  1683. expect(activeState[2]).toBe(true);
  1684. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1685. expect(bitrates[0]).toBe(300000);
  1686. expect(bitrates[1]).toBe(600000);
  1687. expect(bitrates[2]).toBe(2000000);
  1688. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1689. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  1690. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  1691. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  1692. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1693. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1694. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1695. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1696. });
  1697. it('and requested resolution is 360', () => {
  1698. height = 360;
  1699. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1700. expect(activeState[0]).toBe(true);
  1701. expect(activeState[1]).toBe(true);
  1702. expect(activeState[2]).toBe(false);
  1703. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1704. expect(bitrates[0]).toBe(300000);
  1705. expect(bitrates[1]).toBe(600000);
  1706. expect(bitrates[2]).toBe(2000000);
  1707. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1708. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  1709. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  1710. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  1711. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1712. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1713. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1714. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1715. });
  1716. it('and requested resolution is 180', () => {
  1717. height = 180;
  1718. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1719. expect(activeState[0]).toBe(true);
  1720. expect(activeState[1]).toBe(false);
  1721. expect(activeState[2]).toBe(false);
  1722. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1723. expect(bitrates[0]).toBe(300000);
  1724. expect(bitrates[1]).toBe(600000);
  1725. expect(bitrates[2]).toBe(2000000);
  1726. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1727. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  1728. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  1729. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  1730. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1731. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1732. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1733. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1734. });
  1735. it('and requested resolution is 0', () => {
  1736. height = 0;
  1737. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1738. expect(activeState[0]).toBe(false);
  1739. expect(activeState[1]).toBe(false);
  1740. expect(activeState[2]).toBe(false);
  1741. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1742. expect(bitrates[0]).toBe(300000);
  1743. expect(bitrates[1]).toBe(600000);
  1744. expect(bitrates[2]).toBe(2000000);
  1745. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1746. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  1747. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  1748. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  1749. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1750. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1751. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1752. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1753. });
  1754. });
  1755. describe('for VP9 camera tracks and scalabilityMode is disabled', () => {
  1756. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  1757. const codec = CodecMimeType.VP9;
  1758. // Configure VP9 to run in K-SVC mode.
  1759. const videoQuality = {
  1760. vp9: {
  1761. scalabilityModeEnabled: false
  1762. }
  1763. };
  1764. beforeEach(() => {
  1765. pc = new MockPeerConnection('1', true, true /* simulcast */);
  1766. pc.options = { videoQuality };
  1767. pc.videoTransferActive = true;
  1768. tpcUtils = new TPCUtils(pc);
  1769. });
  1770. afterEach(() => {
  1771. pc = null;
  1772. tpcUtils = null;
  1773. });
  1774. it('and requested resolution is 720', () => {
  1775. height = 720;
  1776. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1777. expect(activeState[0]).toBe(true);
  1778. expect(activeState[1]).toBe(true);
  1779. expect(activeState[2]).toBe(true);
  1780. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1781. expect(bitrates[0]).toBe(100000);
  1782. expect(bitrates[1]).toBe(300000);
  1783. expect(bitrates[2]).toBe(1200000);
  1784. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1785. expect(scalabilityModes).toBe(undefined);
  1786. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1787. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1788. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1789. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1790. });
  1791. it('and requested resolution is 360', () => {
  1792. height = 360;
  1793. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1794. expect(activeState[0]).toBe(true);
  1795. expect(activeState[1]).toBe(true);
  1796. expect(activeState[2]).toBe(false);
  1797. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1798. expect(bitrates[0]).toBe(100000);
  1799. expect(bitrates[1]).toBe(300000);
  1800. expect(bitrates[2]).toBe(1200000);
  1801. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1802. expect(scalabilityModes).toBe(undefined);
  1803. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1804. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1805. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1806. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1807. });
  1808. it('and requested resolution is 180', () => {
  1809. height = 180;
  1810. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1811. expect(activeState[0]).toBe(true);
  1812. expect(activeState[1]).toBe(false);
  1813. expect(activeState[2]).toBe(false);
  1814. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1815. expect(bitrates[0]).toBe(100000);
  1816. expect(bitrates[1]).toBe(300000);
  1817. expect(bitrates[2]).toBe(1200000);
  1818. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1819. expect(scalabilityModes).toBe(undefined);
  1820. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1821. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1822. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1823. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1824. });
  1825. it('and requested resolution is 0', () => {
  1826. height = 0;
  1827. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1828. expect(activeState[0]).toBe(false);
  1829. expect(activeState[1]).toBe(false);
  1830. expect(activeState[2]).toBe(false);
  1831. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1832. expect(bitrates[0]).toBe(100000);
  1833. expect(bitrates[1]).toBe(300000);
  1834. expect(bitrates[2]).toBe(1200000);
  1835. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1836. expect(scalabilityModes).toBe(undefined);
  1837. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1838. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1839. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1840. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1841. });
  1842. });
  1843. describe('for VP9 camera tracks and scalabilityMode is disabled', () => {
  1844. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  1845. const codec = CodecMimeType.VP9;
  1846. // Configure VP9 to run in K-SVC mode.
  1847. const videoQuality = {
  1848. vp9: {
  1849. scalabilityModeEnabled: false
  1850. }
  1851. };
  1852. beforeEach(() => {
  1853. pc = new MockPeerConnection('1', true, true /* simulcast */);
  1854. pc.options = { videoQuality };
  1855. pc.videoTransferActive = true;
  1856. tpcUtils = new TPCUtils(pc);
  1857. });
  1858. afterEach(() => {
  1859. pc = null;
  1860. tpcUtils = null;
  1861. });
  1862. it('and requested resolution is 720', () => {
  1863. height = 720;
  1864. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1865. expect(activeState[0]).toBe(true);
  1866. expect(activeState[1]).toBe(true);
  1867. expect(activeState[2]).toBe(true);
  1868. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1869. expect(bitrates[0]).toBe(100000);
  1870. expect(bitrates[1]).toBe(300000);
  1871. expect(bitrates[2]).toBe(1200000);
  1872. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1873. expect(scalabilityModes).toBe(undefined);
  1874. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1875. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1876. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1877. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1878. });
  1879. it('and requested resolution is 360', () => {
  1880. height = 360;
  1881. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1882. expect(activeState[0]).toBe(true);
  1883. expect(activeState[1]).toBe(true);
  1884. expect(activeState[2]).toBe(false);
  1885. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1886. expect(bitrates[0]).toBe(100000);
  1887. expect(bitrates[1]).toBe(300000);
  1888. expect(bitrates[2]).toBe(1200000);
  1889. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1890. expect(scalabilityModes).toBe(undefined);
  1891. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1892. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1893. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1894. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1895. });
  1896. it('and requested resolution is 180', () => {
  1897. height = 180;
  1898. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1899. expect(activeState[0]).toBe(true);
  1900. expect(activeState[1]).toBe(false);
  1901. expect(activeState[2]).toBe(false);
  1902. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1903. expect(bitrates[0]).toBe(100000);
  1904. expect(bitrates[1]).toBe(300000);
  1905. expect(bitrates[2]).toBe(1200000);
  1906. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1907. expect(scalabilityModes).toBe(undefined);
  1908. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1909. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1910. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1911. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1912. });
  1913. it('and requested resolution is 0', () => {
  1914. height = 0;
  1915. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1916. expect(activeState[0]).toBe(false);
  1917. expect(activeState[1]).toBe(false);
  1918. expect(activeState[2]).toBe(false);
  1919. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1920. expect(bitrates[0]).toBe(100000);
  1921. expect(bitrates[1]).toBe(300000);
  1922. expect(bitrates[2]).toBe(1200000);
  1923. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1924. expect(scalabilityModes).toBe(undefined);
  1925. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1926. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1927. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1928. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1929. });
  1930. });
  1931. describe('for VP9 low fps desktop tracks and scalabilityMode is disabled', () => {
  1932. const track = new MockJitsiLocalTrack(440, 'video', 'desktop');
  1933. const codec = CodecMimeType.VP9;
  1934. // Configure VP9 to run in K-SVC mode.
  1935. const videoQuality = {
  1936. vp9: {
  1937. scalabilityModeEnabled: false
  1938. }
  1939. };
  1940. beforeEach(() => {
  1941. pc = new MockPeerConnection('1', true, true /* simulcast */);
  1942. pc.options = { videoQuality };
  1943. pc._capScreenshareBitrate = true;
  1944. pc.videoTransferActive = true;
  1945. tpcUtils = new TPCUtils(pc);
  1946. });
  1947. afterEach(() => {
  1948. pc = null;
  1949. tpcUtils = null;
  1950. });
  1951. it('and requested resolution is 2160', () => {
  1952. height = 2160;
  1953. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1954. expect(activeState[0]).toBe(false);
  1955. expect(activeState[1]).toBe(false);
  1956. expect(activeState[2]).toBe(true);
  1957. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1958. expect(bitrates[0]).toBe(2500000);
  1959. expect(bitrates[1]).toBe(2500000);
  1960. expect(bitrates[2]).toBe(2500000);
  1961. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1962. expect(scalabilityModes).toBe(undefined);
  1963. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1964. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1965. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1966. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1967. });
  1968. it('and requested resolution is 0', () => {
  1969. height = 0;
  1970. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  1971. expect(activeState[0]).toBe(false);
  1972. expect(activeState[1]).toBe(false);
  1973. expect(activeState[2]).toBe(false);
  1974. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  1975. expect(bitrates[0]).toBe(2500000);
  1976. expect(bitrates[1]).toBe(2500000);
  1977. expect(bitrates[2]).toBe(2500000);
  1978. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  1979. expect(scalabilityModes).toBe(undefined);
  1980. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  1981. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  1982. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  1983. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  1984. });
  1985. });
  1986. describe('for VP9 high fps desktop tracks and scalabilityMode is disabled', () => {
  1987. const track = new MockJitsiLocalTrack(560, 'video', 'desktop');
  1988. const codec = CodecMimeType.VP9;
  1989. // Configure VP9 to run in K-SVC mode.
  1990. const videoQuality = {
  1991. vp9: {
  1992. scalabilityModeEnabled: false
  1993. }
  1994. };
  1995. beforeEach(() => {
  1996. pc = new MockPeerConnection('1', true, true /* simulcast */);
  1997. pc.options = { videoQuality };
  1998. pc._capScreenshareBitrate = false;
  1999. pc.videoTransferActive = true;
  2000. tpcUtils = new TPCUtils(pc);
  2001. });
  2002. afterEach(() => {
  2003. pc = null;
  2004. tpcUtils = null;
  2005. });
  2006. it('and requested resolution is 2160', () => {
  2007. height = 2160;
  2008. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2009. expect(activeState[0]).toBe(true);
  2010. expect(activeState[1]).toBe(true);
  2011. expect(activeState[2]).toBe(true);
  2012. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  2013. expect(bitrates[0]).toBe(100000);
  2014. expect(bitrates[1]).toBe(300000);
  2015. expect(bitrates[2]).toBe(2500000);
  2016. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  2017. expect(scalabilityModes).toBe(undefined);
  2018. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  2019. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  2020. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  2021. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  2022. });
  2023. it('and requested resolution is 0', () => {
  2024. height = 0;
  2025. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2026. expect(activeState[0]).toBe(false);
  2027. expect(activeState[1]).toBe(false);
  2028. expect(activeState[2]).toBe(false);
  2029. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  2030. expect(bitrates[0]).toBe(100000);
  2031. expect(bitrates[1]).toBe(300000);
  2032. expect(bitrates[2]).toBe(2500000);
  2033. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  2034. expect(scalabilityModes).toBe(undefined);
  2035. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  2036. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  2037. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  2038. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  2039. });
  2040. });
  2041. describe('for H.264 camera tracks, scalability mode is disabled', () => {
  2042. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  2043. const codec = CodecMimeType.H264;
  2044. // Configure VP9 to run in simulcast mode.
  2045. const videoQuality = {
  2046. h264: {
  2047. scalabilityModeEnabled: false
  2048. }
  2049. };
  2050. beforeEach(() => {
  2051. pc = new MockPeerConnection('1', true, false /* simulcast */);
  2052. pc.options = { videoQuality };
  2053. pc.videoTransferActive = true;
  2054. tpcUtils = new TPCUtils(pc);
  2055. });
  2056. afterEach(() => {
  2057. pc = null;
  2058. tpcUtils = null;
  2059. });
  2060. it('and requested resolution is 720', () => {
  2061. height = 720;
  2062. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2063. expect(activeState[0]).toBe(true);
  2064. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  2065. expect(bitrates[0]).toBe(2000000);
  2066. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  2067. expect(scalabilityModes).toBe(undefined);
  2068. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  2069. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  2070. });
  2071. it('and requested resolution is 360', () => {
  2072. height = 360;
  2073. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2074. expect(activeState[0]).toBe(true);
  2075. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  2076. expect(bitrates[0]).toBe(800000);
  2077. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  2078. expect(scalabilityModes).toBe(undefined);
  2079. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  2080. expect(scaleFactor[0]).toBe(SIM_LAYERS[1].scaleFactor);
  2081. });
  2082. it('and requested resolution is 180', () => {
  2083. height = 180;
  2084. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2085. expect(activeState[0]).toBe(true);
  2086. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  2087. expect(bitrates[0]).toBe(400000);
  2088. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  2089. expect(scalabilityModes).toBe(undefined);
  2090. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  2091. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  2092. });
  2093. it('and requested resolution is 0', () => {
  2094. height = 0;
  2095. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2096. expect(activeState[0]).toBe(false);
  2097. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  2098. expect(scalabilityModes).toBe(undefined);
  2099. });
  2100. });
  2101. describe('for VP9 camera tracks when deprecated settings are used for overriding bitrates', () => {
  2102. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  2103. const codec = CodecMimeType.VP9;
  2104. // Configure VP9 bitrates using the deprecated settings.
  2105. const videoQuality = {
  2106. maxbitratesvideo: {
  2107. VP9: {
  2108. low: 300000,
  2109. standard: 600000,
  2110. high: 2000000
  2111. }
  2112. }
  2113. };
  2114. beforeEach(() => {
  2115. pc = new MockPeerConnection('1', true, true /* simulcast */);
  2116. pc.options = { videoQuality };
  2117. pc.videoTransferActive = true;
  2118. tpcUtils = new TPCUtils(pc);
  2119. });
  2120. afterEach(() => {
  2121. pc = null;
  2122. tpcUtils = null;
  2123. });
  2124. it('and requested resolution is 720', () => {
  2125. height = 720;
  2126. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2127. expect(activeState[0]).toBe(true);
  2128. expect(activeState[1]).toBe(false);
  2129. expect(activeState[2]).toBe(false);
  2130. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  2131. expect(bitrates[0]).toBe(2000000);
  2132. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  2133. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L3T3_KEY);
  2134. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  2135. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  2136. });
  2137. it('and requested resolution is 360', () => {
  2138. height = 360;
  2139. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2140. expect(activeState[0]).toBe(true);
  2141. expect(activeState[1]).toBe(false);
  2142. expect(activeState[2]).toBe(false);
  2143. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  2144. expect(bitrates[0]).toBe(600000);
  2145. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  2146. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L2T3_KEY);
  2147. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  2148. expect(scaleFactor[0]).toBe(SIM_LAYERS[1].scaleFactor);
  2149. });
  2150. it('and requested resolution is 180', () => {
  2151. height = 180;
  2152. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2153. expect(activeState[0]).toBe(true);
  2154. expect(activeState[1]).toBe(false);
  2155. expect(activeState[2]).toBe(false);
  2156. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  2157. expect(bitrates[0]).toBe(300000);
  2158. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  2159. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  2160. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  2161. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  2162. });
  2163. it('and requested resolution is 0', () => {
  2164. height = 0;
  2165. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2166. expect(activeState[0]).toBe(false);
  2167. expect(activeState[1]).toBe(false);
  2168. expect(activeState[2]).toBe(false);
  2169. });
  2170. });
  2171. describe('for VP9 camera tracks when L3T3 mode is used', () => {
  2172. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  2173. const codec = CodecMimeType.VP9;
  2174. // Configure VP9 to use SVC mode instead of the K-SVC mode.
  2175. const videoQuality = {
  2176. vp9: {
  2177. useKSVC: false
  2178. }
  2179. };
  2180. beforeEach(() => {
  2181. pc = new MockPeerConnection('1', true, true /* simulcast */);
  2182. pc.options = { videoQuality };
  2183. pc.videoTransferActive = true;
  2184. tpcUtils = new TPCUtils(pc);
  2185. });
  2186. afterEach(() => {
  2187. pc = null;
  2188. tpcUtils = null;
  2189. });
  2190. it('and requested resolution is 720', () => {
  2191. height = 720;
  2192. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2193. expect(activeState[0]).toBe(true);
  2194. expect(activeState[1]).toBe(false);
  2195. expect(activeState[2]).toBe(false);
  2196. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  2197. expect(bitrates[0]).toBe(1200000);
  2198. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  2199. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L3T3);
  2200. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  2201. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  2202. });
  2203. it('and requested resolution is 360', () => {
  2204. height = 360;
  2205. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2206. expect(activeState[0]).toBe(true);
  2207. expect(activeState[1]).toBe(false);
  2208. expect(activeState[2]).toBe(false);
  2209. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  2210. expect(bitrates[0]).toBe(300000);
  2211. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  2212. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L2T3);
  2213. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  2214. expect(scaleFactor[0]).toBe(SIM_LAYERS[1].scaleFactor);
  2215. });
  2216. it('and requested resolution is 180', () => {
  2217. height = 180;
  2218. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2219. expect(activeState[0]).toBe(true);
  2220. expect(activeState[1]).toBe(false);
  2221. expect(activeState[2]).toBe(false);
  2222. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  2223. expect(bitrates[0]).toBe(100000);
  2224. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  2225. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  2226. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  2227. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  2228. });
  2229. it('and requested resolution is 0', () => {
  2230. height = 0;
  2231. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2232. expect(activeState[0]).toBe(false);
  2233. expect(activeState[1]).toBe(false);
  2234. expect(activeState[2]).toBe(false);
  2235. });
  2236. });
  2237. describe('for VP9 camera/desktop tracks when simulcast is used', () => {
  2238. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  2239. const desktop = new MockJitsiLocalTrack(1440, 'video', 'desktop');
  2240. const codec = CodecMimeType.VP9;
  2241. // Configure VP9 to use SVC mode instead of the K-SVC mode.
  2242. const videoQuality = {
  2243. vp9: {
  2244. useSimulcast: true
  2245. }
  2246. };
  2247. pc = new MockPeerConnection('1', true, true /* simulcast */);
  2248. pc.options = { videoQuality };
  2249. pc._capScreenshareBitrate = true;
  2250. pc.videoTransferActive = true;
  2251. const utils = new TPCUtils(pc);
  2252. it('and requested desktop resolution is 2160', () => {
  2253. height = 2160;
  2254. activeState = utils.calculateEncodingsActiveState(desktop, codec, height);
  2255. expect(activeState[0]).toBe(false);
  2256. expect(activeState[1]).toBe(false);
  2257. expect(activeState[2]).toBe(true);
  2258. bitrates = utils.calculateEncodingsBitrates(desktop, codec, height);
  2259. expect(bitrates[0]).toBe(2500000);
  2260. expect(bitrates[1]).toBe(2500000);
  2261. expect(bitrates[2]).toBe(2500000);
  2262. scalabilityModes = utils.calculateEncodingsScalabilityMode(desktop, codec, height);
  2263. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  2264. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  2265. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  2266. scaleFactor = utils.calculateEncodingsScaleFactor(desktop, codec, height);
  2267. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  2268. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  2269. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  2270. });
  2271. it('and requested camera resolution is 720', () => {
  2272. height = 720;
  2273. activeState = utils.calculateEncodingsActiveState(track, codec, height);
  2274. expect(activeState[0]).toBe(true);
  2275. expect(activeState[1]).toBe(true);
  2276. expect(activeState[2]).toBe(true);
  2277. bitrates = utils.calculateEncodingsBitrates(track, codec, height);
  2278. expect(bitrates[0]).toBe(100000);
  2279. expect(bitrates[1]).toBe(300000);
  2280. expect(bitrates[2]).toBe(1200000);
  2281. scalabilityModes = utils.calculateEncodingsScalabilityMode(track, codec, height);
  2282. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  2283. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  2284. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  2285. scaleFactor = utils.calculateEncodingsScaleFactor(track, codec, height);
  2286. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  2287. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  2288. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  2289. });
  2290. it('and requested camera resolution is 360', () => {
  2291. height = 360;
  2292. activeState = utils.calculateEncodingsActiveState(track, codec, height);
  2293. expect(activeState[0]).toBe(true);
  2294. expect(activeState[1]).toBe(true);
  2295. expect(activeState[2]).toBe(false);
  2296. bitrates = utils.calculateEncodingsBitrates(track, codec, height);
  2297. expect(bitrates[0]).toBe(100000);
  2298. expect(bitrates[1]).toBe(300000);
  2299. expect(bitrates[2]).toBe(1200000);
  2300. scalabilityModes = utils.calculateEncodingsScalabilityMode(track, codec, height);
  2301. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  2302. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  2303. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  2304. scaleFactor = utils.calculateEncodingsScaleFactor(track, codec, height);
  2305. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  2306. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  2307. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  2308. });
  2309. it('and requested camera resolution is 180', () => {
  2310. height = 180;
  2311. activeState = utils.calculateEncodingsActiveState(track, codec, height);
  2312. expect(activeState[0]).toBe(true);
  2313. expect(activeState[1]).toBe(false);
  2314. expect(activeState[2]).toBe(false);
  2315. bitrates = utils.calculateEncodingsBitrates(track, codec, height);
  2316. expect(bitrates[0]).toBe(100000);
  2317. expect(bitrates[1]).toBe(300000);
  2318. expect(bitrates[2]).toBe(1200000);
  2319. scalabilityModes = utils.calculateEncodingsScalabilityMode(track, codec, height);
  2320. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  2321. expect(scalabilityModes[1]).toBe(VideoEncoderScalabilityMode.L1T3);
  2322. expect(scalabilityModes[2]).toBe(VideoEncoderScalabilityMode.L1T3);
  2323. scaleFactor = utils.calculateEncodingsScaleFactor(track, codec, height);
  2324. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  2325. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  2326. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  2327. });
  2328. it('and requested camera resolution is 0', () => {
  2329. height = 0;
  2330. activeState = utils.calculateEncodingsActiveState(track, codec, height);
  2331. expect(activeState[0]).toBe(false);
  2332. expect(activeState[1]).toBe(false);
  2333. expect(activeState[2]).toBe(false);
  2334. });
  2335. });
  2336. describe('for VP8 camera/desktop tracks when simulcast is used', () => {
  2337. const track = new MockJitsiLocalTrack(2160, 'video', 'camera');
  2338. const desktop = new MockJitsiLocalTrack(1440, 'video', 'desktop');
  2339. const codec = CodecMimeType.VP8;
  2340. const videoQuality = {};
  2341. pc = new MockPeerConnection('1', true, true /* simulcast */);
  2342. pc.options = { videoQuality };
  2343. pc._capScreenshareBitrate = true;
  2344. pc.videoTransferActive = true;
  2345. const utils = new TPCUtils(pc);
  2346. it('and requested desktop resolution is 2160', () => {
  2347. height = 2160;
  2348. activeState = utils.calculateEncodingsActiveState(desktop, codec, height);
  2349. expect(activeState[0]).toBe(false);
  2350. expect(activeState[1]).toBe(false);
  2351. expect(activeState[2]).toBe(true);
  2352. bitrates = utils.calculateEncodingsBitrates(desktop, codec, height);
  2353. expect(bitrates[0]).toBe(2500000);
  2354. expect(bitrates[1]).toBe(2500000);
  2355. expect(bitrates[2]).toBe(2500000);
  2356. scalabilityModes = utils.calculateEncodingsScalabilityMode(desktop, codec, height);
  2357. expect(scalabilityModes).toBe(undefined);
  2358. scaleFactor = utils.calculateEncodingsScaleFactor(desktop, codec, height);
  2359. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  2360. expect(scaleFactor[1]).toBe(SIM_LAYERS[1].scaleFactor);
  2361. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  2362. });
  2363. it('and requested camera resolution is 2160', () => {
  2364. height = 2160;
  2365. activeState = utils.calculateEncodingsActiveState(track, codec, height);
  2366. expect(activeState[0]).toBe(true);
  2367. expect(activeState[1]).toBe(true);
  2368. expect(activeState[2]).toBe(true);
  2369. bitrates = utils.calculateEncodingsBitrates(track, codec, height);
  2370. expect(bitrates[0]).toBe(200000);
  2371. expect(bitrates[1]).toBe(500000);
  2372. expect(bitrates[2]).toBe(6000000);
  2373. scalabilityModes = utils.calculateEncodingsScalabilityMode(track, codec, height);
  2374. expect(scalabilityModes).toBe(undefined);
  2375. scaleFactor = utils.calculateEncodingsScaleFactor(track, codec, height);
  2376. expect(scaleFactor[0]).toBe(12);
  2377. expect(scaleFactor[1]).toBe(6);
  2378. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  2379. });
  2380. it('and requested camera resolution is 360', () => {
  2381. height = 360;
  2382. activeState = utils.calculateEncodingsActiveState(track, codec, height);
  2383. expect(activeState[0]).toBe(true);
  2384. expect(activeState[1]).toBe(true);
  2385. expect(activeState[2]).toBe(false);
  2386. bitrates = utils.calculateEncodingsBitrates(track, codec, height);
  2387. expect(bitrates[0]).toBe(200000);
  2388. expect(bitrates[1]).toBe(500000);
  2389. expect(bitrates[2]).toBe(6000000);
  2390. scalabilityModes = utils.calculateEncodingsScalabilityMode(track, codec, height);
  2391. expect(scalabilityModes).toBe(undefined);
  2392. scaleFactor = utils.calculateEncodingsScaleFactor(track, codec, height);
  2393. expect(scaleFactor[0]).toBe(12);
  2394. expect(scaleFactor[1]).toBe(6);
  2395. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  2396. });
  2397. it('and requested camera resolution is 180', () => {
  2398. height = 180;
  2399. activeState = utils.calculateEncodingsActiveState(track, codec, height);
  2400. expect(activeState[0]).toBe(true);
  2401. expect(activeState[1]).toBe(false);
  2402. expect(activeState[2]).toBe(false);
  2403. bitrates = utils.calculateEncodingsBitrates(track, codec, height);
  2404. expect(bitrates[0]).toBe(200000);
  2405. expect(bitrates[1]).toBe(500000);
  2406. expect(bitrates[2]).toBe(6000000);
  2407. scalabilityModes = utils.calculateEncodingsScalabilityMode(track, codec, height);
  2408. expect(scalabilityModes).toBe(undefined);
  2409. scaleFactor = utils.calculateEncodingsScaleFactor(track, codec, height);
  2410. expect(scaleFactor[0]).toBe(12);
  2411. expect(scaleFactor[1]).toBe(6);
  2412. expect(scaleFactor[2]).toBe(SIM_LAYERS[2].scaleFactor);
  2413. });
  2414. it('and requested camera resolution is 0', () => {
  2415. height = 0;
  2416. activeState = utils.calculateEncodingsActiveState(track, codec, height);
  2417. expect(activeState[0]).toBe(false);
  2418. expect(activeState[1]).toBe(false);
  2419. expect(activeState[2]).toBe(false);
  2420. });
  2421. });
  2422. describe('for VP9 camera tracks and the jvb connection is suspended', () => {
  2423. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  2424. const codec = CodecMimeType.VP9;
  2425. beforeEach(() => {
  2426. pc = new MockPeerConnection('1', true, true /* simulcast */);
  2427. pc.options = {};
  2428. pc.videoTransferActive = false;
  2429. tpcUtils = new TPCUtils(pc);
  2430. });
  2431. afterEach(() => {
  2432. pc = null;
  2433. tpcUtils = null;
  2434. });
  2435. it('and requested resolution is 720', () => {
  2436. height = 720;
  2437. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2438. expect(activeState[0]).toBe(false);
  2439. expect(activeState[1]).toBe(false);
  2440. expect(activeState[2]).toBe(false);
  2441. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  2442. expect(bitrates[0]).toBe(1200000);
  2443. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  2444. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L3T3_KEY);
  2445. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  2446. expect(scaleFactor[0]).toBe(SIM_LAYERS[2].scaleFactor);
  2447. });
  2448. it('and requested resolution is 360', () => {
  2449. height = 360;
  2450. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2451. expect(activeState[0]).toBe(false);
  2452. expect(activeState[1]).toBe(false);
  2453. expect(activeState[2]).toBe(false);
  2454. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  2455. expect(bitrates[0]).toBe(300000);
  2456. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  2457. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L2T3_KEY);
  2458. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  2459. expect(scaleFactor[0]).toBe(SIM_LAYERS[1].scaleFactor);
  2460. });
  2461. it('and requested resolution is 180', () => {
  2462. height = 180;
  2463. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2464. expect(activeState[0]).toBe(false);
  2465. expect(activeState[1]).toBe(false);
  2466. expect(activeState[2]).toBe(false);
  2467. bitrates = tpcUtils.calculateEncodingsBitrates(track, codec, height);
  2468. expect(bitrates[0]).toBe(100000);
  2469. scalabilityModes = tpcUtils.calculateEncodingsScalabilityMode(track, codec, height);
  2470. expect(scalabilityModes[0]).toBe(VideoEncoderScalabilityMode.L1T3);
  2471. scaleFactor = tpcUtils.calculateEncodingsScaleFactor(track, codec, height);
  2472. expect(scaleFactor[0]).toBe(SIM_LAYERS[0].scaleFactor);
  2473. });
  2474. it('and requested resolution is 0', () => {
  2475. height = 0;
  2476. activeState = tpcUtils.calculateEncodingsActiveState(track, codec, height);
  2477. expect(activeState[0]).toBe(false);
  2478. expect(activeState[1]).toBe(false);
  2479. expect(activeState[2]).toBe(false);
  2480. });
  2481. });
  2482. });
  2483. });