mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-11 10:30:25 +08:00
rtmp: add user control messages
This commit is contained in:
42
internal/rtmp/message/msg_usercontrol_pingrequest.go
Normal file
42
internal/rtmp/message/msg_usercontrol_pingrequest.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package message
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/aler9/rtsp-simple-server/internal/rtmp/chunk"
|
||||
"github.com/aler9/rtsp-simple-server/internal/rtmp/rawmessage"
|
||||
)
|
||||
|
||||
// MsgUserControlPingRequest is a user control message.
|
||||
type MsgUserControlPingRequest struct {
|
||||
ServerTime uint32
|
||||
}
|
||||
|
||||
// Unmarshal implements Message.
|
||||
func (m *MsgUserControlPingRequest) 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.ServerTime = binary.BigEndian.Uint32(raw.Body[2:])
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Marshal implements Message.
|
||||
func (m MsgUserControlPingRequest) Marshal() (*rawmessage.Message, error) {
|
||||
body := make([]byte, 6)
|
||||
binary.BigEndian.PutUint16(body, UserControlTypePingRequest)
|
||||
binary.BigEndian.PutUint32(body[2:], m.ServerTime)
|
||||
|
||||
return &rawmessage.Message{
|
||||
ChunkStreamID: ControlChunkStreamID,
|
||||
Type: chunk.MessageTypeUserControl,
|
||||
Body: body,
|
||||
}, nil
|
||||
}
|
Reference in New Issue
Block a user