github.com/bluenviron/mediacommon@v1.9.3/pkg/codecs/h265/pps.go (about) 1 package h265 2 3 import ( 4 "fmt" 5 6 "github.com/bluenviron/mediacommon/pkg/bits" 7 "github.com/bluenviron/mediacommon/pkg/codecs/h264" 8 ) 9 10 // PPS is a H265 picture parameter set. 11 // Specification: ITU-T Rec. H.265, 7.3.2.3.1 12 type PPS struct { 13 ID uint32 14 SPSID uint32 15 DependentSliceSegmentsEnabledFlag bool 16 OutputFlagPresentFlag bool 17 NumExtraSliceHeaderBits uint8 18 } 19 20 // Unmarshal decodes a PPS. 21 func (p *PPS) Unmarshal(buf []byte) error { 22 if len(buf) < 2 { 23 return fmt.Errorf("not enough bits") 24 } 25 26 if NALUType((buf[0]>>1)&0b111111) != NALUType_PPS_NUT { 27 return fmt.Errorf("not a PPS") 28 } 29 30 buf = h264.EmulationPreventionRemove(buf[1:]) 31 pos := 8 32 33 var err error 34 p.ID, err = bits.ReadGolombUnsigned(buf, &pos) 35 if err != nil { 36 return err 37 } 38 39 p.SPSID, err = bits.ReadGolombUnsigned(buf, &pos) 40 if err != nil { 41 return err 42 } 43 44 err = bits.HasSpace(buf, pos, 5) 45 if err != nil { 46 return err 47 } 48 49 p.DependentSliceSegmentsEnabledFlag = bits.ReadFlagUnsafe(buf, &pos) 50 p.OutputFlagPresentFlag = bits.ReadFlagUnsafe(buf, &pos) 51 p.NumExtraSliceHeaderBits = uint8(bits.ReadBitsUnsafe(buf, &pos, 3)) 52 53 return nil 54 }