Skip to content

Commit

Permalink
Merge branch 'master' into sdl-audio
Browse files Browse the repository at this point in the history
  • Loading branch information
hwsmm committed Dec 16, 2023
2 parents 03a6787 + ba569bf commit aff6271
Show file tree
Hide file tree
Showing 120 changed files with 3,330 additions and 943 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Setup JDK 11
uses: actions/setup-java@v3
with:
distribution: microsoft
java-version: 11

- name: Install .NET 6.0.x
uses: actions/setup-dotnet@v3
with:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/deploy-pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ jobs:
with:
dotnet-version: "6.0.x"

- name: Setup JDK 11
uses: actions/setup-java@v3
with:
distribution: microsoft
java-version: 11

- name: Restore .NET workloads
run: dotnet workload install android

Expand Down
1 change: 1 addition & 0 deletions osu-framework.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ See the LICENCE file in the repository root for full licence text.
<s:Boolean x:Key="/Default/Environment/AutoImport2/=CSHARP/BlackLists/=System_002ENumerics_002E_002A/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/AutoImport2/=CSHARP/BlackLists/=System_002ESecurity_002ECryptography_002ERSA/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/AutoImport2/=CSHARP/BlackLists/=TagLib_002EMpeg4_002EBox/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EFeature_002EServices_002ECodeCleanup_002EFileHeader_002EFileHeaderSettingsMigrate/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EFeature_002EServices_002EDaemon_002ESettings_002EMigration_002ESwaWarningsModeSettingsMigrate/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
Expand Down
10 changes: 8 additions & 2 deletions osu.Framework.Benchmarks/BenchmarkFontLoading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,22 @@ public void TearDown()
[Benchmark]
public void BenchmarkRawCachingReuse()
{
using (var store = new RawCachingGlyphStore(baseResources, font_name) { CacheStorage = sharedTemp })
using (var store = new RawCachingGlyphStore(baseResources, font_name))
{
store.CacheStorage = sharedTemp;
runFor(store);
}
}

[Benchmark(Baseline = true)]
public void BenchmarkRawCaching()
{
using (var temp = new TemporaryNativeStorage("fontstore-test" + Guid.NewGuid()))
using (var store = new RawCachingGlyphStore(baseResources, font_name) { CacheStorage = temp })
using (var store = new RawCachingGlyphStore(baseResources, font_name))
{
store.CacheStorage = temp;
runFor(store);
}
}

[Benchmark]
Expand Down
43 changes: 43 additions & 0 deletions osu.Framework.Benchmarks/BenchmarkPiecewiseLinearToBezier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using osu.Framework.Utils;
using osuTK;

namespace osu.Framework.Benchmarks
{
public class BenchmarkPiecewiseLinearToBezier : BenchmarkTest
{
private Vector2[] inputPath = null!;

[Params(5, 25)]
public int NumControlPoints;

[Params(5, 200)]
public int NumTestPoints;

[Params(0, 100, 200)]
public int MaxIterations;

public override void SetUp()
{
base.SetUp();

Vector2[] points = new Vector2[5];
points[0] = new Vector2(50, 250);
points[1] = new Vector2(150, 230);
points[2] = new Vector2(100, 150);
points[3] = new Vector2(200, 80);
points[4] = new Vector2(250, 50);
inputPath = PathApproximator.LagrangePolynomialToPiecewiseLinear(points).ToArray();
}

[Benchmark]
public List<Vector2> PiecewiseLinearToBezier()
{
return PathApproximator.PiecewiseLinearToBezier(inputPath, NumControlPoints, NumTestPoints, MaxIterations);
}
}
}
2 changes: 1 addition & 1 deletion osu.Framework.Benchmarks/BenchmarkTextBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void initialiseBuilder(bool withDifferentBaselines)

