Skip to content

Commit

Permalink
Add padding support to TrackLocalStaticSample
Browse files Browse the repository at this point in the history
To add padding-only samples call GeneratePadding
  • Loading branch information
Alex Pokotilo committed Apr 9, 2024
1 parent b2af663 commit 6d1c672
Showing 1 changed file with 25 additions and 0 deletions.
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 @@ func (s *TrackLocalStaticSample) WriteSample(sample media.Sample) error {

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
}

0 comments on commit 6d1c672

Please sign in to comment.