"io/fs"
"math"
"net/http"
+ "net/http/pprof"
"path/filepath"
"sort"
"strconv"
common = c.C
)
common.Roomid = roomid
- tmp.LoadConfig(common, c.C.Log)
+ if e := tmp.LoadConfig(common); e != nil {
+ flog.L(`E: `, e)
+ return
+ }
//录制回调,关于ass
tmp.Callback_startRec = func(ms *M4SStream) error {
StartRecDanmu(ms.Current_save_path + "0.csv")
return
}
+ // debug模式
+ if de, ok := c.C.K_v.LoadV(`debug模式`).(bool); ok && de {
+ c.C.SerF.Store("/debug/pprof/", pprof.Index)
+ c.C.SerF.Store("/debug/pprof/cmdline", pprof.Cmdline)
+ c.C.SerF.Store("/debug/pprof/profile", pprof.Profile)
+ c.C.SerF.Store("/debug/pprof/symbol", pprof.Symbol)
+ c.C.SerF.Store("/debug/pprof/trace", pprof.Trace)
+ }
+
// 直播流主页
c.C.SerF.Store(path, func(w http.ResponseWriter, r *http.Request) {
p := strings.TrimPrefix(r.URL.Path, path)
return t.common
}
-func (t *M4SStream) LoadConfig(common c.Common, l *log.Log_interface) {
+func (t *M4SStream) LoadConfig(common c.Common) (e error) {
t.common = common
- t.log = l.Base(`直播流保存`)
+ t.log = common.Log.Base(`直播流保存`)
//读取配置
if path, ok := common.K_v.LoadV("直播流保存位置").(string); ok {
if fs, err := os.Stat(path); err != nil {
if errors.Is(err, os.ErrNotExist) {
if err := p.File().NewPath(path); err != nil {
- t.log.L(`E: `, `直播流保存位置错误`, err)
- return
+ return errors.New(`直播流保存位置错误` + err.Error())
}
} else {
- t.log.L(`E: `, `直播流保存位置错误`, err)
- return
+ return errors.New(`直播流保存位置错误` + err.Error())
}
} else if !fs.IsDir() {
- t.log.L(`E: `, `直播流保存位置不是目录`)
- return
+ return errors.New(`直播流保存位置不是目录`)
}
t.config.save_path = path + "/"
} else {
- t.log.L(`E: `, `直播流保存位置错误`, err)
- return
+ return errors.New(`直播流保存位置错误` + err.Error())
}
+ } else {
+ return errors.New(`未配置直播流保存位置`)
}
if v, ok := common.K_v.LoadV(`直播hls流保存为MP4`).(bool); ok {
t.config.save_as_mp4 = v
if v, ok := common.K_v.LoadV(`直播流类型`).(string); ok {
t.config.want_type = v
}
+ return
}
func (t *M4SStream) getFirstBuf() []byte {
"直播流类型-help": "flv,fmp4,flvH,fmp4H,带H后缀的为Hevc格式编码",
"直播流类型": "flv",
"直播流保存位置": "./live",
- "直播流保存天数-help": "当t日有1录播时,会尝试删除t-n日的1个最早的录播",
+ "直播流保存天数-help": "当t日有1录播时,会尝试删除t-n日的1个最早的录播。小于1的数将禁用此功能",
"直播流保存天数": 4,
"直播hls流故障转移-help":"true:hls服务器故障时,使用其他",
"直播hls流故障转移": true,
"启动时显示ip":true,
"几秒后重载-help":"最少间隔60s,-1时不重载",
"几秒后重载":60,
- "下播后不记录人气观看人数":true
+ "下播后不记录人气观看人数":true,
+ "debug模式-help":"在/debug/pprof/启用调试",
+ "debug模式":false
}
\ No newline at end of file
package main
-import ( // "runtime"
- // "runtime/pprof"
- // "net/http"
- // _ "net/http/pprof"
- // "github.com/skratchdot/open-golang/open"
+import (
q "github.com/qydysky/bili_danmu"
)
func main() {
- // go func() {
- // http.ListenAndServe("0.0.0.0:8899", nil)
- // }()
- // defer func(){
- // open.Run("http://127.0.0.1:8899/debug/pprof/goroutine?debug=2")
- // time.Sleep(time.Duration(3)*time.Second)
- // }()
- // go func() {
- // for {
- // View()
- // time.Sleep(time.Duration(60) * time.Second)
- // {
- // debug.FreeOSMemory()
- // }
- // }
- // }()
- // f, err := os.OpenFile("cpu.pprof", os.O_RDWR|os.O_CREATE, 0644)
- // if err != nil {
- // log.Fatal(err)
- // }
- // defer f.Close()
- // pprof.StartCPUProfile(f)
-
q.Start()
-
- // pprof.StopCPUProfile()
}
-
-// func View() {
-// var memStats runtime.MemStats
-// runtime.ReadMemStats(&memStats)
-// fmt.Printf("=====\n")
-// fmt.Printf("总内存:%v MB\n",memStats.Alloc/1024e2/8)
-// fmt.Printf("GC次数:%v \n",memStats.NumGC)
-// fmt.Printf("堆 :%v %v MB\n",memStats.HeapInuse/1024e2/8,(memStats.HeapIdle - memStats.HeapReleased)/1024e2/8)
-// fmt.Printf("=====\n")
-// }