media

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusContinue                      = 100
	StatusOK                            = 200
	StatusCreated                       = 201
	StatusLowOnStorageSpace             = 250
	StatusMultipleChoices               = 300
	StatusMovedPermanently              = 301
	StatusMovedTemporarily              = 302
	StatusSeeOther                      = 303
	StatusNotModified                   = 304
	StatusUseProxy                      = 305
	StatusBadRequest                    = 400
	StatusUnauthorized                  = 401
	StatusPaymentRequired               = 402
	StatusForbidden                     = 403
	StatusNotFound                      = 404
	StatusMethodNotAllowed              = 405
	StatusNotAcceptable                 = 406
	StatusProxyAuthenticationRequired   = 407
	StatusRequestTimeout                = 408
	StatusGone                          = 410
	StatusLengthRequired                = 411
	StatusPreconditionFailed            = 412
	StatusRequestEntityTooLarge         = 413
	StatusRequestURITooLong             = 414
	StatusUnsupportedMediaType          = 415
	StatusInvalidparameter              = 451
	StatusIllegalConferenceIdentifier   = 452
	StatusNotEnoughBandwidth            = 453
	StatusSessionNotFound               = 454
	StatusMethodNotValidInThisState     = 455
	StatusHeaderFieldNotValid           = 456
	StatusInvalidRange                  = 457
	StatusParameterIsReadOnly           = 458
	StatusAggregateOperationNotAllowed  = 459
	StatusOnlyAggregateOperationAllowed = 460
	StatusUnsupportedTransport          = 461
	StatusDestinationUnreachable        = 462
	StatusInternalServerError           = 500
	StatusNotImplemented                = 501
	StatusBadGateway                    = 502
	StatusServiceUnavailable            = 503
	StatusGatewayTimeout                = 504
	StatusRTSPVersionNotSupported       = 505
	StatusOptionNotsupport              = 551
)

RTSP response status codes

View Source
const (
	MSE = iota
	WEBRTC
	RTSP
)

Default stream type

View Source
const (
	OFFLINE = iota
	ONLINE
)

Default stream status type

View Source
const (
	SignalStreamRestart = iota ///< Y   Restart
	SignalStreamStop
	SignalStreamClient
)

Default streams signals

Variables

View Source
var (
	Version   = "RTSP/1.0"
	UserAgent = "Lavf58.29.100"
	Session   = "000a959d6816"
)
View Source
var (
	OPTIONS  = "OPTIONS"
	DESCRIBE = "DESCRIBE"
	SETUP    = "SETUP"
	PLAY     = "PLAY"
	TEARDOWN = "TEARDOWN"
)
View Source
var (
	ErrorStreamNotFound             = apperr.ErrorWithCode("STREAM_NOT_FOUND", "stream not found", apperr.ErrNotFound)
	ErrorStreamAlreadyExists        = apperr.ErrorWithCode("STREAM_ALREADY_EXISTS", "stream already exists", apperr.ErrInvalidRequest)
	ErrorStreamChannelAlreadyExists = apperr.ErrorWithCode("STREAM_CHANNEL_ALREADY_EXISTS", "stream channel already exists", apperr.ErrInvalidRequest)
	ErrorStreamNotHLSSegments       = apperr.ErrorWithCode("STREAM_HLS_NOT_TS_SEQ_FOUND", "stream hls not ts seq found", apperr.ErrNotFound)
	ErrorStreamNoVideo              = apperr.ErrorWithCode("STREAM_NO_VIDEO", "stream no video", apperr.ErrNotFound)
	ErrorStreamNoClients            = apperr.ErrorWithCode("STREAM_NO_CLIENTS", "stream no clients", apperr.ErrNotFound)
	ErrorStreamRestart              = apperr.ErrorWithCode("STREAM_RESTART", "stream restart", apperr.ErrInternal)
	ErrorStreamStopCoreSignal       = apperr.ErrorWithCode("STREAM_STOP_CORE_SIGNAL", "stream stop core signal", apperr.ErrInternal)
	ErrorStreamStopRTSPSignal       = apperr.ErrorWithCode("STREAM_STOP_RTSP_SIGNAL", "stream stop rtsp signal", apperr.ErrInternal)
	ErrorStreamChannelNotFound      = apperr.ErrorWithCode("STREAM_CHANNEL_NOT_FOUND", "stream channel not found", apperr.ErrNotFound)
	ErrorStreamChannelCodecNotFound = apperr.ErrorWithCode("STREAM_CHANNEL_CODEC_NOT_READY,_POSSIBLE_STREAM_OFFLINE", "stream channel codec not ready, possible stream offline", apperr.ErrInternal)
	ErrorStreamsLen0                = apperr.ErrorWithCode("STREAMS_LEN_ZERO", "streams len zero", apperr.ErrInternal)
	ErrorStreamUnauthorized         = apperr.ErrorWithCode("STREAM_REQUEST_UNAUTHORIZED", "stream request unauthorized", apperr.ErrUnauthorized)
)

