httpflv

package
v0.19.16 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagHeaderSize        int = 11
	PrevTagSizeFieldSize int = 4
)
View Source
const (
	TagTypeMetadata uint8 = 18
	TagTypeVideo    uint8 = 9
	TagTypeAudio    uint8 = 8
)
View Source
const (
	AVCKeyFrame   = frameTypeKey<<4 | codecIDAVC
	AVCInterFrame = frameTypeInter<<4 | codecIDAVC

	HEVCKeyFrame   = frameTypeKey<<4 | codecIDHEVC
	HEVCInterFrame = frameTypeInter<<4 | codecIDHEVC
)
View Source
const (
	AVCPacketTypeSeqHeader uint8 = 0
	AVCPacketTypeNALU      uint8 = 1

	HEVCPacketTypeSeqHeader uint8 = 0
	HEVCPacketTypeNALU      uint8 = 1

	AACPacketTypeSeqHeader uint8 = 0
	AACPacketTypeRaw       uint8 = 1
)
View Source
const (
	SoundFormatAAC uint8 = 10
)

Variables

View Source
var ErrHTTPFLV = errors.New("lal.httpflv: fxxk")
View Source
var FLVHeader = []byte{0x46, 0x4c, 0x56, 0x01, 0x05, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00}

Functions

func PackHTTPFLVTag

func PackHTTPFLVTag(t uint8, timestamp uint32, in []byte) []byte

打包一个序列化后的 tag 二进制buffer,包含 tag header,body,prev tag size

Types

type FLVFileReader

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

func (*FLVFileReader) Dispose

func (ffr *FLVFileReader) Dispose()

func (*FLVFileReader) Open

func (ffr *FLVFileReader) Open(filename string) (err error)

func (*FLVFileReader) ReadFLVHeader

func (ffr *FLVFileReader) ReadFLVHeader() ([]byte, error)

func (*FLVFileReader) ReadTag

func (ffr *FLVFileReader) ReadTag() (Tag, error)

type FLVFileWriter

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

func (*FLVFileWriter) Dispose

func (ffw *FLVFileWriter) Dispose() error

func (*FLVFileWriter) Name added in v0.19.12

func (ffw *FLVFileWriter) Name() string

func (*FLVFileWriter) Open

func (ffw *FLVFileWriter) Open(filename string) (err error)

func (*FLVFileWriter) WriteFLVHeader added in v0.19.12

func (ffw *FLVFileWriter) WriteFLVHeader() (err error)

func (*FLVFileWriter) WriteRaw

func (ffw *FLVFileWriter) WriteRaw(b []byte) (err error)

func (*FLVFileWriter) WriteTag

func (ffw *FLVFileWriter) WriteTag(tag Tag) (err error)

type ModPullSessionOption

type ModPullSessionOption func(option *PullSessionOption)

type OnReadFLVTag

type OnReadFLVTag func(tag Tag)

type PullSession

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

func NewPullSession

func NewPullSession(modOptions ...ModPullSessionOption) *PullSession

func (*PullSession) AppName

func (session *PullSession) AppName() string

文档请参考: interface ISessionURLContext

func (*PullSession) Dispose

func (session *PullSession) Dispose() error

文档请参考: interface IClientSessionLifecycle

func (*PullSession) GetStat

func (session *PullSession) GetStat() base.StatSession

文档请参考: interface ISessionStat

func (*PullSession) IsAlive

func (session *PullSession) IsAlive() (readAlive, writeAlive bool)

文档请参考: interface ISessionStat

func (*PullSession) Pull

func (session *PullSession) Pull(rawURL string, onReadFLVTag OnReadFLVTag) error

阻塞直到和对端完成拉流前,握手部分的工作(也即发送完HTTP Request),或者发生错误

rawURL 支持如下两种格式。(当然,关键点是对端支持)

http://{domain}/{app_name}/{stream_name}.flv
http://{ip}/{domain}/{app_name}/{stream_name}.flv

onReadFLVTag 读取到 flv tag 数据时回调。回调结束后,PullSession 不会再使用这块 <tag> 数据。

func (*PullSession) RawQuery

func (session *PullSession) RawQuery() string

文档请参考: interface ISessionURLContext

func (*PullSession) StreamName

func (session *PullSession) StreamName() string

文档请参考: interface ISessionURLContext

func (*PullSession) URL added in v0.19.12

func (session *PullSession) URL() string

文档请参考: interface ISessionURLContext

func (*PullSession) UniqueKey

func (session *PullSession) UniqueKey() string

文档请参考: interface IObject

func (*PullSession) UpdateStat

func (session *PullSession) UpdateStat(intervalSec uint32)

文档请参考: interface ISessionStat

func (*PullSession) WaitChan added in v0.19.12

func (session *PullSession) WaitChan() <-chan error

