2021-09-27 08:36:28 +00:00
|
|
|
package conf
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
|
2023-08-26 16:54:28 +00:00
|
|
|
"github.com/bluenviron/gortsplib/v4"
|
2021-09-27 08:36:28 +00:00
|
|
|
)
|
|
|
|
|
2023-11-04 10:12:22 +00:00
|
|
|
// RTSPTransport is the rtspTransport parameter.
|
|
|
|
type RTSPTransport struct {
|
2021-10-22 16:41:10 +00:00
|
|
|
*gortsplib.Transport
|
2021-09-27 08:36:28 +00:00
|
|
|
}
|
|
|
|
|
2022-06-21 11:41:15 +00:00
|
|
|
// MarshalJSON implements json.Marshaler.
|
2023-11-04 10:12:22 +00:00
|
|
|
func (d RTSPTransport) MarshalJSON() ([]byte, error) {
|
2021-09-27 08:36:28 +00:00
|
|
|
var out string
|
|
|
|
|
2021-10-22 16:41:10 +00:00
|
|
|
if d.Transport == nil {
|
2021-09-27 08:36:28 +00:00
|
|
|
out = "automatic"
|
|
|
|
} else {
|
2021-10-22 16:41:10 +00:00
|
|
|
switch *d.Transport {
|
|
|
|
case gortsplib.TransportUDP:
|
2021-09-27 08:36:28 +00:00
|
|
|
out = "udp"
|
|
|
|
|
2021-10-22 16:41:10 +00:00
|
|
|
case gortsplib.TransportUDPMulticast:
|
2021-09-27 08:36:28 +00:00
|
|
|
out = "multicast"
|
|
|
|
|
2023-03-31 14:22:08 +00:00
|
|
|
default:
|
2024-03-04 13:20:34 +00:00
|
|
|
out = "tcp"
|
2021-09-27 08:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return json.Marshal(out)
|
|
|
|
}
|
|
|
|
|
2022-06-21 11:41:15 +00:00
|
|
|
// UnmarshalJSON implements json.Unmarshaler.
|
2023-11-04 10:12:22 +00:00
|
|
|
func (d *RTSPTransport) UnmarshalJSON(b []byte) error {
|
2021-09-27 08:36:28 +00:00
|
|
|
var in string
|
|
|
|
if err := json.Unmarshal(b, &in); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
switch in {
|
|
|
|
case "udp":
|
2021-10-22 16:41:10 +00:00
|
|
|
v := gortsplib.TransportUDP
|
|
|
|
d.Transport = &v
|
2021-09-27 08:36:28 +00:00
|
|
|
|
|
|
|
case "multicast":
|
2021-10-22 16:41:10 +00:00
|
|
|
v := gortsplib.TransportUDPMulticast
|
|
|
|
d.Transport = &v
|
2021-09-27 08:36:28 +00:00
|
|
|
|
|
|
|
case "tcp":
|
2021-10-22 16:41:10 +00:00
|
|
|
v := gortsplib.TransportTCP
|
|
|
|
d.Transport = &v
|
2021-09-27 08:36:28 +00:00
|
|
|
|
|
|
|
case "automatic":
|
2023-03-31 14:22:08 +00:00
|
|
|
d.Transport = nil
|
2021-09-27 08:36:28 +00:00
|
|
|
|
|
|
|
default:
|
2021-09-27 08:43:48 +00:00
|
|
|
return fmt.Errorf("invalid protocol '%s'", in)
|
2021-09-27 08:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-10-11 09:46:40 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
// UnmarshalEnv implements env.Unmarshaler.
|
2023-11-04 10:12:22 +00:00
|
|
|
func (d *RTSPTransport) UnmarshalEnv(_ string, v string) error {
|
2023-10-07 21:32:15 +00:00
|
|
|
return d.UnmarshalJSON([]byte(`"` + v + `"`))
|
2021-10-11 09:46:40 +00:00
|
|
|
}
|