package main import ( "context" "errors" "fmt" "io" "log" mxladapter "mxl-player/internal/adapter/mxl" "mxl-player/internal/imgui" "mxl-player/internal/output" "mxl-player/internal/playback" "mxl-player/internal/renderer" "mxl-player/internal/sdl" "mxl-player/internal/source" "os" "runtime" "time" "unsafe" cimgui "github.com/AllenDang/cimgui-go/imgui" vk "github.com/christerso/vulkan-go/vk" pflag "github.com/spf13/pflag" ) const ( APP_NAME = "MXL Player" APP_VER = "0.1.0" WIN_WIDTH int32 = 1280 WIN_HEIGHT int32 = 720 ) const ( placeholderWidth uint32 = 1 placeholderHeight uint32 = 1 placeholderStride uint32 = 4 ) const ( initialRetryDelay = 500 * time.Millisecond maxRetryDelay = 5 * time.Second ) type appArgs struct { ShowHelp bool Domain string VideoDomain string AudioDomain string VideoFlowId string AudioFlowId string IsFullscreen bool PlaybackId uint32 GpuId uint32 IsVerbose bool ListAudio bool ListGPU bool SyncRequested bool MaxAttempts int } func printCliHelp(fs *pflag.FlagSet) { fmt.Printf("%s %s\n", APP_NAME, APP_VER) fmt.Println("Usage: mxl-player [-d ] [-v ] [-a ] [options]") fmt.Println(" [-g ] [-p ] [--verbose]") fmt.Println(" or: mxl-player [--list-playback] [--list-gpu]") fmt.Println(" or: mxl-player (and set everything in GUI)") fmt.Println() fs.PrintDefaults() } func printUsage(w io.Writer) { fmt.Fprintln(w, "Usage: mxl-player [-d ] [-v ] [-a ] [options]") fmt.Fprintln(w, "Try 'mxl-player -h' for more information.") } func checkMXLargs(args appArgs) { if args.VideoFlowId == "" && args.AudioFlowId == "" { return } if args.Domain == "" { fmt.Fprintln( os.Stderr, "You must provide a domain when a feed UUID is configured", ) printUsage(os.Stderr) os.Exit(2) } 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) } } func main() { // timelapse video: 5fbec3b1-1b0f-417d-9059-8b94a47197ed // timelapse audio: 5fbec3b1-1b0f-417d-9059-8b94a47197ec // f1 video: 5fbec3b1-1b0f-417d-9059-8b94a47197ef // f1 audio: 5fbec3b1-1b0f-417d-9059-8b94a47197eb var args appArgs flagSet := pflag.NewFlagSet(APP_NAME, pflag.ContinueOnError) 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.VideoFlowId, "video", "v", "", "Video flow UUID") flagSet.StringVarP(&args.AudioFlowId, "audio", "a", "", "Audio flow UUID") flagSet.IntVar( &args.MaxAttempts, "max-attempts", 0, "Maximum connection attempts per playback lifecycle; 0 retries indefinitely", ) flagSet.BoolVarP(&args.IsFullscreen, "fullscreen", "f", false, "Run app in fullscreen mode") flagSet.Uint32VarP(&args.GpuId, "gpu-id", "g", 0, "GPU id [TODO]") flagSet.Uint32VarP(&args.PlaybackId, "playback-id", "p", 0, "Playback audio device id") flagSet.BoolVar(&args.IsVerbose, "verbose", false, "Verbose output [TODO]") flagSet.BoolVar(&args.ListAudio, "list-playback", false, "List audio playback devices and exit") flagSet.BoolVar(&args.ListGPU, "list-gpu", false, "List GPUs and exit") if err := flagSet.Parse(os.Args[1:]); err != nil { fmt.Fprintln(os.Stderr, err) printUsage(os.Stderr) os.Exit(2) } if args.ShowHelp { printCliHelp(flagSet) return } if args.MaxAttempts < 0 { fmt.Fprintln(os.Stderr, "--max-attempts cannot be negative") printUsage(os.Stderr) os.Exit(2) } retryPolicy := playback.RetryPolicy{ MaxAttempts: args.MaxAttempts, InitialDelay: initialRetryDelay, MaxDelay: maxRetryDelay, } if err := retryPolicy.Validate(); err != nil { fmt.Fprintln(os.Stderr, "invalid retry configuration:", err) os.Exit(2) } if !args.ListAudio && !args.ListGPU { checkMXLargs(args) } // path selection useVideoSlot := args.AudioFlowId == "" useAudioSlot := args.AudioFlowId != "" && args.VideoFlowId == "" runtime.LockOSThread() if err := sdl.Load(); err != nil { panic(err) } if !sdl.Init(sdl.InitVideo | sdl.InitAudio) { log.Fatalf("SDL_Init: %s", sdl.GetError()) return } sdlAudioDevice := sdl.AudioDeviceDefaultPlayback if args.PlaybackId != 0 { sdlAudioDevice = args.PlaybackId } // List audio playback devices and exit if args.ListAudio { devs := sdl.GetAudioPlaybackDevices() fmt.Println("Available playback audio devices") fmt.Println("id name") for _, d := range devs { fmt.Println(d.ID, d.Name) } return } windowHandler := sdl.CreateWindow(fmt.Sprintf("%s %s", APP_NAME, APP_VER), WIN_WIDTH, WIN_HEIGHT, sdl.WindowVulkan|sdl.WindowResizable) if windowHandler == 0 { sdl.Quit() log.Fatalf("SDL_CreateWindow: %s", sdl.GetError()) return } // ImGui init gui := imgui.New() defer gui.Destroy() sdl.StartTextInput(windowHandler) defer sdl.StopTextInput(windowHandler) // fin on ImGui init if err := vk.Load(); err != nil { panic(err) } sdlExtensions := sdl.VulkanGetInstanceExtensions() if len(sdlExtensions) == 0 { log.Fatal("sdlVulkanGetInstanceExtensions is 0") return } var vkLayers []string vkExtensions := append(sdlExtensions, vk.ExtDebugUtils) vkInstance, err := vk.CreateInstance(vk.InstanceConfig{ ApplicationName: APP_NAME, EngineName: "no engine", Extensions: vkExtensions, Layers: vkLayers, }) if err != nil { log.Fatalf("%s", err) panic(err) } defer vkInstance.Destroy() var vkSurface uint64 if !sdl.VulkanCreateSurface(windowHandler, uintptr(vkInstance), 0, &vkSurface) { log.Fatalf("SDL_Vulkan_CreateSurface: %s", sdl.GetError()) return } vkSurf := vk.SurfaceKHR(vkSurface) defer vkInstance.DestroySurface(vkSurf) devices, err := vkInstance.EnumeratePhysicalDevices() if err != nil || len(devices) == 0 { panic("No Vulkan devices") } // List GPU's and exit if args.ListGPU { fmt.Println("Available Vulkan physical devices:") fmt.Println("id name (type)") for i, pd := range devices { info := pd.Info() fmt.Printf("%2d %s (%s)\n", i, info.Name, info.Type) } return } vkPhysDevice := devices[0] gfx, err := vkPhysDevice.GraphicsFamily() if err != nil { panic(err.Error()) } if !vkPhysDevice.SurfaceSupport(gfx, vkSurf) { log.Fatalf("graphics queue cannot present") return } vkDevice, vkQueue, err := vkPhysDevice.CreateDevice(vk.DeviceConfig{ GraphicsFamily: gfx, Extensions: []string{"VK_KHR_swapchain"}, }) if err != nil { panic(err) } defer vkDevice.Destroy() var ( syncSrc *source.SyncSource videoSrc *source.Source audioSrc *source.AudioSource audioStream uintptr audioBatch uint64 aChans uint64 ) interleaveAudio := func(samples [][]byte) []byte { frameBytes := int(audioBatch) * int(aChans) * 4 out := make([]byte, frameBytes) for ch := uint64(0); ch < aChans; ch++ { srcBytes := samples[ch] for i := uint64(0); i < audioBatch; i++ { srcOff := i * 4 dstOff := (i*aChans + ch) * 4 if srcOff+4 <= uint64(len(srcBytes)) { copy(out[dstOff:dstOff+4], srcBytes[srcOff:srcOff+4]) } } } return out } switch { case args.VideoFlowId != "" && args.AudioFlowId != "": syncSrc, err = source.OpenSameDomainSync(args.Domain, args.VideoFlowId, args.AudioFlowId) if err != nil { log.Fatalf("sync source: %v", err) } aChans = syncSrc.Channels() audioBatch = uint64(syncSrc.AudioRate().Num) / uint64(syncSrc.Rate().Num) if audioBatch == 0 { audioBatch = 1 } audioStream = sdl.OpenAudioDeviceStream(sdlAudioDevice, sdl.AudioSpec{ Format: sdl.AudioF32, Channels: int32(aChans), Freq: int32(syncSrc.AudioRate().Num / syncSrc.AudioRate().Den), }) if audioStream == 0 { log.Fatalf("audio: %s", sdl.GetError()) } sdl.ResumeAudioStreamDevice(audioStream) fmt.Printf("sync: video %dx%d audio %dch batch=%d\n", syncSrc.Width(), syncSrc.Height(), aChans, audioBatch) case args.VideoFlowId != "": // VideoSlot owns opening and closing the video reader. case args.AudioFlowId != "": // AudioSlot owns opening and closing the audio reader. default: // No configured feeds. Renderer and GUI use the placeholder. } defer func() { if syncSrc != nil { _ = syncSrc.Close() } if videoSrc != nil { _ = videoSrc.Close() } if audioSrc != nil { _ = audioSrc.Close() } }() if audioStream != 0 { defer sdl.DestroyAudioStream(audioStream) } // Create renderer r, err := renderer.New(renderer.Config{ PhysDevice: vkPhysDevice, Device: vkDevice, Queue: vkQueue, Surface: vkSurf, Window: windowHandler, GraphicsFamily: gfx, VideoWidth: placeholderWidth, VideoHeight: placeholderHeight, VideoStride: placeholderStride, }) if err != nil { panic(err) } defer r.Destroy() // Create GUI backend guiBackend, err := imgui.NewVulkanBackend( vkPhysDevice, vkDevice, vkQueue, r.CmdPool(), r.RenderPass(), ) if err != nil { panic(err) } defer guiBackend.Destroy() r.ImGuiDraw = func(cmd vk.CommandBuffer) { guiBackend.RecordDraw(cmd, gui.LastDrawData()) } if err := r.StageFrame( []byte{0, 0, 0, 255}, placeholderWidth, placeholderHeight, placeholderStride, ); err != nil { panic(err) } defer vkDevice.WaitIdle() // GUI state (accessible from doReconnect + goroutine) var ( domainStr string = args.Domain videoStr string = args.VideoFlowId audioStr string = args.AudioFlowId showStats bool = true ) videoActive := args.VideoFlowId != "" audioActive := useAudioSlot ctx, cancel := context.WithCancel(context.Background()) defer cancel() type reconnectParams struct { domain string video string audio string } // Reconnect requests from GUI or automatic retry control := make(chan reconnectParams, 1) videoBridge := playback.NewVideoBridge() statusStore := playback.NewStatusStore() videoWorker, err := playback.NewVideoWorker( mxladapter.VideoFactory{}, videoBridge, retryPolicy, mxladapter.ShouldRetry, func(status playback.Status) { statusStore.Observe(status) if status.Err != nil { log.Printf( "video: state=%v attempt=%d failed=%d: %v", status.State, status.Attempt, status.FailedAttempts, status.Err, ) return } log.Printf( "video: state=%v attempt=%d failed=%d", status.State, status.Attempt, status.FailedAttempts, ) }, ) if err != nil { panic(err) } videoSlot, err := playback.NewVideoSlot(videoWorker) if err != nil { panic(err) } videoCommands := make(chan playback.FeedConfig, 1) audioOutput := output.NewSDLAudioSink(sdlAudioDevice) defer audioOutput.Close() audioWorker, err := playback.NewAudioWorker( mxladapter.AudioFactory{}, audioOutput, retryPolicy, mxladapter.ShouldRetry, func(status playback.Status) { statusStore.Observe(status) if status.Err != nil { log.Printf( "audio: state=%v attempt=%d failed=%d: %v", status.State, status.Attempt, status.FailedAttempts, status.Err, ) return } log.Printf( "audio: state=%v attempt=%d failed=%d", status.State, status.Attempt, status.FailedAttempts, ) }, ) if err != nil { panic(err) } audioSlot, err := playback.NewAudioSlot(audioWorker) if err != nil { panic(err) } audioCommands := make(chan playback.FeedConfig, 1) reopen := func(params reconnectParams) error { // Close current sources if syncSrc != nil { _ = syncSrc.Close() syncSrc = nil } if videoSrc != nil { _ = videoSrc.Close() videoSrc = nil } if audioSrc != nil { _ = audioSrc.Close() audioSrc = nil } // Try once. Return error if fails — caller loops back to select // and can pick up newer reconnect request. if params.video != "" && params.audio != "" { s, e := source.OpenSameDomainSync(params.domain, params.video, params.audio) if e == nil { syncSrc = s aChans = s.Channels() audioBatch = uint64(s.AudioRate().Num) / uint64(s.Rate().Num) if audioBatch == 0 { audioBatch = 1 } return nil } return e } else if params.video != "" { s, e := source.Open(params.domain, params.video) if e == nil { videoSrc = s return nil } return e } else if params.audio != "" { s, e := source.OpenAudio(params.domain, params.audio) if e == nil { audioSrc = s aChans = s.Channels() audioBatch = uint64(s.Rate().Num) / (100 * uint64(s.Rate().Den)) if audioBatch == 0 { audioBatch = 1 } return nil } return e } return fmt.Errorf("reopen: no flow specified") } enqueueVideoConfig := func(config playback.FeedConfig) { select { case <-videoCommands: default: } select { case videoCommands <- config: default: } } enqueueAudioConfig := func(config playback.FeedConfig) { select { case <-audioCommands: default: } select { case audioCommands <- config: default: } } doReconnect := func() { if useVideoSlot { videoActive = videoStr != "" config := playback.FeedConfig{} if videoStr != "" { config = playback.FeedConfig{ Domain: domainStr, UUID: videoStr, Active: true, } } enqueueVideoConfig(config) return } if useAudioSlot { audioActive = audioStr != "" config := playback.FeedConfig{} if audioStr != "" { config = playback.FeedConfig{ Domain: domainStr, UUID: audioStr, Active: true, } } enqueueAudioConfig(config) return } // legacy select { case <-control: default: } control <- reconnectParams{domain: domainStr, video: videoStr, audio: audioStr} } playbackDone := make(chan struct{}) go func() { defer close(playbackDone) if useVideoSlot { err := videoSlot.Run( ctx, playback.FeedConfig{ Domain: args.Domain, UUID: args.VideoFlowId, Active: args.VideoFlowId != "", }, videoCommands, ) if err != nil && !errors.Is(err, context.Canceled) { log.Printf("video slot: %v", err) } return } if useAudioSlot { err := audioSlot.Run( ctx, playback.FeedConfig{ Domain: args.Domain, UUID: args.AudioFlowId, Active: args.AudioFlowId != "", }, audioCommands, ) if err != nil && !errors.Is(err, context.Canceled) { log.Printf("audio slot: %v", err) } return } // Audio-only mode: independent loop. if audioSrc != nil && syncSrc == nil && videoSrc == nil { for { select { case <-ctx.Done(): return case params := <-control: if params.video != "" || params.audio != "" { if rerr := reopen(params); rerr != nil { if errors.Is(rerr, context.Canceled) { return } log.Printf("source: reopen failed: %v, retrying", rerr) select { case <-time.After(500 * time.Millisecond): case <-ctx.Done(): return } select { case control <- params: default: } } } continue default: } queued := sdl.GetAudioStreamQueued(audioStream) maxQueued := int32(audioBatch) * int32(aChans) * 4 * 20 if queued > maxQueued { select { case <-time.After(10 * time.Millisecond): case <-ctx.Done(): return } continue } f, err := audioSrc.NextAudio(ctx, audioBatch, 20*time.Millisecond) if err != nil { if errors.Is(err, context.Canceled) { return } log.Printf("source: %v", err) params := reconnectParams{domain: domainStr, video: videoStr, audio: audioStr} select { case <-control: default: } select { case <-time.After(500 * time.Millisecond): case <-ctx.Done(): return } select { case control <- params: default: } continue } if f.Samples != nil && audioStream != 0 { sdl.PutAudioStreamData(audioStream, interleaveAudio(f.Samples)) } } } // Video bridge provides backpressure: only one borrowed frame is in flight. for { select { case <-ctx.Done(): return case params := <-control: if rerr := reopen(params); rerr != nil { if errors.Is(rerr, context.Canceled) { return } log.Printf("source: reopen failed: %v, retrying", rerr) select { case <-time.After(500 * time.Millisecond): case <-ctx.Done(): return } select { case control <- params: default: // Preserve an already queued, potentially newer request. } } continue default: } var videoFrame playback.VideoFrame if syncSrc != nil { vFrame, aFrame, err := syncSrc.NextSync(ctx, audioBatch, 200*time.Millisecond) if err != nil { if errors.Is(err, context.Canceled) { return } log.Printf("source: %v", err) // Request a reconnect after the read failure. params := reconnectParams{ domain: domainStr, video: videoStr, audio: audioStr, } select { case control <- params: default: // Preserve an already queued, potentially newer request. } continue } videoFrame = playback.VideoFrame{ Index: vFrame.Index, Width: vFrame.Width, Height: vFrame.Height, Stride: vFrame.Stride, Size: vFrame.Size, Invalid: vFrame.Invalid, Payload: vFrame.Payload, } if aFrame.Samples != nil && audioStream != 0 { sdl.PutAudioStreamData(audioStream, interleaveAudio(aFrame.Samples)) } } else if videoSrc != nil { f, err := videoSrc.NextCtx(ctx, 200*time.Millisecond) if err != nil { if errors.Is(err, context.Canceled) { return } log.Printf("source: %v", err) params := reconnectParams{ domain: domainStr, video: videoStr, audio: audioStr, } select { case control <- params: default: // Preserve an already queued, potentially newer request. } continue } videoFrame = playback.VideoFrame{ Index: f.Index, Width: f.Width, Height: f.Height, Stride: f.Stride, Size: f.Size, Invalid: f.Invalid, Payload: f.Payload, } } if err := videoBridge.ConsumeVideo(ctx, videoFrame); err != nil { if errors.Is(err, context.Canceled) { return } log.Printf("video output: %v", err) return } } }() running := true resized := false fullscreen := args.IsFullscreen if fullscreen { sdl.SetWindowFullscreen(windowHandler, true) } var ( displayedVideoWidth uint32 = placeholderWidth displayedVideoHeight uint32 = placeholderHeight displayedVideoStride uint32 = placeholderStride hasDisplayedVideo bool = false fps float64 lastIndex uint64 dropped uint64 frameCount uint64 lastReport time.Time lastFrame time.Time ) lastFrame = time.Now() for running { frameStart := time.Now() var event [128]byte for sdl.PollEvent(unsafe.Pointer(&event[0])) { eventType := *(*uint32)(unsafe.Pointer(&event[0])) switch eventType { case sdl.EventQuit: running = false case sdl.EventWindowResized, sdl.EventPixelSizeChanged: resized = true case sdl.EventKeyDown: if gui.IO().WantCaptureKeyboard() { break } key := *(*int32)(unsafe.Pointer(&event[28])) switch uint32(key) { case sdl.KeyQ: fallthrough case sdl.KeyEscape: running = false case sdl.KeyF: fullscreen = !fullscreen sdl.SetWindowFullscreen(windowHandler, fullscreen) resized = true case sdl.KeyF1: showStats = !showStats } } gui.ProcessEvent(&event) } if !running { break } if resized && r != nil { if err := r.RecreateSwapchain(); err != nil { if errors.Is(err, renderer.ErrMinimized) { resized = true continue } panic(err) } resized = false } var shownIndex uint64 hasFrame := false frameCtx, frameCancel := context.WithTimeout(ctx, 100*time.Millisecond) pendingFrame, frameErr := videoBridge.Next(frameCtx) frameCancel() if pendingFrame != nil { var stageErr error if r != nil { stageErr = r.StageFrame( pendingFrame.Frame.Payload, pendingFrame.Frame.Width, pendingFrame.Frame.Height, pendingFrame.Frame.Stride, ) } // Release the borrowed payload before reacting to a staging error pendingFrame.Complete(stageErr) if stageErr != nil { panic(stageErr) } shownIndex = pendingFrame.Frame.Index displayedVideoWidth = pendingFrame.Frame.Width displayedVideoHeight = pendingFrame.Frame.Height displayedVideoStride = pendingFrame.Frame.Stride hasDisplayedVideo = true hasFrame = true } else if frameErr != nil && !errors.Is(frameErr, context.DeadlineExceeded) && !errors.Is(frameErr, context.Canceled) { panic(frameErr) } // stats if hasFrame { if lastIndex != 0 && shownIndex > lastIndex { if g := shownIndex - lastIndex - 1; g > 0 { dropped += g } } lastIndex = shownIndex frameCount++ if now := time.Now(); now.Sub(lastReport) >= time.Second { dt := now.Sub(lastReport).Seconds() fps = float64(frameCount) / dt fmt.Printf("fps=%.1f dropped=%d idx=%d frameTime=%.2fms\n", fps, dropped, shownIndex, float64(now.Sub(frameStart).Microseconds())/1000.0) frameCount = 0 dropped = 0 lastReport = now } } // end of stats if r != nil { gui.BeginFrame(time.Since(lastFrame), int32(r.Extent().Width), int32(r.Extent().Height)) // test widget // cimgui.Begin("Test") if showStats { cimgui.SetNextWindowPos(cimgui.Vec2{X: 10, Y: 10}) cimgui.SetNextWindowSize(cimgui.Vec2{X: 200, Y: 200}) cimgui.BeginV("Stats", &showStats, cimgui.WindowFlagsNoTitleBar|cimgui.WindowFlagsNoResize|cimgui.WindowFlagsNoScrollbar) cimgui.Text(fmt.Sprintf("FPS: %.1f", fps)) cimgui.Text(fmt.Sprintf("Dropped: %d", dropped)) cimgui.Text(fmt.Sprintf("Index: %d", shownIndex)) if hasDisplayedVideo { cimgui.Text(fmt.Sprintf( "Video: %dx%d", displayedVideoWidth, displayedVideoHeight, )) } cimgui.Text("\nPress F1 to hide stats") cimgui.Text("Q or Esc to quit") cimgui.Text("F for fullscreen") cimgui.End() } cimgui.Begin("Connection") cimgui.InputTextWithHint("Domain", "/dev/shm/mxl", &domainStr, 0, nil) cimgui.InputTextWithHint("Video UUID", "", &videoStr, 0, nil) cimgui.InputTextWithHint("Audio UUID", "", &audioStr, 0, nil) cimgui.Checkbox("Show stats", &showStats) if cimgui.Button("Connect") { doReconnect() } if useVideoSlot && videoActive { cimgui.SameLine() if cimgui.Button("Stop video") { videoActive = false enqueueVideoConfig( playback.FeedConfig{ Domain: domainStr, UUID: videoStr, Active: false, }) } } if useVideoSlot && !videoActive && videoStr != "" { cimgui.SameLine() if cimgui.Button("Resume video") { videoActive = true enqueueVideoConfig(playback.FeedConfig{ Domain: domainStr, UUID: videoStr, Active: true, }) } } if useVideoSlot && videoStr != "" { if cimgui.Button("Remove video") { videoActive = false videoStr = "" enqueueVideoConfig(playback.FeedConfig{}) } } if useVideoSlot { if videoActive { cimgui.Text("Video desired: active") } else if videoStr != "" { cimgui.Text("Video desired: stopped") } else { cimgui.Text("Video desired: not configured") } if status, ok := statusStore.Snapshot(playback.UnitVideo); ok { cimgui.Text(fmt.Sprintf( "Video actual: %s", status.State, )) cimgui.Text(fmt.Sprintf( "Attempt: %d, failed: %d", status.Attempt, status.FailedAttempts, )) if status.RetryIn > 0 { cimgui.Text(fmt.Sprintf( "Retry in: %s", status.RetryIn.Round(time.Millisecond), )) } if status.Err != nil { cimgui.TextWrapped(status.Err.Error()) } } else { cimgui.Text("Video actual: not started") } } if useAudioSlot && audioActive { if cimgui.Button("Stop audio") { audioActive = false enqueueAudioConfig(playback.FeedConfig{ Domain: domainStr, UUID: audioStr, Active: false, }) } } if useAudioSlot && !audioActive && audioStr != "" { if cimgui.Button("Resume audio") { audioActive = true enqueueAudioConfig(playback.FeedConfig{ Domain: domainStr, UUID: audioStr, Active: true, }) } } if useAudioSlot && audioStr != "" { if cimgui.Button("Remove audio") { audioActive = false audioStr = "" enqueueAudioConfig(playback.FeedConfig{}) } } if useAudioSlot { if audioActive { cimgui.Text("Audio desired: active") } else if audioStr != "" { cimgui.Text("Audio desired: stopped") } else { cimgui.Text("Audio desired: not configured") } if status, ok := statusStore.Snapshot(playback.UnitAudio); ok { cimgui.Text(fmt.Sprintf( "Audio actual: %s", status.State, )) cimgui.Text(fmt.Sprintf( "Attempt: %d, failed: %d", status.Attempt, status.FailedAttempts, )) if status.RetryIn > 0 { cimgui.Text(fmt.Sprintf( "Retry in: %s", status.RetryIn.Round(time.Millisecond), )) } if status.Err != nil { cimgui.TextWrapped(status.Err.Error()) } } else { cimgui.Text("Audio actual: not started") } } cimgui.End() gui.EndFrame() lastFrame = time.Now() // end of test widget err := r.DrawFrame( displayedVideoWidth, displayedVideoHeight, displayedVideoStride, ) if errors.Is(err, renderer.ErrOutOfDate) { if rerr := r.RecreateSwapchain(); rerr != nil { if errors.Is(rerr, renderer.ErrMinimized) { resized = true continue } panic(rerr) } continue } if err != nil { panic(err) } } else { time.Sleep(10 * time.Millisecond) } } cancel() <-playbackDone }