@@ -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}
0 commit comments