mirror of
https://github.com/harshabose/transcode.git
synced 2025-10-05 19:36:51 +08:00
44 lines
574 B
Go
44 lines
574 B
Go
package internal
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/asticode/go-astiav"
|
|
)
|
|
|
|
type framePool struct {
|
|
pool sync.Pool
|
|
}
|
|
|
|
func (pool *framePool) Get() *astiav.Frame {
|
|
frame, ok := pool.pool.Get().(*astiav.Frame)
|
|
|
|
if frame == nil || !ok {
|
|
return astiav.AllocFrame()
|
|
}
|
|
return frame
|
|
}
|
|
|
|
func (pool *framePool) Put(frame *astiav.Frame) {
|
|
if frame == nil {
|
|
return
|
|
}
|
|
|
|
frame.Unref()
|
|
pool.pool.Put(frame)
|
|
}
|
|
|
|
func (pool *framePool) Release() {
|
|
for {
|
|
frame, ok := pool.pool.Get().(*astiav.Frame)
|
|
if frame == nil {
|
|
break
|
|
}
|
|
if !ok {
|
|
continue
|
|
}
|
|
|
|
frame.Free()
|
|
}
|
|
}
|