1
1
mirror of https://github.com/wader/fq.git synced 2024-11-23 18:56:52 +03:00
fq/format/vpx/vp9_cfm.go
Mattias Wadman 2fc0a71a47 decode: Refactor scalar usage
Move scalar into own package.
Split scalar code into decode related scalar code (that reads etc) and
scalar code that just transform the scalar value.
Use a scalar.Mapper interface instead of just a function.
Make mappers, assert and validat impement the interface.
2021-12-02 17:39:26 +01:00

45 lines
1.0 KiB
Go

package vpx
// https://www.webmproject.org/docs/container/#vp9-codec-feature-metadata-codecprivate
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
)
func init() {
registry.MustRegister(decode.Format{
Name: format.VP9_CFM,
Description: "VP9 Codec Feature Metadata",
DecodeFn: vp9CFMDecode,
RootArray: true,
RootName: "features",
})
}
func vp9CFMDecode(d *decode.D, in interface{}) interface{} {
for d.NotEnd() {
d.FieldStruct("feature", func(d *decode.D) {
id := d.FieldU8("id", vp9FeatureIDNames)
l := d.FieldU8("length")
d.LenFn(int64(l)*8, func(d *decode.D) {
switch id {
case vp9FeatureProfile:
d.FieldU8("profile")
case vp9FeatureLevel:
d.FieldU8("level", vpxLevelNames)
case vp9FeatureBitDepth:
d.FieldU8("bit_depth")
case vp9FeatureChromaSubsampling:
d.FieldU8("chroma_subsampling", vpxChromeSubsamplingNames)
default:
d.FieldRawLen("data", d.BitsLeft())
}
})
})
}
return nil
}