Skip to content

Commit

Permalink
rem - Got rid of net8.0-windows version
Browse files Browse the repository at this point in the history
---

We've removed the Windows-exclusive build of BassBoom native helper library by making additional structures suffixed with "_win" indicating that it's exclusive to Windows. This reduces the maintenance burden.

---

Type: rem
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Jan 17, 2024
1 parent a13fcc7 commit 3b70f1e
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 65 deletions.
2 changes: 1 addition & 1 deletion BassBoom.Basolia/BassBoom.Basolia.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0-windows;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>BassBoom.Basolia</PackageId>
Expand Down
96 changes: 72 additions & 24 deletions BassBoom.Basolia/Format/AudioInfoTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,35 +432,83 @@ public static FrameInfo GetFrameInfo()
// Check to see if we're playing
if (PlaybackTools.Playing)
throw new BasoliaException("Trying to get the frame information during playback causes playback corruption! Don't call this function during playback.", mpg123_errors.MPG123_ERR_READER);

mpg123_frameinfo frameInfo = default;
unsafe

// Some variables
mpg123_version version;
int layer;
long rate;
mpg123_mode mode;
int mode_ext;
int framesize;
mpg123_flags flags;
int emphasis;
int bitrate;
int abr_rate;
mpg123_vbr vbr;

