add support for other protocol. add user/pass for media uri

This commit is contained in:
程广 2024-11-08 00:17:42 +08:00
parent afe338f3d8
commit 69da67139f
2 changed files with 24 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import (
"errors" "errors"
"net" "net"
"net/http" "net/http"
"net/url"
"strings" "strings"
"time" "time"
@ -187,7 +188,13 @@ func (d *Device) GetReplayUri(token string, stream onvifmodel.StreamSetup) (stri
} }
// 返回获取到的URI // 返回获取到的URI
return string(resp.Uri), nil // return string(resp.Uri), nil
if err != nil {
return "", err
}
urlobj, _ := url.Parse(string(resp.Uri))
urlobj.User = url.UserPassword(d.Username, d.Password)
return urlobj.String(), nil
} }
func (d *Device) GetStreamUri(stream onvifmodel.StreamSetup, profileToken string) (string, error) { func (d *Device) GetStreamUri(stream onvifmodel.StreamSetup, profileToken string) (string, error) {
@ -201,7 +208,13 @@ func (d *Device) GetStreamUri(stream onvifmodel.StreamSetup, profileToken string
} }
resp, rerr := media_sdk.Call_GetStreamUri(d.ctx, d.device, getStreamUri) resp, rerr := media_sdk.Call_GetStreamUri(d.ctx, d.device, getStreamUri)
// resp, rerr := media_sdk.Call_GetStreamUri(d.ctx, d.device, media.GetStreamUri{}) // resp, rerr := media_sdk.Call_GetStreamUri(d.ctx, d.device, media.GetStreamUri{})
return string(resp.MediaUri.Uri), rerr // return string(resp.MediaUri.Uri), rerr
if rerr != nil {
return "", rerr
}
urlobj, _ := url.Parse(string(resp.MediaUri.Uri))
urlobj.User = url.UserPassword(d.Username, d.Password)
return urlobj.String(), nil
} }
func (d *Device) GetStreamUriTcp(profileToken string) (string, error) { func (d *Device) GetStreamUriTcp(profileToken string) (string, error) {

View File

@ -167,7 +167,15 @@ func NewDevice(params DeviceParams) (*Device, error) {
dev := new(Device) dev := new(Device)
dev.params = params dev.params = params
dev.endpoints = make(map[string]string) dev.endpoints = make(map[string]string)
dev.addEndpoint("Device", "http://"+dev.params.Xaddr+"/onvif/device_service") var urlstr string
if strings.HasPrefix(params.Xaddr, "http") {
urlObj, _ := url.Parse(params.Xaddr)
urlObj.Path = "/onvif/device_service"
urlstr = urlObj.String()
} else {
urlstr = "http://" + params.Xaddr + "/onvif/device_service"
}
dev.addEndpoint("Device", urlstr)
if dev.params.HttpClient == nil { if dev.params.HttpClient == nil {
dev.params.HttpClient = new(http.Client) dev.params.HttpClient = new(http.Client)