Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions server/pkg/gst/gst.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ void gstreamer_pipeline_destory(GstPipelineCtx *ctx) {
// set null state
gst_element_set_state(GST_ELEMENT(ctx->pipeline), GST_STATE_NULL);

// the watch holds a reference to the bus, which would keep it and its
// control sockets after the pipeline is gone
GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(ctx->pipeline));
gst_bus_remove_watch(bus);
gst_object_unref(bus);

if (ctx->appsink) {
gst_object_unref(ctx->appsink);
ctx->appsink = NULL;
Expand Down
33 changes: 33 additions & 0 deletions server/pkg/gst/gst_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gst

import (
"os"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -95,6 +96,38 @@ func TestCreatePipelineReleasesLockBeforeSlowCUDAProbe(t *testing.T) {
}
}

func TestDestroyClosesPipelineFiles(t *testing.T) {
openFiles := func() int {
entries, err := os.ReadDir("/proc/self/fd")
if err != nil {
t.Fatalf("count open files: %v", err)
}
return len(entries)
}

runPipeline := func() {
p, err := CreatePipeline("fakesrc num-buffers=1 ! fakesink")
if err != nil {
t.Fatalf("CreatePipeline() error = %v", err)
}
p.Play()
p.Destroy()
}

// the first pipeline opens files that GStreamer keeps for the process
runPipeline()

const pipelines = 10
before := openFiles()
for i := 0; i < pipelines; i++ {
runPipeline()
}

if left := openFiles() - before; left > 0 {
t.Fatalf("%d pipelines left %d files open", pipelines, left)
}
}

func TestNVENCFailureDetail(t *testing.T) {
t.Parallel()

Expand Down
Loading