Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for sending abs-capture-time RTP extension #217

Draft
wants to merge 4 commits into
base: v3
Choose a base branch
from
Draft
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 lib/handlers/Chrome74.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion lib/handlers/Chrome74.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,25 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
});
let offer = await this._pc.createOffer();
let localSdpObject = sdpTransform.parse(offer.sdp);
let offerMediaObject;
let offerMediaObject = localSdpObject.media[mediaSectionIdx.idx];
// May force abs-capture-time RTP extension negotiation.
{
const exten = sdpCommonUtils.addRtpExtensionToMediaObject({
mediaObject: offerMediaObject,
uri: 'http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time'
});
if (exten) {
offer = { type: 'offer', sdp: sdpTransform.write(localSdpObject) };
sdpCommonUtils.addRtpExtensionToRtpParameters({
rtpParameters: sendingRtpParameters,
extension: exten
});
sdpCommonUtils.addRtpExtensionToRtpParameters({
rtpParameters: sendingRemoteRtpParameters,
extension: exten
});
}
}
if (!this._transportReady) {
await this._setupTransport({
localDtlsRole: (_a = this._forcedLocalDtlsRole) !== null && _a !== void 0 ? _a : 'client',
Expand Down
22 changes: 21 additions & 1 deletion lib/handlers/sdp/commonUtils.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DtlsParameters } from '../../Transport';
import { RtpCapabilities, RtpParameters } from '../../RtpParameters';
import { RtpCapabilities, RtpHeaderExtensionParameters, RtpParameters } from '../../RtpParameters';
export declare function extractRtpCapabilities({ sdpObject }: {
sdpObject: any;
}): RtpCapabilities;
Expand All @@ -17,4 +17,24 @@ export declare function applyCodecParameters({ offerRtpParameters, answerMediaOb
offerRtpParameters: RtpParameters;
answerMediaObject: any;
}): void;
/**
* Adds the given RTP extension to the given SDP media object and returns a
* RtpHeaderExtensionParameters object.
* If the extension is already present, this function doesn't add anything and
* doesn't return anything.
*/
export declare function addRtpExtensionToMediaObject({ mediaObject, uri }: {
mediaObject: any;
uri: string;
}): RtpHeaderExtensionParameters | undefined;
/**
* Adds the given RTP extension to the given RTP parameters.
* If the extension is already present (with same id), this function doesn't
* add anything. If the extension is present with a different id, then existing
* one is removed and the new one is added.
*/
export declare function addRtpExtensionToRtpParameters({ rtpParameters, extension }: {
rtpParameters: RtpParameters;
extension: RtpHeaderExtensionParameters;
}): void;
//# sourceMappingURL=commonUtils.d.ts.map
2 changes: 1 addition & 1 deletion lib/handlers/sdp/commonUtils.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 53 additions & 1 deletion lib/handlers/sdp/commonUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyCodecParameters = exports.getCname = exports.extractDtlsParameters = exports.extractRtpCapabilities = void 0;
exports.addRtpExtensionToRtpParameters = exports.addRtpExtensionToMediaObject = exports.applyCodecParameters = exports.getCname = exports.extractDtlsParameters = exports.extractRtpCapabilities = void 0;
const sdpTransform = __importStar(require("sdp-transform"));
function extractRtpCapabilities({ sdpObject }) {
// Map of RtpCodecParameters indexed by payload type.
Expand Down Expand Up @@ -192,3 +192,55 @@ function applyCodecParameters({ offerRtpParameters, answerMediaObject }) {
}
}
exports.applyCodecParameters = applyCodecParameters;
/**
* Adds the given RTP extension to the given SDP media object and returns a
* RtpHeaderExtensionParameters object.
* If the extension is already present, this function doesn't add anything and
* doesn't return anything.
*/
function addRtpExtensionToMediaObject({ mediaObject, uri }) {
if (!Array.isArray(mediaObject.ext)) {
mediaObject.ext = [];
}
let id = 1;
for (const exten of mediaObject.ext) {
// If extension uri is already present, don't do anything.
if (exten.uri === uri) {
id = 0;
break;
}
if (exten.value >= id)
id = exten.value + 1;
}
if (id > 0) {
mediaObject.ext.push({ value: id, uri });
// NOTE: No support for encrypt/parameters fields.
return { uri, id };
}
}
exports.addRtpExtensionToMediaObject = addRtpExtensionToMediaObject;
/**
* Adds the given RTP extension to the given RTP parameters.
* If the extension is already present (with same id), this function doesn't
* add anything. If the extension is present with a different id, then existing
* one is removed and the new one is added.
*/
function addRtpExtensionToRtpParameters({ rtpParameters, extension }) {
if (!Array.isArray(rtpParameters.headerExtensions)) {
rtpParameters.headerExtensions = [];
}
let replaced = false;
for (const exten of rtpParameters.headerExtensions) {
if (exten.uri === extension.uri && exten.id === extension.id) {
return;
}
else if (exten.uri === extension.uri && exten.id !== extension.id) {
exten.id = extension.id;
replaced = true;
}
}
if (!replaced) {
rtpParameters.headerExtensions.push(extension);
}
}
exports.addRtpExtensionToRtpParameters = addRtpExtensionToRtpParameters;
28 changes: 27 additions & 1 deletion src/handlers/Chrome74.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,33 @@ export class Chrome74 extends HandlerInterface
});
let offer = await this._pc.createOffer();
let localSdpObject = sdpTransform.parse(offer.sdp);
let offerMediaObject;
let offerMediaObject = localSdpObject.media[mediaSectionIdx.idx];

