2022-07-17 13:17:18 +00:00
|
|
|
package message //nolint:dupl
|
2022-06-04 23:06:40 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-04-01 17:52:06 +00:00
|
|
|
"github.com/aler9/mediamtx/internal/rtmp/rawmessage"
|
2022-06-04 23:06:40 +00:00
|
|
|
)
|
|
|
|
|
2023-05-04 18:37:25 +00:00
|
|
|
// SetPeerBandwidth is a set peer bandwidth message.
|
|
|
|
type SetPeerBandwidth struct {
|
2022-06-04 23:06:40 +00:00
|
|
|
Value uint32
|
|
|
|
Type byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal implements Message.
|
2023-05-04 18:37:25 +00:00
|
|
|
func (m *SetPeerBandwidth) Unmarshal(raw *rawmessage.Message) error {
|
2022-06-04 23:06:40 +00:00
|
|
|
if raw.ChunkStreamID != ControlChunkStreamID {
|
|
|
|
return fmt.Errorf("unexpected chunk stream ID")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(raw.Body) != 5 {
|
2023-05-04 18:37:25 +00:00
|
|
|
return fmt.Errorf("invalid body size")
|
2022-06-04 23:06:40 +00:00
|
|
|
}
|
|
|
|
|
2022-07-17 13:17:18 +00:00
|
|
|
m.Value = uint32(raw.Body[0])<<24 | uint32(raw.Body[1])<<16 | uint32(raw.Body[2])<<8 | uint32(raw.Body[3])
|
2022-06-04 23:06:40 +00:00
|
|
|
m.Type = raw.Body[4]
|
2022-07-17 13:17:18 +00:00
|
|
|
|
2022-06-04 23:06:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Marshal implements Message.
|
2023-05-04 18:37:25 +00:00
|
|
|
func (m *SetPeerBandwidth) Marshal() (*rawmessage.Message, error) {
|
2022-07-17 13:17:18 +00:00
|
|
|
buf := make([]byte, 5)
|
|
|
|
|
|
|
|
buf[0] = byte(m.Value >> 24)
|
|
|
|
buf[1] = byte(m.Value >> 16)
|
|
|
|
buf[2] = byte(m.Value >> 8)
|
|
|
|
buf[3] = byte(m.Value)
|
|
|
|
buf[4] = m.Type
|
2022-06-04 23:06:40 +00:00
|
|
|
|
|
|
|
return &rawmessage.Message{
|
|
|
|
ChunkStreamID: ControlChunkStreamID,
|
2023-05-04 18:37:25 +00:00
|
|
|
Type: uint8(TypeSetPeerBandwidth),
|
2022-07-17 13:17:18 +00:00
|
|
|
Body: buf,
|
2022-06-04 23:06:40 +00:00
|
|
|
}, nil
|
|
|
|
}
|