Default stream errors

View Source
var (
	//Default www static file dir
	DefaultHTTPDir = "static_source/media"
)
View Source
var Storage = NewStreamCore()

Functions

func RTSPServer

func RTSPServer()

RTSPServer func

func RTSPServerClientHandle

func RTSPServerClientHandle(conn net.Conn)

RTSPServerClientHandle func

func RTSPServerClientPlay

func RTSPServerClientPlay(uuid string, channel string, conn net.Conn)

handleRTSPServerPlay func

func RTSPServerClientResponse

func RTSPServerClientResponse(uuid string, channel string, conn net.Conn, status int, headers map[string]string) error

handleRTSPServerPlay func

func RemoteAuthorization

func RemoteAuthorization(proto string, stream string, channel string, token string, ip string) bool

func StatusText

func StatusText(code int) string

func StreamServerRunStream

func StreamServerRunStream(streamID string, channelID string, opt *ChannelST) (int, error)

StreamServerRunStream core stream

func StreamServerRunStreamDo

func StreamServerRunStreamDo(streamID string, channelID string)

StreamServerRunStreamDo stream run do mux

func StreamServerRunStreamRTMP

func StreamServerRunStreamRTMP(streamID string, channelID string, opt *ChannelST) (int, error)

Types

type AuthorizationReq

type AuthorizationReq struct {
	Proto   string `json:"proto,omitempty"`
	Stream  string `json:"stream,omitempty"`
	Channel string `json:"channel,omitempty"`
	Token   string `json:"token,omitempty"`
	IP      string `json:"ip,omitempty"`
}

type AuthorizationRes

type AuthorizationRes struct {
	Status string `json:"status,omitempty"`
}

type ChannelST

type ChannelST struct {
	Name               string `json:"name,omitempty" groups:"api,config"`
	URL                string `json:"url,omitempty" groups:"api,config"`
	OnDemand           bool   `json:"on_demand,omitempty" groups:"api,config"`
	Debug              bool   `json:"debug,omitempty" groups:"api,config"`
	Status             int    `json:"status,omitempty" groups:"api"`
	InsecureSkipVerify bool   `json:"insecure_skip_verify,omitempty" groups:"api,config"`
	Audio              bool   `json:"audio,omitempty" groups:"api,config"`
	// contains filtered or unexported fields
}

type ClientST

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

ClientST client storage section

type EventRemoveList

type EventRemoveList struct {
	Name string `json:"name"`
}

type EventUpdateList

type EventUpdateList struct {
	Name     string   `json:"name"`
	Channels []string `json:"channels"`
}

type Fragment

type Fragment struct {
	Independent bool          //Fragment have i-frame (key frame)
	Finish      bool          //Fragment Ready
	Duration    time.Duration //Fragment Duration
	Packets     []*av.Packet  //Packet Slice
}

Fragment struct

func (*Fragment) Close

func (element *Fragment) Close()

Close fragment block func

func (*Fragment) GetDuration

func (element *Fragment) GetDuration() time.Duration

GetDuration return fragment dur

func (*Fragment) WritePacket

func (element *Fragment) WritePacket(packet *av.Packet)

WritePacket to fragment func

type Media

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

func NewMedia

