🐛 FIX: 修复与srs服务器互联不通的问题

This commit is contained in:
dexter
2022-09-24 21:01:11 +08:00
parent b120021f8f
commit 9357e8799f
4 changed files with 27 additions and 26 deletions

8
amf.go
View File

@@ -160,8 +160,8 @@ func (amf *AMF) readDate() uint64 {
func (amf *AMF) readStrictArray() (list []AMFValue) {
amf.ReadByte()
size := amf.ReadUint16()
for i := uint16(0); i < size; i++ {
size := amf.ReadUint32()
for i := uint32(0); i < size; i++ {
list = append(list, amf.decodeObject())
}
return
@@ -170,8 +170,8 @@ func (amf *AMF) readStrictArray() (list []AMFValue) {
func (amf *AMF) readECMAArray() (m AMFObject) {
m = make(AMFObject, 0)
amf.ReadByte()
size := amf.ReadUint16()
for i := uint16(0); i < size; i++ {
size := amf.ReadUint32()
for i := uint32(0); i < size; i++ {
k := amf.readString1()
v := amf.decodeObject()
if k == "" && v == ObjectEnd {

View File

@@ -50,7 +50,7 @@ func NewRTMPClient(addr string) (client *NetConnection, err error) {
"app": client.appName,
"flashVer": "monibuca/" + engine.Engine.Version,
"swfUrl": addr,
"tcUrl": addr,
"tcUrl": strings.TrimSuffix(addr, u.Path) + "/" + client.appName,
},
nil,
})

View File

@@ -119,18 +119,18 @@ func (r *RTMPReceiver) ReceiveAudio(msg *Chunk) {
r.WriteAVCCAudio(0, msg.Body)
return
}
// plugin.Tracef("rec_audio chunkType:%d chunkStreamID:%d ts:%d", msg.ChunkType, msg.ChunkStreamID, msg.Timestamp)
ts := msg.Timestamp
if ts == 0xffffff {
ts = msg.ExtendTimestamp
}
if msg.ChunkType == 0 {
if r.AudioTrack.GetBase().Name == "" {
r.absTs[msg.ChunkStreamID] = 0
} else {
r.absTs[msg.ChunkStreamID] = r.AudioTrack.PreFrame().AbsTime
r.absTs[msg.ChunkStreamID] = ts
}
}
if msg.Timestamp == 0xffffff {
r.absTs[msg.ChunkStreamID] += msg.ExtendTimestamp
} else {
r.absTs[msg.ChunkStreamID] += msg.Timestamp
r.absTs[msg.ChunkStreamID] += ts
}
r.AudioTrack.WriteAVCC(r.absTs[msg.ChunkStreamID], msg.Body)
}
@@ -140,19 +140,18 @@ func (r *RTMPReceiver) ReceiveVideo(msg *Chunk) {
r.WriteAVCCVideo(0, msg.Body)
return
}
// plugin.Tracef("rev_video chunkType:%d chunkStreamID:%d ts:%d", msg.ChunkType, msg.ChunkStreamID, msg.Timestamp)
ts := msg.Timestamp
if ts == 0xffffff {
ts = msg.ExtendTimestamp
}
if msg.ChunkType == 0 {
if r.VideoTrack.GetBase().Name == "" {
r.absTs[msg.ChunkStreamID] = 0
} else {
r.absTs[msg.ChunkStreamID] = r.VideoTrack.PreFrame().AbsTime
r.absTs[msg.ChunkStreamID] = ts
}
}
if msg.Timestamp == 0xffffff {
r.absTs[msg.ChunkStreamID] += msg.ExtendTimestamp
} else {
r.absTs[msg.ChunkStreamID] += msg.Timestamp
r.absTs[msg.ChunkStreamID] += ts
}
r.VideoTrack.WriteAVCC(r.absTs[msg.ChunkStreamID], msg.Body)
}

18
msg.go
View File

@@ -334,7 +334,9 @@ func decodeCommandAMF0(chunk *Chunk) {
chunk.MsgData = response
}
case "FCPublish", "FCUnpublish":
fallthrough
default:
chunk.MsgData = &struct{ CommandMessage }{cmdMsg}
RTMPPlugin.Info("decode command amf0 ", zap.String("cmd", cmd))
}
}
@@ -505,16 +507,16 @@ func (msg *PlayMessage) Encode() []byte {
amf.writeNumber(float64(msg.TransactionId))
amf.writeNull()
amf.writeString(msg.StreamName)
amf.writeNumber(-2000)
// if msg.Start > 0 {
// amf.writeNumber(msg.Start)
// }
if msg.Start > 0 {
amf.writeNumber(msg.Start)
}
// if msg.Duration > 0 {
// amf.writeNumber(msg.Duration)
// }
if msg.Duration > 0 {
amf.writeNumber(msg.Duration)
}
amf.writeBool(msg.Reset)
// amf.writeBool(msg.Reset)
return amf.Buffer
}