Class Utility
Various utilities for unity media collections
Namespace: Unity.Media.Utilities
Syntax
public static class Utility : object
Properties
EnableLeakTracking
Enable tracking of leaks via AllocateUnsafe/FreeUnsafe
Declaration
public static bool EnableLeakTracking { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
This also requires UNITY_MEDIA_MONITOR_NATIVE_ALLOCATIONS to be defined. Burst is currently not supported.
Methods
AllocateUnsafe<T>(Int32, Allocator, Boolean)
Allocate native memory
Declaration
public static T*AllocateUnsafe<T>(int count = 1, Allocator allocator = null, bool permanentAllocation = false)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | The number of elements to allocate |
Allocator | allocator | The native allocator to use |
Boolean | permanentAllocation | Whether this allocation will remain alive for the lifetime of the program. This is used for leak tracking. |
Returns
Type | Description |
---|---|
T* | A pointer to a newly-allocated buffer of count elements |
Type Parameters
Name | Description |
---|---|
T | The element type to allocate |
ClearBuffer(Void*, Byte, Int64)
Clears a portion of a buffer using a provided clear value
Declaration
public static void ClearBuffer(void *buffer, byte clearValue, long byteCount)
Parameters
Type | Name | Description |
---|---|---|
Void* | buffer | The buffer to be cleared |
Byte | clearValue | The value to be set in each byte |
Int64 | byteCount | The number of bytes to clear |
Remarks
Equivalent to libc's memset()
CopyToPersistentAllocation<T>(ref T)
Make a copy of a structure in native memory
Declaration
public static void *CopyToPersistentAllocation<T>(ref T structure)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
T | structure | The structure to copy |
Returns
Type | Description |
---|---|
Void* | A pointer to newly-allocated memory containing a copy of structure |
Type Parameters
Name | Description |
---|---|
T | The type of structure |
Remarks
This uses the Persistent native allocator
DeinterleaveAudioStream(Single*, Single*, Int32, Int32, BufferWriteMode)
Read an interleaved audio stream (LRLRLRLR...) and write an per-channel audio stream (LLLL...RRRR...)
Declaration
public static void DeinterleaveAudioStream(float *source, float *destination, int frames, int channels, BufferWriteMode writeMode = default(BufferWriteMode))
Parameters
Type | Name | Description |
---|---|---|
Single* | source | A pointer to an interleaved buffer |
Single* | destination | A pointer to the destination buffer |
Int32 | frames | How many frames are to be converted |
Int32 | channels | How many channels are in the source |
BufferWriteMode | writeMode | The write mode to be used |
Remarks
The source buffer is assumed to be one float per channel per frame
FreeUnsafe(Void*, Allocator)
Free native memory
Declaration
public static void FreeUnsafe(void *memory, Allocator allocator = null)
Parameters
Type | Name | Description |
---|---|---|
Void* | memory | A pointer to the native memory to be freed |
Allocator | allocator | The native allocator with which the memory was allocated |
FreeUnsafe<T>(T*, Allocator)
Free native memory
Declaration
public static void FreeUnsafe<T>(T*memory, Allocator allocator = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
T* | memory | A pointer to the native memory to be freed |
Allocator | allocator | The native allocator with which the memory was allocated |
Type Parameters
Name | Description |
---|---|
T | The element type of memory |
InterleaveAudioStream(Single*, Single*, Int32, Int32, BufferWriteMode)
Read a per-channel audio stream (LLLL...RRRR...) and write an interleaved audio stream (LRLRLRLR...)
Declaration
public static void InterleaveAudioStream(float *source, float *destination, int frames, int channels, BufferWriteMode writeMode = default(BufferWriteMode))
Parameters
Type | Name | Description |
---|---|---|
Single* | source | A pointer to a per-channel buffer |
Single* | destination | A pointer to the destination buffer |
Int32 | frames | How many frames are to be converted |
Int32 | channels | How many channels are in the source |
BufferWriteMode | writeMode | The write mode to be used |
Remarks
The source buffer is assumed to be one float per channel per frame
ValidateIndex(Int32, Int32, Int32)
Validate an index within a range
Declaration
public static void ValidateIndex(int index, int highestIndex = null, int lowestIndex = 0)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index to be validated |
Int32 | highestIndex | The highest valid index |
Int32 | lowestIndex | The lowest valid index |
VerifyLeaks()
Perform leak verification, if leak tracking was enabled
Declaration
public static void VerifyLeaks()