func NewMedia(lc fx.Lifecycle,
	eventBus bus.Bus) *Media

func (*Media) Shutdown

func (r *Media) Shutdown(ctx context.Context) (err error)

func (*Media) Start

func (r *Media) Start(ctx context.Context) (err error)

type MuxerHLS

type MuxerHLS struct {
	UUID              string             //Current UUID
	MSN               int                //Current MSN
	FPS               int                //Current FPS
	MediaSequence     int                //Current MediaSequence
	CurrentFragmentID int                //Current fragment id
	CacheM3U8         string             //Current index cache
	CurrentSegment    *Segment           //Current segment link
	Segments          map[int]*Segment   //Current segments group
	FragmentCtx       context.Context    //chan 1-N
	FragmentCancel    context.CancelFunc //chan 1-N
	// contains filtered or unexported fields
}

MuxerHLS struct

func NewHLSMuxer

func NewHLSMuxer(uuid string) *MuxerHLS

NewHLSMuxer Segments

func (*MuxerHLS) Close

func (element *MuxerHLS) Close()

func (*MuxerHLS) GetFragment

func (element *MuxerHLS) GetFragment(segment int, fragment int) ([]*av.Packet, error)

GetFragment func

func (*MuxerHLS) GetIndexM3u8

func (element *MuxerHLS) GetIndexM3u8(needMSN int, needPart int) (string, error)

GetIndexM3u8 func

func (*MuxerHLS) GetSegment

func (element *MuxerHLS) GetSegment(segment int) ([]*av.Packet, error)

GetSegment func

func (*MuxerHLS) NewSegment

func (element *MuxerHLS) NewSegment() *Segment

NewSegment func

func (*MuxerHLS) PlaylistUpdate

func (element *MuxerHLS) PlaylistUpdate()

PlaylistUpdate func

func (*MuxerHLS) SetFPS

func (element *MuxerHLS) SetFPS(fps int)

SetFPS func

func (*MuxerHLS) SortFragment

func (element *MuxerHLS) SortFragment(val map[int]*Fragment) []int

SortFragment func

func (*MuxerHLS) SortSegments

func (element *MuxerHLS) SortSegments(val map[int]*Segment) []int

SortSegments fuc

func (*MuxerHLS) UpdateIndexM3u8

func (element *MuxerHLS) UpdateIndexM3u8()

UpdateIndexM3u8 func

func (*MuxerHLS) WaitFragment

func (element *MuxerHLS) WaitFragment(timeOut time.Duration, segment, fragment int) ([]*av.Packet, error)

WaitFragment func

func (*MuxerHLS) WaitIndex

func (element *MuxerHLS) WaitIndex(timeOut time.Duration, segment, fragment int) (string, error)

WaitIndex func

func (*MuxerHLS) WritePacket

func (element *MuxerHLS) WritePacket(packet *av.Packet)

WritePacket func

type Segment

type Segment struct {
	FPS               int               //Current fps
	CurrentFragment   *Fragment         //CurrentFragment link
	CurrentFragmentID int               //CurrentFragment ID
	Finish            bool              //Segment Ready
	Duration          time.Duration     //Segment Duration
	Time              time.Time         //Realtime EXT-X-PROGRAM-DATE-TIME
	Fragment          map[int]*Fragment //Fragment map
}

Segment struct

func (*Segment) Close

func (element *Segment) Close()

Close segment func

func (*Segment) FragmentMS

func (element *Segment) FragmentMS(fps int) int64

FragmentMS func

func (*Segment) GetDuration

func (element *Segment) GetDuration() time.Duration

GetDuration func

func (*Segment) GetFragmentID

func (element *Segment) GetFragmentID() int

GetFragmentID func

func (*Segment) NewFragment

func (element *Segment) NewFragment() *Fragment

NewFragment open new fragment

func (*Segment) SetFPS

func (element *Segment) SetFPS(fps int)

SetFPS func

func (*Segment) WritePacket

func (element *Segment) WritePacket(packet *av.Packet)

WritePacket func

type SegmentOld

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

SegmentOld HLS cache section

type ServerST

