From d92e0bfb5e2e47131808a6e9d549ade1b26d1f34 Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 9 Sep 2019 11:28:43 +0930 Subject: [PATCH] codec/h264/h264dec/decode.go: wrote function picOrderCntType0 to handle derivation of TopFieldOrderCnt and BottomFieldOrderCnt when pic_order_cnt_type == 0 --- codec/h264/h264dec/decode.go | 35 +++++++++++++++++++++++++++++++++++ codec/h264/h264dec/slice.go | 11 ++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/codec/h264/h264dec/decode.go b/codec/h264/h264dec/decode.go index 22cfc181..5a914263 100644 --- a/codec/h264/h264dec/decode.go +++ b/codec/h264/h264dec/decode.go @@ -23,3 +23,38 @@ LICENSE */ 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 +} diff --git a/codec/h264/h264dec/slice.go b/codec/h264/h264dec/slice.go index 4952cfd9..83e3b7bf 100644 --- a/codec/h264/h264dec/slice.go +++ b/codec/h264/h264dec/slice.go @@ -35,12 +35,21 @@ const ( chroma444 ) +type picture struct { + isIDR bool + isBottomField bool + isTopField bool +} + type VideoStream struct { *SPS *PPS Slices []*SliceContext - ChromaArrayType int + ChromaArrayType int + currPic picture + maxPicOrderCntLsb int + picOrderCntMsb int } type SliceContext struct {