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