2019-08-04 07:15:28 +03:00
|
|
|
/*
|
|
|
|
DESCRIPTION
|
2019-08-20 05:26:42 +03:00
|
|
|
slice.go provides parsing functionality for slice raw byte sequence data.
|
2019-08-04 07:15:28 +03:00
|
|
|
|
|
|
|
AUTHORS
|
|
|
|
Saxon Nelson-Milton <saxon@ausocean.org>, The Australian Ocean Laboratory (AusOcean)
|
2019-08-20 05:26:42 +03:00
|
|
|
Bruce McMoran <mcmoranbjr@gmail.com>
|
2019-08-04 07:15:28 +03:00
|
|
|
*/
|
|
|
|
|
2019-07-19 08:50:39 +03:00
|
|
|
package h264dec
|
2019-07-18 07:32:42 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
|
2019-07-19 09:14:45 +03:00
|
|
|
"bitbucket.org/ausocean/av/codec/h264/h264dec/bits"
|
2019-07-18 07:32:42 +03:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2019-08-19 09:54:53 +03:00
|
|
|
// Slice types as defined by table 7-6 in specifications.
|
2019-08-14 07:38:24 +03:00
|
|
|
const (
|
|
|
|
sliceTypeP = 0
|
|
|
|
sliceTypeB = 1
|
|
|
|
sliceTypeI = 2
|
|
|
|
sliceTypeSP = 3
|
|
|
|
sliceTypeSI = 4
|
|
|
|
)
|
|
|
|
|
2019-07-18 07:32:42 +03:00
|
|
|
// Chroma formats as defined in section 6.2, tab 6-1.
|
|
|
|
const (
|
|
|
|
chromaMonochrome = iota
|
|
|
|
chroma420
|
|
|
|
chroma422
|
|
|
|
chroma444
|
|
|
|
)
|
|
|
|
|
|
|
|
type VideoStream struct {
|
2019-09-09 04:38:48 +03:00
|
|
|
*SPS
|
|
|
|
*PPS
|
2019-07-18 07:32:42 +03:00
|
|
|
Slices []*SliceContext
|
2019-08-04 18:47:19 +03:00
|
|
|
|
|
|
|
ChromaArrayType int
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
|
2019-07-18 07:32:42 +03:00
|
|
|
type SliceContext struct {
|
2019-07-19 14:28:01 +03:00
|
|
|
*NALUnit
|
2019-07-18 07:32:42 +03:00
|
|
|
*Slice
|
2019-09-06 05:19:28 +03:00
|
|
|
chromaArrayType int
|
|
|
|
nalType int
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
|
2019-07-18 07:32:42 +03:00
|
|
|
type Slice struct {
|
2019-09-09 04:38:48 +03:00
|
|
|
*SliceHeader
|
|
|
|
*SliceData
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-07-22 06:26:37 +03:00
|
|
|
|
|
|
|
// RefPicListModification provides elements of a ref_pic_list_modification syntax
|
|
|
|
// (defined in 7.3.3.1 of specifications) and a ref_pic_list_mvc_modification
|
|
|
|
// (defined in H.7.3.3.1.1 of specifications).
|
|
|
|
type RefPicListModification struct {
|
2019-08-04 06:29:13 +03:00
|
|
|
RefPicListModificationFlag [2]bool
|
|
|
|
ModificationOfPicNums [2][]int
|
|
|
|
AbsDiffPicNumMinus1 [2][]int
|
|
|
|
LongTermPicNum [2][]int
|
2019-07-22 06:26:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: need to complete this.
|
|
|
|
// NewRefPicListMVCModification parses elements of a ref_pic_list_mvc_modification
|
|
|
|
// following the syntax structure defined in section H.7.3.3.1.1, and returns as
|
|
|
|
// a new RefPicListModification.
|
|
|
|
func NewRefPicListMVCModifiation(br *bits.BitReader) (*RefPicListModification, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewRefPicListModification parses elements of a ref_pic_list_modification
|
|
|
|
// following the syntax structure defined in section 7.3.3.1, and returns as
|
|
|
|
// a new RefPicListModification.
|
2019-08-04 06:29:13 +03:00
|
|
|
func NewRefPicListModification(br *bits.BitReader, p *PPS, s *SliceHeader) (*RefPicListModification, error) {
|
2019-07-22 06:26:37 +03:00
|
|
|
r := &RefPicListModification{}
|
2019-08-04 06:29:13 +03:00
|
|
|
r.ModificationOfPicNums[0] = make([]int, p.NumRefIdxL0DefaultActiveMinus1+2)
|
|
|
|
r.ModificationOfPicNums[1] = make([]int, p.NumRefIdxL1DefaultActiveMinus1+2)
|
2019-08-04 07:10:53 +03:00
|
|
|
r.AbsDiffPicNumMinus1[0] = make([]int, p.NumRefIdxL0DefaultActiveMinus1+2)
|
2019-08-04 06:29:13 +03:00
|
|
|
r.AbsDiffPicNumMinus1[1] = make([]int, p.NumRefIdxL1DefaultActiveMinus1+2)
|
2019-08-04 07:10:53 +03:00
|
|
|
r.LongTermPicNum[0] = make([]int, p.NumRefIdxL0DefaultActiveMinus1+2)
|
2019-08-04 06:29:13 +03:00
|
|
|
r.LongTermPicNum[1] = make([]int, p.NumRefIdxL1DefaultActiveMinus1+2)
|
|
|
|
fr := newFieldReader(br)
|
|
|
|
|
2019-07-22 06:26:37 +03:00
|
|
|
// 7.3.3.1
|
2019-08-04 06:29:13 +03:00
|
|
|
if s.SliceType%5 != 2 && s.SliceType%5 != 4 {
|
|
|
|
r.RefPicListModificationFlag[0] = fr.readBits(1) == 1
|
2019-07-22 06:26:37 +03:00
|
|
|
|
2019-08-04 06:29:13 +03:00
|
|
|
if r.RefPicListModificationFlag[0] {
|
|
|
|
for i := 0; ; i++ {
|
2019-08-05 08:11:26 +03:00
|
|
|
r.ModificationOfPicNums[0][i] = int(fr.readUe())
|
2019-07-22 06:26:37 +03:00
|
|
|
|
2019-08-04 06:29:13 +03:00
|
|
|
if r.ModificationOfPicNums[0][i] == 0 || r.ModificationOfPicNums[0][i] == 1 {
|
2019-08-05 08:11:26 +03:00
|
|
|
r.AbsDiffPicNumMinus1[0][i] = int(fr.readUe())
|
2019-08-04 06:29:13 +03:00
|
|
|
} else if r.ModificationOfPicNums[0][i] == 2 {
|
2019-08-05 08:11:26 +03:00
|
|
|
r.LongTermPicNum[0][i] = int(fr.readUe())
|
2019-07-22 06:26:37 +03:00
|
|
|
}
|
|
|
|
|
2019-08-04 06:29:13 +03:00
|
|
|
if r.ModificationOfPicNums[0][i] == 3 {
|
|
|
|
break
|
2019-07-22 06:26:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-04 06:29:13 +03:00
|
|
|
if s.SliceType%5 == 1 {
|
|
|
|
r.RefPicListModificationFlag[1] = fr.readBits(1) == 1
|
|
|
|
|
|
|
|
if r.RefPicListModificationFlag[1] {
|
|
|
|
for i := 0; ; i++ {
|
2019-08-05 08:11:26 +03:00
|
|
|
r.ModificationOfPicNums[1][i] = int(fr.readUe())
|
2019-08-04 06:29:13 +03:00
|
|
|
|
|
|
|
if r.ModificationOfPicNums[1][i] == 0 || r.ModificationOfPicNums[1][i] == 1 {
|
2019-08-05 08:11:26 +03:00
|
|
|
r.AbsDiffPicNumMinus1[1][i] = int(fr.readUe())
|
2019-08-04 06:29:13 +03:00
|
|
|
} else if r.ModificationOfPicNums[1][i] == 2 {
|
2019-08-05 08:11:26 +03:00
|
|
|
r.LongTermPicNum[1][i] = int(fr.readUe())
|
2019-07-22 06:26:37 +03:00
|
|
|
}
|
|
|
|
|
2019-08-04 06:29:13 +03:00
|
|
|
if r.ModificationOfPicNums[1][i] == 3 {
|
|
|
|
break
|
2019-07-22 06:26:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-04 06:29:13 +03:00
|
|
|
return r, nil
|
2019-07-22 06:26:37 +03:00
|
|
|
}
|
|
|
|
|
2019-07-22 07:31:23 +03:00
|
|
|
// PredWeightTable provides elements of a pred_weight_table syntax structure
|
|
|
|
// as defined in section 7.3.3.2 of the specifications.
|
|
|
|
type PredWeightTable struct {
|
|
|
|
LumaLog2WeightDenom int
|
|
|
|
ChromaLog2WeightDenom int
|
|
|
|
LumaWeightL0Flag bool
|
|
|
|
LumaWeightL0 []int
|
|
|
|
LumaOffsetL0 []int
|
|
|
|
ChromaWeightL0Flag bool
|
|
|
|
ChromaWeightL0 [][]int
|
|
|
|
ChromaOffsetL0 [][]int
|
|
|
|
LumaWeightL1Flag bool
|
|
|
|
LumaWeightL1 []int
|
|
|
|
LumaOffsetL1 []int
|
|
|
|
ChromaWeightL1Flag bool
|
|
|
|
ChromaWeightL1 [][]int
|
|
|
|
ChromaOffsetL1 [][]int
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewPredWeightTable parses elements of a pred_weight_table following the
|
|
|
|
// syntax structure defined in section 7.3.3.2, and returns as a new
|
|
|
|
// PredWeightTable.
|
2019-08-04 18:47:19 +03:00
|
|
|
func NewPredWeightTable(br *bits.BitReader, h *SliceHeader, chromaArrayType int) (*PredWeightTable, error) {
|
2019-07-22 07:31:23 +03:00
|
|
|
p := &PredWeightTable{}
|
2019-08-05 07:16:02 +03:00
|
|
|
r := newFieldReader(br)
|
2019-07-22 07:31:23 +03:00
|
|
|
|
2019-08-05 07:16:02 +03:00
|
|
|
p.LumaLog2WeightDenom = int(r.readUe())
|
2019-07-22 07:31:23 +03:00
|
|
|
|
2019-08-04 18:47:19 +03:00
|
|
|
if chromaArrayType != 0 {
|
2019-08-05 07:16:02 +03:00
|
|
|
p.ChromaLog2WeightDenom = int(r.readUe())
|
2019-07-22 07:31:23 +03:00
|
|
|
}
|
|
|
|
for i := 0; i <= h.NumRefIdxL0ActiveMinus1; i++ {
|
2019-08-05 07:16:02 +03:00
|
|
|
p.LumaWeightL0Flag = r.readBits(1) == 1
|
2019-07-22 07:31:23 +03:00
|
|
|
|
|
|
|
if p.LumaWeightL0Flag {
|
|
|
|
se, err := readSe(br)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse LumaWeightL0")
|
|
|
|
}
|
|
|
|
p.LumaWeightL0 = append(p.LumaWeightL0, se)
|
|
|
|
|
|
|
|
se, err = readSe(br)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse LumaOffsetL0")
|
|
|
|
}
|
|
|
|
p.LumaOffsetL0 = append(p.LumaOffsetL0, se)
|
|
|
|
}
|
2019-08-04 18:47:19 +03:00
|
|
|
if chromaArrayType != 0 {
|
2019-07-22 07:31:23 +03:00
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read ChromaWeightL0Flag")
|
|
|
|
}
|
|
|
|
p.ChromaWeightL0Flag = b == 1
|
|
|
|
|
|
|
|
if p.ChromaWeightL0Flag {
|
|
|
|
p.ChromaWeightL0 = append(p.ChromaWeightL0, []int{})
|
|
|
|
p.ChromaOffsetL0 = append(p.ChromaOffsetL0, []int{})
|
|
|
|
for j := 0; j < 2; j++ {
|
|
|
|
se, err := readSe(br)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse ChromaWeightL0")
|
|
|
|
}
|
|
|
|
p.ChromaWeightL0[i] = append(p.ChromaWeightL0[i], se)
|
|
|
|
|
|
|
|
se, err = readSe(br)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse ChromaOffsetL0")
|
|
|
|
}
|
|
|
|
p.ChromaOffsetL0[i] = append(p.ChromaOffsetL0[i], se)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if h.SliceType%5 == 1 {
|
|
|
|
for i := 0; i <= h.NumRefIdxL1ActiveMinus1; i++ {
|
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read LumaWeightL1Flag")
|
|
|
|
}
|
|
|
|
p.LumaWeightL1Flag = b == 1
|
|
|
|
|
|
|
|
if p.LumaWeightL1Flag {
|
|
|
|
se, err := readSe(br)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse LumaWeightL1")
|
|
|
|
}
|
|
|
|
p.LumaWeightL1 = append(p.LumaWeightL1, se)
|
|
|
|
|
|
|
|
se, err = readSe(br)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse LumaOffsetL1")
|
|
|
|
}
|
|
|
|
p.LumaOffsetL1 = append(p.LumaOffsetL1, se)
|
|
|
|
}
|
2019-08-04 18:47:19 +03:00
|
|
|
if chromaArrayType != 0 {
|
2019-07-22 07:31:23 +03:00
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read ChromaWeightL1Flag")
|
|
|
|
}
|
|
|
|
p.ChromaWeightL1Flag = b == 1
|
|
|
|
|
|
|
|
if p.ChromaWeightL1Flag {
|
|
|
|
p.ChromaWeightL1 = append(p.ChromaWeightL1, []int{})
|
|
|
|
p.ChromaOffsetL1 = append(p.ChromaOffsetL1, []int{})
|
|
|
|
for j := 0; j < 2; j++ {
|
|
|
|
se, err := readSe(br)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse ChromaWeightL1")
|
|
|
|
}
|
|
|
|
p.ChromaWeightL1[i] = append(p.ChromaWeightL1[i], se)
|
|
|
|
|
|
|
|
se, err = readSe(br)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse ChromaOffsetL1")
|
|
|
|
}
|
|
|
|
p.ChromaOffsetL1[i] = append(p.ChromaOffsetL1[i], se)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p, nil
|
|
|
|
}
|
|
|
|
|
2019-07-22 08:43:18 +03:00
|
|
|
// DecRefPicMarking provides elements of a dec_ref_pic_marking syntax structure
|
|
|
|
// as defined in section 7.3.3.3 of the specifications.
|
|
|
|
type DecRefPicMarking struct {
|
2019-08-05 08:11:26 +03:00
|
|
|
NoOutputOfPriorPicsFlag bool
|
|
|
|
LongTermReferenceFlag bool
|
|
|
|
AdaptiveRefPicMarkingModeFlag bool
|
|
|
|
elements []drpmElement
|
2019-08-05 04:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type drpmElement struct {
|
2019-07-18 07:32:42 +03:00
|
|
|
MemoryManagementControlOperation int
|
|
|
|
DifferenceOfPicNumsMinus1 int
|
2019-08-04 06:29:13 +03:00
|
|
|
LongTermPicNum int
|
2019-07-18 07:32:42 +03:00
|
|
|
LongTermFrameIdx int
|
|
|
|
MaxLongTermFrameIdxPlus1 int
|
|
|
|
}
|
|
|
|
|
2019-07-22 08:43:18 +03:00
|
|
|
// NewDecRefPicMarking parses elements of a dec_ref_pic_marking following the
|
|
|
|
// syntax structure defined in section 7.3.3.3, and returns as a new
|
|
|
|
// DecRefPicMarking.
|
2019-08-05 04:10:20 +03:00
|
|
|
func NewDecRefPicMarking(br *bits.BitReader, idrPic bool) (*DecRefPicMarking, error) {
|
2019-07-22 08:43:18 +03:00
|
|
|
d := &DecRefPicMarking{}
|
2019-08-05 07:16:02 +03:00
|
|
|
r := newFieldReader(br)
|
2019-07-22 08:43:18 +03:00
|
|
|
if idrPic {
|
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read NoOutputOfPriorPicsFlag")
|
|
|
|
}
|
|
|
|
d.NoOutputOfPriorPicsFlag = b == 1
|
|
|
|
|
|
|
|
b, err = br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read LongTermReferenceFlag")
|
|
|
|
}
|
|
|
|
d.LongTermReferenceFlag = b == 1
|
|
|
|
} else {
|
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read AdaptiveRefPicMarkingModeFlag")
|
|
|
|
}
|
|
|
|
d.AdaptiveRefPicMarkingModeFlag = b == 1
|
|
|
|
|
|
|
|
if d.AdaptiveRefPicMarkingModeFlag {
|
2019-08-05 04:10:20 +03:00
|
|
|
for i := 0; ; i++ {
|
2019-08-05 08:11:26 +03:00
|
|
|
d.elements = append(d.elements, drpmElement{})
|
2019-08-05 04:10:20 +03:00
|
|
|
|
2019-08-05 08:11:26 +03:00
|
|
|
d.elements[i].MemoryManagementControlOperation = int(r.readUe())
|
2019-08-05 04:10:20 +03:00
|
|
|
|
|
|
|
if d.elements[i].MemoryManagementControlOperation == 1 || d.elements[i].MemoryManagementControlOperation == 3 {
|
2019-08-05 08:11:26 +03:00
|
|
|
d.elements[i].DifferenceOfPicNumsMinus1 = int(r.readUe())
|
2019-07-22 08:43:18 +03:00
|
|
|
}
|
2019-08-05 04:10:20 +03:00
|
|
|
if d.elements[i].MemoryManagementControlOperation == 2 {
|
2019-08-05 08:11:26 +03:00
|
|
|
d.elements[i].LongTermPicNum = int(r.readUe())
|
2019-07-22 08:43:18 +03:00
|
|
|
}
|
2019-08-05 04:10:20 +03:00
|
|
|
if d.elements[i].MemoryManagementControlOperation == 3 || d.elements[i].MemoryManagementControlOperation == 6 {
|
2019-08-05 08:11:26 +03:00
|
|
|
d.elements[i].LongTermFrameIdx = int(r.readUe())
|
2019-07-22 08:43:18 +03:00
|
|
|
}
|
2019-08-05 04:10:20 +03:00
|
|
|
if d.elements[i].MemoryManagementControlOperation == 4 {
|
2019-08-05 08:11:26 +03:00
|
|
|
d.elements[i].MaxLongTermFrameIdxPlus1 = int(r.readUe())
|
2019-07-22 08:43:18 +03:00
|
|
|
}
|
2019-08-05 04:10:20 +03:00
|
|
|
|
|
|
|
if d.elements[i].MemoryManagementControlOperation == 0 {
|
|
|
|
break
|
2019-07-22 08:43:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return d, nil
|
|
|
|
}
|
|
|
|
|
2019-07-18 07:32:42 +03:00
|
|
|
type SliceHeader struct {
|
2019-07-22 06:26:37 +03:00
|
|
|
FirstMbInSlice int
|
|
|
|
SliceType int
|
|
|
|
PPSID int
|
|
|
|
ColorPlaneID int
|
|
|
|
FrameNum int
|
|
|
|
FieldPic bool
|
|
|
|
BottomField bool
|
|
|
|
IDRPicID int
|
|
|
|
PicOrderCntLsb int
|
|
|
|
DeltaPicOrderCntBottom int
|
|
|
|
DeltaPicOrderCnt []int
|
|
|
|
RedundantPicCnt int
|
|
|
|
DirectSpatialMvPred bool
|
|
|
|
NumRefIdxActiveOverride bool
|
|
|
|
NumRefIdxL0ActiveMinus1 int
|
|
|
|
NumRefIdxL1ActiveMinus1 int
|
2019-07-22 07:31:23 +03:00
|
|
|
*RefPicListModification
|
|
|
|
*PredWeightTable
|
2019-07-22 08:43:18 +03:00
|
|
|
*DecRefPicMarking
|
2019-07-22 06:26:37 +03:00
|
|
|
CabacInit int
|
|
|
|
SliceQpDelta int
|
|
|
|
SpForSwitch bool
|
|
|
|
SliceQsDelta int
|
|
|
|
DisableDeblockingFilter int
|
|
|
|
SliceAlphaC0OffsetDiv2 int
|
|
|
|
SliceBetaOffsetDiv2 int
|
|
|
|
SliceGroupChangeCycle int
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type SliceData struct {
|
|
|
|
BitReader *bits.BitReader
|
|
|
|
CabacAlignmentOneBit int
|
|
|
|
MbSkipRun int
|
|
|
|
MbSkipFlag bool
|
|
|
|
MbFieldDecodingFlag bool
|
|
|
|
EndOfSliceFlag bool
|
|
|
|
MbType int
|
|
|
|
MbTypeName string
|
|
|
|
SliceTypeName string
|
|
|
|
PcmAlignmentZeroBit int
|
|
|
|
PcmSampleLuma []int
|
|
|
|
PcmSampleChroma []int
|
|
|
|
TransformSize8x8Flag bool
|
|
|
|
CodedBlockPattern int
|
|
|
|
MbQpDelta int
|
|
|
|
PrevIntra4x4PredModeFlag []int
|
|
|
|
RemIntra4x4PredMode []int
|
|
|
|
PrevIntra8x8PredModeFlag []int
|
|
|
|
RemIntra8x8PredMode []int
|
|
|
|
IntraChromaPredMode int
|
|
|
|
RefIdxL0 []int
|
|
|
|
RefIdxL1 []int
|
|
|
|
MvdL0 [][][]int
|
|
|
|
MvdL1 [][][]int
|
|
|
|
}
|
|
|
|
|
|
|
|
// Table 7-6
|
|
|
|
var sliceTypeMap = map[int]string{
|
|
|
|
0: "P",
|
|
|
|
1: "B",
|
|
|
|
2: "I",
|
|
|
|
3: "SP",
|
|
|
|
4: "SI",
|
|
|
|
5: "P",
|
|
|
|
6: "B",
|
|
|
|
7: "I",
|
|
|
|
8: "SP",
|
|
|
|
9: "SI",
|
|
|
|
}
|
|
|
|
|
|
|
|
func flagVal(b bool) int {
|
|
|
|
if b {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// context-adaptive arithmetic entropy-coded element (CABAC)
|
|
|
|
// 9.3
|
|
|
|
// When parsing the slice date of a slice (7.3.4) the initialization is 9.3.1
|
|
|
|
func (d SliceData) ae(v int) int {
|
|
|
|
// 9.3.1.1 : CABAC context initialization ctxIdx
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// 8.2.2
|
|
|
|
func MbToSliceGroupMap(sps *SPS, pps *PPS, header *SliceHeader) []int {
|
|
|
|
mbaffFrameFlag := 0
|
2019-07-21 15:41:24 +03:00
|
|
|
if sps.MBAdaptiveFrameFieldFlag && !header.FieldPic {
|
2019-07-18 07:32:42 +03:00
|
|
|
mbaffFrameFlag = 1
|
|
|
|
}
|
|
|
|
mapUnitToSliceGroupMap := MapUnitToSliceGroupMap(sps, pps, header)
|
|
|
|
mbToSliceGroupMap := []int{}
|
|
|
|
for i := 0; i <= PicSizeInMbs(sps, header)-1; i++ {
|
2019-07-21 15:41:24 +03:00
|
|
|
if sps.FrameMBSOnlyFlag || header.FieldPic {
|
2019-07-18 07:32:42 +03:00
|
|
|
mbToSliceGroupMap = append(mbToSliceGroupMap, mapUnitToSliceGroupMap[i])
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if mbaffFrameFlag == 1 {
|
|
|
|
mbToSliceGroupMap = append(mbToSliceGroupMap, mapUnitToSliceGroupMap[i/2])
|
|
|
|
continue
|
|
|
|
}
|
2019-07-21 15:41:24 +03:00
|
|
|
if !sps.FrameMBSOnlyFlag && !sps.MBAdaptiveFrameFieldFlag && !header.FieldPic {
|
2019-07-18 07:32:42 +03:00
|
|
|
mbToSliceGroupMap = append(
|
|
|
|
mbToSliceGroupMap,
|
|
|
|
mapUnitToSliceGroupMap[(i/(2*PicWidthInMbs(sps)))*PicWidthInMbs(sps)+(i%PicWidthInMbs(sps))])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mbToSliceGroupMap
|
|
|
|
|
|
|
|
}
|
|
|
|
func PicWidthInMbs(sps *SPS) int {
|
2019-07-30 03:46:08 +03:00
|
|
|
return int(sps.PicWidthInMBSMinus1 + 1)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
func PicHeightInMapUnits(sps *SPS) int {
|
2019-07-30 03:46:08 +03:00
|
|
|
return int(sps.PicHeightInMapUnitsMinus1 + 1)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
func PicSizeInMapUnits(sps *SPS) int {
|
2019-07-30 03:46:08 +03:00
|
|
|
return int(PicWidthInMbs(sps) * PicHeightInMapUnits(sps))
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
func FrameHeightInMbs(sps *SPS) int {
|
2019-07-30 03:46:08 +03:00
|
|
|
return int((2 - flagVal(sps.FrameMBSOnlyFlag)) * PicHeightInMapUnits(sps))
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
func PicHeightInMbs(sps *SPS, header *SliceHeader) int {
|
2019-07-30 03:46:08 +03:00
|
|
|
return int(FrameHeightInMbs(sps) / (1 + flagVal(header.FieldPic)))
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
func PicSizeInMbs(sps *SPS, header *SliceHeader) int {
|
2019-07-30 03:46:08 +03:00
|
|
|
return int(PicWidthInMbs(sps) * PicHeightInMbs(sps, header))
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// table 6-1
|
|
|
|
func SubWidthC(sps *SPS) int {
|
|
|
|
n := 17
|
2019-07-21 15:41:24 +03:00
|
|
|
if sps.SeparateColorPlaneFlag {
|
|
|
|
if sps.ChromaFormatIDC == chroma444 {
|
2019-07-18 07:32:42 +03:00
|
|
|
return n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-21 15:41:24 +03:00
|
|
|
switch sps.ChromaFormatIDC {
|
2019-07-18 07:32:42 +03:00
|
|
|
case chromaMonochrome:
|
|
|
|
return n
|
|
|
|
case chroma420:
|
|
|
|
n = 2
|
|
|
|
case chroma422:
|
|
|
|
n = 2
|
|
|
|
case chroma444:
|
|
|
|
n = 1
|
|
|
|
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
func SubHeightC(sps *SPS) int {
|
|
|
|
n := 17
|
2019-07-21 15:41:24 +03:00
|
|
|
if sps.SeparateColorPlaneFlag {
|
|
|
|
if sps.ChromaFormatIDC == chroma444 {
|
2019-07-18 07:32:42 +03:00
|
|
|
return n
|
|
|
|
}
|
|
|
|
}
|
2019-07-21 15:41:24 +03:00
|
|
|
switch sps.ChromaFormatIDC {
|
2019-07-18 07:32:42 +03:00
|
|
|
case chromaMonochrome:
|
|
|
|
return n
|
|
|
|
case chroma420:
|
|
|
|
n = 2
|
|
|
|
case chroma422:
|
|
|
|
n = 1
|
|
|
|
case chroma444:
|
|
|
|
n = 1
|
|
|
|
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
// 7-36
|
|
|
|
func CodedBlockPatternLuma(data *SliceData) int {
|
|
|
|
return data.CodedBlockPattern % 16
|
|
|
|
}
|
|
|
|
func CodedBlockPatternChroma(data *SliceData) int {
|
|
|
|
return data.CodedBlockPattern / 16
|
|
|
|
}
|
|
|
|
|
|
|
|
// dependencyId see Annex G.8.8.1
|
|
|
|
// Also G7.3.1.1 nal_unit_header_svc_extension
|
2019-07-19 14:28:01 +03:00
|
|
|
func DQId(nalUnit *NALUnit) int {
|
2019-07-29 07:11:40 +03:00
|
|
|
return int((nalUnit.SVCExtension.DependencyID << 4)) + int(nalUnit.SVCExtension.QualityID)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Annex G p527
|
2019-07-19 14:28:01 +03:00
|
|
|
func NumMbPart(nalUnit *NALUnit, sps *SPS, header *SliceHeader, data *SliceData) int {
|
2019-07-18 07:32:42 +03:00
|
|
|
sliceType := sliceTypeMap[header.SliceType]
|
|
|
|
numMbPart := 0
|
|
|
|
if MbTypeName(sliceType, CurrMbAddr(sps, header)) == "B_SKIP" || MbTypeName(sliceType, CurrMbAddr(sps, header)) == "B_Direct_16x16" {
|
|
|
|
if DQId(nalUnit) == 0 && nalUnit.Type != 20 {
|
|
|
|
numMbPart = 4
|
|
|
|
} else if DQId(nalUnit) > 0 && nalUnit.Type == 20 {
|
|
|
|
numMbPart = 1
|
|
|
|
}
|
|
|
|
} else if MbTypeName(sliceType, CurrMbAddr(sps, header)) != "B_SKIP" && MbTypeName(sliceType, CurrMbAddr(sps, header)) != "B_Direct_16x16" {
|
|
|
|
numMbPart = CurrMbAddr(sps, header)
|
|
|
|
|
|
|
|
}
|
|
|
|
return numMbPart
|
|
|
|
}
|
|
|
|
|
2019-09-09 04:38:48 +03:00
|
|
|
func MbPred(chromaArrayType int, vid *VideoStream, sliceContext *SliceContext, br *bits.BitReader, rbsp []byte) error {
|
2019-07-18 07:32:42 +03:00
|
|
|
var cabac *CABAC
|
2019-08-05 08:11:26 +03:00
|
|
|
r := newFieldReader(br)
|
|
|
|
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceType := sliceTypeMap[sliceContext.Slice.SliceHeader.SliceType]
|
|
|
|
mbPartPredMode, err := MbPartPredMode(sliceContext.Slice.SliceData, sliceType, sliceContext.Slice.SliceData.MbType, 0)
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not get mbPartPredMode")
|
|
|
|
}
|
|
|
|
if mbPartPredMode == intra4x4 || mbPartPredMode == intra8x8 || mbPartPredMode == intra16x16 {
|
|
|
|
if mbPartPredMode == intra4x4 {
|
|
|
|
for luma4x4BlkIdx := 0; luma4x4BlkIdx < 16; luma4x4BlkIdx++ {
|
|
|
|
var v int
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.PPS.EntropyCodingMode == 1 {
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO: 1 bit or ae(v)
|
|
|
|
binarization := NewBinarization(
|
|
|
|
"PrevIntra4x4PredModeFlag",
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData)
|
2019-07-18 07:32:42 +03:00
|
|
|
binarization.Decode(sliceContext, br, rbsp)
|
|
|
|
|
2019-09-09 04:38:48 +03:00
|
|
|
// TODO: fix videostream should be nil.
|
|
|
|
cabac = initCabac(binarization, nil, sliceContext)
|
2019-07-18 07:32:42 +03:00
|
|
|
_ = cabac
|
|
|
|
logger.Printf("TODO: ae for PevIntra4x4PredModeFlag[%d]\n", luma4x4BlkIdx)
|
|
|
|
} else {
|
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not read PrevIntra4x4PredModeFlag")
|
|
|
|
}
|
|
|
|
v = int(b)
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.PrevIntra4x4PredModeFlag = append(
|
|
|
|
sliceContext.Slice.SliceData.PrevIntra4x4PredModeFlag,
|
2019-07-18 07:32:42 +03:00
|
|
|
v)
|
2019-09-09 04:38:48 +03:00
|
|
|
if sliceContext.Slice.SliceData.PrevIntra4x4PredModeFlag[luma4x4BlkIdx] == 0 {
|
|
|
|
if vid.PPS.EntropyCodingMode == 1 {
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO: 3 bits or ae(v)
|
|
|
|
binarization := NewBinarization(
|
|
|
|
"RemIntra4x4PredMode",
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData)
|
2019-07-18 07:32:42 +03:00
|
|
|
binarization.Decode(sliceContext, br, rbsp)
|
|
|
|
|
|
|
|
logger.Printf("TODO: ae for RemIntra4x4PredMode[%d]\n", luma4x4BlkIdx)
|
|
|
|
} else {
|
|
|
|
b, err := br.ReadBits(3)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not read RemIntra4x4PredMode")
|
|
|
|
}
|
|
|
|
v = int(b)
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
if len(sliceContext.Slice.SliceData.RemIntra4x4PredMode) < luma4x4BlkIdx {
|
|
|
|
sliceContext.Slice.SliceData.RemIntra4x4PredMode = append(
|
|
|
|
sliceContext.Slice.SliceData.RemIntra4x4PredMode,
|
|
|
|
make([]int, luma4x4BlkIdx-len(sliceContext.Slice.SliceData.RemIntra4x4PredMode)+1)...)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.RemIntra4x4PredMode[luma4x4BlkIdx] = v
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if mbPartPredMode == intra8x8 {
|
|
|
|
for luma8x8BlkIdx := 0; luma8x8BlkIdx < 4; luma8x8BlkIdx++ {
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Update(sliceContext.Slice.SliceHeader, sliceContext.Slice.SliceData)
|
2019-07-18 07:32:42 +03:00
|
|
|
var v int
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.PPS.EntropyCodingMode == 1 {
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO: 1 bit or ae(v)
|
2019-09-09 04:38:48 +03:00
|
|
|
binarization := NewBinarization("PrevIntra8x8PredModeFlag", sliceContext.Slice.SliceData)
|
2019-07-18 07:32:42 +03:00
|
|
|
binarization.Decode(sliceContext, br, rbsp)
|
|
|
|
|
|
|
|
logger.Printf("TODO: ae for PrevIntra8x8PredModeFlag[%d]\n", luma8x8BlkIdx)
|
|
|
|
} else {
|
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not read PrevIntra8x8PredModeFlag")
|
|
|
|
}
|
|
|
|
v = int(b)
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.PrevIntra8x8PredModeFlag = append(
|
|
|
|
sliceContext.Slice.SliceData.PrevIntra8x8PredModeFlag, v)
|
|
|
|
if sliceContext.Slice.SliceData.PrevIntra8x8PredModeFlag[luma8x8BlkIdx] == 0 {
|
|
|
|
if vid.PPS.EntropyCodingMode == 1 {
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO: 3 bits or ae(v)
|
|
|
|
binarization := NewBinarization(
|
|
|
|
"RemIntra8x8PredMode",
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData)
|
2019-07-18 07:32:42 +03:00
|
|
|
binarization.Decode(sliceContext, br, rbsp)
|
|
|
|
|
|
|
|
logger.Printf("TODO: ae for RemIntra8x8PredMode[%d]\n", luma8x8BlkIdx)
|
|
|
|
} else {
|
|
|
|
b, err := br.ReadBits(3)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not read RemIntra8x8PredMode")
|
|
|
|
}
|
|
|
|
v = int(b)
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
if len(sliceContext.Slice.SliceData.RemIntra8x8PredMode) < luma8x8BlkIdx {
|
|
|
|
sliceContext.Slice.SliceData.RemIntra8x8PredMode = append(
|
|
|
|
sliceContext.Slice.SliceData.RemIntra8x8PredMode,
|
|
|
|
make([]int, luma8x8BlkIdx-len(sliceContext.Slice.SliceData.RemIntra8x8PredMode)+1)...)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.RemIntra8x8PredMode[luma8x8BlkIdx] = v
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-08-04 18:47:19 +03:00
|
|
|
if chromaArrayType == 1 || chromaArrayType == 2 {
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.PPS.EntropyCodingMode == 1 {
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO: ue(v) or ae(v)
|
|
|
|
binarization := NewBinarization(
|
|
|
|
"IntraChromaPredMode",
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData)
|
2019-07-18 07:32:42 +03:00
|
|
|
binarization.Decode(sliceContext, br, rbsp)
|
|
|
|
|
|
|
|
logger.Printf("TODO: ae for IntraChromaPredMode\n")
|
|
|
|
} else {
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.IntraChromaPredMode = int(r.readUe())
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if mbPartPredMode != direct {
|
2019-09-09 04:38:48 +03:00
|
|
|
for mbPartIdx := 0; mbPartIdx < NumMbPart(sliceContext.NALUnit, vid.SPS, sliceContext.Slice.SliceHeader, sliceContext.Slice.SliceData); mbPartIdx++ {
|
|
|
|
sliceContext.Update(sliceContext.Slice.SliceHeader, sliceContext.Slice.SliceData)
|
|
|
|
m, err := MbPartPredMode(sliceContext.Slice.SliceData, sliceType, sliceContext.Slice.SliceData.MbType, mbPartIdx)
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, fmt.Sprintf("could not get mbPartPredMode for loop 1 mbPartIdx: %d", mbPartIdx))
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
if (sliceContext.Slice.SliceHeader.NumRefIdxL0ActiveMinus1 > 0 || sliceContext.Slice.SliceData.MbFieldDecodingFlag != sliceContext.Slice.SliceHeader.FieldPic) && m != predL1 {
|
2019-07-18 07:32:42 +03:00
|
|
|
logger.Printf("\tTODO: refIdxL0[%d] te or ae(v)\n", mbPartIdx)
|
2019-09-09 04:38:48 +03:00
|
|
|
if len(sliceContext.Slice.SliceData.RefIdxL0) < mbPartIdx {
|
|
|
|
sliceContext.Slice.SliceData.RefIdxL0 = append(
|
|
|
|
sliceContext.Slice.SliceData.RefIdxL0, make([]int, mbPartIdx-len(sliceContext.Slice.SliceData.RefIdxL0)+1)...)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.PPS.EntropyCodingMode == 1 {
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO: te(v) or ae(v)
|
|
|
|
binarization := NewBinarization(
|
|
|
|
"RefIdxL0",
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData)
|
2019-07-18 07:32:42 +03:00
|
|
|
binarization.Decode(sliceContext, br, rbsp)
|
|
|
|
|
|
|
|
logger.Printf("TODO: ae for RefIdxL0[%d]\n", mbPartIdx)
|
|
|
|
} else {
|
|
|
|
// TODO: Only one reference picture is used for inter-prediction,
|
|
|
|
// then the value should be 0
|
2019-09-09 04:38:48 +03:00
|
|
|
if MbaffFrameFlag(vid.SPS, sliceContext.Slice.SliceHeader) == 0 || !sliceContext.Slice.SliceData.MbFieldDecodingFlag {
|
|
|
|
sliceContext.Slice.SliceData.RefIdxL0[mbPartIdx] = int(r.readTe(uint(sliceContext.Slice.SliceHeader.NumRefIdxL0ActiveMinus1)))
|
2019-07-18 07:32:42 +03:00
|
|
|
} else {
|
2019-09-09 04:38:48 +03:00
|
|
|
rangeMax := 2*sliceContext.Slice.SliceHeader.NumRefIdxL0ActiveMinus1 + 1
|
|
|
|
sliceContext.Slice.SliceData.RefIdxL0[mbPartIdx] = int(r.readTe(uint(rangeMax)))
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
for mbPartIdx := 0; mbPartIdx < NumMbPart(sliceContext.NALUnit, vid.SPS, sliceContext.Slice.SliceHeader, sliceContext.Slice.SliceData); mbPartIdx++ {
|
|
|
|
m, err := MbPartPredMode(sliceContext.Slice.SliceData, sliceType, sliceContext.Slice.SliceData.MbType, mbPartIdx)
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, fmt.Sprintf("could not get mbPartPredMode for loop 2 mbPartIdx: %d", mbPartIdx))
|
|
|
|
}
|
|
|
|
if m != predL1 {
|
|
|
|
for compIdx := 0; compIdx < 2; compIdx++ {
|
2019-09-09 04:38:48 +03:00
|
|
|
if len(sliceContext.Slice.SliceData.MvdL0) < mbPartIdx {
|
|
|
|
sliceContext.Slice.SliceData.MvdL0 = append(
|
|
|
|
sliceContext.Slice.SliceData.MvdL0,
|
|
|
|
make([][][]int, mbPartIdx-len(sliceContext.Slice.SliceData.MvdL0)+1)...)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
if len(sliceContext.Slice.SliceData.MvdL0[mbPartIdx][0]) < compIdx {
|
|
|
|
sliceContext.Slice.SliceData.MvdL0[mbPartIdx][0] = append(
|
|
|
|
sliceContext.Slice.SliceData.MvdL0[mbPartIdx][0],
|
|
|
|
make([]int, compIdx-len(sliceContext.Slice.SliceData.MvdL0[mbPartIdx][0])+1)...)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.PPS.EntropyCodingMode == 1 {
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO: se(v) or ae(v)
|
|
|
|
if compIdx == 0 {
|
|
|
|
binarization := NewBinarization(
|
|
|
|
"MvdLnEnd0",
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData)
|
2019-07-18 07:32:42 +03:00
|
|
|
binarization.Decode(sliceContext, br, rbsp)
|
|
|
|
|
|
|
|
} else if compIdx == 1 {
|
|
|
|
binarization := NewBinarization(
|
|
|
|
"MvdLnEnd1",
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData)
|
2019-07-18 07:32:42 +03:00
|
|
|
binarization.Decode(sliceContext, br, rbsp)
|
|
|
|
|
|
|
|
}
|
|
|
|
logger.Printf("TODO: ae for MvdL0[%d][0][%d]\n", mbPartIdx, compIdx)
|
|
|
|
} else {
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.MvdL0[mbPartIdx][0][compIdx], _ = readSe(br)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
for mbPartIdx := 0; mbPartIdx < NumMbPart(sliceContext.NALUnit, vid.SPS, sliceContext.Slice.SliceHeader, sliceContext.Slice.SliceData); mbPartIdx++ {
|
|
|
|
sliceContext.Update(sliceContext.Slice.SliceHeader, sliceContext.Slice.SliceData)
|
|
|
|
m, err := MbPartPredMode(sliceContext.Slice.SliceData, sliceType, sliceContext.Slice.SliceData.MbType, mbPartIdx)
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, fmt.Sprintf("could not get mbPartPredMode for loop 3 mbPartIdx: %d", mbPartIdx))
|
|
|
|
}
|
|
|
|
if m != predL0 {
|
|
|
|
for compIdx := 0; compIdx < 2; compIdx++ {
|
2019-09-09 04:38:48 +03:00
|
|
|
if len(sliceContext.Slice.SliceData.MvdL1) < mbPartIdx {
|
|
|
|
sliceContext.Slice.SliceData.MvdL1 = append(
|
|
|
|
sliceContext.Slice.SliceData.MvdL1,
|
|
|
|
make([][][]int, mbPartIdx-len(sliceContext.Slice.SliceData.MvdL1)+1)...)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
if len(sliceContext.Slice.SliceData.MvdL1[mbPartIdx][0]) < compIdx {
|
|
|
|
sliceContext.Slice.SliceData.MvdL1[mbPartIdx][0] = append(
|
|
|
|
sliceContext.Slice.SliceData.MvdL0[mbPartIdx][0],
|
|
|
|
make([]int, compIdx-len(sliceContext.Slice.SliceData.MvdL1[mbPartIdx][0])+1)...)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.PPS.EntropyCodingMode == 1 {
|
2019-07-18 07:32:42 +03:00
|
|
|
if compIdx == 0 {
|
|
|
|
binarization := NewBinarization(
|
|
|
|
"MvdLnEnd0",
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData)
|
2019-07-18 07:32:42 +03:00
|
|
|
binarization.Decode(sliceContext, br, rbsp)
|
|
|
|
|
|
|
|
} else if compIdx == 1 {
|
|
|
|
binarization := NewBinarization(
|
|
|
|
"MvdLnEnd1",
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData)
|
2019-07-18 07:32:42 +03:00
|
|
|
binarization.Decode(sliceContext, br, rbsp)
|
|
|
|
|
|
|
|
}
|
|
|
|
// TODO: se(v) or ae(v)
|
|
|
|
logger.Printf("TODO: ae for MvdL1[%d][0][%d]\n", mbPartIdx, compIdx)
|
|
|
|
} else {
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.MvdL1[mbPartIdx][0][compIdx], _ = readSe(br)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// 8.2.2.1
|
|
|
|
func MapUnitToSliceGroupMap(sps *SPS, pps *PPS, header *SliceHeader) []int {
|
|
|
|
mapUnitToSliceGroupMap := []int{}
|
|
|
|
picSizeInMapUnits := PicSizeInMapUnits(sps)
|
|
|
|
if pps.NumSliceGroupsMinus1 == 0 {
|
|
|
|
// 0 to PicSizeInMapUnits -1 inclusive
|
|
|
|
for i := 0; i <= picSizeInMapUnits-1; i++ {
|
|
|
|
mapUnitToSliceGroupMap = append(mapUnitToSliceGroupMap, 0)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch pps.SliceGroupMapType {
|
|
|
|
case 0:
|
|
|
|
// 8.2.2.1
|
|
|
|
i := 0
|
|
|
|
for i < picSizeInMapUnits {
|
|
|
|
// iGroup should be incremented in the pps.RunLengthMinus1 index operation. There may be a bug here
|
|
|
|
for iGroup := 0; iGroup <= pps.NumSliceGroupsMinus1 && i < picSizeInMapUnits; i += pps.RunLengthMinus1[iGroup+1] + 1 {
|
|
|
|
for j := 0; j < pps.RunLengthMinus1[iGroup] && i+j < picSizeInMapUnits; j++ {
|
|
|
|
if len(mapUnitToSliceGroupMap) < i+j {
|
|
|
|
mapUnitToSliceGroupMap = append(
|
|
|
|
mapUnitToSliceGroupMap,
|
|
|
|
make([]int, (i+j)-len(mapUnitToSliceGroupMap)+1)...)
|
|
|
|
}
|
|
|
|
mapUnitToSliceGroupMap[i+j] = iGroup
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
// 8.2.2.2
|
|
|
|
for i := 0; i < picSizeInMapUnits; i++ {
|
|
|
|
v := ((i % PicWidthInMbs(sps)) + (((i / PicWidthInMbs(sps)) * (pps.NumSliceGroupsMinus1 + 1)) / 2)) % (pps.NumSliceGroupsMinus1 + 1)
|
|
|
|
mapUnitToSliceGroupMap = append(mapUnitToSliceGroupMap, v)
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
// 8.2.2.3
|
|
|
|
for i := 0; i < picSizeInMapUnits; i++ {
|
|
|
|
mapUnitToSliceGroupMap = append(mapUnitToSliceGroupMap, pps.NumSliceGroupsMinus1)
|
|
|
|
}
|
|
|
|
for iGroup := pps.NumSliceGroupsMinus1 - 1; iGroup >= 0; iGroup-- {
|
|
|
|
yTopLeft := pps.TopLeft[iGroup] / PicWidthInMbs(sps)
|
|
|
|
xTopLeft := pps.TopLeft[iGroup] % PicWidthInMbs(sps)
|
|
|
|
yBottomRight := pps.BottomRight[iGroup] / PicWidthInMbs(sps)
|
|
|
|
xBottomRight := pps.BottomRight[iGroup] % PicWidthInMbs(sps)
|
|
|
|
for y := yTopLeft; y <= yBottomRight; y++ {
|
|
|
|
for x := xTopLeft; x <= xBottomRight; x++ {
|
|
|
|
idx := y*PicWidthInMbs(sps) + x
|
|
|
|
if len(mapUnitToSliceGroupMap) < idx {
|
|
|
|
mapUnitToSliceGroupMap = append(
|
|
|
|
mapUnitToSliceGroupMap,
|
|
|
|
make([]int, idx-len(mapUnitToSliceGroupMap)+1)...)
|
|
|
|
mapUnitToSliceGroupMap[idx] = iGroup
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
// 8.2.2.4
|
|
|
|
// TODO
|
|
|
|
case 4:
|
|
|
|
// 8.2.2.5
|
|
|
|
// TODO
|
|
|
|
case 5:
|
|
|
|
// 8.2.2.6
|
|
|
|
// TODO
|
|
|
|
case 6:
|
|
|
|
// 8.2.2.7
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 8.2.2.8
|
|
|
|
// Convert mapUnitToSliceGroupMap to MbToSliceGroupMap
|
|
|
|
return mapUnitToSliceGroupMap
|
|
|
|
}
|
|
|
|
func nextMbAddress(n int, sps *SPS, pps *PPS, header *SliceHeader) int {
|
|
|
|
i := n + 1
|
|
|
|
// picSizeInMbs is the number of macroblocks in picture 0
|
|
|
|
// 7-13
|
2019-07-21 15:41:24 +03:00
|
|
|
// PicWidthInMbs = sps.PicWidthInMBSMinus1 + 1
|
2019-07-18 07:32:42 +03:00
|
|
|
// PicHeightInMapUnits = sps.PicHeightInMapUnitsMinus1 + 1
|
|
|
|
// 7-29
|
|
|
|
// picSizeInMbs = PicWidthInMbs * PicHeightInMbs
|
|
|
|
// 7-26
|
|
|
|
// PicHeightInMbs = FrameHeightInMbs / (1 + header.fieldPicFlag)
|
|
|
|
// 7-18
|
2019-07-21 15:41:24 +03:00
|
|
|
// FrameHeightInMbs = (2 - ps.FrameMBSOnlyFlag) * PicHeightInMapUnits
|
|
|
|
picWidthInMbs := sps.PicWidthInMBSMinus1 + 1
|
2019-07-18 07:32:42 +03:00
|
|
|
picHeightInMapUnits := sps.PicHeightInMapUnitsMinus1 + 1
|
2019-07-30 03:46:08 +03:00
|
|
|
frameHeightInMbs := (2 - flagVal(sps.FrameMBSOnlyFlag)) * int(picHeightInMapUnits)
|
2019-07-18 07:32:42 +03:00
|
|
|
picHeightInMbs := frameHeightInMbs / (1 + flagVal(header.FieldPic))
|
2019-07-30 03:46:08 +03:00
|
|
|
picSizeInMbs := int(picWidthInMbs) * picHeightInMbs
|
2019-07-18 07:32:42 +03:00
|
|
|
mbToSliceGroupMap := MbToSliceGroupMap(sps, pps, header)
|
|
|
|
for i < picSizeInMbs && mbToSliceGroupMap[i] != mbToSliceGroupMap[i] {
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
|
|
|
func CurrMbAddr(sps *SPS, header *SliceHeader) int {
|
|
|
|
mbaffFrameFlag := 0
|
2019-07-21 15:41:24 +03:00
|
|
|
if sps.MBAdaptiveFrameFieldFlag && !header.FieldPic {
|
2019-07-18 07:32:42 +03:00
|
|
|
mbaffFrameFlag = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
return header.FirstMbInSlice * (1 * mbaffFrameFlag)
|
|
|
|
}
|
|
|
|
|
|
|
|
func MbaffFrameFlag(sps *SPS, header *SliceHeader) int {
|
2019-07-21 15:41:24 +03:00
|
|
|
if sps.MBAdaptiveFrameFieldFlag && !header.FieldPic {
|
2019-07-18 07:32:42 +03:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2019-09-09 04:38:48 +03:00
|
|
|
func NewSliceData(chromaArrayType int, vid *VideoStream, sliceContext *SliceContext, br *bits.BitReader) (*SliceData, error) {
|
2019-07-30 03:46:08 +03:00
|
|
|
r := newFieldReader(br)
|
2019-07-18 07:32:42 +03:00
|
|
|
var cabac *CABAC
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData = &SliceData{BitReader: br}
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO: Why is this being initialized here?
|
|
|
|
// initCabac(sliceContext)
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.PPS.EntropyCodingMode == 1 {
|
2019-07-18 07:32:42 +03:00
|
|
|
for !br.ByteAligned() {
|
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read CabacAlignmentOneBit")
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.CabacAlignmentOneBit = int(b)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mbaffFrameFlag := 0
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.SPS.MBAdaptiveFrameFieldFlag && !sliceContext.Slice.SliceHeader.FieldPic {
|
2019-07-18 07:32:42 +03:00
|
|
|
mbaffFrameFlag = 1
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
currMbAddr := sliceContext.Slice.SliceHeader.FirstMbInSlice * (1 * mbaffFrameFlag)
|
2019-07-18 07:32:42 +03:00
|
|
|
|
|
|
|
moreDataFlag := true
|
|
|
|
prevMbSkipped := 0
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.SliceTypeName = sliceTypeMap[sliceContext.Slice.SliceHeader.SliceType]
|
|
|
|
sliceContext.Slice.SliceData.MbTypeName = MbTypeName(sliceContext.Slice.SliceData.SliceTypeName, sliceContext.Slice.SliceData.MbType)
|
2019-07-18 07:32:42 +03:00
|
|
|
logger.Printf("debug: \tSliceData: Processing moreData: %v\n", moreDataFlag)
|
|
|
|
for moreDataFlag {
|
2019-09-09 04:38:48 +03:00
|
|
|
logger.Printf("debug: \tLooking for more sliceContext.Slice.SliceData in slice type %s\n", sliceContext.Slice.SliceData.SliceTypeName)
|
|
|
|
if sliceContext.Slice.SliceData.SliceTypeName != "I" && sliceContext.Slice.SliceData.SliceTypeName != "SI" {
|
2019-07-18 07:32:42 +03:00
|
|
|
logger.Printf("debug: \tNonI/SI slice, processing moreData\n")
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.PPS.EntropyCodingMode == 0 {
|
|
|
|
sliceContext.Slice.SliceData.MbSkipRun = int(r.readUe())
|
2019-07-18 07:32:42 +03:00
|
|
|
|
2019-09-09 04:38:48 +03:00
|
|
|
if sliceContext.Slice.SliceData.MbSkipRun > 0 {
|
2019-07-18 07:32:42 +03:00
|
|
|
prevMbSkipped = 1
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
for i := 0; i < sliceContext.Slice.SliceData.MbSkipRun; i++ {
|
2019-07-18 07:32:42 +03:00
|
|
|
// nextMbAddress(currMbAdd
|
2019-09-09 04:38:48 +03:00
|
|
|
currMbAddr = nextMbAddress(currMbAddr, vid.SPS, vid.PPS, sliceContext.Slice.SliceHeader)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
if sliceContext.Slice.SliceData.MbSkipRun > 0 {
|
2019-07-18 07:32:42 +03:00
|
|
|
moreDataFlag = moreRBSPData(br)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read MbSkipFlag")
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.MbSkipFlag = b == 1
|
2019-07-18 07:32:42 +03:00
|
|
|
|
2019-09-09 04:38:48 +03:00
|
|
|
moreDataFlag = !sliceContext.Slice.SliceData.MbSkipFlag
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if moreDataFlag {
|
|
|
|
if mbaffFrameFlag == 1 && (currMbAddr%2 == 0 || (currMbAddr%2 == 1 && prevMbSkipped == 1)) {
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.PPS.EntropyCodingMode == 1 {
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO: ae implementation
|
2019-09-09 04:38:48 +03:00
|
|
|
binarization := NewBinarization("MbFieldDecodingFlag", sliceContext.Slice.SliceData)
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO: this should take a BitReader where the nil is.
|
|
|
|
binarization.Decode(sliceContext, br, nil)
|
|
|
|
|
|
|
|
logger.Printf("TODO: ae for MbFieldDecodingFlag\n")
|
|
|
|
} else {
|
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read MbFieldDecodingFlag")
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.MbFieldDecodingFlag = b == 1
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// BEGIN: macroblockLayer()
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.PPS.EntropyCodingMode == 1 {
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO: ae implementation
|
2019-09-09 04:38:48 +03:00
|
|
|
binarization := NewBinarization("MbType", sliceContext.Slice.SliceData)
|
|
|
|
cabac = initCabac(binarization, nil, sliceContext)
|
2019-07-18 07:32:42 +03:00
|
|
|
_ = cabac
|
|
|
|
// TODO: remove bytes parameter from this function.
|
|
|
|
binarization.Decode(sliceContext, br, nil)
|
|
|
|
if binarization.PrefixSuffix {
|
|
|
|
logger.Printf("debug: MBType binarization has prefix and suffix\n")
|
|
|
|
}
|
|
|
|
bits := []int{}
|
|
|
|
for binIdx := 0; binarization.IsBinStringMatch(bits); binIdx++ {
|
|
|
|
newBit, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read bit")
|
|
|
|
}
|
|
|
|
if binarization.UseDecodeBypass == 1 {
|
|
|
|
// DecodeBypass
|
|
|
|
logger.Printf("TODO: decodeBypass is set: 9.3.3.2.3")
|
2019-09-09 04:38:48 +03:00
|
|
|
codIRange, codIOffset, err := initDecodingEngine(sliceContext.Slice.SliceData.BitReader)
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not initialise decoding engine")
|
|
|
|
}
|
|
|
|
// Initialize the decoder
|
|
|
|
// TODO: When should the suffix of MaxBinIdxCtx be used and when just the prefix?
|
|
|
|
// TODO: When should the suffix of CtxIdxOffset be used?
|
|
|
|
arithmeticDecoder, err := NewArithmeticDecoding(
|
|
|
|
sliceContext,
|
|
|
|
binarization,
|
|
|
|
CtxIdx(
|
|
|
|
binarization.binIdx,
|
|
|
|
binarization.MaxBinIdxCtx.Prefix,
|
|
|
|
binarization.CtxIdxOffset.Prefix,
|
|
|
|
),
|
|
|
|
codIRange,
|
|
|
|
codIOffset,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "error from NewArithmeticDecoding")
|
|
|
|
}
|
|
|
|
// Bypass decoding
|
|
|
|
codIOffset, _, err = arithmeticDecoder.DecodeBypass(
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData,
|
2019-07-18 07:32:42 +03:00
|
|
|
codIRange,
|
|
|
|
codIOffset,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not DecodeBypass")
|
|
|
|
}
|
|
|
|
// End DecodeBypass
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// DO 9.3.3.1
|
|
|
|
ctxIdx := CtxIdx(
|
|
|
|
binIdx,
|
|
|
|
binarization.MaxBinIdxCtx.Prefix,
|
|
|
|
binarization.CtxIdxOffset.Prefix)
|
|
|
|
if binarization.MaxBinIdxCtx.IsPrefixSuffix {
|
|
|
|
logger.Printf("TODO: Handle PrefixSuffix binarization\n")
|
|
|
|
}
|
|
|
|
logger.Printf("debug: MBType ctxIdx for %d is %d\n", binIdx, ctxIdx)
|
|
|
|
// Then 9.3.3.2
|
|
|
|
codIRange, codIOffset, err := initDecodingEngine(br)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "error from initDecodingEngine")
|
|
|
|
}
|
|
|
|
logger.Printf("debug: coding engine initialized: %d/%d\n", codIRange, codIOffset)
|
|
|
|
}
|
|
|
|
bits = append(bits, int(newBit))
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.Printf("TODO: ae for MBType\n")
|
|
|
|
} else {
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.MbType = int(r.readUe())
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
if sliceContext.Slice.SliceData.MbTypeName == "I_PCM" {
|
2019-07-18 07:32:42 +03:00
|
|
|
for !br.ByteAligned() {
|
|
|
|
_, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read PCMAlignmentZeroBit")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 7-3 p95
|
2019-09-09 04:38:48 +03:00
|
|
|
bitDepthY := 8 + vid.SPS.BitDepthLumaMinus8
|
2019-07-18 07:32:42 +03:00
|
|
|
for i := 0; i < 256; i++ {
|
2019-07-30 03:46:08 +03:00
|
|
|
s, err := br.ReadBits(int(bitDepthY))
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, fmt.Sprintf("could not read PcmSampleLuma[%d]", i))
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.PcmSampleLuma = append(
|
|
|
|
sliceContext.Slice.SliceData.PcmSampleLuma,
|
2019-07-18 07:32:42 +03:00
|
|
|
int(s))
|
|
|
|
}
|
|
|
|
// 9.3.1 p 246
|
|
|
|
// cabac = initCabac(binarization, sliceContext)
|
|
|
|
// 6-1 p 47
|
2019-09-09 04:38:48 +03:00
|
|
|
mbWidthC := 16 / SubWidthC(vid.SPS)
|
|
|
|
mbHeightC := 16 / SubHeightC(vid.SPS)
|
2019-07-18 07:32:42 +03:00
|
|
|
// if monochrome
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.SPS.ChromaFormatIDC == chromaMonochrome || vid.SPS.SeparateColorPlaneFlag {
|
2019-07-18 07:32:42 +03:00
|
|
|
mbWidthC = 0
|
|
|
|
mbHeightC = 0
|
|
|
|
}
|
|
|
|
|
2019-09-09 04:38:48 +03:00
|
|
|
bitDepthC := 8 + vid.SPS.BitDepthChromaMinus8
|
2019-07-18 07:32:42 +03:00
|
|
|
for i := 0; i < 2*mbWidthC*mbHeightC; i++ {
|
2019-07-30 03:46:08 +03:00
|
|
|
s, err := br.ReadBits(int(bitDepthC))
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, fmt.Sprintf("could not read PcmSampleChroma[%d]", i))
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.PcmSampleChroma = append(
|
|
|
|
sliceContext.Slice.SliceData.PcmSampleChroma,
|
2019-07-18 07:32:42 +03:00
|
|
|
int(s))
|
|
|
|
}
|
|
|
|
// 9.3.1 p 246
|
|
|
|
// cabac = initCabac(binarization, sliceContext)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
noSubMbPartSizeLessThan8x8Flag := 1
|
2019-09-09 04:38:48 +03:00
|
|
|
m, err := MbPartPredMode(sliceContext.Slice.SliceData, sliceContext.Slice.SliceData.SliceTypeName, sliceContext.Slice.SliceData.MbType, 0)
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not get mbPartPredMode")
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
if sliceContext.Slice.SliceData.MbTypeName == "I_NxN" && m != intra16x16 && NumMbPart(sliceContext.NALUnit, vid.SPS, sliceContext.Slice.SliceHeader, sliceContext.Slice.SliceData) == 4 {
|
2019-07-18 07:32:42 +03:00
|
|
|
logger.Printf("\tTODO: subMbPred\n")
|
|
|
|
/*
|
2019-09-09 04:38:48 +03:00
|
|
|
subMbType := SubMbPred(sliceContext.Slice.SliceData.MbType)
|
2019-07-18 07:32:42 +03:00
|
|
|
for mbPartIdx := 0; mbPartIdx < 4; mbPartIdx++ {
|
|
|
|
if subMbType[mbPartIdx] != "B_Direct_8x8" {
|
|
|
|
if NumbSubMbPart(subMbType[mbPartIdx]) > 1 {
|
|
|
|
noSubMbPartSizeLessThan8x8Flag = 0
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
} else if !vid.SPS.Direct8x8InferenceFlag {
|
2019-07-18 07:32:42 +03:00
|
|
|
noSubMbPartSizeLessThan8x8Flag = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
} else {
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.PPS.Transform8x8Mode == 1 && sliceContext.Slice.SliceData.MbTypeName == "I_NxN" {
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO
|
|
|
|
// 1 bit or ae(v)
|
2019-09-09 04:38:48 +03:00
|
|
|
// If vid.PPS.EntropyCodingMode == 1, use ae(v)
|
|
|
|
if vid.PPS.EntropyCodingMode == 1 {
|
|
|
|
binarization := NewBinarization("TransformSize8x8Flag", sliceContext.Slice.SliceData)
|
|
|
|
cabac = initCabac(binarization, nil, sliceContext)
|
2019-07-18 07:32:42 +03:00
|
|
|
binarization.Decode(sliceContext, br, nil)
|
|
|
|
|
|
|
|
logger.Println("TODO: ae(v) for TransformSize8x8Flag")
|
|
|
|
} else {
|
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read TransformSize8x8Flag")
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.TransformSize8x8Flag = b == 1
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO: fix nil argument for.
|
2019-09-09 04:38:48 +03:00
|
|
|
MbPred(chromaArrayType, nil, sliceContext, br, nil)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
m, err = MbPartPredMode(sliceContext.Slice.SliceData, sliceContext.Slice.SliceData.SliceTypeName, sliceContext.Slice.SliceData.MbType, 0)
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not get mbPartPredMode")
|
|
|
|
}
|
|
|
|
if m != intra16x16 {
|
|
|
|
// TODO: me, ae
|
|
|
|
logger.Printf("TODO: CodedBlockPattern pending me/ae implementation\n")
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.PPS.EntropyCodingMode == 1 {
|
|
|
|
binarization := NewBinarization("CodedBlockPattern", sliceContext.Slice.SliceData)
|
|
|
|
cabac = initCabac(binarization, nil, sliceContext)
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO: fix nil argument.
|
|
|
|
binarization.Decode(sliceContext, br, nil)
|
|
|
|
|
|
|
|
logger.Printf("TODO: ae for CodedBlockPattern\n")
|
|
|
|
} else {
|
|
|
|
me, _ := readMe(
|
2019-07-19 08:06:50 +03:00
|
|
|
br,
|
2019-08-04 18:47:19 +03:00
|
|
|
uint(chromaArrayType),
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO: fix this
|
2019-09-09 04:38:48 +03:00
|
|
|
//MbPartPredMode(sliceContext.Slice.SliceData, sliceContext.Slice.SliceData.SliceTypeName, sliceContext.Slice.SliceData.MbType, 0)))
|
2019-07-18 07:32:42 +03:00
|
|
|
0)
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.CodedBlockPattern = int(me)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
|
2019-09-09 04:38:48 +03:00
|
|
|
// sliceContext.Slice.SliceData.CodedBlockPattern = me(v) | ae(v)
|
|
|
|
if CodedBlockPatternLuma(sliceContext.Slice.SliceData) > 0 && vid.PPS.Transform8x8Mode == 1 && sliceContext.Slice.SliceData.MbTypeName != "I_NxN" && noSubMbPartSizeLessThan8x8Flag == 1 && (sliceContext.Slice.SliceData.MbTypeName != "B_Direct_16x16" || vid.SPS.Direct8x8InferenceFlag) {
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO: 1 bit or ae(v)
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.PPS.EntropyCodingMode == 1 {
|
|
|
|
binarization := NewBinarization("Transform8x8Flag", sliceContext.Slice.SliceData)
|
|
|
|
cabac = initCabac(binarization, nil, sliceContext)
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO: fix nil argument.
|
|
|
|
binarization.Decode(sliceContext, br, nil)
|
|
|
|
|
|
|
|
logger.Printf("TODO: ae for TranformSize8x8Flag\n")
|
|
|
|
} else {
|
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "coult not read TransformSize8x8Flag")
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.TransformSize8x8Flag = b == 1
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
m, err = MbPartPredMode(sliceContext.Slice.SliceData, sliceContext.Slice.SliceData.SliceTypeName, sliceContext.Slice.SliceData.MbType, 0)
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not get mbPartPredMode")
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
if CodedBlockPatternLuma(sliceContext.Slice.SliceData) > 0 || CodedBlockPatternChroma(sliceContext.Slice.SliceData) > 0 || m == intra16x16 {
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO: se or ae(v)
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.PPS.EntropyCodingMode == 1 {
|
|
|
|
binarization := NewBinarization("MbQpDelta", sliceContext.Slice.SliceData)
|
|
|
|
cabac = initCabac(binarization, nil, sliceContext)
|
2019-07-18 07:32:42 +03:00
|
|
|
// TODO; fix nil argument
|
|
|
|
binarization.Decode(sliceContext, br, nil)
|
|
|
|
|
|
|
|
logger.Printf("TODO: ae for MbQpDelta\n")
|
|
|
|
} else {
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.MbQpDelta, _ = readSe(br)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // END MacroblockLayer
|
2019-09-09 04:38:48 +03:00
|
|
|
if vid.PPS.EntropyCodingMode == 0 {
|
2019-07-18 07:32:42 +03:00
|
|
|
moreDataFlag = moreRBSPData(br)
|
|
|
|
} else {
|
2019-09-09 04:38:48 +03:00
|
|
|
if sliceContext.Slice.SliceData.SliceTypeName != "I" && sliceContext.Slice.SliceData.SliceTypeName != "SI" {
|
|
|
|
if sliceContext.Slice.SliceData.MbSkipFlag {
|
2019-07-18 07:32:42 +03:00
|
|
|
prevMbSkipped = 1
|
|
|
|
} else {
|
|
|
|
prevMbSkipped = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if mbaffFrameFlag == 1 && currMbAddr%2 == 0 {
|
|
|
|
moreDataFlag = true
|
|
|
|
} else {
|
|
|
|
// TODO: ae implementation
|
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read EndOfSliceFlag")
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData.EndOfSliceFlag = b == 1
|
|
|
|
moreDataFlag = !sliceContext.Slice.SliceData.EndOfSliceFlag
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
currMbAddr = nextMbAddress(currMbAddr, vid.SPS, vid.PPS, sliceContext.Slice.SliceHeader)
|
2019-07-18 07:32:42 +03:00
|
|
|
} // END while moreDataFlag
|
2019-09-09 04:38:48 +03:00
|
|
|
return sliceContext.Slice.SliceData, nil
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *SliceContext) Update(header *SliceHeader, data *SliceData) {
|
2019-09-09 04:38:48 +03:00
|
|
|
c.Slice = &Slice{SliceHeader: header, SliceData: data}
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-08-04 18:47:19 +03:00
|
|
|
func NewSliceContext(vid *VideoStream, nalUnit *NALUnit, rbsp []byte, showPacket bool) (*SliceContext, error) {
|
2019-07-18 07:32:42 +03:00
|
|
|
var err error
|
2019-08-04 18:47:19 +03:00
|
|
|
sps := vid.SPS
|
|
|
|
pps := vid.PPS
|
2019-07-29 06:34:59 +03:00
|
|
|
logger.Printf("debug: %s RBSP %d bytes %d bits == \n", NALUnitType[int(nalUnit.Type)], len(rbsp), len(rbsp)*8)
|
2019-07-18 07:32:42 +03:00
|
|
|
logger.Printf("debug: \t%#v\n", rbsp[0:8])
|
|
|
|
var idrPic bool
|
|
|
|
if nalUnit.Type == 5 {
|
|
|
|
idrPic = true
|
|
|
|
}
|
|
|
|
header := SliceHeader{}
|
2019-07-21 15:41:24 +03:00
|
|
|
if sps.SeparateColorPlaneFlag {
|
2019-08-04 18:47:19 +03:00
|
|
|
vid.ChromaArrayType = 0
|
2019-07-18 07:32:42 +03:00
|
|
|
} else {
|
2019-08-05 08:11:26 +03:00
|
|
|
vid.ChromaArrayType = int(sps.ChromaFormatIDC)
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
br := bits.NewBitReader(bytes.NewReader(rbsp))
|
2019-07-30 03:46:08 +03:00
|
|
|
r := newFieldReader(br)
|
2019-07-18 07:32:42 +03:00
|
|
|
|
2019-07-30 03:46:08 +03:00
|
|
|
header.FirstMbInSlice = int(r.readUe())
|
|
|
|
header.SliceType = int(r.readUe())
|
2019-07-18 07:32:42 +03:00
|
|
|
|
|
|
|
sliceType := sliceTypeMap[header.SliceType]
|
2019-07-29 06:34:59 +03:00
|
|
|
logger.Printf("debug: %s (%s) slice of %d bytes\n", NALUnitType[int(nalUnit.Type)], sliceType, len(rbsp))
|
2019-07-30 03:46:08 +03:00
|
|
|
header.PPSID = int(r.readUe())
|
2019-07-21 15:41:24 +03:00
|
|
|
if sps.SeparateColorPlaneFlag {
|
2019-07-18 07:32:42 +03:00
|
|
|
b, err := br.ReadBits(2)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read ColorPlaneID")
|
|
|
|
}
|
|
|
|
header.ColorPlaneID = int(b)
|
|
|
|
}
|
|
|
|
// TODO: See 7.4.3
|
|
|
|
// header.FrameNum = b.NextField("FrameNum", 0)
|
2019-07-21 15:41:24 +03:00
|
|
|
if !sps.FrameMBSOnlyFlag {
|
2019-07-18 07:32:42 +03:00
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read FieldPic")
|
|
|
|
}
|
|
|
|
header.FieldPic = b == 1
|
|
|
|
if header.FieldPic {
|
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read BottomField")
|
|
|
|
}
|
|
|
|
header.BottomField = b == 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if idrPic {
|
2019-07-30 03:46:08 +03:00
|
|
|
header.IDRPicID = int(r.readUe())
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
if sps.PicOrderCountType == 0 {
|
2019-07-30 03:46:08 +03:00
|
|
|
b, err := br.ReadBits(int(sps.Log2MaxPicOrderCntLSBMin4 + 4))
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read PicOrderCntLsb")
|
|
|
|
}
|
|
|
|
header.PicOrderCntLsb = int(b)
|
|
|
|
|
|
|
|
if pps.BottomFieldPicOrderInFramePresent && !header.FieldPic {
|
2019-07-19 08:06:50 +03:00
|
|
|
header.DeltaPicOrderCntBottom, err = readSe(br)
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse DeltaPicOrderCntBottom")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-21 15:41:24 +03:00
|
|
|
if sps.PicOrderCountType == 1 && !sps.DeltaPicOrderAlwaysZeroFlag {
|
2019-07-19 08:06:50 +03:00
|
|
|
header.DeltaPicOrderCnt[0], err = readSe(br)
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse DeltaPicOrderCnt")
|
|
|
|
}
|
|
|
|
|
|
|
|
if pps.BottomFieldPicOrderInFramePresent && !header.FieldPic {
|
2019-07-19 08:06:50 +03:00
|
|
|
header.DeltaPicOrderCnt[1], err = readSe(br)
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse DeltaPicOrderCnt")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if pps.RedundantPicCntPresent {
|
2019-07-30 03:46:08 +03:00
|
|
|
header.RedundantPicCnt = int(r.readUe())
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
if sliceType == "B" {
|
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read DirectSpatialMvPred")
|
|
|
|
}
|
|
|
|
header.DirectSpatialMvPred = b == 1
|
|
|
|
}
|
|
|
|
if sliceType == "B" || sliceType == "SP" {
|
|
|
|
b, err := br.ReadBits(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read NumRefIdxActiveOverride")
|
|
|
|
}
|
|
|
|
header.NumRefIdxActiveOverride = b == 1
|
|
|
|
|
|
|
|
if header.NumRefIdxActiveOverride {
|
2019-07-30 03:46:08 +03:00
|
|
|
header.NumRefIdxL0ActiveMinus1 = int(r.readUe())
|
2019-07-18 07:32:42 +03:00
|
|
|
if sliceType == "B" {
|
2019-07-30 03:46:08 +03:00
|
|
|
header.NumRefIdxL1ActiveMinus1 = int(r.readUe())
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if nalUnit.Type == 20 || nalUnit.Type == 21 {
|
|
|
|
// Annex H
|
|
|
|
// H.7.3.3.1.1
|
|
|
|
// refPicListMvcModifications()
|
|
|
|
} else {
|
2019-08-04 06:29:13 +03:00
|
|
|
header.RefPicListModification, err = NewRefPicListModification(br, pps, &header)
|
2019-07-22 06:26:37 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse RefPicListModification")
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pps.WeightedPred && (sliceType == "P" || sliceType == "SP")) || (pps.WeightedBipred == 1 && sliceType == "B") {
|
2019-08-04 18:47:19 +03:00
|
|
|
header.PredWeightTable, err = NewPredWeightTable(br, &header, vid.ChromaArrayType)
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
2019-07-22 07:31:23 +03:00
|
|
|
return nil, errors.Wrap(err, "could not parse PredWeightTable")
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-07-22 07:31:23 +03:00
|
|
|
}
|
2019-07-18 07:32:42 +03:00
|
|
|
if nalUnit.RefIdc != 0 {
|
|
|
|
// devRefPicMarking()
|
2019-08-05 04:10:20 +03:00
|
|
|
header.DecRefPicMarking, err = NewDecRefPicMarking(br, idrPic)
|
2019-07-22 08:43:18 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse DecRefPicMarking")
|
|
|
|
}
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
if pps.EntropyCodingMode == 1 && sliceType != "I" && sliceType != "SI" {
|
2019-07-30 03:46:08 +03:00
|
|
|
header.CabacInit = int(r.readUe())
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-07-30 03:46:08 +03:00
|
|
|
header.SliceQpDelta = int(r.readSe())
|
2019-07-18 07:32:42 +03:00
|
|
|
|
|
|
|
if sliceType == "SP" || sliceType == "SI" {
|
|
|
|
if sliceType == "SP" {
|
2019-07-30 03:46:08 +03:00
|
|
|
header.SpForSwitch = r.readBits(1) == 1
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
2019-07-30 03:46:08 +03:00
|
|
|
header.SliceQsDelta = int(r.readSe())
|
2019-07-18 07:32:42 +03:00
|
|
|
}
|
|
|
|
if pps.DeblockingFilterControlPresent {
|
2019-07-30 03:46:08 +03:00
|
|
|
header.DisableDeblockingFilter = int(r.readUe())
|
2019-07-18 07:32:42 +03:00
|
|
|
if header.DisableDeblockingFilter != 1 {
|
2019-07-19 08:06:50 +03:00
|
|
|
header.SliceAlphaC0OffsetDiv2, err = readSe(br)
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse SliceAlphaC0OffsetDiv2")
|
|
|
|
}
|
|
|
|
|
2019-07-19 08:06:50 +03:00
|
|
|
header.SliceBetaOffsetDiv2, err = readSe(br)
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse SliceBetaOffsetDiv2")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if pps.NumSliceGroupsMinus1 > 0 && pps.SliceGroupMapType >= 3 && pps.SliceGroupMapType <= 5 {
|
|
|
|
b, err := br.ReadBits(int(math.Ceil(math.Log2(float64(pps.PicSizeInMapUnitsMinus1/pps.SliceGroupChangeRateMinus1 + 1)))))
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read SliceGruopChangeCycle")
|
|
|
|
}
|
|
|
|
header.SliceGroupChangeCycle = int(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
sliceContext := &SliceContext{
|
2019-07-19 14:28:01 +03:00
|
|
|
NALUnit: nalUnit,
|
2019-07-18 07:32:42 +03:00
|
|
|
Slice: &Slice{
|
2019-09-09 04:38:48 +03:00
|
|
|
SliceHeader: &header,
|
2019-07-18 07:32:42 +03:00
|
|
|
},
|
|
|
|
}
|
2019-09-09 04:38:48 +03:00
|
|
|
sliceContext.Slice.SliceData, err = NewSliceData(vid.ChromaArrayType, nil, sliceContext, br)
|
2019-07-18 07:32:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not create slice data")
|
|
|
|
}
|
2019-07-21 15:41:24 +03:00
|
|
|
|
2019-07-18 07:32:42 +03:00
|
|
|
return sliceContext, nil
|
|
|
|
}
|