mirror of
https://github.com/Monibuca/plugin-rtmp.git
synced 2025-10-05 15:37:11 +08:00
适配引擎变更
This commit is contained in:
37
main.go
37
main.go
@@ -5,38 +5,22 @@ import (
|
||||
"log"
|
||||
|
||||
. "github.com/Monibuca/engine/v4"
|
||||
"github.com/Monibuca/engine/v4/config"
|
||||
"github.com/Monibuca/engine/v4/util"
|
||||
. "github.com/logrusorgru/aurora"
|
||||
)
|
||||
|
||||
type RTMPConfig struct {
|
||||
Publish PublishConfig
|
||||
Subscribe SubscribeConfig
|
||||
TCPConfig
|
||||
config.Publish
|
||||
config.Subscribe
|
||||
config.TCP
|
||||
ChunkSize int
|
||||
context.Context
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
var config = &RTMPConfig{
|
||||
Publish: DefaultPublishConfig,
|
||||
Subscribe: DefaultSubscribeConfig,
|
||||
ChunkSize: 4096,
|
||||
TCPConfig: TCPConfig{ListenAddr: ":1935"},
|
||||
}
|
||||
|
||||
func (cfg *RTMPConfig) Update(override Config) {
|
||||
override.Unmarshal(cfg)
|
||||
if config.cancel == nil {
|
||||
func (config *RTMPConfig) Update(override config.Config) {
|
||||
override.Unmarshal(config)
|
||||
util.Print(Green("server rtmp start at"), BrightBlue(config.ListenAddr))
|
||||
} else if override.Has("ListenAddr") {
|
||||
config.cancel()
|
||||
util.Print(Green("server rtmp restart at"), BrightBlue(config.ListenAddr))
|
||||
} else {
|
||||
return
|
||||
}
|
||||
config.Context, config.cancel = context.WithCancel(Ctx)
|
||||
err := cfg.Listen(cfg)
|
||||
err := config.Listen(plugin, config)
|
||||
if err == context.Canceled {
|
||||
log.Println(err)
|
||||
} else {
|
||||
@@ -44,6 +28,7 @@ func (cfg *RTMPConfig) Update(override Config) {
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
InstallPlugin(config)
|
||||
}
|
||||
var plugin = InstallPlugin(&RTMPConfig{
|
||||
ChunkSize: 4096,
|
||||
TCP: config.TCP{ListenAddr: ":1935"},
|
||||
})
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
|
||||
"github.com/Monibuca/engine/v4"
|
||||
. "github.com/Monibuca/engine/v4"
|
||||
"github.com/Monibuca/engine/v4/util"
|
||||
)
|
||||
|
||||
@@ -46,7 +46,7 @@ const (
|
||||
|
||||
func newConnectResponseMessageData(objectEncoding float64) (amfobj AMFObject) {
|
||||
amfobj = make(AMFObject)
|
||||
amfobj["fmsVer"] = "monibuca/" + engine.Version
|
||||
amfobj["fmsVer"] = "monibuca/" + Engine.Version
|
||||
amfobj["capabilities"] = 31
|
||||
amfobj["mode"] = 1
|
||||
amfobj["Author"] = "dexter"
|
||||
@@ -76,8 +76,8 @@ func newPlayResponseMessageData(streamid uint32, code, level string) (amfobj AMF
|
||||
}
|
||||
|
||||
type NetConnection struct {
|
||||
engine.Publisher
|
||||
subscribers map[uint32]*engine.Subscriber
|
||||
Publisher
|
||||
subscribers map[uint32]*Subscriber
|
||||
*bufio.Reader
|
||||
*net.TCPConn
|
||||
bandwidth uint32
|
||||
@@ -208,7 +208,7 @@ func (conn *NetConnection) SendCommand(message string, args any) error {
|
||||
// }
|
||||
//}
|
||||
|
||||
pro["fmsVer"] = "monibuca/" + engine.Version
|
||||
pro["fmsVer"] = "monibuca/" + Engine.Version
|
||||
pro["capabilities"] = 31
|
||||
pro["mode"] = 1
|
||||
pro["Author"] = "dexter"
|
||||
|
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
var gstreamid = uint32(64)
|
||||
|
||||
func (cfg *RTMPConfig) ServeTCP(conn *net.TCPConn) {
|
||||
func (config *RTMPConfig) ServeTCP(conn *net.TCPConn) {
|
||||
nc := NetConnection{
|
||||
TCPConn: conn,
|
||||
Reader: bufio.NewReader(conn),
|
||||
@@ -87,8 +87,7 @@ func (cfg *RTMPConfig) ServeTCP(conn *net.TCPConn) {
|
||||
}
|
||||
case "publish":
|
||||
pm := msg.MsgData.(*PublishMessage)
|
||||
nc.Config = config.Publish
|
||||
if nc.Publish(nc.appName+"/"+pm.PublishingName, &nc) {
|
||||
if nc.Publish(nc.appName+"/"+pm.PublishingName, &nc, config.Publish) {
|
||||
absTs := make(map[uint32]uint32)
|
||||
vt := nc.Stream.NewVideoTrack()
|
||||
at := nc.Stream.NewAudioTrack()
|
||||
@@ -135,7 +134,7 @@ func (cfg *RTMPConfig) ServeTCP(conn *net.TCPConn) {
|
||||
vt, at := subscriber.WaitVideoTrack(), subscriber.WaitAudioTrack()
|
||||
if vt != nil {
|
||||
frame := vt.DecoderConfiguration
|
||||
err = nc.sendAVMessage(0, frame.AVCC, false, true)
|
||||
err = nc.sendAVMessage(0, net.Buffers(frame.AVCC), false, true)
|
||||
subscriber.OnVideo = func(frame *engine.VideoFrame) error {
|
||||
return nc.sendAVMessage(frame.DeltaTime, frame.AVCC, false, false)
|
||||
}
|
||||
@@ -144,7 +143,7 @@ func (cfg *RTMPConfig) ServeTCP(conn *net.TCPConn) {
|
||||
subscriber.OnAudio = func(frame *engine.AudioFrame) (err error) {
|
||||
if at.CodecID == codec.CodecID_AAC {
|
||||
frame := at.DecoderConfiguration
|
||||
err = nc.sendAVMessage(0, frame.AVCC, true, true)
|
||||
err = nc.sendAVMessage(0, net.Buffers{frame.AVCC}, true, true)
|
||||
} else {
|
||||
err = nc.sendAVMessage(0, frame.AVCC, true, true)
|
||||
}
|
||||
|
Reference in New Issue
Block a user