mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-11-03 10:41:00 +08:00
BIG core logic rewrite
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package webrtc
|
||||
|
||||
import (
|
||||
"github.com/AlexxIT/go2rtc/pkg/streamer"
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
"github.com/pion/sdp/v3"
|
||||
"github.com/pion/webrtc/v3"
|
||||
)
|
||||
@@ -20,14 +20,14 @@ func (c *Conn) SetOffer(offer string) (err error) {
|
||||
var tr *webrtc.RTPTransceiver
|
||||
for _, attr := range md.Attributes {
|
||||
switch attr.Key {
|
||||
case streamer.DirectionSendRecv:
|
||||
case core.DirectionSendRecv:
|
||||
tr, _ = c.pc.AddTransceiverFromTrack(NewTrack(md.MediaName.Media))
|
||||
case streamer.DirectionSendonly:
|
||||
case core.DirectionSendonly:
|
||||
tr, _ = c.pc.AddTransceiverFromKind(
|
||||
webrtc.NewRTPCodecType(md.MediaName.Media),
|
||||
webrtc.RTPTransceiverInit{Direction: webrtc.RTPTransceiverDirectionRecvonly},
|
||||
)
|
||||
case streamer.DirectionRecvonly:
|
||||
case core.DirectionRecvonly:
|
||||
tr, _ = c.pc.AddTransceiverFromTrack(
|
||||
NewTrack(md.MediaName.Media),
|
||||
webrtc.RTPTransceiverInit{Direction: webrtc.RTPTransceiverDirectionSendonly},
|
||||
@@ -42,20 +42,7 @@ func (c *Conn) SetOffer(offer string) (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
medias := streamer.UnmarshalMedias(sd.MediaDescriptions)
|
||||
|
||||
// sort medias, so video will always be before audio
|
||||
// and ignore application media from Hass default lovelace card
|
||||
for _, media := range medias {
|
||||
if media.Kind == streamer.KindVideo {
|
||||
c.medias = append(c.medias, media)
|
||||
}
|
||||
}
|
||||
for _, media := range medias {
|
||||
if media.Kind == streamer.KindAudio {
|
||||
c.medias = append(c.medias, media)
|
||||
}
|
||||
}
|
||||
c.medias = UnmarshalMedias(sd.MediaDescriptions)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -67,15 +54,21 @@ func (c *Conn) GetAnswer() (answer string, err error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// disable transceivers if we don't have track
|
||||
// make direction=inactive
|
||||
// don't really necessary, but anyway
|
||||
// disable transceivers if we don't have track, make direction=inactive
|
||||
transeivers:
|
||||
for _, tr := range c.pc.GetTransceivers() {
|
||||
if tr.Direction() == webrtc.RTPTransceiverDirectionSendonly && tr.Sender() == nil {
|
||||
if err = tr.Stop(); err != nil {
|
||||
return
|
||||
for _, sender := range c.senders {
|
||||
if sender.Media.ID == tr.Mid() {
|
||||
continue transeivers
|
||||
}
|
||||
}
|
||||
|
||||
switch tr.Direction() {
|
||||
case webrtc.RTPTransceiverDirectionSendrecv:
|
||||
_ = tr.Sender().Stop()
|
||||
case webrtc.RTPTransceiverDirectionSendonly:
|
||||
_ = tr.Stop()
|
||||
}
|
||||
}
|
||||
|
||||
if desc, err = c.pc.CreateAnswer(nil); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user