codec/h264/h264dec: fixed random build errors

This commit is contained in:
Saxon 2019-07-19 20:58:01 +09:30
parent 278c6f2ef1
commit 4d65d0d433
3 changed files with 28 additions and 34 deletions

View File

@ -129,11 +129,11 @@ func NewThreeDAVCExtension(br *bits.BitReader) (*ThreeDAVCExtension, error) {
// defined in section G.7.3.1.1 of the specifications.
type SVCExtension struct {
IdrFlag bool
PriorityId int
PriorityID int
NoInterLayerPredFlag bool
DependencyId int
QualityId int
TemporalId int
DependencyID int
QualityID int
TemporalID int
UseRefBasePicFlag bool
DiscardableFlag bool
OutputFlag bool
@ -152,7 +152,7 @@ func NewSVCExtension(br *bits.BitReader) (*SVCExtension, error) {
return nil, errors.Wrap(err, "could not read IdrFlag")
}
e.PriorityId, err = br.ReadBitsInt(6)
e.PriorityID, err = br.ReadBitsInt(6)
if err != nil {
return nil, errors.Wrap(err, "could not read PriorityId")
}
@ -162,17 +162,17 @@ func NewSVCExtension(br *bits.BitReader) (*SVCExtension, error) {
return nil, errors.Wrap(err, "could not read NoInterLayerPredFlag")
}
e.DependencyId, err = br.ReadBitsInt(3)
e.DependencyID, err = br.ReadBitsInt(3)
if err != nil {
return nil, errors.Wrap(err, "could not read DependencyId")
}
e.QualityId, err = br.ReadBitsInt(4)
e.QualityID, err = br.ReadBitsInt(4)
if err != nil {
return nil, errors.Wrap(err, "could not read QualityId")
}
e.TemporalId, err = br.ReadBitsInt(3)
e.TemporalID, err = br.ReadBitsInt(3)
if err != nil {
return nil, errors.Wrap(err, "could not read TemporalId")
}
@ -206,8 +206,8 @@ type NALUnit struct {
ForbiddenZeroBit int
RefIdc int
Type int
SVCExtensionFlag int
AVC3dExtensionFlag int
SVCExtensionFlag bool
AVC3DExtensionFlag bool
SVCExtension *SVCExtension
ThreeDAVCExtension *ThreeDAVCExtension
MVCExtension *MVCExtension
@ -229,8 +229,6 @@ func NewNALUnit(br *bits.BitReader) (*NALUnit, error) {
return nil, err
}
var headBytes, rbspBytes = 1, 0
// TODO: use consts for the NAL types here
if n.Type == 14 || n.Type == 20 || n.Type == 21 {
if n.Type != 21 {
@ -249,26 +247,23 @@ func NewNALUnit(br *bits.BitReader) (*NALUnit, error) {
if err != nil {
return nil, errors.Wrap(err, "could not parse SVCExtension")
}
n.HeaderBytes += 3
} else if n.AVC3DExtensionFlag {
n.ThreeDAVCExtension, err = NewThreeDAVCExtension(br)
if err != nil {
return nil, errors.Wrap(err, "could not parse ThreeDAVCExtension")
}
n.HeaderBytes += 2
} else {
n.MVCExtension, err = NewMVCExtension(br)
if err != nil {
return nil, errors.Wrap(err, "could not parse MVCExtension")
}
n.HeaderBytes += 3
}
}
for moreRBSPData(br) {
next3Bytes, err := br.PeekBits(24)
if err != nil && errors.Cause(err) != io.EOF {
return nil, errors.Wrap("could not Peek next 3 bytes")
return nil, errors.Wrap(err, "could not Peek next 3 bytes")
}
if next3Bytes == 0x000003 {
@ -277,9 +272,8 @@ func NewNALUnit(br *bits.BitReader) (*NALUnit, error) {
if err != nil {
return nil, errors.Wrap(err, "could not read rbspByte")
}
n.rbsp = append(n.rbsp, byte(rbspByte))
n.RBSP = append(n.RBSP, byte(rbspByte))
}
i += 2
// Read Emulation prevention three byte.
eptByte, err := br.ReadBits(8)
@ -292,7 +286,7 @@ func NewNALUnit(br *bits.BitReader) (*NALUnit, error) {
if err != nil {
return nil, errors.Wrap(err, "could not read RBSP byte")
}
n.rbsp = append(n.rbsp, byte(b))
n.RBSP = append(n.RBSP, byte(b))
}
}

View File

@ -63,7 +63,7 @@ func (h *H264Reader) Start() {
switch nalUnit.Type {
case naluTypeSPS:
// TODO: handle this error
sps, _ := NewSPS(nalUnit.rbsp, false)
sps, _ := NewSPS(nalUnit.RBSP, false)
h.VideoStreams = append(
h.VideoStreams,
&VideoStream{SPS: sps},
@ -71,20 +71,20 @@ func (h *H264Reader) Start() {
case naluTypePPS:
videoStream := h.VideoStreams[len(h.VideoStreams)-1]
// TODO: handle this error
videoStream.PPS, _ = NewPPS(videoStream.SPS, nalUnit.RBSP(), false)
videoStream.PPS, _ = NewPPS(videoStream.SPS, nalUnit.RBSP, false)
case naluTypeSliceIDRPicture:
fallthrough
case naluTypeSliceNonIDRPicture:
videoStream := h.VideoStreams[len(h.VideoStreams)-1]
logger.Printf("info: frame number %d\n", len(videoStream.Slices))
// TODO: handle this error
sliceContext, _ := NewSliceContext(videoStream, nalUnit, nalUnit.RBSP(), true)
sliceContext, _ := NewSliceContext(videoStream, nalUnit, nalUnit.RBSP, true)
videoStream.Slices = append(videoStream.Slices, sliceContext)
}
}
}
func (r *H264Reader) readNalUnit() (*NalUnit, *bits.BitReader, error) {
func (r *H264Reader) readNalUnit() (*NALUnit, *bits.BitReader, error) {
// Read to start of NAL
logger.Printf("debug: Seeking NAL %d start\n", len(r.NalUnits))
@ -131,7 +131,7 @@ func (r *H264Reader) readNalUnit() (*NalUnit, *bits.BitReader, error) {
r.NalUnits = append(r.NalUnits, nalUnitReader)
// TODO: this should really take an io.Reader rather than []byte. Need to fix nil
// once this is fixed.
nalUnit, err := NewNalUnit(nil, 0)
nalUnit, err := NewNALUnit(nil)
if err != nil {
return nil, nil, errors.Wrap(err, "cannot create new nal unit")
}

View File

@ -23,7 +23,7 @@ type VideoStream struct {
Slices []*SliceContext
}
type SliceContext struct {
*NalUnit
*NALUnit
*SPS
*PPS
*Slice
@ -240,12 +240,12 @@ 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.DependencyId << 4) + nalUnit.QualityId
func DQId(nalUnit *NALUnit) int {
return (nalUnit.SVCExtension.DependencyID << 4) + nalUnit.SVCExtension.QualityID
}
// Annex G p527
func NumMbPart(nalUnit *NalUnit, sps *SPS, header *SliceHeader, data *SliceData) int {
func NumMbPart(nalUnit *NALUnit, sps *SPS, header *SliceHeader, data *SliceData) int {
sliceType := sliceTypeMap[header.SliceType]
numMbPart := 0
if MbTypeName(sliceType, CurrMbAddr(sps, header)) == "B_SKIP" || MbTypeName(sliceType, CurrMbAddr(sps, header)) == "B_Direct_16x16" {
@ -381,7 +381,7 @@ func MbPred(sliceContext *SliceContext, br *bits.BitReader, rbsp []byte) error {
}
} else if mbPartPredMode != direct {
for mbPartIdx := 0; mbPartIdx < NumMbPart(sliceContext.NalUnit, sliceContext.SPS, sliceContext.Slice.Header, sliceContext.Slice.Data); mbPartIdx++ {
for mbPartIdx := 0; mbPartIdx < NumMbPart(sliceContext.NALUnit, sliceContext.SPS, sliceContext.Slice.Header, sliceContext.Slice.Data); mbPartIdx++ {
sliceContext.Update(sliceContext.Slice.Header, sliceContext.Slice.Data)
m, err := MbPartPredMode(sliceContext.Slice.Data, sliceType, sliceContext.Slice.Data.MbType, mbPartIdx)
if err != nil {
@ -417,7 +417,7 @@ func MbPred(sliceContext *SliceContext, br *bits.BitReader, rbsp []byte) error {
}
}
}
for mbPartIdx := 0; mbPartIdx < NumMbPart(sliceContext.NalUnit, sliceContext.SPS, sliceContext.Slice.Header, sliceContext.Slice.Data); mbPartIdx++ {
for mbPartIdx := 0; mbPartIdx < NumMbPart(sliceContext.NALUnit, sliceContext.SPS, sliceContext.Slice.Header, sliceContext.Slice.Data); mbPartIdx++ {
m, err := MbPartPredMode(sliceContext.Slice.Data, sliceType, sliceContext.Slice.Data.MbType, mbPartIdx)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("could not get mbPartPredMode for loop 2 mbPartIdx: %d", mbPartIdx))
@ -456,7 +456,7 @@ func MbPred(sliceContext *SliceContext, br *bits.BitReader, rbsp []byte) error {
}
}
}
for mbPartIdx := 0; mbPartIdx < NumMbPart(sliceContext.NalUnit, sliceContext.SPS, sliceContext.Slice.Header, sliceContext.Slice.Data); mbPartIdx++ {
for mbPartIdx := 0; mbPartIdx < NumMbPart(sliceContext.NALUnit, sliceContext.SPS, sliceContext.Slice.Header, sliceContext.Slice.Data); mbPartIdx++ {
sliceContext.Update(sliceContext.Slice.Header, sliceContext.Slice.Data)
m, err := MbPartPredMode(sliceContext.Slice.Data, sliceType, sliceContext.Slice.Data.MbType, mbPartIdx)
if err != nil {
@ -815,7 +815,7 @@ func NewSliceData(sliceContext *SliceContext, br *bits.BitReader) (*SliceData, e
if err != nil {
return nil, errors.Wrap(err, "could not get mbPartPredMode")
}
if sliceContext.Slice.Data.MbTypeName == "I_NxN" && m != intra16x16 && NumMbPart(sliceContext.NalUnit, sliceContext.SPS, sliceContext.Slice.Header, sliceContext.Slice.Data) == 4 {
if sliceContext.Slice.Data.MbTypeName == "I_NxN" && m != intra16x16 && NumMbPart(sliceContext.NALUnit, sliceContext.SPS, sliceContext.Slice.Header, sliceContext.Slice.Data) == 4 {
logger.Printf("\tTODO: subMbPred\n")
/*
subMbType := SubMbPred(sliceContext.Slice.Data.MbType)
@ -945,7 +945,7 @@ func NewSliceData(sliceContext *SliceContext, br *bits.BitReader) (*SliceData, e
func (c *SliceContext) Update(header *SliceHeader, data *SliceData) {
c.Slice = &Slice{Header: header, Data: data}
}
func NewSliceContext(videoStream *VideoStream, nalUnit *NalUnit, rbsp []byte, showPacket bool) (*SliceContext, error) {
func NewSliceContext(videoStream *VideoStream, nalUnit *NALUnit, rbsp []byte, showPacket bool) (*SliceContext, error) {
var err error
sps := videoStream.SPS
pps := videoStream.PPS
@ -1350,7 +1350,7 @@ func NewSliceContext(videoStream *VideoStream, nalUnit *NalUnit, rbsp []byte, sh
}
sliceContext := &SliceContext{
NalUnit: nalUnit,
NALUnit: nalUnit,
SPS: sps,
PPS: pps,
Slice: &Slice{