mirror of
https://github.com/Monibuca/engine.git
synced 2025-10-05 08:36:56 +08:00
1.修复读取ts中aac格式数据多次flush问题
2.修复subscribe结束时判断IsClosed调用对象错误 3.增加DefaultYaml功能
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
|
||||||
"m7s.live/engine/v4/log"
|
"m7s.live/engine/v4/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -162,11 +161,11 @@ func (config Config) Merge(source Config) {
|
|||||||
case Config:
|
case Config:
|
||||||
m.Merge(v.(Config))
|
m.Merge(v.(Config))
|
||||||
default:
|
default:
|
||||||
log.Debug("merge", zap.String("k", k), zap.Any("v", v))
|
log.Debug("merge", k, v)
|
||||||
config[k] = v
|
config[k] = v
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Debug("exist", zap.String("k", k))
|
log.Debug("exist", k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
main.go
15
main.go
@@ -9,6 +9,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -96,12 +97,20 @@ func Run(ctx context.Context, configFile string) (err error) {
|
|||||||
EventBus = make(chan any, EngineConfig.EventBusSize)
|
EventBus = make(chan any, EngineConfig.EventBusSize)
|
||||||
go EngineConfig.Listen(Engine)
|
go EngineConfig.Listen(Engine)
|
||||||
for name, plugin := range Plugins {
|
for name, plugin := range Plugins {
|
||||||
plugin.RawConfig = cg.GetChild(name)
|
userConfig := cg.GetChild(name)
|
||||||
if plugin.RawConfig != nil {
|
if userConfig != nil {
|
||||||
if b, err := yaml.Marshal(plugin.RawConfig); err == nil {
|
if b, err := yaml.Marshal(userConfig); err == nil {
|
||||||
plugin.Yaml = string(b)
|
plugin.Yaml = string(b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if defaultYaml := reflect.ValueOf(plugin.Config).Elem().FieldByName("DefaultYaml"); defaultYaml.IsValid() {
|
||||||
|
if err := yaml.Unmarshal([]byte(defaultYaml.String()), &plugin.RawConfig); err != nil {
|
||||||
|
log.Error("parsing default config error:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if plugin.Yaml != "" {
|
||||||
|
yaml.Unmarshal([]byte(plugin.Yaml), &plugin.RawConfig)
|
||||||
|
}
|
||||||
plugin.assign()
|
plugin.assign()
|
||||||
}
|
}
|
||||||
UUID := uuid.NewString()
|
UUID := uuid.NewString()
|
||||||
|
16
plugin.go
16
plugin.go
@@ -48,6 +48,7 @@ func InstallPlugin(config config.Plugin) *Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FirstConfig config.Config
|
type FirstConfig config.Config
|
||||||
|
type DefaultYaml string
|
||||||
|
|
||||||
// Plugin 插件信息
|
// Plugin 插件信息
|
||||||
type Plugin struct {
|
type Plugin struct {
|
||||||
@@ -91,21 +92,21 @@ func (opt *Plugin) handle(pattern string, handler http.Handler) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 读取独立配置合并入总配置中
|
// 读取独立配置合并入总配置中
|
||||||
// TODO: 覆盖逻辑有待商榷
|
|
||||||
func (opt *Plugin) assign() {
|
func (opt *Plugin) assign() {
|
||||||
f, err := os.Open(opt.settingPath())
|
f, err := os.Open(opt.settingPath())
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
var b []byte
|
var b []byte
|
||||||
b, err = io.ReadAll(f)
|
b, err = io.ReadAll(f)
|
||||||
opt.modifiedYaml = string(b)
|
if err == nil {
|
||||||
if err = yaml.Unmarshal(b, &opt.Modified); err == nil {
|
opt.modifiedYaml = string(b)
|
||||||
if opt.RawConfig == nil {
|
if err = yaml.Unmarshal(b, &opt.Modified); err == nil {
|
||||||
opt.RawConfig = opt.Modified
|
err = yaml.Unmarshal(b, &opt.RawConfig)
|
||||||
} else {
|
|
||||||
opt.RawConfig.Assign(opt.Modified)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
opt.Warn("assign config failed", zap.Error(err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if opt == Engine {
|
if opt == Engine {
|
||||||
opt.registerHandler()
|
opt.registerHandler()
|
||||||
@@ -150,6 +151,7 @@ func (opt *Plugin) run() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
delete(opt.RawConfig, "defaultyaml")
|
||||||
opt.Debug("config", zap.Any("config", opt.Config))
|
opt.Debug("config", zap.Any("config", opt.Config))
|
||||||
// opt.RawConfig = config.Struct2Config(opt.Config)
|
// opt.RawConfig = config.Struct2Config(opt.Config)
|
||||||
if conf, ok := opt.Config.(config.HTTPConfig); ok {
|
if conf, ok := opt.Config.(config.HTTPConfig); ok {
|
||||||
|
@@ -87,8 +87,8 @@ func (t *TSPublisher) OnPES(pes mpegts.MpegTsPESPacket) {
|
|||||||
t.AudioTrack.WriteSlice(pes.Payload[7:frameLen])
|
t.AudioTrack.WriteSlice(pes.Payload[7:frameLen])
|
||||||
pes.Payload = pes.Payload[frameLen:remainLen]
|
pes.Payload = pes.Payload[frameLen:remainLen]
|
||||||
remainLen -= frameLen
|
remainLen -= frameLen
|
||||||
t.AudioTrack.Flush()
|
|
||||||
}
|
}
|
||||||
|
t.AudioTrack.Flush()
|
||||||
case *track.G711:
|
case *track.G711:
|
||||||
t.AudioTrack.WriteRaw(uint32(pes.Header.Pts), pes.Payload)
|
t.AudioTrack.WriteRaw(uint32(pes.Header.Pts), pes.Payload)
|
||||||
}
|
}
|
||||||
|
@@ -348,11 +348,10 @@ func (s *Subscriber) PlayBlock(subType byte) {
|
|||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println("exit")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Subscriber) onStop() {
|
func (s *Subscriber) onStop() {
|
||||||
if !s.IsClosed() {
|
if !s.Stream.IsClosed() {
|
||||||
s.Info("stop")
|
s.Info("stop")
|
||||||
if !s.IsInternal {
|
if !s.IsInternal {
|
||||||
s.Stream.Receive(s.Spesific)
|
s.Stream.Receive(s.Spesific)
|
||||||
|
@@ -26,6 +26,7 @@ func (p *流速控制) 时间戳差(绝对时间戳 uint32) time.Duration {
|
|||||||
}
|
}
|
||||||
func (p *流速控制) 控制流速(绝对时间戳 uint32) {
|
func (p *流速控制) 控制流速(绝对时间戳 uint32) {
|
||||||
数据时间差, 实际时间差 := p.时间戳差(绝对时间戳), time.Since(p.起始时间)
|
数据时间差, 实际时间差 := p.时间戳差(绝对时间戳), time.Since(p.起始时间)
|
||||||
|
// println("数据时间差", 数据时间差, "实际时间差", 实际时间差, "绝对时间戳", 绝对时间戳, "起始时间戳", p.起始时间戳, "起始时间", p.起始时间.Format("2006-01-02 15:04:05"))
|
||||||
// if 实际时间差 > 数据时间差 {
|
// if 实际时间差 > 数据时间差 {
|
||||||
// p.重置(绝对时间戳)
|
// p.重置(绝对时间戳)
|
||||||
// return
|
// return
|
||||||
@@ -136,6 +137,7 @@ func (av *Media[T]) Flush() {
|
|||||||
av.重置(curValue.AbsTime)
|
av.重置(curValue.AbsTime)
|
||||||
} else {
|
} else {
|
||||||
curValue.DeltaTime = (curValue.DTS - preValue.DTS) / 90
|
curValue.DeltaTime = (curValue.DTS - preValue.DTS) / 90
|
||||||
|
println(curValue.DeltaTime ,curValue.DTS , preValue.DTS)
|
||||||
curValue.AbsTime = preValue.AbsTime + curValue.DeltaTime
|
curValue.AbsTime = preValue.AbsTime + curValue.DeltaTime
|
||||||
}
|
}
|
||||||
av.Base.Flush(&curValue.BaseFrame)
|
av.Base.Flush(&curValue.BaseFrame)
|
||||||
|
@@ -36,7 +36,6 @@ func (vt *H264) WriteAnnexB(pts uint32, dts uint32, frame AnnexBFrame) {
|
|||||||
if len(vt.Value.Raw) > 0 {
|
if len(vt.Value.Raw) > 0 {
|
||||||
vt.Flush()
|
vt.Flush()
|
||||||
}
|
}
|
||||||
// println(vt.Value.DTS, vt.Value.PTS, vt.Value.PTS-vt.Value.DTS, len(frame))
|
|
||||||
// println(vt.FPS)
|
// println(vt.FPS)
|
||||||
}
|
}
|
||||||
func (vt *H264) WriteSlice(slice NALUSlice) {
|
func (vt *H264) WriteSlice(slice NALUSlice) {
|
||||||
|
Reference in New Issue
Block a user