// May force abs-capture-time RTP extension negotiation.
{
const exten = sdpCommonUtils.addRtpExtensionToMediaObject(
{
mediaObject : offerMediaObject,
uri : 'http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time'
});

if (exten)
{
offer = { type: 'offer', sdp: sdpTransform.write(localSdpObject) };

sdpCommonUtils.addRtpExtensionToRtpParameters(
{
rtpParameters : sendingRtpParameters,
extension : exten
});

sdpCommonUtils.addRtpExtensionToRtpParameters(
{
rtpParameters : sendingRemoteRtpParameters,
extension : exten
});
}
}

if (!this._transportReady)
{
Expand Down
86 changes: 86 additions & 0 deletions src/handlers/sdp/commonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
RtpCapabilities,
RtpCodecCapability,
RtpHeaderExtension,
RtpHeaderExtensionParameters,
RtpParameters,
RtcpFeedback
} from '../../RtpParameters';
Expand Down Expand Up @@ -257,3 +258,88 @@ export function applyCodecParameters(
}
}
}

/**
* Adds the given RTP extension to the given SDP media object and returns a
* RtpHeaderExtensionParameters object.
* If the extension is already present, this function doesn't add anything and
* doesn't return anything.
*/
export function addRtpExtensionToMediaObject(
{ mediaObject, uri }:
{ mediaObject: any; uri: string }
): RtpHeaderExtensionParameters | undefined
{
if (!Array.isArray(mediaObject.ext))
{
mediaObject.ext = [];
}

let id = 1;

for (const exten of mediaObject.ext)
{
// If extension uri is already present, don't do anything.
if (exten.uri === uri)
{
id = 0;

break;
}

if (exten.value >= id)
id = exten.value + 1;
}

if (id > 0)
{
mediaObject.ext.push({ value: id, uri });

// NOTE: No support for encrypt/parameters fields.
return { uri, id };
}
}

/**
* Adds the given RTP extension to the given RTP parameters.
* If the extension is already present (with same id), this function doesn't
* add anything. If the extension is present with a different id, then existing
* one is removed and the new one is added.
*/
export function addRtpExtensionToRtpParameters(
{
rtpParameters,
extension
}:
{
rtpParameters: RtpParameters;
extension: RtpHeaderExtensionParameters;
}
): void
{
if (!Array.isArray(rtpParameters.headerExtensions))
{
rtpParameters.headerExtensions = [];
}

let replaced = false;

for (const exten of rtpParameters.headerExtensions)
{
if (exten.uri === extension.uri && exten.id === extension.id)
{
return;
}
else if (exten.uri === extension.uri && exten.id !== extension.id)
{
exten.id = extension.id;

replaced = true;
}
}

if (!replaced)
{
rtpParameters.headerExtensions.push(extension);
}
}