first-commit

This commit is contained in:
harshabose
2025-02-18 16:44:58 +05:30
parent f91d9277bb
commit be46bbacb8
5 changed files with 166 additions and 2 deletions

View File

@@ -1 +1,43 @@
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()
}
}

View File

@@ -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()
}
}

View File

@@ -1 +1,41 @@
package internal
import (
"sync"
"github.com/pion/rtp"
)
type rtpPool struct {
pool sync.Pool
}
func (pool *rtpPool) Get() *rtp.Packet {
packet, ok := pool.pool.Get().(*rtp.Packet)
if packet == nil || !ok {
return &rtp.Packet{}
}
return packet
}
func (pool *rtpPool) Put(packet *rtp.Packet) {
if packet == nil {
return
}
pool.pool.Put(packet)
}
func (pool *rtpPool) Release() {
for {
packet, ok := pool.pool.Get().(*rtp.Packet)
if !ok {
continue
}
if packet == nil {
break
}
packet = nil
}
}

View File

@@ -1 +1,41 @@
package internal
import (
"sync"
"github.com/pion/webrtc/v4/pkg/media"
)
type samplePool struct {
pool sync.Pool
}
func (pool *samplePool) Get() *media.Sample {
packet, ok := pool.pool.Get().(*media.Sample)
if packet == nil || !ok {
return &media.Sample{}
}
return packet
}
func (pool *samplePool) Put(sample *media.Sample) {
if sample == nil {
return
}
pool.pool.Put(sample)
}
func (pool *samplePool) Release() {
for {
sample, ok := pool.pool.Get().(*media.Sample)
if !ok {
continue
}
if sample == nil {
break
}
sample = nil
}
}

View File

@@ -109,8 +109,8 @@ func (decoder *Decoder) PutBack(frame *astiav.Frame) {
decoder.buffer.PutBack(frame)
}
func (decoder *Decoder) GetSrcFilterContextOptions() func(filter types.BaseFilter) error {
return filt.VideoSetFilterContextParameters(decoder.decoderContext)
func (decoder *Decoder) GetSrcFilterContextOptions() func(filter *Filter) error {
return VideoSetFilterContextParameters(decoder.decoderContext)
}
func (decoder *Decoder) close() {