type ServerST struct {
	Debug bool `json:"debug" groups:"api,config"`
	//LogLevel           logrus.Level `json:"log_level" groups:"api,config"`
	HTTPDemo           bool     `json:"http_demo" groups:"api,config"`
	HTTPDebug          bool     `json:"http_debug" groups:"api,config"`
	HTTPLogin          string   `json:"http_login" groups:"api,config"`
	HTTPPassword       string   `json:"http_password" groups:"api,config"`
	HTTPDir            string   `json:"http_dir" groups:"api,config"`
	HTTPPort           string   `json:"http_port" groups:"api,config"`
	RTSPPort           string   `json:"rtsp_port" groups:"api,config"`
	HTTPS              bool     `json:"https" groups:"api,config"`
	HTTPSPort          string   `json:"https_port" groups:"api,config"`
	HTTPSCert          string   `json:"https_cert" groups:"api,config"`
	HTTPSKey           string   `json:"https_key" groups:"api,config"`
	HTTPSAutoTLSEnable bool     `json:"https_auto_tls" groups:"api,config"`
	HTTPSAutoTLSName   string   `json:"https_auto_tls_name" groups:"api,config"`
	ICEServers         []string `json:"ice_servers" groups:"api,config"`
	ICEUsername        string   `json:"ice_username" groups:"api,config"`
	ICECredential      string   `json:"ice_credential" groups:"api,config"`
	Token              Token    `json:"token,omitempty" groups:"api,config"`
	WebRTCPortMin      uint16   `json:"webrtc_port_min" groups:"api,config"`
	WebRTCPortMax      uint16   `json:"webrtc_port_max" groups:"api,config"`
}

ServerST server storage section

type StorageST

type StorageST struct {
	Server          ServerST            `json:"server" groups:"api,config"`
	Streams         map[string]StreamST `json:"streams,omitempty" groups:"api,config"`
	ChannelDefaults ChannelST           `json:"channel_defaults,omitempty" groups:"api,config"`
	// contains filtered or unexported fields
}

StorageST main storage struct

func NewStreamCore

func NewStreamCore() *StorageST

NewStreamCore do load config file

func (*StorageST) ClientAdd

func (obj *StorageST) ClientAdd(streamID string, channelID string, mode int) (string, chan *av.Packet, chan *[]byte, error)

ClientAdd Add New Client to Translations

func (*StorageST) ClientDelete

func (obj *StorageST) ClientDelete(streamID string, cid string, channelID string)

ClientDelete Delete Client

func (*StorageST) ClientHas

func (obj *StorageST) ClientHas(streamID string, channelID string) bool

ClientHas check is client ext

func (*StorageST) HLSMuxerClose

func (obj *StorageST) HLSMuxerClose(uuid string, channelID string)

HLSMuxerClose close muxer

func (*StorageST) HLSMuxerFragment

func (obj *StorageST) HLSMuxerFragment(uuid string, channelID string, segment, fragment int) ([]*av.Packet, error)

HLSMuxerFragment get fragment

func (*StorageST) HLSMuxerM3U8

func (obj *StorageST) HLSMuxerM3U8(uuid string, channelID string, msn, part int) (string, error)

HLSMuxerM3U8 get m3u8 list

func (*StorageST) HLSMuxerSegment

func (obj *StorageST) HLSMuxerSegment(uuid string, channelID string, segment int) ([]*av.Packet, error)

HLSMuxerSegment get segment

func (*StorageST) HlsMuxerSetFPS

func (obj *StorageST) HlsMuxerSetFPS(uuid string, channelID string, fps int)

HlsMuxerSetFPS write packet

func (*StorageST) HlsMuxerWritePacket

func (obj *StorageST) HlsMuxerWritePacket(uuid string, channelID string, packet *av.Packet)

HlsMuxerWritePacket write packet

func (*StorageST) MarshalledStreamsList

func (obj *StorageST) MarshalledStreamsList() (interface{}, error)

MarshalledStreamsList lists all streams and includes only fields which are safe to serialize.

func (*StorageST) NewHLSMuxer

func (obj *StorageST) NewHLSMuxer(uuid string, channelID string)

