10 changed files with 344 additions and 51 deletions
@ -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 |
||||||
|
} |
@ -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" |
||||||
|
) |
||||||
|
|
||||||
|
// MsgUserControlPingResponse is a user control message.
|
||||||
|
type MsgUserControlPingResponse struct { |
||||||
|
ServerTime uint32 |
||||||
|
} |
||||||
|
|
||||||
|
// Unmarshal implements Message.
|
||||||
|
func (m *MsgUserControlPingResponse) 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 MsgUserControlPingResponse) Marshal() (*rawmessage.Message, error) { |
||||||
|
body := make([]byte, 6) |
||||||
|
binary.BigEndian.PutUint16(body, UserControlTypePingResponse) |
||||||
|
binary.BigEndian.PutUint32(body[2:], m.ServerTime) |
||||||
|
|
||||||
|
return &rawmessage.Message{ |
||||||
|
ChunkStreamID: ControlChunkStreamID, |
||||||
|
Type: chunk.MessageTypeUserControl, |
||||||
|
Body: body, |
||||||
|
}, nil |
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
package message |
||||||
|
|
||||||
|
import ( |
||||||
|
"encoding/binary" |
||||||
|
"fmt" |
||||||
|
|
||||||
|
"github.com/aler9/rtsp-simple-server/internal/rtmp/chunk" |
||||||
|
"github.com/aler9/rtsp-simple-server/internal/rtmp/rawmessage" |
||||||
|
) |
||||||
|
|
||||||
|
// MsgUserControlSetBufferLength is a user control message.
|
||||||
|
type MsgUserControlSetBufferLength struct { |
||||||
|
StreamID uint32 |
||||||
|
BufferLength uint32 |
||||||
|
} |
||||||
|
|
||||||
|
// Unmarshal implements Message.
|
||||||
|
func (m *MsgUserControlSetBufferLength) Unmarshal(raw *rawmessage.Message) error { |
||||||
|
if raw.ChunkStreamID != ControlChunkStreamID { |
||||||
|
return fmt.Errorf("unexpected chunk stream ID") |
||||||
|
} |
||||||
|
|
||||||
|
if len(raw.Body) != 10 { |
||||||
|
return fmt.Errorf("invalid body size") |
||||||
|
} |
||||||
|
|
||||||
|
m.StreamID = binary.BigEndian.Uint32(raw.Body[2:]) |
||||||
|
m.BufferLength = binary.BigEndian.Uint32(raw.Body[6:]) |
||||||
|
|
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
// Marshal implements Message.
|
||||||
|
func (m MsgUserControlSetBufferLength) Marshal() (*rawmessage.Message, error) { |
||||||
|
body := make([]byte, 10) |
||||||
|
binary.BigEndian.PutUint16(body, UserControlTypeSetBufferLength) |
||||||
|
binary.BigEndian.PutUint32(body[2:], m.StreamID) |
||||||
|
binary.BigEndian.PutUint32(body[6:], m.BufferLength) |
||||||
|
|
||||||
|
return &rawmessage.Message{ |
||||||
|
ChunkStreamID: ControlChunkStreamID, |
||||||
|
Type: chunk.MessageTypeUserControl, |
||||||
|
Body: body, |
||||||
|
}, nil |
||||||
|
} |
@ -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" |
||||||
|
) |
||||||
|
|
||||||
|
// 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 = binary.BigEndian.Uint32(raw.Body[2:]) |
||||||
|
|
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
// Marshal implements Message.
|
||||||
|
func (m MsgUserControlStreamBegin) Marshal() (*rawmessage.Message, error) { |
||||||
|
body := make([]byte, 6) |
||||||
|
binary.BigEndian.PutUint16(body, UserControlTypeStreamBegin) |
||||||
|
binary.BigEndian.PutUint32(body[2:], m.StreamID) |
||||||
|
|
||||||
|
return &rawmessage.Message{ |
||||||
|
ChunkStreamID: ControlChunkStreamID, |
||||||
|
Type: chunk.MessageTypeUserControl, |
||||||
|
Body: body, |
||||||
|
}, nil |
||||||
|
} |
@ -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" |
||||||
|
) |
||||||
|
|
||||||
|
// MsgUserControlStreamDry is a user control message.
|
||||||
|
type MsgUserControlStreamDry struct { |
||||||
|
StreamID uint32 |
||||||
|
} |
||||||
|
|
||||||
|
// Unmarshal implements Message.
|
||||||
|
func (m *MsgUserControlStreamDry) 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 = binary.BigEndian.Uint32(raw.Body[2:]) |
||||||
|
|
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
// Marshal implements Message.
|
||||||
|
func (m MsgUserControlStreamDry) Marshal() (*rawmessage.Message, error) { |
||||||
|
body := make([]byte, 6) |
||||||
|
binary.BigEndian.PutUint16(body, UserControlTypeStreamDry) |
||||||
|
binary.BigEndian.PutUint32(body[2:], m.StreamID) |
||||||
|
|
||||||
|
return &rawmessage.Message{ |
||||||
|
ChunkStreamID: ControlChunkStreamID, |
||||||
|
Type: chunk.MessageTypeUserControl, |
||||||
|
Body: body, |
||||||
|
}, nil |
||||||
|
} |
@ -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" |
||||||
|
) |
||||||
|
|
||||||
|
// MsgUserControlStreamEOF is a user control message.
|
||||||
|
type MsgUserControlStreamEOF struct { |
||||||
|
StreamID uint32 |
||||||
|
} |
||||||
|
|
||||||
|
// Unmarshal implements Message.
|
||||||
|
func (m *MsgUserControlStreamEOF) 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 = binary.BigEndian.Uint32(raw.Body[2:]) |
||||||
|
|
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
// Marshal implements Message.
|
||||||
|
func (m MsgUserControlStreamEOF) Marshal() (*rawmessage.Message, error) { |
||||||
|
body := make([]byte, 6) |
||||||
|
binary.BigEndian.PutUint16(body, UserControlTypeStreamEOF) |
||||||
|
binary.BigEndian.PutUint32(body[2:], m.StreamID) |
||||||
|
|
||||||
|
return &rawmessage.Message{ |
||||||
|
ChunkStreamID: ControlChunkStreamID, |
||||||
|
Type: chunk.MessageTypeUserControl, |
||||||
|
Body: body, |
||||||
|
}, nil |
||||||
|
} |
@ -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" |
||||||
|
) |
||||||
|
|
||||||
|
// MsgUserControlStreamIsRecorded is a user control message.
|
||||||
|
type MsgUserControlStreamIsRecorded struct { |
||||||
|
StreamID uint32 |
||||||
|
} |
||||||
|
|
||||||
|
// Unmarshal implements Message.
|
||||||
|
func (m *MsgUserControlStreamIsRecorded) 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 = binary.BigEndian.Uint32(raw.Body[2:]) |
||||||
|
|
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
// Marshal implements Message.
|
||||||
|
func (m MsgUserControlStreamIsRecorded) Marshal() (*rawmessage.Message, error) { |
||||||
|
body := make([]byte, 6) |
||||||
|
binary.BigEndian.PutUint16(body, UserControlTypeStreamIsRecorded) |
||||||
|
binary.BigEndian.PutUint32(body[2:], m.StreamID) |
||||||
|
|
||||||
|
return &rawmessage.Message{ |
||||||
|
ChunkStreamID: ControlChunkStreamID, |
||||||
|
Type: chunk.MessageTypeUserControl, |
||||||
|
Body: body, |
||||||
|
}, nil |
||||||
|
} |
Loading…
Reference in new issue