Skip to content

Commit

Permalink
chore: update typo and modifies disableRemb
Browse files Browse the repository at this point in the history
  • Loading branch information
bxu2 committed Dec 19, 2023
1 parent e0e960f commit e2b347f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 22 deletions.
66 changes: 49 additions & 17 deletions src/munge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
retainCandidates,
retainCodecs,
disableRtcpFbValue,
disableRemb,
disableTwcc,
} from './munge';
import { parse } from './parser';
Expand Down Expand Up @@ -44,20 +45,16 @@ const validateOfferCodecs = (offer: Sdp): boolean => {
* @param rtcpFbValue - The rtcp-fb value to check.
* @returns True if the offer contains rtcp-fb value.
*/
const checkOfferContainsRtcpFeedbacks = (
const checkOfferContainsRtcpFeedback = (
offer: Sdp | AvMediaDescription,
rtcpFbValue: string
): boolean => {
let bContains = false;
const mediaDescriptions = offer instanceof Sdp ? offer.avMedia : [offer];
mediaDescriptions.forEach((av: AvMediaDescription) => {
av.codecs.forEach((ci: CodecInfo) => {
if (ci.feedback.includes(rtcpFbValue)) {
bContains = true;
}
return mediaDescriptions.some((av: AvMediaDescription) => {
return [...av.codecs.values()].some((ci: CodecInfo) => {
return ci.feedback.includes(rtcpFbValue);
});
});
return bContains;
};

describe('munging', () => {
Expand Down Expand Up @@ -156,8 +153,8 @@ describe('munging', () => {
const parsed = parse(offer);

disableRtcpFbValue(parsed, 'transport-cc');
expect(checkOfferContainsRtcpFeedbacks(parsed, 'transport-cc')).toBe(false);
expect(checkOfferContainsRtcpFeedbacks(parsed, 'goog-remb')).toBe(true);
expect(checkOfferContainsRtcpFeedback(parsed, 'transport-cc')).toBe(false);
expect(checkOfferContainsRtcpFeedback(parsed, 'goog-remb')).toBe(true);
});
it('should remove rtcp feedback correctly when passing in an AvMediaDescription', () => {
expect.hasAssertions();
Expand All @@ -168,15 +165,24 @@ describe('munging', () => {
.filter((av) => av.type === 'audio')
.forEach((av) => {
disableRtcpFbValue(av, 'transport-cc');
expect(checkOfferContainsRtcpFeedbacks(av, 'transport-cc')).toBe(false);
expect(checkOfferContainsRtcpFeedback(av, 'transport-cc')).toBe(false);
});
expect(checkOfferContainsRtcpFeedbacks(parsed, 'transport-cc')).toBe(true);
expect(checkOfferContainsRtcpFeedbacks(parsed, 'goog-remb')).toBe(true);
expect(checkOfferContainsRtcpFeedback(parsed, 'transport-cc')).toBe(true);
expect(checkOfferContainsRtcpFeedback(parsed, 'goog-remb')).toBe(true);
});
});

describe('disableTwcc', () => {
it('should remove rtcp feedback correctly when passing in an AvMediaDescription', () => {
it('should disable twcc when passing in an SDP', () => {
expect.hasAssertions();
const offer = fs.readFileSync('./src/sdp-corpus/offer_with_rtcp_feedback.sdp', 'utf-8');
const parsed = parse(offer);

disableTwcc(parsed);
expect(checkOfferContainsRtcpFeedback(parsed, 'transport-cc')).toBe(false);
expect(checkOfferContainsRtcpFeedback(parsed, 'goog-remb')).toBe(true);
});
it('should disable twcc when passing in an AvMediaDescription', () => {
expect.hasAssertions();
const offer = fs.readFileSync('./src/sdp-corpus/offer_with_rtcp_feedback.sdp', 'utf-8');
const parsed = parse(offer);
Expand All @@ -185,10 +191,36 @@ describe('munging', () => {
.filter((av) => av.type === 'audio')
.forEach((av) => {
disableTwcc(av);
expect(checkOfferContainsRtcpFeedbacks(av, 'transport-cc')).toBe(false);
expect(checkOfferContainsRtcpFeedback(av, 'transport-cc')).toBe(false);
});
expect(checkOfferContainsRtcpFeedback(parsed, 'transport-cc')).toBe(true);
expect(checkOfferContainsRtcpFeedback(parsed, 'goog-remb')).toBe(true);
});
});

describe('disableRemb', () => {
it('should disable remb when passing in an SDP', () => {
expect.hasAssertions();
const offer = fs.readFileSync('./src/sdp-corpus/offer_with_rtcp_feedback.sdp', 'utf-8');
const parsed = parse(offer);

disableRemb(parsed);
expect(checkOfferContainsRtcpFeedback(parsed, 'goog-remb')).toBe(false);
expect(checkOfferContainsRtcpFeedback(parsed, 'transport-cc')).toBe(true);
});
it('should disable remb when passing in an AvMediaDescription', () => {
expect.hasAssertions();
const offer = fs.readFileSync('./src/sdp-corpus/offer_with_rtcp_feedback.sdp', 'utf-8');
const parsed = parse(offer);

parsed.avMedia
.filter((av) => av.type === 'video')
.forEach((av) => {
disableRemb(av);
expect(checkOfferContainsRtcpFeedback(av, 'goog-remb')).toBe(false);
});
expect(checkOfferContainsRtcpFeedbacks(parsed, 'transport-cc')).toBe(true);
expect(checkOfferContainsRtcpFeedbacks(parsed, 'goog-remb')).toBe(true);
expect(checkOfferContainsRtcpFeedback(parsed, 'goog-remb')).toBe(false);
expect(checkOfferContainsRtcpFeedback(parsed, 'transport-cc')).toBe(true);
});
});
});
10 changes: 5 additions & 5 deletions src/munge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ export function disableRtcpFbValue(sdpOrAv: Sdp | AvMediaDescription, rtcpFbValu
}

/**
* Disable REMB from all media blocks in the given SDP.
* Disable REMB from the media blocks in the given SDP or audio/video media description.
*
* @param sdp - The SDP from which to filter REMB.
* @param sdpOrAv - The {@link Sdp} or {@link AvMediaDescription} from which to filter REMB.
*/
export function disableRemb(sdp: Sdp) {
disableRtcpFbValue(sdp, 'goog-remb');
export function disableRemb(sdpOrAv: Sdp | AvMediaDescription) {
disableRtcpFbValue(sdpOrAv, 'goog-remb');
}

/**
* Disable REMB from all media blocks in the given SDP.
* Disable TWCC from the media blocks in the given SDP or audio/video media description.
*
* @param sdpOrAv - The {@link Sdp} or {@link AvMediaDescription} from which to filter TWCC.
*/
Expand Down

0 comments on commit e2b347f

Please sign in to comment.