codec/h264/decode: added SVCExtension struct with NewSVCExtension function

This commit is contained in:
Saxon 2019-07-19 17:37:54 +09:30
parent 16b4d570b6
commit 0d9861c49e
1 changed files with 70 additions and 24 deletions

View File

@ -1,7 +1,7 @@
package h264 package h264
import ( import (
"github.com/ausocean/h264decode/h264/bits" "bitbucket.org/ausocean/av/codec/h264/decode/bits"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -12,16 +12,7 @@ type NalUnit struct {
Type int Type int
SvcExtensionFlag int SvcExtensionFlag int
Avc3dExtensionFlag int Avc3dExtensionFlag int
IdrFlag int SVCExtension *SVCExtension
PriorityId int
NoInterLayerPredFlag int
DependencyId int
QualityId int
TemporalId int
UseRefBasePicFlag int
DiscardableFlag int
OutputFlag int
ReservedThree2Bits int
HeaderBytes int HeaderBytes int
NonIdrFlag int NonIdrFlag int
ViewId int ViewId int
@ -34,19 +25,74 @@ type NalUnit struct {
rbsp []byte rbsp []byte
} }
func NalUnitHeaderSvcExtension(nalUnit *NalUnit, br *bits.BitReader) error { type SVCExtension struct {
return readFields(br, []field{ IdrFlag bool
{&nalUnit.IdrFlag, "IdrFlag", 1}, PriorityId int
{&nalUnit.PriorityId, "PriorityId", 6}, NoInterLayerPredFlag bool
{&nalUnit.NoInterLayerPredFlag, "NoInterLayerPredFlag", 1}, DependencyId int
{&nalUnit.DependencyId, "DependencyId", 3}, QualityId int
{&nalUnit.QualityId, "QualityId", 4}, TemporalId int
{&nalUnit.TemporalId, "TemporalId", 3}, UseRefBasePicFlag bool
{&nalUnit.UseRefBasePicFlag, "UseRefBasePicFlag", 1}, DiscardableFlag bool
{&nalUnit.DiscardableFlag, "DiscardableFlag", 1}, OutputFlag bool
{&nalUnit.OutputFlag, "OutputFlag", 1}, ReservedThree2Bits int
{&nalUnit.ReservedThree2Bits, "ReservedThree2Bits", 2}, }
})
func NewSVCExtension(br *bits.BitReader) (*SVCExtension, error) {
e := &SVCExtension{}
var err error
e.IdrFlag, err = br.ReadBool()
if err != nil {
return nil, errors.Wrap(err, "could not read IdrFlag")
}
e.PriorityId, err = br.ReadBitsInt(6)
if err != nil {
return nil, errors.Wrap(err, "could not read PriorityId")
}
e.NoInterLayerPredFlag, err = br.ReadBool()
if err != nil {
return nil, errors.Wrap(err, "could not read NoInterLayerPredFlag")
}
e.DependencyId, err = br.ReadBitsInt(3)
if err != nil {
return nil, errors.Wrap(err, "could not read DependencyId")
}
e.QualityId, err = br.ReadBitsInt(4)
if err != nil {
return nil, errors.Wrap(err, "could not read QualityId")
}
e.TemporalId, err = br.ReadBitsInt(3)
if err != nil {
return nil, errors.Wrap(err, "could not read TemporalId")
}
e.UseRefBasePicFlag, err = br.ReadBool()
if err != nil {
return nil, errors.Wrap(err, "could not read UseRefBasePicFlag")
}
e.DiscardableFlag, err = br.ReadBool()
if err != nil {
return nil, errors.Wrap(err, "could not read DiscardableFlag")
}
e.OutputFlag, err = br.ReadBool()
if err != nil {
return nil, errors.Wrap(err, "could not read OutputFlag")
}
e.ReservedThree2Bits, err = br.ReadBitsInt(2)
if err != nil {
return nil, errors.Wrap(err, "could not read ReservedThree2Bits")
}
return e, nil
} }
func NalUnitHeader3davcExtension(nalUnit *NalUnit, br *bits.BitReader) error { func NalUnitHeader3davcExtension(nalUnit *NalUnit, br *bits.BitReader) error {