diff --git a/README.md b/README.md index 38f0c5f..ea2e16a 100644 --- a/README.md +++ b/README.md @@ -288,6 +288,11 @@ ovenLivekit.getUserMedia().then(function () { - Number: Unit is Kbps. - If set limits max bitrates of streaming to OvenMediaEngine. +##### `sdp.appendFmtp` +- type + - String: String you want to append to a=fmtp of SDP. +- If set video format is appended to the a=fmtp sections of SDP. + ## For more information * [WebRTC Input in OvenPlayer Demo](https://demo.ovenplayer.com/demo_input.html) * Test Player based on OvenPlayer. diff --git a/package.json b/package.json index 7e0e59e..9043bae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ovenlivekit", - "version": "1.0.0", + "version": "1.0.1", "description": "OvenLiveKit for Web is an open source JavaScript SDK suite for live streaming from web browsers to OvenMediaEngine.", "main": "dist/OvenLiveKit.min.js", "scripts": { diff --git a/src/OvenLiveKit.js b/src/OvenLiveKit.js index c55bf65..c0db3e3 100644 --- a/src/OvenLiveKit.js +++ b/src/OvenLiveKit.js @@ -331,34 +331,56 @@ function addMethod(instance) { } - function removeH264(sdp) { + function appendFmtp(sdp) { - let newLines = []; - let lines = sdp.split('\n'); + const fmtpStr = instance.connectionConfig.sdp.appendFmtp; + + const lines = sdp.split('\n'); + const payloads = []; for (let i = 0; i < lines.length; i++) { if (lines[i].indexOf('m=video') === 0) { - newLines.push(lines[i].replace(' 100', '')); - } else if (lines[i].indexOf('100') > -1) { - } else { - newLines.push(lines[i]); + let tokens = lines[i].split(' ') - if (lines[i].indexOf('a=rtpmap:101') > -1) { - // newLines.push('a=fmtp:101 useadaptivelayering=true;useadaptivelayering_v2=true'); + for (let j = 3; j < tokens.length; j++) { + + payloads.push(tokens[j].replace('\r', '')); } + + break; } } - return newLines.join('\n') - } + for (let i = 0; i < payloads.length; i++) { - function createPeerConnection(id, peerId, offer, candidates, iceServers) { + let fmtpLineFound = false; + + for (let j = 0; j < lines.length; j++) { + + if (lines[j].indexOf('a=fmtp:' + payloads[i]) === 0) { + fmtpLineFound = true; + lines[j] += ';' + fmtpStr; + } + } + + if (!fmtpLineFound) { + + for (let j = 0; j < lines.length; j++) { - // console.log(removeH264(offer.sdp)); + if (lines[j].indexOf('a=rtpmap:' + payloads[i]) === 0) { - // offer.sdp = removeH264(offer.sdp); + lines[j] += '\na=fmtp:' + payloads[i] + ' ' + fmtpStr; + } + } + } + } + + return lines.join('\n') + } + + function createPeerConnection(id, peerId, offer, candidates, iceServers) { let peerConnectionConfig = {}; @@ -470,12 +492,22 @@ function addMethod(instance) { offer.sdp = setBitrateLimit(offer.sdp, 'video', instance.connectionConfig.maxVideoBitrate); } + if (instance.connectionConfig.sdp && instance.connectionConfig.sdp.appendFmtp) { + + offer.sdp = appendFmtp(offer.sdp); + } + peerConnection.setRemoteDescription(new RTCSessionDescription(offer)) .then(function () { peerConnection.createAnswer() .then(function (answer) { + if (instance.connectionConfig.sdp && instance.connectionConfig.sdp.appendFmtp) { + + answer.sdp = appendFmtp(answer.sdp); + } + peerConnection.setLocalDescription(answer) .then(function () { @@ -655,7 +687,7 @@ function addMethod(instance) { // static methods OvenLiveKit.create = function (options) { - console.info(logEventHeader, 'Create WebRTC Input'); + console.info(logEventHeader, 'Create WebRTC Input v1.0.1'); let instance = {};