mirror of
https://github.com/langhuihui/monibuca.git
synced 2025-12-24 13:48:04 +08:00
fix: hls no body read
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user