Adapters: add Meet, Zoom, Teams (coloured border) + adapter registry
Front-loads the remaining visual adapters per the Signal→Meet→Zoom priority. All three reuse GridCallAnalyzer's coloured-border (saturated) detection path and share the new bottom-left name anchor: - GridCallAnalyzer: generalise nameAtBottom:Bool into a NameAnchor enum (.bottomCenter for Signal's centered footer, .bottomLeft for Meet/Zoom/Teams where the name hugs the tile's bottom-left corner, .center for completeness). tileRect estimates the tile up-and-right of a bottom-left name. - MeetAdapter (Google-blue ring, browser-hosted), ZoomAdapter (green/yellow border), TeamsAdapter (violet ring): coloured-border on, white-border off, bottom-left names. Geometry constants are first-pass pending real fixtures. - AdapterRegistry.adapter(for:) maps CallDetector.DetectedApp → AppAdapter so VisualObserver can be constructed when live visual capture is wired in; unmapped apps degrade to audio-only. Synthetic 4-tile tests: Meet picks each blue-bordered speaker with no adjacent-tile bleed, Zoom picks the green-bordered speaker, and Signal's white-only detector correctly ignores a coloured border. 18/18 XCTest pass.
This commit is contained in:
@@ -61,4 +61,67 @@ final class GridCallAnalyzerTests: XCTestCase {
|
||||
XCTAssertEqual(speaking.first?.bbox.midX ?? 0, 210, accuracy: 160)
|
||||
XCTAssertEqual(speaking.first?.bbox.midY ?? 0, 435, accuracy: 160)
|
||||
}
|
||||
|
||||
// MARK: - Coloured-border apps (Meet / Zoom / Teams): name in bottom-LEFT corner.
|
||||
|
||||
private func leftText(_ s: String, _ ctx: CGContext, leftBaseline: CGPoint, size: CGFloat) {
|
||||
let font = CTFontCreateWithName("Helvetica-Bold" as CFString, size, nil)
|
||||
let attrs = [kCTFontAttributeName: font,
|
||||
kCTForegroundColorAttributeName: CGColor(red: 1, green: 1, blue: 1, alpha: 1)] as CFDictionary
|
||||
let line = CTLineCreateWithAttributedString(CFAttributedStringCreate(nil, s as CFString, attrs)!)
|
||||
ctx.textPosition = leftBaseline
|
||||
CTLineDraw(line, ctx)
|
||||
}
|
||||
|
||||
private func coloredFrame(speakingIndex: Int, border: CGColor) -> CGImage {
|
||||
let W = 900, H = 640
|
||||
let ctx = CGContext(data: nil, width: W, height: H, bitsPerComponent: 8, bytesPerRow: 0,
|
||||
space: CGColorSpaceCreateDeviceRGB(),
|
||||
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!
|
||||
ctx.setFillColor(CGColor(red: 0.1, green: 0.1, blue: 0.12, alpha: 1))
|
||||
ctx.fill(CGRect(x: 0, y: 0, width: W, height: H))
|
||||
let rects: [(String, CGRect)] = [
|
||||
("GRANT", CGRect(x: 40, y: 340, width: 380, height: 250)),
|
||||
("SARAH", CGRect(x: 480, y: 340, width: 380, height: 250)),
|
||||
("DMITRI", CGRect(x: 40, y: 50, width: 380, height: 250)),
|
||||
("ALEX", CGRect(x: 480, y: 50, width: 380, height: 250)),
|
||||
]
|
||||
for (i, (name, rect)) in rects.enumerated() {
|
||||
ctx.setFillColor(CGColor(red: 0.18, green: 0.18, blue: 0.2, alpha: 1)); ctx.fill(rect)
|
||||
if i == speakingIndex {
|
||||
ctx.setStrokeColor(border); ctx.setLineWidth(8)
|
||||
ctx.stroke(rect.insetBy(dx: 4, dy: 4))
|
||||
}
|
||||
// Name in the bottom-LEFT corner (bottom-left origin: near minX/minY).
|
||||
leftText(name, ctx, leftBaseline: CGPoint(x: rect.minX + 16, y: rect.minY + 16), size: 40)
|
||||
}
|
||||
return ctx.makeImage()!
|
||||
}
|
||||
|
||||
func testMeetPicksBlueBorderedSpeaker() {
|
||||
let blue = CGColor(red: 0.16, green: 0.45, blue: 0.95, alpha: 1)
|
||||
for (idx, name) in ["GRANT", "SARAH", "DMITRI", "ALEX"].enumerated() {
|
||||
let obs = MeetAdapter().analyze(cgImage: coloredFrame(speakingIndex: idx, border: blue), at: 0)
|
||||
let speaking = Set(obs.filter { $0.speaking }.map { $0.name })
|
||||
XCTAssertEqual(speaking, [name], "Meet: only \(name) should be speaking")
|
||||
}
|
||||
// No border → no speaker.
|
||||
let none = MeetAdapter().analyze(cgImage: coloredFrame(speakingIndex: -1, border: blue), at: 0)
|
||||
XCTAssertTrue(none.filter { $0.speaking }.isEmpty)
|
||||
}
|
||||
|
||||
func testZoomPicksGreenBorderedSpeaker() {
|
||||
let green = CGColor(red: 0.2, green: 0.85, blue: 0.3, alpha: 1)
|
||||
let obs = ZoomAdapter().analyze(cgImage: coloredFrame(speakingIndex: 3, border: green), at: 0) // ALEX
|
||||
let speaking = Set(obs.filter { $0.speaking }.map { $0.name })
|
||||
XCTAssertEqual(speaking, ["ALEX"])
|
||||
}
|
||||
|
||||
func testWhiteBorderDetectorIgnoresColouredBorder() {
|
||||
// Signal looks only for the white border, so a coloured (Meet) border must
|
||||
// not register as a Signal speaker.
|
||||
let blue = CGColor(red: 0.16, green: 0.45, blue: 0.95, alpha: 1)
|
||||
let obs = SignalAdapter().analyze(cgImage: coloredFrame(speakingIndex: 0, border: blue), at: 0)
|
||||
XCTAssertTrue(obs.filter { $0.speaking }.isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user