support separate audio and video domains

This commit is contained in:
Dmitry Sergeev
2026-08-28 23:09:50 +03:00
parent 27dcbd1b40
commit 774361df47
2 changed files with 71 additions and 36 deletions
+70 -35
View File
@@ -75,25 +75,26 @@ func printUsage(w io.Writer) {
}
func checkMXLargs(args appArgs) {
if args.VideoFlowId == "" && args.AudioFlowId == "" {
return
checkDomain := func(label, domain string) {
if domain == "" {
fmt.Fprintf(os.Stderr, "%s domain is required when its UUID is configured\n", label)
printUsage(os.Stderr)
os.Exit(2)
}
info, err := os.Stat(domain)
if err != nil || !info.IsDir() {
fmt.Fprintf(os.Stderr, "Invalid %s MXL domain: %s\n", label, domain)
fmt.Fprintln(os.Stderr, "Domain must be a directory in tmpfs")
printUsage(os.Stderr)
os.Exit(2)
}
}
if args.Domain == "" {
fmt.Fprintln(
os.Stderr,
"You must provide a domain when a feed UUID is configured",
)
printUsage(os.Stderr)
os.Exit(2)
if args.VideoFlowId != "" {
checkDomain("video", args.VideoDomain)
}
fi, err := os.Stat(args.Domain)
if err != nil || !fi.IsDir() {
fmt.Fprintln(os.Stderr, "Invalid MXL domain:", args.Domain)
fmt.Fprintln(os.Stderr, "Domain must be a directory in tmpfs")
printUsage(os.Stderr)
os.Exit(2)
if args.AudioFlowId != "" {
checkDomain("audio", args.AudioDomain)
}
}
@@ -107,7 +108,15 @@ func main() {
flagSet.SortFlags = false
flagSet.Usage = func() { printUsage(os.Stderr) }
flagSet.BoolVarP(&args.ShowHelp, "help", "h", false, "Show help message and exit")
flagSet.StringVarP(&args.Domain, "domain", "d", "", "MXL domain directory")
flagSet.StringVarP(
&args.Domain,
"domain",
"d",
"",
"Default MXL domain for feeds without a specific domain",
)
flagSet.StringVar(&args.VideoDomain, "video-domain", "", "MXL domain for the video feed")
flagSet.StringVar(&args.AudioDomain, "audio-domain", "", "MXL domain for the audio feed")
flagSet.StringVarP(&args.VideoFlowId, "video", "v", "", "Video flow UUID")
flagSet.StringVarP(&args.AudioFlowId, "audio", "a", "", "Audio flow UUID")
flagSet.BoolVarP(
@@ -152,9 +161,25 @@ func main() {
fmt.Fprintln(os.Stderr, "invalid retry configuration:", err)
os.Exit(2)
}
if args.VideoDomain == "" {
args.VideoDomain = args.Domain
}
if args.AudioDomain == "" {
args.AudioDomain = args.Domain
}
if !args.ListAudio && !args.ListGPU {
checkMXLargs(args)
}
if args.SyncRequested &&
args.VideoFlowId != "" &&
args.AudioFlowId != "" &&
args.VideoDomain != args.AudioDomain {
fmt.Fprintln(
os.Stderr,
"--sync currently requires video and audio to use the same MXL domain",
)
os.Exit(2)
}
// path selection
useLegacySync := args.SyncRequested &&
args.VideoFlowId != "" &&
@@ -292,7 +317,7 @@ func main() {
switch {
case useLegacySync:
syncSrc, err = source.OpenSameDomainSync(
args.Domain,
args.VideoDomain,
args.VideoFlowId,
args.AudioFlowId,
)
@@ -378,10 +403,11 @@ func main() {
// GUI state (accessible from doReconnect + goroutine)
var (
domainStr string = args.Domain
videoStr string = args.VideoFlowId
audioStr string = args.AudioFlowId
showStats bool = true
videoDomainStr string = args.VideoDomain
audioDomainStr string = args.AudioDomain
videoStr string = args.VideoFlowId
audioStr string = args.AudioFlowId
showStats bool = true
)
videoActive := args.VideoFlowId != ""
audioActive := args.AudioFlowId != ""
@@ -552,7 +578,7 @@ func main() {
videoConfig := playback.FeedConfig{}
if videoStr != "" {
videoConfig = playback.FeedConfig{
Domain: domainStr,
Domain: videoDomainStr,
UUID: videoStr,
Active: true,
}
@@ -561,7 +587,7 @@ func main() {
audioConfig := playback.FeedConfig{}
if audioStr != "" {
audioConfig = playback.FeedConfig{
Domain: domainStr,
Domain: audioDomainStr,
UUID: audioStr,
Active: true,
}
@@ -572,11 +598,19 @@ func main() {
return
}
// legacy
if videoDomainStr != audioDomainStr {
log.Printf(
"sync reconnect rejected: video domain %q differs from audio domain %q",
videoDomainStr,
audioDomainStr,
)
return
}
select {
case <-control:
default:
}
control <- reconnectParams{domain: domainStr, video: videoStr, audio: audioStr}
control <- reconnectParams{domain: videoDomainStr, video: videoStr, audio: audioStr}
}
playbackDone := make(chan struct{})
@@ -593,7 +627,7 @@ func main() {
err := videoSlot.Run(
ctx,
playback.FeedConfig{
Domain: args.Domain,
Domain: args.VideoDomain,
UUID: args.VideoFlowId,
Active: args.VideoFlowId != "",
},
@@ -610,7 +644,7 @@ func main() {
err := audioSlot.Run(
ctx,
playback.FeedConfig{
Domain: args.Domain,
Domain: args.AudioDomain,
UUID: args.AudioFlowId,
Active: args.AudioFlowId != "",
},
@@ -669,7 +703,7 @@ func main() {
return
}
log.Printf("source: %v", err)
params := reconnectParams{domain: domainStr, video: videoStr, audio: audioStr}
params := reconnectParams{domain: videoDomainStr, video: videoStr, audio: audioStr}
select {
case <-control:
default:
@@ -731,7 +765,7 @@ func main() {
log.Printf("source: %v", err)
// Request a reconnect after the read failure.
params := reconnectParams{
domain: domainStr,
domain: videoDomainStr,
video: videoStr,
audio: audioStr,
}
@@ -763,7 +797,7 @@ func main() {
}
log.Printf("source: %v", err)
params := reconnectParams{
domain: domainStr,
domain: videoDomainStr,
video: videoStr,
audio: audioStr,
}
@@ -941,7 +975,8 @@ func main() {
cimgui.End()
}
cimgui.Begin("Connection")
cimgui.InputTextWithHint("Domain", "/dev/shm/mxl", &domainStr, 0, nil)
cimgui.InputTextWithHint("Video domain", "/dev/shm/mxl", &videoDomainStr, 0, nil)
cimgui.InputTextWithHint("Audio domain", "/dev/shm/mxl", &audioDomainStr, 0, nil)
cimgui.InputTextWithHint("Video UUID", "", &videoStr, 0, nil)
cimgui.InputTextWithHint("Audio UUID", "", &audioStr, 0, nil)
if cimgui.Button("Connect") {
@@ -954,7 +989,7 @@ func main() {
videoActive = false
enqueueVideoConfig(
playback.FeedConfig{
Domain: domainStr,
Domain: videoDomainStr,
UUID: videoStr,
Active: false,
})
@@ -965,7 +1000,7 @@ func main() {
if cimgui.Button("Resume video") {
videoActive = true
enqueueVideoConfig(playback.FeedConfig{
Domain: domainStr,
Domain: videoDomainStr,
UUID: videoStr,
Active: true,
})
@@ -1016,7 +1051,7 @@ func main() {
if cimgui.Button("Stop audio") {
audioActive = false
enqueueAudioConfig(playback.FeedConfig{
Domain: domainStr,
Domain: audioDomainStr,
UUID: audioStr,
Active: false,
})
@@ -1027,7 +1062,7 @@ func main() {
if cimgui.Button("Resume audio") {
audioActive = true
enqueueAudioConfig(playback.FeedConfig{
Domain: domainStr,
Domain: audioDomainStr,
UUID: audioStr,
Active: true,
})