fix encoding of RTP packets with padding

this fixes a SIGSEGV with GStreamer
This commit is contained in:
aler9
2022-03-08 12:47:53 +01:00
parent 94aaa6719d
commit e12b22ae77
38 changed files with 52 additions and 36 deletions

View File

@@ -22,7 +22,7 @@ import (
"time" "time"
"github.com/pion/rtcp" "github.com/pion/rtcp"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
"github.com/aler9/gortsplib/pkg/auth" "github.com/aler9/gortsplib/pkg/auth"
"github.com/aler9/gortsplib/pkg/base" "github.com/aler9/gortsplib/pkg/base"
@@ -765,6 +765,10 @@ func (c *Client) runReader() {
return return
} }
// remove padding
pkt.Header.Padding = false
pkt.PaddingSize = 0
c.tracks[trackID].rtcpReceiver.ProcessPacketRTP(now, pkt) c.tracks[trackID].rtcpReceiver.ProcessPacketRTP(now, pkt)
c.OnPacketRTP(trackID, pkt) c.OnPacketRTP(trackID, pkt)
} else { } else {

View File

@@ -10,7 +10,7 @@ import (
"time" "time"
"github.com/pion/rtcp" "github.com/pion/rtcp"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/aler9/gortsplib/pkg/base" "github.com/aler9/gortsplib/pkg/base"

View File

@@ -12,7 +12,7 @@ import (
"time" "time"
"github.com/pion/rtcp" "github.com/pion/rtcp"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"golang.org/x/net/ipv4" "golang.org/x/net/ipv4"

View File

@@ -183,6 +183,10 @@ func (u *clientUDPListener) processPlayRTP(now time.Time, payload []byte) {
return return
} }
// remove padding
pkt.Header.Padding = false
pkt.PaddingSize = 0
u.c.tracks[u.trackID].rtcpReceiver.ProcessPacketRTP(now, pkt) u.c.tracks[u.trackID].rtcpReceiver.ProcessPacketRTP(now, pkt)
u.c.OnPacketRTP(u.trackID, pkt) u.c.OnPacketRTP(u.trackID, pkt)
} }

View File

@@ -5,7 +5,7 @@ import (
"net" "net"
"github.com/aler9/gortsplib" "github.com/aler9/gortsplib"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
// This example shows how to // This example shows how to

View File

@@ -6,7 +6,7 @@ import (
"github.com/aler9/gortsplib" "github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/rtph264" "github.com/aler9/gortsplib/pkg/rtph264"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
// This example shows how to // This example shows how to

View File

@@ -7,7 +7,7 @@ import (
"github.com/aler9/gortsplib" "github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/rtph264" "github.com/aler9/gortsplib/pkg/rtph264"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
// This example shows how to // This example shows how to

View File

@@ -5,7 +5,7 @@ import (
"net" "net"
"github.com/aler9/gortsplib" "github.com/aler9/gortsplib"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
// This example shows how to // This example shows how to

View File

@@ -7,7 +7,7 @@ import (
"github.com/aler9/gortsplib" "github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/rtph264" "github.com/aler9/gortsplib/pkg/rtph264"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
// This example shows how to // This example shows how to

View File

@@ -6,7 +6,7 @@ import (
"github.com/aler9/gortsplib" "github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/base" "github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/gortsplib/pkg/rtpaac" "github.com/aler9/gortsplib/pkg/rtpaac"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
// This example shows how to // This example shows how to

View File

@@ -11,7 +11,7 @@ import (
"github.com/aler9/gortsplib" "github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/base" "github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/gortsplib/pkg/rtph264" "github.com/aler9/gortsplib/pkg/rtph264"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
// This example shows how to // This example shows how to

View File

@@ -4,7 +4,7 @@ import (
"github.com/aler9/gortsplib" "github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/base" "github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/gortsplib/pkg/rtph264" "github.com/aler9/gortsplib/pkg/rtph264"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
// This example shows how to // This example shows how to

View File

@@ -6,7 +6,7 @@ import (
"github.com/aler9/gortsplib" "github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/base" "github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/gortsplib/pkg/rtph264" "github.com/aler9/gortsplib/pkg/rtph264"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
// This example shows how to // This example shows how to

View File

@@ -6,7 +6,7 @@ import (
"github.com/aler9/gortsplib" "github.com/aler9/gortsplib"
"github.com/pion/rtcp" "github.com/pion/rtcp"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
// This example shows how to // This example shows how to

View File

@@ -6,7 +6,7 @@ import (
"github.com/aler9/gortsplib" "github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/base" "github.com/aler9/gortsplib/pkg/base"
"github.com/pion/rtcp" "github.com/pion/rtcp"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
// This example shows how to // This example shows how to

View File

@@ -6,7 +6,7 @@ import (
"github.com/aler9/gortsplib" "github.com/aler9/gortsplib"
"github.com/pion/rtcp" "github.com/pion/rtcp"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
// This example shows how to // This example shows how to

View File

@@ -5,7 +5,7 @@ import (
"github.com/aler9/gortsplib" "github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/base" "github.com/aler9/gortsplib/pkg/base"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
// This example shows how to // This example shows how to

View File

@@ -5,7 +5,7 @@ import (
"github.com/aler9/gortsplib" "github.com/aler9/gortsplib"
"github.com/pion/rtcp" "github.com/pion/rtcp"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
// This example shows how to connect to a RTSP server // This example shows how to connect to a RTSP server

2
go.mod
View File

@@ -6,7 +6,7 @@ require (
github.com/asticode/go-astits v1.10.0 github.com/asticode/go-astits v1.10.0
github.com/icza/bitio v1.0.0 github.com/icza/bitio v1.0.0
github.com/pion/rtcp v1.2.9 github.com/pion/rtcp v1.2.9
github.com/pion/rtp v1.7.4 github.com/pion/rtp/v2 v2.0.0-20220302185659-b3d10fc096b0
github.com/pion/sdp/v3 v3.0.2 github.com/pion/sdp/v3 v3.0.2
github.com/stretchr/testify v1.7.0 github.com/stretchr/testify v1.7.0
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b golang.org/x/net v0.0.0-20210610132358-84b48f89b13b

4
go.sum
View File

@@ -12,8 +12,8 @@ github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
github.com/pion/rtcp v1.2.9 h1:1ujStwg++IOLIEoOiIQ2s+qBuJ1VN81KW+9pMPsif+U= github.com/pion/rtcp v1.2.9 h1:1ujStwg++IOLIEoOiIQ2s+qBuJ1VN81KW+9pMPsif+U=
github.com/pion/rtcp v1.2.9/go.mod h1:qVPhiCzAm4D/rxb6XzKeyZiQK69yJpbUDJSF7TgrqNo= github.com/pion/rtcp v1.2.9/go.mod h1:qVPhiCzAm4D/rxb6XzKeyZiQK69yJpbUDJSF7TgrqNo=
github.com/pion/rtp v1.7.4 h1:4dMbjb1SuynU5OpA3kz1zHK+u+eOCQjW3MAeVHf1ODA= github.com/pion/rtp/v2 v2.0.0-20220302185659-b3d10fc096b0 h1:zyOGxHutZ6IhksQSMtwf3OFXB29W5R18yFQWOQJYWjU=
github.com/pion/rtp v1.7.4/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko= github.com/pion/rtp/v2 v2.0.0-20220302185659-b3d10fc096b0/go.mod h1:Vj+rrFbJCT3yxqE/VSwaOo9DQ2pMKGPxuE7hplGOlOs=
github.com/pion/sdp/v3 v3.0.2 h1:UNnSPVaMM+Pdu/mR9UvAyyo6zkdYbKeuOooCwZvTl/g= github.com/pion/sdp/v3 v3.0.2 h1:UNnSPVaMM+Pdu/mR9UvAyyo6zkdYbKeuOooCwZvTl/g=
github.com/pion/sdp/v3 v3.0.2/go.mod h1:bNiSknmJE0HYBprTHXKPQ3+JjacTv5uap92ueJZKsRk= github.com/pion/sdp/v3 v3.0.2/go.mod h1:bNiSknmJE0HYBprTHXKPQ3+JjacTv5uap92ueJZKsRk=
github.com/pkg/profile v1.4.0/go.mod h1:NWz/XGvpEW1FyYQ7fCx4dqYBLlfTcE+A9FLAkNKqjFE= github.com/pkg/profile v1.4.0/go.mod h1:NWz/XGvpEW1FyYQ7fCx4dqYBLlfTcE+A9FLAkNKqjFE=

View File

@@ -7,7 +7,7 @@ import (
"time" "time"
"github.com/pion/rtcp" "github.com/pion/rtcp"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
func randUint32() uint32 { func randUint32() uint32 {

View File

@@ -5,7 +5,7 @@ import (
"time" "time"
"github.com/pion/rtcp" "github.com/pion/rtcp"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )

View File

@@ -6,7 +6,7 @@ import (
"time" "time"
"github.com/pion/rtcp" "github.com/pion/rtcp"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
// RTCPSender is a utility to generate RTCP sender reports. // RTCPSender is a utility to generate RTCP sender reports.

View File

@@ -5,7 +5,7 @@ import (
"time" "time"
"github.com/pion/rtcp" "github.com/pion/rtcp"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )

View File

@@ -6,7 +6,7 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
"github.com/aler9/gortsplib/pkg/rtptimedec" "github.com/aler9/gortsplib/pkg/rtptimedec"
) )

View File

@@ -5,7 +5,7 @@ import (
"encoding/binary" "encoding/binary"
"time" "time"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
const ( const (

View File

@@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )

View File

@@ -8,7 +8,7 @@ import (
"net" "net"
"time" "time"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
"github.com/aler9/gortsplib/pkg/h264" "github.com/aler9/gortsplib/pkg/h264"
"github.com/aler9/gortsplib/pkg/rtptimedec" "github.com/aler9/gortsplib/pkg/rtptimedec"

View File

@@ -5,7 +5,7 @@ import (
"encoding/binary" "encoding/binary"
"time" "time"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
const ( const (

View File

@@ -6,7 +6,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )

View File

@@ -1,7 +1,7 @@
package gortsplib package gortsplib
import ( import (
"github.com/pion/rtp" "github.com/pion/rtp/v2"
) )
type rtpPacketMultiBuffer struct { type rtpPacketMultiBuffer struct {

View File

@@ -9,7 +9,7 @@ import (
"time" "time"
"github.com/pion/rtcp" "github.com/pion/rtcp"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
psdp "github.com/pion/sdp/v3" psdp "github.com/pion/sdp/v3"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"

View File

@@ -10,7 +10,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
psdp "github.com/pion/sdp/v3" psdp "github.com/pion/sdp/v3"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"golang.org/x/net/ipv4" "golang.org/x/net/ipv4"

View File

@@ -256,6 +256,10 @@ func (sc *ServerConn) readFuncTCP(readRequest chan readReq) error {
return return
} }
// remove padding
pkt.Header.Padding = false
pkt.PaddingSize = 0
if h, ok := sc.s.Handler.(ServerHandlerOnPacketRTP); ok { if h, ok := sc.s.Handler.(ServerHandlerOnPacketRTP); ok {
h.OnPacketRTP(&ServerHandlerOnPacketRTPCtx{ h.OnPacketRTP(&ServerHandlerOnPacketRTPCtx{
Session: sc.session, Session: sc.session,

View File

@@ -2,7 +2,7 @@ package gortsplib
import ( import (
"github.com/pion/rtcp" "github.com/pion/rtcp"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
"github.com/aler9/gortsplib/pkg/base" "github.com/aler9/gortsplib/pkg/base"
) )

View File

@@ -12,7 +12,7 @@ import (
"time" "time"
"github.com/pion/rtcp" "github.com/pion/rtcp"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
"github.com/aler9/gortsplib/pkg/base" "github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/gortsplib/pkg/headers" "github.com/aler9/gortsplib/pkg/headers"

View File

@@ -6,7 +6,7 @@ import (
"time" "time"
"github.com/pion/rtcp" "github.com/pion/rtcp"
"github.com/pion/rtp" "github.com/pion/rtp/v2"
"github.com/aler9/gortsplib/pkg/liberrors" "github.com/aler9/gortsplib/pkg/liberrors"
) )

View File

@@ -203,6 +203,10 @@ func (u *serverUDPListener) processRTP(clientData *clientData, payload []byte) {
return return
} }
// remove padding
pkt.Header.Padding = false
pkt.PaddingSize = 0
now := time.Now() now := time.Now()
atomic.StoreInt64(clientData.ss.udpLastFrameTime, now.Unix()) atomic.StoreInt64(clientData.ss.udpLastFrameTime, now.Unix())
clientData.ss.announcedTracks[clientData.trackID].rtcpReceiver.ProcessPacketRTP(now, pkt) clientData.ss.announcedTracks[clientData.trackID].rtcpReceiver.ProcessPacketRTP(now, pkt)