Skip to content

Commit 2cf2cfd

Browse files
committed
update for no_output_of_prior_pics_flag and pic_output_flag
1 parent 1ea6c67 commit 2cf2cfd

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

libavcodec/hevc.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,11 @@ static int hls_slice_header(HEVCContext *s)
361361
if (IS_IDR(s))
362362
ff_hevc_clear_refs(s);
363363
}
364+
sh->no_output_of_prior_pics_flag = 0;
364365
if (s->nal_unit_type >= 16 && s->nal_unit_type <= 23)
365366
sh->no_output_of_prior_pics_flag = get_bits1(gb);
367+
if (s->nal_unit_type == NAL_CRA_NUT && s->last_eos == 1)
368+
sh->no_output_of_prior_pics_flag = 1;
366369

367370
sh->pps_id = get_ue_golomb_long(gb);
368371
if (sh->pps_id >= MAX_PPS_COUNT || !s->pps_list[sh->pps_id]) {
@@ -377,7 +380,13 @@ static int hls_slice_header(HEVCContext *s)
377380
s->pps = (HEVCPPS*)s->pps_list[sh->pps_id]->data;
378381

379382
if (s->sps != (HEVCSPS*)s->sps_list[s->pps->sps_id]->data) {
383+
const HEVCSPS* last_sps = s->sps;
380384
s->sps = (HEVCSPS*)s->sps_list[s->pps->sps_id]->data;
385+
if(last_sps) {
386+
if (s->sps->width != last_sps->width || s->sps->height != last_sps->height ||
387+
s->sps->temporal_layer[s->sps->max_sub_layers - 1].max_dec_pic_buffering != last_sps->temporal_layer[last_sps->max_sub_layers - 1].max_dec_pic_buffering)
388+
sh->no_output_of_prior_pics_flag = 0;
389+
}
381390
ff_hevc_clear_refs(s);
382391
ret = set_sps(s, s->sps);
383392
if (ret < 0)
@@ -436,6 +445,7 @@ static int hls_slice_header(HEVCContext *s)
436445
return AVERROR_INVALIDDATA;
437446
}
438447

448+
sh->pic_output_flag = 1;
439449
if (s->pps->output_flag_present_flag)
440450
sh->pic_output_flag = get_bits1(gb);
441451

@@ -2589,6 +2599,7 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
25892599
int i, consumed, ret = 0;
25902600

25912601
s->ref = NULL;
2602+
s->last_eos = s->eos;
25922603
s->eos = 0;
25932604

25942605
/* split the input packet into NAL units, so we know the upper bound on the
@@ -2945,7 +2956,7 @@ static av_cold int hevc_init_context(AVCodecContext *avctx)
29452956
ff_dsputil_init(&s->dsp, avctx);
29462957

29472958
s->context_initialized = 1;
2948-
2959+
s->eos = 0;
29492960
return 0;
29502961

29512962
fail:
@@ -3009,6 +3020,7 @@ static int hevc_update_thread_context(AVCodecContext *dst,
30093020
s->seq_output = s0->seq_output;
30103021
s->pocTid0 = s0->pocTid0;
30113022
s->max_ra = s0->max_ra;
3023+
s->eos = s0->eos;
30123024

30133025
s->is_nalff = s0->is_nalff;
30143026
s->nal_length_size = s0->nal_length_size;

libavcodec/hevc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ typedef struct HEVCContext {
804804
int pocTid0;
805805
int slice_idx; ///< number of the slice being currently decoded
806806
int eos; ///< current packet contains an EOS/EOB NAL
807+
int last_eos; ///< last packet contains an EOS/EOB NAL
807808
int max_ra;
808809
int bs_width;
809810
int bs_height;

libavcodec/hevc_refs.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame **frame, int poc)
146146

147147
ref->poc = poc;
148148
ref->flags = HEVC_FRAME_FLAG_OUTPUT | HEVC_FRAME_FLAG_SHORT_REF;
149+
if(s->sh.pic_output_flag == 0)
150+
ref->flags &= ~(HEVC_FRAME_FLAG_OUTPUT);
149151
ref->sequence = s->seq_decode;
150152
ref->window = s->sps->output_window;
151153

@@ -159,6 +161,16 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush)
159161
int min_poc = INT_MAX;
160162
int i, min_idx, ret;
161163

164+
if(s->sh.no_output_of_prior_pics_flag == 1) {
165+
for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
166+
HEVCFrame *frame = &s->DPB[i];
167+
if ((frame->flags & HEVC_FRAME_FLAG_OUTPUT) && frame->poc != s->poc &&
168+
frame->sequence == s->seq_output) {
169+
frame->flags &= ~(HEVC_FRAME_FLAG_OUTPUT);
170+
}
171+
}
172+
}
173+
162174
for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
163175
HEVCFrame *frame = &s->DPB[i];
164176
if ((frame->flags & HEVC_FRAME_FLAG_OUTPUT) &&

0 commit comments

Comments
 (0)