From 24f6b2d12f27d7ee0df2b8577908a05532c49686 Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 19 Jul 2019 18:04:51 +0930 Subject: [PATCH] codec/h264/decode: added MVCExtension type and NewMVCExtension func --- codec/h264/decode/nalunit.go | 65 +++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/codec/h264/decode/nalunit.go b/codec/h264/decode/nalunit.go index db983909..9969cf91 100644 --- a/codec/h264/decode/nalunit.go +++ b/codec/h264/decode/nalunit.go @@ -14,10 +14,63 @@ type NalUnit struct { Avc3dExtensionFlag int SVCExtension *SVCExtension ThreeDAVCExtension *ThreeDAVCExtension + MVCExtension *MVCExtension EmulationPreventionThreeByte byte rbsp []byte } +type MVCExtension struct { + NonIdrFlag bool + PriorityID int + ViewID int + TemporalID int + AnchorPicFlag bool + InterViewFlag bool + ReservedOneBit int +} + +func NewMVCExtension(br *bits.BitReader) (*MVCExtension, error) { + e := &MVCExtension{} + var err error + + e.NonIdrFlag, err = br.ReadBool() + if err != nil { + return nil, errors.Wrap(err, "could not read NonIdrFlag") + } + + e.PriorityID, err = br.ReadBitsInt(6) + if err != nil { + return nil, errors.Wrap(err, "could not read PriorityId") + } + + e.ViewID, err = br.ReadBitsInt(10) + if err != nil { + return nil, errors.Wrap(err, "could not read ViewId") + } + + e.TemporalID, err = br.ReadBitsInt(3) + if err != nil { + return nil, errors.Wrap(err, "could not read TemporalId") + } + + e.AnchorPicFlag, err = br.ReadBool() + if err != nil { + return nil, errors.Wrap(err, "could not read AnchorPicFlag") + } + + e.InterViewFlag, err = br.ReadBool() + if err != nil { + return nil, errors.Wrap(err, "could not read InterViewFlag") + } + + e.ReservedOneBit, err = br.ReadBitsInt(1) + if err != nil { + return nil, errors.Wrap(err, "could not read ReservedOneBit") + } + + return e, nil +} + type ThreeDAVCExtension struct { ViewIdx int DepthFlag bool @@ -134,18 +187,6 @@ func NewSVCExtension(br *bits.BitReader) (*SVCExtension, error) { return e, nil } -func NalUnitHeaderMvcExtension(nalUnit *NalUnit, br *bits.BitReader) error { - return readFields(br, []field{ - {&nalUnit.NonIdrFlag, "NonIdrFlag", 1}, - {&nalUnit.PriorityId, "PriorityId", 6}, - {&nalUnit.ViewId, "ViewId", 10}, - {&nalUnit.TemporalId, "TemporalId", 3}, - {&nalUnit.AnchorPicFlag, "AnchorPicFlag", 1}, - {&nalUnit.InterViewFlag, "InterViewFlag", 1}, - {&nalUnit.ReservedOneBit, "ReservedOneBit", 1}, - }) -} - func (n *NalUnit) RBSP() []byte { return n.rbsp }