Skip to content

Commit

Permalink
Add function to append additional string to the
Browse files Browse the repository at this point in the history
a=fmtp sections of SDP
  • Loading branch information
SangwonOh committed Sep 2, 2021
1 parent 7249aa6 commit c21b32e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 16 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
62 changes: 47 additions & 15 deletions src/OvenLiveKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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 () {

Expand Down Expand Up @@ -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 = {};

Expand Down

0 comments on commit c21b32e

Please sign in to comment.