signal "github.com/qydysky/part/signal"
slice "github.com/qydysky/part/slice"
pstring "github.com/qydysky/part/strings"
+ pu "github.com/qydysky/part/util"
pweb "github.com/qydysky/part/web"
)
return e
}
- contextC, done := pctx.WaitCtx(contextC)
+ ctx1, done := pctx.WaitCtx(contextC)
defer done()
+ to := 2.0
+ if tmp, ok := t.common.K_v.LoadV("直播流保存写入超时").(float64); ok && tmp > 2 {
+ to = tmp
+ }
+
_, _ = f.Write(t.getFirstBuf(), true)
cancelRec := t.Stream_msg.Pull_tag(map[string]func([]byte) bool{
`data`: func(b []byte) bool {
+ defer pu.Callback(func(startT time.Time, args ...any) {
+ if dru := time.Since(startT).Seconds(); dru > to {
+ t.log.L("W: ", "磁盘写入超时", dru)
+ done()
+ }
+ })()
+
select {
- case <-contextC.Done():
+ case <-ctx1.Done():
return true
default:
}
if len(b) == 0 {
return true
}
- _, _ = f.Write(b, true)
+ if n, err := f.Write(b, true); err != nil || n == 0 {
+ done()
+ }
return false
},
`close`: func(_ []byte) bool {
return true
},
})
- <-contextC.Done()
+ <-ctx1.Done()
cancelRec()
if e := stopFunc(t); e != nil {
// 流服务推送方法
//
// 在客户端存在某种代理时,将有可能无法监测到客户端关闭,这有可能导致goroutine泄漏
-func (t *M4SStream) PusherToHttp(conn net.Conn, w http.ResponseWriter, r *http.Request, startFunc func(*M4SStream) error, stopFunc func(*M4SStream) error) error {
+func (t *M4SStream) PusherToHttp(plog *log.Log_interface, conn net.Conn, w http.ResponseWriter, r *http.Request, startFunc func(*M4SStream) error, stopFunc func(*M4SStream) error) error {
switch t.stream_type {
case `m3u8`:
fallthrough
return err
}
+ w = pweb.WithCache(w)
+
var cancelRec = t.Stream_msg.Pull_tag(map[string]func([]byte) bool{
`data`: func(b []byte) bool {
select {
if len(b) == 0 {
return true
}
+
_ = conn.SetWriteDeadline(time.Now().Add(time.Second * 30))
if n, err := w.Write(b); err != nil || n == 0 {
+ if pweb.IsCacheBusy(err) {
+ plog.L(`I: `, r.RemoteAddr, "回放连接慢,缓存跳过")
+ return false
+ }
return true
}
return false
require (
github.com/gotk3/gotk3 v0.6.4
github.com/mdp/qrterminal/v3 v3.2.0
- github.com/qydysky/part v0.28.20250120190624
+ github.com/qydysky/part v0.28.20250127053704
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
golang.org/x/text v0.21.0
github.com/qydysky/biliApi v0.0.0-20240725184407-15076dddb6fb/go.mod h1:om024vfxALQ5vxsbaGoMm8IS0esLYBnEOpJI8FsGoDg=
github.com/qydysky/brotli v0.0.0-20240828134800-e9913a6e7ed9 h1:k451T+bpsLr+Dq9Ujo+Qtx0iomRA1XXS5ttlEojvfuQ=
github.com/qydysky/brotli v0.0.0-20240828134800-e9913a6e7ed9/go.mod h1:cI8/gy/wjy2Eb+p2IUj2ZuDnC8R5Vrx3O0VMPvMvphA=
-github.com/qydysky/part v0.28.20250120190624 h1:KyxUMxO0k5/loU1TP9usKJpN8YDGPgrIC6Yc37OeGws=
-github.com/qydysky/part v0.28.20250120190624/go.mod h1:RAb3G05OaqCSRWFJz9FnONB6iqF/Dk4R+Z5c/H7mWSg=
+github.com/qydysky/part v0.28.20250127053704 h1:UkhwV4IkqkP/u3H3IlnwG9lywSvsIIMgXkmu+MW/hq4=
+github.com/qydysky/part v0.28.20250127053704/go.mod h1:RAb3G05OaqCSRWFJz9FnONB6iqF/Dk4R+Z5c/H7mWSg=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=