From 0240c4c5f790392dd0efbaf998b6d4321c50d36b Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 22 Jul 2019 15:13:18 +0930 Subject: [PATCH] codec/h264/h264dec: wrote DecRefPicMarking type with constructor and gave to SliceHeader type --- codec/h264/h264dec/slice.go | 140 ++++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 63 deletions(-) diff --git a/codec/h264/h264dec/slice.go b/codec/h264/h264dec/slice.go index 5fa12c82..531e4f8e 100644 --- a/codec/h264/h264dec/slice.go +++ b/codec/h264/h264dec/slice.go @@ -254,6 +254,78 @@ func NewPredWeightTable(br *bits.BitReader, h *SliceHeader) (*PredWeightTable, e return p, nil } +// DecRefPicMarking provides elements of a dec_ref_pic_marking syntax structure +// as defined in section 7.3.3.3 of the specifications. +type DecRefPicMarking struct { + NoOutputOfPriorPicsFlag bool + LongTermReferenceFlag bool + AdaptiveRefPicMarkingModeFlag bool + MemoryManagementControlOperation int + DifferenceOfPicNumsMinus1 int + LongTermFrameIdx int + MaxLongTermFrameIdxPlus1 int +} + +// NewDecRefPicMarking parses elements of a dec_ref_pic_marking following the +// syntax structure defined in section 7.3.3.3, and returns as a new +// DecRefPicMarking. +func NewDecRefPicMarking(br *bits.BitReader, idrPic bool, h *SliceHeader) (*DecRefPicMarking, error) { + d := &DecRefPicMarking{} + if idrPic { + b, err := br.ReadBits(1) + if err != nil { + return nil, errors.Wrap(err, "could not read NoOutputOfPriorPicsFlag") + } + d.NoOutputOfPriorPicsFlag = b == 1 + + b, err = br.ReadBits(1) + if err != nil { + return nil, errors.Wrap(err, "could not read LongTermReferenceFlag") + } + d.LongTermReferenceFlag = b == 1 + } else { + b, err := br.ReadBits(1) + if err != nil { + return nil, errors.Wrap(err, "could not read AdaptiveRefPicMarkingModeFlag") + } + d.AdaptiveRefPicMarkingModeFlag = b == 1 + + if d.AdaptiveRefPicMarkingModeFlag { + d.MemoryManagementControlOperation, err = readUe(br) + if err != nil { + return nil, errors.Wrap(err, "could not parse MemoryManagementControlOperation") + } + for d.MemoryManagementControlOperation != 0 { + if d.MemoryManagementControlOperation == 1 || d.MemoryManagementControlOperation == 3 { + d.DifferenceOfPicNumsMinus1, err = readUe(br) + if err != nil { + return nil, errors.Wrap(err, "could not parse MemoryManagementControlOperation") + } + } + if d.MemoryManagementControlOperation == 2 { + h.RefPicListModification.LongTermPicNum, err = readUe(br) + if err != nil { + return nil, errors.Wrap(err, "could not parse LongTermPicNum") + } + } + if d.MemoryManagementControlOperation == 3 || d.MemoryManagementControlOperation == 6 { + d.LongTermFrameIdx, err = readUe(br) + if err != nil { + return nil, errors.Wrap(err, "could not parse LongTermFrameIdx") + } + } + if d.MemoryManagementControlOperation == 4 { + d.MaxLongTermFrameIdxPlus1, err = readUe(br) + if err != nil { + return nil, errors.Wrap(err, "could not parse MaxLongTermFrameIdxPlus1") + } + } + } + } + } + return d, nil +} + type SliceHeader struct { FirstMbInSlice int SliceType int @@ -271,19 +343,9 @@ type SliceHeader struct { NumRefIdxActiveOverride bool NumRefIdxL0ActiveMinus1 int NumRefIdxL1ActiveMinus1 int - *RefPicListModification *PredWeightTable - - // dec_ref_pic_marking - NoOutputOfPriorPicsFlag bool - LongTermReferenceFlag bool - AdaptiveRefPicMarkingModeFlag bool - MemoryManagementControlOperation int - DifferenceOfPicNumsMinus1 int - LongTermFrameIdx int - MaxLongTermFrameIdxPlus1 int - + *DecRefPicMarking CabacInit int SliceQpDelta int SpForSwitch bool @@ -1297,58 +1359,10 @@ func NewSliceContext(videoStream *VideoStream, nalUnit *NalUnit, rbsp []byte, sh } if nalUnit.RefIdc != 0 { // devRefPicMarking() - if idrPic { - b, err := br.ReadBits(1) - if err != nil { - return nil, errors.Wrap(err, "could not read NoOutputOfPriorPicsFlag") - } - header.NoOutputOfPriorPicsFlag = b == 1 - - b, err = br.ReadBits(1) - if err != nil { - return nil, errors.Wrap(err, "could not read LongTermReferenceFlag") - } - header.LongTermReferenceFlag = b == 1 - } else { - b, err := br.ReadBits(1) - if err != nil { - return nil, errors.Wrap(err, "could not read AdaptiveRefPicMarkingModeFlag") - } - header.AdaptiveRefPicMarkingModeFlag = b == 1 - - if header.AdaptiveRefPicMarkingModeFlag { - header.MemoryManagementControlOperation, err = readUe(br) - if err != nil { - return nil, errors.Wrap(err, "could not parse MemoryManagementControlOperation") - } - for header.MemoryManagementControlOperation != 0 { - if header.MemoryManagementControlOperation == 1 || header.MemoryManagementControlOperation == 3 { - header.DifferenceOfPicNumsMinus1, err = readUe(br) - if err != nil { - return nil, errors.Wrap(err, "could not parse MemoryManagementControlOperation") - } - } - if header.MemoryManagementControlOperation == 2 { - header.RefPicListModification.LongTermPicNum, err = readUe(br) - if err != nil { - return nil, errors.Wrap(err, "could not parse LongTermPicNum") - } - } - if header.MemoryManagementControlOperation == 3 || header.MemoryManagementControlOperation == 6 { - header.LongTermFrameIdx, err = readUe(br) - if err != nil { - return nil, errors.Wrap(err, "could not parse LongTermFrameIdx") - } - } - if header.MemoryManagementControlOperation == 4 { - header.MaxLongTermFrameIdxPlus1, err = readUe(br) - if err != nil { - return nil, errors.Wrap(err, "could not parse MaxLongTermFrameIdxPlus1") - } - } - } - } - } // end decRefPicMarking + header.DecRefPicMarking, err = NewDecRefPicMarking(br, idrPic, &header) + if err != nil { + return nil, errors.Wrap(err, "could not parse DecRefPicMarking") + } } if pps.EntropyCodingMode == 1 && sliceType != "I" && sliceType != "SI" { header.CabacInit, err = readUe(br)