// In Windows, the "long" rate byte number differs from the Linux version.
if (PlatformTools.IsOnWindows())
{
var handle = Mpg123Instance._mpg123Handle;
mpg123_frameinfo_win frameInfo = default;
unsafe
{
var handle = Mpg123Instance._mpg123Handle;

// We need to scan the file to get accurate info
int scanStatus = NativeStatus.mpg123_scan(handle);
if (scanStatus == (int)mpg123_errors.MPG123_ERR)
throw new BasoliaException("Can't scan file for frame information", mpg123_errors.MPG123_ERR);
// We need to scan the file to get accurate info
int scanStatus = NativeStatus.mpg123_scan(handle);
if (scanStatus == (int)mpg123_errors.MPG123_ERR)
throw new BasoliaException("Can't scan file for frame information", mpg123_errors.MPG123_ERR);

// Now, get the frame info.
int getStatus = NativeStatus.mpg123_info(handle, ref frameInfo);
if (getStatus != (int)mpg123_errors.MPG123_OK)
throw new BasoliaException("Can't get frame information", (mpg123_errors)getStatus);
// Now, get the frame info.
int getStatus = NativeStatus.mpg123_info_win(handle, ref frameInfo);
if (getStatus != (int)mpg123_errors.MPG123_OK)
throw new BasoliaException("Can't get frame information", (mpg123_errors)getStatus);
}

// Move every info to the class
version = frameInfo.version;
layer = frameInfo.layer;
rate = frameInfo.rate;
mode = frameInfo.mode;
mode_ext = frameInfo.mode_ext;
framesize = frameInfo.framesize;
flags = frameInfo.flags;
emphasis = frameInfo.emphasis;
bitrate = frameInfo.bitrate;
abr_rate = frameInfo.abr_rate;
vbr = frameInfo.vbr;
}
else
{
mpg123_frameinfo frameInfo = default;
unsafe
{
var handle = Mpg123Instance._mpg123Handle;

// Move every info to the class
mpg123_version version = frameInfo.version;
int layer = frameInfo.layer;
long rate = frameInfo.rate;
mpg123_mode mode = frameInfo.mode;
int mode_ext = frameInfo.mode_ext;
int framesize = frameInfo.framesize;
mpg123_flags flags = frameInfo.flags;
int emphasis = frameInfo.emphasis;
int bitrate = frameInfo.bitrate;
int abr_rate = frameInfo.abr_rate;
mpg123_vbr vbr = frameInfo.vbr;
// We need to scan the file to get accurate info
int scanStatus = NativeStatus.mpg123_scan(handle);
if (scanStatus == (int)mpg123_errors.MPG123_ERR)
throw new BasoliaException("Can't scan file for frame information", mpg123_errors.MPG123_ERR);

// Now, get the frame info.
int getStatus = NativeStatus.mpg123_info(handle, ref frameInfo);
if (getStatus != (int)mpg123_errors.MPG123_OK)
throw new BasoliaException("Can't get frame information", (mpg123_errors)getStatus);
}

// Move every info to the class
version = frameInfo.version;
layer = frameInfo.layer;
rate = frameInfo.rate;
mode = frameInfo.mode;
mode_ext = frameInfo.mode_ext;
framesize = frameInfo.framesize;
flags = frameInfo.flags;
emphasis = frameInfo.emphasis;
bitrate = frameInfo.bitrate;
abr_rate = frameInfo.abr_rate;
vbr = frameInfo.vbr;
}
var frameInfoInstance = new FrameInfo(version, layer, rate, mode, mode_ext, framesize, flags, emphasis, bitrate, abr_rate, vbr);
return frameInfoInstance;
}
Expand Down
25 changes: 21 additions & 4 deletions BassBoom.Basolia/Format/FormatTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,27 @@ public static FormatInfo[] GetFormats()
// Now, iterate through the list of supported formats
for (int i = 0; i < getStatus; i++)
{
var fmtStruct = Marshal.PtrToStructure<mpg123_fmt>(fmtlist);
long rate = fmtStruct.rate;
int channels = fmtStruct.channels;
int encoding = fmtStruct.encoding;
long rate = 0;
int channels = 0;
int encoding = 0;

// The "long" rate is different on our Windows compilations than on Linux compilations.
if (PlatformTools.IsOnWindows())
{
var fmtStruct = Marshal.PtrToStructure<mpg123_fmt_win>(fmtlist);
rate = fmtStruct.rate;
channels = fmtStruct.channels;
encoding = fmtStruct.encoding;
}
else
{
var fmtStruct = Marshal.PtrToStructure<mpg123_fmt>(fmtlist);
rate = fmtStruct.rate;
channels = fmtStruct.channels;
encoding = fmtStruct.encoding;
}

// Check the validity of the three values
if (rate >= 0 && channels >= 0 && encoding >= 0)
{
var fmtInstance = new FormatInfo(rate, channels, encoding);
Expand Down
2 changes: 1 addition & 1 deletion BassBoom.Cli/BassBoom.Cli.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0-windows;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\aptivi_snk.snk</AssemblyOriginatorKeyFile>
Expand Down
2 changes: 1 addition & 1 deletion BassBoom.Desktop/BassBoom.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<OutputType>Exe</OutputType>
<!--If you are willing to use Windows/MacOS native APIs you will need to create 3 projects.
One for Windows with net8.0-windows TFM, one for MacOS with net8.0-macos and one with net8.0 TFM for Linux.-->
<TargetFrameworks>net8.0-windows;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
Expand Down
2 changes: 1 addition & 1 deletion BassBoom.Native/BassBoom.Native.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0-windows;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Nullable>disable</Nullable>
Expand Down
11 changes: 7 additions & 4 deletions BassBoom.Native/Interop/Analysis/NativeFormats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ public enum mpg123_enc_enum

public unsafe struct mpg123_fmt
{
#if WINDOWS
internal int rate;
#else
internal long rate;
#endif
internal int channels;
internal int encoding;
}

public unsafe struct mpg123_fmt_win
{
internal int rate;
internal int channels;
internal int encoding;
}
Expand Down
52 changes: 44 additions & 8 deletions BassBoom.Native/Interop/Analysis/NativeStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,43 @@ public enum mpg123_state
}

[StructLayout(LayoutKind.Sequential)]
public struct mpg123_frameinfo
public struct mpg123_frameinfo_win
{
internal mpg123_version version;
internal int layer;
#if WINDOWS
internal int rate;
#else
internal mpg123_mode mode;
internal int mode_ext;
internal int framesize;
internal mpg123_flags flags;
internal int emphasis;
internal int bitrate;
internal int abr_rate;
internal mpg123_vbr vbr;
}

[StructLayout(LayoutKind.Sequential)]
public struct mpg123_frameinfo2_win
{
internal int version;
internal int layer;
internal int rate;
internal int mode;
internal int mode_ext;
internal int framesize;
internal int flags;
internal int emphasis;
internal int bitrate;
internal int abr_rate;
internal int vbr;
}

[StructLayout(LayoutKind.Sequential)]
public struct mpg123_frameinfo
{
internal mpg123_version version;
internal int layer;
internal long rate;
#endif
internal mpg123_mode mode;
internal int mode_ext;
internal int framesize;
Expand All @@ -88,11 +116,7 @@ public struct mpg123_frameinfo2
{
internal int version;
internal int layer;
#if WINDOWS
internal int rate;
#else
internal long rate;
#endif
internal int mode;
internal int mode_ext;
internal int framesize;
Expand Down Expand Up @@ -120,6 +144,18 @@ public static unsafe class NativeStatus
[DllImport(LibraryTools.LibraryName, CharSet = CharSet.Ansi)]
internal static extern int mpg123_info2(mpg123_handle* mh, ref mpg123_frameinfo2 mi);

/// <summary>
/// MPG123_EXPORT int mpg123_info(mpg123_handle *mh, struct mpg123_frameinfo *mi);
/// </summary>
[DllImport(LibraryTools.LibraryName, CharSet = CharSet.Ansi, EntryPoint = "mpg123_info")]
internal static extern int mpg123_info_win(mpg123_handle* mh, ref mpg123_frameinfo_win mi);

/// <summary>
/// MPG123_EXPORT int mpg123_info2(mpg123_handle *mh, struct mpg123_frameinfo2 *mi);
/// </summary>
[DllImport(LibraryTools.LibraryName, CharSet = CharSet.Ansi, EntryPoint = "mpg123_info2")]
internal static extern int mpg123_info2_win(mpg123_handle* mh, ref mpg123_frameinfo2_win mi);

/// <summary>
/// MPG123_EXPORT size_t mpg123_safe_buffer(void);
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion BassBoom/BassBoom.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0-windows;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>disable</Nullable>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
Expand Down
10 changes: 0 additions & 10 deletions tools/pack.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ echo Packing binary...
"%ProgramFiles%\7-Zip\7z.exe" a -tzip %temp%/%version%-proto.zip "..\BassBoom.Desktop\bin\%releaseconfig%\net8.0\*"
"%ProgramFiles%\7-Zip\7z.exe" a -tzip %temp%/%version%-protocli.zip "..\BassBoom.Cli\bin\%releaseconfig%\net8.0\*"
"%ProgramFiles%\7-Zip\7z.exe" a -tzip %temp%/%version%-unsafeapi.zip "..\BassBoom.Native\bin\%releaseconfig%\net8.0\*"
"%ProgramFiles%\7-Zip\7z.exe" a -tzip %temp%/%version%-bin-win.zip "..\BassBoom\bin\%releaseconfig%\net8.0-windows\*"
"%ProgramFiles%\7-Zip\7z.exe" a -tzip %temp%/%version%-api-win.zip "..\BassBoom.Basolia\bin\%releaseconfig%\net8.0-windows\*"
"%ProgramFiles%\7-Zip\7z.exe" a -tzip %temp%/%version%-proto-win.zip "..\BassBoom.Desktop\bin\%releaseconfig%\net8.0-windows\*"
"%ProgramFiles%\7-Zip\7z.exe" a -tzip %temp%/%version%-protocli-win.zip "..\BassBoom.Cli\bin\%releaseconfig%\net8.0-windows\*"
"%ProgramFiles%\7-Zip\7z.exe" a -tzip %temp%/%version%-unsafeapi-win.zip "..\BassBoom.Native\bin\%releaseconfig%\net8.0-windows\*"
if %errorlevel% == 0 goto :complete
echo There was an error trying to pack binary (%errorlevel%).
goto :finished
Expand All @@ -43,11 +38,6 @@ move %temp%\%version%-api.zip
move %temp%\%version%-proto.zip
move %temp%\%version%-protocli.zip
move %temp%\%version%-unsafeapi.zip
move %temp%\%version%-bin-win.zip
move %temp%\%version%-api-win.zip
move %temp%\%version%-proto-win.zip
move %temp%\%version%-protocli-win.zip
move %temp%\%version%-unsafeapi-win.zip

echo Pack successful.
:finished
11 changes: 1 addition & 10 deletions tools/pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ cd "../BassBoom.Basolia/bin/$releaseconf/net8.0/" && "$zippath" -r /tmp/$version
cd "../BassBoom/bin.Desktop/$releaseconf/net8.0/" && "$zippath" -r /tmp/$version-proto.zip . && cd -
cd "../BassBoom/bin.Cli/$releaseconf/net8.0/" && "$zippath" -r /tmp/$version-protocli.zip . && cd -
cd "../BassBoom/bin.Native/$releaseconf/net8.0/" && "$zippath" -r /tmp/$version-unsafeapi.zip . && cd -
cd "../BassBoom/bin/$releaseconf/net8.0-windows/" && "$zippath" -r /tmp/$version-bin-win.zip . && cd -
cd "../BassBoom.Basolia/bin/$releaseconf/net8.0-windows/" && "$zippath" -r /tmp/$version-api-win.zip . && cd -
cd "../BassBoom/bin.Desktop/$releaseconf/net8.0-windows/" && "$zippath" -r /tmp/$version-proto-win.zip . && cd -
cd "../BassBoom/bin.Cli/$releaseconf/net8.0-windows/" && "$zippath" -r /tmp/$version-protocli-win.zip . && cd -
cd "../BassBoom/bin.Native/$releaseconf/net8.0-windows/" && "$zippath" -r /tmp/$version-unsafeapi-win.zip . && cd -
if [ ! $? == 0 ]; then
echo Packing using zip failed.
exit 1
Expand All @@ -52,11 +47,7 @@ fi
mv ~/tmp/$version-bin.zip .
mv ~/tmp/$version-api.zip .
mv ~/tmp/$version-proto.zip .
mv ~/tmp/$version-protocli.zip .
mv ~/tmp/$version-unsafeapi.zip .
mv ~/tmp/$version-bin-win.zip .
mv ~/tmp/$version-api-win.zip .
mv ~/tmp/$version-proto-win.zip .
mv ~/tmp/$version-protocli-win.zip .
mv ~/tmp/$version-unsafeapi-win.zip .
echo Build and pack successful.
exit 0

0 comments on commit 3b70f1e

Please sign in to comment.