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

Add padding support to TrackLocalStaticSample #2745

Closed
Closed
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
25 changes: 25 additions & 0 deletions track_local_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,28 @@

return util.FlattenErrs(writeErrs)
}

// GeneratePadding writes padding-only samples to the TrackLocalStaticSample
// If one PeerConnection fails the packets will still be sent to
// all PeerConnections. The error message will contain the ID of the failed
// PeerConnections so you can remove them
func (s *TrackLocalStaticSample) GeneratePadding(samples uint32) error {
s.rtpTrack.mu.RLock()
p := s.packetizer
s.rtpTrack.mu.RUnlock()

Check warning on line 315 in track_local_static.go

View check run for this annotation

Codecov / codecov/patch

track_local_static.go#L312-L315

Added lines #L312 - L315 were not covered by tests

if p == nil {
return nil

Check warning on line 318 in track_local_static.go

View check run for this annotation

Codecov / codecov/patch

track_local_static.go#L317-L318

Added lines #L317 - L318 were not covered by tests
}

packets := p.GeneratePadding(samples)

Check warning on line 321 in track_local_static.go

View check run for this annotation

Codecov / codecov/patch

track_local_static.go#L321

Added line #L321 was not covered by tests

writeErrs := []error{}
for _, p := range packets {
if err := s.rtpTrack.WriteRTP(p); err != nil {
writeErrs = append(writeErrs, err)

Check warning on line 326 in track_local_static.go

View check run for this annotation

Codecov / codecov/patch

track_local_static.go#L323-L326

Added lines #L323 - L326 were not covered by tests
}
}

return util.FlattenErrs(writeErrs)

Check warning on line 330 in track_local_static.go

View check run for this annotation

Codecov / codecov/patch

track_local_static.go#L330

Added line #L330 was not covered by tests
}
Loading