utils

package
v0.0.0-...-b9bb5e3 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DebugLevel is the lowest level of logging
	DebugLevel = iota
	// InfoLevel is the second lowest level of logging
	InfoLevel
	// WarnLevel is the third highest level of logging
	WarnLevel
	// ErrorLevel is the highest level of logging
	ErrorLevel
	// NoLevel disables all logging
	NoLevel
)
View Source
const (
	SmallHeaderSize = 8
	LargeHeaderSize = 16
	LengthUnlimited = math.MaxUint32
)

Variables

View Source
var DcList = map[int]string{
	1: "149.154.175.58:443",
	2: "149.154.167.50:443",
	3: "149.154.175.100:443",
	4: "149.154.167.91:443",
	5: "91.108.56.151:443",
}
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 FullStack

func FullStack()

func GenerateMessageId

func GenerateMessageId(prevID int64, offset int64) int64

func GenerateSessionID

func GenerateSessionID() 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 ...interface{}) ([]interface{}, error)

func ReadBoxStructureFromInternal

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

func SetDCs

func SetDCs(dcList map[int]string)

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 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 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 Logger

type Logger struct {
	Level  int
	Prefix string
}

Logger is the logging struct.

func NewLogger

func NewLogger(prefix string) *Logger

NewLogger returns a new Logger instance.

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() string

func (*Logger) Panic

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

func (*Logger) SetLevel

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

SetLevelString sets the level string

func (*Logger) Warn

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

func (*Logger) WinTerminal

func (l *Logger) WinTerminal() bool

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      []interface{}
	BoxInfo     BoxInfo
	Path        BoxPath
	ReadPayload func() (box IBox, n uint64, err error)
	ReadData    func(io.Writer) (n uint64, err error)
	Expand      func(params ...interface{}) (vals []interface{}, err error)
}

type ReadHandler

type ReadHandler func(handle *ReadHandle) (val interface{}, 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 SyncSetInt

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

func NewSyncSetInt

func NewSyncSetInt() *SyncSetInt

func (*SyncSetInt) Add

func (s *SyncSetInt) Add(key int) bool

func (*SyncSetInt) Delete

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

func (*SyncSetInt) Has

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

func (*SyncSetInt) Reset

func (s *SyncSetInt) Reset()

type UpdatesGetStateParams

type UpdatesGetStateParams struct{}

func (*UpdatesGetStateParams) CRC

Jump to

Keyboard shortcuts

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