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
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions osu.Framework/Graphics/Video/VideoDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,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 @@ -808,9 +814,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 @@ -821,8 +827,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
Loading