Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
f0db9781
提交
f0db9781
authored
6月 26, 2016
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Redesign capabilities stuf.
上级
0ad4ae10
隐藏空白字符变更
内嵌
并排
正在显示
21 个修改的文件
包含
498 行增加
和
719 行删除
+498
-719
supportedCapabilities.js
data/supportedCapabilities.js
+3
-98
Peer.js
lib/Peer.js
+34
-0
Room.js
lib/Room.js
+3
-6
options.js
test/data/options.js
+40
-17
test_Peer.js
test/test_Peer.js
+6
-2
test_RtpReceiver.js
test/test_RtpReceiver.js
+31
-27
test_Transport.js
test/test_Transport.js
+2
-3
Request.h
worker/include/Channel/Request.h
+1
-0
Peer.h
worker/include/RTC/Peer.h
+10
-1
Room.h
worker/include/RTC/Room.h
+1
-0
RtpDictionaries.h
worker/include/RTC/RtpDictionaries.h
+34
-53
mediasoup-worker.gyp
worker/mediasoup-worker.gyp
+0
-2
Request.cpp
worker/src/Channel/Request.cpp
+1
-0
Loop.cpp
worker/src/Loop.cpp
+1
-0
Peer.cpp
worker/src/RTC/Peer.cpp
+63
-13
Room.cpp
worker/src/RTC/Room.cpp
+77
-119
RtpCapabilities.cpp
worker/src/RTC/RtpDictionaries/RtpCapabilities.cpp
+15
-17
RtpCodec.cpp
worker/src/RTC/RtpDictionaries/RtpCodec.cpp
+0
-90
RtpCodecCapability.cpp
worker/src/RTC/RtpDictionaries/RtpCodecCapability.cpp
+0
-231
RtpCodecParameters.cpp
worker/src/RTC/RtpDictionaries/RtpCodecParameters.cpp
+171
-35
RtpParameters.cpp
worker/src/RTC/RtpDictionaries/RtpParameters.cpp
+5
-5
没有找到文件。
data/supportedCapabilities.js
浏览文件 @
f0db9781
...
...
@@ -7,103 +7,7 @@
let
supportedCapabilities
=
{
codecs
:
[
// Audio codecs:
{
kind
:
'audio'
,
name
:
'audio/opus'
,
preferredPayloadType
:
96
,
clockRate
:
48000
,
numChannels
:
2
},
{
kind
:
'audio'
,
name
:
'audio/ISAC'
,
preferredPayloadType
:
97
,
clockRate
:
16000
},
{
kind
:
'audio'
,
name
:
'audio/ISAC'
,
preferredPayloadType
:
98
,
clockRate
:
32000
},
{
kind
:
'audio'
,
name
:
'audio/G722'
,
preferredPayloadType
:
9
,
clockRate
:
8000
},
{
kind
:
'audio'
,
name
:
'audio/PCMU'
,
preferredPayloadType
:
0
,
clockRate
:
8000
},
{
kind
:
'audio'
,
name
:
'audio/PCMA'
,
preferredPayloadType
:
8
,
clockRate
:
8000
},
// Video codecs:
{
kind
:
'video'
,
name
:
'video/VP8'
,
preferredPayloadType
:
110
,
clockRate
:
90000
},
{
kind
:
'video'
,
name
:
'video/VP9'
,
preferredPayloadType
:
111
,
clockRate
:
90000
},
{
kind
:
'video'
,
name
:
'video/H264'
,
preferredPayloadType
:
112
,
clockRate
:
90000
,
parameters
:
{
packetizationMode
:
[
0
,
1
,
2
]
}
},
// Depth codecs:
{
kind
:
'depth'
,
name
:
'video/VP8'
,
preferredPayloadType
:
120
,
clockRate
:
90000
},
// Feature codecs:
{
kind
:
'audio'
,
name
:
'audio/CN'
,
preferredPayloadType
:
77
,
clockRate
:
32000
},
{
kind
:
'audio'
,
name
:
'audio/CN'
,
preferredPayloadType
:
78
,
clockRate
:
16000
},
{
kind
:
'audio'
,
name
:
'audio/CN'
,
preferredPayloadType
:
13
,
clockRate
:
8000
},
{
kind
:
'audio'
,
name
:
'audio/telephone-event'
,
preferredPayloadType
:
79
,
clockRate
:
8000
}
],
headerExtensions
:
headerExtensions
:
[
{
kind
:
''
,
...
...
@@ -111,7 +15,8 @@ let supportedCapabilities =
preferredId
:
1
,
preferredEncrypt
:
false
}
]
],
fecMechanisms
:
[]
};
module
.
exports
=
supportedCapabilities
;
lib/Peer.js
浏览文件 @
f0db9781
...
...
@@ -212,6 +212,40 @@ class Peer extends EventEmitter
});
}
/**
* Set peer capabilities.
*
* @param {RtpCapabilities} [options.capabilities]
* @param {[Object]} [options]
* @param {[Boolean]} [options.udp=true] - Listen UDP.
* @param {[Boolean]} [options.tcp=true] - Listen TCP.
* @param {[Boolean]} [options.preferIPv4=false] - Prefer IPv4 candidates.
* @param {[Boolean]} [options.preferIPv6=false] - Prefer IPv6 candidates.
* @param {[Boolean]} [options.preferUdp=false] - Prefer UDP candidates.
* @param {[Boolean]} [options.preferTcp=false] - Prefer TCP candidates.
*
* @return {Promise} Resolves to the created Transport.
*/
setCapabilities
(
capabilities
)
{
logger
.
debug
(
'setCapabilities() [capabilities:%o]'
,
capabilities
);
if
(
this
.
_closed
)
return
Promise
.
reject
(
new
errors
.
InvalidStateError
(
'Peer closed'
));
return
this
.
_channel
.
request
(
'peer.setCapabilities'
,
this
.
_internal
,
capabilities
)
.
then
((
data
)
=>
{
logger
.
debug
(
'"peer.setCapabilities" request succeeded'
);
})
.
catch
((
error
)
=>
{
logger
.
error
(
'"peer.setCapabilities" request failed: %s'
,
error
);
throw
error
;
});
}
/**
* Create a Transport instance.
*
...
...
lib/Room.js
浏览文件 @
f0db9781
...
...
@@ -157,15 +157,12 @@ class Room extends EventEmitter
* Create a Peer instance.
*
* @param {String} peerName - Peer identificator.
* @param {Object} [options]
* @param {RtpCapabilities} [options.capabilities]
*
* @return {Peer}
*/
Peer
(
peerName
,
data
)
Peer
(
peerName
)
{
logger
.
debug
(
'Peer() [peerName:"%s", data:%o]'
,
peerName
,
data
);
logger
.
debug
(
'Peer() [peerName:"%s]'
,
peerName
);
if
(
this
.
_closed
)
throw
new
errors
.
InvalidStateError
(
'Room closed'
);
...
...
@@ -198,7 +195,7 @@ class Room extends EventEmitter
this
.
_peers
.
delete
(
peerName
);
});
this
.
_channel
.
request
(
'room.createPeer'
,
internal
,
data
)
this
.
_channel
.
request
(
'room.createPeer'
,
internal
)
.
then
(()
=>
{
logger
.
debug
(
'"room.createPeer" request succeeded'
);
...
...
test/data/options.js
浏览文件 @
f0db9781
...
...
@@ -48,26 +48,49 @@ module.exports =
]
},
peer
Option
s
:
peer
Capabilitie
s
:
{
capabilities
:
{
codecs
:
[
codecs
:
[
{
kind
:
'audio'
,
name
:
'audio/opus'
,
payloadType
:
100
,
clockRate
:
48000
,
numChannels
:
2
},
{
kind
:
'audio'
,
name
:
'audio/PCMU'
,
payloadType
:
0
,
clockRate
:
8000
},
{
kind
:
'video'
,
name
:
'video/VP8'
,
payloadType
:
101
,
clockRate
:
90000
},
{
kind
:
'video'
,
name
:
'video/H264'
,
payloadType
:
102
,
clockRate
:
90000
,
parameters
:
{
kind
:
'audio'
,
name
:
'audio/opus'
,
preferredPayloadType
:
100
,
clockRate
:
48000
,
numChannels
:
2
},
packetizationMode
:
0
}
},
{
kind
:
'video'
,
name
:
'video/H264'
,
payloadType
:
103
,
clockRate
:
90000
,
parameters
:
{
kind
:
'video'
,
name
:
'video/VP8'
,
preferredPayloadType
:
101
,
clockRate
:
90000
packetizationMode
:
1
}
]
}
}
]
}
};
test/test_Peer.js
浏览文件 @
f0db9781
...
...
@@ -4,7 +4,7 @@ const tap = require('tap');
const
mediasoup
=
require
(
'../'
);
const
roomOptions
=
require
(
'./data/options'
).
roomOptions
;
const
peer
Options
=
require
(
'./data/options'
).
peerOption
s
;
const
peer
Capabilities
=
require
(
'./data/options'
).
peerCapabilitie
s
;
function
initTest
(
t
)
{
...
...
@@ -16,8 +16,12 @@ function initTest(t)
return
server
.
createRoom
(
roomOptions
)
.
then
((
room
)
=>
{
peer
=
room
.
Peer
(
'alice'
,
peerOptions
);
peer
=
room
.
Peer
(
'alice'
);
return
peer
.
setCapabilities
(
peerCapabilities
);
})
.
then
(()
=>
{
return
{
peer
:
peer
};
});
}
...
...
test/test_RtpReceiver.js
浏览文件 @
f0db9781
...
...
@@ -4,7 +4,7 @@ const tap = require('tap');
const
mediasoup
=
require
(
'../'
);
const
roomOptions
=
require
(
'./data/options'
).
roomOptions
;
const
peer
Options
=
require
(
'./data/options'
).
peerOption
s
;
const
peer
Capabilities
=
require
(
'./data/options'
).
peerCapabilitie
s
;
const
promiseSeries
=
require
(
'./utils/promiseSeries'
);
function
initTest
(
t
)
...
...
@@ -17,8 +17,12 @@ function initTest(t)
return
server
.
createRoom
(
roomOptions
)
.
then
((
room
)
=>
{
peer
=
room
.
Peer
(
'alice'
,
peerOptions
);
peer
=
room
.
Peer
(
'alice'
);
return
peer
.
setCapabilities
(
peerCapabilities
);
})
.
then
(()
=>
{
return
peer
.
createTransport
({
tcp
:
false
});
})
.
then
((
transport
)
=>
...
...
@@ -78,7 +82,7 @@ tap.test('rtpReceiver.receive() with encodings without codecPayloadType must suc
[
{
name
:
'video/H264'
,
payloadType
:
10
1
,
payloadType
:
10
2
,
clockRate
:
90000
,
parameters
:
{
...
...
@@ -87,7 +91,7 @@ tap.test('rtpReceiver.receive() with encodings without codecPayloadType must suc
},
{
name
:
'video/H264'
,
payloadType
:
10
2
,
payloadType
:
10
3
,
clockRate
:
90000
,
parameters
:
{
...
...
@@ -101,7 +105,7 @@ tap.test('rtpReceiver.receive() with encodings without codecPayloadType must suc
ssrc
:
1111
},
{
codecPayloadType
:
10
2
codecPayloadType
:
10
3
},
{
ssrc
:
3333
...
...
@@ -115,9 +119,9 @@ tap.test('rtpReceiver.receive() with encodings without codecPayloadType must suc
let
rtpParameters
=
rtpReceiver
.
rtpParameters
;
t
.
equal
(
rtpParameters
.
encodings
.
length
,
3
,
'computed rtpParameters has 3 encodings'
);
t
.
equal
(
rtpParameters
.
encodings
[
0
].
codecPayloadType
,
10
1
,
'first encoding has codecPayloadType 101
'
);
t
.
equal
(
rtpParameters
.
encodings
[
1
].
codecPayloadType
,
10
2
,
'second encoding has codecPayloadType 102
'
);
t
.
equal
(
rtpParameters
.
encodings
[
2
].
codecPayloadType
,
10
1
,
'third encoding has codecPayloadType 101
'
);
t
.
equal
(
rtpParameters
.
encodings
[
0
].
codecPayloadType
,
10
2
,
'first encoding has codecPayloadType 102
'
);
t
.
equal
(
rtpParameters
.
encodings
[
1
].
codecPayloadType
,
10
3
,
'second encoding has codecPayloadType 103
'
);
t
.
equal
(
rtpParameters
.
encodings
[
2
].
codecPayloadType
,
10
2
,
'third encoding has codecPayloadType 102
'
);
})
.
catch
((
error
)
=>
t
.
fail
(
`rtpReceiver.receive() failed:
${
error
}
`
));
});
...
...
@@ -138,7 +142,7 @@ tap.test('rtpReceiver.receive() with full rtpParameters must succeed', { timeout
[
{
name
:
'video/VP8'
,
payloadType
:
10
0
,
payloadType
:
10
1
,
clockRate
:
90000
,
maxptime
:
80
,
ptime
:
60
,
...
...
@@ -172,7 +176,7 @@ tap.test('rtpReceiver.receive() with full rtpParameters must succeed', { timeout
[
{
ssrc
:
100000
,
codecPayloadType
:
10
0
,
codecPayloadType
:
10
1
,
fec
:
{
ssrc
:
200000
,
...
...
@@ -258,7 +262,7 @@ tap.test('two rtpReceiver.receive() over the same transport sharing PT values mu
[
{
name
:
'audio/opus'
,
payloadType
:
10
1
,
payloadType
:
10
0
,
clockRate
:
48000
}
],
...
...
@@ -280,7 +284,7 @@ tap.test('two rtpReceiver.receive() over the same transport sharing PT values mu
[
{
name
:
'audio/opus'
,
payloadType
:
10
1
,
payloadType
:
10
0
,
clockRate
:
48000
}
],
...
...
@@ -336,7 +340,7 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
[
{
name
:
'opus'
,
payloadType
:
10
1
payloadType
:
10
0
}
]
})
...
...
@@ -355,7 +359,7 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
[
{
name
:
'/opus'
,
payloadType
:
10
1
,
payloadType
:
10
0
,
clockRate
:
48000
}
]
...
...
@@ -375,7 +379,7 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
[
{
name
:
'audio/'
,
payloadType
:
10
1
,
payloadType
:
10
0
,
clockRate
:
48000
}
]
...
...
@@ -433,7 +437,7 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
[
{
name
:
'audio/opus'
,
payloadType
:
10
2
payloadType
:
10
0
}
]
})
...
...
@@ -452,7 +456,7 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
[
{
name
:
'audio/opus'
,
payloadType
:
10
1
,
payloadType
:
10
0
,
clockRate
:
48000
,
rtx
:
{}
}
...
...
@@ -473,12 +477,12 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
[
{
name
:
'audio/opus'
,
payloadType
:
10
1
,
payloadType
:
10
0
,
clockRate
:
48000
},
{
name
:
'audio/opus'
,
payloadType
:
10
1
,
payloadType
:
10
0
,
clockRate
:
48000
}
]
...
...
@@ -502,12 +506,12 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
clockRate
:
48000
,
rtx
:
{
payloadType
:
101
payloadType
:
0
}
},
{
name
:
'audio/
G722
'
,
payloadType
:
101
,
name
:
'audio/
PCMU
'
,
payloadType
:
0
,
clockRate
:
8000
}
]
...
...
@@ -541,7 +545,7 @@ tap.test('rtpReceiver.receive() with wrong encodings must fail', { timeout: 2000
[
{
name
:
'audio/opus'
,
payloadType
:
10
1
,
payloadType
:
10
0
,
clockRate
:
48000
}
],
...
...
@@ -611,7 +615,7 @@ tap.test('two rtpReceiver.receive() over the same transport sharing PT values mu
[
{
name
:
'audio/opus'
,
payloadType
:
10
1
,
payloadType
:
10
0
,
clockRate
:
48000
}
]
...
...
@@ -626,9 +630,9 @@ tap.test('two rtpReceiver.receive() over the same transport sharing PT values mu
codecs
:
[
{
name
:
'audio/
PCMU
'
,
payloadType
:
10
1
,
clockRate
:
8000
name
:
'audio/
opus
'
,
payloadType
:
10
0
,
clockRate
:
4
8000
}
]
})
...
...
test/test_Transport.js
浏览文件 @
f0db9781
...
...
@@ -4,7 +4,6 @@ const tap = require('tap');
const
mediasoup
=
require
(
'../'
);
const
roomOptions
=
require
(
'./data/options'
).
roomOptions
;
const
peerOptions
=
require
(
'./data/options'
).
peerOptions
;
function
initTest
(
t
)
{
...
...
@@ -16,7 +15,7 @@ function initTest(t)
return
server
.
createRoom
(
roomOptions
)
.
then
((
room
)
=>
{
peer
=
room
.
Peer
(
'alice'
,
peerOptions
);
peer
=
room
.
Peer
(
'alice'
);
return
peer
.
createTransport
({
tcp
:
false
});
})
...
...
@@ -180,7 +179,7 @@ tap.test('transport.close() must succeed', { timeout: 2000 }, (t) =>
server
.
createRoom
(
roomOptions
)
.
then
((
room
)
=>
{
let
peer
=
room
.
Peer
(
'alice'
,
peerOptions
);
let
peer
=
room
.
Peer
(
'alice'
);
peer
.
createTransport
({
tcp
:
false
})
.
then
((
transport
)
=>
...
...
worker/include/Channel/Request.h
浏览文件 @
f0db9781
...
...
@@ -25,6 +25,7 @@ namespace Channel
room_createPeer
,
peer_close
,
peer_dump
,
peer_setCapabilities
,
peer_createTransport
,
peer_createRtpReceiver
,
transport_close
,
...
...
worker/include/RTC/Peer.h
浏览文件 @
f0db9781
...
...
@@ -27,6 +27,7 @@ namespace RTC
{
public
:
virtual
void
onPeerClosed
(
RTC
::
Peer
*
peer
)
=
0
;
virtual
void
onPeerCapabilities
(
RTC
::
Peer
*
peer
)
=
0
;
virtual
void
onPeerRtpReceiverParameters
(
RTC
::
Peer
*
peer
,
RTC
::
RtpReceiver
*
rtpReceiver
)
=
0
;
virtual
void
onPeerRtpReceiverParametersDone
(
RTC
::
Peer
*
peer
,
RTC
::
RtpReceiver
*
rtpReceiver
)
=
0
;
virtual
void
onPeerRtpReceiverClosed
(
RTC
::
Peer
*
peer
,
RTC
::
RtpReceiver
*
rtpReceiver
)
=
0
;
...
...
@@ -35,12 +36,13 @@ namespace RTC
};
public
:
Peer
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
uint32_t
peerId
,
std
::
string
&
peerName
,
Json
::
Value
&
data
);
Peer
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
uint32_t
peerId
,
std
::
string
&
peerName
);
virtual
~
Peer
();
void
Close
();
Json
::
Value
toJson
();
void
HandleRequest
(
Channel
::
Request
*
request
);
bool
HasCapabilities
();
std
::
vector
<
RTC
::
RtpReceiver
*>
GetRtpReceivers
();
/**
* Add a new RtpSender to the Peer.
...
...
@@ -79,6 +81,7 @@ namespace RTC
Listener
*
listener
=
nullptr
;
Channel
::
Notifier
*
notifier
=
nullptr
;
// Others.
bool
hasCapabilities
=
false
;
RTC
::
RtpCapabilities
capabilities
;
std
::
unordered_map
<
uint32_t
,
RTC
::
Transport
*>
transports
;
std
::
unordered_map
<
uint32_t
,
RTC
::
RtpReceiver
*>
rtpReceivers
;
...
...
@@ -87,6 +90,12 @@ namespace RTC
/* Inline methods. */
inline
bool
Peer
::
HasCapabilities
()
{
return
this
->
hasCapabilities
;
}
inline
std
::
vector
<
RTC
::
RtpReceiver
*>
Peer
::
GetRtpReceivers
()
{
...
...
worker/include/RTC/Room.h
浏览文件 @
f0db9781
...
...
@@ -49,6 +49,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::Peer::Listener. */
public
:
virtual
void
onPeerClosed
(
RTC
::
Peer
*
peer
)
override
;
virtual
void
onPeerCapabilities
(
RTC
::
Peer
*
peer
)
override
;
virtual
void
onPeerRtpReceiverParameters
(
RTC
::
Peer
*
peer
,
RTC
::
RtpReceiver
*
rtpReceiver
)
override
;
virtual
void
onPeerRtpReceiverParametersDone
(
RTC
::
Peer
*
peer
,
RTC
::
RtpReceiver
*
rtpReceiver
)
override
;
virtual
void
onPeerRtpReceiverClosed
(
RTC
::
Peer
*
peer
,
RTC
::
RtpReceiver
*
rtpReceiver
)
override
;
...
...
worker/include/RTC/RtpDictionaries.h
浏览文件 @
f0db9781
...
...
@@ -11,6 +11,13 @@
namespace
RTC
{
enum
class
Scope
:
uint8_t
{
ROOM_CAPABILITY
=
1
,
PEER_CAPABILITY
,
RECEIVE
};
class
Media
{
public
:
...
...
@@ -56,12 +63,13 @@ namespace RTC
VP9
,
H264
,
H265
,
// Complementary codecs:
CN
=
300
,
TELEPHONE_EVENT
,
// Feature codecs:
ULPFEC
=
10
00
,
ULPFEC
=
4
00
,
FLEXFEC
,
RED
,
CN
,
TELEPHONE_EVENT
RED
};
private
:
...
...
@@ -92,12 +100,17 @@ namespace RTC
bool
IsMediaCodec
()
{
return
this
->
subtype
>=
Subtype
(
100
)
&&
this
->
subtype
<
(
Subtype
)
1000
;
return
this
->
subtype
>=
Subtype
(
100
)
&&
this
->
subtype
<
(
Subtype
)
300
;
}
bool
IsComplementaryCodec
()
{
return
this
->
subtype
>=
Subtype
(
300
)
&&
this
->
subtype
<
(
Subtype
)
400
;
}
bool
IsFeatureCodec
()
{
return
this
->
subtype
>=
Subtype
(
10
00
);
return
this
->
subtype
>=
Subtype
(
4
00
);
}
public
:
...
...
@@ -108,23 +121,6 @@ namespace RTC
std
::
string
name
;
};
class
RtpCodec
{
public
:
RtpCodec
()
{};
RtpCodec
(
Json
::
Value
&
data
);
void
toJson
(
Json
::
Value
&
json
);
public
:
RtpCodecMime
mime
;
uint32_t
clockRate
=
0
;
uint32_t
maxptime
=
0
;
uint32_t
ptime
=
0
;
uint32_t
numChannels
=
1
;
RTC
::
Parameters
parameters
;
};
class
RTCRtpCodecRtxParameters
{
public
:
...
...
@@ -150,23 +146,31 @@ namespace RTC
std
::
string
parameter
;
};
class
RtpCodecParameters
:
public
RtpCodec
class
RtpCodecParameters
{
public
:
RtpCodecParameters
(
Json
::
Value
&
data
,
bool
isRoomCodec
);
RtpCodecParameters
()
{};
// TODO: yes?
RtpCodecParameters
(
Json
::
Value
&
data
,
RTC
::
Scope
scope
);
Json
::
Value
toJson
();
bool
Matches
(
RtpCodecParameters
&
codec
,
bool
checkPayloadType
=
false
);
private
:
void
CheckCodec
();
private
:
bool
isRoomCodec
=
false
;
RTC
::
Scope
scope
=
RTC
::
Scope
::
ROOM_CAPABILITY
;
public
:
Media
::
Kind
kind
=
Media
::
Kind
::
ALL
;
RtpCodecMime
mime
;
uint8_t
payloadType
=
0
;
bool
hasPayloadType
=
false
;
uint32_t
clockRate
=
0
;
uint32_t
maxptime
=
0
;
uint32_t
ptime
=
0
;
uint32_t
numChannels
=
1
;
RTC
::
Parameters
parameters
;
RTCRtpCodecRtxParameters
rtx
;
bool
hasRtx
=
false
;
std
::
vector
<
RtcpFeedback
>
rtcpFeedback
;
...
...
@@ -271,29 +275,6 @@ namespace RTC
Json
::
Value
userParameters
;
};
class
RtpCodecCapability
:
public
RtpCodec
{
public
:
RtpCodecCapability
()
{};
RtpCodecCapability
(
Json
::
Value
&
data
);
Json
::
Value
toJson
();
bool
MatchesCodec
(
RtpCodecParameters
&
codec
);
void
Reduce
(
RtpCodecParameters
&
codec
);
private
:
void
CheckCodecCapability
();
public
:
Media
::
Kind
kind
=
Media
::
Kind
::
ALL
;
uint8_t
preferredPayloadType
=
0
;
std
::
vector
<
RtcpFeedback
>
rtcpFeedback
;
uint16_t
maxTemporalLayers
=
0
;
uint16_t
maxSpatialLayers
=
0
;
bool
svcMultiStreamSupport
=
false
;
};
class
RtpHeaderExtension
{
public
:
...
...
@@ -312,15 +293,15 @@ namespace RTC
{
public
:
RtpCapabilities
()
{};
RtpCapabilities
(
Json
::
Value
&
data
);
RtpCapabilities
(
Json
::
Value
&
data
,
RTC
::
Scope
scope
);
Json
::
Value
toJson
();
private
:
void
ValidateCodecs
();
void
ValidateCodecs
(
RTC
::
Scope
scope
);
public
:
std
::
vector
<
RtpCodec
Capability
>
codecs
;
std
::
vector
<
RtpCodec
Parameters
>
codecs
;
std
::
vector
<
RtpHeaderExtension
>
headerExtensions
;
std
::
vector
<
std
::
string
>
fecMechanisms
;
};
...
...
worker/mediasoup-worker.gyp
浏览文件 @
f0db9781
...
...
@@ -49,8 +49,6 @@
'src/RTC/RtpDictionaries/RtcpFeedback.cpp',
'src/RTC/RtpDictionaries/RtcpParameters.cpp',
'src/RTC/RtpDictionaries/RtpCapabilities.cpp',
'src/RTC/RtpDictionaries/RtpCodec.cpp',
'src/RTC/RtpDictionaries/RtpCodecCapability.cpp',
'src/RTC/RtpDictionaries/RtpCodecMime.cpp',
'src/RTC/RtpDictionaries/RtpCodecParameters.cpp',
'src/RTC/RtpDictionaries/RtpEncodingParameters.cpp',
...
...
worker/src/Channel/Request.cpp
浏览文件 @
f0db9781
...
...
@@ -18,6 +18,7 @@ namespace Channel
{
"room.createPeer"
,
Request
::
MethodId
::
room_createPeer
},
{
"peer.close"
,
Request
::
MethodId
::
peer_close
},
{
"peer.dump"
,
Request
::
MethodId
::
peer_dump
},
{
"peer.setCapabilities"
,
Request
::
MethodId
::
peer_setCapabilities
},
{
"peer.createTransport"
,
Request
::
MethodId
::
peer_createTransport
},
{
"peer.createRtpReceiver"
,
Request
::
MethodId
::
peer_createRtpReceiver
},
{
"transport.close"
,
Request
::
MethodId
::
transport_close
},
...
...
worker/src/Loop.cpp
浏览文件 @
f0db9781
...
...
@@ -226,6 +226,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
case
Channel
:
:
Request
::
MethodId
::
room_createPeer
:
case
Channel
:
:
Request
::
MethodId
::
peer_close
:
case
Channel
:
:
Request
::
MethodId
::
peer_dump
:
case
Channel
:
:
Request
::
MethodId
::
peer_setCapabilities
:
case
Channel
:
:
Request
::
MethodId
::
peer_createTransport
:
case
Channel
:
:
Request
::
MethodId
::
peer_createRtpReceiver
:
case
Channel
:
:
Request
::
MethodId
::
transport_close
:
...
...
worker/src/RTC/Peer.cpp
浏览文件 @
f0db9781
...
...
@@ -9,24 +9,13 @@ namespace RTC
{
/* Instance methods. */
Peer
::
Peer
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
uint32_t
peerId
,
std
::
string
&
peerName
,
Json
::
Value
&
data
)
:
Peer
::
Peer
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
uint32_t
peerId
,
std
::
string
&
peerName
)
:
peerId
(
peerId
),
peerName
(
peerName
),
listener
(
listener
),
notifier
(
notifier
)
{
MS_TRACE
();
static
const
Json
::
StaticString
k_capabilities
(
"capabilities"
);
// `mediaCodecs` is mandatory.
if
(
!
data
[
k_capabilities
].
isObject
())
MS_THROW_ERROR
(
"missing capabilities"
);
auto
&
json_capabilities
=
data
[
k_capabilities
];
// Build peer's capabilities.
this
->
capabilities
=
RTC
::
RtpCapabilities
(
json_capabilities
);
}
Peer
::~
Peer
()
...
...
@@ -104,7 +93,8 @@ namespace RTC
json
[
k_peerName
]
=
this
->
peerName
;
// Add `capabilities`.
json
[
k_capabilities
]
=
this
->
capabilities
.
toJson
();
if
(
this
->
hasCapabilities
)
json
[
k_capabilities
]
=
this
->
capabilities
.
toJson
();
// Add `transports`.
for
(
auto
&
kv
:
this
->
transports
)
...
...
@@ -163,6 +153,37 @@ namespace RTC
break
;
}
case
Channel
:
:
Request
::
MethodId
::
peer_setCapabilities
:
{
// Capabilities must not be set.
if
(
this
->
hasCapabilities
)
{
request
->
Reject
(
"peer capabilities already set"
);
return
;
}
try
{
this
->
capabilities
=
RTC
::
RtpCapabilities
(
request
->
data
,
RTC
::
Scope
::
PEER_CAPABILITY
);
}
catch
(
const
MediaSoupError
&
error
)
{
request
->
Reject
(
error
.
what
());
return
;
}
this
->
hasCapabilities
=
true
;
MS_DEBUG
(
"capabilities set"
);
request
->
Accept
();
// Notify the listener.
this
->
listener
->
onPeerCapabilities
(
this
);
break
;
}
case
Channel
:
:
Request
::
MethodId
::
peer_createTransport
:
{
RTC
::
Transport
*
transport
;
...
...
@@ -213,6 +234,13 @@ namespace RTC
RTC
::
Transport
*
transport
=
nullptr
;
uint32_t
rtpReceiverId
;
// Capabilities must be set.
if
(
!
this
->
hasCapabilities
)
{
request
->
Reject
(
"peer capabilities are not yet set"
);
return
;
}
try
{
rtpReceiver
=
GetRtpReceiverFromRequest
(
request
,
&
rtpReceiverId
);
...
...
@@ -545,6 +573,28 @@ namespace RTC
{
MS_TRACE
();
auto
rtpParameters
=
rtpReceiver
->
GetParameters
();
// Given codecs must be a subset of the capability codecs of the peer.
for
(
auto
codec
:
rtpParameters
->
codecs
)
{
auto
it
=
this
->
capabilities
.
codecs
.
begin
();
for
(;
it
!=
this
->
capabilities
.
codecs
.
end
();
++
it
)
{
auto
&
codecCapability
=
*
it
;
if
(
codecCapability
.
Matches
(
codec
,
true
))
break
;
}
if
(
it
==
this
->
capabilities
.
codecs
.
end
())
{
MS_THROW_ERROR
(
"no matching peer codec found [payloadType:%"
PRIu8
"]"
,
codec
.
payloadType
);
}
}
// Notify the listener (Room) so it can check provided codecs and,
// optionally, normalize them.
// NOTE: This may throw.
...
...
worker/src/RTC/Room.cpp
浏览文件 @
f0db9781
...
...
@@ -30,7 +30,7 @@ namespace RTC
Json
::
CharReader
*
jsonReader
=
builder
.
newCharReader
();
// NOTE: This line is auto-generated from data/supportedCapabilities.js.
const
std
::
string
capabilities
=
R"({"
codecs":[{"kind":"audio","name":"audio/opus","preferredPayloadType":96,"clockRate":48000,"numChannels":2},{"kind":"audio","name":"audio/ISAC","preferredPayloadType":97,"clockRate":16000},{"kind":"audio","name":"audio/ISAC","preferredPayloadType":98,"clockRate":32000},{"kind":"audio","name":"audio/G722","preferredPayloadType":9,"clockRate":8000},{"kind":"audio","name":"audio/PCMU","preferredPayloadType":0,"clockRate":8000},{"kind":"audio","name":"audio/PCMA","preferredPayloadType":8,"clockRate":8000},{"kind":"video","name":"video/VP8","preferredPayloadType":110,"clockRate":90000},{"kind":"video","name":"video/VP9","preferredPayloadType":111,"clockRate":90000},{"kind":"video","name":"video/H264","preferredPayloadType":112,"clockRate":90000,"parameters":{"packetizationMode":[0,1,2]}},{"kind":"depth","name":"video/VP8","preferredPayloadType":120,"clockRate":90000},{"kind":"audio","name":"audio/CN","preferredPayloadType":77,"clockRate":32000},{"kind":"audio","name":"audio/CN","preferredPayloadType":78,"clockRate":16000},{"kind":"audio","name":"audio/CN","preferredPayloadType":13,"clockRate":8000},{"kind":"audio","name":"audio/telephone-event","preferredPayloadType":79,"clockRate":8000}],"headerExtensions":[{"kind":"","uri":"urn:ietf:params:rtp-hdrext:sdes:mid","preferredId":1,"preferredEncrypt":false}
]})"
;
const
std
::
string
capabilities
=
R"({"
headerExtensions":[{"kind":"","uri":"urn:ietf:params:rtp-hdrext:sdes:mid","preferredId":1,"preferredEncrypt":false}],"fecMechanisms":[
]})"
;
Json
::
Value
json
;
std
::
string
json_parse_error
;
...
...
@@ -46,7 +46,7 @@ namespace RTC
try
{
Room
::
supportedCapabilities
=
RTC
::
RtpCapabilities
(
json
);
Room
::
supportedCapabilities
=
RTC
::
RtpCapabilities
(
json
,
RTC
::
Scope
::
ROOM_CAPABILITY
);
}
catch
(
const
MediaSoupError
&
error
)
{
...
...
@@ -75,7 +75,11 @@ namespace RTC
for
(
Json
::
UInt
i
=
0
;
i
<
json_mediaCodecs
.
size
();
i
++
)
{
RTC
::
RtpCodecParameters
mediaCodec
(
json_mediaCodecs
[
i
],
true
);
RTC
::
RtpCodecParameters
mediaCodec
(
json_mediaCodecs
[
i
],
RTC
::
Scope
::
ROOM_CAPABILITY
);
// Ignore feature codecs.
if
(
mediaCodec
.
mime
.
IsFeatureCodec
())
continue
;
mediaCodecs
.
push_back
(
mediaCodec
);
}
...
...
@@ -230,7 +234,7 @@ namespace RTC
try
{
peer
=
new
RTC
::
Peer
(
this
,
this
->
notifier
,
peerId
,
peerName
,
request
->
data
);
peer
=
new
RTC
::
Peer
(
this
,
this
->
notifier
,
peerId
,
peerName
);
}
catch
(
const
MediaSoupError
&
error
)
{
...
...
@@ -238,44 +242,19 @@ namespace RTC
return
;
}
MS_DEBUG
(
"Peer created [peerId:%u, peerName:'%s']"
,
peerId
,
peerName
.
c_str
());
request
->
Accept
();
// Get all the ready RtpReceivers of the others Peers in the Room and
// create RtpSenders for this new Peer.
for
(
auto
&
kv
:
this
->
peers
)
{
RTC
::
Peer
*
receiver_peer
=
kv
.
second
;
for
(
auto
rtpReceiver
:
receiver_peer
->
GetRtpReceivers
())
{
// Skip if the RtpReceiver has not parameters.
if
(
!
rtpReceiver
->
GetParameters
())
continue
;
uint32_t
rtpSenderId
=
Utils
::
Crypto
::
GetRandomUInt
(
10000000
,
99999999
);
RTC
::
RtpSender
*
rtpSender
=
new
RTC
::
RtpSender
(
peer
,
this
->
notifier
,
rtpSenderId
,
rtpReceiver
->
kind
);
// Store into the map.
this
->
mapRtpReceiverRtpSenders
[
rtpReceiver
].
insert
(
rtpSender
);
// Provide the RtpSender with the parameters of the RtpReceiver.
rtpSender
->
Send
(
rtpReceiver
->
GetParameters
());
// Attach the RtpSender to peer.
peer
->
AddRtpSender
(
rtpSender
,
receiver_peer
->
peerName
);
}
}
// Store the new Peer.
// NOTE: Do it after iterating existing Peers.
this
->
peers
[
peerId
]
=
peer
;
MS_DEBUG
(
"Peer created [peerId:%u, peerName:'%s']"
,
peerId
,
peerName
.
c_str
());
request
->
Accept
();
break
;
}
case
Channel
:
:
Request
::
MethodId
::
peer_close
:
case
Channel
:
:
Request
::
MethodId
::
peer_dump
:
case
Channel
:
:
Request
::
MethodId
::
peer_setCapabilities
:
case
Channel
:
:
Request
::
MethodId
::
peer_createTransport
:
case
Channel
:
:
Request
::
MethodId
::
peer_createRtpReceiver
:
case
Channel
:
:
Request
::
MethodId
::
transport_close
:
...
...
@@ -369,8 +348,6 @@ namespace RTC
55
,
56
,
57
,
58
,
59
,
60
,
61
,
62
,
63
,
64
,
65
,
66
,
67
,
68
,
69
,
70
,
71
};
// Maximum static payload type.
static
const
uint8_t
maxStaticPayloadType
=
34
;
// Iterator for available dynamic payload types.
auto
dynamicPayloadTypeIt
=
dynamicPayloadTypes
.
begin
();
// Payload types used by the room.
...
...
@@ -381,108 +358,54 @@ namespace RTC
// Set the given room codecs.
for
(
auto
&
mediaCodec
:
mediaCodecs
)
{
RTC
::
RtpCodecCapability
codecCapability
;
// The room has this kind.
roomKinds
.
insert
(
mediaCodec
.
kind
);
// Search the given codec in the list of supported codec capabilities.
auto
it
=
Room
::
supportedCapabilities
.
codecs
.
begin
();
for
(;
it
!=
Room
::
supportedCapabilities
.
codecs
.
end
();
++
it
)
{
auto
&
supportedCodecCapability
=
*
it
;
// Kind must match.
if
(
mediaCodec
.
kind
!=
supportedCodecCapability
.
kind
)
continue
;
// Check whether the codec capability matches the given codec.
if
(
supportedCodecCapability
.
MatchesCodec
(
mediaCodec
))
{
// Deep copy.
codecCapability
=
supportedCodecCapability
;
break
;
}
}
if
(
it
==
Room
::
supportedCapabilities
.
codecs
.
end
())
MS_THROW_ERROR
(
"no matching codec capability found"
);
// Reduce the capabilities of the matching capability codec.
codecCapability
.
Reduce
(
mediaCodec
);
// Set unique PT.
auto
payloadType
=
codecCapability
.
preferredPayloadType
;
// If the codec capability has static PT and such a PT is not already used,
// let it untouched.
if
(
payloadType
>
maxStaticPayloadType
||
roomPayloadTypes
.
find
(
payloadType
)
!=
roomPayloadTypes
.
end
())
// If the codec has PT and it's not already used, let it untouched.
if
(
mediaCodec
.
hasPayloadType
&&
roomPayloadTypes
.
find
(
mediaCodec
.
payloadType
)
==
roomPayloadTypes
.
end
())
{
// If there are no more dynamic PTs throw.
if
(
dynamicPayloadTypeIt
==
dynamicPayloadTypes
.
end
())
MS_THROW_ERROR
(
"not enough available dynamic payload types for given media codecs"
);
// Assign preferred PT.
payloadType
=
*
dynamicPayloadTypeIt
;
codecCapability
.
preferredPayloadType
=
payloadType
;
// Increment the iterator.
dynamicPayloadTypeIt
++
;
;
}
// Otherwise assign an available PT.
else
{
uint8_t
payloadType
;
// Store the selected PT.
roomPayloadTypes
.
insert
(
payloadType
);
// Append the codec to the room capabilities.
this
->
capabilities
.
codecs
.
push_back
(
codecCapability
);
}
// Add feature codec capabilities.
for
(
auto
&
codecCapability
:
Room
::
supportedCapabilities
.
codecs
)
{
// Just feature codecs.
if
(
!
codecCapability
.
mime
.
IsFeatureCodec
())
continue
;
// Ignore if no media codecs of this kind were given.
if
(
roomKinds
.
find
(
codecCapability
.
kind
)
==
roomKinds
.
end
())
continue
;
// Set unique PT.
auto
payloadType
=
codecCapability
.
preferredPayloadType
;
while
(
dynamicPayloadTypeIt
!=
dynamicPayloadTypes
.
end
())
{
payloadType
=
*
dynamicPayloadTypeIt
;
dynamicPayloadTypeIt
++
;
if
(
payloadType
>
maxStaticPayloadType
||
roomPayloadTypes
.
find
(
payloadType
)
!=
roomPayloadTypes
.
end
())
{
// If there are no more dynamic PTs throw.
if
(
dynamicPayloadTypeIt
==
dynamicPayloadTypes
.
end
())
MS_THROW_ERROR
(
"not enough available dynamic payload types for feature codecs"
);
if
(
roomPayloadTypes
.
find
(
payloadType
)
==
roomPayloadTypes
.
end
())
{
// Assign PT.
mediaCodec
.
payloadType
=
payloadType
;
mediaCodec
.
hasPayloadType
=
true
;
// Assign preferred PT.
payloadType
=
*
dynamicPayloadTypeIt
;
codecCapability
.
preferredPayloadType
=
payloadType
;
break
;
}
}
// Increment the iterator.
dynamicPayloadTypeIt
++
;
// If no one found, throw.
if
(
!
mediaCodec
.
hasPayloadType
)
MS_THROW_ERROR
(
"no more available dynamic payload types for given media codecs"
);
}
// Store the selected PT.
roomPayloadTypes
.
insert
(
payloadType
);
roomPayloadTypes
.
insert
(
mediaCodec
.
payloadType
);
// Append the codec to the room capabilities.
this
->
capabilities
.
codecs
.
push_back
(
codecCapability
);
this
->
capabilities
.
codecs
.
push_back
(
mediaCodec
);
}
}
//
Copy
supported RTP header extensions.
//
Add
supported RTP header extensions.
this
->
capabilities
.
headerExtensions
=
Room
::
supportedCapabilities
.
headerExtensions
;
//
Copy
supported FEC mechanisms.
//
Add
supported FEC mechanisms.
this
->
capabilities
.
fecMechanisms
=
Room
::
supportedCapabilities
.
fecMechanisms
;
}
...
...
@@ -493,6 +416,37 @@ namespace RTC
this
->
peers
.
erase
(
peer
->
peerId
);
}
void
Room
::
onPeerCapabilities
(
RTC
::
Peer
*
peer
)
{
MS_TRACE
();
// Get all the ready RtpReceivers of the others Peers in the Room and
// create RtpSenders for this new Peer.
for
(
auto
&
kv
:
this
->
peers
)
{
RTC
::
Peer
*
receiver_peer
=
kv
.
second
;
for
(
auto
rtpReceiver
:
receiver_peer
->
GetRtpReceivers
())
{
// Skip if the RtpReceiver has not parameters.
if
(
!
rtpReceiver
->
GetParameters
())
continue
;
uint32_t
rtpSenderId
=
Utils
::
Crypto
::
GetRandomUInt
(
10000000
,
99999999
);
RTC
::
RtpSender
*
rtpSender
=
new
RTC
::
RtpSender
(
peer
,
this
->
notifier
,
rtpSenderId
,
rtpReceiver
->
kind
);
// Store into the map.
this
->
mapRtpReceiverRtpSenders
[
rtpReceiver
].
insert
(
rtpSender
);
// Provide the RtpSender with the parameters of the RtpReceiver.
rtpSender
->
Send
(
rtpReceiver
->
GetParameters
());
// Attach the RtpSender to peer.
peer
->
AddRtpSender
(
rtpSender
,
receiver_peer
->
peerName
);
}
}
}
void
Room
::
onPeerRtpReceiverParameters
(
RTC
::
Peer
*
peer
,
RTC
::
RtpReceiver
*
rtpReceiver
)
{
MS_TRACE
();
...
...
@@ -509,12 +463,12 @@ namespace RTC
{
auto
&
codecCapability
=
*
it
;
if
(
codecCapability
.
Matches
Codec
(
codec
))
if
(
codecCapability
.
Matches
(
codec
))
break
;
}
if
(
it
==
this
->
capabilities
.
codecs
.
end
())
{
MS_THROW_ERROR
(
"no matching
codec capability
found [payloadType:%"
PRIu8
"]"
,
MS_THROW_ERROR
(
"no matching
room codec
found [payloadType:%"
PRIu8
"]"
,
codec
.
payloadType
);
}
}
...
...
@@ -541,6 +495,10 @@ namespace RTC
if
(
sender_peer
==
peer
)
continue
;
// Skip peer with capabilities unset yet.
if
(
!
sender_peer
->
HasCapabilities
())
continue
;
// Create a RtpSender for the other Peer.
uint32_t
rtpSenderId
=
Utils
::
Crypto
::
GetRandomUInt
(
10000000
,
99999999
);
RTC
::
RtpSender
*
rtpSender
=
new
RTC
::
RtpSender
(
sender_peer
,
this
->
notifier
,
rtpSenderId
,
rtpReceiver
->
kind
);
...
...
worker/src/RTC/RtpDictionaries/RtpCapabilities.cpp
浏览文件 @
f0db9781
...
...
@@ -9,7 +9,7 @@ namespace RTC
{
/* Instance methods. */
RtpCapabilities
::
RtpCapabilities
(
Json
::
Value
&
data
)
RtpCapabilities
::
RtpCapabilities
(
Json
::
Value
&
data
,
RTC
::
Scope
scope
)
{
MS_TRACE
();
...
...
@@ -24,7 +24,7 @@ namespace RTC
for
(
Json
::
UInt
i
=
0
;
i
<
json_codecs
.
size
();
i
++
)
{
RtpCodec
Capability
codec
(
json_codecs
[
i
]
);
RtpCodec
Parameters
codec
(
json_codecs
[
i
],
scope
);
// Append to the codecs vector.
this
->
codecs
.
push_back
(
codec
);
...
...
@@ -62,7 +62,7 @@ namespace RTC
// Validate RTP capabilities.
ValidateCodecs
();
ValidateCodecs
(
scope
);
}
Json
::
Value
RtpCapabilities
::
toJson
()
...
...
@@ -103,25 +103,23 @@ namespace RTC
}
inline
void
RtpCapabilities
::
ValidateCodecs
()
void
RtpCapabilities
::
ValidateCodecs
(
RTC
::
Scope
scope
)
{
MS_TRACE
();
// Must be at least one codec.
if
(
this
->
codecs
.
size
()
==
0
)
MS_THROW_ERROR
(
"empty RtpCapabilities.codecs"
);
// Preferred payload types must be unique.
if
(
scope
==
RTC
::
Scope
::
PEER_CAPABILITY
)
{
// Payload types must be unique.
std
::
unordered_set
<
uint8_t
>
preferredP
ayloadTypes
;
std
::
unordered_set
<
uint8_t
>
p
ayloadTypes
;
for
(
auto
&
codec
:
this
->
codecs
)
{
// Preferred payload types must be unique.
if
(
preferredPayloadTypes
.
find
(
codec
.
preferredPayloadType
)
!=
preferredPayloadTypes
.
end
())
MS_THROW_ERROR
(
"duplicated codec.preferredPayloadType"
);
else
preferredPayloadTypes
.
insert
(
codec
.
preferredPayloadType
);
for
(
auto
&
codec
:
this
->
codecs
)
{
if
(
payloadTypes
.
find
(
codec
.
payloadType
)
!=
payloadTypes
.
end
())
MS_THROW_ERROR
(
"duplicated codec.payloadType"
);
else
payloadTypes
.
insert
(
codec
.
payloadType
);
}
}
}
}
worker/src/RTC/RtpDictionaries/RtpCodec.cpp
deleted
100644 → 0
浏览文件 @
0ad4ae10
#define MS_CLASS "RTC::RtpCodec"
#include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h"
#include "Logger.h"
namespace
RTC
{
/* Instance methods. */
RtpCodec
::
RtpCodec
(
Json
::
Value
&
data
)
{
MS_TRACE
();
static
const
Json
::
StaticString
k_name
(
"name"
);
static
const
Json
::
StaticString
k_clockRate
(
"clockRate"
);
static
const
Json
::
StaticString
k_maxptime
(
"maxptime"
);
static
const
Json
::
StaticString
k_ptime
(
"ptime"
);
static
const
Json
::
StaticString
k_numChannels
(
"numChannels"
);
static
const
Json
::
StaticString
k_parameters
(
"parameters"
);
if
(
!
data
.
isObject
())
MS_THROW_ERROR
(
"RtpCodec is not an object"
);
// `name` is mandatory.
if
(
!
data
[
k_name
].
isString
())
MS_THROW_ERROR
(
"missing RtpCodec.name"
);
std
::
string
name
=
data
[
k_name
].
asString
();
// Set MIME field.
// NOTE: This may throw.
this
->
mime
.
SetName
(
name
);
// `clockRate` is mandatory.
if
(
!
data
[
k_clockRate
].
isUInt
())
MS_THROW_ERROR
(
"missing RtpCodec.clockRate"
);
this
->
clockRate
=
(
uint32_t
)
data
[
k_clockRate
].
asUInt
();
// `maxptime` is optional.
if
(
data
[
k_maxptime
].
isUInt
())
this
->
maxptime
=
(
uint32_t
)
data
[
k_maxptime
].
asUInt
();
// `ptime` is optional.
if
(
data
[
k_ptime
].
isUInt
())
this
->
ptime
=
(
uint32_t
)
data
[
k_ptime
].
asUInt
();
// `numChannels` is optional.
if
(
data
[
k_numChannels
].
isUInt
())
this
->
numChannels
=
(
uint32_t
)
data
[
k_numChannels
].
asUInt
();
// `parameters` is optional.
if
(
data
[
k_parameters
].
isObject
())
this
->
parameters
.
Set
(
data
[
k_parameters
]);
}
void
RtpCodec
::
toJson
(
Json
::
Value
&
json
)
{
MS_TRACE
();
static
const
Json
::
StaticString
k_name
(
"name"
);
static
const
Json
::
StaticString
k_clockRate
(
"clockRate"
);
static
const
Json
::
StaticString
k_maxptime
(
"maxptime"
);
static
const
Json
::
StaticString
k_ptime
(
"ptime"
);
static
const
Json
::
StaticString
k_numChannels
(
"numChannels"
);
static
const
Json
::
StaticString
k_parameters
(
"parameters"
);
// Add `name`.
json
[
k_name
]
=
this
->
mime
.
GetName
();
// Add `clockRate`.
json
[
k_clockRate
]
=
(
Json
::
UInt
)
this
->
clockRate
;
// Add `maxptime`.
if
(
this
->
maxptime
)
json
[
k_maxptime
]
=
(
Json
::
UInt
)
this
->
maxptime
;
// Add `ptime`.
if
(
this
->
ptime
)
json
[
k_ptime
]
=
(
Json
::
UInt
)
this
->
ptime
;
// Add `numChannels`.
if
(
this
->
numChannels
>
1
)
json
[
k_numChannels
]
=
(
Json
::
UInt
)
this
->
numChannels
;
// Add `parameters`.
json
[
k_parameters
]
=
this
->
parameters
.
toJson
();
}
}
worker/src/RTC/RtpDictionaries/RtpCodecCapability.cpp
deleted
100644 → 0
浏览文件 @
0ad4ae10
#define MS_CLASS "RTC::RtpCodecCapability"
#include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h"
#include "Logger.h"
namespace
RTC
{
/* Instance methods. */
RtpCodecCapability
::
RtpCodecCapability
(
Json
::
Value
&
data
)
:
RtpCodec
(
data
)
{
MS_TRACE
();
static
const
Json
::
StaticString
k_kind
(
"kind"
);
static
const
Json
::
StaticString
k_preferredPayloadType
(
"preferredPayloadType"
);
static
const
Json
::
StaticString
k_rtcpFeedback
(
"rtcpFeedback"
);
static
const
Json
::
StaticString
k_maxTemporalLayers
(
"maxTemporalLayers"
);
static
const
Json
::
StaticString
k_maxSpatialLayers
(
"maxSpatialLayers"
);
static
const
Json
::
StaticString
k_svcMultiStreamSupport
(
"svcMultiStreamSupport"
);
// `kind` is mandatory.
if
(
!
data
[
k_kind
].
isString
())
MS_THROW_ERROR
(
"missing RtpCodecCapability.kind"
);
std
::
string
kind
=
data
[
k_kind
].
asString
();
// NOTE: This may throw.
this
->
kind
=
RTC
::
Media
::
GetKind
(
kind
);
// It can not be empty kind (all).
if
(
this
->
kind
==
RTC
::
Media
::
Kind
::
ALL
)
MS_THROW_ERROR
(
"invalid empty RtpCodecCapability.kind"
);
// `preferredPayloadType` is mandatory.
if
(
!
data
[
k_preferredPayloadType
].
isUInt
())
MS_THROW_ERROR
(
"missing RtpCodecCapability.preferredPayloadType"
);
this
->
preferredPayloadType
=
(
uint8_t
)
data
[
k_preferredPayloadType
].
asUInt
();
// `rtcpFeedback` is optional.
if
(
data
[
k_rtcpFeedback
].
isArray
())
{
auto
&
json_rtcpFeedback
=
data
[
k_rtcpFeedback
];
for
(
Json
::
UInt
i
=
0
;
i
<
json_rtcpFeedback
.
size
();
i
++
)
{
RtcpFeedback
rtcpFeedback
(
json_rtcpFeedback
[
i
]);
// Append to the rtcpFeedback vector.
this
->
rtcpFeedback
.
push_back
(
rtcpFeedback
);
}
}
// `maxTemporalLayers` is optional.
if
(
data
[
k_maxTemporalLayers
].
isUInt
())
this
->
maxTemporalLayers
=
(
uint16_t
)
data
[
k_maxTemporalLayers
].
asUInt
();
// `maxSpatialLayers` is optional.
if
(
data
[
k_maxSpatialLayers
].
isUInt
())
this
->
maxSpatialLayers
=
(
uint16_t
)
data
[
k_maxSpatialLayers
].
asUInt
();
// `svcMultiStreamSupport` is optional.
if
(
data
[
k_svcMultiStreamSupport
].
isBool
())
this
->
svcMultiStreamSupport
=
data
[
k_svcMultiStreamSupport
].
asBool
();
// Check codec capability.
CheckCodecCapability
();
}
Json
::
Value
RtpCodecCapability
::
toJson
()
{
MS_TRACE
();
static
const
Json
::
StaticString
k_kind
(
"kind"
);
static
const
Json
::
StaticString
k_preferredPayloadType
(
"preferredPayloadType"
);
static
const
Json
::
StaticString
k_rtcpFeedback
(
"rtcpFeedback"
);
static
const
Json
::
StaticString
k_maxTemporalLayers
(
"maxTemporalLayers"
);
static
const
Json
::
StaticString
k_maxSpatialLayers
(
"maxSpatialLayers"
);
static
const
Json
::
StaticString
k_svcMultiStreamSupport
(
"svcMultiStreamSupport"
);
Json
::
Value
json
(
Json
::
objectValue
);
// Call the parent method.
RtpCodec
::
toJson
(
json
);
// Add `kind`.
json
[
k_kind
]
=
RTC
::
Media
::
GetJsonString
(
this
->
kind
);
// Add `preferredPayloadType`.
json
[
k_preferredPayloadType
]
=
(
Json
::
UInt
)
this
->
preferredPayloadType
;
// Add `rtcpFeedback`.
json
[
k_rtcpFeedback
]
=
Json
::
arrayValue
;
for
(
auto
&
entry
:
this
->
rtcpFeedback
)
{
json
[
k_rtcpFeedback
].
append
(
entry
.
toJson
());
}
// Add `maxTemporalLayers` (if set).
if
(
this
->
maxTemporalLayers
)
json
[
k_maxTemporalLayers
]
=
(
Json
::
UInt
)
this
->
maxTemporalLayers
;
// Add `maxSpatialLayers` (if set).
if
(
this
->
maxSpatialLayers
)
json
[
k_maxSpatialLayers
]
=
(
Json
::
UInt
)
this
->
maxSpatialLayers
;
// Add `svcMultiStreamSupport` (if set).
if
(
this
->
svcMultiStreamSupport
)
json
[
k_svcMultiStreamSupport
]
=
true
;
return
json
;
}
bool
RtpCodecCapability
::
MatchesCodec
(
RtpCodecParameters
&
codec
)
{
MS_TRACE
();
static
std
::
string
k_packetizationMode
=
"packetizationMode"
;
// MIME must match.
if
(
this
->
mime
!=
codec
.
mime
)
return
false
;
// Clock rate must match.
if
(
this
->
clockRate
!=
codec
.
clockRate
)
return
false
;
// Per kind checks.
switch
(
this
->
kind
)
{
case
RTC
:
:
Media
::
Kind
::
AUDIO
:
{
// Num channels must match
if
(
this
->
numChannels
!=
codec
.
numChannels
)
return
false
;
break
;
}
default
:
;
}
// Per MIME checks.
switch
(
this
->
mime
.
subtype
)
{
case
RTC
:
:
RtpCodecMime
::
Subtype
::
H264
:
{
if
(
!
this
->
parameters
.
IncludesInteger
(
k_packetizationMode
,
codec
.
parameters
.
GetInteger
(
k_packetizationMode
)))
{
return
false
;
}
break
;
}
default
:
;
}
return
true
;
}
// NOTE: This method assumes that MatchesCodec() has been called before
// with same codec and returned true.
void
RtpCodecCapability
::
Reduce
(
RtpCodecParameters
&
codec
)
{
MS_TRACE
();
static
std
::
string
k_packetizationMode
=
"packetizationMode"
;
switch
(
codec
.
mime
.
subtype
)
{
case
RTC
:
:
RtpCodecMime
::
Subtype
::
H264
:
{
std
::
vector
<
int32_t
>
packetizationMode
;
// NOTE: `packetizationMode` is set by RtpCodecParameter if not present.
packetizationMode
.
push_back
(
codec
.
parameters
.
GetInteger
(
k_packetizationMode
));
this
->
parameters
.
SetArrayOfIntegers
(
k_packetizationMode
,
packetizationMode
);
break
;
}
default
:
;
}
}
inline
void
RtpCodecCapability
::
CheckCodecCapability
()
{
MS_TRACE
();
static
std
::
string
k_packetizationMode
=
"packetizationMode"
;
// Check per MIME parameters and set default values.
switch
(
this
->
mime
.
subtype
)
{
case
RTC
:
:
RtpCodecMime
::
Subtype
::
OPUS
:
{
// Opus default numChannels is 2.
if
(
this
->
numChannels
<
2
)
this
->
numChannels
=
2
;
break
;
}
case
RTC
:
:
RtpCodecMime
::
Subtype
::
H264
:
{
// H264 default packetizationMode is 0.
std
::
vector
<
int32_t
>
packetizationMode
=
{
0
};
if
(
!
this
->
parameters
.
HasArrayOfIntegers
(
k_packetizationMode
))
this
->
parameters
.
SetArrayOfIntegers
(
k_packetizationMode
,
packetizationMode
);
break
;
}
default
:
;
}
}
}
worker/src/RTC/RtpDictionaries/RtpCodecParameters.cpp
浏览文件 @
f0db9781
...
...
@@ -8,33 +8,96 @@ namespace RTC
{
/* Instance methods. */
RtpCodecParameters
::
RtpCodecParameters
(
Json
::
Value
&
data
,
bool
isRoomCodec
)
:
RtpCodec
(
data
),
isRoomCodec
(
isRoomCodec
)
RtpCodecParameters
::
RtpCodecParameters
(
Json
::
Value
&
data
,
RTC
::
Scope
scope
)
:
scope
(
scope
)
{
MS_TRACE
();
static
const
Json
::
StaticString
k_kind
(
"kind"
);
static
const
Json
::
StaticString
k_name
(
"name"
);
static
const
Json
::
StaticString
k_payloadType
(
"payloadType"
);
static
const
Json
::
StaticString
k_clockRate
(
"clockRate"
);
static
const
Json
::
StaticString
k_maxptime
(
"maxptime"
);
static
const
Json
::
StaticString
k_ptime
(
"ptime"
);
static
const
Json
::
StaticString
k_numChannels
(
"numChannels"
);
static
const
Json
::
StaticString
k_parameters
(
"parameters"
);
static
const
Json
::
StaticString
k_rtx
(
"rtx"
);
static
const
Json
::
StaticString
k_rtcpFeedback
(
"rtcpFeedback"
);
// Not a room codec.
if
(
!
this
->
isRoomCodec
)
if
(
!
data
.
isObject
())
MS_THROW_ERROR
(
"RtpCodecParameters is not an object"
);
if
(
this
->
scope
==
RTC
::
Scope
::
ROOM_CAPABILITY
||
this
->
scope
==
RTC
::
Scope
::
PEER_CAPABILITY
)
{
// `payloadType` is mandatory.
if
(
!
data
[
k_payloadType
].
isUInt
())
MS_THROW_ERROR
(
"missing RtpCodecParameters.payloadType"
);
// `kind` is mandatory.
if
(
!
data
[
k_kind
].
isString
())
MS_THROW_ERROR
(
"missing RtpCodecParameters.kind"
);
std
::
string
kind
=
data
[
k_kind
].
asString
();
// NOTE: This may throw.
this
->
kind
=
RTC
::
Media
::
GetKind
(
kind
);
}
// `name` is mandatory.
if
(
!
data
[
k_name
].
isString
())
MS_THROW_ERROR
(
"missing RtpCodec.name"
);
std
::
string
name
=
data
[
k_name
].
asString
();
// Set MIME field.
// NOTE: This may throw.
this
->
mime
.
SetName
(
name
);
if
(
data
[
k_payloadType
].
isUInt
())
{
this
->
payloadType
=
(
uint8_t
)
data
[
k_payloadType
].
asUInt
();
this
->
hasPayloadType
=
true
;
}
if
(
this
->
scope
==
RTC
::
Scope
::
PEER_CAPABILITY
||
this
->
scope
==
RTC
::
Scope
::
RECEIVE
)
{
if
(
!
this
->
hasPayloadType
)
MS_THROW_ERROR
(
"missing RtpCodecParameters.payloadType"
);
}
// `clockRate` is mandatory.
if
(
!
data
[
k_clockRate
].
isUInt
())
MS_THROW_ERROR
(
"missing RtpCodecParameters.clockRate"
);
this
->
clockRate
=
(
uint32_t
)
data
[
k_clockRate
].
asUInt
();
// `maxptime` is optional.
if
(
data
[
k_maxptime
].
isUInt
())
this
->
maxptime
=
(
uint32_t
)
data
[
k_maxptime
].
asUInt
();
// `ptime` is optional.
if
(
data
[
k_ptime
].
isUInt
())
this
->
ptime
=
(
uint32_t
)
data
[
k_ptime
].
asUInt
();
// `numChannels` is optional.
if
(
data
[
k_numChannels
].
isUInt
())
this
->
numChannels
=
(
uint32_t
)
data
[
k_numChannels
].
asUInt
();
// `parameters` is optional.
if
(
data
[
k_parameters
].
isObject
())
this
->
parameters
.
Set
(
data
[
k_parameters
]);
if
(
this
->
scope
==
RTC
::
Scope
::
RECEIVE
)
{
// `rtx` is optional.
if
(
data
[
k_rtx
].
isObject
())
{
this
->
rtx
=
RTCRtpCodecRtxParameters
(
data
[
k_rtx
]);
this
->
rtx
=
RTC
::
RTC
RtpCodecRtxParameters
(
data
[
k_rtx
]);
this
->
hasRtx
=
true
;
}
}
if
(
this
->
scope
==
RTC
::
Scope
::
PEER_CAPABILITY
||
this
->
scope
==
RTC
::
Scope
::
RECEIVE
)
{
// `rtcpFeedback` is optional.
if
(
data
[
k_rtcpFeedback
].
isArray
())
{
...
...
@@ -42,29 +105,13 @@ namespace RTC
for
(
Json
::
UInt
i
=
0
;
i
<
json_rtcpFeedback
.
size
();
i
++
)
{
RtcpFeedback
rtcpFeedback
(
json_rtcpFeedback
[
i
]);
R
TC
::
R
tcpFeedback
rtcpFeedback
(
json_rtcpFeedback
[
i
]);
// Append to the rtcpFeedback vector.
this
->
rtcpFeedback
.
push_back
(
rtcpFeedback
);
}
}
}
// Room codec.
else
{
// `kind` is mandatory.
if
(
!
data
[
k_kind
].
isString
())
MS_THROW_ERROR
(
"missing RtpCodecParameters.kind"
);
std
::
string
kind
=
data
[
k_kind
].
asString
();
// NOTE: This may throw.
this
->
kind
=
RTC
::
Media
::
GetKind
(
kind
);
// It must not be a feature codec.
if
(
this
->
mime
.
IsFeatureCodec
())
MS_THROW_ERROR
(
"can not be a feature codec"
);
}
// Check codec.
CheckCodec
();
...
...
@@ -75,25 +122,62 @@ namespace RTC
MS_TRACE
();
static
const
Json
::
StaticString
k_kind
(
"kind"
);
static
const
Json
::
StaticString
k_name
(
"name"
);
static
const
Json
::
StaticString
k_payloadType
(
"payloadType"
);
static
const
Json
::
StaticString
k_clockRate
(
"clockRate"
);
static
const
Json
::
StaticString
k_maxptime
(
"maxptime"
);
static
const
Json
::
StaticString
k_ptime
(
"ptime"
);
static
const
Json
::
StaticString
k_numChannels
(
"numChannels"
);
static
const
Json
::
StaticString
k_parameters
(
"parameters"
);
static
const
Json
::
StaticString
k_rtx
(
"rtx"
);
static
const
Json
::
StaticString
k_rtcpFeedback
(
"rtcpFeedback"
);
Json
::
Value
json
(
Json
::
objectValue
);
// Call the parent method.
RtpCodec
::
toJson
(
json
);
if
(
this
->
scope
==
RTC
::
Scope
::
ROOM_CAPABILITY
||
this
->
scope
==
RTC
::
Scope
::
PEER_CAPABILITY
)
{
// Add `kind`.
json
[
k_kind
]
=
RTC
::
Media
::
GetJsonString
(
this
->
kind
);
}
// Add `name`.
json
[
k_name
]
=
this
->
mime
.
GetName
();
// Not a room codec.
if
(
!
this
->
isRoomCodec
)
if
(
this
->
hasPayloadType
)
{
// Add `payloadType`.
json
[
k_payloadType
]
=
(
Json
::
UInt
)
this
->
payloadType
;
}
// Add `clockRate`.
json
[
k_clockRate
]
=
(
Json
::
UInt
)
this
->
clockRate
;
// Add `maxptime`.
if
(
this
->
maxptime
)
json
[
k_maxptime
]
=
(
Json
::
UInt
)
this
->
maxptime
;
// Add `ptime`.
if
(
this
->
ptime
)
json
[
k_ptime
]
=
(
Json
::
UInt
)
this
->
ptime
;
// Add `numChannels`.
if
(
this
->
numChannels
>
1
)
json
[
k_numChannels
]
=
(
Json
::
UInt
)
this
->
numChannels
;
// Add `parameters`.
json
[
k_parameters
]
=
this
->
parameters
.
toJson
();
if
(
this
->
scope
==
RTC
::
Scope
::
RECEIVE
)
{
// Add `rtx`
if
(
this
->
hasRtx
)
json
[
k_rtx
]
=
this
->
rtx
.
toJson
();
}
if
(
this
->
scope
==
RTC
::
Scope
::
PEER_CAPABILITY
||
this
->
scope
==
RTC
::
Scope
::
RECEIVE
)
{
// Add `rtcpFeedback`.
json
[
k_rtcpFeedback
]
=
Json
::
arrayValue
;
...
...
@@ -102,14 +186,66 @@ namespace RTC
json
[
k_rtcpFeedback
].
append
(
entry
.
toJson
());
}
}
// Room codec.
else
return
json
;
}
bool
RtpCodecParameters
::
Matches
(
RtpCodecParameters
&
codec
,
bool
checkPayloadType
)
{
MS_TRACE
();
static
std
::
string
k_packetizationMode
=
"packetizationMode"
;
// MIME must match.
if
(
this
->
mime
!=
codec
.
mime
)
return
false
;
if
(
checkPayloadType
)
{
// Add `kind`.
json
[
k_kind
]
=
RTC
::
Media
::
GetJsonString
(
this
->
kind
)
;
if
(
this
->
payloadType
!=
codec
.
payloadType
)
return
false
;
}
return
json
;
// Clock rate must match.
if
(
this
->
clockRate
!=
codec
.
clockRate
)
return
false
;
// Per kind checks.
switch
(
this
->
kind
)
{
case
RTC
:
:
Media
::
Kind
::
AUDIO
:
{
// Num channels must match
if
(
this
->
numChannels
!=
codec
.
numChannels
)
return
false
;
break
;
}
default
:
;
}
// Per MIME checks.
switch
(
this
->
mime
.
subtype
)
{
case
RTC
:
:
RtpCodecMime
::
Subtype
::
H264
:
{
if
(
this
->
parameters
.
GetInteger
(
k_packetizationMode
)
!=
codec
.
parameters
.
GetInteger
(
k_packetizationMode
))
{
return
false
;
}
break
;
}
default
:
;
}
return
true
;
}
inline
...
...
worker/src/RTC/RtpDictionaries/RtpParameters.cpp
浏览文件 @
f0db9781
...
...
@@ -36,7 +36,7 @@ namespace RTC
for
(
Json
::
UInt
i
=
0
;
i
<
json_codecs
.
size
();
i
++
)
{
R
tpCodecParameters
codec
(
json_codecs
[
i
],
false
);
R
TC
::
RtpCodecParameters
codec
(
json_codecs
[
i
],
RTC
::
Scope
::
RECEIVE
);
// Append to the codecs vector.
this
->
codecs
.
push_back
(
codec
);
...
...
@@ -54,7 +54,7 @@ namespace RTC
for
(
Json
::
UInt
i
=
0
;
i
<
json_array
.
size
();
i
++
)
{
RtpEncodingParameters
encoding
(
json_array
[
i
]);
R
TC
::
R
tpEncodingParameters
encoding
(
json_array
[
i
]);
// Append to the encodings vector.
this
->
encodings
.
push_back
(
encoding
);
...
...
@@ -68,7 +68,7 @@ namespace RTC
for
(
Json
::
UInt
i
=
0
;
i
<
json_array
.
size
();
i
++
)
{
RtpHeaderExtensionParameters
headerExtension
(
json_array
[
i
]);
R
TC
::
R
tpHeaderExtensionParameters
headerExtension
(
json_array
[
i
]);
// Append to the headerExtensions vector.
this
->
headerExtensions
.
push_back
(
headerExtension
);
...
...
@@ -78,7 +78,7 @@ namespace RTC
// `rtcp` is optional.
if
(
data
[
k_rtcp
].
isObject
())
{
this
->
rtcp
=
RtcpParameters
(
data
[
k_rtcp
]);
this
->
rtcp
=
R
TC
::
R
tcpParameters
(
data
[
k_rtcp
]);
this
->
hasRtcp
=
true
;
}
...
...
@@ -216,7 +216,7 @@ namespace RTC
// the first media codec.
if
(
this
->
encodings
.
size
()
==
0
)
{
RtpEncodingParameters
encoding
;
R
TC
::
R
tpEncodingParameters
encoding
;
encoding
.
codecPayloadType
=
firstMediaPayloadType
;
encoding
.
hasCodecPayloadType
=
true
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论