diff --git a/peerconnection_media_test.go b/peerconnection_media_test.go index 3cb2a1f92d9..0ef49e48c9d 100644 --- a/peerconnection_media_test.go +++ b/peerconnection_media_test.go @@ -1729,3 +1729,48 @@ func TestPeerConnection_Simulcast_NoDataChannel(t *testing.T) { closePairNow(t, pcSender, pcReceiver) } + +// Check that PayloadType of 0 is handled correctly. At one point +// we incorrectly assumed 0 meant an invalid stream and wouldn't update things +// properly +func TestPeerConnection_Zero_PayloadType(t *testing.T) { + lim := test.TimeOut(time.Second * 5) + defer lim.Stop() + + report := test.CheckRoutines(t) + defer report() + + pcOffer, pcAnswer, err := newPair() + require.NoError(t, err) + + audioTrack, err := NewTrackLocalStaticSample(RTPCodecCapability{MimeType: MimeTypePCMU}, "audio", "audio") + require.NoError(t, err) + + _, err = pcOffer.AddTrack(audioTrack) + require.NoError(t, err) + + assert.NoError(t, signalPair(pcOffer, pcAnswer)) + + onTrackFired, onTrackFiredCancel := context.WithCancel(context.Background()) + pcAnswer.OnTrack(func(track *TrackRemote, _ *RTPReceiver) { + require.Equal(t, track.Codec().MimeType, MimeTypePCMU) + onTrackFiredCancel() + }) + + go func() { + ticker := time.NewTicker(20 * time.Millisecond) + defer ticker.Stop() + + select { + case <-onTrackFired.Done(): + return + case <-ticker.C: + if routineErr := audioTrack.WriteSample(media.Sample{Data: []byte{0x00}, Duration: time.Second}); routineErr != nil { + fmt.Println(routineErr) + } + } + }() + + <-onTrackFired.Done() + closePairNow(t, pcOffer, pcAnswer) +} diff --git a/track_remote.go b/track_remote.go index e2d8d70df2e..7e448dd9895 100644 --- a/track_remote.go +++ b/track_remote.go @@ -153,7 +153,8 @@ func (t *TrackRemote) checkAndUpdateTrack(b []byte) error { return errRTPTooShort } - if payloadType := PayloadType(b[1] & rtpPayloadTypeBitmask); payloadType != t.PayloadType() { + payloadType := PayloadType(b[1] & rtpPayloadTypeBitmask) + if payloadType != t.PayloadType() || len(t.params.Codecs) == 0 { t.mu.Lock() defer t.mu.Unlock()