From c0be9b1910055cb98c12c08a7ad3747866866c62 Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 9 Sep 2019 13:26:46 +0930 Subject: [PATCH] codec/h264/h264dec/decode.go: added picOrderCntType2 to derive topfieldOrderCnt and bottomFieldOrderCnt for when picOrderCntType == 2 --- codec/h264/h264dec/decode.go | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) 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 +}