Skip to content

Commit

Permalink
SimulcastConsumer::GetDesiredBitrate(): Choose the highest bitrate am…
Browse files Browse the repository at this point in the history
…ong all Producer streams (versatica#992)
  • Loading branch information
ibc authored and piranna committed Feb 8, 2023
1 parent 0d1758f commit aa45c49
Show file tree
Hide file tree
Showing 15 changed files with 220 additions and 237 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/mediasoup-rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,20 @@ jobs:
- ubuntu-22.04
- macos-12
- windows-2022
rust:
- stable
# - nightly

runs-on: ${{ matrix.os }}

steps:
- 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
Expand Down
271 changes: 138 additions & 133 deletions CHANGELOG.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.67.0"
components = ["rustfmt", "clippy"]
26 changes: 13 additions & 13 deletions rust/examples/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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())
}
Expand Down
22 changes: 11 additions & 11 deletions rust/examples/multiopus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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())
}
Expand Down
26 changes: 13 additions & 13 deletions rust/examples/svc-simulcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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())
}
Expand Down
Loading

0 comments on commit aa45c49

Please sign in to comment.