@@ -10,6 +10,7 @@ import (
10
10
11
11
"github.com/AlexxIT/go2rtc/pkg/core"
12
12
"github.com/AlexxIT/go2rtc/pkg/webrtc"
13
+ "github.com/pion/sdp/v3"
13
14
)
14
15
15
16
// https://github.com/AlexxIT/go2rtc/issues/1600
@@ -27,7 +28,6 @@ func crealityClient(url string) (core.Producer, error) {
27
28
28
29
medias := []* core.Media {
29
30
{Kind : core .KindVideo , Direction : core .DirectionRecvonly },
30
- {Kind : core .KindAudio , Direction : core .DirectionRecvonly },
31
31
}
32
32
33
33
// TODO: return webrtc.SessionDescription
@@ -36,6 +36,8 @@ func crealityClient(url string) (core.Producer, error) {
36
36
return nil , err
37
37
}
38
38
39
+ log .Trace ().Msgf ("[webrtc] offer:\n %s" , offer )
40
+
39
41
body , err := offerToB64 (offer )
40
42
if err != nil {
41
43
return nil , err
@@ -61,6 +63,12 @@ func crealityClient(url string) (core.Producer, error) {
61
63
return nil , err
62
64
}
63
65
66
+ log .Trace ().Msgf ("[webrtc] answer:\n %s" , answer )
67
+
68
+ if answer , err = fixCrealitySDP (answer ); err != nil {
69
+ return nil , err
70
+ }
71
+
64
72
if err = prod .SetAnswer (answer ); err != nil {
65
73
return nil , err
66
74
}
@@ -108,3 +116,37 @@ func answerFromB64(r io.Reader) (string, error) {
108
116
// string "v=0..."
109
117
return v ["sdp" ], nil
110
118
}
119
+
120
+ func fixCrealitySDP (value string ) (string , error ) {
121
+ var sd sdp.SessionDescription
122
+ if err := sd .UnmarshalString (value ); err != nil {
123
+ return "" , err
124
+ }
125
+
126
+ md := sd .MediaDescriptions [0 ]
127
+
128
+ // important to skip first codec, because second codec will be used
129
+ skip := md .MediaName .Formats [0 ]
130
+ md .MediaName .Formats = md .MediaName .Formats [1 :]
131
+
132
+ attrs := make ([]sdp.Attribute , 0 , len (md .Attributes ))
133
+ for _ , attr := range md .Attributes {
134
+ switch attr .Key {
135
+ case "fmtp" , "rtpmap" :
136
+ // important to skip fmtp with x-google, because this is second fmtp for same codec
137
+ // and pion library will fail parsing this SDP
138
+ if strings .HasPrefix (attr .Value , skip ) || strings .Contains (attr .Value , "x-google" ) {
139
+ continue
140
+ }
141
+ }
142
+ attrs = append (attrs , attr )
143
+ }
144
+
145
+ md .Attributes = attrs
146
+
147
+ b , err := sd .Marshal ()
148
+ if err != nil {
149
+ return "" , err
150
+ }
151
+ return string (b ), nil
152
+ }
0 commit comments