major rework of reference handling

This commit is contained in:
Avi Zimmerman
2021-01-19 00:18:30 +02:00
parent 63a53be42a
commit 1f7d60b390
79 changed files with 1239 additions and 800 deletions

View File

@@ -18,6 +18,16 @@ type Pipeline struct {
bus *Bus
}
// FromGstPipelineUnsafeFull wraps the given pipeline pointer.
func FromGstPipelineUnsafeFull(pipeline unsafe.Pointer) *Pipeline {
return &Pipeline{Bin: &Bin{&Element{wrapObject(glib.TransferFull(pipeline))}}}
}
// FromGstPipelineUnsafeNone wraps the given pipeline pointer.
func FromGstPipelineUnsafeNone(pipeline unsafe.Pointer) *Pipeline {
return &Pipeline{Bin: &Bin{&Element{wrapObject(glib.TransferNone(pipeline))}}}
}
// NewPipeline allocates and returns a new empty pipeline. If name is empty, one
// is generated by gstreamer.
func NewPipeline(name string) (*Pipeline, error) {
@@ -30,7 +40,7 @@ func NewPipeline(name string) (*Pipeline, error) {
if pipeline == nil {
return nil, errors.New("Could not create new pipeline")
}
return wrapPipeline(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(pipeline))}), nil
return FromGstPipelineUnsafeNone(unsafe.Pointer(pipeline)), nil
}
// NewPipelineFromString creates a new gstreamer pipeline from the given launch string.
@@ -47,7 +57,7 @@ func NewPipelineFromString(launchv string) (*Pipeline, error) {
errMsg := C.GoString(gerr.message)
return nil, errors.New(errMsg)
}
return wrapPipeline(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(pipeline))}), nil
return FromGstPipelineUnsafeNone(unsafe.Pointer(pipeline)), nil
}
// Instance returns the native GstPipeline instance.
@@ -57,7 +67,7 @@ func (p *Pipeline) Instance() *C.GstPipeline { return C.toGstPipeline(p.Unsafe()
func (p *Pipeline) GetPipelineBus() *Bus {
if p.bus == nil {
cBus := C.gst_pipeline_get_bus((*C.GstPipeline)(p.Instance()))
p.bus = wrapBus(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(cBus))})
p.bus = FromGstBusUnsafeFull(unsafe.Pointer(cBus))
}
return p.bus
}
@@ -65,7 +75,7 @@ func (p *Pipeline) GetPipelineBus() *Bus {
// GetPipelineClock returns the global clock for this pipeline.
func (p *Pipeline) GetPipelineClock() *Clock {
cClock := C.gst_pipeline_get_pipeline_clock((*C.GstPipeline)(p.Instance()))
return wrapClock(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(cClock))})
return FromGstClockUnsafeFull(unsafe.Pointer(cClock))
}
/*
@@ -92,35 +102,3 @@ func (p *Pipeline) SetAutoFlushBus(b bool) {
func (p *Pipeline) Start() error {
return p.SetState(StatePlaying)
}
// Destroy will attempt to stop the pipeline and then unref once the stream has
// fully completed.
func (p *Pipeline) Destroy() error {
if err := p.BlockSetState(StateNull); err != nil {
return err
}
p.Unref()
return nil
}
// Wait waits for the given pipeline to reach end of stream or be stopped.
func Wait(p *Pipeline) {
if p.Instance() == nil {
return
}
msgCh := p.GetPipelineBus().MessageChan()
for {
select {
default:
if p.Instance() == nil || p.GetState() == StateNull {
return
}
case msg := <-msgCh:
defer msg.Unref()
switch msg.Type() {
case MessageEOS:
return
}
}
}
}