Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/sdp/RtxModifier.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as transform from 'sdp-transform';

import RtxModifier from './RtxModifier.js';
import RtxModifier from './RtxModifier.ts';
import SDPUtil from './SDPUtil';
import { default as SampleSdpStrings } from './SampleSdpStrings';

Expand Down
55 changes: 39 additions & 16 deletions modules/sdp/RtxModifier.js → modules/sdp/RtxModifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ import { MediaType } from '../../service/RTC/MediaType';
import { SSRC_GROUP_SEMANTICS } from '../../service/RTC/StandardVideoQualitySettings';

import SDPUtil from './SDPUtil';
import { SdpTransformWrap, parseSecondarySSRC } from './SdpTransformUtil';
import { MLineWrap, SdpTransformWrap, parseSecondarySSRC } from './SdpTransformUtil';

const logger = getLogger('sdp:RtxModifier');

/**
* Helper interfaces for type safety.
*/
export interface IPrimarySsrcInfo {
cname?: string;
id: number;
msid?: string;
}


/**
* Begin helper functions
*/
Expand All @@ -22,7 +32,11 @@ const logger = getLogger('sdp:RtxModifier');
* primary ssrc
* @param {number} rtxSsrc the rtx ssrc to associate with the primary ssrc
*/
function updateAssociatedRtxStream(mLine, primarySsrcInfo, rtxSsrc) {
function updateAssociatedRtxStream(
mLine: MLineWrap,
primarySsrcInfo: IPrimarySsrcInfo,
rtxSsrc: number
): void {
const primarySsrc = primarySsrcInfo.id;
const primarySsrcMsid = primarySsrcInfo.msid;
const primarySsrcCname = primarySsrcInfo.cname;
Expand Down Expand Up @@ -63,6 +77,12 @@ function updateAssociatedRtxStream(mLine, primarySsrcInfo, rtxSsrc) {
* and makes sure that they remain consistent
*/
export default class RtxModifier {
/**
* Map of video ssrc to corresponding RTX
* ssrc
*/
private correspondingRtxSsrcs: Map<number, number>;

/**
* Constructor
*/
Expand All @@ -71,15 +91,15 @@ export default class RtxModifier {
* Map of video ssrc to corresponding RTX
* ssrc
*/
this.correspondingRtxSsrcs = new Map();
this.correspondingRtxSsrcs = new Map<number, number>();
}

/**
* Clear the cached map of primary video ssrcs to
* their corresponding rtx ssrcs so that they will
* not be used for the next call to modifyRtxSsrcs
*/
clearSsrcCache() {
clearSsrcCache(): void {
this.correspondingRtxSsrcs.clear();
}

Expand All @@ -89,7 +109,7 @@ export default class RtxModifier {
* @param {Map} ssrcMapping a mapping of primary video
* ssrcs to their corresponding rtx ssrcs
*/
setSsrcCache(ssrcMapping) {
setSsrcCache(ssrcMapping: Map<number, number>): void {
logger.debug('Setting ssrc cache to ', ssrcMapping);
this.correspondingRtxSsrcs = ssrcMapping;
}
Expand All @@ -101,19 +121,19 @@ export default class RtxModifier {
* @param {string} sdpStr sdp in raw string format
* @returns {string} The modified sdp in raw string format.
*/
modifyRtxSsrcs(sdpStr) {
modifyRtxSsrcs(sdpStr: string): string {
let modified = false;
const sdpTransformer = new SdpTransformWrap(sdpStr);
const videoMLines = sdpTransformer.selectMedia(MediaType.VIDEO);

if (!videoMLines?.length) {
if (!videoMLines || (Array.isArray(videoMLines) && videoMLines.length === 0)) {
logger.debug(`No 'video' media found in the sdp: ${sdpStr}`);

return sdpStr;
}

for (const videoMLine of videoMLines) {
if (this.modifyRtxSsrcs2(videoMLine)) {
for (const videoMLine of Array.isArray(videoMLines) ? videoMLines : [ videoMLines ]) {
if (this.modifyRtxSsrcs2(videoMLine as MLineWrap)) {
modified = true;
}
}
Expand All @@ -128,7 +148,7 @@ export default class RtxModifier {
* @return {boolean} <tt>true</tt> if the SDP wrapped by {@link SdpTransformWrap} has been modified or
* <tt>false</tt> otherwise.
*/
modifyRtxSsrcs2(videoMLine) {
modifyRtxSsrcs2(videoMLine: MLineWrap): boolean {
if (videoMLine.direction === MediaDirection.RECVONLY) {
return false;
}
Expand Down Expand Up @@ -161,7 +181,8 @@ export default class RtxModifier {
id: ssrc,
msid
},
correspondingRtxSsrc);
correspondingRtxSsrc
);
}

// FIXME we're not looking into much details whether the SDP has been
Expand All @@ -175,20 +196,22 @@ export default class RtxModifier {
* @param {string} sdpStr sdp in raw string format
* @returns {string} sdp string with all rtx streams stripped
*/
stripRtx(sdpStr) {
stripRtx(sdpStr: string): string {
const sdpTransformer = new SdpTransformWrap(sdpStr);
const videoMLines = sdpTransformer.selectMedia(MediaType.VIDEO);

if (!videoMLines?.length) {
if (!videoMLines || (Array.isArray(videoMLines) && videoMLines.length === 0)) {
logger.debug(`No 'video' media found in the sdp: ${sdpStr}`);

return sdpStr;
}

for (const videoMLine of videoMLines) {
if (videoMLine.direction !== MediaDirection.RECVONLY
for (const videoMLine of Array.isArray(videoMLines) ? videoMLines : [ videoMLines ]) {
if (
videoMLine.direction !== MediaDirection.RECVONLY
&& videoMLine.getSSRCCount()
&& videoMLine.containsAnySSRCGroups()) {
&& videoMLine.containsAnySSRCGroups()
) {
const fidGroups = videoMLine.findGroups(SSRC_GROUP_SEMANTICS.FID);

// Remove the fid groups from the mline
Expand Down