History

avcodec/evc_parse: split off deriving PoC

James Almer committed 3 years ago

Commit ff7a4cd1 parent f7e0af52 files · +79 −68Browse files

Showing the changes to libavcodec (2 of 2 files). Show all

Unified · Split

2 files
  1. libavcodec/evc_parse.c +74 −68
  2. libavcodec/evc_parse.h +5 −0
libavcodec/evc_parse.c+74−68
@@ -187,6 +187,77 @@ static int evc_parse_slice_header(EVCParserContext *ctx, EVCParserSliceHeader *s · 186 unmodified lines
187187 return 0;
188188 }
189189
190+int ff_evc_derive_poc(const EVCParamSets *ps, const EVCParserSliceHeader *sh,
191+ EVCParserPoc *poc, enum EVCNALUnitType nalu_type, int tid)
192+{
193+ const EVCParserPPS *pps = ps->pps[sh->slice_pic_parameter_set_id];
194+ const EVCParserSPS *sps;
195+
196+ if (!pps)
197+ return AVERROR_INVALIDDATA;
198+
199+ sps = ps->sps[pps->pps_seq_parameter_set_id];
200+ if (!sps)
201+ return AVERROR_INVALIDDATA;
202+
203+ if (sps->sps_pocs_flag) {
204+ int PicOrderCntMsb = 0;
205+ poc->prevPicOrderCntVal = poc->PicOrderCntVal;
206+
207+ if (nalu_type == EVC_IDR_NUT)
208+ PicOrderCntMsb = 0;
209+ else {
210+ int MaxPicOrderCntLsb = 1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4);
211+ int prevPicOrderCntLsb = poc->PicOrderCntVal & (MaxPicOrderCntLsb - 1);
212+ int prevPicOrderCntMsb = poc->PicOrderCntVal - prevPicOrderCntLsb;
213+
214+ if ((sh->slice_pic_order_cnt_lsb < prevPicOrderCntLsb) &&
215+ ((prevPicOrderCntLsb - sh->slice_pic_order_cnt_lsb) >= (MaxPicOrderCntLsb / 2)))
216+ PicOrderCntMsb = prevPicOrderCntMsb + MaxPicOrderCntLsb;
217+ else if ((sh->slice_pic_order_cnt_lsb > prevPicOrderCntLsb) &&
218+ ((sh->slice_pic_order_cnt_lsb - prevPicOrderCntLsb) > (MaxPicOrderCntLsb / 2)))
219+ PicOrderCntMsb = prevPicOrderCntMsb - MaxPicOrderCntLsb;
220+ else
221+ PicOrderCntMsb = prevPicOrderCntMsb;
222+ }
223+ poc->PicOrderCntVal = PicOrderCntMsb + sh->slice_pic_order_cnt_lsb;
224+ } else {
225+ if (nalu_type == EVC_IDR_NUT) {
226+ poc->PicOrderCntVal = 0;
227+ poc->DocOffset = -1;
228+ } else {
229+ int SubGopLength = (int)pow(2.0, sps->log2_sub_gop_length);
230+ if (tid == 0) {
231+ poc->PicOrderCntVal = poc->prevPicOrderCntVal + SubGopLength;
232+ poc->DocOffset = 0;
233+ poc->prevPicOrderCntVal = poc->PicOrderCntVal;
234+ } else {
235+ int ExpectedTemporalId;
236+ int PocOffset;
237+ int prevDocOffset = poc->DocOffset;
238+
239+ poc->DocOffset = (prevDocOffset + 1) % SubGopLength;
240+ if (poc->DocOffset == 0) {
241+ poc->prevPicOrderCntVal += SubGopLength;
242+ ExpectedTemporalId = 0;
243+ } else
244+ ExpectedTemporalId = 1 + (int)log2(poc->DocOffset);
245+ while (tid != ExpectedTemporalId) {
246+ poc->DocOffset = (poc->DocOffset + 1) % SubGopLength;
247+ if (poc->DocOffset == 0)
248+ ExpectedTemporalId = 0;
249+ else
250+ ExpectedTemporalId = 1 + (int)log2(poc->DocOffset);
251+ }
252+ PocOffset = (int)(SubGopLength * ((2.0 * poc->DocOffset + 1) / (int)pow(2.0, tid) - 2));
253+ poc->PicOrderCntVal = poc->prevPicOrderCntVal + PocOffset;
254+ }
255+ }
256+ }
257+
258+ return 0;
259+}
260+
190261 int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_size, void *logctx)
191262 {
192263 int nalu_type, nalu_size;
@@ -299,8 +370,6 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz · 106 unmodified lines
299370 case EVC_IDR_NUT: // Coded slice of a IDR or non-IDR picture
300371 case EVC_NOIDR_NUT: {
301372 EVCParserSliceHeader sh;
302− const EVCParserSPS *sps;
303− const EVCParserPPS *pps;
304373 int ret;
305374
306375 ret = evc_parse_slice_header(ctx, &sh, data, nalu_size);
@@ -331,72 +400,9 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz · 24 unmodified lines
331400
332401 // POC (picture order count of the current picture) derivation
333402 // @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for picture order count
334− pps = ctx->ps.pps[sh.slice_pic_parameter_set_id];
335− sps = ctx->ps.sps[pps->pps_seq_parameter_set_id];
336− av_assert0(sps && pps);
337−
338− if (sps->sps_pocs_flag) {
339−
340− int PicOrderCntMsb = 0;
341− ctx->poc.prevPicOrderCntVal = ctx->poc.PicOrderCntVal;
342−
343− if (nalu_type == EVC_IDR_NUT)
344− PicOrderCntMsb = 0;
345− else {
346− int MaxPicOrderCntLsb = 1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4);
347−
348− int prevPicOrderCntLsb = ctx->poc.PicOrderCntVal & (MaxPicOrderCntLsb - 1);
349− int prevPicOrderCntMsb = ctx->poc.PicOrderCntVal - prevPicOrderCntLsb;
350−
351−
352− if ((sh.slice_pic_order_cnt_lsb < prevPicOrderCntLsb) &&
353− ((prevPicOrderCntLsb - sh.slice_pic_order_cnt_lsb) >= (MaxPicOrderCntLsb / 2)))
354−
355− PicOrderCntMsb = prevPicOrderCntMsb + MaxPicOrderCntLsb;
356−
357− else if ((sh.slice_pic_order_cnt_lsb > prevPicOrderCntLsb) &&
358− ((sh.slice_pic_order_cnt_lsb - prevPicOrderCntLsb) > (MaxPicOrderCntLsb / 2)))
359−
360− PicOrderCntMsb = prevPicOrderCntMsb - MaxPicOrderCntLsb;
361−
362− else
363− PicOrderCntMsb = prevPicOrderCntMsb;
364− }
365− ctx->poc.PicOrderCntVal = PicOrderCntMsb + sh.slice_pic_order_cnt_lsb;
366−
367− } else {
368− if (nalu_type == EVC_IDR_NUT) {
369− ctx->poc.PicOrderCntVal = 0;
370− ctx->poc.DocOffset = -1;
371− } else {
372− int SubGopLength = (int)pow(2.0, sps->log2_sub_gop_length);
373− if (tid == 0) {
374− ctx->poc.PicOrderCntVal = ctx->poc.prevPicOrderCntVal + SubGopLength;
375− ctx->poc.DocOffset = 0;
376− ctx->poc.prevPicOrderCntVal = ctx->poc.PicOrderCntVal;
377− } else {
378− int ExpectedTemporalId;
379− int PocOffset;
380− int prevDocOffset = ctx->poc.DocOffset;
381−
382− ctx->poc.DocOffset = (prevDocOffset + 1) % SubGopLength;
383− if (ctx->poc.DocOffset == 0) {
384− ctx->poc.prevPicOrderCntVal += SubGopLength;
385− ExpectedTemporalId = 0;
386− } else
387− ExpectedTemporalId = 1 + (int)log2(ctx->poc.DocOffset);
388− while (tid != ExpectedTemporalId) {
389− ctx->poc.DocOffset = (ctx->poc.DocOffset + 1) % SubGopLength;
390− if (ctx->poc.DocOffset == 0)
391− ExpectedTemporalId = 0;
392− else
393− ExpectedTemporalId = 1 + (int)log2(ctx->poc.DocOffset);
394− }
395− PocOffset = (int)(SubGopLength * ((2.0 * ctx->poc.DocOffset + 1) / (int)pow(2.0, tid) - 2));
396− ctx->poc.PicOrderCntVal = ctx->poc.prevPicOrderCntVal + PocOffset;
397− }
398− }
399− }
403+ ret = ff_evc_derive_poc(&ctx->ps, &sh, &ctx->poc, nalu_type, tid);
404+ if (ret < 0)
405+ return ret;
400406
401407 ctx->output_picture_number = ctx->poc.PicOrderCntVal;
402408 ctx->key_frame = (nalu_type == EVC_IDR_NUT) ? 1 : 0;
libavcodec/evc_parse.h+5−0
@@ -159,4 +159,9 @@ int ff_evc_get_temporal_id(const uint8_t *bits, int bits_size, void *logctx); · 158 unmodified lines
159159
160160 int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_size, void *logctx);
161161
162+// POC (picture order count of the current picture) derivation
163+// @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for picture order count
164+int ff_evc_derive_poc(const EVCParamSets *ps, const EVCParserSliceHeader *sh,
165+ EVCParserPoc *poc, enum EVCNALUnitType nalu_type, int tid);
166+
162167 #endif /* AVCODEC_EVC_PARSE_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t