Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apidocs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ components:
type: boolean
runOnDisconnect:
type: string
gopCache:
type: boolean

# Authentication
authMethod:
Expand Down
1 change: 1 addition & 0 deletions internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ type Conf struct {
RunOnConnect string `json:"runOnConnect"`
RunOnConnectRestart bool `json:"runOnConnectRestart"`
RunOnDisconnect string `json:"runOnDisconnect"`
GopCache bool `json:"gopCache"`

// Authentication
AuthMethod AuthMethod `json:"authMethod"`
Expand Down
2 changes: 2 additions & 0 deletions internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ func (p *Core) createResources(initial bool) error {
pathConfs: p.conf.Paths,
externalCmdPool: p.externalCmdPool,
parent: p,
gopCache: p.conf.GopCache,
}
p.pathManager.initialize()

Expand Down Expand Up @@ -715,6 +716,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
newConf.WriteTimeout != p.conf.WriteTimeout ||
newConf.WriteQueueSize != p.conf.WriteQueueSize ||
newConf.UDPMaxPayloadSize != p.conf.UDPMaxPayloadSize ||
newConf.GopCache != p.conf.GopCache ||
closeMetrics ||
closeAuthManager ||
closeLogger
Expand Down
2 changes: 2 additions & 0 deletions internal/core/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type path struct {
wg *sync.WaitGroup
externalCmdPool *externalcmd.Pool
parent pathParent
gopCache bool

ctx context.Context
ctxCancel func()
Expand Down Expand Up @@ -701,6 +702,7 @@ func (pa *path) setReady(desc *description.Session, allocateEncoder bool) error
Desc: desc,
GenerateRTPPackets: allocateEncoder,
DecodeErrLogger: logger.NewLimitedLogger(pa.source),
GopCache: pa.gopCache,
}
err := pa.stream.Initialize()
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/core/path_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type pathManager struct {
pathConfs map[string]*conf.Path
externalCmdPool *externalcmd.Pool
parent pathManagerParent
gopCache bool

ctx context.Context
ctxCancel func()
Expand Down Expand Up @@ -352,6 +353,7 @@ func (pm *pathManager) createPath(
wg: &pm.wg,
externalCmdPool: pm.externalCmdPool,
parent: pm,
gopCache: pm.gopCache,
}
pa.initialize()

Expand Down
22 changes: 22 additions & 0 deletions internal/servers/rtsp/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/base"
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/google/uuid"
"github.com/pion/rtp"

Expand Down Expand Up @@ -250,6 +251,27 @@ func (s *session) onPlay(_ *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, e
s.state = gortsplib.ServerSessionStatePlay
s.transport = s.rsession.SetuppedTransport()
s.mutex.Unlock()

if len(s.stream.CachedUnits) > 0 {
lastCachedUnits := s.stream.CachedUnits[len(s.stream.CachedUnits)-1]
rtpPackets := lastCachedUnits.GetRTPPackets()
if len(rtpPackets) > 0 {
lastTimestamp := rtpPackets[0].Timestamp
for _, medi := range s.stream.Desc.Medias {
if medi.Type == description.MediaTypeVideo {
for _, u := range s.stream.CachedUnits {
for _, pkt := range u.GetRTPPackets() {
pkt.Timestamp = lastTimestamp
err := s.rsession.WritePacketRTP(medi, pkt)
if err != nil {
break
}
}
}
}
}
}
}
}

return &base.Response{
Expand Down
Loading