Add stream validation pt2 -- need to add unit tests

This commit is contained in:
Brendan Le Glaunec
2018-07-22 17:03:10 +02:00
committed by Brendan LE GLAUNEC
parent 1ea9850842
commit 055dc69158
3 changed files with 18 additions and 3 deletions
+3 -1
View File
@@ -163,6 +163,8 @@ func validateStream(c Curler, stream Stream, timeout time.Duration, enableLogs b
// Set custom timeout // Set custom timeout
c.Setopt(curl.OPT_TIMEOUT_MS, int(timeout/time.Millisecond)) c.Setopt(curl.OPT_TIMEOUT_MS, int(timeout/time.Millisecond))
c.Setopt(curl.OPT_RTSP_TRANSPORT, "RTP/AVP;unicast;client_port=33332-33333")
// Perform the request // Perform the request
err := c.Perform() err := c.Perform()
if err != nil { if err != nil {
@@ -186,7 +188,7 @@ func validateStream(c Curler, stream Stream, timeout time.Duration, enableLogs b
// ValidateStreams tries to setup the stream to validate whether or not it is available // ValidateStreams tries to setup the stream to validate whether or not it is available
func ValidateStreams(c Curler, targets []Stream, timeout time.Duration, log bool) ([]Stream, error) { func ValidateStreams(c Curler, targets []Stream, timeout time.Duration, log bool) ([]Stream, error) {
for idx, target := range targets { for idx, target := range targets {
targets[idx].StreamAvailable = validateStream(c, target, timeout, log) targets[idx].Available = validateStream(c, target, timeout, log)
} }
return targets, nil return targets, nil
+14 -1
View File
@@ -151,6 +151,12 @@ func main() {
} }
} }
updateSpinner(w, "Found "+fmt.Sprint(len(streams))+" streams. Validating their availability...", options.EnableLogs)
streams, err = cmrdr.ValidateStreams(c, streams, time.Duration(options.Timeout)*time.Millisecond, options.EnableLogs)
if err != nil && len(streams) > 0 {
printErr(err)
}
clearOutput(w, options.EnableLogs) clearOutput(w, options.EnableLogs)
prettyPrint(streams) prettyPrint(streams)
} }
@@ -166,7 +172,7 @@ func prettyPrint(streams []cmrdr.Stream) {
if len(streams) > 0 { if len(streams) > 0 {
for _, stream := range streams { for _, stream := range streams {
if stream.CredentialsFound && stream.RouteFound { if stream.CredentialsFound && stream.RouteFound && stream.Available {
fmt.Printf("%s\tDevice RTSP URL:\t%s\n", green("\xE2\x96\xB6"), blue(cmrdr.GetCameraRTSPURL(stream))) fmt.Printf("%s\tDevice RTSP URL:\t%s\n", green("\xE2\x96\xB6"), blue(cmrdr.GetCameraRTSPURL(stream)))
success++ success++
} else { } else {
@@ -174,6 +180,13 @@ func prettyPrint(streams []cmrdr.Stream) {
} }
fmt.Printf("\tDevice model:\t\t%s\n\n", stream.Device) fmt.Printf("\tDevice model:\t\t%s\n\n", stream.Device)
if stream.Available {
fmt.Printf("\tAvailable:\t\t%s\n", green("yes"))
} else {
fmt.Printf("\tAvailable:\t\t%s\n", red("no"))
}
fmt.Printf("\tIP address:\t\t%s\n", stream.Address) fmt.Printf("\tIP address:\t\t%s\n", stream.Address)
fmt.Printf("\tRTSP port:\t\t%d\n", stream.Port) fmt.Printf("\tRTSP port:\t\t%d\n", stream.Port)
if stream.CredentialsFound { if stream.CredentialsFound {
+1 -1
View File
@@ -13,7 +13,7 @@ type Stream struct {
CredentialsFound bool `json:"credentials_found"` CredentialsFound bool `json:"credentials_found"`
RouteFound bool `json:"route_found"` RouteFound bool `json:"route_found"`
StreamAvailable bool `json:"stream_available"` Available bool `json:"available"`
} }
// Credentials is a map of credentials // Credentials is a map of credentials