status-go/vendor/github.com/pion/webrtc/v3/track_local.go

115 lines
4.0 KiB
Go
Raw Normal View History

2024-05-15 23:15:00 +00:00
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
2022-03-10 09:44:48 +00:00
package webrtc
2024-05-15 23:15:00 +00:00
import (
"github.com/pion/interceptor"
"github.com/pion/rtp"
)
2022-03-10 09:44:48 +00:00
// TrackLocalWriter is the Writer for outbound RTP Packets
type TrackLocalWriter interface {
// WriteRTP encrypts a RTP packet and writes to the connection
WriteRTP(header *rtp.Header, payload []byte) (int, error)
// Write encrypts and writes a full RTP packet
Write(b []byte) (int, error)
}
// TrackLocalContext is the Context passed when a TrackLocal has been Binded/Unbinded from a PeerConnection, and used
// in Interceptors.
2024-06-05 20:10:03 +00:00
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 {
2024-05-15 23:15:00 +00:00
id string
params RTPParameters
ssrc SSRC
writeStream TrackLocalWriter
rtcpInterceptor interceptor.RTCPReader
2022-03-10 09:44:48 +00:00
}
// CodecParameters returns the negotiated RTPCodecParameters. These are the codecs supported by both
// PeerConnections and the SSRC/PayloadTypes
2024-06-05 20:10:03 +00:00
func (t *baseTrackLocalContext) CodecParameters() []RTPCodecParameters {
2022-03-10 09:44:48 +00:00
return t.params.Codecs
}
// HeaderExtensions returns the negotiated RTPHeaderExtensionParameters. These are the header extensions supported by
// both PeerConnections and the SSRC/PayloadTypes
2024-06-05 20:10:03 +00:00
func (t *baseTrackLocalContext) HeaderExtensions() []RTPHeaderExtensionParameter {
2022-03-10 09:44:48 +00:00
return t.params.HeaderExtensions
}
// SSRC requires the negotiated SSRC of this track
// This track may have multiple if RTX is enabled
2024-06-05 20:10:03 +00:00
func (t *baseTrackLocalContext) SSRC() SSRC {
2022-03-10 09:44:48 +00:00
return t.ssrc
}
// WriteStream returns the WriteStream for this TrackLocal. The implementer writes the outbound
// media packets to it
2024-06-05 20:10:03 +00:00
func (t *baseTrackLocalContext) WriteStream() TrackLocalWriter {
2022-03-10 09:44:48 +00:00
return t.writeStream
}
// ID is a unique identifier that is used for both Bind/Unbind
2024-06-05 20:10:03 +00:00
func (t *baseTrackLocalContext) ID() string {
2022-03-10 09:44:48 +00:00
return t.id
}
2024-05-15 23:15:00 +00:00
// RTCPReader returns the RTCP interceptor for this TrackLocal. Used to read RTCP of this TrackLocal.
2024-06-05 20:10:03 +00:00
func (t *baseTrackLocalContext) RTCPReader() interceptor.RTCPReader {
2024-05-15 23:15:00 +00:00
return t.rtcpInterceptor
}
2022-03-10 09:44:48 +00:00
// TrackLocal is an interface that controls how the user can send media
// The user can provide their own TrackLocal implementations, or use
// the implementations in pkg/media
type TrackLocal interface {
// Bind should implement the way how the media data flows from the Track to the PeerConnection
// This will be called internally after signaling is complete and the list of available
// codecs has been determined
Bind(TrackLocalContext) (RTPCodecParameters, error)
// Unbind should implement the teardown logic when the track is no longer needed. This happens
// because a track has been stopped.
Unbind(TrackLocalContext) error
// ID is the unique identifier for this Track. This should be unique for the
// stream, but doesn't have to globally unique. A common example would be 'audio' or 'video'
// and StreamID would be 'desktop' or 'webcam'
ID() string
// RID is the RTP Stream ID for this track.
RID() string
// StreamID is the group this track belongs too. This must be unique
StreamID() string
// Kind controls if this TrackLocal is audio or video
Kind() RTPCodecType
}