mirror of
https://github.com/Monibuca/plugin-rtmp.git
synced 2025-10-30 18:26:19 +08:00
修正若干错误
This commit is contained in:
@@ -3,11 +3,13 @@ package rtmpplugin
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
|
||||
"github.com/Monibuca/engine"
|
||||
"github.com/Monibuca/engine/avformat"
|
||||
"github.com/Monibuca/engine/pool"
|
||||
"github.com/Monibuca/engine/util"
|
||||
"io"
|
||||
"log"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -45,7 +47,7 @@ const (
|
||||
|
||||
func newConnectResponseMessageData(objectEncoding float64) (amfobj AMFObjects) {
|
||||
amfobj = newAMFObjects()
|
||||
amfobj["fmsVer"] = "monibuca/1.0"
|
||||
amfobj["fmsVer"] = "monibuca/" + engine.Version
|
||||
amfobj["capabilities"] = 31
|
||||
amfobj["mode"] = 1
|
||||
amfobj["Author"] = "dexter"
|
||||
@@ -167,7 +169,7 @@ func (conn *NetConnection) SendMessage(message string, args interface{}) error {
|
||||
if args != 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:
|
||||
if args != nil {
|
||||
return errors.New(SEND_PING_RESPONSE_MESSAGE + ", The parameter is nil")
|
||||
@@ -334,7 +336,6 @@ func (conn *NetConnection) SendMessage(message string, args interface{}) error {
|
||||
|
||||
return conn.sendAVMessage(video, false, true)
|
||||
case SEND_VIDEO_MESSAGE:
|
||||
{
|
||||
video, ok := args.(*avformat.SendPacket)
|
||||
if !ok {
|
||||
errors.New(message + ", The parameter is AVPacket")
|
||||
@@ -342,7 +343,6 @@ func (conn *NetConnection) SendMessage(message string, args interface{}) error {
|
||||
|
||||
return conn.sendAVMessage(video, false, false)
|
||||
}
|
||||
}
|
||||
|
||||
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的时间差值
|
||||
// 当块类型为0的时候,Chunk Message Header没有时间字段,与上一个Chunk时间值相同
|
||||
func (conn *NetConnection) sendAVMessage(av *avformat.SendPacket, isAudio bool, isFirst bool) error {
|
||||
if conn.writeSeqNum > conn.bandwidth {
|
||||
conn.totalWrite += conn.writeSeqNum
|
||||
conn.writeSeqNum = 0
|
||||
conn.SendMessage(SEND_ACK_MESSAGE, conn.totalWrite)
|
||||
conn.SendMessage(SEND_PING_REQUEST_MESSAGE, nil)
|
||||
}
|
||||
// if conn.writeSeqNum > conn.bandwidth {
|
||||
// conn.totalWrite += conn.writeSeqNum
|
||||
// conn.writeSeqNum = 0
|
||||
// conn.SendMessage(SEND_ACK_MESSAGE, conn.totalWrite)
|
||||
// conn.SendMessage(SEND_PING_REQUEST_MESSAGE, nil)
|
||||
// }
|
||||
|
||||
var err error
|
||||
var mark []byte
|
||||
|
||||
12
netStream.go
12
netStream.go
@@ -3,12 +3,13 @@ package rtmpplugin
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
. "github.com/Monibuca/engine"
|
||||
"github.com/Monibuca/engine/avformat"
|
||||
"log"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
. "github.com/Monibuca/engine"
|
||||
"github.com/Monibuca/engine/avformat"
|
||||
)
|
||||
|
||||
type RTMP struct {
|
||||
@@ -58,6 +59,9 @@ func processRtmp(conn net.Conn) {
|
||||
if room != nil {
|
||||
room.Cancel()
|
||||
}
|
||||
for _, s := range streams {
|
||||
s.Close()
|
||||
}
|
||||
}()
|
||||
var totalDuration uint32
|
||||
nc := &NetConnection{
|
||||
@@ -102,7 +106,7 @@ func processRtmp(conn net.Conn) {
|
||||
streamPath := nc.appName + "/" + strings.Split(pm.PublishingName, "?")[0]
|
||||
pub := new(RTMP)
|
||||
if pub.Publish(streamPath, pub) {
|
||||
pub.FirstScreen = make([]*avformat.AVPacket, 0)
|
||||
//pub.FirstScreen = make([]*avformat.AVPacket, 0)
|
||||
room = pub.Room
|
||||
err = nc.SendMessage(SEND_STREAM_BEGIN_MESSAGE, nil)
|
||||
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:
|
||||
err = nc.SendMessage(SEND_AUDIO_MESSAGE, packet)
|
||||
}
|
||||
return nil
|
||||
return
|
||||
}}
|
||||
stream.Type = "RTMP"
|
||||
stream.ID = fmt.Sprintf("%s|%d", conn.RemoteAddr().String(), nc.streamID)
|
||||
|
||||
Reference in New Issue
Block a user