NewHLSMuxer new muxer init

func (*StorageST) SaveConfig

func (obj *StorageST) SaveConfig() error

SaveConfig ...

func (*StorageST) ServerHTTPDebug

func (obj *StorageST) ServerHTTPDebug() bool

ServerHTTPDebug read debug options

func (*StorageST) ServerHTTPDemo

func (obj *StorageST) ServerHTTPDemo() bool

ServerHTTPDemo read demo options

func (*StorageST) ServerHTTPDir

func (obj *StorageST) ServerHTTPDir() string

ServerHTTPDir

func (*StorageST) ServerHTTPLogin

func (obj *StorageST) ServerHTTPLogin() string

ServerHTTPLogin read Login options

func (*StorageST) ServerHTTPPassword

func (obj *StorageST) ServerHTTPPassword() string

ServerHTTPPassword read Password options

func (*StorageST) ServerHTTPPort

func (obj *StorageST) ServerHTTPPort() string

ServerHTTPPort read HTTP Port options

func (*StorageST) ServerHTTPS

func (obj *StorageST) ServerHTTPS() bool

ServerHTTPS read HTTPS Port options

func (*StorageST) ServerHTTPSAutoTLSEnable

func (obj *StorageST) ServerHTTPSAutoTLSEnable() bool

ServerHTTPSAutoTLSEnable read HTTPS Port options

func (*StorageST) ServerHTTPSAutoTLSName

func (obj *StorageST) ServerHTTPSAutoTLSName() string

ServerHTTPSAutoTLSName read HTTPS Port options

func (*StorageST) ServerHTTPSCert

func (obj *StorageST) ServerHTTPSCert() string

ServerHTTPSCert read HTTPS Cert options

func (*StorageST) ServerHTTPSKey

func (obj *StorageST) ServerHTTPSKey() string

ServerHTTPSKey read HTTPS Key options

func (*StorageST) ServerHTTPSPort

func (obj *StorageST) ServerHTTPSPort() string

ServerHTTPSPort read HTTPS Port options

func (*StorageST) ServerICECredential

func (obj *StorageST) ServerICECredential() string

ServerICEServers read ICE credential

func (*StorageST) ServerICEServers

func (obj *StorageST) ServerICEServers() []string

ServerICEServers read ICE servers

func (*StorageST) ServerICEUsername

func (obj *StorageST) ServerICEUsername() string

ServerICEServers read ICE username

func (*StorageST) ServerRTSPPort

func (obj *StorageST) ServerRTSPPort() string

ServerRTSPPort read HTTP Port options

func (*StorageST) ServerTokenBackend

func (obj *StorageST) ServerTokenBackend() string

ServerTokenBackend read HTTPS Key options

func (*StorageST) ServerTokenEnable

func (obj *StorageST) ServerTokenEnable() bool

ServerTokenEnable read HTTPS Key options

func (*StorageST) ServerWebRTCPortMax

func (obj *StorageST) ServerWebRTCPortMax() uint16

ServerWebRTCPortMax read WebRTC Port Max

func (*StorageST) ServerWebRTCPortMin

func (obj *StorageST) ServerWebRTCPortMin() uint16

ServerWebRTCPortMin read WebRTC Port Min

func (*StorageST) StopAll

func (obj *StorageST) StopAll()

StreamReload reload stream

func (*StorageST) StreamAdd

func (obj *StorageST) StreamAdd(uuid string, val StreamST) error

StreamAdd add stream

func (*StorageST) StreamChannelAdd

func (obj *StorageST) StreamChannelAdd(uuid string, channelID string, val ChannelST) error

StreamChannelAdd add stream

func (*StorageST) StreamChannelCast

func (obj *StorageST) StreamChannelCast(key string, channelID string, val *av.Packet)

StreamChannelCast broadcast stream

func (*StorageST) StreamChannelCastProxy

func (obj *StorageST) StreamChannelCastProxy(key string, channelID string, val *[]byte)

StreamChannelCastProxy broadcast stream

func (*StorageST) StreamChannelCodecs

