Added NewChildCloser to node Closer interface

This commit is contained in:
Quentin Renard
2023-05-01 10:32:35 +02:00
parent 59f5ecbe9e
commit 65ae19ed5d
6 changed files with 12 additions and 7 deletions

View File

@@ -58,7 +58,7 @@ func NewDecoder(o DecoderOptions, eh *astiencoder.EventHandler, c *astikit.Close
d.BaseNode = astiencoder.NewBaseNode(o.Node, c, eh, s, d, astiencoder.EventTypeToNodeEventName)
// Create pools
d.fp = newFramePool(d)
d.fp = newFramePool(d.NewChildCloser())
d.pp = newPktPool(d)
// Create frame dispatcher

View File

@@ -50,7 +50,7 @@ func NewEncoder(o EncoderOptions, eh *astiencoder.EventHandler, c *astikit.Close
e.BaseNode = astiencoder.NewBaseNode(o.Node, c, eh, s, e, astiencoder.EventTypeToNodeEventName)
// Create pools
e.fp = newFramePool(e)
e.fp = newFramePool(e.NewChildCloser())
e.pp = newPktPool(e)
// Create pkt dispatcher

View File

@@ -50,7 +50,7 @@ func NewForwarder(o ForwarderOptions, eh *astiencoder.EventHandler, c *astikit.C
f.BaseNode = astiencoder.NewBaseNode(o.Node, c, eh, s, f, astiencoder.EventTypeToNodeEventName)
// Create frame pool
f.p = newFramePool(f)
f.p = newFramePool(f.NewChildCloser())
// Create frame dispatcher
f.d = newFrameDispatcher(f, eh)

View File

@@ -109,13 +109,13 @@ func (d *frameDispatcher) statOptions() []astikit.StatOptions {
}
type framePool struct {
c astiencoder.Closer
c *astikit.Closer
m *sync.Mutex
p []*astiav.Frame
statFramesAllocated uint64
}
func newFramePool(c astiencoder.Closer) *framePool {
func newFramePool(c *astikit.Closer) *framePool {
return &framePool{
c: c,
m: &sync.Mutex{},
@@ -128,7 +128,7 @@ func (p *framePool) get() (f *astiav.Frame) {
if len(p.p) == 0 {
f = astiav.AllocFrame()
atomic.AddUint64(&p.statFramesAllocated, 1)
p.c.AddClose(f.Free)
p.c.Add(f.Free)
return
}
f = p.p[0]

View File

@@ -51,7 +51,7 @@ func NewFrameRateEmulator(o FrameRateEmulatorOptions, eh *astiencoder.EventHandl
r.BaseNode = astiencoder.NewBaseNode(o.Node, c, eh, s, r, astiencoder.EventTypeToNodeEventName)
// Create frame pool
r.p = newFramePool(r)
r.p = newFramePool(r.NewChildCloser())
// Create frame dispatcher
r.d = newFrameDispatcher(r, eh)

View File

@@ -98,6 +98,7 @@ type Closer interface {
Close() error
DoWhenUnclosed(func())
IsClosed() bool
NewChildCloser() *astikit.Closer
}
// Starter represents an object that can start/pause/continue/stop
@@ -193,6 +194,10 @@ func (n *BaseNode) AddCloseWithError(fn astikit.CloseFuncWithError) {
n.c.AddWithError(fn)
}
func (n *BaseNode) NewChildCloser() *astikit.Closer {
return n.c.NewChild()
}
func (n *BaseNode) Close() error {
return n.c.Close()
}