mediamtx/internal/rtmp/message/msg_usercontrol_streambegin.go

47 lines
1.2 KiB
Go
Raw Normal View History

package message //nolint:dupl
2022-06-05 20:44:55 +00:00
import (
"fmt"
"github.com/aler9/rtsp-simple-server/internal/rtmp/chunk"
"github.com/aler9/rtsp-simple-server/internal/rtmp/rawmessage"
)
// MsgUserControlStreamBegin is a user control message.
type MsgUserControlStreamBegin struct {
StreamID uint32
}
// Unmarshal implements Message.
func (m *MsgUserControlStreamBegin) Unmarshal(raw *rawmessage.Message) error {
if raw.ChunkStreamID != ControlChunkStreamID {
return fmt.Errorf("unexpected chunk stream ID")
}
if len(raw.Body) != 6 {
return fmt.Errorf("invalid body size")
}
m.StreamID = uint32(raw.Body[2])<<24 | uint32(raw.Body[3])<<16 | uint32(raw.Body[4])<<8 | uint32(raw.Body[5])
2022-06-05 20:44:55 +00:00
return nil
}
// Marshal implements Message.
func (m MsgUserControlStreamBegin) Marshal() (*rawmessage.Message, error) {
buf := make([]byte, 6)
buf[0] = byte(UserControlTypeStreamBegin >> 8)
buf[1] = byte(UserControlTypeStreamBegin)
buf[2] = byte(m.StreamID >> 24)
buf[3] = byte(m.StreamID >> 16)
buf[4] = byte(m.StreamID >> 8)
buf[5] = byte(m.StreamID)
2022-06-05 20:44:55 +00:00
return &rawmessage.Message{
ChunkStreamID: ControlChunkStreamID,
Type: chunk.MessageTypeUserControl,
Body: buf,
2022-06-05 20:44:55 +00:00
}, nil
}