コード例 #1
0
 public bool DecoderMatches(string decoderId, ICodecSettings codecSettings)
 {
     if (Decoder == null)
     {
         return(false);
     }
     return(Decoder.CodecId == decoderId && Decoder.SettingsMatch(codecSettings));
 }
コード例 #2
0
 public IEncoder CreateEncoder(string codecId, ICodecSettings codecSettings)
 {
     if (_encoderFactories.TryGetValue(codecId, out Func <ICodecSettings, IEncoder>?factory))
     {
         return(factory(codecSettings ?? throw new InvalidOperationException($"CodecId '{codecId}' has null default settings.")));
     }
     throw new InvalidOperationException($"CodecId '{codecId}' is not registered.");
 }
コード例 #3
0
 public void RegisterCodec(string codecId, ICodecSettings defaultSettings, Func <ICodecSettings, IEncoder> encoderFactory, Func <ICodecSettings, IDecoder> decoderFactory)
 {
     if (string.IsNullOrEmpty(codecId))
     {
         throw new ArgumentNullException(nameof(codecId));
     }
     if (defaultSettings == null)
     {
         throw new ArgumentNullException(nameof(defaultSettings));
     }
     if (encoderFactory == null)
     {
         throw new ArgumentNullException(nameof(encoderFactory));
     }
     if (decoderFactory == null)
     {
         throw new ArgumentNullException(nameof(decoderFactory));
     }
     _defaultSettings[codecId]  = defaultSettings;
     _encoderFactories[codecId] = encoderFactory;
     _decoderFactories[codecId] = decoderFactory;
 }
コード例 #4
0
 public static OpusSettings CloneSettings(ICodecSettings codecSettings)
 {
     if (codecSettings == null)
     {
         throw new ArgumentNullException(nameof(codecSettings));
     }
     if (codecSettings is OpusSettings opusSettings)
     {
         return(opusSettings.Clone());
     }
     else
     {
         return(new OpusSettings()
         {
             SampleRate = codecSettings.SampleRate,
             Channels = codecSettings.Channels,
             DecoderGain = codecSettings.DecoderGain,
             FrameDuration = OpusDefaults.FrameDuration,
             Bitrate = OpusDefaults.Bitrate,
         });
     }
 }