mirror of
https://github.com/Monibuca/plugin-rtmp.git
synced 2026-04-22 22:57:04 +08:00
优化代码
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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)
|
||||
|
||||
+8
-9
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user