-
Notifications
You must be signed in to change notification settings - Fork 235
TEL-886: Self review #805
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
Merged
Merged
TEL-886: Self review #805
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f5c2daf
Self-review
alexlivekit 9c96604
Self-review: dead ends without response to reINVITE
alexlivekit b11494e
Self-review: negotiate before room join; clear locals on pipeline close
alexlivekit 1c00fcc
Self-review: Warn Downgrade; Drop dead param; use const; reinvite tag
alexlivekit e577bdd
Self-review: Typos
alexlivekit d2793db
Bah
alexlivekit 5fcb481
one more typo
alexlivekit fcc2021
PR comment - print close errors:
alexlivekit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,19 +152,15 @@ func (p *mediaPortPipeline) init( | |
| return nil | ||
| } | ||
|
|
||
| // Construct the Audio and optionally DTM pipleine from SIP RTP to LK PCM, in reverse order. | ||
| // Construct the Audio and optionally DTMF pipeline from SIP RTP to LK PCM, in reverse order. | ||
| func (p *mediaPortPipeline) setupInput(mc *sdp.MediaConfig, audioToRoom msdk.PCM16Writer, dtmfToRoom msdk.WriteCloser[*livekit.SipDTMF]) error { | ||
| var err error | ||
| var inboundLatencyEntry atomic.Int64 | ||
| sink := msdk.NopCloser(audioToRoom) // Prevent pipeline close from closing room | ||
| sink = newLatencyPCMExit(sink, &inboundLatencyEntry, &p.conf.stats.LatencyInE2E) | ||
|
|
||
| codecInfo := mc.Audio.Codec.Info() | ||
| sink = msdk.ResampleWriter(sink, codecInfo.SampleRate) | ||
|
|
||
| if p.conf.stats != nil { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line 160 already dereferences |
||
| sink = newMediaWriterCount(sink, &p.conf.stats.AudioInFrames, &p.conf.stats.AudioInSamples) | ||
| } | ||
| sink = newMediaWriterCount(sink, &p.conf.stats.AudioInFrames, &p.conf.stats.AudioInSamples) | ||
|
|
||
| if p.conf.opts.LogSignalChanges { | ||
| sink, err = NewSignalLogger(p.conf.log, "input", sink) | ||
|
|
@@ -231,8 +227,8 @@ func (p *mediaPortPipeline) handleEventRTP(h *rtp.Header, payload []byte) error | |
| }) | ||
| } | ||
|
|
||
| // Construct the Audio and optionally DTM pipleine from LK PCM to SIP RTP | ||
| // Retuirns the insulated (nopCloser) connectors, and an error. | ||
| // Construct the Audio and optionally DTMF pipeline from LK PCM to SIP RTP | ||
| // Returns the insulated (nopCloser) connectors, and an error. | ||
| func (p *mediaPortPipeline) setupOutput(mc *sdp.MediaConfig, incomingSampleRate int) error { | ||
| p.rtpLoopWG.Go(p.rtpLoop) | ||
| w, err := p.sess.OpenWriteStream() | ||
|
|
@@ -440,12 +436,12 @@ func (w *dtmfOutWriter) WriteSample(sample *livekit.SipDTMF) error { | |
| if len(digits) == 0 { | ||
| digit := dtmf.CodeToChar(byte(sample.Code)) | ||
| if digit == 0 { | ||
| return fmt.Errorf("code %d not supoported", sample.Code) | ||
| return fmt.Errorf("code %d not supported", sample.Code) | ||
| } | ||
| digits = string([]byte{digit}) | ||
| } else if sample.Code > 0 { | ||
| // We can't distinguish between a code0 and no code, but better have something here | ||
| w.log.Warnw("code payload detected, ignored due to explicit digits", nil, "code", sample.Code, "digits", sample.Digit) | ||
| w.log.Debugw("code payload detected, ignored due to explicit digits", "code", sample.Code, "digits", sample.Digit) | ||
| } | ||
|
|
||
| w.mu.Lock() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,6 +123,44 @@ func (c *dtmfCollector) snapshot() []*livekit.SipDTMF { | |
| return out | ||
| } | ||
|
|
||
| // pcmCollector accumulates decoded room audio. The pipeline writes from the RTP | ||
| // read goroutine while the test reads, so every access is guarded. | ||
| type pcmCollector struct { | ||
| sampleRate int | ||
|
|
||
| mu sync.Mutex | ||
| buf msdk.PCM16Sample | ||
| } | ||
|
Comment on lines
+128
to
+133
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix data race in test by synchronizing the harness |
||
|
|
||
| func (c *pcmCollector) String() string { return fmt.Sprintf("pcmCollector(%d)", c.sampleRate) } | ||
|
|
||
| func (c *pcmCollector) SampleRate() int { return c.sampleRate } | ||
|
|
||
| func (c *pcmCollector) Close() error { return nil } | ||
|
|
||
| func (c *pcmCollector) WriteSample(sample msdk.PCM16Sample) error { | ||
| c.mu.Lock() | ||
| defer c.mu.Unlock() | ||
| c.buf = append(c.buf, sample...) | ||
| return nil | ||
| } | ||
|
|
||
| func (c *pcmCollector) len() int { | ||
| c.mu.Lock() | ||
| defer c.mu.Unlock() | ||
| return len(c.buf) | ||
| } | ||
|
|
||
| // since returns a copy of everything written after the first n samples. | ||
| func (c *pcmCollector) since(n int) msdk.PCM16Sample { | ||
| c.mu.Lock() | ||
| defer c.mu.Unlock() | ||
| if n >= len(c.buf) { | ||
| return nil | ||
| } | ||
| return slices.Clone(c.buf[n:]) | ||
| } | ||
|
|
||
| // pipelineHarness is the durable side of a mediaPort: UDP pipe, pipeline config, | ||
| // buffer anchors, and a synthesized MediaConfig. The pipeline itself is swapped | ||
| // on configure / reconfigure. | ||
|
|
@@ -136,7 +174,7 @@ type pipelineHarness struct { | |
| audioOut *msdk.WriteCloserSwitch[msdk.PCM16Sample] | ||
| dtmfIn *msdk.WriteCloserSwitch[*livekit.SipDTMF] | ||
| dtmfOut *msdk.WriteCloserSwitch[*livekit.SipDTMF] | ||
| roomAudio *msdk.PCM16Sample | ||
| roomAudio *pcmCollector | ||
| roomDTMF *dtmfCollector | ||
| pipeline *mediaPortPipeline | ||
| ssrcCount atomic.Uint64 | ||
|
|
@@ -159,10 +197,10 @@ func newPipelineHarness(t *testing.T, sampleRate int) *pipelineHarness { | |
| audioOut: msdk.NewWriteCloserSwitch[msdk.PCM16Sample](sampleRate), | ||
| dtmfIn: msdk.NewWriteCloserSwitch[*livekit.SipDTMF](dtmf.SampleRate), | ||
| dtmfOut: msdk.NewWriteCloserSwitch[*livekit.SipDTMF](dtmf.SampleRate), | ||
| roomAudio: new(msdk.PCM16Sample), | ||
| roomAudio: &pcmCollector{sampleRate: sampleRate}, | ||
| roomDTMF: &dtmfCollector{}, | ||
| } | ||
| h.audioIn.Swap(msdk.NewPCM16BufferWriter(h.roomAudio, sampleRate)) | ||
| h.audioIn.Swap(h.roomAudio) | ||
| h.dtmfIn.Swap(h.roomDTMF) | ||
| h.conf = &MediaPortPipelineConfig{ | ||
| log: log, | ||
|
|
@@ -348,7 +386,7 @@ func (h *pipelineHarness) testAudioFromRoom(t *testing.T) { | |
| } | ||
|
|
||
| func (h *pipelineHarness) testAudioFromPort(t *testing.T) { | ||
| before := len(*h.roomAudio) | ||
| before := h.roomAudio.len() | ||
| packetsBefore := h.packetCount.Load() | ||
| clock := h.codec.Info().RTPClockRate | ||
| if clock == 0 { | ||
|
|
@@ -363,15 +401,15 @@ func (h *pipelineHarness) testAudioFromPort(t *testing.T) { | |
| return h.packetCount.Load() >= packetsBefore+5 | ||
| }, time.Second, 5*time.Millisecond, "RTP should be accepted") | ||
| require.Eventually(t, func() bool { | ||
| return len(*h.roomAudio) > before | ||
| return h.roomAudio.len() > before | ||
| }, time.Second, 5*time.Millisecond, "decoded PCM should reach room (packets=%d input=%d failed=%d ignored=%d room=%d)", | ||
| h.packetCount.Load(), | ||
| h.pipeline.conf.stats.InputPackets.Load(), | ||
| h.pipeline.conf.stats.FailedPackets.Load(), | ||
| h.pipeline.conf.stats.IgnoredPackets.Load(), | ||
| len(*h.roomAudio), | ||
| h.roomAudio.len(), | ||
| ) | ||
| require.Greater(t, pcmEnergy((*h.roomAudio)[before:]), int64(0), "decoded room audio should carry energy") | ||
| require.Greater(t, pcmEnergy(h.roomAudio.since(before)), int64(0), "decoded room audio should carry energy") | ||
| } | ||
|
|
||
| func (h *pipelineHarness) testDTMFFromRoom(t *testing.T) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Possibly fail on media first, then join room