mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-05 15:46:58 +08:00
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:
@@ -170,12 +170,15 @@ func (s *rtmpSource) run(ctx context.Context) error {
|
||||
return fmt.Errorf("unable to decode AVCC: %v", err)
|
||||
}
|
||||
|
||||
res.stream.writeData(&data{
|
||||
err = res.stream.writeData(&dataH264{
|
||||
trackID: videoTrackID,
|
||||
ptsEqualsDTS: h264.IDRPresent(nalus),
|
||||
pts: tmsg.DTS + tmsg.PTSDelta,
|
||||
h264NALUs: nalus,
|
||||
nalus: nalus,
|
||||
})
|
||||
if err != nil {
|
||||
s.Log(logger.Warn, "%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
case *message.MsgAudio:
|
||||
@@ -184,12 +187,14 @@ func (s *rtmpSource) run(ctx context.Context) error {
|
||||
return fmt.Errorf("received an AAC packet, but track is not set up")
|
||||
}
|
||||
|
||||
res.stream.writeData(&data{
|
||||
trackID: audioTrackID,
|
||||
ptsEqualsDTS: true,
|
||||
pts: tmsg.DTS,
|
||||
mpeg4AudioAU: tmsg.Payload,
|
||||
err := res.stream.writeData(&dataMPEG4Audio{
|
||||
trackID: audioTrackID,
|
||||
pts: tmsg.DTS,
|
||||
aus: [][]byte{tmsg.Payload},
|
||||
})
|
||||
if err != nil {
|
||||
s.Log(logger.Warn, "%v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user