From d90127def66fc41a57b8ac5e11e03062f01a32e4 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Sun, 13 Aug 2023 14:30:39 +0500 Subject: [PATCH] Try writing chunks, start with window ack size msg --- rtmp/chunk_wrap.go | 28 +++++++++++++++++++++++++++- rtmp/connect.go | 3 +++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/rtmp/chunk_wrap.go b/rtmp/chunk_wrap.go index 927adda..f801ca7 100644 --- a/rtmp/chunk_wrap.go +++ b/rtmp/chunk_wrap.go @@ -4,6 +4,7 @@ import ( "net" "encoding/binary" "stream_server/rtmp/amf" + "fmt" ) type ChunkWrapper struct { @@ -48,6 +49,20 @@ func (chnk_wrp_ptr *ChunkWrapper) ReadChunk() (*Message, error) { return full_msg_ptr, nil } +func (chnk_wrp_ptr *ChunkWrapper) WriteChunk(csid uint32, msg_strmid uint32, msg_ptr *Message) (error) { + err := WriteChunk( + chnk_wrp_ptr.conn, + csid, + msg_strmid, + msg_ptr, + chnk_wrp_ptr.params.chunk_size, + ) + if err != nil { + return err + } + return nil +} + func (chnk_wrp_ptr *ChunkWrapper) ReadPeerChunkSize() (error) { set_chunk_size_msg, err := chnk_wrp_ptr.ReadChunk() if err != nil || set_chunk_size_msg.msg_type != 1 || set_chunk_size_msg.msg_len != 4 { @@ -71,5 +86,16 @@ func (chnk_wrp_ptr *ChunkWrapper) ReadConnectCommand() (error) { return err } return err - +} + +func (chnk_wrp_ptr *ChunkWrapper) WriteWindowAckSize() (error) { + msg_ptr := new(Message) + msg_ptr.msg_type = 5 + msg_ptr.data = make([]byte, 4) + msg_ptr.msg_len = 4 + binary.BigEndian.PutUint32(msg_ptr.data, 5000000) + if err := chnk_wrp_ptr.WriteChunk(2, 0, msg_ptr); err != nil { + return err + } + return nil } diff --git a/rtmp/connect.go b/rtmp/connect.go index 6eb006a..452f178 100644 --- a/rtmp/connect.go +++ b/rtmp/connect.go @@ -11,6 +11,9 @@ func NegotiateConnect(chnk_wrp_ptr *ChunkWrapper) (bool) { if err := chnk_wrp_ptr.ReadConnectCommand(); err != nil { return false } + if err := chnk_wrp_ptr.WriteWindowAckSize(); err != nil { + return false + } fmt.Println(chnk_wrp_ptr.params) return false }