Skip to content
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

Make TrackLocalContext an interface #2170

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Dean Sheather <dean@coder.com>
decanus <7621705+decanus@users.noreply.github.com>
Denis <Hixon10@yandex.ru>
digitalix <digitalix4@gmail.com>
do-hyung-kim <do_hyung.kim@navercorp.com>
donotanswer <viktor.ferter@doclerholding.com>
earle <aguilar@dm.ai>
Egon Elbre <egonelbre@gmail.com>
Expand Down Expand Up @@ -101,6 +102,7 @@ juberti <juberti@alphaexplorationco.com>
Juliusz Chroboczek <jch@irif.fr>
Justin Okamoto <jdokamoto@gmail.com>
Justin Okamoto <justmoto@amazon.com>
Kevin <kevmo314@gmail.com>
Kevin Staunton-Lambert <kevin.staunton-lambert@metacdn.com>
Kevin Wang <kevmo314@gmail.com>
Konstantin Chugalinskiy <kchugalinskiy@yandex.ru>
Expand Down Expand Up @@ -137,6 +139,7 @@ mr-shitij <21.shitijagrawal@gmail.com>
mxmCherry <mxmCherry@gmail.com>
Nam V. Do <vannam12a7@gmail.com>
Nick Mykins <nmykins@digitalocean.com>
Nicolas Menard <nicolas.p.menard@gmail.com>
nindolabs <6729798+nindolabs@users.noreply.github.com>
Norman Rasmussen <norman@rasmussen.co.za>
notedit <notedit@gmail.com>
Expand Down
22 changes: 11 additions & 11 deletions rtpsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type trackEncoding struct {
rtcpInterceptor interceptor.RTCPReader
streamInfo interceptor.StreamInfo

context TrackLocalContext
context *baseTrackLocalContext

ssrc SSRC
}
Expand Down Expand Up @@ -242,13 +242,13 @@ func (r *RTPSender) ReplaceTrack(track TrackLocal) error {
}

var replacedTrack TrackLocal
var context *TrackLocalContext
var context *baseTrackLocalContext
if len(r.trackEncodings) != 0 {
replacedTrack = r.trackEncodings[0].track
context = &r.trackEncodings[0].context
context = r.trackEncodings[0].context
}
if r.hasSent() && replacedTrack != nil {
if err := replacedTrack.Unbind(*context); err != nil {
if err := replacedTrack.Unbind(context); err != nil {
return err
}
}
Expand All @@ -258,16 +258,16 @@ func (r *RTPSender) ReplaceTrack(track TrackLocal) error {
return nil
}

codec, err := track.Bind(TrackLocalContext{
id: context.id,
codec, err := track.Bind(&baseTrackLocalContext{
id: context.ID(),
params: r.api.mediaEngine.getRTPParametersByKind(track.Kind(), []RTPTransceiverDirection{RTPTransceiverDirectionSendonly}),
ssrc: context.ssrc,
writeStream: context.writeStream,
rtcpInterceptor: context.rtcpInterceptor,
ssrc: context.SSRC(),
writeStream: context.WriteStream(),
rtcpInterceptor: context.RTCPReader(),
})
if err != nil {
// Re-bind the original track
if _, reBindErr := replacedTrack.Bind(*context); reBindErr != nil {
if _, reBindErr := replacedTrack.Bind(context); reBindErr != nil {
return reBindErr
}

Expand Down Expand Up @@ -297,7 +297,7 @@ func (r *RTPSender) Send(parameters RTPSendParameters) error {

for idx, trackEncoding := range r.trackEncodings {
writeStream := &interceptorToTrackLocalWriter{}
trackEncoding.context = TrackLocalContext{
trackEncoding.context = &baseTrackLocalContext{
id: r.id,
params: r.api.mediaEngine.getRTPParametersByKind(trackEncoding.track.Kind(), []RTPTransceiverDirection{RTPTransceiverDirectionSendonly}),
ssrc: parameters.Encodings[idx].SSRC,
Expand Down
38 changes: 31 additions & 7 deletions track_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,31 @@

// TrackLocalContext is the Context passed when a TrackLocal has been Binded/Unbinded from a PeerConnection, and used
// in Interceptors.
type TrackLocalContext struct {
type TrackLocalContext interface {
// CodecParameters returns the negotiated RTPCodecParameters. These are the codecs supported by both
// PeerConnections and the SSRC/PayloadTypes
CodecParameters() []RTPCodecParameters

// HeaderExtensions returns the negotiated RTPHeaderExtensionParameters. These are the header extensions supported by
// both PeerConnections and the SSRC/PayloadTypes
HeaderExtensions() []RTPHeaderExtensionParameter

// SSRC requires the negotiated SSRC of this track
// This track may have multiple if RTX is enabled
SSRC() SSRC

// WriteStream returns the WriteStream for this TrackLocal. The implementer writes the outbound
// media packets to it
WriteStream() TrackLocalWriter

// ID is a unique identifier that is used for both Bind/Unbind
ID() string

// RTCPReader returns the RTCP interceptor for this TrackLocal. Used to read RTCP of this TrackLocal.
RTCPReader() interceptor.RTCPReader
}

type baseTrackLocalContext struct {
id string
params RTPParameters
ssrc SSRC
Expand All @@ -29,35 +53,35 @@

// CodecParameters returns the negotiated RTPCodecParameters. These are the codecs supported by both
// PeerConnections and the SSRC/PayloadTypes
func (t *TrackLocalContext) CodecParameters() []RTPCodecParameters {
func (t *baseTrackLocalContext) CodecParameters() []RTPCodecParameters {
return t.params.Codecs
}

// HeaderExtensions returns the negotiated RTPHeaderExtensionParameters. These are the header extensions supported by
// both PeerConnections and the SSRC/PayloadTypes
func (t *TrackLocalContext) HeaderExtensions() []RTPHeaderExtensionParameter {
func (t *baseTrackLocalContext) HeaderExtensions() []RTPHeaderExtensionParameter {

Check warning on line 62 in track_local.go

View check run for this annotation

Codecov / codecov/patch

track_local.go#L62

Added line #L62 was not covered by tests
return t.params.HeaderExtensions
}

// SSRC requires the negotiated SSRC of this track
// This track may have multiple if RTX is enabled
func (t *TrackLocalContext) SSRC() SSRC {
func (t *baseTrackLocalContext) SSRC() SSRC {
return t.ssrc
}

// WriteStream returns the WriteStream for this TrackLocal. The implementer writes the outbound
// media packets to it
func (t *TrackLocalContext) WriteStream() TrackLocalWriter {
func (t *baseTrackLocalContext) WriteStream() TrackLocalWriter {
return t.writeStream
}

// ID is a unique identifier that is used for both Bind/Unbind
func (t *TrackLocalContext) ID() string {
func (t *baseTrackLocalContext) ID() string {
return t.id
}

// RTCPReader returns the RTCP interceptor for this TrackLocal. Used to read RTCP of this TrackLocal.
func (t *TrackLocalContext) RTCPReader() interceptor.RTCPReader {
func (t *baseTrackLocalContext) RTCPReader() interceptor.RTCPReader {
return t.rtcpInterceptor
}

Expand Down
Loading