mirror of
https://github.com/bluenviron/mediamtx
synced 2025-01-07 15:30:06 +00:00
9e6abc6e9f
* 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
40 lines
943 B
Go
40 lines
943 B
Go
package chunk
|
|
|
|
import (
|
|
"io"
|
|
)
|
|
|
|
// Chunk3 is a type 3 chunk.
|
|
// Type 3 chunks have no message header. The stream ID, message length
|
|
// and timestamp delta fields are not present; chunks of this type take
|
|
// values from the preceding chunk for the same Chunk Stream ID. When a
|
|
// single message is split into chunks, all chunks of a message except
|
|
// the first one SHOULD use this type.
|
|
type Chunk3 struct {
|
|
ChunkStreamID byte
|
|
Body []byte
|
|
}
|
|
|
|
// Read reads the chunk.
|
|
func (c *Chunk3) Read(r io.Reader, chunkBodyLen uint32) error {
|
|
header := make([]byte, 1)
|
|
_, err := io.ReadFull(r, header)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
c.ChunkStreamID = header[0] & 0x3F
|
|
|
|
c.Body = make([]byte, chunkBodyLen)
|
|
_, err = io.ReadFull(r, c.Body)
|
|
return err
|
|
}
|
|
|
|
// Marshal writes the chunk.
|
|
func (c Chunk3) Marshal() ([]byte, error) {
|
|
buf := make([]byte, 1+len(c.Body))
|
|
buf[0] = 3<<6 | c.ChunkStreamID
|
|
copy(buf[1:], c.Body)
|
|
return buf, nil
|
|
}
|