Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFmpeg: Only load versioned libraries on Linux #6154

Merged
merged 4 commits into from Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions osu.Framework/Graphics/Video/VideoDecoder.cs
Expand Up @@ -113,12 +113,18 @@ static VideoDecoder()
{
if (RuntimeInfo.OS == RuntimeInfo.Platform.Linux)
{
void loadVersionedLibraryGlobally(string name)
{
int version = FFmpeg.AutoGen.ffmpeg.LibraryVersionMap[name];
Library.Load($"lib{name}.so.{version}", Library.LoadFlags.RTLD_LAZY | Library.LoadFlags.RTLD_GLOBAL);
}

// FFmpeg.AutoGen doesn't load libraries as RTLD_GLOBAL, so we must load them ourselves to fix inter-library dependencies
// otherwise they would fallback to the system-installed libraries that can differ in version installed.
Library.Load("libavutil.so", Library.LoadFlags.RTLD_LAZY | Library.LoadFlags.RTLD_GLOBAL);
Library.Load("libavcodec.so", Library.LoadFlags.RTLD_LAZY | Library.LoadFlags.RTLD_GLOBAL);
Library.Load("libavformat.so", Library.LoadFlags.RTLD_LAZY | Library.LoadFlags.RTLD_GLOBAL);
Library.Load("libswscale.so", Library.LoadFlags.RTLD_LAZY | Library.LoadFlags.RTLD_GLOBAL);
loadVersionedLibraryGlobally("avutil");
loadVersionedLibraryGlobally("avcodec");
loadVersionedLibraryGlobally("avformat");
loadVersionedLibraryGlobally("swscale");
}
}

Expand Down Expand Up @@ -807,9 +813,9 @@ protected virtual FFmpegFuncs CreateFuncs()
{
int version = FFmpeg.AutoGen.ffmpeg.LibraryVersionMap[name];

// "lib" prefix and extensions are resolved by .net core
string libraryName;

// "lib" prefix and extensions are resolved by .net core
switch (RuntimeInfo.OS)
{
case RuntimeInfo.Platform.macOS:
Expand All @@ -820,8 +826,11 @@ protected virtual FFmpegFuncs CreateFuncs()
libraryName = $"{name}-{version}";
break;

// To handle versioning in Linux, we have to specify the entire file name
// because Linux uses a version suffix after the file extension (e.g. libavutil.so.56)
// More info: https://learn.microsoft.com/en-us/dotnet/standard/native-interop/native-library-loading?view=net-6.0
case RuntimeInfo.Platform.Linux:
libraryName = name;
libraryName = $"lib{name}.so.{version}";
smoogipoo marked this conversation as resolved.
Show resolved Hide resolved
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/osu.Framework.csproj
Expand Up @@ -44,7 +44,7 @@

<!-- DO NOT use ProjectReference for native packaging project.
See https://github.com/NuGet/Home/issues/4514 and https://github.com/dotnet/sdk/issues/765 . -->
<PackageReference Include="ppy.osu.Framework.NativeLibs" Version="2023.1225.0-nativelibs" />
<PackageReference Include="ppy.osu.Framework.NativeLibs" Version="2024.326.0-nativelibs" />

<!-- Any version ahead of this will cause AOT issues with iOS
See https://github.com/mono/mono/issues/21188 -->
Expand Down