utils

package
v0.0.0-...-3d255a5 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2025 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SmallHeaderSize = 8
	LargeHeaderSize = 16
	LengthUnlimited = math.MaxUint32
)

Variables

View Source
var DcList = DCOptions{
	DCS: map[int][]DC{
		1: {{"149.154.175.58:443", false}},
		2: {{"149.154.167.50:443", false}},
		3: {{"149.154.175.100:443", false}},
		4: {{"149.154.167.91:443", false},
			{"[2001:067c:04e8:f002::a]:443", true}},
		5: {{"91.108.56.151:443", false}},
	},
	TestDCs: map[int]string{
		1: "149.154.175.10:443",
		2: "149.154.167.40:443",
		3: "149.154.175.117:443",
	},
	CdnDCs: map[int][]DC{
		201: {{"91.108.23.100:443", false}},
		203: {{"91.105.192.100:443", false},
			{"[2a0a:f280:0203:000a:5000:0000:0000:0100]:443", true}},
	},
}
View Source
var ErrUnsupportedBoxVersion = errors.New("unsupported box version")

Functions

func AddBoxDef

func AddBoxDef(payload IBox, versions ...uint8)

func AskForConfirmation

func AskForConfirmation() bool

func AuthKeyHash

func AuthKeyHash(key []byte) []byte

func CloseChannelWithoutPanic

func CloseChannelWithoutPanic(c chan tl.Object)

func FmtIp

func FmtIp(ipv6WithPort string) string

func FullStack

func FullStack()

func GenerateSessionID

func GenerateSessionID() int64

func GetDefaultHostIp

func GetDefaultHostIp(dc int, test bool, ipv6 bool) string

func NewMsgIDGenerator

func NewMsgIDGenerator() func(timeOffset int64) int64

func ParseDuration

func ParseDuration(file string) (int64, error)

func RandomBytes

func RandomBytes(size int) []byte

func ReadBoxStructure

func ReadBoxStructure(r io.ReadSeeker, handler ReadHandler, params ...any) ([]any, error)

func ReadBoxStructureFromInternal

func ReadBoxStructureFromInternal(r io.ReadSeeker, bi *BoxInfo, handler ReadHandler, params ...any) (any, error)

func Sha1

func Sha1(input string) []byte

func Sha1Byte

func Sha1Byte(input []byte) []byte

func Unmarshal

func Unmarshal(r io.ReadSeeker, payloadSize uint64, dst IBox, ctx Context) (n uint64, err error)

func Vtcp

func Vtcp(isV6 bool) string

func Xor

func Xor(dst, src []byte)

Types

type BaseCustomFieldObject

type BaseCustomFieldObject struct{}

func (*BaseCustomFieldObject) BeforeUnmarshal

func (*BaseCustomFieldObject) GetFieldLength

func (box *BaseCustomFieldObject) GetFieldLength(string, Context) uint

func (*BaseCustomFieldObject) GetFieldSize

func (box *BaseCustomFieldObject) GetFieldSize(string, Context) uint

func (*BaseCustomFieldObject) IsOptFieldEnabled

func (box *BaseCustomFieldObject) IsOptFieldEnabled(string, Context) bool

func (*BaseCustomFieldObject) OnReadField

type Box

type Box struct {
	BaseCustomFieldObject
}

func (*Box) AddFlag

func (box *Box) AddFlag(_ uint32)

AddFlag adds the flag

func (*Box) CheckFlag

func (box *Box) CheckFlag(_ uint32) bool

CheckFlag checks the flag status

func (*Box) GetFlags

func (box *Box) GetFlags() uint32

GetFlags returns the flags

func (*Box) GetVersion

func (box *Box) GetVersion() uint8

GetVersion returns the box version

func (*Box) RemoveFlag

func (box *Box) RemoveFlag(_ uint32)

RemoveFlag removes the flag

func (*Box) SetFlags

func (box *Box) SetFlags(uint32)

SetFlags sets the flags

func (*Box) SetVersion

func (box *Box) SetVersion(uint8)

SetVersion sets the box version

type BoxInfo

type BoxInfo struct {
	Offset      uint64
	Size        uint64
	HeaderSize  uint64
	Type        BoxType
	ExtendToEOF bool
	Context
}

BoxInfo has common infomations of box

func ExtractBoxes

func ExtractBoxes(r io.ReadSeeker, parent *BoxInfo, paths []BoxPath) ([]*BoxInfo, error)

