app

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: BSD-3-Clause Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UtcTimingNtpServer    = "1.de.pool.ntp.org"
	UtcTimingSntpServer   = "time.kfki.hu"
	UtcTimingHttpServer   = "http://time.akamai.com/?iso"
	UtcTimingHttpServerMS = "http://time.akamai.com/?isoms"
	UtcTimingHeadAsset    = "/static/time.txt"
)
View Source
const (
	SUBS_STPP_PREFIX    = "timestpp"
	SUBS_WVTT_PREFIX    = "timewvtt"
	SUBS_TIME_INIT      = "init.mp4"
	SUBS_TIME_TIMESCALE = 1000
)
View Source
const (
	MAX_TIME_SHIFT_BUFFER_DEPTH_S = 48 * 3600
)

Variables

View Source
var DefaultConfig = ServerConfig{
	LogFormat:   "consolepretty",
	LogLevel:    "info",
	Port:        8888,
	LiveWindowS: 300,
	TimeoutS:    60,
	MaxRequests: 0,
	VodRoot:     "./vod",

	RepDataRoot:  "+",
	WriteRepData: false,
}
View Source
var (
	ErrAtoInfTimeline = errors.New("infinite availabilityTimeOffset for SegmentTimeline")
)

Functions

func CheckTimeValidity added in v0.5.1

func CheckTimeValidity(availTimeS, nowS, timeShiftBufferDepthS, availabilityTimeOffsetS float64) error

CheckTimeValidity checks if availTimeS is a valid time given current time and parameters. Returns errors if too early, or too late. availabilityTimeOffset < 0 signals always available.

func LiveMPD

func LiveMPD(a *asset, mpdName string, cfg *ResponseConfig, nowMS int) (*m.MPD, error)

LiveMPD generates a dynamic configured MPD for a VoD asset.

func NewIPRequestLimiter

func NewIPRequestLimiter(hdrName string, maxNrRequests int, interval time.Duration) func(next http.Handler) http.Handler

NewIPRequestLimiter returns a middleware that limits the number of requests per IP address per interval

An HTTP response 429 Too Many Requests is generated if there are too many requests A header with the

func NewPrometheusMiddleware

func NewPrometheusMiddleware() func(next http.Handler) http.Handler

NewPrometheusMiddleware returns a new prometheus Middleware handler.

func Ptr

func Ptr[T any](v T) *T

Ptr returns a pointer to a value of any type

Types

type AssetInfo added in v0.7.0

type AssetInfo struct {
	Path      string
	LoopDurMS int
	MPDs      []MPDInfo
}

type AssetsInfo added in v0.7.0

type AssetsInfo struct {
	Host   string
	Assets []*AssetInfo
}

type Config

type Config struct {
	Konf      *koanf.Koanf
	ServerCfg ServerConfig
}

type IPRequestLimiter

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

IPRequestLimiter limits the number of requests per interval

func (*IPRequestLimiter) Inc

func (il *IPRequestLimiter) Inc(now time.Time, key string) (int, bool)

Inc incremets the number of requests and returns number and ok value

type MPDInfo added in v0.7.0

type MPDInfo struct {
	Path string
	Desc string
	Dur  string
}

type RepData

type RepData struct {
	ID             string `json:"id"`
	ContentType    string `json:"contentType"`
	Codecs         string `json:"codecs"`
	MpdTimescale   int    `json:"mpdTimescale"`
	MediaTimescale int    `json:"mediaTimescale"` // Used in the segments
	InitURI        string `json:"initURI"`
	MediaURI       string `json:"mediaURI"`

	DefaultSampleDuration uint32    `json:"defaultSampleDuration"`
	Segments              []Segment `json:"segments"`
	// contains filtered or unexported fields
}

RepData provides information about a representation

func (RepData) SegmentType

func (r RepData) SegmentType() string

SegmentType returns MIME type for MP4 segment.

type ResponseConfig

