fix: hls no body read

This commit is contained in:
langhuihui
2025-09-22 11:47:25 +08:00
parent e52c37e74e
commit 8280ee95c0
3 changed files with 16 additions and 103 deletions

View File

@@ -2,6 +2,7 @@ package hls
import (
"container/ring"
"errors"
"fmt"
"math"
"strconv"
@@ -24,6 +25,8 @@ func NewTransform() m7s.ITransformer {
return ret
}
var ErrNoBodyRead = errors.New("no body read")
type HLSWriter struct {
m7s.DefaultTransformer
Window int
@@ -49,6 +52,10 @@ func (w *HLSWriter) GetTs(key string) (any, bool) {
return w.memoryTs.Load(key)
}
func (w *HLSWriter) checkNoBodyRead() bool {
return time.Since(w.lastReadTime) > time.Second*15
}
func (w *HLSWriter) Run() (err error) {
if conf, ok := w.TransformJob.Config.Input.(string); ok {
ss := strings.Split(conf, "x")
@@ -86,8 +93,14 @@ func (w *HLSWriter) Run() (err error) {
w.ts.WritePMTPacket(audioCodec, videoCodec)
return m7s.PlayBlock(subscriber, func(audio *format.Mpeg2Audio) error {
pesAudio.Pts = uint64(subscriber.AudioReader.AbsTime) * 90
if w.checkNoBodyRead() {
return ErrNoBodyRead
}
return pesAudio.WritePESPacket(audio.Memory, &w.ts.RecyclableMemory)
}, func(video *mpegts.VideoFrame) (err error) {
if w.checkNoBodyRead() {
return ErrNoBodyRead
}
vr := w.TransformJob.Subscriber.VideoReader
if vr.Value.IDR {
if err = w.checkFragment(video.Timestamp); err != nil {