mirror of https://bitbucket.org/ausocean/av.git
codec/h264/h264dec/decode.go: added picOrderCntType1 to derive topfieldOrderCnt and bottomFieldOrderCnt for when picOrderCntType == 1
This commit is contained in:
parent
d92e0bfb5e
commit
43118814fb
|
@ -26,13 +26,14 @@ package h264dec
|
||||||
|
|
||||||
// picOrderCntType0 is used to return topFieldOrderCnt and bottomFieldOrderCnt
|
// picOrderCntType0 is used to return topFieldOrderCnt and bottomFieldOrderCnt
|
||||||
// when pic_order_cnt_type i.e vid.PicOrderCntType == 0, using the process
|
// when pic_order_cnt_type i.e vid.PicOrderCntType == 0, using the process
|
||||||
// defined in section 8.2.1.1 of the specifications.
|
// defined in section 8.2.1.1 of the specifications. If topFieldOrderCnt or
|
||||||
func picOrderCntType0(vid VideoStream, ctx SliceContext) (topFieldOrderCnt, bottomFieldOrderCnt int) {
|
// bottomFieldOrderCnt are -1 they are unset.
|
||||||
|
func picOrderCntType0(vid *VideoStream, ctx SliceContext) (topFieldOrderCnt, bottomFieldOrderCnt int) {
|
||||||
prevPicOrderCntMsb, prevPicOrderCntLsb := 0, 0
|
prevPicOrderCntMsb, prevPicOrderCntLsb := 0, 0
|
||||||
topFieldOrderCnt, bottomFieldOrderCnt = -1, -1
|
topFieldOrderCnt, bottomFieldOrderCnt = -1, -1
|
||||||
|
|
||||||
// NB: We're currently only handling IDRs so panic.
|
// NB: We're currently only handling IDRs so panic.
|
||||||
if !vid.currPic.isIDR {
|
if !vid.idrPicFlag {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,11 +46,9 @@ func picOrderCntType0(vid VideoStream, ctx SliceContext) (topFieldOrderCnt, bott
|
||||||
vid.picOrderCntMsb = prevPicOrderCntMsb
|
vid.picOrderCntMsb = prevPicOrderCntMsb
|
||||||
}
|
}
|
||||||
|
|
||||||
if !vid.currPic.isBottomField {
|
if !ctx.BottomField {
|
||||||
topFieldOrderCnt = vid.picOrderCntMsb + ctx.PicOrderCntLsb
|
topFieldOrderCnt = vid.picOrderCntMsb + ctx.PicOrderCntLsb
|
||||||
}
|
} else {
|
||||||
|
|
||||||
if !vid.currPic.isTopField {
|
|
||||||
if !ctx.FieldPic {
|
if !ctx.FieldPic {
|
||||||
bottomFieldOrderCnt = topFieldOrderCnt + ctx.DeltaPicOrderCntBottom
|
bottomFieldOrderCnt = topFieldOrderCnt + ctx.DeltaPicOrderCntBottom
|
||||||
} else {
|
} else {
|
||||||
|
@ -58,3 +57,54 @@ func picOrderCntType0(vid VideoStream, ctx SliceContext) (topFieldOrderCnt, bott
|
||||||
}
|
}
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type picture struct {
|
type picture struct {
|
||||||
|
*SliceContext
|
||||||
isIDR bool
|
isIDR bool
|
||||||
isBottomField bool
|
isBottomField bool
|
||||||
isTopField bool
|
isTopField bool
|
||||||
|
@ -47,12 +48,18 @@ type VideoStream struct {
|
||||||
Slices []*SliceContext
|
Slices []*SliceContext
|
||||||
|
|
||||||
ChromaArrayType int
|
ChromaArrayType int
|
||||||
currPic picture
|
priorPic *picture
|
||||||
|
currPic *picture
|
||||||
maxPicOrderCntLsb int
|
maxPicOrderCntLsb int
|
||||||
picOrderCntMsb int
|
picOrderCntMsb int
|
||||||
|
idrPicFlag bool
|
||||||
|
frameNumOffset int
|
||||||
|
expectedDeltaPerPicOrderCntCycle int
|
||||||
}
|
}
|
||||||
|
|
||||||
type SliceContext struct {
|
type SliceContext struct {
|
||||||
|
*SPS
|
||||||
|
*PPS
|
||||||
*NALUnit
|
*NALUnit
|
||||||
*Slice
|
*Slice
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue