Files
Strix/pkg/tester/source.go
T
eduard256 44ab0651cb Add DVRIP protocol support
- Register dvrip stream handler using go2rtc pkg/dvrip
- Add default port 34567 for dvrip scheme in URL builder
2026-04-03 21:01:39 +00:00

77 lines
2.1 KiB
Go

package tester
import (
"fmt"
"strings"
"github.com/AlexxIT/go2rtc/pkg/bubble"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/dvrip"
"github.com/AlexxIT/go2rtc/pkg/rtmp"
"github.com/AlexxIT/go2rtc/pkg/rtsp"
)
// SourceHandler tests stream URL, returns Producer or error
type SourceHandler func(rawURL string) (core.Producer, error)
var handlers = map[string]SourceHandler{}
func RegisterSource(scheme string, handler SourceHandler) {
handlers[scheme] = handler
}
func GetHandler(rawURL string) SourceHandler {
if i := strings.IndexByte(rawURL, ':'); i > 0 {
return handlers[rawURL[:i]]
}
return nil
}
func init() {
RegisterSource("rtsp", rtspHandler)
RegisterSource("rtsps", rtspHandler)
RegisterSource("rtspx", rtspHandler)
RegisterSource("bubble", bubbleHandler)
RegisterSource("rtmp", rtmpHandler)
RegisterSource("rtmps", rtmpHandler)
RegisterSource("rtmpx", rtmpHandler)
RegisterSource("dvrip", dvripHandler)
}
// dvripHandler -- Dial handles TCP connect, Sofia MD5 auth, and OPMonitor stream negotiation.
// ex. "dvrip://admin:pass@192.168.1.100:34567?channel=0&subtype=0"
func dvripHandler(rawURL string) (core.Producer, error) {
return dvrip.Dial(rawURL)
}
// bubbleHandler -- Dial handles TCP connect, HTTP handshake, XML parsing, and auth.
// ex. "bubble://admin:pass@192.168.1.100:80/bubble/live?ch=0&stream=0"
func bubbleHandler(rawURL string) (core.Producer, error) {
return bubble.Dial(rawURL)
}
// rtmpHandler -- DialPlay handles TCP connect, RTMP handshake, and play command.
// ex. "rtmp://admin:pass@192.168.1.100:1935/bcs/channel0_main.bcs?channel=0&stream=0"
func rtmpHandler(rawURL string) (core.Producer, error) {
return rtmp.DialPlay(rawURL)
}
// rtspHandler -- Dial + Describe. Proves: port open, RTSP responds, auth OK, SDP received.
func rtspHandler(rawURL string) (core.Producer, error) {
rawURL, _, _ = strings.Cut(rawURL, "#")
conn := rtsp.NewClient(rawURL)
conn.Backchannel = false
if err := conn.Dial(); err != nil {
return nil, fmt.Errorf("rtsp: dial: %w", err)
}
if err := conn.Describe(); err != nil {
_ = conn.Stop()
return nil, fmt.Errorf("rtsp: describe: %w", err)
}
return conn, nil
}