Documentation
¶
Index ¶
- Constants
- type Buf
- type BufPos
- type DataSliceInfo
- type DemuxCloser
- type Demuxer
- type Extend
- type Header
- type MuxCloser
- type Muxer
- type Option
- func WithAfterReadSliceHeaders(f func([]Packet) error) Option
- func WithAfterReadSlicePacket(f func(*Packet) error) Option
- func WithAfterWriteSliceHeaders(f func([]Packet) error) Option
- func WithAfterWriteSlicePacket(f func(*Packet) error) Option
- func WithConnectedTimestamp(t time.Time) Option
- func WithHandlerName(name string) Option
- func WithSID(id string) Option
- type Options
- type Packet
- type PacketReader
- type PacketWriter
- type Queue
- func (q *Queue) Close() (err error)
- func (q *Queue) CursorBySliceReq(id, sid string, sliceStartId uint64, sliceSubstreamId []uint8, ...) *QueueCursor
- func (q *Queue) GetBySliceID(sliceID uint64) (Packet, error)
- func (q *Queue) GetPktCount() int
- func (q *Queue) IsClosed() bool
- func (q *Queue) SetMaxCacheTime(n int)
- func (q *Queue) SetMaxPktCount(n int)
- func (q *Queue) SetSID(id string)
- func (q *Queue) Stat() *Stat
- func (q *Queue) WriteHeader(datas []Packet) error
- func (q *Queue) WritePacket(pkt Packet) error
- func (q *Queue) WriteTrailer() error
- type QueueCursor
- func (qc *QueueCursor) Close() error
- func (qc *QueueCursor) Format() string
- func (q *QueueCursor) Headers() (cdata []Packet, err error)
- func (q *QueueCursor) IsReqSubStreamId(sliceId uint64) bool
- func (q *QueueCursor) ReadPacket() (pkt Packet, err error)
- func (q *QueueCursor) SetTimeOffset(timeOffset int)
- type Stat
- type Transport
Constants ¶
const ( // DefaultPktCount 默认bufqueue缓存pkt个数 DefaultPktCount = 10000 //10MB DefaultCacheTimeMax = 20000 //20s )
const ( SLICE_TYPE_FLV_HEADER = 0 SLICE_TYPE_SCRIPT_DATA = 1 SLICE_TYPE_AUDIO = 2 SLICE_TYPE_VIDEO = 3 )
切片类型: (00 flv header;01 script data;02 audio;03 video)
const ( SLICE_FRAME_TYPE_AUDIO = 0 SLICE_FRAME_TYPE_IDR = 1 SLICE_FRAME_TYPE_REF = 2 SLICE_FRAME_TYPE_NOREF = 3 )
帧类型: 00 非视频帧,音频或头部,01 IDR;02 有参考性帧;03无参考性帧;
const ( SLICE_POSFLAG_MIDDLE = 0 SLICE_POSFLAG_START = 1 SLICE_POSFLAG_END = 2 SLICE_POSFLAG_STARTEND = 3 )
当前切片在当前数据段的位 置,一共两个bits,最后一 个 bit=1 代表起始,第一个 bit=1 代表结束 (eg: 00 中间; 01 起始非结束;10: 结束非起始;11 起始且结束)
const ( SLICE_ID_AVC_HEADER = 1 SLICE_ID_AAC_HEADER = 2 )
flv header 切片ID
const KSliceDefaultSizeMax = 1280
const KSliceExtendFlag = 0
const KSliceExtendHeaderLen = 2
const (
KSliceExtendKeyTimeStamp = 1
)
extend key define
const KSliceHeaderSize = 15
const KSliceSizeThreshold = 3 << 10
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buf ¶
func (*Buf) IsValidPos ¶
type DataSliceInfo ¶
type DataSliceInfo struct {
SliceId uint64 // slice id
FrameId uint32 // frame id
SliceSizeMax int
}
func NewDataSliceInfo ¶
func NewDataSliceInfo() *DataSliceInfo
func (*DataSliceInfo) GenerateSlice ¶
func (s *DataSliceInfo) GenerateSlice(data []byte, avPkt *av.Packet) []Packet
func (DataSliceInfo) SetSliceSizeMax ¶
func (s DataSliceInfo) SetSliceSizeMax(sliceSizeMax int)
type DemuxCloser ¶
DemuxCloser Demuxer with Close() method
type Demuxer ¶
type Demuxer interface {
PacketReader // read slice packets
Headers() ([]Packet, error) // reads the file header, contains flv header infomations
}
type Muxer ¶
type Muxer interface {
WriteHeader(pkt []Packet) error // write the file header
PacketWriter // write slice packets
WriteTrailer() error // finish writing file, this func can be called only once
}
type Option ¶
type Option func(*Options)
func WithConnectedTimestamp ¶
WithConnectedTimestamp 设置Options的ConnectedTimestamp选项
func WithHandlerName ¶
WithHandlerName 设置Options的HandlerName选项
type Packet ¶
type Packet struct {
Size uint16 // slice size
SliceType uint8 // slice type
SliceId uint64 // slice id
FrameId uint32 // frame id
PosFlag uint8
FrameType uint8
Reserved uint8
ExtendFlag uint8
Extend Extend
Data []byte // slice data
// no encode, for p2p quickOffset
FrameDts int32 // frame dts
HeaderBeginAt int // header pos in queue
HeaderChanged bool // indicates if the sps/pps info changed
}
Packet 切片数据包结构 |SliceLen|SliceType|SliceSeq|FrameId|posFlag|frameType|reserved|extended|data | |UB12 |UB4 |Uint64 |Uint32 |UB2 |UB2 |UB3 |UB1 |string|
type PacketReader ¶
type PacketWriter ¶
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue buffer queue
func (*Queue) CursorBySliceReq ¶
func (q *Queue) CursorBySliceReq(id, sid string, sliceStartId uint64, sliceSubstreamId []uint8, sliceStreamBase uint8) *QueueCursor
CursorBySliceReq 按切片请求参数,找到对应的位置
func (*Queue) GetBySliceID ¶
GetBySliceID for slice range
func (*Queue) SetMaxCacheTime ¶
SetMaxCacheTime setMaxCacheTime
func (*Queue) WriteHeader ¶
func (*Queue) WritePacket ¶
WritePacket Put packet into buffer, old packets will be discared.
type QueueCursor ¶
type QueueCursor struct {
// P2P quickTime req
TimeOffset int
// slice req
SliceStartId uint64
SliceSubstreamId []uint8
SliceStreamBase uint8
// contains filtered or unexported fields
}
QueueCursor Cursor of queue
func (*QueueCursor) Close ¶
func (qc *QueueCursor) Close() error
func (*QueueCursor) Format ¶
func (qc *QueueCursor) Format() string
func (*QueueCursor) Headers ¶
func (q *QueueCursor) Headers() (cdata []Packet, err error)
Headers 返回队列中缓存的音视频header
func (*QueueCursor) IsReqSubStreamId ¶
func (q *QueueCursor) IsReqSubStreamId(sliceId uint64) bool
func (*QueueCursor) ReadPacket ¶
func (q *QueueCursor) ReadPacket() (pkt Packet, err error)
ReadPacket will not consume packets in Queue, it's just a cursor.
func (*QueueCursor) SetTimeOffset ¶
func (q *QueueCursor) SetTimeOffset(timeOffset int)
type Stat ¶
type Stat struct {
PktCount uint32 `json:"pkt_count"`
GopCount uint32 `json:"gop_count"`
PktDuration int32 `json:"pkt_duration"`
LossPktCount uint32 `json:"loss_pkt_count"`
HeadPos int `json:"head_pos"`
TailPos int `json:"tail_pos"`
Closed bool `json:"closed"`
MaxSliceId uint64 `json:"max_slice_id"`
}
Stat ...
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport 从高层次封装了slice传输
func (*Transport) CopyHeaders ¶
CopyHeaders ...
func (*Transport) CopyPackets ¶
CopyPackets ...