protocol

package
v0.0.0-...-ed4fbfc Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2016 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

The protocol package provides protocol feature for oryx, for example, the rtmp/flv/264/aac muxer and demuxer.

Index

Examples

Constants

View Source
const (
	MarkerAmf0Number      = 0x00
	MarkerAmf0Boolean     = 0x01
	MarkerAmf0String      = 0x02
	MarkerAmf0Object      = 0x03
	MarkerAmf0MovieClip   = 0x04 // reserved, not supported
	MarkerAmf0Null        = 0x05
	MarkerAmf0Undefined   = 0x06
	MarkerAmf0Reference   = 0x07
	MarkerAmf0EcmaArray   = 0x08
	MarkerAmf0ObjectEnd   = 0x09
	MarkerAmf0StrictArray = 0x0A
	MarkerAmf0Date        = 0x0B
	MarkerAmf0LongString  = 0x0C
	MarkerAmf0UnSupported = 0x0D
	MarkerAmf0RecordSet   = 0x0E // reserved, not supported
	MarkerAmf0XmlDocument = 0x0F
	MarkerAmf0TypedObject = 0x10
	// AVM+ object is the AMF3 object.
	MarkerAmf0AVMplusObject = 0x11
	// origin array whose data takes the same form as LengthValueBytes
	MarkerAmf0OriginStrictArray = 0x20

	// User defined
	MarkerAmf0Invalid = 0x3F
)

AMF0 marker

View Source
const (
	// timeout for rtmp.
	HandshakeTimeout   = 2100 * time.Millisecond
	ConnectAppTimeout  = 5000 * time.Millisecond
	IdentifyTimeout    = ConnectAppTimeout
	FmlePublishTimeout = IdentifyTimeout
	PublishRecvTimeout = 30 * time.Second

	// the input cache, to read from network and put in it.
	RtmpInCache = 16
)
View Source
const (
	// c1s1 schema0
	//     key: 764bytes
	//     digest: 764bytes
	Schema0 chsSchema = iota
	// c1s1 schema1
	//     digest: 764bytes
	//     key: 764bytes
	// @remark FMS only support schema1, please read
	// 		http://blog.csdn.net/win_lin/article/details/13006803
	Schema1
)
View Source
const (
	// 6.1.2.1. Type 0
	// Chunks of Type 0 are 11 bytes long. This type MUST be used at the
	// start of a chunk stream, and whenever the stream timestamp goes
	// backward (e.g., because of a backward seek).
	RtmpFmtType0 = iota
	// 6.1.2.2. Type 1
	// Chunks of Type 1 are 7 bytes long. The message stream ID is not
	// included; this chunk takes the same stream ID as the preceding chunk.
	// Streams with variable-sized messages (for example, many video
	// formats) SHOULD use this format for the first chunk of each new
	// message after the first.
	RtmpFmtType1
	// 6.1.2.3. Type 2
	// Chunks of Type 2 are 3 bytes long. Neither the stream ID nor the
	// message length is included; this chunk has the same stream ID and
	// message length as the preceding chunk. Streams with constant-sized
	// messages (for example, some audio and data formats) SHOULD use this
	// format for the first chunk of each message after the first.
	RtmpFmtType2
	// 6.1.2.4. Type 3
	// Chunks of Type 3 have no header. Stream ID, message length and
	// timestamp delta are not present; chunks of this type take values from
	// the preceding chunk. When a single message is split into chunks, all
	// chunks of a message except the first one, SHOULD use this type. Refer
	// to example 2 in section 6.2.2. Stream consisting of messages of
	// exactly the same size, stream ID and spacing in time SHOULD use this
	// type for all chunks after chunk of Type 2. Refer to example 1 in
	// section 6.2.1. If the delta between the first message and the second
	// message is same as the time stamp of first message, then chunk of
	// type 3 would immediately follow the chunk of type 0 as there is no
	// need for a chunk of type 2 to register the delta. If Type 3 chunk
	// follows a Type 0 chunk, then timestamp delta for this Type 3 chunk is
	// the same as the timestamp of Type 0 chunk.
	RtmpFmtType3
)

6.1.2. Chunk Message Header There are four different formats for the chunk message header, selected by the "fmt" field in the chunk basic header.

View Source
const (
	// the chunk stream id used for some under-layer message,
	// for example, the PC(protocol control) message.
	RtmpCidProtocolControl = 0x02 + iota
	// the AMF0/AMF3 command message, invoke method and return the result, over NetConnection.
	// generally use 0x03.
	RtmpCidOverConnection
	// the AMF0/AMF3 command message, invoke method and return the result, over NetConnection,
	// the midst state(we guess).
	// rarely used, e.g. onStatus(NetStream.Play.Reset).
	RtmpCidOverConnection2
	// the stream message(amf0/amf3), over NetStream.
	// generally use 0x05.
	RtmpCidOverStream
	// the stream message(amf0/amf3), over NetStream, the midst state(we guess).
	// rarely used, e.g. play("mp4:mystram.f4v")
	RtmpCidOverStream2
	// the stream message(video), over NetStream
	// generally use 0x06.
	RtmpCidVideo
	// the stream message(audio), over NetStream.
	// generally use 0x07.
	RtmpCidAudio
)
View Source
const (
	// amf0 command message, command name macros
	Amf0CommandConnect       = "connect"
	Amf0CommandCreateStream  = "createStream"
	Amf0CommandCloseStream   = "closeStream"
	Amf0CommandPlay          = "play"
	Amf0CommandPause         = "pause"
	Amf0CommandOnBwDone      = "onBWDone"
	Amf0CommandOnStatus      = "onStatus"
	Amf0CommandResult        = "_result"
	Amf0CommandError         = "_error"
	Amf0CommandReleaseStream = "releaseStream"
	Amf0CommandFcPublish     = "FCPublish"
	Amf0CommandUnpublish     = "FCUnpublish"
	Amf0CommandPublish       = "publish"
	Amf0DataSampleAccess     = "|RtmpSampleAccess"

	// FMLE
	Amf0CommandOnFcPublish   = "onFCPublish"
	Amf0CommandOnFcUnpublish = "onFCUnpublish"

	// the signature for packets to client.
	RtmpSigFmsVer   = "3,5,3,888"
	RtmpSigAmf0Ver  = 0
	RtmpSigClientId = "ASAICiss"

	// onStatus consts.
	StatusLevel       = "level"
	StatusCode        = "code"
	StatusDescription = "description"
	StatusDetails     = "details"
	StatusClientId    = "clientid"
	// status value
	StatusLevelStatus = "status"
	// status error
	StatusLevelError = "error"
	// code value
	StatusCodeConnectSuccess   = "NetConnection.Connect.Success"
	StatusCodeConnectRejected  = "NetConnection.Connect.Rejected"
	StatusCodeStreamReset      = "NetStream.Play.Reset"
	StatusCodeStreamStart      = "NetStream.Play.Start"
	StatusCodeStreamPause      = "NetStream.Pause.Notify"
	StatusCodeStreamUnpause    = "NetStream.Unpause.Notify"
	StatusCodePublishStart     = "NetStream.Publish.Start"
	StatusCodeDataStart        = "NetStream.Data.Start"
	StatusCodeUnpublishSuccess = "NetStream.Unpublish.Success"
)
View Source
const RtmpDefaultMwMessages = 25

the preloaded group messages.

View Source
const RtmpExtendedTimestamp = 0xFFFFFF

6.1. Chunk Format Extended timestamp: 0 or 4 bytes This field MUST be sent when the normal timsestamp is set to 0xffffff, it MUST NOT be sent if the normal timestamp is set to anything else. So for values less than 0xffffff the normal timestamp field SHOULD be used in which case the extended timestamp MUST NOT be present. For values greater than or equal to 0xffffff the normal timestamp field MUST NOT be used and MUST be set to 0xffffff and the extended timestamp MUST be sent.

View Source
const RtmpMaxChunkHeader = 12

max chunk header is fmt0.

View Source
const RtmpMaxChunkSize = 65536
View Source
const RtmpMinChunkSize = 128

6. Chunking The chunk size is configurable. It can be set using a control message(Set Chunk Size) as described in section 7.1. The maximum chunk size can be 65536 bytes and minimum 128 bytes. Larger values reduce CPU usage, but also commit to larger writes that can delay other content on lower bandwidth connections. Smaller chunks are not good for high-bit rate streaming. Chunk size is maintained independently for each direction.

View Source
const RtmpProtocolChunkSize = 128

6. Chunking, RTMP protocol default chunk size.