private class TestStore : ITexturedGlyphLookupStore
{
public ITexturedCharacterGlyph Get(string fontName, char character) => new TexturedCharacterGlyph(
public ITexturedCharacterGlyph Get(string? fontName, char character) => new TexturedCharacterGlyph(
new CharacterGlyph(character, character, character, character, character, null),
new DummyRenderer().CreateTexture(1, 1));

Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified osu.Framework.NativeLibs/runtimes/linux-x64/native/libavutil.so
Binary file not shown.
Binary file modified osu.Framework.NativeLibs/runtimes/linux-x64/native/libswscale.so
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified osu.Framework.NativeLibs/runtimes/osx/native/libavutil.56.dylib
Binary file not shown.
Binary file modified osu.Framework.NativeLibs/runtimes/osx/native/libswscale.5.dylib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified osu.Framework.NativeLibs/runtimes/win-arm64/native/avutil-56.dll
Binary file not shown.
Binary file modified osu.Framework.NativeLibs/runtimes/win-arm64/native/swscale-5.dll
Binary file not shown.
Binary file modified osu.Framework.NativeLibs/runtimes/win-x64/native/avcodec-58.dll
Binary file not shown.
Binary file modified osu.Framework.NativeLibs/runtimes/win-x64/native/avformat-58.dll
Binary file not shown.
Binary file modified osu.Framework.NativeLibs/runtimes/win-x64/native/avutil-56.dll
Binary file not shown.
Binary file modified osu.Framework.NativeLibs/runtimes/win-x64/native/swscale-5.dll
Binary file not shown.
Binary file modified osu.Framework.NativeLibs/runtimes/win-x86/native/avcodec-58.dll
Binary file not shown.
Binary file modified osu.Framework.NativeLibs/runtimes/win-x86/native/avformat-58.dll
Binary file not shown.
Binary file modified osu.Framework.NativeLibs/runtimes/win-x86/native/avutil-56.dll
Binary file not shown.
Binary file modified osu.Framework.NativeLibs/runtimes/win-x86/native/swscale-5.dll
Binary file not shown.
13 changes: 9 additions & 4 deletions osu.Framework.NativeLibs/scripts/ffmpeg/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ FFMPEG_FLAGS=(
--enable-avformat
--enable-swscale

# File and video formats
--enable-demuxer='mov,matroska,flv,avi' # mov = mp4, matroska = mkv & webm
--enable-parser='mpeg4video,h264,hevc,vp8,vp9'
--enable-decoder='flv,mpeg4,h264,hevc,vp8,vp9'
# Legacy video formats
--enable-demuxer='avi,flv,asf'
--enable-parser='mpeg4video'
--enable-decoder='flv,msmpeg4v1,msmpeg4v2,msmpeg4v3,mpeg4,vp6,vp6f,wmv2'

# Modern video formats
--enable-demuxer='mov,matroska' # mov = mp4, matroska = mkv & webm
--enable-parser='h264,hevc,vp8,vp9'
--enable-decoder='h264,hevc,vp8,vp9'
--enable-protocol=pipe
)

Expand Down
8 changes: 8 additions & 0 deletions osu.Framework.Tests.Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<!--
READ_MEDIA_* permissions are available only on API 33 or greater. Devices with older android versions
don't understand the new permissions, so request the old READ_EXTERNAL_STORAGE permission to get storage access.
Since the old permission has no effect on >= API 33, don't request it.
Care needs to be taken to ensure runtime permission checks target the correct permission for the API level.
-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32"/>
</manifest>
9 changes: 2 additions & 7 deletions osu.Framework.Tests/Audio/AudioCollectionManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,27 @@ public void TestDisposalWhileItemsAreAddedDoesNotThrowInvalidOperationException(
{
var manager = new TestAudioCollectionManager();

var threadExecutionFinished = new ManualResetEventSlim();
var updateLoopStarted = new ManualResetEventSlim();

// add a huge amount of items to the queue
for (int i = 0; i < 10000; i++)
manager.AddItem(new TestingAdjustableAudioComponent());

// in a separate thread start processing the queue
var thread = new Thread(() =>
var thread = AudioTestHelper.StartNewAudioThread(() =>
{
while (!manager.IsDisposed)
{
updateLoopStarted.Set();
manager.Update();
}

threadExecutionFinished.Set();
});

thread.Start();

Assert.IsTrue(updateLoopStarted.Wait(10000));

Assert.DoesNotThrow(() => manager.Dispose());

Assert.IsTrue(threadExecutionFinished.Wait(10000));
thread.Dispose();
}

private class TestAudioCollectionManager : AudioCollectionManager<AdjustableAudioComponent>
Expand Down
65 changes: 65 additions & 0 deletions osu.Framework.Tests/Audio/AudioTestHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Runtime.ExceptionServices;
using System.Threading;
using osu.Framework.Allocation;
using osu.Framework.Development;
using osu.Framework.Threading;

namespace osu.Framework.Tests.Audio
{
internal static class AudioTestHelper
{
/// <summary>
/// Runs an <paramref name="action"/> on a newly created audio thread, and blocks until it has been run to completion.
/// </summary>
/// <param name="action">The action to run on the audio thread.</param>
public static void RunOnAudioThread(Action action)
{
using (var _ = StartNewAudioThread(action))
{
}
}

/// <summary>
/// Runs an <paramref name="action"/> on a newly created audio thread.
/// </summary>
/// <param name="action">The action to run on the audio thread.</param>
/// <returns>An <see cref="InvokeOnDisposal"/> that waits for the thread to stop and rethrows any unhandled exceptions thrown by the <paramref name="action"/>.</returns>
public static IDisposable StartNewAudioThread(Action action)
{
var resetEvent = new ManualResetEvent(false);
Exception? threadException = null;

new Thread(() =>
{
ThreadSafety.IsAudioThread = true;

try
{
action();
}
catch (Exception e)
{
threadException = e;
}

resetEvent.Set();
})
{
Name = GameThread.SuffixedThreadNameFor("Audio")
}.Start();

return new InvokeOnDisposal(() =>
{
if (!resetEvent.WaitOne(TimeSpan.FromSeconds(10)))
throw new TimeoutException();

if (threadException != null)
ExceptionDispatchInfo.Throw(threadException);
});
}
}
}
27 changes: 7 additions & 20 deletions osu.Framework.Tests/Audio/BassTestComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Threading;
using ManagedBass;
using osu.Framework.Audio;
using osu.Framework.Audio.Mixing.Bass;
Expand Down Expand Up @@ -78,32 +77,20 @@ public void Update()
RunOnAudioThread(() => allComponents.Update());
}

public void RunOnAudioThread(Action action)
{
var resetEvent = new ManualResetEvent(false);

new Thread(() =>
{
ThreadSafety.IsAudioThread = true;
action();
resetEvent.Set();
})
{
Name = GameThread.SuffixedThreadNameFor("Audio")
}.Start();

if (!resetEvent.WaitOne(TimeSpan.FromSeconds(10)))
throw new TimeoutException();
}
/// <summary>
/// Runs an <paramref name="action"/> on a newly created audio thread, and blocks until it has been run to completion.
/// </summary>
/// <param name="action">The action to run on the audio thread.</param>
public void RunOnAudioThread(Action action) => AudioTestHelper.RunOnAudioThread(action);

internal TrackBass GetTrack() => (TrackBass)TrackStore.Get("Resources.Tracks.sample-track.mp3");
internal SampleBass GetSample() => (SampleBass)SampleStore.Get("Resources.Tracks.sample-track.mp3");

public void Dispose()
public void Dispose() => RunOnAudioThread(() =>
{
allComponents.Dispose();
allComponents.Update(); // Actually runs the disposal.
Bass.Free();
}
});
}
}
31 changes: 1 addition & 30 deletions osu.Framework.Tests/Audio/SampleChannelVirtualTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@

#nullable disable

using System;
using System.Threading;
using NUnit.Framework;
using osu.Framework.Audio.Sample;
using osu.Framework.Development;
using osu.Framework.Threading;

namespace osu.Framework.Tests.Audio
{
Expand Down Expand Up @@ -56,31 +52,6 @@ public void TestLooping()
Assert.IsTrue(channel.HasCompleted);
}

private void updateSample() => RunOnAudioThread(() => sample.Update());

/// <summary>
/// Certain actions are invoked on the audio thread.
/// Here we simulate this process on a correctly named thread to avoid endless blocking.
/// </summary>
/// <param name="action">The action to perform.</param>
public static void RunOnAudioThread(Action action)
{
var resetEvent = new ManualResetEvent(false);

new Thread(() =>
{
ThreadSafety.IsAudioThread = true;

action();

resetEvent.Set();
})
{
Name = GameThread.SuffixedThreadNameFor("Audio")
}.Start();

if (!resetEvent.WaitOne(TimeSpan.FromSeconds(10)))
throw new TimeoutException();
}
private void updateSample() => AudioTestHelper.RunOnAudioThread(() => sample.Update());
}
}
Loading

0 comments on commit aff6271

Please sign in to comment.