Skip to content

Commit

Permalink
feat: provide loader class
Browse files Browse the repository at this point in the history
  • Loading branch information
silenium-dev committed Jul 26, 2024
1 parent 5194751 commit 29924ff
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/main/kotlin/dev/silenium/libs/ffmpeg/FFmpeg.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,38 @@ object FFmpeg {
"swresample",
"swscale",
)
private var loaded = false
private var loadedGPL = false
private var loadedLGPL = false

@Synchronized
fun ensureLoaded(withGPL: Boolean = false) {
if (loaded) return
fun ensureLoadedGPL(): Result<Unit> {
if (loadedLGPL) return Result.failure(IllegalStateException("GPL and LGPL libraries are mutually exclusive"))
if (loadedGPL) return Result.success(Unit)

libs.forEach {
NativeLoader.loadLibraryFromClasspath(
baseName = it,
platform = NativePlatform.platform("-gpl".takeIf { withGPL }.orEmpty()),
platform = NativePlatform.platform("-gpl"),
)
}

loaded = true
loadedGPL = true
return Result.success(Unit)
}

@Synchronized
fun ensureLoadedLGPL(): Result<Unit> {
if (loadedGPL) return Result.failure(IllegalStateException("GPL and LGPL libraries are mutually exclusive"))
if (loadedLGPL) return Result.success(Unit)

libs.forEach {
NativeLoader.loadLibraryFromClasspath(
baseName = it,
platform = NativePlatform.platform(),
)
}

loadedLGPL = true
return Result.success(Unit)
}
}

0 comments on commit 29924ff

Please sign in to comment.