diff --git a/handshake.go b/handshake.go index 031f858..b15bf52 100644 --- a/handshake.go +++ b/handshake.go @@ -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 diff --git a/main.go b/main.go index dc7523f..c105eb8 100644 --- a/main.go +++ b/main.go @@ -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) { diff --git a/netConnection.go b/netConnection.go index b6d04e6..960cad9 100644 --- a/netConnection.go +++ b/netConnection.go @@ -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 }