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
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2021-11-17 18:46:10 +03:00
|
|
|
registry.MustRegister(decode.Format{
|
2020-06-08 03:29:51 +03:00
|
|
|
Name: format.AVC_PPS,
|
|
|
|
Description: "H.264/AVC Picture Parameter Set",
|
|
|
|
DecodeFn: avcPPSDecode,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func moreRBSPData(d *decode.D) bool {
|
|
|
|
l := d.BitsLeft()
|
2022-05-04 13:24:52 +03:00
|
|
|
return l >= 8 && d.PeekBits(8) != 0b1000_0000
|
2020-06-08 03:29:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func avcPPSDecode(d *decode.D, in interface{}) interface{} {
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldUFn("pic_parameter_set_id", uEV)
|
|
|
|
d.FieldUFn("seq_parameter_set_id", uEV)
|
2020-06-08 03:29:51 +03:00
|
|
|
d.FieldBool("entropy_coding_mode_flag")
|
|
|
|
d.FieldBool("bottom_field_pic_order_in_frame_present_flag")
|
2021-12-02 00:48:25 +03:00
|
|
|
numSliceGroups := d.FieldUFn("num_slice_groups", uEV, scalar.UAdd(1))
|
2021-11-28 18:59:45 +03:00
|
|
|
if numSliceGroups > 1 {
|
2021-11-05 17:04:26 +03:00
|
|
|
sliceGroupMapType := d.FieldUFn("slice_group_map_type", uEV)
|
2020-06-08 03:29:51 +03:00
|
|
|
switch sliceGroupMapType {
|
|
|
|
case 0:
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldArray("slice_groups", func(d *decode.D) {
|
2021-11-28 18:59:45 +03:00
|
|
|
for i := uint64(0); i < numSliceGroups; i++ {
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldUFn("slice_group", uEV)
|
2020-06-08 03:29:51 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
case 2:
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldArray("slice_groups", func(d *decode.D) {
|
2021-11-28 18:59:45 +03:00
|
|
|
for i := uint64(0); i < numSliceGroups; i++ {
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldStruct("slice_group", func(d *decode.D) {
|
|
|
|
d.FieldUFn("top_left", uEV)
|
|
|
|
d.FieldUFn("bottom_right", uEV)
|
2020-06-08 03:29:51 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
case 3, 4, 5:
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldArray("slice_groups", func(d *decode.D) {
|
2021-11-28 18:59:45 +03:00
|
|
|
for i := uint64(0); i < numSliceGroups; i++ {
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldStruct("slice_group", func(d *decode.D) {
|
2020-06-08 03:29:51 +03:00
|
|
|
d.FieldBool("change_direction_flag")
|
2021-12-02 00:48:25 +03:00
|
|
|
d.FieldUFn("change_rate", uEV, scalar.UAdd(1))
|
2020-06-08 03:29:51 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
case 6:
|
2021-12-02 00:48:25 +03:00
|
|
|
picSizeInMapUnits := d.FieldUFn("pic_size_in_map_units", uEV, scalar.UAdd(1))
|
2021-11-28 18:59:45 +03:00
|
|
|
for i := uint64(0); i < picSizeInMapUnits; i++ {
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldStruct("slice_group", func(d *decode.D) {
|
2020-06-08 03:29:51 +03:00
|
|
|
d.FieldBool("id")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-02 00:48:25 +03:00
|
|
|
d.FieldUFn("num_ref_idx_l0_default_active", uEV, scalar.UAdd(1))
|
|
|
|
d.FieldUFn("num_ref_idx_l1_default_active", uEV, scalar.UAdd(1))
|
2020-06-08 03:29:51 +03:00
|
|
|
d.FieldBool("weighted_pred_flag")
|
|
|
|
d.FieldU2("weighted_bipred_idc")
|
2021-12-02 00:48:25 +03:00
|
|
|
d.FieldSFn("pic_init_qp", sEV, scalar.SAdd(26))
|
|
|
|
d.FieldSFn("pic_init_qs", sEV, scalar.SAdd(26))
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldSFn("chroma_qp_index_offset", sEV)
|
2020-06-08 03:29:51 +03:00
|
|
|
d.FieldBool("deblocking_filter_control_present_flag")
|
|
|
|
d.FieldBool("constrained_intra_pred_flag")
|
|
|
|
d.FieldBool("redundant_pic_cnt_present_flag")
|
|
|
|
|
|
|
|
if moreRBSPData(d) {
|
|
|
|
d.FieldBool("transform_8x8_mode_flag")
|
|
|
|
picScalingMatrixPresentFlag := d.FieldBool("pic_scaling_matrix_present_flag")
|
|
|
|
if picScalingMatrixPresentFlag {
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldArray("pic_scaling_list", func(d *decode.D) {
|
2020-06-08 03:29:51 +03:00
|
|
|
for i := 0; i < 6; i++ {
|
|
|
|
d.Bool()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldSFn("second_chroma_qp_index_offset", sEV)
|
2022-05-04 13:24:52 +03:00
|
|
|
} else {
|
|
|
|
d.FieldBool("rbsp_stop_one_bit")
|
2020-06-08 03:29:51 +03:00
|
|
|
}
|
|
|
|
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldRawLen("rbsp_trailing_bits", d.BitsLeft())
|
2020-06-08 03:29:51 +03:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|