Skip to content

Commit 0076192

Browse files
committed
Fix PulseAudio readiness and scope ffmpeg audio tuning
1 parent 114f47b commit 0076192

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

server/cmd/wrapper/main.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ func main() {
188188
startAll("mutter")
189189
}
190190
waitForSocket(pulseSocket, 10*time.Second)
191+
waitForPulseSink(os.Getenv("PULSE_SINK"), 10*time.Second)
191192
startAll("chromium")
192193
waitForSocket(dbusSocket, 10*time.Second)
193194
if prof == profileHeadful && webrtc {
@@ -332,3 +333,21 @@ func fatalf(format string, args ...any) {
332333
logf(format, args...)
333334
os.Exit(1)
334335
}
336+
337+
func waitForPulseSink(sinkName string, timeout time.Duration) {
338+
sinkName = strings.TrimSpace(sinkName)
339+
if sinkName == "" {
340+
logf("WARNING: pulse sink name is empty; skipping sink wait")
341+
return
342+
}
343+
344+
deadline := time.Now().Add(timeout)
345+
for time.Now().Before(deadline) {
346+
out, err := exec.Command("pactl", "-s", "unix:"+pulseSocket, "list", "short", "sinks").Output()
347+
if err == nil && strings.Contains(string(out), "\t"+sinkName+"\t") {
348+
return
349+
}
350+
time.Sleep(50 * time.Millisecond)
351+
}
352+
logf("WARNING: pulse sink %s not ready after %s", sinkName, timeout)
353+
}

server/lib/recorder/ffmeg_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package recorder
22

33
import (
44
"path/filepath"
5+
"runtime"
56
"testing"
67
"time"
78

@@ -113,6 +114,20 @@ func TestFFmpegArgs_IncludesPulseAudioWhenEnabled(t *testing.T) {
113114
assert.NotContains(t, args, "aresample=async=1:first_pts=0")
114115
}
115116

117+
func TestFFmpegArgs_VideoOnlyLinuxUsesWallclockTimestamps(t *testing.T) {
118+
if runtime.GOOS != "linux" {
119+
t.Skip("linux-only ffmpeg flag behavior")
120+
}
121+
122+
tempDir := t.TempDir()
123+
args, err := ffmpegArgs(defaultParams(tempDir), filepath.Join(tempDir, "out.mp4"))
124+
require.NoError(t, err)
125+
126+
assert.Contains(t, args, "-use_wallclock_as_timestamps")
127+
assert.NotContains(t, args, "veryfast")
128+
assert.NotContains(t, args, "zerolatency")
129+
}
130+
116131
func TestFFmpegRecorder_ForceStop(t *testing.T) {
117132
tempDir := t.TempDir()
118133
rec := &FFmpegRecorder{

server/lib/recorder/ffmpeg.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,11 +563,15 @@ func ffmpegArgs(params FFmpegRecordingParams, outputPath string) ([]string, erro
563563

564564
// Video encoding
565565
"-c:v", "libx264",
566-
"-preset", "veryfast",
567-
"-tune", "zerolatency",
568566
"-profile:v", "high", // Explicit web-compatible profile
569567
"-pix_fmt", "yuv420p", // Web-standard pixel format
570568
}...)
569+
if runtime.GOOS == "linux" && recordAudio {
570+
args = append(args,
571+
"-preset", "veryfast",
572+
"-tune", "zerolatency",
573+
)
574+
}
571575

572576
if recordAudio {
573577
args = append(args, []string{
@@ -577,6 +581,9 @@ func ffmpegArgs(params FFmpegRecordingParams, outputPath string) ([]string, erro
577581
"-ac", "2",
578582
}...)
579583
}
584+
if runtime.GOOS == "linux" && !recordAudio {
585+
args = append(args, "-use_wallclock_as_timestamps", "1")
586+
}
580587

581588
args = append(args, []string{
582589
// Timestamp handling for reliable playback

0 commit comments

Comments
 (0)