All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good
67 lines
2.2 KiB
Java
67 lines
2.2 KiB
Java
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<String> availableHardwareEncodings) {
|
|
|
|
private static final ConfigHandler configHandler = FFMpegConvert.getConfiguration().getConfigHandler();
|
|
|
|
/**
|
|
* Gets all hardware encodings
|
|
*
|
|
* @return <p>All hardware encodings</p>
|
|
*/
|
|
@Override
|
|
@NotNull
|
|
public List<String> availableHardwareEncodings() {
|
|
return new ArrayList<>(this.availableHardwareEncodings);
|
|
}
|
|
|
|
/**
|
|
* Removes the specified hardware encoding
|
|
*
|
|
* @param encoding <p>The hardware encoding to remove</p>
|
|
*/
|
|
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 <p>The loaded available hardware encoder handler, or a new one if no data has been saved</p>
|
|
*/
|
|
@NotNull
|
|
public static AvailableHardwareEncoderHandler load() {
|
|
try {
|
|
configHandler.load();
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
return new AvailableHardwareEncoderHandler(FFMpegConvert.getConfiguration().hardwareEncoders());
|
|
}
|
|
|
|
}
|