librtmp

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CONNECT        = "connect"
	RELEASE_STREAM = "releaseStream"
	FCPUBLISH      = "FCPublish"
	FCUNPUBLISH    = "FCUnpublish"
	CALL           = "call"
	CLOSE          = "close"
	CREATE_STREAM  = "createStream"
	PUBLISH        = "publish"
	PLAY           = "play"
	PLAY2          = "play2"
	DELETE_STREAM  = "deleteStream"
	CLOSE_STREAM   = "closeStream"
	RECEIVE_AUDIO  = "receiveAudio"
	RECEIVE_VIDEO  = "receiveVideo"
	SEEK           = "seek"
	PAUSE          = "pause"

	ON_STATUS = "onStatus"
)
View Source
const (
	C0_LEN = 1
	C1_LEN = 1536
	C2_LEN = 1536
	S0_LEN = 1
	S1_LEN = 1536
	S2_LEN = 1536
)
View Source
const (
	//control message
	SET_CHUNK_SIZE              MessageType = iota + 1 //1
	ABORT_MESSAGE                                      //2
	ACKNOWLEDGEMENT                                    //3
	USER_CONTROL_MESSAGE                               //4
	WINDOW_ACKNOWLEDGEMENT_SIZE                        //5
	SET_PEER_BANDWIDTH                                 //6

	//common message
	AUDIO_MESSAGE = iota + 2 //8
	VIDEO_MESSAGE            //9

	//command message
	DATA_MESSAGE_AMF3         = iota + 7 //15
	SHARE_OBJECT_MESSAGE_AMF3            //16
	COMMAND_MESSAGE_AMF3                 //17
	DATA_MESSAGE_AMF0                    //18
	SHARE_OBJECT_MESSAGE_AMF0            //19
	COMMAND_MESSAGE_AMF0                 //20
)

Variables

View Source
var (
	FMSKey = []byte{
		0x47, 0x65, 0x6e, 0x75, 0x69, 0x6e, 0x65, 0x20,
		0x41, 0x64, 0x6f, 0x62, 0x65, 0x20, 0x46, 0x6c,
		0x61, 0x73, 0x68, 0x20, 0x4d, 0x65, 0x64, 0x69,
		0x61, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72,
		0x20, 0x30, 0x30, 0x31,
		0xf0, 0xee, 0xc2, 0x4a, 0x80, 0x68, 0xbe, 0xe8,
		0x2e, 0x00, 0xd0, 0xd1, 0x02, 0x9e, 0x7e, 0x57,
		0x6e, 0xec, 0x5d, 0x2d, 0x29, 0x80, 0x6f, 0xab,
		0x93, 0xb8, 0xe6, 0x36, 0xcf, 0xeb, 0x31, 0xae,
	}
	FPkey = []byte{
		0x47, 0x65, 0x6E, 0x75, 0x69, 0x6E, 0x65, 0x20,
		0x41, 0x64, 0x6F, 0x62, 0x65, 0x20, 0x46, 0x6C,
		0x61, 0x73, 0x68, 0x20, 0x50, 0x6C, 0x61, 0x79,
		0x65, 0x72, 0x20, 0x30, 0x30, 0x31,
		0xF0, 0xEE, 0xC2, 0x4A, 0x80, 0x68, 0xBE, 0xE8,
		0x2E, 0x00, 0xD0, 0xD1, 0x02, 0x9E, 0x7E, 0x57,
		0x6E, 0xEC, 0x5D, 0x2D, 0x29, 0x80, 0x6F, 0xAB,
		0x93, 0xB8, 0xE6, 0x36, 0xCF, 0xEB, 0x31, 0xAE,
	}
)

Functions

func HandshakeClient

func HandshakeClient(rtmp *RTMP) (err error)

func HandshakeServer

func HandshakeServer(rtmp *RTMP) (err error)

func NewServer

func NewServer(address string, apps ...string) (s *server)

func ParseMessage

func ParseMessage(rtmp *RTMP) (err error)

Types

type AbortMessage

type AbortMessage struct {
	MessageBase
	ChunkStreamID int
}

func NewAbortMessage

func NewAbortMessage(mb MessageBase, fields ...interface{}) (am *AbortMessage)

func (*AbortMessage) Do

func (scsm *AbortMessage) Do() error

func (*AbortMessage) Parse

func (scsm *AbortMessage) Parse() (err error)

func (*AbortMessage) Send

