Skip to content

Commit

Permalink
Add media get-stream-uri command.
Browse files Browse the repository at this point in the history
  • Loading branch information
osery committed Sep 29, 2022
1 parent 70f9a2a commit c27c4b4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/gonvif/media/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func init() {
getAnalyticsConfigurations,
getProfiles,
getSnapshotURI,
getStreamURI,
getVideoSourceConfigurations,
)
}
Expand Down
43 changes: 43 additions & 0 deletions cmd/gonvif/media/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 nil
}
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)
}

0 comments on commit c27c4b4

Please sign in to comment.