修正若干错误

This commit is contained in:
langhuihui
2020-03-17 21:38:20 +08:00
parent 2e3b40de36
commit 3f64c5a398
2 changed files with 25 additions and 21 deletions

View File

@@ -3,11 +3,13 @@ package rtmpplugin
import ( import (
"bufio" "bufio"
"errors" "errors"
"io"
"log"
"github.com/Monibuca/engine"
"github.com/Monibuca/engine/avformat" "github.com/Monibuca/engine/avformat"
"github.com/Monibuca/engine/pool" "github.com/Monibuca/engine/pool"
"github.com/Monibuca/engine/util" "github.com/Monibuca/engine/util"
"io"
"log"
) )
const ( const (
@@ -45,7 +47,7 @@ const (
func newConnectResponseMessageData(objectEncoding float64) (amfobj AMFObjects) { func newConnectResponseMessageData(objectEncoding float64) (amfobj AMFObjects) {
amfobj = newAMFObjects() amfobj = newAMFObjects()
amfobj["fmsVer"] = "monibuca/1.0" amfobj["fmsVer"] = "monibuca/" + engine.Version
amfobj["capabilities"] = 31 amfobj["capabilities"] = 31
amfobj["mode"] = 1 amfobj["mode"] = 1
amfobj["Author"] = "dexter" amfobj["Author"] = "dexter"
@@ -167,7 +169,7 @@ func (conn *NetConnection) SendMessage(message string, args interface{}) error {
if args != nil { if args != nil {
return errors.New(SEND_PING_REQUEST_MESSAGE + ", The parameter is nil") return errors.New(SEND_PING_REQUEST_MESSAGE + ", The parameter is nil")
} }
return conn.writeMessage(RTMP_MSG_USER_CONTROL, &UserControlMessage{EventType: RTMP_USER_PING_REQUEST}) return conn.writeMessage(RTMP_MSG_USER_CONTROL, &PingRequestMessage{UserControlMessage{EventType: RTMP_USER_PING_REQUEST}, 0})
case SEND_PING_RESPONSE_MESSAGE: case SEND_PING_RESPONSE_MESSAGE:
if args != nil { if args != nil {
return errors.New(SEND_PING_RESPONSE_MESSAGE + ", The parameter is nil") return errors.New(SEND_PING_RESPONSE_MESSAGE + ", The parameter is nil")
@@ -334,14 +336,12 @@ func (conn *NetConnection) SendMessage(message string, args interface{}) error {
return conn.sendAVMessage(video, false, true) return conn.sendAVMessage(video, false, true)
case SEND_VIDEO_MESSAGE: case SEND_VIDEO_MESSAGE:
{ video, ok := args.(*avformat.SendPacket)
video, ok := args.(*avformat.SendPacket) if !ok {
if !ok { errors.New(message + ", The parameter is AVPacket")
errors.New(message + ", The parameter is AVPacket")
}
return conn.sendAVMessage(video, false, false)
} }
return conn.sendAVMessage(video, false, false)
} }
return errors.New("send message no exist") return errors.New("send message no exist")
@@ -351,12 +351,12 @@ func (conn *NetConnection) SendMessage(message string, args interface{}) error {
// 当块类型为4,8的时候,Chunk Message Header有一个字段TimeStamp Delta,记录与上一个Chunk的时间差值 // 当块类型为4,8的时候,Chunk Message Header有一个字段TimeStamp Delta,记录与上一个Chunk的时间差值
// 当块类型为0的时候,Chunk Message Header没有时间字段,与上一个Chunk时间值相同 // 当块类型为0的时候,Chunk Message Header没有时间字段,与上一个Chunk时间值相同
func (conn *NetConnection) sendAVMessage(av *avformat.SendPacket, isAudio bool, isFirst bool) error { func (conn *NetConnection) sendAVMessage(av *avformat.SendPacket, isAudio bool, isFirst bool) error {
if conn.writeSeqNum > conn.bandwidth { // if conn.writeSeqNum > conn.bandwidth {
conn.totalWrite += conn.writeSeqNum // conn.totalWrite += conn.writeSeqNum
conn.writeSeqNum = 0 // conn.writeSeqNum = 0
conn.SendMessage(SEND_ACK_MESSAGE, conn.totalWrite) // conn.SendMessage(SEND_ACK_MESSAGE, conn.totalWrite)
conn.SendMessage(SEND_PING_REQUEST_MESSAGE, nil) // conn.SendMessage(SEND_PING_REQUEST_MESSAGE, nil)
} // }
var err error var err error
var mark []byte var mark []byte

View File

@@ -3,12 +3,13 @@ package rtmpplugin
import ( import (
"bufio" "bufio"
"fmt" "fmt"
. "github.com/Monibuca/engine"
"github.com/Monibuca/engine/avformat"
"log" "log"
"net" "net"
"strings" "strings"
"time" "time"
. "github.com/Monibuca/engine"
"github.com/Monibuca/engine/avformat"
) )
type RTMP struct { type RTMP struct {
@@ -58,6 +59,9 @@ func processRtmp(conn net.Conn) {
if room != nil { if room != nil {
room.Cancel() room.Cancel()
} }
for _, s := range streams {
s.Close()
}
}() }()
var totalDuration uint32 var totalDuration uint32
nc := &NetConnection{ nc := &NetConnection{
@@ -102,7 +106,7 @@ func processRtmp(conn net.Conn) {
streamPath := nc.appName + "/" + strings.Split(pm.PublishingName, "?")[0] streamPath := nc.appName + "/" + strings.Split(pm.PublishingName, "?")[0]
pub := new(RTMP) pub := new(RTMP)
if pub.Publish(streamPath, pub) { if pub.Publish(streamPath, pub) {
pub.FirstScreen = make([]*avformat.AVPacket, 0) //pub.FirstScreen = make([]*avformat.AVPacket, 0)
room = pub.Room room = pub.Room
err = nc.SendMessage(SEND_STREAM_BEGIN_MESSAGE, nil) err = nc.SendMessage(SEND_STREAM_BEGIN_MESSAGE, nil)
err = nc.SendMessage(SEND_PUBLISH_START_MESSAGE, newPublishResponseMessageData(nc.streamID, NetStream_Publish_Start, Level_Status)) err = nc.SendMessage(SEND_PUBLISH_START_MESSAGE, newPublishResponseMessageData(nc.streamID, NetStream_Publish_Start, Level_Status))
@@ -138,7 +142,7 @@ func processRtmp(conn net.Conn) {
case packet.Packet.Type == RTMP_MSG_AUDIO: case packet.Packet.Type == RTMP_MSG_AUDIO:
err = nc.SendMessage(SEND_AUDIO_MESSAGE, packet) err = nc.SendMessage(SEND_AUDIO_MESSAGE, packet)
} }
return nil return
}} }}
stream.Type = "RTMP" stream.Type = "RTMP"
stream.ID = fmt.Sprintf("%s|%d", conn.RemoteAddr().String(), nc.streamID) stream.ID = fmt.Sprintf("%s|%d", conn.RemoteAddr().String(), nc.streamID)