Documentation
¶
Index ¶
- Constants
- Variables
- func CheckTimeValidity(availTimeS, nowS, timeShiftBufferDepthS, availabilityTimeOffsetS float64) error
- func LiveMPD(a *asset, mpdName string, cfg *ResponseConfig, nowMS int) (*m.MPD, error)
- func NewLimiterMiddleware(hdrName string, reqLimiter *IPRequestLimiter) func(next http.Handler) http.Handler
- func NewPrometheusMiddleware() func(next http.Handler) http.Handler
- func Ptr[T any](v T) *T
- type CCPKey
- type Config
- type IPRequestLimiter
- type LaURLRequest
- type LaURLResponse
- type LossItvl
- type LossItvls
- type RepData
- type ResponseConfig
- type SegStatusCodes
- type Segment
- type Server
- type ServerConfig
- type StppTimeCue
- type StppTimeData
- type UTCTimingMethod
- type WvttTimeCue
- type WvttTimeData
Constants ¶
const ( UtcTimingDirectScheme = "urn:mpeg:dash:utc:direct:2014" UtcTimingHeadScheme = "urn:mpeg:dash:utc:head:2014" UtcTimingHttpISOScheme = "urn:mpeg:dash:utc:iso:2014" UtcTimingHttpXSDateScheme = "urn:mpeg:dash:utc:http-xsdate:2014" UtcTimingNtpDateScheme = "urn:mpeg:dash:utc:ntp:2014" UtcTimingSntpDateScheme = "urn:mpeg:dash:utc:sntp:2014" )
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" )
const ( Number segmentTimelineType = "nr" TimelineTime segmentTimelineType = "tlt" TimelineNumber segmentTimelineType = "tlnr" )
const ( SUBS_STPP_PREFIX = "timestpp" SUBS_WVTT_PREFIX = "timewvtt" SUBS_TIME_INIT = "init.mp4" SUBS_TIME_TIMESCALE = 1000 )
const (
MAX_TIME_SHIFT_BUFFER_DEPTH_S = 48 * 3600
)
Variables ¶
var DefaultConfig = ServerConfig{ LogFormat: "text", LogLevel: "INFO", Port: 8888, LiveWindowS: 300, TimeoutS: 60, MaxRequests: 0, ReqLimitInt: defaultReqIntervalS, VodRoot: "./vod", RepDataRoot: "+", WriteRepData: false, PlayURL: defaultPlayURL, }
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 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 ¶
NewPrometheusMiddleware returns a new prometheus Middleware handler.
Types ¶
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.
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 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
CreateAllLossItvls creates loss intervals for multiple BaseURLs
func CreateLossItvls ¶ added in v1.0.0
CreateLossItvls creates a LossItvls from a pattern like u20d10 (20s up, 10 down)
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 ¶
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"` // 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 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.
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 ¶
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" UtcTimingHttpXSDateMs UTCTimingMethod = "httpxsdatems" UtcTimingHttpISO UTCTimingMethod = "httpiso" UtcTimingHttpISOMs UTCTimingMethod = "httpisoms" UtcTimingNone UTCTimingMethod = "none" UtcTimingKeep UTCTimingMethod = "keep" )
type WvttTimeCue ¶ added in v0.7.0
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.
Source Files
¶
- asset.go
- audiosegmentation.go
- config.go
- configurl.go
- content.go
- errors.go
- handler_assets.go
- handler_config.go
- handler_index.go
- handler_laurl.go
- handler_livesim.go
- handler_reqcount.go
- handler_urlgen.go
- handler_vod.go
- ipreqlimit.go
- keys.go
- livempd.go
- livesegment.go
- middleware.go
- prometheus.go
- routes.go
- server.go
- start.go
- strconv.go
- templates.go
- timesubs.go
- timesubs_wvtt.go