From 9109fc17444f694a0af66e8ee2a1d9c7a40e0d89 Mon Sep 17 00:00:00 2001 From: dexter <178529795@qq.com> Date: Sat, 12 Feb 2022 21:15:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- amf.go | 19 ++++++++----------- main.go | 7 +++---- msg.go | 3 +-- netConnection.go | 4 ++-- netStream.go | 17 ++++++++--------- 5 files changed, 22 insertions(+), 28 deletions(-) diff --git a/amf.go b/amf.go index bf96b53..a5acfdc 100644 --- a/amf.go +++ b/amf.go @@ -1,8 +1,6 @@ package rtmp import ( - "fmt" - "log" "github.com/Monibuca/engine/v4/util" ) @@ -85,8 +83,7 @@ var ObjectEnd = &struct{}{} var Undefined = &struct{}{} func (amf *AMF) decodeObject() (obj AMFValue) { - if amf.Len() == 0 { - fmt.Sprintf("no enough bytes, %v/%v", amf.Len(), 1) + if !amf.CanRead() { return nil } t := amf.Buffer[0] @@ -100,14 +97,14 @@ func (amf *AMF) decodeObject() (obj AMFValue) { case AMF0_OBJECT: return amf.readObject() case AMF0_MOVIECLIP: - log.Println("This type is not supported and is reserved for future use.(AMF0_MOVIECLIP)") + plugin.Println("This type is not supported and is reserved for future use.(AMF0_MOVIECLIP)") case AMF0_NULL: return amf.readNull() case AMF0_UNDEFINED: amf.ReadByte() return Undefined case AMF0_REFERENCE: - log.Println("reference-type.(AMF0_REFERENCE)") + plugin.Println("reference-type.(AMF0_REFERENCE)") case AMF0_ECMA_ARRAY: return amf.readECMAArray() case AMF0_END_OBJECT: @@ -121,15 +118,15 @@ func (amf *AMF) decodeObject() (obj AMFValue) { AMF0_XML_DOCUMENT: return amf.readLongString() case AMF0_UNSUPPORTED: - log.Println("If a type cannot be serialized a special unsupported marker can be used in place of the type.(AMF0_UNSUPPORTED)") + plugin.Println("If a type cannot be serialized a special unsupported marker can be used in place of the type.(AMF0_UNSUPPORTED)") case AMF0_RECORDSET: - log.Println("This type is not supported and is reserved for future use.(AMF0_RECORDSET)") + plugin.Println("This type is not supported and is reserved for future use.(AMF0_RECORDSET)") case AMF0_TYPED_OBJECT: - log.Println("If a strongly typed object has an alias registered for its class then the type name will also be serialized. Typed objects are considered complex types and reoccurring instances can be sent by reference.(AMF0_TYPED_OBJECT)") + plugin.Println("If a strongly typed object has an alias registered for its class then the type name will also be serialized. Typed objects are considered complex types and reoccurring instances can be sent by reference.(AMF0_TYPED_OBJECT)") case AMF0_AVMPLUS_OBJECT: - log.Println("AMF0_AVMPLUS_OBJECT") + plugin.Println("AMF0_AVMPLUS_OBJECT") default: - fmt.Sprintf("Unsupported type %v", t) + plugin.Warnf("Unsupported type %v", t) } return nil } diff --git a/main.go b/main.go index 32df47c..9feda02 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package rtmp import ( "context" - "log" . "github.com/Monibuca/engine/v4" "github.com/Monibuca/engine/v4/config" @@ -17,12 +16,12 @@ type RTMPConfig struct { } func (config *RTMPConfig) Update(override config.Config) { - plugin.Infoln(Green("server rtmp start at"), BrightBlue(config.ListenAddr)) + plugin.Info(Green("server rtmp start at"), BrightBlue(config.ListenAddr)) err := config.Listen(plugin, config) if err == context.Canceled { - log.Println(err) + plugin.Println(err) } else { - log.Fatal(err) + plugin.Fatal(err) } } diff --git a/msg.go b/msg.go index b983ea9..5297e10 100644 --- a/msg.go +++ b/msg.go @@ -3,7 +3,6 @@ package rtmp import ( "encoding/binary" "errors" - "log" "github.com/Monibuca/engine/v4/util" ) @@ -283,7 +282,7 @@ func decodeCommandAMF0(chunk *Chunk) { } case "FCPublish", "FCUnpublish": default: - log.Println("decode command amf0 cmd:", cmd) + plugin.Println("decode command amf0 cmd:", cmd) } } diff --git a/netConnection.go b/netConnection.go index 6784533..ea0c7bc 100644 --- a/netConnection.go +++ b/netConnection.go @@ -7,7 +7,7 @@ import ( "io" "net" -. "github.com/Monibuca/engine/v4" + . "github.com/Monibuca/engine/v4" "github.com/Monibuca/engine/v4/util" ) @@ -355,7 +355,7 @@ func (conn *NetConnection) readChunk() (msg *Chunk, err error) { needRead = unRead } if n, err := conn.ReadFull(currentBody.Malloc(needRead)); err != nil { - plugin.Errorln(err) + plugin.Error(err) return nil, err } else { conn.readSeqNum += uint32(n) diff --git a/netStream.go b/netStream.go index a385bbe..fe134ff 100644 --- a/netStream.go +++ b/netStream.go @@ -3,7 +3,6 @@ package rtmp import ( "bufio" "fmt" - "log" "net" "sync/atomic" @@ -29,7 +28,7 @@ func (config *RTMPConfig) ServeTCP(conn *net.TCPConn) { defer nc.Close() /* Handshake */ if err := nc.Handshake(); err != nil { - plugin.Errorln("handshake", err) + plugin.Error("handshake", err) return } var rec_audio, rec_video func(*Chunk) @@ -59,7 +58,7 @@ func (config *RTMPConfig) ServeTCP(conn *net.TCPConn) { break } cmd := msg.MsgData.(Commander).GetCommand() - plugin.Debugln("recv cmd", cmd.CommandName) + plugin.Debugf("recv cmd '%s'", cmd.CommandName) switch cmd.CommandName { case "connect": connect := msg.MsgData.(*CallMessage) @@ -69,7 +68,7 @@ func (config *RTMPConfig) ServeTCP(conn *net.TCPConn) { nc.objectEncoding = objectEncoding.(float64) } nc.appName = app.(string) - log.Printf("app:%v,objectEncoding:%v", app, objectEncoding) + plugin.Infof("connect app:'%s',objectEncoding:%v", nc.appName, objectEncoding) err = nc.SendMessage(RTMP_MSG_ACK_SIZE, Uint32Message(512<<10)) nc.writeChunkSize = config.ChunkSize err = nc.SendMessage(RTMP_MSG_CHUNK_SIZE, Uint32Message(config.ChunkSize)) @@ -81,10 +80,10 @@ func (config *RTMPConfig) ServeTCP(conn *net.TCPConn) { err = nc.SendCommand(SEND_CONNECT_RESPONSE_MESSAGE, nc.objectEncoding) case "createStream": nc.streamID = atomic.AddUint32(&gstreamid, 1) - log.Println("createStream:", nc.streamID) + plugin.Info("createStream:", nc.streamID) err = nc.SendCommand(SEND_CREATE_STREAM_RESPONSE_MESSAGE, cmd.TransactionId) if err != nil { - plugin.Errorln(err) + plugin.Error(err) return } case "publish": @@ -94,7 +93,7 @@ func (config *RTMPConfig) ServeTCP(conn *net.TCPConn) { vt := nc.Stream.NewVideoTrack() at := nc.Stream.NewAudioTrack() rec_audio = func(msg *Chunk) { - plugin.Traceln("rec_audio", "chunkType", msg.ChunkType, "chunkStreamID", msg.ChunkStreamID, "ts", msg.Timestamp) + plugin.Tracef("rec_audio chunkType:%d chunkStreamID:%d ts:%d", msg.ChunkType, msg.ChunkStreamID, msg.Timestamp) if msg.ChunkType == 0 { absTs[msg.ChunkStreamID] = 0 } @@ -106,7 +105,7 @@ func (config *RTMPConfig) ServeTCP(conn *net.TCPConn) { at.WriteAVCC(absTs[msg.ChunkStreamID], msg.Body) } rec_video = func(msg *Chunk) { - plugin.Traceln("rev_video", "chunkType", msg.ChunkType, "chunkStreamID", msg.ChunkStreamID, "ts", msg.Timestamp) + plugin.Tracef("rev_video chunkType:%d chunkStreamID:%d ts:%d", msg.ChunkType, msg.ChunkStreamID, msg.Timestamp) if msg.ChunkType == 0 { absTs[msg.ChunkStreamID] = 0 } @@ -185,7 +184,7 @@ func (config *RTMPConfig) ServeTCP(conn *net.TCPConn) { rec_video(msg) } } else { - plugin.Errorln(err) + plugin.Error(err) return } }