From 57eae89cc5522a738a08a16f8299fd7a4e644843 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Mon, 31 Aug 2020 09:27:23 +0200 Subject: [PATCH] HeaderTransport: add IsUdp() and IsTcp() --- header-transport.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/header-transport.go b/header-transport.go index c925b057..d9a0f3d6 100644 --- a/header-transport.go +++ b/header-transport.go @@ -27,6 +27,23 @@ func ReadHeaderTransport(v HeaderValue) (HeaderTransport, error) { return ht, nil } +// IsUdp check whether the header contains the UDP protocol. +func (ht HeaderTransport) IsUdp() bool { + if _, ok := ht["RTP/AVP"]; ok { + return true + } + if _, ok := ht["RTP/AVP/UDP"]; ok { + return true + } + return false +} + +// IsTcp check whether the header contains the TCP protocol. +func (ht HeaderTransport) IsTcp() bool { + _, ok := ht["RTP/AVP/TCP"] + return ok +} + // Value gets a value from the header. func (ht HeaderTransport) Value(key string) string { prefix := key + "=" @@ -38,7 +55,7 @@ func (ht HeaderTransport) Value(key string) string { return "" } -// Ports gets a given header value and parses its ports. +// Ports gets a value from the header and parses its ports. func (ht HeaderTransport) Ports(key string) (int, int) { val := ht.Value(key) if val == "" {