codec/h264/h264dec/decode.go: added picOrderCntType1 to derive topfieldOrderCnt and bottomFieldOrderCnt for when picOrderCntType == 1

This commit is contained in:
Saxon 2019-09-09 13:03:11 +09:30
parent d92e0bfb5e
commit 43118814fb
2 changed files with 68 additions and 11 deletions

View File

@ -26,13 +26,14 @@ package h264dec
// picOrderCntType0 is used to return topFieldOrderCnt and bottomFieldOrderCnt
// when pic_order_cnt_type i.e vid.PicOrderCntType == 0, using the process
// defined in section 8.2.1.1 of the specifications.
func picOrderCntType0(vid VideoStream, ctx SliceContext) (topFieldOrderCnt, bottomFieldOrderCnt int) {
// defined in section 8.2.1.1 of the specifications. If topFieldOrderCnt or
// bottomFieldOrderCnt are -1 they are unset.
func picOrderCntType0(vid *VideoStream, ctx SliceContext) (topFieldOrderCnt, bottomFieldOrderCnt int) {
prevPicOrderCntMsb, prevPicOrderCntLsb := 0, 0
topFieldOrderCnt, bottomFieldOrderCnt = -1, -1
// NB: We're currently only handling IDRs so panic.
if !vid.currPic.isIDR {
if !vid.idrPicFlag {
panic("not implemented")
}
@ -45,11 +46,9 @@ func picOrderCntType0(vid VideoStream, ctx SliceContext) (topFieldOrderCnt, bott
vid.picOrderCntMsb = prevPicOrderCntMsb
}
if !vid.currPic.isBottomField {
if !ctx.BottomField {
topFieldOrderCnt = vid.picOrderCntMsb + ctx.PicOrderCntLsb
}
if !vid.currPic.isTopField {
} else {
if !ctx.FieldPic {
bottomFieldOrderCnt = topFieldOrderCnt + ctx.DeltaPicOrderCntBottom
} else {
@ -58,3 +57,54 @@ func picOrderCntType0(vid VideoStream, ctx SliceContext) (topFieldOrderCnt, bott
}
return
}
// picOrderCntType1 is used to return topFieldOrderCnt and bottomFieldOrderCnt
// when vic.PicOrderCntType == 1 according to logic defined in section 8.2.1.2
// of the specifications. If topFieldOrderCnt or bottomFieldOrderCnt are -1,
// then they are considered unset.
func picOrderCntType1(vid VideoStream, ctx SliceContext) (topFieldOrderCnt, bottomFieldOrderCnt int) {
topFieldOrderCnt, bottomFieldOrderCnt = -1, -1
// TODO: this will be prevFrameNum when we do frames other than IDR.
_ = vid.priorPic.FrameNum
if vid.idrPicFlag {
vid.frameNumOffset = 0
} else {
panic("not implemented")
}
absFrameNum := 0
if ctx.NumRefFramesInPicOrderCntCycle != 0 {
absFrameNum = vid.frameNumOffset + ctx.FrameNum
}
if ctx.RefIdc == 0 && absFrameNum > 0 {
absFrameNum = absFrameNum - 1
}
var expectedPicOrderCnt int
if absFrameNum > 0 {
picOrderCntCycleCnt := (absFrameNum - 1) / int(ctx.NumRefFramesInPicOrderCntCycle)
frameNumInPicOrderCntCycle := (absFrameNum - 1) % int(ctx.NumRefFramesInPicOrderCntCycle)
expectedPicOrderCnt = picOrderCntCycleCnt * vid.expectedDeltaPerPicOrderCntCycle
for i := 0; i <= frameNumInPicOrderCntCycle; i++ {
expectedPicOrderCnt = expectedPicOrderCnt + ctx.OffsetForRefFrameList[i]
}
}
if ctx.RefIdc == 0 {
expectedPicOrderCnt = expectedPicOrderCnt + int(ctx.OffsetForNonRefPic)
}
switch {
case !ctx.FieldPic:
topFieldOrderCnt = expectedPicOrderCnt + ctx.DeltaPicOrderCnt[0]
bottomFieldOrderCnt = topFieldOrderCnt + int(ctx.OffsetForTopToBottomField) + ctx.DeltaPicOrderCnt[1]
case !ctx.BottomField:
topFieldOrderCnt = expectedPicOrderCnt + ctx.DeltaPicOrderCnt[0]
default:
bottomFieldOrderCnt = expectedPicOrderCnt + int(ctx.OffsetForTopToBottomField) + ctx.DeltaPicOrderCnt[0]
}
return
}

View File

@ -36,6 +36,7 @@ const (
)
type picture struct {
*SliceContext
isIDR bool
isBottomField bool
isTopField bool
@ -47,12 +48,18 @@ type VideoStream struct {
Slices []*SliceContext
ChromaArrayType int
currPic picture
priorPic *picture
currPic *picture
maxPicOrderCntLsb int
picOrderCntMsb int
idrPicFlag bool
frameNumOffset int
expectedDeltaPerPicOrderCntCycle int
}
type SliceContext struct {
*SPS
*PPS
*NALUnit
*Slice
}