Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Runtime/Scripts/Rooms/Streaming/Audio/AudioStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class AudioStream : IDisposable

public WavTeeControl WavTeeControl => currentInternal.WavTeeControl;

public Option<int> LastFrameReceivedAt => currentInternal.LastFrameReceivedAt;

public AudioStream(StreamKey streamKey, LiveKit.Rooms.Tracks.ITrack track)
{
this.streamKey = streamKey;
Expand Down Expand Up @@ -106,11 +108,21 @@ public class AudioStreamInternal : IDisposable
);

private bool disposed;
private int volatileLastFrameReceivedAt = -1;

public readonly AudioStreamInfo audioStreamInfo;
private readonly uint internalChannels;
private readonly uint internalSampleRate;

public Option<int> LastFrameReceivedAt
{
get
{
int value = Volatile.Read(ref volatileLastFrameReceivedAt);
return value == -1 ? Option<int>.None : Option<int>.Some(value);
}
}

public WavTeeControl WavTeeControl
{
get
Expand Down Expand Up @@ -222,6 +234,8 @@ private void OnAudioStreamEvent(AudioStreamEvent e)
return;
}

Volatile.Write(ref volatileLastFrameReceivedAt, Environment.TickCount);

using var guard = buffer.Lock();
guard.Value.Write(frame);
guard.Value.TryWriteWavTee(frame, frame);
Expand Down
14 changes: 12 additions & 2 deletions Runtime/Scripts/Rooms/Streaming/Audio/IAudioStreams.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#if !UNITY_WEBGL || UNITY_EDITOR
#if !UNITY_WEBGL || UNITY_EDITOR

using RichTypes;

namespace LiveKit.Rooms.Streaming.Audio
{
public interface IAudioStreams : IStreams<AudioStream, AudioStreamInfo>
{

}

public static class AudioStreamsExtensions
{
public static Option<int> GetLastFrameReceivedAt(this IAudioStreams streams, StreamKey streamKey)
{
var weak = streams.ActiveStream(streamKey);
return weak.Resource.Has ? weak.Resource.Value.LastFrameReceivedAt : Option<int>.None;
}
}
}

Expand Down