func (scsm *AbortMessage) Send() error

type AcknowledgeMessage

type AcknowledgeMessage struct {
	MessageBase
	SequenceNumber int
}

func NewAcknowledgeMessage

func NewAcknowledgeMessage(mb MessageBase, fields ...interface{}) (am *AcknowledgeMessage)

func (*AcknowledgeMessage) Do

func (scsm *AcknowledgeMessage) Do() error

func (*AcknowledgeMessage) Parse

func (scsm *AcknowledgeMessage) Parse() (err error)

func (*AcknowledgeMessage) Send

func (scsm *AcknowledgeMessage) Send() error

type App

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

func NewApp

func NewApp(appName string) *App

func (*App) Load

func (app *App) Load(roomID string) *Room

func (*App) Store

func (app *App) Store(roomID string, room *Room)

type AudioCodec

type AudioCodec float64
const (
	SUPPORT_SND_NONE AudioCodec = 0x0001 << iota
	SUPPORT_SND_ADPCM
	SUPPORT_SND_MP3
	SUPPORT_SND_INTEL
	SUPPORT_SND_UNUSED
	SUPPORT_SND_NELLY8
	SUPPORT_SND_NELLY
	SUPPORT_SND_G711A
	SUPPORT_SND_G711U
	SUPPORT_SND_NELLY16
	SUPPORT_SND_AAC
	SUPPORT_SND_SPEEX
	SUPPORT_SND_ALL = 0x0fff
)

type AudioMessage

type AudioMessage struct {
	MessageBase
	// contains filtered or unexported fields
}

func NewAudioMessage

func NewAudioMessage(mb MessageBase, fields ...interface{}) (am *AudioMessage)

func (*AudioMessage) Do

func (am *AudioMessage) Do() (err error)

func (*AudioMessage) Parse

func (am *AudioMessage) Parse() (err error)

func (*AudioMessage) Send

func (am *AudioMessage) Send() (err error)

type Chunk

type Chunk struct {
	ChunkBasicHeader
	ChunkMessageHeader
	Payload []byte
}

func NewChunk

func NewChunk(messageType MessageType, messageLength uint32, messageTime uint32, format MessageHeaderType, csid uint32, payload []byte) (chunk *Chunk)

NOTE: ensure len(payload) <= peerMaxChunkSize

func ParseChunk

func ParseChunk(rtmp *RTMP, message Message) (cp *Chunk, err error)

func (*Chunk) Send

func (chunk *Chunk) Send(rtmp *RTMP) (err error)

type ChunkBasicHeader

type ChunkBasicHeader struct {
	Fmt  MessageHeaderType //2 bits
	CsID uint32            //6, 14 or 22 bits
}

type ChunkMessageHeader

type ChunkMessageHeader struct {
	MessageTimeStamp uint32 //3bytes or 4bytes(extended timestamp)
	MessageTimeDelta uint32
	MessageLength    uint32 //3bytes
	MessageType      MessageType
	MessageStreamID  uint32 //little-endian 4bytes
}

type CommandMessage

type CommandMessage struct {
	MessageBase
	CommandName    string
	TranscationID  int
	CommandObject  ConnectReqCommandObject
	PublishingName string //releaseStream,FCPublish,publish
	//Type of publishing. Set to "live", "record", or "append".
	//TODO:record: The stream is published and the data is recorded to a new file. The file is stored on the server in a subdirectory within the directory that contains the server application. If the file already exists, it is overwritten.
	//TODO:append: The stream is published and the data is appended to a file. If no file is found, it is created.
	//live: Live data is published without recording it in a file.
	PublishingType string  //publish
	StreamName     string  //play
	Start          float64 //play
	Duration       float64 //play
	Reset          bool    //play
}

func NewCommandMessage

func NewCommandMessage(mb MessageBase, fields ...interface{}) (cm *CommandMessage)

func (*CommandMessage) Do

func (cm *CommandMessage) Do() (err error)

func (*CommandMessage) Parse

func (cm *CommandMessage) Parse() (err error)

func (*CommandMessage) Send

func (cm *CommandMessage) Send() (err error)

type CommandMessageResponse

type CommandMessageResponse struct {
	MessageBase
	CommandName     string
	CommandRespName string
	TranscationID   int
	CommandObject   ConnectRespCommandObject
	StreamID        uint32
}

func (*CommandMessageResponse) Send

func (cmr *CommandMessageResponse) Send() (err error)