文档请参考: interface IClientSessionLifecycle

type PullSessionOption

type PullSessionOption struct {
	// 从调用Pull函数,到接收音视频数据的前一步,也即发送完HTTP请求的超时时间
	// 如果为0,则没有超时时间
	PullTimeoutMS int

	ReadTimeoutMS int // 接收数据超时,单位毫秒,如果为0,则不设置超时
}

type Server

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

func NewServer

func NewServer(observer ServerObserver, config ServerConfig) *Server

func (*Server) Dispose

func (server *Server) Dispose()

func (*Server) Listen

func (server *Server) Listen() (err error)

func (*Server) RunLoop

func (server *Server) RunLoop() error

type ServerConfig

type ServerConfig struct {
	Enable        bool   `json:"enable"`
	SubListenAddr string `json:"sub_listen_addr"`
	EnableHTTPS   bool   `json:"enable_https"`
	HTTPSAddr     string `json:"https_addr"`
	HTTPSCertFile string `json:"https_cert_file"`
	HTTPSKeyFile  string `json:"https_key_file"`
}

type ServerObserver

type ServerObserver interface {
	// 通知上层有新的拉流者
	// 返回值: true则允许拉流,false则关闭连接
	OnNewHTTPFLVSubSession(session *SubSession) bool

	OnDelHTTPFLVSubSession(session *SubSession)
}

type SubSession

type SubSession struct {
	IsFresh bool
	// contains filtered or unexported fields
}

func NewSubSession

func NewSubSession(conn net.Conn, scheme string) *SubSession

func (*SubSession) AppName

func (session *SubSession) AppName() string

func (*SubSession) Dispose

func (session *SubSession) Dispose() error

func (*SubSession) GetStat

func (session *SubSession) GetStat() base.StatSession

func (*SubSession) IsAlive

func (session *SubSession) IsAlive() (readAlive, writeAlive bool)

func (*SubSession) RawQuery

func (session *SubSession) RawQuery() string

func (*SubSession) ReadRequest

func (session *SubSession) ReadRequest() (err error)

TODO chef: read request timeout

func (*SubSession) RunLoop

func (session *SubSession) RunLoop() error

func (*SubSession) StreamName

func (session *SubSession) StreamName() string

func (*SubSession) URL

func (session *SubSession) URL() string

func (*SubSession) UniqueKey

func (session *SubSession) UniqueKey() string

func (*SubSession) UpdateStat

func (session *SubSession) UpdateStat(intervalSec uint32)

func (*SubSession) WriteFLVHeader

func (session *SubSession) WriteFLVHeader()

func (*SubSession) WriteHTTPResponseHeader

func (session *SubSession) WriteHTTPResponseHeader()

func (*SubSession) WriteRawPacket

func (session *SubSession) WriteRawPacket(pkt []byte)

func (*SubSession) WriteTag

func (session *SubSession) WriteTag(tag *Tag)

type Tag

type Tag struct {
	Header TagHeader
	Raw    []byte // 结构为 (11字节的 tag header) + (body) + (4字节的 prev tag size)
}

func ReadAllTagsFromFLVFile

func ReadAllTagsFromFLVFile(filename string) ([]Tag, error)

func (*Tag) IsAACSeqHeader

func (tag *Tag) IsAACSeqHeader() bool

func (*Tag) IsAVC

func (tag *Tag) IsAVC() bool

func (*Tag) IsAVCKeyNALU

func (tag *Tag) IsAVCKeyNALU() bool

func (*Tag) IsAVCKeySeqHeader

func (tag *Tag) IsAVCKeySeqHeader() bool

func (*Tag) IsHEVC

func (tag *Tag) IsHEVC() bool

func (*Tag) IsHEVCKeyNALU

func (tag *Tag) IsHEVCKeyNALU() bool

func (*Tag) IsHEVCKeySeqHeader

func (tag *Tag) IsHEVCKeySeqHeader() bool

func (*Tag) IsMetadata

func (tag *Tag) IsMetadata() bool

func (*Tag) IsVideoKeyNALU

func (tag *Tag) IsVideoKeyNALU() bool

AVC或HEVC的关键帧

func (*Tag) IsVideoKeySeqHeader

func (tag *Tag) IsVideoKeySeqHeader() bool

AVC或HEVC的seq header

func (*Tag) ModTagTimestamp

func (tag *Tag) ModTagTimestamp(timestamp uint32)

func (*Tag) Payload

func (tag *Tag) Payload() []byte

type TagHeader

type TagHeader struct {
	Type      uint8  // type
	DataSize  uint32 // body大小,不包含 header 和 prev tag size 字段
	Timestamp uint32 // 绝对时间戳,单位毫秒
	StreamID  uint32 // always 0
}

Jump to

Keyboard shortcuts

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