From e54bc234c87881f1df90049731adb6a647e9060e Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 19 Jul 2019 17:50:45 +0930 Subject: [PATCH] codec/h264/decode: added ThreeDAVCExtenstion type and NewThreeDAVCExtension function --- codec/h264/decode/nalunit.go | 66 +++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/codec/h264/decode/nalunit.go b/codec/h264/decode/nalunit.go index 0101f750..db983909 100644 --- a/codec/h264/decode/nalunit.go +++ b/codec/h264/decode/nalunit.go @@ -13,18 +13,57 @@ type NalUnit struct { SvcExtensionFlag int Avc3dExtensionFlag int SVCExtension *SVCExtension - HeaderBytes int - NonIdrFlag int - ViewId int - AnchorPicFlag int - InterViewFlag int - ReservedOneBit int - ViewIdx int - DepthFlag int + ThreeDAVCExtension *ThreeDAVCExtension EmulationPreventionThreeByte byte rbsp []byte } +type ThreeDAVCExtension struct { + ViewIdx int + DepthFlag bool + NonIdrFlag bool + TemporalID int + AnchorPicFlag bool + InterViewFlag bool +} + +func NewThreeDAVCExtension(br *bits.BitReader) (*ThreeDAVCExtension, error) { + e := &ThreeDAVCExtension{} + var err error + + e.ViewIdx, err = br.ReadBitsInt(8) + if err != nil { + return nil, errors.Wrap(err, "could not read ViewIdx") + } + + e.DepthFlag, err = br.ReadBool() + if err != nil { + return nil, errors.Wrap(err, "could not read DepthFlag") + } + + e.NonIdrFlag, err = br.ReadBool() + if err != nil { + return nil, errors.Wrap(err, "could not read NonIdrFlag") + } + + 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") + } + + return e, nil +} + type SVCExtension struct { IdrFlag bool PriorityId int @@ -95,17 +134,6 @@ func NewSVCExtension(br *bits.BitReader) (*SVCExtension, error) { return e, nil } -func NalUnitHeader3davcExtension(nalUnit *NalUnit, br *bits.BitReader) error { - return readFields(br, []field{ - {&nalUnit.ViewIdx, "ViewIdx", 8}, - {&nalUnit.DepthFlag, "DepthFlag", 1}, - {&nalUnit.NonIdrFlag, "NonIdrFlag", 1}, - {&nalUnit.TemporalId, "TemporalId", 3}, - {&nalUnit.AnchorPicFlag, "AnchorPicFlag", 1}, - {&nalUnit.InterViewFlag, "InterViewFlag", 1}, - }) -} - func NalUnitHeaderMvcExtension(nalUnit *NalUnit, br *bits.BitReader) error { return readFields(br, []field{ {&nalUnit.NonIdrFlag, "NonIdrFlag", 1},