func ReadBoxInfo

func ReadBoxInfo(r io.ReadSeeker) (*BoxInfo, error)

func (*BoxInfo) SeekToEnd

func (bi *BoxInfo) SeekToEnd(s io.Seeker) (int64, error)

func (*BoxInfo) SeekToPayload

func (bi *BoxInfo) SeekToPayload(s io.Seeker) (int64, error)

func (*BoxInfo) SeekToStart

func (bi *BoxInfo) SeekToStart(s io.Seeker) (int64, error)

type BoxPath

type BoxPath []BoxType

type BoxType

type BoxType [4]byte

func BoxTypeAny

func BoxTypeAny() BoxType

func BoxTypeMeta

func BoxTypeMeta() BoxType

func BoxTypeMoov

func BoxTypeMoov() BoxType

func BoxTypeMvhd

func BoxTypeMvhd() BoxType

func StrToBoxType

func StrToBoxType(code string) BoxType

func (BoxType) IsSupportedVersion

func (boxType BoxType) IsSupportedVersion(ver uint8, ctx Context) bool

func (BoxType) MatchWith

func (lhs BoxType) MatchWith(rhs BoxType) bool

func (BoxType) New

func (boxType BoxType) New(ctx Context) (IBox, error)

func (BoxType) String

func (boxType BoxType) String() string

type CompatibleBrandElem

type CompatibleBrandElem struct {
	CompatibleBrand [4]byte `mp4:"0,size=8,string"`
}

type Context

type Context struct {
	IsQuickTimeCompatible bool
	UnderWave             bool
	UnderIlst             bool
	UnderIlstMeta         bool
	UnderIlstFreeMeta     bool
	UnderUdta             bool
}

type DC

type DC struct {
	Addr string
	V    bool
}

type DCOptions

type DCOptions struct {
	DCS     map[int][]DC
	TestDCs map[int]string
	CdnDCs  map[int][]DC
}

func NewDCOptions

func NewDCOptions() *DCOptions

func (*DCOptions) GetCdnAddr

func (opt *DCOptions) GetCdnAddr(dc int) (string, bool)

func (*DCOptions) GetHostIp

func (opt *DCOptions) GetHostIp(dc int, test bool, ipv6 bool) string

func (*DCOptions) SearchAddr

func (opt *DCOptions) SearchAddr(addr string) int

func (*DCOptions) SetDCs

func (opt *DCOptions) SetDCs(dcs map[int][]DC, cdnDcs map[int][]DC)

type Ftyp

type Ftyp struct {
	Box
	MajorBrand       [4]byte               `mp4:"0,size=8,string"`
	MinorVersion     uint32                `mp4:"1,size=32"`
	CompatibleBrands []CompatibleBrandElem `mp4:"2,size=32"` // reach to end of the box
}

func (*Ftyp) HasCompatibleBrand

func (ftyp *Ftyp) HasCompatibleBrand(cb [4]byte) bool

type FullBox

type FullBox struct {
	BaseCustomFieldObject
	Version uint8   `mp4:"0,size=8"`
	Flags   [3]byte `mp4:"1,size=8"`
}

func (*FullBox) AddFlag

func (box *FullBox) AddFlag(flag uint32)

AddFlag adds the flag

func (*FullBox) CheckFlag

func (box *FullBox) CheckFlag(flag uint32) bool

CheckFlag checks the flag status

func (*FullBox) GetFlags

func (box *FullBox) GetFlags() uint32

GetFlags returns the flags

func (*FullBox) GetVersion

func (box *FullBox) GetVersion() uint8

GetVersion returns the box version

func (*FullBox) RemoveFlag

func (box *FullBox) RemoveFlag(flag uint32)

RemoveFlag removes the flag

func (*FullBox) SetFlags

func (box *FullBox) SetFlags(flags uint32)

SetFlags sets the flags

func (*FullBox) SetVersion

func (box *FullBox) SetVersion(version uint8)

SetVersion sets the box version

type IAnyType

type IAnyType interface {
	IBox
	SetType(BoxType)
}

type IBox

type IBox interface {
	IImmutableBox
	SetVersion(uint8)
	SetFlags(uint32)
	AddFlag(uint32)
	RemoveFlag(uint32)
}

IBox is common interface of box

func UnmarshalAny

func UnmarshalAny(r io.ReadSeeker, boxType BoxType, payloadSize uint64, ctx Context) (box IBox, n uint64, err error)

type ICustomFieldObject

