fix: extend timestamp

This commit is contained in:
langhuihui
2024-05-20 12:57:25 +08:00
parent efe5c2b0ee
commit 8df3cf16e2
3 changed files with 18 additions and 8 deletions

View File

@@ -115,7 +115,7 @@ func (nc *NetConnection) simple_handshake(C1 []byte) error {
copy(S0S1[5:], "Monibuca")
nc.Write(S0S1)
nc.Write(C1) // S2
if C2 := ReadBuf(nc.Reader, C1S1_SIZE); bytes.Compare(C2[8:], S0S1[9:]) != 0 {
if C2 := ReadBuf(nc.Reader, C1S1_SIZE); conf.C2 && bytes.Compare(C2[8:], S0S1[9:]) != 0 {
return errors.New("C2 Error")
}
return nil

View File

@@ -20,6 +20,7 @@ type RTMPConfig struct {
config.Push
ChunkSize int `default:"65535" desc:"分片大小"`
KeepAlive bool `desc:"保持连接,流断开不关闭连接"` //保持rtmp连接默认随着stream的close而主动断开
C2 bool `desc:"握手是否检查C2"`
}
func pull(streamPath, url string) {

View File

@@ -156,7 +156,6 @@ func (conn *NetConnection) readChunk() (msg *Chunk, err error) {
conn.readSeqNum += uint32(n)
}
if chunk.AVData.Push(mem); chunk.AVData.ByteLength == msgLen {
chunk.ChunkHeader.ExtendTimestamp += chunk.ChunkHeader.Timestamp
msg = chunk
switch chunk.MessageTypeID {
case RTMP_MSG_AUDIO, RTMP_MSG_VIDEO:
@@ -210,6 +209,7 @@ func (conn *NetConnection) readChunkType(h *ChunkHeader, chunkType byte) (err er
if chunkType == 3 {
// 3个字节的时间戳
} else {
h.Timestamp = 0
// Timestamp 3 bytes
if _, err = conn.ReadFull(b3); err != nil {
return err
@@ -234,17 +234,26 @@ func (conn *NetConnection) readChunkType(h *ChunkHeader, chunkType byte) (err er
}
}
}
// ExtendTimestamp 4 bytes
if h.Timestamp == 0xffffff { // 对于type 0的chunk,绝对时间戳在这里表示,如果时间戳值大于等于0xffffff(16777215),该值必须是0xffffff,且时间戳扩展字段必须发送,其他情况没有要求
if h.Timestamp >= 0xffffff { // 对于type 0的chunk,绝对时间戳在这里表示,如果时间戳值大于等于0xffffff(16777215),该值必须是0xffffff,且时间戳扩展字段必须发送,其他情况没有要求
if _, err = conn.ReadFull(b4); err != nil {
return err
}
util.GetBE(b4, &h.Timestamp)
}
if chunkType == 0 {
h.ExtendTimestamp = h.Timestamp
h.Timestamp = 0
switch chunkType {
case 0:
h.ExtendTimestamp = h.Timestamp
case 1, 2:
h.ExtendTimestamp += (h.Timestamp -0xffffff)
}
} else {
switch chunkType {
case 0:
h.ExtendTimestamp = h.Timestamp
case 1, 2:
h.ExtendTimestamp += h.Timestamp
}
}
return nil
}