2020-08-18 03:49:37 +02:00
|
|
|
using Ryujinx.Audio.Renderer.Parameter;
|
Audio rendering: reduce memory allocations (#6604)
* - WritableRegion: enable wrapping IMemoryOwner<byte>
- IVirtualMemoryManager impls of GetWritableRegion() use pooled memory when region is non-contiguous.
- IVirtualMemoryManager: add GetReadOnlySequence() and impls
- ByteMemoryPool: add new method RentCopy()
- ByteMemoryPool: make class static, remove ctor and singleton field from earlier impl
* - BytesReadOnlySequenceSegment: move from Ryujinx.Common.Memory to Ryujinx.Memory
- BytesReadOnlySequenceSegment: add IsContiguousWith() and Replace() methods
- VirtualMemoryManagerBase:
- remove generic type parameters, instead use ulong for virtual addresses and nuint for host/physical addresses
- implement IWritableBlock
- add virtual GetReadOnlySequence() with coalescing of contiguous segments
- add virtual GetSpan()
- add virtual GetWritableRegion()
- add abstract IsMapped()
- add virtual MapForeign(ulong, nuint, ulong)
- add virtual Read<T>()
- add virtual Read(ulong, Span<byte>)
- add virtual ReadTracked<T>()
- add virtual SignalMemoryTracking()
- add virtual Write()
- add virtual Write<T>()
- add virtual WriteUntracked()
- add virtual WriteWithRedundancyCheck()
- VirtualMemoryManagerRefCountedBase: remove generic type parameters
- AddressSpaceManager: remove redundant methods, add required overrides
- HvMemoryManager: remove redundant methods, add required overrides, add overrides for _invalidAccessHandler handling
- MemoryManager: remove redundant methods, add required overrides, add overrides for _invalidAccessHandler handling
- MemoryManagerHostMapped: remove redundant methods, add required overrides, add overrides for _invalidAccessHandler handling
- NativeMemoryManager: add get properties for Pointer and Length
- throughout: removed invalid <inheritdoc/> comments
* - WritableRegion: enable wrapping IMemoryOwner<byte>
- IVirtualMemoryManager impls of GetWritableRegion() use pooled memory when region is non-contiguous.
- IVirtualMemoryManager: add GetReadOnlySequence() and impls
- ByteMemoryPool: add new method RentCopy()
- ByteMemoryPool: make class static, remove ctor and singleton field from earlier impl
* add PagedMemoryRange enumerator types, use them in IVirtualMemoryManager implementations to consolidate page-handling logic and add a new capability - the coalescing of pages for consolidating memory copies and segmentation.
* new: more tests for PagedMemoryRangeCoalescingEnumerator showing coalescing of contiguous segments
* make some struct properties readonly
* put braces around `foreach` bodies
* encourage inlining of some PagedMemoryRange*Enumerator members
* DynamicRingBuffer:
- use ByteMemoryPool
- make some methods return without locking when size/count argument = 0
- make generic Read<T>()/Write<T>() non-generic because its only usage is as T = byte
- change Read(byte[]...) to Read(Span<byte>...)
- change Write(byte[]...) to Write(Span<byte>...)
* change IAudioRenderer.RequestUpdate() to take a ReadOnlySequence<byte>, enabling zero-copy audio rendering
* HipcGenerator: support ReadOnlySequence<byte> as IPC method parameter
* change IAudioRenderer/AudioRenderer RequestUpdate* methods to take input as ReadOnlySequence<byte>
* MemoryManagerHostTracked: use rented memory when contiguous in `GetWritableRegion()`
* rebase cleanup
* dotnet format fixes
* format and comment fixes
* format long parameter list - take 2
* - add support to HipcGenerator for buffers of type `Memory<byte>`
- change `AudioRenderer` `RequestUpdate()` and `RequestUpdateAuto()` to use Memory<byte> for output buffers, removing another memory block allocation/copy
* SplitterContext `UpdateState()` and `UpdateData()` smooth out advance/rewind logic, only rewind if magic is invalid
* DynamicRingBuffer.Write(): change Span<byte> to ReadOnlySpan<byte>
2024-04-07 17:07:32 -04:00
|
|
|
using Ryujinx.Common.Extensions;
|
2020-08-18 03:49:37 +02:00
|
|
|
using System;
|
|
|
|
|
using System.Buffers;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Audio.Renderer.Server.Splitter
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Server state for a splitter.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Size = 0x20, Pack = Alignment)]
|
|
|
|
|
public struct SplitterState
|
|
|
|
|
{
|
|
|
|
|
public const int Alignment = 0x10;
|
|
|
|
|
|
2024-05-17 16:46:43 -03:00
|
|
|
private delegate void SplitterDestinationAction(SplitterDestination destination, int index);
|
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// The unique id of this <see cref="SplitterState"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Id;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Target sample rate to use on the splitter.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public uint SampleRate;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-17 16:46:43 -03:00
|
|
|
/// Count of splitter destinations.
|
2020-08-18 03:49:37 +02:00
|
|
|
/// </summary>
|
|
|
|
|
public int DestinationCount;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Set to true if the splitter has a new connection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[MarshalAs(UnmanagedType.I1)]
|
|
|
|
|
public bool HasNewConnection;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-17 16:46:43 -03:00
|
|
|
/// Linked list of <see cref="SplitterDestinationVersion1"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private unsafe SplitterDestinationVersion1* _destinationDataV1;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Linked list of <see cref="SplitterDestinationVersion2"/>.
|
2020-08-18 03:49:37 +02:00
|
|
|
/// </summary>
|
2024-05-17 16:46:43 -03:00
|
|
|
private unsafe SplitterDestinationVersion2* _destinationDataV2;
|
2020-08-18 03:49:37 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-17 16:46:43 -03:00
|
|
|
/// First element of the linked list of splitter destinations data.
|
2020-08-18 03:49:37 +02:00
|
|
|
/// </summary>
|
2024-05-17 16:46:43 -03:00
|
|
|
public readonly SplitterDestination Destination
|
2020-08-18 03:49:37 +02:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
unsafe
|
|
|
|
|
{
|
2024-05-17 16:46:43 -03:00
|
|
|
return new SplitterDestination(_destinationDataV1, _destinationDataV2);
|
2020-08-18 03:49:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a new <see cref="SplitterState"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">The unique id of this <see cref="SplitterState"/>.</param>
|
|
|
|
|
public SplitterState(int id) : this()
|
|
|
|
|
{
|
|
|
|
|
Id = id;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 16:46:43 -03:00
|
|
|
public readonly SplitterDestination GetData(int index)
|
2020-08-18 03:49:37 +02:00
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
2024-05-17 16:46:43 -03:00
|
|
|
SplitterDestination result = Destination;
|
2020-08-18 03:49:37 +02:00
|
|
|
|
|
|
|
|
while (i < index)
|
|
|
|
|
{
|
2024-05-17 16:46:43 -03:00
|
|
|
if (result.IsNull)
|
2020-08-18 03:49:37 +02:00
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 16:46:43 -03:00
|
|
|
result = result.Next;
|
2020-08-18 03:49:37 +02:00
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Clear the new connection flag.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ClearNewConnectionFlag()
|
|
|
|
|
{
|
|
|
|
|
HasNewConnection = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-17 16:46:43 -03:00
|
|
|
/// Utility function to apply an action to all <see cref="Destination"/>.
|
2020-08-18 03:49:37 +02:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="action">The action to execute on each elements.</param>
|
2024-05-17 16:46:43 -03:00
|
|
|
private readonly void ForEachDestination(SplitterDestinationAction action)
|
2020-08-18 03:49:37 +02:00
|
|
|
{
|
2024-05-17 16:46:43 -03:00
|
|
|
SplitterDestination temp = Destination;
|
2020-08-18 03:49:37 +02:00
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
2024-05-17 16:46:43 -03:00
|
|
|
if (temp.IsNull)
|
2020-08-18 03:49:37 +02:00
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 16:46:43 -03:00
|
|
|
SplitterDestination next = temp.Next;
|
2020-08-18 03:49:37 +02:00
|
|
|
|
2024-05-17 16:46:43 -03:00
|
|
|
action(temp, i++);
|
2020-08-18 03:49:37 +02:00
|
|
|
|
|
|
|
|
temp = next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Update the <see cref="SplitterState"/> from user parameter.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="context">The splitter context.</param>
|
|
|
|
|
/// <param name="parameter">The user parameter.</param>
|
|
|
|
|
/// <param name="input">The raw input data after the <paramref name="parameter"/>.</param>
|
Audio rendering: reduce memory allocations (#6604)
* - WritableRegion: enable wrapping IMemoryOwner<byte>
- IVirtualMemoryManager impls of GetWritableRegion() use pooled memory when region is non-contiguous.
- IVirtualMemoryManager: add GetReadOnlySequence() and impls
- ByteMemoryPool: add new method RentCopy()
- ByteMemoryPool: make class static, remove ctor and singleton field from earlier impl
* - BytesReadOnlySequenceSegment: move from Ryujinx.Common.Memory to Ryujinx.Memory
- BytesReadOnlySequenceSegment: add IsContiguousWith() and Replace() methods
- VirtualMemoryManagerBase:
- remove generic type parameters, instead use ulong for virtual addresses and nuint for host/physical addresses
- implement IWritableBlock
- add virtual GetReadOnlySequence() with coalescing of contiguous segments
- add virtual GetSpan()
- add virtual GetWritableRegion()
- add abstract IsMapped()
- add virtual MapForeign(ulong, nuint, ulong)
- add virtual Read<T>()
- add virtual Read(ulong, Span<byte>)
- add virtual ReadTracked<T>()
- add virtual SignalMemoryTracking()
- add virtual Write()
- add virtual Write<T>()
- add virtual WriteUntracked()
- add virtual WriteWithRedundancyCheck()
- VirtualMemoryManagerRefCountedBase: remove generic type parameters
- AddressSpaceManager: remove redundant methods, add required overrides
- HvMemoryManager: remove redundant methods, add required overrides, add overrides for _invalidAccessHandler handling
- MemoryManager: remove redundant methods, add required overrides, add overrides for _invalidAccessHandler handling
- MemoryManagerHostMapped: remove redundant methods, add required overrides, add overrides for _invalidAccessHandler handling
- NativeMemoryManager: add get properties for Pointer and Length
- throughout: removed invalid <inheritdoc/> comments
* - WritableRegion: enable wrapping IMemoryOwner<byte>
- IVirtualMemoryManager impls of GetWritableRegion() use pooled memory when region is non-contiguous.
- IVirtualMemoryManager: add GetReadOnlySequence() and impls
- ByteMemoryPool: add new method RentCopy()
- ByteMemoryPool: make class static, remove ctor and singleton field from earlier impl
* add PagedMemoryRange enumerator types, use them in IVirtualMemoryManager implementations to consolidate page-handling logic and add a new capability - the coalescing of pages for consolidating memory copies and segmentation.
* new: more tests for PagedMemoryRangeCoalescingEnumerator showing coalescing of contiguous segments
* make some struct properties readonly
* put braces around `foreach` bodies
* encourage inlining of some PagedMemoryRange*Enumerator members
* DynamicRingBuffer:
- use ByteMemoryPool
- make some methods return without locking when size/count argument = 0
- make generic Read<T>()/Write<T>() non-generic because its only usage is as T = byte
- change Read(byte[]...) to Read(Span<byte>...)
- change Write(byte[]...) to Write(Span<byte>...)
* change IAudioRenderer.RequestUpdate() to take a ReadOnlySequence<byte>, enabling zero-copy audio rendering
* HipcGenerator: support ReadOnlySequence<byte> as IPC method parameter
* change IAudioRenderer/AudioRenderer RequestUpdate* methods to take input as ReadOnlySequence<byte>
* MemoryManagerHostTracked: use rented memory when contiguous in `GetWritableRegion()`
* rebase cleanup
* dotnet format fixes
* format and comment fixes
* format long parameter list - take 2
* - add support to HipcGenerator for buffers of type `Memory<byte>`
- change `AudioRenderer` `RequestUpdate()` and `RequestUpdateAuto()` to use Memory<byte> for output buffers, removing another memory block allocation/copy
* SplitterContext `UpdateState()` and `UpdateData()` smooth out advance/rewind logic, only rewind if magic is invalid
* DynamicRingBuffer.Write(): change Span<byte> to ReadOnlySpan<byte>
2024-04-07 17:07:32 -04:00
|
|
|
public void Update(SplitterContext context, in SplitterInParameter parameter, ref SequenceReader<byte> input)
|
2020-08-18 03:49:37 +02:00
|
|
|
{
|
|
|
|
|
ClearLinks();
|
|
|
|
|
|
|
|
|
|
int destinationCount;
|
|
|
|
|
|
|
|
|
|
if (context.IsBugFixed)
|
|
|
|
|
{
|
|
|
|
|
destinationCount = parameter.DestinationCount;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
destinationCount = Math.Min(context.GetDestinationCountPerStateForCompatibility(), parameter.DestinationCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (destinationCount > 0)
|
|
|
|
|
{
|
Audio rendering: reduce memory allocations (#6604)
* - WritableRegion: enable wrapping IMemoryOwner<byte>
- IVirtualMemoryManager impls of GetWritableRegion() use pooled memory when region is non-contiguous.
- IVirtualMemoryManager: add GetReadOnlySequence() and impls
- ByteMemoryPool: add new method RentCopy()
- ByteMemoryPool: make class static, remove ctor and singleton field from earlier impl
* - BytesReadOnlySequenceSegment: move from Ryujinx.Common.Memory to Ryujinx.Memory
- BytesReadOnlySequenceSegment: add IsContiguousWith() and Replace() methods
- VirtualMemoryManagerBase:
- remove generic type parameters, instead use ulong for virtual addresses and nuint for host/physical addresses
- implement IWritableBlock
- add virtual GetReadOnlySequence() with coalescing of contiguous segments
- add virtual GetSpan()
- add virtual GetWritableRegion()
- add abstract IsMapped()
- add virtual MapForeign(ulong, nuint, ulong)
- add virtual Read<T>()
- add virtual Read(ulong, Span<byte>)
- add virtual ReadTracked<T>()
- add virtual SignalMemoryTracking()
- add virtual Write()
- add virtual Write<T>()
- add virtual WriteUntracked()
- add virtual WriteWithRedundancyCheck()
- VirtualMemoryManagerRefCountedBase: remove generic type parameters
- AddressSpaceManager: remove redundant methods, add required overrides
- HvMemoryManager: remove redundant methods, add required overrides, add overrides for _invalidAccessHandler handling
- MemoryManager: remove redundant methods, add required overrides, add overrides for _invalidAccessHandler handling
- MemoryManagerHostMapped: remove redundant methods, add required overrides, add overrides for _invalidAccessHandler handling
- NativeMemoryManager: add get properties for Pointer and Length
- throughout: removed invalid <inheritdoc/> comments
* - WritableRegion: enable wrapping IMemoryOwner<byte>
- IVirtualMemoryManager impls of GetWritableRegion() use pooled memory when region is non-contiguous.
- IVirtualMemoryManager: add GetReadOnlySequence() and impls
- ByteMemoryPool: add new method RentCopy()
- ByteMemoryPool: make class static, remove ctor and singleton field from earlier impl
* add PagedMemoryRange enumerator types, use them in IVirtualMemoryManager implementations to consolidate page-handling logic and add a new capability - the coalescing of pages for consolidating memory copies and segmentation.
* new: more tests for PagedMemoryRangeCoalescingEnumerator showing coalescing of contiguous segments
* make some struct properties readonly
* put braces around `foreach` bodies
* encourage inlining of some PagedMemoryRange*Enumerator members
* DynamicRingBuffer:
- use ByteMemoryPool
- make some methods return without locking when size/count argument = 0
- make generic Read<T>()/Write<T>() non-generic because its only usage is as T = byte
- change Read(byte[]...) to Read(Span<byte>...)
- change Write(byte[]...) to Write(Span<byte>...)
* change IAudioRenderer.RequestUpdate() to take a ReadOnlySequence<byte>, enabling zero-copy audio rendering
* HipcGenerator: support ReadOnlySequence<byte> as IPC method parameter
* change IAudioRenderer/AudioRenderer RequestUpdate* methods to take input as ReadOnlySequence<byte>
* MemoryManagerHostTracked: use rented memory when contiguous in `GetWritableRegion()`
* rebase cleanup
* dotnet format fixes
* format and comment fixes
* format long parameter list - take 2
* - add support to HipcGenerator for buffers of type `Memory<byte>`
- change `AudioRenderer` `RequestUpdate()` and `RequestUpdateAuto()` to use Memory<byte> for output buffers, removing another memory block allocation/copy
* SplitterContext `UpdateState()` and `UpdateData()` smooth out advance/rewind logic, only rewind if magic is invalid
* DynamicRingBuffer.Write(): change Span<byte> to ReadOnlySpan<byte>
2024-04-07 17:07:32 -04:00
|
|
|
input.ReadLittleEndian(out int destinationId);
|
2020-08-18 03:49:37 +02:00
|
|
|
|
2024-05-17 16:46:43 -03:00
|
|
|
SplitterDestination destination = context.GetDestination(destinationId);
|
2020-08-18 03:49:37 +02:00
|
|
|
|
2024-05-17 16:46:43 -03:00
|
|
|
SetDestination(destination);
|
2020-08-18 03:49:37 +02:00
|
|
|
|
|
|
|
|
DestinationCount = destinationCount;
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < destinationCount; i++)
|
|
|
|
|
{
|
Audio rendering: reduce memory allocations (#6604)
* - WritableRegion: enable wrapping IMemoryOwner<byte>
- IVirtualMemoryManager impls of GetWritableRegion() use pooled memory when region is non-contiguous.
- IVirtualMemoryManager: add GetReadOnlySequence() and impls
- ByteMemoryPool: add new method RentCopy()
- ByteMemoryPool: make class static, remove ctor and singleton field from earlier impl
* - BytesReadOnlySequenceSegment: move from Ryujinx.Common.Memory to Ryujinx.Memory
- BytesReadOnlySequenceSegment: add IsContiguousWith() and Replace() methods
- VirtualMemoryManagerBase:
- remove generic type parameters, instead use ulong for virtual addresses and nuint for host/physical addresses
- implement IWritableBlock
- add virtual GetReadOnlySequence() with coalescing of contiguous segments
- add virtual GetSpan()
- add virtual GetWritableRegion()
- add abstract IsMapped()
- add virtual MapForeign(ulong, nuint, ulong)
- add virtual Read<T>()
- add virtual Read(ulong, Span<byte>)
- add virtual ReadTracked<T>()
- add virtual SignalMemoryTracking()
- add virtual Write()
- add virtual Write<T>()
- add virtual WriteUntracked()
- add virtual WriteWithRedundancyCheck()
- VirtualMemoryManagerRefCountedBase: remove generic type parameters
- AddressSpaceManager: remove redundant methods, add required overrides
- HvMemoryManager: remove redundant methods, add required overrides, add overrides for _invalidAccessHandler handling
- MemoryManager: remove redundant methods, add required overrides, add overrides for _invalidAccessHandler handling
- MemoryManagerHostMapped: remove redundant methods, add required overrides, add overrides for _invalidAccessHandler handling
- NativeMemoryManager: add get properties for Pointer and Length
- throughout: removed invalid <inheritdoc/> comments
* - WritableRegion: enable wrapping IMemoryOwner<byte>
- IVirtualMemoryManager impls of GetWritableRegion() use pooled memory when region is non-contiguous.
- IVirtualMemoryManager: add GetReadOnlySequence() and impls
- ByteMemoryPool: add new method RentCopy()
- ByteMemoryPool: make class static, remove ctor and singleton field from earlier impl
* add PagedMemoryRange enumerator types, use them in IVirtualMemoryManager implementations to consolidate page-handling logic and add a new capability - the coalescing of pages for consolidating memory copies and segmentation.
* new: more tests for PagedMemoryRangeCoalescingEnumerator showing coalescing of contiguous segments
* make some struct properties readonly
* put braces around `foreach` bodies
* encourage inlining of some PagedMemoryRange*Enumerator members
* DynamicRingBuffer:
- use ByteMemoryPool
- make some methods return without locking when size/count argument = 0
- make generic Read<T>()/Write<T>() non-generic because its only usage is as T = byte
- change Read(byte[]...) to Read(Span<byte>...)
- change Write(byte[]...) to Write(Span<byte>...)
* change IAudioRenderer.RequestUpdate() to take a ReadOnlySequence<byte>, enabling zero-copy audio rendering
* HipcGenerator: support ReadOnlySequence<byte> as IPC method parameter
* change IAudioRenderer/AudioRenderer RequestUpdate* methods to take input as ReadOnlySequence<byte>
* MemoryManagerHostTracked: use rented memory when contiguous in `GetWritableRegion()`
* rebase cleanup
* dotnet format fixes
* format and comment fixes
* format long parameter list - take 2
* - add support to HipcGenerator for buffers of type `Memory<byte>`
- change `AudioRenderer` `RequestUpdate()` and `RequestUpdateAuto()` to use Memory<byte> for output buffers, removing another memory block allocation/copy
* SplitterContext `UpdateState()` and `UpdateData()` smooth out advance/rewind logic, only rewind if magic is invalid
* DynamicRingBuffer.Write(): change Span<byte> to ReadOnlySpan<byte>
2024-04-07 17:07:32 -04:00
|
|
|
input.ReadLittleEndian(out destinationId);
|
|
|
|
|
|
2024-05-17 16:46:43 -03:00
|
|
|
SplitterDestination nextDestination = context.GetDestination(destinationId);
|
2020-08-18 03:49:37 +02:00
|
|
|
|
2024-05-17 16:46:43 -03:00
|
|
|
destination.Link(nextDestination);
|
2020-08-18 03:49:37 +02:00
|
|
|
destination = nextDestination;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-10 12:07:31 -03:00
|
|
|
if (destinationCount < parameter.DestinationCount)
|
|
|
|
|
{
|
|
|
|
|
input.Advance((parameter.DestinationCount - destinationCount) * sizeof(int));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 03:49:37 +02:00
|
|
|
Debug.Assert(parameter.Id == Id);
|
|
|
|
|
|
|
|
|
|
if (parameter.Id == Id)
|
|
|
|
|
{
|
|
|
|
|
SampleRate = parameter.SampleRate;
|
|
|
|
|
HasNewConnection = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-17 16:46:43 -03:00
|
|
|
/// Set the head of the linked list of <see cref="Destination"/>.
|
2020-08-18 03:49:37 +02:00
|
|
|
/// </summary>
|
2024-05-17 16:46:43 -03:00
|
|
|
/// <param name="newValue">New destination value.</param>
|
|
|
|
|
public void SetDestination(SplitterDestination newValue)
|
2020-08-18 03:49:37 +02:00
|
|
|
{
|
|
|
|
|
unsafe
|
|
|
|
|
{
|
2024-05-17 16:46:43 -03:00
|
|
|
fixed (SplitterDestinationVersion1* newValuePtr = &newValue.GetV1RefOrNull())
|
|
|
|
|
{
|
|
|
|
|
_destinationDataV1 = newValuePtr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fixed (SplitterDestinationVersion2* newValuePtr = &newValue.GetV2RefOrNull())
|
2020-08-18 03:49:37 +02:00
|
|
|
{
|
2024-05-17 16:46:43 -03:00
|
|
|
_destinationDataV2 = newValuePtr;
|
2020-08-18 03:49:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Update the internal state of this instance.
|
|
|
|
|
/// </summary>
|
2023-07-02 01:27:18 +02:00
|
|
|
public readonly void UpdateInternalState()
|
2020-08-18 03:49:37 +02:00
|
|
|
{
|
2024-05-17 16:46:43 -03:00
|
|
|
ForEachDestination((destination, _) => destination.UpdateInternalState());
|
2020-08-18 03:49:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-17 16:46:43 -03:00
|
|
|
/// Clear all links from the <see cref="Destination"/>.
|
2020-08-18 03:49:37 +02:00
|
|
|
/// </summary>
|
|
|
|
|
public void ClearLinks()
|
|
|
|
|
{
|
2024-05-17 16:46:43 -03:00
|
|
|
ForEachDestination((destination, _) => destination.Unlink());
|
2020-08-18 03:49:37 +02:00
|
|
|
|
|
|
|
|
unsafe
|
|
|
|
|
{
|
2024-05-17 16:46:43 -03:00
|
|
|
_destinationDataV1 = null;
|
|
|
|
|
_destinationDataV2 = null;
|
2020-08-18 03:49:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initialize a given <see cref="Span{SplitterState}"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="splitters">All the <see cref="SplitterState"/> to initialize.</param>
|
|
|
|
|
public static void InitializeSplitters(Span<SplitterState> splitters)
|
|
|
|
|
{
|
|
|
|
|
foreach (ref SplitterState splitter in splitters)
|
|
|
|
|
{
|
|
|
|
|
unsafe
|
|
|
|
|
{
|
2024-05-17 16:46:43 -03:00
|
|
|
splitter._destinationDataV1 = null;
|
|
|
|
|
splitter._destinationDataV2 = null;
|
2020-08-18 03:49:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
splitter.DestinationCount = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-02 01:27:18 +02:00
|
|
|
}
|