rename to PeerStreamTrack.

This commit is contained in:
Miroslav Šedivý 2021-10-01 00:02:54 +02:00
parent c9c8cc67ca
commit 0245c73e2b
2 changed files with 9 additions and 10 deletions

View File

@ -113,7 +113,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
// audio track // audio track
audioTrack, err := manager.newPeerTrack(audioStream, logger) audioTrack, err := manager.newPeerStreamTrack(audioStream, logger)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -125,7 +125,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
// video track // video track
videoTrack, err := manager.newPeerTrack(videoStream, logger) videoTrack, err := manager.newPeerStreamTrack(videoStream, logger)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -11,7 +11,7 @@ import (
"github.com/rs/zerolog" "github.com/rs/zerolog"
) )
func (manager *WebRTCManagerCtx) newPeerTrack(stream types.StreamManager, logger zerolog.Logger) (*PeerTrack, error) { func (manager *WebRTCManagerCtx) newPeerStreamTrack(stream types.StreamManager, logger zerolog.Logger) (*PeerStreamTrack, error) {
codec := stream.Codec() codec := stream.Codec()
id := codec.Type.String() id := codec.Type.String()
@ -22,7 +22,7 @@ func (manager *WebRTCManagerCtx) newPeerTrack(stream types.StreamManager, logger
logger = logger.With().Str("id", id).Logger() logger = logger.With().Str("id", id).Logger()
peer := &PeerTrack{ peer := &PeerStreamTrack{
logger: logger, logger: logger,
track: track, track: track,
listener: func(sample types.Sample) { listener: func(sample types.Sample) {
@ -35,19 +35,18 @@ func (manager *WebRTCManagerCtx) newPeerTrack(stream types.StreamManager, logger
peer.SetStream(stream) peer.SetStream(stream)
return peer, nil return peer, nil
} }
type PeerTrack struct { type PeerStreamTrack struct {
logger zerolog.Logger logger zerolog.Logger
track *webrtc.TrackLocalStaticSample track *webrtc.TrackLocalStaticSample
listener func(sample types.Sample) listener func(sample types.Sample)
streamMu sync.Mutex
stream types.StreamManager stream types.StreamManager
streamMu sync.Mutex
} }
func (peer *PeerTrack) SetStream(stream types.StreamManager) error { func (peer *PeerStreamTrack) SetStream(stream types.StreamManager) error {
peer.streamMu.Lock() peer.streamMu.Lock()
defer peer.streamMu.Unlock() defer peer.streamMu.Unlock()
@ -75,7 +74,7 @@ func (peer *PeerTrack) SetStream(stream types.StreamManager) error {
return nil return nil
} }
func (peer *PeerTrack) RemoveStream() { func (peer *PeerStreamTrack) RemoveStream() {
peer.streamMu.Lock() peer.streamMu.Lock()
defer peer.streamMu.Unlock() defer peer.streamMu.Unlock()
@ -85,7 +84,7 @@ func (peer *PeerTrack) RemoveStream() {
} }
} }
func (peer *PeerTrack) AddToConnection(connection *webrtc.PeerConnection) error { func (peer *PeerStreamTrack) AddToConnection(connection *webrtc.PeerConnection) error {
sender, err := connection.AddTrack(peer.track) sender, err := connection.AddTrack(peer.track)
if err != nil { if err != nil {
return err return err