type ConnectReqCommandObject

type ConnectReqCommandObject struct {
	App            string        `mapstructure:"app"`
	FlashVer       string        `mapstructure:"flashver"`
	SwfURL         string        `mapstructure:"swfUrl"`
	TcURL          string        `mapstructure:"tcUrl"`
	Fpad           bool          `mapstructure:"fpad"`
	AudioCodecs    AudioCodec    `mapstructure:"audioCodecs"`
	VideoCodecs    VideoCodec    `mapstructure:"videoCodecs"`
	VideoFunction  VideoFunction `mapstructure:"videoFunction"`
	PageURL        string        `mapstructure:"pageUrl"`
	ObjectEncoding float64       `mapstructure:"objectEncoding"`
	Type           string        `mapstructure:"type"`
	Capabilities   float64       `mapstructure:"capabilities"`
}

type ConnectRespCommandObject

type ConnectRespCommandObject struct {
	FmsVer         string  `structs:"fmsVer,omitempty"`
	Level          string  `structs:"level,omitempty"`
	Code           string  `structs:"code,omitempty"`
	Description    string  `structs:"description,omitempty"`
	Capabilities   float64 `structs:"capabilities,omitempty"`
	ObjectEncoding float64 `structs:"object_encoding,omitempty"`
}

type DataMessage

type DataMessage struct {
	MessageBase
	// contains filtered or unexported fields
}

func NewDataMessage

func NewDataMessage(mb MessageBase, fields ...interface{}) (dm *DataMessage)

func (*DataMessage) Do

func (dm *DataMessage) Do() (err error)

func (*DataMessage) Parse

func (dm *DataMessage) Parse() (err error)

func (*DataMessage) Send

func (dm *DataMessage) Send() (err error)

type EventType

type EventType uint16
const (
	StreamBegin EventType = iota
	StreamEOF
	StreamDry
	SetBufferLength
	StreamIsRecorded

	PingRequest
	PingResponse
)

type HandshakeMode

type HandshakeMode int
const (
	SIMPLE   HandshakeMode = 0
	COMPLEX1 HandshakeMode = 1
	COMPLEX2 HandshakeMode = 2
)

type LimitType

type LimitType uint8
const (
	HARD    LimitType = 0
	SOFT    LimitType = 1
	DYNAMIC LimitType = 2
)

type Message

type Message interface {
	Append(*Chunk)
	Remain() uint32
	Done() bool
	GetInfo() *MessageBase
	Update(uint32)

	//Parse() parse binary data that receive from peer
	Parse() error
	//when receive the message, Do() operator fields in RTMP belongs to this message, and send response to peer
	Do() error
	//Send() post the message to peer which generated from NewXXX()
	Send() error
}

type MessageBase

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

func (*MessageBase) Append

func (mb *MessageBase) Append(chunk *Chunk)

func (*MessageBase) Done

func (mb *MessageBase) Done() bool

func (*MessageBase) GetInfo

func (mb *MessageBase) GetInfo() *MessageBase

func (*MessageBase) Remain

func (mb *MessageBase) Remain() uint32

func (*MessageBase) Update

func (mb *MessageBase) Update(time uint32)

type MessageHeaderType

type MessageHeaderType uint8
const (
	FMT0 MessageHeaderType = iota
	FMT1
	FMT2
	FMT3
)

type MessageType

type MessageType uint8
  • MessageType 1-7 --- control message --- -- MessageStreamID: 0 -- ChunkStreamID: 2 -- TimeStamp: ignore
  • 1: set chunk size
  • 2: abort message
  • 3: acknowledgement
  • 4: user control message
  • 5: window acknowledgement size
  • 6: set peer bandwidth
  • 7: TODO is used between edge server and origin server --- common message ---
  • 8: audio message
  • 9: video message --- command message ---
  • 15(AMF3)/18(AMF0): data message
  • 16(AMF3)/19(AMF0): share object message
  • 17(AMF3)/20(AMF0): command message
  • 22: aggregate message

type Peer

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

type RTMP

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

func NewRTMP

func NewRTMP(conn net.Conn, peer string, server *server) (rtmp *RTMP)

func (*RTMP) HandlerClient

func (rtmp *RTMP) HandlerClient()

func (*RTMP) HandlerServer

func (rtmp *RTMP) HandlerServer()

type Room

