Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
4f5df6fa
提交
4f5df6fa
authored
8月 24, 2017
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Breaking things!
上级
a3d2de61
隐藏空白字符变更
内嵌
并排
正在显示
27 个修改的文件
包含
1028 行增加
和
493 行删除
+1028
-493
.eslintrc.js
.eslintrc.js
+1
-1
TODO_V2.md
TODO_V2.md
+2
-0
gulpfile.js
gulpfile.js
+6
-18
Room.js
lib/Room.js
+5
-8
Server.js
lib/Server.js
+26
-2
Worker.js
lib/Worker.js
+35
-0
ortc.js
lib/ortc.js
+133
-0
supportedRtpCapabilities.js
lib/supportedRtpCapabilities.js
+94
-79
utils.js
lib/utils.js
+10
-13
test-Server.js
test/test-Server.js
+206
-118
Room.hpp
worker/include/RTC/Room.hpp
+0
-7
RtpDictionaries.hpp
worker/include/RTC/RtpDictionaries.hpp
+47
-25
RtpStream.hpp
worker/include/RTC/RtpStream.hpp
+1
-1
mediasoup-worker.gyp
worker/mediasoup-worker.gyp
+1
-2
Consumer.cpp
worker/src/RTC/Consumer.cpp
+1
-4
Peer.cpp
worker/src/RTC/Peer.cpp
+1
-1
Producer.cpp
worker/src/RTC/Producer.cpp
+3
-7
Room.cpp
worker/src/RTC/Room.cpp
+4
-4
RtpCapabilities.cpp
worker/src/RTC/RtpDictionaries/RtpCapabilities.cpp
+12
-15
RtpCodecCapability.cpp
worker/src/RTC/RtpDictionaries/RtpCodecCapability.cpp
+269
-0
RtpCodecMime.cpp
worker/src/RTC/RtpDictionaries/RtpCodecMime.cpp
+0
-119
RtpCodecMimeType.cpp
worker/src/RTC/RtpDictionaries/RtpCodecMimeType.cpp
+124
-0
RtpCodecParameters.cpp
worker/src/RTC/RtpDictionaries/RtpCodecParameters.cpp
+39
-60
RtpParameters.cpp
worker/src/RTC/RtpDictionaries/RtpParameters.cpp
+6
-6
RtpStream.cpp
worker/src/RTC/RtpStream.cpp
+1
-1
RtpStreamRecv.cpp
worker/src/RTC/RtpStreamRecv.cpp
+1
-1
main.cpp
worker/src/main.cpp
+0
-1
没有找到文件。
.eslintrc.js
浏览文件 @
4f5df6fa
...
...
@@ -66,7 +66,7 @@ module.exports =
'max-len'
:
[
2
,
86
,
{
tabWidth
:
2
,
comments
:
86
,
comments
:
90
,
ignoreUrls
:
false
,
ignoreStrings
:
false
,
ignoreTemplateLiterals
:
false
,
...
...
TODO_V2.md
浏览文件 @
4f5df6fa
# TODO in mediasoup v2 (server-side)
*
Remove
`gulp rtpcapabilities`
.
*
Should accept
`peer.createTransport()`
by passing a
`transportId`
number. The same for
`Producer`
.
*
May have to react on DTLS ALERT CLOSE in the server and make it "really" close the Transport and notify the client. Bufff... I don't like this...
...
...
gulpfile.js
浏览文件 @
4f5df6fa
...
...
@@ -23,13 +23,13 @@ const workerFiles =
];
const
nodeTests
=
[
'test/test-mediasoup.js'
,
//
'test/test-mediasoup.js',
'test/test-Server.js'
,
'test/test-Room.js'
,
'test/test-Peer.js'
,
'test/test-Transport.js'
,
'test/test-Producer.js'
,
'test/test-utils.js'
//
'test/test-Room.js',
//
'test/test-Peer.js',
//
'test/test-Transport.js',
//
'test/test-Producer.js',
//
'test/test-utils.js'
];
const
workerCompilationDatabaseTemplate
=
'worker/compile_commands_template.json'
;
const
workerHeaderFilterRegex
=
...
...
@@ -38,18 +38,6 @@ const workerHeaderFilterRegex =
'|handles/*.hpp|Channel/*.hpp|RTC/**/*.hpp)'
;
const
numCpus
=
os
.
cpus
().
length
;
gulp
.
task
(
'rtpcapabilities'
,
()
=>
{
const
supportedRtpCapabilities
=
require
(
'./lib/supportedRtpCapabilities'
);
return
gulp
.
src
(
'worker/src/RTC/Room.cpp'
)
// Let's generate valid syntax as expected by clang-format rules.
.
pipe
(
replace
(
/
(
const std::string supportedRtpCapabilities =
)
.*
\r?\n
.*/
,
`$1\n\t\t\t R"(
${
JSON
.
stringify
(
supportedRtpCapabilities
)}
)";`
))
.
pipe
(
gulp
.
dest
(
'worker/src/RTC/'
))
.
pipe
(
touch
());
});
gulp
.
task
(
'lint:node'
,
()
=>
{
return
gulp
.
src
(
nodeFiles
)
...
...
lib/Room.js
浏览文件 @
4f5df6fa
...
...
@@ -22,7 +22,7 @@ class Room extends EventEmitter
this
.
_internal
=
internal
;
// Room data.
// - .
c
apabilities
// - .
rtpC
apabilities
this
.
_data
=
data
;
// Channel instance.
...
...
@@ -157,9 +157,9 @@ class Room extends EventEmitter
return
this
.
_closed
;
}
get
c
apabilities
()
get
rtpC
apabilities
()
{
return
this
.
_data
.
c
apabilities
;
return
this
.
_data
.
rtpC
apabilities
;
}
/**
...
...
@@ -280,10 +280,7 @@ class Room extends EventEmitter
// Store the Peer instance and remove it when closed.
this
.
_peers
.
set
(
peerName
,
peer
);
peer
.
on
(
'close'
,
()
=>
{
this
.
_peers
.
delete
(
peerName
);
});
peer
.
on
(
'close'
,
()
=>
this
.
_peers
.
delete
(
peerName
));
// Listen for new Producers so we can associate new Consumers.
peer
.
on
(
'newproducer'
,
(
producer
)
=>
...
...
@@ -343,7 +340,7 @@ class Room extends EventEmitter
{
const
response
=
{
rtpCapabilities
:
this
.
c
apabilities
,
rtpCapabilities
:
this
.
rtpC
apabilities
,
mandatoryCodecPayloadTypes
:
[]
// TODO
};
...
...
lib/Server.js
浏览文件 @
4f5df6fa
...
...
@@ -5,8 +5,9 @@ const path = require('path');
const
EventEmitter
=
require
(
'events'
).
EventEmitter
;
const
check
=
require
(
'check-types'
);
const
Logger
=
require
(
'./Logger'
);
const
utils
=
require
(
'./utils'
);
const
errors
=
require
(
'./errors'
);
const
utils
=
require
(
'./utils'
);
const
ortc
=
require
(
'./ortc'
);
const
Worker
=
require
(
'./Worker'
);
const
DEFAULT_NUM_WORKERS
=
Object
.
keys
(
os
.
cpus
()).
length
;
...
...
@@ -46,7 +47,7 @@ class Server extends EventEmitter
this
.
_closed
=
false
;
// Clone options.
options
=
utils
.
clone
(
options
);
options
=
utils
.
clone
Object
(
options
);
// Update numWorkers (if given).
if
(
check
.
integer
(
options
.
numWorkers
)
&&
check
.
positive
(
options
.
numWorkers
))
...
...
@@ -229,6 +230,7 @@ class Server extends EventEmitter
return
Promise
.
all
(
promises
);
}
// TODO: REMOVE
/**
* Create a Room instance.
*
...
...
@@ -252,6 +254,28 @@ class Server extends EventEmitter
});
}
/**
* Create a Room instance.
*
* @return {Room}
*/
Room
(
mediaCodecs
)
{
logger
.
debug
(
'Room()'
);
if
(
this
.
_closed
)
throw
new
errors
.
InvalidStateError
(
'Server closed'
);
// This may throw.
const
rtpCapabilities
=
ortc
.
generateRoomRtpCapabilities
(
mediaCodecs
);
const
worker
=
this
.
_getRandomWorker
();
const
room
=
worker
.
Room
({
rtpCapabilities
});
this
.
emit
(
'newroom'
,
room
);
return
room
;
}
_addWorker
(
worker
)
{
// Store the Worker instance and remove it when closed.
...
...
lib/Worker.js
浏览文件 @
4f5df6fa
...
...
@@ -181,6 +181,7 @@ class Worker extends EventEmitter
});
}
// TODO: REMOVE
createRoom
(
options
)
{
logger
.
debug
(
'createRoom() [options:%o]'
,
options
);
...
...
@@ -211,6 +212,40 @@ class Worker extends EventEmitter
throw
error
;
});
}
/**
* Create a Room instance.
*
* @return {Room}
*/
Room
(
data
)
{
logger
.
debug
(
'Room()'
);
const
internal
=
{
roomId
:
utils
.
randomNumber
()
};
const
room
=
new
Room
(
internal
,
data
,
this
.
_channel
);
// Store the Room instance and remove it when closed.
this
.
_rooms
.
add
(
room
);
room
.
on
(
'close'
,
()
=>
this
.
_rooms
.
delete
(
room
));
this
.
_channel
.
request
(
'worker.createRoom'
,
internal
)
.
then
(()
=>
{
logger
.
debug
(
'"worker.createRoom" request succeeded'
);
})
.
catch
((
error
)
=>
{
logger
.
error
(
'"worker.createRoom" request failed: %s'
,
error
);
room
.
close
(
error
,
true
);
});
return
room
;
}
}
module
.
exports
=
Worker
;
lib/ortc.js
0 → 100644
浏览文件 @
4f5df6fa
'use strict'
;
const
supportedRtpCapabilities
=
require
(
'./supportedRtpCapabilities'
);
const
DYNAMIC_PAYLOAD_TYPES
=
[
100
,
101
,
102
,
103
,
104
,
105
,
106
,
107
,
108
,
109
,
110
,
111
,
112
,
113
,
114
,
115
,
116
,
117
,
118
,
119
,
120
,
121
,
122
,
123
,
124
,
125
,
126
,
127
,
96
,
97
,
98
,
99
,
77
,
78
,
79
,
80
,
81
,
82
,
83
,
84
,
85
,
86
,
87
,
88
,
89
,
90
,
91
,
92
,
93
,
94
,
95
,
35
,
36
,
37
,
38
,
39
,
40
,
41
,
42
,
43
,
44
,
45
,
46
,
47
,
48
,
49
,
50
,
51
,
52
,
53
,
54
,
55
,
56
,
57
,
58
,
59
,
60
,
61
,
62
,
63
,
64
,
65
,
66
,
67
,
68
,
69
,
70
,
71
];
/**
* Generate RTP capabilities for the room based on the given media codecs and
* mediasoup supported RTP capabilities. It may throw.
*
* @param {array<RoomMediaCodec>]} mediaCodecs
*
* @return {RTCRtpCapabilities}
*/
exports
.
generateRoomRtpCapabilities
=
function
(
mediaCodecs
)
{
if
(
!
Array
.
isArray
(
mediaCodecs
))
throw
new
TypeError
(
'mediaCodecs must be an Array'
);
const
supportedCodecs
=
supportedRtpCapabilities
.
codecs
;
const
caps
=
{
codecs
:
[],
headerExtensions
:
supportedRtpCapabilities
.
headerExtensions
,
fecMechanisms
:
supportedRtpCapabilities
.
fecMechanisms
};
let
dynamicPayloadTypeIdx
=
0
;
for
(
const
mediaCodec
of
mediaCodecs
)
{
if
(
typeof
mediaCodecs
!==
'object'
)
throw
new
TypeError
(
'mediaCodec must be an Object'
);
const
matchedSupportedCodec
=
supportedCodecs
.
find
((
supportedCodec
)
=>
{
return
matchCodecCapabilities
(
mediaCodec
,
supportedCodec
);
});
if
(
!
matchedSupportedCodec
)
throw
new
Error
(
`RoomMediaCodec not supported [name:
${
mediaCodec
.
name
}
]`
);
// Clone the supported codec.
const
codec
=
Object
.
assign
({},
matchedSupportedCodec
);
// Normalize channels.
if
(
codec
.
kind
!==
'audio'
)
delete
codec
.
channels
;
else
if
(
!
codec
.
channels
)
codec
.
channels
=
1
;
// Merge the media codec parameters.
codec
.
parameters
=
Object
.
assign
({},
codec
.
parameters
,
mediaCodec
.
parameters
);
// Ensure rtcpFeedback is an Array.
codec
.
rtcpFeedback
=
codec
.
rtcpFeedback
||
[];
// Assign a payload type.
if
(
typeof
codec
.
preferredPayloadType
!==
'number'
)
{
const
pt
=
DYNAMIC_PAYLOAD_TYPES
[
dynamicPayloadTypeIdx
++
];
if
(
!
pt
)
throw
new
Error
(
'cannot allocate more dynamic codec payload types'
);
codec
.
preferredPayloadType
=
pt
;
}
// Append to the codec list.
caps
.
codecs
.
push
(
codec
);
// Add a RTX video codec if video.
if
(
codec
.
kind
===
'video'
)
{
const
pt
=
DYNAMIC_PAYLOAD_TYPES
[
dynamicPayloadTypeIdx
++
];
if
(
!
pt
)
throw
new
Error
(
'cannot allocate more dynamic codec payload types'
);
const
rtxCodec
=
{
kind
:
codec
.
kind
,
name
:
'rtx'
,
mimeType
:
`
${
codec
.
kind
}
/rtx`
,
preferredPayloadType
:
pt
,
clockRate
:
codec
.
clockRate
,
parameters
:
{
apt
:
codec
.
preferredPayloadType
}
};
// Append to the codec list.
caps
.
codecs
.
push
(
rtxCodec
);
}
}
console
.
log
(
caps
);
return
caps
;
};
function
matchCodecCapabilities
(
codecA
,
codecB
)
{
if
(
codecA
.
kind
!==
codecB
.
kind
)
return
false
;
if
(
codecA
.
name
.
toLowerCase
()
!==
codecB
.
name
.
toLowerCase
())
return
false
;
if
(
codecA
.
clockRate
!==
codecB
.
clockRate
)
return
false
;
if
(
(
codecA
.
channels
>
1
||
codecB
.
channels
>
1
)
&&
codecA
.
channels
!==
codecB
.
channels
)
{
return
false
;
}
// TODO: H264 parameters.
return
true
;
}
lib/supportedRtpCapabilities.js
浏览文件 @
4f5df6fa
...
...
@@ -5,124 +5,135 @@ const supportedRtpCapabilities =
codecs
:
[
{
kind
:
'audio'
,
name
:
'audio/
opus'
,
clockRate
:
48000
,
numChannels
:
2
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'
opus'
,
mimeType
:
'audio/opus'
,
clockRate
:
48000
,
channels
:
2
},
{
kind
:
'audio'
,
name
:
'audio/PCMU'
,
clockRate
:
8000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'PCMU'
,
mimeType
:
'audio/PCMU'
,
preferredPayloadType
:
0
,
clockRate
:
8000
,
rtcpFeedback
:
[]
},
{
kind
:
'audio'
,
name
:
'audio/PCMA'
,
clockRate
:
8000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'PCMA'
,
mimeType
:
'audio/PCMA'
,
preferredPayloadType
:
8
,
clockRate
:
8000
,
rtcpFeedback
:
[]
},
{
kind
:
'audio'
,
name
:
'audio/ISAC'
,
name
:
'ISAC'
,
mimeType
:
'audio/ISAC'
,
clockRate
:
32000
,
rtcpFeedback
:
[]
},
{
kind
:
'audio'
,
name
:
'audio/
ISAC'
,
clockRate
:
16000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'
ISAC'
,
mimeType
:
'audio/ISAC'
,
clockRate
:
16000
},
{
kind
:
'audio'
,
name
:
'audio/G722'
,
clockRate
:
8000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'G722'
,
mimeType
:
'audio/G722'
,
preferredPayloadType
:
9
,
clockRate
:
8000
},
{
kind
:
'audio'
,
name
:
'audio/
iLBC'
,
clockRate
:
8000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'
iLBC'
,
mimeType
:
'audio/iLBC'
,
clockRate
:
8000
},
{
kind
:
'audio'
,
name
:
'audio/
SILK'
,
clockRate
:
24000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'
SILK'
,
mimeType
:
'audio/SILK'
,
clockRate
:
24000
},
{
kind
:
'audio'
,
name
:
'audio/
SILK'
,
clockRate
:
16000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'
SILK'
,
mimeType
:
'audio/SILK'
,
clockRate
:
16000
},
{
kind
:
'audio'
,
name
:
'audio/
SILK'
,
clockRate
:
12000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'
SILK'
,
mimeType
:
'audio/SILK'
,
clockRate
:
12000
},
{
kind
:
'audio'
,
name
:
'audio/
SILK'
,
clockRate
:
8000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'
SILK'
,
mimeType
:
'audio/SILK'
,
clockRate
:
8000
},
{
kind
:
'audio'
,
name
:
'audio/CN'
,
clockRate
:
32000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'CN'
,
mimeType
:
'audio/CN'
,
preferredPayloadType
:
13
,
clockRate
:
32000
},
{
kind
:
'audio'
,
name
:
'audio/CN'
,
clockRate
:
16000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'CN'
,
mimeType
:
'audio/CN'
,
preferredPayloadType
:
13
,
clockRate
:
16000
},
{
kind
:
'audio'
,
name
:
'audio/CN'
,
clockRate
:
8000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'CN'
,
mimeType
:
'audio/CN'
,
preferredPayloadType
:
13
,
clockRate
:
8000
},
{
kind
:
'audio'
,
name
:
'audio/CN'
,
clockRate
:
32000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'CN'
,
mimeType
:
'audio/CN'
,
preferredPayloadType
:
13
,
clockRate
:
32000
},
{
kind
:
'audio'
,
name
:
'audio/
telephone-event'
,
clockRate
:
48000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'
telephone-event'
,
mimeType
:
'audio/telephone-event'
,
clockRate
:
48000
},
{
kind
:
'audio'
,
name
:
'audio/
telephone-event'
,
clockRate
:
32000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'
telephone-event'
,
mimeType
:
'audio/telephone-event'
,
clockRate
:
32000
},
{
kind
:
'audio'
,
name
:
'audio/
telephone-event'
,
clockRate
:
16000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'
telephone-event'
,
mimeType
:
'audio/telephone-event'
,
clockRate
:
16000
},
{
kind
:
'audio'
,
name
:
'audio/
telephone-event'
,
clockRate
:
8000
,
rtcpFeedback
:
[]
kind
:
'audio'
,
name
:
'
telephone-event'
,
mimeType
:
'audio/telephone-event'
,
clockRate
:
8000
},
{
kind
:
'video'
,
name
:
'video/VP8'
,
name
:
'VP8'
,
mimeType
:
'video/VP8'
,
clockRate
:
90000
,
rtcpFeedback
:
[
...
...
@@ -139,7 +150,8 @@ const supportedRtpCapabilities =
},
{
kind
:
'video'
,
name
:
'video/VP9'
,
name
:
'VP9'
,
mimeType
:
'video/VP9'
,
clockRate
:
90000
,
rtcpFeedback
:
[
...
...
@@ -156,7 +168,8 @@ const supportedRtpCapabilities =
},
{
kind
:
'video'
,
name
:
'video/H264'
,
name
:
'H264'
,
mimeType
:
'video/H264'
,
clockRate
:
90000
,
parameters
:
{
...
...
@@ -177,7 +190,8 @@ const supportedRtpCapabilities =
},
{
kind
:
'video'
,
name
:
'video/H264'
,
name
:
'H264'
,
mimeType
:
'video/H264'
,
clockRate
:
90000
,
parameters
:
{
...
...
@@ -198,7 +212,8 @@ const supportedRtpCapabilities =
},
{
kind
:
'video'
,
name
:
'video/H265'
,
name
:
'H265'
,
mimeType
:
'video/H265'
,
clockRate
:
90000
,
rtcpFeedback
:
[
...
...
lib/utils.js
浏览文件 @
4f5df6fa
...
...
@@ -11,20 +11,17 @@ const randomNumberGenerator = randomNumber.generator(
integer
:
true
});
module
.
exports
=
exports
.
randomString
=
function
(
length
)
{
randomString
(
length
)
{
return
randomatic
(
'a'
,
length
||
8
);
},
return
randomatic
(
'a'
,
length
||
8
);
};
randomNumber
:
randomNumberGenerator
,
exports
.
randomNumber
=
randomNumberGenerator
;
clone
(
obj
)
{
if
(
!
obj
||
typeof
obj
!==
'object'
)
return
{};
else
return
clone
(
obj
,
false
);
}
exports
.
cloneObject
=
function
(
obj
)
{
if
(
typeof
obj
!==
'object'
)
return
{};
return
clone
(
obj
,
false
);
};
test/test-Server.js
浏览文件 @
4f5df6fa
...
...
@@ -2,139 +2,227 @@
const
tap
=
require
(
'tap'
);
const
mediasoup
=
require
(
'../'
);
const
roomOptions
=
require
(
'./data/options'
).
roomOptions
;
//
const roomOptions = require('./data/options').roomOptions;
tap
.
test
(
'server.
updateSettings() with no options must succeed
'
,
{
timeout
:
2000
},
(
t
)
=>
'server.
Room() with valid media codecs
'
,
{
timeout
:
2000
},
(
t
)
=>
{
const
server
=
mediasoup
.
Server
();
t
.
tearDown
(()
=>
server
.
close
());
server
.
updateSettings
()
.
then
(()
=>
const
mediaCodecs
=
[
{
t
.
pass
(
'server.updateSettings() succeeded'
);
t
.
end
();
})
.
catch
((
error
)
=>
t
.
fail
(
`server.updateSettings() failed:
${
error
}
`
));
});
tap
.
test
(
'server.updateSettings() with valid options must succeed'
,
{
timeout
:
2000
},
(
t
)
=>
{
const
server
=
mediasoup
.
Server
();
t
.
tearDown
(()
=>
server
.
close
());
server
.
updateSettings
({
logLevel
:
'warn'
})
.
then
(()
=>
kind
:
'audio'
,
name
:
'opus'
,
clockRate
:
48000
,
channels
:
2
},
{
t
.
pass
(
'server.updateSettings() succeeded'
);
t
.
end
();
})
.
catch
((
error
)
=>
t
.
fail
(
`server.updateSettings() failed:
${
error
}
`
));
});
tap
.
test
(
'server.updateSettings() with invalid options must fail'
,
{
timeout
:
2000
},
(
t
)
=>
{
const
server
=
mediasoup
.
Server
();
t
.
tearDown
(()
=>
server
.
close
());
server
.
updateSettings
({
logLevel
:
'chicken'
})
.
then
(()
=>
t
.
fail
(
'server.updateSettings() succeeded'
))
.
catch
((
error
)
=>
kind
:
'audio'
,
name
:
'PCMU'
,
clockRate
:
8000
},
{
t
.
pass
(
`server.updateSettings() failed:
${
error
}
`
);
t
.
end
();
});
});
tap
.
test
(
'server.updateSettings() in a closed server must fail'
,
{
timeout
:
2000
},
(
t
)
=>
{
const
server
=
mediasoup
.
Server
();
t
.
tearDown
(()
=>
server
.
close
());
server
.
on
(
'close'
,
()
=>
{
server
.
updateSettings
({
logLevel
:
'error'
})
.
then
(()
=>
t
.
fail
(
'server.updateSettings() succeeded'
))
.
catch
((
error
)
=>
kind
:
'video'
,
name
:
'VP8'
,
clockRate
:
90000
,
parameters
:
{
t
.
pass
(
`server.updateSettings() failed:
${
error
}
`
);
t
.
type
(
error
,
mediasoup
.
errors
.
InvalidStateError
,
'server.updateSettings() must reject with InvalidStateError'
);
t
.
end
();
});
});
server
.
close
();
});
foo
:
123
}
}
];
tap
.
test
(
'server.createRoom() must succeed'
,
{
_timeout
:
2000
},
(
t
)
=>
{
const
server
=
mediasoup
.
Server
();
t
.
tearDown
(()
=>
server
.
close
());
server
.
createRoom
(
roomOptions
)
.
then
((
room
)
=>
const
expectedCodecs
=
[
{
t
.
pass
(
'server.createRoom() succeeded'
);
room
.
on
(
'close'
,
(
error
)
=>
kind
:
'audio'
,
name
:
'opus'
,
mimeType
:
'audio/opus'
,
preferredPayloadType
:
100
,
clockRate
:
48000
,
channels
:
2
,
parameters
:
{}
},
{
kind
:
'audio'
,
name
:
'PCMU'
,
mimeType
:
'audio/PCMU'
,
preferredPayloadType
:
0
,
clockRate
:
8000
,
channels
:
1
,
parameters
:
{}
},
{
kind
:
'video'
,
name
:
'VP8'
,
mimeType
:
'video/VP8'
,
preferredPayloadType
:
101
,
clockRate
:
90000
,
parameters
:
{
t
.
error
(
error
,
'room must close cleanly'
);
t
.
end
();
});
// Wait a bit so Channel requests receive response
setTimeout
(()
=>
room
.
close
(),
50
);
})
.
catch
((
error
)
=>
t
.
fail
(
`server.createRoom() failed:
${
error
}
`
));
});
tap
.
test
(
'server.createRoom() in a closed server must fail'
,
{
timeout
:
2000
},
(
t
)
=>
{
const
server
=
mediasoup
.
Server
();
server
.
close
();
server
.
createRoom
(
roomOptions
)
.
then
(()
=>
t
.
fail
(
'server.createRoom() succeeded'
))
.
catch
((
error
)
=>
foo
:
123
}
},
{
t
.
pass
(
`server.createRoom() failed:
${
error
}
`
);
t
.
type
(
error
,
mediasoup
.
errors
.
InvalidStateError
,
'server.createRoom() must reject with InvalidStateError'
);
t
.
end
();
});
});
tap
.
test
(
'server.dump() must succeed'
,
{
timeout
:
2000
},
(
t
)
=>
{
const
server
=
mediasoup
.
Server
({
numWorkers
:
2
});
kind
:
'video'
,
name
:
'rtx'
,
mimeType
:
'video/rtx'
,
preferredPayloadType
:
102
,
clockRate
:
90000
,
parameters
:
{
apt
:
101
}
}
];
const
room
=
server
.
Room
(
mediaCodecs
);
const
reducedCodecs
=
room
.
rtpCapabilities
.
codecs
.
map
((
codec
)
=>
{
delete
codec
.
rtcpFeedback
;
t
.
tearDown
(()
=>
server
.
close
());
return
codec
;
});
server
.
dump
()
.
then
((
data
)
=>
{
t
.
pass
(
'server.dump() succeeded'
);
t
.
equal
(
Object
.
keys
(
data
.
workers
).
length
,
2
,
'server.dump() must retrieve two workers'
);
t
.
end
();
})
.
catch
((
error
)
=>
t
.
fail
(
`server.dump() failed:
${
error
}
`
));
t
.
same
(
reducedCodecs
,
expectedCodecs
,
'room codecs match'
);
t
.
end
();
});
// tap.test(
// 'server.updateSettings() with no options must succeed', { timeout: 2000 }, (t) =>
// {
// const server = mediasoup.Server();
// t.tearDown(() => server.close());
// server.updateSettings()
// .then(() =>
// {
// t.pass('server.updateSettings() succeeded');
// t.end();
// })
// .catch((error) => t.fail(`server.updateSettings() failed: ${error}`));
// });
// tap.test(
// 'server.updateSettings() with valid options must succeed',
// { timeout: 2000 }, (t) =>
// {
// const server = mediasoup.Server();
// t.tearDown(() => server.close());
// server.updateSettings({ logLevel: 'warn' })
// .then(() =>
// {
// t.pass('server.updateSettings() succeeded');
// t.end();
// })
// .catch((error) => t.fail(`server.updateSettings() failed: ${error}`));
// });
// tap.test(
// 'server.updateSettings() with invalid options must fail', { timeout: 2000 }, (t) =>
// {
// const server = mediasoup.Server();
// t.tearDown(() => server.close());
// server.updateSettings({ logLevel: 'chicken' })
// .then(() => t.fail('server.updateSettings() succeeded'))
// .catch((error) =>
// {
// t.pass(`server.updateSettings() failed: ${error}`);
// t.end();
// });
// });
// tap.test(
// 'server.updateSettings() in a closed server must fail', { timeout: 2000 }, (t) =>
// {
// const server = mediasoup.Server();
// t.tearDown(() => server.close());
// server.on('close', () =>
// {
// server.updateSettings({ logLevel: 'error' })
// .then(() => t.fail('server.updateSettings() succeeded'))
// .catch((error) =>
// {
// t.pass(`server.updateSettings() failed: ${error}`);
// t.type(
// error, mediasoup.errors.InvalidStateError,
// 'server.updateSettings() must reject with InvalidStateError');
// t.end();
// });
// });
// server.close();
// });
// tap.test(
// 'server.createRoom() must succeed', { _timeout: 2000 }, (t) =>
// {
// const server = mediasoup.Server();
// t.tearDown(() => server.close());
// server.createRoom(roomOptions)
// .then((room) =>
// {
// t.pass('server.createRoom() succeeded');
// room.on('close', (error) =>
// {
// t.error(error, 'room must close cleanly');
// t.end();
// });
// // Wait a bit so Channel requests receive response
// setTimeout(() => room.close(), 50);
// })
// .catch((error) => t.fail(`server.createRoom() failed: ${error}`));
// });
// tap.test(
// 'server.createRoom() in a closed server must fail', { timeout: 2000 }, (t) =>
// {
// const server = mediasoup.Server();
// server.close();
// server.createRoom(roomOptions)
// .then(() => t.fail('server.createRoom() succeeded'))
// .catch((error) =>
// {
// t.pass(`server.createRoom() failed: ${error}`);
// t.type(
// error, mediasoup.errors.InvalidStateError,
// 'server.createRoom() must reject with InvalidStateError');
// t.end();
// });
// });
// tap.test(
// 'server.dump() must succeed', { timeout: 2000 }, (t) =>
// {
// const server = mediasoup.Server({ numWorkers: 2 });
// t.tearDown(() => server.close());
// server.dump()
// .then((data) =>
// {
// t.pass('server.dump() succeeded');
// t.equal(
// Object.keys(data.workers).length, 2,
// 'server.dump() must retrieve two workers');
// t.end();
// })
// .catch((error) => t.fail(`server.dump() failed: ${error}`));
// });
worker/include/RTC/Room.hpp
浏览文件 @
4f5df6fa
...
...
@@ -30,13 +30,6 @@ namespace RTC
virtual
void
OnRoomClosed
(
RTC
::
Room
*
room
)
=
0
;
};
public
:
static
void
ClassInit
();
private
:
static
RTC
::
RtpCapabilities
supportedRtpCapabilities
;
static
std
::
vector
<
uint8_t
>
availablePayloadTypes
;
public
:
Room
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
uint32_t
roomId
,
Json
::
Value
&
data
);
...
...
worker/include/RTC/RtpDictionaries.hpp
浏览文件 @
4f5df6fa
...
...
@@ -11,13 +11,6 @@
namespace
RTC
{
enum
class
Scope
:
uint8_t
{
ROOM_CAPABILITY
=
1
,
PEER_CAPABILITY
,
RECEIVE
};
class
Media
{
public
:
...
...
@@ -38,7 +31,7 @@ namespace RTC
static
std
::
map
<
Kind
,
Json
::
StaticString
>
kind2Json
;
};
class
RtpCodecMime
class
RtpCodecMime
Type
{
public
:
enum
class
Type
:
uint8_t
...
...
@@ -84,19 +77,24 @@ namespace RTC
static
std
::
map
<
Subtype
,
std
::
string
>
subtype2String
;
public
:
RtpCodecMime
(){};
RtpCodecMime
Type
(){};
bool
operator
==
(
const
RtpCodecMime
&
other
)
const
bool
operator
==
(
const
RtpCodecMime
Type
&
other
)
const
{
return
this
->
type
==
other
.
type
&&
this
->
subtype
==
other
.
subtype
;
}
bool
operator
!=
(
const
RtpCodecMime
&
other
)
const
bool
operator
!=
(
const
RtpCodecMime
Type
&
other
)
const
{
return
!
(
*
this
==
other
);
}
void
SetName
(
const
std
::
string
&
name
);
void
SetMimeType
(
const
std
::
string
&
mimeType
);
const
std
::
string
&
ToString
()
const
{
return
this
->
mimeType
;
}
const
std
::
string
&
GetName
()
const
{
...
...
@@ -121,6 +119,9 @@ namespace RTC
public
:
Type
type
{
Type
::
UNSET
};
Subtype
subtype
{
Subtype
::
UNSET
};
private
:
std
::
string
mimeType
;
std
::
string
name
;
};
...
...
@@ -156,31 +157,27 @@ namespace RTC
std
::
string
parameter
;
};
class
RtpCodec
Parameters
class
RtpCodec
Capability
{
public
:
RtpCodec
Parameters
(){};
RtpCodec
Parameters
(
Json
::
Value
&
data
,
RTC
::
Scope
scope
);
RtpCodec
Capability
(){};
RtpCodec
Capability
(
Json
::
Value
&
data
);
Json
::
Value
ToJson
()
const
;
bool
Matches
(
RtpCodec
Parameters
&
codec
,
bool
checkPayloadType
=
false
);
bool
Matches
(
RtpCodec
Capability
&
codec
,
bool
checkPayloadType
=
false
);
void
ReduceRtcpFeedback
(
std
::
vector
<
RtcpFeedback
>&
supportedRtcpFeedback
);
private
:
void
CheckCodec
();
private
:
RTC
::
Scope
scope
{
RTC
::
Scope
::
ROOM_CAPABILITY
};
public
:
Media
::
Kind
kind
{
Media
::
Kind
::
ALL
};
RtpCodecMime
mime
;
RtpCodecMime
Type
mime
;
uint8_t
payloadType
{
0
};
bool
hasPayloadType
{
false
};
uint32_t
clockRate
{
0
};
uint32_t
maxptime
{
0
};
uint32_t
ptime
{
0
};
uint32_t
numC
hannels
{
1
};
uint32_t
c
hannels
{
1
};
RTC
::
Parameters
parameters
;
std
::
vector
<
RtcpFeedback
>
rtcpFeedback
;
};
...
...
@@ -204,21 +201,46 @@ namespace RTC
{
public
:
RtpCapabilities
(){};
RtpCapabilities
(
Json
::
Value
&
data
,
RTC
::
Scope
scope
);
RtpCapabilities
(
Json
::
Value
&
data
);
Json
::
Value
ToJson
()
const
;
void
ReduceHeaderExtensions
(
std
::
vector
<
RtpHeaderExtension
>&
supportedHeaderExtensions
);
void
ReduceFecMechanisms
(
std
::
vector
<
std
::
string
>&
supportedFecMechanisms
);
private
:
void
ValidateCodecs
(
RTC
::
Scope
scope
);
void
ValidateCodecs
();
public
:
std
::
vector
<
RtpCodec
Parameters
>
codecs
;
std
::
vector
<
RtpCodec
Capability
>
codecs
;
std
::
vector
<
RtpHeaderExtension
>
headerExtensions
;
std
::
vector
<
std
::
string
>
fecMechanisms
;
};
class
RtpCodecParameters
{
public
:
RtpCodecParameters
(){};
RtpCodecParameters
(
Json
::
Value
&
data
);
Json
::
Value
ToJson
()
const
;
bool
Matches
(
RtpCodecParameters
&
codec
,
bool
checkPayloadType
=
false
);
void
ReduceRtcpFeedback
(
std
::
vector
<
RtcpFeedback
>&
supportedRtcpFeedback
);
private
:
void
CheckCodec
();
public
:
Media
::
Kind
kind
{
Media
::
Kind
::
ALL
};
RtpCodecMimeType
mime
;
uint8_t
payloadType
{
0
};
uint32_t
clockRate
{
0
};
uint32_t
maxptime
{
0
};
uint32_t
ptime
{
0
};
uint32_t
channels
{
1
};
RTC
::
Parameters
parameters
;
std
::
vector
<
RtcpFeedback
>
rtcpFeedback
;
};
class
RtpFecParameters
{
public
:
...
...
worker/include/RTC/RtpStream.hpp
浏览文件 @
4f5df6fa
...
...
@@ -17,7 +17,7 @@ namespace RTC
uint32_t
ssrc
{
0
};
uint8_t
payloadType
{
0
};
RTC
::
RtpCodecMime
mime
;
RTC
::
RtpCodecMime
Type
mime
;
uint32_t
clockRate
{
0
};
bool
useNack
{
false
};
bool
usePli
{
false
};
...
...
worker/mediasoup-worker.gyp
浏览文件 @
4f5df6fa
...
...
@@ -46,8 +46,7 @@
'src/RTC/RtpDictionaries/Parameters.cpp',
'src/RTC/RtpDictionaries/RtcpFeedback.cpp',
'src/RTC/RtpDictionaries/RtcpParameters.cpp',
'src/RTC/RtpDictionaries/RtpCapabilities.cpp',
'src/RTC/RtpDictionaries/RtpCodecMime.cpp',
'src/RTC/RtpDictionaries/RtpCodecMimeType.cpp',
'src/RTC/RtpDictionaries/RtpCodecParameters.cpp',
'src/RTC/RtpDictionaries/RtpEncodingParameters.cpp',
'src/RTC/RtpDictionaries/RtpFecParameters.cpp',
...
...
worker/src/RTC/Consumer.cpp
浏览文件 @
4f5df6fa
...
...
@@ -469,10 +469,7 @@ namespace RTC
{
auto
&
codec
=
this
->
rtpParameters
->
GetRtxCodecForEncoding
(
encoding
);
if
(
codec
.
hasPayloadType
)
{
this
->
rtpStream
->
SetRtx
(
codec
.
payloadType
,
encoding
.
rtx
.
ssrc
);
}
this
->
rtpStream
->
SetRtx
(
codec
.
payloadType
,
encoding
.
rtx
.
ssrc
);
}
}
...
...
worker/src/RTC/Peer.cpp
浏览文件 @
4f5df6fa
...
...
@@ -179,7 +179,7 @@ namespace RTC
try
{
this
->
capabilities
=
RTC
::
RtpCapabilities
(
request
->
data
,
RTC
::
Scope
::
PEER_CAPABILITY
);
this
->
capabilities
=
RTC
::
RtpCapabilities
(
request
->
data
);
}
catch
(
const
MediaSoupError
&
error
)
{
...
...
worker/src/RTC/Producer.cpp
浏览文件 @
4f5df6fa
...
...
@@ -466,14 +466,10 @@ namespace RTC
return
;
auto
&
codec
=
this
->
rtpParameters
->
GetRtxCodecForEncoding
(
encoding
);
auto
rtpStream
=
this
->
rtpStreams
[
ssrc
];
if
(
codec
.
hasPayloadType
)
{
auto
rtpStream
=
this
->
rtpStreams
[
ssrc
];
rtpStream
->
SetRtx
(
codec
.
payloadType
,
encoding
.
rtx
.
ssrc
);
this
->
rtxStreamMap
[
encoding
.
rtx
.
ssrc
]
=
rtpStream
;
}
rtpStream
->
SetRtx
(
codec
.
payloadType
,
encoding
.
rtx
.
ssrc
);
this
->
rtxStreamMap
[
encoding
.
rtx
.
ssrc
]
=
rtpStream
;
}
}
...
...
worker/src/RTC/Room.cpp
浏览文件 @
4f5df6fa
...
...
@@ -30,7 +30,7 @@ namespace RTC
{
// NOTE: These lines are auto-generated from data/supportedCapabilities.js.
const
std
::
string
supportedRtpCapabilities
=
R"({"codecs":[{"kind":"audio","name":"
audio/opus","clockRate":48000,"numChannels":2,"rtcpFeedback":[]},{"kind":"audio","name":"audio/PCMU","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/PCMA","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/ISAC","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/ISAC","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/G722","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/iLBC","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/SILK","clockRate":24000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/SILK","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/SILK","clockRate":12000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/SILK","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/CN","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/CN","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/CN","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/CN","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/telephone-event","clockRate":48000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/telephone-event","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/telephone-event","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/telephone-event","clockRate":8000,"rtcpFeedback":[]},{"kind":"video","name":"video/VP8","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"video/VP9","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"video/H264","clockRate":90000,"parameters":{"packetizationMode":0},"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"video/H264","clockRate":90000,"parameters":{"packetizationMode":1},"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","nam
e":"video/H265","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]}],"headerExtensions":[{"kind":"audio","uri":"urn:ietf:params:rtp-hdrext:ssrc-audio-level","preferredId":1,"preferredEncrypt":false},{"kind":"video","uri":"urn:ietf:params:rtp-hdrext:toffset","preferredId":2,"preferredEncrypt":false},{"kind":"","uri":"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time","preferredId":3,"preferredEncrypt":false},{"kind":"video","uri":"urn:3gpp:video-orientation","preferredId":4,"preferredEncrypt":false},{"kind":"","uri":"urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id","preferredId":5,"preferredEncrypt":false}],"fecMechanisms":[]})"
;
R"({"codecs":[{"kind":"audio","name":"
opus","mimeType":"audio/opus","clockRate":48000,"channels":2,"rtcpFeedback":[]},{"kind":"audio","name":"PCMU","mimeType":"audio/PCMU","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"PCMA","mimeType":"audio/PCMA","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"ISAC","mimeType":"audio/ISAC","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"ISAC","mimeType":"audio/ISAC","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"G722","mimeType":"audio/G722","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"LBC","mimeType":"audio/iLBC","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"SILK","mimeType":"audio/SILK","clockRate":24000,"rtcpFeedback":[]},{"kind":"audio","name":"SILK","mimeType":"audio/SILK","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"SILK","mimeType":"audio/SILK","clockRate":12000,"rtcpFeedback":[]},{"kind":"audio","name":"SILK","mimeType":"audio/SILK","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"CN","mimeType":"audio/CN","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"CN","mimeType":"audio/CN","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"CN","mimeType":"audio/CN","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"CN","mimeType":"audio/CN","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"telephone-event","mimeType":"audio/telephone-event","clockRate":48000,"rtcpFeedback":[]},{"kind":"audio","name":"telephone-event","mimeType":"audio/telephone-event","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"telephone-event","mimeType":"audio/telephone-event","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"telephone-event","mimeType":"audio/telephone-event","clockRate":8000,"rtcpFeedback":[]},{"kind":"video","name":"VP8","mimeType":"video/VP8","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"VP9","mimeType":"video/VP9","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"H264","mimeType":"video/H264","clockRate":90000,"parameters":{"packetizationMode":0},"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"H264","mimeType":"video/H264","clockRate":90000,"parameters":{"packetizationMode":1},"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"H265","mimeTyp
e":"video/H265","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]}],"headerExtensions":[{"kind":"audio","uri":"urn:ietf:params:rtp-hdrext:ssrc-audio-level","preferredId":1,"preferredEncrypt":false},{"kind":"video","uri":"urn:ietf:params:rtp-hdrext:toffset","preferredId":2,"preferredEncrypt":false},{"kind":"","uri":"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time","preferredId":3,"preferredEncrypt":false},{"kind":"video","uri":"urn:3gpp:video-orientation","preferredId":4,"preferredEncrypt":false},{"kind":"","uri":"urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id","preferredId":5,"preferredEncrypt":false}],"fecMechanisms":[]})"
;
Json
::
CharReaderBuilder
builder
;
Json
::
Value
settings
=
Json
::
nullValue
;
...
...
@@ -59,7 +59,7 @@ namespace RTC
try
{
Room
::
supportedRtpCapabilities
=
RTC
::
RtpCapabilities
(
json
,
RTC
::
Scope
::
ROOM_CAPABILITY
);
Room
::
supportedRtpCapabilities
=
RTC
::
RtpCapabilities
(
json
);
}
catch
(
const
MediaSoupError
&
error
)
{
...
...
@@ -85,7 +85,7 @@ namespace RTC
for
(
auto
&
jsonMediaCodec
:
jsonMediaCodecs
)
{
RTC
::
RtpCodecParameters
mediaCodec
(
jsonMediaCodec
,
RTC
::
Scope
::
ROOM_CAPABILITY
);
RTC
::
RtpCodecParameters
mediaCodec
(
jsonMediaCodec
);
// Ignore feature codecs.
if
(
mediaCodec
.
mime
.
IsFeatureCodec
())
...
...
@@ -507,7 +507,7 @@ namespace RTC
static
const
std
::
string
videoRtx
=
"video/rtx"
;
rtxCodec
.
kind
=
RTC
::
Media
::
Kind
::
VIDEO
;
rtxCodec
.
mime
.
Set
Nam
e
(
videoRtx
);
rtxCodec
.
mime
.
Set
MimeTyp
e
(
videoRtx
);
rtxCodec
.
clockRate
=
mediaCodec
.
clockRate
;
rtxCodec
.
parameters
.
SetInteger
(
associatedPayloadType
,
mediaCodec
.
payloadType
);
...
...
worker/src/RTC/RtpDictionaries/RtpCapabilities.cpp
浏览文件 @
4f5df6fa
...
...
@@ -10,7 +10,7 @@ namespace RTC
{
/* Instance methods. */
RtpCapabilities
::
RtpCapabilities
(
Json
::
Value
&
data
,
RTC
::
Scope
scope
)
RtpCapabilities
::
RtpCapabilities
(
Json
::
Value
&
data
)
{
MS_TRACE
();
...
...
@@ -25,7 +25,7 @@ namespace RTC
for
(
auto
&
jsonCodec
:
jsonCodecs
)
{
RtpCodec
Parameters
codec
(
jsonCodec
,
scope
);
RtpCodec
Capability
codec
(
jsonCodec
);
// Append to the codecs vector.
this
->
codecs
.
push_back
(
codec
);
...
...
@@ -64,7 +64,7 @@ namespace RTC
// Validate RTP capabilities.
ValidateCodecs
(
scope
);
ValidateCodecs
();
}
Json
::
Value
RtpCapabilities
::
ToJson
()
const
...
...
@@ -155,23 +155,20 @@ namespace RTC
this
->
fecMechanisms
=
updatedFecMechanisms
;
}
inline
void
RtpCapabilities
::
ValidateCodecs
(
RTC
::
Scope
scope
)
inline
void
RtpCapabilities
::
ValidateCodecs
()
{
MS_TRACE
();
if
(
scope
==
RTC
::
Scope
::
PEER_CAPABILITY
)
{
// Payload types must be unique.
// Payload types must be unique.
std
::
unordered_set
<
uint8_t
>
payloadTypes
;
std
::
unordered_set
<
uint8_t
>
payloadTypes
;
for
(
auto
&
codec
:
this
->
codecs
)
{
if
(
payloadTypes
.
find
(
codec
.
payloadType
)
!=
payloadTypes
.
end
())
MS_THROW_ERROR
(
"duplicated codec.payloadType"
);
else
payloadTypes
.
insert
(
codec
.
payloadType
);
}
for
(
auto
&
codec
:
this
->
codecs
)
{
if
(
payloadTypes
.
find
(
codec
.
payloadType
)
!=
payloadTypes
.
end
())
MS_THROW_ERROR
(
"duplicated codec.payloadType"
);
else
payloadTypes
.
insert
(
codec
.
payloadType
);
}
}
}
// namespace RTC
worker/src/RTC/RtpDictionaries/RtpCodecCapability.cpp
0 → 100644
浏览文件 @
4f5df6fa
#define MS_CLASS "RTC::RtpCodecCapability"
// #define MS_LOG_DEV
#include "Logger.hpp"
#include "MediaSoupError.hpp"
#include "RTC/RtpDictionaries.hpp"
namespace
RTC
{
/* Instance methods. */
RtpCodecCapability
::
RtpCodecCapability
(
Json
::
Value
&
data
)
{
MS_TRACE
();
static
const
Json
::
StaticString
JsonStringKind
{
"kind"
};
static
const
Json
::
StaticString
JsonStringMimeType
{
"mimeType"
};
static
const
Json
::
StaticString
JsonStringPayloadType
{
"payloadType"
};
static
const
Json
::
StaticString
JsonStringClockRate
{
"clockRate"
};
static
const
Json
::
StaticString
JsonStringMaxptime
{
"maxptime"
};
static
const
Json
::
StaticString
JsonStringPtime
{
"ptime"
};
static
const
Json
::
StaticString
JsonStringNumChannels
{
"channels"
};
static
const
Json
::
StaticString
JsonStringParameters
{
"parameters"
};
static
const
Json
::
StaticString
JsonStringRtcpFeedback
{
"rtcpFeedback"
};
if
(
!
data
.
isObject
())
MS_THROW_ERROR
(
"RtpCodecCapability is not an object"
);
// `kind` is mandatory.
if
(
!
data
[
JsonStringKind
].
isString
())
MS_THROW_ERROR
(
"missing RtpCodecCapability.kind"
);
std
::
string
kind
=
data
[
JsonStringKind
].
asString
();
// NOTE: This may throw.
this
->
kind
=
RTC
::
Media
::
GetKind
(
kind
);
// `mimeType` is mandatory.
if
(
!
data
[
JsonStringMimeType
].
isString
())
MS_THROW_ERROR
(
"missing RtpCodec.mimeType"
);
std
::
string
mimeType
=
data
[
JsonStringMimeType
].
asString
();
// Set MIME field.
// NOTE: This may throw.
this
->
mime
.
SetMimeType
(
mimeType
);
if
(
!
data
[
JsonStringPayloadType
].
isUInt
())
MS_THROW_ERROR
(
"missing RtpCodecCapability.payloadType"
);
this
->
payloadType
=
static_cast
<
uint8_t
>
(
data
[
JsonStringPayloadType
].
asUInt
());
// `clockRate` is mandatory.
if
(
!
data
[
JsonStringClockRate
].
isUInt
())
MS_THROW_ERROR
(
"missing RtpCodecCapability.clockRate"
);
this
->
clockRate
=
uint32_t
{
data
[
JsonStringClockRate
].
asUInt
()
};
// `maxptime` is optional.
if
(
data
[
JsonStringMaxptime
].
isUInt
())
this
->
maxptime
=
uint32_t
{
data
[
JsonStringMaxptime
].
asUInt
()
};
// `ptime` is optional.
if
(
data
[
JsonStringPtime
].
isUInt
())
this
->
ptime
=
uint32_t
{
data
[
JsonStringPtime
].
asUInt
()
};
// `channels` is optional.
if
(
data
[
JsonStringNumChannels
].
isUInt
())
this
->
channels
=
uint32_t
{
data
[
JsonStringNumChannels
].
asUInt
()
};
// `parameters` is optional.
if
(
data
[
JsonStringParameters
].
isObject
())
this
->
parameters
.
Set
(
data
[
JsonStringParameters
]);
// `rtcpFeedback` is optional.
if
(
data
[
JsonStringRtcpFeedback
].
isArray
())
{
auto
&
jsonRtcpFeedback
=
data
[
JsonStringRtcpFeedback
];
for
(
auto
&
i
:
jsonRtcpFeedback
)
{
RTC
::
RtcpFeedback
rtcpFeedback
(
i
);
// Append to the rtcpFeedback vector.
this
->
rtcpFeedback
.
push_back
(
rtcpFeedback
);
}
}
// Check codec.
CheckCodec
();
}
Json
::
Value
RtpCodecCapability
::
ToJson
()
const
{
MS_TRACE
();
static
const
Json
::
StaticString
JsonStringKind
{
"kind"
};
static
const
Json
::
StaticString
JsonStringMimeType
{
"mimeType"
};
static
const
Json
::
StaticString
JsonStringName
{
"name"
};
static
const
Json
::
StaticString
JsonStringPayloadType
{
"payloadType"
};
static
const
Json
::
StaticString
JsonStringClockRate
{
"clockRate"
};
static
const
Json
::
StaticString
JsonStringMaxptime
{
"maxptime"
};
static
const
Json
::
StaticString
JsonStringPtime
{
"ptime"
};
static
const
Json
::
StaticString
JsonStringNumChannels
{
"channels"
};
static
const
Json
::
StaticString
JsonStringParameters
{
"parameters"
};
static
const
Json
::
StaticString
JsonStringRtcpFeedback
{
"rtcpFeedback"
};
Json
::
Value
json
(
Json
::
objectValue
);
// Add `kind`.
json
[
JsonStringKind
]
=
RTC
::
Media
::
GetJsonString
(
this
->
kind
);
// Add `mimeType`.
json
[
JsonStringMimeType
]
=
this
->
mime
.
ToString
();
// Add `name`.
json
[
JsonStringName
]
=
this
->
mime
.
GetName
();
// Add `payloadType`.
json
[
JsonStringPayloadType
]
=
Json
::
UInt
{
this
->
payloadType
};
// Add `clockRate`.
json
[
JsonStringClockRate
]
=
Json
::
UInt
{
this
->
clockRate
};
// Add `maxptime`.
if
(
this
->
maxptime
!=
0u
)
json
[
JsonStringMaxptime
]
=
Json
::
UInt
{
this
->
maxptime
};
// Add `ptime`.
if
(
this
->
ptime
!=
0u
)
json
[
JsonStringPtime
]
=
Json
::
UInt
{
this
->
ptime
};
// Add `channels`.
if
(
this
->
channels
>
1
)
json
[
JsonStringNumChannels
]
=
Json
::
UInt
{
this
->
channels
};
// Add `parameters`.
json
[
JsonStringParameters
]
=
this
->
parameters
.
ToJson
();
// Add `rtcpFeedback`.
json
[
JsonStringRtcpFeedback
]
=
Json
::
arrayValue
;
for
(
auto
&
entry
:
this
->
rtcpFeedback
)
{
json
[
JsonStringRtcpFeedback
].
append
(
entry
.
ToJson
());
}
return
json
;
}
bool
RtpCodecCapability
::
Matches
(
RtpCodecCapability
&
codec
,
bool
checkPayloadType
)
{
MS_TRACE
();
static
std
::
string
jsonStringPacketizationMode
{
"packetizationMode"
};
// MIME must match.
if
(
this
->
mime
!=
codec
.
mime
)
return
false
;
if
(
checkPayloadType
)
{
if
(
this
->
payloadType
!=
codec
.
payloadType
)
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
->
channels
!=
codec
.
channels
)
return
false
;
break
;
}
default
:
;
}
// Per MIME checks.
switch
(
this
->
mime
.
subtype
)
{
case
RTC
:
:
RtpCodecMimeType
::
Subtype
::
H264
:
{
int32_t
packetizationMode
=
this
->
parameters
.
GetInteger
(
jsonStringPacketizationMode
);
int32_t
givenPacketizationMode
=
codec
.
parameters
.
GetInteger
(
jsonStringPacketizationMode
);
if
(
packetizationMode
!=
givenPacketizationMode
)
return
false
;
break
;
}
default
:
;
}
return
true
;
}
void
RtpCodecCapability
::
ReduceRtcpFeedback
(
std
::
vector
<
RTC
::
RtcpFeedback
>&
supportedRtcpFeedback
)
{
MS_TRACE
();
std
::
vector
<
RTC
::
RtcpFeedback
>
updatedRtcpFeedback
;
for
(
auto
&
rtcpFeedbackItem
:
this
->
rtcpFeedback
)
{
for
(
auto
&
supportedRtcpFeedbackItem
:
supportedRtcpFeedback
)
{
if
(
rtcpFeedbackItem
.
type
==
supportedRtcpFeedbackItem
.
type
&&
rtcpFeedbackItem
.
parameter
==
supportedRtcpFeedbackItem
.
parameter
)
{
updatedRtcpFeedback
.
push_back
(
supportedRtcpFeedbackItem
);
break
;
}
}
}
this
->
rtcpFeedback
=
updatedRtcpFeedback
;
}
inline
void
RtpCodecCapability
::
CheckCodec
()
{
MS_TRACE
();
static
std
::
string
jsonStringApt
{
"apt"
};
static
std
::
string
jsonStringPacketizationMode
{
"packetizationMode"
};
// Check per MIME parameters and set default values.
switch
(
this
->
mime
.
subtype
)
{
case
RTC
:
:
RtpCodecMimeType
::
Subtype
::
RTX
:
{
// A RTX codec must have 'apt' parameter.
if
(
!
this
->
parameters
.
HasInteger
(
jsonStringApt
))
MS_THROW_ERROR
(
"missing apt parameter in RTX RtpCodecCapability"
);
break
;
}
case
RTC
:
:
RtpCodecMimeType
::
Subtype
::
OPUS
:
{
// Opus default channels is 2.
if
(
this
->
channels
<
2
)
this
->
channels
=
2
;
break
;
}
case
RTC
:
:
RtpCodecMimeType
::
Subtype
::
H264
:
{
// H264 default packetizationMode is 0.
if
(
!
this
->
parameters
.
HasInteger
(
jsonStringPacketizationMode
))
this
->
parameters
.
SetInteger
(
jsonStringPacketizationMode
,
0
);
break
;
}
default
:
;
}
}
}
// namespace RTC
worker/src/RTC/RtpDictionaries/RtpCodecMime.cpp
deleted
100644 → 0
浏览文件 @
a3d2de61
#define MS_CLASS "RTC::RtpCodecMime"
// #define MS_LOG_DEV
#include "Logger.hpp"
#include "MediaSoupError.hpp"
#include "Utils.hpp"
#include "RTC/RtpDictionaries.hpp"
namespace
RTC
{
/* Class variables. */
// clang-format off
std
::
unordered_map
<
std
::
string
,
RtpCodecMime
::
Type
>
RtpCodecMime
::
string2Type
=
{
{
"audio"
,
RtpCodecMime
::
Type
::
AUDIO
},
{
"video"
,
RtpCodecMime
::
Type
::
VIDEO
}
};
std
::
map
<
RtpCodecMime
::
Type
,
std
::
string
>
RtpCodecMime
::
type2String
=
{
{
RtpCodecMime
::
Type
::
AUDIO
,
"audio"
},
{
RtpCodecMime
::
Type
::
VIDEO
,
"video"
}
};
std
::
unordered_map
<
std
::
string
,
RtpCodecMime
::
Subtype
>
RtpCodecMime
::
string2Subtype
=
{
// Audio codecs:
{
"opus"
,
RtpCodecMime
::
Subtype
::
OPUS
},
{
"pcma"
,
RtpCodecMime
::
Subtype
::
PCMA
},
{
"pcmu"
,
RtpCodecMime
::
Subtype
::
PCMU
},
{
"isac"
,
RtpCodecMime
::
Subtype
::
ISAC
},
{
"g722"
,
RtpCodecMime
::
Subtype
::
G722
},
{
"ilbc"
,
RtpCodecMime
::
Subtype
::
ILBC
},
{
"silk"
,
RtpCodecMime
::
Subtype
::
SILK
},
// Video codecs:
{
"vp8"
,
RtpCodecMime
::
Subtype
::
VP8
},
{
"vp9"
,
RtpCodecMime
::
Subtype
::
VP9
},
{
"h264"
,
RtpCodecMime
::
Subtype
::
H264
},
{
"x-h264uc"
,
RtpCodecMime
::
Subtype
::
X_H264UC
},
{
"h265"
,
RtpCodecMime
::
Subtype
::
H265
},
// Complementary codecs:
{
"cn"
,
RtpCodecMime
::
Subtype
::
CN
},
{
"telephone-event"
,
RtpCodecMime
::
Subtype
::
TELEPHONE_EVENT
},
// Feature codecs:
{
"rtx"
,
RtpCodecMime
::
Subtype
::
RTX
},
{
"ulpfec"
,
RtpCodecMime
::
Subtype
::
ULPFEC
},
{
"flexfec"
,
RtpCodecMime
::
Subtype
::
FLEXFEC
},
{
"x-ulpfecuc"
,
RtpCodecMime
::
Subtype
::
X_ULPFECUC
},
{
"red"
,
RtpCodecMime
::
Subtype
::
RED
}
};
std
::
map
<
RtpCodecMime
::
Subtype
,
std
::
string
>
RtpCodecMime
::
subtype2String
=
{
// Audio codecs:
{
RtpCodecMime
::
Subtype
::
OPUS
,
"opus"
},
{
RtpCodecMime
::
Subtype
::
PCMA
,
"PCMA"
},
{
RtpCodecMime
::
Subtype
::
PCMU
,
"PCMU"
},
{
RtpCodecMime
::
Subtype
::
ISAC
,
"ISAC"
},
{
RtpCodecMime
::
Subtype
::
G722
,
"G722"
},
{
RtpCodecMime
::
Subtype
::
ILBC
,
"iLBC"
},
{
RtpCodecMime
::
Subtype
::
SILK
,
"SILK"
},
// Video codecs:
{
RtpCodecMime
::
Subtype
::
VP8
,
"VP8"
},
{
RtpCodecMime
::
Subtype
::
VP9
,
"VP9"
},
{
RtpCodecMime
::
Subtype
::
H264
,
"H264"
},
{
RtpCodecMime
::
Subtype
::
X_H264UC
,
"X-H264UC"
},
{
RtpCodecMime
::
Subtype
::
H265
,
"H265"
},
// Complementary codecs:
{
RtpCodecMime
::
Subtype
::
CN
,
"CN"
},
{
RtpCodecMime
::
Subtype
::
TELEPHONE_EVENT
,
"telephone-event"
},
// Feature codecs:
{
RtpCodecMime
::
Subtype
::
RTX
,
"rtx"
},
{
RtpCodecMime
::
Subtype
::
ULPFEC
,
"ulpfec"
},
{
RtpCodecMime
::
Subtype
::
FLEXFEC
,
"flexfec"
},
{
RtpCodecMime
::
Subtype
::
X_ULPFECUC
,
"x-ulpfecuc"
},
{
RtpCodecMime
::
Subtype
::
RED
,
"red"
}
};
// clang-format on
/* Instance methods. */
void
RtpCodecMime
::
SetName
(
const
std
::
string
&
name
)
{
MS_TRACE
();
auto
slashPos
=
name
.
find
(
'/'
);
if
(
slashPos
==
std
::
string
::
npos
||
slashPos
==
0
||
slashPos
==
name
.
length
()
-
1
)
MS_THROW_ERROR
(
"wrong codec MIME"
);
std
::
string
type
=
name
.
substr
(
0
,
slashPos
);
std
::
string
subtype
=
name
.
substr
(
slashPos
+
1
);
// Force lowcase names.
Utils
::
String
::
ToLowerCase
(
type
);
Utils
::
String
::
ToLowerCase
(
subtype
);
// Set MIME type.
{
auto
it
=
RtpCodecMime
::
string2Type
.
find
(
type
);
if
(
it
!=
RtpCodecMime
::
string2Type
.
end
())
this
->
type
=
it
->
second
;
else
MS_THROW_ERROR
(
"unknown codec MIME type '%s'"
,
type
.
c_str
());
}
// Set MIME subtype.
{
auto
it
=
RtpCodecMime
::
string2Subtype
.
find
(
subtype
);
if
(
it
!=
RtpCodecMime
::
string2Subtype
.
end
())
this
->
subtype
=
it
->
second
;
else
MS_THROW_ERROR
(
"unknown codec MIME subtype '%s'"
,
subtype
.
c_str
());
}
// Set name.
this
->
name
=
type2String
[
this
->
type
]
+
"/"
+
subtype2String
[
this
->
subtype
];
}
}
// namespace RTC
worker/src/RTC/RtpDictionaries/RtpCodecMimeType.cpp
0 → 100644
浏览文件 @
4f5df6fa
#define MS_CLASS "RTC::RtpCodecMimeType"
// #define MS_LOG_DEV
#include "Logger.hpp"
#include "MediaSoupError.hpp"
#include "Utils.hpp"
#include "RTC/RtpDictionaries.hpp"
namespace
RTC
{
/* Class variables. */
// clang-format off
std
::
unordered_map
<
std
::
string
,
RtpCodecMimeType
::
Type
>
RtpCodecMimeType
::
string2Type
=
{
{
"audio"
,
RtpCodecMimeType
::
Type
::
AUDIO
},
{
"video"
,
RtpCodecMimeType
::
Type
::
VIDEO
}
};
std
::
map
<
RtpCodecMimeType
::
Type
,
std
::
string
>
RtpCodecMimeType
::
type2String
=
{
{
RtpCodecMimeType
::
Type
::
AUDIO
,
"audio"
},
{
RtpCodecMimeType
::
Type
::
VIDEO
,
"video"
}
};
std
::
unordered_map
<
std
::
string
,
RtpCodecMimeType
::
Subtype
>
RtpCodecMimeType
::
string2Subtype
=
{
// Audio codecs:
{
"opus"
,
RtpCodecMimeType
::
Subtype
::
OPUS
},
{
"pcma"
,
RtpCodecMimeType
::
Subtype
::
PCMA
},
{
"pcmu"
,
RtpCodecMimeType
::
Subtype
::
PCMU
},
{
"isac"
,
RtpCodecMimeType
::
Subtype
::
ISAC
},
{
"g722"
,
RtpCodecMimeType
::
Subtype
::
G722
},
{
"ilbc"
,
RtpCodecMimeType
::
Subtype
::
ILBC
},
{
"silk"
,
RtpCodecMimeType
::
Subtype
::
SILK
},
// Video codecs:
{
"vp8"
,
RtpCodecMimeType
::
Subtype
::
VP8
},
{
"vp9"
,
RtpCodecMimeType
::
Subtype
::
VP9
},
{
"h264"
,
RtpCodecMimeType
::
Subtype
::
H264
},
{
"x-h264uc"
,
RtpCodecMimeType
::
Subtype
::
X_H264UC
},
{
"h265"
,
RtpCodecMimeType
::
Subtype
::
H265
},
// Complementary codecs:
{
"cn"
,
RtpCodecMimeType
::
Subtype
::
CN
},
{
"telephone-event"
,
RtpCodecMimeType
::
Subtype
::
TELEPHONE_EVENT
},
// Feature codecs:
{
"rtx"
,
RtpCodecMimeType
::
Subtype
::
RTX
},
{
"ulpfec"
,
RtpCodecMimeType
::
Subtype
::
ULPFEC
},
{
"flexfec"
,
RtpCodecMimeType
::
Subtype
::
FLEXFEC
},
{
"x-ulpfecuc"
,
RtpCodecMimeType
::
Subtype
::
X_ULPFECUC
},
{
"red"
,
RtpCodecMimeType
::
Subtype
::
RED
}
};
std
::
map
<
RtpCodecMimeType
::
Subtype
,
std
::
string
>
RtpCodecMimeType
::
subtype2String
=
{
// Audio codecs:
{
RtpCodecMimeType
::
Subtype
::
OPUS
,
"opus"
},
{
RtpCodecMimeType
::
Subtype
::
PCMA
,
"PCMA"
},
{
RtpCodecMimeType
::
Subtype
::
PCMU
,
"PCMU"
},
{
RtpCodecMimeType
::
Subtype
::
ISAC
,
"ISAC"
},
{
RtpCodecMimeType
::
Subtype
::
G722
,
"G722"
},
{
RtpCodecMimeType
::
Subtype
::
ILBC
,
"iLBC"
},
{
RtpCodecMimeType
::
Subtype
::
SILK
,
"SILK"
},
// Video codecs:
{
RtpCodecMimeType
::
Subtype
::
VP8
,
"VP8"
},
{
RtpCodecMimeType
::
Subtype
::
VP9
,
"VP9"
},
{
RtpCodecMimeType
::
Subtype
::
H264
,
"H264"
},
{
RtpCodecMimeType
::
Subtype
::
X_H264UC
,
"X-H264UC"
},
{
RtpCodecMimeType
::
Subtype
::
H265
,
"H265"
},
// Complementary codecs:
{
RtpCodecMimeType
::
Subtype
::
CN
,
"CN"
},
{
RtpCodecMimeType
::
Subtype
::
TELEPHONE_EVENT
,
"telephone-event"
},
// Feature codecs:
{
RtpCodecMimeType
::
Subtype
::
RTX
,
"rtx"
},
{
RtpCodecMimeType
::
Subtype
::
ULPFEC
,
"ulpfec"
},
{
RtpCodecMimeType
::
Subtype
::
FLEXFEC
,
"flexfec"
},
{
RtpCodecMimeType
::
Subtype
::
X_ULPFECUC
,
"x-ulpfecuc"
},
{
RtpCodecMimeType
::
Subtype
::
RED
,
"red"
}
};
// clang-format on
/* Instance methods. */
void
RtpCodecMimeType
::
SetMimeType
(
const
std
::
string
&
mimeType
)
{
MS_TRACE
();
auto
slashPos
=
mimeType
.
find
(
'/'
);
if
(
slashPos
==
std
::
string
::
npos
||
slashPos
==
0
||
slashPos
==
mimeType
.
length
()
-
1
)
{
MS_THROW_ERROR
(
"wrong codec MIME"
);
}
std
::
string
type
=
mimeType
.
substr
(
0
,
slashPos
);
std
::
string
subtype
=
mimeType
.
substr
(
slashPos
+
1
);
// Force lowcase names.
Utils
::
String
::
ToLowerCase
(
type
);
Utils
::
String
::
ToLowerCase
(
subtype
);
// Set MIME type.
{
auto
it
=
RtpCodecMimeType
::
string2Type
.
find
(
type
);
if
(
it
!=
RtpCodecMimeType
::
string2Type
.
end
())
this
->
type
=
it
->
second
;
else
MS_THROW_ERROR
(
"unknown codec MIME type '%s'"
,
type
.
c_str
());
}
// Set MIME subtype.
{
auto
it
=
RtpCodecMimeType
::
string2Subtype
.
find
(
subtype
);
if
(
it
!=
RtpCodecMimeType
::
string2Subtype
.
end
())
this
->
subtype
=
it
->
second
;
else
MS_THROW_ERROR
(
"unknown codec MIME subtype '%s'"
,
subtype
.
c_str
());
}
// Set mimeType and name.
this
->
mimeType
=
type2String
[
this
->
type
]
+
"/"
+
subtype2String
[
this
->
subtype
];
this
->
name
=
subtype
;
}
}
// namespace RTC
worker/src/RTC/RtpDictionaries/RtpCodecParameters.cpp
浏览文件 @
4f5df6fa
...
...
@@ -9,65 +9,46 @@ namespace RTC
{
/* Instance methods. */
RtpCodecParameters
::
RtpCodecParameters
(
Json
::
Value
&
data
,
RTC
::
Scope
scope
)
:
scope
(
scope
)
RtpCodecParameters
::
RtpCodecParameters
(
Json
::
Value
&
data
)
{
MS_TRACE
();
static
const
Json
::
StaticString
JsonStringKind
{
"kind"
};
static
const
Json
::
StaticString
JsonString
Name
{
"nam
e"
};
static
const
Json
::
StaticString
JsonString
MimeType
{
"mimeTyp
e"
};
static
const
Json
::
StaticString
JsonStringPayloadType
{
"payloadType"
};
static
const
Json
::
StaticString
JsonStringClockRate
{
"clockRate"
};
static
const
Json
::
StaticString
JsonStringMaxptime
{
"maxptime"
};
static
const
Json
::
StaticString
JsonStringPtime
{
"ptime"
};
static
const
Json
::
StaticString
JsonStringNumChannels
{
"
numC
hannels"
};
static
const
Json
::
StaticString
JsonStringNumChannels
{
"
c
hannels"
};
static
const
Json
::
StaticString
JsonStringParameters
{
"parameters"
};
static
const
Json
::
StaticString
JsonStringRtcpFeedback
{
"rtcpFeedback"
};
if
(
!
data
.
isObject
())
MS_THROW_ERROR
(
"RtpCodecParameters is not an object"
);
if
(
this
->
scope
==
RTC
::
Scope
::
ROOM_CAPABILITY
||
this
->
scope
==
RTC
::
Scope
::
PEER_CAPABILITY
)
{
// `kind` is mandatory.
if
(
!
data
[
JsonStringKind
].
isString
())
MS_THROW_ERROR
(
"missing RtpCodecParameters.kind"
);
// `kind` is mandatory.
if
(
!
data
[
JsonStringKind
].
isString
())
MS_THROW_ERROR
(
"missing RtpCodecParameters.kind"
);
std
::
string
kind
=
data
[
JsonStringKind
].
asString
();
std
::
string
kind
=
data
[
JsonStringKind
].
asString
();
// NOTE: This may throw.
this
->
kind
=
RTC
::
Media
::
GetKind
(
kind
);
}
// NOTE: This may throw.
this
->
kind
=
RTC
::
Media
::
GetKind
(
kind
);
// `
nam
e` is mandatory.
if
(
!
data
[
JsonString
Nam
e
].
isString
())
MS_THROW_ERROR
(
"missing RtpCodec.
nam
e"
);
// `
mimeTyp
e` is mandatory.
if
(
!
data
[
JsonString
MimeTyp
e
].
isString
())
MS_THROW_ERROR
(
"missing RtpCodec.
mimeTyp
e"
);
std
::
string
name
=
data
[
JsonStringNam
e
].
asString
();
std
::
string
mimeType
=
data
[
JsonStringMimeTyp
e
].
asString
();
// Set MIME field.
// NOTE: This may throw.
this
->
mime
.
Set
Name
(
nam
e
);
this
->
mime
.
Set
MimeType
(
mimeTyp
e
);
if
(
data
[
JsonStringPayloadType
].
isUInt
())
{
this
->
payloadType
=
static_cast
<
uint8_t
>
(
data
[
JsonStringPayloadType
].
asUInt
());
this
->
hasPayloadType
=
true
;
}
if
(
!
data
[
JsonStringPayloadType
].
isUInt
())
MS_THROW_ERROR
(
"missing RtpCodecParameters.payloadType"
);
if
(
this
->
scope
==
RTC
::
Scope
::
PEER_CAPABILITY
)
{
if
(
!
this
->
hasPayloadType
)
MS_THROW_ERROR
(
"missing RtpCodecParameters.payloadType"
);
}
if
(
this
->
scope
==
RTC
::
Scope
::
RECEIVE
)
{
if
(
!
data
[
JsonStringPayloadType
].
isUInt
())
MS_THROW_ERROR
(
"missing RtpCodecParameters.payloadType"
);
this
->
payloadType
=
static_cast
<
uint8_t
>
(
data
[
JsonStringPayloadType
].
asUInt
());
this
->
hasPayloadType
=
true
;
}
this
->
payloadType
=
static_cast
<
uint8_t
>
(
data
[
JsonStringPayloadType
].
asUInt
());
// `clockRate` is mandatory.
if
(
!
data
[
JsonStringClockRate
].
isUInt
())
...
...
@@ -83,9 +64,9 @@ namespace RTC
if
(
data
[
JsonStringPtime
].
isUInt
())
this
->
ptime
=
uint32_t
{
data
[
JsonStringPtime
].
asUInt
()
};
// `
numC
hannels` is optional.
// `
c
hannels` is optional.
if
(
data
[
JsonStringNumChannels
].
isUInt
())
this
->
numC
hannels
=
uint32_t
{
data
[
JsonStringNumChannels
].
asUInt
()
};
this
->
c
hannels
=
uint32_t
{
data
[
JsonStringNumChannels
].
asUInt
()
};
// `parameters` is optional.
if
(
data
[
JsonStringParameters
].
isObject
())
...
...
@@ -114,31 +95,29 @@ namespace RTC
MS_TRACE
();
static
const
Json
::
StaticString
JsonStringKind
{
"kind"
};
static
const
Json
::
StaticString
JsonStringMimeType
{
"mimeType"
};
static
const
Json
::
StaticString
JsonStringName
{
"name"
};
static
const
Json
::
StaticString
JsonStringPayloadType
{
"payloadType"
};
static
const
Json
::
StaticString
JsonStringClockRate
{
"clockRate"
};
static
const
Json
::
StaticString
JsonStringMaxptime
{
"maxptime"
};
static
const
Json
::
StaticString
JsonStringPtime
{
"ptime"
};
static
const
Json
::
StaticString
JsonStringNumChannels
{
"
numC
hannels"
};
static
const
Json
::
StaticString
JsonStringNumChannels
{
"
c
hannels"
};
static
const
Json
::
StaticString
JsonStringParameters
{
"parameters"
};
static
const
Json
::
StaticString
JsonStringRtcpFeedback
{
"rtcpFeedback"
};
Json
::
Value
json
(
Json
::
objectValue
);
if
(
this
->
scope
==
RTC
::
Scope
::
ROOM_CAPABILITY
||
this
->
scope
==
RTC
::
Scope
::
PEER_CAPABILITY
)
{
// Add `kind`.
json
[
JsonStringKind
]
=
RTC
::
Media
::
GetJsonString
(
this
->
kind
);
}
// Add `kind`.
json
[
JsonStringKind
]
=
RTC
::
Media
::
GetJsonString
(
this
->
kind
);
// Add `mimeType`.
json
[
JsonStringMimeType
]
=
this
->
mime
.
ToString
();
// Add `name`.
json
[
JsonStringName
]
=
this
->
mime
.
GetName
();
if
(
this
->
hasPayloadType
)
{
// Add `payloadType`.
json
[
JsonStringPayloadType
]
=
Json
::
UInt
{
this
->
payloadType
};
}
// Add `payloadType`.
json
[
JsonStringPayloadType
]
=
Json
::
UInt
{
this
->
payloadType
};
// Add `clockRate`.
json
[
JsonStringClockRate
]
=
Json
::
UInt
{
this
->
clockRate
};
...
...
@@ -151,9 +130,9 @@ namespace RTC
if
(
this
->
ptime
!=
0u
)
json
[
JsonStringPtime
]
=
Json
::
UInt
{
this
->
ptime
};
// Add `
numC
hannels`.
if
(
this
->
numC
hannels
>
1
)
json
[
JsonStringNumChannels
]
=
Json
::
UInt
{
this
->
numC
hannels
};
// Add `
c
hannels`.
if
(
this
->
c
hannels
>
1
)
json
[
JsonStringNumChannels
]
=
Json
::
UInt
{
this
->
c
hannels
};
// Add `parameters`.
json
[
JsonStringParameters
]
=
this
->
parameters
.
ToJson
();
...
...
@@ -195,7 +174,7 @@ namespace RTC
case
RTC
:
:
Media
::
Kind
::
AUDIO
:
{
// Num channels must match.
if
(
this
->
numChannels
!=
codec
.
numC
hannels
)
if
(
this
->
channels
!=
codec
.
c
hannels
)
return
false
;
break
;
...
...
@@ -207,7 +186,7 @@ namespace RTC
// Per MIME checks.
switch
(
this
->
mime
.
subtype
)
{
case
RTC
:
:
RtpCodecMime
::
Subtype
::
H264
:
case
RTC
:
:
RtpCodecMime
Type
::
Subtype
::
H264
:
{
int32_t
packetizationMode
=
this
->
parameters
.
GetInteger
(
jsonStringPacketizationMode
);
int32_t
givenPacketizationMode
=
codec
.
parameters
.
GetInteger
(
jsonStringPacketizationMode
);
...
...
@@ -257,7 +236,7 @@ namespace RTC
// Check per MIME parameters and set default values.
switch
(
this
->
mime
.
subtype
)
{
case
RTC
:
:
RtpCodecMime
::
Subtype
::
RTX
:
case
RTC
:
:
RtpCodecMime
Type
::
Subtype
::
RTX
:
{
// A RTX codec must have 'apt' parameter.
if
(
!
this
->
parameters
.
HasInteger
(
jsonStringApt
))
...
...
@@ -266,16 +245,16 @@ namespace RTC
break
;
}
case
RTC
:
:
RtpCodecMime
::
Subtype
::
OPUS
:
case
RTC
:
:
RtpCodecMime
Type
::
Subtype
::
OPUS
:
{
// Opus default
numC
hannels is 2.
if
(
this
->
numC
hannels
<
2
)
this
->
numC
hannels
=
2
;
// Opus default
c
hannels is 2.
if
(
this
->
c
hannels
<
2
)
this
->
c
hannels
=
2
;
break
;
}
case
RTC
:
:
RtpCodecMime
::
Subtype
::
H264
:
case
RTC
:
:
RtpCodecMime
Type
::
Subtype
::
H264
:
{
// H264 default packetizationMode is 0.
if
(
!
this
->
parameters
.
HasInteger
(
jsonStringPacketizationMode
))
...
...
worker/src/RTC/RtpDictionaries/RtpParameters.cpp
浏览文件 @
4f5df6fa
...
...
@@ -37,7 +37,7 @@ namespace RTC
for
(
auto
&
jsonCodec
:
jsonCodecs
)
{
RTC
::
RtpCodecParameters
codec
(
jsonCodec
,
RTC
::
Scope
::
RECEIVE
);
RTC
::
RtpCodecParameters
codec
(
jsonCodec
);
// Append to the codecs vector.
this
->
codecs
.
push_back
(
codec
);
...
...
@@ -184,7 +184,7 @@ namespace RTC
MS_WARN_DEV
(
"no matching peer codec capability found [payloadType:%"
PRIu8
", mime:%s]"
,
codec
.
payloadType
,
codec
.
mime
.
GetName
().
c_str
());
codec
.
mime
.
ToString
().
c_str
());
removedCodecPayloadTypes
.
push_back
(
codec
.
payloadType
);
it
=
this
->
codecs
.
erase
(
it
);
...
...
@@ -317,7 +317,7 @@ namespace RTC
switch
(
codec
.
mime
.
subtype
)
{
// A RTX codec must have 'apt' parameter pointing to a non RTX codec.
case
RTC
:
:
RtpCodecMime
::
Subtype
::
RTX
:
case
RTC
:
:
RtpCodecMime
Type
::
Subtype
::
RTX
:
{
// NOTE: RtpCodecParameters already asserted that there is 'apt' parameter.
int32_t
apt
=
codec
.
parameters
.
GetInteger
(
jsonStringApt
);
...
...
@@ -329,11 +329,11 @@ namespace RTC
if
(
static_cast
<
int32_t
>
(
codec
.
payloadType
)
==
apt
)
{
if
(
codec
.
mime
.
subtype
==
RTC
::
RtpCodecMime
::
Subtype
::
RTX
)
if
(
codec
.
mime
.
subtype
==
RTC
::
RtpCodecMime
Type
::
Subtype
::
RTX
)
MS_THROW_ERROR
(
"apt in RTX codec points to a RTX codec"
);
else
if
(
codec
.
mime
.
subtype
==
RTC
::
RtpCodecMime
::
Subtype
::
ULPFEC
)
else
if
(
codec
.
mime
.
subtype
==
RTC
::
RtpCodecMime
Type
::
Subtype
::
ULPFEC
)
MS_THROW_ERROR
(
"apt in RTX codec points to a ULPFEC codec"
);
else
if
(
codec
.
mime
.
subtype
==
RTC
::
RtpCodecMime
::
Subtype
::
FLEXFEC
)
else
if
(
codec
.
mime
.
subtype
==
RTC
::
RtpCodecMime
Type
::
Subtype
::
FLEXFEC
)
MS_THROW_ERROR
(
"apt in RTX codec points to a FLEXFEC codec"
);
else
break
;
...
...
worker/src/RTC/RtpStream.cpp
浏览文件 @
4f5df6fa
...
...
@@ -187,7 +187,7 @@ namespace RTC
json
[
JsonStringSsrc
]
=
Json
::
UInt
{
this
->
ssrc
};
json
[
JsonStringPayloadType
]
=
Json
::
UInt
{
this
->
payloadType
};
json
[
JsonStringMime
]
=
this
->
mime
.
name
;
json
[
JsonStringMime
]
=
this
->
mime
.
ToString
()
;
json
[
JsonStringClockRate
]
=
Json
::
UInt
{
this
->
clockRate
};
json
[
JsonStringUseNack
]
=
this
->
useNack
;
json
[
JsonStringUsePli
]
=
this
->
usePli
;
...
...
worker/src/RTC/RtpStreamRecv.cpp
浏览文件 @
4f5df6fa
...
...
@@ -226,7 +226,7 @@ namespace RTC
this
->
nackGenerator
.
reset
(
new
RTC
::
NackGenerator
(
this
));
// Request a full frame so dropped video packets don't cause lag.
if
(
this
->
params
.
mime
.
type
==
RTC
::
RtpCodecMime
::
Type
::
VIDEO
)
if
(
this
->
params
.
mime
.
type
==
RTC
::
RtpCodecMime
Type
::
Type
::
VIDEO
)
{
MS_DEBUG_TAG
(
rtx
,
"stream initialized, triggering PLI [ssrc:%"
PRIu32
"]"
,
this
->
params
.
ssrc
);
...
...
worker/src/main.cpp
浏览文件 @
4f5df6fa
...
...
@@ -118,7 +118,6 @@ void init()
RTC
::
TcpServer
::
ClassInit
();
RTC
::
DtlsTransport
::
ClassInit
();
RTC
::
SrtpSession
::
ClassInit
();
RTC
::
Room
::
ClassInit
();
}
void
ignoreSignals
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论