From b2029d10047fc36e7ab9b61d17404697dc74dbae Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Sat, 11 Feb 2023 12:45:46 +0300 Subject: [PATCH] Support channels for DVRIP --- pkg/dvrip/client.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pkg/dvrip/client.go b/pkg/dvrip/client.go index 9f2a4e6d..e8913245 100644 --- a/pkg/dvrip/client.go +++ b/pkg/dvrip/client.go @@ -66,11 +66,25 @@ func (c *Client) Dial() (err error) { c.reader = bufio.NewReader(c.conn) - c.stream = u.Path - if c.stream == "" { - c.stream = "Main" + query := u.Query() + channel := query.Get("channel") + if channel == "" { + channel = "0" } + subtype := query.Get("subtype") + switch subtype { + case "", "0": + subtype = "Main" + case "1": + subtype = "Extra1" + } + + c.stream = fmt.Sprintf( + `{"Channel":%s,"CombinMode":"NONE","StreamType":"%s","TransMode":"TCP"}`, + channel, subtype, + ) + if u.User != nil { pass, _ := u.User.Password() return c.Login(u.User.Username(), pass) @@ -94,8 +108,7 @@ func (c *Client) Login(user, pass string) (err error) { } func (c *Client) Play() (err error) { - format := `{"Name":"OPMonitor","SessionID":"0x%08X","OPMonitor":{"Action":"%s","Parameter":` + - `{"Channel":0,"CombinMode":"NONE","StreamType":"%s","TransMode":"TCP"}}}` + format := `{"Name":"OPMonitor","SessionID":"0x%08X","OPMonitor":{"Action":"%s","Parameter":%s}}` data := fmt.Sprintf(format, c.session, "Claim", c.stream) if err = c.Request(OPMonitorClaim, data); err != nil {