Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

68 lines
1.1 KiB

package conf
import (
"encoding/json"
"fmt"
"github.com/aler9/gortsplib/v2"
)
// SourceProtocol is the sourceProtocol parameter.
type SourceProtocol struct {
*gortsplib.Transport
}
// MarshalJSON implements json.Marshaler.
func (d SourceProtocol) MarshalJSON() ([]byte, error) {
var out string
if d.Transport == nil {
out = "automatic"
} else {
switch *d.Transport {
case gortsplib.TransportUDP:
out = "udp"
case gortsplib.TransportUDPMulticast:
out = "multicast"
default:
out = "tcp"
}
}
return json.Marshal(out)
}
// UnmarshalJSON implements json.Unmarshaler.
func (d *SourceProtocol) UnmarshalJSON(b []byte) error {
var in string
if err := json.Unmarshal(b, &in); err != nil {
return err
}
switch in {
case "udp":
v := gortsplib.TransportUDP
d.Transport = &v
case "multicast":
v := gortsplib.TransportUDPMulticast
d.Transport = &v
case "tcp":
v := gortsplib.TransportTCP
d.Transport = &v
case "automatic":
default:
return fmt.Errorf("invalid protocol '%s'", in)
}
return nil
}
func (d *SourceProtocol) unmarshalEnv(s string) error {
return d.UnmarshalJSON([]byte(`"` + s + `"`))
}