2021-09-27 08:36:28 +00:00
|
|
|
package conf
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Protocol is a RTSP stream protocol.
|
|
|
|
type Protocol int
|
|
|
|
|
|
|
|
// supported RTSP protocols.
|
|
|
|
const (
|
|
|
|
ProtocolUDP Protocol = iota
|
|
|
|
ProtocolMulticast
|
|
|
|
ProtocolTCP
|
|
|
|
)
|
|
|
|
|
|
|
|
// Protocols is the protocols parameter.
|
|
|
|
type Protocols map[Protocol]struct{}
|
|
|
|
|
|
|
|
// MarshalJSON marshals a Protocols into JSON.
|
|
|
|
func (d Protocols) MarshalJSON() ([]byte, error) {
|
|
|
|
out := make([]string, len(d))
|
|
|
|
|
|
|
|
for p := range d {
|
|
|
|
var v string
|
|
|
|
|
|
|
|
switch p {
|
|
|
|
case ProtocolUDP:
|
|
|
|
v = "udp"
|
|
|
|
|
|
|
|
case ProtocolMulticast:
|
|
|
|
v = "multicast"
|
|
|
|
|
|
|
|
default:
|
|
|
|
v = "tcp"
|
|
|
|
}
|
|
|
|
|
|
|
|
out = append(out, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
return json.Marshal(out)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON unmarshals a Protocols from JSON.
|
|
|
|
func (d *Protocols) UnmarshalJSON(b []byte) error {
|
|
|
|
var in []string
|
|
|
|
if err := json.Unmarshal(b, &in); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*d = make(Protocols)
|
|
|
|
|
|
|
|
for _, proto := range in {
|
|
|
|
switch proto {
|
|
|
|
case "udp":
|
|
|
|
(*d)[ProtocolUDP] = struct{}{}
|
|
|
|
|
|
|
|
case "multicast":
|
|
|
|
(*d)[ProtocolMulticast] = struct{}{}
|
|
|
|
|
|
|
|
case "tcp":
|
|
|
|
(*d)[ProtocolTCP] = struct{}{}
|
|
|
|
|
|
|
|
default:
|
2021-09-27 08:43:48 +00:00
|
|
|
return fmt.Errorf("invalid protocol: %s", proto)
|
2021-09-27 08:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|