type ResponseConfig struct {
	URLParts                     []string          `json:"-"`
	URLContentIdx                int               `json:"-"`
	BaseURLs                     []string          `json:"BaseURLs,omitempty"`
	UTCTimingMethods             []UTCTimingMethod `json:"UTCTimingMethods,omitempty"`
	PeriodDurations              []int             `json:"PeriodDurations,omitempty"`
	StartTimeS                   int               `json:"StartTimeS"`
	StopTimeS                    *int              `json:"StopTimeS,omitempty"`
	TimeOffsetS                  *float64          `json:"TimeOffsetS,omitempty"`
	InitSegAvailOffsetS          *int              `json:"InitSegAvailOffsetS,omitempty"`
	TimeShiftBufferDepthS        *int              `json:"TimeShiftBufferDepthS,omitempty"`
	MinimumUpdatePeriodS         *int              `json:"MinimumUpdatePeriodS,omitempty"`
	PeriodsPerHour               *int              `json:"PeriodsPerHour,omitempty"`
	XlinkPeriodsPerHour          *int              `json:"XlinkPeriodsPerHour,omitempty"`
	EtpPeriodsPerHour            *int              `json:"EtpPeriodsPerHour,omitempty"`
	EtpDuration                  *int              `json:"EtpDuration,omitempty"`
	PeriodOffset                 *int              `json:"PeriodOffset,omitempty"`
	SCTE35PerMinute              *int              `json:"SCTE35PerMinute,omitempty"`
	StartNr                      *int              `json:"StartNr,omitempty"`
	SuggestedPresentationDelayS  *int              `json:"SuggestedPresentationDelayS,omitempty"`
	AvailabilityTimeOffsetS      float64           `json:"AvailabilityTimeOffsetS,omitempty"`
	ChunkDurS                    *float64          `json:"ChunkDurS,omitempty"`
	LatencyTargetMS              *int              `json:"LatencyTargetMS,omitempty"`
	AddLocationFlag              bool              `json:"AddLocationFlag,omitempty"`
	Tfdt32Flag                   bool              `json:"Tfdt32Flag,omitempty"`
	ContUpdateFlag               bool              `json:"ContUpdateFlag,omitempty"`
	InsertAdFlag                 bool              `json:"InsertAdFlag,omitempty"`
	ContMultiPeriodFlag          bool              `json:"ContMultiPeriodFlag,omitempty"`
	SegTimelineFlag              bool              `json:"SegTimelineFlag,omitempty"`
	SegTimelineNrFlag            bool              `json:"SegTimelineNrFlag,omitempty"`
	SidxFlag                     bool              `json:"SidxFlag,omitempty"`
	SegTimelineLossFlag          bool              `json:"SegTimelineLossFlag,omitempty"`
	AvailabilityTimeCompleteFlag bool              `json:"AvailabilityTimeCompleteFlag,omitempty"`
	TimeSubsStpp                 []string          `json:"TimeSubsStppLanguages,omitempty"`
	TimeSubsWvtt                 []string          `json:"TimeSubsWvttLanguages,omitempty"`
	TimeSubsDurMS                int               `json:"TimeSubsDurMS,omitempty"`
	TimeSubsRegion               int               `json:"TimeSubsRegion,omitempty"`
	Host                         string            `json:"Host,omitempty"`
}

func NewResponseConfig

func NewResponseConfig() *ResponseConfig

NewResponseConfig returns a new ResponseConfig with default values.

func (*ResponseConfig) SetHost added in v0.6.0

func (c *ResponseConfig) SetHost(cfgValue string, r *http.Request)

SetHost sets scheme://host to non-trivial cfgValue or tries to detect from request.

func (*ResponseConfig) URLContentPart added in v0.6.0

func (c *ResponseConfig) URLContentPart() string

type Segment added in v0.7.0

type Segment struct {
	StartTime uint64 `json:"startTime"`
	EndTime   uint64 `json:"endTime"`
	Nr        uint32 `json:"nr"`
}

type Server

type Server struct {
	Router     *chi.Mux
	LiveRouter *chi.Mux
	VodRouter  *chi.Mux

	Cfg *ServerConfig
	// contains filtered or unexported fields
}

func SetupServer

func SetupServer(ctx context.Context, cfg *ServerConfig) (*Server, error)

SetupServer sets up router, middleware, and server, given koanf configuration.

func (*Server) GetLogger

func (s *Server) GetLogger() *logging.Logger

func (*Server) Routes

func (s *Server) Routes(ctx context.Context) error

Routes defines dispatches for all routes.

type ServerConfig

type ServerConfig struct {
	LogFormat   string `json:"logformat"`
	LogLevel    string `json:"loglevel"`
	Port        int    `json:"port"`
	LiveWindowS int    `json:"livewindowS"`
	TimeoutS    int    `json:"timeoutS"`
	MaxRequests int    `json:"maxrequests"`
	VodRoot     string `json:"vodroot"`
	// RepDataRoot is the root directory for representation metadata
	RepDataRoot string `json:"repdataroot"`
	// WriteRepData is true if representation metadata should be written if not present
	WriteRepData bool `json:"writerepdata"`
	// Domains is a comma-separated list of domains for Let's Encrypt
	Domains string `json:"domains"`
	// CertPath is a path to a valid TLS certificate
	CertPath string `json:"certpath"`
	// KeyPath is a path to a valid private TLS key
	KeyPath string `json:"keypath"`
	// If Host is set, it will be used instead of autodetected value scheme://host.
	Host string `json:"host"`
}

func LoadConfig

func LoadConfig(args []string, cwd string) (*ServerConfig, error)

LoadConfig loads defaults, config file, command line, and finally applies environment variables

VodRoot is set to cwd/root by default.

type StppTimeCue

type StppTimeCue struct {
	Id    string
	Begin string
	End   string
	Msg   string
}

StppTimeCue is cue information to put in template.

type StppTimeData

type StppTimeData struct {
	Lang   string
	Region int
	Cues   []StppTimeCue
}

StppTimeData is information for creating an stpp media segment.

type UTCTimingMethod added in v0.6.0

type UTCTimingMethod string
const (
	UtcTimingDirect     UTCTimingMethod = "direct"
	UtcTimingHead       UTCTimingMethod = "head"
	UtcTimingNtp        UTCTimingMethod = "ntp"
	UtcTimingSntp       UTCTimingMethod = "sntp"
	UtcTimingHttpXSDate UTCTimingMethod = "httpxsdate"
	UtcTimingHttpISO    UTCTimingMethod = "httpiso"
	UtcTimingNone       UTCTimingMethod = "none"
)

type WvttTimeCue added in v0.7.0

type WvttTimeCue struct {
	Id      string
	StartMS int
	EndMS   int
	Vttc    []byte
}

WvttTimeCue is cue information to put in template.

type WvttTimeData added in v0.7.0

type WvttTimeData struct {
	Lang   string
	Region int
	Cues   []WvttTimeCue
}

WvttTimeData is information for creating a wvtt media segment.

Jump to

Keyboard shortcuts

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