Sharing failures were often reduced to a generic message, and changing Windows audio exclusion required reopening source selection. This phase keeps actionable failure context at the TV status indicator, adds live source-audio controls, and integrates independent capture, codec and ICE-lifetime repairs against the published contract. The audio controls reuse source replacement and the existing mixer; audio-only changes preserve video capture, encoded sources and connections. Source enumeration is bounded by the serialized control response. Codec preflight and H.264 decoder input enforce the existing native format. Gateway mappings are revalidated only for actual ICE gatherings. Website scripts and styles now share content-addressed build output. Browser/server v23, Native control v9, capture v7 and the 1440p ceiling stay unchanged. The held 4K/capability candidate and Magicsock transport are excluded. Documentation changes belong to the existing guides, standards and evidence owners. ## Validation - `npm run check`: type checking, 81 test files / 1,370 tests and the production Web build passed. - `npm run check:go`: Go tests, formatting, vet, cross-builds and Windows native capture regressions passed. A first run hit Windows temporary-directory cleanup after an unchanged SQLite test; five focused repetitions and the full rerun passed. - Native Host gates passed separately with H.264 and VP8: live/paused quality changes, minimized-window recovery, source replacement, Viewer decoding and complete process/port cleanup. The App Local entry/authentication/invitation gate passed. - Website/documentation build, documentation links and repository hygiene passed. Browser review covered Chinese/English, dark/light controls, 320px/360px and desktop layouts, audio selection/off state, troubleshooting dialog/ESC focus return, matching GitHub/Gitee architecture links and the embedded film. - macOS/Linux physical capture, Windows 10 exclusion and representative network/device coverage remain explicit evidence limits. CI must pass Linux race checks and native packaging before publication. ## Release notes ### 中文 这是一次分享体验与兼容性更新。Windows App 支持在开播后调整排除的应用声音;遇到分享失败时,也有更清楚的提示和排查入口。 #### 使用改进 - 在「分享设置 → 声音」中调整系统声音和排除的应用,无需停止分享。支持的 Windows 10 系统也会按实际能力显示排除选项。 - 分享失败提示保留具体原因。点击电视下方状态,可查看处理建议、诊断入口及对应的故障排查文档。 - 补全中英文常见问题说明,涵盖 App 连接、选源与编码、站点地址配置、严格网络和浏览器 HDR 限制。 #### 修复 - 修复窗口较多或名称较长时选源列表可能加载失败,以及部分独立窗口未列出的情况。 - 改善 Windows 窗口最小化、恢复后的采集衔接。 - 修复部分 Firefox 编码属性影响连接的问题,并使原生接收的格式预判与实际支持范围一致。 - 重连时刷新网关端口映射,避免沿用已失效的映射结果;加强原生 H.264 输入校验。 - 官网下载架构切换增加统一动效,脚本与样式使用带内容标识的地址,减少更新后的缓存混用。 更新 App 并刷新页面即可使用相应改进,无需迁移配置或房间数据。Windows 10 音频排除是否可用取决于系统能力。 ### English This update improves sharing controls and compatibility. Windows App users can change audio exclusion during a share, and sharing failures now provide clearer guidance and a direct troubleshooting entry. #### Improvements - Change system sound and the excluded application under **Sharing settings → Sound** without stopping the share. Supported Windows 10 installations can also expose exclusion after the capability check. - Sharing failures retain their specific cause. Select the status below the TV for recovery suggestions, diagnostics and the relevant troubleshooting guide. - Updated English and Chinese guides cover App connectivity, source selection and encoding, site-address configuration, restricted networks and Browser HDR limitations. #### Fixes - Fixed source lists failing with many windows or long titles, and certain independent application windows being omitted. - Improved Windows capture transitions when a window is minimized and restored. - Fixed stale Firefox codec attributes disrupting connections and aligned native receiver preflight with its supported formats. - Refresh gateway port mappings for new ICE gatherings instead of reusing stale results, and validate H.264 input before native decoding. - Added consistent motion to website architecture selection and content-hashed script/style URLs to prevent mixed cached versions. Update the App and reload the page to use the relevant improvements. No configuration or room-data migration is required. Windows 10 audio exclusion depends on actual system capability.
289 lines
9.9 KiB
Go
289 lines
9.9 KiB
Go
package nativecapture
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"io"
|
|
"log/slog"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestSourceListBoundsFollowSerializedOutput(t *testing.T) {
|
|
for _, check := range []struct {
|
|
name, title string
|
|
count int
|
|
truncated bool
|
|
}{
|
|
{"empty", "Window", 0, false},
|
|
{"long-localized-titles", strings.Repeat("界", 512), 64, false},
|
|
{"many-windows", "Window", maxSources, false},
|
|
{"escaped-titles", strings.Repeat("<", 512), 100, true},
|
|
{"full-list", strings.Repeat("a", maxSourceTitleBytes), maxSources, true},
|
|
} {
|
|
t.Run(check.name, func(t *testing.T) {
|
|
targets := make([]CaptureTarget, check.count)
|
|
for index := range targets {
|
|
targets[index] = CaptureTarget{Kind: "window", SourceID: strconv.Itoa(index + 1),
|
|
PID: 1, CreationTime: "1", Title: check.title}
|
|
}
|
|
var input bytes.Buffer
|
|
encoder := json.NewEncoder(&input)
|
|
// The platform helpers need not use Go's HTML escaping.
|
|
encoder.SetEscapeHTML(false)
|
|
if err := encoder.Encode(targets); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := readSources(&input)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if (!check.truncated && len(got) != len(targets)) ||
|
|
(check.truncated && (len(got) == 0 || len(got) >= len(targets))) {
|
|
t.Fatalf("source count = %d of %d", len(got), len(targets))
|
|
}
|
|
for index, target := range got {
|
|
if target != targets[index] {
|
|
t.Fatal("bounded list changed a source's identity or title")
|
|
}
|
|
}
|
|
output, _ := json.Marshal(got)
|
|
if len(output) > maxSourceListBytes || string(output) == "null" {
|
|
t.Fatalf("source-list response exceeds its contract: %d bytes", len(output))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSourceListRejectsMalformedOutputEvenAfterTheReturnedPrefix(t *testing.T) {
|
|
valid := `{"kind":"display","sourceId":"1","title":"Display"}`
|
|
full := `{"kind":"display","sourceId":"1","title":"` + strings.Repeat("a", maxSourceTitleBytes) + `"}`
|
|
for _, payload := range []string{
|
|
`null`, `{}`, `[`, `[` + valid, `[` + valid + `] []`,
|
|
`[{"kind":"display","sourceId":"1","title":"Display","extra":true}]`,
|
|
`[` + strings.Repeat(valid+",", maxSources) + valid + `]`,
|
|
`[` + strings.Repeat(full+",", 100) + `{"kind":"wrong","sourceId":"1","title":"Window"}]`,
|
|
`[]` + strings.Repeat(" ", maxSourceOutputBytes),
|
|
} {
|
|
if _, err := readSources(strings.NewReader(payload)); err == nil {
|
|
t.Fatal("invalid helper output was accepted")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCaptureStopHelper(t *testing.T) {
|
|
mode := os.Getenv("PIIK_CAPTURE_STOP_FIXTURE")
|
|
if mode == "" {
|
|
return
|
|
}
|
|
if err := writeFrame(os.Stdout, Frame{Kind: FrameStatus, Data: []byte("ready")}); err != nil {
|
|
os.Exit(2)
|
|
}
|
|
if mode == "unresponsive" {
|
|
time.Sleep(10 * time.Second)
|
|
os.Exit(3)
|
|
}
|
|
if strings.HasPrefix(mode, "blocked-output-") {
|
|
// A producer can fill stdout before returning to its control reader.
|
|
if err := writeFrame(os.Stdout, Frame{Kind: FrameVP8, Width: 1280, Height: 720,
|
|
Duration: time.Second / 30, Data: make([]byte, 1024*1024)}); err != nil {
|
|
os.Exit(6)
|
|
}
|
|
}
|
|
frame, err := readFrame(os.Stdin)
|
|
if err != nil || frame.Kind != FrameControl || string(frame.Data) != "Q" {
|
|
os.Exit(4)
|
|
}
|
|
// A platform capture must get time to release its session before process exit.
|
|
time.Sleep(50 * time.Millisecond)
|
|
if err := os.WriteFile(os.Getenv("PIIK_CAPTURE_STOP_MARKER"), []byte("released"), 0600); err != nil {
|
|
os.Exit(5)
|
|
}
|
|
os.Exit(0)
|
|
}
|
|
|
|
func TestCaptureStopUsesOneBoundedRetirementPath(t *testing.T) {
|
|
executable, err := os.Executable()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, mode := range []string{"explicit", "parent", "both", "unresponsive",
|
|
"blocked-output-explicit", "blocked-output-parent", "blocked-output-both"} {
|
|
t.Run(mode, func(t *testing.T) {
|
|
ctx, cancel := context.WithCancel(t.Context())
|
|
defer cancel()
|
|
marker := filepath.Join(t.TempDir(), "released")
|
|
stream, err := startStreamWithEnvironment(ctx, executable,
|
|
[]string{"-test.run=^TestCaptureStopHelper$"},
|
|
[]string{"PIIK_CAPTURE_STOP_FIXTURE=" + mode, "PIIK_CAPTURE_STOP_MARKER=" + marker})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer stream.Close()
|
|
if _, err := stream.Read(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
stop := strings.TrimPrefix(mode, "blocked-output-")
|
|
if stop != "explicit" {
|
|
cancel()
|
|
}
|
|
if stop == "explicit" || stop == "both" {
|
|
go stream.Close()
|
|
}
|
|
select {
|
|
case <-stream.Done():
|
|
case <-time.After(captureStopTimeout + 3*time.Second):
|
|
t.Fatal("capture retirement exceeded its stop budget")
|
|
}
|
|
_, err = os.Stat(marker)
|
|
if mode == "unresponsive" {
|
|
if !os.IsNotExist(err) {
|
|
t.Fatalf("unresponsive capture unexpectedly released: %v", err)
|
|
}
|
|
} else if err != nil {
|
|
t.Fatalf("capture was killed before receiving its stop command: %v", err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCaptureStopPreservesAnInFlightFrame(t *testing.T) {
|
|
input, output := io.Pipe()
|
|
control, commands := io.Pipe()
|
|
done := make(chan error)
|
|
var finishOnce sync.Once
|
|
finish := func() {
|
|
finishOnce.Do(func() {
|
|
_ = output.Close()
|
|
_ = input.Close()
|
|
_ = control.Close()
|
|
close(done)
|
|
})
|
|
}
|
|
stream := &Stream{input: input, key: commands, done: done, cancel: finish}
|
|
t.Cleanup(func() { finish(); _ = stream.Close() })
|
|
expected := Frame{Kind: FrameVP8, Width: 1280, Height: 720,
|
|
Duration: time.Second / 30, Data: bytes.Repeat([]byte{0x12}, 1024*1024)}
|
|
var encoded bytes.Buffer
|
|
if err := writeFrame(&encoded, expected); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
read := make(chan error, 1)
|
|
go func() {
|
|
frame, err := stream.Read()
|
|
if err == nil && (frame.Kind != expected.Kind || !bytes.Equal(frame.Data, expected.Data)) {
|
|
err = errors.New("retirement discarded part of the in-flight frame")
|
|
}
|
|
read <- err
|
|
}()
|
|
// Pipe.Write returns after Read has entered the frame, before its header is complete.
|
|
if _, err := output.Write(encoded.Bytes()[:1]); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
closed := make(chan struct{})
|
|
go func() { _ = stream.Close(); close(closed) }()
|
|
frame, err := readFrame(control)
|
|
if err != nil || frame.Kind != FrameControl || string(frame.Data) != "Q" {
|
|
t.Fatalf("stop command = %+v, %v", frame, err)
|
|
}
|
|
if _, err := output.Write(encoded.Bytes()[1:]); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := <-read; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
finish()
|
|
<-closed
|
|
}
|
|
|
|
func TestDiagnosticStderrOverflowDoesNotStopTheChildReader(t *testing.T) {
|
|
for _, discard := range []bool{false, true} {
|
|
buffer := &boundedBuffer{limit: 4, discardOverflow: discard}
|
|
var forwarded bytes.Buffer
|
|
writer := io.MultiWriter(buffer, &forwarded)
|
|
_, err := io.Copy(writer, strings.NewReader("stage=capture-closed\ndetail=more evidence\n"))
|
|
if discard {
|
|
if err != nil || string(buffer.Bytes()) != "nce\n" || !strings.Contains(forwarded.String(), "more evidence") {
|
|
t.Fatalf("diagnostic stderr stopped or lost its bounded tail: %q, %q, %v", buffer.Bytes(), forwarded.String(), err)
|
|
}
|
|
} else if err == nil {
|
|
t.Fatal("strict probe output no longer rejects overflow")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestVideoOutputGroupCountIsBoundedBeforeProcessStartup(t *testing.T) {
|
|
options := VideoOptions{
|
|
Target: CaptureTarget{Kind: "display", SourceID: "1", Title: "Display"},
|
|
Codec: "vp8",
|
|
Profile: VideoProfile{Width: 1280, Height: 720, Framerate: 30,
|
|
Bitrate: 3_000_000, Preference: "balanced"},
|
|
}
|
|
for _, groups := range []int{-1, maxOutputs - 1} {
|
|
options.OutputGroups = groups
|
|
if _, err := StartVideo(t.Context(), "", options); err == nil || err.Error() != "native video target is invalid" {
|
|
t.Fatalf("group count %d reached process startup: %v", groups, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCaptureFailureDebugUsesOnlyFixedFields(t *testing.T) {
|
|
previous := slog.Default()
|
|
t.Cleanup(func() { slog.SetDefault(previous) })
|
|
for _, check := range []struct {
|
|
name, stderr, stage, hresult string
|
|
debug, canceled, success, logged bool
|
|
}{
|
|
{name: "closed", stderr: "result=window-capture-failed\r\nstage=capture-closed\r\ndetail=private window title\r\n", stage: "capture-closed", debug: true, logged: true},
|
|
{name: "device", stderr: "stage=windows-runtime\nhresult=0x887A0005\ndetail=C:\\private\\capture.exe", stage: "windows-runtime", hresult: "0x887a0005", debug: true, logged: true},
|
|
{name: "malformed", stderr: "stage=C:\\private\\capture.exe\nhresult=0x887a0005 private\n", debug: true, logged: true},
|
|
{name: "oversized-stage", stderr: "stage=" + strings.Repeat("a", 65), debug: true, logged: true},
|
|
{name: "private-detail", stderr: "detail=private window title\n", debug: true, logged: true},
|
|
{name: "disabled", stderr: "stage=capture-closed\n", debug: false},
|
|
{name: "clean", stderr: "stage=capture-closed\n", debug: true, success: true},
|
|
{name: "canceled", stderr: "detail=private cancellation\n", debug: true, canceled: true},
|
|
{name: "failure-before-cancel", stderr: "stage=capture-closed\n", stage: "capture-closed", debug: true, canceled: true, logged: true},
|
|
} {
|
|
t.Run(check.name, func(t *testing.T) {
|
|
var output bytes.Buffer
|
|
level := slog.LevelInfo
|
|
if check.debug {
|
|
level = slog.LevelDebug
|
|
}
|
|
slog.SetDefault(slog.New(slog.NewJSONHandler(&output, &slog.HandlerOptions{Level: level})))
|
|
ctx, cancel := context.WithCancel(t.Context())
|
|
defer cancel()
|
|
if check.canceled {
|
|
cancel()
|
|
}
|
|
var failure error
|
|
if !check.success {
|
|
failure = errors.New("private executable path")
|
|
}
|
|
logCaptureFailure(ctx, failure, 2, []byte(check.stderr))
|
|
if !check.logged {
|
|
if output.Len() != 0 {
|
|
t.Fatalf("unexpected diagnostic: %s", output.String())
|
|
}
|
|
return
|
|
}
|
|
var record map[string]any
|
|
if err := json.Unmarshal(output.Bytes(), &record); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(record) != 8 || record["event"] != "capture-process-failed" || record["msg"] != "piik-client" ||
|
|
record["level"] != "DEBUG" || record["exitCode"] != float64(2) || record["stage"] != check.stage ||
|
|
record["hresult"] != check.hresult || record["canceled"] != check.canceled || strings.Contains(output.String(), "private") {
|
|
t.Fatalf("diagnostic leaked or changed fields: %s", output.String())
|
|
}
|
|
})
|
|
}
|
|
}
|