message

package
v0.0.0-...-0558441 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package message contains a RTMP message reader/writer.

Index

Constants

View Source
const (
	CodecMPEG1Audio = 2
	CodecMPEG4Audio = 10
)

supported audio codecs

View Source
const (
	// AudioChunkStreamID is the chunk stream ID that is usually used to send Audio{}
	AudioChunkStreamID = 4
)
View Source
const (
	CodecH264 = 7
)

supported video codecs

View Source
const (
	// ControlChunkStreamID is the stream ID used for control messages.
	ControlChunkStreamID = 2
)
View Source
const (
	// VideoChunkStreamID is the chunk stream ID that is usually used to send Video{}
	VideoChunkStreamID = 6
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Acknowledge

type Acknowledge struct {
	Value uint32
}

Acknowledge is an acknowledgement message.

func (*Acknowledge) Marshal

func (m *Acknowledge) Marshal() (*rawmessage.Message, error)

Marshal implements Message.

func (*Acknowledge) Unmarshal

func (m *Acknowledge) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type Audio

type Audio struct {
	ChunkStreamID   byte
	DTS             time.Duration
	MessageStreamID uint32
	Codec           uint8
	Rate            uint8
	Depth           uint8
	Channels        uint8
	AACType         AudioAACType // only for CodecMPEG4Audio
	Payload         []byte
}

Audio is an audio message.

func (Audio) Marshal

func (m Audio) Marshal() (*rawmessage.Message, error)

Marshal implements Message.

func (*Audio) Unmarshal

func (m *Audio) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type AudioAACType

type AudioAACType uint8

AudioAACType is the AAC type of a Audio.

const (
	AudioAACTypeConfig AudioAACType = 0
	AudioAACTypeAU     AudioAACType = 1
)

AudioAACType values.

type CommandAMF0

type CommandAMF0 struct {
	ChunkStreamID   byte
	MessageStreamID uint32
	Name            string
	CommandID       int
	Arguments       []interface{}
}

CommandAMF0 is a AMF0 command message.

func (CommandAMF0) Marshal

func (m CommandAMF0) Marshal() (*rawmessage.Message, error)

Marshal implements Message.

func (*CommandAMF0) Unmarshal

func (m *CommandAMF0) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type DataAMF0

type DataAMF0 struct {
	ChunkStreamID   byte
	MessageStreamID uint32
	Payload         []interface{}
}

DataAMF0 is a AMF0 data message.

func (DataAMF0) Marshal

func (m DataAMF0) Marshal() (*rawmessage.Message, error)

Marshal implements Message.

func (*DataAMF0) Unmarshal

func (m *DataAMF0) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type ExtendedCodedFrames

type ExtendedCodedFrames struct {
	ChunkStreamID   byte
	DTS             time.Duration
	MessageStreamID uint32
	FourCC          FourCC
	PTSDelta        time.Duration
	Payload         []byte
}

ExtendedCodedFrames is a CodedFrames extended message.

func (ExtendedCodedFrames) Marshal

func (m ExtendedCodedFrames) Marshal() (*rawmessage.Message, error)

Marshal implements Message.

func (*ExtendedCodedFrames) Unmarshal

func (m *ExtendedCodedFrames) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type ExtendedFramesX

type ExtendedFramesX struct {
	ChunkStreamID   byte
	DTS             time.Duration
	MessageStreamID uint32
	FourCC          FourCC
	Payload         []byte
}

ExtendedFramesX is a FramesX extended message.

func (ExtendedFramesX) Marshal

func (m ExtendedFramesX) Marshal() (*rawmessage.Message, error)

Marshal implements Message.

func (*ExtendedFramesX) Unmarshal

func (m *ExtendedFramesX) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type ExtendedMPEG2TSSequenceStart

type ExtendedMPEG2TSSequenceStart struct {
	FourCC FourCC
}

ExtendedMPEG2TSSequenceStart is a MPEG2-TS sequence start extended message.

func (ExtendedMPEG2TSSequenceStart) Marshal

Marshal implements Message.

func (*ExtendedMPEG2TSSequenceStart) Unmarshal

Unmarshal implements Message.

type ExtendedMetadata

type ExtendedMetadata struct {
	FourCC FourCC
}

ExtendedMetadata is a metadata extended message.

func (ExtendedMetadata) Marshal

func (m ExtendedMetadata) Marshal() (*rawmessage.Message, error)

Marshal implements Message.

func (*ExtendedMetadata) Unmarshal

func (m *ExtendedMetadata) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type ExtendedSequenceEnd

type ExtendedSequenceEnd struct {
	FourCC FourCC
}

ExtendedSequenceEnd is a sequence end extended message.

func (ExtendedSequenceEnd) Marshal

func (m ExtendedSequenceEnd) Marshal() (*rawmessage.Message, error)

Marshal implements Message.

func (*ExtendedSequenceEnd) Unmarshal

func (m *ExtendedSequenceEnd) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type ExtendedSequenceStart

type ExtendedSequenceStart struct {
	ChunkStreamID   byte
	MessageStreamID uint32
	FourCC          FourCC
	Config          []byte
}

ExtendedSequenceStart is a sequence start extended message.

func (ExtendedSequenceStart) Marshal

Marshal implements Message.

func (*ExtendedSequenceStart) Unmarshal

func (m *ExtendedSequenceStart) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type ExtendedType

type ExtendedType uint8

ExtendedType is a message extended type.

const (
	ExtendedTypeSequenceStart        ExtendedType = 0
	ExtendedTypeCodedFrames          ExtendedType = 1
	ExtendedTypeSequenceEnd          ExtendedType = 2
	ExtendedTypeFramesX              ExtendedType = 3
	ExtendedTypeMetadata             ExtendedType = 4
	ExtendedTypeMPEG2TSSequenceStart ExtendedType = 5
)

message extended types.

type FourCC

type FourCC uint32

FourCC is an identifier of a video codec.

var (
	FourCCAV1  FourCC = 'a'<<24 | 'v'<<16 | '0'<<8 | '1'
	FourCCVP9  FourCC = 'v'<<24 | 'p'<<16 | '0'<<8 | '9'
	FourCCHEVC FourCC = 'h'<<24 | 'v'<<16 | 'c'<<8 | '1'
)

video codec identifiers.

type Message

type Message interface {
	Unmarshal(*rawmessage.Message) error
	Marshal() (*rawmessage.Message, error)
}

Message is a message.

type ReadWriter

type ReadWriter struct {
	// contains filtered or unexported fields
}

ReadWriter is a message reader/writer.

func NewReadWriter

func NewReadWriter(
	rw io.ReadWriter,
	bcrw *bytecounter.ReadWriter,
	checkAcknowledge bool,
) *ReadWriter

NewReadWriter allocates a ReadWriter.

func (*ReadWriter) Read

func (rw *ReadWriter) Read() (Message, error)

Read reads a message.

func (*ReadWriter) Write

func (rw *ReadWriter) Write(msg Message) error

Write writes a message.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader is a message reader.

func NewReader

func NewReader(
	r io.Reader,
	bcr *bytecounter.Reader,
	onAckNeeded func(uint32) error,
) *Reader

NewReader allocates a Reader.

func (*Reader) Read

func (r *Reader) Read() (Message, error)

Read reads a Message.

type SetChunkSize

type SetChunkSize struct {
	Value uint32
}

SetChunkSize is a set chunk size message.

func (*SetChunkSize) Marshal

func (m *SetChunkSize) Marshal() (*rawmessage.Message, error)

Marshal implements Message.

func (*SetChunkSize) Unmarshal

func (m *SetChunkSize) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type SetPeerBandwidth

type SetPeerBandwidth struct {
	Value uint32
	Type  byte
}

SetPeerBandwidth is a set peer bandwidth message.

func (*SetPeerBandwidth) Marshal

func (m *SetPeerBandwidth) Marshal() (*rawmessage.Message, error)

Marshal implements Message.

func (*SetPeerBandwidth) Unmarshal

func (m *SetPeerBandwidth) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type SetWindowAckSize

type SetWindowAckSize struct {
	Value uint32
}

SetWindowAckSize is a set window acknowledgement message.

func (*SetWindowAckSize) Marshal

func (m *SetWindowAckSize) Marshal() (*rawmessage.Message, error)

Marshal implements Message.

func (*SetWindowAckSize) Unmarshal

func (m *SetWindowAckSize) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type Type

type Type byte

Type is a message type.

const (
	TypeSetChunkSize     Type = 1
	TypeAbortMessage     Type = 2
	TypeAcknowledge      Type = 3
	TypeSetWindowAckSize Type = 5
	TypeSetPeerBandwidth Type = 6

	TypeUserControl Type = 4

	TypeCommandAMF3 Type = 17
	TypeCommandAMF0 Type = 20

	TypeDataAMF3 Type = 15
	TypeDataAMF0 Type = 18

	TypeAudio Type = 8
	TypeVideo Type = 9
)

message types.

type UserControlPingRequest

type UserControlPingRequest struct {
	ServerTime uint32
}

UserControlPingRequest is a user control message.

func (UserControlPingRequest) Marshal

Marshal implements Message.

func (*UserControlPingRequest) Unmarshal

func (m *UserControlPingRequest) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type UserControlPingResponse

type UserControlPingResponse struct {
	ServerTime uint32
}

UserControlPingResponse is a user control message.

func (UserControlPingResponse) Marshal

Marshal implements Message.

func (*UserControlPingResponse) Unmarshal

func (m *UserControlPingResponse) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type UserControlSetBufferLength

type UserControlSetBufferLength struct {
	StreamID     uint32
	BufferLength uint32
}

UserControlSetBufferLength is a user control message.

func (UserControlSetBufferLength) Marshal

Marshal implements Message.

func (*UserControlSetBufferLength) Unmarshal

Unmarshal implements Message.

type UserControlStreamBegin

type UserControlStreamBegin struct {
	StreamID uint32
}

UserControlStreamBegin is a user control message.

func (UserControlStreamBegin) Marshal

Marshal implements Message.

func (*UserControlStreamBegin) Unmarshal

func (m *UserControlStreamBegin) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type UserControlStreamDry

type UserControlStreamDry struct {
	StreamID uint32
}

UserControlStreamDry is a user control message.

func (UserControlStreamDry) Marshal

func (m UserControlStreamDry) Marshal() (*rawmessage.Message, error)

Marshal implements Message.

func (*UserControlStreamDry) Unmarshal

func (m *UserControlStreamDry) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type UserControlStreamEOF

type UserControlStreamEOF struct {
	StreamID uint32
}

UserControlStreamEOF is a user control message.

func (UserControlStreamEOF) Marshal

func (m UserControlStreamEOF) Marshal() (*rawmessage.Message, error)

Marshal implements Message.

func (*UserControlStreamEOF) Unmarshal

func (m *UserControlStreamEOF) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type UserControlStreamIsRecorded

type UserControlStreamIsRecorded struct {
	StreamID uint32
}

UserControlStreamIsRecorded is a user control message.

func (UserControlStreamIsRecorded) Marshal

Marshal implements Message.

func (*UserControlStreamIsRecorded) Unmarshal

Unmarshal implements Message.

type UserControlType

type UserControlType uint16

UserControlType is a user control type.

const (
	UserControlTypeStreamBegin      UserControlType = 0
	UserControlTypeStreamEOF        UserControlType = 1
	UserControlTypeStreamDry        UserControlType = 2
	UserControlTypeSetBufferLength  UserControlType = 3
	UserControlTypeStreamIsRecorded UserControlType = 4
	UserControlTypePingRequest      UserControlType = 6
	UserControlTypePingResponse     UserControlType = 7
)

user control types.

type Video

type Video struct {
	ChunkStreamID   byte
	DTS             time.Duration
	MessageStreamID uint32
	Codec           uint8
	IsKeyFrame      bool
	Type            VideoType
	PTSDelta        time.Duration
	Payload         []byte
}

Video is a video message.

func (Video) Marshal

func (m Video) Marshal() (*rawmessage.Message, error)

Marshal implements Message.

func (*Video) Unmarshal

func (m *Video) Unmarshal(raw *rawmessage.Message) error

Unmarshal implements Message.

type VideoType

type VideoType uint8

VideoType is the type of a video message.

const (
	VideoTypeConfig VideoType = 0
	VideoTypeAU     VideoType = 1
	VideoTypeEOS    VideoType = 2
)

VideoType values.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer is a message writer.

func NewWriter

func NewWriter(
	w io.Writer,
	bcw *bytecounter.Writer,
	checkAcknowledge bool,
) *Writer

NewWriter allocates a Writer.

func (*Writer) SetAcknowledgeValue

func (w *Writer) SetAcknowledgeValue(v uint32)

SetAcknowledgeValue sets the value of the last received acknowledge.

func (*Writer) Write

func (w *Writer) Write(msg Message) error

Write writes a message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL