Unverified 提交 8287299f authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

SimulcastConsumer::GetDesiredBitrate(): Choose the highest bitrate among all…

SimulcastConsumer::GetDesiredBitrate(): Choose the highest bitrate among all Producer streams (#992)
上级 b0cd7a99
......@@ -14,9 +14,6 @@ jobs:
- ubuntu-22.04
- macos-12
- windows-2022
rust:
- stable
# - nightly
runs-on: ${{ matrix.os }}
......@@ -24,20 +21,13 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt, clippy
- name: Configure cache
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ matrix.os }}-cargo-${{ matrix.rust }}-${{ hashFiles('**/Cargo.toml') }}
key: ${{ matrix.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
- name: cargo fmt
uses: actions-rs/cargo@v1
......
差异被折叠。
[toolchain]
channel = "1.67.0"
components = ["rustfmt", "clippy"]
......@@ -172,11 +172,11 @@ impl EchoConnection {
settings
})
.await
.map_err(|error| format!("Failed to create worker: {}", error))?;
.map_err(|error| format!("Failed to create worker: {error}"))?;
let router = worker
.create_router(RouterOptions::new(media_codecs()))
.await
.map_err(|error| format!("Failed to create router: {}", error))?;
.map_err(|error| format!("Failed to create router: {error}"))?;
// We know that for echo example we'll need 2 transports, so we can create both right away.
// This may not be the case for real-world applications or you may create this at a
......@@ -188,12 +188,12 @@ impl EchoConnection {
let producer_transport = router
.create_webrtc_transport(transport_options.clone())
.await
.map_err(|error| format!("Failed to create producer transport: {}", error))?;
.map_err(|error| format!("Failed to create producer transport: {error}"))?;
let consumer_transport = router
.create_webrtc_transport(transport_options)
.await
.map_err(|error| format!("Failed to create consumer transport: {}", error))?;
.map_err(|error| format!("Failed to create consumer transport: {error}"))?;
Ok(Self {
client_rtp_capabilities: None,
......@@ -259,11 +259,11 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for EchoConnection {
ctx.address().do_send(message);
}
Err(error) => {
eprintln!("Failed to parse client message: {}\n{}", error, text);
eprintln!("Failed to parse client message: {error}\n{text}");
}
},
Ok(ws::Message::Binary(bin)) => {
eprintln!("Unexpected binary message: {:?}", bin);
eprintln!("Unexpected binary message: {bin:?}");
}
Ok(ws::Message::Close(reason)) => {
ctx.close(reason);
......@@ -300,7 +300,7 @@ impl Handler<ClientMessage> for EchoConnection {
println!("Producer transport connected");
}
Err(error) => {
eprintln!("Failed to connect producer transport: {}", error);
eprintln!("Failed to connect producer transport: {error}");
address.do_send(InternalMessage::Stop);
}
}
......@@ -325,10 +325,10 @@ impl Handler<ClientMessage> for EchoConnection {
// Producer is stored in a hashmap since if we don't do it, it will get
// destroyed as soon as its instance goes out out scope
address.do_send(InternalMessage::SaveProducer(producer));
println!("{:?} producer created: {}", kind, id);
println!("{kind:?} producer created: {id}");
}
Err(error) => {
eprintln!("Failed to create {:?} producer: {}", kind, error);
eprintln!("Failed to create {kind:?} producer: {error}");
address.do_send(InternalMessage::Stop);
}
}
......@@ -348,7 +348,7 @@ impl Handler<ClientMessage> for EchoConnection {
println!("Consumer transport connected");
}
Err(error) => {
eprintln!("Failed to connect consumer transport: {}", error);
eprintln!("Failed to connect consumer transport: {error}");
address.do_send(InternalMessage::Stop);
}
}
......@@ -384,10 +384,10 @@ impl Handler<ClientMessage> for EchoConnection {
// Consumer is stored in a hashmap since if we don't do it, it will get
// destroyed as soon as its instance goes out out scope
address.do_send(InternalMessage::SaveConsumer(consumer));
println!("{:?} consumer created: {}", kind, id);
println!("{kind:?} consumer created: {id}");
}
Err(error) => {
eprintln!("Failed to create consumer: {}", error);
eprintln!("Failed to create consumer: {error}");
address.do_send(InternalMessage::Stop);
}
}
......@@ -463,7 +463,7 @@ async fn ws_index(
match EchoConnection::new(&worker_manager).await {
Ok(echo_server) => ws::start(echo_server, &request, stream),
Err(error) => {
eprintln!("{}", error);
eprintln!("{error}");
Ok(HttpResponse::InternalServerError().finish())
}
......
......@@ -136,11 +136,11 @@ impl EchoConnection {
settings
})
.await
.map_err(|error| format!("Failed to create worker: {}", error))?;
.map_err(|error| format!("Failed to create worker: {error}"))?;
let router = worker
.create_router(RouterOptions::new(media_codecs()))
.await
.map_err(|error| format!("Failed to create router: {}", error))?;
.map_err(|error| format!("Failed to create router: {error}"))?;
// For simplicity we will create plain transport for audio producer right away
let plain_transport = router
......@@ -156,7 +156,7 @@ impl EchoConnection {
options
})
.await
.map_err(|error| format!("Failed to create plain transport: {}", error))?;
.map_err(|error| format!("Failed to create plain transport: {error}"))?;
// And creating audio producer that will be consumed over WebRTC later
let rtp_producer = plain_transport
......@@ -185,7 +185,7 @@ impl EchoConnection {
},
))
.await
.map_err(|error| format!("Failed to create audio producer: {}", error))?;
.map_err(|error| format!("Failed to create audio producer: {error}"))?;
println!(
"Plain transport created:\n \
......@@ -232,7 +232,7 @@ impl EchoConnection {
},
)))
.await
.map_err(|error| format!("Failed to create consumer transport: {}", error))?;
.map_err(|error| format!("Failed to create consumer transport: {error}"))?;
Ok(Self {
client_rtp_capabilities: None,
......@@ -290,11 +290,11 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for EchoConnection {
ctx.address().do_send(message);
}
Err(error) => {
eprintln!("Failed to parse client message: {}\n{}", error, text);
eprintln!("Failed to parse client message: {error}\n{text}");
}
},
Ok(ws::Message::Binary(bin)) => {
eprintln!("Unexpected binary message: {:?}", bin);
eprintln!("Unexpected binary message: {bin:?}");
}
Ok(ws::Message::Close(reason)) => {
ctx.close(reason);
......@@ -329,7 +329,7 @@ impl Handler<ClientMessage> for EchoConnection {
println!("Consumer transport connected");
}
Err(error) => {
eprintln!("Failed to connect consumer transport: {}", error);
eprintln!("Failed to connect consumer transport: {error}");
address.do_send(InternalMessage::Stop);
}
}
......@@ -365,10 +365,10 @@ impl Handler<ClientMessage> for EchoConnection {
// Consumer is stored in a hashmap since if we don't do it, it will get
// destroyed as soon as its instance goes out out scope
address.do_send(InternalMessage::SaveConsumer(consumer));
println!("{:?} consumer created: {}", kind, id);
println!("{kind:?} consumer created: {id}");
}
Err(error) => {
eprintln!("Failed to create consumer: {}", error);
eprintln!("Failed to create consumer: {error}");
address.do_send(InternalMessage::Stop);
}
}
......@@ -417,7 +417,7 @@ async fn ws_index(
match EchoConnection::new(&worker_manager).await {
Ok(echo_server) => ws::start(echo_server, &request, stream),
Err(error) => {
eprintln!("{}", error);
eprintln!("{error}");
Ok(HttpResponse::InternalServerError().finish())
}
......
......@@ -191,11 +191,11 @@ impl SvcSimulcastConnection {
settings
})
.await
.map_err(|error| format!("Failed to create worker: {}", error))?;
.map_err(|error| format!("Failed to create worker: {error}"))?;
let router = worker
.create_router(RouterOptions::new(media_codecs()))
.await
.map_err(|error| format!("Failed to create router: {}", error))?;
.map_err(|error| format!("Failed to create router: {error}"))?;
// We know that for svc-simulcast example we'll need 2 transports, so we can create both
// right away.
......@@ -208,12 +208,12 @@ impl SvcSimulcastConnection {
let producer_transport = router
.create_webrtc_transport(transport_options.clone())
.await
.map_err(|error| format!("Failed to create producer transport: {}", error))?;
.map_err(|error| format!("Failed to create producer transport: {error}"))?;
let consumer_transport = router
.create_webrtc_transport(transport_options)
.await
.map_err(|error| format!("Failed to create consumer transport: {}", error))?;
.map_err(|error| format!("Failed to create consumer transport: {error}"))?;
Ok(Self {
client_rtp_capabilities: None,
......@@ -279,11 +279,11 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for SvcSimulcastConne
ctx.address().do_send(message);
}
Err(error) => {
eprintln!("Failed to parse client message: {}\n{}", error, text);
eprintln!("Failed to parse client message: {text}\n{error}");
}
},
Ok(ws::Message::Binary(bin)) => {
eprintln!("Unexpected binary message: {:?}", bin);
eprintln!("Unexpected binary message: {bin:?}");
}
Ok(ws::Message::Close(reason)) => {
ctx.close(reason);
......@@ -346,7 +346,7 @@ impl Handler<ClientMessage> for SvcSimulcastConnection {
println!("Producer transport connected");
}
Err(error) => {
eprintln!("Failed to connect producer transport: {}", error);
eprintln!("Failed to connect producer transport: {error}");
address.do_send(InternalMessage::Stop);
}
}
......@@ -371,10 +371,10 @@ impl Handler<ClientMessage> for SvcSimulcastConnection {
// Producer is stored in a hashmap since if we don't do it, it will get
// destroyed as soon as its instance goes out out scope
address.do_send(InternalMessage::SaveProducer(producer));
println!("{:?} producer created: {}", kind, id);
println!("{kind:?} producer created: {id}");
}
Err(error) => {
eprintln!("Failed to create {:?} producer: {}", kind, error);
eprintln!("Failed to create {kind:?} producer: {error}");
address.do_send(InternalMessage::Stop);
}
}
......@@ -394,7 +394,7 @@ impl Handler<ClientMessage> for SvcSimulcastConnection {
println!("Consumer transport connected");
}
Err(error) => {
eprintln!("Failed to connect consumer transport: {}", error);
eprintln!("Failed to connect consumer transport: {error}");
address.do_send(InternalMessage::Stop);
}
}
......@@ -430,10 +430,10 @@ impl Handler<ClientMessage> for SvcSimulcastConnection {
// Consumer is stored in a hashmap since if we don't do it, it will get
// destroyed as soon as its instance goes out out scope
address.do_send(InternalMessage::SaveConsumer(consumer));
println!("{:?} consumer created: {}", kind, id);
println!("{kind:?} consumer created: {id}");
}
Err(error) => {
eprintln!("Failed to create consumer: {}", error);
eprintln!("Failed to create consumer: {error}");
address.do_send(InternalMessage::Stop);
}
}
......@@ -509,7 +509,7 @@ async fn ws_index(
match SvcSimulcastConnection::new(&worker_manager).await {
Ok(svc_simulcast_connection) => ws::start(svc_simulcast_connection, &request, stream),
Err(error) => {
eprintln!("{}", error);
eprintln!("{error}");
Ok(HttpResponse::InternalServerError().finish())
}
......
......@@ -111,13 +111,13 @@ mod room {
settings
})
.await
.map_err(|error| format!("Failed to create worker: {}", error))?;
.map_err(|error| format!("Failed to create worker: {error}"))?;
let router = worker
.create_router(RouterOptions::new(crate::media_codecs()))
.await
.map_err(|error| format!("Failed to create router: {}", error))?;
.map_err(|error| format!("Failed to create router: {error}"))?;
println!("Room {} created", id);
println!("Room {id} created");
Ok(Self {
inner: Arc::new(Inner {
......@@ -504,13 +504,13 @@ mod participant {
.router()
.create_webrtc_transport(transport_options.clone())
.await
.map_err(|error| format!("Failed to create producer transport: {}", error))?;
.map_err(|error| format!("Failed to create producer transport: {error}"))?;
let consumer_transport = room
.router()
.create_webrtc_transport(transport_options)
.await
.map_err(|error| format!("Failed to create consumer transport: {}", error))?;
.map_err(|error| format!("Failed to create consumer transport: {error}"))?;
Ok(Self {
id: ParticipantId::new(),
......@@ -598,7 +598,7 @@ mod participant {
}
fn stopped(&mut self, _ctx: &mut Self::Context) {
println!("[participant_id {}] WebSocket connection closed", self.id);
println!("[participant_id {0}] WebSocket connection closed", self.id);
}
}
......@@ -620,11 +620,11 @@ mod participant {
ctx.address().do_send(message);
}
Err(error) => {
eprintln!("Failed to parse client message: {}\n{}", error, text);
eprintln!("Failed to parse client message: {error}\n{text}");
}
},
Ok(ws::Message::Binary(bin)) => {
eprintln!("Unexpected binary message: {:?}", bin);
eprintln!("Unexpected binary message: {bin:?}");
}
Ok(ws::Message::Close(reason)) => {
ctx.close(reason);
......@@ -660,12 +660,11 @@ mod participant {
Ok(_) => {
address.do_send(ServerMessage::ConnectedProducerTransport);
println!(
"[participant_id {}] Producer transport connected",
participant_id,
"[participant_id {participant_id}] Producer transport connected"
);
}
Err(error) => {
eprintln!("Failed to connect producer transport: {}", error);
eprintln!("Failed to connect producer transport: {error}");
address.do_send(InternalMessage::Stop);
}
}
......@@ -695,14 +694,12 @@ mod participant {
// get destroyed as soon as its instance goes out out scope
address.do_send(InternalMessage::SaveProducer(producer));
println!(
"[participant_id {}] {:?} producer created: {}",
participant_id, kind, id,
"[participant_id {participant_id}] {kind:?} producer created: {id}"
);
}
Err(error) => {
eprintln!(
"[participant_id {}] Failed to create {:?} producer: {}",
participant_id, kind, error
"[participant_id {participant_id}] Failed to create {kind:?} producer: {error}"
);
address.do_send(InternalMessage::Stop);
}
......@@ -722,14 +719,12 @@ mod participant {
Ok(_) => {
address.do_send(ServerMessage::ConnectedConsumerTransport);
println!(
"[participant_id {}] Consumer transport connected",
participant_id,
"[participant_id {participant_id}] Consumer transport connected"
);
}
Err(error) => {
eprintln!(
"[participant_id {}] Failed to connect consumer transport: {}",
participant_id, error,
"[participant_id {participant_id}] Failed to connect consumer transport: {error}"
);
address.do_send(InternalMessage::Stop);
}
......@@ -744,9 +739,8 @@ mod participant {
Some(rtp_capabilities) => rtp_capabilities,
None => {
eprintln!(
"[participant_id {}] Client should send RTP capabilities before \
consuming",
participant_id,
"[participant_id {participant_id}] Client should send RTP capabilities before \
consuming"
);
return;
}
......@@ -772,14 +766,12 @@ mod participant {
// get destroyed as soon as its instance goes out out scope
address.do_send(InternalMessage::SaveConsumer(consumer));
println!(
"[participant_id {}] {:?} consumer created: {}",
participant_id, kind, id,
"[participant_id {participant_id}] {kind:?} consumer created: {id}"
);
}
Err(error) => {
eprintln!(
"[participant_id {}] Failed to create consumer: {}",
participant_id, error,
"[participant_id {participant_id}] Failed to create consumer: {error}"
);
address.do_send(InternalMessage::Stop);
}
......@@ -904,7 +896,7 @@ async fn ws_index(
let room = match room {
Ok(room) => room,
Err(error) => {
eprintln!("{}", error);
eprintln!("{error}");
return Ok(HttpResponse::InternalServerError().finish());
}
......@@ -913,7 +905,7 @@ async fn ws_index(
match ParticipantConnection::new(room).await {
Ok(echo_server) => ws::start(echo_server, &request, stream),
Err(error) => {
eprintln!("{}", error);
eprintln!("{error}");
Ok(HttpResponse::InternalServerError().finish())
}
......
......@@ -377,8 +377,7 @@ impl<'de> Deserialize<'de> for DtlsFingerprint {
*v = u8::from_str_radix(&input[i * 3..(i * 3) + 2], 16).map_err(
|error| {
format!(
"Failed to parse value {} as series of hex bytes: {}",
input, error,
"Failed to parse value {input} as series of hex bytes: {error}"
)
},
)?;
......
......@@ -539,7 +539,7 @@ pub(super) trait TransportImpl: TransportGeneric {
.next_mid_for_consumers()
.fetch_add(1, Ordering::Relaxed);
let mid = next_mid_for_consumers % 100_000_000;
Some(format!("{}", mid))
Some(format!("{mid}"))
})
}
......
......@@ -500,8 +500,7 @@ impl Inner {
Err(error) => Err(io::Error::new(
io::ErrorKind::Other,
format!(
"unexpected first notification from worker [id:{}]: {:?}; error = {}",
id, notification, error
"unexpected first notification from worker [id:{id}]: {notification:?}; error = {error}"
),
)),
};
......@@ -537,7 +536,7 @@ impl Inner {
error!("[id:{}] {}", id, text)
}
}
channel::InternalMessage::Dump(text) => eprintln!("{}", text),
channel::InternalMessage::Dump(text) => eprintln!("{text}"),
channel::InternalMessage::Unexpected(data) => error!(
"worker[id:{}] unexpected channel data: {}",
id,
......
......@@ -60,7 +60,7 @@ where
let buffer_worker_messages_guard = channel.buffer_messages_for(std::process::id().into());
std::thread::Builder::new()
.name(format!("mediasoup-worker-{}", id))
.name(format!("mediasoup-worker-{id}"))
.spawn(move || {
if let Some(thread_initializer) = thread_initializer {
thread_initializer();
......
......@@ -581,7 +581,7 @@ fn pipe_to_router_fails_if_both_routers_belong_to_the_same_worker() {
{
assert!(reason.contains("already exists [method:transport.produce]"));
} else {
panic!("Unexpected result: {:?}", result);
panic!("Unexpected result: {result:?}");
}
});
}
......
......@@ -71,7 +71,7 @@ fn main() {
.expect("Failed to decode path")
.trim()
);
println!("cargo:rustc-link-search={}", libpath);
println!("cargo:rustc-link-search={libpath}");
println!("cargo:rustc-link-lib=dylib=c++");
println!("cargo:rustc-link-lib=dylib=c++abi");
}
......@@ -98,16 +98,13 @@ fn main() {
#[cfg(target_os = "windows")]
{
let dot_a = format!("{}/libmediasoup-worker.a", out_dir);
let dot_lib = format!("{}/mediasoup-worker.lib", out_dir);
let dot_a = format!("{out_dir}/libmediasoup-worker.a");
let dot_lib = format!("{out_dir}/mediasoup-worker.lib");
// Meson builds `libmediasoup-worker.a` on Windows instead of `*.lib` file under MinGW
if std::path::Path::new(&dot_a).exists() {
std::fs::copy(&dot_a, &dot_lib).unwrap_or_else(|error| {
panic!(
"Failed to copy static library from {} to {}: {}",
dot_a, dot_lib, error
)
panic!("Failed to copy static library from {dot_a} to {dot_lib}: {error}");
});
}
......@@ -143,5 +140,5 @@ fn main() {
}
println!("cargo:rustc-link-lib=static=mediasoup-worker");
println!("cargo:rustc-link-search=native={}", out_dir);
println!("cargo:rustc-link-search=native={out_dir}");
}
......@@ -630,6 +630,11 @@ namespace RTC
auto nowMs = DepLibUV::GetTimeMs();
uint32_t desiredBitrate{ 0u };
// Let's iterate all streams of the Producer (from highest to lowest) and
// obtain their bitrate. Choose the highest one.
// NOTE: When the Producer enables a higher stream, initially the bitrate of
// it could be less than the bitrate of a lower stream. That's why we
// iterate all streams here anyway.
for (auto sIdx{ static_cast<int16_t>(this->producerRtpStreams.size() - 1) }; sIdx >= 0; --sIdx)
{
auto* producerRtpStream = this->producerRtpStreams.at(sIdx);
......@@ -637,10 +642,10 @@ namespace RTC
if (!producerRtpStream)
continue;
desiredBitrate = producerRtpStream->GetBitrate(nowMs);
auto streamBitrate = producerRtpStream->GetBitrate(nowMs);
if (desiredBitrate)
break;
if (streamBitrate > desiredBitrate)
desiredBitrate = streamBitrate;
}
// If consumer.rtpParameters.encodings[0].maxBitrate was given and it's
......
......@@ -2324,16 +2324,9 @@ namespace RTC
for (uint8_t i{ 1u }; i <= (baseAllocation ? 1u : priority); ++i)
{
uint32_t usedBitrate{ 0u };
bool considerLoss = (bweType == RTC::BweType::REMB);
switch (bweType)
{
case RTC::BweType::TRANSPORT_CC:
usedBitrate = consumer->IncreaseLayer(availableBitrate, /*considerLoss*/ false);
break;
case RTC::BweType::REMB:
usedBitrate = consumer->IncreaseLayer(availableBitrate, /*considerLoss*/ true);
break;
}
usedBitrate = consumer->IncreaseLayer(availableBitrate, considerLoss);
MS_ASSERT(usedBitrate <= availableBitrate, "Consumer used more layer bitrate than given");
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论