mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-23 07:39:32 +08:00
update gohlslib (#1566)
This commit is contained in:
@@ -1162,6 +1162,7 @@ Related projects
|
|||||||
* pion/sdp (SDP library used internally) https://github.com/pion/sdp
|
* pion/sdp (SDP library used internally) https://github.com/pion/sdp
|
||||||
* pion/rtp (RTP library used internally) https://github.com/pion/rtp
|
* pion/rtp (RTP library used internally) https://github.com/pion/rtp
|
||||||
* pion/rtcp (RTCP library used internally) https://github.com/pion/rtcp
|
* pion/rtcp (RTCP library used internally) https://github.com/pion/rtcp
|
||||||
|
* pion/webrtc (WebRTC library used internally) https://github.com/pion/webrtc
|
||||||
* notedit/rtmp (RTMP library used internally) https://github.com/notedit/rtmp
|
* notedit/rtmp (RTMP library used internally) https://github.com/notedit/rtmp
|
||||||
* go-astits (MPEG-TS library used internally) https://github.com/asticode/go-astits
|
* go-astits (MPEG-TS library used internally) https://github.com/asticode/go-astits
|
||||||
* go-mp4 (MP4 library used internally) https://github.com/abema/go-mp4
|
* go-mp4 (MP4 library used internally) https://github.com/abema/go-mp4
|
||||||
|
2
go.mod
2
go.mod
@@ -7,7 +7,7 @@ require (
|
|||||||
github.com/alecthomas/kong v0.7.1
|
github.com/alecthomas/kong v0.7.1
|
||||||
github.com/aler9/gortsplib/v2 v2.1.4
|
github.com/aler9/gortsplib/v2 v2.1.4
|
||||||
github.com/asticode/go-astits v1.11.0
|
github.com/asticode/go-astits v1.11.0
|
||||||
github.com/bluenviron/gohlslib v0.0.0-20230312114838-5feec7e35841
|
github.com/bluenviron/gohlslib v0.0.0-20230312151707-933e641d84aa
|
||||||
github.com/fsnotify/fsnotify v1.4.9
|
github.com/fsnotify/fsnotify v1.4.9
|
||||||
github.com/gin-gonic/gin v1.9.0
|
github.com/gin-gonic/gin v1.9.0
|
||||||
github.com/google/uuid v1.3.0
|
github.com/google/uuid v1.3.0
|
||||||
|
4
go.sum
4
go.sum
@@ -12,8 +12,8 @@ github.com/asticode/go-astikit v0.30.0 h1:DkBkRQRIxYcknlaU7W7ksNfn4gMFsB0tqMJflx
|
|||||||
github.com/asticode/go-astikit v0.30.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0=
|
github.com/asticode/go-astikit v0.30.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0=
|
||||||
github.com/asticode/go-astits v1.11.0 h1:GTHUXht0ZXAJXsVbsLIcyfHr1Bchi4QQwMARw2ZWAng=
|
github.com/asticode/go-astits v1.11.0 h1:GTHUXht0ZXAJXsVbsLIcyfHr1Bchi4QQwMARw2ZWAng=
|
||||||
github.com/asticode/go-astits v1.11.0/go.mod h1:QSHmknZ51pf6KJdHKZHJTLlMegIrhega3LPWz3ND/iI=
|
github.com/asticode/go-astits v1.11.0/go.mod h1:QSHmknZ51pf6KJdHKZHJTLlMegIrhega3LPWz3ND/iI=
|
||||||
github.com/bluenviron/gohlslib v0.0.0-20230312114838-5feec7e35841 h1:J5AIpE6ue/l/IgIlLCi/QQJL2MNBTFQrAkDScGbUaDs=
|
github.com/bluenviron/gohlslib v0.0.0-20230312151707-933e641d84aa h1:zvGhswcO4E4B9k8+Jx7l+KERoKoQsxGFdMubsf8PVg4=
|
||||||
github.com/bluenviron/gohlslib v0.0.0-20230312114838-5feec7e35841/go.mod h1:SYixOK6Kux6cA9AGR1sg1GJdU2TmYiccVpPmS/Rxdt0=
|
github.com/bluenviron/gohlslib v0.0.0-20230312151707-933e641d84aa/go.mod h1:SYixOK6Kux6cA9AGR1sg1GJdU2TmYiccVpPmS/Rxdt0=
|
||||||
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
|
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
|
||||||
github.com/bytedance/sonic v1.8.0 h1:ea0Xadu+sHlu7x5O3gKhRpQ1IKiMrSiHttPF0ybECuA=
|
github.com/bytedance/sonic v1.8.0 h1:ea0Xadu+sHlu7x5O3gKhRpQ1IKiMrSiHttPF0ybECuA=
|
||||||
github.com/bytedance/sonic v1.8.0/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
|
github.com/bytedance/sonic v1.8.0/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
|
||||||
|
@@ -8,13 +8,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// HLSVariant is the hlsVariant parameter.
|
// HLSVariant is the hlsVariant parameter.
|
||||||
type HLSVariant hls.MuxerVariant
|
type HLSVariant gohlslib.MuxerVariant
|
||||||
|
|
||||||
// supported HLS variants.
|
// supported HLS variants.
|
||||||
const (
|
const (
|
||||||
HLSVariantMPEGTS HLSVariant = HLSVariant(hls.MuxerVariantMPEGTS)
|
HLSVariantMPEGTS HLSVariant = HLSVariant(gohlslib.MuxerVariantMPEGTS)
|
||||||
HLSVariantFMP4 HLSVariant = HLSVariant(hls.MuxerVariantFMP4)
|
HLSVariantFMP4 HLSVariant = HLSVariant(gohlslib.MuxerVariantFMP4)
|
||||||
HLSVariantLowLatency HLSVariant = HLSVariant(hls.MuxerVariantLowLatency)
|
HLSVariantLowLatency HLSVariant = HLSVariant(gohlslib.MuxerVariantLowLatency)
|
||||||
)
|
)
|
||||||
|
|
||||||
// MarshalJSON implements json.Marshaler.
|
// MarshalJSON implements json.Marshaler.
|
||||||
|
@@ -36,7 +36,7 @@ var hlsIndex []byte
|
|||||||
|
|
||||||
type hlsMuxerResponse struct {
|
type hlsMuxerResponse struct {
|
||||||
muxer *hlsMuxer
|
muxer *hlsMuxer
|
||||||
cb func() *hls.MuxerFileResponse
|
cb func() *gohlslib.MuxerFileResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
type hlsMuxerRequest struct {
|
type hlsMuxerRequest struct {
|
||||||
@@ -77,7 +77,7 @@ type hlsMuxer struct {
|
|||||||
path *path
|
path *path
|
||||||
ringBuffer *ringbuffer.RingBuffer
|
ringBuffer *ringbuffer.RingBuffer
|
||||||
lastRequestTime *int64
|
lastRequestTime *int64
|
||||||
muxer *hls.Muxer
|
muxer *gohlslib.Muxer
|
||||||
requests []*hlsMuxerRequest
|
requests []*hlsMuxerRequest
|
||||||
bytesSent *uint64
|
bytesSent *uint64
|
||||||
|
|
||||||
@@ -296,17 +296,17 @@ func (m *hlsMuxer) runInner(innerCtx context.Context, innerReady chan struct{})
|
|||||||
"the stream doesn't contain any supported codec (which are currently H264, H265, MPEG4-Audio, Opus)")
|
"the stream doesn't contain any supported codec (which are currently H264, H265, MPEG4-Audio, Opus)")
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
m.muxer = &gohlslib.Muxer{
|
||||||
m.muxer, err = hls.NewMuxer(
|
Variant: gohlslib.MuxerVariant(m.variant),
|
||||||
hls.MuxerVariant(m.variant),
|
SegmentCount: m.segmentCount,
|
||||||
m.segmentCount,
|
SegmentDuration: time.Duration(m.segmentDuration),
|
||||||
time.Duration(m.segmentDuration),
|
PartDuration: time.Duration(m.partDuration),
|
||||||
time.Duration(m.partDuration),
|
SegmentMaxSize: uint64(m.segmentMaxSize),
|
||||||
uint64(m.segmentMaxSize),
|
VideoTrack: videoFormat,
|
||||||
videoFormat,
|
AudioTrack: audioFormat,
|
||||||
audioFormat,
|
}
|
||||||
"",
|
|
||||||
)
|
err := m.muxer.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("muxer error: %v", err)
|
return fmt.Errorf("muxer error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -507,15 +507,15 @@ func (m *hlsMuxer) runWriter() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *hlsMuxer) handleRequest(req *hlsMuxerRequest) func() *hls.MuxerFileResponse {
|
func (m *hlsMuxer) handleRequest(req *hlsMuxerRequest) func() *gohlslib.MuxerFileResponse {
|
||||||
atomic.StoreInt64(m.lastRequestTime, time.Now().UnixNano())
|
atomic.StoreInt64(m.lastRequestTime, time.Now().UnixNano())
|
||||||
|
|
||||||
err := m.authenticate(req.ctx)
|
err := m.authenticate(req.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if terr, ok := err.(pathErrAuthCritical); ok {
|
if terr, ok := err.(pathErrAuthCritical); ok {
|
||||||
m.log(logger.Info, "authentication error: %s", terr.message)
|
m.log(logger.Info, "authentication error: %s", terr.message)
|
||||||
return func() *hls.MuxerFileResponse {
|
return func() *gohlslib.MuxerFileResponse {
|
||||||
return &hls.MuxerFileResponse{
|
return &gohlslib.MuxerFileResponse{
|
||||||
Status: http.StatusUnauthorized,
|
Status: http.StatusUnauthorized,
|
||||||
Header: map[string]string{
|
Header: map[string]string{
|
||||||
"WWW-Authenticate": `Basic realm="rtsp-simple-server"`,
|
"WWW-Authenticate": `Basic realm="rtsp-simple-server"`,
|
||||||
@@ -524,8 +524,8 @@ func (m *hlsMuxer) handleRequest(req *hlsMuxerRequest) func() *hls.MuxerFileResp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return func() *hls.MuxerFileResponse {
|
return func() *gohlslib.MuxerFileResponse {
|
||||||
return &hls.MuxerFileResponse{
|
return &gohlslib.MuxerFileResponse{
|
||||||
Status: http.StatusUnauthorized,
|
Status: http.StatusUnauthorized,
|
||||||
Header: map[string]string{
|
Header: map[string]string{
|
||||||
"WWW-Authenticate": `Basic realm="rtsp-simple-server"`,
|
"WWW-Authenticate": `Basic realm="rtsp-simple-server"`,
|
||||||
@@ -535,8 +535,8 @@ func (m *hlsMuxer) handleRequest(req *hlsMuxerRequest) func() *hls.MuxerFileResp
|
|||||||
}
|
}
|
||||||
|
|
||||||
if req.file == "" {
|
if req.file == "" {
|
||||||
return func() *hls.MuxerFileResponse {
|
return func() *gohlslib.MuxerFileResponse {
|
||||||
return &hls.MuxerFileResponse{
|
return &gohlslib.MuxerFileResponse{
|
||||||
Status: http.StatusOK,
|
Status: http.StatusOK,
|
||||||
Header: map[string]string{
|
Header: map[string]string{
|
||||||
"Content-Type": `text/html`,
|
"Content-Type": `text/html`,
|
||||||
@@ -546,7 +546,7 @@ func (m *hlsMuxer) handleRequest(req *hlsMuxerRequest) func() *hls.MuxerFileResp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return func() *hls.MuxerFileResponse {
|
return func() *gohlslib.MuxerFileResponse {
|
||||||
return m.muxer.File(
|
return m.muxer.File(
|
||||||
req.file,
|
req.file,
|
||||||
req.ctx.Query("_HLS_msn"),
|
req.ctx.Query("_HLS_msn"),
|
||||||
|
@@ -52,13 +52,10 @@ func (s *hlsSource) run(ctx context.Context, cnf *conf.PathConf, reloadConf chan
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
c, err := hls.NewClient(
|
c := &gohlslib.Client{
|
||||||
cnf.Source,
|
URI: cnf.Source,
|
||||||
cnf.SourceFingerprint,
|
Fingerprint: cnf.SourceFingerprint,
|
||||||
hlsLoggerWrapper(s.Log),
|
Logger: hlsLoggerWrapper(s.Log),
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.OnTracks(func(tracks []format.Format) error {
|
c.OnTracks(func(tracks []format.Format) error {
|
||||||
@@ -144,11 +141,15 @@ func (s *hlsSource) run(ctx context.Context, cnf *conf.PathConf, reloadConf chan
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
c.Start()
|
err := c.Start()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case err := <-c.Wait():
|
case err := <-c.Wait():
|
||||||
|
c.Close()
|
||||||
return err
|
return err
|
||||||
|
|
||||||
case <-reloadConf:
|
case <-reloadConf:
|
||||||
|
@@ -2,6 +2,7 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -58,18 +59,23 @@ func newWebRTCTestClient(addr string) (*webRTCTestClient, error) {
|
|||||||
|
|
||||||
connected := make(chan struct{})
|
connected := make(chan struct{})
|
||||||
closed := make(chan struct{})
|
closed := make(chan struct{})
|
||||||
|
var stateChangeMutex sync.Mutex
|
||||||
|
|
||||||
pc.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
|
pc.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
|
||||||
|
stateChangeMutex.Lock()
|
||||||
|
defer stateChangeMutex.Unlock()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-closed:
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
switch state {
|
switch state {
|
||||||
case webrtc.PeerConnectionStateConnected:
|
case webrtc.PeerConnectionStateConnected:
|
||||||
close(connected)
|
close(connected)
|
||||||
|
|
||||||
case webrtc.PeerConnectionStateClosed:
|
case webrtc.PeerConnectionStateClosed:
|
||||||
select {
|
|
||||||
case <-closed:
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
close(closed)
|
close(closed)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user