Browse Source

Merge remote-tracking branch 'upstream/main'

pull/3051/head
Hideaki Takahashi 2 years ago
parent
commit
e64ee1431f
  1. 1
      .golangci.yml
  2. 2
      Makefile
  3. 2
      README.md
  4. 20
      go.mod
  5. 47
      go.sum
  6. 1
      internal/asyncwriter/async_writer.go
  7. 22
      internal/asyncwriter/async_writer_test.go
  8. 2
      internal/conf/env/env_test.go
  9. 4
      internal/core/path_test.go
  10. 2
      internal/formatprocessor/h264_test.go
  11. 2
      internal/formatprocessor/h265_test.go
  12. 2
      internal/protocols/rtmp/amf0/unmarshal_test.go
  13. 8
      internal/protocols/rtmp/chunk/chunk_test.go
  14. 2
      internal/protocols/rtmp/message/reader_test.go
  15. 8
      internal/protocols/rtmp/rawmessage/reader_test.go
  16. 2
      internal/protocols/websocket/serverconn.go
  17. 2
      internal/protocols/websocket/serverconn_test.go
  18. 4
      internal/record/agent_test.go
  19. 15
      internal/servers/hls/muxer.go
  20. 4
      internal/servers/hls/muxer_instance.go
  21. 50
      internal/servers/hls/server_test.go
  22. 2
      internal/servers/rtmp/conn.go
  23. 2
      internal/servers/rtmp/server_test.go
  24. 2
      internal/servers/rtsp/server_test.go
  25. 2
      internal/servers/srt/conn.go
  26. 3
      internal/servers/webrtc/session.go
  27. 4
      internal/staticsources/hls/source.go
  28. 12
      internal/staticsources/rtsp/source_test.go
  29. 1
      internal/test/source_tester.go

1
.golangci.yml

@ -15,6 +15,7 @@ linters: @@ -15,6 +15,7 @@ linters:
- nilerr
- prealloc
- revive
- usestdlibvars
- unconvert
- tparallel
- wastedassign

2
Makefile

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
BASE_IMAGE = golang:1.21-alpine3.19
LINT_IMAGE = golangci/golangci-lint:v1.55.2
LINT_IMAGE = golangci/golangci-lint:v1.56.2
NODE_IMAGE = node:20-alpine3.19
ALPINE_IMAGE = alpine:3.19
RPI32_IMAGE = balenalib/raspberry-pi:bullseye-run-20230712

2
README.md