View Source
const RtmpServerChunkSize = 60000

the default chunk size for system.

Variables

View Source
var Amf0Error = errors.New("amf0 error")

the amf0 object error.

View Source
var RequestUrlError = errors.New("rtmp request url error")

the rtmp request url error.

View Source
var RtmpChunkError = errors.New("rtmp chunk error")

when read RTMP chunk error.

View Source
var RtmpGenuineFMSKey []byte = []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,

} // 68

68bytes FMS key which is used to sign the sever packet.

View Source
var RtmpGenuineFPKey []byte = []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,

} // 62

62bytes FP key which is used to sign the client packet.

View Source
var RtmpPayloadError = errors.New("rtmp msg payload error")

when got RTMP msg invalid payload.

Functions

func NewAmf0Properties

func NewAmf0Properties() *amf0Properties

func NewHsBytes

func NewHsBytes(ctx core.Context) *hsBytes

func NewReaderSize

func NewReaderSize(ctx core.Context, r io.Reader, size int) bufferedReader

Types

type Amf0Any

type Amf0Any interface {
	encoding.BinaryMarshaler
	core.UnmarshalSizer
}

the amf0 type interface

func Amf0Discovery

func Amf0Discovery(data []byte) (a Amf0Any, err error)

discovery the Amf0Any type by marker.

type Amf0Boolean

type Amf0Boolean bool

read amf0 boolean from stream. 2.4 String Type boolean-type = boolean-marker U8

0 is false, <> 0 is true

@return default value is false.

func NewAmf0Bool

func NewAmf0Bool(v bool) *Amf0Boolean

func (*Amf0Boolean) MarshalBinary

func (v *Amf0Boolean) MarshalBinary() (data []byte, err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	s := protocol.Amf0Boolean(true)

	var b []byte
	var err error
	if b, err = s.MarshalBinary(); err != nil {
		return
	}

	fmt.Println(len(b))
	fmt.Println(b)

}
Output:

2
[1 1]

func (*Amf0Boolean) Size

func (v *Amf0Boolean) Size() int

func (Amf0Boolean) String

func (v Amf0Boolean) String() string

func (*Amf0Boolean) UnmarshalBinary

func (v *Amf0Boolean) UnmarshalBinary(data []byte) (err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	b := []byte{0x01, 0x01} // read from network

	var s protocol.Amf0Boolean
	if err := s.UnmarshalBinary(b); err != nil {
		return
	}

	fmt.Println(s)

}
Output:

true

type Amf0Date

type Amf0Date struct {
	// date value
	// An ActionScript Date is serialized as the number of milliseconds
	// elapsed since the epoch of midnight on 1st Jan 1970 in the UTC
	// time zone.
	Date uint64
	// time zone
	// While the design of this type reserves room for time zone offset
	// information, it should not be filled in, nor used, as it is unconventional
	// to change time zones when serializing dates on a network. It is suggested
	// that the time zone be queried independently as needed.
	Zone uint16
}

2.13 Date Type time-zone = S16 ; reserved, not supported should be set to 0x0000 date-type = date-marker DOUBLE time-zone @see: https://github.com/ossrs/srs/issues/185

func (*Amf0Date) From

func (v *Amf0Date) From(t time.Time)

TODO: parse with system time.Time.

func (*Amf0Date) MarshalBinary

func (v *Amf0Date) MarshalBinary() (data []byte, err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
	"time"
)

func main() {
	s := protocol.Amf0Date{}

	s.From(time.Now())

	var b []byte
	var err error
	if b, err = s.MarshalBinary(); err != nil {
		return
	}

	fmt.Println(len(b))
	fmt.Println("amf0 date")

}
Output:

11
amf0 date

func (*Amf0Date) Size

func (v *Amf0Date) Size() int

func (Amf0Date) String

func (v Amf0Date) String() string

func (*Amf0Date) UnmarshalBinary

func (v *Amf0Date) UnmarshalBinary(data []byte) (err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	b := []byte{0x0b, 0, 0, 1, 81, 30, 96, 9, 6, 112, 128} // read from network

	var s protocol.Amf0Date
	if err := s.UnmarshalBinary(b); err != nil {
		return
	}

	fmt.Println("amf0 date")

}
Output:

amf0 date

type Amf0EcmaArray

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

2.10 ECMA Array Type ecma-array-type = associative-count *(object-property) associative-count = U32 object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker)

func NewAmf0EcmaArray

func NewAmf0EcmaArray() *Amf0EcmaArray

func (*Amf0EcmaArray) Get

func (v *Amf0EcmaArray) Get(name string) (value Amf0Any)

func (*Amf0EcmaArray) MarshalBinary

func (v *Amf0EcmaArray) MarshalBinary() (data []byte, err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	s := protocol.NewAmf0EcmaArray()

	s.Set("pj", protocol.NewAmf0String("oryx"))
	s.Set("start", protocol.NewAmf0Number(2015))

	var b []byte
	var err error
	if b, err = s.MarshalBinary(); err != nil {
		return
	}

	fmt.Println(len(b))
	fmt.Println("amf0 ecma array")

}
Output:

35
amf0 ecma array

func (*Amf0EcmaArray) Set

func (v *Amf0EcmaArray) Set(name string, value Amf0Any)

func (*Amf0EcmaArray) Size

func (v *Amf0EcmaArray) Size() int

func (Amf0EcmaArray) String

func (v Amf0EcmaArray) String() string

func (*Amf0EcmaArray) UnmarshalBinary

func (v *Amf0EcmaArray) UnmarshalBinary(data []byte) (err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	b := []byte{8, 0, 0, 0, 0, 0, 2, 'p', 'j', 2, 0, 4, 'o', 'r', 'y', 'x', 0, 5, 's', 't', 'a', 'r', 't', 0, 64, 159, 124, 0, 0, 0, 0, 0, 0, 0, 9} // read from network

	// must always new the amf0 ecma-array to init the properties.
	s := protocol.NewAmf0EcmaArray()
	if err := s.UnmarshalBinary(b); err != nil {
		return
	}

	fmt.Println("amf0 ecma array")

	if v, ok := s.Get("pj").(*protocol.Amf0String); ok {
		fmt.Println("value string:", string(*v))
	}
	if v, ok := s.Get("start").(*protocol.Amf0Number); ok {
		fmt.Println("value number:", float64(*v))
	}

}
Output:

amf0 ecma array
value string: oryx
value number: 2015

type Amf0Null

type Amf0Null struct{}

read amf0 null from stream. 2.7 null Type null-type = null-marker

func (*Amf0Null) MarshalBinary

func (v *Amf0Null) MarshalBinary() (data []byte, err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	s := protocol.Amf0Null{}

	var b []byte
	var err error
	if b, err = s.MarshalBinary(); err != nil {
		return
	}

	fmt.Println(len(b))
	fmt.Println(b)

}
Output:

1
[5]

func (*Amf0Null) Size

func (v *Amf0Null) Size() int

func (Amf0Null) String

func (v Amf0Null) String() string

func (*Amf0Null) UnmarshalBinary

func (v *Amf0Null) UnmarshalBinary(data []byte) (err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	b := []byte{0x05} // read from network

	var s protocol.Amf0Null
	if err := s.UnmarshalBinary(b); err != nil {
		return
	}

	fmt.Println("amf0 null")

}
Output:

amf0 null

type Amf0Number

type Amf0Number float64

read amf0 number from stream. 2.2 Number Type number-type = number-marker DOUBLE @return default value is 0.

func NewAmf0Number

func NewAmf0Number(v float64) *Amf0Number

func (*Amf0Number) MarshalBinary

func (v *Amf0Number) MarshalBinary() (data []byte, err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	s := protocol.Amf0Number(100.0)

	var b []byte
	var err error
	if b, err = s.MarshalBinary(); err != nil {
		return
	}

	fmt.Println(len(b))
	fmt.Println(b)

}
Output:

9
[0 64 89 0 0 0 0 0 0]

func (*Amf0Number) Size

func (v *Amf0Number) Size() int

func (Amf0Number) String

func (v Amf0Number) String() string

func (*Amf0Number) UnmarshalBinary

func (v *Amf0Number) UnmarshalBinary(data []byte) (err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	b := []byte{0x00, 0x40, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // read from network

	var s protocol.Amf0Number
	if err := s.UnmarshalBinary(b); err != nil {
		return
	}

	fmt.Println(s)

}
Output:

100

type Amf0Object

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

2.5 Object Type anonymous-object-type = object-marker *(object-property) object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker)

