make RTP packet size compatible with RTSP/SRTP (#4692)
Some checks failed
code_lint / golangci_lint (push) Has been cancelled
code_lint / mod_tidy (push) Has been cancelled
code_lint / api_docs (push) Has been cancelled
code_test / test_64 (push) Has been cancelled
code_test / test_32 (push) Has been cancelled
code_test / test_e2e (push) Has been cancelled

when RTSP encryption is enabled, maximum RTP packet size is slightly
decreased to make room for SRTP.
This commit is contained in:
Alessandro Ros 2025-07-05 15:42:58 +02:00 committed by GitHub
parent bf9cd328a9
commit 1083eea307
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 157 additions and 142 deletions

View file

@ -14,7 +14,7 @@ import (
)
type ac3 struct {
UDPMaxPayloadSize int
RTPMaxPayloadSize int
Format *format.AC3
GenerateRTPPackets bool
Parent logger.Writer
@ -81,9 +81,9 @@ func (t *ac3) ProcessRTPPacket( //nolint:dupl
pkt.Padding = false
pkt.PaddingSize = 0
if pkt.MarshalSize() > t.UDPMaxPayloadSize {
return nil, fmt.Errorf("payload size (%d) is greater than maximum allowed (%d)",
pkt.MarshalSize(), t.UDPMaxPayloadSize)
if len(pkt.Payload) > t.RTPMaxPayloadSize {
return nil, fmt.Errorf("RTP payload size (%d) is greater than maximum allowed (%d)",
len(pkt.Payload), t.RTPMaxPayloadSize)
}
// decode from RTP

View file

@ -21,7 +21,7 @@ var (
)
type av1 struct {
UDPMaxPayloadSize int
RTPMaxPayloadSize int
Format *format.AV1
GenerateRTPPackets bool
Parent logger.Writer
@ -49,7 +49,7 @@ func (t *av1) initialize() error {
func (t *av1) createEncoder() error {
t.encoder = &rtpav1.Encoder{
PayloadMaxSize: t.UDPMaxPayloadSize - 12,
PayloadMaxSize: t.RTPMaxPayloadSize,
PayloadType: t.Format.PayloadTyp,
}
return t.encoder.Init()
@ -89,9 +89,9 @@ func (t *av1) ProcessRTPPacket( //nolint:dupl
pkt.Padding = false
pkt.PaddingSize = 0
if pkt.MarshalSize() > t.UDPMaxPayloadSize {
return nil, fmt.Errorf("payload size (%d) is greater than maximum allowed (%d)",
pkt.MarshalSize(), t.UDPMaxPayloadSize)
if len(pkt.Payload) > t.RTPMaxPayloadSize {
return nil, fmt.Errorf("RTP payload size (%d) is greater than maximum allowed (%d)",
len(pkt.Payload), t.RTPMaxPayloadSize)
}
// decode from RTP

View file

@ -13,7 +13,7 @@ import (
)
type g711 struct {
UDPMaxPayloadSize int
RTPMaxPayloadSize int
Format *format.G711
GenerateRTPPackets bool
Parent logger.Writer
@ -41,7 +41,7 @@ func (t *g711) initialize() error {
func (t *g711) createEncoder() error {
t.encoder = &rtplpcm.Encoder{
PayloadMaxSize: t.UDPMaxPayloadSize - 12,
PayloadMaxSize: t.RTPMaxPayloadSize,
PayloadType: t.Format.PayloadType(),
BitDepth: 8,
ChannelCount: t.Format.ChannelCount,
@ -83,9 +83,9 @@ func (t *g711) ProcessRTPPacket( //nolint:dupl
pkt.Padding = false
pkt.PaddingSize = 0
if pkt.MarshalSize() > t.UDPMaxPayloadSize {
return nil, fmt.Errorf("payload size (%d) is greater than maximum allowed (%d)",
pkt.MarshalSize(), t.UDPMaxPayloadSize)
if len(pkt.Payload) > t.RTPMaxPayloadSize {
return nil, fmt.Errorf("RTP payload size (%d) is greater than maximum allowed (%d)",
len(pkt.Payload), t.RTPMaxPayloadSize)
}
// decode from RTP

View file

@ -18,7 +18,7 @@ func TestG711Encode(t *testing.T) {
ChannelCount: 1,
}
p, err := New(1472, forma, true, nil)
p, err := New(1450, forma, true, nil)
require.NoError(t, err)
unit := &unit.G711{
@ -47,7 +47,7 @@ func TestG711Encode(t *testing.T) {
ChannelCount: 1,
}
p, err := New(1472, forma, true, nil)
p, err := New(1450, forma, true, nil)
require.NoError(t, err)
unit := &unit.G711{

View file

@ -12,7 +12,7 @@ import (
)
type generic struct {
UDPMaxPayloadSize int
RTPMaxPayloadSize int
Format format.Format
GenerateRTPPackets bool
Parent logger.Writer
@ -48,9 +48,9 @@ func (t *generic) ProcessRTPPacket(
pkt.Padding = false
pkt.PaddingSize = 0
if pkt.MarshalSize() > t.UDPMaxPayloadSize {
return nil, fmt.Errorf("payload size (%d) is greater than maximum allowed (%d)",
pkt.MarshalSize(), t.UDPMaxPayloadSize)
if len(pkt.Payload) > t.RTPMaxPayloadSize {
return nil, fmt.Errorf("RTP payload size (%d) is greater than maximum allowed (%d)",
len(pkt.Payload), t.RTPMaxPayloadSize)
}
return u, nil

View file

@ -17,7 +17,7 @@ func TestGenericRemovePadding(t *testing.T) {
err := forma.Init()
require.NoError(t, err)
p, err := New(1472, forma, false, nil)
p, err := New(1450, forma, false, nil)
require.NoError(t, err)
pkt := &rtp.Packet{

View file

@ -83,7 +83,7 @@ func rtpH264ExtractParams(payload []byte) ([]byte, []byte) {
}
type h264 struct {
UDPMaxPayloadSize int
RTPMaxPayloadSize int
Format *format.H264
GenerateRTPPackets bool
Parent logger.Writer
@ -114,7 +114,7 @@ func (t *h264) createEncoder(
initialSequenceNumber *uint16,
) error {
t.encoder = &rtph264.Encoder{
PayloadMaxSize: t.UDPMaxPayloadSize - 12,
PayloadMaxSize: t.RTPMaxPayloadSize,
PayloadType: t.Format.PayloadTyp,
SSRC: ssrc,
InitialSequenceNumber: initialSequenceNumber,
@ -267,7 +267,7 @@ func (t *h264) ProcessRTPPacket( //nolint:dupl
pkt.PaddingSize = 0
// RTP packets exceed maximum size: start re-encoding them
if pkt.MarshalSize() > t.UDPMaxPayloadSize {
if len(pkt.Payload) > t.RTPMaxPayloadSize {
t.Parent.Log(logger.Info, "RTP packets are too big, remuxing them into smaller ones")
v1 := pkt.SSRC

View file

@ -36,7 +36,7 @@ func TestH264DynamicParams(t *testing.T) {
PacketizationMode: 1,
}
p, err := New(1472, forma, false, nil)
p, err := New(1450, forma, false, nil)
require.NoError(t, err)
enc, err := forma.CreateEncoder()
@ -103,7 +103,7 @@ func TestH264OversizedPackets(t *testing.T) {
logged := false
p, err := New(1472, forma, false,
p, err := New(1460, forma, false,
Logger(func(_ logger.Level, s string, i ...interface{}) {
require.Equal(t, "RTP packets are too big, remuxing them into smaller ones", fmt.Sprintf(s, i...))
logged = true
@ -207,7 +207,7 @@ func TestH264EmptyPacket(t *testing.T) {
PacketizationMode: 1,
}
p, err := New(1472, forma, true, nil)
p, err := New(1450, forma, true, nil)
require.NoError(t, err)
unit := &unit.H264{

View file

@ -103,7 +103,7 @@ func rtpH265ExtractParams(payload []byte) ([]byte, []byte, []byte) {
}
type h265 struct {
UDPMaxPayloadSize int
RTPMaxPayloadSize int
Format *format.H265
GenerateRTPPackets bool
Parent logger.Writer
@ -134,7 +134,7 @@ func (t *h265) createEncoder(
initialSequenceNumber *uint16,
) error {
t.encoder = &rtph265.Encoder{
PayloadMaxSize: t.UDPMaxPayloadSize - 12,
PayloadMaxSize: t.RTPMaxPayloadSize,
PayloadType: t.Format.PayloadTyp,
SSRC: ssrc,
InitialSequenceNumber: initialSequenceNumber,
@ -299,7 +299,7 @@ func (t *h265) ProcessRTPPacket( //nolint:dupl
pkt.PaddingSize = 0
// RTP packets exceed maximum size: start re-encoding them
if pkt.MarshalSize() > t.UDPMaxPayloadSize {
if len(pkt.Payload) > t.RTPMaxPayloadSize {
t.Parent.Log(logger.Info, "RTP packets are too big, remuxing them into smaller ones")
v1 := pkt.SSRC

View file

@ -22,7 +22,7 @@ func TestH265DynamicParams(t *testing.T) {
PayloadTyp: 96,
}
p, err := New(1472, forma, false, nil)
p, err := New(1450, forma, false, nil)
require.NoError(t, err)
enc, err := forma.CreateEncoder()
@ -98,7 +98,7 @@ func TestH265OversizedPackets(t *testing.T) {
logged := false
p, err := New(1472, forma, false,
p, err := New(1460, forma, false,
Logger(func(_ logger.Level, s string, i ...interface{}) {
require.Equal(t, "RTP packets are too big, remuxing them into smaller ones", fmt.Sprintf(s, i...))
logged = true
@ -189,7 +189,7 @@ func TestH265EmptyPacket(t *testing.T) {
PayloadTyp: 96,
}
p, err := New(1472, forma, true, nil)
p, err := New(1450, forma, true, nil)
require.NoError(t, err)
unit := &unit.H265{

View file

@ -13,7 +13,7 @@ import (
)
type lpcm struct {
UDPMaxPayloadSize int
RTPMaxPayloadSize int
Format *format.LPCM
GenerateRTPPackets bool
Parent logger.Writer
@ -41,7 +41,7 @@ func (t *lpcm) initialize() error {
func (t *lpcm) createEncoder() error {
t.encoder = &rtplpcm.Encoder{
PayloadMaxSize: t.UDPMaxPayloadSize - 12,
PayloadMaxSize: t.RTPMaxPayloadSize,
PayloadType: t.Format.PayloadTyp,
BitDepth: t.Format.BitDepth,
ChannelCount: t.Format.ChannelCount,
@ -83,9 +83,9 @@ func (t *lpcm) ProcessRTPPacket( //nolint:dupl
pkt.Padding = false
pkt.PaddingSize = 0
if pkt.MarshalSize() > t.UDPMaxPayloadSize {
return nil, fmt.Errorf("payload size (%d) is greater than maximum allowed (%d)",
pkt.MarshalSize(), t.UDPMaxPayloadSize)
if len(pkt.Payload) > t.RTPMaxPayloadSize {
return nil, fmt.Errorf("RTP payload size (%d) is greater than maximum allowed (%d)",
len(pkt.Payload), t.RTPMaxPayloadSize)
}
// decode from RTP

View file

@ -17,7 +17,7 @@ func TestLPCMEncode(t *testing.T) {
ChannelCount: 2,
}
p, err := New(1472, forma, true, nil)
p, err := New(1450, forma, true, nil)
require.NoError(t, err)
unit := &unit.LPCM{

View file

@ -14,7 +14,7 @@ import (
)
type mjpeg struct {
UDPMaxPayloadSize int
RTPMaxPayloadSize int
Format *format.MJPEG
GenerateRTPPackets bool
Parent logger.Writer
@ -42,7 +42,7 @@ func (t *mjpeg) initialize() error {
func (t *mjpeg) createEncoder() error {
t.encoder = &rtpmjpeg.Encoder{
PayloadMaxSize: t.UDPMaxPayloadSize - 12,
PayloadMaxSize: t.RTPMaxPayloadSize,
}
return t.encoder.Init()
}
@ -82,9 +82,9 @@ func (t *mjpeg) ProcessRTPPacket( //nolint:dupl
pkt.Padding = false
pkt.PaddingSize = 0
if pkt.MarshalSize() > t.UDPMaxPayloadSize {
return nil, fmt.Errorf("payload size (%d) is greater than maximum allowed (%d)",
pkt.MarshalSize(), t.UDPMaxPayloadSize)
if len(pkt.Payload) > t.RTPMaxPayloadSize {
return nil, fmt.Errorf("RTP payload size (%d) is greater than maximum allowed (%d)",
len(pkt.Payload), t.RTPMaxPayloadSize)
}
// decode from RTP

View file

@ -14,7 +14,7 @@ import (
)
type mpeg1Audio struct {
UDPMaxPayloadSize int
RTPMaxPayloadSize int
Format *format.MPEG1Audio
GenerateRTPPackets bool
Parent logger.Writer
@ -42,7 +42,7 @@ func (t *mpeg1Audio) initialize() error {
func (t *mpeg1Audio) createEncoder() error {
t.encoder = &rtpmpeg1audio.Encoder{
PayloadMaxSize: t.UDPMaxPayloadSize - 12,
PayloadMaxSize: t.RTPMaxPayloadSize,
}
return t.encoder.Init()
}
@ -81,9 +81,9 @@ func (t *mpeg1Audio) ProcessRTPPacket( //nolint:dupl
pkt.Padding = false
pkt.PaddingSize = 0
if pkt.MarshalSize() > t.UDPMaxPayloadSize {
return nil, fmt.Errorf("payload size (%d) is greater than maximum allowed (%d)",
pkt.MarshalSize(), t.UDPMaxPayloadSize)
if len(pkt.Payload) > t.RTPMaxPayloadSize {
return nil, fmt.Errorf("RTP payload size (%d) is greater than maximum allowed (%d)",
len(pkt.Payload), t.RTPMaxPayloadSize)
}
// decode from RTP

View file

@ -23,7 +23,7 @@ var (
)
type mpeg1Video struct {
UDPMaxPayloadSize int
RTPMaxPayloadSize int
Format *format.MPEG1Video
GenerateRTPPackets bool
Parent logger.Writer
@ -51,7 +51,7 @@ func (t *mpeg1Video) initialize() error {
func (t *mpeg1Video) createEncoder() error {
t.encoder = &rtpmpeg1video.Encoder{
PayloadMaxSize: t.UDPMaxPayloadSize - 12,
PayloadMaxSize: t.RTPMaxPayloadSize,
}
return t.encoder.Init()
}
@ -91,9 +91,9 @@ func (t *mpeg1Video) ProcessRTPPacket( //nolint:dupl
pkt.Padding = false
pkt.PaddingSize = 0
if pkt.MarshalSize() > t.UDPMaxPayloadSize {
return nil, fmt.Errorf("payload size (%d) is greater than maximum allowed (%d)",
pkt.MarshalSize(), t.UDPMaxPayloadSize)
if len(pkt.Payload) > t.RTPMaxPayloadSize {
return nil, fmt.Errorf("RTP payload size (%d) is greater than maximum allowed (%d)",
len(pkt.Payload), t.RTPMaxPayloadSize)
}
// decode from RTP

View file

@ -14,7 +14,7 @@ import (
)
type mpeg4Audio struct {
UDPMaxPayloadSize int
RTPMaxPayloadSize int
Format *format.MPEG4Audio
GenerateRTPPackets bool
Parent logger.Writer
@ -42,7 +42,7 @@ func (t *mpeg4Audio) initialize() error {
func (t *mpeg4Audio) createEncoder() error {
t.encoder = &rtpmpeg4audio.Encoder{
PayloadMaxSize: t.UDPMaxPayloadSize - 12,
PayloadMaxSize: t.RTPMaxPayloadSize,
PayloadType: t.Format.PayloadTyp,
SizeLength: t.Format.SizeLength,
IndexLength: t.Format.IndexLength,
@ -85,9 +85,9 @@ func (t *mpeg4Audio) ProcessRTPPacket( //nolint:dupl
pkt.Padding = false
pkt.PaddingSize = 0
if pkt.MarshalSize() > t.UDPMaxPayloadSize {
return nil, fmt.Errorf("payload size (%d) is greater than maximum allowed (%d)",
pkt.MarshalSize(), t.UDPMaxPayloadSize)
if len(pkt.Payload) > t.RTPMaxPayloadSize {
return nil, fmt.Errorf("RTP payload size (%d) is greater than maximum allowed (%d)",
len(pkt.Payload), t.RTPMaxPayloadSize)
}
// decode from RTP

View file

@ -28,7 +28,7 @@ var (
)
type mpeg4Video struct {
UDPMaxPayloadSize int
RTPMaxPayloadSize int
Format *format.MPEG4Video
GenerateRTPPackets bool
Parent logger.Writer
@ -56,7 +56,7 @@ func (t *mpeg4Video) initialize() error {
func (t *mpeg4Video) createEncoder() error {
t.encoder = &rtpmpeg4video.Encoder{
PayloadMaxSize: t.UDPMaxPayloadSize - 12,
PayloadMaxSize: t.RTPMaxPayloadSize,
PayloadType: t.Format.PayloadTyp,
}
return t.encoder.Init()
@ -136,9 +136,9 @@ func (t *mpeg4Video) ProcessRTPPacket( //nolint:dupl
pkt.Padding = false
pkt.PaddingSize = 0
if pkt.MarshalSize() > t.UDPMaxPayloadSize {
return nil, fmt.Errorf("payload size (%d) is greater than maximum allowed (%d)",
pkt.MarshalSize(), t.UDPMaxPayloadSize)
if len(pkt.Payload) > t.RTPMaxPayloadSize {
return nil, fmt.Errorf("RTP payload size (%d) is greater than maximum allowed (%d)",
len(pkt.Payload), t.RTPMaxPayloadSize)
}
// decode from RTP

View file

@ -14,7 +14,7 @@ import (
)
type opus struct {
UDPMaxPayloadSize int
RTPMaxPayloadSize int
Format *format.Opus
GenerateRTPPackets bool
Parent logger.Writer
@ -42,7 +42,7 @@ func (t *opus) initialize() error {
func (t *opus) createEncoder() error {
t.encoder = &rtpsimpleaudio.Encoder{
PayloadMaxSize: t.UDPMaxPayloadSize - 12,
PayloadMaxSize: t.RTPMaxPayloadSize,
PayloadType: t.Format.PayloadTyp,
}
return t.encoder.Init()
@ -89,9 +89,9 @@ func (t *opus) ProcessRTPPacket(
pkt.Padding = false
pkt.PaddingSize = 0
if pkt.MarshalSize() > t.UDPMaxPayloadSize {
return nil, fmt.Errorf("payload size (%d) is greater than maximum allowed (%d)",
pkt.MarshalSize(), t.UDPMaxPayloadSize)
if len(pkt.Payload) > t.RTPMaxPayloadSize {
return nil, fmt.Errorf("RTP payload size (%d) is greater than maximum allowed (%d)",
len(pkt.Payload), t.RTPMaxPayloadSize)
}
// decode from RTP

View file

@ -15,7 +15,7 @@ func TestOpusEncode(t *testing.T) {
ChannelCount: 2,
}
p, err := New(1472, forma, true, nil)
p, err := New(1450, forma, true, nil)
require.NoError(t, err)
unit := &unit.Opus{

View file

@ -39,7 +39,7 @@ type Processor interface {
// New allocates a Processor.
func New(
udpMaxPayloadSize int,
rtpMaxPayloadSize int,
forma format.Format,
generateRTPPackets bool,
parent logger.Writer,
@ -49,7 +49,7 @@ func New(
switch forma := forma.(type) {
case *format.AV1:
proc = &av1{
UDPMaxPayloadSize: udpMaxPayloadSize,
RTPMaxPayloadSize: rtpMaxPayloadSize,
Format: forma,
GenerateRTPPackets: generateRTPPackets,
Parent: parent,
@ -57,7 +57,7 @@ func New(
case *format.VP9:
proc = &vp9{
UDPMaxPayloadSize: udpMaxPayloadSize,
RTPMaxPayloadSize: rtpMaxPayloadSize,
Format: forma,
GenerateRTPPackets: generateRTPPackets,
Parent: parent,
@ -65,7 +65,7 @@ func New(
case *format.VP8:
proc = &vp8{
UDPMaxPayloadSize: udpMaxPayloadSize,
RTPMaxPayloadSize: rtpMaxPayloadSize,
Format: forma,
GenerateRTPPackets: generateRTPPackets,
Parent: parent,
@ -73,7 +73,7 @@ func New(
case *format.H265:
proc = &h265{
UDPMaxPayloadSize: udpMaxPayloadSize,
RTPMaxPayloadSize: rtpMaxPayloadSize,
Format: forma,
GenerateRTPPackets: generateRTPPackets,
Parent: parent,
@ -81,7 +81,7 @@ func New(
case *format.H264:
proc = &h264{
UDPMaxPayloadSize: udpMaxPayloadSize,
RTPMaxPayloadSize: rtpMaxPayloadSize,
Format: forma,
GenerateRTPPackets: generateRTPPackets,
Parent: parent,
@ -89,7 +89,7 @@ func New(
case *format.MPEG4Video:
proc = &mpeg4Video{
UDPMaxPayloadSize: udpMaxPayloadSize,
RTPMaxPayloadSize: rtpMaxPayloadSize,
Format: forma,
GenerateRTPPackets: generateRTPPackets,
Parent: parent,
@ -97,7 +97,7 @@ func New(
case *format.MPEG1Video:
proc = &mpeg1Video{
UDPMaxPayloadSize: udpMaxPayloadSize,
RTPMaxPayloadSize: rtpMaxPayloadSize,
Format: forma,
GenerateRTPPackets: generateRTPPackets,
Parent: parent,
@ -105,7 +105,7 @@ func New(
case *format.MJPEG:
proc = &mjpeg{
UDPMaxPayloadSize: udpMaxPayloadSize,
RTPMaxPayloadSize: rtpMaxPayloadSize,
Format: forma,
GenerateRTPPackets: generateRTPPackets,
Parent: parent,
@ -113,7 +113,7 @@ func New(
case *format.Opus:
proc = &opus{
UDPMaxPayloadSize: udpMaxPayloadSize,
RTPMaxPayloadSize: rtpMaxPayloadSize,
Format: forma,
GenerateRTPPackets: generateRTPPackets,
Parent: parent,
@ -121,7 +121,7 @@ func New(
case *format.MPEG4Audio:
proc = &mpeg4Audio{
UDPMaxPayloadSize: udpMaxPayloadSize,
RTPMaxPayloadSize: rtpMaxPayloadSize,
Format: forma,
GenerateRTPPackets: generateRTPPackets,
Parent: parent,
@ -129,7 +129,7 @@ func New(
case *format.MPEG1Audio:
proc = &mpeg1Audio{
UDPMaxPayloadSize: udpMaxPayloadSize,
RTPMaxPayloadSize: rtpMaxPayloadSize,
Format: forma,
GenerateRTPPackets: generateRTPPackets,
Parent: parent,
@ -137,7 +137,7 @@ func New(
case *format.AC3:
proc = &ac3{
UDPMaxPayloadSize: udpMaxPayloadSize,
RTPMaxPayloadSize: rtpMaxPayloadSize,
Format: forma,
GenerateRTPPackets: generateRTPPackets,
Parent: parent,
@ -145,7 +145,7 @@ func New(
case *format.G711:
proc = &g711{
UDPMaxPayloadSize: udpMaxPayloadSize,
RTPMaxPayloadSize: rtpMaxPayloadSize,
Format: forma,
GenerateRTPPackets: generateRTPPackets,
Parent: parent,
@ -153,7 +153,7 @@ func New(
case *format.LPCM:
proc = &lpcm{
UDPMaxPayloadSize: udpMaxPayloadSize,
RTPMaxPayloadSize: rtpMaxPayloadSize,
Format: forma,
GenerateRTPPackets: generateRTPPackets,
Parent: parent,
@ -161,7 +161,7 @@ func New(
default:
proc = &generic{
UDPMaxPayloadSize: udpMaxPayloadSize,
RTPMaxPayloadSize: rtpMaxPayloadSize,
Format: forma,
GenerateRTPPackets: generateRTPPackets,
Parent: parent,

View file

@ -90,7 +90,7 @@ func TestNew(t *testing.T) {
},
} {
t.Run(ca.name, func(t *testing.T) {
p, err := New(1472, ca.in, false, nil)
p, err := New(1450, ca.in, false, nil)
require.NoError(t, err)
require.IsType(t, ca.out, p)
})

View file

@ -14,7 +14,7 @@ import (
)
type vp8 struct {
UDPMaxPayloadSize int
RTPMaxPayloadSize int
Format *format.VP8
GenerateRTPPackets bool
Parent logger.Writer
@ -42,7 +42,7 @@ func (t *vp8) initialize() error {
func (t *vp8) createEncoder() error {
t.encoder = &rtpvp8.Encoder{
PayloadMaxSize: t.UDPMaxPayloadSize - 12,
PayloadMaxSize: t.RTPMaxPayloadSize,
PayloadType: t.Format.PayloadTyp,
}
return t.encoder.Init()
@ -82,9 +82,9 @@ func (t *vp8) ProcessRTPPacket( //nolint:dupl
pkt.Padding = false
pkt.PaddingSize = 0
if pkt.MarshalSize() > t.UDPMaxPayloadSize {
return nil, fmt.Errorf("payload size (%d) is greater than maximum allowed (%d)",
pkt.MarshalSize(), t.UDPMaxPayloadSize)
if len(pkt.Payload) > t.RTPMaxPayloadSize {
return nil, fmt.Errorf("RTP payload size (%d) is greater than maximum allowed (%d)",
len(pkt.Payload), t.RTPMaxPayloadSize)
}
// decode from RTP

View file

@ -14,7 +14,7 @@ import (
)
type vp9 struct {
UDPMaxPayloadSize int
RTPMaxPayloadSize int
Format *format.VP9
GenerateRTPPackets bool
Parent logger.Writer
@ -42,7 +42,7 @@ func (t *vp9) initialize() error {
func (t *vp9) createEncoder() error {
t.encoder = &rtpvp9.Encoder{
PayloadMaxSize: t.UDPMaxPayloadSize - 12,
PayloadMaxSize: t.RTPMaxPayloadSize,
PayloadType: t.Format.PayloadTyp,
}
return t.encoder.Init()
@ -82,9 +82,9 @@ func (t *vp9) ProcessRTPPacket( //nolint:dupl
pkt.Padding = false
pkt.PaddingSize = 0
if pkt.MarshalSize() > t.UDPMaxPayloadSize {
return nil, fmt.Errorf("payload size (%d) is greater than maximum allowed (%d)",
pkt.MarshalSize(), t.UDPMaxPayloadSize)
if len(pkt.Payload) > t.RTPMaxPayloadSize {
return nil, fmt.Errorf("RTP payload size (%d) is greater than maximum allowed (%d)",
len(pkt.Payload), t.RTPMaxPayloadSize)
}
// decode from RTP