mirror of
https://github.com/livekit/livekit.git
synced 2026-03-30 22:05:39 +00:00
* Remove `Head` field from `ExtPacket` structure. Although we do not intend to, but if packets get out-of-order in the forwarding path (maybe reading in multiple goroutines or using some worker pool to distribute packets), the `Head` indicator could lead to wrong behaviour. It is possible that at the receiver, the order is - Seq Num N, Head = true - N + 1, Head = true If the forwarding path sees `N + 1` first, the Head flag when it sees `N` packet is incorrect and will lead to incorrect behaviour. The alternative check is very simple. So, remove `Head` flag. * Remove unused field
82 lines
1.7 KiB
Go
82 lines
1.7 KiB
Go
package testutils
|
|
|
|
import (
|
|
"github.com/pion/rtp"
|
|
"github.com/pion/webrtc/v3"
|
|
|
|
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
|
)
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
type TestExtPacketParams struct {
|
|
SetMarker bool
|
|
IsKeyFrame bool
|
|
PayloadType uint8
|
|
SequenceNumber uint16
|
|
Timestamp uint32
|
|
SSRC uint32
|
|
PayloadSize int
|
|
PaddingSize byte
|
|
ArrivalTime int64
|
|
}
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
func GetTestExtPacket(params *TestExtPacketParams) (*buffer.ExtPacket, error) {
|
|
packet := rtp.Packet{
|
|
Header: rtp.Header{
|
|
Version: 2,
|
|
Padding: params.PaddingSize != 0,
|
|
Marker: params.SetMarker,
|
|
PayloadType: params.PayloadType,
|
|
SequenceNumber: params.SequenceNumber,
|
|
Timestamp: params.Timestamp,
|
|
SSRC: params.SSRC,
|
|
},
|
|
Payload: make([]byte, params.PayloadSize),
|
|
PaddingSize: params.PaddingSize,
|
|
}
|
|
|
|
raw, err := packet.Marshal()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ep := &buffer.ExtPacket{
|
|
Arrival: params.ArrivalTime,
|
|
Packet: &packet,
|
|
KeyFrame: params.IsKeyFrame,
|
|
RawPacket: raw,
|
|
}
|
|
|
|
return ep, nil
|
|
}
|
|
|
|
// --------------------------------------
|
|
|
|
func GetTestExtPacketVP8(params *TestExtPacketParams, vp8 *buffer.VP8) (*buffer.ExtPacket, error) {
|
|
ep, err := GetTestExtPacket(params)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ep.KeyFrame = vp8.IsKeyFrame
|
|
ep.Payload = *vp8
|
|
return ep, nil
|
|
}
|
|
|
|
// --------------------------------------
|
|
|
|
var TestVP8Codec = webrtc.RTPCodecCapability{
|
|
MimeType: "video/vp8",
|
|
ClockRate: 90000,
|
|
}
|
|
|
|
var TestOpusCodec = webrtc.RTPCodecCapability{
|
|
MimeType: "audio/opus",
|
|
ClockRate: 48000,
|
|
}
|
|
|
|
// --------------------------------------
|