Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
248aaa3a
提交
248aaa3a
authored
1月 28, 2017
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
WebRTC refactor in progress.
上级
539e1c31
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
283 行增加
和
623 行删除
+283
-623
Peer.js
lib/Peer.js
+1
-1
mediasoup.js
lib/mediasoup.js
+1
-1
utils.js
lib/utils.js
+2
-2
RTCDictionaries.js
lib/webrtc/RTCDictionaries.js
+1
-13
RTCPeerConnectionPlanB.js
lib/webrtc/RTCPeerConnection/RTCPeerConnectionPlanB.js
+169
-599
common.js
lib/webrtc/RTCPeerConnection/common.js
+96
-0
index.js
lib/webrtc/RTCPeerConnection/index.js
+10
-7
Peer.cpp
worker/src/RTC/Peer.cpp
+3
-0
没有找到文件。
lib/Peer.js
浏览文件 @
248aaa3a
...
...
@@ -239,7 +239,7 @@ class Peer extends EventEmitter
{
logger
.
debug
(
'"peer.setCapabilities" request succeeded'
);
//
Update peer
capabilities.
//
Set peer's effective
capabilities.
this
.
_data
.
capabilities
=
effectiveCapabilities
;
return
effectiveCapabilities
;
...
...
lib/mediasoup.js
浏览文件 @
248aaa3a
...
...
@@ -34,7 +34,7 @@ module.exports =
*
* @return {Server}
*/
Server
:
function
(
options
)
Server
(
options
)
{
logger
.
debug
(
'Server() [options:%o]'
,
options
);
...
...
lib/utils.js
浏览文件 @
248aaa3a
...
...
@@ -13,14 +13,14 @@ const randomNumberGenerator = randomNumber.generator(
module
.
exports
=
{
randomString
:
function
(
length
)
randomString
(
length
)
{
return
randomString
({
numeric
:
false
,
length
:
length
||
8
}).
toLowerCase
();
},
randomNumber
:
randomNumberGenerator
,
cloneObject
:
function
(
obj
)
cloneObject
(
obj
)
{
if
(
!
obj
||
typeof
obj
!==
'object'
||
Array
.
isArray
(
obj
))
return
{};
...
...
lib/webrtc/RTCDictionaries.js
浏览文件 @
248aaa3a
...
...
@@ -2,22 +2,10 @@
module
.
exports
=
{
RTCSdpType
:
{
offer
:
'offer'
,
answer
:
'answer'
},
RTCSignalingState
:
RTCSignalingState
:
{
stable
:
'stable'
,
haveLocalOffer
:
'have-local-offer'
,
haveRemoteOffer
:
'have-remote-offer'
},
RTCRtpTransceiverDirection
:
{
sendrecv
:
'sendrecv'
,
sendonly
:
'sendonly'
,
recvonly
:
'recvonly'
,
inactive
:
'inactive'
}
};
lib/webrtc/RTCPeerConnection/RTCPeerConnectionPlanB.js
浏览文件 @
248aaa3a
...
...
@@ -8,33 +8,25 @@ const extra = require('../../extra');
const
InvalidStateError
=
require
(
'../../errors'
).
InvalidStateError
;
const
RTCDictionaries
=
require
(
'../RTCDictionaries'
);
const
RTCSessionDescription
=
require
(
'../RTCSessionDescription'
);
const
common
=
require
(
'./common'
);
const
NEGOTIATION_NEEDED_DELAY
=
1000
;
class
RTCPeerConnectionPlanB
extends
EventEmitter
{
constructor
(
room
,
peerName
,
options
)
constructor
(
options
)
{
super
();
this
.
setMaxListeners
(
Infinity
);
this
.
_logger
=
logger
(
`webrtc:RTCPeerConnectionPlanB:
${
peerName
}
`
);
this
.
_logger
=
logger
(
`webrtc:RTCPeerConnectionPlanB:
${
options
.
peerName
}
`
);
this
.
_logger
.
debug
(
'constructor() [options:%o]'
,
options
);
// Room instance.
this
.
_room
=
room
;
// Peer name.
this
.
_peerName
=
peerName
;
// Options.
this
.
_options
=
options
||
{}
;
this
.
_options
=
options
;
// Peer instance.
this
.
_peer
=
null
;
// Peer effective capabilities.
this
.
_capabilities
=
null
;
this
.
_peer
=
options
.
peer
;
// Local RTCSessionDescription.
this
.
_localDescription
=
null
;
...
...
@@ -58,16 +50,22 @@ class RTCPeerConnectionPlanB extends EventEmitter
this
.
_sdpGlobalFields
=
{
id
:
randomString
({
letters
:
false
,
length
:
16
}),
version
:
1
version
:
0
};
// Set of available media kinds in this SDP O/A.
this
.
_setKinds
=
new
Set
();
// Handle Peer 'close' event.
this
.
_peer
.
on
(
'close'
,
(
error
)
=>
{
this
.
emit
(
'close'
,
error
);
});
}
get
closed
()
{
return
this
.
_peer
?
this
.
_peer
.
closed
:
false
;
return
this
.
_peer
.
closed
;
}
get
peer
()
...
...
@@ -97,15 +95,69 @@ class RTCPeerConnectionPlanB extends EventEmitter
// Cancel the negotiation timer.
clearTimeout
(
this
.
_negotiationNeededTimer
);
if
(
this
.
_peer
)
this
.
_peer
.
close
();
else
this
.
emit
(
'close'
);
this
.
_peer
.
close
();
}
/**
* Set the peer's capabilities.
* @param {string} sdp - SDP offer generated by the remote peer.
*/
setCapabilities
(
sdp
)
{
this
.
_logger
.
debug
(
'setCapabilities()'
);
if
(
this
.
closed
)
throw
new
InvalidStateError
(
'closed'
);
if
(
this
.
_peer
.
capabilities
)
throw
new
InvalidStateError
(
'capabilities are ready set'
);
let
desc
;
try
{
desc
=
new
RTCSessionDescription
({
type
:
'offer'
,
sdp
:
sdp
});
}
catch
(
error
)
{
return
Promise
.
reject
(
new
Error
(
`invalid capabilities SDP:
${
error
}
`
));
}
// Set busy flag.
this
.
_busy
=
true
;
// Return a promise that resolves when everything is done.
return
Promise
.
resolve
()
.
then
(()
=>
{
// First set peer capabilities.
let
capabilities
=
common
.
descToCapabilities
(
desc
);
return
this
.
_peer
.
setCapabilities
(
capabilities
);
})
.
then
(()
=>
{
// Then create a Transport instance.
return
this
.
_peer
.
createTransport
(
this
.
_options
.
transportOptions
);
})
.
then
(()
=>
{
this
.
_logger
.
debug
(
'setCapabilities() | succeed'
);
// Unset busy flag.
this
.
_busy
=
false
;
})
.
catch
((
error
)
=>
{
this
.
_logger
.
error
(
'setCapabilities() | failed: %s'
,
error
);
// Unset busy flag.
this
.
_busy
=
false
;
throw
error
;
});
}
// TODO: This is wrong because it assumes there is already a Transport.
// TODO: If initial local offer, it must get room capabilities and generate
// a proper SDP for receiving audio/video from the remote answerer.
createOffer
()
{
this
.
_logger
.
debug
(
'createOffer()'
);
...
...
@@ -113,21 +165,85 @@ class RTCPeerConnectionPlanB extends EventEmitter
if
(
this
.
_busy
)
return
Promise
.
reject
(
new
InvalidStateError
(
'busy'
));
if
(
!
this
.
_peer
.
capabilities
)
return
Promise
.
reject
(
new
InvalidStateError
(
'capabilities not yet set'
));
if
(
this
.
_signalingState
!==
RTCDictionaries
.
RTCSignalingState
.
stable
)
{
return
Promise
.
reject
(
new
InvalidStateError
(
`invalid signaling state [signalingState:
${
this
.
_signalingState
}
]`
));
}
// Initial offer to be generated by mediasoup.
if
(
!
this
.
_remoteDescription
)
{
return
this
.
_createLocalInitialOffer
();
}
// Re-offer to be generated by mediasoup.
else
{
return
this
.
_createLocalReOffer
();
}
// Set busy flag.
this
.
_busy
=
true
;
// Return a promise that resolves when everything is done.
return
Promise
.
resolve
()
.
then
(()
=>
{
// First handle all the RtpSenders.
let
transport
=
this
.
_peer
.
transports
[
0
];
let
promises
=
[];
// Inspect the already existing RtpSenders and handle them.
for
(
let
rtpSender
of
this
.
_peer
.
rtpSenders
)
{
// Ignore if it already has a transport (so it was already handled).
if
(
rtpSender
.
transport
)
continue
;
let
promise
=
rtpSender
.
setTransport
(
transport
)
.
then
(()
=>
{
rtpSender
.
on
(
'close'
,
()
=>
{
this
.
_logger
.
debug
(
'rtpSender "close" event'
);
// Set flag.
this
.
_negotiationNeeded
=
true
;
// Try to renegotiate.
this
.
_mayRenegotiate
();
});
rtpSender
.
on
(
'parameterschange'
,
()
=>
{
this
.
_logger
.
debug
(
'rtpSender "parameterschange" event'
);
// Set flag.
this
.
_negotiationNeeded
=
true
;
// Try to renegotiate.
this
.
_mayRenegotiate
();
});
});
promises
.
push
(
promise
);
}
return
Promise
.
all
(
promises
);
})
.
then
(()
=>
{
this
.
_logger
.
debug
(
'createOffer() | succeed'
);
// Unset busy flag.
this
.
_busy
=
false
;
// Create an offer.
let
localDescription
=
this
.
_createLocalDescription
(
'offer'
);
// Resolve with it.
return
Promise
.
resolve
(
localDescription
);
})
.
catch
((
error
)
=>
{
this
.
_logger
.
error
(
'createOffer() | failed: %s'
,
error
);
// Unset busy flag.
this
.
_busy
=
false
;
throw
error
;
});
}
createAnswer
()
...
...
@@ -156,8 +272,11 @@ class RTCPeerConnectionPlanB extends EventEmitter
if
(
this
.
_busy
)
return
Promise
.
reject
(
new
InvalidStateError
(
'busy'
));
// NOTE: This method assumes that the given desc is the one previously created
// by createOffer() or createAnswer();
if
(
!
this
.
_peer
.
capabilities
)
return
Promise
.
reject
(
new
InvalidStateError
(
'capabilities not yet set'
));
// NOTE: This method assumes that the given desc is the one previously
// created by createOffer() or createAnswer().
let
remoteDescription
=
desc
;
let
newSignalingState
;
...
...
@@ -206,6 +325,9 @@ class RTCPeerConnectionPlanB extends EventEmitter
if
(
this
.
_busy
)
return
Promise
.
reject
(
new
InvalidStateError
(
'busy'
));
if
(
!
this
.
_peer
.
capabilities
)
return
Promise
.
reject
(
new
InvalidStateError
(
'capabilities not yet set'
));
let
remoteDescription
;
try
...
...
@@ -229,7 +351,7 @@ class RTCPeerConnectionPlanB extends EventEmitter
// Initial offer received from the client.
if
(
!
this
.
_remoteDescription
)
{
return
this
.
_setRemoteInitialOffer
(
remoteDescription
);
return
Promise
.
reject
(
new
Error
(
'initial offer from the endpoint not supported'
)
);
}
// Re-offer received from the client.
else
...
...
@@ -264,68 +386,6 @@ class RTCPeerConnectionPlanB extends EventEmitter
}
}
_createLocalInitialOffer
()
{
this
.
_logger
.
debug
(
'_createLocalInitialOffer()'
);
// TODO: TMP
return
Promise
.
reject
(
new
Error
(
'initial offer generated by mediasoup not yet supported'
));
}
_createLocalReOffer
()
{
this
.
_logger
.
debug
(
'_createLocalReOffer()'
);
let
self
=
this
;
// Set busy flag.
this
.
_busy
=
true
;
// Refresh our RtpSenders.
return
handleRtpSenders
()
.
then
(()
=>
{
this
.
_logger
.
debug
(
'_createLocalReOffer() | succeed'
);
// Unset busy flag.
this
.
_busy
=
false
;
// Increase our SDP version.
this
.
_sdpGlobalFields
.
version
++
;
// Create an offer.
let
localDescription
=
this
.
_createLocalDescription
(
'offer'
);
// Resolve with it.
return
Promise
.
resolve
(
localDescription
);
})
.
catch
((
error
)
=>
{
this
.
_logger
.
error
(
'_createLocalReOffer() | failed: %s'
,
error
);
// Unset busy flag.
this
.
_busy
=
false
;
throw
error
;
});
function
handleRtpSenders
()
{
let
transport
=
self
.
_peer
.
transports
[
0
];
let
promises
=
[];
// Inspect the already existing RtpSenders and handle them.
for
(
let
rtpSender
of
self
.
_peer
.
rtpSenders
)
{
let
promise
=
self
.
_handleRtpSender
(
rtpSender
,
transport
);
promises
.
push
(
promise
);
}
return
Promise
.
all
(
promises
);
}
}
_setRemoteInitialOffer
(
remoteDescription
)
{
this
.
_logger
.
debug
(
'_setRemoteInitialOffer()'
);
...
...
@@ -730,7 +790,8 @@ class RTCPeerConnectionPlanB extends EventEmitter
{
this
.
_logger
.
debug
(
'_setRemoteReOffer()'
);
// TODO: TMP
// TODO: Do it.
return
Promise
.
reject
(
new
Error
(
'renegotiation initiated by the endpoint not yet supported'
));
}
...
...
@@ -755,161 +816,6 @@ class RTCPeerConnectionPlanB extends EventEmitter
return
Promise
.
resolve
();
}
_createPeer
(
sdpObject
)
{
this
.
_logger
.
debug
(
'_createPeer()'
);
this
.
_peer
=
this
.
_room
.
Peer
(
this
.
_peerName
);
// Manage events.
this
.
_peer
.
on
(
'close'
,
(
error
)
=>
{
this
.
emit
(
'close'
,
error
);
});
this
.
_peer
.
on
(
'newrtpsender'
,
()
=>
{
this
.
_logger
.
debug
(
'peer "newrtpsender" event'
);
// Set flag.
this
.
_negotiationNeeded
=
true
;
// Try to renegotiate.
this
.
_checkNegotiationNeeded
();
});
// Map of RtpCodecParameters indexed by payload type.
let
mapCodecs
=
new
Map
();
for
(
let
media
of
sdpObject
.
media
)
{
// Media kind.
let
kind
=
media
.
type
;
for
(
let
rtp
of
media
.
rtp
)
{
// Ignore RTX codecs.
if
(
rtp
.
codec
.
toLowerCase
()
===
'rtx'
)
continue
;
// TODO: This will fail for kind:depth and video/vp8
let
codecMime
=
kind
+
'/'
+
rtp
.
codec
;
let
codec
=
{
kind
:
kind
,
name
:
codecMime
,
payloadType
:
rtp
.
payload
,
clockRate
:
rtp
.
rate
,
rtcpFeedback
:
[],
parameters
:
{}
};
if
(
rtp
.
encoding
>
1
)
codec
.
numChannels
=
rtp
.
encoding
;
mapCodecs
.
set
(
rtp
.
payload
,
codec
);
}
if
(
media
.
fmtp
)
{
for
(
let
fmtp
of
media
.
fmtp
)
{
let
params
=
sdpTransform
.
parseFmtpConfig
(
fmtp
.
config
);
let
codec
=
mapCodecs
.
get
(
fmtp
.
payload
);
if
(
!
codec
)
continue
;
for
(
let
key
in
params
)
{
if
(
params
.
hasOwnProperty
(
key
))
{
let
normalizedKey
=
extra
.
paramFromSDP
(
key
);
codec
.
parameters
[
normalizedKey
]
=
params
[
key
];
}
}
}
}
if
(
media
.
rtcpFb
)
{
for
(
let
fb
of
media
.
rtcpFb
)
{
let
codec
=
mapCodecs
.
get
(
fb
.
payload
);
if
(
!
codec
)
continue
;
codec
.
rtcpFeedback
.
push
(
{
type
:
fb
.
type
,
parameter
:
fb
.
subtype
});
}
}
}
// Set peer capabilities.
let
capabilities
=
{
codecs
:
Array
.
from
(
mapCodecs
.
values
()),
headerExtensions
:
[],
// TODO
fecMechanisms
:
[]
// TODO
};
return
this
.
_peer
.
setCapabilities
(
capabilities
)
.
then
((
capabilities
)
=>
{
// TODO: Why are capabilities stored? they are used nowhere!
this
.
_capabilities
=
capabilities
;
});
}
_handleRtpSender
(
rtpSender
,
transport
)
{
this
.
_logger
.
debug
(
'_handleRtpSender()'
);
let
id
=
rtpSender
.
rtpParameters
.
muxId
;
// If already handled, ignore it.
if
(
this
.
_rtpHandlers
.
has
(
id
))
return
Promise
.
resolve
();
return
rtpSender
.
setTransport
(
transport
)
.
then
(()
=>
{
// Store in the map.
this
.
_rtpHandlers
.
set
(
id
,
rtpSender
);
// Set events.
rtpSender
.
on
(
'close'
,
()
=>
{
this
.
_logger
.
debug
(
'rtpSender "close" event'
);
// Set flag.
this
.
_negotiationNeeded
=
true
;
// Try to renegotiate.
this
.
_checkNegotiationNeeded
();
});
rtpSender
.
on
(
'parameterschange'
,
()
=>
{
this
.
_logger
.
debug
(
'rtpSender "parameterschange" event'
);
// Set flag.
this
.
_negotiationNeeded
=
true
;
// Try to renegotiate.
this
.
_checkNegotiationNeeded
();
});
});
}
_setSignalingState
(
signalingState
)
{
this
.
_logger
.
debug
(
'_setSignalingState() [signalingState:%s]'
,
signalingState
);
...
...
@@ -922,16 +828,17 @@ class RTCPeerConnectionPlanB extends EventEmitter
// Emit 'signalingstatechange'.
this
.
emit
(
'signalingstatechange'
);
// Things may have happened while busy, so check it.
if
(
this
.
_signalingState
===
RTCDictionaries
.
RTCSignalingState
.
stable
)
{
process
.
nextTick
(()
=>
{
this
.
_
checkNegotiationNeeded
();
this
.
_
mayRenegotiate
();
});
}
}
_
checkNegotiationNeeded
()
_
mayRenegotiate
()
{
// If already scheduled, ignore.
if
(
this
.
_negotiationNeededTimer
)
...
...
@@ -941,11 +848,7 @@ class RTCPeerConnectionPlanB extends EventEmitter
if
(
this
.
_busy
)
return
;
// If signalingState is 'stable' we must check whether:
// - negotiation-needed flag was enabled, or
// - there are pending rtpSenders to handle
// If so, emit 'negotiationneeded'.
// Ignore if signalingState is not 'stable'.
if
(
this
.
_signalingState
!==
RTCDictionaries
.
RTCSignalingState
.
stable
)
return
;
...
...
@@ -975,347 +878,14 @@ class RTCPeerConnectionPlanB extends EventEmitter
_createLocalDescription
(
type
)
{
if
(
!
this
.
_options
.
usePlanB
)
return
this
.
_createLocalDescriptionUnifiedPlan
(
type
);
else
return
this
.
_createLocalDescriptionPlanB
(
type
);
}
_createLocalDescriptionUnifiedPlan
(
type
)
{
this
.
_logger
.
debug
(
'_createLocalDescriptionUnifiedPlan() [type:%s]'
,
type
);
this
.
_logger
.
debug
(
'_createLocalDescription() [type:%s]'
,
type
);
let
obj
=
{};
let
sdpVersion
=
this
.
_sdpGlobalFields
.
version
;
obj
.
version
=
0
;
obj
.
origin
=
{
address
:
'0.0.0.0'
,
ipVer
:
4
,
netType
:
'IN'
,
sessionId
:
this
.
_sdpGlobalFields
.
id
,
sessionVersion
:
this
.
_sdpGlobalFields
.
version
,
username
:
'mediasoup'
};
obj
.
name
=
'-'
;
obj
.
timing
=
{
start
:
0
,
stop
:
0
};
obj
.
icelite
=
'ice-lite'
;
obj
.
msidSemantic
=
{
semantic
:
'WMS'
,
token
:
'*'
};
obj
.
groups
=
[
{
type
:
'BUNDLE'
,
mids
:
Array
.
from
(
this
.
_rtpHandlers
.
keys
())
.
filter
((
mid
)
=>
{
let
rtpHandler
=
this
.
_rtpHandlers
.
get
(
mid
);
return
!
rtpHandler
.
closed
;
})
.
join
(
' '
)
}
];
obj
.
media
=
[];
let
transport
=
this
.
_peer
.
transports
[
0
];
// DTLS fingerprint.
obj
.
fingerprint
=
{
type
:
'sha-256'
,
hash
:
extra
.
fingerprintToSDP
(
transport
.
dtlsLocalParameters
.
fingerprints
[
'sha-256'
])
};
let
bundleTranspportSet
=
false
;
for
(
let
rtpHandler
of
this
.
_rtpHandlers
.
values
())
{
let
objMedia
=
{};
let
transport
=
rtpHandler
.
transport
;
let
isClosedRtpSender
=
false
;
if
(
rtpHandler
.
isRtpSender
()
&&
(
rtpHandler
.
closed
||
!
rtpHandler
.
available
))
{
isClosedRtpSender
=
true
;
}
// m= line.
objMedia
.
type
=
rtpHandler
.
kind
;
objMedia
.
port
=
7
;
objMedia
.
protocol
=
'RTP/SAVPF'
;
// If closed or not available sender, set port 0.
if
(
rtpHandler
.
closed
||
isClosedRtpSender
)
objMedia
.
port
=
0
;
// c= line.
objMedia
.
connection
=
{
ip
:
'127.0.0.1'
,
version
:
4
};
// mid.
objMedia
.
mid
=
rtpHandler
.
rtpParameters
.
muxId
;
// ICE.
objMedia
.
iceUfrag
=
transport
.
iceLocalParameters
.
usernameFragment
;
objMedia
.
icePwd
=
transport
.
iceLocalParameters
.
password
;
if
(
!
bundleTranspportSet
)
{
objMedia
.
candidates
=
[];
for
(
let
candidate
of
transport
.
iceLocalCandidates
)
{
let
objCandidate
=
{};
// mediasoup does not support non rtcp-mux so candidates component is
// always RTP (1).
objCandidate
.
component
=
1
;
objCandidate
.
foundation
=
candidate
.
foundation
;
objCandidate
.
ip
=
candidate
.
ip
;
objCandidate
.
port
=
candidate
.
port
;
objCandidate
.
priority
=
candidate
.
priority
;
objCandidate
.
transport
=
candidate
.
protocol
;
objCandidate
.
type
=
candidate
.
type
;
if
(
candidate
.
tcpType
)
objCandidate
.
tcpType
=
candidate
.
tcpType
;
objMedia
.
candidates
.
push
(
objCandidate
);
}
}
if
(
!
rtpHandler
.
closed
)
bundleTranspportSet
=
true
;
// DTLS.
// If 'offer' always use 'actpass'.
if
(
type
===
'offer'
)
objMedia
.
setup
=
'actpass'
;
else
objMedia
.
setup
=
transport
.
dtlsLocalParameters
.
role
===
'client'
?
'active'
:
'passive'
;
// Media.
if
(
rtpHandler
.
isRtpReceiver
())
{
objMedia
.
direction
=
'recvonly'
;
}
else
{
if
(
!
isClosedRtpSender
)
objMedia
.
direction
=
'sendonly'
;
else
objMedia
.
direction
=
'inactive'
;
}
// SSRC for media.
let
mediaSsrc
;
// SSRC for RTX.
let
featureSsrc
;
// Array of payload types.
let
payloads
=
[];
objMedia
.
payloads
=
''
;
objMedia
.
rtp
=
[];
objMedia
.
rtcpFb
=
[];
objMedia
.
fmtp
=
[];
if
(
rtpHandler
.
isRtpReceiver
()
||
!
isClosedRtpSender
)
{
for
(
let
codec
of
rtpHandler
.
rtpParameters
.
codecs
)
{
payloads
.
push
(
codec
.
payloadType
);
let
codecSubtype
=
codec
.
name
.
split
(
'/'
)[
1
];
let
rtp
=
{
payload
:
codec
.
payloadType
,
codec
:
codecSubtype
,
rate
:
codec
.
clockRate
};
if
(
codec
.
numChannels
>
1
)
rtp
.
encoding
=
codec
.
numChannels
;
objMedia
.
rtp
.
push
(
rtp
);
// If the codec has RTX add another SDP codec and a corresponding
// fmtp entry.
if
(
codec
.
rtx
)
{
payloads
.
push
(
codec
.
rtx
.
payloadType
);
objMedia
.
rtp
.
push
(
{
payload
:
codec
.
rtx
.
payloadType
,
codec
:
'rtx'
,
rate
:
codec
.
clockRate
});
let
rtxFmtp
=
{
payload
:
codec
.
rtx
.
payloadType
,
config
:
`apt=
${
codec
.
payloadType
}
`
};
if
(
codec
.
rtx
.
rtxTime
)
rtxFmtp
.
config
+=
`;rtx-time=
${
codec
.
rtx
.
rtxTime
}
`
;
objMedia
.
fmtp
.
push
(
rtxFmtp
);
}
// If codec has parameters add them into fmtp.
if
(
codec
.
parameters
)
{
let
paramFmtp
=
{
payload
:
codec
.
payloadType
,
config
:
''
};
for
(
let
key
in
codec
.
parameters
)
{
if
(
codec
.
parameters
.
hasOwnProperty
(
key
))
{
let
normalizedKey
=
extra
.
paramToSDP
(
key
);
if
(
paramFmtp
.
config
)
paramFmtp
.
config
+=
';'
;
paramFmtp
.
config
+=
`
${
normalizedKey
}
=
${
codec
.
parameters
[
key
]}
`
;
}
}
if
(
paramFmtp
.
config
)
objMedia
.
fmtp
.
push
(
paramFmtp
);
}
if
(
codec
.
rtcpFeedback
)
{
for
(
let
fb
of
codec
.
rtcpFeedback
)
{
objMedia
.
rtcpFb
.
push
(
{
payload
:
codec
.
payloadType
,
type
:
fb
.
type
,
subtype
:
fb
.
parameter
});
}
}
}
objMedia
.
payloads
=
payloads
.
join
(
' '
);
objMedia
.
ssrcs
=
[];
for
(
let
encoding
of
rtpHandler
.
rtpParameters
.
encodings
)
{
// TODO: Wrong when simulcast
mediaSsrc
=
mediaSsrc
||
encoding
.
ssrc
;
// TODO: Same
// TODO: Uncomment when implemented
// if (encoding.rtx)
// featureSsrc = featureSsrc || encoding.rtx.ssrc;
}
// SSRC (just for available RtpSender).
if
(
rtpHandler
.
isRtpSender
()
&&
!
isClosedRtpSender
)
{
if
(
mediaSsrc
)
{
objMedia
.
ssrcs
.
push
(
{
id
:
mediaSsrc
,
attribute
:
'cname'
,
value
:
rtpHandler
.
rtpParameters
.
rtcp
.
cname
});
if
(
rtpHandler
.
rtpParameters
.
userParameters
.
msid
)
objMedia
.
msid
=
rtpHandler
.
rtpParameters
.
userParameters
.
msid
;
}
if
(
featureSsrc
)
{
objMedia
.
ssrcs
.
push
(
{
id
:
featureSsrc
,
attribute
:
'cname'
,
value
:
rtpHandler
.
rtpParameters
.
rtcp
.
cname
});
}
if
(
mediaSsrc
&&
featureSsrc
)
{
objMedia
.
ssrcGroups
=
[
{
semantics
:
'FID'
,
// TODO: what is this?
ssrcs
:
`
${
mediaSsrc
}
${
featureSsrc
}
`
}
];
}
}
}
// RTCP.
// Set rtcp-mux.
objMedia
.
rtcpMux
=
'rtcp-mux'
;
// Set rtcp-mux-only.
// TODO: https://github.com/clux/sdp-transform/issues/48
// objMedia.rtcpMuxOnly = 'rtcp-mux-only';
// Bandwidth.
switch
(
rtpHandler
.
kind
)
{
case
'audio'
:
{
if
(
this
.
_options
.
bandwidth
&&
this
.
_options
.
bandwidth
.
audio
)
{
objMedia
.
bandwidth
=
[
{
type
:
'AS'
,
limit
:
this
.
_options
.
bandwidth
.
audio
}
];
}
break
;
}
case
'video'
:
{
if
(
this
.
_options
.
bandwidth
&&
this
.
_options
.
bandwidth
.
video
)
{
objMedia
.
bandwidth
=
[
{
type
:
'AS'
,
limit
:
this
.
_options
.
bandwidth
.
video
}
];
}
break
;
}
}
// Add the media section.
obj
.
media
.
push
(
objMedia
);
}
// Create local RTCSessionDescription.
let
localDescription
=
new
RTCSessionDescription
(
{
type
:
type
,
sdp
:
obj
});
return
localDescription
;
}
_createLocalDescriptionPlanB
(
type
)
{
this
.
_logger
.
debug
(
'_createLocalDescriptionPlanB() [type:%s]'
,
type
);
let
obj
=
{};
// Increase SDP version if an offer.
if
(
type
===
'offer'
)
sdpVersion
++
;
obj
.
version
=
0
;
obj
.
origin
=
...
...
@@ -1324,7 +894,7 @@ class RTCPeerConnectionPlanB extends EventEmitter
ipVer
:
4
,
netType
:
'IN'
,
sessionId
:
this
.
_sdpGlobalFields
.
id
,
sessionVersion
:
this
.
_sdpGlobalFields
.
v
ersion
,
sessionVersion
:
sdpV
ersion
,
username
:
'mediasoup'
};
obj
.
name
=
'-'
;
...
...
lib/webrtc/RTCPeerConnection/common.js
0 → 100644
浏览文件 @
248aaa3a
'use strict'
;
const
sdpTransform
=
require
(
'sdp-transform'
);
const
extra
=
require
(
'../../extra'
);
module
.
exports
=
{
descToCapabilities
(
desc
)
{
let
parsed
=
desc
.
parsed
;
// Map of RtpCodecParameters indexed by payload type.
let
mapCodecs
=
new
Map
();
for
(
let
media
of
parsed
.
media
)
{
// Media kind.
let
kind
=
media
.
type
;
for
(
let
rtp
of
media
.
rtp
)
{
// Ignore feature codecs.
switch
(
rtp
.
codec
.
toLowerCase
())
{
case
'rtx'
:
case
'ulpfec'
:
case
'flexfec'
:
case
'red'
:
continue
;
default
:
}
// TODO: This will fail for kind:depth and video/vp8, but who knows?
let
codecMime
=
kind
+
'/'
+
rtp
.
codec
;
let
codec
=
{
kind
:
kind
,
name
:
codecMime
,
payloadType
:
rtp
.
payload
,
clockRate
:
rtp
.
rate
,
rtcpFeedback
:
[],
parameters
:
{}
};
if
(
rtp
.
encoding
>
1
)
codec
.
numChannels
=
rtp
.
encoding
;
mapCodecs
.
set
(
rtp
.
payload
,
codec
);
}
if
(
media
.
fmtp
)
{
for
(
let
fmtp
of
media
.
fmtp
)
{
let
params
=
sdpTransform
.
parseFmtpConfig
(
fmtp
.
config
);
let
codec
=
mapCodecs
.
get
(
fmtp
.
payload
);
if
(
!
codec
)
continue
;
for
(
let
key
in
Object
.
keys
(
params
))
{
let
normalizedKey
=
extra
.
paramFromSDP
(
key
);
codec
.
parameters
[
normalizedKey
]
=
params
[
key
];
}
}
}
if
(
media
.
rtcpFb
)
{
for
(
let
fb
of
media
.
rtcpFb
)
{
let
codec
=
mapCodecs
.
get
(
fb
.
payload
);
if
(
!
codec
)
continue
;
codec
.
rtcpFeedback
.
push
(
{
type
:
fb
.
type
,
parameter
:
fb
.
subtype
});
}
}
let
capabilities
=
{
codecs
:
Array
.
from
(
mapCodecs
.
values
()),
headerExtensions
:
[],
// TODO
fecMechanisms
:
[]
// TODO
};
return
capabilities
;
}
}
};
lib/webrtc/RTCPeerConnection/index.js
浏览文件 @
248aaa3a
...
...
@@ -2,28 +2,31 @@
const
RTCPeerConnectionUnifiedPlan
=
require
(
'./RTCPeerConnectionUnifiedPlan'
);
const
RTCPeerConnectionPlanB
=
require
(
'./RTCPeerConnectionPlanB'
);
const
Peer
=
require
(
'../../Peer'
);
class
RTCPeerConnection
{
/**
* RTCPeerConnection constructor.
* @param {Room} room
* @param {string} peerName
* @param {object} [options]
* RTCPeerConnection constructor.ç
* @param {object} options
* @param {Peer} options.peer - Peer instance.
* @param {object} [options.transportOptions] - Options for Transport.
* @param {boolean} [options.usePlanB] - Use Plan-B rather than Unified-Plan.
* @param {object} [options.bandwidth]
* @param {number} [options.bandwidth.audio] - Maximum bandwidth for audio streams.
* @param {number} [options.bandwidth.video] - Maximum bandwidth for video streams.
*/
constructor
(
room
,
peerName
,
options
)
constructor
(
options
)
{
options
=
options
||
{};
if
(
!
(
options
.
peer
instanceof
Peer
))
throw
new
TypeError
(
'missing/wrong options.peer'
);
if
(
!
options
.
usePlanB
)
return
new
RTCPeerConnectionUnifiedPlan
(
room
,
peerName
,
options
);
return
new
RTCPeerConnectionUnifiedPlan
(
options
);
else
return
new
RTCPeerConnectionPlanB
(
room
,
peerName
,
options
);
return
new
RTCPeerConnectionPlanB
(
options
);
}
}
...
...
worker/src/RTC/Peer.cpp
浏览文件 @
248aaa3a
...
...
@@ -189,6 +189,9 @@ namespace RTC
Json
::
Value
data
=
this
->
capabilities
.
toJson
();
// NOTE: We accept the request *after* calling onPeerCapabilities(). This
// guarantees that the Peer will receive a 'newrtpsender' event for all its
// associated RtpSenders *before* the setCapabilities() Promise resolves.
request
->
Accept
(
data
);
break
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论