mirror of https://bitbucket.org/ausocean/av.git
codec/h264/h264dec: fixed random build errors
This commit is contained in:
parent
278c6f2ef1
commit
4d65d0d433
|
@ -129,11 +129,11 @@ func NewThreeDAVCExtension(br *bits.BitReader) (*ThreeDAVCExtension, error) {
|
||||||
// defined in section G.7.3.1.1 of the specifications.
|
// defined in section G.7.3.1.1 of the specifications.
|
||||||
type SVCExtension struct {
|
type SVCExtension struct {
|
||||||
IdrFlag bool
|
IdrFlag bool
|
||||||
PriorityId int
|
PriorityID int
|
||||||
NoInterLayerPredFlag bool
|
NoInterLayerPredFlag bool
|
||||||
DependencyId int
|
DependencyID int
|
||||||
QualityId int
|
QualityID int
|
||||||
TemporalId int
|
TemporalID int
|
||||||
UseRefBasePicFlag bool
|
UseRefBasePicFlag bool
|
||||||
DiscardableFlag bool
|
DiscardableFlag bool
|
||||||
OutputFlag bool
|
OutputFlag bool
|
||||||
|
@ -152,7 +152,7 @@ func NewSVCExtension(br *bits.BitReader) (*SVCExtension, error) {
|
||||||
return nil, errors.Wrap(err, "could not read IdrFlag")
|
return nil, errors.Wrap(err, "could not read IdrFlag")
|
||||||
}
|
}
|
||||||
|
|
||||||
e.PriorityId, err = br.ReadBitsInt(6)
|
e.PriorityID, err = br.ReadBitsInt(6)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not read PriorityId")
|
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")
|
return nil, errors.Wrap(err, "could not read NoInterLayerPredFlag")
|
||||||
}
|
}
|
||||||
|
|
||||||
e.DependencyId, err = br.ReadBitsInt(3)
|
e.DependencyID, err = br.ReadBitsInt(3)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not read DependencyId")
|
return nil, errors.Wrap(err, "could not read DependencyId")
|
||||||
}
|
}
|
||||||
|
|
||||||
e.QualityId, err = br.ReadBitsInt(4)
|
e.QualityID, err = br.ReadBitsInt(4)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not read QualityId")
|
return nil, errors.Wrap(err, "could not read QualityId")
|
||||||
}
|
}
|
||||||
|
|
||||||
e.TemporalId, err = br.ReadBitsInt(3)
|
e.TemporalID, err = br.ReadBitsInt(3)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not read TemporalId")
|
return nil, errors.Wrap(err, "could not read TemporalId")
|
||||||
}
|
}
|
||||||
|
@ -206,8 +206,8 @@ type NALUnit struct {
|
||||||
ForbiddenZeroBit int
|
ForbiddenZeroBit int
|
||||||
RefIdc int
|
RefIdc int
|
||||||
Type int
|
Type int
|
||||||
SVCExtensionFlag int
|
SVCExtensionFlag bool
|
||||||
AVC3dExtensionFlag int
|
AVC3DExtensionFlag bool
|
||||||
SVCExtension *SVCExtension
|
SVCExtension *SVCExtension
|
||||||
ThreeDAVCExtension *ThreeDAVCExtension
|
ThreeDAVCExtension *ThreeDAVCExtension
|
||||||
MVCExtension *MVCExtension
|
MVCExtension *MVCExtension
|
||||||
|
@ -229,8 +229,6 @@ func NewNALUnit(br *bits.BitReader) (*NALUnit, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var headBytes, rbspBytes = 1, 0
|
|
||||||
|
|
||||||
// TODO: use consts for the NAL types here
|
// TODO: use consts for the NAL types here
|
||||||
if n.Type == 14 || n.Type == 20 || n.Type == 21 {
|
if n.Type == 14 || n.Type == 20 || n.Type == 21 {
|
||||||
if n.Type != 21 {
|
if n.Type != 21 {
|
||||||
|
@ -249,26 +247,23 @@ func NewNALUnit(br *bits.BitReader) (*NALUnit, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not parse SVCExtension")
|
return nil, errors.Wrap(err, "could not parse SVCExtension")
|
||||||
}
|
}
|
||||||
n.HeaderBytes += 3
|
|
||||||
} else if n.AVC3DExtensionFlag {
|
} else if n.AVC3DExtensionFlag {
|
||||||
n.ThreeDAVCExtension, err = NewThreeDAVCExtension(br)
|
n.ThreeDAVCExtension, err = NewThreeDAVCExtension(br)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not parse ThreeDAVCExtension")
|
return nil, errors.Wrap(err, "could not parse ThreeDAVCExtension")
|
||||||
}
|
}
|
||||||
n.HeaderBytes += 2
|
|
||||||
} else {
|
} else {
|
||||||
n.MVCExtension, err = NewMVCExtension(br)
|
n.MVCExtension, err = NewMVCExtension(br)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not parse MVCExtension")
|
return nil, errors.Wrap(err, "could not parse MVCExtension")
|
||||||
}
|
}
|
||||||
n.HeaderBytes += 3
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for moreRBSPData(br) {
|
for moreRBSPData(br) {
|
||||||
next3Bytes, err := br.PeekBits(24)
|
next3Bytes, err := br.PeekBits(24)
|
||||||
if err != nil && errors.Cause(err) != io.EOF {
|
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 {
|
if next3Bytes == 0x000003 {
|
||||||
|
@ -277,9 +272,8 @@ func NewNALUnit(br *bits.BitReader) (*NALUnit, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not read rbspByte")
|
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.
|
// Read Emulation prevention three byte.
|
||||||
eptByte, err := br.ReadBits(8)
|
eptByte, err := br.ReadBits(8)
|
||||||
|
@ -292,7 +286,7 @@ func NewNALUnit(br *bits.BitReader) (*NALUnit, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not read RBSP byte")
|
return nil, errors.Wrap(err, "could not read RBSP byte")
|
||||||
}
|
}
|
||||||
n.rbsp = append(n.rbsp, byte(b))
|
n.RBSP = append(n.RBSP, byte(b))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ func (h *H264Reader) Start() {
|
||||||
switch nalUnit.Type {
|
switch nalUnit.Type {
|
||||||
case naluTypeSPS:
|
case naluTypeSPS:
|
||||||
// TODO: handle this error
|
// TODO: handle this error
|
||||||
sps, _ := NewSPS(nalUnit.rbsp, false)
|
sps, _ := NewSPS(nalUnit.RBSP, false)
|
||||||
h.VideoStreams = append(
|
h.VideoStreams = append(
|
||||||
h.VideoStreams,
|
h.VideoStreams,
|
||||||
&VideoStream{SPS: sps},
|
&VideoStream{SPS: sps},
|
||||||
|
@ -71,20 +71,20 @@ func (h *H264Reader) Start() {
|
||||||
case naluTypePPS:
|
case naluTypePPS:
|
||||||
videoStream := h.VideoStreams[len(h.VideoStreams)-1]
|
videoStream := h.VideoStreams[len(h.VideoStreams)-1]
|
||||||
// TODO: handle this error
|
// TODO: handle this error
|
||||||
videoStream.PPS, _ = NewPPS(videoStream.SPS, nalUnit.RBSP(), false)
|
videoStream.PPS, _ = NewPPS(videoStream.SPS, nalUnit.RBSP, false)
|
||||||
case naluTypeSliceIDRPicture:
|
case naluTypeSliceIDRPicture:
|
||||||
fallthrough
|
fallthrough
|
||||||
case naluTypeSliceNonIDRPicture:
|
case naluTypeSliceNonIDRPicture:
|
||||||
videoStream := h.VideoStreams[len(h.VideoStreams)-1]
|
videoStream := h.VideoStreams[len(h.VideoStreams)-1]
|
||||||
logger.Printf("info: frame number %d\n", len(videoStream.Slices))
|
logger.Printf("info: frame number %d\n", len(videoStream.Slices))
|
||||||
// TODO: handle this error
|
// TODO: handle this error
|
||||||
sliceContext, _ := NewSliceContext(videoStream, nalUnit, nalUnit.RBSP(), true)
|
sliceContext, _ := NewSliceContext(videoStream, nalUnit, nalUnit.RBSP, true)
|
||||||
videoStream.Slices = append(videoStream.Slices, sliceContext)
|
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
|
// Read to start of NAL
|
||||||
logger.Printf("debug: Seeking NAL %d start\n", len(r.NalUnits))
|
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)
|
r.NalUnits = append(r.NalUnits, nalUnitReader)
|
||||||
// TODO: this should really take an io.Reader rather than []byte. Need to fix nil
|
// TODO: this should really take an io.Reader rather than []byte. Need to fix nil
|
||||||
// once this is fixed.
|
// once this is fixed.
|
||||||
nalUnit, err := NewNalUnit(nil, 0)
|
nalUnit, err := NewNALUnit(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, errors.Wrap(err, "cannot create new nal unit")
|
return nil, nil, errors.Wrap(err, "cannot create new nal unit")
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ type VideoStream struct {
|
||||||
Slices []*SliceContext
|
Slices []*SliceContext
|
||||||
}
|
}
|
||||||
type SliceContext struct {
|
type SliceContext struct {
|
||||||
*NalUnit
|
*NALUnit
|
||||||
*SPS
|
*SPS
|
||||||
*PPS
|
*PPS
|
||||||
*Slice
|
*Slice
|
||||||
|
@ -240,12 +240,12 @@ 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.DependencyId << 4) + nalUnit.QualityId
|
return (nalUnit.SVCExtension.DependencyID << 4) + nalUnit.SVCExtension.QualityID
|
||||||
}
|
}
|
||||||
|
|
||||||
// Annex G p527
|
// 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]
|
sliceType := sliceTypeMap[header.SliceType]
|
||||||
numMbPart := 0
|
numMbPart := 0
|
||||||
if MbTypeName(sliceType, CurrMbAddr(sps, header)) == "B_SKIP" || MbTypeName(sliceType, CurrMbAddr(sps, header)) == "B_Direct_16x16" {
|
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 {
|
} 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)
|
sliceContext.Update(sliceContext.Slice.Header, sliceContext.Slice.Data)
|
||||||
m, err := MbPartPredMode(sliceContext.Slice.Data, sliceType, sliceContext.Slice.Data.MbType, mbPartIdx)
|
m, err := MbPartPredMode(sliceContext.Slice.Data, sliceType, sliceContext.Slice.Data.MbType, mbPartIdx)
|
||||||
if err != nil {
|
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)
|
m, err := MbPartPredMode(sliceContext.Slice.Data, sliceType, sliceContext.Slice.Data.MbType, mbPartIdx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, fmt.Sprintf("could not get mbPartPredMode for loop 2 mbPartIdx: %d", mbPartIdx))
|
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)
|
sliceContext.Update(sliceContext.Slice.Header, sliceContext.Slice.Data)
|
||||||
m, err := MbPartPredMode(sliceContext.Slice.Data, sliceType, sliceContext.Slice.Data.MbType, mbPartIdx)
|
m, err := MbPartPredMode(sliceContext.Slice.Data, sliceType, sliceContext.Slice.Data.MbType, mbPartIdx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -815,7 +815,7 @@ func NewSliceData(sliceContext *SliceContext, br *bits.BitReader) (*SliceData, e
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not get mbPartPredMode")
|
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")
|
logger.Printf("\tTODO: subMbPred\n")
|
||||||
/*
|
/*
|
||||||
subMbType := SubMbPred(sliceContext.Slice.Data.MbType)
|
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) {
|
func (c *SliceContext) Update(header *SliceHeader, data *SliceData) {
|
||||||
c.Slice = &Slice{Header: header, Data: data}
|
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
|
var err error
|
||||||
sps := videoStream.SPS
|
sps := videoStream.SPS
|
||||||
pps := videoStream.PPS
|
pps := videoStream.PPS
|
||||||
|
@ -1350,7 +1350,7 @@ func NewSliceContext(videoStream *VideoStream, nalUnit *NalUnit, rbsp []byte, sh
|
||||||
}
|
}
|
||||||
|
|
||||||
sliceContext := &SliceContext{
|
sliceContext := &SliceContext{
|
||||||
NalUnit: nalUnit,
|
NALUnit: nalUnit,
|
||||||
SPS: sps,
|
SPS: sps,
|
||||||
PPS: pps,
|
PPS: pps,
|
||||||
Slice: &Slice{
|
Slice: &Slice{
|
||||||
|
|
Loading…
Reference in New Issue