Set process priority to idle on Windows.
parent
d704db400b
commit
537be95850
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/delthas/go-libnp"
|
||||
"github.com/dhowden/tag"
|
||||
"github.com/gin-gonic/gin"
|
||||
"golang.org/x/sys/windows"
|
||||
"gopkg.in/alecthomas/kingpin.v3-unstable"
|
||||
|
||||
"github.com/icedream/livestream-tools/icedreammusic/metacollector"
|
||||
|
@ -61,9 +62,31 @@ func generateIDFromMetadata(metadata libnp.Info) [64]byte {
|
|||
return sha512.Sum512([]byte(strings.Join(metadata.Artists, "|") + "||" + metadata.Title))
|
||||
}
|
||||
|
||||
// https://learn.microsoft.com/en-us/windows/win32/procthread/process-security-and-access-rights
|
||||
const PROCESS_ALL_ACCESS = windows.STANDARD_RIGHTS_REQUIRED | windows.SYNCHRONIZE | 0xffff
|
||||
|
||||
func SetPriorityWindows(pid int, priority uint32) error {
|
||||
handle, err := windows.OpenProcess(PROCESS_ALL_ACCESS, false, uint32(pid))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer windows.CloseHandle(handle) // Technically this can fail, but we ignore it if it does
|
||||
|
||||
err = windows.SetPriorityClass(handle, priority)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Set priority to idle to not use CPU that is required for audio playback
|
||||
err := SetPriorityWindows(os.Getpid(), windows.IDLE_PRIORITY_CLASS)
|
||||
if err != nil {
|
||||
log.Println("WARNING: Failed to set priority class: ", err)
|
||||
}
|
||||
|
||||
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt, syscall.SIGTERM)
|
||||
defer cancel()
|
||||
|
||||
|
|
Loading…
Reference in New Issue