func NewAmf0Object

func NewAmf0Object() *Amf0Object

func (*Amf0Object) Get

func (v *Amf0Object) Get(name string) (value Amf0Any)

func (*Amf0Object) MarshalBinary

func (v *Amf0Object) MarshalBinary() (data []byte, err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	s := protocol.NewAmf0Object()

	s.Set("pj", protocol.NewAmf0String("oryx"))
	s.Set("start", protocol.NewAmf0Number(2015))

	var b []byte
	var err error
	if b, err = s.MarshalBinary(); err != nil {
		return
	}

	fmt.Println(len(b))
	fmt.Println("amf0 object")

}
Output:

31
amf0 object

func (*Amf0Object) Set

func (v *Amf0Object) Set(name string, value Amf0Any)

func (*Amf0Object) Size

func (v *Amf0Object) Size() int

func (Amf0Object) String

func (v Amf0Object) String() string

func (*Amf0Object) UnmarshalBinary

func (v *Amf0Object) UnmarshalBinary(data []byte) (err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	b := []byte{3, 0, 2, 'p', 'j', 2, 0, 4, 'o', 'r', 'y', 'x', 0, 5, 's', 't', 'a', 'r', 't', 0, 64, 159, 124, 0, 0, 0, 0, 0, 0, 0, 9} // read from network

	// must always new the amf0 object to init the properties.
	s := protocol.NewAmf0Object()
	if err := s.UnmarshalBinary(b); err != nil {
		return
	}

	fmt.Println("amf0 object")

	if v, ok := s.Get("pj").(*protocol.Amf0String); ok {
		fmt.Println("value string:", string(*v))
	}
	if v, ok := s.Get("start").(*protocol.Amf0Number); ok {
		fmt.Println("value number:", float64(*v))
	}

}
Output:

amf0 object
value string: oryx
value number: 2015

type Amf0StrictArray

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

2.12 Strict Array Type array-count = U32 strict-array-type = array-count *(value-type)

func NewAmf0StrictArray

func NewAmf0StrictArray() *Amf0StrictArray

func (*Amf0StrictArray) Add

func (*Amf0StrictArray) Count

func (v *Amf0StrictArray) Count() int

func (*Amf0StrictArray) Get

func (v *Amf0StrictArray) Get(index int) Amf0Any

func (*Amf0StrictArray) MarshalBinary

func (v *Amf0StrictArray) MarshalBinary() (data []byte, err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	s := protocol.NewAmf0StrictArray()

	s.Add(protocol.NewAmf0String("oryx"))
	s.Add(protocol.NewAmf0Number(2015))

	var b []byte
	var err error
	if b, err = s.MarshalBinary(); err != nil {
		return
	}

	fmt.Println(len(b))
	fmt.Println("amf0 strict array")

}
Output:

21
amf0 strict array

func (*Amf0StrictArray) Size

func (v *Amf0StrictArray) Size() int

func (Amf0StrictArray) String

func (v Amf0StrictArray) String() string

func (*Amf0StrictArray) UnmarshalBinary

func (v *Amf0StrictArray) UnmarshalBinary(data []byte) (err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	b := []byte{0x0A, 0, 0, 0, 2, 2, 0, 4, 'o', 'r', 'y', 'x', 0, 64, 159, 124, 0, 0, 0, 0, 0} // read from network

	// must always new the amf0 strict-array to init the properties.
	s := protocol.NewAmf0StrictArray()
	if err := s.UnmarshalBinary(b); err != nil {
		return
	}

	fmt.Println("amf0 strict array")

	if v, ok := s.Get(0).(*protocol.Amf0String); ok {
		fmt.Println("elem string:", string(*v))
	}
	if v, ok := s.Get(1).(*protocol.Amf0Number); ok {
		fmt.Println("elem number:", float64(*v))
	}

}
Output:

amf0 strict array
elem string: oryx
elem number: 2015

type Amf0String

type Amf0String string

read amf0 string from stream. 2.4 String Type string-type = string-marker UTF-8 @return default value is empty string. @remark: use SrsAmf0Any::str() to create it.

func NewAmf0String

func NewAmf0String(v string) *Amf0String

func (*Amf0String) MarshalBinary

func (v *Amf0String) MarshalBinary() (data []byte, err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	s := protocol.Amf0String("oryx")

	var b []byte
	var err error
	if b, err = s.MarshalBinary(); err != nil {
		return
	}

	fmt.Println(len(b))
	fmt.Println(b)

}
Output:

7
[2 0 4 111 114 121 120]

func (*Amf0String) Size

func (v *Amf0String) Size() int

func (Amf0String) String

func (v Amf0String) String() string

func (*Amf0String) UnmarshalBinary

func (v *Amf0String) UnmarshalBinary(data []byte) (err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	b := []byte{0x02, 0x00, 0x04, 'o', 'r', 'y', 'x'} // read from network

	var s protocol.Amf0String
	if err := s.UnmarshalBinary(b); err != nil {
		return
	}

	fmt.Println(s)

}
Output:

oryx

type Amf0Undefined

type Amf0Undefined struct{}

read amf0 undefined from stream. 2.8 undefined Type undefined-type = undefined-marker

func (*Amf0Undefined) MarshalBinary

func (v *Amf0Undefined) MarshalBinary() (data []byte, err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	s := protocol.Amf0Undefined{}

	var b []byte
	var err error
	if b, err = s.MarshalBinary(); err != nil {
		return
	}

	fmt.Println(len(b))
	fmt.Println(b)

}
Output:

1
[6]

func (*Amf0Undefined) Size

func (v *Amf0Undefined) Size() int

func (Amf0Undefined) String

func (v Amf0Undefined) String() string

func (*Amf0Undefined) UnmarshalBinary

func (v *Amf0Undefined) UnmarshalBinary(data []byte) (err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx/protocol"
)

func main() {
	b := []byte{0x06} // read from network

	var s protocol.Amf0Undefined
	if err := s.UnmarshalBinary(b); err != nil {
		return
	}

	fmt.Println("amf0 undefined")

}
Output:

amf0 undefined

type OryxRtmpMessage

type OryxRtmpMessage struct {
	Metadata            bool
	VideoSequenceHeader bool
	AudioSequenceHeader bool
	// contains filtered or unexported fields
}

covert the rtmp message to oryx message.

func NewOryxRtmpMessage

func NewOryxRtmpMessage(m *RtmpMessage) (*OryxRtmpMessage, error)

func (*OryxRtmpMessage) Copy

func (v *OryxRtmpMessage) Copy() *OryxRtmpMessage

copy the message headers, share body.

func (*OryxRtmpMessage) Muxer

func (v *OryxRtmpMessage) Muxer() core.MessageMuxer

func (*OryxRtmpMessage) Payload

func (v *OryxRtmpMessage) Payload() *RtmpMessage

func (*OryxRtmpMessage) SetTimestamp

func (v *OryxRtmpMessage) SetTimestamp(ts uint64) *OryxRtmpMessage

func (*OryxRtmpMessage) String

func (v *OryxRtmpMessage) String() string

func (*OryxRtmpMessage) Timestamp

func (v *OryxRtmpMessage) Timestamp() uint64

type RtmpAVCFrame

type RtmpAVCFrame uint8

E.4.3.1 VIDEODATA Frame Type UB [4] Type of video frame. The following values are defined:

1 = key frame (for AVC, a seekable frame)
2 = inter frame (for AVC, a non-seekable frame)
3 = disposable inter frame (H.263 only)
4 = generated key frame (reserved for server use only)
5 = video info/command frame
const (
	RtmpReservedAVCFrame RtmpAVCFrame = iota
	RtmpKeyFrame
	RtmpInterFrame
	RtmpDisposableInterFrame
	RtmpGeneratedKeyFrame
	RtmpVideoInfoFrame
	RtmpReserved1AVCFrame
)

type RtmpAacType

type RtmpAacType uint8

AACPacketType IF SoundFormat == 10 UI8 The following values are defined:

0 = AAC sequence header
1 = AAC raw
const (
	RtmpAacSequenceHeader RtmpAacType = iota
	RtmpAacRawData
	RtmpAacReserved
)

type RtmpCallPacket

type RtmpCallPacket struct {
	// Name of the remote procedure that is called.
	Name Amf0String
	// If a response is expected we give a transaction Id. Else we pass a value of 0
	TransactionId Amf0Number
	// If there exists any command info this
	// is set, else this is set to null type.
	// @remark, optional, init to and maybe NULL.
	Command Amf0Any
	// Any optional arguments to be provided
	// @remark, optional, init to and maybe NULL.
	Args Amf0Any
}

