Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
payloadType, payloadTypeRTX, payloadTypeFEC PayloadType,
codec RTPCodecCapability,
webrtcHeaderExtensions []RTPHeaderExtensionParameter,
codecs []RTPCodecParameters,
) *interceptor.StreamInfo {
headerExtensions := make([]interceptor.RTPHeaderExtension, 0, len(webrtcHeaderExtensions))
for _, h := range webrtcHeaderExtensions {
Expand All @@ -233,6 +234,11 @@
feedbacks = append(feedbacks, interceptor.RTCPFeedback{Type: f.Type, Parameter: f.Parameter})
}

payloadToMimeType := make(map[uint8]string)
for _, c := range codecs {
payloadToMimeType[uint8(c.PayloadType)] = c.MimeType
}

return &interceptor.StreamInfo{
ID: id,
Attributes: interceptor.Attributes{},
Expand All @@ -248,5 +254,6 @@
Channels: codec.Channels,
SDPFmtpLine: codec.SDPFmtpLine,
RTCPFeedback: feedbacks,
PayloadToMimeType: payloadToMimeType,

Check failure on line 257 in interceptor.go

View workflow job for this annotation

GitHub Actions / lint / Go

unknown field PayloadToMimeType in struct literal of type interceptor.StreamInfo

Check failure on line 257 in interceptor.go

View workflow job for this annotation

GitHub Actions / lint / Go

unknown field PayloadToMimeType in struct literal of type interceptor.StreamInfo) (typecheck)

Check failure on line 257 in interceptor.go

View workflow job for this annotation

GitHub Actions / lint / Go

unknown field PayloadToMimeType in struct literal of type interceptor.StreamInfo) (typecheck)

Check failure on line 257 in interceptor.go

View workflow job for this annotation

GitHub Actions / lint / Go

unknown field PayloadToMimeType in struct literal of type interceptor.StreamInfo) (typecheck)

Check failure on line 257 in interceptor.go

View workflow job for this annotation

GitHub Actions / test (1.23) / Go 1.23

unknown field PayloadToMimeType in struct literal of type interceptor.StreamInfo

Check failure on line 257 in interceptor.go

View workflow job for this annotation

GitHub Actions / test (1.23) / Go 1.23

unknown field PayloadToMimeType in struct literal of type interceptor.StreamInfo

Check failure on line 257 in interceptor.go

View workflow job for this annotation

GitHub Actions / test (1.24) / Go 1.24

unknown field PayloadToMimeType in struct literal of type interceptor.StreamInfo

Check failure on line 257 in interceptor.go

View workflow job for this annotation

GitHub Actions / test (1.24) / Go 1.24