@ -1676,7 +1676,7 @@ api: yes @@ -1676,7 +1676,7 @@ api: yes
The API listens on `apiAddress`, that by default is `127.0.0.1:9997`; for instance, to obtain a list of active paths, run:
```
curl http://127.0.0.1:9997/v2/paths/list
curl http://127.0.0.1:9997/v3/paths/list
```
Full documentation of the Control API is available on the [dedicated site](https://bluenviron.github.io/mediamtx/).

20
go.mod

@ -4,13 +4,13 @@ go 1.21 @@ -4,13 +4,13 @@ go 1.21
require (
code.cloudfoundry.org/bytefmt v0.0.0
github.com/MicahParks/keyfunc/v3 v3.2.7
github.com/MicahParks/keyfunc/v3 v3.3.2
github.com/abema/go-mp4 v1.2.0
github.com/alecthomas/kong v0.8.1
github.com/alecthomas/kong v0.9.0
github.com/bluenviron/gohlslib v1.3.0
github.com/bluenviron/gortsplib/v4 v4.8.0
github.com/bluenviron/mediacommon v1.9.2
github.com/datarhei/gosrt v0.5.7
github.com/datarhei/gosrt v0.6.0
github.com/fsnotify/fsnotify v1.7.0
github.com/gin-gonic/gin v1.9.1
github.com/golang-jwt/jwt/v5 v5.2.1
@ -20,21 +20,21 @@ require ( @@ -20,21 +20,21 @@ require (
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/matthewhartstonge/argon2 v1.0.0
github.com/pion/ice/v2 v2.3.11
github.com/pion/interceptor v0.1.25
github.com/pion/interceptor v0.1.27
github.com/pion/logging v0.2.2
github.com/pion/rtcp v1.2.14
github.com/pion/rtp v1.8.3
github.com/pion/sdp/v3 v3.0.8
github.com/pion/rtp v1.8.5
github.com/pion/sdp/v3 v3.0.9
github.com/pion/webrtc/v3 v3.2.22
github.com/stretchr/testify v1.9.0
golang.org/x/crypto v0.21.0
golang.org/x/sys v0.18.0
golang.org/x/term v0.18.0
golang.org/x/sys v0.19.0
golang.org/x/term v0.19.0
gopkg.in/yaml.v2 v2.4.0
)
require (
github.com/MicahParks/jwkset v0.5.13 // indirect
github.com/MicahParks/jwkset v0.5.17 // indirect
github.com/asticode/go-astikit v0.30.0 // indirect
github.com/asticode/go-astits v1.13.0 // indirect
github.com/benburkert/openpgp v0.0.0-20160410205803-c2471f86866c // indirect
@ -71,7 +71,7 @@ require ( @@ -71,7 +71,7 @@ require (
golang.org/x/net v0.21.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

47
go.sum

@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
github.com/MicahParks/jwkset v0.5.13 h1:vRXsx+b8uaZm1AU6MpavHJXOmuwP36iR+DNmlg2Lx8o=
github.com/MicahParks/jwkset v0.5.13/go.mod h1:q8ptTGn/Z9c4MwbcfeCDssADeVQb3Pk7PnVxrvi+2QY=
github.com/MicahParks/keyfunc/v3 v3.2.7 h1:ZNVuh6dQ/1JQamtahDy1fUUPMVewZupWTDpMq/pxMqk=
github.com/MicahParks/keyfunc/v3 v3.2.7/go.mod h1:LXARqJdr+5ETgA2soFi8ZqX7hAES9YbSwxakZxLRWTk=
github.com/MicahParks/jwkset v0.5.17 h1:DrcwyKwSP5adD0G2XJTvDulnWXjD6gbjROMgMXDbkKA=
github.com/MicahParks/jwkset v0.5.17/go.mod h1:q8ptTGn/Z9c4MwbcfeCDssADeVQb3Pk7PnVxrvi+2QY=
github.com/MicahParks/keyfunc/v3 v3.3.2 h1:YTtwc4dxalBZKFqHhqctBWN6VhbLdGhywmne9u5RQVM=
github.com/MicahParks/keyfunc/v3 v3.3.2/go.mod h1:GJBeEjnv25OnD9y2OYQa7ELU6gYahEMBNXINZb+qm34=
github.com/abema/go-mp4 v1.2.0 h1:gi4X8xg/m179N/J15Fn5ugywN9vtI6PLk6iLldHGLAk=
github.com/abema/go-mp4 v1.2.0/go.mod h1:vPl9t5ZK7K0x68jh12/+ECWBCXoWuIDtNgPtU2f04ws=
github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0=
github.com/alecthomas/assert/v2 v2.1.0/go.mod h1:b/+1DI2Q6NckYi+3mXyH3wFb8qG37K/DuK80n7WefXA=
github.com/alecthomas/kong v0.8.1 h1:acZdn3m4lLRobeh3Zi2S2EpnXTd1mOL6U7xVml+vfkY=
github.com/alecthomas/kong v0.8.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
github.com/alecthomas/repr v0.1.0/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU=
github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/kong v0.9.0 h1:G5diXxc85KvoV2f0ZRVuMsi45IrBgx9zDNGNj165aPA=
github.com/alecthomas/kong v0.9.0/go.mod h1:Y47y5gKfHp1hDc7CH7OeXgLIpp+Q2m1Ni0L5s3bI8Os=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/aler9/ice/v2 v2.0.0-20231112223552-32d34dfcf3a1 h1:fD6eZt+3/t8bzFn6ZZA2eP63xBP06v3EPfPJu8DO8ys=
github.com/aler9/ice/v2 v2.0.0-20231112223552-32d34dfcf3a1/go.mod h1:lT3kv5uUIlHfXHU/ZRD7uKD/ufM202+eTa3C/umgGf4=
github.com/aler9/webrtc/v3 v3.0.0-20231112223655-e402ed2689c6 h1:wMd3D1mLghoYYh31STig8Kwm2qi8QyQKUy09qUUZrVw=
@ -35,8 +35,8 @@ github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583j @@ -35,8 +35,8 @@ github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583j
github.com/cloudfoundry/bytefmt v0.0.0-20211005130812-5bb3c17173e5 h1:xB7KkA98BcUdzVcwyZxb5R0FGIHxNPHgZOzkjPEY5gM=
github.com/cloudfoundry/bytefmt v0.0.0-20211005130812-5bb3c17173e5/go.mod h1:v4VVB6oBMz/c9fRY6vZrwr5xKRWOH5NPDjQZlPk0Gbs=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/datarhei/gosrt v0.5.7 h1:1COeDgF0D0v0poWu0yKDC72d29x16Ma6VFR1icx+3Xc=
github.com/datarhei/gosrt v0.5.7/go.mod h1:ZicbsY9T2rXtWgQVBTR9ilnEkSYVSIb36hG9Lj7XCKM=
github.com/datarhei/gosrt v0.6.0 h1:HrrXAw90V78ok4WMIhX6se1aTHPCn82Sg2hj+PhdmGc=
github.com/datarhei/gosrt v0.6.0/go.mod h1:fsOWdLSHUHShHjgi/46h6wjtdQrtnSdAQFnlas8ONxs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -134,8 +134,9 @@ github.com/pion/datachannel v1.5.5 h1:10ef4kwdjije+M9d7Xm9im2Y3O6A6ccQb0zcqZcJew @@ -134,8 +134,9 @@ github.com/pion/datachannel v1.5.5 h1:10ef4kwdjije+M9d7Xm9im2Y3O6A6ccQb0zcqZcJew
github.com/pion/datachannel v1.5.5/go.mod h1:iMz+lECmfdCMqFRhXhcA/219B0SQlbpoR2V118yimL0=
github.com/pion/dtls/v2 v2.2.7 h1:cSUBsETxepsCSFSxC3mc/aDo14qQLMSL+O6IjG28yV8=
github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s=
github.com/pion/interceptor v0.1.25 h1:pwY9r7P6ToQ3+IF0bajN0xmk/fNw/suTgaTdlwTDmhc=
github.com/pion/interceptor v0.1.25/go.mod h1:wkbPYAak5zKsfpVDYMtEfWEy8D4zL+rpxCxPImLOg3Y=
github.com/pion/interceptor v0.1.27 h1:mZ01OiGiukwRxezmDGzYjjokCVlDOk4T6BfaL5qrtGo=
github.com/pion/interceptor v0.1.27/go.mod h1:/vVaqLwDjGv4GRbgmChIKZIT5EXFDijwmj4WmIYy9bI=
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
github.com/pion/mdns v0.0.7/go.mod h1:4iP2UbeFhLI/vWju/bw6ZfwjJzk0z8DNValjGxR/dD8=
@ -148,14 +149,16 @@ github.com/pion/rtcp v1.2.12/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9 @@ -148,14 +149,16 @@ github.com/pion/rtcp v1.2.12/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9
github.com/pion/rtcp v1.2.14 h1:KCkGV3vJ+4DAJmvP0vaQShsb0xkRfWkO540Gy102KyE=
github.com/pion/rtcp v1.2.14/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4=
github.com/pion/rtp v1.8.2/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU=
github.com/pion/rtp v1.8.3 h1:VEHxqzSVQxCkKDSHro5/4IUUG1ea+MFdqR2R3xSpNU8=
github.com/pion/rtp v1.8.3/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU=
github.com/pion/rtp v1.8.4/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU=
github.com/pion/rtp v1.8.5 h1:uYzINfaK+9yWs7r537z/Rc1SvT8ILjBcmDOpJcTB+OU=
github.com/pion/rtp v1.8.5/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU=
github.com/pion/sctp v1.8.5/go.mod h1:SUFFfDpViyKejTAdwD1d/HQsCu+V/40cCs2nZIvC3s0=
github.com/pion/sctp v1.8.8 h1:5EdnnKI4gpyR1a1TwbiS/wxEgcUWBHsc7ILAjARJB+U=
github.com/pion/sctp v1.8.8/go.mod h1:igF9nZBrjh5AtmKc7U30jXltsFHicFCXSmWA2GWRaWs=
github.com/pion/sdp/v3 v3.0.6/go.mod h1:iiFWFpQO8Fy3S5ldclBkpXqmWy02ns78NOKoLLL0YQw=
github.com/pion/sdp/v3 v3.0.8 h1:yd/wkrS0nzXEAb+uwv1TL3SG/gzsTiXHVOtXtD7EKl0=
github.com/pion/sdp/v3 v3.0.8/go.mod h1:B5xmvENq5IXJimIO4zfp6LAe1fD9N+kFv+V/1lOdz8M=
github.com/pion/sdp/v3 v3.0.9 h1:pX++dCHoHUwq43kuwf3PyJfHlwIj4hXA7Vrifiq0IJY=
github.com/pion/sdp/v3 v3.0.9/go.mod h1:B5xmvENq5IXJimIO4zfp6LAe1fD9N+kFv+V/1lOdz8M=
github.com/pion/srtp/v2 v2.0.18 h1:vKpAXfawO9RtTRKZJbG4y0v1b11NZxQnxRl85kGuUlo=
github.com/pion/srtp/v2 v2.0.18/go.mod h1:0KJQjA99A6/a0DOVTu1PhDSw0CXF2jTkqOoMg3ODqdA=
github.com/pion/stun v0.6.1 h1:8lp6YejULeHBF8NmV8e2787BogQhduZugh5PdhDyyN4=
@ -265,8 +268,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -265,8 +268,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
@ -277,8 +280,8 @@ golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= @@ -277,8 +280,8 @@ golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
@ -312,8 +315,8 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi @@ -312,8 +315,8 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=

1
internal/asyncwriter/async_writer.go

@ -50,6 +50,7 @@ func (w *Writer) Error() chan error { @@ -50,6 +50,7 @@ func (w *Writer) Error() chan error {
func (w *Writer) run() {
w.err <- w.runInner()
close(w.err)
}
func (w *Writer) runInner() error {

22
internal/asyncwriter/async_writer_test.go

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
package asyncwriter
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func TestAsyncWriter(t *testing.T) {
w := New(512, nil)
w.Start()
defer w.Stop()
w.Push(func() error {
return fmt.Errorf("testerror")
})
err := <-w.Error()
require.EqualError(t, err, "testerror")
}

2
internal/conf/env/env_test.go vendored

@ -194,7 +194,7 @@ func FuzzLoad(f *testing.F) { @@ -194,7 +194,7 @@ func FuzzLoad(f *testing.F) {
f.Add("MYPREFIX_MYDURATION", "a")
f.Add("MYPREFIX_MYDURATION_A", "a")
f.Fuzz(func(t *testing.T, key string, val string) {
f.Fuzz(func(_ *testing.T, key string, val string) {
env := map[string]string{
key: val,
}

4
internal/core/path_test.go

@ -650,12 +650,12 @@ func TestPathSourceRegexp(t *testing.T) { @@ -650,12 +650,12 @@ func TestPathSourceRegexp(t *testing.T) {
StatusCode: base.StatusOK,
}, stream, nil
},
onSetup: func(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
onSetup: func(_ *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
return &base.Response{
StatusCode: base.StatusOK,
}, stream, nil
},
onPlay: func(ctx *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error) {
onPlay: func(_ *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error) {
return &base.Response{
StatusCode: base.StatusOK,
}, nil

2
internal/formatprocessor/h264_test.go

@ -202,7 +202,7 @@ func TestH264EmptyPacket(t *testing.T) { @@ -202,7 +202,7 @@ func TestH264EmptyPacket(t *testing.T) {
}
func FuzzRTPH264ExtractParams(f *testing.F) {
f.Fuzz(func(t *testing.T, b []byte) {
f.Fuzz(func(_ *testing.T, b []byte) {
rtpH264ExtractParams(b)
})
}

2
internal/formatprocessor/h265_test.go

@ -198,7 +198,7 @@ func TestH265EmptyPacket(t *testing.T) { @@ -198,7 +198,7 @@ func TestH265EmptyPacket(t *testing.T) {
}
func FuzzRTPH265ExtractParams(f *testing.F) {
f.Fuzz(func(t *testing.T, b []byte) {
f.Fuzz(func(_ *testing.T, b []byte) {
rtpH265ExtractParams(b)
})
}

2
internal/protocols/rtmp/amf0/unmarshal_test.go

@ -307,7 +307,7 @@ func FuzzUnmarshal(f *testing.F) { @@ -307,7 +307,7 @@ func FuzzUnmarshal(f *testing.F) {
f.Add(ca.enc)
}
f.Fuzz(func(t *testing.T, b []byte) {
f.Fuzz(func(_ *testing.T, b []byte) {
Unmarshal(b) //nolint:errcheck
})
}

8
internal/protocols/rtmp/chunk/chunk_test.go

@ -158,28 +158,28 @@ func TestChunkMarshal(t *testing.T) { @@ -158,28 +158,28 @@ func TestChunkMarshal(t *testing.T) {
}
func FuzzChunk0Read(f *testing.F) {
f.Fuzz(func(t *testing.T, b []byte) {
f.Fuzz(func(_ *testing.T, b []byte) {
var chunk Chunk0
chunk.Read(bytes.NewReader(b), 65536, false) //nolint:errcheck
})
}
func FuzzChunk1Read(f *testing.F) {
f.Fuzz(func(t *testing.T, b []byte) {
f.Fuzz(func(_ *testing.T, b []byte) {
var chunk Chunk1
chunk.Read(bytes.NewReader(b), 65536, false) //nolint:errcheck
})
}
func FuzzChunk2Read(f *testing.F) {
f.Fuzz(func(t *testing.T, b []byte) {
f.Fuzz(func(_ *testing.T, b []byte) {
var chunk Chunk2
chunk.Read(bytes.NewReader(b), 65536, false) //nolint:errcheck
})
}
func FuzzChunk3Read(f *testing.F) {
f.Fuzz(func(t *testing.T, b []byte) {
f.Fuzz(func(_ *testing.T, b []byte) {
var chunk Chunk3
chunk.Read(bytes.NewReader(b), 65536, true) //nolint:errcheck
})

2
internal/protocols/rtmp/message/reader_test.go

@ -297,7 +297,7 @@ func FuzzReader(f *testing.F) { @@ -297,7 +297,7 @@ func FuzzReader(f *testing.F) {
0x01, 0x00, 0x00, 0x00, 0x88, 0x68, 0x76, 0x63,
0x31, 0x01, 0x02, 0x03,
})
f.Fuzz(func(t *testing.T, b []byte) {
f.Fuzz(func(_ *testing.T, b []byte) {
bc := bytecounter.NewReader(bytes.NewReader(b))
r := NewReader(bc, bc, nil)
r.Read() //nolint:errcheck

8
internal/protocols/rtmp/rawmessage/reader_test.go

@ -205,7 +205,7 @@ func TestReader(t *testing.T) { @@ -205,7 +205,7 @@ func TestReader(t *testing.T) {
t.Run(ca.name, func(t *testing.T) {
var buf bytes.Buffer
br := bytecounter.NewReader(&buf)
r := NewReader(br, br, func(count uint32) error {
r := NewReader(br, br, func(_ uint32) error {
return nil
})
@ -234,7 +234,7 @@ func TestReaderAcknowledge(t *testing.T) { @@ -234,7 +234,7 @@ func TestReaderAcknowledge(t *testing.T) {
var buf bytes.Buffer
bc := bytecounter.NewReader(&buf)
r := NewReader(bc, bc, func(count uint32) error {
r := NewReader(bc, bc, func(_ uint32) error {
close(onAckCalled)
return nil
})
@ -269,9 +269,9 @@ func TestReaderAcknowledge(t *testing.T) { @@ -269,9 +269,9 @@ func TestReaderAcknowledge(t *testing.T) {
}
func FuzzReader(f *testing.F) {
f.Fuzz(func(t *testing.T, b []byte) {
f.Fuzz(func(_ *testing.T, b []byte) {
br := bytecounter.NewReader(bytes.NewReader(b))
r := NewReader(br, br, func(count uint32) error {
r := NewReader(br, br, func(_ uint32) error {
return nil
})

2
internal/protocols/websocket/serverconn.go

@ -18,7 +18,7 @@ var ( @@ -18,7 +18,7 @@ var (
)
var upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
CheckOrigin: func(_ *http.Request) bool {
return true
},
}

2
internal/protocols/websocket/serverconn_test.go

@ -39,7 +39,7 @@ func TestServerConn(t *testing.T) { @@ -39,7 +39,7 @@ func TestServerConn(t *testing.T) {
defer res.Body.Close()
defer c.Close() //nolint:errcheck
c.SetPingHandler(func(msg string) error {
c.SetPingHandler(func(_ string) error {
close(pingReceived)
return nil
})

4
internal/record/agent_test.go

@ -167,10 +167,10 @@ func TestAgent(t *testing.T) { @@ -167,10 +167,10 @@ func TestAgent(t *testing.T) {
SegmentDuration: 1 * time.Second,
PathName: "mypath",
Stream: stream,
OnSegmentCreate: func(fpath string) {
OnSegmentCreate: func(_ string) {
segCreated <- struct{}{}
},
OnSegmentComplete: func(fpath string) {
OnSegmentComplete: func(_ string) {
segDone <- struct{}{}
},
Parent: &test.NilLogger{},

15
internal/servers/hls/muxer.go

@ -165,6 +165,12 @@ func (m *muxer) runInner() error { @@ -165,6 +165,12 @@ func (m *muxer) runInner() error {
recreateTimer = emptyTimer()
}
defer func() {
if mi != nil {
mi.close()
}
}()
var activityCheckTimer *time.Timer
if m.remoteAddr != "" {
activityCheckTimer = time.NewTimer(closeCheckPeriod)
@ -178,13 +184,12 @@ func (m *muxer) runInner() error { @@ -178,13 +184,12 @@ func (m *muxer) runInner() error {
req.res <- mi
case err := <-instanceError:
mi.close()
if m.remoteAddr != "" {
return err
}
m.Log(logger.Error, err.Error())
mi.close()
mi = nil
instanceError = make(chan error)
recreateTimer = time.NewTimer(recreatePause)
@ -215,17 +220,11 @@ func (m *muxer) runInner() error { @@ -215,17 +220,11 @@ func (m *muxer) runInner() error {
case <-activityCheckTimer.C:
t := time.Unix(0, atomic.LoadInt64(m.lastRequestTime))
if time.Since(t) >= closeAfterInactivity {
if mi != nil {
mi.close()
}
return fmt.Errorf("not used anymore")
}
activityCheckTimer = time.NewTimer(closeCheckPeriod)
case <-m.ctx.Done():
if mi != nil {
mi.close()
}
return errors.New("terminated")
}
}

4
internal/servers/hls/muxer_instance.go

@ -54,7 +54,6 @@ func (mi *muxerInstance) initialize() error { @@ -54,7 +54,6 @@ func (mi *muxerInstance) initialize() error {
if mi.directory != "" {
muxerDirectory = filepath.Join(mi.directory, mi.pathName)
os.MkdirAll(muxerDirectory, 0o755)
defer os.Remove(muxerDirectory)
}
mi.hmuxer = &gohlslib.Muxer{
@ -91,6 +90,9 @@ func (mi *muxerInstance) close() { @@ -91,6 +90,9 @@ func (mi *muxerInstance) close() {
mi.writer.Stop()
mi.hmuxer.Close()
mi.stream.RemoveReader(mi.writer)
if mi.hmuxer.Directory != "" {
os.Remove(mi.hmuxer.Directory)
}
}
func (mi *muxerInstance) createVideoTrack() *gohlslib.Track {

50
internal/servers/hls/server_test.go

@ -3,6 +3,8 @@ package hls @@ -3,6 +3,8 @@ package hls
import (
"fmt"
"net/http"
"os"
"path/filepath"
"testing"
"time"
@ -293,3 +295,51 @@ func TestServerRead(t *testing.T) { @@ -293,3 +295,51 @@ func TestServerRead(t *testing.T) {
<-recv
})
}
func TestDirectory(t *testing.T) {
dir, err := os.MkdirTemp("", "mediamtx-playback")
require.NoError(t, err)
defer os.RemoveAll(dir)
desc := &description.Session{Medias: []*description.Media{test.MediaH264}}
stream, err := stream.New(
1460,
desc,
true,
test.NilLogger{},
)
require.NoError(t, err)
pathManager := &dummyPathManager{stream: stream}
s := &Server{
Address: "127.0.0.1:8888",
Encryption: false,
ServerKey: "",
ServerCert: "",
AlwaysRemux: true,
Variant: conf.HLSVariant(gohlslib.MuxerVariantMPEGTS),
SegmentCount: 7,
SegmentDuration: conf.StringDuration(1 * time.Second),
PartDuration: conf.StringDuration(200 * time.Millisecond),
SegmentMaxSize: 50 * 1024 * 1024,
AllowOrigin: "",
TrustedProxies: conf.IPNetworks{},
Directory: filepath.Join(dir, "mydir"),
ReadTimeout: conf.StringDuration(10 * time.Second),
WriteQueueSize: 512,
PathManager: pathManager,
Parent: &test.NilLogger{},
}
err = s.Initialize()
require.NoError(t, err)
defer s.Close()
s.PathReady(&dummyPath{})
time.Sleep(100 * time.Millisecond)
_, err = os.Stat(filepath.Join(dir, "mydir", "mystream"))
require.NoError(t, err)
}

2
internal/servers/rtmp/conn.go

@ -237,10 +237,10 @@ func (c *conn) runRead(conn *rtmp.Conn, u *url.URL) error { @@ -237,10 +237,10 @@ func (c *conn) runRead(conn *rtmp.Conn, u *url.URL) error {
c.nconn.SetReadDeadline(time.Time{})
writer.Start()
defer writer.Stop()
select {
case <-c.ctx.Done():
writer.Stop()
return fmt.Errorf("terminated")
case err := <-writer.Error():

2
internal/servers/rtmp/server_test.go

@ -258,7 +258,7 @@ func TestServerRead(t *testing.T) { @@ -258,7 +258,7 @@ func TestServerRead(t *testing.T) {
},
})
r.OnDataH264(func(pts time.Duration, au [][]byte) {
r.OnDataH264(func(_ time.Duration, au [][]byte) {
require.Equal(t, [][]byte{
test.FormatH264.SPS,
test.FormatH264.PPS,

2
internal/servers/rtsp/server_test.go

@ -228,7 +228,7 @@ func TestServerRead(t *testing.T) { @@ -228,7 +228,7 @@ func TestServerRead(t *testing.T) {
recv := make(chan struct{})
reader.OnPacketRTPAny(func(m *description.Media, f format.Format, p *rtp.Packet) {
reader.OnPacketRTPAny(func(_ *description.Media, _ format.Format, p *rtp.Packet) {
require.Equal(t, &rtp.Packet{
Header: rtp.Header{
Version: 2,

2
internal/servers/srt/conn.go

@ -327,10 +327,10 @@ func (c *conn) runRead(req srtNewConnReq, streamID *streamID) (bool, error) { @@ -327,10 +327,10 @@ func (c *conn) runRead(req srtNewConnReq, streamID *streamID) (bool, error) {
sconn.SetReadDeadline(time.Time{})
writer.Start()
defer writer.Stop()
select {
case <-c.ctx.Done():
writer.Stop()
return true, fmt.Errorf("terminated")
case err := <-writer.Error():

3
internal/servers/webrtc/session.go

@ -612,17 +612,16 @@ func (s *session) runRead() (int, error) { @@ -612,17 +612,16 @@ func (s *session) runRead() (int, error) {
defer onUnreadHook()
writer.Start()
defer writer.Stop()
select {
case <-pc.Disconnected():
writer.Stop()
return 0, fmt.Errorf("peer connection closed")
case err := <-writer.Error():
return 0, err
case <-s.ctx.Done():
writer.Stop()
return 0, fmt.Errorf("terminated")
}
}

4
internal/staticsources/hls/source.go

@ -123,7 +123,7 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error { @@ -123,7 +123,7 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error {
}},
}
c.OnDataH26x(track, func(pts time.Duration, dts time.Duration, au [][]byte) {
c.OnDataH26x(track, func(pts time.Duration, _ time.Duration, au [][]byte) {
stream.WriteUnit(medi, medi.Formats[0], &unit.H264{
Base: unit.Base{
NTP: time.Now(),
@ -144,7 +144,7 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error { @@ -144,7 +144,7 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error {
}},
}
c.OnDataH26x(track, func(pts time.Duration, dts time.Duration, au [][]byte) {
c.OnDataH26x(track, func(pts time.Duration, _ time.Duration, au [][]byte) {
stream.WriteUnit(medi, medi.Formats[0], &unit.H265{
Base: unit.Base{
NTP: time.Now(),

12
internal/staticsources/rtsp/source_test.go

@ -69,12 +69,12 @@ func TestSource(t *testing.T) { @@ -69,12 +69,12 @@ func TestSource(t *testing.T) {
StatusCode: base.StatusOK,
}, stream, nil
},
onSetup: func(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
onSetup: func(_ *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
return &base.Response{
StatusCode: base.StatusOK,
}, stream, nil
},
onPlay: func(ctx *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error) {
onPlay: func(_ *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error) {
go func() {
time.Sleep(100 * time.Millisecond)
err := stream.WritePacketRTP(media0, &rtp.Packet{
@ -195,7 +195,7 @@ func TestRTSPSourceNoPassword(t *testing.T) { @@ -195,7 +195,7 @@ func TestRTSPSourceNoPassword(t *testing.T) {
StatusCode: base.StatusOK,
}, stream, nil
},
onSetup: func(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
onSetup: func(_ *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
go func() {
time.Sleep(100 * time.Millisecond)
err := stream.WritePacketRTP(media0, &rtp.Packet{
@ -216,7 +216,7 @@ func TestRTSPSourceNoPassword(t *testing.T) { @@ -216,7 +216,7 @@ func TestRTSPSourceNoPassword(t *testing.T) {
StatusCode: base.StatusOK,
}, stream, nil
},
onPlay: func(ctx *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error) {
onPlay: func(_ *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error) {
return &base.Response{
StatusCode: base.StatusOK,
}, nil
@ -263,12 +263,12 @@ func TestRTSPSourceRange(t *testing.T) { @@ -263,12 +263,12 @@ func TestRTSPSourceRange(t *testing.T) {
s := gortsplib.Server{
Handler: &testServer{
onDescribe: func(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error) {
onDescribe: func(_ *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error) {
return &base.Response{
StatusCode: base.StatusOK,
}, stream, nil
},
onSetup: func(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
onSetup: func(_ *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
return &base.Response{
StatusCode: base.StatusOK,
}, stream, nil

1
internal/test/source_tester.go

@ -69,6 +69,7 @@ func (t *SourceTester) SetReady(req defs.PathSourceStaticSetReadyReq) defs.PathS @@ -69,6 +69,7 @@ func (t *SourceTester) SetReady(req defs.PathSourceStaticSetReadyReq) defs.PathS
)
t.writer = asyncwriter.New(2048, t)
t.stream.AddReader(t.writer, req.Desc.Medias[0], req.Desc.Medias[0].Formats[0], func(u unit.Unit) error {
t.Unit <- u
close(t.Unit)

Loading…
Cancel
Save