codec/h264/h264dec/decode.go: wrote function picOrderCntType0 to handle derivation of TopFieldOrderCnt and BottomFieldOrderCnt when pic_order_cnt_type == 0

This commit is contained in:
Saxon 2019-09-09 11:28:43 +09:30
parent 5261f82ef7
commit d92e0bfb5e
2 changed files with 45 additions and 1 deletions

View File

@ -23,3 +23,38 @@ LICENSE
*/ */
package h264dec 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) {
prevPicOrderCntMsb, prevPicOrderCntLsb := 0, 0
topFieldOrderCnt, bottomFieldOrderCnt = -1, -1
// NB: We're currently only handling IDRs so panic.
if !vid.currPic.isIDR {
panic("not implemented")
}
switch {
case (ctx.PicOrderCntLsb < prevPicOrderCntLsb) && ((prevPicOrderCntLsb - ctx.PicOrderCntLsb) >= (vid.maxPicOrderCntLsb / 2)):
vid.picOrderCntMsb = prevPicOrderCntMsb + vid.maxPicOrderCntLsb
case (ctx.PicOrderCntLsb > prevPicOrderCntLsb) && ((ctx.PicOrderCntLsb - prevPicOrderCntLsb) > (vid.maxPicOrderCntLsb / 2)):
vid.picOrderCntMsb = prevPicOrderCntMsb - vid.maxPicOrderCntLsb
default:
vid.picOrderCntMsb = prevPicOrderCntMsb
}
if !vid.currPic.isBottomField {
topFieldOrderCnt = vid.picOrderCntMsb + ctx.PicOrderCntLsb
}
if !vid.currPic.isTopField {
if !ctx.FieldPic {
bottomFieldOrderCnt = topFieldOrderCnt + ctx.DeltaPicOrderCntBottom
} else {
bottomFieldOrderCnt = vid.picOrderCntMsb + ctx.PicOrderCntLsb
}
}
return
}

View File

@ -35,12 +35,21 @@ const (
chroma444 chroma444
) )
type picture struct {
isIDR bool
isBottomField bool
isTopField bool
}
type VideoStream struct { type VideoStream struct {
*SPS *SPS
*PPS *PPS
Slices []*SliceContext Slices []*SliceContext
ChromaArrayType int ChromaArrayType int
currPic picture
maxPicOrderCntLsb int
picOrderCntMsb int
} }
type SliceContext struct { type SliceContext struct {