Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

TPCUtils.spec.js 131KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964
  1. /* eslint-disable max-len */
  2. import { CodecMimeType } from '../../service/RTC/CodecMimeType';
  3. import { SIM_LAYERS } from '../../service/RTC/StandardVideoSettings';
  4. import { VideoEncoderScalabilityMode } from '../../service/RTC/VideoEncoderScalabilityMode';
  5. import { MockJitsiLocalTrack, MockPeerConnection } from './MockClasses';
  6. import { TPCUtils } from './TPCUtils';
  7. describe('TPCUtils', () => {
  8. describe('ensureCorrectOrderOfSsrcs()', () => {
  9. const commonSdpLines = [
  10. 'v=0',
  11. 'o=- 814997227879783433 5 IN IP4 127.0.0.1',
  12. 's=-',
  13. 't=0 0',
  14. 'a=msid-semantic: WMS 0836cc8e-a7bb-47e9-affb-0599414bc56d',
  15. 'a=group:BUNDLE video',
  16. 'm=video 9 RTP/SAVPF 100 96',
  17. 'c=IN IP4 0.0.0.0',
  18. 'a=rtpmap:100 VP8/90000',
  19. 'a=fmtp:96 apt=100',
  20. 'a=rtcp:9 IN IP4 0.0.0.0',
  21. 'a=rtcp-fb:100 ccm fir',
  22. 'a=rtcp-fb:100 nack',
  23. 'a=rtcp-fb:100 nack pli',
  24. 'a=rtcp-fb:100 goog-remb',
  25. 'a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time',
  26. 'a=setup:passive',
  27. 'a=mid:video',
  28. 'a=sendrecv',
  29. 'a=ice-ufrag:adPg',
  30. 'a=ice-pwd:Xsr05Mq8S7CR44DAnusZE26F',
  31. 'a=fingerprint:sha-256 6A:39:DE:11:24:AD:2E:4E:63:D6:69:D3:85:05:53:C7:3C:38:A4:B7:91:74:C0:91:44:FC:94:63:7F:01:AB:A9'
  32. ];
  33. it('sort ssrcs associated with all FID ssrc-groups', () => {
  34. const pc = new MockPeerConnection();
  35. const tpcUtils = new TPCUtils(pc);
  36. const source = new RTCSessionDescription({
  37. type: 'offer',
  38. sdp: getSourceSdp()
  39. });
  40. const result = tpcUtils.ensureCorrectOrderOfSsrcs(source);
  41. expect(result.sdp).toBe(getExpectedSdp());
  42. /**
  43. * Test SDP with multiple FID groups
  44. */
  45. function getSourceSdp() {
  46. return `${[
  47. ...commonSdpLines,
  48. 'a=ssrc:1757014965 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  49. 'a=ssrc:1757014965 cname:peDGrDD6WsxUOki/',
  50. 'a=ssrc:1479742055 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  51. 'a=ssrc:1479742055 cname:peDGrDD6WsxUOki/',
  52. 'a=ssrc:1089111804 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  53. 'a=ssrc:1089111804 cname:peDGrDD6WsxUOki/',
  54. 'a=ssrc:855213044 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  55. 'a=ssrc:855213044 cname:peDGrDD6WsxUOki/',
  56. 'a=ssrc:984899560 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  57. 'a=ssrc:984899560 cname:peDGrDD6WsxUOki/',
  58. 'a=ssrc:2963867077 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  59. 'a=ssrc:2963867077 cname:peDGrDD6WsxUOki/',
  60. 'a=ssrc-group:FID 1757014965 984899560',
  61. 'a=ssrc-group:FID 1479742055 855213044',
  62. 'a=ssrc-group:FID 1089111804 2963867077',
  63. 'a=ssrc-group:SIM 1757014965 1479742055 1089111804',
  64. 'a=rtcp-mux'
  65. ].join('\r\n')}\r\n`;
  66. }
  67. /**
  68. * Expected SDP: all ssrc must be present and ordered
  69. */
  70. function getExpectedSdp() {
  71. return `${[
  72. ...commonSdpLines,
  73. 'a=ssrc:1757014965 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  74. 'a=ssrc:1757014965 cname:peDGrDD6WsxUOki/',
  75. 'a=ssrc:984899560 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  76. 'a=ssrc:984899560 cname:peDGrDD6WsxUOki/',
  77. 'a=ssrc:1479742055 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  78. 'a=ssrc:1479742055 cname:peDGrDD6WsxUOki/',
  79. 'a=ssrc:855213044 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  80. 'a=ssrc:855213044 cname:peDGrDD6WsxUOki/',
  81. 'a=ssrc:1089111804 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  82. 'a=ssrc:1089111804 cname:peDGrDD6WsxUOki/',
  83. 'a=ssrc:2963867077 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  84. 'a=ssrc:2963867077 cname:peDGrDD6WsxUOki/',
  85. 'a=ssrc-group:FID 1757014965 984899560',
  86. 'a=ssrc-group:FID 1479742055 855213044',
  87. 'a=ssrc-group:FID 1089111804 2963867077',
  88. 'a=ssrc-group:SIM 1757014965 1479742055 1089111804',
  89. 'a=rtcp-mux'
  90. ].join('\r\n')}\r\n`;
  91. }
  92. });
  93. it('sort ssrcs in case the first ssrc in the SIM group is not present at the top', () => {
  94. const pc = new MockPeerConnection();
  95. const tpcUtils = new TPCUtils(pc);
  96. const source = new RTCSessionDescription({
  97. type: 'offer',
  98. sdp: getSourceSdp()
  99. });
  100. const result = tpcUtils.ensureCorrectOrderOfSsrcs(source);
  101. expect(result.sdp).toBe(getExpectedSdp());
  102. /**
  103. * Test SDP with multiple FID groups where the first ssrc in the SIM group is not present at the top
  104. */
  105. function getSourceSdp() {
  106. return `${[
  107. ...commonSdpLines,
  108. 'a=ssrc:1479742055 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  109. 'a=ssrc:1479742055 cname:peDGrDD6WsxUOki/',
  110. 'a=ssrc:1757014965 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  111. 'a=ssrc:1757014965 cname:peDGrDD6WsxUOki/',
  112. 'a=ssrc:1089111804 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  113. 'a=ssrc:1089111804 cname:peDGrDD6WsxUOki/',
  114. 'a=ssrc:855213044 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  115. 'a=ssrc:855213044 cname:peDGrDD6WsxUOki/',
  116. 'a=ssrc:984899560 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  117. 'a=ssrc:984899560 cname:peDGrDD6WsxUOki/',
  118. 'a=ssrc:2963867077 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  119. 'a=ssrc:2963867077 cname:peDGrDD6WsxUOki/',
  120. 'a=ssrc-group:FID 1757014965 984899560',
  121. 'a=ssrc-group:FID 1479742055 855213044',
  122. 'a=ssrc-group:FID 1089111804 2963867077',
  123. 'a=ssrc-group:SIM 1757014965 1479742055 1089111804',
  124. 'a=rtcp-mux'
  125. ].join('\r\n')}\r\n`;
  126. }
  127. /**
  128. * Expected SDP: all ssrc must be present and ordered
  129. */
  130. function getExpectedSdp() {
  131. return `${[
  132. ...commonSdpLines,
  133. 'a=ssrc:1757014965 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  134. 'a=ssrc:1757014965 cname:peDGrDD6WsxUOki/',
  135. 'a=ssrc:984899560 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  136. 'a=ssrc:984899560 cname:peDGrDD6WsxUOki/',
  137. 'a=ssrc:1479742055 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  138. 'a=ssrc:1479742055 cname:peDGrDD6WsxUOki/',
  139. 'a=ssrc:855213044 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  140. 'a=ssrc:855213044 cname:peDGrDD6WsxUOki/',
  141. 'a=ssrc:1089111804 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  142. 'a=ssrc:1089111804 cname:peDGrDD6WsxUOki/',
  143. 'a=ssrc:2963867077 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  144. 'a=ssrc:2963867077 cname:peDGrDD6WsxUOki/',
  145. 'a=ssrc-group:FID 1757014965 984899560',
  146. 'a=ssrc-group:FID 1479742055 855213044',
  147. 'a=ssrc-group:FID 1089111804 2963867077',
  148. 'a=ssrc-group:SIM 1757014965 1479742055 1089111804',
  149. 'a=rtcp-mux'
  150. ].join('\r\n')}\r\n`;
  151. }
  152. });
  153. it('sort ssrcs in case there is a single FID group', () => {
  154. const pc = new MockPeerConnection();
  155. const tpcUtils = new TPCUtils(pc);
  156. const source = new RTCSessionDescription({
  157. type: 'offer',
  158. sdp: getSourceSdp()
  159. });
  160. const result = tpcUtils.ensureCorrectOrderOfSsrcs(source);
  161. expect(result.sdp).toBe(getExpectedSdp());
  162. /**
  163. * Test SDP with the single FID group
  164. */
  165. function getSourceSdp() {
  166. return `${[
  167. ...commonSdpLines,
  168. 'a=ssrc:984899560 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  169. 'a=ssrc:984899560 cname:peDGrDD6WsxUOki/',
  170. 'a=ssrc:1757014965 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  171. 'a=ssrc:1757014965 cname:peDGrDD6WsxUOki/',
  172. 'a=ssrc-group:FID 1757014965 984899560',
  173. 'a=rtcp-mux'
  174. ].join('\r\n')}\r\n`;
  175. }
  176. /**
  177. * Expected SDP: all ssrc must be present and ordered
  178. */
  179. function getExpectedSdp() {
  180. return `${[
  181. ...commonSdpLines,
  182. 'a=ssrc:1757014965 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  183. 'a=ssrc:1757014965 cname:peDGrDD6WsxUOki/',
  184. 'a=ssrc:984899560 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf',
  185. 'a=ssrc:984899560 cname:peDGrDD6WsxUOki/',
  186. 'a=ssrc-group:FID 1757014965 984899560',
  187. 'a=rtcp-mux'
  188. ].join('\r\n')}\r\n`;
  189. }
  190. });
  191. });
  192. describe('Test encodings when default settings are used for', () => {
  193. let pc, tpcUtils;
  194. let activeState, height, maxBitrates, scalabilityModes, scaleFactor;
  195. afterEach(() => {
  196. activeState = null;
  197. height = null;
  198. maxBitrates = null;
  199. scalabilityModes = null;
  200. scaleFactor = null;
  201. });
  202. const videoQuality = {};
  203. describe('AV1 camera tracks', () => {
  204. const track = new MockJitsiLocalTrack(720, 'video', 'camera');
  205. const codec = CodecMimeType.AV1;
  206. beforeEach(() => {
  207. pc = new MockPeerConnection('1', true, true /* simulcast */);
  208. pc.options = { videoQuality };
  209. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  280. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  386. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  424. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  456. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  493. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  555. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  584. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  656. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  694. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  731. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  819. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  907. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  958. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  987. tpcUtils = new TPCUtils(pc);
  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(200000);
  1001. expect(maxBitrates[1]).toBe(500000);
  1002. expect(maxBitrates[2]).toBe(1500000);
  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(200000);
  1020. expect(maxBitrates[1]).toBe(500000);
  1021. expect(maxBitrates[2]).toBe(1500000);
  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(200000);
  1039. expect(maxBitrates[1]).toBe(500000);
  1040. expect(maxBitrates[2]).toBe(1500000);
  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.options = { videoQuality };
  1065. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  1105. tpcUtils = new TPCUtils(pc);
  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(200000);
  1119. expect(maxBitrates[1]).toBe(500000);
  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.options = { videoQuality };
  1144. tpcUtils = new TPCUtils(pc);
  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(1500000);
  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(500000);
  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(200000);
  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.options = { videoQuality };
  1195. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  1224. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  1314. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  1352. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  1389. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  1440. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  1491. pc._capScreenshareBitrate = false;
  1492. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  1544. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  1645. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  1740. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  1827. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  1914. pc._capScreenshareBitrate = true;
  1915. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  1968. pc._capScreenshareBitrate = false;
  1969. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  2022. tpcUtils = new TPCUtils(pc);
  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(1500000);
  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(500000);
  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(200000);
  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.options = { videoQuality };
  2085. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  2150. tpcUtils = new TPCUtils(pc);
  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.options = { videoQuality };
  2215. pc._capScreenshareBitrate = true;
  2216. const utils = new TPCUtils(pc);
  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.options = { videoQuality };
  2308. pc._capScreenshareBitrate = true;
  2309. const utils = new TPCUtils(pc);
  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. });
  2387. });