From 3151670829f0dfe76a3ab6219056ea160307c964 Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Wed, 1 Mar 2023 15:48:52 +0100 Subject: [PATCH] Add descriptions to functions --- restream/replace/replace.go | 29 +++++++++-------------------- restream/restream.go | 10 ++++++++++ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/restream/replace/replace.go b/restream/replace/replace.go index fa7227f5..9dd534d6 100644 --- a/restream/replace/replace.go +++ b/restream/replace/replace.go @@ -12,24 +12,16 @@ import ( type ReplaceFunc func(params map[string]string, config *app.Config, section string) string type Replacer interface { - // RegisterTemplate registers a template for a specific placeholder. Template - // may contain placeholders as well of the form {name}. They will be replaced - // by the parameters of the placeholder (see Replace). If a parameter is not of - // a template is not present, default values can be provided. - - // RegisterTemplateFunc does the same as RegisterTemplate, but the template - // is returned by the template function. - + // RegisterReplaceFunc registers a function for replacing for a specific placeholder. + // If a parameter is not of a placeholder is not present, default values can be provided. RegisterReplaceFunc(placeholder string, replacer ReplaceFunc, defaults map[string]string) // Replace replaces all occurences of placeholder in str with value. The placeholder is of the // form {placeholder}. It is possible to escape a characters in value with \\ by appending a ^ // and the character to escape to the placeholder name, e.g. {placeholder^:} to escape ":". // A placeholder may also have parameters of the form {placeholder,key1=value1,key2=value2}. - // If the value has placeholders itself (see RegisterTemplate), they will be replaced by - // the value of the corresponding key in the parameters. - // If the value is an empty string, the registered templates will be searched for that - // placeholder. If no template is found, the placeholder will be replaced by the empty string. + // If the value is an empty string, the registered replacer functions will be searched for that + // placeholder. If no function is found, the placeholder will be replaced by the empty string. // A placeholder name may consist on of the letters a-z and ':'. The placeholder may contain // a glob pattern to find the appropriate template. Replace(str, placeholder, value string, vars map[string]string, config *app.Config, section string) string @@ -109,6 +101,11 @@ func (r *replacer) Replace(str, placeholder, value string, vars map[string]strin return str } +// parseParametes parses the parameters of a placeholder. The params string is a comma-separated +// string of key=value pairs. The key and values can be escaped as in net/url.QueryEscape. +// The provided defaults will be used as basis. Any parsed key/value from the params might overwrite +// the default value. Any variables in the values will be replaced by their value from the +// vars parameter. func (r *replacer) parseParametes(params string, vars map[string]string, defaults map[string]string) map[string]string { p := make(map[string]string) @@ -153,11 +150,3 @@ func (r *replacer) parseParametes(params string, vars map[string]string, default return p } - -// compileTemplate fills in the placeholder in the template with the values from the params -// string. The placeholders in the template are delimited by {} and their name may only -// contain the letters a-z. The params string is a comma-separated string of key=value pairs. -// Example: the template is "Hello {who}!", the params string is "who=World". The key is the -// placeholder name and will be replaced with the value. The resulting string is "Hello World!". -// If a placeholder name is not present in the params string, it will not be replaced. The key -// and values can be escaped as in net/url.QueryEscape. diff --git a/restream/restream.go b/restream/restream.go index c3716adc..735e58ea 100644 --- a/restream/restream.go +++ b/restream/restream.go @@ -440,6 +440,7 @@ func (r *restream) AddProcess(config *app.Config) error { return nil } +// createTask creates a new task based on a process config. func (r *restream) createTask(config *app.Config) (*task, error) { id := strings.TrimSpace(config.ID) @@ -520,6 +521,9 @@ func (r *restream) createTask(config *app.Config) (*task, error) { return t, nil } +// onArgs is a callback that gets called by a process before it will be started. +// It evalutes the dynamic placeholders in a process config and returns the +// resulting command line to the process. func (r *restream) onArgs(cfg *app.Config) func([]string) []string { return func(args []string) []string { config := cfg.Clone() @@ -747,6 +751,7 @@ func validateConfig(config *app.Config, fss []rfs.Filesystem, ffmpeg ffmpeg.FFmp return hasFiles, nil } +// validateInputAddress checks whether the given input address is valid and is allowed to be used. func validateInputAddress(address, basedir string, ffmpeg ffmpeg.FFmpeg) (string, error) { if ok := url.HasScheme(address); ok { if err := url.Validate(address); err != nil { @@ -761,6 +766,7 @@ func validateInputAddress(address, basedir string, ffmpeg ffmpeg.FFmpeg) (string return address, nil } +// validateOutputAddress checks whether the given output address is valid and is allowed to be used. func validateOutputAddress(address, basedir string, ffmpeg ffmpeg.FFmpeg) (string, bool, error) { // If the address contains a "|" or it starts with a "[", then assume that it // is an address for the tee muxer. @@ -833,6 +839,7 @@ func validateOutputAddress(address, basedir string, ffmpeg ffmpeg.FFmpeg) (strin return "file:" + address, true, nil } +// resolveAddresses replaces the addresse reference from each input in a config with the actual address. func (r *restream) resolveAddresses(tasks map[string]*task, config *app.Config) error { for i, input := range config.Input { // Resolve any references @@ -849,6 +856,7 @@ func (r *restream) resolveAddresses(tasks map[string]*task, config *app.Config) return nil } +// resolveAddress replaces the address reference with the actual address. func (r *restream) resolveAddress(tasks map[string]*task, id, address string) (string, error) { re := regexp.MustCompile(`^#(.+):output=(.+)`) @@ -1294,6 +1302,7 @@ func (r *restream) GetProcessState(id string) (*app.State, error) { return state, nil } +// convertProgressFromParser converts a ffmpeg/parse.Progress type into a restream/app.Progress type. func convertProgressFromParser(progress *app.Progress, pprogress parse.Progress) { progress.Frame = pprogress.Frame progress.Packet = pprogress.Packet @@ -1510,6 +1519,7 @@ func (r *restream) ProbeWithTimeout(id string, timeout time.Duration) app.Probe return appprobe } +// convertProbeFromProber converts a ffmpeg/probe.Probe type into an restream/app.Probe type. func convertProbeFromProber(appprobe *app.Probe, pprobe probe.Probe) { appprobe.Log = make([]string, len(pprobe.Log)) copy(appprobe.Log, pprobe.Log)