Skip to content

Commit

Permalink
ref - Refactored native library tools
Browse files Browse the repository at this point in the history
---

Type: ref
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed May 31, 2024
1 parent 4bd7edb commit 9a77835
Show file tree
Hide file tree
Showing 24 changed files with 295 additions and 358 deletions.
8 changes: 4 additions & 4 deletions BassBoom.Basolia/Devices/DeviceTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
//

using BassBoom.Basolia.Helpers;
using BassBoom.Native;
using BassBoom.Native.Interop.Init;
using BassBoom.Native.Interop.Output;
using BassBoom.Native.Runtime;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -53,7 +53,7 @@ public static ReadOnlyDictionary<string, string> GetDrivers()
unsafe
{
// Query the drivers
var handle = Mpg123Instance._out123Handle;
var handle = MpgNative._out123Handle;
int driversStatus = NativeOutputLib.out123_drivers(handle, ref names, ref descr);
if (driversStatus == (int)mpg123_errors.MPG123_ERR)
throw new BasoliaException("Can't query the drivers", mpg123_errors.MPG123_ERR);
Expand Down Expand Up @@ -93,7 +93,7 @@ public static ReadOnlyDictionary<string, string> GetDevices(string driver, ref s
unsafe
{
// Query the devices
var handle = Mpg123Instance._out123Handle;
var handle = MpgNative._out123Handle;
int devicesStatus = NativeOutputLib.out123_devices(handle, driver, out names, out descr, ref active);
if (devicesStatus == (int)mpg123_errors.MPG123_ERR)
throw new BasoliaException("Can't query the devices", mpg123_errors.MPG123_ERR);
Expand Down Expand Up @@ -126,7 +126,7 @@ public static (string driver, string device) GetCurrent()
unsafe
{
// Query the devices
var handle = Mpg123Instance._out123Handle;
var handle = MpgNative._out123Handle;
IntPtr driverPtr = IntPtr.Zero;
IntPtr devicePtr = IntPtr.Zero;
int devicesStatus = NativeOutputLib.out123_driver_info(handle, ref driverPtr, ref devicePtr);
Expand Down
8 changes: 4 additions & 4 deletions BassBoom.Basolia/File/FileTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

using BassBoom.Basolia.Playback;
using BassBoom.Basolia.Radio;
using BassBoom.Native;
using BassBoom.Native.Interop.Init;
using BassBoom.Native.Interop.Play;
using BassBoom.Native.Runtime;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
Expand Down Expand Up @@ -92,7 +92,7 @@ public static void OpenFile(string path)
unsafe
{
// Open the file
var handle = Mpg123Instance._mpg123Handle;
var handle = MpgNative._mpg123Handle;
int openStatus = NativeInput.mpg123_open(handle, path);
if (openStatus == (int)mpg123_errors.MPG123_ERR)
throw new BasoliaException("Can't open file", mpg123_errors.MPG123_ERR);
Expand Down Expand Up @@ -143,7 +143,7 @@ public static async Task OpenUrlAsync(string path)
unsafe
{
// Open the radio station
var handle = Mpg123Instance._mpg123Handle;
var handle = MpgNative._mpg123Handle;
int openStatus = NativeInput.mpg123_open_feed(handle);
if (openStatus == (int)mpg123_errors.MPG123_ERR)
throw new BasoliaException("Can't open radio station", mpg123_errors.MPG123_ERR);
Expand Down Expand Up @@ -175,7 +175,7 @@ public static void CloseFile()
unsafe
{
// Close the file
var handle = Mpg123Instance._mpg123Handle;
var handle = MpgNative._mpg123Handle;
int closeStatus = NativeInput.mpg123_close(handle);
if (closeStatus == (int)mpg123_errors.MPG123_ERR)
throw new BasoliaException("Can't close file", mpg123_errors.MPG123_ERR);
Expand Down
20 changes: 10 additions & 10 deletions BassBoom.Basolia/Format/AudioInfoTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using BassBoom.Native.Runtime;
using BassBoom.Native.Interop.Analysis;
using BassBoom.Native.Interop.Init;
using BassBoom.Basolia.File;
Expand All @@ -31,6 +30,7 @@
using System.Linq;
using SpecProbe.Platform;
using BassBoom.Basolia.Enumerations;
using BassBoom.Native;

namespace BassBoom.Basolia.Format
{
Expand Down Expand Up @@ -64,7 +64,7 @@ public static int GetDuration(bool scan)
// We're now entering the dangerous zone
unsafe
{
var handle = Mpg123Instance._mpg123Handle;
var handle = MpgNative._mpg123Handle;
if (scan)
{
lock (PlaybackPositioningTools.PositionLock)
Expand Down Expand Up @@ -145,7 +145,7 @@ public static int GetFrameSize()

unsafe
{
var outHandle = Mpg123Instance._out123Handle;
var outHandle = MpgNative._out123Handle;

// Get the output format to get the frame size
int getStatus = NativeOutputLib.out123_getformat(outHandle, null, null, null, out frameSize);
Expand All @@ -172,7 +172,7 @@ public static int GetFrameLength()

unsafe
{
var handle = Mpg123Instance._mpg123Handle;
var handle = MpgNative._mpg123Handle;

// Get the frame length
getStatus = NativeStatus.mpg123_framelength(handle);
Expand All @@ -199,7 +199,7 @@ public static int GetSamplesPerFrame()

unsafe
{
var handle = Mpg123Instance._mpg123Handle;
var handle = MpgNative._mpg123Handle;

// Get the samples per frame
getStatus = NativeStatus.mpg123_spf(handle);
Expand All @@ -226,7 +226,7 @@ public static int GetBufferSize()

unsafe
{
var handle = Mpg123Instance._mpg123Handle;
var handle = MpgNative._mpg123Handle;

// Now, buffer the entire music file and create an empty array based on its size
bufferSize = NativeLowIo.mpg123_outblock(handle);
Expand Down Expand Up @@ -257,7 +257,7 @@ public static void GetId3Metadata(out Id3V1Metadata managedV1, out Id3V2Metadata
IntPtr v2 = IntPtr.Zero;
unsafe
{
var handle = Mpg123Instance._mpg123Handle;
var handle = MpgNative._mpg123Handle;

// We need to scan the file to get accurate info
if (!FileTools.IsRadioStation)
Expand Down Expand Up @@ -410,7 +410,7 @@ public static string GetIcyMetadata()
string icy = "";
unsafe
{
var handle = Mpg123Instance._mpg123Handle;
var handle = MpgNative._mpg123Handle;

// We need to scan the file to get accurate info
if (!FileTools.IsRadioStation)
Expand Down Expand Up @@ -464,7 +464,7 @@ public static FrameInfo GetFrameInfo()
mpg123_frameinfo_win frameInfo = default;
unsafe
{
var handle = Mpg123Instance._mpg123Handle;
var handle = MpgNative._mpg123Handle;

// We need to scan the file to get accurate info, but it only works with files
if (!FileTools.IsRadioStation)
Expand Down Expand Up @@ -498,7 +498,7 @@ public static FrameInfo GetFrameInfo()
mpg123_frameinfo frameInfo = default;
unsafe
{
var handle = Mpg123Instance._mpg123Handle;
var handle = MpgNative._mpg123Handle;

// We need to scan the file to get accurate info
if (!FileTools.IsRadioStation)
Expand Down
8 changes: 4 additions & 4 deletions BassBoom.Basolia/Format/DecodeTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

using BassBoom.Basolia.File;
using BassBoom.Basolia.Helpers;
using BassBoom.Native;
using BassBoom.Native.Interop.Init;
using BassBoom.Native.Interop.Play;
using BassBoom.Native.Runtime;
using System;
using System.Linq;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -60,7 +60,7 @@ public static int DecodeFrame(ref int num, ref byte[] audio, ref int bytes)
// We're now entering the dangerous zone
unsafe
{
var handle = Mpg123Instance._mpg123Handle;
var handle = MpgNative._mpg123Handle;

// Get the frame
IntPtr numPtr, bytesPtr, audioPtr = IntPtr.Zero;
Expand Down Expand Up @@ -110,7 +110,7 @@ private static string GetCurrentDecoder()
// Try to set the equalizer value
unsafe
{
var handle = Mpg123Instance._mpg123Handle;
var handle = MpgNative._mpg123Handle;
IntPtr decoderPtr = NativeDecoder.mpg123_current_decoder(handle);
return Marshal.PtrToStringAnsi(decoderPtr);
}
Expand All @@ -129,7 +129,7 @@ private static void SetCurrentDecoder(string decoderName)
string[] supportedDecoders = GetDecoders(true);
if (!supportedDecoders.Contains(decoderName))
throw new BasoliaException($"Decoder {decoderName} not supported by your device", mpg123_errors.MPG123_BAD_DECODER);
var handle = Mpg123Instance._mpg123Handle;
var handle = MpgNative._mpg123Handle;
int status = NativeDecoder.mpg123_decoder(handle, decoderName);
if (status != (int)mpg123_errors.MPG123_OK)
throw new BasoliaException($"Can't set decoder to {decoderName}", (mpg123_errors)status);
Expand Down
6 changes: 3 additions & 3 deletions BassBoom.Basolia/Format/FormatTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using BassBoom.Native.Runtime;
using BassBoom.Native.Interop.Play;
using BassBoom.Native.Interop.Init;
using System;
Expand All @@ -26,6 +25,7 @@
using System.Runtime.InteropServices;
using BassBoom.Native.Interop.Analysis;
using SpecProbe.Platform;
using BassBoom.Native;

namespace BassBoom.Basolia.Format
{
Expand All @@ -45,7 +45,7 @@ public static (long rate, int channels, int encoding) GetFormatInfo()
// We're now entering the dangerous zone
unsafe
{
var handle = Mpg123Instance._mpg123Handle;
var handle = MpgNative._mpg123Handle;

// Get the rate, the number of channels, and encoding
int length = NativeOutput.mpg123_getformat(handle, out fileRate, out fileChannel, out fileEncoding);
Expand All @@ -69,7 +69,7 @@ public static FormatInfo[] GetFormats()
nint fmtlist = IntPtr.Zero;
unsafe
{
var outHandle = Mpg123Instance._out123Handle;
var outHandle = MpgNative._out123Handle;

// Get the list of supported formats
getStatus = NativeOutputLib.out123_formats(outHandle, IntPtr.Zero, 0, 0, 0, ref fmtlist);
Expand Down
17 changes: 8 additions & 9 deletions BassBoom.Basolia/InitBasolia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using BassBoom.Native.Interop;
using BassBoom.Native;
using BassBoom.Native.Interop.Init;
using BassBoom.Native.Interop.Output;
using BassBoom.Native.Runtime;
using System;
using System.Reflection;

Expand Down Expand Up @@ -48,7 +47,7 @@ public static Version MpgLibVersion
{
if (!BasoliaInitialized)
throw new BasoliaException("Can't get version until the library is initialized", mpg123_errors.MPG123_NOT_INITIALIZED);
return LibraryTools.MpgLibVersion;
return MpgNative.MpgLibVersion;
}
}

Expand All @@ -61,7 +60,7 @@ public static Version OutLibVersion
{
if (!BasoliaInitialized)
throw new BasoliaOutException("Can't get version until the library is initialized", out123_error.OUT123_ERR);
return LibraryTools.OutLibVersion;
return MpgNative.OutLibVersion;
}
}

Expand All @@ -78,13 +77,13 @@ public static Version OutLibVersion
public static void Init(string root = "")
{
if (string.IsNullOrEmpty(root))
Mpg123Instance.InitializeLibrary();
MpgNative.InitializeLibrary();
else
{
string mpg = Mpg123Instance.GetAppropriateMpg123LibraryPath(root);
string @out = Mpg123Instance.GetAppropriateOut123LibraryPath(root);
string pthreads = Mpg123Instance.GetAppropriateWinpthreadsLibraryPath(root);
Mpg123Instance.InitializeLibrary(mpg, @out, pthreads);
string mpg = MpgNative.GetAppropriateMpg123LibraryPath(root);
string @out = MpgNative.GetAppropriateOut123LibraryPath(root);
string pthreads = MpgNative.GetAppropriateWinpthreadsLibraryPath(root);
MpgNative.InitializeLibrary(mpg, @out, pthreads);
}
_basoliaInited = true;
}
Expand Down
14 changes: 7 additions & 7 deletions BassBoom.Basolia/Playback/PlaybackPositioningTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
using BassBoom.Native.Interop.Init;
using BassBoom.Native.Interop.Play;
using BassBoom.Native.Interop.Output;
using BassBoom.Native.Runtime;
using System;
using System.Threading;
using BassBoom.Basolia.Lyrics;
using BassBoom.Native;

namespace BassBoom.Basolia.Playback
{
Expand All @@ -51,7 +51,7 @@ public static int GetCurrentDuration()
// We're now entering the dangerous zone
unsafe
{
var handle = Mpg123Instance._mpg123Handle;
var handle = MpgNative._mpg123Handle;

// Get the length
length = NativePositioning.mpg123_tell(handle);
Expand Down Expand Up @@ -95,8 +95,8 @@ public static void SeekToTheBeginning()
// We're now entering the dangerous zone
unsafe
{
var handle = Mpg123Instance._mpg123Handle;
var outHandle = Mpg123Instance._out123Handle;
var handle = MpgNative._mpg123Handle;
var outHandle = MpgNative._out123Handle;

// Get the length
PlaybackTools.holding = true;
Expand Down Expand Up @@ -128,8 +128,8 @@ public static void SeekToFrame(int frame)
// We're now entering the dangerous zone
unsafe
{
var handle = Mpg123Instance._mpg123Handle;
var outHandle = Mpg123Instance._out123Handle;
var handle = MpgNative._mpg123Handle;
var outHandle = MpgNative._out123Handle;

// Get the length
PlaybackTools.holding = true;
Expand Down Expand Up @@ -185,7 +185,7 @@ public static void Drop()
// We're now entering the dangerous zone
unsafe
{
var outHandle = Mpg123Instance._out123Handle;
var outHandle = MpgNative._out123Handle;
NativeOutputLib.out123_drop(outHandle);
}
}
Expand Down
Loading

0 comments on commit 9a77835

Please sign in to comment.