mirror of https://bitbucket.org/ausocean/av.git
Merged in vui-hrd-parameters-types (pull request #217)
codec/h264/h264dec: separated VUI and HRD from SPS struct
This commit is contained in:
commit
401f75a712
|
@ -35,14 +35,14 @@ func YOffset(yRefMin16, refMbH int) int {
|
||||||
}
|
}
|
||||||
func MbWidthC(sps *SPS) int {
|
func MbWidthC(sps *SPS) int {
|
||||||
mbWidthC := 16 / SubWidthC(sps)
|
mbWidthC := 16 / SubWidthC(sps)
|
||||||
if sps.ChromaFormat == chromaMonochrome || sps.UseSeparateColorPlane {
|
if sps.ChromaFormatIDC == chromaMonochrome || sps.SeparateColorPlaneFlag {
|
||||||
mbWidthC = 0
|
mbWidthC = 0
|
||||||
}
|
}
|
||||||
return mbWidthC
|
return mbWidthC
|
||||||
}
|
}
|
||||||
func MbHeightC(sps *SPS) int {
|
func MbHeightC(sps *SPS) int {
|
||||||
mbHeightC := 16 / SubHeightC(sps)
|
mbHeightC := 16 / SubHeightC(sps)
|
||||||
if sps.ChromaFormat == chromaMonochrome || sps.UseSeparateColorPlane {
|
if sps.ChromaFormatIDC == chromaMonochrome || sps.SeparateColorPlaneFlag {
|
||||||
mbHeightC = 0
|
mbHeightC = 0
|
||||||
}
|
}
|
||||||
return mbHeightC
|
return mbHeightC
|
||||||
|
|
|
@ -64,11 +64,11 @@ func (r fieldReader) readBits(n int) uint64 {
|
||||||
// Exp-Golomb-coded element using method as specified in section 9.1 of ITU-T
|
// Exp-Golomb-coded element using method as specified in section 9.1 of ITU-T
|
||||||
// H.264 and return as an int. The read does not happen if the fieldReader
|
// H.264 and return as an int. The read does not happen if the fieldReader
|
||||||
// has a non-nil error.
|
// has a non-nil error.
|
||||||
func (r fieldReader) readUe() int {
|
func (r fieldReader) readUe() uint64 {
|
||||||
if r.e != nil {
|
if r.e != nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
var i int
|
var i uint64
|
||||||
i, r.e = readUe(r.br)
|
i, r.e = readUe(r.br)
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
@ -77,11 +77,11 @@ func (r fieldReader) readUe() int {
|
||||||
// Exp-Golomb-coded syntax element using method as specified in section 9.1
|
// Exp-Golomb-coded syntax element using method as specified in section 9.1
|
||||||
// and returns as an int. The read does not happen if the fieldReader
|
// and returns as an int. The read does not happen if the fieldReader
|
||||||
// has a non-nil error.
|
// has a non-nil error.
|
||||||
func (r fieldReader) readTe(x uint) int {
|
func (r fieldReader) readTe(x uint) int64 {
|
||||||
if r.e != nil {
|
if r.e != nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
var i int
|
var i int64
|
||||||
i, r.e = readTe(r.br, x)
|
i, r.e = readTe(r.br, x)
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ func (r fieldReader) err() error {
|
||||||
//
|
//
|
||||||
// TODO: this should return uint, but rest of code needs to be changed for this
|
// TODO: this should return uint, but rest of code needs to be changed for this
|
||||||
// to happen.
|
// to happen.
|
||||||
func readUe(r *bits.BitReader) (int, error) {
|
func readUe(r *bits.BitReader) (uint64, error) {
|
||||||
nZeros := -1
|
nZeros := -1
|
||||||
var err error
|
var err error
|
||||||
for b := uint64(0); b == 0; nZeros++ {
|
for b := uint64(0); b == 0; nZeros++ {
|
||||||
|
@ -135,7 +135,7 @@ func readUe(r *bits.BitReader) (int, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return int(math.Pow(float64(2), float64(nZeros)) - 1 + float64(rem)), nil
|
return uint64(math.Pow(float64(2), float64(nZeros)) - 1 + float64(rem)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// readTe parses a syntax element of te(v) descriptor i.e, truncated
|
// readTe parses a syntax element of te(v) descriptor i.e, truncated
|
||||||
|
@ -143,9 +143,10 @@ func readUe(r *bits.BitReader) (int, error) {
|
||||||
// Rec. ITU-T H.264 (04/2017).
|
// Rec. ITU-T H.264 (04/2017).
|
||||||
//
|
//
|
||||||
// TODO: this should also return uint.
|
// TODO: this should also return uint.
|
||||||
func readTe(r *bits.BitReader, x uint) (int, error) {
|
func readTe(r *bits.BitReader, x uint) (int64, error) {
|
||||||
if x > 1 {
|
if x > 1 {
|
||||||
return readUe(r)
|
ue, err := readUe(r)
|
||||||
|
return int64(ue), err
|
||||||
}
|
}
|
||||||
|
|
||||||
if x == 1 {
|
if x == 1 {
|
||||||
|
@ -181,7 +182,7 @@ func readSe(r *bits.BitReader) (int, error) {
|
||||||
// in Rec. ITU-T H.264 (04/2017).
|
// in Rec. ITU-T H.264 (04/2017).
|
||||||
func readMe(r *bits.BitReader, chromaArrayType uint, mpm mbPartPredMode) (uint, error) {
|
func readMe(r *bits.BitReader, chromaArrayType uint, mpm mbPartPredMode) (uint, error) {
|
||||||
// Indexes to codedBlockPattern map.
|
// Indexes to codedBlockPattern map.
|
||||||
var i1, i2, i3 int
|
var i1, i2, i3 uint64
|
||||||
|
|
||||||
// ChromaArrayType selects first index.
|
// ChromaArrayType selects first index.
|
||||||
switch chromaArrayType {
|
switch chromaArrayType {
|
||||||
|
@ -200,7 +201,7 @@ func readMe(r *bits.BitReader, chromaArrayType uint, mpm mbPartPredMode) (uint,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to check that we won't go out of bounds with this index.
|
// Need to check that we won't go out of bounds with this index.
|
||||||
if i2 >= len(codedBlockPattern[i1]) {
|
if int(i2) >= len(codedBlockPattern[i1]) {
|
||||||
return 0, errInvalidCodeNum
|
return 0, errInvalidCodeNum
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"bitbucket.org/ausocean/av/codec/h264/h264dec/bits"
|
"bitbucket.org/ausocean/av/codec/h264/h264dec/bits"
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// import "strings"
|
// import "strings"
|
||||||
|
@ -42,152 +41,54 @@ type PPS struct {
|
||||||
|
|
||||||
func NewPPS(br *bits.BitReader, chromaFormat int) (*PPS, error) {
|
func NewPPS(br *bits.BitReader, chromaFormat int) (*PPS, error) {
|
||||||
pps := PPS{}
|
pps := PPS{}
|
||||||
var err error
|
r := newFieldReader(br)
|
||||||
|
|
||||||
pps.ID, err = readUe(br)
|
pps.ID = int(r.readUe())
|
||||||
if err != nil {
|
pps.SPSID = int(r.readUe())
|
||||||
return nil, errors.Wrap(err, "could not parse ID")
|
pps.EntropyCodingMode = int(r.readBits(1))
|
||||||
}
|
pps.BottomFieldPicOrderInFramePresent = r.readBits(1) == 1
|
||||||
|
pps.NumSliceGroupsMinus1 = int(r.readUe())
|
||||||
pps.SPSID, err = readUe(br)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse SPS ID")
|
|
||||||
}
|
|
||||||
|
|
||||||
b, err := br.ReadBits(1)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not read EntropyCodingMode")
|
|
||||||
}
|
|
||||||
pps.EntropyCodingMode = int(b)
|
|
||||||
|
|
||||||
b, err = br.ReadBits(1)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not read BottomFieldPicOrderInFramePresent")
|
|
||||||
}
|
|
||||||
pps.BottomFieldPicOrderInFramePresent = b == 1
|
|
||||||
|
|
||||||
pps.NumSliceGroupsMinus1, err = readUe(br)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse NumSliceGroupsMinus1")
|
|
||||||
}
|
|
||||||
|
|
||||||
if pps.NumSliceGroupsMinus1 > 0 {
|
if pps.NumSliceGroupsMinus1 > 0 {
|
||||||
pps.SliceGroupMapType, err = readUe(br)
|
pps.SliceGroupMapType = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse SliceGroupMapType")
|
|
||||||
}
|
|
||||||
|
|
||||||
if pps.SliceGroupMapType == 0 {
|
if pps.SliceGroupMapType == 0 {
|
||||||
for iGroup := 0; iGroup <= pps.NumSliceGroupsMinus1; iGroup++ {
|
for iGroup := 0; iGroup <= pps.NumSliceGroupsMinus1; iGroup++ {
|
||||||
b, err := readUe(br)
|
pps.RunLengthMinus1[iGroup] = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse RunLengthMinus1")
|
|
||||||
}
|
|
||||||
pps.RunLengthMinus1 = append(pps.RunLengthMinus1, b)
|
|
||||||
}
|
}
|
||||||
} else if pps.SliceGroupMapType == 2 {
|
} else if pps.SliceGroupMapType == 2 {
|
||||||
for iGroup := 0; iGroup < pps.NumSliceGroupsMinus1; iGroup++ {
|
for iGroup := 0; iGroup < pps.NumSliceGroupsMinus1; iGroup++ {
|
||||||
pps.TopLeft[iGroup], err = readUe(br)
|
pps.TopLeft[iGroup] = int(r.readUe())
|
||||||
if err != nil {
|
pps.BottomRight[iGroup] = int(r.readUe())
|
||||||
return nil, errors.Wrap(err, "could not parse TopLeft[iGroup]")
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse TopLeft[iGroup]")
|
|
||||||
}
|
|
||||||
|
|
||||||
pps.BottomRight[iGroup], err = readUe(br)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse BottomRight[iGroup]")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if pps.SliceGroupMapType > 2 && pps.SliceGroupMapType < 6 {
|
} else if pps.SliceGroupMapType > 2 && pps.SliceGroupMapType < 6 {
|
||||||
b, err = br.ReadBits(1)
|
pps.SliceGroupChangeDirection = r.readBits(1) == 1
|
||||||
if err != nil {
|
pps.SliceGroupChangeRateMinus1 = int(r.readUe())
|
||||||
return nil, errors.Wrap(err, "could not read SliceGroupChangeDirection")
|
|
||||||
}
|
|
||||||
pps.SliceGroupChangeDirection = b == 1
|
|
||||||
|
|
||||||
pps.SliceGroupChangeRateMinus1, err = readUe(br)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse SliceGroupChangeRateMinus1")
|
|
||||||
}
|
|
||||||
} else if pps.SliceGroupMapType == 6 {
|
} else if pps.SliceGroupMapType == 6 {
|
||||||
pps.PicSizeInMapUnitsMinus1, err = readUe(br)
|
pps.PicSizeInMapUnitsMinus1 = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse PicSizeInMapUnitsMinus1")
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i <= pps.PicSizeInMapUnitsMinus1; i++ {
|
for i := 0; i <= pps.PicSizeInMapUnitsMinus1; i++ {
|
||||||
b, err = br.ReadBits(int(math.Ceil(math.Log2(float64(pps.NumSliceGroupsMinus1 + 1)))))
|
pps.SliceGroupId[i] = int(r.readBits(int(math.Ceil(math.Log2(float64(pps.NumSliceGroupsMinus1 + 1))))))
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "coult not read SliceGroupId")
|
|
||||||
}
|
|
||||||
pps.SliceGroupId[i] = int(b)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
pps.NumRefIdxL0DefaultActiveMinus1, err = readUe(br)
|
pps.NumRefIdxL0DefaultActiveMinus1 = int(r.readUe())
|
||||||
if err != nil {
|
pps.NumRefIdxL1DefaultActiveMinus1 = int(r.readUe())
|
||||||
return nil, errors.New("could not parse NumRefIdxL0DefaultActiveMinus1")
|
pps.WeightedPred = r.readBits(1) == 1
|
||||||
}
|
pps.WeightedBipred = int(r.readBits(2))
|
||||||
|
pps.PicInitQpMinus26 = int(r.readSe())
|
||||||
pps.NumRefIdxL1DefaultActiveMinus1, err = readUe(br)
|
pps.PicInitQsMinus26 = int(r.readSe())
|
||||||
if err != nil {
|
pps.ChromaQpIndexOffset = int(r.readSe())
|
||||||
return nil, errors.New("could not parse NumRefIdxL1DefaultActiveMinus1")
|
pps.DeblockingFilterControlPresent = r.readBits(1) == 1
|
||||||
}
|
pps.ConstrainedIntraPred = r.readBits(1) == 1
|
||||||
|
pps.RedundantPicCntPresent = r.readBits(1) == 1
|
||||||
b, err = br.ReadBits(1)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not read WeightedPred")
|
|
||||||
}
|
|
||||||
pps.WeightedPred = b == 1
|
|
||||||
|
|
||||||
b, err = br.ReadBits(2)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not read WeightedBipred")
|
|
||||||
}
|
|
||||||
pps.WeightedBipred = int(b)
|
|
||||||
|
|
||||||
pps.PicInitQpMinus26, err = readSe(br)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("could not parse PicInitQpMinus26")
|
|
||||||
}
|
|
||||||
|
|
||||||
pps.PicInitQsMinus26, err = readSe(br)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("could not parse PicInitQsMinus26")
|
|
||||||
}
|
|
||||||
|
|
||||||
pps.ChromaQpIndexOffset, err = readSe(br)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("could not parse ChromaQpIndexOffset")
|
|
||||||
}
|
|
||||||
|
|
||||||
err = readFlags(br, []flag{
|
|
||||||
{&pps.DeblockingFilterControlPresent, "DeblockingFilterControlPresent"},
|
|
||||||
{&pps.ConstrainedIntraPred, "ConstrainedIntraPred"},
|
|
||||||
{&pps.RedundantPicCntPresent, "RedundantPicCntPresent"},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.Printf("debug: \tChecking for more PPS data")
|
logger.Printf("debug: \tChecking for more PPS data")
|
||||||
if moreRBSPData(br) {
|
if moreRBSPData(br) {
|
||||||
logger.Printf("debug: \tProcessing additional PPS data")
|
logger.Printf("debug: \tProcessing additional PPS data")
|
||||||
|
pps.Transform8x8Mode = int(r.readBits(1))
|
||||||
b, err = br.ReadBits(1)
|
pps.PicScalingMatrixPresent = r.readBits(1) == 1
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not read Transform8x8Mode")
|
|
||||||
}
|
|
||||||
pps.Transform8x8Mode = int(b)
|
|
||||||
|
|
||||||
b, err = br.ReadBits(1)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not read PicScalingMatrixPresent")
|
|
||||||
}
|
|
||||||
pps.PicScalingMatrixPresent = b == 1
|
|
||||||
|
|
||||||
if pps.PicScalingMatrixPresent {
|
if pps.PicScalingMatrixPresent {
|
||||||
v := 6
|
v := 6
|
||||||
|
@ -195,11 +96,7 @@ func NewPPS(br *bits.BitReader, chromaFormat int) (*PPS, error) {
|
||||||
v = 2
|
v = 2
|
||||||
}
|
}
|
||||||
for i := 0; i < 6+(v*pps.Transform8x8Mode); i++ {
|
for i := 0; i < 6+(v*pps.Transform8x8Mode); i++ {
|
||||||
b, err = br.ReadBits(1)
|
pps.PicScalingListPresent[i] = r.readBits(1) == 1
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not read PicScalingListPresent")
|
|
||||||
}
|
|
||||||
pps.PicScalingListPresent[i] = b == 1
|
|
||||||
if pps.PicScalingListPresent[i] {
|
if pps.PicScalingListPresent[i] {
|
||||||
if i < 6 {
|
if i < 6 {
|
||||||
scalingList(
|
scalingList(
|
||||||
|
@ -218,12 +115,10 @@ func NewPPS(br *bits.BitReader, chromaFormat int) (*PPS, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pps.SecondChromaQpIndexOffset = r.readSe()
|
||||||
}
|
}
|
||||||
pps.SecondChromaQpIndexOffset, err = readSe(br)
|
moreRBSPData(br)
|
||||||
if err != nil {
|
// rbspTrailingBits()
|
||||||
return nil, errors.New("could not parse SecondChromaQpIndexOffset")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
moreRBSPData(br)
|
|
||||||
return &pps, nil
|
return &pps, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,8 @@ 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(nil, videoStream.SPS.ChromaFormat)
|
// TODO: fix chromaFormat
|
||||||
|
videoStream.PPS, _ = NewPPS(nil, 0)
|
||||||
case naluTypeSliceIDRPicture:
|
case naluTypeSliceIDRPicture:
|
||||||
fallthrough
|
fallthrough
|
||||||
case naluTypeSliceNonIDRPicture:
|
case naluTypeSliceNonIDRPicture:
|
||||||
|
|
|
@ -56,61 +56,36 @@ func NewRefPicListMVCModifiation(br *bits.BitReader) (*RefPicListModification, e
|
||||||
// following the syntax structure defined in section 7.3.3.1, and returns as
|
// following the syntax structure defined in section 7.3.3.1, and returns as
|
||||||
// a new RefPicListModification.
|
// a new RefPicListModification.
|
||||||
func NewRefPicListModification(br *bits.BitReader, h *SliceHeader) (*RefPicListModification, error) {
|
func NewRefPicListModification(br *bits.BitReader, h *SliceHeader) (*RefPicListModification, error) {
|
||||||
r := &RefPicListModification{}
|
ref := &RefPicListModification{}
|
||||||
|
r := newFieldReader(br)
|
||||||
// 7.3.3.1
|
// 7.3.3.1
|
||||||
if h.SliceType%5 != 2 && h.SliceType%5 != 4 {
|
if h.SliceType%5 != 2 && h.SliceType%5 != 4 {
|
||||||
b, err := br.ReadBits(1)
|
ref.RefPicListModificationFlagL0 = r.readBits(1) == 1
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not read RefPicListModificationFlagL0")
|
|
||||||
}
|
|
||||||
r.RefPicListModificationFlagL0 = b == 1
|
|
||||||
|
|
||||||
if r.RefPicListModificationFlagL0 {
|
if ref.RefPicListModificationFlagL0 {
|
||||||
for r.ModificationOfPicNums != 3 {
|
for ref.ModificationOfPicNums != 3 {
|
||||||
r.ModificationOfPicNums, err = readUe(br)
|
ref.ModificationOfPicNums = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse ModificationOfPicNums")
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.ModificationOfPicNums == 0 || r.ModificationOfPicNums == 1 {
|
if ref.ModificationOfPicNums == 0 || ref.ModificationOfPicNums == 1 {
|
||||||
r.AbsDiffPicNumMinus1, err = readUe(br)
|
ref.AbsDiffPicNumMinus1 = int(r.readUe())
|
||||||
if err != nil {
|
} else if ref.ModificationOfPicNums == 2 {
|
||||||
return nil, errors.Wrap(err, "could not parse AbsDiffPicNumMinus1")
|
ref.LongTermPicNum = int(r.readUe())
|
||||||
}
|
|
||||||
} else if r.ModificationOfPicNums == 2 {
|
|
||||||
r.LongTermPicNum, err = readUe(br)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse LongTermPicNum")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if h.SliceType%5 == 1 {
|
if h.SliceType%5 == 1 {
|
||||||
b, err := br.ReadBits(1)
|
ref.RefPicListModificationFlagL1 = r.readBits(1) == 1
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not read RefPicListModificationFlagL1")
|
|
||||||
}
|
|
||||||
r.RefPicListModificationFlagL1 = b == 1
|
|
||||||
|
|
||||||
if r.RefPicListModificationFlagL1 {
|
if ref.RefPicListModificationFlagL1 {
|
||||||
for r.ModificationOfPicNums != 3 {
|
for ref.ModificationOfPicNums != 3 {
|
||||||
r.ModificationOfPicNums, err = readUe(br)
|
ref.ModificationOfPicNums = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse ModificationOfPicNums")
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.ModificationOfPicNums == 0 || r.ModificationOfPicNums == 1 {
|
if ref.ModificationOfPicNums == 0 || ref.ModificationOfPicNums == 1 {
|
||||||
r.AbsDiffPicNumMinus1, err = readUe(br)
|
ref.AbsDiffPicNumMinus1 = int(r.readUe())
|
||||||
if err != nil {
|
} else if ref.ModificationOfPicNums == 2 {
|
||||||
return nil, errors.Wrap(err, "could not parse AbsDiffPicNumMinus1")
|
ref.LongTermPicNum = int(r.readUe())
|
||||||
}
|
|
||||||
} else if r.ModificationOfPicNums == 2 {
|
|
||||||
r.LongTermPicNum, err = readUe(br)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse LongTermPicNum")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,25 +119,15 @@ type PredWeightTable struct {
|
||||||
// PredWeightTable.
|
// PredWeightTable.
|
||||||
func NewPredWeightTable(br *bits.BitReader, h *SliceHeader) (*PredWeightTable, error) {
|
func NewPredWeightTable(br *bits.BitReader, h *SliceHeader) (*PredWeightTable, error) {
|
||||||
p := &PredWeightTable{}
|
p := &PredWeightTable{}
|
||||||
var err error
|
r := newFieldReader(br)
|
||||||
|
|
||||||
p.LumaLog2WeightDenom, err = readUe(br)
|
p.LumaLog2WeightDenom = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse LumaLog2WeightDenom")
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.ChromaArrayType != 0 {
|
if p.ChromaArrayType != 0 {
|
||||||
p.ChromaLog2WeightDenom, err = readUe(br)
|
p.ChromaLog2WeightDenom = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse ChromaLog2WeightDenom")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for i := 0; i <= h.NumRefIdxL0ActiveMinus1; i++ {
|
for i := 0; i <= h.NumRefIdxL0ActiveMinus1; i++ {
|
||||||
b, err := br.ReadBits(1)
|
p.LumaWeightL0Flag = r.readBits(1) == 1
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not read LumaWeightL0Flag")
|
|
||||||
}
|
|
||||||
p.LumaWeightL0Flag = b == 1
|
|
||||||
|
|
||||||
if p.LumaWeightL0Flag {
|
if p.LumaWeightL0Flag {
|
||||||
se, err := readSe(br)
|
se, err := readSe(br)
|
||||||
|
@ -271,6 +236,7 @@ type DecRefPicMarking struct {
|
||||||
// DecRefPicMarking.
|
// DecRefPicMarking.
|
||||||
func NewDecRefPicMarking(br *bits.BitReader, idrPic bool, h *SliceHeader) (*DecRefPicMarking, error) {
|
func NewDecRefPicMarking(br *bits.BitReader, idrPic bool, h *SliceHeader) (*DecRefPicMarking, error) {
|
||||||
d := &DecRefPicMarking{}
|
d := &DecRefPicMarking{}
|
||||||
|
r := newFieldReader(br)
|
||||||
if idrPic {
|
if idrPic {
|
||||||
b, err := br.ReadBits(1)
|
b, err := br.ReadBits(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -291,34 +257,19 @@ func NewDecRefPicMarking(br *bits.BitReader, idrPic bool, h *SliceHeader) (*DecR
|
||||||
d.AdaptiveRefPicMarkingModeFlag = b == 1
|
d.AdaptiveRefPicMarkingModeFlag = b == 1
|
||||||
|
|
||||||
if d.AdaptiveRefPicMarkingModeFlag {
|
if d.AdaptiveRefPicMarkingModeFlag {
|
||||||
d.MemoryManagementControlOperation, err = readUe(br)
|
d.MemoryManagementControlOperation = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse MemoryManagementControlOperation")
|
|
||||||
}
|
|
||||||
for d.MemoryManagementControlOperation != 0 {
|
for d.MemoryManagementControlOperation != 0 {
|
||||||
if d.MemoryManagementControlOperation == 1 || d.MemoryManagementControlOperation == 3 {
|
if d.MemoryManagementControlOperation == 1 || d.MemoryManagementControlOperation == 3 {
|
||||||
d.DifferenceOfPicNumsMinus1, err = readUe(br)
|
d.DifferenceOfPicNumsMinus1 = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse MemoryManagementControlOperation")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if d.MemoryManagementControlOperation == 2 {
|
if d.MemoryManagementControlOperation == 2 {
|
||||||
h.RefPicListModification.LongTermPicNum, err = readUe(br)
|
h.RefPicListModification.LongTermPicNum = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse LongTermPicNum")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if d.MemoryManagementControlOperation == 3 || d.MemoryManagementControlOperation == 6 {
|
if d.MemoryManagementControlOperation == 3 || d.MemoryManagementControlOperation == 6 {
|
||||||
d.LongTermFrameIdx, err = readUe(br)
|
d.LongTermFrameIdx = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse LongTermFrameIdx")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if d.MemoryManagementControlOperation == 4 {
|
if d.MemoryManagementControlOperation == 4 {
|
||||||
d.MaxLongTermFrameIdxPlus1, err = readUe(br)
|
d.MaxLongTermFrameIdxPlus1 = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse MaxLongTermFrameIdxPlus1")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -415,13 +366,13 @@ func (d SliceData) ae(v int) int {
|
||||||
// 8.2.2
|
// 8.2.2
|
||||||
func MbToSliceGroupMap(sps *SPS, pps *PPS, header *SliceHeader) []int {
|
func MbToSliceGroupMap(sps *SPS, pps *PPS, header *SliceHeader) []int {
|
||||||
mbaffFrameFlag := 0
|
mbaffFrameFlag := 0
|
||||||
if sps.MBAdaptiveFrameField && !header.FieldPic {
|
if sps.MBAdaptiveFrameFieldFlag && !header.FieldPic {
|
||||||
mbaffFrameFlag = 1
|
mbaffFrameFlag = 1
|
||||||
}
|
}
|
||||||
mapUnitToSliceGroupMap := MapUnitToSliceGroupMap(sps, pps, header)
|
mapUnitToSliceGroupMap := MapUnitToSliceGroupMap(sps, pps, header)
|
||||||
mbToSliceGroupMap := []int{}
|
mbToSliceGroupMap := []int{}
|
||||||
for i := 0; i <= PicSizeInMbs(sps, header)-1; i++ {
|
for i := 0; i <= PicSizeInMbs(sps, header)-1; i++ {
|
||||||
if sps.FrameMbsOnly || header.FieldPic {
|
if sps.FrameMBSOnlyFlag || header.FieldPic {
|
||||||
mbToSliceGroupMap = append(mbToSliceGroupMap, mapUnitToSliceGroupMap[i])
|
mbToSliceGroupMap = append(mbToSliceGroupMap, mapUnitToSliceGroupMap[i])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -429,7 +380,7 @@ func MbToSliceGroupMap(sps *SPS, pps *PPS, header *SliceHeader) []int {
|
||||||
mbToSliceGroupMap = append(mbToSliceGroupMap, mapUnitToSliceGroupMap[i/2])
|
mbToSliceGroupMap = append(mbToSliceGroupMap, mapUnitToSliceGroupMap[i/2])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !sps.FrameMbsOnly && !sps.MBAdaptiveFrameField && !header.FieldPic {
|
if !sps.FrameMBSOnlyFlag && !sps.MBAdaptiveFrameFieldFlag && !header.FieldPic {
|
||||||
mbToSliceGroupMap = append(
|
mbToSliceGroupMap = append(
|
||||||
mbToSliceGroupMap,
|
mbToSliceGroupMap,
|
||||||
mapUnitToSliceGroupMap[(i/(2*PicWidthInMbs(sps)))*PicWidthInMbs(sps)+(i%PicWidthInMbs(sps))])
|
mapUnitToSliceGroupMap[(i/(2*PicWidthInMbs(sps)))*PicWidthInMbs(sps)+(i%PicWidthInMbs(sps))])
|
||||||
|
@ -439,34 +390,34 @@ func MbToSliceGroupMap(sps *SPS, pps *PPS, header *SliceHeader) []int {
|
||||||
|
|
||||||
}
|
}
|
||||||
func PicWidthInMbs(sps *SPS) int {
|
func PicWidthInMbs(sps *SPS) int {
|
||||||
return sps.PicWidthInMbsMinus1 + 1
|
return int(sps.PicWidthInMBSMinus1 + 1)
|
||||||
}
|
}
|
||||||
func PicHeightInMapUnits(sps *SPS) int {
|
func PicHeightInMapUnits(sps *SPS) int {
|
||||||
return sps.PicHeightInMapUnitsMinus1 + 1
|
return int(sps.PicHeightInMapUnitsMinus1 + 1)
|
||||||
}
|
}
|
||||||
func PicSizeInMapUnits(sps *SPS) int {
|
func PicSizeInMapUnits(sps *SPS) int {
|
||||||
return PicWidthInMbs(sps) * PicHeightInMapUnits(sps)
|
return int(PicWidthInMbs(sps) * PicHeightInMapUnits(sps))
|
||||||
}
|
}
|
||||||
func FrameHeightInMbs(sps *SPS) int {
|
func FrameHeightInMbs(sps *SPS) int {
|
||||||
return (2 - flagVal(sps.FrameMbsOnly)) * PicHeightInMapUnits(sps)
|
return int((2 - flagVal(sps.FrameMBSOnlyFlag)) * PicHeightInMapUnits(sps))
|
||||||
}
|
}
|
||||||
func PicHeightInMbs(sps *SPS, header *SliceHeader) int {
|
func PicHeightInMbs(sps *SPS, header *SliceHeader) int {
|
||||||
return FrameHeightInMbs(sps) / (1 + flagVal(header.FieldPic))
|
return int(FrameHeightInMbs(sps) / (1 + flagVal(header.FieldPic)))
|
||||||
}
|
}
|
||||||
func PicSizeInMbs(sps *SPS, header *SliceHeader) int {
|
func PicSizeInMbs(sps *SPS, header *SliceHeader) int {
|
||||||
return PicWidthInMbs(sps) * PicHeightInMbs(sps, header)
|
return int(PicWidthInMbs(sps) * PicHeightInMbs(sps, header))
|
||||||
}
|
}
|
||||||
|
|
||||||
// table 6-1
|
// table 6-1
|
||||||
func SubWidthC(sps *SPS) int {
|
func SubWidthC(sps *SPS) int {
|
||||||
n := 17
|
n := 17
|
||||||
if sps.UseSeparateColorPlane {
|
if sps.SeparateColorPlaneFlag {
|
||||||
if sps.ChromaFormat == chroma444 {
|
if sps.ChromaFormatIDC == chroma444 {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch sps.ChromaFormat {
|
switch sps.ChromaFormatIDC {
|
||||||
case chromaMonochrome:
|
case chromaMonochrome:
|
||||||
return n
|
return n
|
||||||
case chroma420:
|
case chroma420:
|
||||||
|
@ -481,12 +432,12 @@ func SubWidthC(sps *SPS) int {
|
||||||
}
|
}
|
||||||
func SubHeightC(sps *SPS) int {
|
func SubHeightC(sps *SPS) int {
|
||||||
n := 17
|
n := 17
|
||||||
if sps.UseSeparateColorPlane {
|
if sps.SeparateColorPlaneFlag {
|
||||||
if sps.ChromaFormat == chroma444 {
|
if sps.ChromaFormatIDC == chroma444 {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch sps.ChromaFormat {
|
switch sps.ChromaFormatIDC {
|
||||||
case chromaMonochrome:
|
case chromaMonochrome:
|
||||||
return n
|
return n
|
||||||
case chroma420:
|
case chroma420:
|
||||||
|
@ -532,6 +483,7 @@ func NumMbPart(nalUnit *NALUnit, sps *SPS, header *SliceHeader, data *SliceData)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MbPred(sliceContext *SliceContext, br *bits.BitReader, rbsp []byte) error {
|
func MbPred(sliceContext *SliceContext, br *bits.BitReader, rbsp []byte) error {
|
||||||
|
r := newFieldReader(br)
|
||||||
var cabac *CABAC
|
var cabac *CABAC
|
||||||
sliceType := sliceTypeMap[sliceContext.Slice.Header.SliceType]
|
sliceType := sliceTypeMap[sliceContext.Slice.Header.SliceType]
|
||||||
mbPartPredMode, err := MbPartPredMode(sliceContext.Slice.Data, sliceType, sliceContext.Slice.Data.MbType, 0)
|
mbPartPredMode, err := MbPartPredMode(sliceContext.Slice.Data, sliceType, sliceContext.Slice.Data.MbType, 0)
|
||||||
|
@ -642,11 +594,7 @@ func MbPred(sliceContext *SliceContext, br *bits.BitReader, rbsp []byte) error {
|
||||||
|
|
||||||
logger.Printf("TODO: ae for IntraChromaPredMode\n")
|
logger.Printf("TODO: ae for IntraChromaPredMode\n")
|
||||||
} else {
|
} else {
|
||||||
var err error
|
sliceContext.Slice.Data.IntraChromaPredMode = int(r.readUe())
|
||||||
sliceContext.Slice.Data.IntraChromaPredMode, err = readUe(br)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "could not parse IntraChromaPredMode")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -675,14 +623,10 @@ func MbPred(sliceContext *SliceContext, br *bits.BitReader, rbsp []byte) error {
|
||||||
// TODO: Only one reference picture is used for inter-prediction,
|
// TODO: Only one reference picture is used for inter-prediction,
|
||||||
// then the value should be 0
|
// then the value should be 0
|
||||||
if MbaffFrameFlag(sliceContext.SPS, sliceContext.Slice.Header) == 0 || !sliceContext.Slice.Data.MbFieldDecodingFlag {
|
if MbaffFrameFlag(sliceContext.SPS, sliceContext.Slice.Header) == 0 || !sliceContext.Slice.Data.MbFieldDecodingFlag {
|
||||||
sliceContext.Slice.Data.RefIdxL0[mbPartIdx], _ = readTe(
|
sliceContext.Slice.Data.RefIdxL0[mbPartIdx] = int(r.readTe(uint(sliceContext.Slice.Header.NumRefIdxL0ActiveMinus1)))
|
||||||
br,
|
|
||||||
uint(sliceContext.Slice.Header.NumRefIdxL0ActiveMinus1))
|
|
||||||
} else {
|
} else {
|
||||||
rangeMax := 2*sliceContext.Slice.Header.NumRefIdxL0ActiveMinus1 + 1
|
rangeMax := 2*sliceContext.Slice.Header.NumRefIdxL0ActiveMinus1 + 1
|
||||||
sliceContext.Slice.Data.RefIdxL0[mbPartIdx], _ = readTe(
|
sliceContext.Slice.Data.RefIdxL0[mbPartIdx] = int(r.readTe(uint(rangeMax)))
|
||||||
br,
|
|
||||||
uint(rangeMax))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -848,19 +792,19 @@ func nextMbAddress(n int, sps *SPS, pps *PPS, header *SliceHeader) int {
|
||||||
i := n + 1
|
i := n + 1
|
||||||
// picSizeInMbs is the number of macroblocks in picture 0
|
// picSizeInMbs is the number of macroblocks in picture 0
|
||||||
// 7-13
|
// 7-13
|
||||||
// PicWidthInMbs = sps.PicWidthInMbsMinus1 + 1
|
// PicWidthInMbs = sps.PicWidthInMBSMinus1 + 1
|
||||||
// PicHeightInMapUnits = sps.PicHeightInMapUnitsMinus1 + 1
|
// PicHeightInMapUnits = sps.PicHeightInMapUnitsMinus1 + 1
|
||||||
// 7-29
|
// 7-29
|
||||||
// picSizeInMbs = PicWidthInMbs * PicHeightInMbs
|
// picSizeInMbs = PicWidthInMbs * PicHeightInMbs
|
||||||
// 7-26
|
// 7-26
|
||||||
// PicHeightInMbs = FrameHeightInMbs / (1 + header.fieldPicFlag)
|
// PicHeightInMbs = FrameHeightInMbs / (1 + header.fieldPicFlag)
|
||||||
// 7-18
|
// 7-18
|
||||||
// FrameHeightInMbs = (2 - ps.FrameMbsOnly) * PicHeightInMapUnits
|
// FrameHeightInMbs = (2 - ps.FrameMBSOnlyFlag) * PicHeightInMapUnits
|
||||||
picWidthInMbs := sps.PicWidthInMbsMinus1 + 1
|
picWidthInMbs := sps.PicWidthInMBSMinus1 + 1
|
||||||
picHeightInMapUnits := sps.PicHeightInMapUnitsMinus1 + 1
|
picHeightInMapUnits := sps.PicHeightInMapUnitsMinus1 + 1
|
||||||
frameHeightInMbs := (2 - flagVal(sps.FrameMbsOnly)) * picHeightInMapUnits
|
frameHeightInMbs := (2 - flagVal(sps.FrameMBSOnlyFlag)) * int(picHeightInMapUnits)
|
||||||
picHeightInMbs := frameHeightInMbs / (1 + flagVal(header.FieldPic))
|
picHeightInMbs := frameHeightInMbs / (1 + flagVal(header.FieldPic))
|
||||||
picSizeInMbs := picWidthInMbs * picHeightInMbs
|
picSizeInMbs := int(picWidthInMbs) * picHeightInMbs
|
||||||
mbToSliceGroupMap := MbToSliceGroupMap(sps, pps, header)
|
mbToSliceGroupMap := MbToSliceGroupMap(sps, pps, header)
|
||||||
for i < picSizeInMbs && mbToSliceGroupMap[i] != mbToSliceGroupMap[i] {
|
for i < picSizeInMbs && mbToSliceGroupMap[i] != mbToSliceGroupMap[i] {
|
||||||
i++
|
i++
|
||||||
|
@ -870,7 +814,7 @@ func nextMbAddress(n int, sps *SPS, pps *PPS, header *SliceHeader) int {
|
||||||
|
|
||||||
func CurrMbAddr(sps *SPS, header *SliceHeader) int {
|
func CurrMbAddr(sps *SPS, header *SliceHeader) int {
|
||||||
mbaffFrameFlag := 0
|
mbaffFrameFlag := 0
|
||||||
if sps.MBAdaptiveFrameField && !header.FieldPic {
|
if sps.MBAdaptiveFrameFieldFlag && !header.FieldPic {
|
||||||
mbaffFrameFlag = 1
|
mbaffFrameFlag = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -878,15 +822,15 @@ func CurrMbAddr(sps *SPS, header *SliceHeader) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func MbaffFrameFlag(sps *SPS, header *SliceHeader) int {
|
func MbaffFrameFlag(sps *SPS, header *SliceHeader) int {
|
||||||
if sps.MBAdaptiveFrameField && !header.FieldPic {
|
if sps.MBAdaptiveFrameFieldFlag && !header.FieldPic {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSliceData(sliceContext *SliceContext, br *bits.BitReader) (*SliceData, error) {
|
func NewSliceData(sliceContext *SliceContext, br *bits.BitReader) (*SliceData, error) {
|
||||||
|
r := newFieldReader(br)
|
||||||
var cabac *CABAC
|
var cabac *CABAC
|
||||||
var err error
|
|
||||||
sliceContext.Slice.Data = &SliceData{BitReader: br}
|
sliceContext.Slice.Data = &SliceData{BitReader: br}
|
||||||
// TODO: Why is this being initialized here?
|
// TODO: Why is this being initialized here?
|
||||||
// initCabac(sliceContext)
|
// initCabac(sliceContext)
|
||||||
|
@ -900,7 +844,7 @@ func NewSliceData(sliceContext *SliceContext, br *bits.BitReader) (*SliceData, e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mbaffFrameFlag := 0
|
mbaffFrameFlag := 0
|
||||||
if sliceContext.SPS.MBAdaptiveFrameField && !sliceContext.Slice.Header.FieldPic {
|
if sliceContext.SPS.MBAdaptiveFrameFieldFlag && !sliceContext.Slice.Header.FieldPic {
|
||||||
mbaffFrameFlag = 1
|
mbaffFrameFlag = 1
|
||||||
}
|
}
|
||||||
currMbAddr := sliceContext.Slice.Header.FirstMbInSlice * (1 * mbaffFrameFlag)
|
currMbAddr := sliceContext.Slice.Header.FirstMbInSlice * (1 * mbaffFrameFlag)
|
||||||
|
@ -915,10 +859,7 @@ func NewSliceData(sliceContext *SliceContext, br *bits.BitReader) (*SliceData, e
|
||||||
if sliceContext.Slice.Data.SliceTypeName != "I" && sliceContext.Slice.Data.SliceTypeName != "SI" {
|
if sliceContext.Slice.Data.SliceTypeName != "I" && sliceContext.Slice.Data.SliceTypeName != "SI" {
|
||||||
logger.Printf("debug: \tNonI/SI slice, processing moreData\n")
|
logger.Printf("debug: \tNonI/SI slice, processing moreData\n")
|
||||||
if sliceContext.PPS.EntropyCodingMode == 0 {
|
if sliceContext.PPS.EntropyCodingMode == 0 {
|
||||||
sliceContext.Slice.Data.MbSkipRun, err = readUe(br)
|
sliceContext.Slice.Data.MbSkipRun = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse MbSkipRun")
|
|
||||||
}
|
|
||||||
|
|
||||||
if sliceContext.Slice.Data.MbSkipRun > 0 {
|
if sliceContext.Slice.Data.MbSkipRun > 0 {
|
||||||
prevMbSkipped = 1
|
prevMbSkipped = 1
|
||||||
|
@ -1032,10 +973,7 @@ func NewSliceData(sliceContext *SliceContext, br *bits.BitReader) (*SliceData, e
|
||||||
|
|
||||||
logger.Printf("TODO: ae for MBType\n")
|
logger.Printf("TODO: ae for MBType\n")
|
||||||
} else {
|
} else {
|
||||||
sliceContext.Slice.Data.MbType, err = readUe(br)
|
sliceContext.Slice.Data.MbType = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse MbType")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if sliceContext.Slice.Data.MbTypeName == "I_PCM" {
|
if sliceContext.Slice.Data.MbTypeName == "I_PCM" {
|
||||||
for !br.ByteAligned() {
|
for !br.ByteAligned() {
|
||||||
|
@ -1047,7 +985,7 @@ func NewSliceData(sliceContext *SliceContext, br *bits.BitReader) (*SliceData, e
|
||||||
// 7-3 p95
|
// 7-3 p95
|
||||||
bitDepthY := 8 + sliceContext.SPS.BitDepthLumaMinus8
|
bitDepthY := 8 + sliceContext.SPS.BitDepthLumaMinus8
|
||||||
for i := 0; i < 256; i++ {
|
for i := 0; i < 256; i++ {
|
||||||
s, err := br.ReadBits(bitDepthY)
|
s, err := br.ReadBits(int(bitDepthY))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, fmt.Sprintf("could not read PcmSampleLuma[%d]", i))
|
return nil, errors.Wrap(err, fmt.Sprintf("could not read PcmSampleLuma[%d]", i))
|
||||||
}
|
}
|
||||||
|
@ -1061,14 +999,14 @@ func NewSliceData(sliceContext *SliceContext, br *bits.BitReader) (*SliceData, e
|
||||||
mbWidthC := 16 / SubWidthC(sliceContext.SPS)
|
mbWidthC := 16 / SubWidthC(sliceContext.SPS)
|
||||||
mbHeightC := 16 / SubHeightC(sliceContext.SPS)
|
mbHeightC := 16 / SubHeightC(sliceContext.SPS)
|
||||||
// if monochrome
|
// if monochrome
|
||||||
if sliceContext.SPS.ChromaFormat == chromaMonochrome || sliceContext.SPS.UseSeparateColorPlane {
|
if sliceContext.SPS.ChromaFormatIDC == chromaMonochrome || sliceContext.SPS.SeparateColorPlaneFlag {
|
||||||
mbWidthC = 0
|
mbWidthC = 0
|
||||||
mbHeightC = 0
|
mbHeightC = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
bitDepthC := 8 + sliceContext.SPS.BitDepthChromaMinus8
|
bitDepthC := 8 + sliceContext.SPS.BitDepthChromaMinus8
|
||||||
for i := 0; i < 2*mbWidthC*mbHeightC; i++ {
|
for i := 0; i < 2*mbWidthC*mbHeightC; i++ {
|
||||||
s, err := br.ReadBits(bitDepthC)
|
s, err := br.ReadBits(int(bitDepthC))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, fmt.Sprintf("could not read PcmSampleChroma[%d]", i))
|
return nil, errors.Wrap(err, fmt.Sprintf("could not read PcmSampleChroma[%d]", i))
|
||||||
}
|
}
|
||||||
|
@ -1094,7 +1032,7 @@ func NewSliceData(sliceContext *SliceContext, br *bits.BitReader) (*SliceData, e
|
||||||
if NumbSubMbPart(subMbType[mbPartIdx]) > 1 {
|
if NumbSubMbPart(subMbType[mbPartIdx]) > 1 {
|
||||||
noSubMbPartSizeLessThan8x8Flag = 0
|
noSubMbPartSizeLessThan8x8Flag = 0
|
||||||
}
|
}
|
||||||
} else if !sliceContext.SPS.Direct8x8Inference {
|
} else if !sliceContext.SPS.Direct8x8InferenceFlag {
|
||||||
noSubMbPartSizeLessThan8x8Flag = 0
|
noSubMbPartSizeLessThan8x8Flag = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1146,7 +1084,7 @@ func NewSliceData(sliceContext *SliceContext, br *bits.BitReader) (*SliceData, e
|
||||||
}
|
}
|
||||||
|
|
||||||
// sliceContext.Slice.Data.CodedBlockPattern = me(v) | ae(v)
|
// sliceContext.Slice.Data.CodedBlockPattern = me(v) | ae(v)
|
||||||
if CodedBlockPatternLuma(sliceContext.Slice.Data) > 0 && sliceContext.PPS.Transform8x8Mode == 1 && sliceContext.Slice.Data.MbTypeName != "I_NxN" && noSubMbPartSizeLessThan8x8Flag == 1 && (sliceContext.Slice.Data.MbTypeName != "B_Direct_16x16" || sliceContext.SPS.Direct8x8Inference) {
|
if CodedBlockPatternLuma(sliceContext.Slice.Data) > 0 && sliceContext.PPS.Transform8x8Mode == 1 && sliceContext.Slice.Data.MbTypeName != "I_NxN" && noSubMbPartSizeLessThan8x8Flag == 1 && (sliceContext.Slice.Data.MbTypeName != "B_Direct_16x16" || sliceContext.SPS.Direct8x8InferenceFlag) {
|
||||||
// TODO: 1 bit or ae(v)
|
// TODO: 1 bit or ae(v)
|
||||||
if sliceContext.PPS.EntropyCodingMode == 1 {
|
if sliceContext.PPS.EntropyCodingMode == 1 {
|
||||||
binarization := NewBinarization("Transform8x8Flag", sliceContext.Slice.Data)
|
binarization := NewBinarization("Transform8x8Flag", sliceContext.Slice.Data)
|
||||||
|
@ -1226,31 +1164,21 @@ func NewSliceContext(videoStream *VideoStream, nalUnit *NALUnit, rbsp []byte, sh
|
||||||
idrPic = true
|
idrPic = true
|
||||||
}
|
}
|
||||||
header := SliceHeader{}
|
header := SliceHeader{}
|
||||||
if sps.UseSeparateColorPlane {
|
if sps.SeparateColorPlaneFlag {
|
||||||
header.ChromaArrayType = 0
|
header.ChromaArrayType = 0
|
||||||
} else {
|
} else {
|
||||||
header.ChromaArrayType = sps.ChromaFormat
|
header.ChromaArrayType = int(sps.ChromaFormatIDC)
|
||||||
}
|
}
|
||||||
br := bits.NewBitReader(bytes.NewReader(rbsp))
|
br := bits.NewBitReader(bytes.NewReader(rbsp))
|
||||||
|
r := newFieldReader(br)
|
||||||
|
|
||||||
header.FirstMbInSlice, err = readUe(br)
|
header.FirstMbInSlice = int(r.readUe())
|
||||||
if err != nil {
|
header.SliceType = int(r.readUe())
|
||||||
return nil, errors.Wrap(err, "could not parse FirstMbInSlice")
|
|
||||||
}
|
|
||||||
|
|
||||||
header.SliceType, err = readUe(br)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse SliceType")
|
|
||||||
}
|
|
||||||
|
|
||||||
sliceType := sliceTypeMap[header.SliceType]
|
sliceType := sliceTypeMap[header.SliceType]
|
||||||
logger.Printf("debug: %s (%s) slice of %d bytes\n", NALUnitType[int(nalUnit.Type)], sliceType, len(rbsp))
|
logger.Printf("debug: %s (%s) slice of %d bytes\n", NALUnitType[int(nalUnit.Type)], sliceType, len(rbsp))
|
||||||
header.PPSID, err = readUe(br)
|
header.PPSID = int(r.readUe())
|
||||||
if err != nil {
|
if sps.SeparateColorPlaneFlag {
|
||||||
return nil, errors.Wrap(err, "could not parse PPSID")
|
|
||||||
}
|
|
||||||
|
|
||||||
if sps.UseSeparateColorPlane {
|
|
||||||
b, err := br.ReadBits(2)
|
b, err := br.ReadBits(2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not read ColorPlaneID")
|
return nil, errors.Wrap(err, "could not read ColorPlaneID")
|
||||||
|
@ -1259,7 +1187,7 @@ func NewSliceContext(videoStream *VideoStream, nalUnit *NALUnit, rbsp []byte, sh
|
||||||
}
|
}
|
||||||
// TODO: See 7.4.3
|
// TODO: See 7.4.3
|
||||||
// header.FrameNum = b.NextField("FrameNum", 0)
|
// header.FrameNum = b.NextField("FrameNum", 0)
|
||||||
if !sps.FrameMbsOnly {
|
if !sps.FrameMBSOnlyFlag {
|
||||||
b, err := br.ReadBits(1)
|
b, err := br.ReadBits(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not read FieldPic")
|
return nil, errors.Wrap(err, "could not read FieldPic")
|
||||||
|
@ -1274,13 +1202,10 @@ func NewSliceContext(videoStream *VideoStream, nalUnit *NALUnit, rbsp []byte, sh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if idrPic {
|
if idrPic {
|
||||||
header.IDRPicID, err = readUe(br)
|
header.IDRPicID = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse IDRPicID")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if sps.PicOrderCountType == 0 {
|
if sps.PicOrderCountType == 0 {
|
||||||
b, err := br.ReadBits(sps.Log2MaxPicOrderCntLSBMin4 + 4)
|
b, err := br.ReadBits(int(sps.Log2MaxPicOrderCntLSBMin4 + 4))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not read PicOrderCntLsb")
|
return nil, errors.Wrap(err, "could not read PicOrderCntLsb")
|
||||||
}
|
}
|
||||||
|
@ -1293,7 +1218,7 @@ func NewSliceContext(videoStream *VideoStream, nalUnit *NALUnit, rbsp []byte, sh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if sps.PicOrderCountType == 1 && !sps.DeltaPicOrderAlwaysZero {
|
if sps.PicOrderCountType == 1 && !sps.DeltaPicOrderAlwaysZeroFlag {
|
||||||
header.DeltaPicOrderCnt[0], err = readSe(br)
|
header.DeltaPicOrderCnt[0], err = readSe(br)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not parse DeltaPicOrderCnt")
|
return nil, errors.Wrap(err, "could not parse DeltaPicOrderCnt")
|
||||||
|
@ -1307,10 +1232,7 @@ func NewSliceContext(videoStream *VideoStream, nalUnit *NALUnit, rbsp []byte, sh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pps.RedundantPicCntPresent {
|
if pps.RedundantPicCntPresent {
|
||||||
header.RedundantPicCnt, err = readUe(br)
|
header.RedundantPicCnt = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse RedundantPicCnt")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if sliceType == "B" {
|
if sliceType == "B" {
|
||||||
b, err := br.ReadBits(1)
|
b, err := br.ReadBits(1)
|
||||||
|
@ -1327,15 +1249,9 @@ func NewSliceContext(videoStream *VideoStream, nalUnit *NALUnit, rbsp []byte, sh
|
||||||
header.NumRefIdxActiveOverride = b == 1
|
header.NumRefIdxActiveOverride = b == 1
|
||||||
|
|
||||||
if header.NumRefIdxActiveOverride {
|
if header.NumRefIdxActiveOverride {
|
||||||
header.NumRefIdxL0ActiveMinus1, err = readUe(br)
|
header.NumRefIdxL0ActiveMinus1 = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse NumRefIdxL0ActiveMinus1")
|
|
||||||
}
|
|
||||||
if sliceType == "B" {
|
if sliceType == "B" {
|
||||||
header.NumRefIdxL1ActiveMinus1, err = readUe(br)
|
header.NumRefIdxL1ActiveMinus1 = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse NumRefIdxL1ActiveMinus1")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1365,35 +1281,18 @@ func NewSliceContext(videoStream *VideoStream, nalUnit *NALUnit, rbsp []byte, sh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pps.EntropyCodingMode == 1 && sliceType != "I" && sliceType != "SI" {
|
if pps.EntropyCodingMode == 1 && sliceType != "I" && sliceType != "SI" {
|
||||||
header.CabacInit, err = readUe(br)
|
header.CabacInit = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse CabacInit")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
header.SliceQpDelta, err = readSe(br)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse SliceQpDelta")
|
|
||||||
}
|
}
|
||||||
|
header.SliceQpDelta = int(r.readSe())
|
||||||
|
|
||||||
if sliceType == "SP" || sliceType == "SI" {
|
if sliceType == "SP" || sliceType == "SI" {
|
||||||
if sliceType == "SP" {
|
if sliceType == "SP" {
|
||||||
b, err := br.ReadBits(1)
|
header.SpForSwitch = r.readBits(1) == 1
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not read SpForSwitch")
|
|
||||||
}
|
|
||||||
header.SpForSwitch = b == 1
|
|
||||||
}
|
|
||||||
header.SliceQsDelta, err = readSe(br)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse SliceQsDelta")
|
|
||||||
}
|
}
|
||||||
|
header.SliceQsDelta = int(r.readSe())
|
||||||
}
|
}
|
||||||
if pps.DeblockingFilterControlPresent {
|
if pps.DeblockingFilterControlPresent {
|
||||||
header.DisableDeblockingFilter, err = readUe(br)
|
header.DisableDeblockingFilter = int(r.readUe())
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not parse DisableDeblockingFilter")
|
|
||||||
}
|
|
||||||
|
|
||||||
if header.DisableDeblockingFilter != 1 {
|
if header.DisableDeblockingFilter != 1 {
|
||||||
header.SliceAlphaC0OffsetDiv2, err = readSe(br)
|
header.SliceAlphaC0OffsetDiv2, err = readSe(br)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1426,9 +1325,6 @@ func NewSliceContext(videoStream *VideoStream, nalUnit *NALUnit, rbsp []byte, sh
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not create slice data")
|
return nil, errors.Wrap(err, "could not create slice data")
|
||||||
}
|
}
|
||||||
if showPacket {
|
|
||||||
debugPacket("debug: Header", sliceContext.Slice.Header)
|
|
||||||
debugPacket("debug: Data", sliceContext.Slice.Data)
|
|
||||||
}
|
|
||||||
return sliceContext, nil
|
return sliceContext, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,12 @@ var subWidthCTests = []struct {
|
||||||
want int
|
want int
|
||||||
}{
|
}{
|
||||||
{SPS{}, 17},
|
{SPS{}, 17},
|
||||||
{SPS{ChromaFormat: 0}, 17},
|
{SPS{ChromaFormatIDC: 0}, 17},
|
||||||
{SPS{ChromaFormat: 1}, 2},
|
{SPS{ChromaFormatIDC: 1}, 2},
|
||||||
{SPS{ChromaFormat: 2}, 2},
|
{SPS{ChromaFormatIDC: 2}, 2},
|
||||||
{SPS{ChromaFormat: 3}, 1},
|
{SPS{ChromaFormatIDC: 3}, 1},
|
||||||
{SPS{ChromaFormat: 3, UseSeparateColorPlane: true}, 17},
|
{SPS{ChromaFormatIDC: 3, SeparateColorPlaneFlag: true}, 17},
|
||||||
{SPS{ChromaFormat: 999}, 17},
|
{SPS{ChromaFormatIDC: 999}, 17},
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSubWidthC tests that the correct SubWidthC is returned given
|
// TestSubWidthC tests that the correct SubWidthC is returned given
|
||||||
|
@ -30,12 +30,12 @@ var subHeightCTests = []struct {
|
||||||
want int
|
want int
|
||||||
}{
|
}{
|
||||||
{SPS{}, 17},
|
{SPS{}, 17},
|
||||||
{SPS{ChromaFormat: 0}, 17},
|
{SPS{ChromaFormatIDC: 0}, 17},
|
||||||
{SPS{ChromaFormat: 1}, 2},
|
{SPS{ChromaFormatIDC: 1}, 2},
|
||||||
{SPS{ChromaFormat: 2}, 1},
|
{SPS{ChromaFormatIDC: 2}, 1},
|
||||||
{SPS{ChromaFormat: 3}, 1},
|
{SPS{ChromaFormatIDC: 3}, 1},
|
||||||
{SPS{ChromaFormat: 3, UseSeparateColorPlane: true}, 17},
|
{SPS{ChromaFormatIDC: 3, SeparateColorPlaneFlag: true}, 17},
|
||||||
{SPS{ChromaFormat: 999}, 17},
|
{SPS{ChromaFormatIDC: 999}, 17},
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSubHeightC tests that the correct SubHeightC is returned given
|
// TestSubHeightC tests that the correct SubHeightC is returned given
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue