mirror of
https://github.com/asticode/go-astiencoder.git
synced 2025-09-27 03:28:10 +08:00
Added NewChildCloser to node Closer interface
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
@@ -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]
|
||||
|
@@ -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)
|
||||
|
5
node.go
5
node.go
@@ -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()
|
||||
}
|
||||
|
Reference in New Issue
Block a user