mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-26 16:42:19 +00:00
hls: fix multiple timestamp issues introduced by previous commits
This commit is contained in:
parent
f952ff25f6
commit
69e617bc73
@ -12,6 +12,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aler9/gortsplib"
|
"github.com/aler9/gortsplib"
|
||||||
|
"github.com/aler9/gortsplib/pkg/mpeg4audio"
|
||||||
"github.com/aler9/gortsplib/pkg/ringbuffer"
|
"github.com/aler9/gortsplib/pkg/ringbuffer"
|
||||||
"github.com/aler9/gortsplib/pkg/rtpmpeg4audio"
|
"github.com/aler9/gortsplib/pkg/rtpmpeg4audio"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -384,8 +385,11 @@ func (m *hlsMuxer) runInner(innerCtx context.Context, innerReady chan struct{})
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, au := range aus {
|
for i, au := range aus {
|
||||||
err = m.muxer.WriteAAC(pts, au)
|
err = m.muxer.WriteAAC(
|
||||||
|
pts+time.Duration(i)*mpeg4audio.SamplesPerAccessUnit*
|
||||||
|
time.Second/time.Duration(audioTrack.ClockRate()),
|
||||||
|
au)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("muxer error: %v", err)
|
return fmt.Errorf("muxer error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -54,9 +54,9 @@ func (t *streamTrackH264) updateTrackParameters(nalus [][]byte) {
|
|||||||
// remux is needed to
|
// remux is needed to
|
||||||
// - fix corrupted streams
|
// - fix corrupted streams
|
||||||
// - make streams compatible with all protocols
|
// - make streams compatible with all protocols
|
||||||
func (t *streamTrackH264) remuxNALUs(dat *data) {
|
func (t *streamTrackH264) remuxNALUs(nalus [][]byte) [][]byte {
|
||||||
n := 0
|
n := 0
|
||||||
for _, nalu := range dat.h264NALUs {
|
for _, nalu := range nalus {
|
||||||
typ := h264.NALUType(nalu[0] & 0x1F)
|
typ := h264.NALUType(nalu[0] & 0x1F)
|
||||||
switch typ {
|
switch typ {
|
||||||
case h264.NALUTypeSPS, h264.NALUTypePPS:
|
case h264.NALUTypeSPS, h264.NALUTypePPS:
|
||||||
@ -69,10 +69,14 @@ func (t *streamTrackH264) remuxNALUs(dat *data) {
|
|||||||
n++
|
n++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if n == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
filteredNALUs := make([][]byte, n)
|
filteredNALUs := make([][]byte, n)
|
||||||
i := 0
|
i := 0
|
||||||
|
|
||||||
for _, nalu := range dat.h264NALUs {
|
for _, nalu := range nalus {
|
||||||
typ := h264.NALUType(nalu[0] & 0x1F)
|
typ := h264.NALUType(nalu[0] & 0x1F)
|
||||||
switch typ {
|
switch typ {
|
||||||
case h264.NALUTypeSPS, h264.NALUTypePPS:
|
case h264.NALUTypeSPS, h264.NALUTypePPS:
|
||||||
@ -95,15 +99,10 @@ func (t *streamTrackH264) remuxNALUs(dat *data) {
|
|||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
dat.h264NALUs = filteredNALUs
|
return filteredNALUs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *streamTrackH264) generateRTPPackets(dat *data) {
|
func (t *streamTrackH264) generateRTPPackets(dat *data) {
|
||||||
// if remuxNALUs() returned nil, do not write any data
|
|
||||||
if dat.h264NALUs == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
pkts, err := t.rtpEncoder.Encode(dat.h264NALUs, dat.pts)
|
pkts, err := t.rtpEncoder.Encode(dat.h264NALUs, dat.pts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -129,12 +128,14 @@ func (t *streamTrackH264) generateRTPPackets(dat *data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *streamTrackH264) writeData(dat *data) {
|
func (t *streamTrackH264) writeData(dat *data) {
|
||||||
t.updateTrackParameters(dat.h264NALUs)
|
if dat.h264NALUs != nil {
|
||||||
t.remuxNALUs(dat)
|
t.updateTrackParameters(dat.h264NALUs)
|
||||||
|
dat.h264NALUs = t.remuxNALUs(dat.h264NALUs)
|
||||||
|
}
|
||||||
|
|
||||||
if dat.rtpPacket != nil {
|
if dat.rtpPacket != nil {
|
||||||
t.writeDataInner(dat)
|
t.writeDataInner(dat)
|
||||||
} else {
|
} else if dat.h264NALUs != nil {
|
||||||
t.generateRTPPackets(dat)
|
t.generateRTPPackets(dat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user