2020-06-08 03:29:51 +03:00
|
|
|
package mpeg
|
|
|
|
|
|
|
|
import (
|
2021-08-17 13:06:32 +03:00
|
|
|
"github.com/wader/fq/format"
|
|
|
|
"github.com/wader/fq/format/registry"
|
|
|
|
"github.com/wader/fq/pkg/decode"
|
2021-12-02 00:48:25 +03:00
|
|
|
"github.com/wader/fq/pkg/scalar"
|
2020-06-08 03:29:51 +03:00
|
|
|
)
|
|
|
|
|
2021-11-17 18:46:10 +03:00
|
|
|
var hevcDCRNALFormat decode.Group
|
2020-06-08 03:29:51 +03:00
|
|
|
|
|
|
|
func init() {
|
2021-11-17 18:46:10 +03:00
|
|
|
registry.MustRegister(decode.Format{
|
2020-06-08 03:29:51 +03:00
|
|
|
Name: format.HEVC_DCR,
|
|
|
|
Description: "H.265/HEVC Decoder Configuration Record",
|
|
|
|
DecodeFn: hevcDcrDecode,
|
|
|
|
Dependencies: []decode.Dependency{
|
2021-11-17 18:46:10 +03:00
|
|
|
{Names: []string{format.HEVC_NALU}, Group: &hevcDCRNALFormat},
|
2020-06-08 03:29:51 +03:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func hevcDcrDecode(d *decode.D, in interface{}) interface{} {
|
|
|
|
d.FieldU8("configuration_version")
|
|
|
|
d.FieldU2("general_profile_space")
|
|
|
|
d.FieldU1("general_tier_flag")
|
|
|
|
d.FieldU5("general_profile_idc")
|
|
|
|
d.FieldU32("general_profile_compatibility_flags")
|
|
|
|
d.FieldU48("general_constraint_indicator_flags")
|
|
|
|
d.FieldU8("general_level_idc")
|
|
|
|
d.FieldU4("reserved0")
|
|
|
|
d.FieldU12("min_spatial_segmentation_idc")
|
|
|
|
d.FieldU6("reserved1")
|
|
|
|
d.FieldU2("parallelism_type")
|
|
|
|
d.FieldU6("reserved2")
|
|
|
|
d.FieldU2("chroma_format_idc")
|
|
|
|
d.FieldU5("reserved3")
|
2021-12-02 00:48:25 +03:00
|
|
|
d.FieldU3("bit_depth_luma", scalar.UAdd(8))
|
2020-06-08 03:29:51 +03:00
|
|
|
d.FieldU5("reserved4")
|
2021-12-02 00:48:25 +03:00
|
|
|
d.FieldU3("bit_depth_chroma", scalar.UAdd(8))
|
2020-06-08 03:29:51 +03:00
|
|
|
d.FieldU16("avg_frame_rate")
|
|
|
|
d.FieldU2("constant_frame_rate")
|
|
|
|
d.FieldU3("num_temporal_layers")
|
|
|
|
d.FieldU1("temporal_id_nested")
|
2021-12-02 00:48:25 +03:00
|
|
|
lengthSize := d.FieldU2("length_size", scalar.UAdd(1))
|
2020-06-08 03:29:51 +03:00
|
|
|
numArrays := d.FieldU8("num_of_arrays")
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldArray("arrays", func(d *decode.D) {
|
2020-06-08 03:29:51 +03:00
|
|
|
for i := uint64(0); i < numArrays; i++ {
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldStruct("array", func(d *decode.D) {
|
2020-06-08 03:29:51 +03:00
|
|
|
d.FieldU1("array_completeness")
|
|
|
|
d.FieldU1("reserved0")
|
2021-12-02 00:48:25 +03:00
|
|
|
d.FieldU6("nal_unit_type", hevcNALNames)
|
2020-06-08 03:29:51 +03:00
|
|
|
numNals := d.FieldU16("num_nalus")
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldArray("nals", func(d *decode.D) {
|
2020-06-08 03:29:51 +03:00
|
|
|
for i := uint64(0); i < numNals; i++ {
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldStruct("nal", func(d *decode.D) {
|
2020-06-08 03:29:51 +03:00
|
|
|
nalUnitLength := int64(d.FieldU16("nal_unit_length"))
|
2021-09-16 16:29:11 +03:00
|
|
|
d.FieldFormatLen("nal", nalUnitLength*8, hevcDCRNALFormat, nil)
|
2020-06-08 03:29:51 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-11-28 18:59:45 +03:00
|
|
|
return format.HevcDcrOut{LengthSize: lengthSize}
|
2020-06-08 03:29:51 +03:00
|
|
|
}
|