type ICustomFieldObject interface {
	GetFieldSize(name string, ctx Context) uint
	GetFieldLength(name string, ctx Context) uint
	IsOptFieldEnabled(name string, ctx Context) bool
	BeforeUnmarshal(r io.ReadSeeker, size uint64, ctx Context) (n uint64, override bool, err error)
	OnReadField(name string, r ReadSeeker, leftBits uint64, ctx Context) (rbits uint64, override bool, err error)
}

type IImmutableBox

type IImmutableBox interface {
	ICustomFieldObject
	GetVersion() uint8
	GetFlags() uint32
	CheckFlag(uint32) bool
	GetType() BoxType
}

type LogLevel

type LogLevel int
const (
	// DebugLevel is the lowest level of logging
	DebugLevel LogLevel = iota + 1
	// InfoLevel is the second lowest level of logging (default)
	InfoLevel
	// WarnLevel is the third highest level of logging
	WarnLevel
	// ErrorLevel is the highest level of logging
	ErrorLevel
	// NoLevel disables all logging
	NoLevel
	// TraceLevel is the highest level of logging
	TraceLevel
)

type Logger

type Logger struct {
	Level  LogLevel
	Prefix string
	// contains filtered or unexported fields
}

Logger is the logging struct.

func NewLogger

func NewLogger(prefix string) *Logger

NewLogger returns a new Logger instance.

func (*Logger) Color

func (l *Logger) Color() bool

Color enables colorized output. (default)

func (*Logger) Debug

func (l *Logger) Debug(v ...any)

func (*Logger) Error

func (l *Logger) Error(v ...any)

Log logs a message at the given level.

func (*Logger) Info

func (l *Logger) Info(v ...any)

func (*Logger) Lev

func (l *Logger) Lev() LogLevel

func (*Logger) NoColor

func (l *Logger) NoColor(nocolor ...bool) *Logger

NoColor disables colorized output.

func (*Logger) Panic

func (l *Logger) Panic(v ...any)

func (*Logger) SetLevel

func (l *Logger) SetLevel(level LogLevel) *Logger

SetLevelString sets the level string

func (*Logger) SetPrefix

func (l *Logger) SetPrefix(prefix string) *Logger

func (*Logger) Trace

func (l *Logger) Trace(v ...any)

func (*Logger) Warn

func (l *Logger) Warn(v ...any)

type Meta

type Meta struct {
	FullBox `mp4:"0,extend"`
}

func (*Meta) BeforeUnmarshal

func (meta *Meta) BeforeUnmarshal(r io.ReadSeeker, _ uint64, _ Context) (n uint64, override bool, err error)

func (*Meta) GetType

func (*Meta) GetType() BoxType

GetType returns the BoxType

type Moov

type Moov struct {
	Box
}

func (*Moov) GetType

func (*Moov) GetType() BoxType

GetType returns the BoxType

type Mvhd

type Mvhd struct {
	FullBox            `mp4:"0,extend"`
	CreationTimeV0     uint32    `mp4:"1,size=32,ver=0"`
	ModificationTimeV0 uint32    `mp4:"2,size=32,ver=0"`
	CreationTimeV1     uint64    `mp4:"3,size=64,ver=1"`
	ModificationTimeV1 uint64    `mp4:"4,size=64,ver=1"`
	Timescale          uint32    `mp4:"5,size=32"`
	DurationV0         uint32    `mp4:"6,size=32,ver=0"`
	DurationV1         uint64    `mp4:"7,size=64,ver=1"`
	Rate               int32     `mp4:"8,size=32"`
	Volume             int16     `mp4:"9,size=16"`
	Reserved           int16     `mp4:"10,size=16,const=0"`
	Reserved2          [2]uint32 `mp4:"11,size=32,const=0"`
	Matrix             [9]int32  `mp4:"12,size=32,hex"`
	PreDefined         [6]int32  `mp4:"13,size=32"`
	NextTrackID        uint32    `mp4:"14,size=32"`
}

Mvhd is ISOBMFF mvhd box type

func (*Mvhd) AddFlag

func (*Mvhd) AddFlag(_ uint32)

func (*Mvhd) GetCreationTime

func (mvhd *Mvhd) GetCreationTime() uint64

func (*Mvhd) GetDuration

func (mvhd *Mvhd) GetDuration() uint64

func (*Mvhd) GetModificationTime

func (mvhd *Mvhd) GetModificationTime() uint64

