mirror of
https://github.com/Monibuca/plugin-webrtc.git
synced 2025-10-22 06:19:31 +08:00
fix: WHIP
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/pion/rtcp"
|
||||
. "github.com/pion/webrtc/v3"
|
||||
. "github.com/pion/webrtc/v4"
|
||||
"go.uber.org/zap"
|
||||
. "m7s.live/engine/v4"
|
||||
"m7s.live/engine/v4/codec"
|
||||
@@ -73,7 +73,7 @@ func (suber *WebRTCSubscriber) OnSubscribe() {
|
||||
for _, track := range suber.audioTracks {
|
||||
am[track.CodecID] = track
|
||||
}
|
||||
if (vm[codec.CodecID_H264] != nil || vm[codec.CodecID_H265] == nil) && (am[codec.CodecID_PCMA] != nil || am[codec.CodecID_PCMU] != nil || am[codec.CodecID_AAC] == nil) {
|
||||
if (vm[codec.CodecID_H264] != nil || vm[codec.CodecID_AV1] != nil || vm[codec.CodecID_H265] == nil) && (am[codec.CodecID_PCMA] != nil || am[codec.CodecID_PCMU] != nil || am[codec.CodecID_AAC] == nil) {
|
||||
video := vm[codec.CodecID_H264]
|
||||
if video != nil {
|
||||
suber.Subscriber.AddTrack(video)
|
||||
@@ -86,27 +86,30 @@ func (suber *WebRTCSubscriber) OnSubscribe() {
|
||||
}
|
||||
}
|
||||
suber.video.TrackLocalStaticRTP, _ = NewTrackLocalStaticRTP(RTPCodecCapability{MimeType: MimeTypeH264, SDPFmtpLine: "level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=" + pli}, video.Name, suber.Subscriber.Stream.Path)
|
||||
if suber.video.TrackLocalStaticRTP != nil {
|
||||
suber.video.RTPSender, _ = suber.PeerConnection.AddTrack(suber.video.TrackLocalStaticRTP)
|
||||
go func() {
|
||||
rtcpBuf := make([]byte, 1500)
|
||||
for {
|
||||
if n, _, rtcpErr := suber.video.Read(rtcpBuf); rtcpErr != nil {
|
||||
suber.Warn("rtcp read error", zap.Error(rtcpErr))
|
||||
return
|
||||
} else {
|
||||
if p, err := rtcp.Unmarshal(rtcpBuf[:n]); err == nil {
|
||||
for _, pp := range p {
|
||||
switch pp.(type) {
|
||||
case *rtcp.PictureLossIndication:
|
||||
// fmt.Println("PictureLossIndication")
|
||||
}
|
||||
} else if video = vm[codec.CodecID_AV1]; video != nil {
|
||||
suber.Subscriber.AddTrack(video)
|
||||
suber.video.TrackLocalStaticRTP, _ = NewTrackLocalStaticRTP(RTPCodecCapability{MimeType: MimeTypeAV1, SDPFmtpLine: fmt.Sprintf("profile=%d;level-idx=%d;tier=%d", video.ParamaterSets[1][1], video.ParamaterSets[1][0], video.ParamaterSets[1][2])}, video.Name, suber.Subscriber.Stream.Path)
|
||||
}
|
||||
if suber.video.TrackLocalStaticRTP != nil {
|
||||
suber.video.RTPSender, _ = suber.PeerConnection.AddTrack(suber.video.TrackLocalStaticRTP)
|
||||
go func() {
|
||||
rtcpBuf := make([]byte, 1500)
|
||||
for {
|
||||
if n, _, rtcpErr := suber.video.Read(rtcpBuf); rtcpErr != nil {
|
||||
suber.Warn("rtcp read error", zap.Error(rtcpErr))
|
||||
return
|
||||
} else {
|
||||
if p, err := rtcp.Unmarshal(rtcpBuf[:n]); err == nil {
|
||||
for _, pp := range p {
|
||||
switch pp.(type) {
|
||||
case *rtcp.PictureLossIndication:
|
||||
// fmt.Println("PictureLossIndication")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
var audio *track.Audio
|
||||
audioMimeType := MimeTypePCMA
|
||||
@@ -115,8 +118,9 @@ func (suber *WebRTCSubscriber) OnSubscribe() {
|
||||
} else if am[codec.CodecID_PCMU] != nil {
|
||||
audioMimeType = MimeTypePCMU
|
||||
audio = am[codec.CodecID_PCMU]
|
||||
} else {
|
||||
|
||||
} else if am[codec.CodecID_OPUS] != nil {
|
||||
audioMimeType = MimeTypeOpus
|
||||
audio = am[codec.CodecID_OPUS]
|
||||
}
|
||||
if audio != nil {
|
||||
suber.Subscriber.AddTrack(audio)
|
||||
|
Reference in New Issue
Block a user