Skip to content

Clean up writer interfaces. - #793

Open
alexfish8 wants to merge 6 commits into
tel-886/media-portfrom
tel-886/afish/clean-up-interfaces
Open

Clean up writer interfaces.#793
alexfish8 wants to merge 6 commits into
tel-886/media-portfrom
tel-886/afish/clean-up-interfaces

Conversation

@alexfish8

Copy link
Copy Markdown
Contributor
  • Rename MediaSession methods to be more explicit about the direction of a particular writer

    • [My brain kept getting confused about directions, especially when I was tweaking Room to satisfy the MediaSession interface, and so, for my own sanity, I renamed these things. Let me know what you think, I can always swap the names back or we can pick some thing else if you'd prefer]
  • Update Room method names to be similar to those in MediaPort

  • Move some DTMF event conversion logic out of inbound/outbound and into room.

    • Note: I couldn't entirely remove the dtmfEventWriter adapter out of inbound.go, as, even though Room's methods have been updated to the new pattern, the adapter is still responsible for populating some inbound-internal DTFM channel that gets read when validating pin prompts.
  • TODO (before landing this): Update tests to use the new method names.

@alexfish8
alexfish8 requested a review from a team as a code owner August 14, 2026 01:18
@alexfish8
alexfish8 requested a review from alexlivekit August 14, 2026 01:18
devin-ai-integration[bot]

This comment was marked as resolved.

Comment thread pkg/sip/room.go
}

func (r *Room) WriteOutboundAudioTo(w msdk.PCM16Writer) msdk.PCM16Writer {
return r.outboundAudio.Swap(w)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need r.mix.SampleRate() anymore?

Comment thread pkg/sip/inbound.go Outdated
Comment thread pkg/sip/media_port.go Outdated
Comment thread pkg/sip/inbound.go Outdated
Comment thread pkg/sip/inbound.go Outdated
Comment thread pkg/sip/inbound.go Outdated
Comment thread pkg/sip/inbound.go Outdated
Comment thread pkg/sip/outbound.go Outdated
Comment thread pkg/sip/room.go
}

func (r *Room) GetInboundAudioWriter() (msdk.PCM16Writer, error) {
return r.NewParticipantTrack(RoomSampleRate)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I like this one. Would we not create a new track every call? (where we simply return the fixed writer in other places, including GetInboundDTMFWriter below)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mirroring the existing behavior (where, previously, inbound and outbound would get new inbound writers by invoking NewParticipantTrack. We could have a fixed writer stored on Room, but we'd probably want to lazily initialize it the first time GetInboundAudioWriter is called. IMO, that doesn't really seem that much better.

@alexfish8
alexfish8 force-pushed the tel-886/afish/clean-up-interfaces branch from 84e160c to a609e02 Compare August 14, 2026 17:08
Base automatically changed from tel-886/tests to tel-886/media-port August 14, 2026 17:31

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 new potential issues.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment thread pkg/sip/media_port.go
Comment on lines +703 to +704
p.audioIn.Close() // Propagate Close() to onwards to room
p.dtmfIn.Close() // Propagate Close() to onwards to room

@devin-ai-integration devin-ai-integration Bot Aug 14, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Room audio writer for outgoing calls is shut down twice when a call ends

The room-facing audio writer is now shut down a second time (c.lkRoomIn.Close() at pkg/sip/outbound.go:393) after the media port already shut it down (p.audioIn.Close() at pkg/sip/media_port.go:703), so the same encoder and published track get torn down twice on every outbound hangup.
Impact: Every outgoing call end runs the same teardown twice, which can surface as spurious warnings in logs or, if the underlying writer is not tolerant of repeat shutdown, an error/panic during call cleanup.

Close propagation added to mediaPort.Close now overlaps the explicit lkRoomIn close in outboundCall.close

mediaPort.Close() newly propagates Close() through its inbound switches (pkg/sip/media_port.go:703-706). For outbound calls, audioIn's inner writer is c.lkRoomIn (set in connectMedia via c.media.WriteInboundAudioTo(c.lkRoomIn), pkg/sip/outbound.go:551), which is the opus encoder wrapping the published LiveKit track (Room.NewParticipantTrack, pkg/sip/room.go:741-763). outboundCall.close calls c.media.Close() first (pkg/sip/outbound.go:384) and then still calls c.lkRoomIn.Close() and logs a warning if it returns an error. opus.encoder.Close (pkg/media/opus/opus.go:198-207) flushes and then closes the wrapped sample writer, so the track-facing writer receives two Close() calls. Either drop the explicit c.lkRoomIn.Close() block now that the media port owns the propagation, or clear c.lkRoomIn before closing the media port.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread pkg/sip/inbound.go Outdated
@alexfish8
alexfish8 force-pushed the tel-886/afish/clean-up-interfaces branch from b632e7f to 269b1a3 Compare August 14, 2026 18:11

@alexfish8 alexfish8 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reviews!

Comment thread pkg/sip/media_port.go Outdated
Comment thread pkg/sip/inbound.go Outdated
Comment thread pkg/sip/inbound.go Outdated
Comment thread pkg/sip/inbound.go Outdated
Comment thread pkg/sip/inbound.go Outdated
Comment thread pkg/sip/inbound.go Outdated
Comment thread pkg/sip/outbound.go Outdated
Comment thread pkg/sip/room.go
}

func (r *Room) GetInboundAudioWriter() (msdk.PCM16Writer, error) {
return r.NewParticipantTrack(RoomSampleRate)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mirroring the existing behavior (where, previously, inbound and outbound would get new inbound writers by invoking NewParticipantTrack. We could have a fixed writer stored on Room, but we'd probably want to lazily initialize it the first time GetInboundAudioWriter is called. IMO, that doesn't really seem that much better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants