mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-13 19:35:13 +08:00
rtmp: rewrite implementation of rtmp connection (#1047)
* rtmp: improve MsgCommandAMF0 * rtmp: fix MsgSetPeerBandwidth * rtmp: add message tests * rtmp: replace implementation with new one * rtmp: rename handshake functions * rtmp: avoid calling useless function * rtmp: use time.Duration for PTSDelta * rtmp: fix decoding chunks with relevant size * rtmp: rewrite implementation of rtmp connection * rtmp: fix tests * rtmp: improve error message * rtmp: replace h264 config implementation * link against github.com/notedit/rtmp * normalize MessageStreamID * rtmp: make acknowledge optional * rtmp: fix decoding of chunk2 + chunk3 * avoid using encoding/binary
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package message
|
||||
package message //nolint:dupl
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/aler9/rtsp-simple-server/internal/rtmp/chunk"
|
||||
@@ -24,22 +23,30 @@ func (m *MsgUserControlSetBufferLength) Unmarshal(raw *rawmessage.Message) error
|
||||
return fmt.Errorf("invalid body size")
|
||||
}
|
||||
|
||||
m.StreamID = binary.BigEndian.Uint32(raw.Body[2:])
|
||||
m.BufferLength = binary.BigEndian.Uint32(raw.Body[6:])
|
||||
m.StreamID = uint32(raw.Body[2])<<24 | uint32(raw.Body[3])<<16 | uint32(raw.Body[4])<<8 | uint32(raw.Body[5])
|
||||
m.BufferLength = uint32(raw.Body[6])<<24 | uint32(raw.Body[7])<<16 | uint32(raw.Body[8])<<8 | uint32(raw.Body[9])
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Marshal implements Message.
|
||||
func (m MsgUserControlSetBufferLength) Marshal() (*rawmessage.Message, error) {
|
||||
body := make([]byte, 10)
|
||||
binary.BigEndian.PutUint16(body, UserControlTypeSetBufferLength)
|
||||
binary.BigEndian.PutUint32(body[2:], m.StreamID)
|
||||
binary.BigEndian.PutUint32(body[6:], m.BufferLength)
|
||||
buf := make([]byte, 10)
|
||||
|
||||
buf[0] = byte(UserControlTypeSetBufferLength >> 8)
|
||||
buf[1] = byte(UserControlTypeSetBufferLength)
|
||||
buf[2] = byte(m.StreamID >> 24)
|
||||
buf[3] = byte(m.StreamID >> 16)
|
||||
buf[4] = byte(m.StreamID >> 8)
|
||||
buf[5] = byte(m.StreamID)
|
||||
buf[6] = byte(m.BufferLength >> 24)
|
||||
buf[7] = byte(m.BufferLength >> 16)
|
||||
buf[8] = byte(m.BufferLength >> 8)
|
||||
buf[9] = byte(m.BufferLength)
|
||||
|
||||
return &rawmessage.Message{
|
||||
ChunkStreamID: ControlChunkStreamID,
|
||||
Type: chunk.MessageTypeUserControl,
|
||||
Body: body,
|
||||
Body: buf,
|
||||
}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user