-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGapAudio.cs
More file actions
43 lines (36 loc) · 1.48 KB
/
Copy pathGapAudio.cs
File metadata and controls
43 lines (36 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Two-party GAP (audio) frame exchange — minimal in-memory end-to-end example.
//
// Demonstrates:
// - Sending synthetic Opus frames with FlatBuffers codec (recommended for audio)
// - Sequential frames: rtp_sequence advances automatically inside GapClient
//
// Run from repo root:
// dotnet script csharp/examples/GapAudio.cs
using GBPStack;
using var aliceMls = MlsContext.Create("alice");
using var bobMls = MlsContext.Create("bob");
bobMls.AcceptWelcome(aliceMls.Invite(bobMls.ExportKeyPackage()));
var gid = aliceMls.GroupId;
using var alice = GroupNode.Create(1, gid);
using var bob = GroupNode.Create(2, gid);
alice.BootstrapAsCreator(aliceMls.Epoch);
bob.BootstrapAsJoiner(bobMls.Epoch);
using var gapAlice = GapClient.Create();
using var gapBob = GapClient.Create();
// Synthetic 20 ms Opus frame (zeroed; real usage: encode from PCM).
var opus = new byte[40];
for (ulong i = 0; i < 3; i++)
{
// FlatBuffers minimises decode latency on real-time audio paths.
var frame = gapAlice.Send(alice, aliceMls,
target: 2, mediaSourceId: 1, rtpTimestamp: i * 960, opus,
codec: PayloadCodec.FlatBuffers);
foreach (var ev in bob.OnWire(bobMls, frame.Wire))
{
if (ev.Kind == "payload_received" && ev.StreamType == StreamType.Audio)
{
var r = gapBob.Accept(ev.Plaintext!, bobMls.Epoch, ev.Codec ?? PayloadCodec.Cbor);
Console.WriteLine($"frame {i + 1}: status={r.Status} seq={r.Seq} codec={ev.Codec}");
}
}
}