Files
go-mxl-pattern-generator/internal/flow-def/flow-def.go
T
Dmitry Sergeev 94ff41a124 Args parse
2026-09-13 13:41:47 +03:00

121 lines
2.7 KiB
Go

// MXL Flow Definition helper
package flowdef
import (
"encoding/json"
"errors"
"os"
)
const (
TYPE_VIDEO = iota
TYPE_VIDEO_ALPHA
TYPE_AUDIO
)
var (
ErrUnknownFlowType = errors.New("Unknown flow type provided")
ErrIncorrectFlowUUID = errors.New("Incorrect flow uuid")
)
type flowDef struct {
Description string `json:"description"`
Id string `json:"id"`
Tags map[string][]string `json:"tags"`
Format string `json:"format"`
Label string `json:"label"`
Parents []string `json:"parents"`
MediaType string `json:"media_type"`
GrainRate grainRate `json:"grain_rate"`
FrameWidth uint `json:"frame_width"`
FrameHeight uint `json:"frame_height"`
InterlaceMode string `json:"interlace_mode"`
ColorSpace string `json:"colorspace"`
Components [3]videoComponent `json:"components"`
}
type grainRate struct {
Numerator uint `json:"numerator"`
Denominator uint `json:"denominator"`
}
type videoComponent struct {
Name string `json:"name"`
Width uint `json:"width"`
Height uint `json:"height"`
BitDepth uint `json:"bit_depth"`
}
func NewFlowDefJSON(
feedType int,
uuid string,
width uint,
height uint,
fpsNum uint,
fpsDen uint,
) (string, error) {
if feedType != TYPE_VIDEO &&
feedType != TYPE_VIDEO_ALPHA &&
feedType != TYPE_AUDIO {
return "", ErrUnknownFlowType
}
if uuid == "" {
return "", ErrIncorrectFlowUUID
}
tags := map[string][]string{
"urn:x-nmos:tag:grouphint/v1.0": {
"___one day I will follow NMOS specs___:Video",
},
}
flowDef := flowDef{
Description: "go-mxl-pattern-gen generated feed",
Id: uuid,
Tags: tags,
Format: "urn:x-nmos:format:video",
Label: "go-mxl-pattern-gen generated feed",
Parents: nil,
MediaType: "video/v210",
GrainRate: grainRate{
Numerator: fpsNum,
Denominator: fpsDen,
},
FrameWidth: width,
FrameHeight: height,
InterlaceMode: "progressive",
ColorSpace: "BT709",
Components: [3]videoComponent{
videoComponent{
Name: "Y",
Width: width,
Height: height,
BitDepth: 10,
},
videoComponent{
Name: "Cb",
Width: width / 2,
Height: height,
BitDepth: 10,
},
videoComponent{
Name: "Cr",
Width: width / 2,
Height: height,
BitDepth: 10,
},
},
}
jsonBytes, err := json.Marshal(flowDef)
if err != nil {
return "", err
}
return string(jsonBytes), nil
}
func ReadFlowDefFile(path string) (string, error) {
data, err := os.ReadFile(path)
if err != nil {
return "", err
}
return string(data), nil
}