Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit 0568c86

Browse files
authored
Support update source for subscription (#816)
* Support update source for subscription * Change codec order and ext in SDP * Fix sdp and stream arguments issue * Fix not allowed codec issue * Fix activeInput undefined issue for selecting audio
1 parent efbee44 commit 0568c86

File tree

5 files changed

+58
-10
lines changed

5 files changed

+58
-10
lines changed

source/agent/audio/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ module.exports = function (rpcClient, selfRpcId, parentRpcId, clusterWorkerIP) {
142142
// Notify controller
143143
const target = {id: activeStreamIds[i], owner, codec};
144144
ctrlr && rpcClient.remoteCall(ctrlr, 'onAudioActiveness',
145-
[belongToRoom, activeInput, target],
145+
[belongToRoom, streamId, target],
146146
{callback: function(){}});
147147
});
148148
engine = selector;

source/agent/conference/conference.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,10 @@ var Conference = function (rpcClient, selfRpcId) {
16721672
if (update.audio.from && update.audio.from !== audioTrack.from) {
16731673
audioTrack.from = update.audio.from;
16741674
effective = true;
1675+
// TODO: limit format when updating source
1676+
if (oldSub.info && oldSub.info.type === 'webrtc') {
1677+
delete audioTrack.format;
1678+
}
16751679
}
16761680
}
16771681

