golanggohlsrtmpwebrtcmedia-serverobs-studiortcprtmp-proxyrtmp-serverrtprtsprtsp-proxyrtsp-relayrtsp-serversrtstreamingwebrtc-proxy
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.
64 lines
1.1 KiB
64 lines
1.1 KiB
package conf |
|
|
|
import ( |
|
"encoding/json" |
|
"fmt" |
|
|
|
"github.com/aler9/gortsplib" |
|
) |
|
|
|
// SourceProtocol is the sourceProtocol parameter. |
|
type SourceProtocol struct { |
|
*gortsplib.ClientProtocol |
|
} |
|
|
|
// MarshalJSON marshals a SourceProtocol into JSON. |
|
func (d SourceProtocol) MarshalJSON() ([]byte, error) { |
|
var out string |
|
|
|
if d.ClientProtocol == nil { |
|
out = "automatic" |
|
} else { |
|
switch *d.ClientProtocol { |
|
case gortsplib.ClientProtocolUDP: |
|
out = "udp" |
|
|
|
case gortsplib.ClientProtocolMulticast: |
|
out = "multicast" |
|
|
|
default: |
|
out = "tcp" |
|
} |
|
} |
|
|
|
return json.Marshal(out) |
|
} |
|
|
|
// UnmarshalJSON unmarshals a SourceProtocol from JSON. |
|
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.ClientProtocolUDP |
|
d.ClientProtocol = &v |
|
|
|
case "multicast": |
|
v := gortsplib.ClientProtocolMulticast |
|
d.ClientProtocol = &v |
|
|
|
case "tcp": |
|
v := gortsplib.ClientProtocolTCP |
|
d.ClientProtocol = &v |
|
|
|
case "automatic": |
|
|
|
default: |
|
return fmt.Errorf("invalid protocol '%s'", in) |
|
} |
|
|
|
return nil |
|
}
|
|
|