mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-14 10:45:08 +00:00
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package message //nolint:dupl
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/aler9/mediamtx/internal/rtmp/chunk"
|
|
"github.com/aler9/mediamtx/internal/rtmp/rawmessage"
|
|
)
|
|
|
|
// MsgSetChunkSize is a set chunk size message.
|
|
type MsgSetChunkSize struct {
|
|
Value uint32
|
|
}
|
|
|
|
// Unmarshal implements Message.
|
|
func (m *MsgSetChunkSize) Unmarshal(raw *rawmessage.Message) error {
|
|
if raw.ChunkStreamID != ControlChunkStreamID {
|
|
return fmt.Errorf("unexpected chunk stream ID")
|
|
}
|
|
|
|
if len(raw.Body) != 4 {
|
|
return fmt.Errorf("unexpected body size")
|
|
}
|
|
|
|
m.Value = uint32(raw.Body[0])<<24 | uint32(raw.Body[1])<<16 | uint32(raw.Body[2])<<8 | uint32(raw.Body[3])
|
|
|
|
return nil
|
|
}
|
|
|
|
// Marshal implements Message.
|
|
func (m *MsgSetChunkSize) Marshal() (*rawmessage.Message, error) {
|
|
buf := make([]byte, 4)
|
|
|
|
buf[0] = byte(m.Value >> 24)
|
|
buf[1] = byte(m.Value >> 16)
|
|
buf[2] = byte(m.Value >> 8)
|
|
buf[3] = byte(m.Value)
|
|
|
|
return &rawmessage.Message{
|
|
ChunkStreamID: ControlChunkStreamID,
|
|
Type: chunk.MessageTypeSetChunkSize,
|
|
Body: buf,
|
|
}, nil
|
|
}
|