package net.knarcraft.ffmpegconverter.handler; import net.knarcraft.ffmpegconverter.FFMpegConvert; import net.knarcraft.ffmpegconverter.config.ConfigHandler; import net.knarcraft.ffmpegconverter.config.ConfigKey; import net.knarcraft.ffmpegconverter.utility.OutputUtil; import org.apache.commons.configuration2.PropertiesConfiguration; import org.jetbrains.annotations.NotNull; import java.io.IOException; import java.util.ArrayList; import java.util.List; /** * A handler for keeping track of which hardware acceleration methods are available on the current system */ public record AvailableHardwareEncoderHandler(@NotNull List availableHardwareEncodings) { private static final ConfigHandler configHandler = FFMpegConvert.getConfiguration().getConfigHandler(); /** * Gets all hardware encodings * * @return

All hardware encodings

*/ @Override @NotNull public List availableHardwareEncodings() { return new ArrayList<>(this.availableHardwareEncodings); } /** * Removes the specified hardware encoding * * @param encoding

The hardware encoding to remove

*/ public void removeHardwareEncoding(@NotNull String encoding) { this.availableHardwareEncodings.remove(encoding); } /** * Saves settings for this available hardware encoder handler */ public void save() { PropertiesConfiguration configuration = configHandler.getWritableConfiguration(); configuration.setProperty(ConfigKey.HARDWARE_ACCELERATED_ENCODERS.toString(), String.join(",", this.availableHardwareEncodings)); configHandler.writeConfiguration(); OutputUtil.printDebug("Saved available hardware encoder handler"); } /** * Loads saved settings for an available hardware encoder handler * * @return

The loaded available hardware encoder handler, or a new one if no data has been saved

*/ @NotNull public static AvailableHardwareEncoderHandler load() { try { configHandler.load(); } catch (IOException e) { throw new RuntimeException(e); } return new AvailableHardwareEncoderHandler(FFMpegConvert.getConfiguration().hardwareEncoders()); } }