Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
94905469
Unverified
提交
94905469
authored
6月 26, 2024
作者:
dhilipsiva
提交者:
GitHub
6月 26, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: make `hex_as_bytes` DRY (#1409)
上级
5c4b6ce1
隐藏空白字符变更
内嵌
并排
正在显示
16 个修改的文件
包含
95 行增加
和
78 行删除
+95
-78
rust-toolchain.toml
rust-toolchain.toml
+1
-1
data_structures.rs
rust/src/data_structures.rs
+9
-16
ortc.rs
rust/src/ortc.rs
+3
-3
tests.rs
rust/src/ortc/tests.rs
+14
-14
router.rs
rust/src/router.rs
+6
-2
producer.rs
rust/src/router/producer.rs
+1
-1
rtp_parameters.rs
rust/src/rtp_parameters.rs
+0
-1
scalability_modes.rs
rust/src/scalability_modes.rs
+3
-3
common.rs
rust/src/worker/common.rs
+1
-3
channel_read_fn.rs
rust/src/worker/utils/channel_read_fn.rs
+13
-4
channel_write_fn.rs
rust/src/worker/utils/channel_write_fn.rs
+14
-3
consumer.rs
rust/tests/integration/consumer.rs
+16
-7
webrtc_server.rs
rust/tests/integration/webrtc_server.rs
+5
-15
webrtc_transport.rs
rust/tests/integration/webrtc_transport.rs
+3
-3
build.rs
worker/build.rs
+0
-1
lib.rs
worker/src/lib.rs
+6
-1
没有找到文件。
rust-toolchain.toml
浏览文件 @
94905469
[toolchain]
channel
=
"1.7
2
.0"
channel
=
"1.7
9
.0"
components
=
[
"rustfmt"
,
"clippy"
]
rust/src/data_structures.rs
浏览文件 @
94905469
...
...
@@ -528,12 +528,15 @@ pub enum DtlsFingerprint {
},
}
fn
hex_as_bytes
(
input
:
&
str
,
output
:
&
mut
[
u8
])
{
fn
hex_as_bytes
<
const
N
:
usize
>
(
input
:
&
str
)
->
[
u8
;
N
]
{
let
mut
output
=
[
0
_u8
;
N
];
for
(
i
,
o
)
in
input
.split
(
':'
)
.zip
(
&
mut
output
.iter_mut
())
{
*
o
=
u8
::
from_str_radix
(
i
,
16
)
.unwrap_or_else
(|
error
|
{
panic!
(
"Failed to parse value {i} as series of hex bytes: {error}"
)
});
}
output
}
impl
DtlsFingerprint
{
...
...
@@ -565,45 +568,35 @@ impl DtlsFingerprint {
pub
(
crate
)
fn
from_fbs
(
fingerprint
:
&
web_rtc_transport
::
Fingerprint
)
->
DtlsFingerprint
{
match
fingerprint
.algorithm
{
web_rtc_transport
::
FingerprintAlgorithm
::
Sha1
=>
{
let
mut
value_result
=
[
0
_u8
;
20
];
hex_as_bytes
(
fingerprint
.value
.as_str
(),
&
mut
value_result
);
let
value_result
=
hex_as_bytes
::
<
20
>
(
fingerprint
.value
.as_str
());
DtlsFingerprint
::
Sha1
{
value
:
value_result
,
}
}
web_rtc_transport
::
FingerprintAlgorithm
::
Sha224
=>
{
let
mut
value_result
=
[
0
_u8
;
28
];
hex_as_bytes
(
fingerprint
.value
.as_str
(),
&
mut
value_result
);
let
value_result
=
hex_as_bytes
::
<
28
>
(
fingerprint
.value
.as_str
());
DtlsFingerprint
::
Sha224
{
value
:
value_result
,
}
}
web_rtc_transport
::
FingerprintAlgorithm
::
Sha256
=>
{
let
mut
value_result
=
[
0
_u8
;
32
];
hex_as_bytes
(
fingerprint
.value
.as_str
(),
&
mut
value_result
);
let
value_result
=
hex_as_bytes
::
<
32
>
(
fingerprint
.value
.as_str
());
DtlsFingerprint
::
Sha256
{
value
:
value_result
,
}
}
web_rtc_transport
::
FingerprintAlgorithm
::
Sha384
=>
{
let
mut
value_result
=
[
0
_u8
;
48
];
hex_as_bytes
(
fingerprint
.value
.as_str
(),
&
mut
value_result
);
let
value_result
=
hex_as_bytes
::
<
48
>
(
fingerprint
.value
.as_str
());
DtlsFingerprint
::
Sha384
{
value
:
value_result
,
}
}
web_rtc_transport
::
FingerprintAlgorithm
::
Sha512
=>
{
let
mut
value_result
=
[
0
_u8
;
64
];
hex_as_bytes
(
fingerprint
.value
.as_str
(),
&
mut
value_result
);
let
value_result
=
hex_as_bytes
::
<
64
>
(
fingerprint
.value
.as_str
());
DtlsFingerprint
::
Sha512
{
value
:
value_result
,
...
...
rust/src/ortc.rs
浏览文件 @
94905469
...
...
@@ -681,7 +681,7 @@ pub(crate) fn can_consume(
if
caps
.codecs
.iter
()
.any
(|
cap_codec
|
match_codecs
(
cap_codec
.
deref
()
.
into
(),
codec
.into
(),
true
)
.is_ok
())
.any
(|
cap_codec
|
match_codecs
(
cap_codec
.into
(),
codec
.into
(),
true
)
.is_ok
())
{
matching_codecs
.push
(
codec
);
}
...
...
@@ -689,7 +689,7 @@ pub(crate) fn can_consume(
// Ensure there is at least one media codec.
Ok
(
matching_codecs
.
get
(
0
)
.
first
(
)
.map
(|
codec
|
!
codec
.is_rtx
())
.unwrap_or_default
())
}
...
...
@@ -841,7 +841,7 @@ pub(crate) fn get_consumer_rtp_parameters(
// (assume all encodings have the same value).
let
mut
scalability_mode
=
consumable_rtp_parameters
.encodings
.
get
(
0
)
.
first
(
)
.map
(|
encoding
|
encoding
.scalability_mode
.clone
())
.unwrap_or_default
();
...
...
rust/src/ortc/tests.rs
浏览文件 @
94905469
...
...
@@ -255,8 +255,8 @@ fn get_producer_rtp_parameters_mapping_get_consumable_rtp_parameters_get_consume
]
);
assert_eq!
(
rtp_mapping
.encodings
.
get
(
0
)
.unwrap
()
.ssrc
,
Some
(
11111111
));
assert_eq!
(
rtp_mapping
.encodings
.
get
(
0
)
.unwrap
()
.rid
,
None
);
assert_eq!
(
rtp_mapping
.encodings
.
first
(
)
.unwrap
()
.ssrc
,
Some
(
11111111
));
assert_eq!
(
rtp_mapping
.encodings
.
first
(
)
.unwrap
()
.rid
,
None
);
assert_eq!
(
rtp_mapping
.encodings
.get
(
1
)
.unwrap
()
.ssrc
,
Some
(
21111111
));
assert_eq!
(
rtp_mapping
.encodings
.get
(
1
)
.unwrap
()
.rid
,
None
);
assert_eq!
(
rtp_mapping
.encodings
.get
(
2
)
.unwrap
()
.ssrc
,
None
);
...
...
@@ -303,13 +303,13 @@ fn get_producer_rtp_parameters_mapping_get_consumable_rtp_parameters_get_consume
);
assert_eq!
(
consumable_rtp_parameters
.encodings
.
get
(
0
)
.unwrap
()
.ssrc
,
Some
(
rtp_mapping
.encodings
.
get
(
0
)
.unwrap
()
.mapped_ssrc
),
consumable_rtp_parameters
.encodings
.
first
(
)
.unwrap
()
.ssrc
,
Some
(
rtp_mapping
.encodings
.
first
(
)
.unwrap
()
.mapped_ssrc
),
);
assert_eq!
(
consumable_rtp_parameters
.encodings
.
get
(
0
)
.
first
(
)
.unwrap
()
.max_bitrate
,
Some
(
111111
),
...
...
@@ -317,7 +317,7 @@ fn get_producer_rtp_parameters_mapping_get_consumable_rtp_parameters_get_consume
assert_eq!
(
consumable_rtp_parameters
.encodings
.
get
(
0
)
.
first
(
)
.unwrap
()
.scalability_mode
,
ScalabilityMode
::
L1T3
,
...
...
@@ -489,20 +489,20 @@ fn get_producer_rtp_parameters_mapping_get_consumable_rtp_parameters_get_consume
assert_eq!
(
consumer_rtp_parameters
.encodings
.len
(),
1
);
assert
!
(
consumer_rtp_parameters
.encodings
.
get
(
0
)
.
first
(
)
.unwrap
()
.ssrc
.is_some
());
assert
!
(
consumer_rtp_parameters
.encodings
.
get
(
0
)
.
first
(
)
.unwrap
()
.rtx
.is_some
());
assert_eq!
(
consumer_rtp_parameters
.encodings
.
get
(
0
)
.
first
(
)
.unwrap
()
.scalability_mode
,
ScalabilityMode
::
L3T3
,
...
...
@@ -510,7 +510,7 @@ fn get_producer_rtp_parameters_mapping_get_consumable_rtp_parameters_get_consume
assert_eq!
(
consumer_rtp_parameters
.encodings
.
get
(
0
)
.
first
(
)
.unwrap
()
.max_bitrate
,
Some
(
333333
),
...
...
@@ -566,26 +566,26 @@ fn get_producer_rtp_parameters_mapping_get_consumable_rtp_parameters_get_consume
assert_eq!
(
pipe_consumer_rtp_parameters
.encodings
.len
(),
3
);
assert
!
(
pipe_consumer_rtp_parameters
.encodings
.
get
(
0
)
.
first
(
)
.unwrap
()
.ssrc
.is_some
());
assert
!
(
pipe_consumer_rtp_parameters
.encodings
.
get
(
0
)
.
first
(
)
.unwrap
()
.rtx
.is_none
());
assert
!
(
pipe_consumer_rtp_parameters
.encodings
.
get
(
0
)
.
first
(
)
.unwrap
()
.max_bitrate
.is_some
());
assert_eq!
(
pipe_consumer_rtp_parameters
.encodings
.
get
(
0
)
.
first
(
)
.unwrap
()
.scalability_mode
,
ScalabilityMode
::
L1T3
,
...
...
rust/src/router.rs
浏览文件 @
94905469
...
...
@@ -1303,8 +1303,12 @@ impl Router {
// We've created `DataConsumer` with SCTP above, so this should never panic
pipe_data_consumer
.sctp_stream_parameters
()
.unwrap
(),
);
producer_options
.label
=
pipe_data_consumer
.label
()
.clone
();
producer_options
.protocol
=
pipe_data_consumer
.protocol
()
.clone
();
producer_options
.label
.clone_from
(
pipe_data_consumer
.label
());
producer_options
.protocol
.clone_from
(
pipe_data_consumer
.protocol
());
producer_options
.app_data
=
data_producer
.app_data
()
.clone
();
producer_options
...
...
rust/src/router/producer.rs
浏览文件 @
94905469
...
...
@@ -759,7 +759,7 @@ impl Producer {
match
Notification
::
from_fbs
(
notification
)
{
Ok
(
notification
)
=>
match
notification
{
Notification
::
Score
(
scores
)
=>
{
*
score
.lock
()
=
scores
.clone
(
);
score
.lock
()
.clone_from
(
&
scores
);
handlers
.score
.call
(|
callback
|
{
callback
(
&
scores
);
});
...
...
rust/src/rtp_parameters.rs
浏览文件 @
94905469
...
...
@@ -919,7 +919,6 @@ impl RtpParameters {
})
}
#[allow(dead_code)]
pub
(
crate
)
fn
into_fbs
(
self
)
->
rtp_parameters
::
RtpParameters
{
rtp_parameters
::
RtpParameters
{
mid
:
self
.mid
,
...
...
rust/src/scalability_modes.rs
浏览文件 @
94905469
...
...
@@ -184,9 +184,9 @@ impl FromStr for ScalabilityMode {
}
}
impl
ToString
for
ScalabilityMode
{
fn
to_string
(
&
self
)
->
String
{
self
.as_str
()
.to_string
(
)
impl
std
::
fmt
::
Display
for
ScalabilityMode
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
write!
(
f
,
"{}"
,
self
.as_str
()
)
}
}
...
...
rust/src/worker/common.rs
浏览文件 @
94905469
...
...
@@ -35,9 +35,7 @@ impl<F: Sized + Send + Sync + 'static> EventHandlers<F> {
let
index
;
{
let
mut
event_handlers
=
self
.handlers
.lock
();
let
list
=
event_handlers
.entry
(
target_id
.clone
())
.or_insert_with
(
EventHandlersList
::
default
);
let
list
=
event_handlers
.entry
(
target_id
.clone
())
.or_default
();
index
=
list
.index
;
list
.index
+=
1
;
list
.callbacks
.insert
(
index
,
callback
);
...
...
rust/src/worker/utils/channel_read_fn.rs
浏览文件 @
94905469
...
...
@@ -8,9 +8,18 @@ unsafe extern "C" fn free_vec(message: *mut u8, message_len: u32, message_capaci
Vec
::
from_raw_parts
(
message
,
message_len
as
usize
,
message_capacity
);
}
pub
(
super
)
struct
ChannelReadCallback
(
Box
<
dyn
(
FnMut
(
UvAsyncT
)
->
Option
<
Vec
<
u8
>>
)
+
Send
+
'static
>
,
);
pub
(
super
)
struct
ChannelReadCallback
{
// Silence clippy warnings
_callback
:
Box
<
dyn
(
FnMut
(
UvAsyncT
)
->
Option
<
Vec
<
u8
>>
)
+
Send
+
'static
>
,
}
impl
ChannelReadCallback
{
pub
(
super
)
fn
new
(
_callback
:
Box
<
dyn
(
FnMut
(
UvAsyncT
)
->
Option
<
Vec
<
u8
>>
)
+
Send
+
'static
>
,
)
->
Self
{
Self
{
_callback
}
}
}
pub
(
crate
)
struct
PreparedChannelRead
{
channel_read_fn
:
ChannelReadFn
,
...
...
@@ -71,6 +80,6 @@ where
PreparedChannelRead
{
channel_read_fn
:
wrapper
::
<
F
>
,
channel_read_ctx
:
ChannelReadCtx
(
read_callback
.as_ref
()
as
*
const
F
as
*
const
c_void
),
write_callback
:
ChannelReadCallback
(
read_callback
),
write_callback
:
ChannelReadCallback
::
new
(
read_callback
),
}
}
rust/src/worker/utils/channel_write_fn.rs
浏览文件 @
94905469
...
...
@@ -2,8 +2,19 @@ pub(super) use mediasoup_sys::{ChannelWriteCtx, ChannelWriteFn};
use
std
::
os
::
raw
::
c_void
;
use
std
::
slice
;
#[allow(clippy
::
type_complexity)]
pub
(
super
)
struct
ChannelReadCallback
(
Box
<
dyn
FnMut
(
&
[
u8
])
+
Send
+
'static
>
);
/// TypeAlias to silience clippy::type_complexity warnings
type
CallbackType
=
Box
<
dyn
FnMut
(
&
[
u8
])
+
Send
+
'static
>
;
pub
(
super
)
struct
ChannelReadCallback
{
// Silence clippy warnings
_callback
:
CallbackType
,
}
impl
ChannelReadCallback
{
pub
(
super
)
fn
new
(
_callback
:
CallbackType
)
->
Self
{
Self
{
_callback
}
}
}
pub
(
crate
)
struct
PreparedChannelWrite
{
channel_write_fn
:
ChannelWriteFn
,
...
...
@@ -54,6 +65,6 @@ where
PreparedChannelWrite
{
channel_write_fn
:
wrapper
::
<
F
>
,
channel_write_ctx
:
ChannelWriteCtx
(
read_callback
.as_ref
()
as
*
const
F
as
*
const
c_void
),
read_callback
:
ChannelReadCallback
(
read_callback
),
read_callback
:
ChannelReadCallback
::
new
(
read_callback
),
}
}
rust/tests/integration/consumer.rs
浏览文件 @
94905469
...
...
@@ -291,7 +291,16 @@ fn consumer_device_capabilities() -> RtpCapabilities {
}
// Keeps executor threads running until dropped
struct
ExecutorGuard
(
Vec
<
async_oneshot
::
Sender
<
()
>>
);
struct
ExecutorGuard
{
// Silence clippy warnings
_senders
:
Vec
<
async_oneshot
::
Sender
<
()
>>
,
}
impl
ExecutorGuard
{
fn
new
(
_senders
:
Vec
<
async_oneshot
::
Sender
<
()
>>
)
->
Self
{
Self
{
_senders
}
}
}
fn
create_executor
()
->
(
ExecutorGuard
,
Arc
<
Executor
<
'static
>>
)
{
let
executor
=
Arc
::
new
(
Executor
::
new
());
...
...
@@ -318,7 +327,7 @@ fn create_executor() -> (ExecutorGuard, Arc<Executor<'static>>) {
})
.collect
();
(
ExecutorGuard
(
senders
),
executor
)
(
ExecutorGuard
::
new
(
senders
),
executor
)
}
async
fn
init
()
->
(
...
...
@@ -977,7 +986,7 @@ fn dump_succeeds() {
ssrc
:
audio_consumer
.rtp_parameters
()
.encodings
.
get
(
0
)
.
first
(
)
.unwrap
()
.ssrc
,
rid
:
None
,
...
...
@@ -1086,13 +1095,13 @@ fn dump_succeeds() {
ssrc
:
video_consumer
.rtp_parameters
()
.encodings
.
get
(
0
)
.
first
(
)
.unwrap
()
.ssrc
,
rtx
:
video_consumer
.rtp_parameters
()
.encodings
.
get
(
0
)
.
first
(
)
.unwrap
()
.rtx
,
dtx
:
None
,
...
...
@@ -1165,7 +1174,7 @@ fn get_stats_succeeds() {
audio_consumer
.rtp_parameters
()
.encodings
.
get
(
0
)
.
first
(
)
.unwrap
()
.ssrc
.unwrap
()
...
...
@@ -1214,7 +1223,7 @@ fn get_stats_succeeds() {
video_consumer
.rtp_parameters
()
.encodings
.
get
(
0
)
.
first
(
)
.unwrap
()
.ssrc
.unwrap
()
...
...
rust/tests/integration/webrtc_server.rs
浏览文件 @
94905469
...
...
@@ -10,6 +10,11 @@ use std::net::{IpAddr, Ipv4Addr};
use
std
::
sync
::
atomic
::{
AtomicUsize
,
Ordering
};
use
std
::
sync
::
Arc
;
#[derive(Debug,
PartialEq)]
struct
CustomAppData
{
foo
:
u32
,
}
async
fn
init
()
->
(
Worker
,
Worker
)
{
{
let
mut
builder
=
env_logger
::
builder
();
...
...
@@ -52,11 +57,6 @@ fn create_webrtc_server_succeeds() {
})
.detach
();
#[derive(Debug,
PartialEq)]
struct
CustomAppData
{
foo
:
u32
,
}
let
webrtc_server
=
worker1
.create_webrtc_server
({
let
listen_infos
=
WebRtcServerListenInfos
::
new
(
ListenInfo
{
...
...
@@ -150,11 +150,6 @@ fn create_webrtc_server_without_specifying_port_succeeds() {
})
.detach
();
#[derive(Debug,
PartialEq)]
struct
CustomAppData
{
foo
:
u32
,
}
let
webrtc_server
=
worker1
.create_webrtc_server
({
let
listen_infos
=
WebRtcServerListenInfos
::
new
(
ListenInfo
{
...
...
@@ -233,11 +228,6 @@ fn unavailable_infos_fails() {
})
.detach
();
#[derive(Debug,
PartialEq)]
struct
CustomAppData
{
foo
:
u32
,
}
// Using an unavailable listen IP.
{
let
create_result
=
worker1
...
...
rust/tests/integration/webrtc_transport.rs
浏览文件 @
94905469
...
...
@@ -280,7 +280,7 @@ fn create_with_fixed_port_succeeds() {
.await
.expect
(
"Failed to create WebRTC transport"
);
assert_eq!
(
transport
.ice_candidates
()
.
get
(
0
)
.unwrap
()
.port
,
port
);
assert_eq!
(
transport
.ice_candidates
()
.
first
(
)
.unwrap
()
.port
,
port
);
});
}
...
...
@@ -306,7 +306,7 @@ fn create_with_port_range_succeeds() {
.await
.expect
(
"Failed to create WebRTC transport"
);
let
port1
=
transport1
.ice_candidates
()
.
get
(
0
)
.unwrap
()
.port
;
let
port1
=
transport1
.ice_candidates
()
.
first
(
)
.unwrap
()
.port
;
assert
!
(
port1
>=
*
port_range
.start
()
&&
port1
<=
*
port_range
.end
());
let
transport2
=
router
...
...
@@ -325,7 +325,7 @@ fn create_with_port_range_succeeds() {
.await
.expect
(
"Failed to create WebRTC transport"
);
let
port2
=
transport2
.ice_candidates
()
.
get
(
0
)
.unwrap
()
.port
;
let
port2
=
transport2
.ice_candidates
()
.
first
(
)
.unwrap
()
.port
;
assert
!
(
port2
>=
*
port_range
.start
()
&&
port2
<=
*
port_range
.end
());
assert
!
(
matches!
(
...
...
worker/build.rs
浏览文件 @
94905469
...
...
@@ -39,7 +39,6 @@ fn main() {
.expect
(
"Failed to generate Rust code from flatbuffers"
),
)
.expect
(
"Failed to write generated Rust flatbuffers into fbs.rs"
);
if
env
::
var
(
"DOCS_RS"
)
.is_ok
()
{
// Skip everything when building docs on docs.rs
return
;
...
...
worker/src/lib.rs
浏览文件 @
94905469
use
std
::
os
::
raw
::{
c_char
,
c_int
,
c_void
};
include!
(
concat!
(
env!
(
"OUT_DIR"
),
"/fbs.rs"
));
pub
use
planus_codegen
::
*
;
mod
planus_codegen
{
#
!
[
allow
(
clippy
::
all
)]
include!
(
concat!
(
env!
(
"OUT_DIR"
),
"/fbs.rs"
));
}
#[repr(transparent)]
#[derive(Copy,
Clone)]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论