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