mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-14 03:44:42 +08:00
rtmp: add user control messages
This commit is contained in:
@@ -1,44 +1,12 @@
|
||||
package message
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/aler9/rtsp-simple-server/internal/rtmp/chunk"
|
||||
"github.com/aler9/rtsp-simple-server/internal/rtmp/rawmessage"
|
||||
// user control types.
|
||||
const (
|
||||
UserControlTypeStreamBegin = 0
|
||||
UserControlTypeStreamEOF = 1
|
||||
UserControlTypeStreamDry = 2
|
||||
UserControlTypeSetBufferLength = 3
|
||||
UserControlTypeStreamIsRecorded = 4
|
||||
UserControlTypePingRequest = 6
|
||||
UserControlTypePingResponse = 7
|
||||
)
|
||||
|
||||
// MsgUserControl is a user control message.
|
||||
type MsgUserControl struct {
|
||||
Type uint16
|
||||
Payload []byte
|
||||
}
|
||||
|
||||
// Unmarshal implements Message.
|
||||
func (m *MsgUserControl) Unmarshal(raw *rawmessage.Message) error {
|
||||
if raw.ChunkStreamID != ControlChunkStreamID {
|
||||
return fmt.Errorf("unexpected chunk stream ID")
|
||||
}
|
||||
|
||||
if len(raw.Body) < 2 {
|
||||
return fmt.Errorf("unexpected body size")
|
||||
}
|
||||
|
||||
m.Type = binary.BigEndian.Uint16(raw.Body)
|
||||
m.Payload = raw.Body[2:]
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Marshal implements Message.
|
||||
func (m MsgUserControl) Marshal() (*rawmessage.Message, error) {
|
||||
body := make([]byte, 2+len(m.Payload))
|
||||
binary.BigEndian.PutUint16(body, m.Type)
|
||||
copy(body[2:], m.Payload)
|
||||
|
||||
return &rawmessage.Message{
|
||||
ChunkStreamID: ControlChunkStreamID,
|
||||
Type: chunk.MessageTypeUserControl,
|
||||
Body: body,
|
||||
}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user