Refactoring #3
+32
-34
@@ -28,6 +28,12 @@ const (
|
||||
WIN_HEIGHT int32 = 720
|
||||
)
|
||||
|
||||
const (
|
||||
placeholderWidth uint32 = 1
|
||||
placeholderHeight uint32 = 1
|
||||
placeholderStride uint32 = 4
|
||||
)
|
||||
|
||||
type appArgs struct {
|
||||
ShowHelp bool
|
||||
Domain string
|
||||
@@ -308,31 +314,30 @@ func main() {
|
||||
defer sdl.DestroyAudioStream(audioStream)
|
||||
}
|
||||
|
||||
var r *renderer.Renderer
|
||||
if args.VideoFlowId != "" {
|
||||
var w, h, stride uint32
|
||||
if syncSrc != nil {
|
||||
w, h, stride = syncSrc.Width(), syncSrc.Height(), syncSrc.Stride()
|
||||
} else {
|
||||
w, h, stride = videoSrc.Width(), videoSrc.Height(), videoSrc.Stride()
|
||||
}
|
||||
r, err = renderer.New(renderer.Config{
|
||||
// Create renderer
|
||||
r, err := renderer.New(renderer.Config{
|
||||
PhysDevice: vkPhysDevice,
|
||||
Device: vkDevice,
|
||||
Queue: vkQueue,
|
||||
Surface: vkSurf,
|
||||
Window: windowHandler,
|
||||
GraphicsFamily: gfx,
|
||||
VideoWidth: w,
|
||||
VideoHeight: h,
|
||||
VideoStride: stride,
|
||||
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())
|
||||
vkPhysDevice,
|
||||
vkDevice,
|
||||
vkQueue,
|
||||
r.CmdPool(),
|
||||
r.RenderPass(),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -340,8 +345,15 @@ func main() {
|
||||
r.ImGuiDraw = func(cmd vk.CommandBuffer) {
|
||||
guiBackend.RecordDraw(cmd, gui.LastDrawData())
|
||||
}
|
||||
defer vkDevice.WaitIdle()
|
||||
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 (
|
||||
@@ -381,14 +393,6 @@ func main() {
|
||||
if params.video != "" && params.audio != "" {
|
||||
s, e := source.OpenSameDomainSync(params.domain, params.video, params.audio)
|
||||
if e == nil {
|
||||
if r != nil {
|
||||
newSize := vk.DeviceSize(s.Stride()) * vk.DeviceSize(s.Height())
|
||||
if newSize != r.FrameSize() {
|
||||
if e = r.RecreateBuffers(newSize); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
}
|
||||
syncSrc = s
|
||||
aChans = s.Channels()
|
||||
audioBatch = uint64(s.AudioRate().Num) / uint64(s.Rate().Num)
|
||||
@@ -401,14 +405,6 @@ func main() {
|
||||
} else if params.video != "" {
|
||||
s, e := source.Open(params.domain, params.video)
|
||||
if e == nil {
|
||||
if r != nil {
|
||||
newSize := vk.DeviceSize(s.Stride()) * vk.DeviceSize(s.Height())
|
||||
if newSize != r.FrameSize() {
|
||||
if e = r.RecreateBuffers(newSize); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
}
|
||||
videoSrc = s
|
||||
return nil
|
||||
}
|
||||
@@ -614,9 +610,10 @@ func main() {
|
||||
sdl.SetWindowFullscreen(windowHandler, true)
|
||||
}
|
||||
var (
|
||||
displayedVideoWidth uint32
|
||||
displayedVideoHeight uint32
|
||||
displayedVideoStride uint32
|
||||
displayedVideoWidth uint32 = placeholderWidth
|
||||
displayedVideoHeight uint32 = placeholderHeight
|
||||
displayedVideoStride uint32 = placeholderStride
|
||||
hasDisplayedVideo bool = false
|
||||
|
||||
fps float64
|
||||
lastIndex uint64
|
||||
@@ -699,6 +696,7 @@ func main() {
|
||||
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) &&
|
||||
@@ -738,7 +736,7 @@ func main() {
|
||||
cimgui.Text(fmt.Sprintf("FPS: %.1f", fps))
|
||||
cimgui.Text(fmt.Sprintf("Dropped: %d", dropped))
|
||||
cimgui.Text(fmt.Sprintf("Index: %d", shownIndex))
|
||||
if displayedVideoWidth != 0 && displayedVideoHeight != 0 {
|
||||
if hasDisplayedVideo {
|
||||
cimgui.Text(fmt.Sprintf(
|
||||
"Video: %dx%d",
|
||||
displayedVideoWidth,
|
||||
|
||||
Reference in New Issue
Block a user