Skip to content

Commit 9728e0e

Browse files
committed
feat(session): make client_codecs_capabilities() configurable
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
1 parent e4f3b76 commit 9728e0e

File tree

5 files changed

+90
-19
lines changed

5 files changed

+90
-19
lines changed

crates/ironrdp-client/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl Config {
264264
Some(connector::BitmapConfig {
265265
color_depth,
266266
lossy_compression: true,
267-
codecs: client_codecs_capabilities(),
267+
codecs: client_codecs_capabilities(&[]).unwrap(),
268268
})
269269
} else {
270270
None

crates/ironrdp-pdu/src/rdp/capability_sets/bitmap_codecs.rs

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -637,17 +637,69 @@ impl CodecId {
637637
}
638638
}
639639

640-
pub fn client_codecs_capabilities() -> BitmapCodecs {
641-
let codecs = vec![Codec {
642-
id: CodecId::RemoteFx as u8,
643-
property: CodecProperty::RemoteFx(RemoteFxContainer::ClientContainer(RfxClientCapsContainer {
644-
capture_flags: CaptureFlags::empty(),
645-
caps_data: RfxCaps(RfxCapset(vec![RfxICap {
646-
flags: RfxICapFlags::empty(),
647-
entropy_bits: EntropyBits::Rlgr3,
648-
}])),
649-
})),
650-
}];
651-
652-
BitmapCodecs(codecs)
640+
/// This function generates a list of client codec capabilities based on the
641+
/// provided configuration.
642+
///
643+
/// # Arguments
644+
///
645+
/// * `config` - A slice of string slices that specifies which codecs to include
646+
/// in the capabilities. Codecs can be explicitly turned on ("codec:on") or
647+
/// off ("codec:off").
648+
///
649+
/// # List of codecs
650+
///
651+
/// * `remotefx` (on by default)
652+
///
653+
/// # Returns
654+
///
655+
/// A vector of `Codec` structs representing the codec capabilities.
656+
pub fn client_codecs_capabilities(config: &[&str]) -> Result<BitmapCodecs, String> {
657+
use std::collections::HashMap;
658+
659+
fn parse_codecs_config<'a>(codecs: &'a [&'a str]) -> HashMap<&'a str, bool> {
660+
let mut result = HashMap::new();
661+
662+
for &codec_str in codecs {
663+
if let Some(colon_index) = codec_str.find(':') {
664+
let codec_name = &codec_str[0..colon_index];
665+
let state_str = &codec_str[colon_index + 1..];
666+
667+
let state = match state_str {
668+
"on" => true,
669+
"off" => false,
670+
_ => continue, // Skip entries with unknown states
671+
};
672+
673+
result.insert(codec_name, state);
674+
} else {
675+
// No colon found, assume it's "on"
676+
result.insert(codec_str, true);
677+
}
678+
}
679+
680+
result
681+
}
682+
683+
let mut config = parse_codecs_config(config);
684+
let mut codecs = vec![];
685+
686+
if config.remove("remotefx").unwrap_or(true) {
687+
codecs.push(Codec {
688+
id: CodecId::RemoteFx as u8,
689+
property: CodecProperty::RemoteFx(RemoteFxContainer::ClientContainer(RfxClientCapsContainer {
690+
capture_flags: CaptureFlags::empty(),
691+
caps_data: RfxCaps(RfxCapset(vec![RfxICap {
692+
flags: RfxICapFlags::empty(),
693+
entropy_bits: EntropyBits::Rlgr3,
694+
}])),
695+
})),
696+
});
697+
}
698+
699+
let codec_names = config.keys().copied().collect::<Vec<_>>().join(", ");
700+
if !codec_names.is_empty() {
701+
return Err(format!("Unknown codecs: {}", codec_names));
702+
}
703+
704+
Ok(BitmapCodecs(codecs))
653705
}

crates/ironrdp-session/src/utils.rs

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
11
mod rfx;
2+
3+
#[cfg(test)]
4+
mod tests {
5+
use ironrdp_pdu::rdp::capability_sets::{client_codecs_capabilities, CodecProperty};
6+
7+
#[test]
8+
fn test_codecs_capabilities() {
9+
let config = &[];
10+
let _capabilities = client_codecs_capabilities(config).unwrap();
11+
12+
let config = &["badcodec"];
13+
assert!(client_codecs_capabilities(config).is_err());
14+
15+
let config = &["remotefx:on"];
16+
let capabilities = client_codecs_capabilities(config).unwrap();
17+
assert_eq!(capabilities.0.len(), 1);
18+
assert!(matches!(capabilities.0[0].property, CodecProperty::RemoteFx(_)));
19+
20+
let config = &["remotefx:off"];
21+
let capabilities = client_codecs_capabilities(config).unwrap();
22+
assert_eq!(capabilities.0.len(), 0);
23+
}
24+
}

crates/ironrdp-web/src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ fn build_config(
847847
bitmap: Some(connector::BitmapConfig {
848848
color_depth: 16,
849849
lossy_compression: true,
850-
codecs: client_codecs_capabilities(),
850+
codecs: client_codecs_capabilities(&[]).unwrap(),
851851
}),
852852
#[allow(clippy::arithmetic_side_effects)] // fine unless we end up with an insanely big version
853853
client_build: semver::Version::parse(env!("CARGO_PKG_VERSION"))

0 commit comments

Comments
 (0)