Skip to content

Commit

Permalink
Add glib main loop to capture manager (#383)
Browse files Browse the repository at this point in the history
The gstreamer documentation is not particularly amazing on whether or
not this is necessary, but it's clear that some gstreamer events will
not be delivered to their handlers without a running glib loop. This
runs one loop for all pipelines, which should be more than enough.

Disclaimer: This may conflict in demodesk/neko with the dragdrop
feature. Anyone backporting this bug fix to that repo should
investigate whether the loop created by `gtk_main()` will conflict with
this one before blindly porting.

Fixes #380
Fixes #284
  • Loading branch information
tt2468 authored Mar 27, 2024
1 parent 2b13220 commit b1ce755
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions server/internal/capture/gst/gst.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,29 @@ var pSerial int32
var pipelines = make(map[int]*Pipeline)
var pipelinesLock sync.Mutex
var registry *C.GstRegistry
var gMainLoop *C.GMainLoop

func init() {
C.gst_init(nil, nil)
registry = C.gst_registry_get()
}

func RunMainLoop() {
if gMainLoop != nil {
return
}
gMainLoop = C.g_main_loop_new(nil, C.int(0))
C.g_main_loop_run(gMainLoop)
}

func QuitMainLoop() {
if gMainLoop == nil {
return
}
C.g_main_loop_quit(gMainLoop)
gMainLoop = nil
}

func CreatePipeline(pipelineStr string) (*Pipeline, error) {
id := atomic.AddInt32(&pSerial, 1)

Expand Down
4 changes: 4 additions & 0 deletions server/internal/capture/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"m1k1o/neko/internal/capture/gst"
"m1k1o/neko/internal/config"
"m1k1o/neko/internal/types"
)
Expand Down Expand Up @@ -53,6 +54,7 @@ func (manager *CaptureManagerCtx) Start() {
}
}

go gst.RunMainLoop()
go func() {
for {
before, ok := <-manager.desktop.GetScreenSizeChangeChannel()
Expand Down Expand Up @@ -100,6 +102,8 @@ func (manager *CaptureManagerCtx) Shutdown() error {
manager.audio.shutdown()
manager.video.shutdown()

gst.QuitMainLoop()

return nil
}

Expand Down

0 comments on commit b1ce755

Please sign in to comment.