unknown field PayloadToMimeType in struct literal of type interceptor.StreamInfo
}
}
32 changes: 29 additions & 3 deletions interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
// * Assert an extension can be set on an outbound packet
// * Assert an extension can be read on an outbound packet
// * Assert that attributes set by an interceptor are returned to the Reader.
// * Assert that StreamInfo.Codecs contain capabilities of all negotiated codecs for track's SSRC
func TestPeerConnection_Interceptor(t *testing.T) {
to := test.TimeOut(time.Second * 20)
defer to.Stop()
Expand All @@ -36,11 +37,35 @@
defer report()

createPC := func() *PeerConnection {
videoRTCPFeedback := []RTCPFeedback{{"goog-remb", ""}, {"ccm", "fir"}, {"nack", ""}, {"nack", "pli"}}
videoCodecs := []RTPCodecParameters{
{
RTPCodecCapability: RTPCodecCapability{MimeTypeVP8, 90000, 0, "", videoRTCPFeedback},
PayloadType: 96,
},
{
RTPCodecCapability: RTPCodecCapability{MimeTypeVP9, 90000, 0, "profile-id=0", videoRTCPFeedback},
PayloadType: 98,
},
}

me := &MediaEngine{}
for _, videoCodec := range videoCodecs {
err := me.RegisterCodec(videoCodec, RTPCodecTypeVideo)
assert.NoError(t, err)
}

payloadToMimeType := make(map[uint8]string)
for _, c := range videoCodecs {
payloadToMimeType[uint8(c.PayloadType)] = c.MimeType
}

ir := &interceptor.Registry{}
ir.Add(&mock_interceptor.Factory{
NewInterceptorFn: func(_ string) (interceptor.Interceptor, error) {
return &mock_interceptor.Interceptor{
BindLocalStreamFn: func(_ *interceptor.StreamInfo, writer interceptor.RTPWriter) interceptor.RTPWriter {
BindLocalStreamFn: func(streamInfo *interceptor.StreamInfo, writer interceptor.RTPWriter) interceptor.RTPWriter {
assert.Equal(t, payloadToMimeType, streamInfo.PayloadToMimeType)

Check failure on line 68 in interceptor_test.go

View workflow job for this annotation

GitHub Actions / test (1.23) / Go 1.23

streamInfo.PayloadToMimeType undefined (type *interceptor.StreamInfo has no field or method PayloadToMimeType)

Check failure on line 68 in interceptor_test.go

View workflow job for this annotation

GitHub Actions / test (1.24) / Go 1.24

streamInfo.PayloadToMimeType undefined (type *interceptor.StreamInfo has no field or method PayloadToMimeType)
return interceptor.RTPWriterFunc(
func(header *rtp.Header, payload []byte, attributes interceptor.Attributes) (int, error) {
// set extension on outgoing packet
Expand All @@ -52,7 +77,8 @@
},
)
},
BindRemoteStreamFn: func(_ *interceptor.StreamInfo, reader interceptor.RTPReader) interceptor.RTPReader {
BindRemoteStreamFn: func(streamInfo *interceptor.StreamInfo, reader interceptor.RTPReader) interceptor.RTPReader {
assert.Equal(t, payloadToMimeType, streamInfo.PayloadToMimeType)

Check failure on line 81 in interceptor_test.go

View workflow job for this annotation

GitHub Actions / test (1.23) / Go 1.23

streamInfo.PayloadToMimeType undefined (type *interceptor.StreamInfo has no field or method PayloadToMimeType)

Check failure on line 81 in interceptor_test.go

View workflow job for this annotation

GitHub Actions / test (1.24) / Go 1.24

streamInfo.PayloadToMimeType undefined (type *interceptor.StreamInfo has no field or method PayloadToMimeType)
return interceptor.RTPReaderFunc(func(b []byte, a interceptor.Attributes) (int, interceptor.Attributes, error) {
if a == nil {
a = interceptor.Attributes{}
Expand All @@ -67,7 +93,7 @@
},
})

pc, err := NewAPI(WithInterceptorRegistry(ir)).NewPeerConnection(Configuration{})
pc, err := NewAPI(WithInterceptorRegistry(ir), WithMediaEngine(me)).NewPeerConnection(Configuration{})
assert.NoError(t, err)

return pc
Expand Down
1 change: 1 addition & 0 deletions peerconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,7 @@ func (pc *PeerConnection) handleIncomingSSRC(rtpStream io.Reader, ssrc SSRC) err
0, 0,
params.Codecs[0].RTPCodecCapability,
params.HeaderExtensions,
params.Codecs,
)
readStream, interceptor, rtcpReadStream, rtcpInterceptor, err := pc.dtlsTransport.streamsForSSRC(ssrc, *streamInfo)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion rtpreceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func (r *RTPReceiver) startReceive(parameters RTPReceiveParameters) error { //no
0, 0, 0, 0, 0,
codec,
globalParams.HeaderExtensions,
globalParams.Codecs,
)
var err error

Expand All @@ -233,7 +234,7 @@ func (r *RTPReceiver) startReceive(parameters RTPReceiveParameters) error { //no
}

if rtxSsrc := parameters.Encodings[i].RTX.SSRC; rtxSsrc != 0 {
streamInfo := createStreamInfo("", rtxSsrc, 0, 0, 0, 0, 0, codec, globalParams.HeaderExtensions)
streamInfo := createStreamInfo("", rtxSsrc, 0, 0, 0, 0, 0, codec, globalParams.HeaderExtensions, globalParams.Codecs)
rtpReadStream, rtpInterceptor, rtcpReadStream, rtcpInterceptor, err := r.transport.streamsForSSRC(
rtxSsrc,
*streamInfo,
Expand Down
1 change: 1 addition & 0 deletions rtpsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ func (r *RTPSender) Send(parameters RTPSendParameters) error {
findFECPayloadType(rtpParameters.Codecs),
codec.RTPCodecCapability,
parameters.HeaderExtensions,
parameters.Codecs,
)

rtpInterceptor := r.api.interceptor.BindLocalStream(
Expand Down
Loading