func (*Mvhd) GetRate

func (mvhd *Mvhd) GetRate() float64

GetRate returns value of rate as float64

func (*Mvhd) GetRateInt

func (mvhd *Mvhd) GetRateInt() int16

GetRateInt returns value of rate as int16

func (*Mvhd) GetType

func (*Mvhd) GetType() BoxType

GetType returns the BoxType

type PingParams

type PingParams struct {
	PingID int64
}

func (*PingParams) CRC

func (*PingParams) CRC() uint32

type ProbeInfo

type ProbeInfo struct {
	FastStart bool
	Timescale uint32
	Duration  uint64
}

type ReadHandle

type ReadHandle struct {
	Params      []any
	BoxInfo     BoxInfo
	Path        BoxPath
	ReadPayload func() (box IBox, n uint64, err error)
	ReadData    func(io.Writer) (n uint64, err error)
	Expand      func(params ...any) (vals []any, err error)
}

type ReadHandler

type ReadHandler func(handle *ReadHandle) (val any, err error)

type ReadSeeker

type ReadSeeker interface {
	Reader
	io.Seeker
}

func NewReadSeeker

func NewReadSeeker(r io.ReadSeeker) ReadSeeker

type Reader

type Reader interface {
	io.Reader

	// alignment:
	//  |-1-byte-block-|--------------|--------------|--------------|
	//  |<-offset->|<-------------------width---------------------->|
	ReadBits(width uint) (data []byte, err error)

	ReadBit() (bit bool, err error)
}

func NewReader

func NewReader(r io.Reader) Reader

type SyncIntObjectChan

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

func NewSyncIntObjectChan

func NewSyncIntObjectChan() *SyncIntObjectChan

func (*SyncIntObjectChan) Add

func (s *SyncIntObjectChan) Add(key int, value chan tl.Object)

func (*SyncIntObjectChan) Close

func (s *SyncIntObjectChan) Close()

func (*SyncIntObjectChan) Delete

func (s *SyncIntObjectChan) Delete(key int) bool

func (*SyncIntObjectChan) Get

func (s *SyncIntObjectChan) Get(key int) (chan tl.Object, bool)

func (*SyncIntObjectChan) Has

func (s *SyncIntObjectChan) Has(key int) bool

func (*SyncIntObjectChan) Keys

func (s *SyncIntObjectChan) Keys() []int

func (*SyncIntObjectChan) Reset

func (s *SyncIntObjectChan) Reset()

type SyncIntReflectTypes

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

func NewSyncIntReflectTypes

func NewSyncIntReflectTypes() *SyncIntReflectTypes

func (*SyncIntReflectTypes) Add

func (s *SyncIntReflectTypes) Add(key int, value []reflect.Type)

func (*SyncIntReflectTypes) Delete

func (s *SyncIntReflectTypes) Delete(key int) bool

func (*SyncIntReflectTypes) Get

func (s *SyncIntReflectTypes) Get(key int) ([]reflect.Type, bool)

func (*SyncIntReflectTypes) Has

func (s *SyncIntReflectTypes) Has(key int) bool

func (*SyncIntReflectTypes) Keys

func (s *SyncIntReflectTypes) Keys() []int

func (*SyncIntReflectTypes) Reset

func (s *SyncIntReflectTypes) Reset()

type SyncSet

type SyncSet[T comparable] struct {
	// contains filtered or unexported fields
}

func NewSyncSet

func NewSyncSet[T comparable]() *SyncSet[T]

func (*SyncSet[T]) Add

func (s *SyncSet[T]) Add(key T) bool

func (*SyncSet[T]) Clear

func (s *SyncSet[T]) Clear()

func (*SyncSet[T]) Clone

func (s *SyncSet[T]) Clone() *SyncSet[T]

func (*SyncSet[T]) Delete

func (s *SyncSet[T]) Delete(key T)

func (*SyncSet[T]) ForEach

func (s *SyncSet[T]) ForEach(fn func(key T) bool)

func (*SyncSet[T]) Has

func (s *SyncSet[T]) Has(key T) bool

func (*SyncSet[T]) Keys

func (s *SyncSet[T]) Keys() []T

func (*SyncSet[T]) Len

func (s *SyncSet[T]) Len() int

func (*SyncSet[T]) Pop

func (s *SyncSet[T]) Pop(key T) bool

type UpdatesGetStateParams

type UpdatesGetStateParams struct{}

Jump to

Keyboard shortcuts

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