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 {