Skip to content

Commit 46e4c67

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

File tree

6 files changed

+99
-20
lines changed

6 files changed

+99
-20
lines changed

crates/ironrdp-client/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl Config {
270270
Some(connector::BitmapConfig {
271271
color_depth,
272272
lossy_compression: true,
273-
codecs: client_codecs_capabilities(),
273+
codecs: client_codecs_capabilities(&[]).unwrap(),
274274
})
275275
} else {
276276
None

crates/ironrdp-connector/src/connection_activation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ fn create_client_confirm_active(
360360
.bitmap
361361
.as_ref()
362362
.map(|b| b.codecs.clone())
363-
.unwrap_or_else(client_codecs_capabilities),
363+
.unwrap_or_else(|| client_codecs_capabilities(&[]).unwrap()),
364364
),
365365
CapabilitySet::FrameAcknowledge(FrameAcknowledge {
366366
// FIXME(#447): Revert this to 2 per FreeRDP.

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

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -649,17 +649,77 @@ impl CodecId {
649649
}
650650
}
651651

652-
pub fn client_codecs_capabilities() -> BitmapCodecs {
653-
let codecs = vec![Codec {
654-
id: CODEC_ID_REMOTEFX.0,
655-
property: CodecProperty::RemoteFx(RemoteFxContainer::ClientContainer(RfxClientCapsContainer {
656-
capture_flags: CaptureFlags::empty(),
657-
caps_data: RfxCaps(RfxCapset(vec![RfxICap {
658-
flags: RfxICapFlags::empty(),
659-
entropy_bits: EntropyBits::Rlgr3,
660-
}])),
661-
})),
662-
}];
663-
664-
BitmapCodecs(codecs)
652+
/// This function generates a list of client codec capabilities based on the
653+
/// provided configuration.
654+
///
655+
/// # Arguments
656+
///
657+
/// * `config` - A slice of string slices that specifies which codecs to include
658+
/// in the capabilities. Codecs can be explicitly turned on ("codec:on") or
659+
/// off ("codec:off").
660+
///
661+
/// # List of codecs
662+
///
663+
/// * `remotefx` (on by default)
664+
///
665+
/// # Returns
666+
///
667+
/// A vector of `Codec` structs representing the codec capabilities, or an error
668+
/// suitable for CLI.
669+
pub fn client_codecs_capabilities(config: &[&str]) -> Result<BitmapCodecs, String> {
670+
use std::collections::HashMap;
671+
672+
fn parse_codecs_config<'a>(codecs: &'a [&'a str]) -> Result<HashMap<&'a str, bool>, String> {
673+
let mut result = HashMap::new();
674+
675+
for &codec_str in codecs {
676+
if let Some(colon_index) = codec_str.find(':') {
677+
let codec_name = &codec_str[0..colon_index];
678+
let state_str = &codec_str[colon_index + 1..];
679+
680+
let state = match state_str {
681+
"on" => true,
682+
"off" => false,
683+
_ => return Err(format!("Unhandled configuration: {}", state_str)),
684+
};
685+
686+
result.insert(codec_name, state);
687+
} else {
688+
// No colon found, assume it's "on"
689+
result.insert(codec_str, true);
690+
}
691+
}
692+
693+
Ok(result)
694+
}
695+
696+
if config.contains(&"help") {
697+
return Err(r#"
698+
List of codecs:
699+
- `remotefx` (on by default)
700+
"#
701+
.to_owned());
702+
}
703+
let mut config = parse_codecs_config(config)?;
704+
let mut codecs = vec![];
705+
706+
if config.remove("remotefx").unwrap_or(true) {
707+
codecs.push(Codec {
708+
id: CODEC_ID_REMOTEFX.0,
709+
property: CodecProperty::RemoteFx(RemoteFxContainer::ClientContainer(RfxClientCapsContainer {
710+
capture_flags: CaptureFlags::empty(),
711+
caps_data: RfxCaps(RfxCapset(vec![RfxICap {
712+
flags: RfxICapFlags::empty(),
713+
entropy_bits: EntropyBits::Rlgr3,
714+
}])),
715+
})),
716+
});
717+
}
718+
719+
let codec_names = config.keys().copied().collect::<Vec<_>>().join(", ");
720+
if !codec_names.is_empty() {
721+
return Err(format!("Unknown codecs: {}", codec_names));
722+
}
723+
724+
Ok(BitmapCodecs(codecs))
665725
}

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
@@ -856,7 +856,7 @@ fn build_config(
856856
bitmap: Some(connector::BitmapConfig {
857857
color_depth: 16,
858858
lossy_compression: true,
859-
codecs: client_codecs_capabilities(),
859+
codecs: client_codecs_capabilities(&[]).unwrap(),
860860
}),
861861
#[allow(clippy::arithmetic_side_effects)] // fine unless we end up with an insanely big version
862862
client_build: semver::Version::parse(env!("CARGO_PKG_VERSION"))

0 commit comments

Comments
 (0)