Bring managed iOS client to feature parity
.NET port / test (macos-latest) (push) Canceled after 0s
.NET port / test (ubuntu-24.04) (push) Canceled after 0s
.NET port / test (windows-latest) (push) Canceled after 0s
.NET port / apple-client (push) Canceled after 0s
.NET port / cpp-conformance (push) Canceled after 0s
.NET port / test (macos-latest) (push) Canceled after 0s
.NET port / test (ubuntu-24.04) (push) Canceled after 0s
.NET port / test (windows-latest) (push) Canceled after 0s
.NET port / apple-client (push) Canceled after 0s
.NET port / cpp-conformance (push) Canceled after 0s
This commit is contained in:
@@ -12,8 +12,12 @@ internal sealed class BroadcastAudioPump : IAsyncDisposable
|
||||
private Task worker = Task.CompletedTask;
|
||||
private VoiceCatClient? client;
|
||||
private uint streamId;
|
||||
private bool active;
|
||||
private readonly short[] scratch = new short[Frame * 2];
|
||||
|
||||
internal event Action? Changed;
|
||||
internal bool IsActive => active;
|
||||
|
||||
internal void Start(VoiceCatClient owner) { client = owner; worker = RunAsync(stop.Token); }
|
||||
|
||||
private async Task RunAsync(CancellationToken token)
|
||||
@@ -35,12 +39,12 @@ internal sealed class BroadcastAudioPump : IAsyncDisposable
|
||||
using MemoryMappedViewAccessor view = map.CreateViewAccessor(0, Header + Capacity * sizeof(short), MemoryMappedFileAccess.ReadWrite);
|
||||
if (view.ReadUInt32(0) != Magic || view.ReadUInt32(4) != Version) throw new InvalidDataException("Unsupported broadcast ring.");
|
||||
bool active = view.ReadUInt32(16) != 0;
|
||||
if (!active) { StopStream(); return; }
|
||||
if (!active) { StopStream(); SetActive(false); return; }
|
||||
VoiceCatClient owner = client ?? throw new IOException("Client disconnected.");
|
||||
if (streamId == 0)
|
||||
{
|
||||
StreamInfo stream = await owner.StartStreamAsync(StreamKind.StreamScreenAudio, "Screen audio", 2, token).ConfigureAwait(false);
|
||||
streamId = stream.StreamId; view.Write(32, view.ReadUInt64(24));
|
||||
streamId = stream.StreamId; view.Write(32, view.ReadUInt64(24)); SetActive(true);
|
||||
}
|
||||
ulong write = view.ReadUInt64(24), read = view.ReadUInt64(32);
|
||||
if (write - read > Capacity) read = write - Capacity;
|
||||
@@ -63,8 +67,10 @@ internal sealed class BroadcastAudioPump : IAsyncDisposable
|
||||
try { client.StopStream(id); } catch (Exception exception) when (exception is IOException or InvalidOperationException) { }
|
||||
}
|
||||
|
||||
private void SetActive(bool value) { if (active == value) return; active = value; Changed?.Invoke(); }
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
stop.Cancel(); try { await worker.ConfigureAwait(false); } catch (OperationCanceledException) { } StopStream(); stop.Dispose();
|
||||
stop.Cancel(); try { await worker.ConfigureAwait(false); } catch (OperationCanceledException) { } StopStream(); SetActive(false); stop.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user