diff --git a/rtmp/amf/command.go b/rtmp/amf/command.go index 8cab681..81291bf 100644 --- a/rtmp/amf/command.go +++ b/rtmp/amf/command.go @@ -72,3 +72,13 @@ func EncodeConnectResponse() ([]byte, error) { return Encode(amf_root_obj) } + +func EncodeCreateStreamResponse(trans_id float64) ([]byte, error) { + amf_root_obj := make(AMFObj) + amf_root_obj[0] = "_result" + amf_root_obj[1] = trans_id + amf_root_obj[2] = nil + amf_root_obj[3] = 1.0 + + return Encode(amf_root_obj) +} diff --git a/rtmp/chunk_wrap.go b/rtmp/chunk_wrap.go index bc11428..d2ed0b7 100644 --- a/rtmp/chunk_wrap.go +++ b/rtmp/chunk_wrap.go @@ -19,8 +19,8 @@ func NewChunkWrapper(conn net.Conn) (chnk_wrp_ptr *ChunkWrapper) { chnk_wrp_ptr.conn = conn chnk_wrp_ptr.params = new(ProtocolParams) - chnk_wrp_ptr.params.chunk_size = 128 - chnk_wrp_ptr.params.peer_chunk_size = 128 + chnk_wrp_ptr.params.chunk_size = 256 + chnk_wrp_ptr.params.peer_chunk_size = 4096 chnk_wrp_ptr.open_chnkstrms = make(map[uint32]*ChunkStream) chnk_wrp_ptr.open_msgs = make(map[uint32]*Message) buffers := ChunkBuffers{ @@ -158,5 +158,17 @@ func (chnk_wrp_ptr *ChunkWrapper) ReadCreateStream() (error) { } func (chnk_wrp_ptr *ChunkWrapper) WriteCreateStreamResponse() (error) { + msg_ptr := new(Message) + msg_ptr.msg_type = 20 + msg_data, err := amf.EncodeCreateStreamResponse(chnk_wrp_ptr.params.trans_id) + if err != nil { + return err + } + msg_ptr.msg_len = uint32(len(msg_data)) + msg_ptr.data = msg_data + + if err := chnk_wrp_ptr.WriteChunk(3, 0, msg_ptr); err != nil { + return err + } return nil } diff --git a/rtmp/connect.go b/rtmp/connect.go index 9d8fd14..57cf41a 100644 --- a/rtmp/connect.go +++ b/rtmp/connect.go @@ -34,10 +34,10 @@ func CreateStream(chnk_wrp_ptr *ChunkWrapper) (bool) { if err := chnk_wrp_ptr.ReadCreateStream(); err != nil { return false } - fmt.Println("test read") if err := chnk_wrp_ptr.WriteCreateStreamResponse(); err != nil { return false } - fmt.Println("test") + p, _ := chnk_wrp_ptr.ReadChunk() + fmt.Println(p) return true }