Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

SDPSimulcast.spec.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import * as transform from 'sdp-transform';
  2. import { MediaType } from '../../service/RTC/MediaType';
  3. import { default as SampleSdpStrings } from './SampleSdpStrings';
  4. import SdpSimulcast from './SdpSimulcast';
  5. const getVideoGroups = (parsedSdp, groupSemantics) => {
  6. const videoMLine = parsedSdp.media.find(m => m.type === MediaType.VIDEO);
  7. videoMLine.ssrcGroups = videoMLine.ssrcGroups || [];
  8. return videoMLine.ssrcGroups.filter(g => g.semantics === groupSemantics);
  9. };
  10. const numVideoSsrcs = parsedSdp => {
  11. const videoMLine = parsedSdp.media.find(m => m.type === MediaType.VIDEO);
  12. const ssrcs = new Set(videoMLine.ssrcs?.map(ssrcInfo => ssrcInfo.id));
  13. return ssrcs.size;
  14. };
  15. const parseSimLayers = parsedSdp => {
  16. const videoMLine = parsedSdp.media.find(m => m.type === MediaType.VIDEO);
  17. const simGroup = videoMLine.ssrcGroups?.find(group => group.semantics === 'SIM');
  18. if (simGroup) {
  19. return simGroup.ssrcs.split(' ').map(ssrc => parseInt(ssrc, 10));
  20. }
  21. return null;
  22. };
  23. describe('sdp-simulcast', () => {
  24. const numLayers = 3;
  25. let simulcast;
  26. beforeEach(() => {
  27. simulcast = new SdpSimulcast({ numOfLayers: numLayers });
  28. });
  29. describe('mungeLocalDescription', () => {
  30. it('should add simulcast layers to the local sdp', () => {
  31. const sdp = SampleSdpStrings.plainVideoSdp;
  32. const desc = {
  33. type: 'answer',
  34. sdp: transform.write(sdp)
  35. };
  36. const newDesc = simulcast.mungeLocalDescription(desc);
  37. const newSdp = transform.parse(newDesc.sdp);
  38. expect(numVideoSsrcs(newSdp)).toEqual(numLayers);
  39. const simGroup = getVideoGroups(newSdp, 'SIM')[0];
  40. expect(simGroup.ssrcs.split(' ').length).toEqual(numLayers);
  41. });
  42. it('should add the cached SSRCs on subsequent sLD calls to the local sdp', () => {
  43. const sdp = SampleSdpStrings.plainVideoSdp;
  44. const desc = {
  45. type: 'answer',
  46. sdp: transform.write(sdp)
  47. };
  48. const newDesc = simulcast.mungeLocalDescription(desc);
  49. const newSdp = transform.parse(newDesc.sdp);
  50. const cachedSsrcs = parseSimLayers(newSdp);
  51. // Call sLD again with the original description.
  52. const secondDesc = simulcast.mungeLocalDescription(desc);
  53. const secondSdp = transform.parse(secondDesc.sdp);
  54. expect(parseSimLayers(secondSdp)).toEqual(cachedSsrcs);
  55. });
  56. describe('corner cases', () => {
  57. it('should do nothing if the mline has no ssrcs in the local sdp', () => {
  58. const sdp = SampleSdpStrings.plainVideoSdp;
  59. const videoMLine = sdp.media.find(m => m.type === MediaType.VIDEO);
  60. videoMLine.ssrcs = [];
  61. const desc = {
  62. type: 'answer',
  63. sdp: transform.write(sdp)
  64. };
  65. const newDesc = simulcast.mungeLocalDescription(desc);
  66. const newSdp = transform.parse(newDesc.sdp);
  67. expect(numVideoSsrcs(newSdp)).toEqual(0);
  68. });
  69. it('should do nothing if the mline already has a SIM group and 3 ssrcs in the local sdp', () => {
  70. const sdp = SampleSdpStrings.simulcastSdp;
  71. const desc = {
  72. type: 'answer',
  73. sdp: transform.write(sdp)
  74. };
  75. const ssrcs = parseSimLayers(sdp);
  76. const newDesc = simulcast.mungeLocalDescription(desc);
  77. const newSdp = transform.parse(newDesc.sdp);
  78. expect(parseSimLayers(newSdp)).toEqual(ssrcs);
  79. });
  80. it('should do nothing if the m-line has only recv-only ssrcs', () => {
  81. const sdp = SampleSdpStrings.recvOnlySdp;
  82. const desc = {
  83. type: 'answer',
  84. sdp: transform.write(sdp)
  85. };
  86. const newDesc = simulcast.mungeLocalDescription(desc);
  87. const newSdp = transform.parse(newDesc.sdp);
  88. expect(numVideoSsrcs(newSdp)).toEqual(1);
  89. });
  90. });
  91. });
  92. });