MCPcopy
hub / github.com/livekit/livekit / AddSubscriber

Method AddSubscriber

pkg/rtc/mediatrackreceiver.go:530–606  ·  view source on GitHub ↗

AddSubscriber subscribes sub to current mediaTrack

(sub types.LocalParticipant)

Source from the content-addressed store, hash-verified

528
529// AddSubscriber subscribes sub to current mediaTrack
530func (t *MediaTrackReceiver) AddSubscriber(sub types.LocalParticipant) (types.SubscribedTrack, error) {
531 t.lock.RLock()
532 if t.state != mediaTrackReceiverStateOpen {
533 t.lock.RUnlock()
534 return nil, ErrNotOpen
535 }
536
537 receivers := t.receivers
538 potentialCodecs := make([]webrtc.RTPCodecParameters, len(t.potentialCodecs))
539 copy(potentialCodecs, t.potentialCodecs)
540 t.lock.RUnlock()
541
542 if len(receivers) == 0 {
543 // cannot add, no receiver
544 return nil, ErrNoReceiver
545 }
546
547 for _, receiver := range receivers {
548 if receiver.IsRegressed() {
549 continue
550 }
551
552 codec := receiver.Codec()
553 var found bool
554 for _, pc := range potentialCodecs {
555 if mime.IsMimeTypeStringEqual(codec.MimeType, pc.MimeType) {
556 found = true
557 break
558 }
559 }
560 if !found {
561 potentialCodecs = append(potentialCodecs, codec)
562 }
563 }
564
565 streamId := string(t.PublisherID())
566 if sub.ProtocolVersion().SupportsPackedStreamId() {
567 // when possible, pack both IDs in streamID to allow new streams to be generated
568 // react-native-webrtc still uses stream based APIs and require this
569 streamId = PackStreamID(t.PublisherID(), t.ID())
570 }
571
572 tLogger := LoggerWithTrack(sub.GetLogger(), t.ID(), t.params.IsRelayed)
573 wr := NewWrappedReceiver(WrappedReceiverParams{
574 Receivers: receivers,
575 TrackID: t.ID(),
576 StreamId: streamId,
577 UpstreamCodecs: potentialCodecs,
578 Logger: tLogger,
579 DisableRed: !IsRedEnabled(t.TrackInfo()) || !t.params.AudioConfig.ActiveREDEncoding,
580 IsEncrypted: t.IsEncrypted(),
581 })
582 subID := sub.ID()
583 subTrack, err := t.MediaTrackSubscriptions.AddSubscriber(sub, wr)
584
585 // media track could have been closed while adding subscription
586 remove := false
587 isExpectedToResume := false

Callers

nothing calls this directly

Calls 15

PublisherIDMethod · 0.95
IDMethod · 0.95
TrackInfoMethod · 0.95
IsEncryptedMethod · 0.95
PackStreamIDFunction · 0.85
LoggerWithTrackFunction · 0.85
NewWrappedReceiverFunction · 0.85
IsRedEnabledFunction · 0.85
IsRegressedMethod · 0.80
CodecMethod · 0.65
ProtocolVersionMethod · 0.65

Tested by

no test coverage detected