func codecParametersFuzzySearch(needle webrtc.RTPCodecParameters, haystack []webrtc.RTPCodecParameters) (webrtc.RTPCodecParameters, error) {
	for _, c := range haystack {
		if strings.EqualFold(c.RTPCodecCapability.MimeType, needle.RTPCodecCapability.MimeType) &&
			c.RTPCodecCapability.SDPFmtpLine == needle.RTPCodecCapability.SDPFmtpLine {
			return c, nil
		}
	}
	for _, c := range haystack {
		if strings.EqualFold(c.RTPCodecCapability.MimeType, needle.RTPCodecCapability.MimeType) {
			return c, nil
		}
	}
	return webrtc.RTPCodecParameters{}, webrtc.ErrCodecNotFound
}
Do a fuzzy find for a codec in the list of codecs
Used for lookup up a codec in an existing list to find a match
package sfu
import (
	"encoding/binary"
	"strings"
	"sync/atomic"
	"time"
	"github.com/pion/ion-sfu/pkg/buffer"
	"github.com/pion/webrtc/v3"
)
var (
	ntpEpoch = time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC)
)
type atomicBool int32
type ntpTime uint64
func (a *atomicBool) set(value bool) (swapped bool) {
	if value {
		return atomic.SwapInt32((*int32)(a), 1) == 0
	}
	return atomic.SwapInt32((*int32)(a), 0) == 1
}
func (a *atomicBool) get() bool {
	return atomic.LoadInt32((*int32)(a)) != 0
}
func setVP8TemporalLayer(p *buffer.ExtPacket, d *DownTrack) (buf []byte, picID uint16, tlz0Idx uint8, drop bool) {
	pkt, ok := p.Payload.(buffer.VP8)
	if !ok {
		return
	}
	layer := atomic.LoadInt32(&d.temporalLayer)
	currentLayer := uint16(layer)
	currentTargetLayer := uint16(layer >> 16)
	if currentTargetLayer != currentLayer {
		if pkt.TID <= uint8(currentTargetLayer) {
			atomic.StoreInt32(&d.temporalLayer, int32(currentTargetLayer)<<16|int32(currentTargetLayer))
		}
	} else if pkt.TID > uint8(currentLayer) {
		drop = true
		return
	}
	buf = *d.payload
	buf = buf[:len(p.Packet.Payload)]
	copy(buf, p.Packet.Payload)
	picID = pkt.PictureID - d.simulcast.refPicID + d.simulcast.pRefPicID + 1
	tlz0Idx = pkt.TL0PICIDX - d.simulcast.refTlZIdx + d.simulcast.pRefTlZIdx + 1
	if p.Head {
		d.simulcast.lPicID = picID
		d.simulcast.lTlZIdx = tlz0Idx
	}
	modifyVP8TemporalPayload(buf, pkt.PicIDIdx, pkt.TlzIdx, picID, tlz0Idx, pkt.MBit)
	return
}
func modifyVP8TemporalPayload(payload []byte, picIDIdx, tlz0Idx int, picID uint16, tlz0ID uint8, mBit bool) {
	pid := make([]byte, 2)
	binary.BigEndian.PutUint16(pid, picID)
	payload[picIDIdx] = pid[0]
	if mBit {
		payload[picIDIdx] |= 0x80
		payload[picIDIdx+1] = pid[1]
	}
	payload[tlz0Idx] = tlz0ID
}