Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ jobs:
- name: Test with ${{ matrix.crypto.name }}
run: cargo +${{steps.toolchain.outputs.name}} test --no-default-features --features ${{ matrix.crypto.features || matrix.crypto.name }}

snowflake:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Martin's snowflake formatting rules
uses: algesten/snowflake@v1.1.0
with:
check_diff: true
line_width_rules: 'CHANGELOG.md:120;c_cpp_properties.json:160;Cargo.toml:150;README.md:180;README.tpl:180;*.md:110;*.rs:110;*.toml:110;DEFAULT=110'
# snowflake:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert once sctp changes is in

# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# with:
# fetch-depth: 0
# - name: Martin's snowflake formatting rules
# uses: algesten/snowflake@v1.1.0
# with:
# check_diff: true
# line_width_rules: 'CHANGELOG.md:120;c_cpp_properties.json:160;Cargo.toml:150;README.md:180;README.tpl:180;*.md:110;*.rs:110;*.toml:110;DEFAULT=110'

pii:
runs-on: ubuntu-latest
Expand Down
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ _internal_test_exports = []
[dependencies]
tracing = "0.1.37"
fastrand = "2.0.1"
sctp-proto = "0.6.0"
#sctp-proto = "0.7.0"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update this once sctp-change is in

sctp-proto = { git = "https://github.com/xnorpx/sctp-proto", rev = "97b5a07aa42b9d1678c38fb3e54f068cca4a847f" }
combine = "4.6.6"
subtle = "2.0.0"

Expand Down
42 changes: 41 additions & 1 deletion src/change/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::crypto::Fingerprint;
use crate::media::{Media, MediaKind};
use crate::rtp_::MidRid;
use crate::rtp_::{Mid, Rid, Ssrc};
use crate::sctp::ChannelConfig;
use crate::sctp::{ChannelConfig, SctpConfig};
use crate::streams::{StreamRx, StreamTx, DEFAULT_RTX_CACHE_DURATION, DEFAULT_RTX_RATIO_CAP};
use crate::IceCreds;
use crate::Rtc;
Expand Down Expand Up @@ -96,6 +96,46 @@ impl<'a> DirectApi<'a> {
self.rtc.init_dtls(active)
}

/// Set the SCTP configuration.
///
/// This must be called before [`Self::start_sctp()`] to take effect.
/// Use this when you have out-of-band negotiated SCTP parameters,
/// such as the remote INIT chunk.
///
/// # Example
/// ```ignore
/// use str0m::channel::SctpConfig;
///
/// let sctp_config = SctpConfig::new()
/// .with_remote_chunk_init(remote_init_bytes);
/// rtc.direct_api().set_sctp_config(sctp_config);
/// rtc.direct_api().start_sctp(false); // server with out-of-band signaling
/// ```
pub fn set_sctp_config(&mut self, config: SctpConfig) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe return error if we already have a config?

self.rtc.sctp.set_config(config);
}

/// Get a mutable reference to the SCTP configuration.
///
/// Use this to modify the config, for example to set the remote INIT chunk
/// for out-of-band signaling.
///
/// # Panics
///
/// Panics if SCTP has already been initialized via `start_sctp()`.
///
/// # Example
/// ```ignore
/// // Get local INIT chunk to send via signaling
/// let local_init = rtc.direct_api().sctp_config().local_init_chunk();
/// // ... send local_init via signaling, receive remote_init ...
/// rtc.direct_api().sctp_config().set_remote_chunk_init(remote_init);
/// rtc.direct_api().start_sctp(false); // skips SCTP handshake
/// ```
pub fn sctp_config(&mut self) -> &mut SctpConfig {
self.rtc.sctp.sctp_config()
}

/// Start the SCTP over DTLS.
pub fn start_sctp(&mut self, client: bool) {
self.rtc.init_sctp(client)
Expand Down
2 changes: 2 additions & 0 deletions src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use crate::{Rtc, RtcError};

pub use crate::sctp::ChannelConfig;
pub use crate::sctp::Reliability;
pub use crate::sctp::SctpConfig;
pub use crate::sctp::SctpConfigBuilder;

/// Identifier of a data channel.
///
Expand Down
30 changes: 28 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ pub mod rtp {
pub mod bwe;

mod sctp;
use sctp::{RtcSctp, SctpEvent};
use sctp::{RtcSctp, SctpConfig, SctpEvent};

mod sdp;

Expand Down Expand Up @@ -1130,7 +1130,7 @@ impl Rtc {
dtls_buf: vec![0; 2000],
next_dtls_timeout: None,
session,
sctp: RtcSctp::new(),
sctp: RtcSctp::new(config.sctp_config),
chan: ChannelHandler::default(),
stats: config.stats_interval.map(Stats::new),
remote_fingerprint: None,
Expand Down Expand Up @@ -1927,6 +1927,7 @@ pub struct RtcConfig {
send_buffer_video: usize,
rtp_mode: bool,
enable_raw_packets: bool,
sctp_config: Option<SctpConfig>,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -2426,6 +2427,30 @@ impl RtcConfig {
self
}

/// Set the SCTP configuration.
///
/// If not set, default SCTP settings optimized for WebRTC will be used.
///
/// # Example
/// ```
/// # use str0m::Rtc;
/// # use str0m::channel::SctpConfig;
/// let rtc = Rtc::builder()
/// .set_sctp_config(SctpConfig::builder()
/// .with_max_message_size(256 * 1024)
/// .build())
/// .build();
/// ```
pub fn set_sctp_config(mut self, config: SctpConfig) -> Self {
self.sctp_config = Some(config);
self
}

/// Get the configured SCTP settings, if set.
pub fn sctp_config(&self) -> Option<&SctpConfig> {
self.sctp_config.as_ref()
}

/// Create a [`Rtc`] from the configuration.
pub fn build(self) -> Rtc {
Rtc::new_from_config(self).expect("Failed to create Rtc from config")
Expand Down Expand Up @@ -2462,6 +2487,7 @@ impl Default for RtcConfig {
send_buffer_video: 1000,
rtp_mode: false,
enable_raw_packets: false,
sctp_config: None,
}
}
}
Expand Down
Loading
Loading