track_local.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package webrtc
  2. import (
  3. "github.com/pion/interceptor"
  4. "github.com/pion/rtp"
  5. )
  6. // TrackLocalWriter is the Writer for outbound RTP Packets
  7. type TrackLocalWriter interface {
  8. // WriteRTP encrypts a RTP packet and writes to the connection
  9. WriteRTP(header *rtp.Header, payload []byte) (int, error)
  10. // Write encrypts and writes a full RTP packet
  11. Write(b []byte) (int, error)
  12. }
  13. // TrackLocalContext is the Context passed when a TrackLocal has been Binded/Unbinded from a PeerConnection, and used
  14. // in Interceptors.
  15. type TrackLocalContext struct {
  16. id string
  17. params RTPParameters
  18. ssrc SSRC
  19. writeStream TrackLocalWriter
  20. rtcpInterceptor interceptor.RTCPReader
  21. }
  22. // CodecParameters returns the negotiated RTPCodecParameters. These are the codecs supported by both
  23. // PeerConnections and the SSRC/PayloadTypes
  24. func (t *TrackLocalContext) CodecParameters() []RTPCodecParameters {
  25. return t.params.Codecs
  26. }
  27. // HeaderExtensions returns the negotiated RTPHeaderExtensionParameters. These are the header extensions supported by
  28. // both PeerConnections and the SSRC/PayloadTypes
  29. func (t *TrackLocalContext) HeaderExtensions() []RTPHeaderExtensionParameter {
  30. return t.params.HeaderExtensions
  31. }
  32. // SSRC requires the negotiated SSRC of this track
  33. // This track may have multiple if RTX is enabled
  34. func (t *TrackLocalContext) SSRC() SSRC {
  35. return t.ssrc
  36. }
  37. // WriteStream returns the WriteStream for this TrackLocal. The implementer writes the outbound
  38. // media packets to it
  39. func (t *TrackLocalContext) WriteStream() TrackLocalWriter {
  40. return t.writeStream
  41. }
  42. // ID is a unique identifier that is used for both Bind/Unbind
  43. func (t *TrackLocalContext) ID() string {
  44. return t.id
  45. }
  46. // RTCPReader returns the RTCP interceptor for this TrackLocal. Used to read RTCP of this TrackLocal.
  47. func (t *TrackLocalContext) RTCPReader() interceptor.RTCPReader {
  48. return t.rtcpInterceptor
  49. }
  50. // TrackLocal is an interface that controls how the user can send media
  51. // The user can provide their own TrackLocal implementations, or use
  52. // the implementations in pkg/media
  53. type TrackLocal interface {
  54. // Bind should implement the way how the media data flows from the Track to the PeerConnection
  55. // This will be called internally after signaling is complete and the list of available
  56. // codecs has been determined
  57. Bind(TrackLocalContext) (RTPCodecParameters, error)
  58. // Unbind should implement the teardown logic when the track is no longer needed. This happens
  59. // because a track has been stopped.
  60. Unbind(TrackLocalContext) error
  61. // ID is the unique identifier for this Track. This should be unique for the
  62. // stream, but doesn't have to globally unique. A common example would be 'audio' or 'video'
  63. // and StreamID would be 'desktop' or 'webcam'
  64. ID() string
  65. // RID is the RTP Stream ID for this track.
  66. RID() string
  67. // StreamID is the group this track belongs too. This must be unique
  68. StreamID() string
  69. // Kind controls if this TrackLocal is audio or video
  70. Kind() RTPCodecType
  71. }