gofmt
13 files changed,
+604
−19
callscore/media_test.go+88 −0callscore/room.go+42 −4cmd/quality-summary/main.go+41 −0cmd/quality-summary/main_test.go+8 −3internal/calls/hub/media.go+13 −1internal/calls/hub/media_test.go+60 −0internal/calls/quality.go+48 −1internal/calls/signal.go+63 −6internal/callstest/media_test.go+104 −1internal/callstest/quality_test.go+55 −2native/bridge/bridge.go+14 −0protocol/messages.go+48 −1protocol/quality.go+20 −0
diff --git a/callscore/media_test.go b/callscore/media_test.go| index 28956d5..2634fd1 100644 |
| --- a/callscore/media_test.go |
| +++ b/callscore/media_test.go |
| @@ -409,3 +409,91 @@ func TestHearingFallsBackOnAnOldServer(t *testing.T) { |
| } |
| nothingPosted(t, posted, "a roster that agrees with the plain report needs nothing") |
| } |
| + |
| +// §15.30: the asks are kept to roster peers and the wire's levels, sent |
| +// only on a change, and an empty set is no key at all. |
| +func TestVideoAsksAreReportedFromTheRoster(t *testing.T) { |
| + r, posted := mediaRoom(t) |
| + a, b := protocol.PeerID("aaaa"), protocol.PeerID("bbbb") |
| + if err := r.receive(roster(protocol.RosterPeer{Peer: "self"}, protocol.RosterPeer{Peer: a, Gen: 1}, protocol.RosterPeer{Peer: b, Gen: 1})); err != nil { |
| + t.Fatal(err) |
| + } |
| + nextMedia(t, posted) |
| + err := r.SetVideo(map[protocol.PeerID]protocol.VideoLevel{ |
| + a: protocol.VideoMinimal, b: "normal", "self": protocol.VideoAudio, "stranger": protocol.VideoAudio, |
| + }) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if m := nextMedia(t, posted); len(m.Video) != 1 || m.Video[a] != protocol.VideoMinimal { |
| + t.Fatalf("video %v, want only aaaa at minimal", m.Video) |
| + } |
| + if err := r.SetVideo(map[protocol.PeerID]protocol.VideoLevel{a: protocol.VideoMinimal}); err != nil { |
| + t.Fatal(err) |
| + } |
| + nothingPosted(t, posted, "the same asks are not a change") |
| + if err := r.SetVideo(map[protocol.PeerID]protocol.VideoLevel{a: protocol.VideoAudio, b: protocol.VideoReduced}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if m := nextMedia(t, posted); len(m.Video) != 2 || m.Video[a] != protocol.VideoAudio || m.Video[b] != protocol.VideoReduced { |
| + t.Fatalf("video %v", m.Video) |
| + } |
| + if err := r.SetVideo(nil); err != nil { |
| + t.Fatal(err) |
| + } |
| + select { |
| + case s := <-posted: |
| + if strings.Contains(string(s.Payload), "video") { |
| + t.Fatalf("cleared report %s, want no video key", s.Payload) |
| + } |
| + case <-time.After(time.Second): |
| + t.Fatal("clearing the asks sent nothing") |
| + } |
| +} |
| + |
| +// A server from before §15.30 refuses a report carrying asks. The core |
| +// sends it again without them, hearing kept, and leaves them out from |
| +// then on: a mute is never lost, and the sender simply hears no asks. |
| +func TestVideoAsksFallBackOnAnOldServer(t *testing.T) { |
| + posted := make(chan protocol.Signal, 16) |
| + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { |
| + var s protocol.Signal |
| + _ = json.NewDecoder(req.Body).Decode(&s) |
| + var m protocol.MediaState |
| + _ = json.Unmarshal(s.Payload, &m) |
| + posted <- s |
| + if len(m.Video) > 0 { |
| + w.WriteHeader(http.StatusBadRequest) |
| + } |
| + })) |
| + t.Cleanup(srv.Close) |
| + r, err := New(srv.URL, "room", srv.Client(), func(Event) {}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + r.started = true |
| + r.state.Peer = "self" |
| + t.Cleanup(r.Close) |
| + b := protocol.PeerID("bbbb") |
| + if err := r.receive(roster(protocol.RosterPeer{Peer: "self"}, protocol.RosterPeer{Peer: b, Gen: 1})); err != nil { |
| + t.Fatal(err) |
| + } |
| + nextMedia(t, posted) |
| + _ = r.SetMedia(true, false) |
| + nextMedia(t, posted) |
| + if err := r.SetVideo(map[protocol.PeerID]protocol.VideoLevel{b: protocol.VideoMinimal}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if m := nextMedia(t, posted); len(m.Video) != 1 { |
| + t.Fatalf("first report %+v, want the asks", m) |
| + } |
| + if m := nextMedia(t, posted); len(m.Video) != 0 || m.Hearing == nil || !m.Muted { |
| + t.Fatalf("resent %+v, want the same report without asks, hearing kept", m) |
| + } |
| + if err := r.SetVideo(map[protocol.PeerID]protocol.VideoLevel{b: protocol.VideoAudio}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if m := nextMedia(t, posted); len(m.Video) != 0 { |
| + t.Fatalf("later report %+v, want no asks", m) |
| + } |
| +} |
diff --git a/callscore/room.go b/callscore/room.go| index f230f3f..210ac90 100644 |
| --- a/callscore/room.go |
| +++ b/callscore/room.go |
| @@ -6,6 +6,7 @@ import ( |
| "errors" |
| "net/http" |
| "net/url" |
| + "slices" |
| "sort" |
| "sync" |
| "time" |
| @@ -67,6 +68,9 @@ type Room struct { |
| // hears (it predates §15.24), so reports go without the key, and the |
| // people on new clients fall back to their own evidence about us. |
| plainHearing bool |
| + // plainVideo: the server refused a report carrying §15.30's video |
| + // asks — one from before it — so they are left out from then on. |
| + plainVideo bool |
| // report is the latest hello's report token (spec §15.26): a resumed |
| // hello carries the same one, a fresh participation a new one. Kept |
| // past Close, for the after-call window (report.go). |
| @@ -352,6 +356,33 @@ func (r *Room) SetHearing(peers []protocol.PeerID) error { |
| return r.reportMedia() |
| } |
| +// SetVideo records what this client, as a receiver, asks each sender for |
| +// (spec §15.30) and reports it with the rest of its media state. Roster |
| +// peers other than this client only, at most protocol.MaxVideo, and only |
| +// the levels the wire has: an entry for "normal", or for anything else, is |
| +// dropped, because normal is the absence of an entry. |
| +func (r *Room) SetVideo(asks map[protocol.PeerID]protocol.VideoLevel) error { |
| + r.mu.Lock() |
| + var next map[protocol.PeerID]protocol.VideoLevel |
| + for _, p := range r.state.Peers { |
| + level, ok := asks[p.Peer] |
| + if p.Peer == r.state.Peer || !ok || !slices.Contains(protocol.VideoLevels, level) || len(next) >= protocol.MaxVideo { |
| + continue |
| + } |
| + if next == nil { |
| + next = map[protocol.PeerID]protocol.VideoLevel{} |
| + } |
| + next[p.Peer] = level |
| + } |
| + if (protocol.MediaState{Video: next}).Equal(protocol.MediaState{Video: r.media.Video}) { |
| + r.mu.Unlock() |
| + return nil |
| + } |
| + r.media.Video = next |
| + r.mu.Unlock() |
| + return r.reportMedia() |
| +} |
| + |
| func (r *Room) reportMedia() error { |
| r.mu.Lock() |
| report := r.state.Phase == "admitted" && !r.stopped |
| @@ -384,12 +415,16 @@ func (r *Room) wireMediaLocked() protocol.MediaState { |
| if r.plainHearing { |
| report.Hearing = nil |
| } |
| + if r.plainVideo { |
| + report.Video = nil |
| + } |
| return report |
| } |
| -// refusedExtras is a server from before §15.24 or §15.21 refusing a media |
| -// report because of a key it does not know: the newest key goes first — |
| -// hearing, which every report from this core carries — and the report is |
| +// refusedExtras is a server from before §15.30, §15.24 or §15.21 refusing a |
| +// media report because of a key it does not know: the newest key goes |
| +// first — §15.30's video asks when the report had any, then hearing, which |
| +// every report from this core carries — and the report is |
| // sent again without it; a second refusal, of a report naming stalled |
| // screens, takes those off too. From then on reports go without them, so |
| // a mute is never lost to an old server. Without hearing, the people on |
| @@ -402,7 +437,10 @@ func (r *Room) refusedExtras(s protocol.Signal) bool { |
| } |
| r.mu.Lock() |
| dropped := false |
| - if sent.Hearing != nil && !r.plainHearing { |
| + if len(sent.Video) > 0 && !r.plainVideo { |
| + r.plainVideo = true |
| + dropped = true |
| + } else if sent.Hearing != nil && !r.plainHearing { |
| r.plainHearing = true |
| dropped = true |
| } else if len(sent.ScreenStalled) > 0 && !r.plainScreen { |
diff --git a/cmd/quality-summary/main.go b/cmd/quality-summary/main.go| index 619775e..3c7e115 100644 |
| --- a/cmd/quality-summary/main.go |
| +++ b/cmd/quality-summary/main.go |
| @@ -340,6 +340,10 @@ type direction struct { |
| reconnectingSeconds float64 |
| noSound, stalled, blocked int |
| screenSteps float64 |
| + // §15.30: seconds the first asked the second for each lower level |
| + // (reduced, minimal, audio), and seconds the first sent the second less |
| + // because the second asked. |
| + asked, sent [protocol.VideoLevelCount]float64 |
| } |
| type event struct { |
| @@ -500,6 +504,16 @@ func (c *call) addQuality(p *person, l line) { |
| } |
| } |
| if e := q.Events; e != nil { |
| + for i, x := range e.AskedSeconds { |
| + if i < len(d.asked) { |
| + d.asked[i] += val(x) |
| + } |
| + } |
| + for i, x := range e.SentSeconds { |
| + if i < len(d.sent) { |
| + d.sent[i] += val(x) |
| + } |
| + } |
| d.cantHear += val(e.CantHearSeconds) |
| d.reconnecting += val(e.Reconnecting) |
| d.reconnectingSeconds += val(e.ReconnectingSeconds) |
| @@ -568,6 +582,9 @@ func (c *call) print(out io.Writer, loc *time.Location) { |
| if s := headScreen(h); s != "" { |
| fmt.Fprintf(out, ", screen %s", s) |
| } |
| + if h["videoAsked"] > 0 || h["videoSent"] > 0 { |
| + fmt.Fprintf(out, ", asked someone for less video %s, sent someone less %s", minutes(h["videoAsked"]), minutes(h["videoSent"])) |
| + } |
| fmt.Fprintln(out) |
| } |
| } |
| @@ -599,6 +616,12 @@ func (c *call) print(out io.Writer, loc *time.Location) { |
| if d.screenSteps > 0 { |
| fmt.Fprintf(out, ", screen recovery steps %g", d.screenSteps) |
| } |
| + if s := videoLevels(d.asked); s != "" { |
| + fmt.Fprintf(out, ", %s asked %s for %s", short(k[0]), short(k[1]), s) |
| + } |
| + if s := videoLevels(d.sent); s != "" { |
| + fmt.Fprintf(out, ", %s sent %s %s because they asked", short(k[0]), short(k[1]), s) |
| + } |
| fmt.Fprintln(out) |
| } |
| } |
| @@ -620,6 +643,24 @@ func (c *call) print(out io.Writer, loc *time.Location) { |
| fmt.Fprintln(out) |
| } |
| +// videoLevels is §15.30's seconds at each level in words — "Minimal for |
| +// 4m0s, Audio only for 30s" — or "" when it was normal throughout. |
| +func videoLevels(secs [protocol.VideoLevelCount]float64) string { |
| + names := [protocol.VideoLevelCount]string{"Reduced", "Minimal", "Audio only"} |
| + var parts []string |
| + for i, v := range secs { |
| + if v > 0 { |
| + parts = append(parts, names[i]+" for "+minutes(v)) |
| + } |
| + } |
| + return strings.Join(parts, ", ") |
| +} |
| + |
| +// minutes is a number of seconds as a duration, to the second. |
| +func minutes(secs float64) string { |
| + return (time.Duration(secs * float64(time.Second))).Round(time.Second).String() |
| +} |
| + |
| // headScreen is a quality line's screen fields in words (spec §15.22's |
| // ladder and the receiver's watch), or "" when there are none. |
| func headScreen(h map[string]float64) string { |
diff --git a/cmd/quality-summary/main_test.go b/cmd/quality-summary/main_test.go| index 4460b63..837e628 100644 |
| --- a/cmd/quality-summary/main_test.go |
| +++ b/cmd/quality-summary/main_test.go |
| @@ -13,8 +13,8 @@ import ( |
| // report in two parts, and a text line the summary must skip. |
| const fixture = `2026-10-03 14:39:30 [app] calls.bds.oncarlos.com time=2026-10-03T14:39:30.000Z level=INFO msg="rastrillo: serving" |
| 2026-10-03 14:40:00 [app] calls.bds.oncarlos.com {"time":"2026-10-03T14:40:00Z","level":"INFO","msg":"calls: quality","call":"oldcalloldcall22","peer":"zzzzzzzzzzzzzzzz","app":"web","seconds":30,"report":{"seconds":30}} |
| -2026-10-03 14:41:00 [app] calls.bds.oncarlos.com {"time":"2026-10-03T14:41:00Z","level":"INFO","msg":"calls: quality","call":"callcallcallcall","peer":"aaaaaaaaaaaaaaaa","app":"mac","version":"0.4.9","os":"macos","osVersion":"26.0.1","final":false,"seconds":30,"report":{"seconds":30,"devices":{"input":"bluetooth","output":"built-in"},"peers":[{"peer":"bbbbbbbbbbbbbbbb","path":{"local":"srflx","remote":"relay","protocol":"udp"},"rtt":48,"in":{"audio":{"packets":1490,"lost":10,"samples":1440000,"concealed":14400},"video":{"packets":900,"lost":100,"freezes":2,"freezeSeconds":1.5}},"events":{"reconnecting":1,"reconnectingSeconds":4.2}}]}} |
| -2026-10-03 14:41:05 [app] calls.bds.oncarlos.com {"time":"2026-10-03T14:41:05Z","level":"INFO","msg":"calls: quality","call":"callcallcallcall","peer":"bbbbbbbbbbbbbbbb","app":"web","version":"de04e2d","browser":"chrome","browserVersion":"141.0","os":"windows","osVersion":"10.0","seconds":30,"report":{"seconds":30,"peers":[{"peer":"aaaaaaaaaaaaaaaa","path":{"local":"relay","remote":"srflx","protocol":"tls"},"rtt":180,"in":{"audio":{"packets":1500,"lost":0}},"events":{"cantHearSeconds":3}}]}} |
| +2026-10-03 14:41:00 [app] calls.bds.oncarlos.com {"time":"2026-10-03T14:41:00Z","level":"INFO","msg":"calls: quality","call":"callcallcallcall","peer":"aaaaaaaaaaaaaaaa","app":"mac","version":"0.4.9","os":"macos","osVersion":"26.0.1","final":false,"seconds":30,"report":{"seconds":30,"devices":{"input":"bluetooth","output":"built-in"},"peers":[{"peer":"bbbbbbbbbbbbbbbb","path":{"local":"srflx","remote":"relay","protocol":"udp"},"rtt":48,"in":{"audio":{"packets":1490,"lost":10,"samples":1440000,"concealed":14400},"video":{"packets":900,"lost":100,"freezes":2,"freezeSeconds":1.5}},"events":{"reconnecting":1,"reconnectingSeconds":4.2,"sentSeconds":[0,24,0]}}]}} |
| +2026-10-03 14:41:05 [app] calls.bds.oncarlos.com {"time":"2026-10-03T14:41:05Z","level":"INFO","msg":"calls: quality","call":"callcallcallcall","peer":"bbbbbbbbbbbbbbbb","app":"web","version":"de04e2d","browser":"chrome","browserVersion":"141.0","os":"windows","osVersion":"10.0","seconds":30,"videoAsked":24,"report":{"seconds":30,"peers":[{"peer":"aaaaaaaaaaaaaaaa","path":{"local":"relay","remote":"srflx","protocol":"tls"},"rtt":180,"in":{"audio":{"packets":1500,"lost":0}},"events":{"cantHearSeconds":3,"askedSeconds":[0,24,0]}}]}} |
| 2026-10-03 14:41:30 [app] calls.bds.oncarlos.com {"time":"2026-10-03T14:41:30Z","level":"INFO","msg":"calls: quality","call":"callcallcallcall","peer":"aaaaaaaaaaaaaaaa","app":"mac","version":"0.4.9","os":"macos","osVersion":"26.0.1","final":true,"seconds":30,"report":{"seconds":30,"peers":[{"peer":"bbbbbbbbbbbbbbbb","path":{"local":"host","remote":"host","protocol":"udp"},"rtt":20}]}} |
| 2026-10-03 14:41:20 [app] calls.bds.oncarlos.com {"time":"2026-10-03T14:41:20Z","level":"WARN","msg":"calls: problem report","ref":"K7Q2M9PD","call":"callcallcallcall","peer":"aaaaaaaaaaaaaaaa","app":"mac","version":"0.4.9","os":"macos","live":true,"note":"video froze","parts":2} |
| 2026-10-03 14:41:20 [app] calls.bds.oncarlos.com {"time":"2026-10-03T14:41:20Z","level":"WARN","msg":"calls: problem report diagnostics","ref":"K7Q2M9PD","call":"callcallcallcall","peer":"aaaaaaaaaaaaaaaa","part":2,"of":2,"text":"second half\n"} |
| @@ -52,6 +52,9 @@ func TestSummaryOfOneCall(t *testing.T) { |
| `15:41:00 aaaaaa: "Reconnecting to bbbbbb…" (4.2 s)`, |
| `15:41:05 bbbbbb: "aaaaaa can't hear you yet" (3.0 s)`, |
| "15:41:30 aaaaaa left (final report)", |
| + // §15.30: who asked whom for less video, and for how long. |
| + "bbbbbb asked aaaaaa for Minimal for 24s", |
| + "aaaaaa sent bbbbbb Minimal for 24s because they asked", |
| `Problem K7Q2M9PD at 15:41:20 from aaaaaa (mac): "video froze"`, |
| } { |
| if !strings.Contains(out, want) { |
| @@ -79,7 +82,7 @@ func TestSummaryByCallTagAndAProblemReport(t *testing.T) { |
| // `report` at all. Diagnostics text that looks like fields (" in=1", |
| // " time=") must stay text. |
| const carlosFixture = `2026-10-21 14:38:52 [app] calls.bds.oncarlos.com calls: quality app=mac call=ayhk4nffb2gz7eur final=false freezes=4 maxLossPct=0.1 maxRtt=195.9 os=macos osVersion=27.0.0 peer=p2pq7kdbzubekeu6 reconnecting=0 relay=false remotes=1 screenRebuilds=1 screenStalls=0 seconds=30.9 time=2026-10-21T14:38:52.887559374Z version=0.4.10 |
| -2026-10-21 14:39:06 [app] calls.bds.oncarlos.com calls: quality app=web browser=safari browserVersion=26.5 call=ayhk4nffb2gz7eur final=false freezes=0 maxLossPct=0 maxRtt=141 os=macos peer=ce5xx2f463fimkpi reconnecting=0 relay=false remotes=1 screenStalls=2 screenStallsUndecoded=2 seconds=30.2 time=2026-10-21T14:39:06.364245764Z version=882eab8 |
| +2026-10-21 14:39:06 [app] calls.bds.oncarlos.com calls: quality app=web browser=safari browserVersion=26.5 call=ayhk4nffb2gz7eur final=false freezes=0 maxLossPct=0 maxRtt=141 os=macos peer=ce5xx2f463fimkpi reconnecting=0 relay=false remotes=1 screenStalls=2 screenStallsUndecoded=2 seconds=30.2 time=2026-10-21T14:39:06.364245764Z version=882eab8 videoAsked=240 videoSetting=low |
| 2026-10-21 15:06:37 [app] calls.bds.oncarlos.com calls: problem report app=mac call=ayhk4nffb2gz7eur live=true note=it froze, then a=b os=macos osVersion=27.0.0 parts=2 peer=p2pq7kdbzubekeu6 ref=6BPJVTGF time=2026-10-21T15:06:37.899381736Z version=0.4.10 |
| 2026-10-21 15:06:37 [app] calls.bds.oncarlos.com calls: problem report diagnostics call=ayhk4nffb2gz7eur of=2 part=1 peer=p2pq7kdbzubekeu6 ref=6BPJVTGF text=Calls diagnostics — a call's details |
| ## Devices |
| @@ -132,6 +135,8 @@ func TestCarlosPrintedQualityHeadlines(t *testing.T) { |
| "screen 1 rebuilds", |
| "ce5xx2 web 882eab8 safari 26.5 on macos 1 reports", |
| "screen 2 stalls reported here, 2 arriving, not decoded", |
| + // §15.30's headline: time asked for less video. |
| + "asked someone for less video 4m0s, sent someone less 0s", |
| "Problem 6BPJVTGF", |
| } { |
| if !strings.Contains(out, want) { |
diff --git a/internal/calls/hub/media.go b/internal/calls/hub/media.go| index 63a7d7f..b824f51 100644 |
| --- a/internal/calls/hub/media.go |
| +++ b/internal/calls/hub/media.go |
| @@ -3,6 +3,8 @@ package hub |
| import ( |
| "context" |
| "encoding/json" |
| + |
| + "amadan.net/oficina/calls/protocol" |
| ) |
| // SetMedia is §15.19: an admitted peer reports its own microphone and |
| @@ -14,7 +16,8 @@ import ( |
| // |
| // §15.20 adds the receiving half to the same report — audioBlocked and |
| // noSoundFrom, each present only when it has bad news, and 2026-09-28's |
| -// screenStalled beside them, and §15.24's hearing after those — and nothing |
| +// screenStalled beside them, §15.24's hearing after those, and §15.30's |
| +// video asks last — and nothing |
| // about the rules: it is still the sender's own claim, recorded and |
| // carried in rosters, and fanned out only when it changes. |
| // |
| @@ -66,6 +69,15 @@ func (h *Hub) SetMedia(ctx context.Context, sqid, session string, from PeerID, m |
| if m.Hearing != nil { |
| next.Hearing = append(make([]PeerID, 0, len(m.Hearing)), m.Hearing...) |
| } |
| + // §15.30's asks, copied for the same reason as the lists. |
| + if len(m.Video) > 0 { |
| + next.Video = make(map[PeerID]protocol.VideoLevel, len(m.Video)) |
| + for k, v := range m.Video { |
| + next.Video[k] = v |
| + } |
| + } else { |
| + next.Video = nil |
| + } |
| p.Media = &next |
| payload, err := json.Marshal(next) |
| if err != nil { |
diff --git a/internal/calls/hub/media_test.go b/internal/calls/hub/media_test.go| index 480b845..3101eb5 100644 |
| --- a/internal/calls/hub/media_test.go |
| +++ b/internal/calls/hub/media_test.go |
| @@ -9,6 +9,8 @@ import ( |
| "sync" |
| "testing" |
| "time" |
| + |
| + "amadan.net/oficina/calls/protocol" |
| ) |
| // rosterMedia finds one peer's media in a roster, and whether the peer |
| @@ -488,3 +490,61 @@ func TestSetMediaCarriesHearing(t *testing.T) { |
| t.Fatalf("[] must decode as an empty, non-nil list: %+v %v", round, err) |
| } |
| } |
| + |
| +// Spec §15.30: a receiver's video asks are held, carried and fanned out |
| +// as the lists are — the hub's own copy, a change only when the set |
| +// changes, and an empty map the same as none. |
| +func TestSetMediaCarriesVideoAsks(t *testing.T) { |
| + now := time.Date(2026, 10, 28, 9, 0, 0, 0, time.UTC) |
| + h := testHub(&now) |
| + ctx := context.Background() |
| + a, _ := h.Open("r1", "sa", 1, "Ann", KindMember) |
| + h.Join(ctx, "r1", "sa", a.Peer) |
| + b, _ := h.Open("r1", "sb", 2, "Bob", KindMember) |
| + h.Join(ctx, "r1", "sb", b.Peer) |
| + drain(a.Sub) |
| + drain(b.Sub) |
| + |
| + asks := map[PeerID]protocol.VideoLevel{b.Peer: protocol.VideoMinimal} |
| + if err := h.SetMedia(ctx, "r1", "sa", a.Peer, MediaState{Video: asks}); err != nil { |
| + t.Fatal(err) |
| + } |
| + got := drain(b.Sub) |
| + want := `{"muted":false,"cameraOff":false,"video":{"` + string(b.Peer) + `":"minimal"}}` |
| + if len(got) != 1 || string(got[0].Payload) != want { |
| + t.Fatalf("payload %v, want %s", got, want) |
| + } |
| + asks[b.Peer] = protocol.VideoAudio |
| + c, _ := h.Open("r1", "sc", 3, "Cy", KindMember) |
| + h.Join(ctx, "r1", "sc", c.Peer) |
| + var ro *Roster |
| + for _, ev := range drain(c.Sub) { |
| + if ev.Type == TypeRoster { |
| + ro = ev.Roster |
| + } |
| + } |
| + drain(b.Sub) |
| + m, _ := rosterMedia(ro, a.Peer) |
| + if m == nil || m.Video[b.Peer] != protocol.VideoMinimal { |
| + t.Fatalf("roster media %+v, want the hub's own copy of the asks", m) |
| + } |
| + if err := h.SetMedia(ctx, "r1", "sa", a.Peer, MediaState{Video: map[PeerID]protocol.VideoLevel{b.Peer: protocol.VideoMinimal}}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := drain(b.Sub); len(got) != 0 { |
| + t.Fatalf("the same asks again reached Bob: %v", types(got)) |
| + } |
| + if err := h.SetMedia(ctx, "r1", "sa", a.Peer, MediaState{Video: map[PeerID]protocol.VideoLevel{}}); err != nil { |
| + t.Fatal(err) |
| + } |
| + got = drain(b.Sub) |
| + if len(got) != 1 || string(got[0].Payload) != `{"muted":false,"cameraOff":false}` { |
| + t.Fatalf("no asks sent %v", got) |
| + } |
| + if err := h.SetMedia(ctx, "r1", "sa", a.Peer, MediaState{}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := drain(b.Sub); len(got) != 0 { |
| + t.Fatalf("nil after {} reached Bob: %v", types(got)) |
| + } |
| +} |
diff --git a/internal/calls/quality.go b/internal/calls/quality.go| index 74f2fa4..62b5feb 100644 |
| --- a/internal/calls/quality.go |
| +++ b/internal/calls/quality.go |
| @@ -183,6 +183,9 @@ func validateQuality(raw []byte) (protocol.QualityReport, bool) { |
| if d := q.Devices; d != nil && (!enumOrEmpty(d.Input, protocol.DeviceKinds) || !enumOrEmpty(d.Output, protocol.DeviceKinds)) { |
| return q, false |
| } |
| + if e := q.Events; e != nil && !enumOrEmpty(e.VideoSetting, protocol.VideoSettings) { |
| + return q, false |
| + } |
| if len(q.Peers) > protocol.MaxQualityPeers { |
| return q, false |
| } |
| @@ -204,6 +207,9 @@ func validateQuality(raw []byte) (protocol.QualityReport, bool) { |
| } |
| } |
| } |
| + if e := p.Events; e != nil && (!levelSeconds(e.AskedSeconds) || !levelSeconds(e.SentSeconds)) { |
| + return q, false |
| + } |
| } |
| // Every number, wherever it is: finite, non-negative, under its |
| // ceiling, and rounded to a tenth for the line. |
| @@ -213,6 +219,23 @@ func validateQuality(raw []byte) (protocol.QualityReport, bool) { |
| return q, true |
| } |
| +// levelSeconds is §15.30's seconds-at-each-level: absent, or exactly one |
| +// number for each level, none of them null (boundNumbers checks the rest). |
| +func levelSeconds(v []*float64) bool { |
| + if v == nil { |
| + return true |
| + } |
| + if len(v) != protocol.VideoLevelCount { |
| + return false |
| + } |
| + for _, x := range v { |
| + if x == nil { |
| + return false |
| + } |
| + } |
| + return true |
| +} |
| + |
| func validClient(c *protocol.ReportClient) bool { |
| if !slices.Contains(reportApps, c.App) { |
| return false |
| @@ -237,7 +260,8 @@ func enumOrEmpty(v string, allowed []string) bool { return v == "" || slices.Con |
| // numberCeiling is a number's bound, by its JSON name. |
| func numberCeiling(name string) float64 { |
| switch name { |
| - case "seconds", "reconnectingSeconds", "cantHearSeconds", "freezeSeconds": |
| + case "seconds", "reconnectingSeconds", "cantHearSeconds", "freezeSeconds", |
| + "askedSeconds", "sentSeconds": |
| return protocol.MaxQualitySeconds |
| case "rtt", "jitter", "jitterBufferMs": |
| return protocol.MaxQualityMillis |
| @@ -334,6 +358,16 @@ func (a *app) logQuality(rep hub.Reporter, q protocol.QualityReport) { |
| attrs = append(attrs, slog.Float64(f.name, f.v)) |
| } |
| } |
| + // §15.30's, the same way: how long this client asked someone for less |
| + // video, how long it sent someone less, and the person's own setting. |
| + for _, f := range sum.video { |
| + if f.v > 0 { |
| + attrs = append(attrs, slog.Float64(f.name, f.v)) |
| + } |
| + } |
| + if q.Events != nil && q.Events.VideoSetting != "" { |
| + attrs = append(attrs, slog.String("videoSetting", q.Events.VideoSetting)) |
| + } |
| attrs = append(attrs, slog.Any("report", body)) |
| a.reportLog.LogAttrs(context.Background(), slog.LevelInfo, "calls: quality", attrs...) |
| } |
| @@ -359,6 +393,7 @@ type qualitySummary struct { |
| relay bool |
| lossPct, rtt, freezes, reconnecting float64 |
| screen []screenHead |
| + video []screenHead |
| } |
| // screenHead is one of the quality line's screen fields. |
| @@ -417,6 +452,18 @@ func summarize(q protocol.QualityReport) qualitySummary { |
| {"screenKeyframes", keyframes}, {"screenRebuilds", rebuilds}, {"screenReshares", reshares}, |
| {"screenFailures", failures}, {"screenDamped", damped}, {"screenEncoderStalls", encoderStalls}, |
| } |
| + var asked, sent float64 |
| + for _, p := range q.Peers { |
| + if e := p.Events; e != nil { |
| + for _, x := range e.AskedSeconds { |
| + asked += val(x) |
| + } |
| + for _, x := range e.SentSeconds { |
| + sent += val(x) |
| + } |
| + } |
| + } |
| + s.video = []screenHead{{"videoAsked", math.Round(asked*10) / 10}, {"videoSent", math.Round(sent*10) / 10}} |
| for _, p := range q.Peers { |
| if p.Path != nil && (p.Path.Local == "relay" || p.Path.Remote == "relay") { |
| s.relay = true |
diff --git a/internal/calls/signal.go b/internal/calls/signal.go| index 1edfc73..9843d96 100644 |
| --- a/internal/calls/signal.go |
| +++ b/internal/calls/signal.go |
| @@ -7,6 +7,7 @@ import ( |
| "io" |
| "net/http" |
| "regexp" |
| + "slices" |
| "strconv" |
| "unicode/utf8" |
| @@ -185,16 +186,16 @@ func exactKeys(raw json.RawMessage, want ...string) bool { |
| } |
| // maxMediaBytes bounds §15.19's payload before it is decoded. The |
| -// longest honest one — both booleans false, audioBlocked, and full |
| +// longest honest one — both booleans false, audioBlocked, full |
| // noSoundFrom, screenStalled and hearing lists of fifteen 32-character |
| -// peer ids each (§15.20, §15.21, §15.24) — is a little over 1,700 bytes; |
| -// the rest is room |
| +// peer ids each (§15.20, §15.21, §15.24), and a full §15.30 video map of |
| +// fifteen ids at "reduced" — is about 2,450 bytes; the rest is room |
| // for whitespace a client's encoder might add, and nothing a peer can use |
| // to put more on anyone's stream: what goes out is re-encoded from the |
| // validated values. |
| -const maxMediaBytes = 3072 |
| +const maxMediaBytes = 4096 |
| -// validateMedia is §15.19's shape as §15.20, §15.21 and §15.24 extend it: |
| +// validateMedia is §15.19's shape as §15.20, §15.21, §15.24 and §15.30 extend it: |
| // "muted" and "cameraOff", both booleans and both required; "audioBlocked", |
| // a boolean, and "noSoundFrom", "screenStalled" and "hearing", each an |
| // array of at most fifteen distinct peer ids, all optional. An empty |
| @@ -212,7 +213,7 @@ func validateMedia(raw json.RawMessage) (protocol.MediaState, int, string) { |
| if len(raw) > maxMediaBytes { |
| return protocol.MediaState{}, http.StatusRequestEntityTooLarge, "size" |
| } |
| - if !memberKeys(raw, []string{"muted", "cameraOff"}, []string{"audioBlocked", "noSoundFrom", "screenStalled", "hearing"}) { |
| + if !memberKeys(raw, []string{"muted", "cameraOff"}, []string{"audioBlocked", "noSoundFrom", "screenStalled", "hearing", "video"}) { |
| return protocol.MediaState{}, http.StatusBadRequest, "shape" |
| } |
| var p struct { |
| @@ -222,6 +223,7 @@ func validateMedia(raw json.RawMessage) (protocol.MediaState, int, string) { |
| NoSoundFrom json.RawMessage `json:"noSoundFrom"` |
| ScreenStalled json.RawMessage `json:"screenStalled"` |
| Hearing json.RawMessage `json:"hearing"` |
| + Video json.RawMessage `json:"video"` |
| } |
| if err := json.Unmarshal(raw, &p); err != nil || p.Muted == nil || p.CameraOff == nil { |
| return protocol.MediaState{}, http.StatusBadRequest, "shape" |
| @@ -247,9 +249,64 @@ func validateMedia(raw json.RawMessage) (protocol.MediaState, int, string) { |
| if p.Hearing != nil && m.Hearing == nil { |
| m.Hearing = []hub.PeerID{} |
| } |
| + if m.Video, ok = videoAsks(p.Video); !ok { |
| + return protocol.MediaState{}, http.StatusBadRequest, "shape" |
| + } |
| return m, 0, "" |
| } |
| +// videoAsks is §15.30's optional "video": an object (never null, never an |
| +// array) whose members are well-formed peer ids, none repeated — judged |
| +// by a token walk, because a decode into a map keeps the last of two |
| +// equal keys and says nothing — each with one of protocol.VideoLevels as |
| +// a string, at most protocol.MaxVideo of them. Absent and {} are both nil, |
| +// "normal from everyone", so they compare equal. As with the lists, an id |
| +// is checked for shape and not presence. |
| +func videoAsks(raw json.RawMessage) (map[hub.PeerID]protocol.VideoLevel, bool) { |
| + if raw == nil { |
| + return nil, true |
| + } |
| + dec := json.NewDecoder(bytes.NewReader(raw)) |
| + open, err := dec.Token() |
| + if err != nil { |
| + return nil, false |
| + } |
| + if d, ok := open.(json.Delim); !ok || d != '{' { |
| + return nil, false |
| + } |
| + out := map[hub.PeerID]protocol.VideoLevel{} |
| + for dec.More() { |
| + key, err := dec.Token() |
| + if err != nil { |
| + return nil, false |
| + } |
| + name, ok := key.(string) |
| + id := hub.PeerID(name) |
| + if !ok || !validPeerID(id) { |
| + return nil, false |
| + } |
| + if _, dup := out[id]; dup || len(out) >= protocol.MaxVideo { |
| + return nil, false |
| + } |
| + value, err := dec.Token() |
| + if err != nil { |
| + return nil, false |
| + } |
| + level, ok := value.(string) |
| + if !ok || !slices.Contains(protocol.VideoLevels, protocol.VideoLevel(level)) { |
| + return nil, false |
| + } |
| + out[id] = protocol.VideoLevel(level) |
| + } |
| + if _, err := dec.Token(); err != nil || dec.More() { |
| + return nil, false |
| + } |
| + if len(out) == 0 { |
| + return nil, true |
| + } |
| + return out, true |
| +} |
| + |
| // peerList is one of the media report's optional lists of peer ids: |
| // absent is nil, and present is an array (never null) of at most max |
| // well-formed ids with no repeats. Empty is the ordinary report, and is |
diff --git a/internal/callstest/media_test.go b/internal/callstest/media_test.go| index 229607f..5955f98 100644 |
| --- a/internal/callstest/media_test.go |
| +++ b/internal/callstest/media_test.go |
| @@ -162,7 +162,7 @@ func TestMediaShapes(t *testing.T) { |
| } |
| }) |
| t.Run("padded past the cap", func(t *testing.T) { |
| - payload := `{"muted":true,` + strings.Repeat(" ", 3072) + `"cameraOff":false}` |
| + payload := `{"muted":true,` + strings.Repeat(" ", 4096) + `"cameraOff":false}` |
| res, rb := a.signalRaw(sqid, `{"peer":"`+pa+`","type":"media","payload":`+payload+`}`) |
| if res.StatusCode != http.StatusRequestEntityTooLarge || !strings.Contains(string(rb), `"error":"too-large"`) { |
| t.Fatalf("%d %s, want 413 too-large", res.StatusCode, rb) |
| @@ -170,6 +170,52 @@ func TestMediaShapes(t *testing.T) { |
| }) |
| } |
| +// TestMediaVideoShapes is §15.30's video asks, refused as hard as the |
| +// lists are; a pair of its own, because the shapes above already spend |
| +// most of one peer's signalling budget. |
| +func TestMediaVideoShapes(t *testing.T) { |
| + a, sqid, pa, _ := chatPair(t) |
| + bad := []struct { |
| + name, payload string |
| + }{ |
| + // §15.30's video asks: an object of well-formed ids to known levels. |
| + {"video null", `{"muted":true,"cameraOff":false,"video":null}`}, |
| + {"video an array", `{"muted":true,"cameraOff":false,"video":["` + strings.Repeat("a", 32) + `"]}`}, |
| + {"video a string", `{"muted":true,"cameraOff":false,"video":"minimal"}`}, |
| + {"video a short id", `{"muted":true,"cameraOff":false,"video":{"abc":"minimal"}}`}, |
| + {"video an upper-case id", `{"muted":true,"cameraOff":false,"video":{"` + strings.Repeat("A", 32) + `":"minimal"}}`}, |
| + {"video normal", `{"muted":true,"cameraOff":false,"video":{"` + strings.Repeat("a", 32) + `":"normal"}}`}, |
| + {"video an unknown level", `{"muted":true,"cameraOff":false,"video":{"` + strings.Repeat("a", 32) + `":"tiny"}}`}, |
| + {"video a capitalised level", `{"muted":true,"cameraOff":false,"video":{"` + strings.Repeat("a", 32) + `":"Minimal"}}`}, |
| + {"video a number", `{"muted":true,"cameraOff":false,"video":{"` + strings.Repeat("a", 32) + `":2}}`}, |
| + {"video a null level", `{"muted":true,"cameraOff":false,"video":{"` + strings.Repeat("a", 32) + `":null}}`}, |
| + {"video an object level", `{"muted":true,"cameraOff":false,"video":{"` + strings.Repeat("a", 32) + `":{}}}`}, |
| + {"video a repeated id", `{"muted":true,"cameraOff":false,"video":{"` + strings.Repeat("a", 32) + `":"minimal","` + strings.Repeat("a", 32) + `":"audio"}}`}, |
| + {"video sixteen ids", `{"muted":true,"cameraOff":false,"video":{` + sixteenVideo() + `}}`}, |
| + {"video twice", `{"muted":true,"cameraOff":false,"video":{},"video":{}}`}, |
| + {"video capitalised", `{"muted":true,"cameraOff":false,"Video":{}}`}, |
| + {"video alone", `{"video":{}}`}, |
| + } |
| + for _, c := range bad { |
| + t.Run(c.name, func(t *testing.T) { |
| + body := `{"peer":"` + pa + `","type":"media","payload":` + c.payload + `}` |
| + res, rb := a.signalRaw(sqid, body) |
| + if res.StatusCode != http.StatusBadRequest || !strings.Contains(string(rb), `"error":"bad-request"`) { |
| + t.Fatalf("%d %s, want 400 bad-request", res.StatusCode, rb) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// sixteenVideo is a §15.30 video map one entry too long. |
| +func sixteenVideo() string { |
| + ids := strings.Split(sixteenIDs(), ",") |
| + for i := range ids { |
| + ids[i] += `:"reduced"` |
| + } |
| + return strings.Join(ids, ",") |
| +} |
| + |
| func sixteenIDs() string { |
| ids := make([]string, 16) |
| for i := range ids { |
| @@ -314,6 +360,63 @@ func TestMediaCarriesWhoTheReceiverHears(t *testing.T) { |
| } |
| } |
| +// Spec §15.30: a receiver's asks of each sender ride the same report — an |
| +// object of peer ids to levels, re-encoded with its keys in order after |
| +// everything else, {} the same as absent, and a change in it a change. |
| +func TestMediaCarriesVideoAsks(t *testing.T) { |
| + a, sqid, pa, sb := chatPair(t) |
| + x := strings.Repeat("0", 31) + "4" |
| + y := strings.Repeat("0", 31) + "2" |
| + res, rb := a.signalRaw(sqid, `{"peer":"`+pa+`","type":"media","payload":{"video":{"`+x+`":"audio","`+y+`":"minimal"},"muted":false,"cameraOff":false,"hearing":[]}}`) |
| + if res.StatusCode != http.StatusOK { |
| + t.Fatalf("video: %d %s", res.StatusCode, rb) |
| + } |
| + _, data, ok := sb.nextOf("media", 2*time.Second) |
| + want := `"payload":{"muted":false,"cameraOff":false,"hearing":[],"video":{"` + y + `":"minimal","` + x + `":"audio"}}` |
| + if !ok || !strings.Contains(string(data), want) { |
| + t.Fatalf("envelope %s, want %s", data, want) |
| + } |
| + // The same asks in another order are the same report: nothing goes out. |
| + res, _ = a.signalRaw(sqid, `{"peer":"`+pa+`","type":"media","payload":{"muted":false,"cameraOff":false,"hearing":[],"video":{"`+y+`":"minimal","`+x+`":"audio"}}}`) |
| + if res.StatusCode != http.StatusOK { |
| + t.Fatalf("repeat: %d", res.StatusCode) |
| + } |
| + if _, data, ok := sb.nextOf("media", 300*time.Millisecond); ok { |
| + t.Fatalf("an unchanged ask went out again: %s", data) |
| + } |
| + // A level changed is a change. |
| + res, _ = a.signal(sqid, pa, `{"type":"media","payload":{"muted":false,"cameraOff":false,"hearing":[],"video":{"`+y+`":"reduced"}}}`) |
| + if res.StatusCode != http.StatusOK { |
| + t.Fatalf("reduced: %d", res.StatusCode) |
| + } |
| + _, data, ok = sb.nextOf("media", 2*time.Second) |
| + if !ok || !strings.Contains(string(data), `"video":{"`+y+`":"reduced"}}`) { |
| + t.Fatalf("changed ask %s", data) |
| + } |
| + // Every list and the video map full at once fits the cap. |
| + ids := strings.Split(sixteenIDs(), ",")[:15] |
| + video := strings.Split(sixteenVideo(), ",")[:15] |
| + full := `{"muted":false,"cameraOff":false,"audioBlocked":true,"noSoundFrom":[` + strings.Join(ids, ",") + `],"screenStalled":[` + |
| + strings.Join(ids, ",") + `],"hearing":[` + strings.Join(ids, ",") + `],"video":{` + strings.Join(video, ",") + `}}` |
| + res, rb = a.signal(sqid, pa, `{"type":"media","payload":`+full+`}`) |
| + if res.StatusCode != http.StatusOK { |
| + t.Fatalf("everything full: %d %s", res.StatusCode, rb) |
| + } |
| + _, data, ok = sb.nextOf("media", 2*time.Second) |
| + if !ok || !strings.Contains(string(data), `"payload":`+full) { |
| + t.Fatalf("full report %s", data) |
| + } |
| + // {} is "normal from everyone", and goes out without the key. |
| + res, _ = a.signal(sqid, pa, `{"type":"media","payload":{"muted":false,"cameraOff":false,"hearing":[],"video":{}}}`) |
| + if res.StatusCode != http.StatusOK { |
| + t.Fatalf("empty: %d", res.StatusCode) |
| + } |
| + _, data, ok = sb.nextOf("media", 2*time.Second) |
| + if !ok || !strings.Contains(string(data), `"payload":{"muted":false,"cameraOff":false,"hearing":[]}`) || strings.Contains(string(data), "video") { |
| + t.Fatalf("empty asks %s", data) |
| + } |
| +} |
| + |
| // A waiting guest has nobody to tell: its report is the usual 404, and |
| // it hears nothing of the room's. |
| func TestMediaFromAWaitingGuestIsTheUsual404(t *testing.T) { |
diff --git a/internal/callstest/quality_test.go b/internal/callstest/quality_test.go| index 268f3a0..ed99da0 100644 |
| --- a/internal/callstest/quality_test.go |
| +++ b/internal/callstest/quality_test.go |
| @@ -260,6 +260,44 @@ func TestQualityReportsShareACallTagAndNameNothing(t *testing.T) { |
| } |
| } |
| +// Spec §15.30: the time asked for, and sent, less video is in the report |
| +// per peer and summed on the line's top level, with the person's own |
| +// setting, so `carlos logs` shows it without the report member. |
| +func TestQualityReportsCarryAdaptiveVideo(t *testing.T) { |
| + r := newReportRig(t, "") |
| + q := sampleQuality(r.peerB) |
| + q.Events.VideoSetting = "low" |
| + q.Peers[0].Events.AskedSeconds = []*float64{num(0), num(24.04), num(0)} |
| + q.Peers[0].Events.SentSeconds = []*float64{num(6), num(0), num(0)} |
| + if resp, _ := r.a.report(r.sqid, "quality", r.tokA, mustJSON(t, q)); resp.StatusCode != http.StatusAccepted { |
| + t.Fatalf("report: %d, want 202", resp.StatusCode) |
| + } |
| + lines := r.reports.lines(t, "calls: quality") |
| + if len(lines) != 1 { |
| + t.Fatalf("%d lines", len(lines)) |
| + } |
| + l := lines[0] |
| + if l["videoAsked"] != 24.0 || l["videoSent"] != 6.0 || l["videoSetting"] != "low" { |
| + t.Errorf("headline videoAsked=%v videoSent=%v videoSetting=%v", l["videoAsked"], l["videoSent"], l["videoSetting"]) |
| + } |
| + ev := l["report"].(map[string]any)["peers"].([]any)[0].(map[string]any)["events"].(map[string]any) |
| + if fmt.Sprint(ev["askedSeconds"]) != "[0 24 0]" || fmt.Sprint(ev["sentSeconds"]) != "[6 0 0]" { |
| + t.Errorf("per peer asked=%v sent=%v", ev["askedSeconds"], ev["sentSeconds"]) |
| + } |
| + // A quiet report names none of it. |
| + r.x.advance(10 * time.Second) |
| + if resp, _ := r.a.report(r.sqid, "quality", r.tokA, mustJSON(t, sampleQuality(r.peerB))); resp.StatusCode != http.StatusAccepted { |
| + t.Fatalf("quiet report: %d", resp.StatusCode) |
| + } |
| + quiet := r.reports.lines(t, "calls: quality")[1] |
| + for _, k := range []string{"videoAsked", "videoSent", "videoSetting"} { |
| + if _, ok := quiet[k]; ok { |
| + t.Errorf("a quiet report put %q on the line", k) |
| + } |
| + } |
| + r.assertClean(t) |
| +} |
| + |
| func TestQualityReportSchemaIsStrict(t *testing.T) { |
| r := newReportRig(t, "") |
| base := func() map[string]any { |
| @@ -293,7 +331,18 @@ func TestQualityReportSchemaIsStrict(t *testing.T) { |
| "a billion rebuilds and more": func(m map[string]any) { |
| peer0(m)["events"].(map[string]any)["autoRebuilds"] = 1e10 |
| }, |
| - "restarts as words": func(m map[string]any) { peer0(m)["events"].(map[string]any)["autoRestarts"] = "many" }, |
| + "restarts as words": func(m map[string]any) { peer0(m)["events"].(map[string]any)["autoRestarts"] = "many" }, |
| + // §15.30's seconds at each level: three numbers, nothing else. |
| + "two levels": func(m map[string]any) { peer0(m)["events"].(map[string]any)["askedSeconds"] = []any{1, 2} }, |
| + "four levels": func(m map[string]any) { peer0(m)["events"].(map[string]any)["sentSeconds"] = []any{1, 2, 3, 4} }, |
| + "a null level": func(m map[string]any) { peer0(m)["events"].(map[string]any)["askedSeconds"] = []any{1, nil, 3} }, |
| + "a level as words": func(m map[string]any) { peer0(m)["events"].(map[string]any)["askedSeconds"] = []any{1, "two", 3} }, |
| + "a negative level": func(m map[string]any) { peer0(m)["events"].(map[string]any)["sentSeconds"] = []any{1, -2, 3} }, |
| + "an hour at a level": func(m map[string]any) { peer0(m)["events"].(map[string]any)["askedSeconds"] = []any{0, 3600, 0} }, |
| + "levels as a map": func(m map[string]any) { |
| + peer0(m)["events"].(map[string]any)["askedSeconds"] = map[string]any{"minimal": 3} |
| + }, |
| + "an unknown setting": func(m map[string]any) { m["events"].(map[string]any)["videoSetting"] = "potato" }, |
| "the same peer twice": func(m map[string]any) { m["peers"] = append(m["peers"].([]any), peer0(m)) }, |
| "a peer list for a room": func(m map[string]any) { m["peers"] = "everyone" }, |
| "five peers": func(m map[string]any) { |
| @@ -361,6 +410,7 @@ func TestTheLargestQualityLineFitsThePlatformsLine(t *testing.T) { |
| Decoded: big(), Dropped: big(), Width: num(16384), Height: num(16384), FPS: num(240), Reattaches: big()} |
| } |
| q := sampleQuality(r.peerB) |
| + q.Events.VideoSetting = "audio" |
| q.Peers = nil |
| for i := 0; i < protocol.MaxQualityPeers; i++ { |
| q.Peers = append(q.Peers, protocol.PeerQuality{ |
| @@ -373,13 +423,16 @@ func TestTheLargestQualityLineFitsThePlatformsLine(t *testing.T) { |
| }, |
| Events: &protocol.PeerEvents{Reconnecting: big(), ReconnectingSeconds: num(599.9), CantHearSeconds: num(599.9), |
| NoSound: true, NoSoundFromUs: true, AudioBlocked: true, ScreenStalled: true, |
| - AutoRestarts: big(), AutoRebuilds: big()}, |
| + AutoRestarts: big(), AutoRebuilds: big(), |
| + AskedSeconds: []*float64{num(599.9), num(599.9), num(599.9)}, |
| + SentSeconds: []*float64{num(599.9), num(599.9), num(599.9)}}, |
| }) |
| } |
| if resp, _ := r.a.report(r.sqid, "quality", r.tokA, mustJSON(t, q)); resp.StatusCode != http.StatusAccepted { |
| t.Fatalf("the largest report: %d", resp.StatusCode) |
| } |
| line := strings.TrimSpace(r.reports.String()) |
| + t.Logf("the largest quality line is %d bytes", len(line)) |
| if n := len(line); n > 8192 { |
| t.Fatalf("the largest quality line is %d bytes; the platform keeps 8192", n) |
| } |
diff --git a/native/bridge/bridge.go b/native/bridge/bridge.go| index eca9ad9..4fe290f 100644 |
| --- a/native/bridge/bridge.go |
| +++ b/native/bridge/bridge.go |
| @@ -166,6 +166,20 @@ func (c *Client) SetHearing(peersJSON string) error { |
| return c.room.SetHearing(ids) |
| } |
| +// SetVideo is spec §15.30: what this app, as a receiver, asks each sender |
| +// for, as a JSON object of peer id to "reduced", "minimal" or "audio". |
| +// Only peers asked for less than normal are listed; "{}" or "" is normal |
| +// from everyone. Reported with the rest of this app's media state. |
| +func (c *Client) SetVideo(asksJSON string) error { |
| + var asks map[protocol.PeerID]protocol.VideoLevel |
| + if asksJSON != "" { |
| + if err := json.Unmarshal([]byte(asksJSON), &asks); err != nil { |
| + return errors.New("invalid video asks") |
| + } |
| + } |
| + return c.room.SetVideo(asks) |
| +} |
| + |
| // SendQuality posts one quality report (spec §15.26), a |
| // protocol.QualityReport as JSON, with the hello's report token. It |
| // answers what became of it, as a word — gomobile hands Swift every error |
diff --git a/protocol/messages.go b/protocol/messages.go| index 8b9618b..3d452a5 100644 |
| --- a/protocol/messages.go |
| +++ b/protocol/messages.go |
| @@ -159,8 +159,41 @@ type MediaState struct { |
| // omitted only when nil (omitzero), and an empty list travels as []. |
| // At most MaxHearing, each a peer id, none repeated. |
| Hearing []PeerID `json:"hearing,omitzero"` |
| + // Video (spec §15.30, 2026-10-28): what this client, as a receiver, |
| + // asks each sender for — the level of video it can take from them over |
| + // its own connection to them, chosen by its automatic watch or by the |
| + // person's own "Video quality" setting. Only peers asked for less than |
| + // normal are listed; nil (absent) is "normal from everyone", which is |
| + // also what a client from before this section means. A sender that |
| + // reads its own id here sends that receiver less video, by sender |
| + // parameters alone; audio is never reduced. At most MaxVideo entries, |
| + // each a peer id with one of the VideoLevels. |
| + Video map[PeerID]VideoLevel `json:"video,omitempty"` |
| } |
| +// VideoLevel is what a receiver asks one sender for (spec §15.30). |
| +type VideoLevel string |
| + |
| +const ( |
| + // VideoReduced: the camera at most 640×360, 15 fps, about 350 kbit/s; |
| + // a shared screen at a lower frame rate, at full size. |
| + VideoReduced VideoLevel = "reduced" |
| + // VideoMinimal: the camera at most 320×180, 8 fps, about 120 kbit/s |
| + // (paused instead while a screen is shared); a shared screen at a few |
| + // frames a second, smaller if it must be. |
| + VideoMinimal VideoLevel = "minimal" |
| + // VideoAudio: no camera at all to this receiver. A shared screen is |
| + // never paused for it: it goes as at minimal. |
| + VideoAudio VideoLevel = "audio" |
| +) |
| + |
| +// VideoLevels are the values MediaState.Video may carry. Normal is never |
| +// sent: it is the absence of an entry. |
| +var VideoLevels = []VideoLevel{VideoReduced, VideoMinimal, VideoAudio} |
| + |
| +// MaxVideo bounds MediaState.Video, for the same reason as MaxNoSoundFrom. |
| +const MaxVideo = 15 |
| + |
| // MaxNoSoundFrom bounds MediaState.NoSoundFrom: a room holds at most |
| // sixteen participations (§4.2), so fifteen others is every one there |
| // could be. |
| @@ -183,7 +216,21 @@ func (m MediaState) Equal(o MediaState) bool { |
| return false |
| } |
| return samePeers(m.NoSoundFrom, o.NoSoundFrom) && samePeers(m.ScreenStalled, o.ScreenStalled) && |
| - samePeers(m.Hearing, o.Hearing) |
| + samePeers(m.Hearing, o.Hearing) && sameVideo(m.Video, o.Video) |
| +} |
| + |
| +// sameVideo compares two §15.30 asks as sets: an empty map and a nil one |
| +// both say "normal from everyone". |
| +func sameVideo(a, b map[PeerID]VideoLevel) bool { |
| + if len(a) != len(b) { |
| + return false |
| + } |
| + for k, v := range a { |
| + if w, ok := b[k]; !ok || w != v { |
| + return false |
| + } |
| + } |
| + return true |
| } |
| func samePeers(a, b []PeerID) bool { |
diff --git a/protocol/quality.go b/protocol/quality.go| index 4e79e49..0fde3a7 100644 |
| --- a/protocol/quality.go |
| +++ b/protocol/quality.go |
| @@ -69,8 +69,15 @@ type CallEvents struct { |
| Reconnecting *float64 `json:"reconnecting,omitempty"` // times "Reconnecting…" was shown |
| ReconnectingSeconds *float64 `json:"reconnectingSeconds,omitempty"` // for how long |
| AudioBlocked bool `json:"audioBlocked,omitempty"` |
| + // VideoSetting is the person's own "Video quality" choice (spec |
| + // §15.30), when it is not Auto: "low" (Low bandwidth) or "audio" |
| + // (Audio only). VideoSettings. |
| + VideoSetting string `json:"videoSetting,omitempty"` |
| } |
| +// VideoSettings are the values CallEvents.VideoSetting may carry. |
| +var VideoSettings = []string{"low", "audio"} |
| + |
| // PeerQuality is one remote peer's connection, from this side. |
| type PeerQuality struct { |
| // Peer is the remote peer's id as this client knows it. The server |
| @@ -190,8 +197,21 @@ type PeerEvents struct { |
| // rebuilt from nothing (a `reset`). Older servers drop both. |
| AutoRestarts *float64 `json:"autoRestarts,omitempty"` |
| AutoRebuilds *float64 `json:"autoRebuilds,omitempty"` |
| + // Adaptive video (spec §15.30) during the window, as seconds at each |
| + // level below normal in the order reduced, minimal, audio: AskedSeconds |
| + // is how long this client, receiving, asked the peer for each; SentSeconds |
| + // how long this client, sending, sent the peer less because the peer |
| + // asked. Exactly three numbers when present (VideoLevelCount), arrays |
| + // rather than six members because the largest line has to fit the |
| + // platform's 8 KB. Older servers drop both. |
| + AskedSeconds []*float64 `json:"askedSeconds,omitempty"` |
| + SentSeconds []*float64 `json:"sentSeconds,omitempty"` |
| } |
| +// VideoLevelCount is the length of PeerEvents.AskedSeconds and |
| +// SentSeconds: one number for each of VideoLevels. |
| +const VideoLevelCount = 3 |
| + |
| // ProblemReport is "Report a problem": what the person typed, and the |
| // text "Copy call diagnostics" would copy, with the people in the call |
| // named by short peer ids rather than their names. |