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 135KB

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