@@ -1683,6 +1687,11 @@ var Conference = function (rpcClient, selfRpcId) {
16831687
if (update.video.from && update.video.from !== videoTrack.from) {
16841688
videoTrack.from = update.video.from;
16851689
effective = true;
1690+
// TODO: limit format when updating source
1691+
if (oldSub.info && oldSub.info.type === 'webrtc') {
1692+
delete videoTrack.format;
1693+
videoTrack.parameters = {};
1694+
}
16861695
}
16871696
if (update.video.parameters && (Object.keys(update.video.parameters).length > 0)) {
16881697
videoTrack.parameters = (videoTrack.parameters || {});
@@ -1714,18 +1723,18 @@ var Conference = function (rpcClient, selfRpcId) {
17141723
}
17151724
const err = {};
17161725
if (videoTrack && !validateVideoRequest(oldSub.info.type, videoTrack, err)) {
1717-
return Promise.reject('Target video stream does NOT satisfy:', (err && err.message));
1726+
return Promise.reject('Target video stream does NOT satisfy:' + (err && err.message));
17181727
}
17191728
if (audioTrack && !validateAudioRequest(oldSub.info.type, audioTrack, err)) {
1720-
return Promise.reject('Target audio stream does NOT satisfy', (err && err.message));
1729+
return Promise.reject('Target audio stream does NOT satisfy' + (err && err.message));
17211730
}
17221731

17231732
return removeSubscription(subscriptionId)
17241733
.then((result) => {
17251734
return addSubscription(subscriptionId, oldSub.locality, newSubMedia, oldSub.data, oldSub.info);
17261735
}).catch((err) => {
17271736
log.info('Update subscription failed:', err.message ? err.message : err);
1728-
log.info('And is recovering the previous subscription:', JSON.stringify(old_su));
1737+
log.info('And is recovering the previous subscription:', JSON.stringify(oldSub));
17291738
return addSubscription(subscriptionId, oldSub.locality, oldSub.media, oldSub.data, oldSub.info)
17301739
.then(() => {
17311740
return Promise.reject('Update subscription failed');

source/agent/conference/stream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class SelectedStream extends ForwardStream {
346346
activeInput: 'unknown',
347347
type: 'selecting',
348348
};
349-
super(id, media, info, null);
349+
super(id, media, null, info, null);
350350
}
351351
}
352352

source/agent/conference/subscription.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class Subscription {
9696
// Array of unique StreamId or TrackId of subscription
9797
froms() {
9898
return this.media.tracks.map(t => t.from)
99-
.filter((t, i, self) => self.findIndex(v => v.id === t.id) === i);
99+
.filter((t, i, self) => self.indexOf(t) === i);
100100
}
101101

102102
// Merge source format and parameters

source/agent/webrtc/sdpInfo.js

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,15 @@ class SdpInfo {
139139
}
140140
}
141141
}
142-
142+
if (mediaInfo.direction === 'recvonly') {
143+
// For subscription
144+
// concat(optionals.map((fmt) => fmt.codec.toLowerCase()));
145+
mediaInfo.rtp.forEach((rtp) => {
146+
if (optionals.findIndex(fmt => isAudioMatchRtp(fmt, rtp)) > -1) {
147+
relatedPayloads.add(rtp.payload);
148+
}
149+
});
150+
}
143151
if (rtpMap.has(selectedPayload)) {
144152
const selectedRtp = rtpMap.get(selectedPayload);
145153
rtpMap.forEach(rtp => {
@@ -165,12 +173,15 @@ class SdpInfo {
165173
mediaInfo.rtcpFb = mediaInfo.rtcpFb.filter(
166174
(rtcp) => relatedPayloads.has(rtcp.payload));
167175
}
168-
mediaInfo.payloads = mediaInfo.payloads.toString().split(' ')
176+
const payloadList = mediaInfo.payloads.toString().split(' ');
177+
if (selectedPayload !== -1) {
178+
payloadList.unshift(selectedPayload);
179+
}
180+
mediaInfo.payloads = payloadList
169181
.filter((p) => relatedPayloads.has(parseInt(p)))
170182
.filter((v, index, self) => self.indexOf(v) === index)
171183
.join(' ');
172184
}
173-
174185
return finalFmt;
175186
}
176187

@@ -202,6 +213,13 @@ class SdpInfo {
202213
.forEach((p, index) => {
203214
payloadOrder.set(parseInt(p), index);
204215
});
216+
if (mediaInfo.direction === 'recvonly') {
217+
// For subscription
218+
// concat(optionals.map((fmt) => fmt.codec.toLowerCase()));
219+
optionals.forEach((fmt) => {
220+
reservedCodecs.push(fmt.codec.toLowerCase());
221+
});
222+
}
205223

206224
for (let i = 0; i < mediaInfo.rtp.length; i++) {
207225
rtp = mediaInfo.rtp[i];
@@ -245,7 +263,11 @@ class SdpInfo {
245263
mediaInfo.rtcpFb = mediaInfo.rtcpFb.filter(
246264
(rtcp) => relatedPayloads.has(rtcp.payload));
247265
}
248-
mediaInfo.payloads = mediaInfo.payloads.toString().split(' ')
266+
const payloadList = mediaInfo.payloads.toString().split(' ');
267+
if (selectedPayload !== -1) {
268+
payloadList.unshift(selectedPayload);
269+
}
270+
mediaInfo.payloads = payloadList
249271
.filter((p) => relatedPayloads.has(parseInt(p)))
250272
.filter((v, index, self) => self.indexOf(v) === index)
251273
.join(' ');
@@ -530,6 +552,23 @@ class SdpInfo {
530552
mediaInfo.direction = 'recvonly';
531553
}
532554

555+
if (mediaInfo.ext && Array.isArray(mediaInfo.ext)) {
556+
const extMappings = [
557+
'urn:ietf:params:rtp-hdrext:ssrc-audio-level',
558+
'http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01',
559+
'urn:ietf:params:rtp-hdrext:sdes:mid',
560+
'urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id',
561+
'urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id',
562+
'urn:ietf:params:rtp-hdrext:toffset',
563+
'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time',
564+
// 'urn:3gpp:video-orientation',
565+
// 'http://www.webrtc.org/experiments/rtp-hdrext/playout-delay',
566+
];
567+
mediaInfo.ext = mediaInfo.ext.filter((e) => {
568+
return extMappings.includes(e.uri);
569+
});
570+
}
571+
533572
if (mediaInfo.rids && Array.isArray(mediaInfo.rids)) {
534573
// Reverse rids direction
535574
mediaInfo.rids.forEach(r => {

0 commit comments

Comments
 (0)