mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-30 19:22:20 +00:00
move transportHeader into gortsplib
This commit is contained in:
parent
9349146d47
commit
412e2c7642
4
Makefile
4
Makefile
@ -17,7 +17,7 @@ help:
|
|||||||
|
|
||||||
mod-tidy:
|
mod-tidy:
|
||||||
docker run --rm -it -v $(PWD):/s $(BASE_IMAGE) \
|
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:
|
format:
|
||||||
docker run --rm -it -v $(PWD):/s $(BASE_IMAGE) \
|
docker run --rm -it -v $(PWD):/s $(BASE_IMAGE) \
|
||||||
@ -30,7 +30,7 @@ WORKDIR /s
|
|||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
COPY . ./
|
COPY . ./
|
||||||
RUN go build -o /out .
|
RUN GOPROXY=direct go build -o /out .
|
||||||
endef
|
endef
|
||||||
export DOCKERFILE_RUN
|
export DOCKERFILE_RUN
|
||||||
|
|
||||||
|
53
client.go
53
client.go
@ -6,7 +6,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/aler9/gortsplib"
|
"github.com/aler9/gortsplib"
|
||||||
@ -27,50 +26,6 @@ func trackToInterleavedChannel(id int, flow trackFlow) int {
|
|||||||
return (id * 2) + 1
|
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 {
|
type client struct {
|
||||||
p *program
|
p *program
|
||||||
rconn *gortsplib.Conn
|
rconn *gortsplib.Conn
|
||||||
@ -363,7 +318,7 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
th := newTransportHeader(transportStr)
|
th := gortsplib.NewTransportHeader(transportStr)
|
||||||
|
|
||||||
if _, ok := th["unicast"]; !ok {
|
if _, ok := th["unicast"]; !ok {
|
||||||
c.writeResError(req, fmt.Errorf("transport header does not contain unicast"))
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
rtpPort, rtcpPort := th.getClientPorts()
|
rtpPort, rtcpPort := th.GetPorts("client_port")
|
||||||
if rtpPort == 0 || rtcpPort == 0 {
|
if rtpPort == 0 || rtcpPort == 0 {
|
||||||
c.writeResError(req, fmt.Errorf("transport header does not have valid client ports (%s)", transportStr))
|
c.writeResError(req, fmt.Errorf("transport header does not have valid client ports (%s)", transportStr))
|
||||||
return false
|
return false
|
||||||
@ -565,7 +520,7 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
rtpPort, rtcpPort := th.getClientPorts()
|
rtpPort, rtcpPort := th.GetPorts("client_port")
|
||||||
if rtpPort == 0 || rtcpPort == 0 {
|
if rtpPort == 0 || rtcpPort == 0 {
|
||||||
c.writeResError(req, fmt.Errorf("transport header does not have valid client ports (%s)", transportStr))
|
c.writeResError(req, fmt.Errorf("transport header does not have valid client ports (%s)", transportStr))
|
||||||
return false
|
return false
|
||||||
@ -640,7 +595,7 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
|
|||||||
return fmt.Errorf("all the tracks have already been setup")
|
return fmt.Errorf("all the tracks have already been setup")
|
||||||
}
|
}
|
||||||
|
|
||||||
interleaved = th.getKeyValue("interleaved")
|
interleaved = th.GetValue("interleaved")
|
||||||
if interleaved == "" {
|
if interleaved == "" {
|
||||||
return fmt.Errorf("transport header does not contain interleaved field")
|
return fmt.Errorf("transport header does not contain interleaved field")
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.13
|
|||||||
require (
|
require (
|
||||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
|
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
|
||||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // 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
|
gopkg.in/alecthomas/kingpin.v2 v2.2.6
|
||||||
gortc.io/sdp v0.17.0
|
gortc.io/sdp v0.17.0
|
||||||
)
|
)
|
||||||
|
4
go.sum
4
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/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 h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
|
||||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
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-20200120114552-70d65410783c h1:DPTdhbN9SSQgKt6m6/eWbRLok4kA/1NhklNaGM43nqY=
|
||||||
github.com/aler9/gortsplib v0.0.0-20200120091821-97304167de21/go.mod h1:YiIgmmv0ELkWUy11Jj2h5AgfqLCpy8sIX/l9MmS8+uw=
|
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 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
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=
|
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
|
||||||
|
Loading…
Reference in New Issue
Block a user