codec/h264/h264dec: wrote DecRefPicMarking type with constructor and gave to SliceHeader type

This commit is contained in:
Saxon 2019-07-22 15:13:18 +09:30
parent c193853015
commit 0240c4c5f7
1 changed files with 77 additions and 63 deletions

View File

@ -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)
header.DecRefPicMarking, err = NewDecRefPicMarking(br, idrPic, &header)
if err != nil {
return nil, errors.Wrap(err, "could not read NoOutputOfPriorPicsFlag")
return nil, errors.Wrap(err, "could not parse DecRefPicMarking")
}
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
}
if pps.EntropyCodingMode == 1 && sliceType != "I" && sliceType != "SI" {
header.CabacInit, err = readUe(br)