(c *gin.Context)
| 181 | } |
| 182 | |
| 183 | func HTTPAPIServerStreamWebRTC2(c *gin.Context) { |
| 184 | url := c.PostForm("url") |
| 185 | if _, ok := Config.Streams[url]; !ok { |
| 186 | Config.Streams[url] = StreamST{ |
| 187 | URL: url, |
| 188 | OnDemand: true, |
| 189 | Cl: make(map[string]viewer), |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | Config.RunIFNotRun(url) |
| 194 | |
| 195 | codecs := Config.coGe(url) |
| 196 | if codecs == nil { |
| 197 | log.Println("Stream Codec Not Found") |
| 198 | c.JSON(500, ResponseError{Error: Config.LastError.Error()}) |
| 199 | return |
| 200 | } |
| 201 | |
| 202 | muxerWebRTC := webrtc.NewMuxer( |
| 203 | webrtc.Options{ |
| 204 | ICEServers: Config.GetICEServers(), |
| 205 | PortMin: Config.GetWebRTCPortMin(), |
| 206 | PortMax: Config.GetWebRTCPortMax(), |
| 207 | }, |
| 208 | ) |
| 209 | |
| 210 | sdp64 := c.PostForm("sdp64") |
| 211 | answer, err := muxerWebRTC.WriteHeader(codecs, sdp64) |
| 212 | if err != nil { |
| 213 | log.Println("Muxer WriteHeader", err) |
| 214 | c.JSON(500, ResponseError{Error: err.Error()}) |
| 215 | return |
| 216 | } |
| 217 | |
| 218 | response := Response{ |
| 219 | Sdp64: answer, |
| 220 | } |
| 221 | |
| 222 | for _, codec := range codecs { |
| 223 | if codec.Type() != av.H264 && |
| 224 | codec.Type() != av.PCM_ALAW && |
| 225 | codec.Type() != av.PCM_MULAW && |
| 226 | codec.Type() != av.OPUS { |
| 227 | log.Println("Codec Not Supported WebRTC ignore this track", codec.Type()) |
| 228 | continue |
| 229 | } |
| 230 | if codec.Type().IsVideo() { |
| 231 | response.Tracks = append(response.Tracks, "video") |
| 232 | } else { |
| 233 | response.Tracks = append(response.Tracks, "audio") |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | c.JSON(200, response) |
| 238 | |
| 239 | AudioOnly := len(codecs) == 1 && codecs[0].Type().IsAudio() |
| 240 |
nothing calls this directly
no test coverage detected