Fix support RTSPtoWebRTC API
This commit is contained in:
+19
-9
@@ -6,12 +6,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/AlexxIT/go2rtc/cmd/api"
|
"github.com/AlexxIT/go2rtc/cmd/api"
|
||||||
"github.com/AlexxIT/go2rtc/cmd/app"
|
"github.com/AlexxIT/go2rtc/cmd/app"
|
||||||
"github.com/AlexxIT/go2rtc/cmd/rtsp"
|
|
||||||
"github.com/AlexxIT/go2rtc/cmd/streams"
|
"github.com/AlexxIT/go2rtc/cmd/streams"
|
||||||
"github.com/AlexxIT/go2rtc/cmd/webrtc"
|
"github.com/AlexxIT/go2rtc/cmd/webrtc"
|
||||||
"github.com/AlexxIT/go2rtc/pkg/streamer"
|
"github.com/AlexxIT/go2rtc/pkg/streamer"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -90,7 +90,13 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
url := r.FormValue("url")
|
src := r.FormValue("url")
|
||||||
|
src, err := url.QueryUnescape(src)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("[api.hass] query unescape")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
str := r.FormValue("sdp64")
|
str := r.FormValue("sdp64")
|
||||||
|
|
||||||
offer, err := base64.StdEncoding.DecodeString(str)
|
offer, err := base64.StdEncoding.DecodeString(str)
|
||||||
@@ -99,16 +105,20 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fixme
|
// check if stream links to our rtsp server
|
||||||
if strings.HasPrefix(url, "rtsp://") {
|
if strings.HasPrefix(src, "rtsp://") {
|
||||||
port := ":" + rtsp.Port + "/"
|
i := strings.IndexByte(src[7:], '/')
|
||||||
i := strings.Index(url, port)
|
if i > 0 && streams.Has(src[8+i:]) {
|
||||||
if i > 0 {
|
src = src[8+i:]
|
||||||
url = url[i+len(port):]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stream := streams.Get(url)
|
stream := streams.Get(src)
|
||||||
|
if stream == nil {
|
||||||
|
log.Error().Str("url", src).Msg("[api.hass] unsupported source")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
str, err = webrtc.ExchangeSDP(stream, string(offer), r.UserAgent())
|
str, err = webrtc.ExchangeSDP(stream, string(offer), r.UserAgent())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("[api.hass] exchange SDP")
|
log.Error().Err(err).Msg("[api.hass] exchange SDP")
|
||||||
|
|||||||
+13
-8
@@ -24,19 +24,24 @@ func Init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Get(name string) *Stream {
|
func Get(src string) *Stream {
|
||||||
if stream, ok := streams[name]; ok {
|
if stream, ok := streams[src]; ok {
|
||||||
return stream
|
return stream
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if HasProducer(name) {
|
if !HasProducer(src) {
|
||||||
log.Info().Str("url", name).Msg("[streams] create new stream")
|
return nil
|
||||||
stream := NewStream(name)
|
|
||||||
streams[name] = stream
|
|
||||||
return stream
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
log.Info().Str("url", src).Msg("[streams] create new stream")
|
||||||
|
stream := NewStream(src)
|
||||||
|
streams[src] = stream
|
||||||
|
return stream
|
||||||
|
}
|
||||||
|
|
||||||
|
func Has(src string) bool {
|
||||||
|
return streams[src] != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(name string, source interface{}) {
|
func New(name string, source interface{}) {
|
||||||
|
|||||||
Reference in New Issue
Block a user