From 8f093b9a11d5ec78a135b701e771cff4800a907d Mon Sep 17 00:00:00 2001 From: Naxesss <30292137+Naxesss@users.noreply.github.com> Date: Mon, 11 Oct 2021 13:56:26 +0200 Subject: [PATCH] Use TagLib instead of ManagedBass --- .../FileAbstraction/StreamFileAbstraction.cs | 26 ++++++++++++++++++ .../Rulesets/Edit/Checks/CheckAudioInVideo.cs | 27 +++++++++++++++---- osu.Game/osu.Game.csproj | 1 + 3 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 osu.Game/IO/FileAbstraction/StreamFileAbstraction.cs diff --git a/osu.Game/IO/FileAbstraction/StreamFileAbstraction.cs b/osu.Game/IO/FileAbstraction/StreamFileAbstraction.cs new file mode 100644 index 0000000000..602239aac5 --- /dev/null +++ b/osu.Game/IO/FileAbstraction/StreamFileAbstraction.cs @@ -0,0 +1,26 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.IO; + +namespace osu.Game.IO.FileAbstraction +{ + public class StreamFileAbstraction : TagLib.File.IFileAbstraction + { + public StreamFileAbstraction(string filename, Stream fileStream) + { + ReadStream = fileStream; + Name = filename; + } + + public string Name { get; } + + public Stream ReadStream { get; } + public Stream WriteStream => ReadStream; + + public void CloseStream(Stream aStream) + { + aStream.Position = 0; + } + } +} diff --git a/osu.Game/Rulesets/Edit/Checks/CheckAudioInVideo.cs b/osu.Game/Rulesets/Edit/Checks/CheckAudioInVideo.cs index 57a3af6a1c..af87e52c62 100644 --- a/osu.Game/Rulesets/Edit/Checks/CheckAudioInVideo.cs +++ b/osu.Game/Rulesets/Edit/Checks/CheckAudioInVideo.cs @@ -3,8 +3,7 @@ using System.Collections.Generic; using System.IO; -using ManagedBass; -using osu.Framework.Audio.Callbacks; +using osu.Game.IO.FileAbstraction; using osu.Game.Rulesets.Edit.Checks.Components; using osu.Game.Storyboards; @@ -52,9 +51,27 @@ public IEnumerable Run(BeatmapVerifierContext context) } Stream data = context.WorkingBeatmap.GetStream(storagePath); - var fileCallbacks = new FileCallbacks(new DataStreamFileProcedures(data)); - int decodeStream = Bass.CreateStream(StreamSystem.NoBuffer, BassFlags.Decode, fileCallbacks.Callbacks, fileCallbacks.Handle); - if (decodeStream == 0) + StreamFileAbstraction fileAbstraction = new StreamFileAbstraction(filename, data); + + // We use TagLib here for platform invariance; BASS cannot detect audio presence on Linux. + TagLib.File tagFile = null; + string errorReason = null; + + try + { + tagFile = TagLib.File.Create(fileAbstraction); + } + catch (TagLib.CorruptFileException) { errorReason = "Corrupt file"; } + catch (TagLib.UnsupportedFormatException) { errorReason = "Unsupported format"; } + + if (errorReason != null) + { + yield return new IssueTemplateFileError(this).Create(filename, errorReason); + + continue; + } + + if (tagFile.Properties.AudioChannels == 0) continue; yield return new IssueTemplateHasAudioTrack(this).Create(filename); diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 357aa89329..d80d2ade82 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -42,5 +42,6 @@ +