Browse Source

hls: revert 93b1433 and send PCR once in a while

pull/543/head
aler9 5 years ago
parent
commit
6b6d314a07
  1. 24
      internal/hls/tsfile.go

24
internal/hls/tsfile.go

@ -22,6 +22,7 @@ type tsFile struct {
minPTS time.Duration minPTS time.Duration
maxPTS time.Duration maxPTS time.Duration
startPCR time.Time startPCR time.Time
pcrSendCounter int
} }
func newTSFile(videoTrack *gortsplib.Track, audioTrack *gortsplib.Track) *tsFile { func newTSFile(videoTrack *gortsplib.Track, audioTrack *gortsplib.Track) *tsFile {
@ -127,14 +128,22 @@ func (t *tsFile) writeH264(
var af *astits.PacketAdaptationField var af *astits.PacketAdaptationField
if isIDR { if isIDR {
if af == nil {
af = &astits.PacketAdaptationField{} af = &astits.PacketAdaptationField{}
}
af.RandomAccessIndicator = true af.RandomAccessIndicator = true
}
// send PCR with every IDR // send PCR once in a while
if t.pcrSendCounter == 0 {
if af == nil {
af = &astits.PacketAdaptationField{}
}
af.HasPCR = true af.HasPCR = true
pcr := time.Since(t.startPCR) af.PCR = &astits.ClockReference{Base: int64(time.Since(t.startPCR).Seconds() * 90000)}
af.PCR = &astits.ClockReference{Base: int64(pcr.Seconds() * 90000)} t.pcrSendCounter = 3
} }
t.pcrSendCounter--
oh := &astits.PESOptionalHeader{ oh := &astits.PESOptionalHeader{
MarkerBits: 2, MarkerBits: 2,
@ -194,11 +203,14 @@ func (t *tsFile) writeAAC(sampleRate int, channelCount int, pts time.Duration, a
RandomAccessIndicator: true, RandomAccessIndicator: true,
} }
// if audio is the only track, send PCR with every AU // if audio is the only track
if t.videoTrack == nil { if t.videoTrack == nil {
// send PCR once in a while
if t.pcrSendCounter == 0 {
af.HasPCR = true af.HasPCR = true
pcr := time.Since(t.startPCR) af.PCR = &astits.ClockReference{Base: int64(time.Since(t.startPCR).Seconds() * 90000)}
af.PCR = &astits.ClockReference{Base: int64(pcr.Seconds() * 90000)} t.pcrSendCounter = 3
}
} }
_, err = t.mux.WriteData(&astits.MuxerData{ _, err = t.mux.WriteData(&astits.MuxerData{

Loading…
Cancel
Save