Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

54 lines
1.4 KiB

package streamproc
import (
"github.com/aler9/gortsplib"
"github.com/pion/rtp"
"github.com/aler9/rtsp-simple-server/internal/source"
)
// Path is implemented by path.path.
type Path interface {
OnSetStartingPoint(source.SetStartingPointReq)
OnFrame(int, gortsplib.StreamType, []byte)
}
// StreamProc is a stream processor, an intermediate layer between a source and a path.
type StreamProc struct {
source source.Source
path Path
startingPoints []source.TrackStartingPoint
}
// New allocates a StreamProc.
func New(source source.Source, path Path, startingPoints []source.TrackStartingPoint) *StreamProc {
return &StreamProc{
source: source,
path: path,
startingPoints: startingPoints,
}
}
// OnFrame processes a frame.
func (sp *StreamProc) OnFrame(trackID int, streamType gortsplib.StreamType, payload []byte) {
if streamType == gortsplib.StreamTypeRTP &&
!sp.startingPoints[trackID].Filled {
pkt := rtp.Packet{}
err := pkt.Unmarshal(payload)
if err != nil {
return
}
sp.startingPoints[trackID].Filled = true
sp.startingPoints[trackID].SequenceNumber = pkt.SequenceNumber
sp.startingPoints[trackID].Timestamp = pkt.Timestamp
sp.path.OnSetStartingPoint(source.SetStartingPointReq{
Source: sp.source,
TrackID: trackID,
StartingPoint: sp.startingPoints[trackID],
})
}
sp.path.OnFrame(trackID, streamType, payload)
}