audio flowdef
This commit is contained in:
@@ -9,9 +9,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
FormatVideo = "urn:x-nmos:format:video"
|
||||
FormatAudio = "urn:x-nmos:format:audio"
|
||||
MediaTypeV210 = "video/v210"
|
||||
FormatVideo = "urn:x-nmos:format:video"
|
||||
FormatAudio = "urn:x-nmos:format:audio"
|
||||
MediaTypeV210 = "video/v210"
|
||||
MediaTypeFloat32 = "audio/float32"
|
||||
|
||||
InterlaceProgressive = "progressive"
|
||||
ColorSpaceBT709 = "BT709"
|
||||
@@ -32,6 +33,22 @@ type Rational struct {
|
||||
Denominator uint `json:"denominator"`
|
||||
}
|
||||
|
||||
func (r *Rational) UnmarshalJSON(data []byte) error {
|
||||
var value struct {
|
||||
Numerator uint `json:"numerator"`
|
||||
Denominator *uint `json:"denominator"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &value); err != nil {
|
||||
return err
|
||||
}
|
||||
r.Numerator = value.Numerator
|
||||
r.Denominator = 1
|
||||
if value.Denominator != nil {
|
||||
r.Denominator = *value.Denominator
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Video struct {
|
||||
Common
|
||||
|
||||
@@ -141,3 +158,66 @@ func (v Video) Validate() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewFloat32Audio(
|
||||
id string,
|
||||
channels uint,
|
||||
rate Rational,
|
||||
) (Audio, error) {
|
||||
definition := Audio{
|
||||
Common: Common{
|
||||
Description: "go-mxl-pattern-gen generated audio",
|
||||
ID: id,
|
||||
Tags: map[string][]string{
|
||||
"urn:x-nmos:tag:grouphint/v1.0": {
|
||||
"go-mxl-pattern-gen:Audio",
|
||||
},
|
||||
},
|
||||
Format: FormatAudio,
|
||||
Label: "go-mxl-pattern-gen generated audio",
|
||||
Parents: []string{},
|
||||
MediaType: MediaTypeFloat32,
|
||||
},
|
||||
SampleRate: rate,
|
||||
ChannelCount: channels,
|
||||
BitDepth: 32,
|
||||
}
|
||||
if err := definition.Validate(); err != nil {
|
||||
return Audio{}, err
|
||||
}
|
||||
return definition, nil
|
||||
}
|
||||
|
||||
func (a Audio) Validate() error {
|
||||
if err := uuid.Validate(a.ID); err != nil {
|
||||
return fmt.Errorf("invalid id %q: %w", a.ID, err)
|
||||
}
|
||||
if a.Format != FormatAudio {
|
||||
return fmt.Errorf("format must be %q, got %q", FormatAudio, a.Format)
|
||||
}
|
||||
if a.MediaType != MediaTypeFloat32 {
|
||||
return fmt.Errorf("media_type must be %q, got %q", MediaTypeFloat32, a.MediaType)
|
||||
}
|
||||
if a.ChannelCount == 0 {
|
||||
return fmt.Errorf("channel_count must be greater than zero")
|
||||
}
|
||||
if a.SampleRate.Numerator == 0 || a.SampleRate.Denominator == 0 {
|
||||
return fmt.Errorf("sample_rate numerator and denominator must be greater than zero, got %d/%d",
|
||||
a.SampleRate.Numerator, a.SampleRate.Denominator)
|
||||
}
|
||||
if a.BitDepth != 32 {
|
||||
return fmt.Errorf("bit_depth must be 32, got %d", a.BitDepth)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ParseFloat32Audio(data []byte) (Audio, error) {
|
||||
var definition Audio
|
||||
if err := json.Unmarshal(data, &definition); err != nil {
|
||||
return Audio{}, fmt.Errorf("decode audio flow definition: %w", err)
|
||||
}
|
||||
if err := definition.Validate(); err != nil {
|
||||
return Audio{}, fmt.Errorf("invalid audio flow definition: %w", err)
|
||||
}
|
||||
return definition, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user