diff --git a/codec/h264/h264dec/decode.go b/codec/h264/h264dec/decode.go index b3ec42dc..19ae3aa0 100644 --- a/codec/h264/h264dec/decode.go +++ b/codec/h264/h264dec/decode.go @@ -108,3 +108,41 @@ func picOrderCntType1(vid VideoStream, ctx SliceContext) (topFieldOrderCnt, bott } return } + +// picOrderCntType2 is used to return topFieldOrderCnt and bottomFieldOrderCnt +// when vic.PicOrderCntType == 1 according to logic defined in section 8.2.1.3 +// of the specifications. If topFieldOrderCnt or bottomFieldOrderCnt are -1, +// then they are considered unset. +func picOrderCntType2(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") + } + + var tempPicOrderCnt int + switch { + case vid.idrPicFlag: + tempPicOrderCnt = 0 + case ctx.RefIdc == 0: + tempPicOrderCnt = 2*(vid.frameNumOffset+ctx.FrameNum) - 1 + default: + tempPicOrderCnt = 2 * (vid.frameNumOffset + ctx.FrameNum) + } + + switch { + case ctx.FieldPic: + topFieldOrderCnt = tempPicOrderCnt + bottomFieldOrderCnt = tempPicOrderCnt + case ctx.BottomField: + bottomFieldOrderCnt = tempPicOrderCnt + default: + topFieldOrderCnt = tempPicOrderCnt + } + return +}