-
Notifications
You must be signed in to change notification settings - Fork 15
fix(sampleWriter): handle dropped packets & opus dtx #13
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
34b9346
12b1dee
6074196
1a044d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -182,6 +182,7 @@ type sampleWriter[T ~[]byte] struct { | |
| w MediaSampleWriter | ||
| sampleRate int | ||
| sampleDur time.Duration | ||
| lastWrite time.Time | ||
| } | ||
|
|
||
| func (w *sampleWriter[T]) String() string { | ||
|
|
@@ -199,7 +200,17 @@ func (w *sampleWriter[T]) Close() error { | |
| func (w *sampleWriter[T]) WriteSample(in T) error { | ||
| data := make([]byte, len(in)) | ||
| copy(data, in) | ||
| return w.w.WriteSample(media.Sample{Data: data, Duration: w.sampleDur}) | ||
|
|
||
| var droppedPackets uint16 | ||
| if !w.lastWrite.IsZero() { | ||
| timeSinceLastWrite := time.Since(w.lastWrite) | ||
| if timeSinceLastWrite > w.sampleDur { | ||
|
||
| droppedPackets = uint16((timeSinceLastWrite - w.sampleDur) / w.sampleDur) | ||
| } | ||
| } | ||
|
|
||
| w.lastWrite = time.Now() | ||
| return w.w.WriteSample(media.Sample{Data: data, Duration: w.sampleDur, PrevDroppedPackets: droppedPackets}) | ||
| } | ||
|
|
||
| // MonoToStereo converts mono PCM from src to stereo PCM in dst. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:TIL: I thought 1 byte should be transmitted to signal background noise level. I think I have seen 1 byte packets comes in to the server. But,
libwebrtcmentions this also (https://source.chromium.org/chromium/chromium/src/+/main:media/audio/audio_opus_encoder.cc;drc=dfb49a410ff213451f72db8d792973550025033e;l=288). Where are the 1 byte packets coming from into the server? Have to check again if I am not remembering something properly.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe some clients are not negotiating dtx? meet.livekit.io does not seem to be negotiating it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JS SDK sample app does DTX. I think I checked with that. Will test out and check packet sizes with DTX enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DTX packets (or the packet before DTX kicks in) is 1 byte when trying with JS SDK sample app (setting
red: falsein the demo app) and logging on SFU side. Puzzled what opus_encode returns and how that is getting sent. Definitely does not jive with opus_encode() doc or libwebrtc code.