gst destroy remove.

This commit is contained in:
Miroslav Šedivý 2021-12-05 21:31:40 +01:00
parent b932e94f77
commit f9fe303b50
2 changed files with 12 additions and 5 deletions

View File

@ -131,7 +131,6 @@ void gstreamer_pipeline_pause(GstPipelineCtx *ctx) {
void gstreamer_pipeline_destory(GstPipelineCtx *ctx) { void gstreamer_pipeline_destory(GstPipelineCtx *ctx) {
gst_element_set_state(GST_ELEMENT(ctx->pipeline), GST_STATE_NULL); gst_element_set_state(GST_ELEMENT(ctx->pipeline), GST_STATE_NULL);
gst_object_unref(ctx->pipeline); gst_object_unref(ctx->pipeline);
free(ctx);
} }
void gstreamer_pipeline_push(GstPipelineCtx *ctx, char *srcName, void *buffer, int bufferLen) { void gstreamer_pipeline_push(GstPipelineCtx *ctx, char *srcName, void *buffer, int bufferLen) {

View File

@ -9,6 +9,7 @@ import "C"
import ( import (
"fmt" "fmt"
"sync" "sync"
"sync/atomic"
"time" "time"
"unsafe" "unsafe"
@ -25,6 +26,7 @@ type Pipeline struct {
Sample chan types.Sample Sample chan types.Sample
} }
var pSerial int32
var pipelines = make(map[int]*Pipeline) var pipelines = make(map[int]*Pipeline)
var pipelinesLock sync.Mutex var pipelinesLock sync.Mutex
var registry *C.GstRegistry var registry *C.GstRegistry
@ -37,14 +39,14 @@ func init() {
} }
func CreatePipeline(pipelineStr string) (*Pipeline, error) { func CreatePipeline(pipelineStr string) (*Pipeline, error) {
id := atomic.AddInt32(&pSerial, 1)
pipelineStrUnsafe := C.CString(pipelineStr) pipelineStrUnsafe := C.CString(pipelineStr)
defer C.free(unsafe.Pointer(pipelineStrUnsafe)) defer C.free(unsafe.Pointer(pipelineStrUnsafe))
pipelinesLock.Lock() pipelinesLock.Lock()
defer pipelinesLock.Unlock() defer pipelinesLock.Unlock()
id := len(pipelines)
var gstError *C.GError var gstError *C.GError
ctx := C.gstreamer_pipeline_create(pipelineStrUnsafe, C.int(id), &gstError) ctx := C.gstreamer_pipeline_create(pipelineStrUnsafe, C.int(id), &gstError)
@ -54,7 +56,7 @@ func CreatePipeline(pipelineStr string) (*Pipeline, error) {
} }
p := &Pipeline{ p := &Pipeline{
id: id, id: int(id),
Src: pipelineStr, Src: pipelineStr,
Ctx: ctx, Ctx: ctx,
Sample: make(chan types.Sample), Sample: make(chan types.Sample),
@ -81,8 +83,14 @@ func (p *Pipeline) Pause() {
func (p *Pipeline) Destroy() { func (p *Pipeline) Destroy() {
C.gstreamer_pipeline_destory(p.Ctx) C.gstreamer_pipeline_destory(p.Ctx)
p.Ctx = nil
pipelinesLock.Lock()
delete(pipelines, p.id)
pipelinesLock.Unlock()
close(p.Sample) close(p.Sample)
C.free(unsafe.Pointer(p.Ctx))
p = nil
} }
func (p *Pipeline) Push(srcName string, buffer []byte) { func (p *Pipeline) Push(srcName string, buffer []byte) {