Merge branch 'v4' into v4

This commit is contained in:
Rodrigo Stewart
2024-05-21 10:20:51 +08:00
committed by GitHub
3 changed files with 16 additions and 6 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

@@ -160,7 +160,6 @@ func (conn *NetConnection) readChunk() (msg *Chunk, err error) {
return nil, err
}
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:
@@ -236,16 +235,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 _, err = conn.ReadFull(b4); err != nil {
return err
}
util.GetBE(b4, &h.Timestamp)
}
if chunkType == 0 {
h.ExtendTimestamp = h.Timestamp
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
}