4.1.2. Call The call method of the NetConnection object runs remote procedure calls (RPC) at the receiving end. The called RPC name is passed as a parameter to the call command.

func (*RtmpCallPacket) MarshalBinary

func (v *RtmpCallPacket) MarshalBinary() (data []byte, err error)

func (*RtmpCallPacket) MessageType

func (v *RtmpCallPacket) MessageType() RtmpMessageType

func (*RtmpCallPacket) PreferCid

func (v *RtmpCallPacket) PreferCid() uint32

func (*RtmpCallPacket) UnmarshalBinary

func (v *RtmpCallPacket) UnmarshalBinary(data []byte) (err error)

type RtmpCallResPacket

type RtmpCallResPacket struct {
	// Name of the command.
	Name Amf0String
	// ID of the command, to which the response belongs to
	TransactionId Amf0Number
	// If there exists any command info this
	// is set, else this is set to null type.
	// @remark, optional, init to and maybe NULL.
	Command Amf0Any
	// Any optional arguments to be provided
	// @remark, optional, init to and maybe NULL.
	Args Amf0Any
}

response for RtmpCallPacket

func (*RtmpCallResPacket) MarshalBinary

func (v *RtmpCallResPacket) MarshalBinary() (data []byte, err error)

func (*RtmpCallResPacket) MessageType

func (v *RtmpCallResPacket) MessageType() RtmpMessageType

func (*RtmpCallResPacket) PreferCid

func (v *RtmpCallResPacket) PreferCid() uint32

func (*RtmpCallResPacket) UnmarshalBinary

func (v *RtmpCallResPacket) UnmarshalBinary(data []byte) (err error)

type RtmpChunk

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

incoming chunk stream maybe interlaced, use the chunk stream to cache the input RTMP chunk streams.

func NewRtmpChunk

func NewRtmpChunk(cid uint32) *RtmpChunk

type RtmpCodecAudio

type RtmpCodecAudio uint8

SoundFormat UB [4] Format of SoundData. The following values are defined:

0 = Linear PCM, platform endian
1 = ADPCM
2 = MP3
3 = Linear PCM, little endian
4 = Nellymoser 16 kHz mono
5 = Nellymoser 8 kHz mono
6 = Nellymoser
7 = G.711 A-law logarithmic PCM
8 = G.711 mu-law logarithmic PCM
9 = reserved
10 = AAC
11 = Speex
14 = MP3 8 kHz
15 = Device-specific sound

Formats 7, 8, 14, and 15 are reserved. AAC is supported in Flash Player 9,0,115,0 and higher. Speex is supported in Flash Player 10 and higher.

const (
	RtmpLinearPCMPlatformEndian RtmpCodecAudio = iota
	RtmpADPCM
	RtmpMP3
	RtmpLinearPCMLittleEndian
	RtmpNellymoser16kHzMono
	RtmpNellymoser8kHzMono
	RtmpNellymoser
	RtmpReservedG711AlawLogarithmicPCM
	RtmpReservedG711MuLawLogarithmicPCM
	RtmpReserved
	RtmpAAC
	RtmpSpeex
	RtmpReserved1CodecAudio
	RtmpReserved2CodecAudio
	RtmpReservedMP3_8kHz
	RtmpReservedDeviceSpecificSound
	RtmpReserved3CodecAudio
	RtmpDisabledCodecAudio
)

type RtmpCodecVideo

type RtmpCodecVideo uint8

E.4.3.1 VIDEODATA CodecID UB [4] Codec Identifier. The following values are defined:

2 = Sorenson H.263
3 = Screen video
4 = On2 VP6
5 = On2 VP6 with alpha channel
6 = Screen video version 2
7 = AVC
const (
	RtmpReservedCodecVideo RtmpCodecVideo = iota
	RtmpReserved1CodecVideo
	RtmpSorensonH263
	RtmpScreenVideo
	RtmpOn2VP6
	RtmpOn2VP6WithAlphaChannel
	RtmpScreenVideoVersion2
	RtmpAVC
	RtmpDisabledCodecVideo
	RtmpReserved2CodecVideo
)

type RtmpConnType

type RtmpConnType uint8

the rtmp client type.

const (
	RtmpUnknown RtmpConnType = iota
	RtmpPlay
	RtmpFmlePublish
	RtmpFlashPublish
)

func (RtmpConnType) IsPlay

func (v RtmpConnType) IsPlay() bool

whether connection is player

func (RtmpConnType) IsPublish

func (v RtmpConnType) IsPublish() bool

whether connection is flash or fmle publisher.

func (RtmpConnType) String

func (v RtmpConnType) String() string

type RtmpConnectAppPacket

type RtmpConnectAppPacket struct {
	// Name of the command. Set to "connect".
	Name Amf0String
	// Always set to 1.
	TransactionId Amf0Number
	// Command information object which has the name-value pairs.
	// @remark: alloc in packet constructor, user can directly use it,
	//       user should never alloc it again which will cause memory leak.
	// @remark, never be NULL.
	CommandObject *Amf0Object
	// Any optional information
	// @remark, optional, init to and maybe NULL.
	Args *Amf0Object
}

4.1.1. connect The client sends the connect command to the server to request connection to a server application instance.

func (*RtmpConnectAppPacket) MarshalBinary

func (v *RtmpConnectAppPacket) MarshalBinary() (data []byte, err error)

func (*RtmpConnectAppPacket) MessageType

func (v *RtmpConnectAppPacket) MessageType() RtmpMessageType

func (*RtmpConnectAppPacket) PreferCid

func (v *RtmpConnectAppPacket) PreferCid() uint32

func (*RtmpConnectAppPacket) UnmarshalBinary

func (v *RtmpConnectAppPacket) UnmarshalBinary(data []byte) (err error)

type RtmpConnectAppResPacket

type RtmpConnectAppResPacket struct {
	// _result or _error; indicates whether the response is result or error.
	Name Amf0String
	// Transaction ID is 1 for call connect responses
	TransactionId Amf0Number
	// Name-value pairs that describe the properties(fmsver etc.) of the connection.
	// @remark, never be NULL.
	Props *Amf0Object
	// Name-value pairs that describe the response from|the server. 'code',
	// 'level', 'description' are names of few among such information.
	// @remark, never be NULL.
	Info *Amf0Object
}

response for SrsConnectAppPacket.

func (*RtmpConnectAppResPacket) MarshalBinary

func (v *RtmpConnectAppResPacket) MarshalBinary() (data []byte, err error)

func (*RtmpConnectAppResPacket) MessageType

func (v *RtmpConnectAppResPacket) MessageType() RtmpMessageType

func (*RtmpConnectAppResPacket) PreferCid

func (v *RtmpConnectAppResPacket) PreferCid() uint32

func (*RtmpConnectAppResPacket) UnmarshalBinary

func (v *RtmpConnectAppResPacket) UnmarshalBinary(data []byte) (err error)

type RtmpConnection

type RtmpConnection struct {

	// the rtmp request.
	Req *RtmpRequest
	// contains filtered or unexported fields
}

rtmp protocol stack.

func NewRtmpConnection

func NewRtmpConnection(ctx core.Context, transport io.ReadWriteCloser, wc core.WorkerContainer) *RtmpConnection

func (*RtmpConnection) CacheMessage

func (v *RtmpConnection) CacheMessage(m *RtmpMessage) (err error)

the rtmp connection never provides send message, but we use cache message and the main goroutine of connection will use Cycle to flush messages.

func (*RtmpConnection) Close

func (v *RtmpConnection) Close()

close the connection to client. TODO: FIXME: should be thread safe.

func (*RtmpConnection) Ctx

func (v *RtmpConnection) Ctx() core.Context

retrieve the context of connection.

func (*RtmpConnection) Cycle

func (v *RtmpConnection) Cycle(fn func(*RtmpMessage) error) (err error)

cycle to flush messages, and callback the fn when got message from peer.

func (*RtmpConnection) DecodeMessage

func (v *RtmpConnection) DecodeMessage(m *RtmpMessage) (p RtmpPacket, err error)

to decode the message to packet.

func (*RtmpConnection) ExpectConnectApp

func (v *RtmpConnection) ExpectConnectApp(r *RtmpRequest) (err error)

do connect app with client, to discovery tcUrl.

func (*RtmpConnection) FlashStartPlay

func (v *RtmpConnection) FlashStartPlay() (err error)