func (obj *StorageST) StreamChannelCodecs(streamID string, channelID string) ([]av.CodecData, error)

StreamChannelCodecs get stream codec storage or wait

func (*StorageST) StreamChannelCodecsUpdate

func (obj *StorageST) StreamChannelCodecsUpdate(streamID string, channelID string, val []av.CodecData, sdp []byte)

StreamChannelCodecsUpdate update stream codec storage

func (*StorageST) StreamChannelControl

func (obj *StorageST) StreamChannelControl(key string, channelID string) (*ChannelST, error)

StreamChannelControl get stream

func (*StorageST) StreamChannelDelete

func (obj *StorageST) StreamChannelDelete(uuid string, channelID string) error

StreamChannelDelete stream

func (*StorageST) StreamChannelEdit

func (obj *StorageST) StreamChannelEdit(uuid string, channelID string, val ChannelST) error

StreamEdit edit stream

func (*StorageST) StreamChannelExist

func (obj *StorageST) StreamChannelExist(streamID string, channelID string) bool

StreamChannelExist check stream exist

func (*StorageST) StreamChannelInfo

func (obj *StorageST) StreamChannelInfo(uuid string, channelID string) (*ChannelST, error)

StreamInfo return stream info

func (*StorageST) StreamChannelMake

func (obj *StorageST) StreamChannelMake(val ChannelST) ChannelST

StreamChannelMake check stream exist

func (*StorageST) StreamChannelReload

func (obj *StorageST) StreamChannelReload(uuid string, channelID string) error

StreamChannelReload reload stream

func (*StorageST) StreamChannelRun

func (obj *StorageST) StreamChannelRun(streamID string, channelID string)

StreamChannelRun one stream and lock

func (*StorageST) StreamChannelRunAll

func (obj *StorageST) StreamChannelRunAll()

StreamChannelRunAll run all stream go

func (*StorageST) StreamChannelSDP

func (obj *StorageST) StreamChannelSDP(streamID string, channelID string) ([]byte, error)

StreamChannelSDP codec storage or wait

func (*StorageST) StreamChannelStatus

func (obj *StorageST) StreamChannelStatus(key string, channelID string, val int)

StreamChannelStatus change stream status

func (*StorageST) StreamChannelUnlock

func (obj *StorageST) StreamChannelUnlock(streamID string, channelID string)

StreamChannelUnlock unlock status to no lock

func (*StorageST) StreamDelete

func (obj *StorageST) StreamDelete(uuid string) error

StreamDelete stream

func (*StorageST) StreamEdit

func (obj *StorageST) StreamEdit(uuid string, val StreamST) error

StreamEdit edit stream

func (*StorageST) StreamHLSAdd

func (obj *StorageST) StreamHLSAdd(uuid string, channelID string, val []*av.Packet, dur time.Duration)

StreamHLSAdd add hls seq to buffer

func (*StorageST) StreamHLSFlush

func (obj *StorageST) StreamHLSFlush(uuid string, channelID string)

StreamHLSFlush delete hls cache

func (*StorageST) StreamHLSTS

func (obj *StorageST) StreamHLSTS(uuid string, channelID string, seq int) ([]*av.Packet, error)

StreamHLSTS send hls segment buffer to clients

func (*StorageST) StreamHLSm3u8

func (obj *StorageST) StreamHLSm3u8(uuid string, channelID string) (string, int, error)

StreamHLSm3u8 get hls m3u8 list

func (*StorageST) StreamInfo

func (obj *StorageST) StreamInfo(uuid string) (*StreamST, error)

StreamInfo return stream info

func (*StorageST) StreamReload

func (obj *StorageST) StreamReload(uuid string) error

StreamReload reload stream

type StreamST

type StreamST struct {
	Name     string               `json:"name,omitempty" groups:"api,config"`
	Channels map[string]ChannelST `json:"channels,omitempty" groups:"api,config"`
}

ServerST stream storage section

type Token

type Token struct {
	Enable  bool   `json:"enable" groups:"api,config"`
	Backend string `json:"backend" groups:"api,config"`
}

Token auth

Jump to

Keyboard shortcuts

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