Add support TCP MPEG-TS source

This commit is contained in:
Alexey Khit
2023-03-26 17:29:59 +03:00
parent 15e205cc01
commit 8fde2b6fe5
2 changed files with 37 additions and 0 deletions

35
cmd/tcp/init.go Normal file
View File

@@ -0,0 +1,35 @@
package tcp
import (
"github.com/AlexxIT/go2rtc/cmd/streams"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/mpegts"
"net"
"net/http"
"net/url"
"time"
)
func Init() {
streams.HandleFunc("tcp", handle)
}
func handle(rawURL string) (core.Producer, error) {
u, err := url.Parse(rawURL)
if err != nil {
return nil, err
}
conn, err := net.DialTimeout("tcp", u.Host, time.Second*3)
if err != nil {
return nil, err
}
req := &http.Request{URL: u}
res := &http.Response{Body: conn, Request: req}
client := mpegts.NewClient(res)
if err := client.Handle(); err != nil {
return nil, err
}
return client, nil
}