for Flash player or edge, response the start play event.

func (*RtmpConnection) FlashStartPublish

func (v *RtmpConnection) FlashStartPublish() (err error)

for Flash encoder, response the start publish event.

func (*RtmpConnection) FmleStartPublish

func (v *RtmpConnection) FmleStartPublish() (err error)

for FMLE encoder, response the start publish event.

func (*RtmpConnection) FmleUnpublish

func (v *RtmpConnection) FmleUnpublish(upp *RtmpFMLEStartPacket) (err error)

for FMLE encoder, to unpublish.

func (*RtmpConnection) Handshake

func (v *RtmpConnection) Handshake() (err error)

handshake with client, try complex then simple.

func (*RtmpConnection) Identify

func (v *RtmpConnection) Identify() (connType RtmpConnType, streamName string, duration float64, err error)

recv some message to identify the client. @stream_id, client will createStream to play or publish by flash,

the stream_id used to response the createStream request.

@type, output the client type. @stream_name, output the client publish/play stream name. @see: SrsRequest.stream @duration, output the play client duration. @see: SrsRequest.duration

func (*RtmpConnection) OnBwDone

func (v *RtmpConnection) OnBwDone() (err error)

response client the onBWDone message.

func (*RtmpConnection) OnReloadGlobal

func (v *RtmpConnection) OnReloadGlobal(scope int, cc, pc *core.Config) (err error)

interface ReloadHandler

func (*RtmpConnection) OnReloadVhost

func (v *RtmpConnection) OnReloadVhost(vhost string, scope int, cc, pc *core.Config) (err error)

func (*RtmpConnection) OnUrlParsed

func (v *RtmpConnection) OnUrlParsed() (err error)

when request parsed, notify the connection.

func (*RtmpConnection) RecvMessage

func (v *RtmpConnection) RecvMessage(timeout time.Duration, fn func(*RtmpMessage) error) (err error)

to receive message from rtmp.

func (*RtmpConnection) ResponseConnectApp

func (v *RtmpConnection) ResponseConnectApp() (err error)

@param server_ip the ip of server.

func (*RtmpConnection) SetChunkSize

func (v *RtmpConnection) SetChunkSize(n int) (err error)

set the chunk size.

func (*RtmpConnection) SetPeerBandwidth

func (v *RtmpConnection) SetPeerBandwidth(bw uint32, t uint8) (err error)

@type: The sender can mark this message hard (0), soft (1), or dynamic (2) using the Limit type field.

func (*RtmpConnection) SetWindowAckSize

func (v *RtmpConnection) SetWindowAckSize(ack uint32) (err error)

set ack size to client, client will send ack-size for each ack window

type RtmpCreateStreamPacket

type RtmpCreateStreamPacket struct {
	// Name of the command. Set to "createStream".
	Name Amf0String
	// Transaction ID of the command.
	TransactionId Amf0Number
	// If there exists any command info this is set, else this is set to null type.
	// @remark, never be NULL, an AMF0 null instance.
	Command Amf0Null
}

4.1.3. createStream The client sends this command to the server to create a logical channel for message communication The publishing of audio, video, and metadata is carried out over stream channel created using the createStream command.

func (*RtmpCreateStreamPacket) MarshalBinary

func (v *RtmpCreateStreamPacket) MarshalBinary() (data []byte, err error)

func (*RtmpCreateStreamPacket) MessageType

func (v *RtmpCreateStreamPacket) MessageType() RtmpMessageType

func (*RtmpCreateStreamPacket) PreferCid

func (v *RtmpCreateStreamPacket) PreferCid() uint32

func (*RtmpCreateStreamPacket) UnmarshalBinary

func (v *RtmpCreateStreamPacket) UnmarshalBinary(data []byte) (err error)

type RtmpCreateStreamResPacket

type RtmpCreateStreamResPacket struct {
	// _result or _error; indicates whether the response is result or error.
	Name Amf0String
	// ID of the command that response belongs to.
	TransactionId Amf0Number
	// If there exists any command info this is set, else this is set to null type.
	Command Amf0Null
	// The return value is either a stream ID or an error information object.
	StreamId Amf0Number
}

response for RtmpCreateStreamPacket

func (*RtmpCreateStreamResPacket) MarshalBinary

func (v *RtmpCreateStreamResPacket) MarshalBinary() (data []byte, err error)

func (*RtmpCreateStreamResPacket) MessageType

func (v *RtmpCreateStreamResPacket) MessageType() RtmpMessageType

func (*RtmpCreateStreamResPacket) PreferCid

func (v *RtmpCreateStreamResPacket) PreferCid() uint32

func (*RtmpCreateStreamResPacket) UnmarshalBinary

func (v *RtmpCreateStreamResPacket) UnmarshalBinary(data []byte) (err error)

type RtmpEmptyPacket

type RtmpEmptyPacket struct {
	Id Amf0Number
}

the empty packet is a sample rtmp packet.

func (*RtmpEmptyPacket) MarshalBinary

func (v *RtmpEmptyPacket) MarshalBinary() (data []byte, err error)

func (*RtmpEmptyPacket) MessageType

func (v *RtmpEmptyPacket) MessageType() RtmpMessageType

func (*RtmpEmptyPacket) PreferCid

func (v *RtmpEmptyPacket) PreferCid() uint32

func (*RtmpEmptyPacket) UnmarshalBinary

func (v *RtmpEmptyPacket) UnmarshalBinary(data []byte) (err error)

type RtmpFMLEStartPacket

type RtmpFMLEStartPacket struct {
	// Name of the command
	Name Amf0String
	// the transaction ID to get the response.
	TransactionId Amf0Number
	// If there exists any command info this is set, else this is set to null type.
	// @remark, never be NULL, an AMF0 null instance.
	Command Amf0Null
	// the stream name to start publish or release.
	Stream Amf0String
}

FMLE start publish: ReleaseStream/PublishStream

func (*RtmpFMLEStartPacket) MarshalBinary

func (v *RtmpFMLEStartPacket) MarshalBinary() (data []byte, err error)

func (*RtmpFMLEStartPacket) MessageType

func (v *RtmpFMLEStartPacket) MessageType() RtmpMessageType

func (*RtmpFMLEStartPacket) PreferCid

func (v *RtmpFMLEStartPacket) PreferCid() uint32

func (*RtmpFMLEStartPacket) UnmarshalBinary

func (v *RtmpFMLEStartPacket) UnmarshalBinary(data []byte) (err error)

type RtmpFMLEStartResPacket

type RtmpFMLEStartResPacket struct {
	// Name of the command
	Name Amf0String
	// the transaction ID to get the response.
	TransactionId Amf0Number
	// If there exists any command info this is set, else this is set to null type.
	// @remark, never be NULL, an AMF0 null instance.
	Command Amf0Null
	// the optional args, set to undefined.
	Args Amf0Undefined
}

response for RtmpFMLEStartPacket

func (*RtmpFMLEStartResPacket) MarshalBinary

func (v *RtmpFMLEStartResPacket) MarshalBinary() (data []byte, err error)

func (*RtmpFMLEStartResPacket) MessageType

func (v *RtmpFMLEStartResPacket) MessageType() RtmpMessageType

func (*RtmpFMLEStartResPacket) PreferCid

func (v *RtmpFMLEStartResPacket) PreferCid() uint32

func (*RtmpFMLEStartResPacket) UnmarshalBinary

func (v *RtmpFMLEStartResPacket) UnmarshalBinary(data []byte) (err error)

type RtmpMessage

type RtmpMessage struct {
	// Four-byte field that contains a timestamp of the message.
	// The 4 bytes are packed in the big-endian order.
	// @remark, used as calc timestamp when decode and encode time.
	// @remark, we use 64bits for large time for jitter detect and hls.
	Timestamp uint64
	// 4bytes.
	// Four-byte field that identifies the stream of the message. These
	// bytes are set in little-endian format.
	StreamId uint32
	// 1byte.
	// One byte field to represent the message type. A range of type IDs
	// (1-7) are reserved for protocol control messages.
	MessageType RtmpMessageType
	// get the perfered cid(chunk stream id) which sendout over.
	// set at decoding, and canbe used for directly send message,
	// for example, dispatch to all connections.
	PreferCid uint32
	// the payload of message, the SrsCommonMessage never know about the detail of payload,
	// user must use SrsProtocol.decode_message to get concrete packet.
	// @remark, not all message payload can be decoded to packet. for example,
	//       video/audio packet use raw bytes, no video/audio packet.
	Payload []byte
}

