Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 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,23 @@
feedbacks = append(feedbacks, interceptor.RTCPFeedback{Type: f.Type, Parameter: f.Parameter})
}

streamCodecs := make([]interceptor.RTPCodecParameters, 0, len(codecs))

Check failure on line 237 in interceptor.go

View workflow job for this annotation

GitHub Actions / lint / Go

undefined: interceptor.RTPCodecParameters

Check failure on line 237 in interceptor.go

View workflow job for this annotation

GitHub Actions / lint / Go

undefined: interceptor.RTPCodecParameters

Check failure on line 237 in interceptor.go

View workflow job for this annotation

GitHub Actions / test (1.24) / Go 1.24

undefined: interceptor.RTPCodecParameters

Check failure on line 237 in interceptor.go

View workflow job for this annotation

GitHub Actions / test (1.24) / Go 1.24

undefined: interceptor.RTPCodecParameters

Check failure on line 237 in interceptor.go

View workflow job for this annotation

GitHub Actions / test (1.23) / Go 1.23

undefined: interceptor.RTPCodecParameters

Check failure on line 237 in interceptor.go

View workflow job for this annotation

GitHub Actions / test (1.23) / Go 1.23

undefined: interceptor.RTPCodecParameters
for _, c := range codecs {
feedbacks := make([]interceptor.RTCPFeedback, 0, len(c.RTCPFeedback))
for _, f := range c.RTCPFeedback {
feedbacks = append(feedbacks, interceptor.RTCPFeedback{Type: f.Type, Parameter: f.Parameter})
}

streamCodecs = append(streamCodecs, interceptor.RTPCodecParameters{

Check failure on line 244 in interceptor.go

View workflow job for this annotation

GitHub Actions / lint / Go

undefined: interceptor.RTPCodecParameters

Check failure on line 244 in interceptor.go

View workflow job for this annotation

GitHub Actions / lint / Go

undefined: interceptor.RTPCodecParameters

Check failure on line 244 in interceptor.go

View workflow job for this annotation

GitHub Actions / test (1.24) / Go 1.24

undefined: interceptor.RTPCodecParameters

Check failure on line 244 in interceptor.go

View workflow job for this annotation

GitHub Actions / test (1.24) / Go 1.24

undefined: interceptor.RTPCodecParameters

Check failure on line 244 in interceptor.go

View workflow job for this annotation

GitHub Actions / test (1.23) / Go 1.23

undefined: interceptor.RTPCodecParameters

Check failure on line 244 in interceptor.go

View workflow job for this annotation

GitHub Actions / test (1.23) / Go 1.23

undefined: interceptor.RTPCodecParameters
MimeType: c.MimeType,
ClockRate: c.ClockRate,
Channels: c.Channels,
SDPFmtpLine: c.SDPFmtpLine,
RTCPFeedback: feedbacks,
PayloadType: uint8(c.PayloadType),
})
}

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

Check failure on line 269 in interceptor.go

View workflow job for this annotation

GitHub Actions / lint / Go

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

Check failure on line 269 in interceptor.go

View workflow job for this annotation

GitHub Actions / test (1.24) / Go 1.24

unknown field Codecs in struct literal of type interceptor.StreamInfo

Check failure on line 269 in interceptor.go

View workflow job for this annotation

GitHub Actions / test (1.24) / Go 1.24

unknown field Codecs in struct literal of type interceptor.StreamInfo

Check failure on line 269 in interceptor.go

View workflow job for this annotation

GitHub Actions / test (1.23) / Go 1.23

unknown field Codecs in struct literal of type interceptor.StreamInfo

Check failure on line 269 in interceptor.go

View workflow job for this annotation

GitHub Actions / test (1.23) / Go 1.23

unknown field Codecs in struct literal of type interceptor.StreamInfo
}
}
44 changes: 41 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,47 @@
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)
}

streamInfoCodecs := make([]interceptor.RTPCodecParameters, 0, len(videoCodecs))

Check failure on line 58 in interceptor_test.go

View workflow job for this annotation

GitHub Actions / test (1.24) / Go 1.24

undefined: interceptor.RTPCodecParameters

Check failure on line 58 in interceptor_test.go

View workflow job for this annotation

GitHub Actions / test (1.23) / Go 1.23

undefined: interceptor.RTPCodecParameters
for _, c := range videoCodecs {
feedbacks := make([]interceptor.RTCPFeedback, 0, len(c.RTCPFeedback))
for _, f := range c.RTCPFeedback {
feedbacks = append(feedbacks, interceptor.RTCPFeedback{Type: f.Type, Parameter: f.Parameter})
}

streamInfoCodecs = append(streamInfoCodecs, interceptor.RTPCodecParameters{

Check failure on line 65 in interceptor_test.go

View workflow job for this annotation

GitHub Actions / test (1.24) / Go 1.24

undefined: interceptor.RTPCodecParameters

Check failure on line 65 in interceptor_test.go

View workflow job for this annotation

GitHub Actions / test (1.23) / Go 1.23

undefined: interceptor.RTPCodecParameters
MimeType: c.MimeType,
ClockRate: c.ClockRate,
Channels: c.Channels,
SDPFmtpLine: c.SDPFmtpLine,
RTCPFeedback: feedbacks,
PayloadType: uint8(c.PayloadType),
})
}

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, streamInfoCodecs, streamInfo.Codecs)

Check failure on line 80 in interceptor_test.go

View workflow job for this annotation

GitHub Actions / test (1.24) / Go 1.24

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

Check failure on line 80 in interceptor_test.go

View workflow job for this annotation

GitHub Actions / test (1.23) / Go 1.23

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

Check failure on line 93 in interceptor_test.go

View workflow job for this annotation

GitHub Actions / test (1.24) / Go 1.24

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

Check failure on line 93 in interceptor_test.go

View workflow job for this annotation

GitHub Actions / test (1.23) / Go 1.23

streamInfo.Codecs undefined (type *interceptor.StreamInfo has no field or method Codecs)
return interceptor.RTPReaderFunc(func(b []byte, a interceptor.Attributes) (int, interceptor.Attributes, error) {
if a == nil {
a = interceptor.Attributes{}
Expand All @@ -67,7 +105,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