type Room struct {
	RoomID    string
	Publisher *RTMP //TODO: support multi publisher
	//Players   sync.Map     //peer ip+port, rtmp conn
	GOP *broadcast.Broadcast
}

func NewRoom

func NewRoom(rtmp *RTMP, roomID string) *Room

NOTE: the room must be created by publisher

func (*Room) FLVJoin

func (room *Room) FLVJoin(writer easyio.EasyWriter)

func (*Room) HLSJoin

func (room *Room) HLSJoin(writer easyio.EasyWriter)

func (*Room) RTMPJoin

func (room *Room) RTMPJoin(rtmp *RTMP)

player join the room

type SetChunkSizeMessage

type SetChunkSizeMessage struct {
	MessageBase
	NewChunkSize uint32
}

func NewSetChunkSizeMessage

func NewSetChunkSizeMessage(mb MessageBase, fields ...interface{}) (scsm *SetChunkSizeMessage)

func (*SetChunkSizeMessage) Do

func (scsm *SetChunkSizeMessage) Do() error

func (*SetChunkSizeMessage) Parse

func (scsm *SetChunkSizeMessage) Parse() (err error)

func (*SetChunkSizeMessage) Send

func (scsm *SetChunkSizeMessage) Send() error

type SetPeerBandWidthMessage

type SetPeerBandWidthMessage struct {
	MessageBase
	AcknowledgementWindowSize uint32
	LimitType                 LimitType
}

func NewSetPeerBandWidthMessage

func NewSetPeerBandWidthMessage(mb MessageBase, fields ...interface{}) (spbwm *SetPeerBandWidthMessage)

func (*SetPeerBandWidthMessage) Do

func (spbwm *SetPeerBandWidthMessage) Do() (err error)

func (*SetPeerBandWidthMessage) Parse

func (spbwm *SetPeerBandWidthMessage) Parse() (err error)

func (*SetPeerBandWidthMessage) Send

func (spbwm *SetPeerBandWidthMessage) Send() (err error)

type UserControlMessage

type UserControlMessage struct {
	MessageBase
	EventType EventType
	EventData []byte
}

func NewUserControlMessage

func NewUserControlMessage(mb MessageBase, fields ...interface{}) (ucm *UserControlMessage)

func (*UserControlMessage) Do

func (ucm *UserControlMessage) Do() (err error)

func (*UserControlMessage) Parse

func (ucm *UserControlMessage) Parse() (err error)

func (*UserControlMessage) Send

func (ucm *UserControlMessage) Send() (err error)

type VideoCodec

type VideoCodec float64
const (
	SUPPORT_VID_UNUSE VideoCodec = 0x0001 << iota
	SUPPORT_VID_JPEG
	SUPPORT_VID_SORENSON
	SUPPORT_VID_HOMEBREW
	SUPPORT_VID_VP6
	SUPPORT_VID_VP6ALPHA
	SUPPORT_VID_HOMEBREWV
	SUPPORT_VID_H264
	SUPPORT_VID_ALL = 0x00ff
)

type VideoFunction

type VideoFunction float64
const (
	SUPPORT_VID_CLIENT_SEEK VideoFunction = 1
)

type VideoMessage

type VideoMessage struct {
	MessageBase
	// contains filtered or unexported fields
}

func NewVideoMessage

func NewVideoMessage(mb MessageBase, fields ...interface{}) (vm *VideoMessage)

func (*VideoMessage) Do

func (vm *VideoMessage) Do() (err error)

func (*VideoMessage) Parse

func (vm *VideoMessage) Parse() (err error)

func (*VideoMessage) Send

func (vm *VideoMessage) Send() (err error)

type WindowAcknowledgeSizeMessage

type WindowAcknowledgeSizeMessage struct {
	MessageBase
	AcknowledgementWindowSize uint32
}

func NewWindowAcknowledgeSizeMessage

func NewWindowAcknowledgeSizeMessage(mb MessageBase, fields ...interface{}) (wasm *WindowAcknowledgeSizeMessage)

func (*WindowAcknowledgeSizeMessage) Do

func (wasm *WindowAcknowledgeSizeMessage) Do() (err error)

func (*WindowAcknowledgeSizeMessage) Parse

func (wasm *WindowAcknowledgeSizeMessage) Parse() (err error)

func (*WindowAcknowledgeSizeMessage) Send

func (wasm *WindowAcknowledgeSizeMessage) Send() (err error)

Jump to

Keyboard shortcuts

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