Move video output validation to protocol (#233)

This commit is contained in:
Benjamin Pracht
2022-10-20 09:24:42 -07:00
committed by GitHub
parent 2a4be29988
commit f69b436be8
2 changed files with 54 additions and 3 deletions

View File

@@ -3,7 +3,18 @@ package ingress
import "errors"
var (
ErrIngressOutOfDate = errors.New("trying to ovewrite an ingress with an older version")
ErrIngressTimedOut = errors.New("ingress timed out")
ErrNoResponse = errors.New("no response from ingress service")
ErrIngressOutOfDate = errors.New("trying to ovewrite an ingress with an older version")
ErrIngressTimedOut = errors.New("ingress timed out")
ErrNoResponse = errors.New("no response from ingress service")
ErrInvalidOutputDimensions = NewInvalidVideoParamsError("invalid output media dimensions")
)
type InvalidVideoParamsError string
func NewInvalidVideoParamsError(s string) InvalidVideoParamsError {
return InvalidVideoParamsError(s)
}
func (s InvalidVideoParamsError) Error() string {
return "invalid video parameters: " + string(s)
}

40
ingress/validation.go Normal file
View File

@@ -0,0 +1,40 @@
package ingress
import (
"github.com/livekit/protocol/livekit"
)
func ValidateVideoOptionsConsistency(options *livekit.IngressVideoOptions) error {
layersByQuality := make(map[livekit.VideoQuality]*livekit.VideoLayer)
for _, layer := range options.Layers {
if layer.Height == 0 || layer.Width == 0 {
return ErrInvalidOutputDimensions
}
if layer.Bitrate == 0 {
return NewInvalidVideoParamsError("invalid bitrate")
}
if _, ok := layersByQuality[layer.Quality]; ok {
return NewInvalidVideoParamsError("more than one layer with the same quality level")
}
layersByQuality[layer.Quality] = layer
}
var oldLayerArea uint32
for q := livekit.VideoQuality_LOW; q <= livekit.VideoQuality_HIGH; q++ {
layer, ok := layersByQuality[q]
if !ok {
continue
}
layerArea := layer.Width * layer.Height
if layerArea <= oldLayerArea {
return NewInvalidVideoParamsError("video layers do not have increasing pixel count with increasing quality")
}
oldLayerArea = layerArea
}
return nil
}