public DisplaySoftwareEncoder(SoftwareEncoder encoder) { _installed = "No"; _encoder = encoder; }
/// <summary> /// call this function before using an encoder to check /// whether it is possible to use it /// </summary> /// <param name="device">the encoder device</param> /// <param name="dbEncoder">the preferences for dealing with the encoder</param> /// <returns><c>true</c> if the encoder can be used, otherwise <c>false</c></returns> public bool Add(DsDevice device, SoftwareEncoder dbEncoder) { if (device == null) { return false; } int reuseLimit = Convert.ToInt32(_layer.GetSetting("softwareEncoderReuseLimit", "0").Value); lock (_encodersInUse) { DsDevice key = null; foreach (DsDevice dev in _encodersInUse.Keys) { if (dev.Name == device.Name && device.Mon.IsEqual(dev.Mon) == 0 && dev.DevicePath == device.DevicePath) { Log.Log.WriteFile("analog: compressor {0} is in use, checking reuse limit...", dev.Name); key = dev; break; } } // Encoder not yet used -> always okay to use. if (key == null) { Log.Log.WriteFile("analog: compressor {0} is usable", device.Name); _encodersInUse.Add(device, 1); return true; } // Encoder not yet in DB -> assume reusable. if (dbEncoder == null) { Log.Log.WriteFile("analog: unrecognised compressor, assuming usable"); _encodersInUse[key]++; return true; } // If the encoder is reusable then check // the existing usage against the cap. if (dbEncoder.Reusable) { if (reuseLimit <= 0 || _encodersInUse[key] < reuseLimit) { Log.Log.WriteFile("analog: reusable compressor, usage under limit (usage: {0}, limit: {1})", _encodersInUse[key], reuseLimit == 0 ? "[unlimited]" : reuseLimit.ToString()); _encodersInUse[key]++; return true; } else { Log.Log.WriteFile("analog: reusable compressor, usage already at limit (usage: {0}, limit: {1})", _encodersInUse[key], reuseLimit); return false; } } } // If we get to here then the encoder isn't reusable // and it is in use, which means the limit has already // been reached. The encoder wouldn't be in _encodersInUse // if it wasn't in use... Log.Log.WriteFile("analog: non-reusable compressor, already used"); return false; }