Skip to content

Commit

Permalink
Generate Media10 client.
Browse files Browse the repository at this point in the history
  • Loading branch information
osery committed Nov 4, 2022
1 parent 9339043 commit bc34702
Show file tree
Hide file tree
Showing 17 changed files with 3,298 additions and 33 deletions.
1 change: 1 addition & 0 deletions cmd/gonvif/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
_ "github.com/eyetowers/gonvif/cmd/gonvif/device"
_ "github.com/eyetowers/gonvif/cmd/gonvif/imaging"
_ "github.com/eyetowers/gonvif/cmd/gonvif/media"
_ "github.com/eyetowers/gonvif/cmd/gonvif/media2"
_ "github.com/eyetowers/gonvif/cmd/gonvif/ptz"
"github.com/eyetowers/gonvif/cmd/gonvif/root"
)
Expand Down
9 changes: 3 additions & 6 deletions cmd/gonvif/media/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/spf13/cobra"

"github.com/eyetowers/gonvif/cmd/gonvif/root"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver20/media/wsdl"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver10/media/wsdl"
"github.com/eyetowers/gonvif/pkg/gonvif"
)

Expand All @@ -17,20 +17,17 @@ func init() {
root.RequireAuthFlags(cmd)
root.Command.AddCommand(cmd)
cmd.AddCommand(
getAnalyticsConfigurations,
getProfiles,
getSnapshotURI,
getStreamURI,
getVideoEncoderConfigurations,
getVideoSourceConfigurations,
setSynchronizationPoint,
)
}

func ServiceClient(url, username, password string, verbose bool) (wsdl.Media2, error) {
func ServiceClient(url, username, password string, verbose bool) (wsdl.Media, error) {
onvif, err := gonvif.New(url, username, password, verbose)
if err != nil {
return nil, err
}
return onvif.Media2()
return onvif.Media()
}
18 changes: 4 additions & 14 deletions cmd/gonvif/media/get-profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import (
"github.com/spf13/cobra"

"github.com/eyetowers/gonvif/cmd/gonvif/root"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver20/media/wsdl"
)

var (
types []string
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver10/media/wsdl"
)

var getProfiles = &cobra.Command{
Expand All @@ -20,18 +16,12 @@ var getProfiles = &cobra.Command{
if err != nil {
return err
}
return runGetProfiles(client, types)
return runGetProfiles(client)
},
}

func init() {
getProfiles.Flags().StringArrayVarP(&types, "types", "t", []string{"All"}, "Types of profile configurations to include")
}

func runGetProfiles(client wsdl.Media2, types []string) error {
resp, err := client.GetProfiles(&wsdl.GetProfiles{
Type: types,
})
func runGetProfiles(client wsdl.Media) error {
resp, err := client.GetProfiles(&wsdl.GetProfiles{})
if err != nil {
return err
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/gonvif/media/get-snapshot-uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import (
"github.com/spf13/cobra"

"github.com/eyetowers/gonvif/cmd/gonvif/root"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver20/media/wsdl"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver10/media/wsdl"
"github.com/eyetowers/gonvif/pkg/util"
)

var (
profileToken string
)

var getSnapshotURI = &cobra.Command{
Use: "get-snapshot-uri",
Short: "Get Onvif device media snapshot URI",
Expand All @@ -26,7 +30,7 @@ func init() {
root.MustMarkFlagRequired(getSnapshotURI, "profile_token")
}

func runGetSnapshotURI(client wsdl.Media2, profileToken string) error {
func runGetSnapshotURI(client wsdl.Media, profileToken string) error {
resp, err := client.GetSnapshotUri(&wsdl.GetSnapshotUri{
ProfileToken: util.NewReferenceTokenPtr(profileToken),
})
Expand Down
20 changes: 15 additions & 5 deletions cmd/gonvif/media/get-stream-uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"github.com/spf13/cobra"

"github.com/eyetowers/gonvif/cmd/gonvif/root"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver20/media/wsdl"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver10/media/wsdl"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver10/schema"
"github.com/eyetowers/gonvif/pkg/util"
)

var (
protocol string
stream string
)

var getStreamURI = &cobra.Command{
Expand All @@ -21,20 +23,28 @@ var getStreamURI = &cobra.Command{
if err != nil {
return err
}
return runGetStreamURI(client, profileToken, protocol)
return runGetStreamURI(client, profileToken, protocol, stream)
},
}

func init() {
getStreamURI.Flags().StringVarP(&profileToken, "profile_token", "t", "", "The ProfileToken element indicates the media profile to use and will define the configuration of the content of the stream.")
getStreamURI.Flags().StringVarP(&protocol, "protocol", "r", "RTSP", "Defines the network protocol for streaming (RtspUnicast, RtspMulticast, RTSP, RtspOverHttp).")
getStreamURI.Flags().StringVarP(&protocol, "protocol", "r", "RTSP", "Defines the network protocol for streaming (UDP, TCP, RTSP, HTTP).")
getStreamURI.Flags().StringVarP(&stream, "stream", "s", "RTP-Unicast", "Defines the stream type for streaming (RTP-Unicast, RTP-Multicast).")
root.MustMarkFlagRequired(getStreamURI, "profile_token")
}

func runGetStreamURI(client wsdl.Media2, profileToken string, protocol string) error {
func runGetStreamURI(client wsdl.Media, profileToken string, protocol string, stream string) error {
p := schema.TransportProtocol(protocol)
s := schema.StreamType(stream)
resp, err := client.GetStreamUri(&wsdl.GetStreamUri{
ProfileToken: util.NewReferenceTokenPtr(profileToken),
Protocol: protocol,
StreamSetup: &schema.StreamSetup{
Stream: &s,
Transport: &schema.Transport{
Protocol: &p,
},
},
})
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/gonvif/media/set-synchronization-point.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/spf13/cobra"

"github.com/eyetowers/gonvif/cmd/gonvif/root"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver20/media/wsdl"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver10/media/wsdl"
"github.com/eyetowers/gonvif/pkg/util"
)

Expand All @@ -26,7 +26,7 @@ func init() {
root.MustMarkFlagRequired(setSynchronizationPoint, "profile_token")
}

func runSetSynchronizationPoint(client wsdl.Media2, profileToken string) error {
func runSetSynchronizationPoint(client wsdl.Media, profileToken string) error {
resp, err := client.SetSynchronizationPoint(&wsdl.SetSynchronizationPoint{
ProfileToken: util.NewReferenceTokenPtr(profileToken),
})
Expand Down
36 changes: 36 additions & 0 deletions cmd/gonvif/media2/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package media

import (
"github.com/spf13/cobra"

"github.com/eyetowers/gonvif/cmd/gonvif/root"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver20/media/wsdl"
"github.com/eyetowers/gonvif/pkg/gonvif"
)

var cmd = &cobra.Command{
Use: "media2",
Short: "Manipulate Onvif device media features.",
}

func init() {
root.RequireAuthFlags(cmd)
root.Command.AddCommand(cmd)
cmd.AddCommand(
getAnalyticsConfigurations,
getProfiles,
getSnapshotURI,
getStreamURI,
getVideoEncoderConfigurations,
getVideoSourceConfigurations,
setSynchronizationPoint,
)
}

func ServiceClient(url, username, password string, verbose bool) (wsdl.Media2, error) {
onvif, err := gonvif.New(url, username, password, verbose)
if err != nil {
return nil, err
}
return onvif.Media2()
}
39 changes: 39 additions & 0 deletions cmd/gonvif/media2/get-profiles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package media

import (
"github.com/spf13/cobra"

"github.com/eyetowers/gonvif/cmd/gonvif/root"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver20/media/wsdl"
)

var (
types []string
)

var getProfiles = &cobra.Command{
Use: "get-profiles",
Short: "List Onvif device media profiles",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := ServiceClient(root.URL, root.Username, root.Password, root.Verbose)
if err != nil {
return err
}
return runGetProfiles(client, types)
},
}

func init() {
getProfiles.Flags().StringArrayVarP(&types, "types", "t", []string{"All"}, "Types of profile configurations to include")
}

func runGetProfiles(client wsdl.Media2, types []string) error {
resp, err := client.GetProfiles(&wsdl.GetProfiles{
Type: types,
})
if err != nil {
return err
}
return root.OutputJSON(resp)
}
37 changes: 37 additions & 0 deletions cmd/gonvif/media2/get-snapshot-uri.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package media

import (
"github.com/spf13/cobra"

"github.com/eyetowers/gonvif/cmd/gonvif/root"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver20/media/wsdl"
"github.com/eyetowers/gonvif/pkg/util"
)

var getSnapshotURI = &cobra.Command{
Use: "get-snapshot-uri",
Short: "Get Onvif device media snapshot URI",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := ServiceClient(root.URL, root.Username, root.Password, root.Verbose)
if err != nil {
return err
}
return runGetSnapshotURI(client, profileToken)
},
}

func init() {
getSnapshotURI.Flags().StringVarP(&profileToken, "profile_token", "t", "", "The ProfileToken element indicates the media profile to use and will define the source and dimensions of the snapshot.")
root.MustMarkFlagRequired(getSnapshotURI, "profile_token")
}

func runGetSnapshotURI(client wsdl.Media2, profileToken string) error {
resp, err := client.GetSnapshotUri(&wsdl.GetSnapshotUri{
ProfileToken: util.NewReferenceTokenPtr(profileToken),
})
if err != nil {
return err
}
return root.OutputJSON(resp)
}
43 changes: 43 additions & 0 deletions cmd/gonvif/media2/get-stream-uri.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package media

import (
"github.com/spf13/cobra"

"github.com/eyetowers/gonvif/cmd/gonvif/root"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver20/media/wsdl"
"github.com/eyetowers/gonvif/pkg/util"
)

var (
protocol string
)

var getStreamURI = &cobra.Command{
Use: "get-stream-uri",
Short: "Get Onvif device media stream URI",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := ServiceClient(root.URL, root.Username, root.Password, root.Verbose)
if err != nil {
return err
}
return runGetStreamURI(client, profileToken, protocol)
},
}

func init() {
getStreamURI.Flags().StringVarP(&profileToken, "profile_token", "t", "", "The ProfileToken element indicates the media profile to use and will define the configuration of the content of the stream.")
getStreamURI.Flags().StringVarP(&protocol, "protocol", "r", "RTSP", "Defines the network protocol for streaming (RtspUnicast, RtspMulticast, RTSP, RtspOverHttp).")
root.MustMarkFlagRequired(getStreamURI, "profile_token")
}

func runGetStreamURI(client wsdl.Media2, profileToken string, protocol string) error {
resp, err := client.GetStreamUri(&wsdl.GetStreamUri{
ProfileToken: util.NewReferenceTokenPtr(profileToken),
Protocol: protocol,
})
if err != nil {
return err
}
return root.OutputJSON(resp)
}
37 changes: 37 additions & 0 deletions cmd/gonvif/media2/set-synchronization-point.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package media

import (
"github.com/spf13/cobra"

"github.com/eyetowers/gonvif/cmd/gonvif/root"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver20/media/wsdl"
"github.com/eyetowers/gonvif/pkg/util"
)

var setSynchronizationPoint = &cobra.Command{
Use: "set-synchronization-point",
Short: "Request Onvif device to insert a key frame into all streams for the given profile",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := ServiceClient(root.URL, root.Username, root.Password, root.Verbose)
if err != nil {
return err
}
return runSetSynchronizationPoint(client, profileToken)
},
}

func init() {
setSynchronizationPoint.Flags().StringVarP(&profileToken, "profile_token", "t", "", "The ProfileToken element indicates the media profile to use and will define the source and dimensions of the snapshot.")
root.MustMarkFlagRequired(setSynchronizationPoint, "profile_token")
}

func runSetSynchronizationPoint(client wsdl.Media2, profileToken string) error {
resp, err := client.SetSynchronizationPoint(&wsdl.SetSynchronizationPoint{
ProfileToken: util.NewReferenceTokenPtr(profileToken),
})
if err != nil {
return err
}
return root.OutputJSON(resp)
}
Loading

0 comments on commit bc34702

Please sign in to comment.