forked from External/mediamtx
hls: add new parameter hlsSegmentMaxSize
This commit is contained in:
parent
2bfdcc7d89
commit
343a5f17fb
15 changed files with 253 additions and 40 deletions
|
|
@ -101,6 +101,8 @@ components:
|
|||
type: integer
|
||||
hlsSegmentDuration:
|
||||
type: string
|
||||
hlsSegmentMaxSize:
|
||||
type: string
|
||||
hlsAllowOrigin:
|
||||
type: string
|
||||
|
||||
|
|
|
|||
4
go.mod
4
go.mod
|
|
@ -3,6 +3,7 @@ module github.com/aler9/rtsp-simple-server
|
|||
go 1.17
|
||||
|
||||
require (
|
||||
code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5
|
||||
github.com/aler9/gortsplib v0.0.0-20220130155047-8c02b12955f8
|
||||
github.com/asticode/go-astits v1.10.0
|
||||
github.com/fsnotify/fsnotify v1.4.9
|
||||
|
|
@ -27,7 +28,7 @@ require (
|
|||
github.com/go-playground/locales v0.13.0 // indirect
|
||||
github.com/go-playground/universal-translator v0.17.0 // indirect
|
||||
github.com/go-playground/validator/v10 v10.4.1 // indirect
|
||||
github.com/golang/protobuf v1.3.3 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/icza/bitio v1.0.0 // indirect
|
||||
github.com/json-iterator/go v1.1.9 // indirect
|
||||
github.com/leodido/go-urn v1.2.0 // indirect
|
||||
|
|
@ -42,6 +43,7 @@ require (
|
|||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
||||
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b // indirect
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da // indirect
|
||||
google.golang.org/protobuf v1.26.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
)
|
||||
|
||||
|
|
|
|||
73
go.sum
73
go.sum
|
|
@ -1,3 +1,5 @@
|
|||
code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5 h1:tM5+dn2C9xZw1RzgI6WTQW1rGqdUimKB3RFbyu4h6Hc=
|
||||
code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5/go.mod h1:v4VVB6oBMz/c9fRY6vZrwr5xKRWOH5NPDjQZlPk0Gbs=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
|
||||
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=
|
||||
|
|
@ -13,6 +15,7 @@ github.com/asticode/go-astits v1.10.0/go.mod h1:DkOWmBNQpnr9mv24KfZjq4JawCFX1FCq
|
|||
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=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||
|
|
@ -27,13 +30,29 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87
|
|||
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
|
||||
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
|
||||
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
|
||||
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk=
|
||||
github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ=
|
||||
github.com/grafov/m3u8 v0.11.1 h1:igZ7EBIB2IAsPPazKwRKdbhxcoBKO3lO1UY57PZDeNA=
|
||||
github.com/grafov/m3u8 v0.11.1/go.mod h1:nqzOkfBiZJENr52zTVd/Dcl03yzphIMbJqkXGu+u080=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/icza/bitio v1.0.0 h1:squ/m1SHyFeCA6+6Gyol1AxV9nmPPlJFT8c2vKdj3U8=
|
||||
github.com/icza/bitio v1.0.0/go.mod h1:0jGnlLAx8MKMr9VGnn/4YrvZiprkvBelsVIbA9Jjr9A=
|
||||
github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6 h1:8UsGZ2rr2ksmEru6lToqnXgA8Mz1DP11X4zSJ159C3k=
|
||||
|
|
@ -50,6 +69,17 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OH
|
|||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
|
||||
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c=
|
||||
github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
|
||||
github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
|
||||
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
|
||||
github.com/pion/rtcp v1.2.4 h1:NT3H5LkUGgaEapvp0HGik+a+CpflRF7KTD7H+o7OWIM=
|
||||
|
|
@ -65,6 +95,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
|
|||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
|
||||
|
|
@ -73,19 +104,36 @@ github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs
|
|||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b h1:k+E048sYJHyVnsr1GDrRZWQ32D2C7lWs9JRc0bel53A=
|
||||
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
|
@ -93,14 +141,37 @@ golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXR
|
|||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
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 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
|
|
|
|||
|
|
@ -196,6 +196,7 @@ type Conf struct {
|
|||
HLSAlwaysRemux bool `json:"hlsAlwaysRemux"`
|
||||
HLSSegmentCount int `json:"hlsSegmentCount"`
|
||||
HLSSegmentDuration StringDuration `json:"hlsSegmentDuration"`
|
||||
HLSSegmentMaxSize StringSize `json:"hlsSegmentMaxSize"`
|
||||
HLSAllowOrigin string `json:"hlsAllowOrigin"`
|
||||
|
||||
// paths
|
||||
|
|
@ -343,6 +344,10 @@ func (conf *Conf) CheckAndFillMissing() error {
|
|||
conf.HLSSegmentDuration = 1 * StringDuration(time.Second)
|
||||
}
|
||||
|
||||
if conf.HLSSegmentMaxSize == 0 {
|
||||
conf.HLSSegmentMaxSize = 50 * 1024 * 1024
|
||||
}
|
||||
|
||||
if conf.HLSAllowOrigin == "" {
|
||||
conf.HLSAllowOrigin = "*"
|
||||
}
|
||||
|
|
|
|||
35
internal/conf/stringsize.go
Normal file
35
internal/conf/stringsize.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package conf
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"code.cloudfoundry.org/bytefmt"
|
||||
)
|
||||
|
||||
// StringSize is a size that is unmarshaled from a string.
|
||||
type StringSize uint64
|
||||
|
||||
// MarshalJSON marshals a StringSize into JSON.
|
||||
func (s StringSize) MarshalJSON() ([]byte, error) {
|
||||
return []byte(`"` + bytefmt.ByteSize(uint64(s)) + `"`), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON unmarshals a StringSize from JSON.
|
||||
func (s *StringSize) UnmarshalJSON(b []byte) error {
|
||||
var in string
|
||||
if err := json.Unmarshal(b, &in); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
v, err := bytefmt.ToBytes(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*s = StringSize(v)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *StringSize) unmarshalEnv(v string) error {
|
||||
return s.UnmarshalJSON([]byte(`"` + v + `"`))
|
||||
}
|
||||
|
|
@ -86,6 +86,7 @@ func loadConfData(ctx *gin.Context) (interface{}, error) {
|
|||
HLSAlwaysRemux *bool `json:"hlsAlwaysRemux"`
|
||||
HLSSegmentCount *int `json:"hlsSegmentCount"`
|
||||
HLSSegmentDuration *conf.StringDuration `json:"hlsSegmentDuration"`
|
||||
HLSSegmentMaxSize *conf.StringSize `json:"hlsSegmentMaxSize"`
|
||||
HLSAllowOrigin *string `json:"hlsAllowOrigin"`
|
||||
}
|
||||
err := json.NewDecoder(ctx.Request.Body).Decode(&in)
|
||||
|
|
|
|||
|
|
@ -338,6 +338,7 @@ func (p *Core) createResources(initial bool) error {
|
|||
p.conf.HLSAlwaysRemux,
|
||||
p.conf.HLSSegmentCount,
|
||||
p.conf.HLSSegmentDuration,
|
||||
p.conf.HLSSegmentMaxSize,
|
||||
p.conf.HLSAllowOrigin,
|
||||
p.conf.ReadBufferCount,
|
||||
p.pathManager,
|
||||
|
|
@ -481,6 +482,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
|
|||
newConf.HLSAlwaysRemux != p.conf.HLSAlwaysRemux ||
|
||||
newConf.HLSSegmentCount != p.conf.HLSSegmentCount ||
|
||||
newConf.HLSSegmentDuration != p.conf.HLSSegmentDuration ||
|
||||
newConf.HLSSegmentMaxSize != p.conf.HLSSegmentMaxSize ||
|
||||
newConf.HLSAllowOrigin != p.conf.HLSAllowOrigin ||
|
||||
newConf.ReadBufferCount != p.conf.ReadBufferCount ||
|
||||
closePathManager ||
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ type hlsMuxer struct {
|
|||
hlsAlwaysRemux bool
|
||||
hlsSegmentCount int
|
||||
hlsSegmentDuration conf.StringDuration
|
||||
hlsSegmentMaxSize conf.StringSize
|
||||
readBufferCount int
|
||||
wg *sync.WaitGroup
|
||||
pathName string
|
||||
|
|
@ -153,6 +154,7 @@ func newHLSMuxer(
|
|||
hlsAlwaysRemux bool,
|
||||
hlsSegmentCount int,
|
||||
hlsSegmentDuration conf.StringDuration,
|
||||
hlsSegmentMaxSize conf.StringSize,
|
||||
readBufferCount int,
|
||||
wg *sync.WaitGroup,
|
||||
pathName string,
|
||||
|
|
@ -166,6 +168,7 @@ func newHLSMuxer(
|
|||
hlsAlwaysRemux: hlsAlwaysRemux,
|
||||
hlsSegmentCount: hlsSegmentCount,
|
||||
hlsSegmentDuration: hlsSegmentDuration,
|
||||
hlsSegmentMaxSize: hlsSegmentMaxSize,
|
||||
readBufferCount: readBufferCount,
|
||||
wg: wg,
|
||||
pathName: pathName,
|
||||
|
|
@ -313,6 +316,7 @@ func (m *hlsMuxer) runInner(innerCtx context.Context, innerReady chan struct{})
|
|||
m.muxer, err = hls.NewMuxer(
|
||||
m.hlsSegmentCount,
|
||||
time.Duration(m.hlsSegmentDuration),
|
||||
uint64(m.hlsSegmentMaxSize),
|
||||
videoTrack,
|
||||
audioTrack,
|
||||
)
|
||||
|
|
@ -356,7 +360,8 @@ func (m *hlsMuxer) runInner(innerCtx context.Context, innerReady chan struct{})
|
|||
|
||||
err = m.muxer.WriteH264(pts, nalus)
|
||||
if err != nil {
|
||||
return err
|
||||
m.log(logger.Warn, "unable to write segment: %v", err)
|
||||
continue
|
||||
}
|
||||
} else if audioTrack != nil && pair.trackID == audioTrackID {
|
||||
var pkt rtp.Packet
|
||||
|
|
@ -376,7 +381,8 @@ func (m *hlsMuxer) runInner(innerCtx context.Context, innerReady chan struct{})
|
|||
|
||||
err = m.muxer.WriteAAC(pts, aus)
|
||||
if err != nil {
|
||||
return err
|
||||
m.log(logger.Warn, "unable to write segment: %v", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ type hlsServer struct {
|
|||
hlsAlwaysRemux bool
|
||||
hlsSegmentCount int
|
||||
hlsSegmentDuration conf.StringDuration
|
||||
hlsSegmentMaxSize conf.StringSize
|
||||
hlsAllowOrigin string
|
||||
readBufferCount int
|
||||
pathManager *pathManager
|
||||
|
|
@ -75,6 +76,7 @@ func newHLSServer(
|
|||
hlsAlwaysRemux bool,
|
||||
hlsSegmentCount int,
|
||||
hlsSegmentDuration conf.StringDuration,
|
||||
hlsSegmentMaxSize conf.StringSize,
|
||||
hlsAllowOrigin string,
|
||||
readBufferCount int,
|
||||
pathManager *pathManager,
|
||||
|
|
@ -93,6 +95,7 @@ func newHLSServer(
|
|||
hlsAlwaysRemux: hlsAlwaysRemux,
|
||||
hlsSegmentCount: hlsSegmentCount,
|
||||
hlsSegmentDuration: hlsSegmentDuration,
|
||||
hlsSegmentMaxSize: hlsSegmentMaxSize,
|
||||
hlsAllowOrigin: hlsAllowOrigin,
|
||||
readBufferCount: readBufferCount,
|
||||
pathManager: pathManager,
|
||||
|
|
@ -275,6 +278,7 @@ func (s *hlsServer) findOrCreateMuxer(pathName string) *hlsMuxer {
|
|||
s.hlsAlwaysRemux,
|
||||
s.hlsSegmentCount,
|
||||
s.hlsSegmentDuration,
|
||||
s.hlsSegmentMaxSize,
|
||||
s.readBufferCount,
|
||||
&s.wg,
|
||||
pathName,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"context"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
|
|
@ -19,6 +20,12 @@ import (
|
|||
"github.com/aler9/rtsp-simple-server/internal/logger"
|
||||
)
|
||||
|
||||
type testLogger struct{}
|
||||
|
||||
func (testLogger) Log(level logger.Level, format string, args ...interface{}) {
|
||||
log.Printf(format, args...)
|
||||
}
|
||||
|
||||
var serverCert = []byte(`-----BEGIN CERTIFICATE-----
|
||||
MIIDazCCAlOgAwIBAgIUXw1hEC3LFpTsllv7D3ARJyEq7sIwDQYJKoZIhvcNAQEL
|
||||
BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
|
||||
|
|
@ -179,10 +186,6 @@ func (ts *testHLSServer) close() {
|
|||
ts.s.Shutdown(context.Background())
|
||||
}
|
||||
|
||||
type testClientParent struct{}
|
||||
|
||||
func (testClientParent) Log(level logger.Level, format string, args ...interface{}) {}
|
||||
|
||||
func TestClient(t *testing.T) {
|
||||
for _, mode := range []string{"plain", "tls"} {
|
||||
t.Run(mode, func(t *testing.T) {
|
||||
|
|
@ -208,7 +211,7 @@ func TestClient(t *testing.T) {
|
|||
require.Equal(t, byte(0x05), byts[12])
|
||||
close(packetRecv)
|
||||
},
|
||||
testClientParent{},
|
||||
testLogger{},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ type Muxer struct {
|
|||
func NewMuxer(
|
||||
hlsSegmentCount int,
|
||||
hlsSegmentDuration time.Duration,
|
||||
hlsSegmentMaxSize uint64,
|
||||
videoTrack *gortsplib.TrackH264,
|
||||
audioTrack *gortsplib.TrackAAC) (*Muxer, error) {
|
||||
if videoTrack != nil {
|
||||
|
|
@ -34,6 +35,7 @@ func NewMuxer(
|
|||
tsGenerator := newMuxerTSGenerator(
|
||||
hlsSegmentCount,
|
||||
hlsSegmentDuration,
|
||||
hlsSegmentMaxSize,
|
||||
videoTrack,
|
||||
audioTrack,
|
||||
streamPlaylist)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ func TestMuxerVideoAudio(t *testing.T) {
|
|||
audioTrack, err := gortsplib.NewTrackAAC(97, 2, 44100, 2, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
m, err := NewMuxer(3, 1*time.Second, videoTrack, audioTrack)
|
||||
m, err := NewMuxer(3, 1*time.Second, 50*1024*1024, videoTrack, audioTrack)
|
||||
require.NoError(t, err)
|
||||
defer m.Close()
|
||||
|
||||
|
|
@ -130,7 +130,7 @@ func TestMuxerAudio(t *testing.T) {
|
|||
audioTrack, err := gortsplib.NewTrackAAC(97, 2, 44100, 2, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
m, err := NewMuxer(3, 1*time.Second, nil, audioTrack)
|
||||
m, err := NewMuxer(3, 1*time.Second, 50*1024*1024, nil, audioTrack)
|
||||
require.NoError(t, err)
|
||||
defer m.Close()
|
||||
|
||||
|
|
@ -178,7 +178,7 @@ func TestMuxerCloseBeforeFirstSegment(t *testing.T) {
|
|||
videoTrack, err := gortsplib.NewTrackH264(96, []byte{0x07, 0x01, 0x02, 0x03}, []byte{0x08}, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
m, err := NewMuxer(3, 1*time.Second, videoTrack, nil)
|
||||
m, err := NewMuxer(3, 1*time.Second, 50*1024*1024, videoTrack, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
// group with IDR
|
||||
|
|
@ -196,3 +196,45 @@ func TestMuxerCloseBeforeFirstSegment(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, []byte{}, byts)
|
||||
}
|
||||
|
||||
func TestMuxerMaxSegmentSize(t *testing.T) {
|
||||
videoTrack, err := gortsplib.NewTrackH264(96,[]byte{0x07, 0x01, 0x02, 0x03}, []byte{0x08}, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
m, err := NewMuxer(3, 1*time.Second, 0, videoTrack, nil)
|
||||
require.NoError(t, err)
|
||||
defer m.Close()
|
||||
|
||||
err = m.WriteH264(2*time.Second, [][]byte{
|
||||
{5},
|
||||
})
|
||||
require.EqualError(t, err, "reached maximum segment size")
|
||||
}
|
||||
|
||||
func TestMuxerDoubleRead(t *testing.T) {
|
||||
videoTrack, err := gortsplib.NewTrackH264(96, []byte{0x07, 0x01, 0x02, 0x03}, []byte{0x08}, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
m, err := NewMuxer(3, 1*time.Second, 50*1024*1024, videoTrack, nil)
|
||||
require.NoError(t, err)
|
||||
defer m.Close()
|
||||
|
||||
err = m.WriteH264(0, [][]byte{
|
||||
{5},
|
||||
{1},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
err = m.WriteH264(2*time.Second, [][]byte{
|
||||
{5},
|
||||
{2},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
byts1, err := ioutil.ReadAll(m.streamPlaylist.segments[0].reader())
|
||||
require.NoError(t, err)
|
||||
|
||||
byts2, err := ioutil.ReadAll(m.streamPlaylist.segments[0].reader())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, byts1, byts2)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ func idrPresent(nalus [][]byte) bool {
|
|||
type muxerTSGenerator struct {
|
||||
hlsSegmentCount int
|
||||
hlsSegmentDuration time.Duration
|
||||
hlsSegmentMaxSize uint64
|
||||
videoTrack *gortsplib.TrackH264
|
||||
audioTrack *gortsplib.TrackAAC
|
||||
streamPlaylist *muxerStreamPlaylist
|
||||
|
|
@ -35,7 +36,6 @@ type muxerTSGenerator struct {
|
|||
writer *muxerTSWriter
|
||||
currentSegment *muxerTSSegment
|
||||
videoDTSEst *h264.DTSEstimator
|
||||
audioAUCount int
|
||||
startPCR time.Time
|
||||
startPTS time.Duration
|
||||
}
|
||||
|
|
@ -43,6 +43,7 @@ type muxerTSGenerator struct {
|
|||
func newMuxerTSGenerator(
|
||||
hlsSegmentCount int,
|
||||
hlsSegmentDuration time.Duration,
|
||||
hlsSegmentMaxSize uint64,
|
||||
videoTrack *gortsplib.TrackH264,
|
||||
audioTrack *gortsplib.TrackAAC,
|
||||
streamPlaylist *muxerStreamPlaylist,
|
||||
|
|
@ -50,6 +51,7 @@ func newMuxerTSGenerator(
|
|||
m := &muxerTSGenerator{
|
||||
hlsSegmentCount: hlsSegmentCount,
|
||||
hlsSegmentDuration: hlsSegmentDuration,
|
||||
hlsSegmentMaxSize: hlsSegmentMaxSize,
|
||||
videoTrack: videoTrack,
|
||||
audioTrack: audioTrack,
|
||||
streamPlaylist: streamPlaylist,
|
||||
|
|
@ -69,7 +71,7 @@ func (m *muxerTSGenerator) writeH264(pts time.Duration, nalus [][]byte) error {
|
|||
}
|
||||
|
||||
// create first segment
|
||||
m.currentSegment = newMuxerTSSegment(m.videoTrack, m.writer)
|
||||
m.currentSegment = newMuxerTSSegment(m.hlsSegmentMaxSize, m.videoTrack, m.writer)
|
||||
m.startPCR = time.Now()
|
||||
m.startPTS = pts
|
||||
m.videoDTSEst = h264.NewDTSEstimator()
|
||||
|
|
@ -83,7 +85,7 @@ func (m *muxerTSGenerator) writeH264(pts time.Duration, nalus [][]byte) error {
|
|||
(pts-*m.currentSegment.startPTS) >= m.hlsSegmentDuration {
|
||||
m.currentSegment.endPTS = pts
|
||||
m.streamPlaylist.pushSegment(m.currentSegment)
|
||||
m.currentSegment = newMuxerTSSegment(m.videoTrack, m.writer)
|
||||
m.currentSegment = newMuxerTSSegment(m.hlsSegmentMaxSize, m.videoTrack, m.writer)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -111,17 +113,30 @@ func (m *muxerTSGenerator) writeH264(pts time.Duration, nalus [][]byte) error {
|
|||
|
||||
enc, err := h264.EncodeAnnexB(filteredNALUs)
|
||||
if err != nil {
|
||||
if m.currentSegment.buf.Len() > 0 {
|
||||
m.streamPlaylist.pushSegment(m.currentSegment)
|
||||
}
|
||||
m.currentSegment = nil
|
||||
return err
|
||||
}
|
||||
|
||||
return m.currentSegment.writeH264(m.startPCR, dts, pts, idrPresent, enc)
|
||||
err = m.currentSegment.writeH264(m.startPCR, dts, pts, idrPresent, enc)
|
||||
if err != nil {
|
||||
if m.currentSegment.buf.Len() > 0 {
|
||||
m.streamPlaylist.pushSegment(m.currentSegment)
|
||||
}
|
||||
m.currentSegment = nil
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *muxerTSGenerator) writeAAC(pts time.Duration, aus [][]byte) error {
|
||||
if m.videoTrack == nil {
|
||||
if m.currentSegment == nil {
|
||||
// create first segment
|
||||
m.currentSegment = newMuxerTSSegment(m.videoTrack, m.writer)
|
||||
m.currentSegment = newMuxerTSSegment(m.hlsSegmentMaxSize, m.videoTrack, m.writer)
|
||||
m.startPCR = time.Now()
|
||||
m.startPTS = pts
|
||||
pts = pcrOffset
|
||||
|
|
@ -129,13 +144,12 @@ func (m *muxerTSGenerator) writeAAC(pts time.Duration, aus [][]byte) error {
|
|||
pts = pts - m.startPTS + pcrOffset
|
||||
|
||||
// switch segment
|
||||
if m.audioAUCount >= segmentMinAUCount &&
|
||||
if m.currentSegment.audioAUCount >= segmentMinAUCount &&
|
||||
m.currentSegment.startPTS != nil &&
|
||||
(pts-*m.currentSegment.startPTS) >= m.hlsSegmentDuration {
|
||||
m.audioAUCount = 0
|
||||
m.currentSegment.endPTS = pts
|
||||
m.streamPlaylist.pushSegment(m.currentSegment)
|
||||
m.currentSegment = newMuxerTSSegment(m.videoTrack, m.writer)
|
||||
m.currentSegment = newMuxerTSSegment(m.hlsSegmentMaxSize, m.videoTrack, m.writer)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -163,14 +177,14 @@ func (m *muxerTSGenerator) writeAAC(pts time.Duration, aus [][]byte) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = m.currentSegment.writeAAC(m.startPCR, pts, enc)
|
||||
err = m.currentSegment.writeAAC(m.startPCR, pts, enc, len(aus))
|
||||
if err != nil {
|
||||
if m.currentSegment.buf.Len() > 0 {
|
||||
m.streamPlaylist.pushSegment(m.currentSegment)
|
||||
}
|
||||
m.currentSegment = nil
|
||||
return err
|
||||
}
|
||||
|
||||
if m.videoTrack == nil {
|
||||
m.audioAUCount += len(aus)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package hls
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"time"
|
||||
|
|
@ -11,6 +12,7 @@ import (
|
|||
)
|
||||
|
||||
type muxerTSSegment struct {
|
||||
hlsSegmentMaxSize uint64
|
||||
videoTrack gortsplib.Track
|
||||
writer *muxerTSWriter
|
||||
|
||||
|
|
@ -19,16 +21,19 @@ type muxerTSSegment struct {
|
|||
startPTS *time.Duration
|
||||
endPTS time.Duration
|
||||
pcrSendCounter int
|
||||
audioAUCount int
|
||||
}
|
||||
|
||||
func newMuxerTSSegment(
|
||||
hlsSegmentMaxSize uint64,
|
||||
videoTrack gortsplib.Track,
|
||||
writer *muxerTSWriter,
|
||||
) *muxerTSSegment {
|
||||
t := &muxerTSSegment{
|
||||
videoTrack: videoTrack,
|
||||
writer: writer,
|
||||
name: strconv.FormatInt(time.Now().Unix(), 10),
|
||||
hlsSegmentMaxSize: hlsSegmentMaxSize,
|
||||
videoTrack: videoTrack,
|
||||
writer: writer,
|
||||
name: strconv.FormatInt(time.Now().Unix(), 10),
|
||||
}
|
||||
|
||||
// WriteTable() is called automatically when WriteData() is called with
|
||||
|
|
@ -46,6 +51,10 @@ func (t *muxerTSSegment) duration() time.Duration {
|
|||
}
|
||||
|
||||
func (t *muxerTSSegment) write(p []byte) (int, error) {
|
||||
if uint64(len(p)+t.buf.Len()) > t.hlsSegmentMaxSize {
|
||||
return 0, fmt.Errorf("reached maximum segment size")
|
||||
}
|
||||
|
||||
return t.buf.Write(p)
|
||||
}
|
||||
|
||||
|
|
@ -59,10 +68,6 @@ func (t *muxerTSSegment) writeH264(
|
|||
pts time.Duration,
|
||||
idrPresent bool,
|
||||
enc []byte) error {
|
||||
if t.startPTS == nil {
|
||||
t.startPTS = &pts
|
||||
}
|
||||
|
||||
var af *astits.PacketAdaptationField
|
||||
|
||||
if idrPresent {
|
||||
|
|
@ -107,22 +112,26 @@ func (t *muxerTSSegment) writeH264(
|
|||
Data: enc,
|
||||
},
|
||||
})
|
||||
return err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if t.startPTS == nil {
|
||||
t.startPTS = &pts
|
||||
}
|
||||
t.endPTS = pts // save endPTS in case next write fails
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *muxerTSSegment) writeAAC(
|
||||
startPCR time.Time,
|
||||
pts time.Duration,
|
||||
enc []byte) error {
|
||||
if t.startPTS == nil {
|
||||
t.startPTS = &pts
|
||||
}
|
||||
|
||||
enc []byte,
|
||||
ausLen int) error {
|
||||
af := &astits.PacketAdaptationField{
|
||||
RandomAccessIndicator: true,
|
||||
}
|
||||
|
||||
// if audio is the only track
|
||||
if t.videoTrack == nil {
|
||||
// send PCR once in a while
|
||||
if t.pcrSendCounter == 0 {
|
||||
|
|
@ -148,5 +157,17 @@ func (t *muxerTSSegment) writeAAC(
|
|||
Data: enc,
|
||||
},
|
||||
})
|
||||
return err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if t.videoTrack == nil {
|
||||
t.audioAUCount += ausLen
|
||||
}
|
||||
|
||||
if t.startPTS == nil {
|
||||
t.startPTS = &pts
|
||||
}
|
||||
t.endPTS = pts // save endPTS in case next write fails
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,6 +124,9 @@ hlsSegmentCount: 3
|
|||
# The final segment duration is also influenced by the interval between IDR frames,
|
||||
# since the server changes the segment duration to include at least a IDR frame in each one.
|
||||
hlsSegmentDuration: 1s
|
||||
# Maximum size of each segment.
|
||||
# This prevents RAM exhaustion.
|
||||
hlsSegmentMaxSize: 50M
|
||||
# Value of the Access-Control-Allow-Origin header provided in every HTTP response.
|
||||
# This allows to play the HLS stream from an external website.
|
||||
hlsAllowOrigin: '*'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue