unsafe static void OnReadInStream(ref InStreamData stream, int min, int left) { // Recover the 'this' reference from the UserData pointer. var self = (InputStream)GCHandle.FromIntPtr(stream.UserData).Target; while (left > 0) { // Start reading the buffer. var count = left; ChannelArea *areas; stream.BeginRead(out areas, ref count); // When getting count == 0, we must stop reading // immediately without calling InStream.EndRead. if (count == 0) { break; } if (areas == null) { // We must do zero-fill when receiving a null pointer. lock (self._ring) self._ring.WriteEmpty(stream.BytesPerFrame * count); } else { // Determine the memory span of the input data with // assuming the data is tightly packed. // TODO: Is this assumption always true? var span = new ReadOnlySpan <Byte>( (void *)areas[0].Pointer, areas[0].Step * count ); // Transfer the data to the ring buffer. lock (self._ring) self._ring.Write(span); } stream.EndRead(); left -= count; } }
static void OnErrorInStream(ref InStreamData stream, Error error) { UnityEngine.Debug.LogError($"InStream error ({error})"); }
static void OnOverflowInStream(ref InStreamData stream) { UnityEngine.Debug.LogWarning("InStream overflow"); }