httpflv

package
v0.0.0-...-928f415 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 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 (
	SubSessionWriteChanSize  = 1024 // SubSession发送数据时channel的大小
	SubSessionWriteTimeoutMs = 10000
	FlvHeader                = []byte{0x46, 0x4c, 0x56, 0x01, 0x05, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00}

	Log = nazalog.GetGlobalLogger()
)
View Source
var Clock = mock.NewStdClock()

Functions

func PackHttpflvTag

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

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

Types

type FlvFilePump

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

func NewFlvFilePump

func NewFlvFilePump(modOptions ...ModFlvFilePumpOption) *FlvFilePump

func (*FlvFilePump) Pump

func (f *FlvFilePump) Pump(filename string, onFlvTag OnPumpFlvTag) error

Pump

@param onFlvTag 如果回调中返回false,则停止Pump

func (*FlvFilePump) PumpWithTags

func (f *FlvFilePump) PumpWithTags(tags []Tag, onFlvTag OnPumpFlvTag) error

PumpWithTags @return error 暂时只做预留,目前只会返回nil

type FlvFilePumpOption

type FlvFilePumpOption struct {
	IsRecursive bool // 如果为true,则循环返回文件内容(类似于ffmpeg的-stream_loop -1)
}

FlvFilePumpOption

读取flv文件,将tag按时间戳间隔缓慢(类似于ffmpeg的-re)返回

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

func (ffw *FlvFileWriter) Name() string

func (*FlvFileWriter) Open

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

func (*FlvFileWriter) WriteFlvHeader

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 ModFlvFilePumpOption

type ModFlvFilePumpOption func(option *FlvFilePumpOption)

type ModPullSessionOption

type ModPullSessionOption func(option *PullSessionOption)

type OnPumpFlvTag

type OnPumpFlvTag func(tag Tag) bool

type OnReadFlvTag

type OnReadFlvTag func(tag Tag)

OnReadFlvTag @param tag: 底层保证回调上来的Raw数据长度是完整的(但是不会分析Raw内部的编码数据)

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

AppName 文档请参考: interface ISessionUrlContext

func (*PullSession) Dispose

func (session *PullSession) Dispose() error

Dispose 文档请参考: IClientSessionLifecycle interface

func (*PullSession) GetStat

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

GetStat 文档请参考: interface ISessionStat

func (*PullSession) IsAlive

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

IsAlive 文档请参考: interface ISessionStat

func (*PullSession) Pull

func (session *PullSession) Pull(rawUrl string, onReadFlvTag OnReadFlvTag) error

Pull 阻塞直到和对端完成拉流前,握手部分的工作,或者发生错误

注意,握手指的是发送完HTTP Request,不包含接收任何数据,因为有的httpflv服务端,如果流不存在不会发送任何内容,此时我们也应该认为是握手完成了

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

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

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

func (*PullSession) RawQuery

func (session *PullSession) RawQuery() string

RawQuery 文档请参考: interface ISessionUrlContext

func (*PullSession) StreamName

func (session *PullSession) StreamName() string

StreamName 文档请参考: interface ISessionUrlContext

func (*PullSession) UniqueKey

func (session *PullSession) UniqueKey() string

UniqueKey 文档请参考: interface IObject

func (*PullSession) UpdateStat

func (session *PullSession) UpdateStat(intervalSec uint32)

UpdateStat 文档请参考: interface ISessionStat

func (*PullSession) Url

func (session *PullSession) Url() string

Url 文档请参考: interface ISessionUrlContext

func (*PullSession) WaitChan

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

WaitChan 文档请参考: IClientSessionLifecycle interface

type PullSessionOption

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

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

type SubSession

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

func NewSubSession

func NewSubSession(conn net.Conn, urlCtx base.UrlContext, isWebSocket bool, websocketKey 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) RunLoop

func (session *SubSession) RunLoop() error

func (*SubSession) StreamName

func (session *SubSession) StreamName() string

func (*SubSession) UniqueKey

func (session *SubSession) UniqueKey() string

func (*SubSession) UpdateStat

func (session *SubSession) UpdateStat(intervalSec uint32)

func (*SubSession) Url

func (session *SubSession) Url() string

func (*SubSession) Write

func (session *SubSession) Write(b []byte)

func (*SubSession) WriteFlvHeader

func (session *SubSession) WriteFlvHeader()

func (*SubSession) WriteHttpResponseHeader

func (session *SubSession) WriteHttpResponseHeader()

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 ReadTag

func ReadTag(rd io.Reader) (tag Tag, err error)

ReadTag 从`rd`中读取数据并解析至`tag`

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

IsVideoKeyNalu AVC或HEVC的关键帧

func (*Tag) IsVideoKeySeqHeader

func (tag *Tag) IsVideoKeySeqHeader() bool

IsVideoKeySeqHeader AVC或HEVC的seq header

func (*Tag) ModTagTimestamp

func (tag *Tag) ModTagTimestamp(timestamp uint32)

func (*Tag) Payload

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

Payload 只包含数据部分,去除了前面11字节的tag header和后面4字节的prev tag size

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