Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 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 int LastFrameReceivedAt => currentInternal.LastFrameReceivedAt;

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

private bool disposed;
private int lastFrameReceivedAt = -1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lastFrameReceivedAt should be named with Volatile prefix to prevent its misuse


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

public int LastFrameReceivedAt => Volatile.Read(ref lastFrameReceivedAt);

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

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

using var guard = buffer.Lock();
guard.Value.Write(frame);
guard.Value.TryWriteWavTee(frame, frame);
Expand Down
6 changes: 6 additions & 0 deletions Runtime/Scripts/Rooms/Streaming/Audio/AudioStreams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ protected override AudioStreamInfo InfoFromStream(AudioStream stream)
{
return stream.AudioStreamInfo;
}

public int GetLastFrameReceivedAt(StreamKey streamKey)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Option<> and avoid sentinel values

{
var weak = ActiveStream(streamKey);
return weak.Resource.Has ? weak.Resource.Value.LastFrameReceivedAt : -1;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/Rooms/Streaming/Audio/IAudioStreams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace LiveKit.Rooms.Streaming.Audio
{
public interface IAudioStreams : IStreams<AudioStream, AudioStreamInfo>
{

int GetLastFrameReceivedAt(StreamKey streamKey);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it could be an extension method or a method with default impl

}
}

Expand Down