Refactoring #3
+51
-53
@@ -28,6 +28,12 @@ const (
|
|||||||
WIN_HEIGHT int32 = 720
|
WIN_HEIGHT int32 = 720
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
placeholderWidth uint32 = 1
|
||||||
|
placeholderHeight uint32 = 1
|
||||||
|
placeholderStride uint32 = 4
|
||||||
|
)
|
||||||
|
|
||||||
type appArgs struct {
|
type appArgs struct {
|
||||||
ShowHelp bool
|
ShowHelp bool
|
||||||
Domain string
|
Domain string
|
||||||
@@ -308,40 +314,46 @@ func main() {
|
|||||||
defer sdl.DestroyAudioStream(audioStream)
|
defer sdl.DestroyAudioStream(audioStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
var r *renderer.Renderer
|
// Create renderer
|
||||||
if args.VideoFlowId != "" {
|
r, err := renderer.New(renderer.Config{
|
||||||
var w, h, stride uint32
|
PhysDevice: vkPhysDevice,
|
||||||
if syncSrc != nil {
|
Device: vkDevice,
|
||||||
w, h, stride = syncSrc.Width(), syncSrc.Height(), syncSrc.Stride()
|
Queue: vkQueue,
|
||||||
} else {
|
Surface: vkSurf,
|
||||||
w, h, stride = videoSrc.Width(), videoSrc.Height(), videoSrc.Stride()
|
Window: windowHandler,
|
||||||
}
|
GraphicsFamily: gfx,
|
||||||
r, err = renderer.New(renderer.Config{
|
VideoWidth: placeholderWidth,
|
||||||
PhysDevice: vkPhysDevice,
|
VideoHeight: placeholderHeight,
|
||||||
Device: vkDevice,
|
VideoStride: placeholderStride,
|
||||||
Queue: vkQueue,
|
})
|
||||||
Surface: vkSurf,
|
if err != nil {
|
||||||
Window: windowHandler,
|
panic(err)
|
||||||
GraphicsFamily: gfx,
|
|
||||||
VideoWidth: w,
|
|
||||||
VideoHeight: h,
|
|
||||||
VideoStride: stride,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer r.Destroy()
|
|
||||||
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())
|
|
||||||
}
|
|
||||||
defer vkDevice.WaitIdle()
|
|
||||||
}
|
}
|
||||||
|
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)
|
// GUI state (accessible from doReconnect + goroutine)
|
||||||
var (
|
var (
|
||||||
@@ -381,14 +393,6 @@ func main() {
|
|||||||
if params.video != "" && params.audio != "" {
|
if params.video != "" && params.audio != "" {
|
||||||
s, e := source.OpenSameDomainSync(params.domain, params.video, params.audio)
|
s, e := source.OpenSameDomainSync(params.domain, params.video, params.audio)
|
||||||
if e == nil {
|
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
|
syncSrc = s
|
||||||
aChans = s.Channels()
|
aChans = s.Channels()
|
||||||
audioBatch = uint64(s.AudioRate().Num) / uint64(s.Rate().Num)
|
audioBatch = uint64(s.AudioRate().Num) / uint64(s.Rate().Num)
|
||||||
@@ -401,14 +405,6 @@ func main() {
|
|||||||
} else if params.video != "" {
|
} else if params.video != "" {
|
||||||
s, e := source.Open(params.domain, params.video)
|
s, e := source.Open(params.domain, params.video)
|
||||||
if e == nil {
|
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
|
videoSrc = s
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -614,9 +610,10 @@ func main() {
|
|||||||
sdl.SetWindowFullscreen(windowHandler, true)
|
sdl.SetWindowFullscreen(windowHandler, true)
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
displayedVideoWidth uint32
|
displayedVideoWidth uint32 = placeholderWidth
|
||||||
displayedVideoHeight uint32
|
displayedVideoHeight uint32 = placeholderHeight
|
||||||
displayedVideoStride uint32
|
displayedVideoStride uint32 = placeholderStride
|
||||||
|
hasDisplayedVideo bool = false
|
||||||
|
|
||||||
fps float64
|
fps float64
|
||||||
lastIndex uint64
|
lastIndex uint64
|
||||||
@@ -699,6 +696,7 @@ func main() {
|
|||||||
displayedVideoWidth = pendingFrame.Frame.Width
|
displayedVideoWidth = pendingFrame.Frame.Width
|
||||||
displayedVideoHeight = pendingFrame.Frame.Height
|
displayedVideoHeight = pendingFrame.Frame.Height
|
||||||
displayedVideoStride = pendingFrame.Frame.Stride
|
displayedVideoStride = pendingFrame.Frame.Stride
|
||||||
|
hasDisplayedVideo = true
|
||||||
hasFrame = true
|
hasFrame = true
|
||||||
} else if frameErr != nil &&
|
} else if frameErr != nil &&
|
||||||
!errors.Is(frameErr, context.DeadlineExceeded) &&
|
!errors.Is(frameErr, context.DeadlineExceeded) &&
|
||||||
@@ -738,7 +736,7 @@ func main() {
|
|||||||
cimgui.Text(fmt.Sprintf("FPS: %.1f", fps))
|
cimgui.Text(fmt.Sprintf("FPS: %.1f", fps))
|
||||||
cimgui.Text(fmt.Sprintf("Dropped: %d", dropped))
|
cimgui.Text(fmt.Sprintf("Dropped: %d", dropped))
|
||||||
cimgui.Text(fmt.Sprintf("Index: %d", shownIndex))
|
cimgui.Text(fmt.Sprintf("Index: %d", shownIndex))
|
||||||
if displayedVideoWidth != 0 && displayedVideoHeight != 0 {
|
if hasDisplayedVideo {
|
||||||
cimgui.Text(fmt.Sprintf(
|
cimgui.Text(fmt.Sprintf(
|
||||||
"Video: %dx%d",
|
"Video: %dx%d",
|
||||||
displayedVideoWidth,
|
displayedVideoWidth,
|
||||||
|
|||||||
Reference in New Issue
Block a user