From 412e2c76429343d530cd3394f26d225d1a78ae52 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Mon, 20 Jan 2020 12:53:06 +0100 Subject: [PATCH] move transportHeader into gortsplib --- Makefile | 4 ++-- client.go | 53 ++++------------------------------------------------- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 9 insertions(+), 54 deletions(-) diff --git a/Makefile b/Makefile index 49d18e05..5ac94933 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ help: mod-tidy: docker run --rm -it -v $(PWD):/s $(BASE_IMAGE) \ - sh -c "apk add git && cd /s && go get && go mod tidy" + sh -c "apk add git && cd /s && GOPROXY=direct go get && GOPROXY=direct go mod tidy" format: docker run --rm -it -v $(PWD):/s $(BASE_IMAGE) \ @@ -30,7 +30,7 @@ WORKDIR /s COPY go.mod go.sum ./ RUN go mod download COPY . ./ -RUN go build -o /out . +RUN GOPROXY=direct go build -o /out . endef export DOCKERFILE_RUN diff --git a/client.go b/client.go index 720e03f9..495b6168 100644 --- a/client.go +++ b/client.go @@ -6,7 +6,6 @@ import ( "log" "net" "net/url" - "strconv" "strings" "github.com/aler9/gortsplib" @@ -27,50 +26,6 @@ func trackToInterleavedChannel(id int, flow trackFlow) int { return (id * 2) + 1 } -type transportHeader map[string]struct{} - -func newTransportHeader(in string) transportHeader { - th := make(map[string]struct{}) - for _, t := range strings.Split(in, ";") { - th[t] = struct{}{} - } - return th -} - -func (th transportHeader) getKeyValue(key string) string { - prefix := key + "=" - for t := range th { - if strings.HasPrefix(t, prefix) { - return t[len(prefix):] - } - } - return "" -} - -func (th transportHeader) getClientPorts() (int, int) { - val := th.getKeyValue("client_port") - if val == "" { - return 0, 0 - } - - ports := strings.Split(val, "-") - if len(ports) != 2 { - return 0, 0 - } - - port1, err := strconv.ParseInt(ports[0], 10, 64) - if err != nil { - return 0, 0 - } - - port2, err := strconv.ParseInt(ports[1], 10, 64) - if err != nil { - return 0, 0 - } - - return int(port1), int(port2) -} - type client struct { p *program rconn *gortsplib.Conn @@ -363,7 +318,7 @@ func (c *client) handleRequest(req *gortsplib.Request) bool { return false } - th := newTransportHeader(transportStr) + th := gortsplib.NewTransportHeader(transportStr) if _, ok := th["unicast"]; !ok { c.writeResError(req, fmt.Errorf("transport header does not contain unicast")) @@ -397,7 +352,7 @@ func (c *client) handleRequest(req *gortsplib.Request) bool { return false } - rtpPort, rtcpPort := th.getClientPorts() + rtpPort, rtcpPort := th.GetPorts("client_port") if rtpPort == 0 || rtcpPort == 0 { c.writeResError(req, fmt.Errorf("transport header does not have valid client ports (%s)", transportStr)) return false @@ -565,7 +520,7 @@ func (c *client) handleRequest(req *gortsplib.Request) bool { return false } - rtpPort, rtcpPort := th.getClientPorts() + rtpPort, rtcpPort := th.GetPorts("client_port") if rtpPort == 0 || rtcpPort == 0 { c.writeResError(req, fmt.Errorf("transport header does not have valid client ports (%s)", transportStr)) return false @@ -640,7 +595,7 @@ func (c *client) handleRequest(req *gortsplib.Request) bool { return fmt.Errorf("all the tracks have already been setup") } - interleaved = th.getKeyValue("interleaved") + interleaved = th.GetValue("interleaved") if interleaved == "" { return fmt.Errorf("transport header does not contain interleaved field") } diff --git a/go.mod b/go.mod index 59ae66cd..7cf8fabe 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.13 require ( github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect - github.com/aler9/gortsplib v0.0.0-20200120091821-97304167de21 + github.com/aler9/gortsplib v0.0.0-20200120114552-70d65410783c gopkg.in/alecthomas/kingpin.v2 v2.2.6 gortc.io/sdp v0.17.0 ) diff --git a/go.sum b/go.sum index 52c08ac6..f36cb6fa 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/aler9/gortsplib v0.0.0-20200120091821-97304167de21 h1:5TP+mdMu/PiaGeiKXqmvJRQleee93Skiha3fQXOa9ZQ= -github.com/aler9/gortsplib v0.0.0-20200120091821-97304167de21/go.mod h1:YiIgmmv0ELkWUy11Jj2h5AgfqLCpy8sIX/l9MmS8+uw= +github.com/aler9/gortsplib v0.0.0-20200120114552-70d65410783c h1:DPTdhbN9SSQgKt6m6/eWbRLok4kA/1NhklNaGM43nqY= +github.com/aler9/gortsplib v0.0.0-20200120114552-70d65410783c/go.mod h1:YiIgmmv0ELkWUy11Jj2h5AgfqLCpy8sIX/l9MmS8+uw= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=