Skip to content

Commit

Permalink
Move SpeedDemon interop out of the libass plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
9vult committed Sep 25, 2024
1 parent 0e06345 commit 1ad3178
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 15 deletions.
19 changes: 4 additions & 15 deletions Holo/Plugins/LibassSource.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AssCS;
using AssCS.IO;
using Holo.Utilities;
using LibassCS;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -46,17 +47,17 @@ public unsafe void DrawSubtitles(ref VideoFrame frame, long time)
{
// Copy frame data from copy
fixed (byte* ptr = frame.Copy)
SpeedDemon_External.CopyFrame(ptr, frame.Data, frame.Width * frame.Height * BGRA_WIDTH);
SpeedDemonNative.CopyFrame(ptr, frame.Data, frame.Width * frame.Height * BGRA_WIDTH);
}
else
{
// Copy frame data to copy
frame.Copy = new byte[frame.Width * frame.Height * BGRA_WIDTH];
fixed (byte* ptr = frame.Copy)
SpeedDemon_External.CopyFrame(frame.Data, ptr, frame.Width * frame.Height * BGRA_WIDTH);
SpeedDemonNative.CopyFrame(frame.Data, ptr, frame.Width * frame.Height * BGRA_WIDTH);
}

SpeedDemon_External.RenderSubs(frame.Data, frame.Width, frame.Height, image);
SpeedDemonNative.RenderSubs(frame.Data, frame.Width, frame.Height, image);
}

public void LoadSubtitles(File file, int time = -1)
Expand Down Expand Up @@ -126,17 +127,5 @@ public IDictionary<string, dynamic> GetProperties()
{
throw new NotImplementedException();
}

private partial class SpeedDemon_External
{
[LibraryImport("SpeedDemon", EntryPoint = "render_subs")]
public static unsafe partial void RenderSubs(IntPtr frameData, int width, int height, LibassCS.Structures.NativeImage* img);

[LibraryImport("SpeedDemon", EntryPoint = "copy_frame")]
public static unsafe partial void CopyFrame(IntPtr source, byte* destination, int size);

[LibraryImport("SpeedDemon", EntryPoint = "copy_frame")]
public static unsafe partial void CopyFrame(byte* source, IntPtr destination, int size);
}
}
}
22 changes: 22 additions & 0 deletions Holo/Utilities/SpeedDemonNative.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Runtime.InteropServices;

namespace Holo.Utilities
{
/// <summary>
/// This class houses the interop functions
/// for the native SpeedDemon C++ library
/// </summary>
/// <remarks>This class is not exposed</remarks>
internal partial class SpeedDemonNative
{
[LibraryImport("SpeedDemon", EntryPoint = "render_subs")]
public static unsafe partial void RenderSubs(IntPtr frameData, int width, int height, LibassCS.Structures.NativeImage* img);

[LibraryImport("SpeedDemon", EntryPoint = "copy_frame")]
public static unsafe partial void CopyFrame(IntPtr source, byte* destination, int size);

[LibraryImport("SpeedDemon", EntryPoint = "copy_frame")]
public static unsafe partial void CopyFrame(byte* source, IntPtr destination, int size);
}
}
28 changes: 28 additions & 0 deletions Wrappers/LibassCS/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BSD 3-Clause License

Copyright (c) 2024, 9volt and collaborators

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 changes: 28 additions & 0 deletions Wrappers/SpeedDemon/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BSD 3-Clause License

Copyright (c) 2024, 9volt and collaborators

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 changes: 14 additions & 0 deletions Wrappers/SpeedDemon/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SpeedDemon

This library houses C++ utility functions intended for use with Holo for performance reasons.

To build:

1. `mkdir build`
2. `cd build`
3. `cmake ..`
4. `cmake --build .`

Place the resulting dynamic library in the execution directory for Ameko.Desktop.

SpeedDemon is licensed under the BSD 3-clause license.

0 comments on commit 1ad3178

Please sign in to comment.