Rtmp message, which decode from RTMP chunked stream with raw body.

func NewRtmpMessage

func NewRtmpMessage() *RtmpMessage

func (*RtmpMessage) String

func (v *RtmpMessage) String() string

func (*RtmpMessage) ToMessage

func (v *RtmpMessage) ToMessage() (core.Message, error)

convert the rtmp message to oryx message.

type RtmpMessageType

type RtmpMessageType uint8

the message type.

const (
	// 5. Protocol Control Messages
	// RTMP reserves message type IDs 1-7 for protocol control messages.
	// These messages contain information needed by the RTM Chunk Stream
	// protocol or RTMP itself. Protocol messages with IDs 1 & 2 are
	// reserved for usage with RTM Chunk Stream protocol. Protocol messages
	// with IDs 3-6 are reserved for usage of RTMP. Protocol message with ID
	// 7 is used between edge server and origin server.
	RtmpMsgSetChunkSize               RtmpMessageType = 0x01
	RtmpMsgAbortMessage               RtmpMessageType = 0x02
	RtmpMsgAcknowledgement            RtmpMessageType = 0x03
	RtmpMsgUserControlMessage         RtmpMessageType = 0x04
	RtmpMsgWindowAcknowledgementSize  RtmpMessageType = 0x05
	RtmpMsgSetPeerBandwidth           RtmpMessageType = 0x06
	RtmpMsgEdgeAndOriginServerCommand RtmpMessageType = 0x07
	// 3. Types of messages
	// The server and the client send messages over the network to
	// communicate with each other. The messages can be of any type which
	// includes audio messages, video messages, command messages, shared
	// object messages, data messages, and user control messages.
	// 3.1. Command message
	// Command messages carry the AMF-encoded commands between the client
	// and the server. These messages have been assigned message type value
	// of 20 for AMF0 encoding and message type value of 17 for AMF3
	// encoding. These messages are sent to perform some operations like
	// connect, createStream, publish, play, pause on the peer. Command
	// messages like onstatus, result etc. are used to inform the sender
	// about the status of the requested commands. A command message
	// consists of command name, transaction ID, and command object that
	// contains related parameters. A client or a server can request Remote
	// Procedure Calls (RPC) over streams that are communicated using the
	// command messages to the peer.
	RtmpMsgAMF3CommandMessage RtmpMessageType = 17 // 0x11
	RtmpMsgAMF0CommandMessage RtmpMessageType = 20 // 0x14
	// 3.2. Data message
	// The client or the server sends this message to send Metadata or any
	// user data to the peer. Metadata includes details about the
	// data(audio, video etc.) like creation time, duration, theme and so
	// on. These messages have been assigned message type value of 18 for
	// AMF0 and message type value of 15 for AMF3.
	RtmpMsgAMF0DataMessage RtmpMessageType = 18 // 0x12
	RtmpMsgAMF3DataMessage RtmpMessageType = 15 // 0x0F
	// 3.3. Shared object message
	// A shared object is a Flash object (a collection of name value pairs)
	// that are in synchronization across multiple clients, instances, and
	// so on. The message types kMsgContainer=19 for AMF0 and
	// kMsgContainerEx=16 for AMF3 are reserved for shared object events.
	// Each message can contain multiple events.
	RtmpMsgAMF3SharedObject RtmpMessageType = 16 // 0x10
	RtmpMsgAMF0SharedObject RtmpMessageType = 19 // 0x13
	// 3.4. Audio message
	// The client or the server sends this message to send audio data to the
	// peer. The message type value of 8 is reserved for audio messages.
	RtmpMsgAudioMessage RtmpMessageType = 8 // 0x08
	// 3.5. Video message
	// The client or the server sends this message to send video data to the
	// peer. The message type value of 9 is reserved for video messages.
	// These messages are large and can delay the sending of other type of
	// messages. To avoid such a situation, the video message is assigned
	// the lowest priority.
	RtmpMsgVideoMessage RtmpMessageType = 9 // 0x09
	// 3.6. Aggregate message
	// An aggregate message is a single message that contains a list of submessages.
	// The message type value of 22 is reserved for aggregate
	// messages.
	RtmpMsgAggregateMessage RtmpMessageType = 22 // 0x16
)

func (RtmpMessageType) IsCommand

func (v RtmpMessageType) IsCommand() bool

func (RtmpMessageType) String

func (v RtmpMessageType) String() string

type RtmpOnBwDonePacket

type RtmpOnBwDonePacket struct {
	// Name of command. Set to "onBWDone"
	Name Amf0String
	// Transaction ID set to 0.
	TransactionId Amf0Number
	// Command information does not exist. Set to null type.
	// @remark, never be NULL, an AMF0 null instance.
	Args Amf0Null
}

when bandwidth test done, notice client.

func (*RtmpOnBwDonePacket) MarshalBinary

func (v *RtmpOnBwDonePacket) MarshalBinary() (data []byte, err error)

func (*RtmpOnBwDonePacket) MessageType

func (v *RtmpOnBwDonePacket) MessageType() RtmpMessageType

func (*RtmpOnBwDonePacket) PreferCid

func (v *RtmpOnBwDonePacket) PreferCid() uint32

func (*RtmpOnBwDonePacket) UnmarshalBinary

func (v *RtmpOnBwDonePacket) UnmarshalBinary(data []byte) (err error)

type RtmpOnStatusCallPacket

type RtmpOnStatusCallPacket struct {
	// Name of command. Set to "onStatus"
	Name Amf0String
	// Transaction ID set to 0.
	TransactionId Amf0Number
	// Command information does not exist. Set to null type.
	Command Amf0Null
	// Name-value pairs that describe the response from the server.
	// 'code','level', 'description' are names of few among such information.
	Data *Amf0Object
}

onStatus command, AMF0 Call @remark, user must set the stream_id by SrsCommonMessage.set_packet().

func (*RtmpOnStatusCallPacket) MarshalBinary

func (v *RtmpOnStatusCallPacket) MarshalBinary() (data []byte, err error)

func (*RtmpOnStatusCallPacket) MessageType

func (v *RtmpOnStatusCallPacket) MessageType() RtmpMessageType

func (*RtmpOnStatusCallPacket) PreferCid

func (v *RtmpOnStatusCallPacket) PreferCid() uint32

func (*RtmpOnStatusCallPacket) UnmarshalBinary

func (v *RtmpOnStatusCallPacket) UnmarshalBinary(data []byte) (err error)

type RtmpOnStatusDataPacket

type RtmpOnStatusDataPacket struct {
	// Name of command. Set to "onStatus"
	Name Amf0String
	// Name-value pairs that describe the response from the server.
	// 'code', are names of few among such information.
	Data *Amf0Object
}

onStatus data, AMF0 Data

func (*RtmpOnStatusDataPacket) MarshalBinary

func (v *RtmpOnStatusDataPacket) MarshalBinary() (data []byte, err error)

func (*RtmpOnStatusDataPacket) MessageType

func (v *RtmpOnStatusDataPacket) MessageType() RtmpMessageType

func (*RtmpOnStatusDataPacket) PreferCid

func (v *RtmpOnStatusDataPacket) PreferCid() uint32

func (*RtmpOnStatusDataPacket) UnmarshalBinary

func (v *RtmpOnStatusDataPacket) UnmarshalBinary(data []byte) (err error)

type RtmpPacket

type RtmpPacket interface {
	// all packet can marshaler and unmarshaler.
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler

	// the cid(chunk id) specifies the chunk to send data over.
	// generally, each message perfer some cid, for example,
	// all protocol control messages perfer RTMP_CID_ProtocolControl,
	// SrsSetWindowAckSizePacket is protocol control message.
	PreferCid() uint32
	// subpacket must override to provide the right message type.
	// the message type set the RTMP message type in header.
	MessageType() RtmpMessageType
}

RTMP packet, which can be decode from and encode to message payload.

func NewRtmpCallPacket

func NewRtmpCallPacket() RtmpPacket

func NewRtmpCallResPacket

func NewRtmpCallResPacket() RtmpPacket

func NewRtmpConnectAppPacket

func NewRtmpConnectAppPacket() RtmpPacket

func NewRtmpConnectAppResPacket

func NewRtmpConnectAppResPacket() RtmpPacket

func NewRtmpCreateStreamPacket

func NewRtmpCreateStreamPacket() RtmpPacket

func NewRtmpCreateStreamResPacket

func NewRtmpCreateStreamResPacket() RtmpPacket

func NewRtmpEmptyPacket

func NewRtmpEmptyPacket() RtmpPacket

