media

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StreamOK       int32 = iota
	StreamClosed         // 源关闭
	StreamReplaced       // 流被替换
	StreamNoConsumer
)

流状态

Variables

View Source
var (
	// ErrStreamClosed 流被关闭
	ErrStreamClosed = errors.New("stream is closed")
	// ErrStreamReplaced 流被替换
	ErrStreamReplaced = errors.New("stream is replaced")
)

错误定义

Functions

func Count

func Count() (sc, cc int)

Count 流媒体数量和消费者数量

func Regist

func Regist(s *Stream)

Regist 注册流

func RegistPullStreamFactory

func RegistPullStreamFactory(f PullStreamFactory)

RegistPullStreamFactory 注册拉流工厂

func Unregist

func Unregist(s *Stream)

Unregist 取消注册

func UnregistAll

func UnregistAll()

UnregistAll 取消全部注册的流

Types

type CID

type CID uint32

CID consumer ID type(2bits)+sequence(30bits)

func NewCID

func NewCID(packetType PacketType, consumerSequenceSeed *uint32) CID

NewCID 创建新的流消费ID

func (CID) Sequence

func (id CID) Sequence() uint32

Sequence 获取消费者序号

func (CID) Type

func (id CID) Type() PacketType

Type 获取消费者类型

type Consumer

type Consumer interface {
	Consume(pack Pack)
	io.Closer
}

Consumer 消费者接口

type ConsumptionInfo

type ConsumptionInfo struct {
	ID         uint32           `json:"id"`
	StartOn    string           `json:"start_on"`
	PacketType string           `json:"packet_type"`
	Extra      string           `json:"extra"`
	Flow       stats.FlowSample `json:"flow"` // 转换成 K
}

ConsumptionInfo 消费者信息

type Hlsable

type Hlsable interface {
	M3u8(token string) ([]byte, error)
	Segment(seq int) (io.Reader, int, error)
	LastAccessTime() time.Time
}

Hlsable 支持Hls访问

type Multicastable

type Multicastable interface {
	AddMember(io.Closer)
	ReleaseMember(io.Closer)
	MulticastIP() string
	Port(index int) int
	TTL() int
	SourceIP() string
}

Multicastable 支持组播模式的源

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option 配置 Stream 的选项接口

func Attr

func Attr(k, v string) Option

Attr 流属性选项

func Hls

func Hls(hls Hlsable) Option

Hls Hls选项

func Multicast

func Multicast(multicast Multicastable) Option

Multicast 流组播选项

type Pack

type Pack = format.Packet

Pack .

type PacketType

type PacketType uint32

PacketType 消费媒体包类型

const (
	RTPPacket PacketType = iota // 根据 RTP 协议打包的媒体
	FLVPacket
)

预定义消费媒体包类型

func (PacketType) String

func (t PacketType) String() string

String 类型的字串表示

type PullStreamFactory

type PullStreamFactory interface {
	Can(remoteURL string) bool
	Create(localPath, remoteURL string) (*Stream, error)
}

PullStreamFactory 拉流工程流

type Stream

type Stream struct {
	Video codec.VideoMeta
	Audio codec.AudioMeta
	// contains filtered or unexported fields
}

Stream 媒体流

func Get

func Get(path string) *Stream

Get 获取路径为 path 已存在的流。

func GetOrCreate

func GetOrCreate(path string) *Stream

GetOrCreate 获取路径为 path 的流媒体,如果不存在尝试自动创建拉流。

func NewStream

func NewStream(path string, rawsdp string, options ...Option) *Stream

NewStream 创建新的流

func (*Stream) Attr

func (s *Stream) Attr(key string) string

Attr 流属性

func (*Stream) Close

func (s *Stream) Close() error

Close 关闭流

func (*Stream) ConsumerCount

func (s *Stream) ConsumerCount() int

ConsumerCount 流消费者计数

func (*Stream) FlvTypeFlags

func (s *Stream) FlvTypeFlags() byte

FlvTypeFlags 支持的 flv TypeFlags

func (*Stream) GetConsumption

func (s *Stream) GetConsumption(cid CID) (ConsumptionInfo, bool)

GetConsumption 获取指定消费信息

func (*Stream) Hlsable

func (s *Stream) Hlsable() Hlsable

Hlsable 返回支持hls能力,不支持返回nil

func (*Stream) Info

func (s *Stream) Info(includeCS bool) *StreamInfo

Info 获取流信息

func (*Stream) Multicastable

func (s *Stream) Multicastable() Multicastable

Multicastable 返回组播支持能力,不支持返回nil

func (*Stream) Path

func (s *Stream) Path() string

Path 流路径

func (*Stream) Sdp

func (s *Stream) Sdp() string

Sdp sdp 字串

func (*Stream) StartConsume

func (s *Stream) StartConsume(consumer Consumer, packetType PacketType, extra string) CID

StartConsume 开始消费

func (*Stream) StartConsumeNoGopCache

func (s *Stream) StartConsumeNoGopCache(consumer Consumer, packetType PacketType, extra string) CID

StartConsumeNoGopCache 开始消费,不使用GopCahce

func (*Stream) StopConsume

func (s *Stream) StopConsume(cid CID)

StopConsume 开始消费

func (*Stream) WriteFlvTag

func (s *Stream) WriteFlvTag(tag *flv.Tag) error

WriteTag .

func (*Stream) WriteFrame

func (s *Stream) WriteFrame(frame *codec.Frame) error

WriteFrame .

func (*Stream) WriteRtpPacket

func (s *Stream) WriteRtpPacket(packet *rtp.Packet) error

WriteRtpPacket 向流写入一个媒体包

type StreamInfo

type StreamInfo struct {
	StartOn          string            `json:"start_on"`
	Path             string            `json:"path"`
	Addr             string            `json:"addr"`
	Size             int               `json:"size"`
	Video            *codec.VideoMeta  `json:"video,omitempty"`
	Audio            *codec.AudioMeta  `json:"audio,omitempty"`
	ConsumptionCount int               `json:"cc"`
	Consumptions     []ConsumptionInfo `json:"cs,omitempty"`
}

StreamInfo 流信息

func Infos

func Infos(pagetoken string, pagesize int, includeCS bool) (int, []*StreamInfo)

Infos 返回所有的流媒体信息

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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