Optimize SampleBuilder and reset cross-sample state on Flush#3445
Optimize SampleBuilder and reset cross-sample state on Flush#3445solos wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3445 +/- ##
==========================================
- Coverage 85.60% 85.46% -0.14%
==========================================
Files 81 81
Lines 9856 9868 +12
==========================================
- Hits 8437 8434 -3
- Misses 1003 1011 +8
- Partials 416 423 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
f6b2f17 to
d0e74e7
Compare
JoTurk
left a comment
There was a problem hiding this comment.
Change looks good to me, but we'll have to manually test it because samplebuilder has many moving parts.
| sample := &media.Sample{ | ||
| Data: data, | ||
| Duration: time.Duration((float64(samples)/float64(s.sampleRate))*secondToNanoseconds) * time.Nanosecond, | ||
| Duration: time.Duration(samples) * time.Second / time.Duration(s.sampleRate), |
There was a problem hiding this comment.
The old behavior returned invalid value (+Inf) if the sample-rate is 0.00f, this will just panic, both aren't ideal, but if there is a setup where users can pass sample rate to applications, this can be used to trigger panic/DoS.
Maybe we can check and return an error early if the user created a samplebuilder with 0 sample rate?
There was a problem hiding this comment.
Yes, you are right. If we return an error, the caller will need to change too. What about set the Duration to 0.
bb3bcc9 to
be7010a
Compare
- Replace pointer-based lastSampleTimestamp with uint32+bool flag - Preallocate sample data slice - Compute duration using integer arithmetic - Reset cross-sample state in Flush (lastTimestamp, droppedPackets, paddingPackets) to avoid contamination between streams. - Add tests to verify flush resets padding detection and does not misclassify valid frames.
Fix range loop in test cases
check invalid sampleRate
be7010a to
9b109df
Compare
Description
Improve SampleBuilder performance and make Flush() a clean boundary for a new RTP stream.
Performance:
Reference issue
None