func NewRtmpFMLEStartPacket

func NewRtmpFMLEStartPacket() RtmpPacket

func NewRtmpFMLEStartResPacket

func NewRtmpFMLEStartResPacket() RtmpPacket

func NewRtmpOnBwDonePacket

func NewRtmpOnBwDonePacket() RtmpPacket

func NewRtmpOnStatusCallPacket

func NewRtmpOnStatusCallPacket() RtmpPacket

func NewRtmpOnStatusDataPacket

func NewRtmpOnStatusDataPacket() RtmpPacket

func NewRtmpPlayPacket

func NewRtmpPlayPacket() RtmpPacket

func NewRtmpPublishPacket

func NewRtmpPublishPacket() RtmpPacket

func NewRtmpSampleAccessPacket

func NewRtmpSampleAccessPacket() RtmpPacket

func NewRtmpSetChunkSizePacket

func NewRtmpSetChunkSizePacket() RtmpPacket

func NewRtmpSetPeerBandwidthPacket

func NewRtmpSetPeerBandwidthPacket() RtmpPacket

func NewRtmpSetWindowAckSizePacket

func NewRtmpSetWindowAckSizePacket() RtmpPacket

func NewRtmpUserControlPacket

func NewRtmpUserControlPacket() RtmpPacket

type RtmpPcucEventType

type RtmpPcucEventType RtmpUint16

3.7. User Control message

const (

	// The server sends this event to notify the client
	// that a stream has become functional and can be
	// used for communication. By default, this event
	// is sent on ID 0 after the application connect
	// command is successfully received from the
	// client. The event data is 4-byte and represents
	// the stream ID of the stream that became
	// functional.
	RtmpPcucStreamBegin RtmpPcucEventType = 0x00

	// The server sends this event to notify the client
	// that the playback of data is over as requested
	// on this stream. No more data is sent without
	// issuing additional commands. The client discards
	// the messages received for the stream. The
	// 4 bytes of event data represent the ID of the
	// stream on which playback has ended.
	RtmpPcucStreamEOF RtmpPcucEventType = 0x01

	// The server sends this event to notify the client
	// that there is no more data on the stream. If the
	// server does not detect any message for a time
	// period, it can notify the subscribed clients
	// that the stream is dry. The 4 bytes of event
	// data represent the stream ID of the dry stream.
	RtmpPcucStreamDry RtmpPcucEventType = 0x02

	// The client sends this event to inform the server
	// of the buffer size (in milliseconds) that is
	// used to buffer any data coming over a stream.
	// This event is sent before the server starts
	// processing the stream. The first 4 bytes of the
	// event data represent the stream ID and the next
	// 4 bytes represent the buffer length, in
	// milliseconds.
	RtmpPcucSetBufferLength RtmpPcucEventType = 0x03 // 8bytes event-data

	// The server sends this event to notify the client
	// that the stream is a recorded stream. The
	// 4 bytes event data represent the stream ID of
	// the recorded stream.
	RtmpPcucStreamIsRecorded RtmpPcucEventType = 0x04

	// The server sends this event to test whether the
	// client is reachable. Event data is a 4-byte
	// timestamp, representing the local server time
	// when the server dispatched the command. The
	// client responds with kMsgPingResponse on
	// receiving kMsgPingRequest.
	RtmpPcucPingRequest RtmpPcucEventType = 0x06

	// The client sends this event to the server in
	// response to the ping request. The event data is
	// a 4-byte timestamp, which was received with the
	// kMsgPingRequest request.
	RtmpPcucPingResponse RtmpPcucEventType = 0x07

	// for PCUC size=3, the payload is "00 1A 01",
	// where we think the event is 0x001a, fms defined msg,
	// which has only 1bytes event data.
	RtmpPcucFmsEvent0 RtmpPcucEventType = 0x1a
)

type RtmpPlayPacket

type RtmpPlayPacket struct {
	// Name of the command. Set to "play".
	Name Amf0String
	// Transaction ID set to 0.
	TransactionId Amf0Number
	// Command information does not exist. Set to null type.
	// @remark, never be NULL, an AMF0 null instance.
	Command Amf0Null
	// Name of the stream to play.
	// To play video (FLV) files, specify the name of the stream without a file
	//       extension (for example, "sample").
	// To play back MP3 or ID3 tags, you must precede the stream name with mp3:
	//       (for example, "mp3:sample".)
	// To play H.264/AAC files, you must precede the stream name with mp4: and specify the
	//       file extension. For example, to play the file sample.m4v, specify
	//       "mp4:sample.m4v"
	Stream Amf0String
	// An optional parameter that specifies the start time in seconds.
	// The default value is -2, which means the subscriber first tries to play the live
	//       stream specified in the Stream Name field. If a live stream of that name is
	//       not found, it plays the recorded stream specified in the Stream Name field.
	// If you pass -1 in the Start field, only the live stream specified in the Stream
	//       Name field is played.
	// If you pass 0 or a positive number in the Start field, a recorded stream specified
	//       in the Stream Name field is played beginning from the time specified in the
	//       Start field.
	// If no recorded stream is found, the next item in the playlist is played.
	Start *Amf0Number
	// An optional parameter that specifies the duration of playback in seconds.
	// The default value is -1. The -1 value means a live stream is played until it is no
	//       longer available or a recorded stream is played until it ends.
	// If u pass 0, it plays the single frame since the time specified in the Start field
	//       from the beginning of a recorded stream. It is assumed that the value specified
	//       in the Start field is equal to or greater than 0.
	// If you pass a positive number, it plays a live stream for the time period specified
	//       in the Duration field. After that it becomes available or plays a recorded
	//       stream for the time specified in the Duration field. (If a stream ends before the
	//       time specified in the Duration field, playback ends when the stream ends.)
	// If you pass a negative number other than -1 in the Duration field, it interprets the
	//       value as if it were -1.
	Duration *Amf0Number
	// An optional Boolean value or number that specifies whether to flush any
	// previous playlist.
	Reset *Amf0Boolean
}

4.2.1. play The client sends this command to the server to play a stream.

func (*RtmpPlayPacket) MarshalBinary

func (v *RtmpPlayPacket) MarshalBinary() (data []byte, err error)

func (*RtmpPlayPacket) MessageType

func (v *RtmpPlayPacket) MessageType() RtmpMessageType

func (*RtmpPlayPacket) PreferCid

func (v *RtmpPlayPacket) PreferCid() uint32

func (*RtmpPlayPacket) UnmarshalBinary

func (v *RtmpPlayPacket) UnmarshalBinary(data []byte) (err error)

type RtmpPublishPacket

type RtmpPublishPacket struct {
	// Name of the command, set to "publish".
	Name Amf0String
	// Transaction ID set to 0.
	TransactionId Amf0Number
	// Command information object does not exist. Set to null type.
	Command Amf0Null
	// Name with which the stream is published.
	Stream Amf0String
	// Type of publishing. Set to "live", "record", or "append".
	//   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.
	//   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.
	// @remark, SRS only support live.
	// @remark, optional, default to live.
	Type *Amf0String
}

FMLE/flash publish 4.2.6. Publish The client sends the publish command to publish a named stream to the server. Using this name, any client can play this stream and receive the published audio, video, and data messages.

func (*RtmpPublishPacket) MarshalBinary

func (v *RtmpPublishPacket) MarshalBinary() (data []byte, err error)

func (*RtmpPublishPacket) MessageType

func (v *RtmpPublishPacket) MessageType() RtmpMessageType

func (*RtmpPublishPacket) PreferCid

func (v *RtmpPublishPacket) PreferCid() uint32

func (*RtmpPublishPacket) UnmarshalBinary

func (v *RtmpPublishPacket) UnmarshalBinary(data []byte) (err error)

type RtmpRequest

type RtmpRequest struct {

	// the tcUrl in RTMP connect app request.
	TcUrl string
	// the required object encoding.
	ObjectEncoding float64

	// the stream to publish or play.
	Stream string
	// the type of connection, publish or play.
	Type RtmpConnType
	// for play, the duration.
	Duration float64

	// the vhost parsed from tcUrl or stream.
	Vhost string
	// the app parsed from tcUrl.
	App string
	// the url, parsed for tcUrl/stream?params.
	Url *url.URL
	// contains filtered or unexported fields
}

rtmp request.

func NewRtmpRequest

func NewRtmpRequest(ctx core.Context) *RtmpRequest

func (*RtmpRequest) Host

func (v *RtmpRequest) Host() string

