diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c index f82f9fdf5e..9e7fa621ce 100644 --- a/libavcodec/hevc_parser.c +++ b/libavcodec/hevc_parser.c @@ -379,7 +379,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, if (!IS_IDR(h)) { sh->pic_order_cnt_lsb = get_bits(gb, ps->sps->log2_max_poc_lsb); - s->output_picture_number = h->poc = ff_hevc_compute_poc(h, sh->pic_order_cnt_lsb); + s->output_picture_number = h->poc = ff_hevc_compute_poc(h->ps.sps, h->pocTid0, sh->pic_order_cnt_lsb, h->nal_unit_type); } else s->output_picture_number = h->poc = 0; diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c index 6d67dd9c69..b5a970e4f7 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -1665,3 +1665,26 @@ err: av_buffer_unref(&pps_buf); return ret; } + +int ff_hevc_compute_poc(const HEVCSPS *sps, int pocTid0, int poc_lsb, int nal_unit_type) +{ + int max_poc_lsb = 1 << sps->log2_max_poc_lsb; + int prev_poc_lsb = pocTid0 % max_poc_lsb; + int prev_poc_msb = pocTid0 - prev_poc_lsb; + int poc_msb; + + if (poc_lsb < prev_poc_lsb && prev_poc_lsb - poc_lsb >= max_poc_lsb / 2) + poc_msb = prev_poc_msb + max_poc_lsb; + else if (poc_lsb > prev_poc_lsb && poc_lsb - prev_poc_lsb > max_poc_lsb / 2) + poc_msb = prev_poc_msb - max_poc_lsb; + else + poc_msb = prev_poc_msb; + + // For BLA picture types, POCmsb is set to 0. + if (nal_unit_type == HEVC_NAL_BLA_W_LP || + nal_unit_type == HEVC_NAL_BLA_W_RADL || + nal_unit_type == HEVC_NAL_BLA_N_LP) + poc_msb = 0; + + return poc_msb + poc_lsb; +} diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h index b0a17bc8f0..45ef9daf1f 100644 --- a/libavcodec/hevc_ps.h +++ b/libavcodec/hevc_ps.h @@ -344,4 +344,9 @@ int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx, int ff_hevc_encode_nal_vps(HEVCVPS *vps, unsigned int id, uint8_t *buf, int buf_size); +/** + * Compute POC of the current frame and return it. + */ +int ff_hevc_compute_poc(const HEVCSPS *sps, int pocTid0, int poc_lsb, int nal_unit_type); + #endif /* AVCODEC_HEVC_PS_H */ diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c index 6810ffaf17..fc1385ca55 100644 --- a/libavcodec/hevc_refs.c +++ b/libavcodec/hevc_refs.c @@ -516,29 +516,6 @@ fail: return ret; } -int ff_hevc_compute_poc(HEVCContext *s, int poc_lsb) -{ - int max_poc_lsb = 1 << s->ps.sps->log2_max_poc_lsb; - int prev_poc_lsb = s->pocTid0 % max_poc_lsb; - int prev_poc_msb = s->pocTid0 - prev_poc_lsb; - int poc_msb; - - if (poc_lsb < prev_poc_lsb && prev_poc_lsb - poc_lsb >= max_poc_lsb / 2) - poc_msb = prev_poc_msb + max_poc_lsb; - else if (poc_lsb > prev_poc_lsb && poc_lsb - prev_poc_lsb > max_poc_lsb / 2) - poc_msb = prev_poc_msb - max_poc_lsb; - else - poc_msb = prev_poc_msb; - - // For BLA picture types, POCmsb is set to 0. - if (s->nal_unit_type == HEVC_NAL_BLA_W_LP || - s->nal_unit_type == HEVC_NAL_BLA_W_RADL || - s->nal_unit_type == HEVC_NAL_BLA_N_LP) - poc_msb = 0; - - return poc_msb + poc_lsb; -} - int ff_hevc_frame_nb_refs(HEVCContext *s) { int ret = 0; diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 2a02edab28..8f235b0be1 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -541,7 +541,7 @@ static int hls_slice_header(HEVCContext *s) int poc, pos; sh->pic_order_cnt_lsb = get_bits(gb, s->ps.sps->log2_max_poc_lsb); - poc = ff_hevc_compute_poc(s, sh->pic_order_cnt_lsb); + poc = ff_hevc_compute_poc(s->ps.sps, s->pocTid0, sh->pic_order_cnt_lsb, s->nal_unit_type); if (!sh->first_slice_in_pic_flag && poc != s->poc) { av_log(s->avctx, AV_LOG_WARNING, "Ignoring POC change between slices: %d -> %d\n", s->poc, poc); diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h index cc7fc7e35f..d8494ee6b1 100644 --- a/libavcodec/hevcdec.h +++ b/libavcodec/hevcdec.h @@ -579,11 +579,6 @@ void ff_hevc_clear_refs(HEVCContext *s); */ void ff_hevc_flush_dpb(HEVCContext *s); -/** - * Compute POC of the current frame and return it. - */ -int ff_hevc_compute_poc(HEVCContext *s, int poc_lsb); - RefPicList *ff_hevc_get_ref_list(HEVCContext *s, HEVCFrame *frame, int x0, int y0);