From 45a06a10f714798eb233095cd531ec3d48493479 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Thu, 10 Aug 2023 03:24:48 +0500 Subject: [PATCH] chunk read fix, msg stream id read fix and open stream init func --- rtmp/chunk.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rtmp/chunk.go b/rtmp/chunk.go index 28cfef6..a7b0569 100644 --- a/rtmp/chunk.go +++ b/rtmp/chunk.go @@ -21,6 +21,11 @@ type message struct { msg_len uint32 } +func OpenStreamsMapInit() (map[uint32]*chnk_stream, map[uint32]*message) { + open_chnkstrms := make(map[uint32]*chnk_stream) + open_msgs := make(map[uint32]*message) + return open_chnkstrms, open_msgs +} func read_basic_header(conn net.Conn) (uint8, uint32, error) { fmt_csid_byte := make([]byte, 1) @@ -74,7 +79,7 @@ func read_message_header_0(conn net.Conn, chnk_stream_ptr *chnk_stream, msg_ptr msg_ptr.msg_type = msg_typeid[0] msg_streamid := make([]byte, 4) - if _, err := conn.Read(msg_typeid); err != nil { + if _, err := conn.Read(msg_streamid); err != nil { return err } chnk_stream_ptr.last_msg_strm_id = binary.BigEndian.Uint32(msg_streamid) @@ -94,9 +99,9 @@ func read_chunk_data(conn net.Conn, msg_ptr *message, chnk_size uint32) (error) bytes_left := msg_ptr.msg_len - msg_ptr.curr_bytes_read var buffer_end uint32 if bytes_left < chnk_size { - buffer_end = bytes_left + msg_ptr.curr_bytes_read + 1 + buffer_end = bytes_left + msg_ptr.curr_bytes_read } else { - buffer_end = chnk_size + msg_ptr.curr_bytes_read + 1 + buffer_end = chnk_size + msg_ptr.curr_bytes_read } n, err := conn.Read(msg_ptr.data[msg_ptr.curr_bytes_read:buffer_end]) if err != nil {