适配引擎升级

This commit is contained in:
dexter
2022-02-21 21:40:31 +08:00
parent c1bdd8fa8a
commit f7e4c060ab
4 changed files with 36 additions and 17 deletions

11
go.mod
View File

@@ -4,4 +4,13 @@ go 1.18
require github.com/logrusorgru/aurora v2.0.3+incompatible
require github.com/zhangpeihao/goamf v0.0.0-20140409082417-3ff2c19514a8
require (
github.com/zhangpeihao/goamf v0.0.0-20140409082417-3ff2c19514a8
go.uber.org/zap v1.21.0
)
require (
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

11
go.sum
View File

@@ -1,4 +1,15 @@
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/zhangpeihao/goamf v0.0.0-20140409082417-3ff2c19514a8 h1:r1JUI0wuHlgRb8jNd3zPBBkjUdrjpVKr8SdJWc8ntg8=
github.com/zhangpeihao/goamf v0.0.0-20140409082417-3ff2c19514a8/go.mod h1:RZd/IqzNpFANwOB9rVmsnAYpo/6KesK4PqrN1a5cRgg=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=

29
main.go
View File

@@ -10,7 +10,6 @@ import (
. "github.com/Monibuca/engine/v4"
"github.com/Monibuca/engine/v4/codec"
"github.com/Monibuca/engine/v4/common"
"github.com/Monibuca/engine/v4/config"
"github.com/Monibuca/engine/v4/util"
. "github.com/logrusorgru/aurora"
@@ -27,12 +26,18 @@ type HDLConfig struct {
var streamPathReg = regexp.MustCompile(`/(hdl/)?((.+)(\.flv)|(.+))`)
func (c *HDLConfig) Update(override config.Config) {
if c.ListenAddr != "" || c.ListenAddrTLS != "" {
plugin.Info(Green("HDL Server Start").String(), zap.String("ListenAddr", c.ListenAddr), zap.String("ListenAddrTLS", c.ListenAddrTLS))
c.Listen(plugin, c)
func (c *HDLConfig) OnEvent(event any) {
switch event.(type) {
case FirstConfig:
if c.ListenAddr != "" || c.ListenAddrTLS != "" {
plugin.Info(Green("HDL Server Start").String(), zap.String("ListenAddr", c.ListenAddr), zap.String("ListenAddrTLS", c.ListenAddrTLS))
go c.Listen(plugin, c)
} else {
plugin.Info(Green("HDL start reuse engine port").String())
}
}
}
func (c *HDLConfig) API_Pull(rw http.ResponseWriter, r *http.Request) {
var puller Puller
puller.StreamPath = r.URL.Query().Get("streamPath")
@@ -55,7 +60,6 @@ func (*HDLConfig) API_List(rw http.ResponseWriter, r *http.Request) {
var Config = new(HDLConfig)
// 确保HDLConfig实现了PullPlugin接口
var _ PullPlugin = Config
var plugin = InstallPlugin(Config)
@@ -65,19 +69,14 @@ type HDLSubscriber struct {
func (sub *HDLSubscriber) OnEvent(event any) {
switch v := event.(type) {
case AudioDeConf:
if sub.AudioTrack.IsAAC() {
v.FLV.WriteTo(sub)
}
case VideoDeConf:
v.FLV.WriteTo(sub)
case common.MediaFrame:
case HaveFLV:
flvTag := v.GetFLV()
flvTag.WriteTo(sub)
default:
sub.Subscriber.OnEvent(event)
}
}
func (*HDLConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
parts := streamPathReg.FindStringSubmatch(r.RequestURI)
if len(parts) == 0 {
@@ -93,7 +92,7 @@ func (*HDLConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
sub := &HDLSubscriber{}
sub.ID = r.RemoteAddr
sub.OnEvent(r.Context())
if plugin.Subscribe(stringPath, sub) {
if err := plugin.Subscribe(stringPath, sub); err == nil {
if sub.Stream.Publisher == nil {
w.WriteHeader(404)
return
@@ -143,7 +142,7 @@ func (*HDLConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
codec.WriteFLVTag(w, codec.FLV_TAG_TYPE_SCRIPT, 0, net.Buffers{buffer.Bytes()})
sub.PlayBlock(sub)
} else {
w.WriteHeader(500)
http.Error(w, err.Error(), http.StatusBadRequest)
}
}
func WriteEcmaArray(w amf.Writer, o amf.Object) (n int, err error) {

View File

@@ -70,7 +70,7 @@ func (puller *HDLPuller) OnEvent(event any) {
}(v + 1)
} else {
// TODO: 发布失败重新发布
if plugin.Publish(puller.StreamPath, puller) {
if plugin.Publish(puller.StreamPath, puller) == nil {
if strings.HasPrefix(puller.RemoteURL, "http") {
if res, err := http.Get(puller.RemoteURL); err == nil {
puller.Reader = res.Body