the host connected at, the ip or domain name(vhost).

func (*RtmpRequest) Port

func (v *RtmpRequest) Port() int

the rtmp port, default to 1935.

func (*RtmpRequest) Reparse

func (v *RtmpRequest) Reparse() (err error)

parse the rtmp request object from tcUrl/stream?params to finger it out the vhost and url.

func (*RtmpRequest) Uri

func (v *RtmpRequest) Uri() string

the uri to identify the request, vhost/app/stream.

type RtmpSampleAccessPacket

type RtmpSampleAccessPacket struct {
	// Name of command. Set to "|RtmpSampleAccess".
	Name Amf0String
	// whether allow access the sample of video.
	// @see: https://github.com/ossrs/srs/issues/49
	// @see: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#videoSampleAccess
	VideoSampleAccess Amf0Boolean
	// whether allow access the sample of audio.
	// @see: https://github.com/ossrs/srs/issues/49
	// @see: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#audioSampleAccess
	AudioSampleAccess Amf0Boolean
}

AMF0Data RtmpSampleAccess

func (*RtmpSampleAccessPacket) MarshalBinary

func (v *RtmpSampleAccessPacket) MarshalBinary() (data []byte, err error)

func (*RtmpSampleAccessPacket) MessageType

func (v *RtmpSampleAccessPacket) MessageType() RtmpMessageType

func (*RtmpSampleAccessPacket) PreferCid

func (v *RtmpSampleAccessPacket) PreferCid() uint32

func (*RtmpSampleAccessPacket) UnmarshalBinary

func (v *RtmpSampleAccessPacket) UnmarshalBinary(data []byte) (err error)

type RtmpSetChunkSizePacket

type RtmpSetChunkSizePacket struct {
	ChunkSize RtmpUint32
}

7.1. Set Chunk Size Protocol control message 1, Set Chunk Size, is used to notify the peer about the new maximum chunk size.

func (*RtmpSetChunkSizePacket) MarshalBinary

func (v *RtmpSetChunkSizePacket) MarshalBinary() (data []byte, err error)

func (*RtmpSetChunkSizePacket) MessageType

func (v *RtmpSetChunkSizePacket) MessageType() RtmpMessageType

func (*RtmpSetChunkSizePacket) PreferCid

func (v *RtmpSetChunkSizePacket) PreferCid() uint32

func (*RtmpSetChunkSizePacket) UnmarshalBinary

func (v *RtmpSetChunkSizePacket) UnmarshalBinary(data []byte) (err error)

type RtmpSetPeerBandwidthPacket

type RtmpSetPeerBandwidthPacket struct {
	Bandwidth RtmpUint32
	// @see RtmpSetPeerBandwidthType
	Type RtmpUint8
}

5.6. Set Peer Bandwidth (6) The client or the server sends this message to update the output bandwidth of the peer.

func (*RtmpSetPeerBandwidthPacket) MarshalBinary

func (v *RtmpSetPeerBandwidthPacket) MarshalBinary() (data []byte, err error)

func (*RtmpSetPeerBandwidthPacket) MessageType

func (*RtmpSetPeerBandwidthPacket) PreferCid

func (v *RtmpSetPeerBandwidthPacket) PreferCid() uint32

func (*RtmpSetPeerBandwidthPacket) UnmarshalBinary

func (v *RtmpSetPeerBandwidthPacket) UnmarshalBinary(data []byte) (err error)

type RtmpSetPeerBandwidthType

type RtmpSetPeerBandwidthType uint8

5.6. Set Peer Bandwidth (6)

const (
	// The sender can mark this message hard (0), soft (1), or dynamic (2)
	// using the Limit type field.
	Hard RtmpSetPeerBandwidthType = iota
	Soft
	Dynamic
)

type RtmpSetWindowAckSizePacket

type RtmpSetWindowAckSizePacket struct {
	Ack RtmpUint32
}

5.5. Window Acknowledgement Size (5) The client or the server sends this message to inform the peer which window size to use when sending acknowledgment.

func (*RtmpSetWindowAckSizePacket) MarshalBinary

func (v *RtmpSetWindowAckSizePacket) MarshalBinary() (data []byte, err error)

func (*RtmpSetWindowAckSizePacket) MessageType

func (*RtmpSetWindowAckSizePacket) PreferCid

func (v *RtmpSetWindowAckSizePacket) PreferCid() uint32

func (*RtmpSetWindowAckSizePacket) UnmarshalBinary

func (v *RtmpSetWindowAckSizePacket) UnmarshalBinary(data []byte) (err error)

type RtmpStack

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

RTMP protocol stack.

func NewRtmpStack

func NewRtmpStack(ctx core.Context, r io.Reader, w io.Writer) *RtmpStack

func (*RtmpStack) DecodeMessage

func (v *RtmpStack) DecodeMessage(m *RtmpMessage) (p RtmpPacket, err error)

func (*RtmpStack) ReadMessage

func (v *RtmpStack) ReadMessage() (m *RtmpMessage, err error)

func (*RtmpStack) SendMessage

func (v *RtmpStack) SendMessage(msgs ...*RtmpMessage) (err error)

to sendout multiple messages.

type RtmpUint16

type RtmpUint16 uint16

the uint16 which suppport marshal and unmarshal.

func (*RtmpUint16) MarshalBinary

func (v *RtmpUint16) MarshalBinary() (data []byte, err error)

func (*RtmpUint16) Size

func (v *RtmpUint16) Size() int

func (*RtmpUint16) UnmarshalBinary

func (v *RtmpUint16) UnmarshalBinary(data []byte) (err error)

type RtmpUint32

type RtmpUint32 uint32

the uint32 which suppport marshal and unmarshal.

func (*RtmpUint32) MarshalBinary

func (v *RtmpUint32) MarshalBinary() (data []byte, err error)

func (*RtmpUint32) Size

func (v *RtmpUint32) Size() int

func (*RtmpUint32) UnmarshalBinary

func (v *RtmpUint32) UnmarshalBinary(data []byte) (err error)

type RtmpUint8

type RtmpUint8 uint8

the uint8 which suppport marshal and unmarshal.

func (*RtmpUint8) MarshalBinary

func (v *RtmpUint8) MarshalBinary() (data []byte, err error)

func (*RtmpUint8) Size

func (v *RtmpUint8) Size() int

func (*RtmpUint8) UnmarshalBinary

func (v *RtmpUint8) UnmarshalBinary(data []byte) (err error)

type RtmpUserControlPacket

type RtmpUserControlPacket struct {
	// Event type is followed by Event data.
	// @see RtmpPcucEventType
	EventType RtmpUint16
	// the event data generally in 4bytes.
	// @remark for event type is 0x001a, only 1bytes.
	EventData RtmpUint32
	// 4bytes if event_type is RtmpPcucSetBufferLength; otherwise 0.
	ExtraData RtmpUint32
}

5.4. User Control Message (4)

for the EventData is 4bytes. Stream Begin(=0) 4-bytes stream ID Stream EOF(=1) 4-bytes stream ID StreamDry(=2) 4-bytes stream ID SetBufferLength(=3) 8-bytes 4bytes stream ID, 4bytes buffer length. StreamIsRecorded(=4) 4-bytes stream ID PingRequest(=6) 4-bytes timestamp local server time PingResponse(=7) 4-bytes timestamp received ping request.

3.7. User Control message +------------------------------+------------------------- | Event Type ( 2- bytes ) | Event Data +------------------------------+------------------------- Figure 5 Pay load for the 'User Control Message'.

func (*RtmpUserControlPacket) MarshalBinary

func (v *RtmpUserControlPacket) MarshalBinary() (data []byte, err error)

func (*RtmpUserControlPacket) MessageType

func (v *RtmpUserControlPacket) MessageType() RtmpMessageType

func (*RtmpUserControlPacket) PreferCid

func (v *RtmpUserControlPacket) PreferCid() uint32

func (*RtmpUserControlPacket) UnmarshalBinary

func (v *RtmpUserControlPacket) UnmarshalBinary(data []byte) (err error)

type RtmpVideoAVCType

type RtmpVideoAVCType uint8

AVCPacketType IF CodecID == 7 UI8 The following values are defined:

0 = AVC sequence header
1 = AVC NALU
2 = AVC end of sequence (lower level NALU sequence ender is
    not required or supported)
const (
	RtmpSequenceHeader RtmpVideoAVCType = iota
	RtmpNALU
	RtmpSequenceHeaderEOF
	RtmpReservedAVCType
)

Jump to

Keyboard shortcuts

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