Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly update metadata when PayloadType is 0 #2783

Merged
merged 1 commit into from
Jun 5, 2024
Merged
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
45 changes: 45 additions & 0 deletions peerconnection_media_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 2 additions & 1 deletion track_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading