mirror of
https://github.com/harshabose/transcode.git
synced 2025-10-05 23:36:51 +08:00
first-commit
This commit is contained in:
@@ -1 +1,43 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/asticode/go-astiav"
|
||||
)
|
||||
|
||||
type packetPool struct {
|
||||
pool sync.Pool
|
||||
}
|
||||
|
||||
func (pool *packetPool) Get() *astiav.Packet {
|
||||
packet, ok := pool.pool.Get().(*astiav.Packet)
|
||||
|
||||
if packet == nil || !ok {
|
||||
return astiav.AllocPacket()
|
||||
}
|
||||
return packet
|
||||
}
|
||||
|
||||
func (pool *packetPool) Put(packet *astiav.Packet) {
|
||||
if packet == nil {
|
||||
return
|
||||
}
|
||||
|
||||
packet.Unref()
|
||||
pool.pool.Put(packet)
|
||||
}
|
||||
|
||||
func (pool *packetPool) Release() {
|
||||
for {
|
||||
packet, ok := pool.pool.Get().(*astiav.Packet)
|
||||
if packet == nil {
|
||||
break
|
||||
}
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
packet.Free()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user