app

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: BSD-3-Clause Imports: 49 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UtcTimingDirectScheme     = "urn:mpeg:dash:utc:direct:2014"
	UtcTimingHttpHeadScheme   = "urn:mpeg:dash:utc:http-head:2014"
	UtcTimingHttpISOScheme    = "urn:mpeg:dash:utc:http-iso:2014"
	UtcTimingHttpXSDateScheme = "urn:mpeg:dash:utc:http-xsdate:2014"
	UtcTimingNtpDateScheme    = "urn:mpeg:dash:utc:ntp:2014"
	UtcTimingSntpDateScheme   = "urn:mpeg:dash:utc:sntp:2014"
)
View Source
const (
	UtcTimingNtpServer  = "1.de.pool.ntp.org"
	UtcTimingSntpServer = "time.kfki.hu"
	// UtcTimingHttpXSDateServer format is xs:date, which is essentially ISO 8601
	UtcTimingXSDateHttpServer   = "https://time.akamai.com/?iso"
	UtcTimingXSDateHttpServerMS = "https://time.akamai.com/?iso&ms"
	//UtcTimingHttpISOHttpServer format is ISO 8601
	UtcTimingISOHttpServer   = "https://time.akamai.com/?iso"
	UtcTimingISOHttpServerMS = "https://time.akamai.com/?iso&ms"
	UtcTimingHeadAsset       = "/static/time.txt"
)
View Source
const (
	Number         segmentTimelineType = "nr"
	TimelineTime   segmentTimelineType = "tlt"
	TimelineNumber segmentTimelineType = "tlnr"
)
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:   "text",
	LogLevel:    "INFO",
	Port:        8888,
	LiveWindowS: 300,
	TimeoutS:    60,
	MaxRequests: 0,
	ReqLimitInt: defaultReqIntervalS,
	VodRoot:     "./vod",

	RepDataRoot:  "+",
	WriteRepData: false,
	PlayURL:      defaultPlayURL,
}
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 NewLimiterMiddleware added in v0.8.0

func NewLimiterMiddleware(hdrName string, reqLimiter *IPRequestLimiter) func(next http.Handler) http.Handler

NewLimiterMiddleware 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 An HTTP header named hdrName is return the number of requests and the maximum number of requests per interval

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 CCPKey added in v1.2.0

type CCPKey struct {
	// Kty is the key type and should have value oct
	Kty string `json:"kty"`
	// K is the base64-encoded key
	K string `json:"k"`
	// Kid is the base64-encoded key ID
	Kid string `json:"kid"`
}

type Config

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

type IPRequestLimiter

type IPRequestLimiter struct {
	MaxNrRequests int            `json:"maxNrRequests"`
	Interval      time.Duration  `json:"interval"`
	ResetTime     time.Time      `json:"resetTime"`
	Counters      map[string]int `json:"counters"`
	// contains filtered or unexported fields
}

IPRequestLimiter limits the number of requests per interval

func NewIPRequestLimiter

func NewIPRequestLimiter(maxNrRequests int, interval time.Duration, start time.Time, logFile string) *IPRequestLimiter

NewIPRequestLimiter returns a new IPRequestLimiter with maxNrRequests per interval starting now. If logFile is not empty, the IPRequestLimiter is dumped to the logFile at the end of each interval.

func (*IPRequestLimiter) Count added in v0.8.0

func (il *IPRequestLimiter) Count(ip string) int

Count returns the counter value for an IP address

func (*IPRequestLimiter) EndTime added in v0.8.0

func (il *IPRequestLimiter) EndTime() time.Time

EndTime returns next reset time.

func (*IPRequestLimiter) Inc

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

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

type LaURLRequest added in v1.2.0

type LaURLRequest struct {
	// KIDs is a slice of base64-encoded key IDs
	KIDs []string `json:"kids"`
	Type string   `json:"type"`
}

LAURLRequest is the JSON request body for DASH-IF laURL request

type LaURLResponse added in v1.2.0

type LaURLResponse struct {
	Keys []CCPKey `json:"keys"`
	Type string   `json:"type"`
}

type LossItvl added in v1.0.0

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

type LossItvls added in v1.0.0

type LossItvls struct {
	Itvls []LossItvl
}

LossItvls is loss intervals for one BaseURL

func CreateAllLossItvls added in v1.0.0

func CreateAllLossItvls(pattern string) ([]LossItvls, error)

CreateAllLossItvls creates loss intervals for multiple BaseURLs

func CreateLossItvls added in v1.0.0

func CreateLossItvls(pattern string) (LossItvls, error)

CreateLossItvls creates a LossItvls from a pattern like u20d10 (20s up, 10 down)

func (LossItvls) CycleDurS added in v1.0.0

func (l LossItvls) CycleDurS() int

CycleDurS returns complete dur of cycle in seconds

func (LossItvls) StateAt added in v1.0.0

func (l LossItvls) StateAt(nowS int) lossState

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"`
	Segments               []Segment `json:"segments"`
	DefaultSampleDuration  uint32    `json:"defaultSampleDuration"`            // Read from trex or tfhd
	ConstantSampleDuration *uint32   `json:"constantSampleDuration,omitempty"` // Non-zero if all samples have the same duration
	PreEncrypted           bool      `json:"preEncrypted"`
	// 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:"-"`
	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"`
	PatchTTL                     int               `json:"Patch,omitempty"`
	// DashIFECCP is DASH-IF Enhanced Clear Key Content Protection
	DashIFECCP     string           `json:"ECCP,omitempty"`
	SegStatusCodes []SegStatusCodes `json:"SegStatus,omitempty"`
	Traffic        []LossItvls      `json:"Traffic,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 SegStatusCodes added in v1.0.0

type SegStatusCodes struct {
	// Cycle is cycle length in seconds
	Cycle int
	// Rsq is relative sequence number (in cycle)
	Rsq int
	// Code is the HTTP response code
	Code int
	// Reps is a list of applicable representations (empty means all)
	Reps []string
}

SegStatusCodes configures regular extraordinary segment response codes

type Segment added in v0.7.0

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

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) 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"`
	ReqLimitLog string `json:"reqlimitlog"`
	ReqLimitInt int    `json:"reqlimitint"` // in seconds
	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 (will override existing metadata)
	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:"-"`
	// KeyPath is a path to a valid private TLS key
	KeyPath string `json:"-"`
	// If Host is set, it will be used instead of autodetected value scheme://host.
	Host string `json:"host"`
	// PlayURL is a URL template to play asset including player and pattern %s to be replaced by MPD URL
	// For autoplay, start the player muted.
	PlayURL string `json:"playurl"`
}

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"
	UtcTimingHttpHead     UTCTimingMethod = "head"
	UtcTimingNtp          UTCTimingMethod = "ntp"
	UtcTimingSntp         UTCTimingMethod = "sntp"
	UtcTimingHttpXSDate   UTCTimingMethod = "httpxsdate"
	UtcTimingHttpXSDateMs UTCTimingMethod = "httpxsdatems"
	UtcTimingHttpISO      UTCTimingMethod = "httpiso"
	UtcTimingHttpISOMs    UTCTimingMethod = "httpisoms"
	UtcTimingNone         UTCTimingMethod = "none"
	UtcTimingKeep         UTCTimingMethod = "keep"
)

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