codec/h264/h264dec: change field types to types more consistent with specs and now using fieldReader to read fields of syntax structures

This commit is contained in:
Saxon 2019-07-29 13:41:40 +09:30
parent 23d9f289dd
commit 6c69174303
2 changed files with 46 additions and 125 deletions

View File

@ -26,14 +26,14 @@ type MVCExtension struct {
NonIdrFlag bool
// priority_id, indicates priority of NAL unit. A lower value => higher priority.
PriorityID int
PriorityID uint8
// view_id, specifies a view identifier for the unit. Units with identical
// view_id are in the same view.
ViewID int
ViewID uint32
// temporal_id, temporal identifier for the unit.
TemporalID int
TemporalID uint8
// anchor_pic_flag, if true access unit is an anchor access unit.
AnchorPicFlag bool
@ -43,7 +43,7 @@ type MVCExtension struct {
InterViewFlag bool
// reserved_one_bit, always 1 (ignored by decoders)
ReservedOneBit int
ReservedOneBit uint8
}
// NewMVCExtension parses a NAL unit header multiview video coding extension
@ -51,43 +51,19 @@ type MVCExtension struct {
// returns as a new MVCExtension.
func NewMVCExtension(br *bits.BitReader) (*MVCExtension, error) {
e := &MVCExtension{}
var err error
r := newFieldReader(br)
e.NonIdrFlag, err = br.ReadBool()
if err != nil {
return nil, errors.Wrap(err, "could not read NonIdrFlag")
e.NonIdrFlag = r.readBits(1) == 1
e.PriorityID = uint8(r.readBits(6))
e.ViewID = uint32(r.readBits(10))
e.TemporalID = uint8(r.readBits(3))
e.AnchorPicFlag = r.readBits(1) == 1
e.InterViewFlag = r.readBits(1) == 1
e.ReservedOneBit = uint8(r.readBits(1))
if r.err() != nil {
return nil, fmt.Errorf("error from fieldReader: %v", r.err())
}
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
}
@ -96,7 +72,7 @@ func NewMVCExtension(br *bits.BitReader) (*MVCExtension, error) {
// For field semantics see section J.7.4.1.1.
type ThreeDAVCExtension struct {
// view_idx, specifies the order index for the NAL i.e. view_id = view_id[view_idx].
ViewIdx int
ViewIdx uint8
// dpeth_flag, if true indicates NAL part of a depth view component, otherwise
// a texture view component.
@ -106,7 +82,7 @@ type ThreeDAVCExtension struct {
NonIdrFlag bool
// temporal_id, temporal identifier for the unit.
TemporalID int
TemporalID uint8
// anchor_pic_flag, if true access unit is an anchor access unit.
AnchorPicFlag bool
@ -121,36 +97,17 @@ type ThreeDAVCExtension struct {
// J.7.3.1.1, and returns as a new ThreeDAVCExtension.
func NewThreeDAVCExtension(br *bits.BitReader) (*ThreeDAVCExtension, error) {
e := &ThreeDAVCExtension{}
var err error
r := newFieldReader(br)
e.ViewIdx, err = br.ReadBitsInt(8)
if err != nil {
return nil, errors.Wrap(err, "could not read ViewIdx")
}
e.ViewIdx = uint8(r.readBits(8))
e.DepthFlag = r.readBits(1) == 1
e.NonIdrFlag = r.readBits(1) == 1
e.TemporalID = uint8(r.readBits(3))
e.AnchorPicFlag = r.readBits(1) == 1
e.InterViewFlag = r.readBits(1) == 1
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")
if r.err() != nil {
return nil, fmt.Errorf("error from fieldReader: %v", r.err())
}
return e, nil
@ -165,20 +122,20 @@ type SVCExtension struct {
IdrFlag bool
// priority_id, specifies priority identifier for unit.
PriorityID int
PriorityID uint8
// no_inter_layer_pred_flag, if true inter-layer prediction can't be used for
// decoding slice.
NoInterLayerPredFlag bool
// dependency_id, specifies a dependency identifier for the NAL.
DependencyID int
DependencyID uint8
// quality_id, specifies a quality identifier for the NAL.
QualityID int
QualityID uint8
// temporal_id, specifiesa temporal identifier for the NAL.
TemporalID int
TemporalID uint8
// use_ref_base_pic_flag, if true indicates reference base pictures and
// decoded pictures are used as references for inter prediction.
@ -195,7 +152,7 @@ type SVCExtension struct {
OutputFlag bool
// reserved_three_2bits, equal to 3. Decoders ignore.
ReservedThree2Bits int
ReservedThree2Bits uint8
}
// NewSVCExtension parses a NAL unit header scalable video coding extension from
@ -203,58 +160,22 @@ type SVCExtension struct {
// as a new SVCExtension.
func NewSVCExtension(br *bits.BitReader) (*SVCExtension, error) {
e := &SVCExtension{}
var err error
r := newFieldReader(br)
e.IdrFlag, err = br.ReadBool()
if err != nil {
return nil, errors.Wrap(err, "could not read IdrFlag")
e.IdrFlag = r.readBits(1) == 1
e.PriorityID = uint8(r.readBits(6))
e.NoInterLayerPredFlag = r.readBits(1) == 1
e.DependencyID = uint8(r.readBits(3))
e.QualityID = uint8(r.readBits(4))
e.TemporalID = uint8(r.readBits(3))
e.UseRefBasePicFlag = r.readBits(1) == 1
e.DiscardableFlag = r.readBits(1) == 1
e.OutputFlag = r.readBits(1) == 1
e.ReservedThree2Bits = uint8(r.readBits(2))
if r.err() != nil {
return nil, fmt.Errorf("error from fieldReader: %v", r.err())
}
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
}

View File

@ -241,7 +241,7 @@ func CodedBlockPatternChroma(data *SliceData) int {
// dependencyId see Annex G.8.8.1
// Also G7.3.1.1 nal_unit_header_svc_extension
func DQId(nalUnit *NALUnit) int {
return (nalUnit.SVCExtension.DependencyID << 4) + nalUnit.SVCExtension.QualityID
return int((nalUnit.SVCExtension.DependencyID << 4)) + int(nalUnit.SVCExtension.QualityID)
}
// Annex G p527