mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-21 14:49:36 +08:00
rtmp: add message reader / writer
This commit is contained in:
39
internal/rtmp/message/msg_command_amf0.go
Normal file
39
internal/rtmp/message/msg_command_amf0.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package message
|
||||
|
||||
import (
|
||||
"github.com/notedit/rtmp/format/flv/flvio"
|
||||
|
||||
"github.com/aler9/rtsp-simple-server/internal/rtmp/chunk"
|
||||
"github.com/aler9/rtsp-simple-server/internal/rtmp/rawmessage"
|
||||
)
|
||||
|
||||
// MsgCommandAMF0 is a AMF0 command message.
|
||||
type MsgCommandAMF0 struct {
|
||||
ChunkStreamID byte
|
||||
MessageStreamID uint32
|
||||
Payload []interface{}
|
||||
}
|
||||
|
||||
// Unmarshal implements Message.
|
||||
func (m *MsgCommandAMF0) Unmarshal(raw *rawmessage.Message) error {
|
||||
m.ChunkStreamID = raw.ChunkStreamID
|
||||
m.MessageStreamID = raw.MessageStreamID
|
||||
|
||||
payload, err := flvio.ParseAMFVals(raw.Body, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.Payload = payload
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Marshal implements Message.
|
||||
func (m MsgCommandAMF0) Marshal() (*rawmessage.Message, error) {
|
||||
return &rawmessage.Message{
|
||||
ChunkStreamID: m.ChunkStreamID,
|
||||
Type: chunk.MessageTypeCommandAMF0,
|
||||
MessageStreamID: m.MessageStreamID,
|
||||
Body: flvio.FillAMF0ValsMalloc(m.Payload),
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user