forked from External/mediamtx
Decode streams once and only when needed (#1218)
* split data into specialized structs * move MPEG4-audio decoding into streamTrack * restore video/audio synchronization in HLS muxer and RTMP server * log decode errors * move H264 decoding and re-encoding here from gortsplib * add tests * update gortsplib
This commit is contained in:
parent
bf14467331
commit
0943b269ab
19 changed files with 873 additions and 259 deletions
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"github.com/aler9/gortsplib"
|
||||
"github.com/aler9/gortsplib/pkg/base"
|
||||
"github.com/pion/rtp"
|
||||
|
||||
"github.com/aler9/gortsplib/pkg/url"
|
||||
"github.com/aler9/rtsp-simple-server/internal/conf"
|
||||
|
|
@ -143,20 +144,32 @@ func (s *rtspSource) run(ctx context.Context) error {
|
|||
}()
|
||||
|
||||
c.OnPacketRTP = func(ctx *gortsplib.ClientOnPacketRTPCtx) {
|
||||
if ctx.H264NALUs != nil {
|
||||
res.stream.writeData(&data{
|
||||
var err error
|
||||
|
||||
switch tracks[ctx.TrackID].(type) {
|
||||
case *gortsplib.TrackH264:
|
||||
err = res.stream.writeData(&dataH264{
|
||||
trackID: ctx.TrackID,
|
||||
rtpPacket: ctx.Packet,
|
||||
ptsEqualsDTS: ctx.PTSEqualsDTS,
|
||||
pts: ctx.H264PTS,
|
||||
h264NALUs: ctx.H264NALUs,
|
||||
})
|
||||
} else {
|
||||
res.stream.writeData(&data{
|
||||
trackID: ctx.TrackID,
|
||||
rtpPacket: ctx.Packet,
|
||||
rtpPackets: []*rtp.Packet{ctx.Packet},
|
||||
ptsEqualsDTS: ctx.PTSEqualsDTS,
|
||||
})
|
||||
|
||||
case *gortsplib.TrackMPEG4Audio:
|
||||
err = res.stream.writeData(&dataMPEG4Audio{
|
||||
trackID: ctx.TrackID,
|
||||
rtpPackets: []*rtp.Packet{ctx.Packet},
|
||||
})
|
||||
|
||||
default:
|
||||
err = res.stream.writeData(&dataGeneric{
|
||||
trackID: ctx.TrackID,
|
||||
rtpPackets: []*rtp.Packet{ctx.Packet},
|
||||
ptsEqualsDTS: ctx.PTSEqualsDTS,
|
||||
})
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
s.Log(logger.Warn, "%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue